Stepper motors, unlike ordinary DC motors, are brushless and can divide a full 360° into a large number of steps, for example 200. In robotics, stepper motors are widely used. They offer amazing precision as well as continuous rotation. Also, any inaccuracy between steps are non-cumulative; 200 steps will always be 1 revolution. These features make them ideal for driving the wheels on a robot, and creating linear motion using a leadscrew. The drawbacks are that they require current when not moving they are relatively expensive and they are quite heavy for the amount of torque they give.
By using an external stepper motor controller, such as the UCN 5804, you can simplify your programs and control as many motors as you have outputs via an array of UCN 5804's. Not only does it allow for the control of more motors, but more importantly, it simplifies the process. You now only have to output the pulse of your desired speed. Additionaly, you can switch between full and half stepping in real time via a switch on the UCN 5804 (or you may have the PIC control it), as well as reverse direction. A pinout for the UCN804 is shown in below:
The PIC Basic language has a command that allows you to read the value of potentiometers on a given scale. This is the "pot" command, and is used in the following manner:
pot pin,scale,var
Where pin is the pin the potentiometer is connected to (pins B0-7), scale is the maximum value the command will return (in this case 245, being the maximum amount of ms we want in between pulses), and var is the variable the value will be placed in. Using this command, we can determine the value of a potentiometer (we will be using a 50K ohm pot) and then use it to control the pulsewidth outputted to the UCN 5804. A schematic is shown in below:
The Code in given below
' Controlling a stepper motor with the UCN 5804 and a potentiometer
Symbol delay = B0 ' make a delay variable
low 1 ' set the output enable low
start:
pot 2,245,delay ' read pot at pin B2
if delay < 25 min ' set min delay to 25
goto turn
turn: ' if delay is over 25, start moving
delay = delay * 1000 ' turn delay into microseconds
pulsout 0,delay ' send to UCN 5804
goto start ' go back to start
min:
delay = 25 ' bottom out the delay at 25
goto turn ' start the motor
' Controlling a stepper motor with the UCN 5804 and a potentiometer
Symbol delay = B0 ' make a delay variable
low 1 ' set the output enable low
start:
pot 2,245,delay ' read pot at pin B2
if delay < 25 min ' set min delay to 25
goto turn
turn: ' if delay is over 25, start moving
delay = delay * 1000 ' turn delay into microseconds
pulsout 0,delay ' send to UCN 5804
goto start ' go back to start
min:
delay = 25 ' bottom out the delay at 25
goto turn ' start the motor
Nice work.
ReplyDeleteHow do you program a 5804.