WS2811 the Easy Way with XCL on a Xmega8E5


Want pure hardware generation of  a WS2811 signal?  No funky buffers that take CPU time to setup or tricks to bend SPI to your will?  Here’s a straight pure hardware way to generate a WS2811 stream with minimal CPU time on a Xmega8E5 by taking advantage of the XCL (XMEGA Custom Logic) module.  By taking the XCL, DMA, and USART modules and mixing them all in a bowl with the Xmega Event system, we can effortlessly generate a WS2811 stream.  In this example, I’ll use my PixelStick.  The PixelStick is a Xmega8E5 based WS2811 pixel controller that is controlled wirelessly by a nRF24L01+ module. The complete firmware is available on GitHub, but I’ll extract the tasty bits here.

The first thing we need to do is setup the USART in SPI mode.  Note that its running at 800kHz, no funky SPI tricks here.  DMA transfers will be used to feed the USART module and is triggered by incoming nRF24L01 pixel data.

Then we need to setup two PWM streams, representing the WS2811 Hi and Lo bits:

And setup the XCL module as a MUX:

Everything is tied together via the Xmega Event system.  Event Channel 7 links the SPI clock to the timer WS2811 stream timers so bit generation is always synchronized to the SPI stream.

In the end, we have an ISR to handle incoming nRF24L01 data and trigger DMA transfers:

And a main() that just polls for new pixel data and updates our pixel buffer, triggering DMA transfers as needed to generate the WS2811 stream.  The power conscious could sleep here if they wanted.

You can see the PixelSticks in action here:

 

Leave a comment

Your email address will not be published. Required fields are marked *