Interrupt 'returning' to another part of code

Mikler

Member
Hi!

My understanding is that when an interrupt routine has finished, it will return to where it was up to in the code when the interrupt happenned.

My problem is that if an interrupt has occured and the interrupt routine has happened, I want it to go elsewhere, typically to start at the beginning of my code.

Any solutions?

Can I do a reset?

Help appreciated

Thanks

Mik
 

Technical

Technical Support
Staff member
If using an X1 or X2 part you can use the 'reset' command within the interrupt subprocedure.
 

westaust55

Moderator
When you go back to the start do you expect the varaible data to be retained or cleared?

Larger PICAXE chips have a reset pin so depending on what is causing the need for an interrupt and reset the hardware could achieve your goal as an alternative.
 

hippy

Ex-Staff (retired)
Using a variant of the mechanism described in Post #18 here ...

http://www.picaxeforum.co.uk/showthread.php?t=11944&page=2

It is also possible to cause a reset by initiating a fake download, pin 4 this time linked to SI but using "HIGH 4". This may be handy for PICAXE's which do not have a reset input but there will be a significant delay between issuing the "HIGH 4" and the program actually restarting, and 'garbage' will be seen on Output Pin 0 ...

#Picaxe 08M
SerTxd( "RESET " )
Do
Pause 5000
High 4
SerTxd( "Never gets here with pin4 linked to SI",CR,LF )
Loop
 

alpacaman

Member
If you don't want to lose your variable data how about a simple goto command right before the return statement in the interrupt routine. Seems a lot simpler than a reset and you can go to any spot in your program that you want to.

And it will work with any Picaxe chip
 
Last edited:

hippy

Ex-Staff (retired)
And it will work with any Picaxe chip

Unfortunately it will not, or not work in the way people would usually be hoping it will.

When an interrupt occurs all further interrupts are locked-out until the associated RETURN occurs. So, while you can jump to any piece of code with a GOTO, no further interrupts will be responded to.

One can GOTO and GOSUB ( subject to subroutine depth limits ) elsewhere within the interrupt routine then come back, execute the associated RETURN and resume execution where the program was interrupted, but unless that is done, no more interrupt response.
 
Last edited:

SD2100

New Member
Better than a POKE in the eye

Here's another option when your getting desperate, reset the program counter !!!, the program restarts instantly and all variables are cleared. If you want to retain variables then they will have to be saved in eeprom. This method isn't recommended but sometimes you havn't got a lot of options.

Code:
interrupt:

'Do something here		

poke $0A,0: poke $02,0 'Restart program
 
Top