Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Nov 29, 2021

Conversation

dpgeorge
Copy link
Member

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

@microbit-carlos microbit-carlos added this to the Version 1.1 milestone Dec 14, 2018
@rhubarbdog rhubarbdog mentioned this pull request Mar 13, 2019
@dpgeorge dpgeorge force-pushed the pwm-fix-lost-counter branch from 1d84697 to c4db2a4 Compare May 13, 2019 07:47
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.

Example code which demonstrates the bug (by having a long neopixel write
that stops IRQs):

    import microbit
    import music
    import neopixel

    np = neopixel.NeoPixel(microbit.pin0, 64)

    while True:
        music.play(music.BA_DING, wait=False)
        microbit.sleep(1000)
        np.clear()
        microbit.sleep(2000)

Prior to this commit the music would only play every 16 seconds or so,
which is the time taken for the PWM fast ticker to wrap around.

Fixes issue bbcmicrobit#600.

Signed-off-by: Damien George <damien@micropython.org>
@dpgeorge dpgeorge force-pushed the pwm-fix-lost-counter branch from c4db2a4 to 3b55d0d Compare November 29, 2021 11:50
@dpgeorge dpgeorge merged commit 3b55d0d into bbcmicrobit:master Nov 29, 2021
@dpgeorge dpgeorge deleted the pwm-fix-lost-counter branch November 29, 2021 11:51
@dpgeorge
Copy link
Member Author

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

neopixel effects music
2 participants