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

external interrupts (trouble with CCP1)

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



Joined: 08 Jul 2005
Posts: 91

View user's profile Send private message

external interrupts (trouble with CCP1)
PostPosted: Thu Aug 11, 2005 12:34 pm     Reply with quote

If I have pin B0 (my ccp pin) grounded, can someone please tell me why A2 is going high?

Thanks

Code:

#include <16F87.H>
#include <stdlib.h>
#include <math.h>

#define A2 PIN_A2
#define B0 PIN_B0
#define B1 PIN_B1
#define B2 PIN_B2

#fuses HS,NOWDT,NOPROTECT, PUT
#use delay(clock=4000000)

long rise, fall, pulseLength;

#int_ccp1
void isr()
{
   pulseLength=0;
   set_timer1(0);
   while(input(B0));
   pulseLength = get_timer1();
}

main()
{

   delay_ms(1500);

   while(1)
   {
      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 rising edge
      enable_interrupts(GLOBAL);

      if(pulseLength>1500)
      {
         output_high(A2);
         delay_ms(1000);
         output_low(A2);
      }

      else
         output_low(A2);

   }
} // end of main
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Thu Aug 11, 2005 2:09 pm     Reply with quote

The data sheet says right here,
Quote:
9.1.3 SOFTWARE INTERRUPT
When the Capture mode is changed, a false capture
interrupt may be generated. The user should keep bit
CCP1IE (PIE1<2>) clear to avoid false interrupts and
should clear the flag bit, CCP1IF, following any such
change in operating mode.


CCS has the clear_interrupt() function, specifically for this purpose.

You need to clear the INT_CCP1 interrupt before you enable
global interrupts.

Also, anytime a module behaves strangely, it's almost certainly
because of some quirky behavior that will be explained in the
data sheet section on that module. You should read it.
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