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

trouble with CCP2 on B3 on PIC18F24k

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



Joined: 14 Mar 2006
Posts: 45

View user's profile Send private message

trouble with CCP2 on B3 on PIC18F24k
PostPosted: Tue Dec 08, 2009 8:34 pm     Reply with quote

I want to use B3 as the input to CCP2 configured as CCP_CAPTURE_FE.
In addition, I'd like to be able to poll the bit value.

This would make it a quasi "Interrupt on change" input that I could also poll.
The problem is being able to poll the B3 input after this instruction is executed. It is always low. Crying or Very sad
Code:
setup_ccp2(CCP_CAPTURE_FE);


RB0 is being used as another interrupt input
RB1,2,4 are PWM outputs
RB5 is a IOC button input
RB6 & 7 are left for ICD debugging only

Below is a test program.
Can anyone make suggestions on why the RB3 pin is read as 0 instead of in 'parallel' with the CCP2 input ?

Code:

//Compiler version 4.099

#include <18F24K20.h>

   #device ICD=TRUE
   #FUSES NODEBUG                  //No Debug mode for ICD

#device adc=8

#FUSES NOWDT                    //   No Watch Dog Timer
#FUSES WDT128                   //Watch Dog Timer uses 1:128 Postscale
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES NODEBUG                  //No Debug mode for ICD
#FUSES NOLVP                    //No low voltage prgming, B3(PIC16) or B5(PIC18) used for I/O
#FUSES NOWRT                    //Program memory not write protected
#FUSES NOWRTD                   //Data EEPROM not write protected
#FUSES IESO                     //Internal External Switch Over mode enabled
#FUSES FCMEN                    //Fail-safe clock monitor enabled
input channels on RESET

#FUSES LPT1OSC                  //Timer1 configured for low-power operation
#FUSES MCLR                     //Master Clear pin enabled
#FUSES NOXINST                  //Extended set extension and Indexed Addressing mode disabled (Legacy mode)
#FUSES NODELAYINTOSC   

#FUSES CCP2B3                   // enable the CCP2 pin to be used as a button input
//#FUSES PBADEN                   //PORTB pins are configured as analog #FUSES NOPBADEN                   //PORTB pins are configured as digital



#use delay(clock=1000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=CONSOLE)


#BYTE STKPTR = 0xffc    // stack pointer address, 2 msb are flags
#BYTE INTCON = 0xff2    //INTCON: INTERRUPT CONTROL REGISTER
#BYTE IOCB = 0xf7d      // interrupt on change bit  control
#byte LDR_WPUB = 0xF7C
#use fast_io(B)

int8 current, x;
int8 current2;



#int_RB
void  RB_isr(void)
{

}

#int_CCP2
void  CCP2_isr(void)
{

}

#int_EXT
void  EXT_isr(void)
{

}


void main()
{
   char key;   
   int16 duty;

   IOCB = 0x20; // enable interrupt on change for RB5
   ANSELH = 0;

   setup_ccp1(CCP_OFF);
 
   
   x=0;
   disable_interrupts(GLOBAL);
   
   clear_interrupt(INT_RB);
   enable_interrupts(INT_RB);
//   clear_interrupt(INT_EXT);
//   enable_interrupts(INT_EXT);

   clear_interrupt(INT_CCP2);
   enable_interrupts(INT_CCP2);


/////////////////////////////////////////////////////////////////////

   setup_ccp2(CCP_CAPTURE_FE); // don't care about value, just want the clock edge
            // for use as button push detection
   
/////////////////////////////////////////////////////////////////////


   set_tris_b(0b00101000); // RB5 & RB3 set these as inputs
   port_b_pullups(TRUE);   // bits 0, 3, 5 ; intr, up, dn

   while(1)
   {
      fprintf(CONSOLE, "\r\nPress any key.");
      key=fgetc(CONSOLE);
      fputc(key,CONSOLE);  // echo the pressed key
      x++;
      x++;
      x++;
      current=input(PIN_B3);
      x++;
      x++;
      x++;
      current2=input(PIN_B5);
      x++;
      x++;
      x++;
     
     
      fprintf(CONSOLE, "\r\n");
      fprintf(CONSOLE, "%u",current);
      fprintf(CONSOLE, "  ");
      fprintf(CONSOLE, "%u",current2);
   }

}
Leef_me



Joined: 14 Mar 2006
Posts: 45

View user's profile Send private message

PostPosted: Wed Dec 09, 2009 3:39 pm     Reply with quote

bump
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Wed Dec 09, 2009 3:51 pm     Reply with quote

You want to test your theory of using another interrupt pin to detect a
level change event (i.e., to detect an edge). You have posted way too
much code for this test. You don't need all those interrupt routines. You
don't need all the x++ stuff. You don't need the #byte statements.
You don't need #fast io mode. The test could be done in 10 lines,
probably. That's why you're not getting an answer. Strip it down to
essentials.
Leef_me



Joined: 14 Mar 2006
Posts: 45

View user's profile Send private message

PostPosted: Thu Dec 10, 2009 12:32 am     Reply with quote

PCM programmer wrote:
You want to test your theory of using another interrupt pin to detect a
level change event (i.e., to detect an edge). You have posted way too
much code for this test. You don't need all those interrupt routines. You
don't need all the x++ stuff. You don't need the #byte statements.
You don't need #fast io mode. The test could be done in 10 lines,
probably. That's why you're not getting an answer. Strip it down to
essentials.


I know your trying to help, and I appreciate it. But some of what you said is incorrect.
Or so it seems to me.

>>The test could be done in 10 lines, probably.
If that is true, given details added below, perhaps you would show me?

Meanwhile, below is my code, stripped down.

I need to select which pin(s) are used as interrupt-on-change according to 9.11 PORTB Interrupt-on-Change,
but according to 10.3.2 INTERRUPT-ON-CHANGE only RB<7:4> configured as input can cause interrupt.

I may need to make RB4 a non-output to disable its PWM and I have no idea about RB7 & 6.
So I added the definition of IOCB and set the bit I wanted as input.

When I first started testing, I missed that CCP2 could be forcing RB3 to be low so I tried setting all the pull-ups by adding #byte LDR_WPUB = 0xF7C.

I used fast IO because I eventually wanted to read portB as a byte, but using standard IO the input_b() statement would change the states of the PWM outputs.

I want the x++ as a simple location of where to add breakpoints.

Since I want interrupts, I left the interrupt routines as stubs for now.

Code:
//Compiler version 4.099

#include <18F24K20.h>

#device ICD=TRUE
#FUSES INTRC_IO                 //Internal RC Osc, no CLKOUT
#FUSES MCLR                     //Master Clear pin enabled
#FUSES CCP2B3                   // enable the CCP2 pin to be used as a button input
#FUSES NOPBADEN                 //PORTB pins are configured as digital

#use delay(clock=1000000)
#use rs232(baud=9600,parity=N,xmit=PIN_C6,rcv=PIN_C7,bits=8,stream=CONSOLE)

#BYTE IOCB = 0xf7d      // interrupt on change bit control

int8 current, x, key, current2;

#int_RB
void  RB_isr(void)
{

}

#int_CCP2
void  CCP2_isr(void)
{

}

#int_EXT
void  EXT_isr(void)
{

}


void main()
{
   IOCB = 0x20; // enable interrupt on change for RB5

   x=0;
   disable_interrupts(GLOBAL);
   
   clear_interrupt(INT_RB);
   enable_interrupts(INT_RB);
//   clear_interrupt(INT_EXT);
//   enable_interrupts(INT_EXT);

   clear_interrupt(INT_CCP2);
   enable_interrupts(INT_CCP2);

/////////////////////////////////////////////////////////////////////

   setup_ccp2(CCP_CAPTURE_FE); // don't care about value, just want the clock edge
            // for use as button push detection
   
/////////////////////////////////////////////////////////////////////

   set_tris_b(0b00101000); // RB5 & RB3 set these as inputs
   port_b_pullups(TRUE);   // bits 0, 3, 5 ; intr, up, dn

   while(1)
   {
      fprintf(CONSOLE, "\r\nPress any key.");
      key=fgetc(CONSOLE);
      fputc(key,CONSOLE);  // echo the pressed key
      current=input(PIN_B3);
      current2=input(PIN_B5);
      fprintf(CONSOLE, "\r\n");
      fprintf(CONSOLE, "%u",current);
      fprintf(CONSOLE, "  ");
      fprintf(CONSOLE, "%u",current2);
   }

}
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