View previous topic :: View next topic |
Author |
Message |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
CLC problem |
Posted: Wed Feb 22, 2023 3:44 am |
|
|
I used MPLAB X IDE GUI. I copied the resulting code and added it with getenv(). But when I compile I get an error. The error I get is: Expecting an identifier Bad SFR name.
CCS C 5.114
Code: |
#include <18F57Q43.h>
#use delay(internal=64MHz)
#byte CLCSELECT = getenv("SFR:CLCSELECT")
#byte CLCnPOL = getenv("SFR:CLCnPOL")
#byte CLCnSEL0 = getenv("SFR:CLCnSEL0")
#byte CLCnSEL1 = getenv("SFR:CLCnSEL1")
#byte CLCnSEL2 = getenv("SFR:CLCnSEL2")
#byte CLCnSEL3 = getenv("SFR:CLCnSEL3")
#byte CLCnGLS0 = getenv("SFR:CLCnGLS0")
#byte CLCnGLS1 = getenv("SFR:CLCnGLS1")
#byte CLCnGLS2 = getenv("SFR:CLCnGLS2")
#byte CLCnGLS3 = getenv("SFR:CLCnGLS3")
#byte CLCDATA = getenv("SFR:CLCDATA")
#byte CLCnCON = getenv("SFR:CLC1CON")
void CLC1_Initialize(void) // CLCIN0=0,CLCIN1=0,CLCIN2=1 CLCOUT(F0) = 0 else = 1
{
// Set the CLC1 to the options selected in the User Interface
// SLCT 0;
CLCSELECT = 0x00;
// G1POL not_inverted; G2POL not_inverted; G3POL not_inverted; G4POL inverted; POL not_inverted;
CLCnPOL = 0x08;
// D1S CLCIN0 (CLCIN0PPS);
CLCnSEL0 = 0x00;
// D2S CLCIN1 (CLCIN1PPS);
CLCnSEL1 = 0x01;
// D3S CLCIN2 (CLCIN2PPS);
CLCnSEL2 = 0x02;
// D4S CLCIN0 (CLCIN0PPS);
CLCnSEL3 = 0x00;
// G1D3N disabled; G1D2N disabled; G1D4N disabled; G1D1T disabled; G1D3T disabled; G1D2T disabled; G1D4T disabled; G1D1N enabled;
CLCnGLS0 = 0x01;
// G2D2N enabled; G2D1N disabled; G2D4N disabled; G2D3N disabled; G2D2T disabled; G2D1T disabled; G2D4T disabled; G2D3T disabled;
CLCnGLS1 = 0x04;
// G3D1N disabled; G3D2N disabled; G3D3N enabled; G3D4N disabled; G3D1T disabled; G3D2T disabled; G3D3T disabled; G3D4T disabled;
CLCnGLS2 = 0x10;
// G4D1N disabled; G4D2N disabled; G4D3N disabled; G4D4N disabled; G4D1T disabled; G4D2T disabled; G4D3T disabled; G4D4T disabled;
CLCnGLS3 = 0x00;
// CLC1OUT 0;
CLCDATA = 0x00;
// EN enabled; INTN disabled; INTP disabled; MODE 4-input AND;
CLCnCON = 0x82;
}
void main(void)
{
CLC1_Initialize();
while(TRUE)
{
}
} |
_________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Wed Feb 22, 2023 5:24 am |
|
|
It looks as if getenv doesn't know all the CLC register names. Report it
to CCS. Meantime the automatic file generator (in tools), happily generates
an include file for CLC as:
Code: |
#byte CLCnGLS3 = 0x0DF
#bit G4D1N = CLCnGLS3.0
#bit G4D1T = CLCnGLS3.1
#bit G4D2N = CLCnGLS3.2
#bit G4D2T = CLCnGLS3.3
#bit G4D3N = CLCnGLS3.4
#bit G4D3T = CLCnGLS3.5
#bit G4D4N = CLCnGLS3.6
#bit G4D4T = CLCnGLS3.7
#byte CLCnGLS2 = 0x0DE
#bit G3D1N = CLCnGLS2.0
#bit G3D1T = CLCnGLS2.1
#bit G3D2N = CLCnGLS2.2
#bit G3D2T = CLCnGLS2.3
#bit G3D3N = CLCnGLS2.4
#bit G3D3T = CLCnGLS2.5
#bit G3D4N = CLCnGLS2.6
#bit G3D4T = CLCnGLS2.7
#byte CLCnGLS1 = 0x0DD
#bit G2D1N = CLCnGLS1.0
#bit G2D1T = CLCnGLS1.1
#bit G2D2N = CLCnGLS1.2
#bit G2D2T = CLCnGLS1.3
#bit G2D3N = CLCnGLS1.4
#bit G2D3T = CLCnGLS1.5
#bit G2D4N = CLCnGLS1.6
#bit G2D4T = CLCnGLS1.7
#byte CLCnGLS0 = 0x0DC
#bit G1D1N = CLCnGLS0.0
#bit G1D1T = CLCnGLS0.1
#bit G1D2N = CLCnGLS0.2
#bit G1D2T = CLCnGLS0.3
#bit G1D3N = CLCnGLS0.4
#bit G1D3T = CLCnGLS0.5
#bit G1D4N = CLCnGLS0.6
#bit G1D4T = CLCnGLS0.7
#byte CLCnSEL3 = 0x0DB
#byte CLCnSEL2 = 0x0DA
#byte CLCnSEL1 = 0x0D9
#byte CLCnSEL0 = 0x0D8
#byte CLCnPOL = 0x0D7
#bit G1POL = CLCnPOL.0
#bit G2POL = CLCnPOL.1
#bit G3POL = CLCnPOL.2
#bit G4POL = CLCnPOL.3
#bit POL = CLCnPOL.7
#byte CLCnCON = 0x0D6
#bit MODE0 = CLCnCON.0
#bit MODE1 = CLCnCON.1
#bit MODE2 = CLCnCON.2
#bit INTN = CLCnCON.3
#bit INTP = CLCnCON.4
#bit OUT = CLCnCON.5
#bit OE = CLCnCON.6
#bit EN = CLCnCON.7
#byte CLCSELECT = 0x0D5
#byte CLCDATA = 0x0D4
#bit CLC1OUT = CLCDATA.0
#bit CLC2OUT = CLCDATA.1
#bit CLC3OUT = CLCDATA.2
#bit CLC4OUT = CLCDATA.3
#bit CLC5OUT = CLCDATA.4
#bit CLC6OUT = CLCDATA.5
#bit CLC7OUT = CLCDATA.6
#bit CLC8OUT = CLCDATA.7
|
Which should get you going. |
|
![](templates/subSilver/images/spacer.gif) |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Wed Feb 22, 2023 7:27 am |
|
|
I sent an email to CCS. I added what you did to the code. There was no problem in compiling. But I didn't see any movement at the exit. _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Wed Feb 22, 2023 8:02 am |
|
|
You seem to be trying to setup a 3 input OR gate. (AND, with all the
inputs inverted, using three physical inputs, and one pin wired high).
You don't show the PPS setups for CLCIN0, CLCIN1 or CLCIN2.
Remember you have to enable the TRIS on the pin used as the CLC
output. By default all pins are set as inputs. |
|
![](templates/subSilver/images/spacer.gif) |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Wed Feb 22, 2023 8:16 am |
|
|
CLCIN0 PIN_A0
CLCIN1 PIN_A1
CLCIN2 PIN_B0
CLCOUT PIN_F0
Code: |
#include <18F57Q43.h>
#use delay(crystal = 16MHz)
#use FAST_IO(a)
#use FAST_IO(b)
#use FAST_IO(d)
#byte CLCnGLS3 = 0x0DF
#bit G4D1N = CLCnGLS3.0
#bit G4D1T = CLCnGLS3.1
#bit G4D2N = CLCnGLS3.2
#bit G4D2T = CLCnGLS3.3
#bit G4D3N = CLCnGLS3.4
#bit G4D3T = CLCnGLS3.5
#bit G4D4N = CLCnGLS3.6
#bit G4D4T = CLCnGLS3.7
#byte CLCnGLS2 = 0x0DE
#bit G3D1N = CLCnGLS2.0
#bit G3D1T = CLCnGLS2.1
#bit G3D2N = CLCnGLS2.2
#bit G3D2T = CLCnGLS2.3
#bit G3D3N = CLCnGLS2.4
#bit G3D3T = CLCnGLS2.5
#bit G3D4N = CLCnGLS2.6
#bit G3D4T = CLCnGLS2.7
#byte CLCnGLS1 = 0x0DD
#bit G2D1N = CLCnGLS1.0
#bit G2D1T = CLCnGLS1.1
#bit G2D2N = CLCnGLS1.2
#bit G2D2T = CLCnGLS1.3
#bit G2D3N = CLCnGLS1.4
#bit G2D3T = CLCnGLS1.5
#bit G2D4N = CLCnGLS1.6
#bit G2D4T = CLCnGLS1.7
#byte CLCnGLS0 = 0x0DC
#bit G1D1N = CLCnGLS0.0
#bit G1D1T = CLCnGLS0.1
#bit G1D2N = CLCnGLS0.2
#bit G1D2T = CLCnGLS0.3
#bit G1D3N = CLCnGLS0.4
#bit G1D3T = CLCnGLS0.5
#bit G1D4N = CLCnGLS0.6
#bit G1D4T = CLCnGLS0.7
#byte CLCnSEL3 = 0x0DB
#byte CLCnSEL2 = 0x0DA
#byte CLCnSEL1 = 0x0D9
#byte CLCnSEL0 = 0x0D8
#byte CLCnPOL = 0x0D7
#bit G1POL = CLCnPOL.0
#bit G2POL = CLCnPOL.1
#bit G3POL = CLCnPOL.2
#bit G4POL = CLCnPOL.3
#bit POL = CLCnPOL.7
#byte CLCnCON = 0x0D6
#bit MODE0 = CLCnCON.0
#bit MODE1 = CLCnCON.1
#bit MODE2 = CLCnCON.2
#bit INTN = CLCnCON.3
#bit INTP = CLCnCON.4
#bit OUT = CLCnCON.5
#bit OE = CLCnCON.6
#bit EN = CLCnCON.7
#byte CLCSELECT = 0x0D5
#byte CLCDATA = 0x0D4
#bit CLC1OUT = CLCDATA.0
#bit CLC2OUT = CLCDATA.1
#bit CLC3OUT = CLCDATA.2
#bit CLC4OUT = CLCDATA.3
#bit CLC5OUT = CLCDATA.4
#bit CLC6OUT = CLCDATA.5
#bit CLC7OUT = CLCDATA.6
#bit CLC8OUT = CLCDATA.7
void CLC1_Initialize(void)
{
// Set the CLC1 to the options selected in the User Interface
// SLCT 0;
CLCSELECT = 0x00;
// G1POL not_inverted; G2POL not_inverted; G3POL not_inverted; G4POL inverted; POL inverted;
CLCnPOL = 0x88;
// D1S CLCIN0 (CLCIN0PPS);
CLCnSEL0 = 0x00;
// D2S CLCIN1 (CLCIN1PPS);
CLCnSEL1 = 0x01;
// D3S CLCIN2 (CLCIN2PPS);
CLCnSEL2 = 0x02;
// D4S CLCIN0 (CLCIN0PPS);
CLCnSEL3 = 0x00;
// G1D3N disabled; G1D2N disabled; G1D4N disabled; G1D1T disabled; G1D3T disabled; G1D2T disabled; G1D4T disabled; G1D1N enabled;
CLCnGLS0 = 0x01;
// G2D2N enabled; G2D1N disabled; G2D4N disabled; G2D3N disabled; G2D2T disabled; G2D1T disabled; G2D4T disabled; G2D3T disabled;
CLCnGLS1 = 0x04;
// G3D1N disabled; G3D2N disabled; G3D3N disabled; G3D4N disabled; G3D1T disabled; G3D2T disabled; G3D3T enabled; G3D4T disabled;
CLCnGLS2 = 0x20;
// G4D1N disabled; G4D2N disabled; G4D3N disabled; G4D4N disabled; G4D1T disabled; G4D2T disabled; G4D3T disabled; G4D4T disabled;
CLCnGLS3 = 0x00;
// CLC1OUT 0;
CLCDATA = 0x00;
// EN enabled; INTN disabled; INTP disabled; MODE 4-input AND;
CLCnCON = 0x82;
}
void main(void)
{
set_tris_a(0x03);
set_tris_b(0x00);
set_tris_d(0x01);
CLC1_Initialize();
while(TRUE)
{
}
} |
_________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Wed Feb 22, 2023 8:46 am |
|
|
output_drive(PIN_F0);
Otherwise it is set as an input.
Also B0 is used as an input, but you have it set as an output:
set_tris_b(0x00);
Needs to be:
set_tris_b(0x01); |
|
![](templates/subSilver/images/spacer.gif) |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Wed Feb 22, 2023 9:00 am |
|
|
I added these 2 codes. But again it didn't work.
Code: |
#use FAST_IO(f)
set_tris_f(0x00); |
I typed wrong. PIN_D0 , B0 is not used. _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Wed Feb 22, 2023 10:42 am |
|
|
Er. You said:
CLCIN2 PIN_B0
But you have this pin set as an output. |
|
![](templates/subSilver/images/spacer.gif) |
temtronic
Joined: 01 Jul 2010 Posts: 9168 Location: Greensville,Ontario
|
|
Posted: Wed Feb 22, 2023 10:49 am |
|
|
just a comment..
be REAL CAREFUL about using FAST_IO() and SET_TRIS...() !!
If you edit code wrongly, you'll run into problems !!
For now, stay with STANDARD_IO() and let the compiler handle it. |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Wed Feb 22, 2023 10:55 am |
|
|
However, since he is manually programming the CLC, not using CCS
functions, he will have to manually program the TRIS for this. |
|
![](templates/subSilver/images/spacer.gif) |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Thu Feb 23, 2023 12:30 am |
|
|
Now I rearranged it.
I used mplab GUI.
Inputs/Outputs;
CLCIN0 = A0
CLCIN1 = A1
CLCIN2 = B0
CLCOUT = F0
No error occurs when I compile. However, it does not work correctly. It works when I do the same operations with the CCS C compiler. Where is the mistake?
Code: |
//MPLAB GUI
#include <18F57Q43.h>
#use delay(crystal = 16MHz)
#use fast_io(a)
#use fast_io(b)
#use fast_io(f)
#byte CLCnGLS3 = 0x0DF
#byte CLCnGLS2 = 0x0DE
#byte CLCnGLS1 = 0x0DD
#byte CLCnGLS0 = 0x0DC
#byte CLCnSEL3 = 0x0DB
#byte CLCnSEL2 = 0x0DA
#byte CLCnSEL1 = 0x0D9
#byte CLCnSEL0 = 0x0D8
#byte CLCnPOL = 0x0D7
#byte CLCnCON = 0x0D6
#byte CLCSELECT = 0x0D5
#byte CLCDATA = 0x0D4
void CLC1_Initialize(void)
{
// Set the CLC1 to the options selected in the User Interface
// SLCT 0;
CLCSELECT = 0x00;
// G1POL not_inverted; G2POL not_inverted; G3POL not_inverted; G4POL inverted; POL inverted;
CLCnPOL = 0x88;
// D1S CLCIN0 (CLCIN0PPS);
CLCnSEL0 = 0x00;
// D2S CLCIN1 (CLCIN1PPS);
CLCnSEL1 = 0x01;
// D3S CLCIN2 (CLCIN2PPS);
CLCnSEL2 = 0x02;
// D4S CLCIN0 (CLCIN0PPS);
CLCnSEL3 = 0x00;
// G1D3N disabled; G1D2N disabled; G1D4N disabled; G1D1T disabled; G1D3T disabled; G1D2T disabled; G1D4T disabled; G1D1N enabled;
CLCnGLS0 = 0x01;
// G2D2N enabled; G2D1N disabled; G2D4N disabled; G2D3N disabled; G2D2T disabled; G2D1T disabled; G2D4T disabled; G2D3T disabled;
CLCnGLS1 = 0x04;
// G3D1N disabled; G3D2N disabled; G3D3N disabled; G3D4N disabled; G3D1T disabled; G3D2T disabled; G3D3T enabled; G3D4T disabled;
CLCnGLS2 = 0x20;
// G4D1N disabled; G4D2N disabled; G4D3N disabled; G4D4N disabled; G4D1T disabled; G4D2T disabled; G4D3T disabled; G4D4T disabled;
CLCnGLS3 = 0x00;
// CLC1OUT 0;
CLCDATA = 0x00;
// EN enabled; INTN disabled; INTP disabled; MODE 4-input AND;
CLCnCON = 0x82;
}
void main(void)
{
set_tris_a(0x03);
set_tris_b(0x01);
set_tris_f(0x00);
CLC1_Initialize();
while(TRUE)
{
}
}
/////////////////////////////////////////////////////////////////////
//CCS C CODE
#include <18F57Q43.h>
#use delay(internal=64MHz)
#define A PIN_A0
#define B PIN_A1
#define C PIN_B0
#pin_select CLCIN0=A
#pin_select CLCIN1=B
#pin_select CLCIN2=C
#define OUT PIN_F0
#pin_select CLC1OUT=OUT
void CLC1_Initialize(void)
{
//setup CLC1 inputs
clc1_setup_input(1, CLC_INPUT_CLCIN0);
clc1_setup_input(2, CLC_INPUT_CLCIN1);
clc1_setup_input(3, CLC_INPUT_CLCIN2);
//setup CLC1 gates
clc1_setup_gate(1, CLC_GATE_INVERTED_INPUT_1);
clc1_setup_gate(2, CLC_GATE_INVERTED_INPUT_2);
clc1_setup_gate(3, CLC_GATE_NON_INVERTED_INPUT_3);
clc1_setup_gate(4, CLC_GATE_SET);
//setup CLC1
setup_clc1(CLC_ENABLED | CLC_MODE_AND | CLC_OUTPUT_INVERTED); // 0 0 1 = 0
}
void main(void)
{
CLC1_Initialize();
while(TRUE)
{
}
}
|
_________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Thu Feb 23, 2023 2:46 am |
|
|
What you post as the MPLAB version, does not show PIN_SELECT entries.
The CCS version does.
You need these. The gate will not work without these. |
|
![](templates/subSilver/images/spacer.gif) |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Thu Feb 23, 2023 3:16 am |
|
|
So how do I do this? Do I add the same lines? _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
![](templates/subSilver/images/spacer.gif) |
Ttelmah
Joined: 11 Mar 2010 Posts: 19358
|
|
Posted: Thu Feb 23, 2023 3:22 am |
|
|
Yes.
Or just use the CCS code version.
Why if you are using the CCS compiler, would you want to directly write
the registers?. |
|
![](templates/subSilver/images/spacer.gif) |
MCUprogrammer
Joined: 08 Sep 2020 Posts: 221
|
|
Posted: Thu Feb 23, 2023 4:14 am |
|
|
The GUI is much easier to use. By the way, I did what you said and it worked. Thank you very much. Yes it works with CCS. Actually, I can go on. But I want to solve this problem too. It's not that hard after all. But not working is very frustrating.. _________________ Best Regards...
MCUprogrammer
_______________________________
Work Hard |
|
![](templates/subSilver/images/spacer.gif) |
|