PIC18F4525 and WS2803 LED driver, asm code

Discussion in 'Embedded Systems and Microcontrollers' started by thejmh, Jul 6, 2016.

  1. thejmh

    Thread Starter Member

    Jul 3, 2009
    12
    0
    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 (Text):
    1.  
    2.          bcf  PORTA,DAI
    3.          bsf  PORTA,CKI        ; Short pulse CKI
    4.          nop
    5.          nop
    6.          bcf  PORTA,CKI    
    7.  
    8. ; Delay 600us, preparing cycle
    9.          movlw   0xAF
    10.          movwf   delayreg1
    11.          movlw   0x05
    12.          movwf   delayreg2
    13. Delay_loop
    14.          decfsz  delayreg1,f
    15.          goto    $+2
    16.          decfsz  delayreg2,f
    17.          goto    Delay_loop
    18.          nop
    19.          nop
    20.  
    21. ;Send 144 times 1 to DAI pin (=0xFF to all 18 channels)
    22.          movlw   0x90            ; 144 to counter
    23.          movwf   TEMP
    24.  
    25.          bsf     PORTA,DAI       ; Set data bit
    26.          nop
    27.          nop
    28.          nop
    29.          nop
    30. Send_again
    31.          bsf     PORTA,CKI       ; Clock pulse rising edge
    32.          nop
    33.          nop
    34.          nop
    35.          nop
    36.          bcf     PORTA,CKI       ; Cloc pulse falling edge
    37.          bcf     PORTA,DAI       ; Clear data bit
    38.          bsf     PORTA,DAI       ; Set data bit again
    39.          decfsz  TEMP            ; 144 clock pulses sent?
    40.          goto    Send_again      ; not yet, send more
    41.          bcf     PORTA,DAI       ; all sent
    42.          goto    MAIN
     
  2. dannyf

    Well-Known Member

    Sep 13, 2015
    1,810
    362
    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.
     
  3. thejmh

    Thread Starter Member

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

    Code (Text):
    1.  
    2.          
    3.           ; SPI SETUP
    4.           movlw   b'01000000'   ; Input data sampled at end of data output time, CKE=1, SMP=0
    5.           movwf   SSPSTAT
    6.  
    7.           movlw   b'00100000'   ; Enable serial port, SPI mastermode, FOSC/4, CKP Clock Polarity Select bit=0
    8.           movwf   SSPCON1
    9.  
    10.  
    11.  
    12.           bcf     SSPCON1,5    ; Serial port off. PORTC,3 is set as digital output.
    13.           bsf     PORTC,CKI    ; Single pulse
    14.           nop
    15.           nop
    16.           nop
    17.           bcf     PORTC,CKI  
    18.                      
    19.           ; delay 600us Preparing cycle
    20.           movlw    0xAF
    21.           movwf    delayreg1
    22.           movlw    0x05
    23.           movwf    delayreg2
    24. Delay_0
    25.           decfsz   delayreg1,f
    26.           goto     $+2
    27.           decfsz   delayreg2,f
    28.           goto     Delay_0
    29.           nop
    30.           nop              
    31.  
    32.           bsf     SSPCON1,5   ; Serial port on
    33.  
    34.           ; SPI data send
    35.           movlw   0x12        ; 18 to counter, counts 18 bytes
    36.           movwf   bytecounter
    37.  
    38. Send_again    
    39.           movlw   0xFF      
    40.           movwf   SSPBUF            ; place data in send buffer
    41. SPIloop
    42.           btfss   SSPSTAT,BF        ; has data been received?
    43.           goto    SPIloop           ; loop if not received yet
    44.           movff   SSPBUF,rxdata     ; empty the receive buffer
    45.  
    46.           decfsz  bytecounter,f     ; All 18 bytes sent?
    47.           goto    Send_again        ; Not yet, send more
    48.           goto    MAIN
    49.  
     
  4. GopherT

    AAC Fanatic!

    Nov 23, 2012
    6,045
    3,811
    How are your configuration bits set?
     
  5. thejmh

    Thread Starter Member

    Jul 3, 2009
    12
    0
    Code (Text):
    1. CONFIG OSC = HSPLL
    2. CONFIG FCMEN = OFF
    3. CONFIG IESO = OFF
    4. CONFIG PWRT = ON
    5. CONFIG DEBUG = OFF
    6. CONFIG BOREN = OFF
    7. CONFIG WDT = OFF
    8. CONFIG MCLRE = OFF
    9. CONFIG PBADEN = OFF
    10. CONFIG CCP2MX = PORTC
    11. CONFIG STVREN = ON
    12. CONFIG LVP = OFF
     
  6. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,028
    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.
     
  7. thejmh

    Thread Starter Member

    Jul 3, 2009
    12
    0
    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: Jul 7, 2016
  8. JohnInTX

    Moderator

    Jun 26, 2012
    2,345
    1,028
    Fair enough. Just thought I'd throw it out.
     
Loading...