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

Multiple Interrupts on PIC16F876

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







Multiple Interrupts on PIC16F876
PostPosted: Tue Jul 15, 2003 8:14 am     Reply with quote

Hello everyone,

I'am still working on a project, where I have to use 2 different interrupts (int_ext and int_timer2) to switch between 2 different synchronise clockings (internal clock via timer2 and external clock via int_ext).
It is possible to work with 1 or 2 different ISR's on a PIC16F876 with 2 different interrupt sources (switchable from control-software on PC)?
#int_global is not working and only #int_ext is not enough.

Have everyone an idea?
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516001
R.J.Hamlett
Guest







Re: Multiple Interrupts on PIC16F876
PostPosted: Tue Jul 15, 2003 9:35 am     Reply with quote

:=Hello everyone,
:=
:=I'am still working on a project, where I have to use 2 different interrupts (int_ext and int_timer2) to switch between 2 different synchronise clockings (internal clock via timer2 and external clock via int_ext).
:=It is possible to work with 1 or 2 different ISR's on a PIC16F876 with 2 different interrupt sources (switchable from control-software on PC)?
:=#int_global is not working and only #int_ext is not enough.
:=
:=Have everyone an idea?
This appears to be relatively simple.
You have to write two interrupt handlers, each of which increments the required counters, and sets any flags needed to keep the main code synchronised. Each routine should be written to use the same storage locations in global storage for these values.
Then the main code should enable_interrupts(global), setup the required polarity for the external interrupt, and polarity/prescaler for the timer2 interrupt. Then to switch between the routines, you should disable the current routine, clear the interrupt flag for the second routine, then enable this. So a routine like:

#define I_EXT 0
#define I_TIMER2 1
#bit T2IF=0xC,1
#bit EXIF=0x8B,1

switch_to_interrupt(int int_reqd) {
//Ensure neither interrupt is enabled
disable_interrupts(INT_EXT);
disable_interrupts(INT_TIMER2);
if(int_reqd==I_EXT) {
//prevent immediate interrupt for past rollovers
EXIF=0;
enable_interrupts(INT_EXT);
}
else {
T2IF=0;
enable_interrupts(INT_TIMER2);
}
}

Then in main (or anywhere else), you can just 'switch_to_interrupt(I_EXT)', and this will start executing the INT_EXT handler, but leave the INT_TIMER2 handler uncalled.

Best Wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516004
Joerg Hahn
Guest







Re: Multiple Interrupts on PIC16F876
PostPosted: Wed Jul 16, 2003 8:04 am     Reply with quote

:=:=Hello everyone,
:=:=
:=:=I'am still working on a project, where I have to use 2 different interrupts (int_ext and int_timer2) to switch between 2 different synchronise clockings (internal clock via timer2 and external clock via int_ext).
:=:=It is possible to work with 1 or 2 different ISR's on a PIC16F876 with 2 different interrupt sources (switchable from control-software on PC)?
:=:=#int_global is not working and only #int_ext is not enough.
:=:=
:=:=Have everyone an idea?
:=This appears to be relatively simple.
:=You have to write two interrupt handlers, each of which increments the required counters, and sets any flags needed to keep the main code synchronised. Each routine should be written to use the same storage locations in global storage for these values.
:=Then the main code should enable_interrupts(global), setup the required polarity for the external interrupt, and polarity/prescaler for the timer2 interrupt. Then to switch between the routines, you should disable the current routine, clear the interrupt flag for the second routine, then enable this. So a routine like:
:=
:=#define I_EXT 0
:=#define I_TIMER2 1
:=#bit T2IF=0xC,1
:=#bit EXIF=0x8B,1
:=
:=switch_to_interrupt(int int_reqd) {
:= //Ensure neither interrupt is enabled
:= disable_interrupts(INT_EXT);
:= disable_interrupts(INT_TIMER2);
:= if(int_reqd==I_EXT) {
:= //prevent immediate interrupt for past rollovers
:= EXIF=0;
:= enable_interrupts(INT_EXT);
:= }
:= else {
:= T2IF=0;
:= enable_interrupts(INT_TIMER2);
:= }
:=}
:=
:=Then in main (or anywhere else), you can just 'switch_to_interrupt(I_EXT)', and this will start executing the INT_EXT handler, but leave the INT_TIMER2 handler uncalled.
:=
:=Best Wishes


Thank you. It's working now working

Best wishes
___________________________
This message was ported from CCS's old forum
Original Post ID: 144516064
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