feat(V4B): V4.23 — 红灯呼吸对齐vd960Loop(≈2.6s) + 上电自检基准判稳

现场测试 DLD154V4 反馈两问题修复:

1. 红灯呼吸太快 → 借鉴 vd960Loop 效果 (main.c poll_red_pwm)
   - 参数按 665/6800 缩放取整: 大步 100→39(≈5.9%), 近顶 20→10(≈1.5%),
     分界 585(88%), 峰值保持 660×3 步
   - 周期 ≈1.6s → ≈2.6s (仿真 42 步×60ms=2520ms)

2. 绿灯上电自检闪到"稳定基准值"才停 (TaskLoop.c 稳定期判稳)
   - 根因: 固定 128 样本即判稳, 与基准是否稳定无关; static 计数不清零,
     二次稳定期(安全复位)1 样本瞬间判稳
   - 修复: 全局 g_stable_cnt/g_settle_cnt, 每窗(100样本≈1s)Origin 均值
     漂移 ≤0.1% → settle++, 连续 2 窗 + 最少 128 样本判稳; 硬兜底 500
     样本(5s); 计数判稳退出/INIT_VD 清零

验证: tests/test_power_on_stable.c (200/300/500/200 样本 PASS),
      tests/test_red_breath.c (周期 2520ms/峰值保持/写值≤ARR PASS),
      gcc -fsyntax-only 两文件 0 error (借 vd960Loop AT32F421 库头)
文档: devlog 置顶 + 修订表回填 V2.12~V2.20 + V2.21; product-manual §5.1/
      核心特性; technical-spec V2.2 (§5.2 参数表/§7 判稳语义/§15 修订记录)

待现场验证: 呼吸观感、绿灯自检时长 (无车 2~3s / 首窗尖峰 3s / 5s 兜底)
This commit is contained in:
wangfq
2026-09-02 16:26:03 +08:00
parent 47898fd16e
commit cd0fd90770
8 changed files with 405 additions and 51 deletions
+37 -29
View File
@@ -155,45 +155,53 @@ void Timr6_Init(void)
tmr_counter_enable(TMR14, TRUE);
}
/*===========================================================================
* 红灯呼吸 (PB1 / TMR14 PWM) — V4.23: 呼吸节奏对齐 vd960Loop (LED_PWR)
*
* vd960Loop 参考 (周期≈2.6s, 60ms/步): 满量程 6800
* 升: <6000 大步 +400(≈5.9%), ≥6000 小步 +100(≈1.5%)
* 峰值保持 3 步后回落; 降: -400(≈5.9%)
* V4B PWM 满量程 = TMR14 ARR 665, 参数按 665/6800 ≈ 0.0978 缩放取整:
* 大歩 39(≈5.9%) / 小步 10(≈1.5%) / 分界 585(≈88%) / 峰值保持 660(≈99%)
* 全周期 ≈ 2.6s, 与 vd960Loop 观感一致
*===========================================================================*/
#define RED_BREATH_ARR 665 /* 必须与 tmr_base_init(TMR14,665,...) 一致 */
#define RED_STEP_BIG 39 /* 低段升/全程降步长 ≈ 400×665/6800 */
#define RED_STEP_SMALL 10 /* 近顶小步 ≈ 100×665/6800 */
#define RED_SPLIT 585 /* 大步/小步分界 ≈ 6000×665/6800 (88%) */
#define RED_HOLD_LEVEL 660 /* 峰值保持占空比 (≈99%) */
#define RED_HOLD_TICKS 3 /* 峰值保持 3 步 × 60ms = 180ms */
uint8_t g_cnt_pwm_red_low_timeout = 0;
void poll_red_pwm(void)
{
g_pulse_counter++;
if(g_pulse_counter >= 12){
if (g_pulse_counter >= 12) { /* 12 × 5ms = 60ms/步 (同 vd960Loop) */
g_pulse_counter = 0;
if(g_flag_pulse){
if(pulse < 500){
pulse += 100;
}
else{
pulse += 20;
}
if(pulse >= 670)
{
if(g_cnt_pwm_red_low_timeout < 3){
pulse = 665;
g_cnt_pwm_red_low_timeout++;
}
else{
if (g_flag_pulse) {
/* 渐亮: 低段大步, 近顶小步 */
if (pulse < RED_SPLIT)
pulse += RED_STEP_BIG;
else
pulse += RED_STEP_SMALL;
/* 到最亮: 保持 RED_HOLD_TICKS 步再回落 */
if (pulse >= RED_BREATH_ARR) {
g_cnt_pwm_red_low_timeout++;
if (g_cnt_pwm_red_low_timeout >= RED_HOLD_TICKS) {
g_flag_pulse = 0;
g_cnt_pwm_red_low_timeout = 0;
pulse = 660;
}
pulse = RED_HOLD_LEVEL;
}
}
else{
if(pulse <= 600)
{
pulse -= 100;
}
else{
pulse -= 20;
}
if(pulse == 0){
} else {
/* 渐暗 */
if (pulse <= RED_STEP_BIG) {
pulse = 0;
g_flag_pulse = 1;
} else {
pulse -= RED_STEP_BIG;
}
}
tmr_channel_value_set(TMR14, TMR_SELECT_CHANNEL_1, pulse);