From 4c4000eb7d86706ffd51f8aae1e23e1d83ff5feb Mon Sep 17 00:00:00 2001 From: wangfq Date: Wed, 2 Sep 2026 14:52:09 +0800 Subject: [PATCH] =?UTF-8?q?fix(vd960Loop):=20=E5=9F=BA=E7=BA=BF=E8=B7=9F?= =?UTF-8?q?=E8=B8=AA=E5=8F=8C=E5=90=91=E5=AF=B9=E7=A7=B0=E4=BF=9D=E6=8A=A4?= =?UTF-8?q?=E5=90=8C=E6=AD=A5V4B=20V4.20=20=E2=80=94=20=E8=B4=9Fvariation?= =?UTF-8?q?=E9=93=81=E5=9D=97=E9=98=B2Origin=E6=B1=A1=E6=9F=93=E9=94=81?= =?UTF-8?q?=E6=AD=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 负偏差(dev>0,CAPVD>Origin)只冻结永不超时更新Origin, 对称窗口[-4×dlt,+4×dlt] 四路unit结构同步, 与DLD154V4B V4.20修复一致 --- .../at32f421_freertos_demo/src/TaskLoop.c | 20 +++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) 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; } }