Let's Make Robots!

28x2 interrupt to bring it out of Doze

Hi can anyone help. I have a 28x2 and am trying to write a bit of test code for an interrupt to bring it out of Doze. I believe the only way to do this is via a hardware interrupt pin. I have read the code manual but i just don’t understand it. Can any shed some light on this in real simple terms? This is code i have been trying.


#picaxe 28x2
let dirsA = %00000000
let dirsB = %00000000
let dirsC = %11111111

hintsetup %00000010 'enable INT1 only
SETINT %00000010,%00000010,B

main:
doze 5000 'nap
goto main

interrupt:
serin b.1,t2400,b1
SETINT %00000010,%00000010,B
if b1=10 then L1
if b1=11 then L2
if b1=12 then L3
goto main
 
L1:
high c.4
pause 2000
low c.4
Return
 
L2:
high c.5
pause 2000
low c.5
Return
 
L3:
high c.6
pause 2000
low c.6
Return

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

ok cheers for this. i'll have another read through the manual and see if i can make sense of it.

if anyone has any code of similar I’d like to see it as it helps to looks at something as I’m trying to decipher it.

thanks again

V

 

Look at hesersetup and intflags. If you want to interrupt on a serial send, you set your hsersetup to receive in the background and set your int/flags to interrupt when you get a serial send. In the interrupt subroutine, you need to reset your pointer to go back the number of bytes you received, read them from the scratch pad, and then do what ever you want with them. Also, all interrupt routines MUST finish with a return not a goto and should be at the very end of the code.

hsersetup

setint/ setintflags --also learn how to clear your flags so it doesn't interrupt right after leaving the int sub routine.

put/get

ptr

scratchpad

That should get you started.

Didn't realize you could do that with the X2's....man those things rock!!!

Good catch btw ctc.  :)

EDIT See CTC's response, as it points out soemthing I wasn't aware of.

The setup of the INT is fine, portb pin 1.

The problem is that you are attempting to get serial data from a high pulse and using the int to start the read. The serial port is going to be high from whatever device you have so you will get a low then high pulse missing the first bit or so(unless you are sending a trigger bit). so you might not be getting all of the data and serin stalls. Since you also don't have a timeout for the serin, it will sit there waiting for data which may never come. Further, if you attempt to send any more data, you will fill up  the serin buffer from the first data packet and partial second data packet. you will have an incorrect b1 value at this point, setint will be set, and immediately triggered sending more partial data to the serin...the loop continues.

How to fix it, use something else to trigger the the int like a pulse first.

Use the timeout for the serialin

put the setint later like in the main loop before the doze command is run.