Stepper Motor Workshop
UCSD-MAE October 2007
(1.5 hours)
Workshop objectives and goal
of applying stepper motors. We
[his workshop is largely concerned with the “how-to”
Basic characterization of step motor mechanical and electrical properties.
Advantages and limitations of stepper motors.
Brief discussion of speed/torque relationships.
Basic stepper motor ‘anatomy’.
Bit patterns and sequences far digital step control.
Brief discussion of microprocessor input/output (1/O) structures.
Brief discussion of Basic Stamp I/O.
NaVaene
Hands-on exer Following the brief introductory discussion above, our main focus
will be on the hands-on section where we will hook up a stepper motor to a controller and
a Basic Stamp 2 (BS2) microprocessor. You will write and modify microprocessor code
to control the step motor in various Ways. The exercises ate designed to illustrate some
stepper motor capabilities and some limitations, and will give you a good, practical
hands-on introduction to using these devices.
‘What you will get out of this. Following completion of the workshop you should have
erough basic understanding of stepper motors to decide if a step motor might be a good
fit for a given project. You will also be able to design in a stepper motor for your project,
and be able to hook it up, power it appropriately, and control it through your own
software,Stepper Motors: A Brief Introduction
Steve Roberts — UCSD/MAE. October 2007
Figure 10.25 Typical stepper motor rotor and stator
configuration. (Courtesy of Oriental Mots, Torance, CA)
Ball bearings
Iron core B
Permanent magnet
Nonmagnetic motor shaft Iron core &
(Material: Stainless steel SUS303 or equivalent)
Figure 10.26 Actua stopper motor roto. (Courtesy of Oriental Motor, Torrance, CA)
A special type of DC motor, known as a stepper motor,
has the following performance characteristics:
““[Tean rotate Tn both directions, move in precise angul -rements, sustain a hold-
ing torque at zero speed, and be controlled with digital circuits, It moves in accu-
rafe angular increments, known as steps, in response to the application of digital
pulses to an electric drive circuit. The number and cate of the pulses control the
position and speed of the motor shaft. Generally, stepper motors are manufactured.
with steps per revolution of 12, 24, 72, 144, 180, and 200, resulting in shaft incre-
_ments of 30°, 15°, 5°, 2.5°, 2°, and 1.8° per step. “They are pow-
“ered by DC sources and require digital crculiry to produce coil energizing sequences
for rotation of the motor. Feedback is not always required for control, but the use of
‘an encoder or other position sensor can ensure accuracy when exact position eat
is critical. The advantage of operating without feedback (i., in open loop mode) is
that a closed loop control system is not required. Generally, stepper motors produce
ess than 1 tp (746 W) and are therefore used only in low-power position control
applications.
‘A commercial stepper motor has a large number of poles that define a large
‘number of equilibrium positions of the rotor. In the case of a permanent magnet
stepper motor, the stator consists of wound poles, and the rotor poles are perma-
neat magnets, Exciting different stator winding combinations moves and holds
the different positions.
uration of stator and rotor poles to preferred posiens of maximum magnetic
flux, Depending on the eonstraction ofa given motor, there may be 200 or mone such postions. The game then consists
tf sequentially changing te Toeation of the postions of maximum flux (by enerizng the str cols in parila
Sequences) ota the motor operates smoothly inthe desired Siren. The stePmetor has sme asi elecicl and
sararcalpropertics, bu the operational behavior oF the motor (how well or poorly it works is erly a function
your contol algorithm.
‘Motion (and holMing) result fom theSome advantages of using stepper motors:
Control can be (and often is) quite simple: On-Off (0/1) digital control from a
microprocessor.
Accurate stepping means many apps can be done in open-loop mode.
Speed is easily controlled, proportional to pulse frequency from a controller.
Resolution of rotational positioning can be quite good. 2000 stepsitev is commor
Repeatability of absolute position can be excellent (but see step-skipping below).
Best torque at low speeds. Can drive many low-speed applications directly with
no gearing required.
High reliability. No brushes; motor life is mainly bearing life.
Cost is moderate ($25-80 typ), especially for permanent-magnet stepper types.
Stepper motors and controllers are readily available from many vendors.
Some disadvantages:
Not good for some high-speed applications.
Inappropriate control action can cause the motor to skip steps or otherwise
misbehave.
Can require sophisticated controllers for some applications ($$).
Stepper motors are resonant systems (stepping frequency versus inertia cf the
rotor and load combination), so satisfactory operation (noise, torque, startup) in
particular applications can be tricky.Torque ~ Speed Characteristic
A stepper motor is basically a constant power transducer, where power is the speed-torque
product. Therefore, one defining characteristic of step motors is that, at a given voltage, the faster
they run the less torque they produce. You trade speed for torque. The way to get more torque is
to run them at higher voltages. However, if you run the motor at more than it’s rated nameplate
voltage, you will draw too much current at low speeds and motor failure from overheating is the
likely result. Most commercial step motor drivers include a way to limit the maximum eurrent
through the motor windings. This allows high voltages (o be used (operating voltages commonly
range from 3 to 25 times the nameplate rated voltage) for high torque, high speed applications
‘without during out the motor.
‘The graph above shows a stepper being operated at three different voltages, with V1 DirLast THEN
nen-1
ENOTF |
Dirlast = Direction
DEBUG "Step delay (0-100 ms: "
SERIN | D89in,BaudComm, [DEC stepDelay] ‘short delay = faster
DEBUG * nee 13
FOR i ae TO nsteps "send the step patterns
IF Direction=0 THEN *O means clockwise
SEROUT SerPinOut,Baudard, ["" Motor ,Bitpactern(n//4)] ‘control byte
ELSE t= 6 means CCH
SEROUT SerPinOut, Bauderd,["i",Motor,BitPattern(3-(n//4))] ‘control
Page 1ENDIF
PAUSE StepDelay
NeXT
PAUSE 500
Loop
ENG
Fullstep.bs2
Page 2
‘delay after making a step
‘apply holding torque for 500 msFulTRamp.bs2
‘program = FullRamp.bs2 Steve Roberts UCSD/MAE 16 Oct 2007
1A simple: full-step control program for a unipolar stepper motor.
‘with inital and final ramp. . .
‘you specify the number of steps, the direction of rotation, and the speed.
‘For each step of the motor, a control byte is sent out on 1/0 pins 0-7, with
"the actual step pattern contained in the Jowest (least significant) 4 bits of
"the control byte. these 4 bits correspond to 1/0 pins 0,1,2,3. The group of
'8 1/0 pins 0-7 form an 8-bit byte, and are referred to programatically with
‘the pre-defined variable name “OUTL". So, each time you change the bit pattern
‘in OUTL, you are presenting that new pattern to the step motor, which causes
‘a step event.
'NoTE on the '//' operator: This operator is used to calculate which of the four
bit patterns to use at each step. The // operator gives the remainder of a
division. For example, in integer arithmetic 11/4 = 2. But there's a remainder
of 3. The result of 11//4 gives 3, the remainder from the 11/4 division. so, as
the Step count proceeds 0,1,2,3,4,5,6,7,8,9,10,11.,. the // operator will
‘calculate 0,1,2,3,0,1,2,3,0,1,2,3-
"sequence.
1 {SSTAMP BS2}.
* {$paastc 2.5}
DIR. = 811111111
»'which'wiil give us the required step
ying 0,1,2,3,4,5,6,7 are outputs
BitPattern VAR Byte(4) array of the’ four full-step patterns
"46543210 "these are the individual bit nunbers
Bitpattern(0) = 00110000 ‘the most significant 4 bits are used
Bitpattern(1) = 01100000
Bitrattern(2) = #1109000
Bitpattern(3) = 10010000
DB9in CON 16 Tuse the DB9 connector for comm
SerPinout CON 8 tuse this pin for serial out to ctr] board
Baudcomm CON 84 184 means 9600 baud
BaudBrd CON 0 '0 means 50k bps for motor board
Motor CON 4 ‘defines which controller board connections
StepDelay VAR word matt period after each step,” in ms
RampDelay VAR Byte ‘calculated step delay during ramp
Ramp con 30 thow many ramp steps
i VAR word ‘counter for # of sitpattern
ngteps. VAR word tdesired nunber of Bitrattern
Direction VAR Byte tdirection of rotation. O=cw,
n VAR Word "step counter
A =0 ‘starting value
bo
SEROUT, SerPinout, Bauderd, ["i",Motor,%00000000] ‘de-energize all phases
xsteps: DEBUG "How many Steps (=5100)!
SERTN 089in,Baudconm, [DEC nSteps] “how many steps?
IF nSteps < 100 THEN xSteps
DEBUG "Direction (0/1):
SERIN DB9in, BaudComm, [DEC Direction] ‘direction? (O=cw,
DEBUG "Step delay (0-1000 ms:
SERIN | DB9in,Baudcomm, [DEC StepDelay’
DEBUG *
=CCW)
"short delay = faster
1B
FOR i=1 TO Ramp
nent]
IF Direction=0 THEN .
SEROUT SerPinOut, saudBrd, ["i",Motor BitPattern(n//4)] "control
‘amp _up to speed
‘increment the step count
Page 1FullRamp.bs2
ELSE
SEROUT SerPinout,Baudsrd, ["i",Motor,Bitpattern(3-(n//4))] ‘control
ENDIF
RampDelay=(Ramp-i+1) ‘calc current step delay
IF Rampdelay > stepOelay THEN ; ji
PAUSE RampDelay ‘we're still below desired speed
ELSE
PAUSE Stepdelay ‘we're at the desired speed
ENDIF
NEXT
FOR i = 1 TO nSteps-(2*Ramp) ‘we're up to speed here
nent ‘increment the step count
IF Direction=0 THEN *0 means clockwise
SEROUT SerPinout Baudsrd, ["i",Motor,gitPattern(n//4)] ‘control byte
ELSE 0 means _Ccw
SEROUT SerPinOut , BaudBrd, Motor, Bi tpattern(3-(n//4))] ‘control
ENDIF
PAUSE StepDelay
NEXT
FOR i=1 TO Ramp ‘ramp down to stop
1
IF Direction=0 THEN .
SEROUT SerPinout Bauderd, ["i
Motor,Bitpattern(n//4)] ‘control
ELSE
SEROUT SerPinout,BaudBrd, ["i",Motor,Bitpattern(3-(n//4))] ‘control
ENDIF
PAUSE (StepDelay+i) "delay time goes short->long
NEXT
PAUSE 500 ‘apply holding torque FOR SO Ms
Loop
END
page 2Microcontroller I/O Structures
Basic Stamp nomenclature
[=
a vo
Pin #’s
Is @lisbQ —
6 —_ Microcontroller Vdd
20 MCU +—— Power)
pes (MCU) +5, 133V)
a 2
ae
g Sy) Vss
5 4— Ground
°
a 37
Z - 6 — p—T Clock” ]
5 z (Res, Xtal)
SS MSb 7 —
Hl >
2 elise g 4
s x 9 a Reset
a faa]
‘ g 10-
2 ll
a 12-
& oe
= 14-
MSb Ms J5—2__
Input/Output (1/0) can be organized as individual bits, as 8-bit bytes, or as 16-bit words.
Representation: binary (%), decimal ( ), hexidecimal (S) Inthe Basic Stamp language:
Bit: PIN3 = 1, PINI1 - 0 (can only be 0 or
Byte: am = %11010010, 210 (0-255), $D2 (00-FF)
Word OUTS = %1101011011000010, = 54978 (0-65535),
$D6C2_ (0000-FFFF)4: BASIC Stamp Architecture - Memory Organization
‘WeneunbumervarueLss,
“Table 4.2: RAM Organization for
aL BS2 models,
NOTE: There aro 16 words, of
‘wo byes oach fora Toa of 32
bys" A RS aro individual
addressable tvough varie
‘mocies; ho bits wit the
tpper tree wants ar ato
Indiualy aderessable ough
‘tha predefined names shown
‘Allreglters are wor, ye,
‘bole ond bt adaséable
“The BSep, B52po, and BS2px
havo an adaonal sa of INS,
‘OUTS, anc DIRS rites rat
‘are swat an aut ofthe
‘memory pn ace oe rain
Ins, OUTS, and DIRS.
by using AUXIO, MAINIO, ane
IOTERM, Onty to BS2pa0 nas
{he reared extra UO pine tie
features intenda oe
the variable RAM for these models, only the BS2p40 module has the extra
161/0 pins for which this feature is intended,
‘The word variable INS is unique in that itis read-only. The 16 bits of INS
reflect the state of 1/0 pins PO through PIS. It may only he read, not
written. OUTS contains the states of the 16 output latches. DIRS controls
the direction (input or output) af each ofthe 16 1/0 pins.
‘AO ina particular DIRS bit makes the corresponding pin an input and a 1
‘makes the corresponding pin an output. So if bit 5 of DIRS is 0 and bit 6 of
DIRS is 1, then 1/0 pin 5 (PS) is an input and i/O pin 6 (P6) is an output.
‘Appin that is an inputis at the mercy of circuitry outside the BASIC Stamp;
the BASIC Stamp cannot change its state. A pin that is an output is set 10
the state indicated by the corresponding bit of the OUTS register.
When the BASIC Stamp is powered up, or reset, all memory locations are
cleared ty 0, so all pins are inputs (DIRS = 940000000000000000). Also, if
the PBASIC program sets all the 1/O pins to outputs (DIRS
%IIIITIM111110)) ther they will initially output low, since the output
latch (OUTS) is cleared to all zeros upon power-up or reset, as well
Word Naive | Bye Noma] Nibbis Names [ — Bit Names ‘Spsetai Notes
ns | ONG INH [NANG] INO- INT put
Wc. _| we 1N15,
ours’ | OUT OOTH | Guta ours | uTO- OUTT | Oaipal pine
ourc, ourp | oute—ours
Dae | OWL DA | Ora: ORB TO pin erection conor
DiC, omD_| DIAS —DInIS
Wo. B08
we 2B
we BABS
via. 8.67
wa 1. Bo
‘ws [ B10, Bt
‘We | 512 bts
Wr Bi, BIS
wf 16, B17
wo B18. B19
Wid! —|~ 20, bot
wir 3
‘wig | 628, bos
‘BASIC Stamp Stax and Reteronce Mamal 22+ wan paratox.come Page 83Basic Stamp 2 (BS2) V/O structures
Word
DIRECTION CONTROL
DIRx are all ‘reserved’ names in the BS2 syntax, and are used to
specify whether a structure (Word, Byte. Bit) is an input or an output.
Bytes Bits
Comments/Examples
DIRS
DIRL, DIRH_ DIRO-DIR7
DIR8-DIRIS
Indicates VO direction
input=9, output=1)
DIRS = $1101011101101110
DIRE, = 11001111
DIRG = 1 DIR9 = 0
Word
OUTPUTS
Bytes Bits Pins
Comments/Examples
outs
0-15
OUTL 0-7
OUTH 8-15
OUTO-OUT7 0-7
OUTS-OUTIS 8-15
Output entire Word
outs = x (0x 65535)
Output low Byte
oumL = x (0x
Output high Byte
outa = x (0 x 255)
Output on a single pin
oure = x (x-0orJ)
Output on a single pin
ours = x (x=0or J)
Word
INPUTS.
Bytes Bits Pins
CommentsExamples
INS
INH 8-15
INO-IN7 0-7
INS-INIS 8-15
Input entire Word
x = INS (0x 65535)
input low Byte
x = INL (0° x"255)
Input high Byte
x = INH (0-x-255)
Input on a single pin
x = IN (e-Vorl)
Input on a single pin
x = INL1 (x=0or /)