Dealing with infinite loop in an Interrupt Service Routine !!

Status
Not open for further replies.

ROCKET SCIENTIST

Member level 3
Joined
Feb 25, 2012
Messages
61
Helped
5
Reputation
10
Reaction score
5
Trophy points
1,288
Activity points
1,728
Hi guys,

Facing problems with ISR. I don't know to stop an infinite loop in an interrupt service routine. I have set 2 ext. interrupts. Now int_0 service routine has an infinite loop inside of it that just makes a pulse train.. But I want this while(1) infinite loop to stop whenever the other ext. interrupt, int_1 fires thus the execution process goes out of int_0 routine and into int_1 routine. Well, in practice, I've found that even when int_1 fires and the MCU starts to execute codes inside of int_1 routine, still then that infinite loop in int_0 routine is working!! 8-O It didn't stop. Now do u guys have any idea for how to get rid of it??

Now, I also tried this. In int_0 ISR I put a flag, PORTB=0; and instead of using while(1) I used, while(PORTB==0) and then in int_1 ISR I've changed flag into PORTB=1; Thought this might work, but no, it didn't. Hope you guys have some idea for this problem. Thanks in advance.

Here's the little code I've written:

Code:
//processor: Atmel AVR Atmega8

#define F_CPU 8000000UL

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>

ISR(INT1_vect) {  //fires at rising edge
GICR=0; MCUCR=0; MCUCR |= (1<<ISC01); GICR |= (1<<INT0); 
//for the next int. set int0 at falling edge
PORTB=0; //flag for infinite loop
while(PORTB==0) {PORTC=1; PORTC=0;}
}

ISR(INT0_vect) {  //fires at falling edge 
GICR=0; MCUCR=0; MCUCR |= (1<<ISC10)|(1<<ISC11); GICR |= (1<<INT1); 
//for the next int. set int1 at rising edge
PORTB=1; //changing flag, trying to stop infinite loop
}


int main (void) {

DDRC |= 1; DDRB |= 1;
MCUCR=0; MCUCR |= (1<<ISC10)|(1<<ISC11); GICR=0; GICR |= (1<<INT1); sei();
//default int. setting: int_1 at rising edge

while(1) {/*doing nothing*/}

return 0; }


Regards,
Ro_S.
 

hello,


It's not allowed to uses infinit loop inside a interupt treatment !

because you never exit from the ISR(INT1_vect) to be able to treat other interrupt..
It can be done only on evolued controller wich include PRIORITY level treatment...
I don't know AVR µP
do you have High and low priority like on Microchip 18F ?

maybe you can use PWM instead of PORTC=1 PORTC=0
 
Reactions: brhans

    brhans

    Points: 2
    Helpful Answer Positive Rating
Thanks for the comment. INT0 has the higher priority than INT1. Ok, I think using infinite loop was not a good idea, but can I use a normal variable controlled loop in ISR?
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…