interrupt command

a.a.mcmahon

New Member
I'm using the microbot for a project and I want it to follow a line. I can get that to work fine but I want it to react accordingly to if either side of the bumper is hit.
I can set the interrupt command to look at left bump or right bump but not look at both at the same time. I've looked through the help files and found that I can interrupt which activates of 'Lbump AND Rbump' are high, I want an interrupt for 'Lbump OR Rbump' does that make sense? Any help would be gratefully appreciated!!
 

nick12ab

Senior Member
Look at the hintsetup and setintflags commands in PICAXE Manual 2. The quote below implies that the hardware interrupts are OR based.
Activation of each individual pin sets two flags, its own unique flag and the shared ‘hintflag’. The flags must be cleared manually in the user’s PICAXE program. The hintsetup command enables the hardware setting of the flags only, it does not trigger an actual PICAXE program interrupt.
P.S. A graphical wizard for hintsetup is available here.
 

westaust55

Moderator
Welcome to the PICAXE forum

Presuming that you mean the BOT120 PICAXE-20X2 Microbot then as you have a 20X2 PICAXE chip there is the NOT parameter.
The NOT parameter is available for X1, X2 and M2 parts.

By way of example, say both switches are normally low and you want to detect if either goes high then in pseudo code that becomes if the pins are NOT both low.
Have a read of the SETINT section in PICAXE manual 2 (V7.8) page 215 and come back if you have further questions.


EDIT:
the microbot has the bumpers connected to C.1 and C.3 so the SETINT function needs to be used. The HINTSETUP command mentioned by nick12ab uses pins B.0 and B.1 on the 20X2 which are used for other purposes on the microbot (ie BACK-C and Left LED).
 
Last edited:

g6ejd

Senior Member
Your best option is to determine what created the interrupt when it is activated, effectively deciding (the OR function) by testing the interrupt source flags or pins. If L and R Bump trigger sources are on seperate pins, then you can enable them both to interrupt and polling the flags in the interrupt routine will resolve the source for you.
 

a.a.mcmahon

New Member
Thank you all for your warm welcome and quick reply.
Having just turned 18 I would no way near consider myself as advance as any of you guys and girls, my program I am trying to work is below;
It works fine, just that it only works for one bumper side, which is left. I can get it to work for the right bumper (by replacing %00000010 with %00010000) but not both simultaneously, yes I am using the BOT120 PICAXE-20X2 and the setint command doesn't work for both, I have a massive book by David Lincoln on the PICAXE series and that doesn't shed too much light. Are there any other command I can use, could any of you suggest with what lines I would need to change or add below?

Once again, many thanks.


setint %00000010, %00000010 'Tells the PIC to constantly look at pinC.1 (Left Bumper)

input c.5 'Sets motor speed fast

start:
symbol MID_LEVEL = 246 ' Point between marked black line and white reflective path floor
symbol LIMIT = 10000 '5 cycles, change to 10000 for longer patrol path
b2 = 0 ' sets a value back to zero

main: ' main routine to get the microbot to follow a black line for a certain amount of time
for W6 = 1 to LIMIT 'loop command, will loop for 'limit' amount of times,
if pinC.1 = 1 or pinC.3 = 1 then
halt A
halt B
else
readadc 8, b1
if b1 < MID_LEVEL Then
forward A
halt B
else
halt A
forward B
end if
end if
next W6
halt A
halt B

scan: ' tekks another off-board PCB that it has stopped and is ready to scan the area
high B.0
pause 200
low B.0

idle:
if pinC.4 = 0 then idle ' will stop until the external PCB has finished scanning and tells to continue
goto main



interrupt: 'if pinC.1 is hit at any time program runs here to decide appropiate action

forward A ; go forwards
forward B
; test bumpers
; to see if hit
if pinC.3 = 1 then doLeft
if pinC.1 = 1 then doRight


doLeft:
backward A ; reverse for 0.1s
backward B
sound B.2,(50,10) ; beep
pause 200
forward A ; turn for 0.05s
backward B
pause 120
setint %00000010, %00000010 ' reset the interrupt command
return ' returns to main routine


doRight:
backward A ; reverse for 0.1s
backward B
sound B.2,(100,10) ; beep
pause 200
backward A ; turn for 0.05s
forward B
pause 120
setint %00000010, %00000010 ' reset the interrupt command
return ' returns to the main routine
 

Goeytex

Senior Member
From Manual 2 Page 215

setint
Syntax:
SETINT OFF
SETINT input,mask (AND condition)
SETINT AND input,mask (AND condition)

Additional options for M2, X1 and X2 parts:
SETINT OR input,mask (OR Condition)
SETINT NOT input,mask (NOT the AND Condition)
Additional options for X2 parts:
SETINT input,mask,port
SETINT NOT input,mask,port


Just change your code to use the OR. < setint OR .......... >


 

g6ejd

Senior Member
Modify the command 'setint %00000010, %00000010' to add in the other input, so in this example 'setint %00010010, %00010010' now either input will create an interrupt.

In the interrupt routine test the interrupt flags to see which one created it, could be both ( maybe ) and process the source accordingly. You have already produced the code for both directions so all you need is a simple if test to proceed your code at the interrupt label and send control as needed.
 

a.a.mcmahon

New Member
That was the first thing I tried after reading the manual as well as the book but that I found that it only worked if both were high.
I found that setint on its own defaults to a logic gate way of think of 'AND' I then discovered that by putting setint OR, setint NOR even setint NAND I can set the course of logic the interrupt command can take. Many thanks for your reply though! :)
 

westaust55

Moderator
Try the line:
SETINT NOT %00000000, %00001010, C ; mask %00001010 will look at pin 1 and pin 3 on port C

Untested (by me) but the concept is that:
1. the mask %00001010 in conjunction with the port “C” identifies C.1 and C.3 as the interrupt enabled pins.
2. The NOT %00000000 then is used to identify when both pins are not low in this case.
If the bumber inputs are held high, then change the %00000000 to %00001010

Also, when posting program code listings of more than a few lines, please wrap the code in the [code] and [/code] markers/tags so that your program code appears in a sub window within your post rather than stretching the post right out. This is in line with the forum requirements in the sticky post “Read Me First!” at the top of the active forum section here: http://www.picaxeforum.co.uk/showthread.php?7679-Read-Me-First!
 

a.a.mcmahon

New Member
Hello, many thanks for your reply, and yes I did read it and I thought I did wrap it in code by pressing the button and obviously it didn't work. Sorry about that. Everything on computers, bar forums, I'm alright with. Thanks
 
Top