cancel
Showing results for 
Search instead for 
Did you mean: 

Simple Timer TIM7 ''update event''

gene
Associate II
Posted on June 12, 2014 at 02:03

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
5 REPLIES 5
Posted on June 12, 2014 at 02:44

Because the update is basically the wrap to zero event.

Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..
Posted on June 12, 2014 at 09:30

> 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''?

JW

gene
Associate II
Posted on June 12, 2014 at 14:47

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.

Posted on June 12, 2014 at 15:13

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?

JW

gene
Associate II
Posted on June 12, 2014 at 17:17

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