Recent

Author Topic: Questions about CLC inputs on PIC16F18325  (Read 2512 times)

Teddie

  • Newbie
  • Posts: 2
Questions about CLC inputs on PIC16F18325
« on: February 21, 2017, 10:31:05 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.
PIC16F1509 PDF
I've never worked with the CLC before, so I'm not feeling entirely confident with the code I've written. The goal is that the output of the CLC should be:
 
(SCK1 AND (NOT SDO1) AND PWM5OUT) OR (SCK1 AND SDO1)
 
This is the code I've written:
Code: Pascal  [Select][+][-]
  1. void InitCLC(void) {
  2.     RA5PPS = 0b00100; /* CLC1OUT on RA5 */
  3.    
  4.     CLC1SEL0bits.LC1D1S = 0b10011; /* CLC1 input 1 is SDO1 */
  5.     CLC1SEL1bits.LC1D2S = 0b10010; /* CLC1 input 2 is SCK1 */
  6.     CLC1SEL2bits.LC1D3S = 0b10000; /* CLC1 input 3 is PWM5OUT */
  7.    
  8.     CLC1GLS0 = 0x00;
  9.     CLC1GLS1 = 0x00;
  10.     CLC1GLS2 = 0x00;
  11.     CLC1GLS3 = 0x00; /* Gate behavior is undefined at power-on so must be set to zero */
  12.    
  13.     CLC1GLS0bits.LC1G1D1T = 1; /* SDO input to AND gate 1 */
  14.    
  15.     CLC1GLS1bits.LC1G2D2T = 1; /* SCK input to AND gate 1 */
  16.    
  17.     CLC1GLS2bits.LC1G3D1N = 1;
  18.     CLC1GLS2bits.LC1G3D2T = 1; /* nSDO && SCK input to AND gate 2 */
  19.    
  20.     CLC1GLS3bits.LC1G4D3T = 1; /* PWM5OUT input to AND gate 2 */
  21.    
  22.     CLC1POL = 0x00; /* Nothing is inverted */
  23.    
  24.     CLC1CONbits.LC1EN = 1; /* Enable CLC1 with AND-OR logic */
  25. }

One thing that has me confused is the wording on page 221 of the data sheet:
 
Quote
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?

Thaddy

  • Hero Member
  • *****
  • Posts: 14197
  • Probably until I exterminate Putin.
Re: Questions about CLC inputs on PIC16F18325
« Reply #1 on: February 21, 2017, 11:41:44 am »
The usual way to express ourselves on this forum is more like:
Code: Pascal  [Select][+][-]
  1. begin
  2.     RA5PPS := $b00100; (* CLC1OUT on RA5 *)
  3.    
  4.     CLC1SEL0bits.LC1D1S := $b10011; (* CLC1 input 1 is SDO1 *)
  5.     CLC1SEL1bits.LC1D2S := $b10010; (* CLC1 input 2 is SCK1 *)
  6.     CLC1SEL2bits.LC1D3S := $b10000; (* CLC1 input 3 is PWM5OUT *)
  7.    
  8.     CLC1GLS0 := $00;
  9.     CLC1GLS1 := $00;
  10.     CLC1GLS2 := $00;
  11.     CLC1GLS3 := $00; (* Gate behavior is undefined at power-on so must be set to zero *)
  12.    
  13.     CLC1GLS0bits.LC1G1D1T := 1; (* SDO input to AND gate 1 *)
  14.    
  15.     CLC1GLS1bits.LC1G2D2T := 1; (* SCK input to AND gate 1 *)
  16.    
  17.     CLC1GLS2bits.LC1G3D1N := 1;
  18.     CLC1GLS2bits.LC1G3D2T := 1; (* nSDO && SCK input to AND gate 2 *)
  19.    
  20.     CLC1GLS3bits.LC1G4D3T := 1; (* PWM5OUT input to AND gate 2 *)
  21.    
  22.     CLC1POL := $00; (* Nothing is inverted *)
  23.    
  24.     CLC1CONbits.LC1EN := 1; (* Enable CLC1 with AND-OR logic *)
  25. end.

But it has a dependency on an external library, so even if...... >:( >:(

Much more readable, don't you think? O:-)
I also can't find this one in the supported microcontroller types, but I may be wrong.

Note that IF it happens to be supported and IF you resolve the dependency my code would possibly work without change as long as CLC1GLS0bits is declared as a bitpacked record.

Note a PIC16F18325 is very cheap. Burn some trying... :'(

(To help a little: You are close or even on the right track, but this is a Pascal forum)
« Last Edit: February 21, 2017, 12:01:17 pm by Thaddy »
Specialize a type, not a var.

marcov

  • Administrator
  • Hero Member
  • *
  • Posts: 11382
  • FPC developer.
Re: Questions about CLC inputs on PIC16F18325
« Reply #2 on: February 21, 2017, 12:03:45 pm »
offtopic -> locked.

 

TinyPortal © 2005-2018