| View previous topic :: View next topic   | 
	
	
	
		| Author | 
		Message | 
	
	
		
			alec_stewart
 
 
  Joined: 27 Jun 2013 Posts: 3 Location: Paia, HI 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				| Cannot trigger CCP interrupt: Simple Test Code Does Not Work | 
			 
			
				 Posted: Wed Mar 26, 2014 2:54 am     | 
				     | 
			 
			
				
  | 
			 
			
				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: 19967
  
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Wed Mar 26, 2014 3:30 am     | 
				     | 
			 
			
				
  | 
			 
			
				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 
			
			 
			 
			
			
			
			
			
			
			
  
		  | 
		
			
				 | 
			 
			
				 Posted: Wed Mar 26, 2014 3:40 am     | 
				     | 
			 
			
				
  | 
			 
			
				Thanks very much! I never would have figured that out on my own. _________________ Alec Stewart | 
			 
		  | 
	
	
		  | 
	
	
		 |