Markbishop16
Member
Hello
I have a simple program on a Pic 18m2 that operates an electric door.
The program works correctly, except it does not always start instantly when the input is applied, rather it waits for it to be applied then removed. The trigger is from a keypad which is about 3 seconds. Entering the correct code the door does not start opening/closing until the keypad resets, which is a short delay but annoying. I can not see where I have gone wrong, in the simulator it operates straight away.
I can rewrite the code differently without the waiting for an input loop, but I can't see where I have gone wrong. If someone can shine some light on my problem I would be most grateful to know what I am doing wrong.
I have a simple program on a Pic 18m2 that operates an electric door.
The program works correctly, except it does not always start instantly when the input is applied, rather it waits for it to be applied then removed. The trigger is from a keypad which is about 3 seconds. Entering the correct code the door does not start opening/closing until the keypad resets, which is a short delay but annoying. I can not see where I have gone wrong, in the simulator it operates straight away.
I can rewrite the code differently without the waiting for an input loop, but I can't see where I have gone wrong. If someone can shine some light on my problem I would be most grateful to know what I am doing wrong.
Code:
start0:
'picaxe 18m2
'Bay 3 door operator, mains motor switching, with meros trigger and contact monitoring on relay
'NO devices to open or close doors depending on contact position
'Safety beam stops motor either way
Symbol timepot = c.0 ; on board pot for motor time
symbol trigger = pinc.1 ; no to 5v
symbol safety_beam = pinc.2 ;nc to 5v
symbol door_contact = pinc.5 ;nc to 5v
symbol power_relay = B.1 ; 1st relay switches live to relay 2
symbol direction_relay = b.2 ; 2nd relay, NO is open output, NC is close contacts
symbol door_contact_relay = b.3 ; nc to operate meros
symbol safety_out = b.4 ; output when beam broken relay to connect to other doors
symbol greenled = b.7 ; on when safety closed off when beam blocked Panel LED
symbol timestore = b1
symbol opentime = b2
symbol closetime = b3
pause 1000
Main:
pause 10
do while trigger = 0 ; waiting for an input to open or close door
pause 50
do while safety_beam = 0 ;if beam blocked door will not trigger
pause 50
loop
loop
if door_contact = 1 then goto opening_time 'door opens
if door_contact = 0 then goto closing_time 'door closes
opening_time: ; open door loop
readadc timepot, opentime ;load running time
do while opentime > 0 ;timing loop
high power_relay ; door goes up
if safety_beam = 0 then goto safety_Stop 'safety beam operation
dec opentime 'counting down
pause 150 ' gives about 30 secs max operating time
Loop
low power_relay ; end of time relay off
goto main
closing_time: ;door closing loop
readadc timepot, closetime
do while closetime > 0
high power_relay, direction_relay ; with two relays on door coming down
if safety_beam = 0 then goto safety_Stop
dec closetime
pause 150
Loop
low power_relay, direction_relay ; both relays off
goto main
Safety_stop: 'if beam is broken this stops motor and clears variables
Low power_relay, direction_relay, safety_out ;everything off
pause 1000
opentime = 0 ; clears time
closetime = 0 ;;clears time
pause 50
goto main ; go back to needing an input
start1: 'controls meros relay and safety output
if door_contact = 1 then high door_contact_relay else low door_contact_relay endif
Pause 50
if safety_beam = 1 then low safety_out else high safety_out endif
Pause 50
if safety_beam = 1 then high greenled else low greenled end if
pause 50
goto start1