Anda di halaman 1dari 4

Building the Corners Now that we have the transistors picked out, we look at implementing an H-bridge using them.

Because these transistors are a complementary pair, the circuit using them is very symmetrical. The upper right and upper left corners of the H-bridge are called "sources." This name originates from their function which is to be a source of current for the load (in our case the motor). Referring to the schematic on the right, you can see that there is a 10K resistor between the base of the TIP107 and the positive terminal of the battery. This is a pull-up resistor that insures that the transistor is "off" (or not sourcing any current) when the switch is open. The 1K resistor that is connected in series with the switch is used to limit the current coming out of the base when the base is grounded by the switch. So in this case when the switch is closed, the emitter-base junction becomes forward biased and current flows "out" through the base. If the battery is 12V and the voltage drop of the Base-Emitter junction is .7V, then the current flow in the base will be -11.3mA (negative because it is flowing "out"). Given the Hfe specs for this transistor, this level of base current will completely turn "on" this transistor allowing the load to consume as much current as it needs. Conversely, the schematic on the left is called a "sink." Its name is derived from this circuit's function which is to provide a place for current to go once it has passed through the load. The sink lower left and lower right corners of the H-bridge are implemented as circuits. In the sink circuit the 10K resistor connects the base of the transistor to ground, which forces the transistor off when the switch is open. When the switch is closed, current is injected into the base through the now forward biased base-emitter junction. Again the amount of current is nearly identical to the source configuration so an equal amount of current is allowed to flow through the load. Of course if we have to throw switches to turn these transistors on it doesn't make for a very useful Hbridge. In order to drive this H-bridge from a microprocessor we need to put the microprocessor pins in control. In the sink circuit, the transistor stays turned off if the base is grounded, it turns on when current flows through the 1K resistor and into the base. A typical microprocessor's output pin can generally put out either 3.3V or 5V as a logic "true" output. Given that we need only approximately 5 mA to turn the transistor fully on, you could compute the necessary base resistor by subtracting the baseemitter voltage drop (.7V) from the logic high voltage (3.3 or 5) and then dividing by the desired base current (5 mA) to get the appropriate resistor (660 or 1K ohms respectively). The source circuit is another problem entirely and an area I call "the high side problem." Turning on the source is easily accomplished by grounding the 1K resistor, however turning it off requires bringing the 1K resistor up to the motor voltage. You could tri-state the output and let the 10K resistor bring it up to the motor voltage. However, if you did, you're microprocessor pin might be exposed to a voltage that is was not designed to handle. A solution for this problem is to add another transistor to the high side which is a sink circuit to turn on the source circuit! In the schematic you can see that I added a 2N3904 NPN type transistor which replaces the switch in the original schematic. This works because the microprocessor only need turn on the 2N3904 (which is referenced to ground), then that pulls the base of the source

transistor to ground through its 1K resistor which turns on the source transistor and current then flows into the load. But as you need to add two transistors anyway to control the two upper corners of the bridge, there is an even better way to go. The picture on the left is the schematic representation of an optoisolator. An opto-isolator is an LED and a photo-transistor packaged into a single 4 lead package. You can get four opto-isolators in a single IC DIP using the NEC P S2504-4. When current flows in the LED the photons it emits illuminate the base of the photo-transistor. This causes the photo-transistor to turn on and begin conducting current. The photo-transistor is completely electrically isolated from the LED so the voltage on the phototransistor has nothing to do with voltage on the LED. This isolation brings with it two benefits and one drawback. The major benefit is that the photo-transistor can used in place of the switches in our sink and source circuits. This means that the microprocessor sees four LEDs to light up, but what they really do is activate the circuits in the bridge. The second benefit is that the motor power supply with all of the switching noise is completely isolated from the power supply that is powering the microprocessor. The drawback is that the opto-isolator doesn't switch on and off as nearly as fast as a regular transistor. In fact it can take 4 uS to turn this baby on. That means that simply turning it off and on as fast as possible results in a 125Khz, 50% duty cycle waveform. (4uS on, 4uS off). In practical terms, if you want equal PWM steps from 1% to 100%, then the minimum "off" or "on" time is one 4uS increment. The equal step constraint would limit you to a PWM period of 400uS, or 2,500 Hz. If you don't care about the edge conditions you could choose 1 uS as your increment, then given the minimum 4uS switch time, your duty cycle could be 0%, 4%-96%, and 100%. The gaps at the low end and high end represent the 4uS switching minimum. The benefit however is that your base period is now 100uS and your base frequency is 10Khz. In summary, a completely symmetric PWM control will be no faster than 2500 Hz. If the areas of very low duty cycle and very high duty cycle are un-interesting to your application, then the frequency can be increased. The final thing we have to consider before we design the circuit is the nature of DC motors. A DC motor looks like a resistor and an inductor (coil) to the H-bridge. The resistor doesn't cause us much grief, but the inductor does. That is because inductors do not like being switched on and off. When the current through an inductor changes, the voltage across it goes up in proportion to inductance and the rate of change in the current. This is expressed in engineering texts as V = L(di/dt). Well switching off 6 amps of the current in 4 uS means the the voltage is something like L*(6/.000004) or L*1,500,000. Clearly you aren't going to see several million volts but you will see a spike in voltage when the inductor is switche.I'll dive a bit more deeply into this phenomena in the analysis section but for now this means we need some diodes (called free wheeling diodes) to direct those voltage spikes to places where they can do no harm. Fortunately, the TIP107 and TIP102 have freewheeling diodes built into them, but if you decide to use transistors that don't have built in diodes the circuit in the next section provides for them. Building the H-Bridge I really like this H-bridge for a number of reasons, not the least of which is that if you buy your parts in quantities of 1, all the parts cost under $5 (excluding tax & shipping of course) for a 1 - 5 amp capable H-bridge. This keeps the final circuit in the "cheap" category which was one of the design parameters we're optimizing for. The complete schematic for the bridge is shown below.

The fast recovery diodes (shown in light blue) are optional when you are using the TIP102/107 as those transistors have a diode built into them. However you can include them for greater protection at higher currents and still keep the cost at $5 per bridge. In the table below is a parts list, with prices from November of 2003, using part numbers from Mouser Electronics. You will note that I also take advantage of the symmetrical nature of the bridge by using resistor packs rather than individual resistors. These packs allow for a tighter design while still using through hole technology. If size is an issue, you'll probably go with surface mount rather than this type of circuit. Qty Mouser Part # Description TIP107, PNP Power Darlington Transistor (TO-220AB) TIP102, NPN Power Darlington Transistor (TO-220AB) 10K Ohm, SIP Resistor network (independent resistors) 560 Ohm, SIP Resistor network (independent resistors) 1K Ohm, SIP Resistor network (independent resistors) Quad Opto-coupler (16 pin DIP) 1A Fast Recovery Rectifier (Optional) Total For Components Table 1) Parts List for the Simple H-Bridge In the previous section we discussed the individual parts of this design, here they are gathered together in a single circuit. You should notice that the opto-isolator LEDs are connected to three wires labeled "FWD", "REV", and "ENA*." These wires deserve a bit of explanation. Processor Interface The FWD, REV, and ENA* lines are the interface between the bridge and the microprocessor. You will notice their is no "ground" signal. When you connect these pins to a BASIC stamp or a 68HC11 or whatever, combinations of 1's and 0's on the line turn on different pairs of transistors. The following table lists all possible combinations of input. FW D RE V ENA * Description Each Total $0.70 $1.40 $0.70 $1.40 $0.23 $0.23 $0.23 $0.23 $0.23 $0.23 $1.31 $1.31 $0.05 $0.20 $5.00 2 511-TIP107 2 511-TIP102 1 652-4608X-102-10K 1 652-4608X-102-560 1 652-4608X-102-1K 1 551-PS2501-4 4 625-1N4933

1 1 1 1 0 0 0 0

0 0 1 1 1 1 0 0

0 1 0 1 0 1 0 1

Turn on upper left source and lower right sink. (go forward) Disable lower right sink. When fed a PWM signal the bridge modulates the "forward" current through the motor. Turn on both lower left sink and lower right sink, shorting the motor. This causes a rotating motor to stop rotating so this mode is called "Braking." Disable both lower sinks. When fed a PWM signal the bridge modulates the "braking" of the motor. Turn on the upper right source and lower left sink. (go backward) Disable lower left sink. When fed a PWM signal the bridge modulates the "reverse" current through the motor. Turn off all sources and sinks. "Coast" motor is not engaged at all. Turn off all sources and sinks in a different way, same effect though.

This works because the processor pins become a connection to ground when they are outputting a logic 0. Thus when FWD is 1 and ENA is 0, the lower right sink is getting current from FWD which it is returning through the pin connected to ENA. At any given time the pin must be able to supply enough current to turn on two LEDs and when set to zero sink the current of two LEDs. With the 560 ohm resistors and a 5V processor like the PIC this is not a problem. From the data sheet on the opto-isolator, each LED has a forward voltage drop of 1.2V, so (5 - 1.2) / 560 is 6.8mA per LED or 14mA of load total. The PIC is specified to be able to drive 20mA. You can replace the 560 ohm resistors with 680 ohm resistors to reduce the current through the LEDs still further. However the LED voltage drop can be as high as 1.4V and the PIC's operating voltage can be as low as 4.5V, in that condition with 680 ohm resistors you would only put 4.5mA into each LED which is below the 5mA specified in the datasheet. The 560 ohm resistor is the better choice as it maintains sufficient margin. So why go to all this trouble? The interface as designed gives you access to all of the interesting combinations of sinks and sources enable, while not allowing for any "illegal" states. An illegal state in a full quadrant H-bridge (4 inputs, one for each quadrant) is one that turns on the upper source and lower sink on the same side. This combination causes a direct short circuit to be created between the battery terminals (not good!) and usually causes one or both of the transistors that are on to go up in smoke. Further, as the low end PIC chips like the PIC16F628 has a single hardware PWM line, this lets you connect that line to the bridge and a couple of GPIO pins to the FWD and REV lines to get a hardware PWM on the bridge. Just remember not to go above 2.5Khz unless you replace the opto-isolator with a faster one. Summarizing So before we solder it all together, lets analyze the design and try to characterize its performance. This will give us confidence that this H-bridge will meet the requirements we need it to meet, and we won't be surprised by it not working on us.