diff --git a/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h b/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h index a779b36..4e49385 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h +++ b/vd960Loop/utilities/at32f421_freertos_demo/inc/TaskLoop.h @@ -190,8 +190,8 @@ typedef struct { * 全局状态 *===========================================================================*/ typedef struct { - uint32_t report_counter; // 上报间隔计数器 (50ms tick, 自由运行不复位) - uint32_t last_report_tick; // 上次上报时刻, 用于增量判断 + uint32_t report_counter; // 上报间隔计数器 (50ms tick) + uint32_t misc_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 603b6b8..c3d5f59 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/TaskLoop.c @@ -257,6 +257,7 @@ void TMR15_GLOBAL_IRQHandler(void) /*--- 上报计数器 (50ms tick) ---*/ g_loop_states.report_counter++; + g_loop_states.misc_counter++; for (i = 0; i < LOOP_CAPTURE_MAX; i++) { Loop154_Unit *unit = &g_loop_states.loop_unit[i]; @@ -313,7 +314,7 @@ void TMR15_GLOBAL_IRQHandler(void) unit->loop_stable = 0; unit->loop_ORG_CNT = 0; unit->loop_ORG_SUM = 0; - unit->last_exit_tick = g_loop_states.report_counter; + unit->last_exit_tick = g_loop_states.misc_counter; #if USE_FLATNESS_EXIT unit->exit_state = 0; unit->max_slope = 0; @@ -523,11 +524,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; + unit->misc_value = g_loop_states.misc_counter - unit->last_exit_tick; } else { unit->misc_value = 0; // 首次检测, 车间距为0 } - unit->passtime_start = g_loop_states.report_counter; // 50ms tick + unit->passtime_start = g_loop_states.misc_counter; // 50ms tick if (unit->hold_time > 0) { unit->loop_VD_HOLD = 1; } @@ -609,8 +610,8 @@ void vd1_task_per_channel(Loop154_Unit *unit) unit->exit_state = 0; /* 主动上报: 计算通过时间 = 当前-进场 (50ms单位) */ - unit->misc_value = g_loop_states.report_counter - unit->passtime_start; - unit->last_exit_tick = g_loop_states.report_counter; + unit->misc_value = g_loop_states.misc_counter - unit->passtime_start; + unit->last_exit_tick = g_loop_states.misc_counter; unit->relay_count++; // 离开时继电器翻转 } } else { @@ -641,8 +642,8 @@ void vd1_task_per_channel(Loop154_Unit *unit) unit->loop_cnt_release = 0; /* 主动上报: 通过时间 + 继电器 */ - unit->misc_value = g_loop_states.report_counter - unit->passtime_start; - unit->last_exit_tick = g_loop_states.report_counter; + unit->misc_value = g_loop_states.misc_counter - unit->passtime_start; + unit->last_exit_tick = g_loop_states.misc_counter; unit->relay_count++; } } else { diff --git a/vd960Loop/utilities/at32f421_freertos_demo/src/main.c b/vd960Loop/utilities/at32f421_freertos_demo/src/main.c index 44ecbed..4a3dcfa 100644 --- a/vd960Loop/utilities/at32f421_freertos_demo/src/main.c +++ b/vd960Loop/utilities/at32f421_freertos_demo/src/main.c @@ -429,7 +429,7 @@ void uart_report_packet_loop_acs(uint8_t flag) } else { _interval = REPORT_IDLE_TICKS; // 12×50ms = 600ms } - if ((g_loop_states.report_counter - g_loop_states.last_report_tick) < _interval) return; + if (g_loop_states.report_counter < _interval) return; /*--- 3. 确定本轮杂项类型 ---*/ if (_flag_event) { @@ -526,7 +526,7 @@ void uart_report_packet_loop_acs(uint8_t flag) g_pkg_uart_report.pkg[i++] = _sum & 0xFF; usart1_sendstring(g_pkg_uart_report.pkg, i); - g_loop_states.last_report_tick = g_loop_states.report_counter; + g_loop_states.report_counter = 0; } @@ -1062,7 +1062,7 @@ void TMR6_GLOBAL_IRQHandler(void) } } - g_loop_states.last_report_tick = g_loop_states.report_counter; + g_loop_states.report_counter = 0; }