Hi,
I have a PWM interrupt with 100 kHz and for debugging I toggle a GPIO at begin of the ISR. On the Oszi I observe a maximal jitter of 2 us (120 cycles).
The maximal jitter depends definitely on the code of the main loop.
This long Interrupt latency seems to be caused by a for-loop where 64 register are copied. If I split the for-loop into two for-loops the ISR latency is reduced to the half. (See sample code).
void main(void) { ... unsigned reg1[64], reg2[64]; while(1) { .... set GPIO Y #if 1 // cause 2 us Interrupt latency for(int i = 0; i < 64; i++) { reg1[i] = reg2[i]; } #else // cause 1 us Interrupt latency for(int i = 0; i < 32; i++) { reg1[i] = reg2[i]; } for(int i = 32; i < 64; i++) { reg1[i] = reg2[i]; } #endif clear GPIO Y } } void isr_pwm(void){ toggle GPIO X }
Is it possible that a for-loop stall the ISR?
- No disabled ISR
- No nested ISR
- All code is in the ram.
- Maybe stack and the code in the same physical memory block