Quantcast
Channel: Raspberry Pi Forums
Viewing all articles
Browse latest Browse all 7503

Other RP2040 boards • Re: Function to use the WS2812 LED of RP2040-Zero boards using PWM and DMA

$
0
0
Yes, 32 bits each wrap. Assumes there are plenty of PWM slices for everyone :) . Wanted to keep it simple and self-contained.

Interestingly, I was trying things out with a 1Hz PWM (clk_sys on XOSC, 1Hz for the visual LED feedback on a regular Pico) and stopping the 1Hz PWM immediately after dma_channel_wait_for_finish_blocking() causes 2 DMA CC values to go missing. Might be stuff in-flight [1]. For 1Hz PWM I waited for CC to end up with the idle 0 value, acting as a sentinel. Or wait for just over 1 wrap period, then all DMA values appear correctly in the output. Apparently this isn't needed for the higher or normal speed WS2812 thing, but I put the 0 in as a last CC value to simplify the end of colour bit transmit and avoid headaches.

Edited to add: [1] Or rather, one value in CC waiting to be latched on wrap and perhaps one in-flight DMA transaction. Cores and PWM are on clk_sys (XOSC 12MHz) but I dunno about the rest of the blocks and I guess funny things can happen with certain configs. Still it's a nice PWM-DMA learning exercise for me and the function is easy to add into any program.

Statistics: Posted by katak255 — Fri Oct 31, 2025 12:16 am



Viewing all articles
Browse latest Browse all 7503

Trending Articles