diff --git a/vd960Loop/docs/devlog.md b/vd960Loop/docs/devlog.md index 03bba79..918ec44 100644 --- a/vd960Loop/docs/devlog.md +++ b/vd960Loop/docs/devlog.md @@ -145,10 +145,34 @@ misc_value = (report_counter - passtime_start) / 2; --- +## 2026-07-03 — 时间量上报单位改为 50ms + +### 背景 + +上一步 `misc_value` 以 10ms 为单位(内部 5ms tick `/2`),但协议期望 50ms。统一为 50ms 后与 `Hold_CNT/OUTCNT/INCNT` 一致。 + +### 方案 + +1. **`report_counter` 移入 50ms tick 块**:原来在 5ms ISR 外层 `++`,现移到 `if (TM1cnt >= 10)` 内部,每次加 1 = 50ms +2. **去掉 `/2`**:`misc_value = report_counter - timestamp`(直接减,无除法) +3. **上报间隔宏同步**:`REPORT_IDLE_TICKS 120→12`,`REPORT_EVENT_TICKS 30→3` + +### 影响范围 + +| 文件 | 变更 | +|------|------| +| `TaskLoop.c` ISR | `report_counter++` 从 5ms 外层移入 50ms 块 | +| `TaskLoop.c` 进场/离场 | 去掉 `/2`,注释 10ms→50ms | +| `TaskLoop.h` | `REPORT_*_TICKS` /10,注释 5ms→50ms | +| `main.c` | 间隔注释更新 | + +--- + ## 修订记录 | 版本 | 时间 | 说明 | |------|------|------| +| V2.7 | 2026-07-03 | report_counter 改 50ms tick,时间量单位 10ms→50ms | | V2.6 | 2026-07-03 | misc_value 时间量单位 5ms→10ms | | V2.5 | 2026-06-29 | 稳定期窗口 100 快速收敛 | | V2.4 | 2026-06-29 | 去掉快速 IIR,ALFA_CAP1=79 @10ms | diff --git a/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h b/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h index da4119d..0c086b3 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h +++ b/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h @@ -78,11 +78,11 @@ #define MISC_TYPE_RELAY 3 // 继电器输出次数 #define MISC_TYPE_COUNT 4 // 总类型数 -/*=========================================================================== - * 主动上报 — 间隔 (5ms tick, misc_value 上报时 /2 转 10ms) +/* + * 主动上报 — 间隔 (50ms tick) *===========================================================================*/ -#define REPORT_IDLE_TICKS 120 // 空闲稳定: 120×5ms = 600ms -#define REPORT_EVENT_TICKS 30 // 事件/变化: 30×5ms = 150ms +#define REPORT_IDLE_TICKS 12 // 空闲稳定: 12×50ms = 600ms +#define REPORT_EVENT_TICKS 3 // 事件/变化: 3×50ms = 150ms /*=========================================================================== * 灵敏度表(4级: 0=低, 3=高) @@ -181,8 +181,8 @@ typedef struct { /*--- 主动上报杂项计数 ---*/ uint32_t flow_count; // 车流量累计 uint32_t relay_count; // 继电器动作次数 - uint32_t passtime_start; // 进场 时间戳(5ms tick, 上报/2→10ms) - uint32_t last_exit_tick; // 上次离场 时间戳(5ms tick, 上报/2→10ms) + uint32_t passtime_start; // 进场 时间戳(50ms tick) + uint32_t last_exit_tick; // 上次离场 时间戳(50ms tick) uint32_t misc_value; // 当前要上报的杂项值 } Loop154_Unit; @@ -190,7 +190,7 @@ typedef struct { * 全局状态 *===========================================================================*/ typedef struct { - uint32_t report_counter; // 上报间隔计数器 (5ms tick) + uint32_t report_counter; // 上报间隔计数器 (50ms tick) uint8_t report_misc_round; // 空闲轮转: 0=MISC_TYPE_TIME, 1=CUT, 2=FLOW, 3=RELAY Loop154_Unit loop_unit[LOOP_CAPTURE_MAX]; } Loop154_States; diff --git a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c index dce408b..603b6b8 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c @@ -250,14 +250,14 @@ void TMR15_GLOBAL_IRQHandler(void) if (tmr_interrupt_flag_get(TMR15, TMR_OVF_FLAG) != RESET) { - /*--- 上报计数器 ---*/ - g_loop_states.report_counter++; - /*--- 50ms tick 分频 ---*/ TM1cnt++; if (TM1cnt >= 10) { TM1cnt = 0; + /*--- 上报计数器 (50ms tick) ---*/ + g_loop_states.report_counter++; + for (i = 0; i < LOOP_CAPTURE_MAX; i++) { Loop154_Unit *unit = &g_loop_states.loop_unit[i]; @@ -523,11 +523,11 @@ void vd1_task_per_channel(Loop154_Unit *unit) unit->flow_count++; unit->relay_count++; if (unit->last_exit_tick > 0) { - unit->misc_value = (g_loop_states.report_counter - unit->last_exit_tick) / 2; + unit->misc_value = g_loop_states.report_counter - unit->last_exit_tick; } else { unit->misc_value = 0; // 首次检测, 车间距为0 } - unit->passtime_start = g_loop_states.report_counter; // 5ms tick + unit->passtime_start = g_loop_states.report_counter; // 50ms tick if (unit->hold_time > 0) { unit->loop_VD_HOLD = 1; } @@ -608,8 +608,8 @@ void vd1_task_per_channel(Loop154_Unit *unit) unit->flat_ok_cnt = 0; unit->exit_state = 0; - /* 主动上报: 计算通过时间 = (当前-进场)/2 (10ms单位) */ - unit->misc_value = (g_loop_states.report_counter - unit->passtime_start) / 2; + /* 主动上报: 计算通过时间 = 当前-进场 (50ms单位) */ + unit->misc_value = g_loop_states.report_counter - unit->passtime_start; unit->last_exit_tick = g_loop_states.report_counter; unit->relay_count++; // 离开时继电器翻转 } @@ -641,7 +641,7 @@ void vd1_task_per_channel(Loop154_Unit *unit) unit->loop_cnt_release = 0; /* 主动上报: 通过时间 + 继电器 */ - unit->misc_value = (g_loop_states.report_counter - unit->passtime_start) / 2; + unit->misc_value = g_loop_states.report_counter - unit->passtime_start; unit->last_exit_tick = g_loop_states.report_counter; unit->relay_count++; } diff --git a/vd960Loop/utilities/at32f421_freertos_demo/src/main.c b/vd960Loop/utilities/at32f421_freertos_demo/src/main.c index e0dbc86..4a3dcfa 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/main.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/main.c @@ -425,9 +425,9 @@ void uart_report_packet_loop_acs(uint8_t flag) /*--- 2. 确定上报间隔 ---*/ if (_flag_event) { - _interval = REPORT_EVENT_TICKS; // 150ms + _interval = REPORT_EVENT_TICKS; // 3×50ms = 150ms } else { - _interval = REPORT_IDLE_TICKS; // 600ms + _interval = REPORT_IDLE_TICKS; // 12×50ms = 600ms } if (g_loop_states.report_counter < _interval) return;