CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to support@ccsinfo.com

example CLC

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
MCUprogrammer



Joined: 08 Sep 2020
Posts: 220

View user's profile Send private message

example CLC
PostPosted: Wed Oct 26, 2022 8:52 am     Reply with quote

PIC16F19195
#use delay(clock = 32MHz,oscillator = 16MHz)
CCS C 5.112

I am trying to use the CLC peripheral. Controlling 3 inputs 1 output;
When the condition I wrote is met, the output will be 1, otherwise it will be 0. Where is the mistake? and How can I write the correct code.
Code:

 
#define INE                       PIN_C0
#define INA                       PIN_A0
#define INB                       PIN_B4

#pin_select CLCIN0 = INE
#pin_select CLCIN1 = INA
#pin_select CLCIN2 = INB

#define e_out                     PIN_C1
#define p_out                     PIN_A1

#pin_select CLC2OUT=p_out                     

 clc2_setup_gate(1, CLC_GATE_INVERTED_INPUT_1);         // !INA
 clc2_setup_gate(2, CLC_GATE_NON_INVERTED_INPUT_2); // INB
 clc2_setup_gate(3, CLC_GATE_NON_INVERTED_INPUT_3); // INE
 clc2_setup_gate(4, CLC_GATE_SET);
   
//setup CLC2
  setup_clc2(CLC_ENABLED | CLC_MODE_AND | CLC_OUTPUT_INVERTED);
  // INA=0, INB=1, INE=1 - p_out = 1, else  p_out = 0;

   

_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Wed Oct 26, 2022 10:47 am     Reply with quote

Common problem with CCS and the CLC.

You don't set the inversion with the input. Look in the .h file at what
is allowed for each command.

Just set the inputs (no inversion) for the four pins.
The input definitions are not what you are using:
CLC_INPUT_CLCIN1
etc..
The input selection, is _just_ the selection, nothing else.

Then you OR the CLC_GATE_INVERTED_INPUT1, with the CLC_GATE_AND.
MCUprogrammer



Joined: 08 Sep 2020
Posts: 220

View user's profile Send private message

PostPosted: Wed Oct 26, 2022 11:12 am     Reply with quote

I don't fully understand what you mean. If it won't be difficult, can you explain with a simple code example?
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Oct 27, 2022 5:25 am     Reply with quote

OK. May not be quite right, since I'm using PIC24's, not the 16, but basically
should be:
Code:

 clc2_setup_input(1, CLC_INPUT_CLCIN1 ); // !INA
 clc2_setup_input(2, CLC_INPUT_CLCIN2 ); // INB
 clc2_setup_input(3, CLC_INPUT_CLCIN3 ); // INE
//The defines you use for these must _only_ be the ones for the
//clc_setup_input commands, not those from other places

//So you now have the four inputs connected, now 
//set them up individually to the gate inputs
  clc2_setup_gate(1, CLC_GATE_INVERTED_INPUT_1); // !INA
  clc2_setup_gate(2, CLC_GATE_NON_INVERTED_INPUT_2 ); // INB
  clc2_setup_gate(3, CLC_GATE_NON_INVERTED_INPUT_3 ); // INE
  clc2_setup_gate(4, CLC_GATE_SET); //'1'
//The gate setup includes the selection to invert the input.

//setup CLC2
//Now the final CLC part
  setup_clc2(CLC_ENABLED | CLC_MODE_AND |
  CLC_OUTPUT_INVERTED );
  // INA=0, INB=1, INE=1 - p_out = 1, else  p_out = 0;
  //The CLC setup. Setup AND gte with it's output inverted


The point is the CLC_GATE_AND setup you are trying to use specifically
sets all four inputs to be logic '1'. Not the first input inverted that you
want. To do this you either have to make up your own combined setup,
or set them all separately as I show.

I think CLC_GATE_AND_FIRST_NOT would be 0x156

Best Wishes
MCUprogrammer



Joined: 08 Sep 2020
Posts: 220

View user's profile Send private message

PostPosted: Thu Oct 27, 2022 5:30 am     Reply with quote

That's how I did it, I just didn't use the invert event in the last code, it worked. and I started from CLCIN0. Thanks a lot for the support.
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Ttelmah



Joined: 11 Mar 2010
Posts: 19215

View user's profile Send private message

PostPosted: Thu Oct 27, 2022 5:39 am     Reply with quote

Good. Very Happy

It is silly actually. CCS have exactly followed the data sheet layout in
their setups, so you setup the inputs, then the gate selections, then
the actual logic gate. Very logical, but they really could do with a real
swathe of examples for this!...
MCUprogrammer



Joined: 08 Sep 2020
Posts: 220

View user's profile Send private message

PostPosted: Thu Oct 27, 2022 6:02 am     Reply with quote

Very Happy yes you think right
_________________
Best Regards...
MCUprogrammer
_______________________________
Work Hard
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group