Inverting OctoWS2811 output in software

Status
Not open for further replies.

rafl

Member
I'm building a project to control 8 LED strips using the OctoWS2811 library on a Teensy 4.1. I was planning on using two hex non-inverting schmitt-trigger ICs I thought I had around for level-shifting the output, but unfortunately what I had instead was otherwise pin-compatible inverting schmitt-triggers. I didn't notice that mistake until after having assembled a prototype with the wrong IC.

Is there perhaps a way of easily inverting the output signal in software before it gets re-inverted again by the schmitt-triggers as to not require a bunch of rework of the hardware I have already built? I've tried to have a look at OctoWS2811_imxrt.cpp, which is where I think I'd need to make the changes I want, but I haven't quite been able to follow what's going on in all the low-level code to find the right place to make that modification.

Thanks!
 
I looked through the library, paul is a wild genius to figure all of this out. I would do it in hardware if it were me :D

SO the code doesn't use digitalWrite because that's so slow there's no way it would even come close to firing in the right timing. I'm still learning about all this, but it looks like the method he used to talk to the digital pins is Direct Memory Access.

I really don't know how it all works either, but here's an example of what appears to be writing to digital pins very very quickly:
chrome_mhT26TzkkC.png

Between line 282 to 290 is the actual pin writes... I think FTM1_C1SC and FTM1_C0SC are some kind of registers for the corresponding digital pins, but I really don't know how DMA works. Hopefully someone else will weigh in ¯\_(ツ)_/¯

chrome_RSdTCbsjGn.png
 
Between line 282 to 290 is the actual pin writes... I think FTM1_C1SC and FTM1_C0SC are some kind of registers for the corresponding digital pins

Those writes are just configuring the timers, which are used to generate hardware trigger events to cause the DMA to move data from memory to GPIO. And the "FTM" timers are only on Teensy 3. Look for the #ifdef in the code to see which hardware.


Is there perhaps a way of easily inverting the output signal in software before it gets re-inverted again by the schmitt-triggers as to not require a bunch of rework of the hardware I have already built?

Look for the DMA destination addresses. It's these lines in OctoWS2811_imxrt.cpp.

Code:
        dma1.TCD->DADDR = &GPIO1_DR_SET;

        dma2next.TCD->DADDR = &GPIO1_DR_CLEAR;

        dma3.TCD->DADDR = &GPIO1_DR_CLEAR;

                dma2.TCD->DADDR = &GPIO1_DR_CLEAR;

                dma2.TCD->DADDR = &GPIO1_DR_CLEAR;

Change every CLEAR to SET, and the one SET to CLEAR. Kind of like the trick where the magician yanks the table cloth out and all the dishes & silverware stay in place...
 
Awesome - thank you both!

That saved me a whole bunch of labour and also gave me some interesting insights into how the library works.
 
Status
Not open for further replies.
Back
Top