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

Edge of Interruption III

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



Joined: 19 Nov 2003
Posts: 22

View user's profile Send private message

Edge of Interruption III
PostPosted: Fri Apr 23, 2004 9:31 am     Reply with quote

Hi all,

I finally resolved the problem with my external2 interruption routine. The thing was that there are some glitches in the signal and that's why the interruption routine more times than expected (2 times to be accurate).

I resolved the problem adding a delay once in the interruption ;)

Thanks for your help,

Imanol

P.S: I attach the code for my interruption routine

Code:

#int_ext2
void ext_isr(void)
{
   disable_interrupts(int_ext2);
   disable_interrupts(GLOBAL);
   int_flag= 1;
   signal_strength= read_adc();
   ss_acum= ss_acum + signal_strength;
   pulses++;
   delay_ms(30); // To avoid the glitches present in TD
   bit_clear(INTCON3, 1);
   enable_interrupts(int_ext2);
   enable_interrupts(GLOBAL);
}
Neutone



Joined: 08 Sep 2003
Posts: 839
Location: Houston

View user's profile Send private message

PostPosted: Fri Apr 23, 2004 10:30 am     Reply with quote

Why are you turning the interupts on and off inside the interupt?
ttelmah
Guest







Re: Edge of Interruption III
PostPosted: Fri Apr 23, 2004 10:46 am     Reply with quote

ibg wrote:
Hi all,

I finally resolved the problem with my external2 interruption routine. The thing was that there are some glitches in the signal and that's why the interruption routine more times than expected (2 times to be accurate).

I resolved the problem adding a delay once in the interruption ;)

Thanks for your help,

Imanol

P.S: I attach the code for my interruption routine

Code:

#int_ext2
void ext_isr(void)
{
   disable_interrupts(int_ext2);
   disable_interrupts(GLOBAL);
   int_flag= 1;
   signal_strength= read_adc();
   ss_acum= ss_acum + signal_strength;
   pulses++;
   delay_ms(30); // To avoid the glitches present in TD
   bit_clear(INTCON3, 1);
   enable_interrupts(int_ext2);
   enable_interrupts(GLOBAL);
}

As written, this code is _dangerous_.
You absolutely _must not_ enable the global interrupt inside the handler. Doing this, will (if an interrupt occurs while the global handler is tidying up afterwards), result in the stack becoming eventually corrupted.
You can simplify your code a lot, and it'll be safer. Use:
Code:

#int_ext2
void ext_isr(void)
{
   int_flag= 1;
   signal_strength= read_adc();
   ss_acum= ss_acum + signal_strength;
   pulses++;
   delay_ms(30); // To avoid the glitches present in TD
   bit_clear(INTCON3, 1);
   clear_interrupts(INT_EXT2);
}


The interrupt handler, as coded by CCS, allready clears the interrupt on exit, so if you delay in the handler, any interrupts that have occured before the routine exit, will be cleared. This behaviour can be disadvantageous if you want to handle high speed interrupts, but is useful in this case (in the former case, use the 'noclear' option on the interrupt declaration, and clear the interrupt yourself as you enter the routine).

Best Wishes
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