2021-04-24 07:19 PM
Hi, the timers of my STM32WB55x aren't working exactly as I anticipated.
Symptoms: By conventional wisdom that I accumulated when using other MCUs under different brands, if the CNT is modified to a different value, the counter should keep counting from that new, modified value.
Except this is not the case. If I modify the CNT register to pretty much any value, the CNT value in Keil's watch window will immediately be reduced to a really tiny, close-to-zero value and an interrupt will immediately be triggered.
But, if I modify the ARR register, the counter seem to be able to count a length that is slightly shorter than desired one, instead of a period that is precisely as expected, I came to this conclusion by measuring it with a stopwatch. It's not perfect but at least it works... somehow.
In short, if I want to modify the timer cycle on the fly, I need to modify the ARR register instead of the CNT register.
My questions are :
Please help and thanks!
Stephan
2021-04-26 08:05 AM
Hello
In CR1 register, keep ARPE bit disabled to change the ARR "on the fly"
if ARPE== 1, ARR is preloaded and the new value will set in the next counter cycle
2021-05-06 08:37 PM
Got it! I will try it out and provide the feedback.
Sorry for the late reply and thank you for your kind help.
2021-05-07 11:23 PM
Hello, I'm currently doing a simulation on the problematic code in Keil, it appears that ARPE bit is already disabled.
Since Keil is unreliable, I'll find another way to verify it.
Will update in the future.
2021-05-07 11:35 PM
Hi, with the ARPE set or not, the problem remains.
I am now curious: if you want to change the countdown or count-up on-the-fly, should you modify the value of ARR or CNT directly?