Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] goto specific line after interrupt routine is over

Status
Not open for further replies.

asimkumar

Member level 4
Joined
Jan 1, 2011
Messages
78
Helped
8
Reputation
16
Reaction score
7
Trophy points
1,288
Location
Chandigarh, India
Activity points
1,756
i want my code to goto specific line in the main after interrupt routine is over, i am using codevision AVR
1. Does a ISR in C disables all/the same interrupts temporarily.
2. What if i never return from interrupts.
 

When an interrupt is called then the main execution stops executes the interrupt and returns back to the main in the exact point it was.

Your mcu supports recursive interrupts, in that case the interrupt gets stopped in order to execute the new interrupt, when that it done then the rest of the first interrupt is executed and after it is done the execution returns to main
If you get stuck in any of the interrupts then you will never return to main.

I don't know what operation you are doing inside the interrupt that may set stuck but you can use the watchdog so that the mcu resets if that happens.
 

i need an LED to be switch on for 200mili second when an interrupt INT0 occurs. and again it should watch for interrupts again
similar to a retrigggerable monostable.

if am using delay in the main program then it is uncertain about on time because it may not start right from the delay command.

So i have included it in ISR itself, but the recursive interrupt is not working fine.
is there any other method to do this
 

from the INT0 interrupt turn the led on and set a timer to give interrupt after 200ms , then in the timer interrupt turn off the led.
Is this what you mean?

What is supposed to happen if you get a second INT0 interrupt while the led is on and you count the 200ms , should the counting restart for another 200ms?
 
Thanks for the idea, is there any other method except timer as i have to use these for watching other processes
 

A timer is the only accurate method , if you are using all the timers then I can only think of delay_ms but you will get a higher delay depending on the interrupts during the delay plus the code will be stuck it that line for 200ms.

A delay inside the interrupt is not a correct method so the alternative is to set a flag variable inside the interrupt and in the while loop when the flag is set start a delay assuming that you can freeze the main execution for that period.
 

.. and in the while loop when the flag is set start a delay assuming that you can freeze the main execution for that period.

delay in main loop called by a flag, but if the normal execution was inside the same delay before the ISR, then it will again start from the same line and wiil include an extra delay.

this is why i was asking about goto specific line after ISR is over, i guess by editing the stack pointers i can do it but i don't know the address of the delay line code.
 

I's still not clear how you want the code to behave, you didn't reply to my previous question
What is supposed to happen if you get a second INT0 interrupt while the led is on and you count the 200ms , should the counting restart for another 200ms?

I don't know what you are doing with the timers but consider setting a timer to give an interrupt every say 10ms (or maybe lower), then depending on the rate you want to do things you can have several counter variables in the interrupt and do things every x interrupts.
This way the interrupt can be used to do several jobs (keeping a short code of course)

- - - Updated - - -

delay in main loop called by a flag, but if the normal execution was inside the same delay before the ISR, then it will again start from the same line and wiil include an extra delay.

this is why i was asking about goto specific line after ISR is over, i guess by editing the stack pointers i can do it but i don't know the address of the delay line code.

Not really , if the delay is already executing then it will resume to where it left off (if 100ms have been executer then 100ms more will execute), it is up to you to start a new 200ms delay but after the previous one has finished.

The only problem is that you will have 200ms and you want to execute a delay again you have to wait for the first one to finish and then use again a delay of 200ms but this can be fixed if you use smaller say 1ms delays , set the flag to 200 so that the 1ms is executed 200 times , if at some point during that you want to restart the 200ms delay (for example at 100ms when the flag variable is 100 because you got an INT0 interrupt) then just assign 200 again to the flag variable.
 

I's still not clear how you want the code to behave, you didn't reply to my previous question

if the MCU gets a second INT0 interrupt while the led is on, the counting should be restarted for another 200ms? its like a retriggerable monostable.
 

Ok , how about the 1ms idea that is executed 200 times and can be restarted every 1ms?
 

No What I mean basically is

Code:
volatile unsigned char flag;

interrupt [EXT_INT0] void ext_int0_isr(void)
{
    flag = 200;
}

int main(void)
{
    while(1)
    {
        While(flag > 0)
        {
            delay_ms(1);
            flag--;
        }
    }
}

Note that the delay not be 200ms exactly because there will be 200 loops executes and 200 flag-- plus any interrupts that may interrupt the loop and delay its execution.
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top