cancel
Showing results for 
Search instead for 
Did you mean: 

STM32L0x2 timer frequency off by 10%

Fiskk
Associate

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

1 ACCEPTED SOLUTION

Accepted Solutions

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
Up vote any posts that you find helpful, it shows what's working..

View solution in original post

3 REPLIES 3

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
Up vote any posts that you find helpful, it shows what's working..
Fiskk
Associate

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

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".