diff --git a/utilities/at32f421_freertos_demo/src/TaskLoop.c b/utilities/at32f421_freertos_demo/src/TaskLoop.c index f829815..b5d3ecb 100644 --- a/utilities/at32f421_freertos_demo/src/TaskLoop.c +++ b/utilities/at32f421_freertos_demo/src/TaskLoop.c @@ -596,7 +596,12 @@ void vd1_task(void) if (loop1_Origin == 0) return; /*--- 1. IIR 一阶低通滤波 ---*/ - loop1_CAPVD = get_flt_value(loop1_Value, loop1_CAPVD); + /* 重连后 CAPVD=0:跳过 IIR,直接锁定首个有效值 */ + if (loop1_CAPVD == 0) { + loop1_CAPVD = loop1_Value; + } else { + loop1_CAPVD = get_flt_value(loop1_Value, loop1_CAPVD); + } /*--- 2. 稳定期:只跟踪基线,不检测车辆 ---*/ if (!g_loop_stable) { @@ -692,6 +697,7 @@ void loop_task_function(void *pvParameters) if (!loop1_LOOP_OK0) { loop1_LOOP_OK0 = 1; g_disconnect_active = 0; // 重连,清除断开标记 + loop1_CAPVD = 0; // 强制 IIR 从首个有效值重新收敛 } if (loop1_CAP_OK) { @@ -710,7 +716,7 @@ void loop_task_function(void *pvParameters) } } else { /*--- 线圈断开 ---*/ - loop1_VD_FLAG = 0; + /* 注意: 不清除 loop1_VD_FLAG,保留断开前的检测状态 */ RLY1_OFF; RLY2_OFF;