2024-03-15 11:36 AM
Hi
I'm implemented the most simple pwm generation and using interruptions in F401RE with TIM1. But a delay has been in the PWM generation and the update event interrupt (underflow and overflow) the most large pulse is the PWM and the another the when interrupt occours. I tested in diferent frequencys and in another timer and the error persists.
Above has my code, i want centralize the interruption in the middle of pwm pulse.
Thanks.
Solved! Go to Solution.
2024-03-15 03:51 PM
The interrupt is triggered in the middle of the pulse, but it takes time
- until it propagates to NVIC
- latency of interrupt is minimum 12 cycles in Cortex-M4
- Interrupt Service Routine (ISR) in C adds prologue, that's another source of latency
- Cube/HAL adds lots of code until the callback is called, that's another huge source of latency
- the latter two gets worse if compiler optimizations are off or at low level
All in all, if the pulse is 2*30 cycles (or 2*60, depending on the APB prescaler of the APB bus where the timer in question sits), what I see on your second picture is latency of roughly 100-200 cycles, given the last item (Cube/HAL), that sounds about right.
And, of course, this all is subject to jitter, if there are other interrupts of the same or higher priority active.
If you want any precision timing, do everything in hardware, i.e. employ timers' features to generate precisely timed pulses.
JW
2024-03-15 03:51 PM
The interrupt is triggered in the middle of the pulse, but it takes time
- until it propagates to NVIC
- latency of interrupt is minimum 12 cycles in Cortex-M4
- Interrupt Service Routine (ISR) in C adds prologue, that's another source of latency
- Cube/HAL adds lots of code until the callback is called, that's another huge source of latency
- the latter two gets worse if compiler optimizations are off or at low level
All in all, if the pulse is 2*30 cycles (or 2*60, depending on the APB prescaler of the APB bus where the timer in question sits), what I see on your second picture is latency of roughly 100-200 cycles, given the last item (Cube/HAL), that sounds about right.
And, of course, this all is subject to jitter, if there are other interrupts of the same or higher priority active.
If you want any precision timing, do everything in hardware, i.e. employ timers' features to generate precisely timed pulses.
JW
2024-03-18 04:01 PM - edited 2024-03-18 04:02 PM