Skip to main content
StephanMair
Associate III
Apr 25, 2021 2:19 AM UTC
Question

Timer question, STM32WB55x series, modifying CNT register causes unexpected interrupt firing

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 :

  1. Have I forgot to set/reset certain bit(s) which caused this? (the immediate firing)
  2. How should I solve this issue if I want to modify the timer cycle dynamically?

Please help and thanks!

Stephan

This topic has been closed for replies.

4 replies

Vangelis Fortounas
Associate II
Apr 26, 2021 3:05 PM UTC

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

StephanMair
Associate III
May 7, 2021 3:37 AM UTC

Got it! I will try it out and provide the feedback.

Sorry for the late reply and thank you for your kind help.