More than one interrupt using setint

djmikeys

New Member
Hi, I'm trying to have more than one interrupt in my code, I have written what I thought to be the correct code, but only the first interrupt works (led1). Here is the code....

setint %00000100,%00001100
setint %00001000,%00001100

main:

high 6
high 7
pause 60000

goto main


interrupt:


led1:
low 6
pause 1000

if pin3 = 1 then goto led1
setint %00001000,%00001100
return

interrupt2:

led2:
low 7
pause 1000

if pin2 = 1 then goto led2
setint %00000100,%00001100
return

Has anyone managed this before?
heers,
Mike
 

tiscando

Senior Member
You cannot have more than 1 interrupt really.

You could have this:
Code:
main:

high 6
high 7
for w1=1 to 50000
if pin2=1 then gosub interrupt
if pin3=1 then gosub interrupt2
pause 1

goto main

...
 

kevrus

New Member
May I ask what the 'pause 60000' does in the main code? The outputs 6 & 7 do not turn off when the pause expires.
If not required then how about

Code:
main:

do
high 6
high 7
if pin2=1 then gosub interrupt
if pin3=1 then gosub interrupt2
loop


interrupt:
low 6
pause 1000
goto main

interrupt2:
low 7
pause 1000
goto main
 

hippy

Ex-Staff (retired)
setint %00000100,%00001100
setint %00001000,%00001100


Any prior SETINT is disregarded when another SETINT command is executed, so the only interrupt which will be responded to is when pin2=0 and pin3=1.
 

kranenborg

Senior Member
Hello,

Consider searching the forum on "Diode Mixing" and then you will find a number of links that will show how to implement multiple interrupts (that is true interrupts without having to poll inputs continuously). In link http://www.picaxeforum.co.uk/showthread.php?t=10333&highlight=diode+mixing I have added a circuit that uses active LOW interrupts, in your case (active HIGH interrupts) you would reverse the diodes and put the resistor to GND in stead of Vcc.

Hope this helps ...

/Jurjen
 
Last edited:

djmikeys

New Member
Hi,

The pause is pretty important, its a simplified code for something more complex I am making. What I need multiple interrupts to do is break that large pause and commence a sub-routine, I also need these subroutines to be interrupptable, does that make sense?
I tried a few of the suggestions but they dont have that big initial pause so they wo't really work, thanks for the suggestions anyway.
 

hippy

Ex-Staff (retired)
What you are trying to do should work but you will need to modify the way you are trying to use interrupts as only one interrupt is allowed at any one time ( the latest SETINT will overwrite previous SETINT's ).

You can either change and add SETINT's for various areas of code or in response to previous interrupts detected, or you can merge ( for example, diode-mix ) all interrupt sources to create a single interrupt and determine what the actual cause of the interrupt was within the interrupt itself.

If you want an interrpt to enter a subroutine and then have that subroutine interruptable that will be a little more complicated as it's not possible to have nested interrupts in this way, the RETURN of the 'interrupt:' routine must be executed before further interrupts can be responded to. You will need to set flags and alter program flow in the main body of the program rather than do everything within the interrupt handler.
 

djmikeys

New Member
"You can either change and add SETINT's for various areas of code or in response to previous interrupts detected"

Is this not what I have done in the code in the initial post on this thread? Where should the second setint be witin in code if not where I have currently got it? I have spent ages trying different code orders but still to no sucess...

Cheers,
Mike
 

hippy

Ex-Staff (retired)
I cannot really say where the second SETINT should be as I don't know what the program is meant to achieve in total, but, as it is, because of the two consecutive SETINT's, the first may as well not be there.

The SETINT directs interrupts to the 'interrupt:' routine in all cases, so adding an 'interrupt2:' will never get that executed unless called / jumped to from within 'interrupt:'.

If you were looking for cars you could interrupt on "red car", "yellow car", "red and yellow car together", "no cars", "no red car", "no yellow car" and could change the SETINT at any time to choose any one of those combinations. Where you would put the required SETINT's would depend on what you wanted to achieve.
 

djmikeys

New Member
Hi Hippy, thanks for your reply. What I want the code to do is run for the 60sec pause, and loop that until either pin 2 or 3 is high, then I would like it to skip to the relevent part of the code. Basically when 2 is high and 3 is low goto led2 and when 2 low and 3 is high then goto led1. If pin 2 and pin 3 are low then go back to the start. I have got this new code but it is still not quite right, you have to put pin 3 high before pin 2 will go high.

setint %00001000,%00001100

main:

high 6
high 7
pause 60000

goto main


interrupt:


led1:
low 6
pause 10000
setint %00000100,%00001100
if pin3 = 1 then goto led1
if pin2 = 1 then goto led2
setint %00001000,%00001100
return

interrupt2:

led2:
low 7
pause 10000

if pin2 = 1 then goto led2

return



Cheers,
Mike
 

westaust55

Moderator
Hi Hippy, thanks for your reply. What I want the code to do is run for the 60sec pause, and loop that until either pin 2 or 3 is high, then I would like it to skip to the relevent part of the code.
Unfortunately, the SETINT command works as an AND function with all of the designated pins.
While having an OR function would be better, AND'ing is what we have


Where you have the command:
setint %00001000,%00001100

this is saying:
watch pins 2 AND 3 and when pin 3 goes high AND pin 2 goes low then interrupt.

also:
setint %00000100,%00001100
equates to watch pins 2 AND 3 and when pin 3 goes low AND pin 2 goes high then interrupt.
 
Last edited:

djmikeys

New Member
Thanks for the reply. I had a look at the 'diode mixing', I guess this is going to have exactly the same problems?

Cheers,
Mike
 

BCJKiwi

Senior Member
If each output to be sensed is connected to the same input via a diode for each output, this provides the 'missing' OR function.

So the interrupt monitors this single input and will trigger if either output goes high.

Within the interrupt routine, determine which output(s) is(are) high and jump to the relevant code.
 

Technical

Technical Support
Staff member
Unfortunately, the SETINT command works as an AND function with all of the designated pins.
While having an OR function would be better, AND'ing is what we have
If you want to OR instead of AND use the NOT keyword in your SETINT statement (and invert the bits)

e.g.

Code:
setint NOT %00000000,%00001100
does exactly the same function as these lines combined

Code:
setint %00000100,%00001100
setint %00001000,%00001100
setint %00001100,%00001100
- if either of the two pins goes high the interrupt is triggered.
 
Last edited:

westaust55

Moderator
If you want to OR instead of AND use the NOT keyword in your SETINT statement (and invert the bits)

e.g.

Code:
setint [B]NOT[/B] %00000000,%00001100
True and useful to those with an X1 or (forthcoming X2) part.

mshorter has NOT said which PICAXE is being used in this thread :confused:

but elsewhere has indicated has an 18X.
http://www.picaxeforum.co.uk/showthread.php?t=10710&p=85041



EDIT: Oh for people stating a bit more about which PICAXE they are using with respect to each thread. :rolleyes:[
 
Last edited:
Top