Skip to main content
Associate
October 11, 2023
Solved

STM32L0x2 timer frequency off by 10%

  • October 11, 2023
  • 3 replies
  • 1560 views

Hello!

I'm trying to setup up timer6, i need to use it at different frequencies at different times. To test the timer i toggle an output pin in the ISR and measure the frequency with an oscilloscope, but the frequency is consistently off by about 10%.

Any suggestions to why this is? My solution would be to multiply the wanted frequency by some calibration factor.

I would like a frequency of 2 Hz, so the timer interrupts should be at 4 Hz to toggle on and off.

The timer setup is:
32 MHz PLLCLK
Prescaler = 125
Period = 64000

This topic has been closed for replies.
Best answer by Tesla DeLorean

Use N-1 values to divide by N

124 to divide by 125

63999 for divide by 64000

3 replies

Tesla DeLorean
Tesla DeLoreanBest answer
Guru
October 11, 2023

Use N-1 values to divide by N

124 to divide by 125

63999 for divide by 64000

Tips, Buy me a coffee, or three.. PayPal Venmo (See Profile) Up vote any posts that you find helpful, it shows what's working..
FiskkAuthor
Associate
October 11, 2023

Of course, thanks!
Now it's is off by 0.5 % but i guess that's because of the error tolerance of the clock=?

TDK
October 11, 2023

0.5% is within the tolerance of the internal HSI, if that's what you're using as a clock. A crystal will provide a much more accurate clock, to tens of ppm or so. The HSI can also be trimmed, but is not going to be stable long term or across temperatures.

"If you feel a post has answered your question, please click ""Accept as Solution""."