How Is This Possible????
Navic
Posts: 38
I have a BS2px hooked up to 3 sets of IR TX/RX's that work just fine. I'm transmitting data via a serial connection to another device, and after that data is sent the BS2px waits for a received byte. Everything seems to work just fine until two of my four conditionals repeat instantly every time for no apparent reason. Here is my code:
Here's what I get in my debug window when this is running and the 'front' condition is met:
Front
Front
Response from Front
This happens with the 'both' condition also:
Both
Both
Response from Both
But when 'left' or 'right' conditions are met, everything works as I envisioned:
Left
Response from Left
Right
Response from Right
I've tried reordering the IF statements, setting IRR, IRL, IRF to 1 before looping (as you can see), tried adding timeout to the SERIN to jump to a label that pauses for 5 seconds, pausing randomly during the code, changing the GOSUB orders, I just can't see why 'front' and 'both' repeat readings! Every time it should wait for a response, 'left' and 'right' work fine, what is going on here??
Thanks for your help, I'm not a master programmer but I think my code is correct.... this is driving me crazy!!
IRL VAR Byte IRR VAR Byte IRF VAR Byte ard VAR Byte DO GOSUB IR_Left GOSUB IR_Right GOSUB IR_Front IF IRL = 0 THEN DEBUG "Left", CR SEROUT 0, 396, [noparse][[/noparse]"2"] PAUSE 50 SERIN 1, 396, [noparse][[/noparse]WAIT("@"), ard] DEBUG "Response from Left", CR ELSEIF IRR = 0 THEN DEBUG "Right", CR SEROUT 0, 396, [noparse][[/noparse]"3"] PAUSE 50 SERIN 1, 396, [noparse][[/noparse]WAIT("@"), ard] DEBUG "Response from Right", CR ELSEIF IRF = 0 THEN DEBUG "Front", CR SEROUT 0, 396, [noparse][[/noparse]"4"] PAUSE 50 SERIN 1, 396, [noparse][[/noparse]WAIT("@"), ard] DEBUG "Response from Front", CR ELSEIF (IRL = 0) AND (IRR = 0) THEN DEBUG "Both", CR SEROUT 0, 396, [noparse][[/noparse]"1"] PAUSE 50 SERIN 1, 396, [noparse][[/noparse]WAIT("@"), ard] DEBUG "Response from Both", CR ENDIF IRF = 1 IRL = 1 IRR = 1 LOOP END IR_Left: FREQOUT 7,6,6385 IRL = IN6 RETURN IR_Right: FREQOUT 5,6,6385 IRR = IN4 RETURN IR_Front: FREQOUT 15,6,6385 IRF = IN14 RETURN
Here's what I get in my debug window when this is running and the 'front' condition is met:
Front
Front
Response from Front
This happens with the 'both' condition also:
Both
Both
Response from Both
But when 'left' or 'right' conditions are met, everything works as I envisioned:
Left
Response from Left
Right
Response from Right
I've tried reordering the IF statements, setting IRR, IRL, IRF to 1 before looping (as you can see), tried adding timeout to the SERIN to jump to a label that pauses for 5 seconds, pausing randomly during the code, changing the GOSUB orders, I just can't see why 'front' and 'both' repeat readings! Every time it should wait for a response, 'left' and 'right' work fine, what is going on here??
Thanks for your help, I'm not a master programmer but I think my code is correct.... this is driving me crazy!!
Comments
For what it's worth: See if this works. It's your code written in a different way. I've never been a big fan of multiple else conditions. It seems they have never worked properly for me. Also, I can't understand why it ever run "Both" in the first place!? It should have read your Left condition and dropped out of the IF-ELSE block. Wierd..... anyways, that's why I put the "Both" test first.
IRL VAR Byte
IRR VAR Byte
IRF VAR Byte
ard VAR Byte
main:
GOSUB IR_Left
GOSUB IR_Right
GOSUB IR_Front
IF (IRL = 0) AND (IRR = 0) THEN
DEBUG "Both", CR
SEROUT 0, 396, [noparse][[/noparse]"1"]
PAUSE 50
SERIN 1, 396, [noparse][[/noparse]WAIT("@"), ard]
DEBUG "Response from Both", CR
goto main
IF IRL = 0 THEN
DEBUG "Left", CR
SEROUT 0, 396, [noparse][[/noparse]"2"]
PAUSE 50
SERIN 1, 396, [noparse][[/noparse]WAIT("@"), ard]
DEBUG "Response from Left", CR
goto main
IF IRR = 0 THEN
DEBUG "Right", CR
SEROUT 0, 396, [noparse][[/noparse]"3"]
PAUSE 50
SERIN 1, 396, [noparse][[/noparse]WAIT("@"), ard]
DEBUG "Response from Right", CR
goto main
IF IRF = 0 THEN
DEBUG "Front", CR
SEROUT 0, 396, [noparse][[/noparse]"4"]
PAUSE 50
SERIN 1, 396, [noparse][[/noparse]WAIT("@"), ard]
DEBUG "Response from Front", CR
goto main
IRF = 1
IRL = 1
IRR = 1
goto main
END
IR_Left:
FREQOUT 7,6,6385
IRL = IN6
RETURN
IR_Right:
FREQOUT 5,6,6385
IRR = IN4
RETURN
IR_Front:
FREQOUT 15,6,6385
IRF = IN14
RETURN
SERIN takes some execution time to set up, so the extra time may be causing you to miss the WAIT character within a particular loop.
Cheers,
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Tom Sisk
http://www.siskconsult.com
·
2. Have you connected a ground to the device sending to pin 1? If not, that signal may always look like 'noise'.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Oh, and in your original code, 'Both' would never be reached, but you already knew that.
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen
Post Edited (Navic) : 1/26/2010 11:07:06 PM GMT
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
- Stephen