|
|
View previous topic :: View next topic |
Author |
Message |
ibg
Joined: 19 Nov 2003 Posts: 22
|
Edge of Interruption III |
Posted: Fri Apr 23, 2004 9:31 am |
|
|
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
|
|
Posted: Fri Apr 23, 2004 10:30 am |
|
|
Why are you turning the interupts on and off inside the interupt? |
|
|
ttelmah Guest
|
Re: Edge of Interruption III |
Posted: Fri Apr 23, 2004 10:46 am |
|
|
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 |
|
|
|
|
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
|