Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 5 of 5

Thread: Inverting OctoWS2811 output in software

  1. #1
    Junior Member
    Join Date
    Apr 2020
    Posts
    5

    Inverting OctoWS2811 output in software

    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!

  2. #2
    Member pilotplater's Avatar
    Join Date
    Dec 2017
    Location
    Ontario, Canada
    Posts
    31
    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

    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:
    Click image for larger version. 

Name:	chrome_mhT26TzkkC.png 
Views:	16 
Size:	94.6 KB 
ID:	24479

    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 \_(ツ)_/

    Click image for larger version. 

Name:	chrome_RSdTCbsjGn.png 
Views:	7 
Size:	466.7 KB 
ID:	24480

  3. #3
    Senior Member PaulStoffregen's Avatar
    Join Date
    Nov 2012
    Posts
    24,278
    Quote Originally Posted by pilotplater View Post
    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.


    Quote Originally Posted by rafl View Post
    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...

  4. #4
    Member pilotplater's Avatar
    Join Date
    Dec 2017
    Location
    Ontario, Canada
    Posts
    31
    Thanks Paul!

  5. #5
    Junior Member
    Join Date
    Apr 2020
    Posts
    5
    Awesome - thank you both!

    That saved me a whole bunch of labour and also gave me some interesting insights into how the library works.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •