From: kyz Date: Wed, 17 Jun 2026 07:20:21 +0000 (+0800) Subject: use uart2 RXD as bypass signal X-Git-Url: http://kyz.pub/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fv4.4_add_bypass_input_signal;p=yn%2Fweldingcontroller.git use uart2 RXD as bypass signal --- diff --git a/user/user.h b/user/user.h index 08ecfde..13fa87a 100644 --- a/user/user.h +++ b/user/user.h @@ -27,7 +27,7 @@ //#include "fmc.h" //-------------------- #define APP_VER_MAJOR 4 -#define APP_VER_MINOR 4 +#define APP_VER_MINOR 45 #define HW_V2 2 #define HW_V3 3 diff --git a/user/user_app.c b/user/user_app.c index 5b3cef9..c0be2c9 100644 --- a/user/user_app.c +++ b/user/user_app.c @@ -20,7 +20,7 @@ const osThreadAttr_t adcTask_attributes = { }; const osThreadAttr_t ctrlTask_attributes = { .name = "ctrlTask", - .stack_size = 1024, + .stack_size = (1024+256), .priority = (osPriority_t) osPriorityNormal, }; const osThreadAttr_t flowmeterTask_attributes = { diff --git a/user/user_valve_ctrl.c b/user/user_valve_ctrl.c index d5e4efa..a0009f6 100644 --- a/user/user_valve_ctrl.c +++ b/user/user_valve_ctrl.c @@ -404,6 +404,9 @@ void user_valve_set_current( float current ) extern void welding_data_store( uint16_t index ); //记录焊接数据 +static uint32_t force_bypass_flag=0; +static uint32_t force_bypass_time=0; + void user_valve_ctrl_task( void* unused ) { uint32_t last_tick; @@ -463,6 +466,18 @@ void user_valve_ctrl_task( void* unused ) g_dev.welding_start = 0; g_dev.welding_time = 0; + +{ + //这里增加一个gpio初始化,将调试用的uart2 RX初始化成输入模式,后面可以检查他的电平变化 + //这里增加变量,将task的栈增加256 + GPIO_InitTypeDef GPIO_InitStruct = {0}; + __HAL_RCC_GPIOA_CLK_ENABLE(); + GPIO_InitStruct.Pin = GPIO_PIN_3; // PA3 - UART2_RX + GPIO_InitStruct.Mode = GPIO_MODE_INPUT; // 输入模式 + GPIO_InitStruct.Pull = GPIO_NOPULL; // 无上下拉 + HAL_GPIO_Init(GPIOA, &GPIO_InitStruct); +} + while(1){ //200毫秒扫描一次, 考虑pid的流量计反馈,让扫描周期大于流量计的采集周期, vTaskDelayUntil(&last_tick, 100 ); @@ -592,7 +607,27 @@ void user_valve_ctrl_task( void* unused ) } if( g_dev.has_bypass){ - if( g_dev.cfg.bypass || tem_err_state ){ + + if( g_dev.cfg.bypass ){ + //当前正常直通模式,不检测外部信号 + force_bypass_flag = 0; + force_bypass_time = 0; + }else if( HAL_GPIO_ReadPin(GPIOA, GPIO_PIN_3) == GPIO_PIN_RESET ){ + //这里检查到RX引脚是低电平信号触发,强制启动直通阀 + force_bypass_flag = 1; + force_bypass_time = 0; + }else{ + //信号未触发 + if( force_bypass_flag == 1 ){ + //当前为测试信号释放,计时到10秒后取消直通阀 + force_bypass_time += 100; //100ms + if( force_bypass_time > 10*1000){//10s timeout + force_bypass_flag = 0; + force_bypass_time = 0; + } + } + } + if( force_bypass_flag || g_dev.cfg.bypass || tem_err_state ){ //屏上点击旁路或温度故障,开启旁路 valve_bypass( 1 ); //旁路电磁阀开启 g_dev.valve_curr_out = 0; //比例电磁阀关闭