cancel
Showing results for 
Search instead for 
Did you mean: 

STM32H7 timer interrupt slightly too fast

OBjor.1
Associate II

I am using TIM2 on a STM32H7 to generate interrupts - e.g. every 1 ms. Using the formulas from the documentation, Update_event = TIM_CLK/((PSC + 1)*(ARR + 1)*(RCR + 1)), solving for ARR and using RCR = 0 we get

ARR = 1/(Update_event * (1 + PSC) / TIM_CLK) - 1. My prescaler is 10 and the timer clock frequency is 275 MHz, which yields a counter period of 24999.

I then toggle a GPIO pin with the timer interrupt function and measure this on my logic analyzer - what I find is that the pin is toggling about 5us too fast. Any idea to why this could be? I suppose I could tune the counter period until I get the desired result but I feel uneasy not being able to predict the frequency more accurately. Thanks a lot for any input0693W00000QMxaGQAT.png

7 REPLIES 7

What is the primary clock source?

Note, that HSI is not precise. Read the datasheet.

JW

OBjor.1
Associate II

Hi,

Thanks for the reply. I am using HSE at 8MHz through PLLCLK generating a system clock at 550 MHz and 275 MHz for the timers. Please see the attached screen shot.

I have also noticed jitter in the order of 1us, which seems to me as a bit more than I'd expect.

Thanks for input!0693W00000QMz0FQAT.png 

Oskar

Try disable CSS and calculate from your crystal ppm possible PLL errors.+ -

Too you can try trim capacitors around crystal.

What's the 8MHz clock source, a crystal, or STLinkV3 MCO?

JW

This does indeed seem to apply to me as I am using a Nucleo dev board.. Thanks for sharing!

I am however not sure about what they mean when they speak of this 'partial workaround' - how do I change the MCO to this 25/3 MHz mode and how do I make my STM32 understand that it should not use its HSI?

Oskar

OBjor.1
Associate II

That's exactly what I needed, things are working perfectly now! Amazing how quickly you could sort that out for me, thanks a lot