Multiple interrupts

Lez T

Member
As a newbie here I would like to ask a question that I cannot at present find the answer to, the 'senior' members ( in the nicest possible way) will know the answers or point me in the right direction.
Is it possible to set several interrupts in the same program, to explain, I would like to have an immediate response to either input 6 or 7 or both?.
%11000000 would mask the relevant input pins for a 'condition'.
but my 'condition' would be either
'condition1' %01000000, or
'condition2' %10000000 or
'condition3' %11000000.
I cannot seem to find how I would create the correct syntax for this command and would I label them interrupt 1, interrupt 2, interrupt 3.
Thanks.
Lez.
 

Lez T

Member
@e.
I could do it this way if I only needed to see if any one of the ports became high but I cannot do this and see if both inputs 6 and 7 were high at the same time, apart from when they are each high individually. Could this be done if I write the input value to a variable and trigger the interrupt from there?.
Lez.
 

BeanieBots

Moderator
You set up the interrupt to trigger on ONE input line.
You have the other input connected to the same interrupt input via a diode.
Hence, either input will trigger an interrupt. (diode OR).

The first thing you do in the interrupt routine is check which inputs are high. This tells you which input (or both) triggered the interrupt.
 

Lez T

Member
@BB
I understand the principle of diode triggering the same input but this will not tell me which of input 5, or 6, or 7 , ( I know that 5 doesn't exist, this is for explanation only ) has caused the interrupt, to see all three states is what I am trying to achieve. If I diode triggered the three inputs together, which will cause the interrupt, could I then check the variable value, to which I have written the inputs to, to determine the input which has caused the interrupt.
Lez.
 

eclectic

Moderator
@Lez.
This is not meant as a definitive answer,
but, might help.

I breadboarded an 18X circuit, (on an AXE091)
using three switches and three diodes.

Input0 will always be high.
But, inputs 6 and/or 7 may be low or high.

Therefore, with a bit of programming Jiggery-pokery,
it will always show the combinations of high input(s).

Code:
#picaxe 18X

setint %00000001, %00000001 ; high on in0

main:
sertxd (" . ")
pause 1000
goto main

interrupt:
b0 = pin0
b6 = pin6
b7 = pin7


sertxd (cr,lf)
sertxd ("In0 = ",#b0," In6 = ",#b6," in7 = ",#b7,cr,lf)

pause 1000

setint %00000001, %00000001 ; Reset interrupt

return
Apologies in advance, if I've made any mistakes.

e
 

Attachments

KMoffett

Senior Member
Something like this:
Diode OR'ing the three inputs signals to one INPUT.
Set the interrupt for INPUT0.
If a high appears on INT0, INT1, or INT2 the interrupt on INPUT0 will be triggered.
Then look at each of the three inputs to see which was high.
Ken
 

Attachments

BeanieBots

Moderator
@Lez T,
2nd paragraph of post #4.

You can build the input values up into a variable and then use.
Branch, select case or if/then structures to do whatever is required for whatever combination of inputs caused the interrupt.
 

Lez T

Member
@BB
Apologies, I misread your post and didn't get what you meant, I thought this was the only way but didn't explain myself fully on post #3. I also was not sure if it was possible.
Thanks to all who helped. I will attempt this and no doubt have some more questions on this shortly.
Lez.
 

zsalya

New Member
setint implicitly does AND

Per manual (section2, p202) the first argument for setint performs an implicit AND.
So to interrupt on pins 6 and 7 high (Post #3, not Post #1) the relevant code looks to be setint %11000000, %11000000.

Does this work?

If so, is there any reason to prefer diode mixing for AND?
(OR is a different story)
 

inglewoodpete

Senior Member
Unless I'm misreading the problem, diodes are not necessary.

It's just a matter of configuring the SetInt command properly.

Code:
SetInt %11000000, %11000000 'Interrupts only when both i6 & i7 are high

SetInt %00000000, %11000000 'Interrupts only when both i6 & i7 are low

SetInt Or %11000000, %11000000 'Interrupts when either i6 & i7 are high
The first command you should do in the interrupt routine is (like) b0 = pins If the condition is still there after about 1mS, b0 will tell you what caused the interrupt. Otherwise, you will have to use hardware interrupts.
 

BeanieBots

Moderator
You do NOT need to use any diodes for interrupts if you want 'AND' conditions. They are only required for 'OR' (see extra below) and now that 'setinit NOT' has been implemented, they are no longer required for that either. (also see extra below)

When using interrupts the 'AND' way, ONLY ONE condition can ever trigger the interrupt so there is no need (or point) in testing the input conditions. When using 'setint NOT', ANY condition which is NOT true can trigger the interrupt so in most circumstances it will be necessary to test the inputs.

Setint OR is a fairly new addition and negates the need for the previously traditional need to use diodes.
 
Last edited:
Top