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 CCS Technical Support

Help on CLC1 example on PIC16F15325

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



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

Help on CLC1 example on PIC16F15325
PostPosted: Wed Jul 24, 2019 9:39 am     Reply with quote

Trying to understand, but no success, i.e. no signal on RA5 when trying combinations of buttons RC3 and RC4.

Could someone help?

Here is my code:
Code:
#include <16F15325.h>
#device ADC=10
#use delay(internal=32MHz)

#define LED PIN_A1
#define DELAY 1

#byte CLC1GLS0 = getenv("SFR:CLC1GLS0")
#byte CLC1GLS1 = getenv("SFR:CLC1GLS1")
#byte CLC1GLS2 = getenv("SFR:CLC1GLS2")
#byte CLC1GLS3 = getenv("SFR:CLC1GLS3")
#byte CLC1SEL0 = getenv("SFR:CLC1SEL0")
#byte CLC1SEL1 = getenv("SFR:CLC1SEL1")
#byte CLC1SEL2 = getenv("SFR:CLC1SEL2")
#byte CLC1SEL3 = getenv("SFR:CLC1SEL3")
#byte CLC1POL  = getenv("SFR:CLC1POL")
#byte CLC1CON  = getenv("SFR:CLC1CON")
#byte CLCDATA  = getenv("SFR:CLCDATA")

#byte CLCIN0PPS = getenv("SFR:CLCIN0PPS")
#byte CLCIN1PPS = getenv("SFR:CLCIN1PPS")
#byte CLCIN2PPS = getenv("SFR:CLCIN2PPS")
#byte CLCIN3PPS = getenv("SFR:CLCIN3PPS")


#pin_select CLC1OUT=PIN_A5
#pin_select CLCIN0=PIN_C3
#pin_select CLCIN1=PIN_C4

void main() {

  SET_TRIS_C( 0b011000 );

  CLC1CON  = 0x82;

  CLCIN0PPS = 0x13;
  CLCIN1PPS = 0x14;
  CLCIN2PPS = 0x10;
  CLCIN3PPS = 0x10;

 
  CLC1GLS0 = 0x0A;
  CLC1GLS1 = 0x00;
  CLC1GLS2 = 0x00;
  CLC1GLS3 = 0x00;
 
  CLC1SEL0 = 0x00;
  CLC1SEL1 = 0x01;
  CLC1SEL2 = 0x1B;
  CLC1SEL3 = 0x1E;
 
  CLC1POL  = 0x8E;
 
  while(TRUE) {
    output_toggle(LED);
    delay_ms(DELAY);
  }

}
Ttelmah



Joined: 11 Mar 2010
Posts: 19538

View user's profile Send private message

PostPosted: Wed Jul 24, 2019 10:41 am     Reply with quote

Glaring thing is you can't just write to the PPS registers.
The chip has to have a very specific 'unlock' sequence before it'll
accept changes to the PPS.
Use the CCS #PIN_SELECT to setup the PPS.
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

PostPosted: Wed Jul 24, 2019 3:00 pm     Reply with quote

I thought this is what I have been doing in using the following code for PPS remapping.

Code:

#pin_select CLC1OUT=PIN_A5
#pin_select CLCIN0=PIN_C3
#pin_select CLCIN1=PIN_C4



I am directly writing just to the CLC1 registers, not to PPS registers.

Did I misunderstand things?
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Jul 24, 2019 3:46 pm     Reply with quote

Look at your posted code:
Quote:

CLCIN0PPS = 0x13;
CLCIN1PPS = 0x14;
CLCIN2PPS = 0x10;
CLCIN3PPS = 0x10;

Yes, you are writing directly to the PPS registers without doing the
unlocking sequence.
Momboz



Joined: 03 Jun 2009
Posts: 29

View user's profile Send private message

PostPosted: Thu Aug 01, 2019 8:09 am     Reply with quote

Yes, you're right. I've missed those code lines.

I did review my code and now everything works fine. I did it in an easier way:

Code:
  setup_clc1(CLC_ENABLED | CLC_MODE_AND);
 
  clc1_setup_input(1, CLC_INPUT_CLCIN0);
  clc1_setup_input(2, CLC_INPUT_CLCIN1);
 
  clc1_setup_gate(1, CLC_GATE_OR);
  clc1_setup_gate(2, CLC_GATE_SET);
  clc1_setup_gate(3, CLC_GATE_SET);
  clc1_setup_gate(4, CLC_GATE_SET);


However, I have noticed that, the coding in CCS C Compiler differs from that in MPLAB XC8. The difference is in the inputs selection register.
MPLAB takes account that inputs are not connected, e.g. in my case it says
CLC1GLS0=0x0A and CCS C Compiler says CLC1GLS0=0xAA.

In my case, this makes no difference, because I am not using any other signal outside these 2.

Maybe there is a way to tell the gate that the other 2 inputs are disconnected.
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