Now that my ZRC512 runs smoothly thanks to Bill and Wayne, I'll add to this topic some adventures I've had with NeoPixel-type RGB LEDs on the ZRC512 board.
td;lr Double-check the pinout of the "WS2812-type" LEDs you buy before powering-up - they may not have the same polarity as the ZRC512 board pinout (which is correct for Worldsemi's original WS2812B). Also, the order of the red and green colors can vary, ie GRB vs RGB.
I spent quite some time studying adverts on AliExpress to find information on WS2812-type LEDs (compatible or otherwise). Like usual, the far-East marketplace is a mess with advert titles containing lots of unnecessary and/or incorrect terms that, hopefully, search engines will latch onto.
Anyway, with some persistence, patterns can be found. The most important of which is that the manufacturers of these LEDs can't seem to agree on either the length or connections of the device's 4 leads.
So far I've found these four patterns of LED lead lengths:
Type 1: medium, long, medium, short
Type 2: long, long, short, short
Type 3: next longest, long, next shortest, short
Type 4: short, long, next shortest, short
The two inside leads always seem to be for VDD and GND. The outside two are for DIN and DOUT. However, a warning is appropriate here: a package's center leads DON'T always have the same polarity! And there are no markings on these LEDs (apart from lead lengths and, on most of them, one flat edge). I'm surprised that I couldn't find any information or warnings on the net regarding this. My guess is that nearly all of these LEDs are packaged as SMD and manufactured and sold in lengths with connections clearly marked. I certainly didn't find more than a couple of people blogging about the through-hole versions of these devices. The only remarks I found were about the order of the colors red and green, which can differ, ie some devices are GRB, others RGB.
Examples of pinouts I found: WS2812B APA-106 YF923-F8 Pololu "WS2812", 8mm
_______ <-flat
/ |1====== DOUT DOUT DOUT DOUT
/ Type 1 |2======== VDD GND GND GND <- note these
\ LED |3====== GND VDD VDD VDD <- two rows!
\_______|4==== DIN DIN DIN DIN
Sparkfun "WS2812",5mm YF923-F5 Pololu "WS2812",5mm
_______ <-flat
/ |1======== DOUT DOUT DOUT
/ Type 2 |2======== GND GND GND
\ LED |3====== VDD VDD VDD
\_______|4====== DIN DIN DIN
PL9823-F5/F8
_______ <-flat
/ |1======== DOUT
/ Type 3 |2========== GND
\ LED |3====== VDD
\_______|4==== DIN
Sparkfun "WS2812",Clear,5mm
_______ <-flat
/ |1==== DOUT
/ Type 4 |2======== GND
\ LED |3====== VDD
\_______|4==== DIN
Note: no guarantees that I got all the above data correct!
Then there's the order of the red and green colors; some LEDs are GRB, others RGB, ie RED and GREEN reversed.
I bought batches of 50 "WS2812"-type LEDs from 2 different AliExpress sellers. One batch was claimed to be WS2812D LEDs with the 'Type 1' pinout above, and 'DOUT-VDD-GND-DIN', which seems to the "correct" order from Worldsemi, AFAIK the originator of these series-programmable RGB LEDs.
The other batch also claimed to be WS2812D LEDs, although further down in the advert the "specification" had "Part No: YF923-F5-F8". And even much further down I found the 5mm package had the 'Type 2' pinout above, with 'DOUT-GND-VDD-DIN'. Note the reversed polarity of the two batches, something I only understood later on. Interestingly, all of the look-alike LEDs I found, ie, not using a WS2812x chip, have the opposite polarity.
The ZRC512 board has the "Worldsemi WS2812x" LED pinout 'DOUT-VDD-GND-DIN' and I just happened to start testing with the YF923-F5 LED. Using DOUT as a reference, I plugged the LED just loosely into the holes on the board.
I powered up the ZRC512 after having assembled and uploaded Bill's WS2812 test program to a CP/M drive on the CF card. Ran the program and nothing happened. After a number of tries, I decided it was probably a good idea to learn a bit more about what I was doing.
That's when I discovered that these through-hole LED's 2 center leads can have the opposite polarity, ie VDD & GND reversed! Turns out I had killed off the first LED I tried, but before realizing that, and thinking the first one had been a dud, I managed to kill off yet a another one. Well that's why you buy a batch of 50 LEDs, right?
So, without any guarantees that the other batch of LEDs (the WS2812D) was wired any differently, I popped one in the board, powered-up again and re-ran the test program. Wow, it lives! And in glorious RED.
Modifying the test program, I also got GREEN, BLUE and WHITE to turn on.
Then the YF923-F5 LED (after 're-wiring' it) went through with flying colors (pun intended ;)) although RED and GREEN were reversed as expected (GRB for WS2812x, RGB for YF923-F5-F8).
In conclusion, the current bit-banged code works well with both LEDs. Nice work Bill!
Now I've only tried one LED so far. Bill's test program is written to control two LEDs, but I've studied the code and don't completely understand how the second line in 'ledTbl' works.
Here's the test program:
; test program for WS2812B pixel addressable LED
WS2812 equ 1eh ;bit bang WS2812
org 100h
jp start
ledTbl: db 0,8,0
db 10h,0,0
start:
di
ld hl,ledTbl
ld a,(hl)
ld b,8
doGrn:
out (WS2812),a ;11
rla ;4
djnz doGrn ;13 or 8 B==0
ld b,8 ;7
inc hl ;6
ld a,(hl) ;7
doRed:
out (WS2812),a
rla
djnz doRed
ld b,8
inc hl
ld a,(hl)
doBlue:
out (WS2812),a
rla
djnz doBlue
ld b,8
inc hl
ld a,(hl)
;second LED
doGrn2:
out (WS2812),a ;11
rla ;4
djnz doGrn2 ;13 or 8 B==0
ld b,8 ;7
inc hl ;6
ld a,(hl) ;7
doRed2:
out (WS2812),a
rla
djnz doRed2
ld b,8
inc hl
ld a,(hl)
doBlue2:
out (WS2812),a
rla
djnz doBlue2
ei
ld c,0 ;return to cp/m prompt
jp 5
end
I've (mostly) figured out what the first line in 'ledTbl' does:
db 0,8,0 sets the 1st LED GRB colors to G="0" OFF, R="8" ON and B="0" OFF
But I don't follow how the second line works (apart from that it should somehow set the 2nd LED's colors):
db 10h,0,0
I realize that the code needs to get the timing right, so I suspect some intricate algorithm is at work here.
Help, Bill, or anyone else wanting to chip in?
Thanks,
Paul