Transistor Interfacing Semicon Mrobot_ch6

44
CHAPTER 6 ELECTRONIC DEVICES AND INTERFACING The principal active devices in electrical circuits are the transistors. Two im- portant 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

description

transistors application

Transcript of Transistor Interfacing Semicon Mrobot_ch6

  • CHAPTER 6

    ELECTRONIC DEVICES ANDINTERFACING

    The principal active devices in electrical circuits are the transistors. Two im-portant 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 actsas a switch. It is this mode which is most useful in digital electronics. Bipolartransistors are used both in integrated circuits (TTL family) and as interfacingdevices in general circuits. FET is used primarily in integrated circuits (CMOSfamily) and power switching devices.

    6.1 Diodes

    Diodes and transistors are often made from silicon, and sometimes made fromgermanium. Each silicon (Si) atom has four outer electrons which join withneighboring atoms to form a complete bond (insulator). If one of the Si atomsis replaced (doped) by arsenic, which has five outer electrons, one unpairedelectron is present. The extra electron is easily freed by an electric field to formelectricity readily. The carrier is referred to as an n-type, n standing for negativecharge 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 andfill this vacancy; in the process it also conducts. This positive charged carrier isreferred to as a p-type.

    If a p slice and n slice are joined together, the device is called a diode. Thestructure and symbols are shown in Figure 6.1. At about 0.7(V) the diodeconducts 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 canflow in the forward direction with a voltage drop of about 1(V). Diode size isbased on its power rating. On the other hand, resistance to current flow in thereverse direction is very high. Generally, current flow in this direction will bea 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 onedirection 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 increasein voltage with large reverse currents. The rather constant voltage makes thediodes useful for precise voltage regulation.

    A physical analysis of the diodes (neglecting the zener region) shows thatthe current and voltage are related by

    iD = I0(eqvD/mkT 1),where

    iD current through diode, AvD voltage across diode, VI0 reverse saturation current, Aq electron charge = 1.6 1019, Ck Boltzmanns constant = 1.38 1023, J/KT absolute temperature, Km empherical constant between 1 and 2 (we assume m = 1).

    This equation is sketched in Figure 6.2(a) for germanium and silicon. Thecurves of Figure 6.2(a), when plotted to a suitable scale, appear to turn on atapproximately 0.2(V) for germanium and 0.7(V) for silicon.

    At room temperature, i.e., T = 300(K),

    VT :=kT

    q 25(mV ).

    The diode equation states that if vD is negative with magnitude much greaterthan kT/q, the current iD is the reverse saturation current I0. This reversecurrent, 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 I0eqvD/kT = I0evD/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 thecase, the diode can be replaced by an equivalent circuit consisting of a batteryVF in series with an ideal diode, as shown in Figure 6.3(b). For most of ourapplications, 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. Thebase (B), a very thin slice of one of them, is sandwiched by the complementarypair, thus the name bipolar. Other segments are called the collector (C) andthe emitter (E). Figure 6.4 shows the two variations in structure: npn-type andpnp-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 emit-ter, 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) pnptransistor.

    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 areturned ON by applying a voltage HIGH to the base (B) while the pnp transistorsare turned ON by applying a voltage LOW to the base.

    The npn transistor is the most popular type available today because it costsless to produce. The npn transistor is also faster than the pnp transistor. Itoperates in the same manner for any configuration. Power gain is highest for thecommon emitter. This is the reason that the connection is used most frequently.The common base connection has the lowest input resistance and the highestoutput resistance. The common collector connection shows the highest inputresistance and the lowest output resistance.

    A typical transistor circuit is shown in Figure 6.5(a). A small base currentIB 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

    :=ICIB

    , with VCE constant.

    In most company literature, data sheets on transistors refer to the DC currentgain symbol as hFE . Gain usually is within the range 20 to 300 but is notconstant for a given transistor because the device is nonlinear.

    Transistor characteristics are shown in Figure 6.5(b) and (c). Three statesare possible with a transistor: cutoff, active, and saturation.

    Cutoff The base characteristics illustrate the base current IB versus the base-to-emitter voltage VBE . We see that a base voltage below 0.6(V) willnot permit any current to flow through the transistor, including the basecurrent and the load or collector current. The circuit is open and thetransistor 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 base-to-emitter voltage. The behavior is similar to a diode, with VBE neverexceeding 0.8(V).

    Active When the transistor is conducting, it is said to be active and acts as acurrent gain device:

    IC = IB .

    VBE is generally taken to be 0.7(V) when the circuit is conducting. Inthe controlled loop a supply voltage VCC is divided between a calculatedvoltage drop across the load

    VL = RLIC ,

    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) basiccircuit, (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) toVCC , a resultant load line can be drawn across the collector characteristiccurves. The interest in this line is its intersection with the saturationline. 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 isestablished, the current gain can be found from the graph by introducinga small change in the base current.

    Saturation The base current may be increased to any desired value, but thecollector current IC is limited to the saturation value ICS = 24(mA). IfIB ICS/, the transistor is said to be saturated. Notice that VCE is notquite zero at saturation. Generally, the saturation voltage VSAT for VCEis about 0.2(V) for most transistors. The high slope of the saturation lineprecludes any variation in VSAT with the load RL. The base-to-emittervoltage VBE remains about 0.7(V) once the transistor is turned ON.

    Example 6.1 For the basic circuit and transistor characterisitics shown inFigure 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

    RB=

    1 0.710(k)

    = 30(A).

    On the load line at IB = 30(A), VCE 16(V ). Furthermore, IC 11(mA). Usually, characteristic curves are not readily available in graph-ical form and the key device specifications must be read from manufac-turers 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.710(k)

    = 430(A).

    Purdue University Fort Wayne Hossein M. Oloomi

  • 164 ELECTRONIC DEVICES AND INTERFACING

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

    IC =VCC VCE

    RL=

    30 0.21.2(k)

    25(mA),

    IBS =ICS

    =25(mA)250

    = 100(A).

    Since IB > IBS , the transistor is saturated and the preceeding ICS holds.Note that the current gain is nonlinear and a more representative gainnear 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 uponload current control by means of a voltage rather than a base current. It con-sists of a channel of n-type silicon through which the current passes from drainto source (see Figure 6.6(a)), much like the collector-emitter in bipolar transis-tors. The channel is surrounded by p-type silicon but the electrons flow onlythrough the n-type, making it unipolar. When a negative voltage is applied tothe gate (analogous to the base), the carrier electrons are repelled, forming adepleted area, and the channel resistance increases. The drain or load current isdecreased. Maximum drain current occurs for zero gate voltage. Positive gatevoltages destroy the operation of the device by permitting gate current. If thedoping is reversed, the operation of the JFET is reversed. Current must befrom source to drain. Increasing the positive gate voltage decreases the sourcecurrent.

    JFETs have been largely overtaken by metal oxide semiconductor FET orMOSFET, MOS for short. It includes an insulating layer of silicon dioxidebetween the channel and gate as shown in Figure 6.6(b). The field is stilleffective in modulating the electron flow in the channel; however, the gate makesno electrical contact with the channel. Since no current can flow through thegate, positive or negative gate voltages can be applied.

    There are four basic types of MOSFET structures. MOSFET can be eithern channel (p substrate) or p channel (n substrate). If the channel is actuallyprovided, it is said to be a depletion type since the applied gate voltage de-pletes original free carrier electrons in the channel. A zero gate voltage allowsan effective drain (or load) current. Positive voltages increase the drain cur-rent while negative voltages decrease it. The wide operating range makes thedepletion type useful for signal amplification. If a channel is not provided, thegate voltage induces an equal but opposite charge in the adjacent substrate.The free-moving charges behave as though a channel were present. This typeis referred to as an enhancement type. Positive gate voltages are used withthe 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 idealfor 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 MOSFETtransistor.

    The performance of a MOSFET is shown in Figure 6.7. In a confusion ofterms the transistor amplifies in the saturation region where the drain current isnearly proportional to the gate voltage and relatively independent of the drainvoltage. With the drain voltage below 5(V) the device acts as a resistor, wherethe resistance is proportional to the gate voltage.

    The major difference between the bipolar and MOSFET transistor is theinfinite input impedance of the MOSFET; thus, it draws no current. This makesit ideal for amplification of small signals in high impedance circuits. MOSFET isalso insensitive to temperature and cheaper to manufacture. Its higher packingdensities make it ideal for integrated circuits. A disadvantage is that the oxideinsulation is susceptible to breakdown from static electricity. Bipolar transistorsare used as an interfacing device since they can carry a much larger load currentthan the MOSFET. This is because the bipolar device conducts throughout itscross-sectional area while the MOSFET conducts across a narrow channel.

    6.4 Power Electronics

    Power electronics center mainly on three terminal, gate-(base) controlled de-vices. These devices fall into two classes: (1) power transistors, and (2) thyris-tors. In the low-to-medium DC power range power transistors are the choice.They include the bipolar transistor, the Darlington (or dual bipolar) transis-tor, and the field-effect transistor (MOSFET). Each remains ON only as longas the gate is active. MOSFET is preferred because the gate is voltage con-trolled rather than current controlled. Recent design advances have enabledMOSFETs to compete more effectively with Darlingtons in the medium powerrange. From the early 1960s until quite recently, the silicon-controlled rectifier(SCR) member of the thyristor family was universally used as the high-powersemiconductor switch. Today the words thyristor and SCR are interchangeable.SCRs are pn-type devices that are turned ON by a simple voltage pulse. How-

    Hossein M. Oloomi Purdue University Fort Wayne

  • 6.4 Power Electronics 167

    Table 6.1: Limits of present day power semiconductors.

    Transistors ThyristorsDarlington MOSFET TRIAC SCR

    I(A) 400 100 50(rms) 2000V(V) 1000 1000 1000 4000P(kW) 20 5 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 isunidirectional. Recently, interest has been growing in the gate turn OFF thyris-tor (GTO), which can be turned ON by a positive voltage pulse and turned OFFby 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. Itis normally used to switch AC circuits in the low-to-medium power range.

    Table 6.8 gives the present rating limits for power semiconductors. Voltagelimits relate to the pn-juntion breakdown in the OFF state. Current limitsdepend upon chip wire capacity. Power limits pertain to the load power beingswitched, and they are directly tied to the chip power dissipation limits whichare a much lower number.

    Power semiconductors are placed into an assortment of packages. Thesepackages are designed to dissipate heat. All but the low-power ones requireheat sink attachments to meet power specifications. Figure 6.8 shows the mostcommon packages and their approximate current range.

    Power electronics is based primarily on the switching of semiconductor de-

    Purdue 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) theimpact of microprocessors on control strategy, (2) fast-switching speeds, and(3) reduced semiconductor power dissipation, which allows larger loads to becontrolled.

    The ideal switch has infinite impedance in the OFF-state and no voltagedrop (no power dissipation) in the ON-state. Semiconductors are not ideal,but they are reasonably close. Figure 6.9 illustrates the voltage-current of aswitched 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) to3(V). Switching times are on the order of microseconds. Power consumption isgreatest as the device switches through the linear range.

    The measure of acceptability of any power conversion is efficiency. This isa comparison of the load power against the combined load power and wastedpower of the control unit. The most efficient mode is the fully ON (saturatedmode) with efficiencies over 70%. In some cases it is more appropriate to operatein 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 aspower op amps.

    6.4.1 Bipolar Power Transistors

    Parameters controlling the performance of bipolar transistors are essentially thesame regardless of chip size and power handling capacity. The basic theory ofoperation 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 orlinear, and (3) saturation. To turn the transistor ON, input voltage Vi must beincreased above VBE , the base to emitter voltage drop, 0.4(V). Input voltagesare generally 2(V) to 5(V). In the active (linear) state the collector current is

    IC = hFEIB ,

    Hossein M. Oloomi Purdue University Fort Wayne

  • 6.4 Power Electronics 169

    Figure 6.10: Basic circuit for bipolar transistor.

    where hFE is the characteristic current gain of the transistor and IB is thebase current. Collector current increases with IB until the device enters thesaturation 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 basecurrent of at least

    IBS =ICShFE

    .

    Normally, one designs the circuit such that IB exceeds IBS by a factor of 2 to10, called the overdrive factor (ODF):

    ODF =IBIBS

    .

    ODF covers up a considerable degree of uncertainty in the value of hFE . A highvalue 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 all-encompassing performance representing low-cost, high-current gain, lowON resistance, high-operating voltage, and high-speed operation. Thisexplains the sometimes bewildering selection on the market. Althougha transistor can be found to optimize a given design with regard to aset of particular parameters, many transistors will perform satisfactorily.Figure 6.11 gives the performance parameters for TIP73 power transistoras they are found in the Texas Instruments Power Products Data Book.Some data books, including Texas Instruments (TI), will give additionalinformation in the form of characteristic curves. See Figure 6.12.

    Maximum Ratings. Transistor circuits must be designed so that oper-ating 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 ofTexas 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 (terminalto terminal), and power dissipation. Of particular interest are thecollector conditions. Together they form a safe operating area.

    Safe Opertaing Area (SOA). All transistors and power ICs have safeoperating areas similar to Figure 6.12(a) for TIP73. The currentlimit, 15(A), arises because of limitations in the chip or bondingwires. Wires may melt if forced to carry more than the rated col-lector current. All points on the power limit portion have constantpower dissipation, 80(W). Thermal resistance, junction temperatureTJ , and the attachment package limit the dissipation. Finally, thevoltage limit is the maximum-rated collector-to-emitter voltage. Thisvoltage can be sustained from cutoff to about 2(A) of collector cur-rent in the active state. The reader should observe that a saturatedtransistor operates in the extreme left region of an SOA curve.

    Current Gain (hFE). Figure 6.12(b) shows that current gain variesconsiderably with temperature and collector current. hFE decreasesfrom 70 to 10 over the collector current range and increases to alesser extent over the temperature range. It is also a parameter overwhich the manufacturer has little control. Devices in the same batch,even after they are selected, can vary by at least 2:1 in gain. Man-ufacturer curves represent the worse case, and higher-current gainswill be found in a random purchase. When designing a circuit, theengineer assumes the worst condition and the poorest device. Theactual current gains are much smaller for power transistors than forgeneral-purpose transistors. Gains can be improved by testing andmaking a selection from within a group of similar devices.

    Collector-to-Emitter Saturation Voltage (VCE)SAT . Low valuesof (VCE )SAT will reduce the ON-state transistor losses. For general-purpose transistors the collector-emitter voltage at saturation is ap-proximately 0.3(V). However, power transistors have values whichcan range to several volts. As Figure 6.12(c) shows, (VCE)SAT in-creases with collector current to 2(V) for hFE = 10. The reason isthat load voltages are usually higher for power transistors. Thus, thecollector breakdown voltage (VCE)BRO must be made correspond-ingly higher than general-purpose transistors. This cannot be ac-complished without increasing the ON-state resistance.

    Base-to-Base Emitter Saturation Voltage (V BE)SAT . The base-to-emitter saturation voltage also depends upon the collector cur-rent. With general-purpose transistors (V BE)SAT is approximately0.7(V). However, values for power transistors can be much higher asshown in Figure 6.12(d). Since current gains tend to be low for powertransistors, base power loss IB (VBE )SAT cannot be ignored. Theloss 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 to0.9ICS. A more popular measure is the turn-ON time tON as indicated inthe figure. When the transistor is switched OFF, there is a delay, calledthe storage time ts, to remove the saturation charge from the base. Storagetime is increased by ODF and constitutes the limiting factor in switchingspeed. Once the charge is removed the current decays exponentially intime 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

    RC=

    20 1.02

    = 9.5(A).

    From Figure 6.11, hFE (min) = 15, which gives

    IBS =ICShFE

    =9.515

    = 0.63(A).

    Using an overdrive factor of 2, IB = 1.2(A). This high value is rathertypical for bipolar power transistors. Driving RB with the source, weobtain

    RB =VCC VBE

    IB=

    20 1.01.2

    = 15().

    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 transistordrive.

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

    VCE = LdI

    dt=LICtf

    is sufficient to exceed the breakdown voltage. (VCE)BR should never beexceeded. To avoid transistor burn out, a diode is placed in parallel withthe load. Better yet, a zener diode is placed in series with the regulardiode to protect (VCE)BR. The inductor energy is allowed to dissipate bylooking the current back through the load resistance while clamping thevoltage at (VCE)BR.

    Example 6.3 A permanent magnet DC motor is connected in a T bridge forsimple 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 voltageVm = 10(V ). The driver selected is the TIP73 bipolar power transistor ratedat 15(A) continuous collector current. Its case temperature is maintained at25(C) with a heat sink. Supply voltage is 12(V). Let us evaluate the design.

    Continuous modeIC = 2(A) (PD)base = 12(

    435) = 1.4(W ) (including Rb)

    (VCE)SAT = 0.17(V ) (PD)collector = (0.17)(2) = 0.35(W )hFE = 35 (PD)total = (12)(2) = 24(W )IB = 235(A)

    = 435(with overdrive) Efficiency = 24(1.4+0.35)

    24= 93%

    Vm = (12 0.17) = 11.8(V )

    Hossein M. Oloomi Purdue University Fort Wayne

  • 6.4 Power Electronics 175

    Figure 6.15: Darlington circuit.

    Start/stall mode

    IC = 10(A) (PD)base = 12(2013) = 18.5(W )

    (VCE)SAT = 0.8(V ) (PD)collector = (0.8)(10) = 8(W )hFE = 17 (PD)total = (12)(10) = 120(W )IB = 1017(A)

    = 2017(with overdrive) Efficiency =120(18.5+8)

    120 = 78%Vm = (12 0.8) = 11.2(V )

    A major drawback for bipolar power transistors is the large base currentdrive. To meet start conditions, the base current must be supplied by anotherpower transistor. The second transistor must be driven by a buffer (or general-purpose 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 parameterswith the worst possible transistor; i.e., use the electrical characteristics data inFigure 6.11, where (VCE)SAT = 3.5(V ) max. Suppose we had selected a TIP33with a current rating of 10(A). The data sheet has no typical characteristics plotfor (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 worstcase.

    6.4.2 Darlington Transistors

    Bipolar power transistors have low-current gains with high base currents. Itsdriver is usually another lower-rated power transistor. If both transistors aremounted on heat sinks, a considerable amount of space will be occupied bythe two transistors. This problem is circumvented by encapsulating the twotransistors on the same chip, called a Darlington transistor.

    The Darlington circuit is shown in Figure 6.15. Emitter current from Q1 isalso 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 Q2gain. Current gains of the two transistors are controlled during manufacture sothat the overall gain varies linearly over a range of collector current when it isused 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. (Courtesyof Texas Instruments.)

    Performance Parameters Specifications for the TIP663 npn Darlington tran-sistor are listed in Figure 6.16. Typical characteristic curves are also shownin Figure 6.17. Although the transistors are bipolar, there are major dif-ferences from the single unit.

    Current Gain (hFE). Careful matching of the transistor pair in Dar-lingtons produces some rather startling current gains with hFE upto 10,000 possible. Darlingtons often can be driven directly from thePIA or other TTL logic gates. We can see in Figure 6.17(b) thathFE varies significantly with collector current and case temperature.Optimum hFE is approximately equal to 2000 (at 25(C) case tem-perature) and occurs at a collector current nearly one-half the rated20(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 withbuilt-in free wheeling diodes? Case (a) only.

    mistake since hFE is not much better than a single power transistor.Chip temperature presents a somewhat different problem. Unlessthe case temperature is known, hFE is uncertain by a factor of 3.Therefore a large overdrive factor will be necessary to be certainthat saturation is reached.

    Collector-to-Emitter Saturation Voltage. Figure 6.17(c) showsthat (VCE)SAT is higher than bipolar power transistor values at allcollector currents. The voltage drop is far worse at collector cur-rents approaching the maximum-rated current. In spite of the higher-power losses in Darlingtons, they are preferred because the high hFEwill simplify driver hardware. Power losses are minimized by usingDarlingtons in load circuits that have low currents and high voltagesacross the load.

    Switching Time. Darlington switch-ON times are comparable to bipo-lar transistors. However, the switch-OFF times are an order of mag-nitude longer than bipolar power transistor tOFF .

    Free-Wheeling Diode Texas Instruments Darlington transistors have a built-in free-wheeling diode across the collector-emitter terminals. In some con-figurations it will eliminate the need for an external diode to shunt theswitch-OFF voltage buildup with load inductance. The key is placingthe load between the transistor and ground. This point is illustrated inFigure 6.18. Only case (a) should have an external protecting diode.

    Example 6.4 The T bridge motor design in Example 6.3 replaces thebipolar power transistor with the TIP663 Darlington rated 20(A) contin-uous 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 transistordrive.

    compare the two designs at 25(C) case temperature.

    Continuous modeIC = 2(A) (PD)base = 12(

    41500) = 0.03(W )

    (VCE)SAT = 0.8(V ) (PD)collector = (0.8)(2) = 1.6(W )hFE = 1500 (PD)total = 1.6(W )IB = 235(A)

    = 4(mA)(with overdrive) Efficiency = 241.624

    = 93%Vm = (12 0.8) = 11.2(V )

    Start/stall modeIC = 10(A) (PD)base = 12(0.01) = 0.1(W )(VCE)SAT = 1.2(V ) (PD)collector = (1.2)(10) = 12(W )hFE = 1000 (PD)total = (12)(10) = 120(W )IB = 10(mA)

    = 30(mA)(with overdrive) Efficiency = 12012.1120 = 90%Vm = (12 1.2) = 10.8(V )

    The drive requirements are substantially reduced from the bipolar powertransistor design. Still, a 74S241 buffer/driver and pull-up resistor mustbe placed between the PIA and the Darlington. The Darlington dissi-pation is greater than the bipolar transistor, which is expected from itshigher (VCE)SAT . We should point out that using this transistor for amotor rated at 15(A) start/stall is perfectly acceptable. Yet the collectorvoltage drop (VCE )SAT = 3.3(V ). If a heat sink design allows the casetemperature to stabilize much above 100(C), (VCE)SAT could double thisvalue. The motor drive voltage Vm is supply voltage minus the transis-tor voltage drop. In some cases, particularly H bridge drives which havetwo transistor voltage drops, there may be insufficient voltage to meet thedesign 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. Wewill also explain how software drivers can be written for these sensors once thehardware interfacing is accomplished. Software drivers are pieces of codes thatprovide a well-defined interface between a hardware device and a program thatneeds to use the interface. Both assembly language and C language will be usedto this end. It should be noted that, in these codes, the symbol - is used asa normal character rather than the subtraction operator.

    6.5.1 Microswitches

    Microswitches are small momentary switches with many applications. For ex-ample, they can be attached to bumpers of a mobile robot to signal when therobot has run into an obstacle. Figure 6.20 shows two ways to interface thebump switches to the microprocessor. The circuit in Figure 6.20(a) is straight-forward: One pin of port E is used for each switch. When the robot collides withan obstacle, one or two switches close, changing the state of the correspondingbit(s) from 0 to 1. This approach has the advantage of being easy to understandand implement, but it uses up three of the MC68HC11s input lines.

    There is another way to achieve the same functionality that uses only oneMC68HC11 input pin. This second approach is shown in Figure 6.20(b), wherea network of resistors is used to create different voltages at the MC68HC11 inputpin, depending on which switch is closed. (The A/D mode for port E must beused.) 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 ofswitches is closed; this is determined by in which of eight ranges the measuredvoltage falls.

    A careful analysis will show that the circuit in Figure 6.20(b) is essentially avoltage adder. As long as the current flowing from the +5 V supply through thesingle 2.2(k) resistor and two 1.2(k) resistors to ground is large comparedto the current flowing through any other part of the circuit, this approximationwill hold. If, as shown, the powering voltage divider has taps at1/4, 1/2, and1 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 tapor to ground). Since the A/D converter produces digital values between 0 and255, the set of voltages it reads will be 1/3 of 255 times the sum of the voltagesfrom the switches. For example, when only switch A is closed (connected toground), the A/D output will be 1/3255(0 + 1/2 +1/4)64. When switchesB and C are closed, the output will be 85.

    Microswitches can be attached in a number of ways to enhance their appli-cability. They can be connected to one or more whiskers extending from therobot; 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), eachswitch goes to a separate pin of port E. A digital read of port E reveals thestate of the bumper. Circuit (b) channels all bump switches to one pin of portE. Here, an analog-to-digital converter must be used to determine which set ofswitches is closed.

    Figure 6.21: Radio shack 276-1657 photoresistors are shown in a voltage dividerconfiguration connected to port E, bits 0 and 1. Port E is used here in analog-to-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 theiroutputs compatible with a microprocessor, and the complex images camerasrecord are anything but easy to interpret.

    Light sensors can enable robot behaviors such as hiding in the dark, playingtag with a flashlight, and moving toward a beacon. Simple light sensors can bepurchased 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 resis-tors in many ways similar to potentiometers, except that the resistance changeis 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 pho-

    Purdue 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 verywide range of light levels, and respond rapidly to changes in illumination. Thismakes 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 photodiodedoes, however, require amplification before it can be used by a microprocessor.

    Because the photoresistor is so useful and easy to incorporate, we will furtheranalyze a practical circuit for connecting one to a microprocessor. Consider thecircuit for the left photoresistor in Figure 6.21. Here, two resistances form whatis called a voltage divider. The total resistance in the circuit, RT, is the sumof the individual resistances: RT = R + RL. According to Ohms law, thecurrent, I, through the circuit is I = V/RT . In order for the A/D converter inthe microcontroller to measure a voltage, some current must flow into pin PE1.However, because the MC68HC11 has high-impedance inputs, the amount ofcurrent 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 voltagedivider. Thus, the voltage present on PE1 is

    VPE1 = RLI.

    The resistance of the photoresistor falls as the light level increases. Thismeans that the voltage at PE1 decreases. Substituting for I, we get

    VPE1 =RL

    R+RLV.

    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 voltage-divider circuit is not logarithmic, as was recommended for light sensors in Sub-section , a useful output can nevertheless be extracted. A good compromisebetween sensitivity and range will be achieved if the resistance, R, is set to thesame value as the resistance exhibited by the photoresistor when exposed tothe light level in the middle of the range of light levels in which the robot mustoperate.

    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 momentto explain in some detail how to configure the analog-to-digital converter andprogram a software driver for photoresistors. These tasks encompass both thecapabilities of the hardware and the responsibilities of the programmer.

    As was mentioned in Chapter 2, port E of the MC68HC11 can be configuredas either an 8-bit input port or an 8-channel analog-to-digital converter. Inter-nally, there is only one A/D circuit for the entire port and only four registersto store results from the eight channels. Thus, to achieve the full potential ofthe A/D port, a certain software protocol must be enforced.

    First, the voltage reference pins on the MC68HC11 (VRH and VRL) mustbe 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 lim-its, respectively. Voltages between the limits are proportionately scaled. Twocontrol registers, ADCTL and OPTION, are used to configure the mode of con-version. Reference should be made to the MC68HC11 Programmers Manual tosee which bits in these registers should be set to turn on the A/D and to selectits various modes. Conversion sequences can be chosen that repeat on a singlechannel four times or on four channels, once each. In this latter mode, the eightpins 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 de-notes the conversion complete flag (CCF). Conversions are complete 34-clockcycles after the ADCTL register is written. After each conversion, results areposted in the internal result register: ADR1, ADR2, ADR3, and ADR4. Theconverter 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. WhenSCAN = 0, four conversions are performed, once each, to fill the four resultregisters. When SCAN = 1, conversions continue in a round-robin fashion.When MULT = 0, four conversions are repeated on a single channel of portE. 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 bankis specified by bits 2 and 3 of ADCTL. If bits 2 and 3 are set to 0, channelsPE0-PE3 are converted. If bits 2 and 3 are set to 1, channels PE4PE7 areconverted.

    In the following example, written in both assembly language and C code, wecreate a very simple software driver for acquiring a reading from the photocells.The assembly code version might be written:

    ph-right equ $10 ;Create variable for right photocellph-left equ $11 ;Create variable for left photocelloption equ $1039 ;Address of OPTION registeradctl equ $1030 ;Address of ADCTL registeradr1 equ $1031 ;Result register for A/D channel 1adr2 equ $1032 ;Result register for A/D channel 2

    update-photobset option #%10000000 ;Enable A/D system

    Purdue University Fort Wayne Hossein M. Oloomi

  • 184 ELECTRONIC DEVICES AND INTERFACING

    bset adctl #%00010000 ;Begin A/D conversion

    check-resultbrclr adctl #%10000000 check-result; Wait in tight loopIdaa adrl ;Get value from rt photocellstaa ph-right ;Save right valueldaa adr2 ;Get value from lf photocellstaa ph-left ;Save left valuerts ;Return to calling code

    The C version of the photocell code is somewhat simpler:

    int ph_right = 0; /* Variable for right photocell data */int ph_left = 0; /* 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 con-versions 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 propervalue to the OPTION register; then we begin a conversion by writing to the AD-CTL register. The next part of both programs polls the conversion-complete bitof the ADCTL register, remaining in a tight look until the conversion flag is setby the internal hardware of the A/D. Finally, the results of the conversion aremoved from the result registers, ADR1 and ADR2, to the designated locations.

    To learn the details of which registers and which bits control the variousfunctions of the A/D converter and the microprocessors other systems, youshould 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 areused in robotics applications. This can best be explained using Figure 6.23. Thedynamic model for motor/load can be arranged into an open-loop block diagramwith voltage and frictional (or gravitational) load torque as inputs and speed asthe output. The loop includes a voltage amplifier with gain KA. Part of thecontrol voltage VR goes to accelerating the inertia load. The steady-state speedis 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 knownvoltage 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 powertransistors that operate in their linear range, motor voltage being proportionalto VR. Figure 6.24 shows a T-type configuration for driving motors with com-plementary power transistors. When the control voltage is positive, the motorruns clockwise; negative voltages reverse the motor. A single transistor can beused for unidirectional control.

    An alternative drive method using switching transistors is more suitable todigital control. However, these Darlington and MOSFET transistors are not dis-cussed here. There are two approaches: (1) pulse-width-modulated (PWM), and(2) pulse-frequency-modulated (PFM). PWM control voltages work by switch-ing the full voltage of the DC power supply to the motor on and off at a fixedfrequency. By varying the duty cycle (on portion of the cycle), the averagevoltage seen by the motor varies in proportion to the duty cycle. Switchingfrequency 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 andcontinuous. The PFM control voltage switches the DC supply on for a fixedperiod of time (fixed width) but varies the spacing between the pulses or rep-

    Purdue University Fort Wayne Hossein M. Oloomi

  • 186 ELECTRONIC DEVICES AND INTERFACING

    Figure 6.25: H-bridge with switching amplifiers (PWM) for open-loop speedcontrol.

    etition rate. For low average voltages as seen by the motor, the frequency islow. Voltages are increased by increasing the switching frequency. PFM controlis 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. Inthe forward mode, e.g., transistors Q1 and Q4 are ON, and current flow isleft-to-right through the motor. A system that is more compatible with micro-processors 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 secondinput. Either T or H configurations can employ switching or linear amplifiers.The H-bridge is preferable because it takes a single unipolar power supply, butit is more difficult to control with the linear method.

    Linear transistors are confined to low-to-medium performance (less than5(A)) motors because of heat and power loss. Power dissipation in transistorsis the product of current and voltage drop on the order of 0.2(V). If the exces-sive heat generated is not removed, motor current (torque) must be reduced.Linear transistors are susceptible to breakdown at peak current levels, whichoccur when motors are overloaded. For this reason current limiting circuits areemployed.

    6.6.1 Motor-Driver-Power Integrated Circuits

    Motor-driver-power integrated circuits (ICs) make it very convenient to interfacemotors to microprocessors. Typically motor-driver-power ICs also have circuitrythat provides current-limiting and over-voltage protection. One single-chip so-lution is the MPC1710A motor driver from Motorola. This chip, whose blockdiagram 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. Thispower IC incorporates a motor driver using an H-bridge made from bipolartransistors. While this illustration only shows one H-bridge, two full H-bridgesare actually incorporated in an L293D.

    MOSFETs. A level shifter and charge pump circuit are included on the chip todrive the high-side switches.

    Three capacitors and an inverter are the only external components requiredto interface an MPC1710A to Rug Warriors MC68HC11A0. We could use portD pin PD5 to set the forward or reverse direction of the motor and port A pinA5 to pulse-width modulate the enable input for speed control. The MotorolaMPC1710A can deliver up to a 1(A) of current with a 0.4() on-resistance whensourcing 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 andthe other motor by pins PD4 and PA6. The MPC1710A comes in a small 16-pinsurface-mount package, which makes it very compact when used in a printedcircuit board design but rather difficult to use when prototyping with Speedwireor Scotchflex wiring technologies. For this reason, on Rug Warrior, we chose touse a chip that would be more amenable for our readers, the SGS ThompsonL293D.

    The L293D was chosen because it comes in a normal 16-pin dual-inline pack-age (DIP). This selection, which has two H-bridges on board, minimizes theparts 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 incor-porated 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 Bugstwo motors. One MPC1710A is needed for the left motor and one MPC1710Ais needed for the right. This surface-mount integrated circuit motor driver chipuses 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 Boarddmotors. The MC68HC11s port D pins PD4 and PD5 select forward and reversefor the left and right motors, respectively, while port A pins PA6 and PA5 pulse-width modulate the left and right enable pins. Note that OC1 here is used toalso control OC2 and OC3.

    on chip in this circuit. The L293D can deliver 600(mA) to the motor, with a sat-uration voltage drop of 1.4(V) when sourcing current and 1.2(V) when sinkingcurrent.

    Figure 6.28 illustrates how we have interfaced the L293D to Rug Warriors6811. The L293D has some on-chip logic that provides an Enable signal. In thisway, the Inputs to the H-bridge can be used to set the direction of the motorand the Enable signal can be used for pulse-width modulation. We use port Dpin PD5 to set the direction for the right motor. An inverter is used to set oneside of the H-bridge to the opposite polarity voltage of the gating signal of theother side. This ensures that if switches S1 and S4, for instance, are on, thenswitches S2 and S3 will be off and vice versa. Note that this means that themotor is never actively braked. The H-bridge is pulse-width modulated by tyingthe right motor drivers Enable pin to port A pin PA5. The output comparefunction of PA5 is used to facilitate timing. One advantage of the L293D is thattwo full H-bridges are incorporated on chip, which means that only one L293Dis needed to drive both of Rug Warriors wheels. Port D pin PD4 is used to setthe direction of the left motor, and port A pin PA6 is tied to the Enable signalfor pulse-width modulation.

    Many other motor-driver-power integrated circuits are available. As men-tioned in E, the place to begin searching is the IC Master. The IC Master listsintegrated circuits both by part number and by function. Listings under Mo-tor Drivers include a number of suppliers, such as Unitrode, Siemens, Motorolaand 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-controlledcars. These are often called speed controllers, which is a bit of a misnomer, sinceit is only the human who provides the speed control. However speed controllersdo incorporate the power MOSFETs or power bipolar transistors in discrete H-bridges for driving larger motors. They are sold by Futaba, Tower Hobbies, andSheldons 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 bythe programmer. For instance, a higher pulse-width ratio of voltage across themotor is needed to keep the robot moving up a ramp at one foot per secondthan would be required to make it move along a flat tile floor at one foot persecond. To maintain a desired speed, regardless of terrain, means that the robotneeds to count the number of pulses from one of the shaft encoders to see howfast the wheels are turning and then update the pulse width accordingly.

    The second function that the software needs to perform is to make the twowheels actually revolve at the same speed so that the robot will move in astraight line. Note that, innate differences between the two motors can causethe robot to move in an arc, even when the same voltage was applied to bothmotors. The solution is to read the shaft encoders from each wheel and increaseor decrease the speed of the right motor, say, to match its speed with that ofthe left motor.

    6.7.1 Pulse-Width Modulation

    The software we have configured for controlling the Handy Bugs motors takesadvantage of time-counter hardware associated with the MC68HC11A0s portA and succeeds in implementing a pulse-width modulation scheme without re-course to either polling or interrupts. Port As eight pins have various outputcompare and input capture registers, as shown in Figure 6.28. Refer to theMotorola data books on the MC68HC11 for a more complete discussion thanwe will attempt here.

    An output compare register can be set by the programmer so that, for in-stance, when the time-counters value matches the output compare registersvalue, a pin can be set high or an interrupt can be initiated. An input captureregister 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 atthe 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 compareregisters 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 usingthe MC68HC11A0s port A output compare registers. Here, we use three differ-ent output compare registers, where output compare register OC1 directs pinsPA5 and PA6 to both go high at the beginning of each period. Output compareregisters OC3 and OC2 each tell pins PA5 and PA6 when to go low, giving aprogrammable duty cycle for each motor.

    PA7 happens to hold a dual role as either a pulse accumulator or as outputcompare register 1 (OC1). For Rug Warriors right wheel, we have chosen touse PA5, which is associated with output compare register 3 (OC3) and for theleft wheel, PA6, which is associated with output compare register 2 (OC2). Wealso take advantage of OC1 because it is a special output compare register inthat it can control a given selection of the four other output compare registers.The closed connections between OC1 and OC2 and between OC1 and OC3is Figure 6.28 illustrate how we intend to use the timer-counter capabilities todrive the Handy Boards motors. Figure6.29 illustrates the timing sequences forour algorithm that will be generated on PA5 and PA6 to implement pulse-widthmodulation.

    The timer-counter itself is a 16-bit register, TCNT, where the high byte isat hex address $100E and the low byte is at $100F:

    TCNT B15 B0$100E

    The timer-counter runs at a rate dependent upon Rug Warriors crystaloscillator (and therefore the MC68HC11A0s E clock, which is on pin 5 of theMC68HC11A0 and can be checked with an oscilloscope). The E clock has aperiod of one-fourth that of the crystal oscillator frequency. TCNT is a free-running counter that starts at 0 when the MC68HC11A0 is reset and counts upto 216, which is 65,536 counts. The counter then overflows and starts again from0. We use an 8(MHz) crystal for Rug Warrior, giving the E clock a frequencyof 2(MHz) and a period of 0.5(sec). By default, the timer-counter counts atthe same period as the E clock, but there is a way to prescale the timer-counterrate, 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 Eclock for changing the rate at which the timer-counter runs.

    TMSK2 Bit 7 Bit 0$1024 TOI RTII PA0VI PAII 0 0 PR1 PR0

    For our purposes, we will let the timer-counter run at its default setting andnot bother with changing any values in TMSK2. This means that after 216counts at 0.5(sec) per count, 32.77(msec) will have passed. We will use thisstandard overflow time as the period for pulse-width modulation, tperiod.

    Our plan is to create the pulse-width modulated signals for the left and rightmotors using waveforms generated by OC2 and OC3 associated with pins PA6and PA5, as shown in Figure 6.29. In this case, we will use OC1 to set the bitshigh on both PA6 and PA5 when the timer-counter is at 0. We will use theOC2 and OC3 registers to clear the bits on both PA6 and PA5 when the valuereached by the timer-counter matches the values stored in their 16-bit timeroutput compare registers, TOC2 and TOC3. So, for instance, if we want PA5to have a 25% duty cycle, then we store 65, 536 4 = 16, 348 in TOC3. If wewant PA6 to have a 50% duty cycle, we store 65, 536 2 = 32, 768 in TOC2:

    TOC2 B15 B0$1018

    1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

    TOC3 B15 B0$101A

    0 0 1 1 1 1 1 1 1 1 0 1 1 1 0 0

    To specify what action should be taken on PA5 and PA6 when the corre-sponding output compare registers match the timer-counter, we must set somevalues in another register, TCTL1. The appropriate bit sequences are shown inTable 6.2. For the way we designed our algorithm in Figure 6.29, we want PA5and 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), inTCTL1 in the locations associated with OC3 and OC2:

    TCTL1 Bit 7 Bit 0$1020 OM2 OL2 OM3 OL3 OM4 OL4 OM5 OL5

    1 0 1 0 x x x x

    The xs in any bit position represent dont cares. With the falling edge ofthe pulse configured (the signal transitioning from high to low), now we justneed to set up the OC1 rising-edge event (the transition of the signal from lowto high). This is done by storing the value of time equal to 0 in TOC1, the16-bit timer output compare 1 register:

    TOC1 B15 B0$1016

    0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0

    Hossein M. Oloomi 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 notchange, to toggle, to go low, or to go high. Two bits in the TCTL1 register, themost significant bit (OMx) and the least significant bit (OLx), set the desiredresponse for any successful output compare.

    OMx OLx Configuration0 0 OCx Does Not Affect Pin0 1 Toggle OCx Pin1 0 Clear OCx Pin1 1 Set OCx Pin

    To configure the hardware so that OC1 will control PA5 and PA6, we setvalues in some auxiliary registers that control OC1. The output compare 1 mask(OC1M) register signifies which of the other four output compare registers OC1will control. The high five bits in OC1M correspond bit for bit with a port Aoutput pin. Therefore, we store the binary number %01100000 in OC1M to setup OC1 to control PA5 and PA6:

    OC1M Bit 7 Bit 0$100C OC1M7 OC1M6 OC1M5 OC1M4 OC1M3

    x x 1 x x x x x

    Once we have selected which pins will be active, we can program the actionthat we want to result when the timer-counter value matches the value of 0 inTOC1 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 timer-counter overflows and returns to the value 0, the PA5 and PA 6 pins will be setto 1, which forms the rising edge of each pulse.

    OC1D Bit 7 Bit 0$100D OC1D7 OC1D6 OC1D5 OC1D4 OC1D3

    x 1 1 x x x x x

    By using these built-in hardware features of the 6811, no interrupts or pollingsequences are required to implement pulse-width modulation. We simply writeto some registers in the timer-counter system and all actions on pins PA5 andPA6 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 speedhas to be changed.

    6.7.3 PWM Software Driver

    The program below illustrates the IC code that implements this scenario of a25% duty cycle signal asserted by pin PA5 and a 50% duty cycle signal assertedby pin PA6. This sequence will make one wheel rotate at half the speed of theother, 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 DDRD = 0x1009; /* Port D data direction */int OC1M = 0x100C; /* Output Compare 1 Mask */int OC1D = 0x100D; /* Output Compare 1 Data */int TOC1 = 0x1016; /* Output Compare Timer 1, 16-bit reg */int TOC2 = 0x1018; /* Out Cmp Tmr 2, 16-bit reg (left motor) */int TOC3 = 0x101A; /* Out Cmp Tmr 3, 16-bit reg (right motor) */int TCTL1 = 0x1020; /* 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() /* Initialize Pulse-Width Modulation */{ poke(DDRD,0b110010); /* D dir: OUT 5,4,1; IN 3,2,0 */poke(OC1M,0b01100000); /* Out Cmp 1 affects PA5 and PA6 */poke(OC1D,0b01100000); /* Successful OC1 turns on PA5, PA6 */bit_set(TCTL1,0b10100000); /* OC3 turns off PA5, OC2: PA6 */pokeword(TOC1,0); /* When TCNT = 0, OC1 fires */pokeword(TOC2,1); /* Minimum on time for OC2 */pokeword(TOC3,1); } /* 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

  • 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 areassigned and three data structures are created. The arrays TOCx[ ], sign[ ], anddir mask[ ] are all two-element arrays. TOCx[ ] is an array whose first elementis the address TOC2, where left-motor velocities are stored, and whose secondelement is the address TOC3, where right-motor velocities are stored. The arraysign [ ] is an array whose elements are bits representing which direction the leftand right motors are commanded to go. The array dir mask[ ] is an arraywhose 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 theright motor.

    The next three functions also just lay the ground work for the main partof this program. The functions abs(), get sign() and limit range() arefunctions that C does not happen to supply: abs() simply returns the abso-lute value of its argument; get sign() returns the sign of its argument; andlimit range() returns a maximum or minimum value for its argument if it isout of range.

    The actual pulse-width modulation of the motors is accomplished by thefunctions init pwm(), pwm motor(), and move(). The timer-counter hardwareis set up and started by init pwm(). The three pokeword() commands set aninitial (small) pulse width.

    To change the duty cycle, the calling routine uses the pwm motor() func-tion, which takes two arguments: a velocity command and a motor index.pwm motor() then pokes the new velocity into the address, either TOC2 orTOC3, as specified by motor index.

    The function move() is the interface the programmer has for directing therobot. move() takes two arguments, a velocity for the left motor and a velocityfor the right motor. These velocities should be in the range [100.0, 100.0]. Amove(25.0,50.0) command would make the left motor move at 25% of fullspeed and make the right motor move at 50% of full speed, causing the robotto arc to the left.

    Setting up the pulse-width modulation scheme for each motor then merelymeans writing some values to a few registers. Once this has been done, thehardware associated with the timer-counter system will run by itselfalwayssetting pins PA5 and PA6 high when the timer-counter reaches zero, alwayssetting PA5 low when the timer-counter reaches 16348, and always setting PA6low when the timer-counter reaches 32768. The central processing unit of theMC68HC11A0 then is free to attend to other tasks, perhaps reading a sensor orcalculating 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 andTOC3.

    6.8 Problems

    6.1 By measurement, a diode is found to draw 1(mA) of current when thevoltage 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 thevoltage across the diode is vD.

    (a) If the current in the diode is doubled, calculate the increase in thediode 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 byonly 2 percent.

    6.3 In Figure 6.30, let v = 10 sint, VB = 6(V ), and assume that the diode isideal. Under what circumstances will the current i flow? Sketch v and i asfunctions of time using the same axes.

    6.4 Expanding your reasoning and stating any simplifying assumptions, predictcurrent I in Figure 6.31 assuming ideal diodes.

    6.5 In Figure 6.32, v1 = 10 sint 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 sint (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 Fig-ure 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 correspondingvalues of the output voltage Vo, assuming the diodes are ideal. Define inwords 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.37where RS = 1(k) and RL = 2(k). Assuming ideal diodes, if V1 increasesfrom 16 to 24(V) (a 50% increase), calculate the corresponding variation inload voltage VL. Is the regulator doing a good job?

    6.11 A transistor with = 100 and (VCE)SAT = 0.2(V ) is connected in thecircuit of Figure 6.38(a) with VCC = 5(V ) and RC = 1(k).

    (a) Estimate the output voltage and current IC when the transistor switchis 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 whenthe 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 collectorto 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 inputvoltages 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 hFE found on the data sheet in Figure 6.11 withthe plot given in Figure 6.12. What is the difference in terms of a designwith 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 mo-tor. The problem assumes the case is at 25(C). If the case is actually at125(C), how does the solution change?

    6.18 The speed of a DC motor is to be controlled similar to the diagram inFigure 6.19. The small motor has a stall current of 2(A) and a continuouscurrent of 0.3(A). An oversized power transistor in the form of a TIP663Darlington 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