interrupt problems picaxe 28x1

sub-bg

New Member
we are having problems with our interrupt program for the servos!!
at the moment in doesn't jump straight to the command
it goes through each line of the code and then jumps to a certain condition.
I want to intterupt straight a way.
my code is:


-----------------------------------------------------------------------
setint %00000001,%00000001
setint %00000010,%00000010
setint %00000100,%00000100
setint %00001000,%00001000


main:
servopos 0,150 ‘ move servo to one end
servopos 1,150 ‘ move servo to one end

pause 2000 ‘ wait 2 seconds

goto main


interrupt:
if pin0 = 1 then Fwd
if pin1 = 1 then Rig
if pin2 = 1 then Lef
if pin3 = 1 then Bck


Fwd:
servopos 0,180 ‘ move servo to one end
servopos 1,180 ‘ move servo to one end
'if pin0 = 1 then interrupt
pause 2000 ‘ wait 2 seconds
setint %00000010,%00000010

goto main
Rig:
servopos 0,180 ‘ move servo to one end
servopos 1,120 ‘ move servo to one end
'if pin1 = 1 then interrupt
pause 2000 ‘ wait 2 seconds
setint %00000100,%00000100

goto main
Lef:
servopos 0,120 ‘ move servo to one end
servopos 1,180 ‘ move servo to one end
'if pin2 = 1 then interrupt
pause 2000 ‘ wait 2 seconds
setint %00001000,%00001000

goto main
Bck:
servopos 0,120 ‘ move servo to one end
servopos 1,120 ‘ move servo to one end
'if pin3 = 1 then interrupt
pause 2000 ‘ wait 2 seconds
setint %00000001,%00000001

goto main

--------------------------------------------------------------------------


does anyone know what we are doing wrong??

Many thanks
 

hippy

Ex-Staff (retired)
You enter the Interrupt: routine but are exiting it with "goto main". It has to be exited with a RETURN, so replace all your 'goto main' with 'return' ( except the first which is part of the main loop ).

Also you have multiple 'SetInt' at the start of the program. Only one SetInt can be active at any one time, the first three will be rendered ineffective by the fourth. You will only get your first interrupt when Input Pin 3 goes high.

Finally, you need to execute a Servo command on each servo pin to start the internal servo handler working. After that you can use ServoPos to set the servo positions without restarting the servo handler.
 
Last edited:

BeanieBots

Moderator
You will need to diode OR your inputs to one pin so that no matter which input goes high, the interrupt pin will go high. Also connect each input put it's own input pin.
Then, when the interrupt is triggered, check the input pins to see which one caused it.
 
Top