# Setting up an interrupt properly

For school this year we are making picaxe 08m robots and have a sheet of funtions we need to fill out. This one is attempting to seek shade It needs more work but right now i just need help with the interrupt code,  I have this code here

symbol light = pin3
symbol movment = w0
setint %00100000,%00100000

top:
if light = 0 then low 1
if light = 0 then gosub find
endif
if light = 1 then high 1 low 2 low 4
endif
goto top

find: ; using motors and a random chance of going in one of three directions for 10 seconds
random b1
if b1 >= 1 and b1 <= 75 then high 2 high 4 pause 10000
endif
if b1 >= 76 and b1 <= 150 then high 2 low 4 pause 10000
endif
if b1 >= 151 and b1 <= 255 then low 2 high 4 pause 10000
endif
return

interrupt:
high 1
low 2
low 4
setint %00100000,%00100000
return ; I would like the intterupt to turn the motors off and turn the LED on

the problem is I can find a tutorial that tells me what I need to get the setint to function properly, just how to make one using a specific example. If you do fix the code out of your own knowledge can you please also explain it, otherwise a good tutorial would help too :D

Pointers/Questions

Is pin3 connected to something like a LDR or cds cell? If so, why are you not using the analog capabilities of the 08m?

You do realize that w0 = b0 and b1. So, anything you write to w0 will affect b0 and b1. Also, anything written to b0 and/or b1 will affect the contents of w0.

More symbol definitions will help make your code more readable. symbol LED = 1 symbol LMOTOR = 2 symbol RMOTOR = 4 maybe even symbol DRIVE = 10000 and use pause DRIVE to replace the pause 10000. That way if 10 seconds seems too long you change it in one place and it affects all the pauses.

Maybe rewrite your first if/then statement in top: to be

if light = 0 then

low 1 'maybe even low LED

gosub find

endif

As I mentioned above, b1 is part of w0. So, you should maybe change the b1s in your find subroutine for b2s.

yep like i said it needs

yep like i said it needs some work and thanks for that but right now im stummped on how to get the interrupt.

I used w0 on an earlier one and its just a junk line atm.

The analouge abilities are pretty indepth and ill be sure to look into them but for the purpose of this the system is good enough. Personally I feel labelling everything is not really neccicary for the level of work im at but ill get to it when i try combinding more functions

What do you have connected to pin 5?

Your code wants to have an interrupt when pin5 is high, but, without knowledge of your circuit I can’t help much more. In fact, if you can, post a schematic or a picture of what you are working with currently.

fair enough ill

fair enough ill try

it works and its not everything but its the parts used, the chip notch is pointing up incase you were wondering

copy and paste that link its

I noticed

There is some extra ‘garbage’ attached to the end of the link.

If I am reading the manual correctly,

there are 4 outputs 0,1,2, and 4 and 4 inputs 1,2,3,4. If I am correct, you will never set bit 5. So, you will never trigger an interrupt.

dont even know what the

dont even know what the binary says after the setint (was a blind stab with the idea that a digit was a pin),  how can it be set up so that when In3 is 1 then interrupt?

If you are alright with blind stabs,

setint %00000100,%00000100

I was just counting from right to left on your original. I was wrong though, you were expecting a change on pin6.

symbol light = pin3 symbol

symbol light = pin3

symbol movment = w0

setint %00001000,%00001000

top:

if light = 0 then low 1

if light = 0 then gosub find

endif

if light = 1 then high 1 low 2 low 4

endif

goto top

find: ; using motors and a random chance of going in one of three directions for 10 seconds

random b1

if b1 >= 1 and b1 <= 75 then high 2 high 4 pause 10000

endif

if b1 >= 76 and b1 <= 150 then high 2 low 4 pause 10000

endif

if b1 >= 151 and b1 <= 255 then low 2 high 4 pause 10000

endif

return

interrupt:

if light = 1 then high 1 low 2 low 4

endif

setint %00001000,%00001000

return

that functions as I inteded it now, simulate it if you want and thanks for your input