I've been working on a circuit to control a servo and a relay for what seems like months now and have got to the stage were the circuit and code has been refined and work 99% as I want it to
When the circuit starts up for the first time c.3 is used to set the parameters of the servo movement left and right and these are written to memory, however on subsequent start ups the program remembers where everything was with the exception of the relay which is controlled by port c.2
On the first start up c.2 works as it should but on subsequent start ups it doesn't.
If I run the code through the simulator ,it works
If I change the code at the pre operate section to read
Then c.2 works fine, switching the relay fast or slow depending on the value of b4
So I know the hardware's good and I know the software's good, but I can't for the life of me see why C.2 won't work having read the value of b4 on subsequent start ups. I've even put a meter across 0v and pin C.2 but the output stays 0.
Can a fresh pair of eyes see what I'm obviously missing
When the circuit starts up for the first time c.3 is used to set the parameters of the servo movement left and right and these are written to memory, however on subsequent start ups the program remembers where everything was with the exception of the relay which is controlled by port c.2
Code:
#picaxe 08m2 ;servo & relay pcb v2.0
start:
read 1,b2
read 2,b3
read 3,b4
read 4,b5
if b5=0 then goto program
if b5=1 then goto preoperate
goto start
;=================================================================================
;programing mode
;===============
program:
disconnect
b1=150
pulsout c.4,b1 ;centre
pause 1000
do
if pinc.3=1 then gosub check
if pinc.3=1 then goto cont1
pause 35
toggle c.1
loop
check:
pause 1000
return
cont1:
do
high c.1
if pinc.3=0 then goto cont2
loop
cont2:
low c.1
pause 1000
high c.1
do
pulsout c.4,b1
pause 100
inc b1
loop until pinc.3=1
b2=b1
write 1,b2
low c.1
pause 1000
high c.1
do
pulsout c.4,b1
pause 100
dec b1
loop until pinc.3=1
b3=b1
write 2,b3
b4=0
b5=1
write 3,b4
write 4,b5
reconnect
low c.1
B6=1 ;TELLS THE CONTROL PANEL WHICH SERVO IT'S WORKING ON
serout c.1,n1200_4, ("END",b6)
goto operate
;================================================================================
;=============================================================
;normal operation
;=============================================================
preoperate:
if b4=0 then relay
if b4=1 then operate
relay:
pause 1000
high c.2
operate:
serin [1000,reprogram],c.1,n1200_4,("SERVO1"),b7
if b7=0 and b4=0 then goto left
if b7=0 and b4=1 then goto sendend
if b7=1 and b4=1 then goto right
if b7=1 and b4=0 then goto sendend
goto operate
reprogram:
if pinc.3=1 then goto program
goto operate
left:
b4=1
write 3,b4
low c.2
for b0 = b3 to b2
pulsout c.4,b0
pause 50
next b0
goto sendend
right:
b4=0
write 3,b4
high c.2
for b0 = b2 to b3 step-1
pulsout c.4,b0
pause 50
next b0
goto sendend
SENDEND:
b8=1
serout c.1,n1200_4, ("END",b8)
goto operate
If I run the code through the simulator ,it works
If I change the code at the pre operate section to read
Code:
preoperate:
if b4=0 then relay1
if b4=1 then relay2
relay1:
do
toggle c.2
pause 500
loop
relay2:
do
toggle c.2
pause 2000
loop
So I know the hardware's good and I know the software's good, but I can't for the life of me see why C.2 won't work having read the value of b4 on subsequent start ups. I've even put a meter across 0v and pin C.2 but the output stays 0.
Can a fresh pair of eyes see what I'm obviously missing