[Martin Hubáček] wrote in with his WS2812 LED library for the STM32F3 series processors. [Martin]’s library takes the same approach as [Paul Stoffregen]’s OctoWS2811 for the Teensy, and [Erich Styger]’s for the Freescale FRDM-K64F board. That is, it uses three DMA channels to get the signal out as fast as possible.
He has a good overview of the method that you can check out for details, but it goes something like this. The WS2812 uses a PWM-like encoding to transfer data. If the signal is high for 1/3 of the time, it’s a zero, and if it’s high for 2/3 of the time, it’s a one.
The first DMA signal sends the start of a bit, setting all outputs high. The second DMA channel sends out a low signal for all of the zeros, and the third DMA channel sends out a low signal for the ones. Each of these three DMAs are clocked at just the right times to make the pulse timing work out.
The advantage of this GPIO/DMA setup over other methods is that it can drive a whole bank of pins — up to 16 strips simultaneously for the STM32F10x chips. It also loops the graphic buffer around so that you can drive repeating patterns without using much memory. And all the CPU has to do is load up the DMA buffer when it’s (half) empty, which means that even with a full load of LEDs, it’s still got most of its time left for number crunching.
Finally, to show off, [Martin] pulled a sweet trick and captured it on video. Since the digital signals are on/off encoded for the red, green, and blue channels, he decided to experiment with digital color mixing. He and
s and or
s two simultaneous signals together and demonstrates that it works just as you’d expect. Check it out in the video below.
Love that TESLA 74x series chip on that breadboard! That thing has to be at least 30 years old if not more. TESLA stopped producing chips (mostly ceased to exist as a company) after the fall of communism in 1989. Childhood memories of playing with 7400 gates which were extremely precious, because components were hard to get unless you knew the right people or lived in a large city where there was a relatively stocked store …
I still have a lot of them, not exactly sure why, though.
I proudly took the Tesla 74xx one from my drawer. I knew that someone will appreciate that, thanks.
Hello, I’m the author of the library. Just wanted to clarify that this lib is different. It don’t allocate big uint16_t buffer with bit combinations to just throw to GPIO, but thanks to circular DMA and quick bit-banding in DMA’s IRQ it uses only small buffer for two LEDs and updates it on-the-fly from the efficient RGB framebuffer.
I like the idea of the small buffer. I have my own OctoWS2811 lib inspired thing for the stm32f4 which uses a huge buffer.
https://github.com/ain101/SedecimWS2811/tree/master/ws2811_Lib
If you want to see a *hack* check out my up-to-4-strips WS2811 library for the poor little Atmegas, a modification of the original ws2811 library to take advantage of every clock cycle available.
If you really wanted you can drive about 16 strips with an Atmega but your pixel data would need to be preprocessed instead of using the normal RGB buffers.
Your link is broken. There is no href anywhere. only “up-to-4-strips WS2811 library“
Doh