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

CCP Compare Interrupt Problem

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



Joined: 18 Sep 2004
Posts: 22

View user's profile Send private message

CCP Compare Interrupt Problem
PostPosted: Mon Oct 25, 2004 7:23 pm     Reply with quote

I've been trying to debug this code for the entire evening. It is my first attempt at using compare and timer1 to fire a triac or in this case to activate an LED.
It seems to me that FireTriac() interrupt never happens. I know that zero crossing interrupt occurs correctly, but after that the program does not jump to FireTriac() interrupt when timer1==ccp_1.

Since I don't have access to an actual PIC right now, I am using PIC Simulator IDE 5.21 to test my code (maybe the simulator has bug....).

Can anybody tell me why the FireTriac() interrupt never occurs?

Thank you.

#include <16f877.h>

#fuses HS,NOWDT,NOPROTECT
#device PIC 16F877 ADC=8
#use delay(clock=20000000)
#use rs232(BAUD=9600,XMIT=PIN_C6,RCV=PIN_C7)
#opt 9

// Reserve top 255 bytes of memory for the bootloader
#ORG 0x1F00,0x1FFFF{}


void blink()
{
output_high( PIN_B2 );
delay_us(10);
output_low( PIN_B2 );
}


#int_CCP1 //this interrupt occurs when "timer1 == ccp_1"
FireTriac()
{
output_high( PIN_B1 );
delay_us(20); //Note: the delays are small in order to ensure
//the simulator doesn't get stuck
output_low (PIN_B1);
}


#int_ext //pin RB0 EXT interrupt
void zeroCrossing_isr()
{
set_timer1(0);
ccp_1=100;
}

void init_PIC() //initialize PIC hardware
{

set_tris_b(0b00000001);

setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);

enable_interrupts( GLOBAL );
enable_interrupts( INT_EXT );
enable_interrupts( INT_CCP1 );

setup_ccp1(CCP_COMPARE_INT);

/*The following 2 lines ensure that no accidental
CCP interupt occurs*/
set_timer1(0);
ccp_1=65535;


ext_int_edge(L_TO_H);
output_low( PIN_B1 );

main()
{
init_PIC();

while(1)
{ //only an interrupt driven program for now
}

}
dave



Joined: 21 Dec 2003
Posts: 7
Location: Sheffield, South Yorks, UK

View user's profile Send private message

PostPosted: Mon Oct 25, 2004 10:52 pm     Reply with quote

MPLAB ver 6.62
PCM 3.212
Found a missing brace and invalid address range for your #org, code compiled and ran using MPLAB sim.
Code:

#include <16f877.h>

#fuses HS,NOWDT,NOPROTECT
//#device PIC 16F877 ADC=8
#use delay(clock=20000000)
#use rs232(BAUD=9600,XMIT=PIN_C6,RCV=PIN_C7)
#opt 9

// Reserve top 255 bytes of memory for the bootloader
#ORG 0x1F00,0x1FFF{} //<you had ivalid address range


void blink()
{
output_high( PIN_B2 );
delay_us(10);
output_low( PIN_B2 );
}


#int_CCP1 //this interrupt occurs when "timer1 == ccp_1"
FireTriac()
{
output_high( PIN_B1 );
delay_us(20); //Note: the delays are small in order to ensure
//the simulator doesn't get stuck
output_low (PIN_B1);
}


#int_ext //pin RB0 EXT interrupt
void zeroCrossing_isr()
{
set_timer1(0);
ccp_1=100;
}

void init_PIC() //initialize PIC hardware
{

set_tris_b(0b00000001);
}//<<<<<<<<<<< Missing brace!!



main()
{
init_PIC();
set_timer1(0); //The following 2 lines ensure that no accidental
      //CCP interupt occurs*/ a false interrupt occurred before the pic had fully initialised with your code due to the fact that on boot up some registers can have any value see the Microchip data sheet for the device.

ccp_1=65535;
ext_int_edge(L_TO_H);
output_low( PIN_B1 );
setup_ccp1(CCP_COMPARE_INT);
enable_interrupts( INT_EXT );
enable_interrupts( INT_CCP1 );
setup_timer_1(T1_INTERNAL|T1_DIV_BY_1);
enable_interrupts( GLOBAL );                          //set this up last!


while(1)
{

}
}

I know its a matter of personal preferance, but I only use an init routine to set the tris registers and clear the ports.
hope this helps
regards Dave
pop



Joined: 18 Sep 2004
Posts: 22

View user's profile Send private message

PostPosted: Tue Oct 26, 2004 5:38 am     Reply with quote

Thank you

I'll try it immediately. I'm suprised the compiler never "noticed" the missing brace....
pop



Joined: 18 Sep 2004
Posts: 22

View user's profile Send private message

PostPosted: Tue Oct 26, 2004 6:07 am     Reply with quote

Thanks Dave. On MPSIM this works perfectly. I'll give it another shot with PIC simulator, but at least I know the code works.

Thanks again
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