Teensy 4.1 powered by i.MX RT1060 (ARM CORTEX M7). Get to know this, quite different to the M0+ / M4 I am used to.
Start with a little look at the performance from Python:
from machine import Pin
led = Pin("D13", Pin.OUT)
while True:
led.toggle()
Usually this is quite jittery, not so here:
CPU doing something useful then.
Interrupt performance:
from machine import Pin
led = Pin("D13", Pin.OUT)
def irq(stuff):
led.off()
led.irq(handler=irq, trigger=Pin.IRQ_RISING)
while True:
led.on()
Also fairly solid:
Useful start - now look at C implementation of IRQ etc. - a smarter approach is to connect D13 to PWM, D14 as input and D15 as output so the delay can be measured directly:
from machine import Pin, PWM
led = Pin("D13", Pin.OUT)
sense = Pin("D14", Pin.IN)
out = Pin("D15", Pin.OUT)
out.on()
@micropython.viper
def irq(stuff):
out.toggle()
sense.irq(handler=irq, trigger=(Pin.IRQ_RISING | Pin.IRQ_FALLING))
pwm = PWM(led)
pwm.freq(1000)
pwm.duty_ns(10_000)
The delay appears to be a solid 1.72µs:
Switching out the irq
call to:
sense.irq(handler=irq, trigger=(Pin.IRQ_RISING | Pin.IRQ_FALLING), hard=True)
Makes for a small improvement (1.26µs) but still not in the regime where real interrupts live. Moving to C interrupts via drive-by actually bricked the controller 🤔 - does not restart.