Interrupt Routine

Thread Starter

Dritech

Joined Sep 21, 2011
901
Hi all,

i am using assembly to do an interrupt routine. It is working fine but the only problem i have is that when the ISR is finished, i dont want the program to return to where it was. Instead i want it to go to the MAIN label. Is this possible ? can i eliminate the RETFIE instruction ??

Thanks in advance.
 

jimkeith

Joined Oct 26, 2011
540
If you do not use the return from interrupt function, the stack will 'walk' and trash all kinds of stuff. To get around this, you may decrement the stack appropriately before you jump to MAIN. Put a little test instruction in your code to output a specific stack location to prove that it is not walking.

If you have nested interrupts, it will be very difficult unless you jump to your initialization routine every time you return.

I speak from 8051 experience--your micro probably operates in similar manner.
 
Last edited:

MrChips

Joined Oct 2, 2009
30,618
This is a rather unusual way to use interrupts. Go to the main( ) program but reset the stack pointer (SP) or do a warm reset.
 

kubeek

Joined Sep 20, 2005
5,793
I don´t know what micro you´re using, or even if it has any stack at all. If it uses stack, you would want it to reset the pointer before you jump to MAIN.
For example on AVR you could activate watchdog timer and simply let the micro reboot, if it has one.
 

Thread Starter

Dritech

Joined Sep 21, 2011
901
Hi,

Thanks for your replies. I am using a PIC18F4550 micro and im using assembly to program it.

t06afre, if you know of a way that i can do it, i will appreciate it a lot if you can help me because i cannot find a way to do it.
 

joeyd999

Joined Jun 6, 2011
5,220
Hi all,

i am using assembly to do an interrupt routine. It is working fine but the only problem i have is that when the ISR is finished, i dont want the program to return to where it was. Instead i want it to go to the MAIN label. Is this possible ? can i eliminate the RETFIE instruction ??

Thanks in advance.
Can you explain why you want to do this? There is probably a *much* better way with far more predictable (and controllable) results.
 

Thread Starter

Dritech

Joined Sep 21, 2011
901
Hi joeyd999,

The program will be monitoring the temperature of the water. When a pre-set temp is exceeded, a motor will go into action. If for some reason the motor get stuck and therefore draws more current, an external interrupt will be activated to stop the system. When a switch is pressed, the ISR will stop and return to where it was. Now i dont want that to happen, instead i want it to go back to the main label to re-start checking the temperature.
 

kubeek

Joined Sep 20, 2005
5,793
Hi joeyd999,

The program will be monitoring the temperature of the water. When a pre-set temp is exceeded, a motor will go into action. If for some reason the motor get stuck and therefore draws more current, an external interrupt will be activated to stop the system. When a switch is pressed, the ISR will stop and return to where it was. Now i dont want that to happen, instead i want it to go back to the main label to re-start checking the temperature.
Then why not tie the switch to the reset pin of the uC?
 

t06afre

Joined May 11, 2009
5,934
I am somewhat puzzled about your approach. But inside the ISR at the end you can use the POP instruction and then the GOTO instruction to the main function. Then safely in the main function remember to enable interrupt. Test it in MPLAB and see how it works
 

joeyd999

Joined Jun 6, 2011
5,220
Hi joeyd999,

The program will be monitoring the temperature of the water. When a pre-set temp is exceeded, a motor will go into action. If for some reason the motor get stuck and therefore draws more current, an external interrupt will be activated to stop the system. When a switch is pressed, the ISR will stop and return to where it was. Now i dont want that to happen, instead i want it to go back to the main label to re-start checking the temperature.
You don't need an interrupt for this. I am sure you have at least a few tens of milliseconds between a stuck pump and the time you need to shut off the system without damage occurring.

The input signal from the over-current sensor can easily be polled in your main loop. When the signal is exerted, simply jump to the main loop. Done.

Save your interrupts for when timing *really* counts!
 

Papabravo

Joined Feb 24, 2006
21,094
This is structurally a very poor way to do things. It is far superior to to modify the non-interrupt portion of the program to do precisely what you want it to do under the given conditions than to go back and reinitialize everything from scratch. Every embedded systems programmer will tell you the same thing.
 

Thread Starter

Dritech

Joined Sep 21, 2011
901
Hi,

Thanks all for your help. I will try using BTFSC instruction to check the over-current sensor and if set jump to a stop subroutine. I will let you know if it works fine.
 

joeyd999

Joined Jun 6, 2011
5,220
This is structurally a very poor way to do things. It is far superior to to modify the non-interrupt portion of the program to do precisely what you want it to do under the given conditions than to go back and reinitialize everything from scratch. Every embedded systems programmer will tell you the same thing.
I agree with you, Papabravo. I didn't want to spend my whole day explaining to him how to really do it.
 
Top