Trying to implement the WS2811 driver--code debugging

Find out how to setup your programmer's software and how to solve many common problems.

Moderator: phalanx

Post Reply
walkingintheair
Posts: 4
Joined: Mon Feb 05, 2018 7:55 pm

Trying to implement the WS2811 driver--code debugging

Post by walkingintheair » Mon Apr 23, 2018 2:24 am

I'm attempting to implement the WS2811 driver described in app note AN1606 on a PIC16F18325. The app note is written for a PIC16F1509 so I can't just copy and paste the code, and it's nothing but magic numbers anyway so I prefer to re-write it. This implementation makes use of the CLC, PWM, and SPI peripherals to drive WS2811 RGB LEDs.
I would attach you the datasheet of PIC16F1509: http://www.kynix.com/uploadfiles/pdf879 ... _12796.pdf
I've never worked with the CLC before, so I'm not feeling entirely confident with the code I've written:

Code: Select all

void InitCLC(void) {
    RA5PPS = 0b00100; /* CLC1OUT on RA5 */
   
    CLC1SEL0bits.LC1D1S = 0b10011; /* CLC1 input 1 is SDO1 */
    CLC1SEL1bits.LC1D2S = 0b10010; /* CLC1 input 2 is SCK1 */
    CLC1SEL2bits.LC1D3S = 0b10000; /* CLC1 input 3 is PWM5OUT */
   
    CLC1GLS0 = 0x00;
    CLC1GLS1 = 0x00;
    CLC1GLS2 = 0x00;
    CLC1GLS3 = 0x00; /* Gate behavior is undefined at power-on so must be set to zero */
   
    CLC1GLS0bits.LC1G1D1T = 1; /* SDO input to AND gate 1 */
   
    CLC1GLS1bits.LC1G2D2T = 1; /* SCK input to AND gate 1 */
   
    CLC1GLS2bits.LC1G3D1N = 1;
    CLC1GLS2bits.LC1G3D2T = 1; /* nSDO && SCK input to AND gate 2 */
   
    CLC1GLS3bits.LC1G4D3T = 1; /* PWM5OUT input to AND gate 2 */
   
    CLC1POL = 0x00; /* Nothing is inverted */
   
    CLC1CONbits.LC1EN = 1; /* Enable CLC1 with AND-OR logic */
}
The goal is that the output of the CLC should be:
(SCK1 AND (NOT SDO1) AND PWM5OUT) OR (SCK1 AND SDO1)

One thing that has me confused is the wording on page 221 of the data sheet:
When the inputs and output are not inverted, the gate is an AND or all enabled inputs.
This seems to conflict with either Table 20-2 on the same page which shows AND as requiring inversion of both inputs and output, or else with the description of the bits in the CLC1POL register. I'm operating on the assumption that if I gate multiple data sources to the input while CLC1POL is 0, those values will be ANDed. Is that correct?

I probably have some other things that need to be debugged, but I'm more confident in my ability to deal with those. The CLC is intimidating since I've never worked with it before. Will the code I've posted above produce the output I'm expecting?

Many thanks guys. :)

User avatar
phalanx
Non-SFE Guru
Posts: 1964
Joined: Sun Nov 30, 2003 8:57 am
Location: Candia, NH

Re: Trying to implement the WS2811 driver--code debugging

Post by phalanx » Fri May 04, 2018 6:34 pm

It's been a while since you posted so I was curious if you have made any progress with your problem. I don't have any immediate experience with the nuances of the CLC module but I may have some time over the next day or two to look into it if you still need help.

-Bill

Post Reply