v3.8.0: Issue with Timer Input Capture

Hello

I have the following short test/demo script to measure the pulse width of an incoming pulse (for an RC servo in this case, i.e. between 1ms and 2ms approx).
When trying the script in v.3.7.0 everything works as expected and the correct pulse length is printed to stdout.
When trying the script with the newest firmware v3.8.0 the printed pulse width is always 0. I checked, and the callback is actually never executed.

Do I need to implement this differently with v3.8.0? Did I miss something in the documentation?

# tmr_ic_test.py
#
# Minimal test/demo script to measure pulse width of RC servo signal
# using timer input capture and interrupts.
#
################################################################################

import sensor, image, time, pyb, micropython

sensor.reset();
sensor.set_pixformat(sensor.RGB565);
sensor.set_framesize(sensor.QVGA);
sensor.skip_frames(time = 2000);

clock = time.clock();

# Pin P0 / Timer 12 / Channel 2
#
ic_pin = pyb.Pin(pyb.Pin.board.P0, pyb.Pin.IN);
tim    = pyb.Timer(12, prescaler=12-1, period=0xFFFF);
tim_ch = tim.channel(2, pyb.Timer.IC, pin=ic_pin, polarity=pyb.Timer.BOTH);

################################################################################

ic_start  = 0;
ic_width = 0;

################################################################################

# Interrupt Routine (callback)
def tim_ic_isr(tim):

    # static variables don't exist, use globals
    global ic_start;
    global ic_width;

    if ic_pin.value():  # rising edge
        ic_start = tim_ch.capture();
    else:               # falling edge
        ic_width = (tim_ch.capture() - ic_start) & 0xFFFF;

################################################################################

micropython.alloc_emergency_exception_buf(100);
tim_ch.callback(tim_ic_isr);

while(True):

    clock.tick();
    img = sensor.snapshot();
    print("{:.1f} FPS    {:.2f} us".format(clock.fps(), ic_width/20));

################################################################################

Thanks
Regards

Felix

Please report an issue on github, and make sure to fill the issue template.

Ok. I’ve opened an issue:

Thanks, I’ll take a look. In the meantime, can you try setting the callback arg instead ?

....
....
micropython.alloc_emergency_exception_buf(100);
tim_ch = tim.channel(2, pyb.Timer.IC, pin=ic_pin, polarity=pyb.Timer.BOTH, callback=tim_ic_isr);
....

Had only now time to test this, but yes, this is working as intended!

Thanks!
Felix