Re: How to make PWM rising edge trigger an interrupt?
Posted: Tue Jul 19, 2022 2:06 pm
Interesting.
I did a similar measurement, only with the rp2040 doing the measurement on itself.
The resolution is precisely 40ns (PIO at 125MHz)
To test it, I ran the PWM at 2000Hz with duty 50%. The PIO measurement showed exactly 250.000µs from High to low edge. Then I added a hard interrupt which manually forced the GPIO to low for a very short time. Just enough that the PIO was able to detect the falling edge.
On most interrupts, the measured latency was 14.89µs with the occasional 12.2µs
The question is: Why are the first couple of interrupts are so ›all over the place‹?
The graph only shows 200 samples, a 50000 sample long run was very stable and basically a continuation of the first graph.
I did a similar measurement, only with the rp2040 doing the measurement on itself.
The resolution is precisely 40ns (PIO at 125MHz)
To test it, I ran the PWM at 2000Hz with duty 50%. The PIO measurement showed exactly 250.000µs from High to low edge. Then I added a hard interrupt which manually forced the GPIO to low for a very short time. Just enough that the PIO was able to detect the falling edge.
Code: Select all
@micropython.viper
def _force_led_off(pin):
p: ptr32 = ptr32(0x400140cc) # direct GPIO25 access
saved: int = p[0] # save state
p[0] = (3<<12) | (2<<8) # override OEOVER and OUTOVER
loop_count: int = 100
while loop_count > 0: # wait a moment so that the PIO can pick up the new state
loop_count -= 1
p[0] = saved # restore state
and later in the program:
_ = generate.irq(trigger=Pin.IRQ_RISING, handler=_force_led_off, hard=True)
The question is: Why are the first couple of interrupts are so ›all over the place‹?
The graph only shows 200 samples, a 50000 sample long run was very stable and basically a continuation of the first graph.