cancel
Showing results for 
Search instead for 
Did you mean: 

STM32F103RF: Timer generates ''Update Interupt'' too early

denisb-popov
Associate II
Posted on February 01, 2016 at 17:26

IAR Embedded Workbench

Consider timer TIM7 initialized and started in some IRQ handler in the next sequence:

void SOME_IRQ_Handler(void)

{

TIM7->PSC = some_value;

TIM7->ARR = some_value;

TIM7->EGR |= TIM_EGR_UG;

TIM7->SR = 0;

TIM7->DIER = TIM_DIER_UIE;

TIM7->CR1 |= TIM_CR1_CEN;

}

And timer's IRQ is:

void TIM_IRQ_Handler(void)

{

// toggle gpio port on each irq event (PC6 in my case)

}

Consider two cases:

1. some_value = 0x100;

2. some_value = 0xFFFF;

Measure and compare the first period (exactly after enabling the timer) to the second with the scope in both cases.

My questions:

1. Is duration of the 1 period in both cases are the same? In my case the answer is YES!

2. Is duration of the first period is equal to the second, third ..... in both cases respectively? In my case the answer is NO!

In my case the first period is less then should be (in both cases) and has a fixed value

3. Have I missed something? Did anyone had to deal with the same or similar problem?

4. If it's still a problem, how can I solve it?

PS:

- SOME_IRQ_Handler has a lower interrupt priority

- Problem is invariant to the timer used
1 REPLY 1
Posted on February 01, 2016 at 17:46

Probably want to preload the prescaler, and ARR

/* Set the ARR Preload Bit */ TIMx->CR1 |= TIM_CR1_ARPE; I've seen others do this

TIM2->CR1 |= TIM_CR1_ARPE | TIM_CR1_CEN; 
// autoreload on, counter enabled

TIM2->EGR = 1; 
// trigger update event to reload timer registers

Just be aware that the first Update occurs immediately, not after a full period of the timer. From: p.denis.001 Posted: Monday, February 01, 2016 5:26 PM Subject: STM32F103RF: Timer generates ''Update Interupt'' too early

IAR Embedded Workbench

Consider timer TIM7 initialized and started in some IRQ handler in the next sequence: void SOME_IRQ_Handler(void) { TIM7->PSC = some_value; TIM7->ARR = some_value; TIM7->EGR |= TIM_EGR_UG; TIM7->SR = 0; TIM7->DIER = TIM_DIER_UIE; TIM7->CR1 |= TIM_CR1_CEN; } And timer's IRQ is: void TIM_IRQ_Handler(void) { // toggle gpio port on each irq event (PC6 in my case) } Consider two cases: 1. some_value = 0x100; 2. some_value = 0xFFFF; Measure and compare the first period (exactly after enabling the timer) to the second with the scope in both cases. My questions: 1. Is duration of the 1 period in both cases are the same? In my case the answer is YES! 2. Is duration of the first period is equal to the second, third ..... in both cases respectively? In my case the answer is NO! In my case the first period is less then should be (in both cases) and has a fixed value 3. Have I missed something? Did anyone had to deal with the same or similar problem? 4. If it's still a problem, how can I solve it? PS: - SOME_IRQ_Handler has a lower interrupt priority - Problem is invariant to the timer used
Tips, Buy me a coffee, or three.. PayPal Venmo
Up vote any posts that you find helpful, it shows what's working..