Skip to content

Comments

Bug fixes for rare glitches on WS2812B pixels (NeoPixels) and 030 errors on micro:bit V2 (1/3)#61

Open
kevinjwalters wants to merge 44 commits intolancaster-university:masterfrom
kevinjwalters:kjwpwmfix-pr
Open

Bug fixes for rare glitches on WS2812B pixels (NeoPixels) and 030 errors on micro:bit V2 (1/3)#61
kevinjwalters wants to merge 44 commits intolancaster-university:masterfrom
kevinjwalters:kjwpwmfix-pr

Conversation

@kevinjwalters
Copy link

@kevinjwalters kevinjwalters commented Aug 15, 2025

Issue Tickets

This is one of a trio of PRs which fixes issues with neopixel_send_buffer() used by MicroPython's:

@finneyj @martinwork @microbit-carlos may be interested in this.

Summary

The summary of changes for all three PRs (this one has the bulk of them in WS2812B and NRF52PWM classes) is:

  • added volatile to variables in classes for better safety between main and interrupt handler code
  • made WS2812B::play() fully blocking to prevent hazardous overlapping executions of neopixel_send_buffer() - this was implemented using the existing dataWanted() perhaps not quite how it's intended to be used?
  • fixed the one extra pulse bug
  • fixied PWM stopping using same technique as nrfx_pwm_stop() + sprinkling of event clears of EVENTS_SEQEND
  • dramatically reduced chance of bogus pulses occuring after end of transmission by zeroing data buffer and using slightly enlarged emptyBuffer
  • added an errorFlag and errorFlagCumulative (not yet exposed via API or MicroPython)
  • #if disabled currently: added detail pwm statistics and error counters with history and anomalying DMESG printing (only intended for future debugging - this could be removed)
  • safer conditionals with dataReady
  • made interrupt handler in NRF52TouchSensor more efficient.
  • more efficient transfer of from WS2812B to NRF52PWM by reusing existing buffers, removing data initialisation for ManagedBuffer and optimised code - this required a minor addition to the interface for DataSource
  • after some testing and consideration increased the priority of NRF52PWM interrupts by changing PWM2_IRQn from 3 to 2.
  • trivial changes: fixes for periodUs, remove of redundant setSampleRate(), change lock initalisation in WS28128B - these had no impact on glitching bugs.

I've highlighted the three things in bold italics which I think need the most reviewing.

The fixes were applied to a branch from master made on the 24th July 2025. This will clearly be different code to the production release where these bugs were originally observed:MicroPython v1.18 on 2023-10-30; micro:bit v2.1.2 with nRF52833 on a V2.2.1 micro;bit.

The diff looks a lot bigger than it really is, the bulk of the lines are the PWM statistics code which is #ifed out.


Testing

The bug fixes have been tested:

  1. As they were developed in debugger and with logic analyzer, documented in comments in Occasional corruption of neopixel wire data causing visual glitching codal-microbit-v2#475
  2. Recently for four days on three micro:bits with occasional visual observation running neopixel-thirty-bug-colourcycle-26.py
  3. Four days on four micro:bits with occasional visual observation running neopixel-thirty-bug-timedetector-16.py & neopixel-thirty-bug-timedetector-23.py & neopixel-thirty-bug-colourcycle-26.py & zhhclock - video

Partner PRs:


Additional information (not required reading):

Kevin J Walters added 30 commits July 25, 2025 22:59
… been sent to improve blocking behaviour of WS2812B.
…M.STOP.

Using the hardware register changes in setStreamingMode in new setPwmLoopInten(). lancaster-university#59
Avoid dynamic memory allocations in interrupts by reusing existing ManagedBuffer, less cycles with reuse reducing likelihood of overrun. lancaster-university#59
…ppening when PWM is not running.

New irqtotalcount plus irqtotalcountatstart and irqtotalcountatstop per output. lancaster-university#59
The wrapping counters need more care in comparisons with careful use of unsigned and signed values. lancaster-university#59
Kevin J Walters added 14 commits August 5, 2025 01:08
Something is amiss here, values can appear way below 10240 cycles. lancaster-university#59
…PWM values at end of output rather than use emptyBuffer. lancaster-university#59
@kevinjwalters
Copy link
Author

Unrelated to this I would be very grateful if you could discuss increasing the file system size from 24k to at least 32k with the creator (microbit-foundation/micropython-microbit-v2#226).

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.

1 participant