PDA

View Full Version : motor control with limit switches?



lozinit
31-01-2006, 01:04
Hi. I'm new to the mcu game, and looking at picaxe to help solve a problem.

The problem - I have a motor that opens and closes a small plexiglass door for a model house. Using a single momentary pushbutton to start the motor, it should run until it hits a limit switch. It then stops. To close the door, simply push the same momentary button again, the door will proceed to close until it hits another limit switch.

I've downloaded the programming editor on the website and played around with it trying to figure out the code, but am having problems with the design of the logic.

So far I've come up with this rather crude and non working chunk of code (Try not to laugh to hard):

'Start code
main:
test_14: if pin0=1 then test_1B
low 0
goto test_14

test_1B: high 0
test_54: if pin1=1 then test_8C
goto test_54

test_8C: toggle 0
'End code

Also, any suggestions on which chip would be best suited for this application?
Thanks in advance for any help!

bobrayner
31-01-2006, 01:44
On the limit switch side of things most limit switches are arranged to interrupt the motor supply. If simply left like this if one limit switch is open the motor cannot run in the reverse direction when the reversing voltage is applied. The trick is to fit a diode across each limit switch in a direction which allows current flow in the reverse direction across the switch.
cheers BobR

Rickharris
31-01-2006, 18:22
A picaxe 08 will handle this as it has 3 possible inputs/outputs and 1 dedicated input pin 3 and 1 dedicated output pin 0.

You could wire your door open micro switch to pin 1
Door closed to pin 3
Move door push botton to pin 2

Leaving pin 0 and 4 to drive a L293 to give bi directional motor control.

The programme might look like this - I tend to use the programming commands rather than the flow chart because it is more flexible and for me more understandable.

i have made this a little long winded so it is clear for you as a beginner. the programme checks if the door is open or closed - if it isn't either it will close the door by default.

start:
If pin 2=1 then move_door. 'checks for request to move door
goto start

move_door:
if pin 1=1 then close_door
if pin 3=1 then open_door

close-door:
high 4 'move door to closed position
check1:
if pin3=1 then stop_close
goto check1

open_door:
high 0 'move door to open
check2:
if pin 1=1 then stop_open
goto check2

stop_close:
low 4
goto start

stop_open:
low 0
goto start

lozinit
06-02-2006, 06:04
update here -
I built the circuit on an 08m, cleaned up the code provided above a wee bit (typos) and tested it out. I thought I was getting some bad switch bounce at the beginning, but through a little investigation I found that even by taking the wires (that run to the switches) completely OFF the pcb, I still get the same problem. Instead of the motor, I've substituted two leds in it's place for testing.
The problem seems to be this:
Upon download of the code, both leds light up and start flickering. Through testing, I found that the closer I get to the wires (specifically the chip input wires) with my hand, the more the leds flicker, flash, and generally act up. It's almost like the wires are acting like an antenna sensing the em field from my body and triggering the inputs.

I went as far as to strip the switch wires off of the board, and if you move your hand within a close proximity of the board itself, the leds still fire.

Obviously, this will not work, so I ask if anyone has any ideas on how to proceed. Have I missed something simple?

BeanieBots
06-02-2006, 07:35
Sounds like you have missed off the pull up or pull down resistors on the inputs.
If they are OK, do you have the download circuit fitted. If not, the serial in must be pulled down.

lozinit
06-02-2006, 23:01
Thats exactly what was wrong - the inputs were floating and picking up stray signals because I forgot to add pulldown resistors.
3 10k resistors later and all is well!!
Thanks again!