bbcmicrobit / micropython

Port of MicroPython for the BBC micro:bit
https://microbit-micropython.readthedocs.io
Other
603 stars 284 forks source link

lib: Make sure that PWM continues to work even if it misses an IRQ. #607

Closed dpgeorge closed 2 years ago

dpgeorge commented 5 years ago

If the soft PWM driver misses an IRQ then the next CC value (computed as CC[x] += delay) could already be behind the timer counter value, and hence the next compare IRQ won't fire until the timer counter value wraps around.

This needs some testing because the timing of the PWM will now be slightly different compared to before, since the next event will be computed from the current counter value plus delay, rather than the counter value at the time of the previous IRQ. But I can't really think of any other way to fix the issue of missed IRQs.

Should fix #600

dpgeorge commented 2 years ago

This fix was updated so that it retained precise PWM timing in the case when no IRQs were missed.