Bit variable not reconized correctly

buntay

Senior Member
Greetings Picaxe Collective,

Can somebody tell me why this isnt working and what I need to do to fix it
Code:
'REM 28X2 @ 8Mhz

sertxd ("Confirm Reset")



main:
goto dataout
shutdown:
high b.2
high b.0
pause 60000
low b.0
low b.2
dataout:
sertxd ("data ",b12,cr,lf)

serrxd [1000],("datain"),b12
if b12=1 then reset
if b12=2 then goto shutdown
goto shutdown
endif
goto main
This is part of a much bigger program that I would rather not post, but the rest of it works fine.
When you run in simulator sending "datain",2 does not do what it is supposed to. Can somebody explain why?

Buntay
 

westaust55

Moderator
Where precisely is the bit variable you talk of? Are you thinking of the SERRXD qualifier “Datain” ?

The qualifier as used (ie “Datain”) will wait for the receipt of a 6 character string with the matching characters “D”,”a”,”t”,”a”,”i”,”n”.

Note that the Serial comms commands only work with 8-bit, ie bytes, of data so you cannot transmit a bit as a qualifier.

Maybe you need to provide more information about where the bit variable fits into the program.
 

buntay

Senior Member
the problem is here

Code:
serrxd [1000],("datain"),b12
if b12=1 then reset
if b12=2 then goto shutdown
goto shutdown
endif
if I send "datain",1 then the program does what it is supposed to do.....reset
but if i send "datain",2 it is ignored and main program starts over.
 

PaulRB

Senior Member
Buntay, I'm strugglling to understand that code. I'm a bit surprised it passes syntax check.

why is "goto shutdown" repeated?

which "if" does the "endif" belong to? if it belongs to the first if, that might explain what you are seeing.

Paul
 

buntay

Senior Member
here is the program if it helps

Code:
b5=0
b6=0
b7=0
b11=0
w1=0

sertxd ("Reset Successfull, Removing Load, Swinging out tail")
high b.3
high b.1
pause 60000
low b.3
low b.1
sertxd ("System Comming On Line waiting for rotor spin-up")
pause 30000

bladerpm:

sertxd ("System On Line")

DISCONNECT

for b5= 1 to 10
count c.0,1000,w0
w1=w1+w0
next b5
w1=w1 /10
if w1 <20 then gbtemp
if w1 >275 then
 b6=1
goto shutdown
endif
if w1 >195 and w1 <205 then 
goto gbtemp 
endif



'ADD LOAD
if w1 > 205 then high b.0
pause 100
low b.0
b7=b7+1
end if
if b7 > 100 then
 b7 = 100
goto tailclosed
end if

'REMOVE LOAD
if w1 < 195 then high b.1
pause 100
low b.1
b7=b7 -1
endif
if b7 > 100 then 
b7=0
end if
if b7 =0 then
goto tailopen
endif

tailclosed:

'MOVE TAIL CLOSED
if b7 = 100 then
high b.2
pause 100
low b.2
b8=b8 +1
endif
if b8> 99 then 
b8 =100
endif
goto gbtemp

tailopen:
'MOVE TAIL OPEN
if b7=0 then
high b.3
pause 100
low b.3
b8=b8 - 1
endif
if b8 >100 then 
b8 =0
endif
goto gbtemp

'GEARBOX TEMP
gbtemp:
readtemp a.0,b9
if b9> 100 then
b6=2
goto shutdown
endif


'GEARBOX LEVEL
if pinc.1=1 then 
b6=3
goto shutdown
endif

'HYDRO LEVEL
if pinc.2=1 then
 b6=4
 goto shutdown
endif

'HYDRO TEMP
readtemp a.1, b10
if b10 > 100 then
 b6=5
 goto shutdown
 endif


'OVER REV TRIP
if pinc.3=1 then
b6=6
goto shutdown
endif


'GEN TEMP
readtemp a.2, b11
if b11 >100 then 
b6=7
goto shutdown
endif



goto dataout

shutdown:
high b.2
for b12= 1 to 2
pause 60000
next b12
low b.2
high b.0
pause 60000
low b.0

dataout:
sertxd ("data ",#W1,",",#b6,",",#b7,",",#b8,",",#b9,",",#b10,",",#b11,cr,lf)

serrxd [1000],("datain"),b13
if b13=1 then reset
if b13=2 then goto shutdown
endif

sertxd ("System On Line")
if b6>0 then dataout




RECONNECT



goto bladerpm
 

PaulRB

Senior Member
here is the program if it helps

Code:
b5=0
b6=0
b7=0
b11=0
w1=0

sertxd ("Reset Successfull, Removing Load, Swinging out tail")
high b.3
high b.1
pause 60000
low b.3
low b.1
sertxd ("System Comming On Line waiting for rotor spin-up")
pause 30000

bladerpm:

sertxd ("System On Line")

DISCONNECT

for b5= 1 to 10
count c.0,1000,w0
w1=w1+w0
next b5
w1=w1 /10
if w1 <20 then gbtemp
if w1 >275 then
 b6=1
goto shutdown
endif
if w1 >195 and w1 <205 then 
goto gbtemp 
endif



'ADD LOAD
if w1 > 205 then high b.0
pause 100
low b.0
b7=b7+1
end if
if b7 > 100 then
 b7 = 100
goto tailclosed
end if

'REMOVE LOAD
if w1 < 195 then high b.1
pause 100
low b.1
b7=b7 -1
endif
if b7 > 100 then 
b7=0
end if
if b7 =0 then
goto tailopen
endif

tailclosed:

'MOVE TAIL CLOSED
if b7 = 100 then
high b.2
pause 100
low b.2
b8=b8 +1
endif
if b8> 99 then 
b8 =100
endif
goto gbtemp

tailopen:
'MOVE TAIL OPEN
if b7=0 then
high b.3
pause 100
low b.3
b8=b8 - 1
endif
if b8 >100 then 
b8 =0
endif
goto gbtemp

'GEARBOX TEMP
gbtemp:
readtemp a.0,b9
if b9> 100 then
b6=2
goto shutdown
endif


'GEARBOX LEVEL
if pinc.1=1 then 
b6=3
goto shutdown
endif

'HYDRO LEVEL
if pinc.2=1 then
 b6=4
 goto shutdown
endif

'HYDRO TEMP
readtemp a.1, b10
if b10 > 100 then
 b6=5
 goto shutdown
 endif


'OVER REV TRIP
if pinc.3=1 then
b6=6
goto shutdown
endif


'GEN TEMP
readtemp a.2, b11
if b11 >100 then 
b6=7
goto shutdown
endif



goto dataout

shutdown:
high b.2
for b12= 1 to 2
pause 60000
next b12
low b.2
high b.0
pause 60000
low b.0

dataout:
sertxd ("data ",#W1,",",#b6,",",#b7,",",#b8,",",#b9,",",#b10,",",#b11,cr,lf)

serrxd [1000],("datain"),b13
if b13=1 then reset
if b13=2 then goto shutdown
endif

sertxd ("System On Line")
if b6>0 then dataout




RECONNECT



goto bladerpm
Move that "endif" after "goto shutdown" up a line to immediately before "if b13=2".

Does that help?
 

hippy

Ex-Staff (retired)
Make sure you've got the latest version of Programming Editor. It all seems to be working when I test things ...

Code:
#Picaxe 20X2
Do
  SerRxd [1000], ("datain"), b12
  SerTxd( #b12 )
Loop
If the expected value is getting into 'b12' the problem must be in the way the program handles it afterwards. I expect your IF tests are being interpreted as below -

Code:
if b12=1 then
  reset
  if b12=2 then goto shutdown
  goto shutdown
endif
A SELECT-CASE would probably be more appropriate and certainly a lot clearer to understand ...

Code:
SerRxd [1000], ("datain"), b12
Select Case b12
  Case 1 : Reset
  Case 2 : Goto ShutDown
End Select
 
Last edited:
Top