'timer.init()' fails with ENOMEM #18699
Replies: 3 comments 18 replies
-
|
Works perfectly fine with up to 16 Timers. #!/micropython
# vim: fileencoding=utf-8: ts=4: sw=4: expandtab:
from machine import Timer
from random import randrange
from time import sleep_ms
def timer_cb(t):
global new
print(t)
t.deinit()
new += 1
new = 16 # OK
#new = 17 # OSError: [Errno 12] ENOMEM
while True:
sleep_ms(0)
if new:
new -= 1
Timer().init(mode=Timer.ONE_SHOT, period=randrange(50,100), callback=timer_cb) |
Beta Was this translation helpful? Give feedback.
-
|
Further interesting find... I placed a And in order to see this I disable my 'per frame' (30 times per second) prints of TX. With this I was able to cycle through 20 reset/jam cycles without issue. I then re-introduced the 'per frame' prints, and got the error As you can see the reported 'free' memory is around the same as the working condition, so what else (other than lack of memory) might trigger the ENOMEM? Fragmentation??? |
Beta Was this translation helpful? Give feedback.
-
|
As a general point there are some subtle issues with multi-core coding which this doc attempts to address. In particular the lack of a shared GIL has implications relating to objects shared between the two contexts. I don't claim to understand the constraints of your application, but unless there are specific counter-indications it's worth considering using |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I use a couple of timers to create a PWM system, running around 1s period, to modulate between 2 settings for the PIO clock dividers. This works OK, but it gets restarted everytime I restart the PIO machines.
After around 6 restarts, I get a EOMEM during the 'timer.init()'.
I previously thought it was because I was discarding the timer (
timer1=None) and making a new one withtimer1=timer(), but after refactoring the code (to prevent this) I still get the EOMEM. I even added a garbage collection...Bit that fails is
Timer3 is a safety net, Timer 2 is the period (which can change from time to time), Timer1 is the first part/phase of the PWM.
Beta Was this translation helpful? Give feedback.
All reactions