Showing results for 
Search instead for 
Did you mean: 

Inconsistent Timer Interrupt

Senior II

I'm running an STM32F373 with 8Mhz osc and enabled PLL in the clock config to get 24Mhz on the timer buses.

I setup TIM2 to TIM_IT_UPDATE interrupt at 4Hz.  I send a one time 10ms pulse to an output pin each time TIM2 interrupts.  ( I have a speaker beep to hear the output )

For some reason, the output glitches every now and then, indicating TIM2 is running a bit slow, or is slow getting to the interrupt.  ( maybe 2ms-5ms of delay, just enough to be noticeable by ear  )  I plan on connecting my oscope to it again but it does not log long enough for me to capture the glitch.  

I don't have any other interrupts running and have also tried raising the priority interrupt level for TIM2.  

Is it possible PLL is causing a slight glitch when multiplexing the 8Mhz external ocs x6?  

I ensured to stop CubeMX's debugging and even disconnected the USB cable to ensure the IDE or debugger was not causing the glitch. ( which it does when I hit 'stop' debugging, but that is not the cause of my issue )

Thank you!

Principal III

> but it does not log long enough

A $10 logic analyzer would do. Maybe an audio recording using audacity or such.

How do you send the pulse? Showing code helps.

> don't have any other interrupts

SysTick handler?




ST Employee

Hi @LMorr.3,

it's quite impossible to detect system frequency inaccuracy by audio output (unless you are one of the rare gifted ones who claim to hear the digital noise in CD audio). The 24Mhz will be just as accurate as the 8mhz crystal output, apart of some jitter. 

But it's also impossible to hear frequencies as low as 4Hz. Or maybe I fail to understand your setup. If you don't have the scope to monitor the outputs, I'd suggest using a LED indicator, test the timer by trying to regulate the LED brightness using PWM.

There are some useful tips on timer usage in STM32 cross-series timer overview - Application note.


To give better visibility on the answered topics, please click on Accept as Solution on the reply which solved your issue or answered your question.

I have TIM2 interrupting at 4Hz and in the interrupt, I toggle a pin for 10ms. ( one time pulse using a second timer )

I hear a 'tick' like a metronome each time the TIM2 interrupt occurs, and it sounds 'off' just slightly on some intervals... enough to notice.  I have not seen it on the oscope yet at the same time I hear it.  Maybe the 'glitch' is more noticeable by ear when ticks occur at 4Hz and less obvious at lower frequencies.  ( I read an article that the human ear can detect an off-tempo beat by .5ms which is impressive.  

I'll spend more time troubleshooting but wanted to make sure the TIM2 would be very consistent. ( and not cause a 'glitch' noticeable by ear )  I don't have much else running and still notice the glitch.  Don't see it on the scope for some reason... thanks for the info.!

But it's also impossible to hear frequencies as low as 4Hz.

Take a note that the signal processing rules apply to sine waves, not any signal form! One cannot hear a 4 Hz sine wave, but one can definitely hear some short 4 Hz square pulses, because those contain a bunch of higher frequency (sine) components.

You can hear a metronome running at 4Hz though... I"m sending a 10ms 'tick'  at 4Hz... I used a logic analyzer and do not see any anomalies so it's just me hearing it glitch when it actually does not.  I also tried another clock source and it does the same thing.  ( it only does this at certain frequencies )