The tough part about using NeoPixels is the 1-wire control protocol. Frankly, looking at the WS2812 Data Sheet for the first time gave me the creeps!

I like my protocols & interfacing simple.  This ain't quite what I had in mind.  So what now?

OK, if you stand right here and squint like this and the light is just right...there it is!  There is a way to push a little here, pull a little there, and get the "0-code" and "1-code" overall durations to match while still having reasonable T0H and T1H times.  That's what I needed because I'm using one of the PIC CCP (Capture Compare PWM) modules in PWM mode to create 0's and an additional CCP in PWM mode to create 1's.  The CCP's in PWM mode have some constraints and this (from the PIC's Data Sheet) is pretty much all I know:

Ha!  Now I have a constant stream of 0's and a constant stream of 1's.  Great.  Full on or full off - take your pick. However, I want this clock to be colorful which means I need 0's and 1's intermixed.  To do that, there's a wicked-cool little spoonfull of voodoo in the PIC's bag of tricks - the Data Signal Modulator (DSM):

Now this is cool: one "carrier" is the PWM stream of 0 bits and the other "carrier" is the PWM stream of 1 bits.  The "modulated data" will be the output of one of the MSSP's in SPI mode.  This is coming together!

Then Reality comes stomping in and kicks your nice little Lego house all over the room: the MSSP in SPI mode simply will not be convinced to output bytes back-to-back.  There's no way around this little 1 clock lapse between bytes transmitted by the SPI hardware.  Well, that just throws a big ol' monkey wrench into my plan...

So instead, I'll try something else - pushing data through bit-by-bit via the handy MDBIT input to the DSM.  

That's where this portion of the adventure ended up - with a little help from the interrupt-on-change inputs so the code can know exactly when to flip MDBIT to a 0 or a 1 to keep the output bitstream coherent.  It's not as fire-and-forget as SPI but I did indeed learn a lot while writing (and rewriting and rewriting...) those 400 lines of PIC assembly.  WooHoo FUN!

So now I can finally talk to this thing - what do I want to tell it?

This guide was first published on Aug 18, 2014. It was last updated on Aug 18, 2014.

This page (Rubber, meet Road) was last updated on Apr 10, 2021.

Text editor powered by tinymce.