High power loads and modular design

back to main tutorial page

Dr Nathan Scott & Dr Hiroyuki Kagawa · July 2002

As your confidence with the AVR increases, you may wish to start controlling large electrical loads such as big motors, or even electrical appliances that run on mains power.

Mains power safety and responsiblity

Let me say up front that only a licensed electrician can build and turn on any circuit that runs on mains power. There are good reasons for this law, which exists in every civilised country. Up till now we have worked only with low voltages such as 5 or 15V DC. These voltages are very safe to work with (I won't say harmless because, believe it or not, injuries are still possible). Mains voltages, on the other hand, can cause instant death if you touch them. All it takes is one wrong connection or one loose wire, and death, fire, or serious injury could result.

We have to distinguish here between the process of design and the process of construction. Anyone can design a mains electric circuit, after all, a plan by itself can do no harm. However only licensed electricians can build the design and plug it in. I want to tell you how to control mains power, but you must not try to breadboard or build the circuits that do so. If you need such circuits you will have to draw the circuit diagram and then pay a licensed electrician to build them for you. He or she will give you a result which is sealed in an insulated box and offers the same level of safety as commercial electrical devices such as televisions, washing machines etc.


Switching a mains appliance on using a relay

Have you ever wondered how the motors inside a washing machine are controlled? The controller may be a microprocessor such as the AVR, but it must switch on motors which run at mains voltages. A commonly used solution to this problem is to use an electromechanical device called a relay. A relay has a coil and an iron magnetic circuit inside it. When current flows in the coil, the iron parts become electromagnets and this makes them move toward each other. This motion causes a switch to close. In this way a small control current (through the coil) can control a very large load current. Because the load is connected by a mechanical switch, a very large current may pass and it may flow through the load either way (AC is OK).

Figure 1: A typical relay. This one has a 24V DC coil (although it would probably work on less) and can switch mains power at about 15A.

The AVR can only deliver about 40mA to a load directly. This might be enough to energise the coil of a small relay. However it is probably a good idea to use a single bipolar or FET transistor to drive the relay as shown in Figure 2.

Figure 2: Using a relay for low speed, high power switching

The resistor protects the AVR from high voltages which could happen if the transistor fails. It also protects the base of the transistor from damage if the signal input is accidentally driven too high. The input impedance of the base of the transistor is quite high and very little current will flow into the base, so there will be only a small voltage drop across the 10k resistor.

When the signal input is driven high by the AVR, the transistor B "turns on" and the resistance from C to E becomes quite low. It isn't quite a short-circuit, it will have a resistance of a few hundred ohms. The resistance is low enough that a large current flows from the coil supply, through the coil, to GND. This energises the electromagnet and switches the relay on.

A mechanical spring (not shown in the figure) opens the relay switch when the coil current is switched off again.

Relays are quite complex electro-mechanical devices (see Figure 2) but because they are mass-produced in huge numbers, the cost is very reasonable. The one shown in Figure 1 was worth about $USD3 in 2002.

Relays can switch a large machine on or off at a frequency of perhaps once or twice per second. They are not intended for high speed switching use, so they can't be used for PWM style speed control. If you wish to control a large motor using PWM, a powerful version of the H-bridge circuit is needed.


A more powerful reversible motor driver

Consider the h-bridge circuit from the PWM tutorial, when we wish to drive the motor at low speed. The PWM fraction will be close to 50%. This means that half of the time the motor is being driven at full power clockwise, and the other half of the time it is driven at full power counterclockwise. It is not an efficient way to produce zero speed!

The previous h-bridge circuit design also requires that the bridge be driven at VCC, which is of course limited to 5V (6 maximum). Some small motors can accept much higher voltage inputs and this may be desirable in your application.

The previous h-bridge circuit is also limited to a maximum output current of about 500mA. If you wish to drive a motor about the size of your fist, you will need more current, perhaps 4A.

All this is to say, let's try to build a better version of the h-bridge circuit, so we can build bigger, more efficient and more powerful robots.


Driving a large transistor using a small one

Bipolar transistors are the "common or garden" variety. They are very cheap and a huge variety are available. Physically small transistors can only carry small amounts of current, they are called "signal" transistors. Physically large transistors can carry more current and are called "power" transistors. If you are feeling nervous about all these transistors, you might want to revisit the optocoupler tutorial.

Transistors are like valves for water or hydraulic fluid. When you adjust the control of the valve - the handle - it changes the resistance to the flow. A small valve, like the ones in your garden, can be easily turned on by hand: only a small torque is required to turn the handle. A large valve, such as you might find in a water processing plant, has a large handle which would require a large torque to turn. It is the same with transistors. A small transistor can be turned on by a small signal, but can only allow a small current through. A big transistor needs a larger "signal" to turn it on. As usual there is an established solution to this problem: use a small transistor to turn a big one on:

Figure 3: A small transistor driving a large one (sometimes called a cascade).

You might like to breadboard the circuit of Figure 3 and check that you understand how it works. The signal at A turns on transistor B, so its resistance becomes low. This pulls point D LOW, which in turn switches on the power PNP transistor (remember, PNP transistors need a LOW signal to switch on). When the PNP power transitor switches on, it pulls its collector C HIGH very strongly. This is effectively the same as switching on power to the load. By looking at the data sheet for the power transistor 2SB834 we see that it can deliver a current of up to 3A and it can survive a supply voltage of 60V. That means it could (in theory) deliver 60 X 3 = 180 Watts of power to the load! However the data sheet for the 2SB834 suggests that if we try to drive it at the maximum current and maximum voltage, the transistor itself will need to dissipate 30W of heat. So in fact we could only ever drive a 150W load.


Heatsinks

That brings us to the important matter of heatsinks: 30W of heat is not a trivial amount, and it is appearing in a very small plastic package, only about 10mm square and 5mm thick.

Overheating and failure of transistors is a serious problem. The solutions are

  1. Design conservatively i.e. make sure that the biggest transistor only runs at about half its rated current; and
  2. Install all the big transistors on heatsinks.

A heatsink is just a piece of metal - usually aluminium - which is physically clamped onto the transistor so that heat is conducted away from the transistor. If you build your transistor circuits into aluminum boxes, it is a good idea to mount the transistors on the box walls as they can conduct quite a lot of heat away. Care is needed so that the electrical connections to the transistors are correct and sometimes we must attach the transistors using materials that conduct heat but do not conduct electricity (insulating washers).

[Possible expansion needed here: show typical power transistor cases and mounting arrangements]


A half-bridge circuit based on bipolar transistors

A full H-bridge can be made from two half-bridges of the kind shown in Figure 4:

Figure 4: 50V, 3A half H-bridge circuit with dual logic inputs.

  • The optocoupler on the signal input means that the AVR driving the circuit will be well isolated from the 50VDC power supply.
  • Transistor A amplifies the output of the optocoupler to the point where it can directly drive the Power NPN transistor base.
  • Transistor D does two things for us:
    • It allows the base of the Power PNP to float very high when it is turned off (essential so that the PNP transistor will definitely turn off!).
    • It inverts the signal at B, very much as the 74LS14 inverter did in our previous H-bridge circuit. This means that a HIGH signal at B can turn both Power transistors on at the same time.

You might like to build the circuit of Figure 4. If you do, be sure to check each of the transistors as you go so that you are sure that they are working, that you have the correct type (PNP or NPN) and that you know what the three legs are (E, C or B). I use the tests in Figure 5 on all transistors before putting them into a circuit like Figure 4:

Figure 5: Tests for bipolar transistors. VCC should be 5 to 10 Volts.

Testing an NPN transistor

When switch A is connected to GND, the base B is driven LOW. This means that the transistor is OFF and the resistance from C to E is HIGH. If the resistance from C to E is much higher than 1k (and if the transistor is working properly, it will be), then test point A will measure close to VCC.

When switch A is connected to VCC, base B is driven HIGH. This turns the transistor ON and the resistance from C to E becomes LOW. Test point A should be pulled to a low voltage near GND.

We say

  • "when the switch pulls B LOW, C floats HIGH" and
  • "when the switch pulls B HIGH, C is driven LOW"

Testing a PNP transistor

When switch B is connected to VCC, the transistor is switched OFF and the resistance from E to C is HIGH. Therefore test point B should be near GND voltage.

When switch B is connected to GND, this turns the transistor ON and the resistance from E to C becomes LOW. Test point B will be pulled to near VCC i.e. a HIGH voltage.

We say

  • "when the switch pulls B LOW, C is driven HIGH" and
  • "when the switch pulls B HIGH, C floats LOW"


Advice for breadboarding the circuit of Figure 4.

Test each stage of the cascade as you build it.

While you are breadboarding transistor circuits, it is a good idea to always use a resistor on the base (B) terminal of each transistor. I call these "buffer" resistors. They should be 10k for a signal transistor and 1k for a power transistor. Buffer resistors will protect your transistors from excessive base current, which can damage them.

When I first built transistor circuits I did not know about using buffer resistors and had some very frustrating experiences. I would build a circuit and turn it on but it would not work. The reason was often that one or more transistors had burned out because of too much base current. The only way to recover when this happened was to remove and test each transistor using the approach of Figure 5 until the dead one(s) were found.

When you have your transistor circuit working, you can experiment by replacing the "buffer" resistors with wires. If the circuit continues to work and nothing overheats or burns out, then OK. If there is any problem, put the buffer resistors back. They waste a small amount of power, but sometimes that cannot be avoided.

Never allow a transistor to connect the VCC and GND lines directly. There should always be some resistance in the path from VCC to GND.

When you have constructed the circuit, do not connect the motor immediately. Instead, test that everything is working using the following sequence:

  1. With no motor connected, turn on the power and watch the circuit carefully for at least 30 seconds. By "watch" I mean use all your senses to check whether any part is overheating. Smell the air over the circuit. Watch for small curls of blue smoke that may come out of the components. Test for overheating components by touching them briefly (a hot component can burn you before you can jerk your hand away). Listen for crackling or popping sounds. Be ready to switch the power off if any bad thing happens.
  2. Connect a 1k resistor as a test load (shown in blue in Figure 4). Connect a voltmeter or oscilloscope to the + motor output terminal. Turn on the power and check that changes to the input signal (5V DC) cause the expected change in the voltage at the motor terminal. What is the expected change? Think about what the PNP power transistor does when it "switches on". What will this do to the voltage at your test point?
  3. Remove the + test load resistor.
  4. Now perform the same test for the &endash; terminal. This will require a load resistor from the &endash; terminal to VCC. There should be a strong voltage change, from nearly GND to nearly VCC, when you change the input signal.
  5. Remove the &endash; test load resistor.
  6. Now connect the motor. When the control signal is HIGH, the motor should run and should have a lot of torque. When the control signal is LOW, the motor should stop.

If all is well, you are in a strong position to build a full bridge circuit. You will need to build a copy of your first circuit, which will be used to drive the motor in the opposite direction:

Figure 6: Schematic circuit diagram for a full H-bridge made out of two circuits like Figure 4.

Warning

The circuit of Figure 6 is driven by two logic level input signals. This means that there are four possible combinations of input:

CW signal

CCW signal

Effect

0

0

Motor is stopped

VCC

0

Motor rotates clockwise

0

VCC

Motor rotates counterclockwise

VCC

VCC

Power input is shorted to Power GND through all 4 Power transistors. If the power supply can deliver enough current, this could cause thermal failure of two or more of the Power transistors. NEVER ALLOW THIS TO HAPPEN.

Because of the seriousness of the problem of incorrect drive signals, we must implement several protective mechanisms:

  1. The power supply should have a current limit circuit breaker of some kind. Recently a useful, inexpensive device called a polyswitch has become available. It looks like a capacitor but it is actually like a circuit breaker. When the current through the polyswitch exceeds its design value, it suddenly changes to an open circuit. The change is reversible and if the circuit is switched off the polyswitch will recover and the circuit will work again.
  2. We should not rely on software alone to control the two input signals. We should implement a hardware system that will guarantee that the forbidden state (both signals high) cannot happen.

Have a look at the circuit of Figure 7. Don't panic, it's not as bad as it looks.

Figure 7: NAND interlock

First of all, note that the wire labelled "Signal GND" in Figure 4 has been replaced with something called "Signal Common". This wire is now at VCC. Because the NAND inverts its output signals, we must now drive the optocouplers in a new way:

Figure 8: Explanation of "Signal Common" in Figure 7.

Now consider the functions of the 74LS00 Quad NAND gate. NAND is a boolean logic operation. If we have two logic values A and B, then the NAND gate will compute NOT (A and B), which in C language notation would be !(A && B) for booleans and ~(A & B) for bits. The 74LS00 Quad NAND gate has four independant NAND circuits inside it.

The NOT function of the gate can be used by itself, this is illustrated in Figure 7(D) where one of the pins of the gate is fixed to logic high. That NAND circuit has become a NOT circuit. Pin 8 of the chip is now always the logical opposite of pin 9. If we follow the green line back to the AVR we see that it is called the direction signal. This will be a signal sent by the AVR when it wants the motor to run clockwise.

The two NAND gates A and B have a common input which is the PWM signal from the AVR. The other input to each gate is determined by the direction signal as explained above. The result of this arrangement is like a distribution system for the PWM signal. If the direction signal is HIGH, the PWM signal is directed to half bridge 2; if it is LOW, the PWM signal goes to half bridge 1.

Remember, "signal" now has a new meaning, refer to Figure 8! The safe (off) input condition for the full bridge is now "BOTH INPUTS HIGH". The forbidden condition is now "BOTH INPUTS LOW". The way the NAND gate is wired ensures that the new forbidden condition can't happen.

The NAND gates are being used as an interlock, which means a connecting link that prevents forbidden system states.


Modularity and encapsulation

The circuit of Figure 7 (and Figure 8) works. However as designers we have a responsibility to make things that not only work, but which work well, and which are unlikely to cause unexpected problems. There is a design flaw in the circuit of Figure 7, it is to do with the level of modularity of the parts of the system.

The AVR has an executive role: it runs a program and makes decisions about when the motor should go clockwise or counterclockwise, and what the PWM fraction should be. We can call it the Logic Module. The H-bridge has a different role. Electrical engineers would call it a "grunt" circuit because it is there to supply significant power to a load, it is like a big sledgehammer. We will call it the Power Module.

Consider Figure 9:

Figure 9: Schematic view of the circuit of Figure 7

Suppose that we wish to make money by selling system components rather than complete systems. The chips we have been using, such as the AVR and 74LS00, are examples of system components, and it is clear that someone has been making money by selling them. Each component that is for sale must have an interface, a connection to the outside world. The interface of an electronic device is the main topic of its data sheet.

Our Power Module might make a good component for sale. But what would we write in its data sheet? At the moment we would have to write a big warning! Because at the moment it is still possible to damage the Power Module by putting the forbidden signal combination (both LOW) on the input terminals! I think that the user of the module would not like to see such a warning, they would think that we (the designers) had not been very thoughtful.

We can improve the modularity of our design by rearranging the system components like this:

Figure 10: Improved modularity: the interlock is now part of the power module

The NAND interlock is now an integral part of the Power Module. In practice it would be installed on the same circuit board as the transistors. This design improvement protects the Power Module from incorrect input. Whatever signals are put in (at the plugs on the interface, the dotted line in Figure 10), the Power Module will function correctly.

The design of Figure 10 does have the disadvantage that we must now generate a regulated 5V signal for the NAND chip on the Power Module circuit board. But, you say, "why not run another wire from the Logic Module and give the Power Module a small amount of regulated 5VDC?". If electrical isolation is not important then this would be an acceptable approach. However I am trying to train you in good practices. Trust me, we must try to get complete electrical isolation between the Logic Module and the Power Module, this will improve safety, reliability, modularity, customer relations and marketability. Isolation means we cannot have any direct electrical connections that bypass the optocouplers between the modules.

It is easy and inexpensive to generate a small amount of regulated 5V power within the power module, this can be done with a LM317L minuature voltage regulator worth only a few cents.

You may have noticed that I have swapped the function of the input pins on the Power Module again. If we are going to redesign the circuit to match Figure 10, we may as well also make it so that the input to the power module is GND rather than some obscure thing like "Signal common". Everyone understands what GND is!


Exercises

  • Figure 10 is not a complete detailed design. See if you can flesh it out into a full circuit diagram. Breadboard your circuit! Don't give up on it until you have it running, this is important for your self-confidence.

back to main tutorial page


Dr Nathan Scott · nscott@mech.uwa.edu.au