current_v/Src/compressor_valve_switch.c

306 lines
7.5 KiB
C
Raw Permalink Normal View History

2025-12-31 08:21:43 +08:00
/* 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 <EFBFBD><EFBFBD>ʼ<EFBFBD> 2025.12.10
- <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>½<EFBFBD><EFBFBD><EFBFBD>һ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ƽ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ij<EFBFBD><EFBFBD><EFBFBD>ִ<EFBFBD>в<EFBFBD><EFBFBD><EFBFBD>
******************************************************************************
* @attention
*
* <h2><center>&copy; 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"
// <20>տ<EFBFBD>ʼ<EFBFBD>ϵ<EFBFBD>ʱ<EFBFBD>ĵ<EFBFBD><C4B5>ŷ<EFBFBD><C5B7>л<EFBFBD>״̬
typedef enum
{
ON_STAGE_1_3200_11,
ON_STAGE_2_1820_10,
ON_STAGE_3_120_00,
ON_STAGE_4_2880_10, // <20>Ľ׶κ<D7B6><CEBA>л<EFBFBD><D0BB><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ģʽ
} PowerOnValveStage;
typedef enum
{
NORMAL_STAGE_1_500_11,
NORMAL_STAGE_2_4820_01,
NORMAL_STAGE_3_500_11,
NORMAL_STAGE_4_4820_10, // <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ĸ<EFBFBD><C4B8>׶<EFBFBD><D7B6><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD>
} 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)
{
/* <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͨGPIO<49><4F><EFBFBD><EFBFBD>ģʽ */
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;
// <20><><EFBFBD>ŷ<EFBFBD><C5B7><EFBFBD><EFBFBD><EFBFBD>GPIO<49><4F>ʼ<EFBFBD><CABC>
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);
//ѹ<><D1B9><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>GPIO<49><4F>ʼ<EFBFBD><CABC>
GPIO_InitStruct.pin = COMPRESSOR_GPIO_PIN;
FL_GPIO_Init(COMPRESSOR_GPIO_PORT, &GPIO_InitStruct);
// <20><>ʼ<EFBFBD><CABC><EFBFBD><EFBFBD><EFBFBD>ȿ<EFBFBD><C8BF><EFBFBD>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)
{
// <20><>ʼ<EFBFBD>ϵ<EFBFBD><CFB5>׶ν<D7B6><CEBD>е<EFBFBD><D0B5>ŷ<EFBFBD><C5B7>л<EFBFBD>
static uint16_t time_counter = 0;
time_counter++;
switch(on_valve_stage)
{
case ON_STAGE_1_3200_11:
// <20><>ʼ<EFBFBD>ϵ<EFBFBD><CFB5>׶<EFBFBD>
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)
{
// <20><><EFBFBD>ŷ<EFBFBD> ѹ<><D1B9><EFBFBD><EFBFBD> <20><><EFBFBD>ȿ<EFBFBD><C8BF><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> 20msִ<73><D6B4>һ<EFBFBD><D2BB>
// ʵʱ<CAB5><CAB1>ȡ<EFBFBD><C8A1>ǰ״̬<D7B4><CCAC>״̬ <20>л<EFBFBD><D0BB><EFBFBD><EFBFBD>ŷ<EFBFBD>
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:
// <20><>ͣ<EFBFBD><CDA3><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>״̬<D7B4><CCAC><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>л<EFBFBD><D0BB><EFBFBD><EFBFBD>ŷ<EFBFBD>
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;
}
}