interrupting two different subroutines?

212

Senior Member
I tried this in the simulator and it works with that, but will it work the same way in real life too??? I want to interrupt two different subroutines, and I think the interrupt has to be the same...only one interrupt sub allowed right? I want the code to return to the sub that was interrupted, not necessarily to the first one.


Code:
Main:

Setint %00000000,%00000100
high 0
pause 2000
low 0
pause 2000
goto testing

testing:
 
 Setint %00000000,%00000100
 high 1
 pause 2000
 low 1
 pause 2000
 goto main
 
 interrupt:
 
 high 4
 pause 2000
 low 4
 Setint %00000000,%00000100
 return
 
Last edited:

BeanieBots

Moderator
An interrupt will return to the next command after the one that was interrupted irrespective of where that command is.

Incidently, besides the interrupt routine, your example has NO subroutines in it.
 

hippy

Ex-Staff (retired)
The interrupt's return will always return to continuing from where it was when the interrupt occured. So, yes, it will do as you want it to.
 

lbenson

Senior Member
I know your code as shown may be just an abbreviation of what you are planning, but it is not really two subroutines, just a single routine with a label in it. You could remove "goto testing" and "testing:" and it would work the same way.

Regarding your questions, it may be more clear if you think of the interrupt as interrupting your program where ever it is, and when done returning to the instruction following the one after which the interrupt was detected. So the answer is yes.

Your code shows some confusion about how Setint works. If you want the interrupt to be activated anywhere in your program, you only need to set it in two places--at the very beginning of your code (e.g., before "Main:", where it will never be executed again), and in the "interrupt:" subroutine, immediately before you return from the interrupt. You would only need to use "Setint" within looping code if you had a section of code which for some reason you did not want interrupted--for instance perhaps in running a few instructions to another piece of equipment in which timing was critical. Then you would issue "Setint off" before running the critical code, and your "Setint x,y" when you finished that critical code.

Otherwise the answer is that interrupts will work as you intend.
 

212

Senior Member
I was being funny right before your reply lbenson, but I'm glad you offered that anyway. I did not know all that, and I will be changing my code now. Yes parts are critical timings, and I do not want them being interrupted. So I must turn the interrupt off before it happens....then back on after. Not a day has gone by without me learning something new from you guys, and I really appreciate the help!
 

westaust55

Moderator
Also as written in Post1, you do not need the SETINT command in the line after the label Testing:

You can turn off SETINT and also give a NEW SETINT command if you wish to interrupt with a different situation of input pins.
Note however the program will ALWAYS goto the one Interrupt: subroutine
 
Last edited:

BCJKiwi

Senior Member
It should (untested) be possible to create different actions within the interrupt: subroutine depending on the pin interrupted.

1. capture the interrupt state as the first operation within the interrupt: subroutine
2. test again to determine which pin was interrupted
3. use If .. then.. elseif..else..endif within the interrupt subroutine to run the relevant code for the particular interrupt condition
4. rerun setint
5. exit the interrupt: subroutine
 

212

Senior Member
All replies are appreciated!!!

I also learned something on my own too...I'm sooo proud :) I THOUGHT I knew all about how the interrupt worked now, but found something to add. I read that the interrupt continued for as long as the condition existed...and it seems to. But, I did not realize that it kept running over and over instead of sit and wait. I was using the interrupt just to add to a counter, so I could do something different according to how high the number went. My interruption lasts about a second or so, and apparently the number kept going higher and higher all during that second. I have no idea how high it got, but higher than I was wanting for sure. It went something like this....not literally though.

Code:
main:
Setint %00000000,%00000100
pause 1000 
if b1 = 10 then
goto something
endif
goto main

interrupt:

b1 = b1 + 1
Setint %00000000,%00000100
return

something: 

pause 1000
b1 = 0
goto main
That went funny on me, so I put

Code:
if b1 = > 10 then   'made it equal to or greater than 10
And it worked funny still??? So I changed the interrupt to

Code:
interrupt:

b1 = b1 + 1
pause 1500
Setint %00000000,%00000100
return
And it works like I though it would in the first place :)...and I'm done editing I think...
 
Last edited:
Top