Skip to main content
b.a.
Associate III
Nov 4, 2020 6:52 AM UTC
Question

STM32L412 interrupt latency and jitter

I am running STM32L412 on 48MHz MSI, Timer 2 is configured in One-Pulse mode to output a 2ms Pulse. This is done by setting Timer 2 in PWM mode and with a prescaler of 47, ARR = 1999 and CCR = 1, Polarity=LOW

An interrupt is generated on update Event, i.e. when the pulse goes low.

In the ISR I set a GPIO to high, then clear the interrupt flag

void TIM2_IRQHandler(void)
{
	if(LL_TIM_IsActiveFlag_UPDATE(TIM2))
	{
		LL_GPIO_SetOutputPin(BTS_5V_GPIO_Port, BTS_5V_Pin);
		LL_TIM_ClearFlag_UPDATE(TIM2);
	}
}

Configuration is done with CubeIDE

Now, when observing the signals on a scope, I see that there is very unsteady interrupt latency that jitters from fairly good (750ns) to quite poor(2,6µs) and all this in quite neat 166ns intervals

0693W000005AHCxQAO.png 

I am quite new to the STM32, but this very coars jitter seem just not right to me and the total timespan would be something like over 100 clock cycles.

I have the feeling that I am missing something out on the configuration...

Up to now there is no application code running, just timers and some interrupts

Any help welcome to solve this mistery...

Cheers,

Bob

This topic has been closed for replies.

9 replies

b.a.
b.a.Author
Associate III
Nov 4, 2020 7:14 AM UTC

Oh my...

just realized I was still in debug mode !

silly me :\

The latency is much less, but still quite a lot of jitter:

(I left the scope on the same settings to better illustrate change)

0693W000005AHH4QAO.pngeach jitter intervall is around 62ns (which would mean about 3 clock cycles on 48MHz?)

Any idea what can cause this very irregular interrupt latency?

waclawek.jan
Super User
Nov 4, 2020 8:06 AM UTC

Other interrupt of same or higher priority (maybe systick if you use CubeMX autovomited code), combined with jumpcache and bus synchronization artefacts?

In 32-bitters, interrupts are a poor way of realtime control, use hardware whenever possible.

JW

b.a.
b.a.Author
Associate III
Nov 4, 2020 9:01 AM UTC

no systick, as far as I know, when using LL-libraries.

apart from system interrupts, there is only on other interrupt. Used to reset the pin that is set within TIM2_ISR when a falling edge occurs on PA5 (same pin that triggers TIM2)

0693W000005AIVgQAO.pngBUT, when I set this interrupt to priority 1 it is never executed!

I fear, I still don't fully understand interrupt handling :(

any good uploading the project?

waclawek.jan
Super User
Nov 4, 2020 7:33 PM UTC

> when I set this interrupt to priority 1 it is never executed!

This definitively is not normal. Maybe the other interrupt fails to clear its interrupt source (TIM interrupt? TIMx->SR) so loops infinitely.

Toggle a (different) pin in each ISR upon entry and exit and observe.

JW

b.a.
b.a.Author
Associate III
Nov 5, 2020 8:37 AM UTC

I am no "migrating" everything to "handmade" code, still looking at what the Cube-Thingy does and learning...

Too many strange things happened that I had to investigate, what held me away from doing what I want to do...

I now have a very stable interrupt latency of around 300ns (@80MHz PLLCLK) !

I really am convinced that this is the way to go.

I still use the LowLevel-lybraries and one issue is that when I disable peripherls in Cube, the correpsonding drivers, i.e. the .c and .h files are no longer included. small but annoying problem

waclawek.jan
Super User
Nov 5, 2020 9:29 AM UTC

> I now have a very stable interrupt latency of around 300ns (@80MHz PLLCLK) !

So, what did you do to achieve this?

JW

Tesla DeLorean
Guru
Nov 5, 2020 9:45 AM UTC

RAM based vectors and code might have a much more predictable execution profile.

​

Would also want to look at the code actually generated, and clear the interrupt flag earlier.​

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