diff --git a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c index 537152c..29899b5 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c @@ -480,12 +480,19 @@ void vd1_task_per_channel(Loop154_Unit *unit) unit->loop_dlt_ORG = ((uint32_t)unit->loop_Origin * g_loop_sens_list.sens[unit->loop_SensLevel].sens_in) >> 16; { + /* V4B V4.20 同步: 双向对称保护 — 负variation(铁块磁导率)也冻结基线 + * 原单边只挡 dev>+4×dlt, 负variation会把Origin污染抬高 → 离开时假进入 → 锁死不释放 + * 修复: ① 对称窗口 [-4×dlt, +4×dlt] ② 负偏差只冻结永不超时更新 */ int32_t dev = (int32_t)unit->loop_CAPVD - (int32_t)unit->loop_Origin; - if (dev < (int32_t)(unit->loop_dlt_ORG * 4)) { + int32_t freeze_band = (int32_t)(unit->loop_dlt_ORG * 4); + if (dev < freeze_band && dev > -freeze_band) { + /* 对称窗口内 → 正常基线跟踪 */ unit->loop_freeze_cnt = 0; + unit->loop_freeze_ref = 0; update_moving_average(&unit->loop_ORG_SUM, &unit->loop_ORG_CNT, &unit->loop_Origin, unit->loop_CAPVD, WINDOW_ORIGIN); - } else { + } else if (dev < 0) { + /* 正variation (疑似车) → 冻结, 保留超时兜底更新 */ if (unit->loop_freeze_cnt == 0) { unit->loop_freeze_ref = unit->loop_CAPVD; } else { @@ -509,6 +516,15 @@ void vd1_task_per_channel(Loop154_Unit *unit) unit->loop_ORG_CNT = 0; unit->loop_ORG_SUM = 0; } + } else { + /* 负variation (CAPVD高于Origin, 特殊铁块磁导率主导) → 只冻结, 永不更新 Origin */ + if (unit->loop_freeze_cnt == 0) { + unit->loop_freeze_ref = unit->loop_CAPVD; + } + unit->loop_freeze_cnt++; + if (unit->loop_freeze_cnt > FREEZE_TIMEOUT) unit->loop_freeze_cnt = FREEZE_TIMEOUT; + unit->loop_ORG_CNT = 0; + unit->loop_ORG_SUM = 0; } }