Continue to Site

Welcome to

Welcome to our site! 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.

Go to start after interrupt?

Not open for further replies.


Junior Member level 3
Mar 15, 2011
Reaction score
Trophy points
United Kingdom
Activity points
I understand that when an interrupt occurs the micro controller returns to where it left from..

but my interrupt consists of a stop switch, i.e. after the iterrupt I want it to stop everything..

my code consists of running a motor in a while(1) loop.. after the hardware interrupt is pressed it should stop everything and then again wait for the start button to be pressed..
i thought of calling the start button function within the ISR, but that will leave the stack uncleared.

any way to get around this?

could you put your code and schematic... And also you mentioned after the hardware interrupt is pressed it should stop everything, that means you want controller itself turned off or only motor... If you want whole system [controller too] to turned off i can give one solution... This can be done by putting small hardware circuit... Using OR gate [74HC1G32] and Load switch [FPF2100] you can achieve this one...

OR gate has two inputs [A and B] B should connected push button [button one end will go to input of OR gate and other end goes to VCC with pull down resistor] and A should get connected to GPIO of controller, the output of OR gate [Y] should get connected to ON [3rd pin] of FPF2100 [with pull down resistor]... The VOUT [5th pin] of FPF2100 will get connected to VCC of microcontroller...

The logic is quite simple when you press push button, the output of OR gate will be high that is connected to load switch then power goes to controller... In your program make the GPIO high [Which is connected to other input of OR gate], then continuously power goes to controller...
Then stop switch is pressed, stop everything [Like what you told]...
Again start switch pressed, Hardware will take care of everything [Except making GPIO high]...:smile:

Thanks for your detailed reply, kandhu,

but I dont want to turn the microcontroller completely off, as after the interrupt, I want it to wait for the start button again, I just want tahts after teh stop switch is pressed it just stops running everything, i mean send 0 to all output ports, however after that I want it to wait for the start switchg again..

my code for the ISR as of now only contains of sending 0 to teh output ports =/

You could modify your code in the ISR routine, and use a simple loop waiting to the switch to be pressed again. Once it is pressed start everthing then exit the routine.

|I thought of that, but wont it leave teh stack mismanaged.. I mean when teh microcontroller goes to ISR, it stores what its doing on stack and then come back and pick up..

When you enter the routine, it stops the interrupt process. It only stores the return address.

You need something like this

Save registers.
stop the motor.
switch all outputs to zero.

Loop waiting for the switch to be pressed again.

start up the motor
restore the outputs.

clear any interrupt flags
restore registers
exit isr

save registers in the ISR , swap will help you

Not open for further replies.

Part and Inventory Search

Welcome to