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

help - can't get CCP interrupt to fire (SOLVED)

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



Joined: 09 Jun 2011
Posts: 13

View user's profile Send private message

help - can't get CCP interrupt to fire (SOLVED)
PostPosted: Thu Jun 09, 2011 5:07 pm     Reply with quote

Ok so I have never used interrupts before and I am trying to use the CCP on a 12F615 to determine the width of a pulse. I have looked at examples and tried many different things but I cannot seem to get the interrupt routine to ever run. I put a breakpoint at the top of the interrupt routine and it never gets there. I have a scope probe on the CCP pin and it is getting a valid pulse every 20ms that is about 1ms wide. Here is my code:

Code:

#include "12F615.h"

#fuses INTRC_IO,NOWDT,MCLR
#use delay(clock=8000000)
#bit INTF_BIT = 0x0B.1

#define Zero_Cross   PIN_A0
#define Fire_Triac   PIN_A5
#define PWM_In      PIN_A1   

// FUNCTION Prototypes
void main(void);
int16 GetRC_PulseWidth(void);
int16 PWMValue;
int16 DutyCycle;
unsigned int16 TriacDelayPeriod;

long rise,fall,pulse_width;
int edgeflag,nop;

//************************************************************************************
//************  Main  ****************************************************************
//************************************************************************************
#int_ccp1
void isr()
{
   if (edgeflag==1)
   {
         rise = CCP_1;
         setup_ccp1(CCP_CAPTURE_FE);    // now configure CCP1 to capture falling   
      edgeflag=0;
   }
   else
   {
      fall = CCP_1;
         setup_ccp1(CCP_CAPTURE_RE);    // now configure CCP1 to capture rising   
      PWMValue = fall - rise;
      edgeflag=1;
   }
   
}                               



void main ( )
{

   int16 i;
   
   set_tris_a(0x0f); 

   PWMValue = 182;
   fall=0;
   rise=0;
   edgeflag=1;
   SETUP_ADC(No_Analogs),
   setup_ccp1(CCP_CAPTURE_RE);    // Configure CCP1 to capture rise
      setup_timer_1(T1_INTERNAL);    // Start timer 1

      enable_interrupts(INT_CCP1);   // Setup interrupt on falling edge
      enable_interrupts(GLOBAL);
   nop=1;

   do {
      if (PWMValue >100)
      {
         //do something
      }
      else
      {
         // do something else
      }
   

   }while (1);



Last edited by jumanji on Mon Jun 13, 2011 1:22 pm; edited 1 time in total
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 5:24 pm     Reply with quote

What's the Vdd voltage of the PIC and what are the voltage levels of
the waveform going to the CCP1 pin ?

And what's your compiler version ?
jumanji



Joined: 09 Jun 2011
Posts: 13

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 5:25 pm     Reply with quote

Vdd = 5V and the pulse is 5V.
jumanji



Joined: 09 Jun 2011
Posts: 13

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 5:28 pm     Reply with quote

sorry - compiler is v4.121
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Jun 09, 2011 7:44 pm     Reply with quote

Try setting the OPTION register to disable pin GP2 as the Timer0 clock
source, as shown in this post:
http://www.ccsinfo.com/forum/viewtopic.php?t=33336&start=3
jumanji



Joined: 09 Jun 2011
Posts: 13

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 6:22 am     Reply with quote

ok-I tried that but it doesn't make any difference.

I don't know if it makes any difference, but I should mention that I am using the header board that plugs into the debugger (ICD3) and allows you to debug with the 12F615 and not give up the use of the 2 pins needed for programming.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 4:11 pm     Reply with quote

I don't have a 12F615. I do have 12F683 and it's similar. I made the
following test program to blink an LED if I get a CCP1 interrupt when I
press a switch. It works. I get a short blink on the LED every time I
push down the switch. This was tested with vs. 4.121.
Here's the switch circuit:
Code:

           +5v
            |
            <
            > 10K       
            <         ___  Switch 
To PIC      |        _|_|_
pin 5  --------------o   o------
(GP2)                          |             
                              --- GND
                               -   
 


Here is the LED circuit. You can also use 330 or 470 ohms for the resistor.
Code:

To PIC
pin 2     220 ohms      LED       
(GP5) ---/\/\/\/------->|----
                            |
                            |
                          -----  Ground 
                           ---
                            -
 


Here's the test program.
Code:

#include <12F683.H>
#fuses INTRC_IO, NOWDT, BROWNOUT, PUT, NOMCLR
#use delay(clock=4M)

#int_ccp1
void ccp1_isr(void)
{
output_high(PIN_A5);
delay_ms(200);         // Do a short blink on the LED
output_low(PIN_A5);
}

#define set_options(value)   {#ASM         \
                              MOVLW  value \
                              OPTION       \
                              #ENDASM}

//===================================
void main()
{
set_options(0xC0);

setup_ccp1(CCP_CAPTURE_RE);

clear_interrupt(INT_CCP1);
enable_interrupts(INT_CCP1);
enable_interrupts(GLOBAL);

while(1);
}
jumanji



Joined: 09 Jun 2011
Posts: 13

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 4:56 pm     Reply with quote

Thank you for going through the trouble to do this. What hardware are you using to test this? Are you using a debugger or actually programming a device? I have continued to work with this and I have discovered that if I run my code on the simulator that it works - but using the ICD3 and the header board the INTF bit gets set as soon as I enable the interrupts and I am unable to clear it and it never jumps to the isr routine.
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 5:03 pm     Reply with quote

I used a 3M solderless breadboard. I plugged wires and components into
it to make the circuits. I used a PicKit2 programmer to program the PIC
and to supply power to the board. I compiled and programmed the code
in "Release" mode in MPLAB. I just ran it in "standalone" mode, not in
debug mode.
jumanji



Joined: 09 Jun 2011
Posts: 13

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 5:36 pm     Reply with quote

I am convinced the problem is not the code but somewhere in my debugger setup. I have contacted Microchp to see if this is a known issue. In the meantime I will program an actual device and verify that it is working without the debugger. Thanks again for your help on this.
jumanji



Joined: 09 Jun 2011
Posts: 13

View user's profile Send private message

PostPosted: Fri Jun 10, 2011 6:07 pm     Reply with quote

ok- just programmed a device and added some code to pulse a pin if I go thru the isr routine and it is working fine. There is definitely something wrong within the debugger system somewhere....
jumanji



Joined: 09 Jun 2011
Posts: 13

View user's profile Send private message

PostPosted: Mon Jun 13, 2011 1:22 pm     Reply with quote

Just got a nice email from Microchip. Apparently if you dig into the "limitations" section of MPLAB for this family of devices you find this note: "ECCP capture mode interrupts do not occur when emulating the PIC12F615 and PIC12F617 devices".

Bloody hell.
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