cancel
Showing results for 
Search instead for 
Did you mean: 

Need more understanding about the Timer enabling fn I am changing CNT register of the Timer in order to get a changed time period on the go (for down counting mode), but doing so correctly is getting delayed by one period.

Akshat1
Associate II

So I am using STM32H725 on which I have Timer 2 (general purpose timer) which is in down counting, one pulse mode with an interrupt which is triggered at underflow.

Once the interrupt is fired, the TIMx_CNT register value is changed and then __HAL_TIM_ENABLE(&htim2) to run the timer with updated time period but what I am observing on the oscilloscope is that this updated time period not at the next timer period but the one next to it.

What would cause such behaviour?

Also, note that the reference manual says that CNT register is not preloaded (see image) which if it was could have explained this behaviour.

0693W00000LyvUMQAZ.pngAnother thing that I did was that I tried enabling the timer and then changing the TIMx_CNT value and then it worked as expected but this has me confused about the working of the timer.

5 REPLIES 5

TIMx_CNT does not determine the timer period. TIMx_ARR does.

JW

Correct, but for down counting mode, it is the TIMx_CNT which would determine the period. At underflow, by default, the TIMx_CNT is loaded with TIMx_ARR value if I am not mistaken, so if I change the TIMx_CNT value as I require it to be, it should give me a changed time period.

TDK
Guru

> by default, the TIMx_CNT is loaded with TIMx_ARR value if I am not mistaken, so if I change the TIMx_CNT value as I require it to be, it should give me a changed time period.

If the ARR value gets loaded into CNT, how would changing CNT change the frequency? It'll affect it for one cycle, but that's it. Maybe that's what you want? As JW says, ARR determines frequency, not CNT, even in downcounting mode.

If you feel a post has answered your question, please click "Accept as Solution".

Correct, but what I am doing is that I change the TIMx_CNT value after every period depending on my requirement

Write a *minimal* but complete compilable program exhibiting the problem, and post.

JW