Pico Timer Callback - collision with IRQ servicing causes lockup #11704
Replies: 9 comments 13 replies
-
I put in place a whole load of work-arounds, but still get the lock up. :-( For the IRQ servicing I just decided to exit the routine if it detected that the
I've also attempted to minimise the 'window of opportunity' around the
If I disable the timer (set duty cycle to X.0 so that it does not start, and therefore no callback gets called) the code will run for hours. Timing information: Timer is set for a 10s period, but duty factor means that the |
Beta Was this translation helpful? Give feedback.
-
Probably not the best idea to modify the Timer in its own ISR. from machine import Timer
from micropython import schedule
from time import sleep_ms
def timer_cb(t):
print(f'scheduled callback({t})')
t = Timer()
t.init(mode=Timer.PERIODIC, freq=10, callback=lambda timer_info:schedule(timer_cb, timer_info))
sleep_ms(2000)
t.deinit() |
Beta Was this translation helpful? Give feedback.
-
@mungewell from your code I have the impression, that the interrupt service routines run on both cores. We had seen earlier, that this does lead to unpredictable behaviour. Also you acquire a lock in the ISR. This contradicts the need of the ISR to terminate rapidly. |
Beta Was this translation helpful? Give feedback.
-
@GitHubsSilverBullet Using a PID loop, and modulating the PIO dividers does work quite well, the plot above is from: In this test I was able to 'calibrate' the stock crystal to an external reference, and when external reference was de-linked the local time took ~15hr to drift by 1 frame (my target would be <1 frame in 8hrs). Yes a TCXO would be better, I have some from Digikey to install.... but I wanted to see what was achievable with stock. Remember the way that I'm using the timer is to run very-slightly faster for X% of the time, and very-slightly slower for the rest. My previous tests were using NeoTimer in my software loop. Moving to inbuilt My previous comment about |
Beta Was this translation helpful? Give feedback.
-
I mentioned that the Debug header was a mystery to me... not anymore. Proud to say I've earned that badge! In case anyone else is following along: and some fixes:
Next challenge building and flashing MicroPython this way, with UART redirect and (possibly) no USB. I found some high precision XTALs but they are 12.8MHz (rather than 12MHz) and I suspect that this might be enough to throw USB out of operation... |
Beta Was this translation helpful? Give feedback.
-
So I might have the following wrong... but what else can I glean from GDB? Thread-1 seems to be executing ByteCode, and then swapped out for the interrupt handler.
If I step back to the
|
Beta Was this translation helpful? Give feedback.
-
As you might have a seen, I'm getting 'better' at learning/understanding GDB to see what is going on...
What I don't understand ATM is how the call to Thread-1
ports/rp2/mpthreadport.h
|
Beta Was this translation helpful? Give feedback.
-
After 'stalling' on this project for a while I see that there have been fixes done on MicroPython's Mutex... perhaps it's time to get involved again. |
Beta Was this translation helpful? Give feedback.
-
Well I bashed on it pretty hard for the last week.... and ZERO lockups, looks like the microPython team fixed my issue. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Following on from:
https://github.com/orgs/micropython/discussions/11529
I have implement the Timer to modulate the Pico's PIO clock dividers, so that I can a compensate for an imprecise XTAL and get a match to external frequency reference. But every so often the whole code would lock up....
I think I have tracked this down to the IRQ servicing routine is being called during at the same time, and it seems that the timer re-init does NOT operate whilst the IRQs are disabled (as recommended by previous discussion).
Full code is here:
https://github.com/mungewell/pico-timecode/tree/adjust_clock_with_PID
IQR and Timer callback:
https://github.com/mungewell/pico-timecode/blob/adjust_clock_with_PID/pico_timecode.py#L191
With my debug prints in place I get following when crash occurs, and there is no '.' output showing that the Timer Callback is still active.
Is there any (practical) way I can pause the IRQ routine, whilst Timer callback/re-init is happening?
Beta Was this translation helpful? Give feedback.
All reactions