WS2812b Led discussion

Posts: 40

Joined: Sat Nov 11, 2017 1:18 pm

Post Sat May 19, 2018 3:37 pm

WS2812b Led discussion

I am interested in getting more information related to the code to pilot the WS2812b LEDs.
The LEDs works correctly but I don't understand how it can be.

I study the source code and I don't understand how it can work for two reasons (see below). I probably missed something, could you help me to understand?

Reason 1 :
After Powering on, there is two successive calls to LEDon that make the right Led flash in green
These calls are made at lines 463 to 470 just before the instruction "GOTO START"
My question is: Why the Right LED is flashing in green ? I ask this because the registers LEDbuffer (0x50 to 0x58) are all cleared at that moment.
We should have LEDRG (and LEDMG, LEDLG) initialized with a value (e.g. bit 5 at value 1): and I see no initialization of these registers before the 2 calls to LEDon.

Reason 2:
When looking at the subroutine LEDon,it seems that the timings provided in the WS2818 are not respected:
The datasheet recommends :
- to send a 1 : T1H = 0.8us+/-150ns and T1L=0.45us +/-150ns
- to send a 0: T0H = 0.4us+/-150ns and T0L=0.85us +/-150ns

When looking at the code (LEDon) it appears that:
- to send a 1 the instructions are:
bsf PORTA,1 ;Send '1'
decfsz DVAR,F

bsf will take 1 cycle; nop will take 1 cycle: the oscillator is 14,7456Mhz so 1 cycle is 4x(oscillator period) = 0,27us
so, these two instructions (bsf, nop) will take 0,54us : this is correct, we are within the specification range. the problem is that there is no bcf instruction just after and the RCA will remain to 1...It seems that a "bcf" is missing here .

- to send a 0, the instructions are:
bsf PORTA,1 ;Send '0'
bcf PORTA,1
goto LEDback

Here we can see that the level 1 (bsf) will stay for 1 cycle : that means 0.27us and that seems OK (T0Hmin=0.22us)
and for the level 0 (bcf, nop) will stay 2 cycles : that means 0.54us but it is followed by other instructions (goto LEDback, decfsz DVAR,F...), so PORTA,1 will be at 0 for far longer than the maximum delay specified in the datasheet...

I can't understand how it is possible to pilot the LEDs with that code...
Could you explain where I am wrong in my analysis?

Thanks a lot in advance for your help in that! It makes me crazy not to understand !

in attached file is the source code I used for my analysis.
Base piccode.rar
(14.29 KiB) Downloaded 199 times

Site Admin

Posts: 950

Joined: Tue Jul 24, 2012 8:05 pm

Post Thu Jun 07, 2018 1:35 pm

Re: WS2812b Led discussion

The code was written by trial and error, the first version which constructed timing (checked with a Tektronix DPO) according to the datasheet didn't work.The green flash isn't programmed and is a 'feature', probably due to a bit set on initialisation that is shifted out into the shift registers.

Return to 3 - Levitation base

Who is online

Users browsing this forum: No registered users and 1 guest

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software