Sei sulla pagina 1di 44

CHAPTER

ELECTRONIC DEVICES AND


INTERFACING

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

ELECTRONIC DEVICES AND INTERFACING

Figure 6.1: Diode symbols.


current in this direction. Typically, currents of several hundred amperes can
flow in the forward direction with a voltage drop of about 1(V). Diode size is
based on its power rating. On the other hand, resistance to current flow in the
reverse direction is very high. Generally, current flow in this direction will be
a few milliamperes when the reverse breakdown voltage is as high as 1000(V).
Thus, the diode acts as a one-way switch permitting current to flow in one
direction and not the other.
Diodes, called zener diodes, can be made with low reverse breakdown voltages.
Once the reverse breakdown voltage is reached, the zener has very little increase
in voltage with large reverse currents. The rather constant voltage makes the
diodes useful for precise voltage regulation.
A physical analysis of the diodes (neglecting the zener region) shows that
the current and voltage are related by
iD

I0 (eqvD /mkT 1),

where
iD
vD
I0
q
k
T
m

current through diode, A


voltage across diode, V
reverse saturation current, A
electron charge = 1.6 1019, C
Boltzmanns constant = 1.38 1023, J/ K
absolute temperature, K
empherical constant between 1 and 2 (we assume m = 1).

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

Purdue University Fort Wayne

6.2 Bipolar Transistors

159

Figure 6.2: Diode characteristics: (a) actual characteristic, (b) straight-line


(piecewise-linear) characteristics.

Figure 6.3: Piecewise-linear equivalents: (a) vi characteristic, and (b) circuit.


iD

I0 eqvD /kT = I0 evD /VT .

In many applications, the actual diode characteristic can be approximated


by a piecewise-linear characteristic, as shown in Figure 6.2(a). When this is the
case, the diode can be replaced by an equivalent circuit consisting of a battery
VF in series with an ideal diode, as shown in Figure 6.3(b). For most of our
applications, we shall assume that VF = 0.7(V ).

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

ELECTRONIC DEVICES AND INTERFACING

Figure 6.4: Transistor types and connections: (a) npn transistor, and (b) pnp
transistor.

Hossein M. Oloomi

Purdue University Fort Wayne

6.2 Bipolar Transistors

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 .

The transistor parameter , called the DC current gain, is defined as

:=

IC
,
IB

with VCE constant.

In most company literature, data sheets on transistors refer to the DC current


gain symbol as hF E . Gain usually is within the range 20 to 300 but is not
constant for a given transistor because the device is nonlinear.
Transistor characteristics are shown in Figure 6.5(b) and (c). Three states
are possible with a transistor: cutoff, active, and saturation.
Cutoff The base characteristics illustrate the base current IB versus the baseto-emitter voltage VBE . We see that a base voltage below 0.6(V) will
not permit any current to flow through the transistor, including the base
current and the load or collector current. The circuit is open and the
transistor is said to be cutoff. When voltage VBE is greater than 0.6(V),
the transistor conducts, but the base current has little effect on the baseto-emitter voltage. The behavior is similar to a diode, with VBE never
exceeding 0.8(V).
Active When the transistor is conducting, it is said to be active and acts as a
current gain device:
IC

IB .

VBE is generally taken to be 0.7(V) when the circuit is conducting. In


the controlled loop a supply voltage VCC is divided between a calculated
voltage drop across the load
VL

= RL IC ,

and the remaining drop across the transistor


Purdue University Fort Wayne

Hossein M. Oloomi

162

ELECTRONIC DEVICES AND INTERFACING

Figure 6.5: The npn common emitter transistor and characteristics: (a) basic
circuit, (b) base characteristics, and (c) collector characteristics.

Hossein M. Oloomi

Purdue University Fort Wayne

6.2 Bipolar Transistors

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)

On the load line at IB = 30(A), VCE 16(V ). Furthermore, IC


11(mA). Usually, characteristic curves are not readily available in graphical form and the key device specifications must be read from manufacturers tables. Using a current gain of 250 yields
IC IB = 7.5(mA),
compared to 11(mA) previousley, and
VCE = VCC RLIC = 30(V ) 1.2(k) 7.5(mA) = 21(V ),
compared to 16(V).
3.
IB =

5 0.7
= 430(A).
10(k)

Purdue University Fort Wayne

Hossein M. Oloomi

164

ELECTRONIC DEVICES AND INTERFACING


Since IB > IBS , the transistor is saturated. Then ICS = 24(mA). Alternatively to the graph, we have
IC

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

Field-Effect Transistors (FETs)

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

Purdue University Fort Wayne

6.3 Field-Effect Transistors (FETs)

165

Figure 6.6: Types of FET transistors and their symbols: (a) JFET, and (b)
MOSFET.

Purdue University Fort Wayne

Hossein M. Oloomi

166

ELECTRONIC DEVICES AND INTERFACING

Figure 6.7: Drain characteristic for an n-channel enhancement-type MOSFET


transistor.
The performance of a MOSFET is shown in Figure 6.7. In a confusion of
terms the transistor amplifies in the saturation region where the drain current is
nearly proportional to the gate voltage and relatively independent of the drain
voltage. With the drain voltage below 5(V) the device acts as a resistor, where
the resistance is proportional to the gate voltage.
The major difference between the bipolar and MOSFET transistor is the
infinite input impedance of the MOSFET; thus, it draws no current. This makes
it ideal for amplification of small signals in high impedance circuits. MOSFET is
also insensitive to temperature and cheaper to manufacture. Its higher packing
densities make it ideal for integrated circuits. A disadvantage is that the oxide
insulation is susceptible to breakdown from static electricity. Bipolar transistors
are used as an interfacing device since they can carry a much larger load current
than the MOSFET. This is because the bipolar device conducts throughout its
cross-sectional area while the MOSFET conducts across a narrow channel.

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

Purdue University Fort Wayne

6.4 Power Electronics

167

Table 6.1: Limits of present day power semiconductors.

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

Figure 6.8: Power semiconductor packages. (Courtesy of Motorrola Inc.)

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

ELECTRONIC DEVICES AND INTERFACING

Figure 6.9: Voltage-current for a switched-ON semiconductor.


vices rather than on their linear operation. There are several reasons: (1) the
impact of microprocessors on control strategy, (2) fast-switching speeds, and
(3) reduced semiconductor power dissipation, which allows larger loads to be
controlled.
The ideal switch has infinite impedance in the OFF-state and no voltage
drop (no power dissipation) in the ON-state. Semiconductors are not ideal,
but they are reasonably close. Figure 6.9 illustrates the voltage-current of a
switched device. In the OFF-state leakage current is on the order of microamps.
In the ON-state the voltage drop across the device is on the order of 1(V) to
3(V). Switching times are on the order of microseconds. Power consumption is
greatest as the device switches through the linear range.
The measure of acceptability of any power conversion is efficiency. This is
a comparison of the load power against the combined load power and wasted
power of the control unit. The most efficient mode is the fully ON (saturated
mode) with efficiencies over 70%. In some cases it is more appropriate to operate
in the linear range, i.e., audio amplifiers and low-power (analog) DC motors,
where designs can be simplified if control is exercised with power ICs such as
power op amps.

6.4.1

Bipolar Power Transistors

Parameters controlling the performance of bipolar transistors are essentially the


same regardless of chip size and power handling capacity. The basic theory of
operation was discussed in the previous section. Let us review with Figure 6.10.
Bipolar transistors can be placed into three states: (1) cutoff, (2) active or
linear, and (3) saturation. To turn the transistor ON, input voltage Vi must be
increased above VBE , the base to emitter voltage drop, 0.4(V). Input voltages
are generally 2(V) to 5(V). In the active (linear) state the collector current is
IC
Hossein M. Oloomi

hF E IB ,
Purdue University Fort Wayne

6.4 Power Electronics

169

Figure 6.10: Basic circuit for bipolar transistor.


where hF E is the characteristic current gain of the transistor and IB is the
base current. Collector current increases with IB until the device enters the
saturation region at (VCE )SAT .
The collector current in saturation will be nearly constant and given by
ICS

VCC (VCE )SAT


.
RC

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

ODF covers up a considerable degree of uncertainty in the value of hF E . A high


value of overdrive factor will not affect the collector-emitter voltage significantly.
However, the increased base current will increase transistor base power loss.
Performance Parameters It is not possible to achieve in a few devices an allencompassing performance representing low-cost, high-current gain, low
ON resistance, high-operating voltage, and high-speed operation. This
explains the sometimes bewildering selection on the market. Although
a transistor can be found to optimize a given design with regard to a
set of particular parameters, many transistors will perform satisfactorily.
Figure 6.11 gives the performance parameters for TIP73 power transistor
as they are found in the Texas Instruments Power Products Data Book.
Some data books, including Texas Instruments (TI), will give additional
information in the form of characteristic curves. See Figure 6.12.
Maximum Ratings. Transistor circuits must be designed so that operating conditions do not exceed their suggested maximum ratings.
Purdue University Fort Wayne

Hossein M. Oloomi

170

ELECTRONIC DEVICES AND INTERFACING

Figure 6.11: Bipolar power transistor performance characteristics. (Courtesy of


Texas Instruments.)

Hossein M. Oloomi

Purdue University Fort Wayne

6.4 Power Electronics

171

Figure 6.12: Typical characteristics of a TIP73 npn-bipolar power transistor:


(a) safe operating area, (b) current-gain, (c) collector-emitter voltage, and (d)
base-emitter voltage. (Courtesy of Texas Instruments.)

Purdue University Fort Wayne

Hossein M. Oloomi

172

ELECTRONIC DEVICES AND INTERFACING


These limits include current (base and collector), voltage (terminal
to terminal), and power dissipation. Of particular interest are the
collector conditions. Together they form a safe operating area.
Safe Opertaing Area (SOA). All transistors and power ICs have safe
operating areas similar to Figure 6.12(a) for TIP73. The current
limit, 15(A), arises because of limitations in the chip or bonding
wires. Wires may melt if forced to carry more than the rated collector current. All points on the power limit portion have constant
power dissipation, 80(W). Thermal resistance, junction temperature
TJ , and the attachment package limit the dissipation. Finally, the
voltage limit is the maximum-rated collector-to-emitter voltage. This
voltage can be sustained from cutoff to about 2(A) of collector current in the active state. The reader should observe that a saturated
transistor operates in the extreme left region of an SOA curve.
Current Gain (hF E ). Figure 6.12(b) shows that current gain varies
considerably with temperature and collector current. hF E decreases
from 70 to 10 over the collector current range and increases to a
lesser extent over the temperature range. It is also a parameter over
which the manufacturer has little control. Devices in the same batch,
even after they are selected, can vary by at least 2:1 in gain. Manufacturer curves represent the worse case, and higher-current gains
will be found in a random purchase. When designing a circuit, the
engineer assumes the worst condition and the poorest device. The
actual current gains are much smaller for power transistors than for
general-purpose transistors. Gains can be improved by testing and
making a selection from within a group of similar devices.
Collector-to-Emitter Saturation Voltage (VCE )SAT . Low values
of (VCE )SAT will reduce the ON-state transistor losses. For generalpurpose transistors the collector-emitter voltage at saturation is approximately 0.3(V). However, power transistors have values which
can range to several volts. As Figure 6.12(c) shows, (VCE )SAT increases with collector current to 2(V) for hF E = 10. The reason is
that load voltages are usually higher for power transistors. Thus, the
collector breakdown voltage (VCE )BRO must be made correspondingly higher than general-purpose transistors. This cannot be accomplished without increasing the ON-state resistance.
Base-to-Base Emitter Saturation Voltage (V BE)SAT . The baseto-emitter saturation voltage also depends upon the collector current. With general-purpose transistors (V BE)SAT is approximately
0.7(V). However, values for power transistors can be much higher as
shown in Figure 6.12(d). Since current gains tend to be low for power
transistors, base power loss IB (VBE )SAT cannot be ignored. The
loss is compounded with high overdrive factors.
Switching Times Because of internal capacitive effects, transistors do not switch

Hossein M. Oloomi

Purdue University Fort Wayne

6.4 Power Electronics

173

Figure 6.13: Bipolar power transistor switching time.


in zero time. Figure 6.13 illustrates the switch ON and switch OFF times.
A finite delay time td elapses before the base is charged to (V BE)SAT .
After charging the collector current begins an exponential rise time tr to
0.9ICS . A more popular measure is the turn-ON time tON as indicated in
the figure. When the transistor is switched OFF, there is a delay, called
the storage time ts , to remove the saturation charge from the base. Storage
time is increased by ODF and constitutes the limiting factor in switching
speed. Once the charge is removed the current decays exponentially in
time tf , the fall time.
Example 6.2 A TIP73 power transistor switches a 2() load from a 20(V)
source. The transistor operating temperature should not exceed 25( C).
To determine the base resistor, we proceed as follows. If ICS 20(V )/2()
or 10(A), then (VCE )SAT at 10(A) is 1.0(V). This gives
ICS =

VCC (VCE )SAT


20 1.0
=
= 9.5(A).
RC
2

From Figure 6.11, hF E (min) = 15, which gives


IBS =

ICS
9.5
=
= 0.63(A).
hF E
15

Using an overdrive factor of 2, IB = 1.2(A). This high value is rather


typical for bipolar power transistors. Driving RB with the source, we
obtain
RB =

VCC VBE
20 1.0
=
= 15().
IB
1.2

Purdue University Fort Wayne

Hossein M. Oloomi

174

ELECTRONIC DEVICES AND INTERFACING

Figure 6.14: ON-OFF control of a DC motor with bipolar power transistor


drive.
Switching Inductance All loads show some degree of inductance and resistance. Solenoids, stepping motors, and DC motors are highly inductive.
When the transistor switches OFF, voltage buildup
VCE

= L

dI
LIC
=
dt
tf

is sufficient to exceed the breakdown voltage. (VCE )BR should never be


exceeded. To avoid transistor burn out, a diode is placed in parallel with
the load. Better yet, a zener diode is placed in series with the regular
diode to protect (VCE )BR . The inductor energy is allowed to dissipate by
looking the current back through the load resistance while clamping the
voltage at (VCE )BR .
Example 6.3 A permanent magnet DC motor is connected in a T bridge for
simple ON-OFF control. See Figure 6.14. Motor current requirements are 2(A)
in the continuous mode and 10(A) in a start/stall mode, both at motor voltage
Vm = 10(V ). The driver selected is the TIP73 bipolar power transistor rated
at 15(A) continuous collector current. Its case temperature is maintained at
25( C) with a heat sink. Supply voltage is 12(V). Let us evaluate the design.
Continuous mode
IC = 2(A)
(VCE )SAT = 0.17(V )
hF E = 35
2
IB = 35
(A)
4
= 35 (with overdrive)
Vm = (12 0.17) = 11.8(V )
Hossein M. Oloomi

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%

Purdue University Fort Wayne

6.4 Power Electronics

175

Figure 6.15: Darlington circuit.


Start/stall mode
IC = 10(A)
(VCE )SAT = 0.8(V )
hF E = 17
IB = 10
17 (A)
= 20
17 (with overdrive)
Vm = (12 0.8) = 11.2(V )

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

ELECTRONIC DEVICES AND INTERFACING

Figure 6.16: Darlington power transistor performance characteristics. (Courtesy


of Texas Instruments.)
Performance Parameters Specifications for the TIP663 npn Darlington transistor are listed in Figure 6.16. Typical characteristic curves are also shown
in Figure 6.17. Although the transistors are bipolar, there are major differences from the single unit.
Current Gain (hF E ). Careful matching of the transistor pair in Darlingtons produces some rather startling current gains with hF E up
to 10,000 possible. Darlingtons often can be driven directly from the
PIA or other TTL logic gates. We can see in Figure 6.17(b) that
hF E varies significantly with collector current and case temperature.
Optimum hF E is approximately equal to 2000 (at 25(C) case temperature) and occurs at a collector current nearly one-half the rated
20(A). To employ Darlingtons at their rated collector current is a
Hossein M. Oloomi

Purdue University Fort Wayne

6.4 Power Electronics

177

Figure 6.17: Typical characteristics of a TIP663 Darlington power transistor:


(a) safe operating area, (b) current gain, (c) collector-emitter voltage, and (d)
base-emitter voltage. (Courtesy of Texas Instruments.)

Purdue University Fort Wayne

Hossein M. Oloomi

178

ELECTRONIC DEVICES AND INTERFACING

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

Purdue University Fort Wayne

6.4 Power Electronics

179

Figure 6.19: ON-OFF control of a DC motor with Darlington power transistor


drive.
compare the two designs at 25( C) case temperature.
Continuous mode
IC = 2(A)
(VCE )SAT = 0.8(V )
hF E = 1500
2
IB = 35
(A)
= 4(mA)(with overdrive)
Vm = (12 0.8) = 11.2(V )

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 )

(PD )base = 12(0.01) = 0.1(W )


(PD )collector = (1.2)(10) = 12(W )
(PD )total = (12)(10) = 120(W )
Efficiency =

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

ELECTRONIC DEVICES AND INTERFACING

6.5

Electronics and Sensors Interfacing

We now focus on interfacing electronics and sensors to a microprocessor. We


will also explain how software drivers can be written for these sensors once the
hardware interfacing is accomplished. Software drivers are pieces of codes that
provide a well-defined interface between a hardware device and a program that
needs to use the interface. Both assembly language and C language will be used
to this end. It should be noted that, in these codes, the symbol - is used as
a normal character rather than the subtraction operator.

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

Purdue University Fort Wayne

6.5 Electronics and Sensors Interfacing

181

Figure 6.20: Two approaches to force detection in microswitches. In (a), each


switch goes to a separate pin of port E. A digital read of port E reveals the
state of the bumper. Circuit (b) channels all bump switches to one pin of port
E. Here, an analog-to-digital converter must be used to determine which set of
switches is closed.

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

ELECTRONIC DEVICES AND INTERFACING

Figure 6.22: A common phototransistor circuit.


toresistor. Figure 6.22 illustrates a simple configuration using a phototransistor.
Photodiodes possess great sensitivity, produce a linear signal over a very
wide range of light levels, and respond rapidly to changes in illumination. This
makes them useful in communication systems for detecting modulated light;
the remote control receiver in almost every TV, stereo, and compact disk (CD)
player on the market makes use of a photodiode. The output of a photodiode
does, however, require amplification before it can be used by a microprocessor.
Because the photoresistor is so useful and easy to incorporate, we will further
analyze a practical circuit for connecting one to a microprocessor. Consider the
circuit for the left photoresistor in Figure 6.21. Here, two resistances form what
is called a voltage divider. The total resistance in the circuit, RT, is the sum
of the individual resistances: RT = R + RL. According to Ohms law, the
current, I, through the circuit is I = V /RT . In order for the A/D converter in
the microcontroller to measure a voltage, some current must flow into pin PE1.
However, because the MC68HC11 has high-impedance inputs, the amount of
current required is negligible compared to the currents in the rest of the circuit.
In this case, the connection to PE1 can be ignored while analyzing the voltage
divider. Thus, the voltage present on PE1 is
VP E1

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

Purdue University Fort Wayne

6.5 Electronics and Sensors Interfacing

183

We now write a software driver for photoresistors. Here we take a moment


to explain in some detail how to configure the analog-to-digital converter and
program a software driver for photoresistors. These tasks encompass both the
capabilities of the hardware and the responsibilities of the programmer.
As was mentioned in Chapter 2, port E of the MC68HC11 can be configured
as either an 8-bit input port or an 8-channel analog-to-digital converter. Internally, there is only one A/D circuit for the entire port and only four registers
to store results from the eight channels. Thus, to achieve the full potential of
the A/D port, a certain software protocol must be enforced.
First, the voltage reference pins on the MC68HC11 (VRH and VRL) must
be set to calibrate the hardware. If these pins are set to +5 V and GND,
respectively, then A/D result values of 255 and 0 will correspond to those limits, respectively. Voltages between the limits are proportionately scaled. Two
control registers, ADCTL and OPTION, are used to configure the mode of conversion. Reference should be made to the MC68HC11 Programmers Manual to
see which bits in these registers should be set to turn on the A/D and to select
its various modes. Conversion sequences can be chosen that repeat on a single
channel four times or on four channels, once each. In this latter mode, the eight
pins of port E can be converted in two banks of four: PE0PE3 and PE4PE7.
The high bit of the ADCTL mode should be polled periodically because it denotes the conversion complete flag (CCF). Conversions are complete 34-clock
cycles after the ADCTL register is written. After each conversion, results are
posted in the internal result register: ADR1, ADR2, ADR3, and ADR4. The
converter can also be set up in either mode to convert continuously or just once.
Bits 4 and 5 of register ADCTL are MULT and SCAN, respectively. When
SCAN = 0, four conversions are performed, once each, to fill the four result
registers. When SCAN = 1, conversions continue in a round-robin fashion.
When MULT = 0, four conversions are repeated on a single channel of port
E. The selected channel is set by the lower four bits of ADCTL: CD, CC, CB,
and CA. When MULT = 1, one bank of four channels is converted. The bank
is specified by bits 2 and 3 of ADCTL. If bits 2 and 3 are set to 0, channels
PE0-PE3 are converted. If bits 2 and 3 are set to 1, channels PE4PE7 are
converted.
In the following example, written in both assembly language and C code, we
create a very simple software driver for acquiring a reading from the photocells.
The assembly code version might be written:
ph-right
ph-left
option
adctl
adr1
adr2

equ
equ
equ
equ
equ
equ

$10
$11
$1039
$1030
$1031
$1032

;Create variable for right photocell


;Create variable for left photocell
;Address of OPTION register
;Address of ADCTL register
;Result register for A/D channel 1
;Result register for A/D channel 2

update-photo
bset option #%10000000
Purdue University Fort Wayne

;Enable A/D system


Hossein M. Oloomi

184

ELECTRONIC DEVICES AND INTERFACING


bset adctl

#%00010000

;Begin A/D conversion

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

The C version of the photocell code is somewhat simpler:


int ph_right = 0;
int ph_left = 0;

/* Variable for right photocell data */


/* Variable for left photocell data */

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

Before describing the details of interfacing DC motors to a microcontroller,


it is instructive to discuss briefly the general scheme in which DC motors are
used in robotics applications. This can best be explained using Figure 6.23. The
dynamic model for motor/load can be arranged into an open-loop block diagram
with voltage and frictional (or gravitational) load torque as inputs and speed as
the output. The loop includes a voltage amplifier with gain KA. Part of the
control voltage VR goes to accelerating the inertia load. The steady-state speed
is proportional to the control voltage and if Tf is small, = (KA /KE )VR . Thus,
open-loop control of PM motors is speed control, although position control can
Hossein M. Oloomi

Purdue University Fort Wayne

6.6 Interfacing DC Motors

185

Figure 6.23: Open-loop speed control for DC moror.

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

ELECTRONIC DEVICES AND INTERFACING

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

Motor-Driver-Power Integrated Circuits

Motor-driver-power integrated circuits (ICs) make it very convenient to interface


motors to microprocessors. Typically motor-driver-power ICs also have circuitry
that provides current-limiting and over-voltage protection. One single-chip solution is the MPC1710A motor driver from Motorola. This chip, whose block
diagram is shown in Figure 6.27, uses an H-bridge composed of four n-channel
Hossein M. Oloomi

Purdue University Fort Wayne

6.6 Interfacing DC Motors

187

Figure 6.26: One motor-driver power IC is an SGS Thompson L293D. This


power IC incorporates a motor driver using an H-bridge made from bipolar
transistors. While this illustration only shows one H-bridge, two full H-bridges
are actually incorporated in an L293D.

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

ELECTRONIC DEVICES AND INTERFACING

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

Purdue University Fort Wayne

6.6 Interfacing DC Motors

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

ELECTRONIC DEVICES AND INTERFACING


Another avenue to pursue is to purchase motor controllers for radio-controlled
cars. These are often called speed controllers, which is a bit of a misnomer, since
it is only the human who provides the speed control. However speed controllers
do incorporate the power MOSFETs or power bipolar transistors in discrete Hbridges for driving larger motors. They are sold by Futaba, Tower Hobbies, and
Sheldons Hobbies, and are often advertised in radio-control hobbyist magazines.

6.7

Software for Driving Motors

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

Output Compare Registers

For pulse-width modulation, we will take advantage of the output compare


registers associated with port A pins PA3-PA7, as shown in Figure 6.28. Pin
Hossein M. Oloomi

Purdue University Fort Wayne

6.7 Software for Driving Motors

191

Figure 6.29: Pulse-width modulation can be conventionally accomplished using


the MC68HC11A0s port A output compare registers. Here, we use three different output compare registers, where output compare register OC1 directs pins
PA5 and PA6 to both go high at the beginning of each period. Output compare
registers OC3 and OC2 each tell pins PA5 and PA6 when to go low, giving a
programmable duty cycle for each motor.
PA7 happens to hold a dual role as either a pulse accumulator or as output
compare register 1 (OC1). For Rug Warriors right wheel, we have chosen to
use PA5, which is associated with output compare register 3 (OC3) and for the
left wheel, PA6, which is associated with output compare register 2 (OC2). We
also take advantage of OC1 because it is a special output compare register in
that it can control a given selection of the four other output compare registers.
The closed connections between OC1 and OC2 and between OC1 and OC3
is Figure 6.28 illustrate how we intend to use the timer-counter capabilities to
drive the Handy Boards motors. Figure6.29 illustrates the timing sequences for
our algorithm that will be generated on PA5 and PA6 to implement pulse-width
modulation.
The timer-counter itself is a 16-bit register, TCNT, where the high byte is
at hex address $100E and the low byte is at $100F:
TCNT
$100E

B15

B0

The timer-counter runs at a rate dependent upon Rug Warriors crystal


oscillator (and therefore the MC68HC11A0s E clock, which is on pin 5 of the
MC68HC11A0 and can be checked with an oscilloscope). The E clock has a
period of one-fourth that of the crystal oscillator frequency. TCNT is a freerunning counter that starts at 0 when the MC68HC11A0 is reset and counts up
to 216, which is 65,536 counts. The counter then overflows and starts again from
0. We use an 8(MHz) crystal for Rug Warrior, giving the E clock a frequency
of 2(MHz) and a period of 0.5(sec). By default, the timer-counter counts at
the same period as the E clock, but there is a way to prescale the timer-counter
rate, which involves setting two bits in another register, TMSK2. The lowest
Purdue University Fort Wayne

Hossein M. Oloomi

192

ELECTRONIC DEVICES AND INTERFACING


two bits in the TMSK2 register, PR1 and PR0, are used to divide down the E
clock for changing the rate at which the timer-counter runs.
TMSK2
$1024

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

Purdue University Fort Wayne

6.7 Software for Driving Motors

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

By using these built-in hardware features of the 6811, no interrupts or polling


sequences are required to implement pulse-width modulation. We simply write
to some registers in the timer-counter system and all actions on pins PA5 and
PA6 take place in the background of other programs being run on the robot.
The programmer merely writes new values to TOC2 and TOC3 when the speed
has to be changed.

6.7.3

PWM Software Driver

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

ELECTRONIC DEVICES AND INTERFACING


int
int
int
int
int
int
int

DDRD = 0x1009;
OC1M = 0x100C;
OC1D = 0x100D;
TOC1 = 0x1016;
TOC2 = 0x1018;
TOC3 = 0x101A;
TCTL1 = 0x1020;

/*
/*
/*
/*
/*
/*
/*

Port D data direction */


Output Compare 1 Mask */
Output Compare 1 Data */
Output Compare Timer 1, 16-bit reg */
Out Cmp Tmr 2, 16-bit reg (left motor) */
Out Cmp Tmr 3, 16-bit reg (right motor) */
Timer Control 1, 8-bit reg */

/* motor_index: 0 => Left motor, 1 => Right motor */


int TOCx[2] = {TOC2, TOC3}; /* Index for timer register */
int sign[2] = {1,1};
/* Sign of rotation of motor */
int dir_mask[2] = {0b010000, 0b100000}; /* Port D direction bit */
/* Utility functions */
float abs(arg)
/* Absolute value function */
{ if (arg < 0.0)
return (- arg); else return arg; }
int get_sign(float val)
/* Find sign of argument */
{ if (val > 0.0)
return 1; else return -1; }
/* Limit range of val */
float limit_range(float val, float low, float high)
{ if (val < low) return low;
else if (val > high return high;
else return val; }
void init_pwm()
{ poke(DDRD,0b110010);
poke(OC1M,0b01100000);
poke(OC1D,0b01100000);
bit_set(TCTL1,0b10100000);
pokeword(TOC1,0);
pokeword(TOC2,1);
pokeword(TOC3,1); }

/*
/*
/*
/*
/*
/*
/*
/*

Initialize Pulse-Width Modulation */


D dir: OUT 5,4,1; IN 3,2,0 */
Out Cmp 1 affects PA5 and PA6 */
Successful OC1 turns on PA5, PA6 */
OC3 turns off PA5, OC2: PA6 */
When TCNT = 0, OC1 fires */
Minimum on time for OC2 */
Minimum on time for OC3 */

/* The sign is handled in a special way because */


/* we have only a 1 channel encoder */
void pwm_motor(float vel, int motor_index)
{ if (sign[motor_index] > 0) /* Choose the direction of rotation */
bit_set(port_d, dir_mask[motor_index]);
else
bit_clear(port_d, dir_mask[motor_index]);
vel = limit_range(vel, 1.0, 99.0); /* 1 <= duty fctr <= 99 */
pokeword(TOCx[motor_index], (int) (655.36 * vel)); }
Hossein M. Oloomi

Purdue University Fort Wayne

6.7 Software for Driving Motors

195

/* Top-level open-loop PWM command */


void move(float l_vel,float r_vel)/* Vel range [-100.0, 100.0] */
{ sign[0] = get_sign(1_vel); /* Desired direction of rotation */
sign[1] = get_sign(r_val);
pwm_motor(abs(l_vel), 0); /* Set pulse-width modulation cnst */
pwm_motor(abs(r_vel), 1); }
Now lets walk through this program. First, all the necessary registers are
assigned and three data structures are created. The arrays TOCx[ ], sign[ ], and
dir mask[ ] are all two-element arrays. TOCx[ ] is an array whose first element
is the address TOC2, where left-motor velocities are stored, and whose second
element is the address TOC3, where right-motor velocities are stored. The array
sign [ ] is an array whose elements are bits representing which direction the left
and right motors are commanded to go. The array dir mask[ ] is an array
whose first element holds the mask for Port D, required to select the left motor,
and whose second element holds the mask for Port D, required to select the
right motor.
The next three functions also just lay the ground work for the main part
of this program. The functions abs(), get sign() and limit range() are
functions that C does not happen to supply: abs() simply returns the absolute value of its argument; get sign() returns the sign of its argument; and
limit range() returns a maximum or minimum value for its argument if it is
out of range.
The actual pulse-width modulation of the motors is accomplished by the
functions init pwm(), pwm motor(), and move(). The timer-counter hardware
is set up and started by init pwm(). The three pokeword() commands set an
initial (small) pulse width.
To change the duty cycle, the calling routine uses the pwm motor() function, which takes two arguments: a velocity command and a motor index.
pwm motor() then pokes the new velocity into the address, either TOC2 or
TOC3, as specified by motor index.
The function move() is the interface the programmer has for directing the
robot. move() takes two arguments, a velocity for the left motor and a velocity
for the right motor. These velocities should be in the range [100.0, 100.0]. A
move(25.0,50.0) command would make the left motor move at 25% of full
speed and make the right motor move at 50% of full speed, causing the robot
to arc to the left.
Setting up the pulse-width modulation scheme for each motor then merely
means writing some values to a few registers. Once this has been done, the
hardware associated with the timer-counter system will run by itselfalways
setting pins PA5 and PA6 high when the timer-counter reaches zero, always
setting PA5 low when the timer-counter reaches 16348, and always setting PA6
low when the timer-counter reaches 32768. The central processing unit of the
MC68HC11A0 then is free to attend to other tasks, perhaps reading a sensor or
calculating a new speed at which the robot should run. To change the speed,
Purdue University Fort Wayne

Hossein M. Oloomi

196

ELECTRONIC DEVICES AND INTERFACING

Figure 6.30: Diode ciruit for Problem 6.3.

Figure 6.31: Diode ciruit for Problem 6.4.


Rug Warriors main program merely has to store new values in TOC2 and
TOC3.

6.8

Problems

6.1 By measurement, a diode is found to draw 1(mA) of current when the


voltage drop across the diode is 0.75(V).
(a) Use the vol-ampere characteristic of the diode to find I0 .
(b) Plot the volt-ampere characteristic of the diode.
6.2 A diode is operating in a circuit where the diode current is iD and the
voltage across the diode is vD .
(a) If the current in the diode is doubled, calculate the increase in the
diode voltage vD . Assume VT = 25(mV ).
(b) If the diode voltage in Part (a), at the lower current, was 750(mV),
show that the doubling of the current increases the diode voltage by
only 2 percent.
6.3 In Figure 6.30, let v = 10 sin t, VB = 6(V ), and assume that the diode is
ideal. Under what circumstances will the current i flow? Sketch v and i as
functions of time using the same axes.
6.4 Expanding your reasoning and stating any simplifying assumptions, predict
current I in Figure 6.31 assuming ideal diodes.
6.5 In Figure 6.32, v1 = 10 sin t and the diode is assumed ideal.
Hossein M. Oloomi

Purdue University Fort Wayne

6.8 Problems

197

Figure 6.32: Diode ciruit for Problem 6.5.

Figure 6.33: Diode ciruit for Problem 6.6.


(a) Sketch v1 (t) and v2(t) on the same graph.
(b) Draw the transfer characteristic v2 versus v1 .
(c) What function is performed by this circuit?
6.6 For each of the circuits shown in Figure 6.33, let v1 = 10 sin t (V), R =
1(k), V = 4(V ), and assume that the diodes are ideal. Sketch v2 (t).
6.7 Let V1 = 5(V ), V2 = 0(V ), and Vcc = 6(V ) in the ciruits shown in Figure 6.34. Determine Vo .
6.8 In Figure 6.35, input voltages VA and VB are restricted to either 0 or +5(V).
Tabulate the four possible combinations of VA and VB and the corresponding
values of the output voltage Vo , assuming the diodes are ideal. Define in
words the output in terms of the inputs. Why is this called an OR circuit?
Where is it useful?

Figure 6.34: Diode ciruit for Problem 6.7.


Purdue University Fort Wayne

Hossein M. Oloomi

198

ELECTRONIC DEVICES AND INTERFACING

Figure 6.35: Diode ciruit for Problem 6.8.

Figure 6.36: Diode ciruit for Problem 6.9.


6.9 The switching circuit shown in Figure 6.36 contains two silicon diodes.
(a) For switch S closed, estimate IA and IB for VA = 1, 0.1, +1, and
+2(V ).
(b) For switch S open, estimate IA and IB for VA = +1(V ).
6.10 A diode and battery are used in the voltage regulator circuit of Figure 6.37
where RS = 1(k) and RL = 2(k). Assuming ideal diodes, if V1 increases
from 16 to 24(V) (a 50% increase), calculate the corresponding variation in
load voltage VL . Is the regulator doing a good job?
6.11 A transistor with = 100 and (VCE )SAT = 0.2(V ) is connected in the
circuit of Figure 6.38(a) with VCC = 5(V ) and RC = 1(k).
(a) Estimate the output voltage and current IC when the transistor switch
is closed (i.e., when the transistor is in the active region).
(b) Estimate the minimum base current to close the switch.

Figure 6.37: Voltage regulator circuit for Problem 6.10.


Hossein M. Oloomi

Purdue University Fort Wayne

6.8 Problems

199

Figure 6.38: A transistor used as a switch in Problem 6.11.


(c) If VBE = 0.8(V ), specify the value of RB if the switch is to close when
the input voltage exceeds 3(V ).
6.12 For the common emitter npn transistor in Figure 6.4, let = 49, VBE =
0.7(V ), and Vi = 1.0(V ). Find out the output voltage Vo from the collector
to the grounded base of the transistor.
6.13 The common emitter npn transistor in Figure 6.4, with 50 and ICE0
1(nA), is used in the switching circuit. Predict the output voltage for input
voltages of 0.2, 0.7, and 0.8(V).
6.14 The common emitter npn transistor in Figure 6.4, with = 99 and ICE0 =
10(nA), is supplied with a base current of IB = 20(A). Predict IC , IE ,
and VCE .
6.15 Compare the current ratio hF E found on the data sheet in Figure 6.11 with
the plot given in Figure 6.12. What is the difference in terms of a design
with the TIP73 power transistor?
6.16 In Figure 6.14 two bipolar transistors are used to drive the DC motor.
Assume that the TIP42 characteristics are nearly the same as the TIP73.
For the currents shown, find values for each base resistor.
6.17 In Example 6.4, a TIP663 Darlington power transistor drives a DC motor. The problem assumes the case is at 25( C). If the case is actually at
125( C), how does the solution change?
6.18 The speed of a DC motor is to be controlled similar to the diagram in
Figure 6.19. The small motor has a stall current of 2(A) and a continuous
current of 0.3(A). An oversized power transistor in the form of a TIP663
Darlington is used to drive the motor.
Purdue University Fort Wayne

Hossein M. Oloomi

200

ELECTRONIC DEVICES AND INTERFACING


(a) Evaluate the design.
(b) Are there any suggested changes for the diagram?

Hossein M. Oloomi

Purdue University Fort Wayne

Potrebbero piacerti anche