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

16F684 and capture interrupt

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



Joined: 13 Mar 2004
Posts: 7

View user's profile Send private message

16F684 and capture interrupt
PostPosted: Fri Nov 26, 2004 3:10 pm     Reply with quote

I have been using the CCP_1 interrupt to cature data on a 16F876 with no problems. Now when I use the same code, compiled for the 16F684, the interrrupt will never trigger. There is definitely data on the CCP input pin. Has anyone run into this problem? My test code is below. Thanks for your help!

CCS PCM version 3.190

Code:
#include <16F684.h>
#use delay(clock=4000000)
#fuses INTRC_IO, NOWDT, PUT, NOPROTECT, NOMCLR, NOBROWNOUT
long pulse_width;
#int_CCP1
CCP1_isr()
{
   pulse_width = get_timer1();
   set_timer1(0);   //reset timer on every edge change
}

void main()
{
    setup_oscillator(OSC_4MHZ | OSC_INTRC);
    set_tris_c (0xFF);   //set all as inputs
    setup_timer_2(T2_DIV_BY_16,78, 16);
    setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
    setup_ccp1(CCP_CAPTURE_RE);  //switch to rising edge
    enable_interrupts(GLOBAL);
    enable_interrupts(INT_CCP1);

   while(1)
   {
   
   }
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Fri Nov 26, 2004 3:54 pm     Reply with quote

The problem is that the following line of code is not
being compiled correctly by your version of the compiler.
Code:
setup_ccp1(CCP_CAPTURE_RE);  //switch to rising edge

The compiler is writing to the wrong register address.

Below, I have modified your original program with a new routine
to hopefully setup the CCP correctly. The changes are shown
in bold.


#include <16F684.h>
#use delay(clock=4000000)
#fuses INTRC_IO, NOWDT, PUT, NOPROTECT, NOMCLR, NOBROWNOUT
long pulse_width;

#byte CCP1CON = 0x15
#byte PWM1CON = 0x16
#byte ECCPAS = 0x17

//------------------
#int_CCP1
CCP1_isr()
{
pulse_width = get_timer1();
set_timer1(0); //reset timer on every edge change
}
//------------------
// This routine attempts to copy how CCS sets up the CCP
// in later versions of the compiler.
void my_setup_ccp1(int8 value)
{
output_float(PIN_C5);
CCP1CON = 0;
CCP1CON = value;
PWM1CON = 0;
ECCPAS = 0;
}

//==================
void main()
{
setup_oscillator(OSC_4MHZ | OSC_INTRC);
set_tris_c (0xFF); //set all as inputs
setup_timer_2(T2_DIV_BY_16,78, 16);
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
// setup_ccp1(CCP_CAPTURE_RE); // Comment out this line.
my_setup_ccp1(CCP_CAPTURE_RE); // Use this routine instead.

enable_interrupts(GLOBAL);
enable_interrupts(INT_CCP1);

while(1)
{

}
}
wojc0008



Joined: 13 Mar 2004
Posts: 7

View user's profile Send private message

Correct!
PostPosted: Fri Nov 26, 2004 4:21 pm     Reply with quote

Thanks so much. I've been trying to figure it out and actually bought the ICD2 header for the 16f684 (which I guess I don't need now!).

Thanks so much. The interrupt works great now!
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