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

Cannot trigger CCP interrupt: Simple Test Code Does Not Work

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



Joined: 27 Jun 2013
Posts: 3
Location: Paia, HI

View user's profile Send private message

Cannot trigger CCP interrupt: Simple Test Code Does Not Work
PostPosted: Wed Mar 26, 2014 2:54 am     Reply with quote

In the test code below the INT_TIMER1 fires but INT_CCP4 does not.

I would be extremely grateful for any insight on how to get the CCP interrupt to be triggered when timer1 reaches the compare value.

Compiler version is CCS PCH C Compiler, Version 5.021, 10557

Thanks!

Code:

#include <18F6622.h>
#device icd=true
#fuses HS       
#use delay(clock=20000000)

#use rs232(DEBUGGER,xmit=PIN_B5,rcv=PIN_B5,stream=MONITOR,ERRORS)

#INT_CCP4
void CCP4_isr()
{
   
   fprintf(MONITOR, "a\n");
   
}

#INT_TIMER1
void TIMER1_isr()
{
   
   fprintf(MONITOR, "b\n");
   
}

void main()
{
 
   setup_timer_1(T1_EXTERNAL|T1_DIV_BY_1|T1_CLK_OUT);
   clear_interrupt(INT_TIMER1);         
   enable_interrupts(INT_TIMER1);
   
   setup_ccp4(CCP_COMPARE_INT);   
   clear_interrupt(INT_CCP4);         
   enable_interrupts(INT_CCP4);
   CCP_4 = 0x01FF;
   
   enable_interrupts(GLOBAL);
   
   while(TRUE)
   {
     
           
   }
   
}
Ttelmah



Joined: 11 Mar 2010
Posts: 19330

View user's profile Send private message

PostPosted: Wed Mar 26, 2014 3:30 am     Reply with quote

Critical change:

T1_EXTERNAL_SYNC

Compare mode _only_ works, when the timer is either running from an internal clock, or running in synchronous mode (so the timer updates in sync with the internal clock). Quote from data sheet:

"Timer1 and/or Timer3 must be running in Timer mode
or Synchronized Counter mode if the CCP module is
using the compare feature. In Asynchronous Counter
mode, the compare operation may not work."

Best Wishes
alec_stewart



Joined: 27 Jun 2013
Posts: 3
Location: Paia, HI

View user's profile Send private message

PostPosted: Wed Mar 26, 2014 3:40 am     Reply with quote

Thanks very much! I never would have figured that out on my own.
_________________
Alec Stewart
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