I am not sure why the following causes and exception with MemoryError when a divide by 3 is added:
adcY11 = pyb.ADC( pyb.Pin.board.Y11 )
adcTimer = pyb.Timer(7, freq=2)
# THIS WORKS FINE
adcTimer.callback(lambda t: print(adcY11.read() ) )
# THIS GIVES MemoryError exception
adcTimer.callback(lambda t: print(adcY11.read()/3 ) )
ADC Callback Exception
Re: ADC Callback Exception
Dividing by 3 needs to create a new float object, which needs to do a memory allocation.
If you used // 3 then it would create an int which doesn't need to do a memory allocation.
IRQs aren't allowed to do memory allocations.
If you used // 3 then it would create an int which doesn't need to do a memory allocation.
IRQs aren't allowed to do memory allocations.
Re: ADC Callback Exception
Ok that makes sense. Thank you.