PDA

View Full Version : PIC to WS2812B / WS2811 IC



comwarrior
- 23rd October 2013, 14:26
Im sure people have seen the WS2812 and WS2812B's on youtube and ebay.
They are a tri colour LED with built in constant current controller chip.

The arduino community is all over them but I've found nothing for pic's, so, i've tried to do it my self and i'm now a little stuck and could do with some help.

The constant current chip is the WS2811. The chip itself has two speeds, 400KHz or 800KHz. the WS2812 runs at 400KHz and the WS2812B runs at 800KHz.
Communication to these devices is via a daisy chain with a NRZ type wave form. Each chip has 3 channels with 8 bit PWM.
So, at 800KHz to send a 1 bit you send a high pulse of duration 0.8uS and the a low of 0.45uS.
To send a 0 bit you send a high pulse of durations 0.4uS and then a low of 0.85uS.
Total bit lenght is 1.25uS +-300nS
The timing tolerances are +-150nS

Now, the arduino's run entire strings of these things with the MCU running at 8MHz so one would think a 64MHz 18F46K22 would not have an issue...

However, when i kick out a sequence manually like this...




LATD.0 = 1
ASM
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;10
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;20
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;30
nop
nop
nop
nop
nop
nop
nop
nop
;38


ENDASM
LATD.0 = 0
ASM
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;10
nop
nop
nop
nop
nop
nop
nop
nop
nop
nop
;20
nop
nop
nop
nop
nop
nop
nop
nop
nop
;29

ENDASM



Everything works fine. Even using GOSUB's to the on and off bit subroutines works without an issue after a little trimming by trial and error (as above).
However, as soon as i use any sort of IF statement to read from an array, all the timings seem to go out the window and i can not adjust it enough to compensate.

My calcs say that the 46K22 @ 64MHz makes 64 instructions per uS.
Even if i cut off all the NOP's from the off time trailing sequence the pic still can not make the calculations (IF condition) within the required time.

I have tried everything i can think of so far, i was wondering if anyone had any other suggestions?

Thanks

spcw1234
- 23rd October 2013, 18:21
I am also going to be playing with these, but won't have it until the end of the week. Hopefully we can make these things work! Link to my thread (http://www.picbasic.co.uk/forum/showthread.php?t=18431)

Amoque
- 24th October 2013, 01:51
Somewhere here, I looked... I cannot find it... are some code examples for timing execution of code segments; they might be of value to you. Even without, it should be reasonably straightforward to initialize/ start a timer and read the value after to determine exact timing of the If [] Then statements. I have not used the WS LED strings, but I think you don't need help with what is required to do so - only to determine how long what you have takes.

My understanding of such things is limited, but I can "grok" the frustration of timing routines that are written in Basic, but executed in Assembler. I can think of no simpler way than to have your program do it for you.

Ah HA! Here: http://www.picbasic.co.uk/forum/showthread.php?t=9350

One last ting... Have you any numbers for amperage required to run a string of these things? I suspect it could run into the 10's of amps for applications like Christmas lights?

comwarrior
- 26th October 2013, 01:17
Each chip is current limited to ~19mA per channel... and there is 3 channels...

matt79
- 4th March 2014, 02:46
Hello forum! I've got example code working to control a WS2812B LED strip (http://www.ledlightinghut.com/144-led-m-ws2812-digital-intelligent-rgb-led-strip-light.htmlhttp://). I used SPI at 15MHz to get the WS2812B to pay attention and work with the 150ns timing. Works well but I'm not savvy enough at squirrel to really get this code running efficiently.

The full example code is here: https://gist.github.com/nseidle/66d8966463aabee7e6ac#file-gistfile1-txt

PhilXu007
- 19th January 2018, 17:14
it seems the sk6812 (http://addressable-led.com/Products/sk6812-5050-rgb-led.html) is faster PWM frequency than the ws2812b,
and can use the same code as the ws2811,ws2812b

Ioannis
- 19th January 2018, 19:37
Why not use APA101 that is more easy to handle?

Ioannis