Images Scientific Instruments Inc. sitemap






Speed Control via Potentiometers


USB Stepper Motor Kit USB Stepper Motor Kit Pic Stepper Motor Kit PIC Stepper Motor Kit Stepper Motor Stepper Motor

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 Figure 10.

Figure 10
Figure 10

The program is shown in listing 4. First, it reads the value of pin B2 (the potentiometer), then places it on a scale of 245. That value is then multiplied by 1,000 (converting it into microseconds) and set to the UCN 5804.

Listing 4

' Controlling a stepper motor with the UCN 5804 and a potentiometer

Symbol delay = B0
low 1

start:
pot 2,245,delay
if delay < 25 min
goto turn

turn:
delay = delay * 1000
pulsout 0,delay
goto start

min:
delay = 25
goto turn

' make a delay variable
' set the output enable low


' read pot at pin B2
' set min delay to 25
' if delay is over 25, start moving


' turn delay into microseconds
' send to UCN 5804
' go back to start


' bottom out the delay at 25
' start the motor














 

 

 

End Listing 4

Not quite as complicated as you may have expected (thanks to the use of the UCN 5804). Notice again, the minimum delay set at 25 ms. If you would like to make it a lower number (thereby making the motor turn faster), simply change all occurrences of "25" to the number desired.

Previous Page | Next Page