306 lines
7.5 KiB
C
306 lines
7.5 KiB
C
|
|
/* USER CODE BEGIN Header */
|
|
/**
|
|
******************************************************************************
|
|
* @file compressor_valve_switch.c
|
|
* @author Motor Control SDK Team, Yuwell Software XiangenWang
|
|
* @brief Voice Recognition Module Initialization Section,
|
|
including peripheral initialization and message node insertion, etc.
|
|
* @version 1.0
|
|
* @changelog version 1.0 初始版本 2025.12.10
|
|
- 新增:新建第一个版本的软件,待完善解析命令后的程序执行部分
|
|
******************************************************************************
|
|
* @attention
|
|
*
|
|
* <h2><center>© Copyright (c) 2025 Yuwell Software Danyang.Jiangsu.China.
|
|
* All rights reserved.</center></h2>
|
|
*
|
|
* Redistribution and use in source and binary forms, with or without
|
|
* modification, are permitted, provided that the following conditions are met:
|
|
*
|
|
* 1. Redistribution of source code must retain the above copyright notice,
|
|
* this list of conditions and the following disclaimer.
|
|
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
|
* this list of conditions and the following disclaimer in the documentation
|
|
* and/or other materials provided with the distribution.
|
|
* 3. Neither the name of Yuwell Software nor the names of other
|
|
* contributors to this software may be used to endorse or promote products
|
|
* derived from this software without specific written permission.
|
|
* 4. This software, including modifications and/or derivative works of this
|
|
* software, must execute solely and exclusively on microcontroller or
|
|
* microprocessor devices manufactured by or for Yuwell Software.
|
|
* 5. Redistribution and use of this software other than as permitted under
|
|
* this license is void and will automatically terminate your rights under
|
|
* this license.
|
|
*
|
|
* THIS SOFTWARE IS PROVIDED BY Yuwell Software AND CONTRIBUTORS "AS IS"
|
|
* AND ANY EXPRESS, IMPLIED OR STATUTORY WARRANTIES, INCLUDING, BUT NOT
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
|
|
* PARTICULAR PURPOSE AND NON-INFRINGEMENT OF THIRD PARTY INTELLECTUAL PROPERTY
|
|
* RIGHTS ARE DISCLAIMED TO THE FULLEST EXTENT PERMITTED BY LAW. IN NO EVENT
|
|
* SHALL Yuwell Software OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
|
|
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
|
|
* OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
|
|
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
|
|
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
|
|
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
*
|
|
******************************************************************************
|
|
*/
|
|
/* USER CODE END Header */
|
|
#include "compressor_valve_switch.h"
|
|
|
|
|
|
// 刚开始上电时的电磁阀切换状态
|
|
typedef enum
|
|
{
|
|
ON_STAGE_1_3200_11,
|
|
ON_STAGE_2_1820_10,
|
|
ON_STAGE_3_120_00,
|
|
ON_STAGE_4_2880_10, // 四阶段后切换到正常工作模式
|
|
|
|
} PowerOnValveStage;
|
|
|
|
typedef enum
|
|
{
|
|
|
|
NORMAL_STAGE_1_500_11,
|
|
NORMAL_STAGE_2_4820_01,
|
|
NORMAL_STAGE_3_500_11,
|
|
NORMAL_STAGE_4_4820_10, // 正常情况下四个阶段来回切换
|
|
|
|
} NormalValveStage;
|
|
|
|
|
|
typedef enum
|
|
{
|
|
|
|
PHASE_1_POWER_ON,
|
|
PHASE_2_NORMAL,
|
|
|
|
} ValveShiftPhase;
|
|
|
|
PowerOnValveStage on_valve_stage = ON_STAGE_1_3200_11;
|
|
NormalValveStage normal_valve_stage = NORMAL_STAGE_1_500_11;
|
|
ValveShiftPhase valve_phase = PHASE_1_POWER_ON;
|
|
|
|
|
|
void compressor_valve_init(void)
|
|
{
|
|
|
|
/* 配置普通GPIO工作模式 */
|
|
FL_GPIO_InitTypeDef GPIO_InitStruct;
|
|
|
|
GPIO_InitStruct.mode = FL_GPIO_MODE_OUTPUT;
|
|
GPIO_InitStruct.outputType = FL_GPIO_OUTPUT_PUSHPULL;
|
|
GPIO_InitStruct.pull = FL_ENABLE;
|
|
GPIO_InitStruct.remapPin = FL_DISABLE;
|
|
GPIO_InitStruct.analogSwitch = FL_DISABLE;
|
|
|
|
// 电磁阀控制GPIO初始化
|
|
GPIO_InitStruct.pin = VALVE_1_GPIO_PIN;
|
|
FL_GPIO_Init(VALVE_1_GPIO_PORT, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.pin = VALVE_2_GPIO_PIN;
|
|
FL_GPIO_Init(VALVE_2_GPIO_PORT, &GPIO_InitStruct);
|
|
|
|
//压缩机控制GPIO初始化
|
|
GPIO_InitStruct.pin = COMPRESSOR_GPIO_PIN;
|
|
FL_GPIO_Init(COMPRESSOR_GPIO_PORT, &GPIO_InitStruct);
|
|
|
|
// 初始化风扇控制GPIO
|
|
GPIO_InitStruct.pin = FAN_1_GPIO_PIN;
|
|
FL_GPIO_Init(FAN_1_GPIO_PORT, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.pin = FAN_2_GPIO_PIN;
|
|
FL_GPIO_Init(FAN_2_GPIO_PORT, &GPIO_InitStruct);
|
|
|
|
GPIO_InitStruct.pin = FAN_3_GPIO_PIN;
|
|
FL_GPIO_Init(FAN_3_GPIO_PORT, &GPIO_InitStruct);
|
|
}
|
|
|
|
|
|
|
|
static void power_on_valve_shift(void)
|
|
{
|
|
// 初始上电阶段进行电磁阀切换
|
|
static uint16_t time_counter = 0;
|
|
|
|
time_counter++;
|
|
switch(on_valve_stage)
|
|
{
|
|
case ON_STAGE_1_3200_11:
|
|
// 初始上电阶段
|
|
VALVE_1_ON;
|
|
VALVE_2_ON;
|
|
if(time_counter == 160) // 3200/20 = 160
|
|
{
|
|
time_counter = 0;
|
|
on_valve_stage = ON_STAGE_2_1820_10;
|
|
}
|
|
break;
|
|
|
|
case ON_STAGE_2_1820_10:
|
|
VALVE_1_ON;
|
|
VALVE_2_OFF;
|
|
if(time_counter == 91) // 1820/20 = 91
|
|
{
|
|
time_counter = 0;
|
|
on_valve_stage = ON_STAGE_3_120_00;
|
|
}
|
|
break;
|
|
|
|
case ON_STAGE_3_120_00:
|
|
VALVE_1_OFF;
|
|
VALVE_2_OFF;
|
|
if(time_counter == 6) // 120/20 = 6
|
|
{
|
|
time_counter = 0;
|
|
on_valve_stage = ON_STAGE_4_2880_10;
|
|
}
|
|
break;
|
|
|
|
case ON_STAGE_4_2880_10:
|
|
VALVE_1_ON;
|
|
VALVE_2_OFF;
|
|
if(time_counter == 144) // 2880/20 = 144
|
|
{
|
|
time_counter = 0;
|
|
valve_phase = PHASE_2_NORMAL;
|
|
}
|
|
break;
|
|
|
|
}
|
|
}
|
|
|
|
|
|
static void normal_valve_shift(void)
|
|
{
|
|
static uint16_t time_counter = 0;
|
|
|
|
time_counter++;
|
|
switch(normal_valve_stage)
|
|
{
|
|
case NORMAL_STAGE_1_500_11:
|
|
VALVE_1_ON;
|
|
VALVE_2_ON;
|
|
if(time_counter == 25) // 500/20 = 25
|
|
{
|
|
time_counter = 0;
|
|
normal_valve_stage = NORMAL_STAGE_2_4820_01;
|
|
}
|
|
break;
|
|
|
|
case NORMAL_STAGE_2_4820_01:
|
|
VALVE_1_OFF;
|
|
VALVE_2_ON;
|
|
if(time_counter == 241) // 4820/20 = 241
|
|
{
|
|
time_counter = 0;
|
|
normal_valve_stage = NORMAL_STAGE_3_500_11;
|
|
}
|
|
break;
|
|
|
|
case NORMAL_STAGE_3_500_11:
|
|
VALVE_1_ON;
|
|
VALVE_2_ON;
|
|
if(time_counter == 25) // 500/20 = 25
|
|
{
|
|
time_counter = 0;
|
|
normal_valve_stage = NORMAL_STAGE_4_4820_10;
|
|
}
|
|
break;
|
|
|
|
case NORMAL_STAGE_4_4820_10:
|
|
VALVE_1_ON;
|
|
VALVE_2_OFF;
|
|
if(time_counter == 241) // 4820/20 = 241
|
|
{
|
|
time_counter = 0;
|
|
normal_valve_stage = NORMAL_STAGE_1_500_11;
|
|
}
|
|
break;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void compressor_valve_task(void)
|
|
{
|
|
|
|
// 电磁阀 压缩机 风扇控制任务 20ms执行一次
|
|
|
|
// 实时获取当前状态机状态 切换电磁阀
|
|
MsgQueueItem stm_item;
|
|
peek_queue_node_by_type(&global_queue, MSG_TYPE_OXG_STM, &stm_item);
|
|
static uint16_t valve_off_delay = 200;
|
|
static uint32_t fan_off_delay = 6000;
|
|
|
|
switch(stm_item.data.state_machine.oxg_stm)
|
|
{
|
|
case STM_INIT:
|
|
case STM_ERROR_NONE_STOP:
|
|
case STM_NOM:
|
|
case STM_CARLIB:
|
|
case STM_DEBUG:
|
|
|
|
// 非停机故障与正常状态都正常切换电磁阀
|
|
COMPRESSOR_ON;
|
|
FAN_ALL_ON;
|
|
if(valve_phase == PHASE_1_POWER_ON)
|
|
{
|
|
power_on_valve_shift();
|
|
}else{
|
|
|
|
normal_valve_shift();
|
|
}
|
|
|
|
break;
|
|
|
|
case STM_ERROR_SHOUNTDOWN:
|
|
COMPRESSOR_OFF;
|
|
if(valve_off_delay)
|
|
{
|
|
valve_off_delay--;
|
|
VALVE_1_ON;
|
|
VALVE_2_ON;
|
|
}else{
|
|
VALVE_1_OFF;
|
|
VALVE_2_OFF;
|
|
}
|
|
|
|
if(fan_off_delay)
|
|
{
|
|
fan_off_delay--;
|
|
FAN_ALL_ON;
|
|
}else{
|
|
FAN_ALL_OFF;
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
default:
|
|
break;
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|