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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-25 3:34 AM
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.
Another 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.
- Labels:
-
STM32H7 series
-
TIM
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-25 4:04 AM
TIMx_CNT does not determine the timer period. TIMx_ARR does.
JW
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-25 4:23 AM
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-25 7:00 AM
> 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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-25 10:24 PM
Correct, but what I am doing is that I change the TIMx_CNT value after every period depending on my requirement
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content
‎2022-04-25 11:52 PM
Write a *minimal* but complete compilable program exhibiting the problem, and post.
JW
