Interrupt without return

dj_trippn

New Member
Hi all,

I have an application where I have a 3 position toggle switch to select a mode. I am using a 28X2 and the hardware input interrupt. I have the interrupts working correctly to detect what position the toggle switch is in. The purpose of using an interrupt for this is to jump straight to a different part of the program if the switch position changes.

Can I use a goto in my interrupt routine? Or do I always have to finish with a return. I have tried the goto which works but then the interrupt never triggers again. It it possible what I am trying to do?

Thanks,

Glenn
 

inglewoodpete

Senior Member
Hi all,

I have an application where I have a 3 position toggle switch to select a mode. I am using a 28X2 and the hardware input interrupt. I have the interrupts working correctly to detect what position the toggle switch is in. The purpose of using an interrupt for this is to jump straight to a different part of the program if the switch position changes.

Can I use a goto in my interrupt routine? Or do I always have to finish with a return. I have tried the goto which works but then the interrupt never triggers again. It it possible what I am trying to do?

Thanks,

Glenn
While an interrupt can be used for many things, the interrupt's prime purpose is to respond quickly to a brief input condition. Ie the input may not be detected in a 'normal' polling loop.

Again, generally, the interrupt routine's code should be brief. Ideally, the routine should set a flag and then exit. The routine does not have to reenable interrupts if that is to be done in the main code block (usually, you will want the interrupting condition to be removed prior to reenabling the interrupts. Finally, the flag set by the interrupt routine is detected by the main code loop and acted on.

To answer your question, no. The only ways out of your interrupt routine are to reset (restart) the PICAXE or use a Return statement.

However, if you arrange your code so that the part that you want to run is a subroutine (Ie can be called from the main code with a GoSub), then you can use a GoTo statement in the interrupt routine to pass execution to the subroutine. Then, when the subroutine reaches its Return statement, the return is effectively from the Interrupt.

Hope that makes sense.

Peter
 

tarzan

Senior Member
Interrupts must have a return. But you can RUN another slot from your interrupt, which will negate the need for the return.
 

dj_trippn

New Member
Thanks for the reply guys. I thought that would be the answer but was unsure. I was trying to use the interrupt so I wouldnt have to wait for the main code to finish and get to the polling stage. But it looks like Im going to have to make it work.
Or the running another slot idea suggested by tarzan might just work. Because I can run a spare slot straight away on interrupt and then check the position of the switch and run the correct slot, which will jump to the correct part of the code.

Thanks for the reply.
 
Top