[F4] Neopixel driver using hardware timers

What are you developing?
flyboy74
Posts: 31
Joined: Fri Jan 03, 2020 10:12 am

Re: [F4] Neopixel driver using hardware timers

Post by flyboy74 »

ozcar wrote: Wed May 13, 2020 3:35 am I can see you are not a fan of using SPI for this task. The granularity of the available timing is an issue, but 1/3 2/3 pulses does suit a lot of these type of LEDs, even if you also need to mess with the clock configuration to get the overall period within spec.

As for the increase ram usage - the WS2812B library included with Roger's core (which uses SPI) does not use 4 times more ram, it is "only" 3 times more, because the data is not retained in the "raw" format, only in the "expanded" format. At least, that is how I believe it works.

To be fair, you are also expanding the data, and actually by a factor of at least 8 times - one bit of raw LED data becomes an at least 8 bit value to be put in the timer CCR. Of course, you don't have to create an array 8 times the size of the raw LED data, but that is only because you do the conversion, for one bit at a time, in the interrupt routine. I don't see why the same could not be done when using SPI, and that would not require processing one interrupt per bit of LED data. Even without using DMA, it would be just under 1 interrupt per 5 bits of LED data (with 16-bit frame size), and with DMA it could be 1 interrupt per LED or less depending on size of DMA buffer.
It isn't that I am not a fan of SPI for this task but I am for correct comparison. The first time that I read how they were using SPI to create these timings I though that it was very clever.

It is an interest concept you have not buffering the whole LED strip but rather only a small part then with DMA feeding the SPI and an interrupt filling half of a circular buffer it would then lower the amount of RAM used by the SPI method but increase the CPU usage. In the end it is very similar to what you did with timers and DMA. I think in comparison the DMA with timers allows better timing as you have both a pre scaler and an ARR and your not limited to 1/3 and 2/3.
Post Reply

Return to “Projects”