View previous topic :: View next topic |
Author |
Message |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
example CLC |
Posted: Wed Oct 26, 2022 8:52 am |
|
|
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: 19549
|
|
Posted: Wed Oct 26, 2022 10:47 am |
|
|
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: 221
|
|
Posted: Wed Oct 26, 2022 11:12 am |
|
|
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: 19549
|
|
Posted: Thu Oct 27, 2022 5:25 am |
|
|
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: 221
|
|
Posted: Thu Oct 27, 2022 5:30 am |
|
|
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: 19549
|
|
Posted: Thu Oct 27, 2022 5:39 am |
|
|
Good.
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: 221
|
|
Posted: Thu Oct 27, 2022 6:02 am |
|
|
yes you think right _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
|
|