Problem with switch timing [SOLVED]
I have an intermittent fault on a circuit with a Picaxe 18M2
It uses two manual push buttons and drives a motor that opens and controls my curtains.
There are two additional open and close stop switches, these are reed switches activated
by a moving magnet on the curtain track.
The mechanics work fine.
The problem is with the switch timing.
A short press drives the motor for 1 second, a long press drives the motor for 15 seconds.
The short press is < 100ms
The long press is > 100ms
All works well about 7 out of 10 times, When it fails pressing manual Open switch (input C.1)
or manual Close switch (input C.2) does nothing. (By nothing I mean that motor does not
drive and no display on the OLED).
Its not the greatest programming, maybe someone can spot some flaw.
I'm enclosing the program in CODE tags below:
I should add all unused inputs are ground, power to picaxe is 5V and power to LT4424 (motor driver) is 12V.
Currently assembled on a breadboard, input switches are PCB type plugged into breadboard, the reed switches
on curtain rail are twisted pair CAT5 about 4 meters. Home environment is pretty bad for EMI/RFI so not
ruling out interference yet.
Thanks in advance.
I have an intermittent fault on a circuit with a Picaxe 18M2
It uses two manual push buttons and drives a motor that opens and controls my curtains.
There are two additional open and close stop switches, these are reed switches activated
by a moving magnet on the curtain track.
The mechanics work fine.
The problem is with the switch timing.
A short press drives the motor for 1 second, a long press drives the motor for 15 seconds.
The short press is < 100ms
The long press is > 100ms
All works well about 7 out of 10 times, When it fails pressing manual Open switch (input C.1)
or manual Close switch (input C.2) does nothing. (By nothing I mean that motor does not
drive and no display on the OLED).
Its not the greatest programming, maybe someone can spot some flaw.
I'm enclosing the program in CODE tags below:
Code:
#picaxe 18M2
; Setup dirs %msb.......lsb, 1=o/p 0=i/p
let dirsB = %10101100
let dirsC = %00000000
symbol motorRev = B.2 ; LT4424 to motor (B.2 output)
symbol motorFwd = B.3
Symbol OLED = B.7
symbol manOpen = pinC.1 ; pinC.1 input
symbol manClose = pinC.2
symbol closeSw = pinC.7
symbol openSw = pinB.4
symbol ttd = b1 ; reg b1 time to drive
symbol stimer = b2
main: ; scan inputs
if manOpen =1 then gosub stimerOpen
if manClose =1 then gosub stimerClose
serout OLED,N2400,(254,1) ' Clear OLED
goto main
stimerOpen: ; determine long or short press
let stimer = 0
Do While manOpen =1
pause 10
inc stimer
if manOpen = 0 then ; switch released
if stimer < 100 then gosub manualOpen
if stimer > 100 then gosub autoOpen
endif
loop ; increment stimer until switch released
return
stimerClose:
let stimer = 0
Do While manClose =1
pause 10
inc stimer
if manClose = 0 then
if stimer < 100 then gosub manualClose
if stimer > 100 then gosub autoClose
endif
loop
return
manualOpen:
if openSw=1 then
serout B.7,N2400,(254,192,"Curtains Open") 'line 2
pause 1500
return
else
serout B.7,N2400,(254,128, "Man Open") 'line 1
let ttd =10 ; reg b1 duration
gosub motorOpen
endif
return
manualClose:
if closeSw=1 then
serout B.7,N2400,(254,192,"Curtains Closed") 'line 2
pause 1500
return
else
serout B.7,N2400,(254,128, "Manual Closing") 'line 1
let ttd = 10
gosub motorClose
endif
return
autoClose:
'check stopSw (C7) else drive at .1s intervals 110 x .1 = 11sec
serout B.7,N2400,(254,128, "AutomaticClosing") 'line 1
let ttd = 150
gosub motorClose
return
autoOpen:
'check stopSw (C7) else drive at .1s intervals 80 x .1 = 8sec
serout B.7,N2400,(254,128, "AutomaticOpening") 'line 1
let ttd = 150
gosub motorOpen
return
motorOpen:
'check stopSw else drive motor in .1s intervals
for b0 = 1 to ttd ; time to drive duration
if openSw=1 then
serout B.7,N2400,(254,192,"Curtains Open") 'line 2
return ; check if openSw or torque active
else
high motorFwd
pause 100
low motorFwd ' motor on 100ms then off
endif
next b0
return
motorClose:
for b0 = 1 to ttd
if closeSw=1 then return
else
high motorRev
pause 100
low motorRev
endif
next b0
return
I should add all unused inputs are ground, power to picaxe is 5V and power to LT4424 (motor driver) is 12V.
Currently assembled on a breadboard, input switches are PCB type plugged into breadboard, the reed switches
on curtain rail are twisted pair CAT5 about 4 meters. Home environment is pretty bad for EMI/RFI so not
ruling out interference yet.
Thanks in advance.
Last edited: