Sunteți pe pagina 1din 44

Floyd, Digital Fundamentals, 10

th ed
EET 2261 Unit 13
Controlling Stepper Motors and Servos

Read.

Homework #13 and Lab #13 due next


week.

Final Exam next week.

There are many kinds of electric motors.


(See Wikipedia article.)

In many motors, the rotor spins continuously,


ith no ay of precisely controlling the
motor!s rotational position and speed.

Stepper motors and servos are to idely


used kinds of motors hose position and
speed can "e precisely controlled.
Stepper Motors and Servos

#ur te$t"ook does not discuss stepper motors


or servos (e$cept in %uestion & on page '(().

)ut Chapter '* discusses pulse idth


modulation (+WM), hich is the techni,ue
used to control servos.
Coverage of Motors in the
Te$t"ook

- stepper motor is a digitally controlled motor


that allos precise control over the position of
the motor!s rotor.

Changes in the digital input rotate the motor!s


rotor "y a precise amount, hich is called a
step or step angle.
.
/epending on the motor, this step angle may
"e as small as * (or less) or as large as 01.
.
#n our motors, the step angle is 2.3.
Stepper Motors

4ecall that an electromagnet "ehaves like a


magnet only hen current is passing through
it. It!s a magnet that you can 5turn on6 or 5turn
off.6
7lectromagnets

7lectromagnets are
constructed "y rapping ire
around an iron8alloy "ar.
(Illustration from Wikipedia.)

- stepper motor has a permanent magnet


connected to its rotor and electromagnets
connected to its stator.

The digital signals controlling the motor turn


the electromagnets on and off in se,uence,
hich results in rotation of the rotor.
Magnets in a Stepper Motor
Simplified image from
John o!ine"# PIC
Microcontroller
Project Book$ %
nd ed.
4otating a Stepper Motor
(Simplified +icture)
From John o!ine"# PIC
Microcontroller
Project Book$ %
nd ed.
n thi# example$
how big i# ea&h
#tep'

In the previous illustration, only one of the


electromagnets as on at a time.

We can get finer resolution "y sometimes


turning on to electromagnets at a time. This
techni,ue is called half-stepping.
9alf8Stepping

/ifferent designs result in several types of


stepper motors:

;nipolar

)ipolar

;niversal (hich com"ine characteristics of


unipolar and "ipolar motors)

#ur motor is a unipolar stepper motor.


Types of Stepper Motors

The num"er of ires on a stepper motor


varies, depending on the motor!s type.

)ipolar Stepper Motor: 0 ires

;nipolar Stepper Motor: 1 or 3 ires

;niversal Stepper Motor: < ires


Wiring a Stepper Motor

The e"site at
http:==homepage.cs.uioa.edu=>?ones=step=
contains an e$cellent online tutorial on
stepper motors, including this animation
shoing the operation of a unipolar motor.
#nline Tutorial

#ur motor is made


"y 9oard Ind., part
num"er *8*@80'('.

-s shon on its
specifications sheet,
it!s a unipolar motor
ith a 2.3 step
angle.
#ur Stepper Motor

To interfacing pro"lems arise hen driving a


motor from a digital system:
*. Motors introduce a great deal of electrical
5noise6 into a system. This noise can
disrupt the operation of sensitive digital
circuits such as the 9CS*'.
'. Motors consume more current than most
digital outputs can supply. Therefore e
can!t connect the motor directly to the
9CS*'!s output pins.
Interfacing +ro"lems

;se separate poer supplies, one for the


motor and one for the 9CS*'.

If needed, e could also use an optoisolator, such as the


IA%&0, to provide further isolation "eteen the 9CS*' and
the motor.
Solution to Interfacing +ro"lem B*
(Coise)

We!ll poer our motor from


the @ D pin in the /ragon*'
"oard!s loer left corner.
Eor this to ork, e must
plug in the /ragon*'!s
poer adapter, instead of
?ust poering the "oard
from its ;S) port.

;se one of the folloing circuits "eteen the


9CS*' and the motor:

+oer transistors, such as the TI+*'(.

Motor driver IC, such as the ;AC'((2 or the


T)33*'ECF 98"ridge. The Dragon12 board has a
TB6612FNG (U12 near the boards lower left
corner).
Solution to Interfacing +ro"lem B'
(Supplying -de,uate Current)

This chip contains a popular driver design


called an 98"ridge. It is often used to control
/C motors and stepper motors.

T)33*'ECF datasheet.
Toshi"a T)33*'ECF

#n the /ragon*' "oard, the T)33*'ECF is


connected to +orts ) and + of the 9CS*'.

Eigure from /ragon*' Schematic /iagram 1.


Connections to T)33*'ECF

#nce you!ve made the proper connections


and configured the 9CS*'!s ports, stepper
motors are easy to program. The folloing
code ill turn our motor counterclockise
(CCW):
Code for Turning a Stepper Motor

- servo motor (or servo) is a package


containing a /C motor connected via gears to
a shaft.

It also contains a feed"ack circuit that


precisely controls the shaft!s angle of rotation.

;nlike a motor hose rotor spins


continuously, a servo is usually used to set
the shaft to a specific angle of rotation and
then hold it there for a hile.
Servos

Servos are commonly used in small ro"otics


and in radio8controlled (4C) airplanes, cars,
and "oats.

In an 4C airplane, for e$ample, servos may


control the plane!s throttle, rudder, elevators,
ailerons, landing gear, etc.

Ce$t slide shos inner orkings of an 4C


airplane.
Servos in 4C Dehicles
Servos and Stepper Motors
Servo: 7$ploded Die
Servo: )lock /iagram
. (iagram abo!e demon#trate# feedback$ in whi&h a
#)#tem"# output i# fed ba&k in a# an input to pro!ide
more a&&urate &ontrol o!er the output.
. Feedba&k i# a fundamental &on&ept in mo#t &ontrol
#)#tem#.

Servos have three ires:

+oer (red)

Fround ("lack)

Control signal (yello or hite)


Wiring a Servo

The /ragon*' "oard has four connectors


(near the center of the top edge) for servos,
la"eled ++0, ++1, ++3, ++&.

Gumper G21 lets you


choose hether to
poer the servo from
the "oard or from an
e$ternal supply. We!ll
poer it from the "oard,
"ut to do so e must have the poer adapter
plugged in.
Connecting Servos to the
/ragon*'

#n the /ragon*' "oard, the servo outputs are


connected to +ort + of the 9CS*'.

Eigure from /ragon*' Schematic /iagram 1.


/ragon*' Connections

#ur servo is made "y


9itec, part num"er
9S82**.

See ServoCity!s
e"page for detailed
specifications.
#ur Servo

The servo!s control signal is a 1( 9H pulse


train. Therefore, hat is this signal!s periodI

-s shon on the ne$t slide, the width of the


plse is crucial in controlling the servo.
Controlling a Servo
Period = ?

The control signal!s pulse width determines


the shaft!s angle of rotation.

Typically this pulse idth ranges from a"out


(.1 ms to a"out '.1 ms, interpreted as follos:

*.1 ms pulse idth: ( rotation.

+ulse idth less than *.1 ms: rotate


counterclockise (up to @(, for our servo).

+ulse idth greater than *.1 ms: rotate


clockise (up to @().
Controlling a Servo

The term pulse width modulation (+WM)


refers to the techni,ue of varying a signal!s
pulse idth to control a device such as a
servo. (+WM is use to control other kinds of
devices, too, including /C motors.)
+ulse Width Modulation

#ne ay to perform +WM using the 9CS*'


ould "e to rite a loop that sets an output
pin 9IF9 and A#W at the right times to
generate pulses of the desired idth and
fre,uency.

This approach ould tie up a lot of the C+;!s


time.

- more efficient ay is to use the 9CS*'!s


"uilt8in +WM "lock. ;sing this approach, once
e have configured the +WM "lock correctly,
it ill generate pulses of the desired idth and
fre,uency ithout tying up the C+;.
+WM ;sing the 9CS*'

The +ulse Width


Modulation (+WM) "lock
shares pins ith general8
purpose I=# +ort +.

Eigure from p. 3 of
te$t"ook or page '2 of
/evice ;ser Fuide).
+ulse Width Modulation (+WM)
)lock
)lock /iagram of +ulse Width
Modulation (+WM) )lock
.
The +WM "lock!s
eight channels let
us generate up to
eight different
+WM signals at
the same time.
.
See page *0 of the
+WMJ<)<C
)lock ;ser Fuide.
Special8Eunction 4egisters
-ssociated ith the +WM )lock
.
The 2@ special8function registers located at
addresses K((-( to K((C& let us control the
operation of the +WM "lock.
.
See page 21 of /evice ;ser Fuide.
Special8Eunction 4egisters That
We!ll ;se
.
The folloing registers are the most
important ones for using the +WM "lock:
.
+WM 7na"le 4egister (+WM7)
.
+WM +olarity 4egister (+WM+#A)
.
+WM +rescale Clock Select 4egister (+WM+4CAL)
.
+WM Scale - 4egister (+WMSCA-)
.
+WM Clock Select 4egister (+WMCAL)
.
+WM Channel +eriod 4egisters (+WM+74$):
one register for each of the eight channels
.
+WM Channel /uty 4egisters (+WM/TM$): one
register for each of the eight channels
+WM 7na"le 4egister (+WM7)
.
The "its in this register let us ena"le or
disa"le each of the eight +WM channels. If
e ena"le a particular channel, then its I=#
pin cannot also "e used for general8purpose
I=# as part of +ort +.
.
Eigure from p. *@ of +WMJ<)<C )lock ;ser Fuide.
+WM +olarity 4egister (+WM+#A)
.
Eor each +WM channel, e can choose
hether the +WM signal starts 9IF9 and
then goes A#W in each cycle, or vice versa.
.
Eigure from p. '( of +WMJ<)<C )lock ;ser Fuide.
+WM Clocks
.
The +WM "lock has four clocks that are
derived from the system!s "us clock:
.
Clock -
.
Clock )
.
Clock S- (Scaled -)
.
Clock S) (Scaled ))
.
+WM Channels (, *, 0, 1 can use either
Clock - or Clock S-
.
+WM Channels ', 2, 3, & can use either
Clock ) or Clock S).
.
The ne$t three slides discuss the registers
that control these clocks.
+WM +rescale Clock Select
4egister (+WM+4CAL)
.
The "its in this register set the fre,uencies
of Clock - and Clock ), as follos:
Eigures from p. '2 of
+WMJ<)<C )lock ;ser
Fuide.
+WM Scale - 4egister
(+WMSCA-)
.
The <8"it value in this register sets Clock
S-!s fre,uency, according to the formula:
.
Eigures from p. '< of +WMJ<)<C )lock ;ser Fuide.
+WM Clock Select 4egister
(+WMCAL)
.
7ach +WM channel has one "it in this
register to select hich clock it uses:
.
Eor +WM Channels (, *, 0, 1, e can choose
"eteen Clock - and Clock S-.
.
Eor +WMM Channels ', 2, 3, &, e can choose
"eteen Clock ) and Clock S).
.
Eigure from p. '' of +WMJ<)<C )lock ;ser Fuide.
+WM Channel +eriod 4egisters
(+WM+74$)
.
7ach +WM channel has one of these
registers.
.
The value in this register determines the
period (cycle time) of the signal generated
"y the +WM channel:
Signal period N +WM+74$ O +eriod of selected clock source
.
Eigure from p. 2* of +WMJ<)<C )lock ;ser Fuide.
+WM Channel /uty 4egisters
(+WM/TM$)
.
7ach +WM channel has one of these registers.
.
-ssuming +WM+#A has "een set so that the signal
starts 9IF9, the value in this register determines
the pulse width (time high) of the signal generated
"y the +WM channel:
+ulse idth N +WM/TM$ O +eriod of selected clock source
.
Eigure from p. 2' of +WMJ<)<C )lock ;ser Fuide.
Sample Code for Configuring
+WM Channel 0
.
Cote that code is incomplete: you must
decide hat values to load into +WM+740
and +WM/TM0.

S-ar putea să vă placă și