Uncalled pin going high

mandsanda

New Member
My first project with a picaxe.

I am trying to switch a DPDT relay (via a mosfet) to control a latching solenoid.

This is a remote station interfaced back to my PC via a XBee pro.

The switching seem to operating OK except when opening the solenoid, then, the sleep pin (pin 1, leg22 on 28x1) goes high without being called and Xbee goes to sleep and stays there forever.

At no time does the sleep pin go low again - it should cycle every minute to enable instructions to be received.

Any idea why this might be happening.

Other commands (ADC values) are working fine and not causing the picaxe to apparently freeze.

Any help appreciated.

some of the code is:

main:
'the main loop updates temperatures & adc values once a minute at secs = 30
'At secs = 0, wakes the radio up & listens for job code from master

'get the seconds
readi2c 0, (b20)

if seconds = $30 then
goto update_values
elseif seconds < $06 then
goto wake_up
else
low RF_Tx
high RF_Sleep 'put XBee to sleep
endif
pause 250
goto main

'----------------------------------------------------------------------------

update_values:
An0=0
An1=0
An2=0
An3=0

readtemp12 Temp_pin, temp
readadc10 An0_pin, An0
readadc10 An1_pin, An1
readadc10 An2_pin, An2
readadc10 An3_pin, An3
pause 1000 'ensure time is past 30secs

goto main

'----------------------------------------------------------------------------

wake_up:

'wake up the XBee
low RF_Sleep
pause 25 'let the radio wake up
high RF_Tx

'wait for master
serin [1000, main],RF_Rx,T2400,(b26,b27),Job_Code,Param1,Param2

'process job code
if Job_Code = "1" then '1 is an relay open/close command
if Param1 = "1" then 'close solenoid
if Param2 = "1" then 'position on slave
high Sol1_Pwr
pause 75
low Sol1_Pwr
endif
elseif Param1 = "0" then 'open solenoid
if Param2 = "1" then 'position on slave
high Sol1_Dir
pause 25
high Sol1_Pwr
pause 75
low Sol1_Pwr
low Sol1_Dir
endif
endif


elseif Job_Code = "2" then '2 is send temperature
'send temp in w9 = b18,b19
serout RF_Tx, T2400, (b26,b27,#b18,",",#b19)

elseif Job_Code = "3" then '3 is send adc0
serout RF_Tx, T2400, (b26,b27,#b11,",",#b10)

elseif Job_Code = "4" then '4 is send adc1
serout RF_Tx, T2400, (b26,b27,#b13,",",#b12)

elseif Job_Code = "5" then '5 is send adc2
serout RF_Tx, T2400, (b26,b27,#b15,",",#b14)

elseif Job_Code = "6" then '6 is send adc3
serout RF_Tx, T2400, (b26,b27,#b17,",",#b16)

elseif Job_Code = "7" then '7 is a time update we only need seconds
'wait for parameters
serin [1000, main],RF_Rx, T2400,(b26,b27),Job_Code,b3 'seconds

'convert ascii to decimal
b3=b3-48

'update clock
writei2c 0,($b3,$01,$01,$01,$01,$01,$01,$10)
endif

'send completed
serout RF_Tx, T2400, (b26,b27,Job_Code)

goto main

Thanks
 

westaust55

Moderator
Welcome to the PICAXE forum.

some of the code is:
Please upload the full code.

It is not possible to know what symbols are allocated to IO when you have code like:
low RF_Sleep
pause 25 'let the radio wake up
high RF_Tx
but RF_Sleep and RF_Tx are not advised.

Here is a list of those SYMBOL statement missing from the part of the code you posted (I have just allocated random pin numbers and variables):

SYMBOL RF_Sleep = 0
SYMBOL RF_Tx = 1
SYMBOL RF_Rx = 2
SYMBOL Temp_Pin = 3
SYMBOL Sol1_Pwr = 4
SYMBOL Sol1_Dir = 5

SYMBOL An0_pin = 0
SYMBOL An1_pin = 1
SYMBOL An2_pin =2
SYMBOL An3_pin =3

SYMBOL An0 = b0
SYMBOL An1 = b1
SYMBOL An2 = b2
SYMBOL An3 = b3
SYMBOL SECONDS = b4
SYMBOL temp = b5
SYMBOL job_code = b6
SYMBOL param1 = b7
SYMBOL param2 = b8
 

mandsanda

New Member
Complete code listing

Hi,

The complete listing

init:
'variables
symbol Job_Code = b2
symbol Param1 = b3
symbol Param2 = b4
symbol Param3 = b5
symbol Param4 = b6
symbol Param5 = b7
symbol Param6 = b8
symbol Param7 = b9
symbol seconds = b20
symbol temp = w9
symbol An0 = w5
symbol An1 = w6
symbol An2 = w7
symbol An3 = w8


'constants
symbol RF_Tx = 0
symbol RF_Rx = 7
symbol RF_Sleep = 1
symbol Sol1_Dir = 7
symbol Sol1_Pwr = 6
symbol An0_pin = 0
symbol An1_pin = 1
symbol An2_pin = 2
symbol An3_pin = 3
symbol Temp_pin = 6

'initialise varaible values
let Job_Code = 0
let Param1 = 0
let Param2 = 0
let Param3 = 0
let Param4 = 0
let Param5 = 0


' setup I2C - PICAXE as master and DS1307 as slave
pause 250 'let ds1307 start
i2cslave %11010000, i2cslow, i2cbyte


'wake XBee
low RF_Sleep
pause 25
high RF_Tx
pause 100
'get accurate time
serout RF_Tx, T2400, ("00T")

'wait for time - master should send '00T0' which is 0 seconds
serin [5000, init],RF_Rx, T2400,("00T0")

'OK - got the '0' seconds message - update clock
writei2c 0,($00,$01,$01,$01,$01,$01,$01,$10)


init1:

gosub get_id

'check for a 'real' slave id
read 0, WORD w13
if b26 = 0 AND b27 = 0 then 'we have no 'real' address
gosub register_new_with_master
goto init1
endif

'check if Xbee serial number has changed
read 2, b10,b11,b12,b13,b14,b15,b16,b17

if b10=b18 and b11=b19 and b12=b20 and b13=b21 then
if b14=b22 and b15=b23 and b16=b24 and b17=b25 then
goto main
else
gosub register_new_with_master
goto init1
endif
else
gosub register_new_with_master
goto init1
endif

'------------------------------------------------------------------------

get_id:
'
'get serial number from XBee module

serout RF_Tx, T2400, ("+++") 'enter cmd mode
serin [1000, get_id],RF_Rx, T2400,("OK"),Param1
serout RF_Tx, T2400, ("ATSH",CR,LF) 'XBee's serialnumber (high 32bits)
serin [1000, get_id],RF_Rx, T2400,b18,b19,b20,b21
serout RF_Tx, T2400, ("ATSL",CR,LF) 'XBee's serialnumber (low 32bits)
serin [1000, get_id],RF_Rx, T2400,b22,b23,b24,b25
serout RF_Tx, T2400, ("ATCN",CR,LF) 'exit cmd mode

pause 500 'wait for XBee to exit cmd mode

return

'-------------------------------------------------------------------------

register_new_with_master:

'get id sorted
serout RF_Tx, T2400, ("00") 'R for register
serin [5000, init1],RF_Rx, T2400,("00"),Param1
if Param1 = "R" then
'send ID and Xbee serial number to master
serout RF_Tx, T2400, ("00",#b26,#b27,#b18,#b19,#b20,#b21,#b22,#b23,#b24,#b25)
else
goto init1
endif

b0=0

get_id_data:

b0=b0+1

if b0 > 5 then
goto init1
endif

'wait for new address - which will be 00 + 2 bytes eg 005A
'wait for 5 mins (using b0 to multiply time - 1x5) for response
serin [60000, get_id_data],RF_Rx, T2400,("00"),Param1,Param2

'add a check for valid code
'cannot be "01" as this is always the master

if Param1 = "0" AND Param2 = "1" then
goto init1 'start again
endif

'if we get here, all is well - store id
write 0, Param1, Param2
pause 500
'store Xbee serial number
write 2,b18,b19,b20,b21,b22,b23,b24,b25
pause 500
return

'-------------------------------------------------------------------------------

main:
'the main loop updates temperatures & adc values once a minute at secs = 30
'At secs = 0, wakes the radio up & listens for job code from master

'get the seconds
readi2c 0, (b20)

if seconds = $30 then
goto update_values
elseif seconds < $06 then
goto wake_up
else
low RF_Tx
high RF_Sleep 'put XBee to sleep
endif
pause 250
goto main

'----------------------------------------------------------------------------

update_values:
An0=0
An1=0
An2=0
An3=0

readtemp12 Temp_pin, temp
readadc10 An0_pin, An0
readadc10 An1_pin, An1
readadc10 An2_pin, An2
readadc10 An3_pin, An3
pause 1000 'ensure time is past 30secs

goto main

'----------------------------------------------------------------------------

wake_up:

'wake up the XBee
low RF_Sleep
pause 25 'let the radio wake up
high RF_Tx

'wait for master
serin [1000, main],RF_Rx,T2400,(b26,b27),Job_Code,Param1,Param2

'process job code
if Job_Code = "1" then '1 is an relay open/close command
if Param1 = "1" then 'close solenoid
if Param2 = "1" then 'position on slave
high Sol1_Pwr
pause 75
low Sol1_Pwr
endif
elseif Param1 = "0" then 'open solenoid
if Param2 = "1" then 'position on slave
high Sol1_Dir
pause 25
high Sol1_Pwr
pause 75
low Sol1_Pwr
low Sol1_Dir
endif
endif


elseif Job_Code = "2" then '2 is send temperature
'send temp in w9 = b18,b19
serout RF_Tx, T2400, (b26,b27,#b18,",",#b19)

elseif Job_Code = "3" then '3 is send adc0
serout RF_Tx, T2400, (b26,b27,#b11,",",#b10)

elseif Job_Code = "4" then '4 is send adc1
serout RF_Tx, T2400, (b26,b27,#b13,",",#b12)

elseif Job_Code = "5" then '5 is send adc2
serout RF_Tx, T2400, (b26,b27,#b15,",",#b14)

elseif Job_Code = "6" then '6 is send adc3
serout RF_Tx, T2400, (b26,b27,#b17,",",#b16)

elseif Job_Code = "7" then '7 is a time update we only need seconds
'wait for parameters
serin [1000, main],RF_Rx, T2400,(b26,b27),Job_Code,b3 'seconds

'convert ascii to decimal
b3=b3-48

'update clock
writei2c 0,($b3,$01,$01,$01,$01,$01,$01,$10)
endif

'send completed
serout RF_Tx, T2400, (b26,b27,Job_Code)

goto main
 
Top