Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
The principal active devices in electrical circuits are the transistors. Two important types are: (1) the bipolar transistor, simply called a transistor, and (2)
the field-effect transistor or FET. When input currents are kept relatively small,
the transistor serves as an amplifier. When the transistor is overdriven, it acts
as a switch. It is this mode which is most useful in digital electronics. Bipolar
transistors are used both in integrated circuits (TTL family) and as interfacing
devices in general circuits. FET is used primarily in integrated circuits (CMOS
family) and power switching devices.
6.1
Diodes
Diodes and transistors are often made from silicon, and sometimes made from
germanium. Each silicon (Si) atom has four outer electrons which join with
neighboring atoms to form a complete bond (insulator). If one of the Si atoms
is replaced (doped) by arsenic, which has five outer electrons, one unpaired
electron is present. The extra electron is easily freed by an electric field to form
electricity readily. The carrier is referred to as an n-type, n standing for negative
charge carriers. If the Si is doped by gallium, which has three outer electrons,
an electron vacancy called a hole exists. Any free electron can wander in and
fill this vacancy; in the process it also conducts. This positive charged carrier is
referred to as a p-type.
If a p slice and n slice are joined together, the device is called a diode. The
structure and symbols are shown in Figure 6.1. At about 0.7(V) the diode
conducts in the forward direction. Note that there is very little resistance to
158
where
iD
vD
I0
q
k
T
m
This equation is sketched in Figure 6.2(a) for germanium and silicon. The
curves of Figure 6.2(a), when plotted to a suitable scale, appear to turn on at
approximately 0.2(V) for germanium and 0.7(V) for silicon.
At room temperature, i.e., T = 300(K),
VT
:=
kT
25(mV ).
q
The diode equation states that if vD is negative with magnitude much greater
than kT /q, the current iD is the reverse saturation current I0 . This reverse
current, I0 , is a function of material, geometry, and temperature. If, however,
vD is positive and much larger than kT /q, the forward current is
Hossein M. Oloomi
159
6.2
Bipolar Transistors
The bipolar transistor consists of three slices of p-type and n-type material. The
base (B), a very thin slice of one of them, is sandwiched by the complementary
pair, thus the name bipolar. Other segments are called the collector (C) and
the emitter (E). Figure 6.4 shows the two variations in structure: npn-type and
pnp-type.
Each type has three different ways the load can be wired across (C) and (E),
in regard to position and current direction. The connections are common emitter, common collector, and common base. Observe that all current directions
Purdue University Fort Wayne
Hossein M. Oloomi
160
Figure 6.4: Transistor types and connections: (a) npn transistor, and (b) pnp
transistor.
Hossein M. Oloomi
161
are reversed from the npn-type to the pnp-type. Also, the npn transistors are
turned ON by applying a voltage HIGH to the base (B) while the pnp transistors
are turned ON by applying a voltage LOW to the base.
The npn transistor is the most popular type available today because it costs
less to produce. The npn transistor is also faster than the pnp transistor. It
operates in the same manner for any configuration. Power gain is highest for the
common emitter. This is the reason that the connection is used most frequently.
The common base connection has the lowest input resistance and the highest
output resistance. The common collector connection shows the highest input
resistance and the lowest output resistance.
A typical transistor circuit is shown in Figure 6.5(a). A small base current
IB is used to control a much larger collector current IC or
IE
IC + IB IC .
:=
IC
,
IB
IB .
= RL IC ,
Hossein M. Oloomi
162
Figure 6.5: The npn common emitter transistor and characteristics: (a) basic
circuit, (b) base characteristics, and (c) collector characteristics.
Hossein M. Oloomi
163
VCE
VCC VL .
Since the output voltage VCE can vary from VCE = 0 (IC = VCC /RL) to
VCC , a resultant load line can be drawn across the collector characteristic
curves. The interest in this line is its intersection with the saturation
line. Thus, the region of active DC current gain is 0 < IB < 190(A)
for the particular transistor and load given. Once an operating point P is
established, the current gain can be found from the graph by introducing
a small change in the base current.
Saturation The base current may be increased to any desired value, but the
collector current IC is limited to the saturation value ICS = 24(mA). If
IB ICS /, the transistor is said to be saturated. Notice that VCE is not
quite zero at saturation. Generally, the saturation voltage VSAT for VCE
is about 0.2(V) for most transistors. The high slope of the saturation line
precludes any variation in VSAT with the load RL. The base-to-emitter
voltage VBE remains about 0.7(V) once the transistor is turned ON.
Example 6.1 For the basic circuit and transistor characterisitics shown in
Figure 6.5, find the permitted voltage and currents if Vi is: (1) 0.1(V), (2)
1.0(V), and (3) 5(V).
1. Since VBE < 0.6(V ) the transistor is cutoff. IB = IC = 0. Therefore,
VCE = 30(V ).
2. Since Vi > 0.6(V ), VBE 0.7(V ) (any transistor):
IB =
Vi VBE
1 0.7
=
= 30(A).
RB
10(k)
5 0.7
= 430(A).
10(k)
Hossein M. Oloomi
164
IBS
VCC VCE
30 0.2
=
25(mA),
RL
1.2(k)
ICS
25(mA)
=
= 100(A).
250
Since IB > IBS , the transistor is saturated and the preceeding ICS holds.
Note that the current gain is nonlinear and a more representative gain
near saturation is 100 or IBS = 250(A), compared to 190(A) earlier.
6.3
An earlier type of transistor, called the junction FET or JFET, depends upon
load current control by means of a voltage rather than a base current. It consists of a channel of n-type silicon through which the current passes from drain
to source (see Figure 6.6(a)), much like the collector-emitter in bipolar transistors. The channel is surrounded by p-type silicon but the electrons flow only
through the n-type, making it unipolar. When a negative voltage is applied to
the gate (analogous to the base), the carrier electrons are repelled, forming a
depleted area, and the channel resistance increases. The drain or load current is
decreased. Maximum drain current occurs for zero gate voltage. Positive gate
voltages destroy the operation of the device by permitting gate current. If the
doping is reversed, the operation of the JFET is reversed. Current must be
from source to drain. Increasing the positive gate voltage decreases the source
current.
JFETs have been largely overtaken by metal oxide semiconductor FET or
MOSFET, MOS for short. It includes an insulating layer of silicon dioxide
between the channel and gate as shown in Figure 6.6(b). The field is still
effective in modulating the electron flow in the channel; however, the gate makes
no electrical contact with the channel. Since no current can flow through the
gate, positive or negative gate voltages can be applied.
There are four basic types of MOSFET structures. MOSFET can be either
n channel (p substrate) or p channel (n substrate). If the channel is actually
provided, it is said to be a depletion type since the applied gate voltage depletes original free carrier electrons in the channel. A zero gate voltage allows
an effective drain (or load) current. Positive voltages increase the drain current while negative voltages decrease it. The wide operating range makes the
depletion type useful for signal amplification. If a channel is not provided, the
gate voltage induces an equal but opposite charge in the adjacent substrate.
The free-moving charges behave as though a channel were present. This type
is referred to as an enhancement type. Positive gate voltages are used with
the p substrate, while negative gate voltages are used with the n substrate.
Since an open drain-source circuit exists for the enhancement type, it is ideal
for switching applications.
Hossein M. Oloomi
165
Figure 6.6: Types of FET transistors and their symbols: (a) JFET, and (b)
MOSFET.
Hossein M. Oloomi
166
6.4
Power Electronics
Power electronics center mainly on three terminal, gate-(base) controlled devices. These devices fall into two classes: (1) power transistors, and (2) thyristors. In the low-to-medium DC power range power transistors are the choice.
They include the bipolar transistor, the Darlington (or dual bipolar) transistor, and the field-effect transistor (MOSFET). Each remains ON only as long
as the gate is active. MOSFET is preferred because the gate is voltage controlled rather than current controlled. Recent design advances have enabled
MOSFETs to compete more effectively with Darlingtons in the medium power
range. From the early 1960s until quite recently, the silicon-controlled rectifier
(SCR) member of the thyristor family was universally used as the high-power
semiconductor switch. Today the words thyristor and SCR are interchangeable.
SCRs are pn-type devices that are turned ON by a simple voltage pulse. HowHossein M. Oloomi
167
I(A)
V(V)
P(kW)
Transistors
Darlington MOSFET
400
100
1000
1000
20
5
Thyristors
TRIAC SCR
50(rms) 2000
1000
4000
2
100
ever, they latch ON until the load current goes to (almost) zero. Conduction is
unidirectional. Recently, interest has been growing in the gate turn OFF thyristor (GTO), which can be turned ON by a positive voltage pulse and turned OFF
by a negative voltage pulse. SCRs and GTOs control DC or rectified AC power.
The TRIAC consists of opposing SCRs and can conduct in both directions. It
is normally used to switch AC circuits in the low-to-medium power range.
Table 6.8 gives the present rating limits for power semiconductors. Voltage
limits relate to the pn-juntion breakdown in the OFF state. Current limits
depend upon chip wire capacity. Power limits pertain to the load power being
switched, and they are directly tied to the chip power dissipation limits which
are a much lower number.
Power semiconductors are placed into an assortment of packages. These
packages are designed to dissipate heat. All but the low-power ones require
heat sink attachments to meet power specifications. Figure 6.8 shows the most
common packages and their approximate current range.
Power electronics is based primarily on the switching of semiconductor dePurdue University Fort Wayne
Hossein M. Oloomi
168
6.4.1
hF E IB ,
Purdue University Fort Wayne
169
To ensure that the transistor is driven into saturation, we must force a base
current of at least
IBS
ICS
.
hF E
Normally, one designs the circuit such that IB exceeds IBS by a factor of 2 to
10, called the overdrive factor (ODF):
ODF
IB
.
IBS
Hossein M. Oloomi
170
Hossein M. Oloomi
171
Hossein M. Oloomi
172
Hossein M. Oloomi
173
ICS
9.5
=
= 0.63(A).
hF E
15
VCC VBE
20 1.0
=
= 15().
IB
1.2
Hossein M. Oloomi
174
= L
dI
LIC
=
dt
tf
4
(PD )base = 12( 35
) = 1.4(W ) (including Rb)
(PD )collector = (0.17)(2) = 0.35(W )
(PD )total = (12)(2) = 24(W )
Efficiency =
24(1.4+0.35)
24
= 93%
175
20
(PD )base = 12( 13
) = 18.5(W )
(PD )collector = (0.8)(10) = 8(W )
(PD )total = (12)(10) = 120(W )
Efficiency =
120(18.5+8)
120
= 78%
A major drawback for bipolar power transistors is the large base current
drive. To meet start conditions, the base current must be supplied by another
power transistor. The second transistor must be driven by a buffer (or generalpurpose transistor) before interfacing a peripheral interface adater (PIA).
The design is based on the typical characteristics plot of Figure 6.11,
where (VCE )SAT is 0.8(V). A more conservative design evaluates parameters
with the worst possible transistor; i.e., use the electrical characteristics data in
Figure 6.11, where (VCE )SAT = 3.5(V ) max. Suppose we had selected a TIP33
with a current rating of 10(A). The data sheet has no typical characteristics plot
for (VCE )SAT . We would be forced to use the listed (VCE )SAT = 4(V ) max.
Needless to say, the design efficiency would be severely reduced for the worst
case.
6.4.2
Darlington Transistors
Bipolar power transistors have low-current gains with high base currents. Its
driver is usually another lower-rated power transistor. If both transistors are
mounted on heat sinks, a considerable amount of space will be occupied by
the two transistors. This problem is circumvented by encapsulating the two
transistors on the same chip, called a Darlington transistor.
The Darlington circuit is shown in Figure 6.15. Emitter current from Q1 is
also the base current of Q2. The combination has three external connections
(B, C, and E), which act as a single transistor whose gain equals Q1 gain Q2
gain. Current gains of the two transistors are controlled during manufacture so
that the overall gain varies linearly over a range of collector current when it is
used as an amplifier. As a result, Darlingtons have high values of (VCE )SAT ,
which cause larger switching losses than the separated design.
Purdue University Fort Wayne
Hossein M. Oloomi
176
177
Hossein M. Oloomi
178
Figure 6.18: When to include external diodes if using power transistors with
built-in free wheeling diodes? Case (a) only.
mistake since hF E is not much better than a single power transistor.
Chip temperature presents a somewhat different problem. Unless
the case temperature is known, hF E is uncertain by a factor of 3.
Therefore a large overdrive factor will be necessary to be certain
that saturation is reached.
Collector-to-Emitter Saturation Voltage. Figure 6.17(c) shows
that (VCE )SAT is higher than bipolar power transistor values at all
collector currents. The voltage drop is far worse at collector currents approaching the maximum-rated current. In spite of the higherpower losses in Darlingtons, they are preferred because the high hF E
will simplify driver hardware. Power losses are minimized by using
Darlingtons in load circuits that have low currents and high voltages
across the load.
Switching Time. Darlington switch-ON times are comparable to bipolar transistors. However, the switch-OFF times are an order of magnitude longer than bipolar power transistor tOF F .
Free-Wheeling Diode Texas Instruments Darlington transistors have a builtin free-wheeling diode across the collector-emitter terminals. In some configurations it will eliminate the need for an external diode to shunt the
switch-OFF voltage buildup with load inductance. The key is placing
the load between the transistor and ground. This point is illustrated in
Figure 6.18. Only case (a) should have an external protecting diode.
Example 6.4 The T bridge motor design in Example 6.3 replaces the
bipolar power transistor with the TIP663 Darlington rated 20(A) continuous collector current. A driver circuit is given in Figure 6.19. Let us
Hossein M. Oloomi
179
4
(PD )base = 12( 1500
) = 0.03(W )
(PD )collector = (0.8)(2) = 1.6(W )
(PD )total = 1.6(W )
Efficiency =
241.6
24
= 93%
Start/stall mode
IC = 10(A)
(VCE )SAT = 1.2(V )
hF E = 1000
IB = 10(mA)
= 30(mA)(with overdrive)
Vm = (12 1.2) = 10.8(V )
12012.1
120
= 90%
The drive requirements are substantially reduced from the bipolar power
transistor design. Still, a 74S241 buffer/driver and pull-up resistor must
be placed between the PIA and the Darlington. The Darlington dissipation is greater than the bipolar transistor, which is expected from its
higher (VCE )SAT . We should point out that using this transistor for a
motor rated at 15(A) start/stall is perfectly acceptable. Yet the collector
voltage drop (VCE )SAT = 3.3(V ). If a heat sink design allows the case
temperature to stabilize much above 100(C), (VCE )SAT could double this
value. The motor drive voltage Vm is supply voltage minus the transistor voltage drop. In some cases, particularly H bridge drives which have
two transistor voltage drops, there may be insufficient voltage to meet the
design requirements, 10(V). Darlingtons are susceptible to this problem.
Purdue University Fort Wayne
Hossein M. Oloomi
180
6.5
6.5.1
Microswitches
Microswitches are small momentary switches with many applications. For example, they can be attached to bumpers of a mobile robot to signal when the
robot has run into an obstacle. Figure 6.20 shows two ways to interface the
bump switches to the microprocessor. The circuit in Figure 6.20(a) is straightforward: One pin of port E is used for each switch. When the robot collides with
an obstacle, one or two switches close, changing the state of the corresponding
bit(s) from 0 to 1. This approach has the advantage of being easy to understand
and implement, but it uses up three of the MC68HC11s input lines.
There is another way to achieve the same functionality that uses only one
MC68HC11 input pin. This second approach is shown in Figure 6.20(b), where
a network of resistors is used to create different voltages at the MC68HC11 input
pin, depending on which switch is closed. (The A/D mode for port E must be
used.) The bump switch software driver must read pin PE3, do a conversion,
and then set one of eight flags. The correct flag signifies which switch or set of
switches is closed; this is determined by in which of eight ranges the measured
voltage falls.
A careful analysis will show that the circuit in Figure 6.20(b) is essentially a
voltage adder. As long as the current flowing from the +5 V supply through the
single 2.2(k) resistor and two 1.2(k) resistors to ground is large compared
to the current flowing through any other part of the circuit, this approximation
will hold. If, as shown, the powering voltage divider has taps at1/4, 1/2, and
1 times the supply voltage, then the voltage sum will be 1/3(A + B + C)
(where each of points A, B, and C is connected either to its corresponding tap
or to ground). Since the A/D converter produces digital values between 0 and
255, the set of voltages it reads will be 1/3 of 255 times the sum of the voltages
from the switches. For example, when only switch A is closed (connected to
ground), the A/D output will be 1/3255(0 + 1/2 +1/4)64. When switches
B and C are closed, the output will be 85.
Microswitches can be attached in a number of ways to enhance their applicability. They can be connected to one or more whiskers extending from the
robot; deflecting the whisker causes switch closure. For grippers and hands, too,
microswitches make very simple but effective touch sensors.
Hossein M. Oloomi
181
Figure 6.21: Radio shack 276-1657 photoresistors are shown in a voltage divider
configuration connected to port E, bits 0 and 1. Port E is used here in analogto-digital converter mode.
6.5.2
Photoresistors
Visible light sensors and infrared sensors span a broad spectrum of complexity.
Photocells are among the easiest of all sensors to interface to a microprocessor,
and the interpretation of a photocells output is straightforward. Video cameras,
on the other hand, require a good deal of specialized circuitry to make their
outputs compatible with a microprocessor, and the complex images cameras
record are anything but easy to interpret.
Light sensors can enable robot behaviors such as hiding in the dark, playing
tag with a flashlight, and moving toward a beacon. Simple light sensors can be
purchased as photoresistors, photodiodes, or phototransistors. A photoresistor
(or photocell) is easy to interface to a microprocessor. As shown in Figure 6.21,
only one external component is needed. Photoresistors are simply variable resistors in many ways similar to potentiometers, except that the resistance change
is caused by a change in light level rather than by turning a knob.
Phototransistors provide greater sensitivity to light than do photoresistors.
A phototransistor is almost as easy to interface to a microprocessor as a phoPurdue University Fort Wayne
Hossein M. Oloomi
182
RLI.
The resistance of the photoresistor falls as the light level increases. This
means that the voltage at PE1 decreases. Substituting for I, we get
VP E1
RL
V.
R + RL
The 8-bit A/D converter in the MC68HC11 maps the variable voltage, VPE1,
into the range 0 to 255. Although the mapping provided by the simple voltagedivider circuit is not logarithmic, as was recommended for light sensors in Subsection , a useful output can nevertheless be extracted. A good compromise
between sensitivity and range will be achieved if the resistance, R, is set to the
same value as the resistance exhibited by the photoresistor when exposed to
the light level in the middle of the range of light levels in which the robot must
operate.
Hossein M. Oloomi
183
equ
equ
equ
equ
equ
equ
$10
$11
$1039
$1030
$1031
$1032
update-photo
bset option #%10000000
Purdue University Fort Wayne
184
#%00010000
check-result
brclr adctl #%10000000 check-result; Wait in tight
Idaa adrl
;Get value from rt
staa ph-right
;Save right value
ldaa adr2
;Get value from lf
staa ph-left
;Save left value
rts
;Return to calling
loop
photocell
photocell
code
void update_photo()
{ poke(option, ob10000000); /* Enable A/D system */
poke(adctl, 0b00010000); /* Begin conversion */
while( (peek(adctl) & 0b1000000) == 0 )
{}
/* Wait until conversion finished */
ph_left=peek(adr1);
/* Get and store A/D channel 1 */
ph_right=peek(adr2); }
/* Get and store A/D channel 2 */
In both versions, we first designate locations where the results of the A/D conversions will be stored: ph-right, ph-left for the assembly version and ph right,
ph left for the C version. We enable the A/D system by writing the proper
value to the OPTION register; then we begin a conversion by writing to the ADCTL register. The next part of both programs polls the conversion-complete bit
of the ADCTL register, remaining in a tight look until the conversion flag is set
by the internal hardware of the A/D. Finally, the results of the conversion are
moved from the result registers, ADR1 and ADR2, to the designated locations.
To learn the details of which registers and which bits control the various
functions of the A/D converter and the microprocessors other systems, you
should really consult the documentation for the MC68HC11A0.
6.6
Interfacing DC Motors
185
Figure 6.24: T circuit with linar amplifier for open-loop speed control.
be inferred from the time integral of the control voltage; i.e., applying a known
voltage VR (t) for a fixed time will give a corresponding rotation .
There are two methods to control the motor by means of the amplifier: (1)
linear transistors, and (2) switching transistors. Linear transistors are power
transistors that operate in their linear range, motor voltage being proportional
to VR . Figure 6.24 shows a T-type configuration for driving motors with complementary power transistors. When the control voltage is positive, the motor
runs clockwise; negative voltages reverse the motor. A single transistor can be
used for unidirectional control.
An alternative drive method using switching transistors is more suitable to
digital control. However, these Darlington and MOSFET transistors are not discussed here. There are two approaches: (1) pulse-width-modulated (PWM), and
(2) pulse-frequency-modulated (PFM). PWM control voltages work by switching the full voltage of the DC power supply to the motor on and off at a fixed
frequency. By varying the duty cycle (on portion of the cycle), the average
voltage seen by the motor varies in proportion to the duty cycle. Switching
frequency is above the audible range, on the order of 16,000 cycles per second,
much higher than the motor time constant so that the motion is smooth and
continuous. The PFM control voltage switches the DC supply on for a fixed
period of time (fixed width) but varies the spacing between the pulses or repPurdue University Fort Wayne
Hossein M. Oloomi
186
Figure 6.25: H-bridge with switching amplifiers (PWM) for open-loop speed
control.
etition rate. For low average voltages as seen by the motor, the frequency is
low. Voltages are increased by increasing the switching frequency. PFM control
is less popular but common for hobby servos used in radio controlled models.
An H-bridge configuration, Figure 6.25, consists of four switching transistors.
Motor direction is controlled by which input receives the PWM voltage. In
the forward mode, e.g., transistors Q1 and Q4 are ON, and current flow is
left-to-right through the motor. A system that is more compatible with microprocessors is shown in Figure 6.26. A PWM voltage is applied to a single input,
and the motor direction is controlled with HIGH/LOW voltage on a second
input. Either T or H configurations can employ switching or linear amplifiers.
The H-bridge is preferable because it takes a single unipolar power supply, but
it is more difficult to control with the linear method.
Linear transistors are confined to low-to-medium performance (less than
5(A)) motors because of heat and power loss. Power dissipation in transistors
is the product of current and voltage drop on the order of 0.2(V). If the excessive heat generated is not removed, motor current (torque) must be reduced.
Linear transistors are susceptible to breakdown at peak current levels, which
occur when motors are overloaded. For this reason current limiting circuits are
employed.
6.6.1
187
MOSFETs. A level shifter and charge pump circuit are included on the chip to
drive the high-side switches.
Three capacitors and an inverter are the only external components required
to interface an MPC1710A to Rug Warriors MC68HC11A0. We could use port
D pin PD5 to set the forward or reverse direction of the motor and port A pin
A5 to pulse-width modulate the enable input for speed control. The Motorola
MPC1710A can deliver up to a 1(A) of current with a 0.4() on-resistance when
sourcing current and 0.2() on-resistance when sinking current.
For the two motors on Rug Warrior, two MPC1710A chips would be needed,
one for each motor. One motor could be controlled by pins PD5 and PA5 and
the other motor by pins PD4 and PA6. The MPC1710A comes in a small 16-pin
surface-mount package, which makes it very compact when used in a printed
circuit board design but rather difficult to use when prototyping with Speedwire
or Scotchflex wiring technologies. For this reason, on Rug Warrior, we chose to
use a chip that would be more amenable for our readers, the SGS Thompson
L293D.
The L293D was chosen because it comes in a normal 16-pin dual-inline package (DIP). This selection, which has two H-bridges on board, minimizes the
parts count and delivers enough power for Rug Warriors motors. The L293D,
shown in Figure 6.26, uses a bipolar H-bridge instead of a MOSFET H-bridge.
Again, all switches are made from n-type devices and a step-up circuit is incorporated on chip to drive the high-side switches. Flyback diodes are integrated
Purdue University Fort Wayne
Hossein M. Oloomi
188
Figure 6.27: Two Motorola MPC1710As can be used to drive the Handy Bugs
two motors. One MPC1710A is needed for the left motor and one MPC1710A
is needed for the right. This surface-mount integrated circuit motor driver chip
uses an H-bridge made from n-channel power MOSFETs.
Hossein M. Oloomi
189
Figure 6.28: A single L293D chip is used to drive both of the Handy Boardd
motors. The MC68HC11s port D pins PD4 and PD5 select forward and reverse
for the left and right motors, respectively, while port A pins PA6 and PA5 pulsewidth modulate the left and right enable pins. Note that OC1 here is used to
also control OC2 and OC3.
on chip in this circuit. The L293D can deliver 600(mA) to the motor, with a saturation voltage drop of 1.4(V) when sourcing current and 1.2(V) when sinking
current.
Figure 6.28 illustrates how we have interfaced the L293D to Rug Warriors
6811. The L293D has some on-chip logic that provides an Enable signal. In this
way, the Inputs to the H-bridge can be used to set the direction of the motor
and the Enable signal can be used for pulse-width modulation. We use port D
pin PD5 to set the direction for the right motor. An inverter is used to set one
side of the H-bridge to the opposite polarity voltage of the gating signal of the
other side. This ensures that if switches S1 and S4, for instance, are on, then
switches S2 and S3 will be off and vice versa. Note that this means that the
motor is never actively braked. The H-bridge is pulse-width modulated by tying
the right motor drivers Enable pin to port A pin PA5. The output compare
function of PA5 is used to facilitate timing. One advantage of the L293D is that
two full H-bridges are incorporated on chip, which means that only one L293D
is needed to drive both of Rug Warriors wheels. Port D pin PD4 is used to set
the direction of the left motor, and port A pin PA6 is tied to the Enable signal
for pulse-width modulation.
Many other motor-driver-power integrated circuits are available. As mentioned in E, the place to begin searching is the IC Master. The IC Master lists
integrated circuits both by part number and by function. Listings under Motor Drivers include a number of suppliers, such as Unitrode, Siemens, Motorola
and International Rectifier, among others.
Purdue University Fort Wayne
Hossein M. Oloomi
190
6.7
The software for controlling Rug Warriors motors must do two things. First,
the software needs to control the speed of the robot in the manner desired by
the programmer. For instance, a higher pulse-width ratio of voltage across the
motor is needed to keep the robot moving up a ramp at one foot per second
than would be required to make it move along a flat tile floor at one foot per
second. To maintain a desired speed, regardless of terrain, means that the robot
needs to count the number of pulses from one of the shaft encoders to see how
fast the wheels are turning and then update the pulse width accordingly.
The second function that the software needs to perform is to make the two
wheels actually revolve at the same speed so that the robot will move in a
straight line. Note that, innate differences between the two motors can cause
the robot to move in an arc, even when the same voltage was applied to both
motors. The solution is to read the shaft encoders from each wheel and increase
or decrease the speed of the right motor, say, to match its speed with that of
the left motor.
6.7.1
Pulse-Width Modulation
The software we have configured for controlling the Handy Bugs motors takes
advantage of time-counter hardware associated with the MC68HC11A0s port
A and succeeds in implementing a pulse-width modulation scheme without recourse to either polling or interrupts. Port As eight pins have various output
compare and input capture registers, as shown in Figure 6.28. Refer to the
Motorola data books on the MC68HC11 for a more complete discussion than
we will attempt here.
An output compare register can be set by the programmer so that, for instance, when the time-counters value matches the output compare registers
value, a pin can be set high or an interrupt can be initiated. An input capture
register has the opposite function. When a signal on a pin goes low for instance,
the input capture register can store the value of the timer-counter register at
the time that the event happened or initiate an interrupt.
6.7.2
191
B15
B0
Hossein M. Oloomi
192
Bit 7
TOI
RTII
PA0VI
PAII
Bit 0
PR0
PR1
For our purposes, we will let the timer-counter run at its default setting and
not bother with changing any values in TMSK2. This means that after 216
counts at 0.5(sec) per count, 32.77(msec) will have passed. We will use this
standard overflow time as the period for pulse-width modulation, tperiod .
Our plan is to create the pulse-width modulated signals for the left and right
motors using waveforms generated by OC2 and OC3 associated with pins PA6
and PA5, as shown in Figure 6.29. In this case, we will use OC1 to set the bits
high on both PA6 and PA5 when the timer-counter is at 0. We will use the
OC2 and OC3 registers to clear the bits on both PA6 and PA5 when the value
reached by the timer-counter matches the values stored in their 16-bit timer
output compare registers, TOC2 and TOC3. So, for instance, if we want PA5
to have a 25% duty cycle, then we store 65, 536 4 = 16, 348 in TOC3. If we
want PA6 to have a 50% duty cycle, we store 65, 536 2 = 32, 768 in TOC2:
TOC2
$1018
B15
1
TOC3
$101A
B0
0
B15
0
0
B0
To specify what action should be taken on PA5 and PA6 when the corresponding output compare registers match the timer-counter, we must set some
values in another register, TCTL1. The appropriate bit sequences are shown in
Table 6.2. For the way we designed our algorithm in Figure 6.29, we want PA5
and PA6 to be set to 0 when OC3 and OC2 have successful output comparisons.
To set this up, we store the two bits, %10 (which will make the pin go low), in
TCTL1 in the locations associated with OC3 and OC2:
TCTL1
$1020
Bit 7
OM2
1
OL2
0
OM3
1
OL3
0
OM4
x
OL4
x
OM5
x
Bit 0
OL5
x
The xs in any bit position represent dont cares. With the falling edge of
the pulse configured (the signal transitioning from high to low), now we just
need to set up the OC1 rising-edge event (the transition of the signal from low
to high). This is done by storing the value of time equal to 0 in TOC1, the
16-bit timer output compare 1 register:
TOC1
$1016
B15
0
Hossein M. Oloomi
B0
0
193
Table 6.2: The four actions possible by any output compare pin are to not
change, to toggle, to go low, or to go high. Two bits in the TCTL1 register, the
most significant bit (OMx) and the least significant bit (OLx), set the desired
response for any successful output compare.
OMx
0
0
1
1
OLx
0
1
0
1
Configuration
OCx Does Not Affect Pin
Toggle OCx Pin
Clear OCx Pin
Set OCx Pin
To configure the hardware so that OC1 will control PA5 and PA6, we set
values in some auxiliary registers that control OC1. The output compare 1 mask
(OC1M) register signifies which of the other four output compare registers OC1
will control. The high five bits in OC1M correspond bit for bit with a port A
output pin. Therefore, we store the binary number %01100000 in OC1M to set
up OC1 to control PA5 and PA6:
OC1M
$100C
Bit 7
OC1M7
x
OC1M6
x
OC1M5
1
OC1M4
x
OC1M3
x
Bit 0
Once we have selected which pins will be active, we can program the action
that we want to result when the timer-counter value matches the value of 0 in
TOC1 by setting some values in the output compare 1 data (OC1D) register.
By setting the bits corresponding to PA5 and PA6 to 1, whenever the timercounter overflows and returns to the value 0, the PA5 and PA 6 pins will be set
to 1, which forms the rising edge of each pulse.
OC1D
$100D
Bit 7
OC1D7
x
OC1D6
1
OC1D5
1
OC1D4
x
OC1D3
x
Bit 0
6.7.3
The program below illustrates the IC code that implements this scenario of a
25% duty cycle signal asserted by pin PA5 and a 50% duty cycle signal asserted
by pin PA6. This sequence will make one wheel rotate at half the speed of the
other, causing Rug Warrior to move in an arc towards one side or the other.
Purdue University Fort Wayne
Hossein M. Oloomi
194
DDRD = 0x1009;
OC1M = 0x100C;
OC1D = 0x100D;
TOC1 = 0x1016;
TOC2 = 0x1018;
TOC3 = 0x101A;
TCTL1 = 0x1020;
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
/*
195
Hossein M. Oloomi
196
6.8
Problems
6.8 Problems
197
Hossein M. Oloomi
198
6.8 Problems
199
Hossein M. Oloomi
200
Hossein M. Oloomi