Вы находитесь на странице: 1из 3

exist for bigger servos, but a poten-

Pulse-width modulation tiometer is the most common for small


servos. The built-in controller generates

for microcontroller an internal signal from the voltage con-


trolled by the potentiometer, compares
it to the control signal, and then pro-

servo control vides power to the dc motor to rotate


the shaft in the appropriate direction to
match the two. Servos usually
require a pulse-width modulated
control signal.

Pulse-width modulation
NATHANIEL PINCKNEY Often, when controlling an ana-
log device, the ability to drive a
signal with variable power (P = I
× V) is needed. For example, you
may want to adjust the speed of a
dc motor or dim a light-emitting
ANIMATRONICS ARE USED in the diode (LED). This can be a chal-
movie industry to bring aliens, lenge when the signal is generated
dinosaurs, and man-eating sharks by a digital device. Different meth-
to life. Many mechanical devices ods to convert a digital signal to an
are used to impart realism to analog signal exist, one of which is
these puppets. Large motors and a digital-to-analog converter. Using
hydraulics are employed to control a converter will add complexity to
limbs, necks, and other areas a project, so generating a variable
requiring high torque. Small motors power signal with existing circuitry
are used to create facial expres- is desirable to reduce the number
sions, control eyes, and provide of components.
fluidity of movement to add life to An easy method to vary the
these robots. power using a digital signal, when
A common motor used in ani- an analog signal isn’t available, is
matronics is a servo motor. Instead by a method called pulse-width
of providing constant rotation, like modulation (PWM). Instead of con-
most motors, servos are used for trolling the current or voltage of a
precise angular positioning but are signal, a pulse-width-modulated
©ARTVILLE, LLC.

often limited to only 180◦ of maxi- signal works by repeatedly pulsing


mum rotation. Dozens of servos are the digital signal high and low at a
used to control the facial expres- fast rate. When sufficiently fast, the
sions of a robotic puppet. Even a signal creates an effective average
simple android might have five servos your own servo with a few common voltage. A shorter PWM period (the
controlling just the eyes. The latex skin components. Internally, a servo can be length between the rising edges) will
or muscles of an android’s face are con- thought of as a direct current (dc) motor create a cleaner average voltage,
nected to the servo’s shaft so that the (which rotates an external motor shaft because the signal is effectively less “jit-
servo can contort the face into different but provides no way to determine the tery” (i.e., less discharge from the capac-
expressions. Servos are also common in amount of rotation) with a built-in con- itance in the line is needed to smooth
devices such as radio-controlled cars to troller. The control circuitry compares the signal), but the minimum period will
control steering, radio-controlled air- an angular position, determined by a be limited by the speed of the device
planes to control rudders, or even in the control signal, to the current position of generating the signal. The period of the
cruise control systems of cars. Servos are the motor shaft (as shown in Fig. 1). PWM signal is usually constant for a
ideal for applications requiring absolute The motor shaft’s angular position is given application, and the high pulse
positioning of a motor shaft. often determined by a potentiometer, width (the duration of the signal being
Microcontrollers are an excellent and which is rotated by the motor shaft. A driven high within one period) is usual-
inexpensive device for controlling ser- potentiometer is a three-terminal resistor ly variable, so that the average voltage
vos. In order to properly control a whose center connection has variable of the signal can be changed. The ratio
servo with a microcontroller, it is neces- resistance, usually controlled by a slider of high pulse width to period of the sig-
sary to learn a few techniques, such as or dial. The potentiometer acts as a vari- nal is called the duty cycle. By varying
properly generating a control signal for able voltage divider. The voltage from the duty cycle, you can vary the average
a servo, which the rest of this article the center connection of the poten- voltage, as shown in Fig. 2.
will cover. tiometer represents the angular position The power through a device is pro-
Servos may be purchased in a the motor shaft is in. Other methods to portional to the voltage supplied.
prepackaged form, or you can create determine angular position and rotation Therefore, to decrease the power usage

JANUARY/FEBRUARY 2006 0278-6648/06/$20.00 © 2006 IEEE 27


of a device (to dim an LED otherwise, it is driven low.
or to slow a motor), the duty After the PWM period has
cycle of the PWM signal elapsed, the count can be
should be decreased. A PWM Variable reset and the process started
signal can be used to limit Voltage Potentiometer Motor over. The PWM period will
the power to a device to Shaft be the same as the time it
save energy. This technique takes the PIC to run your
is used in many portable Internal Signal code. To increase the length
devices which have limited Generator of the PWM period, loops
battery power. For example, can be used to create delay.
wave a device with an LED This method will work on
back and forth in your hand DC Motor Control the simplest of PICs but
Compare
and you will often see a Control leaves little processor time to
strobe light effect instead of Signal do anything else. A couple
a straight streak. This blink- variations exist and can be
ing is from the pulse-width- used if the PIC includes the
modulated signal turning the Fig. 1 The inside of a servo necessary hardware. A timer
LED on and off. The blinking can be used and polled at
cannot normally be per- intervals in between code to
ceived by the human eye when the LED ing and responding to input) for a determine if the PWM signal needs to
is stationary, since it is blinking at a rate simple robot on a single chip. be updated. Another solution is to have
faster than the eye can perceive. But the PIC update the PWM signal on a
when moving, the discrete flashes Signal generation with a PIC timer overflow interrupt. This guaran-
become visible because the LED is only Pulse-width-modulated signal genera- tees that the PWM signal will be updat-
lit up at certain positions as it moves. tion is easy to implement on microcon- ed at specific intervals, while most of
Some devices, such as servos, do trollers. All microcontrollers will be able the processor time can be used for
not rely on the power of the signal to generate a PWM signal, but the more other tasks.
limited by PWM but instead use the expensive and elaborate ones provide The least processor-intensive
width of the high pulses to transmit hardware to make PWM generation easi- method is to use a built-in PWM mod-
information. This is also used by er, freeing up more processor time to ule if your microcontroller has one.
infrared remote controls to transmit run other tasks. An inexpensive and eas- When enabled, the PWM module will
data to control a television or radio. ily obtainable microcontroller, such as automatically generate a PWM signal
Pulse-width-modulated signals may the PICmicro 18F452, provides enough with a period and duty cycle specified
be generated from many digital hardware to implement PWM generation in control registers on the PIC.
devices, even ones as simple as an using a few different methods, depend- Depending on the microcontroller you
inexpensive timer integrated circuit ing on the needs of the application. are using and the speed it is running
(such as the 8-pin 555 timer). A ver- The simplest but most processor- at, the built-in PWM module might not
satile yet inexpensive solution for intensive method to create a PWM sig- support a large enough period needed
many robotics hobbyists is to use nal is manually comparing a “count” to for the device you are using, such as
microcontroller for PWM generation. a variable that describes how long the for a servo motor (which commonly
Using a microcontroller has the added high pulse width should be. When the has a period of 20 ms). In that case,
advantage of containing all of the count is less than the pulse width vari- you will want to use one of the previ-
control circuitry (needed for analyz- able, the PWM signal is driven high; ously mentioned methods to generate
a longer PWM signal.

Controlling a servo
PWM, Duty Cycle = 1/4 Average Voltage = 1/4 Vdd Most servos, including the Hitec
High RCD USA, Inc. HS-322HD demonstrated
=> here, have three pins: power, ground,
Low and a control signal. The control signal
Pulse is a pulse-width-modulated input signal
Length whose high pulse width determines the
servo’s angular position, as shown in
Period
Fig. 3. Internally, the servo compares
PWM, Duty Cycle = 3/4 Average Voltage = 3/4 Vdd the PWM control signal to an internally
High generated signal, whose pulse widths
=> are controlled by the potentiometer
Low (which determines the shaft angle) and
Pulse Length matches the pulse widths by rotating
Period the motor shaft. For the HS-322HD,
power can be between 4.8 Vdc (volts
of direct current) and 6 Vdc. Since
Fig. 2 Pulse width modulation and average voltage the control signal (which draws a

28 IEEE POTENTIALS
maximum of about 20 mA) other projects as well.
does not drive the motor Depending on the features
directly, an additional bene- PWM included with the microcon-
High
fit of using a servo is that the troller you are using, a PWM
PIC (whose output pins can => signal can be generated in a
drive up to 25 mA) can Low variety of ways.
0.9 ms
drive the control signal
directly. Most motors draw High Additional resources
more than 25 mA of current => This article was written
for operation and, therefore, Low jointly with the development
must be indirectly connected 1.5 ms of a set of tutorials on how
to the PIC through a current High to use different devices with
amplifying device, like an H- => the Microchip Technology’s
bridge or a transistor. Low PIC 18F452 microcontroller
Typically, servos require 2.1 ms and Xilinx’s Spartan 3 FPGA.
a PWM signal with a 20-ms Five undergraduate students
20 ms
period and a pulse width and two professors under-
between 0.9–2.1 ms (0.9 ms took the development of the
corresponds to the minimum tutorials, appropriately
Fig. 3 Controlling an HS-322HD servo with PWM
angle and 2.1 ms corre- named MicroToys guides.
sponds to the maximum More information about PIC-
angle); therefore, the middle controlled servos, as well as
position is 1.5 ms (the average of the signal is applied. If there is no signal, controlling other devices with a PIC
minimum/maximum pulse widths). The the servo’s motor shaft is not driven by microcontroller, can be found at Harvey
HS-322HD has a maximum angle of any circuitry and, hence, can be rotated Mudd College’s E155 MicroToys Web
180◦ . Servos only move a finite angular freely, even when power is supplied to site at <http://www4. hmc.edu:8001/
amount per cycle of the signal, so mul- the servo. Engineering/microtoys/>.
tiple cycles must be sent before the
servo arrives at the correct angle. The Conclusions About the author
speed/power at which the servo moves Microcontrollers offer a simple and Nathaniel Pinckney is a first-year
to a new position is proportional to the inexpensive solution for controlling undergraduate engineering student cur-
distance it needs to travel. So as the servo motors for robotics and other rently attending Harvey Mudd College.
servo becomes closer to the target electronics projects. Through the use of Before attending Harvey Mudd, he was
angle, it will gradually slow. The servo PWM, the angular position of the servo home schooled since second grade. He
will resist change away from the desig- motor shaft can be conveniently con- has been involved in the development
nated angle as long as a signal is trolled by a microcontroller for a vari- of various GNU/Linux software pro-
applied. Note that the servo’s control ety of projects. PWM is an easy solu- grams and is interested in parallel
mechanism will only engage when a tion for the control of analog devices in embedded architecture design.

JANUARY/FEBRUARY 2006 29

Вам также может понравиться