Interrupt Routine

Discussion in 'Programmer's Corner' started by Dritech, Jan 28, 2012.

  1. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    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.
     
  2. jimkeith

    Active Member

    Oct 26, 2011
    539
    99
    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: Jan 28, 2012
  3. MrChips

    Moderator

    Oct 2, 2009
    12,415
    3,354
    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.
     
  4. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,669
    804
    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.
     
  5. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    Which micro are you using? it can be done i think
     
  6. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    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.
     
  7. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    Can you explain why you want to do this? There is probably a *much* better way with far more predictable (and controllable) results.
     
  8. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    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.
     
  9. kubeek

    AAC Fanatic!

    Sep 20, 2005
    4,669
    804
    Then why not tie the switch to the reset pin of the uC?
     
  10. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  11. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    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!
     
  12. Papabravo

    Expert

    Feb 24, 2006
    10,135
    1,786
    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.
     
  13. Dritech

    Thread Starter Well-Known Member

    Sep 21, 2011
    756
    5
    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.
     
  14. joeyd999

    AAC Fanatic!

    Jun 6, 2011
    2,673
    2,712
    I agree with you, Papabravo. I didn't want to spend my whole day explaining to him how to really do it.
     
Loading...