2014-06-11 05:03 PM
Why do I get an immediate update event when I configure TIM7 like this:
TIM7->CR1 = 0;
TIM7->PSC = 7199;
TIM7->ARR = 2000;
TIM7->DIER = 0;
TIM7->CNT = 0;
TIM7->CR1 = TIM_CR1_CEN;
while ((TIM7->SR & TIM_SR_UIF) != TIM_SR_UIF)
{
if (TIM7->CNT > 1)
{
break;
}
}
TIM7->CR1 = 0;
TIM7->SR = 0;
I see the update event as soon as it enters the loop. I would think the count would reach 2000 before the UIF bit in SR would become set. Why do I get an almost immediate update event?
Thanks,
Gene
2014-06-11 05:44 PM
Because the update is basically the wrap to zero event.
2014-06-12 12:30 AM
> I see the update event as soon as it enters the loop.
How do you know that? Do you single-step your program? If so, are you aware of the fact that the timers may be running while the program is ''stopped''? JW2014-06-12 05:47 AM
So are you saying it will only set the update event bit after counting from 0 to 2000 and then returning (wrapping back) to 0? That doesn't seem to be what I am seeing. It seems to set the update event bit without counting at all after configuring the timer and regardless of whether the CNT is set to zero or not.
In answer to the other post: I am not single stepping. However, I do have the register set that stops the timer if I did.2014-06-12 06:13 AM
You still did not explain how do you know it sets the update bit immediately.
You might want to prepare and post a minimal but complete program demonstrating the problem, with explaining what do you see and how is it different from your expectations. You might also want to clear the status register before you enable the timer. Which STM32 variant do you use? JW2014-06-12 08:17 AM
Well, I looked closer at what I was doing and see that indeed the update event bit (UIF) doesn't come on immediately like I thought it was. It only comes on after the timer reaches the ARR value like the manual describes. Thanks for your comments.
Gene