2022-08-04 05:57 AM
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 input
2022-08-04 06:56 AM
What is the primary clock source?
Note, that HSI is not precise. Read the datasheet.
JW
2022-08-04 07:50 AM
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!
Oskar
2022-08-04 07:58 AM
Try disable CSS and calculate from your crystal ppm possible PLL errors.+ -
Too you can try trim capacitors around crystal.
2022-08-04 08:11 AM
What's the 8MHz clock source, a crystal, or STLinkV3 MCO?
JW
2022-08-04 09:13 AM
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
2022-08-04 09:24 AM
2022-08-05 02:25 AM
That's exactly what I needed, things are working perfectly now! Amazing how quickly you could sort that out for me, thanks a lot