PIC18F4525 and WS2803 LED driver, asm code

Thread Starter

thejmh

Joined Jul 3, 2009
12
Hello!

I'm trying to get these two devices to communicate, without any success yet. The WS2803 is a 18 channel constant current LED driver. 2-wire communication to transmit the grayscale data, 8bits/channel. Max clock frequency up to 25MH.

http://www.jarzebski.pl/datasheets/WS2803.pdf

Operation:
After a single pulse on the CKI pin and the signal keeps LOW more than 600us, the internal logic control circuitry resets. Once reset, the internal circuitry is waiting for a positive pulse on the CKI pin. At this state, the signal on SDI pin is shifted in to the internal data registers. Once total 144 pulses are detected, WS2803 will latch the signal from the shift registers and begin the PWM operation.

I'm using a 10MHz crystal, PLL enabled and the PIC is operating at 40MHz. I'm pretty sure that all wirings are right. Common anode LEDs, anodes to +5V and cathodes to WS2803 channel pins. 1k5 resistor fom ground to IREF pin. My goal is to use the SPI at 10MHz speed but at first I'm just trying to get LEDs lit using bit bang. This code sends 0xFF to all channels. Is there something wrong in my code? Delay times maybe?
Thanks!

Code:
         bcf  PORTA,DAI
         bsf  PORTA,CKI        ; Short pulse CKI
         nop
         nop
         bcf  PORTA,CKI     

; Delay 600us, preparing cycle
         movlw   0xAF
         movwf   delayreg1
         movlw   0x05
         movwf   delayreg2
Delay_loop
         decfsz  delayreg1,f
         goto    $+2
         decfsz  delayreg2,f
         goto    Delay_loop
         nop
         nop

;Send 144 times 1 to DAI pin (=0xFF to all 18 channels)
         movlw   0x90            ; 144 to counter
         movwf   TEMP

         bsf     PORTA,DAI       ; Set data bit
         nop
         nop
         nop
         nop
Send_again
         bsf     PORTA,CKI       ; Clock pulse rising edge
         nop
         nop
         nop
         nop
         bcf     PORTA,CKI       ; Cloc pulse falling edge
         bcf     PORTA,DAI       ; Clear data bit
         bsf     PORTA,DAI       ; Set data bit again
         decfsz  TEMP            ; 144 clock pulses sent?
         goto    Send_again      ; not yet, send more
         bcf     PORTA,DAI       ; all sent
         goto    MAIN
 

dannyf

Joined Sep 13, 2015
2,197
You should make sure that the pins output the right waveform, and compare that vs. The ws2803s output.

But if I were you, I would try to make sure that can blink an led on the two serial pins first.
 

Thread Starter

thejmh

Joined Jul 3, 2009
12
Here's my SPI version, doesn't work either.

Code:
          ; SPI SETUP
          movlw   b'01000000'   ; Input data sampled at end of data output time, CKE=1, SMP=0
          movwf   SSPSTAT

          movlw   b'00100000'   ; Enable serial port, SPI mastermode, FOSC/4, CKP Clock Polarity Select bit=0
          movwf   SSPCON1



          bcf     SSPCON1,5    ; Serial port off. PORTC,3 is set as digital output.
          bsf     PORTC,CKI    ; Single pulse
          nop
          nop
          nop
          bcf     PORTC,CKI  
                      
          ; delay 600us Preparing cycle
          movlw    0xAF
          movwf    delayreg1
          movlw    0x05
          movwf    delayreg2
Delay_0
          decfsz   delayreg1,f
          goto     $+2
          decfsz   delayreg2,f
          goto     Delay_0
          nop
          nop               

          bsf     SSPCON1,5   ; Serial port on

          ; SPI data send
          movlw   0x12        ; 18 to counter, counts 18 bytes
          movwf   bytecounter

Send_again    
          movlw   0xFF      
          movwf   SSPBUF            ; place data in send buffer
SPIloop
          btfss   SSPSTAT,BF        ; has data been received?
          goto    SPIloop           ; loop if not received yet
          movff   SSPBUF,rxdata     ; empty the receive buffer

          decfsz  bytecounter,f     ; All 18 bytes sent?
          goto    Send_again        ; Not yet, send more
          goto    MAIN
 

Thread Starter

thejmh

Joined Jul 3, 2009
12
How are your configuration bits set?
Code:
CONFIG OSC = HSPLL
CONFIG FCMEN = OFF
CONFIG IESO = OFF
CONFIG PWRT = ON
CONFIG DEBUG = OFF
CONFIG BOREN = OFF
CONFIG WDT = OFF
CONFIG MCLRE = OFF
CONFIG PBADEN = OFF
CONFIG CCP2MX = PORTC
CONFIG STVREN = ON
CONFIG LVP = OFF
 

JohnInTX

Joined Jun 26, 2012
4,787
Just dropping in but it might be a good idea to post ALL of your code. Some of us have been known to load member's code into our own systems, debug it and tell you what's wrong.
 

Thread Starter

thejmh

Joined Jul 3, 2009
12
Just dropping in but it might be a good idea to post ALL of your code. Some of us have been known to load member's code into our own systems, debug it and tell you what's wrong.
Well, my whole code is quite huge including LDC menus, SPI EEPROM, switch matrix, different operations... Those other areas are working perfectly. In my project I have isolated the part of the code that isn't working and posted it here. It's just the communication between PIC and WS2803. It's quite short and if anyone is willing to try it I'd be very glad, or if anyone already has a working asm code for WS2803 I would like to try it also. If someone can confirm the problem isn't in my code, then I know it's somewhere else and know where to look for next.
 
Last edited:

JohnInTX

Joined Jun 26, 2012
4,787
Well, my code is quite huge including LDC menus, SPI EEPROM, switch matrix, different operations... Those other areas are working perfectly. In my project I have isolated the part of the code that isn't working and posted it here. It's quite short and if anyone is willing to test it I'd be very glad. If it works, then I know that the problem is somewhere else and know where to look for next.
Fair enough. Just thought I'd throw it out.
 
Top