Can I program two interrupts in one program with different interrupt program? THANK U


New Member

I'm using PICAXE 28x. I need to design a program to control the motors through relays. There are different sequence for the motors.

Inputs: pin0 is for ON/OFF purpose
pin1 is for sequence purpose

label_1E: 1st sequence
label_25: 2nd sequence
label_9B: 3rd sequence
label_CF: return to 1st sequence

When input pin0 (ON/OFF)is pressed then 1st sequence is executed. Then, when the sequence1 is interrupted by the pin1 (change sequence) button. The 2nd sequence will be executed after a short delay. So everytime the pin1 is pressed, it will change sequence.

Q1. I would like to program such that when the pin0 (ON/OFF) is pressed to stop(OFF) the whole system. I wanted to use interrupt for the ON/OFF. However, I had used it for changing sequence. If a 2nd interrupt is used, I would like to have a different interrupt program from the 1st one.
Is there other way to OFF the program?

setint %00000000,%00000010

label_6: if pin0=1 then label_6

label_1E: high 0
wait 5
low 0
wait 5
if b1=0 then label_1E

label_25: high 1
wait 1
low 1
wait 1
if b1=1 then label_25

label_9B: high 0
wait 1
low 0
wait 1
if b1=2 then label_9B

label_CF: let b1=0
goto label_1E

interrupt: b1 = b1 + 1
pause 2000
setint %00000000,%00000010

Hi, I don't understand you code but I think the answer is that the picaxe interrupt system can only detect a pre-defined pattern on the chosen inputs. If you want two buttons to cause interrupts then you need to:

- OR these button inputs in hardware (so the output of the OR gate is active when ButtonA or ButtonB is pushed). This 'OR gate' can be just two diodes and a resitor.
- Set the Picaxe to interrupt on the state of the OR gate output.
- In the interrupt routine check the values of ButtonA and ButtonB to determine how to handle the interrupt.

So this solution would need to use 3 picaxe inputs.

Alternatively, forget interrupts and just make your code check the button states frequently (just need two picaxe inputs).
You can only have one Interrupt sub routine but it is still possible to have many buttons cause an interrupt and take different actions depending on which button(s) were pressed.

Let's say you have three buttons (A,B & C) and interrupts are arranged to trigger whenever input 0 is pulled low.
Connect ALL the buttons to input 0 via diodes such that if ANY of the buttons are pressed, input 0 will be pulled down.
Now, any button press will trigger the interrupt. But which button caused it?
To know that, two of the buttons must also be connected to other inputs.
So, let's say button B is also connected to input 1 and button C is also connected to input 2.
Now, if button A is pressed, only input 0 goes low and the interrupt is triggered.
If button B is pressed, input 1 goes low AND input 0 (via the diode) thus activating the interrupt. Similar for button B with input 0 and input 2.

In your interrupt routine, test the inputs to know which button(s) caused it. Then jump to the approriate peice of code. I find the BRANCH command particularly useful for making the jump.
You should be able to achieve two buttons with only two inputs and one diode. Button A on input 1, button B on input 2. Diode pointing from B to A. Trigger the interrupt on A. Then look for high on B. If absent then A was pushed.