cancel
Showing results for 
Search instead for 
Did you mean: 

Timer-Synch + IRQ-Jitter

vincenthamp9
Associate III
Posted on October 09, 2015 at 11:33

Hello

I've a question regarding the timer synchronization on an STM32L4. I've setup TIM1 and TIM8 to run in synch triggered by TIM2. To test the code I simply toggle a pin inside the TIM1 and TIM8 update interrupts. As far as I can tell it seems to work, but two things worry me.

When I debug the whole thing and set a breakpoint, the CNT register values of TIM1 and TIM8 are not equal, although my debug configuration definatly stops both timers when hitting the break. How could that be? I mean... they couldn't be off by much, judging from image #1... but still?

And the other thing I find kinda strange is that it takes the controller between 400 and 500ns (see image #2) just to end one timer IRQ and jump into the next one. Is this jitter normal? Both IRQs are temporarily set to the highest priority, nothing else could preempt them...

0690X000006059tQAA.png

0690X00000605DKQAY.png
2 REPLIES 2
Posted on October 09, 2015 at 12:08

Have you or the debugger set respective TIMx_STOP bits in DBGMCU_APB2FZ? If not the timers are still running after breakpoint. You can verify it by refreshing the timers registers' view in the debugger.

If you wrote the pins change at the beginning-end of ISR in C, the comipler might have added a whole bunch of instructions as prologue/epilogue, depending on compiler, its settings, and the ISR code itself.

JW
vincenthamp9
Associate III
Posted on October 10, 2015 at 16:02

The stop bits are set yes, thats why its bugging me...

Ok, so the jitter might ''normal''?

All the ISR does is clearing the update flag and toggling the bit with direct register access. But I guess saving and restoring all context simply takes that long...