embedded
runtime_error
ai_generated
true
定时器:输出比较事件丢失,计数器值 0x1234 超过比较值
Timer: output compare event missed, counter value 0x1234 exceeds compare value
ID: embedded/timer-output-compare-missed-event
82%修复率
83%置信度
1证据数
2024-06-10首次发现
版本兼容性
| 版本 | 状态 | 引入 | 弃用 | 备注 |
|---|---|---|---|---|
| STM32Cube_FW_L4 V1.18.0 | active | — | — | — |
| FreeRTOS V10.5.0 | active | — | — | — |
根因分析
输出比较事件因中断延迟或软件延迟导致比较寄存器未及时更新而丢失。
English
Output compare event missed because interrupt latency or software delay prevented timely update of compare register.
官方文档
https://www.st.com/resource/en/reference_manual/dm00083598.pdf解决方案
-
使用单脉冲模式(OPM)在比较匹配后自动停止定时器,避免重新使能问题:`TIMx->CR1 |= TIM_CR1_OPM;`
-
缩短中断服务程序,将重处理移至任务上下文,例如使用信号量通知任务。
-
使能影子寄存器预加载比较值:`TIMx->CR2 |= TIM_CR2_CCDS;` 在下一次更新事件时更新。
无效尝试
常见但无效的做法:
-
70% 失败
Increasing timer prescaler reduces resolution but does not fix missed event due to long ISR.
-
60% 失败
Adding more priority levels to NVIC does not address software delay in ISR.