Microcontrollers are great for implementing the smarts behind a given product. This article teaches you how to get around some of their major limitations.
One thing that microcontrollers cannot do is directly control anything other than, maybe, a single LED. That’s because the output drive of most microcontrollers can directly source or sink only about 10mA.
Let’s look at several ways to switch heavier loads on the low side from a typical microcontroller output. A few simple math calculations are required to determine typical component values, and these will be presented in easily accessible formats. However, this approach means that some liberties have been taken with technical rigors.
One of the simplest approaches to controlling large loads that operate on DC current is the saturated switch. The actual electronic switch element comes in two variants: Bipolar Junction Transistors, or BJTs, and MOSFETs.
Before getting to the actual switch itself, let’s define what is meant by low-side switching. Figure 1 shows this type of load switching.
Figure 1 – Low-side load switch
The switch controls the negative side of the load. This means that when the switch is open, the load is essentially floating with respect to the negative of the power supply, which is usually the ground reference in most designs.
If this type of switching arrangement is acceptable, then the low-side switch is usually the cheapest way to achieve load switching.
BJT Low-Side Switch
A BJT can be used as a load switch and come in two flavors: NPN and PNP. For low-side switching, NPN transistors are used, and for high-side switching a PNP is used.
Before getting into the actual methods, let’s define some nomenclature that are used when dealing with NPN transistors.
Figure 2 shows the pertinent voltage and current naming conventions. Starting with the current, IB is the base current, and is shown entering the base of the NPN. The same arguments apply for IC and IE, with IE shown leaving the transistor.
It can be seen that: IE = IC + IB
With the voltages, VCE is the voltage between the Collector and the Emitter, and is generally a positive value for NPN transistors. In other words, for the NPN transistor the collector voltage is generally higher than the emitter voltage.
Following the same convention, VBE is the voltage between the Base and the Emitter. It is generally positive for NPN’s.
Figure 2 – NPN BJT voltage and current
The key to understanding how a transistor can control a large load is this equation:
This says that the Collector current is the β value times the Base current. So, if β = 100, then the Collector current will be 100X the base current.
The value of β is given in the datasheet of a given transistor as hFE. For the purpose of this article, they mean the same thing. Note that it is not a fixed value for a given transistor, but varies somewhat with the value of the Collector current and temperature, but that will not matter much for the purpose of this article.
When BJT’s are used as load switches, they are used in two modes: Cutoff and Saturation. Consider figure 3 below. As previously stated, IC = βIB. So, if IB = 0, then IC must also be 0. In this state, the transistor is in cut-off mode. Note that since no current is flowing in the transistor, it isn’t dissipating any power; also in this case, VC is the same as VCC.
For the next part, assume that VCC = 10 Volts, R = 10Ω, and β = 100. Let’s see what happens when IB = 1mA. In this case, IC = 100mA, since β = 100. The voltage across the resistor is IC x RL, or 1V. This implies that VC must be 9V then, since VCC is 10V, and the voltage drop across RL is 1V. The same argument applies if IB = 2mA, and so on.
Now, what happens if IB = 20mA. According to the calculations, this implies that IC = 2000mA, or 2A. However, this cannot be the case. Since VCC = 10 Volts and RL = 10Ω, the maximum current that can flow through RL is 1A.
In this state, the transistor is said to be in saturation mode. In this mode, the transistor collector current is the maximum that the circuit conditions allow, and increasing base current will not cause it to go any higher.
So, the equation IC = βIB only holds until the transistor is saturated. Note that if, in the example just described, VCC is now increased to, say, 25V, or RL is changed to 1Ω, the transistor will no longer be saturated. Thus, saturation is defined in relation to external circuit conditions.
Finally, note that real transistors cannot be complete short circuits between their collectors and emitters unless they are defective. When a real transistor is saturated its VCE will be at a value of VCEsat. This value is given in the transistor datasheet, and is usually between 0.2V for a small transistor to more than 1V for a large one.
VCEsat is also dependent on the collector current and the temperature. This dependence is typically given as a set of curves in the datasheet.
In saturation mode, the transistor is dissipating some power, given by
However, since VCEsat is usually quite low, the power dissipation will also be low. Thus, cut-off and saturation are the two states where the transistor will be dissipating the lowest power.
Focusing now on the Base of the transistor, a quick way to set IB is to assume VBE is 0.7V. This value works for most transistors.
So, in this case, by Ohm’s Law,
If a given value of IB is needed, then RB can be calculated as:
RB = (VBB – 0.7) / IB
In practice, this IB value should be greater than this minimum by about 10% to 15% to account for device to device variations of the β value.
Figure 3 – Transistor operation
Driving a BJT from a microcontroller
What was just described is actually a low-side NPN BJT switch. If VBB were the output pin of a microcontroller, then knowing its logic high value, the required load current and the transistor β value, the value of RB can easily be calculated.
A few other things to check are to make sure that:
The calculated IB does not exceed the drive current capability of the microcontroller.
The load current does not exceed the maximum collector current of the transistor.
The power dissipation in saturation mode does not exceed the maximum power dissipation of the transistor.
The VCC voltage does not exceed the maximum VCE of the transistor.
Some safety and derating margins should also be incorporated in the above example to ensure reliable operation. About 20% is reasonable.
Driving heavier loads using a Darlington
Since the drive current of a microcontroller GPIO pin rarely exceeds 10mA, and transistor minimum β typically does not exceed around 50 for a power transistor, then the most current that can be controlled is about 500mA.
In order to be able to control higher currents, a Darlington arrangement can be employed. There are Darlingtons available in a single package, or it can be made up using two transistors as shown in figure 4.
Figure 4 – NPN Darlington
In this arrangement, Q1 is generally a low power high gain transistor, and Q2 is a high-power transistor. Assuming that the resistor R is not present for the moment, then it is seen that all the Q1 emitter current flows into the base of Q2.
As previously stated, emitter current is the sum of the Collector current and the Base current.
Since β is quite large, (β + 1) is close to β.
IE ≈ IC
Now, since IE of Q1 flows directly into the Base of Q2, that means the IC2, the collector current of Q2 is given by:
So, a small input base current can produce a large output collector current. There are a few issues to note though. First, the VBE of this composite transistor is now the sum of the VBE’s of the two transistors. This has to be taken into account when base resistor value is calculated as detailed before.
As for the resistor R, it affects the turn-off time of Q2. When Q2 is conducting, it has charges flowing into its Base. Now, when the input to Q1 goes low, Q1 turns off, and the charge stored in the Base of Q2 has nowhere to go.
It will eventually disappear by an internal process called carrier recombination, but until that happens, Q2 will remain in a conducting state. This can last from a few microseconds to tens of microseconds depending on the transistor.
In essence, the microcontroller turns off its output, but the load remains on for a bit of time after. R is used to speed up the turn-off of Q2 by bleeding off the stored base charge.
For applications such as PWM, it is thus recommended to use this resistor. For most embedded applications, values between 1KΩ and 5KΩ work fine.
R also shunts some of the base current of Q2 under normal operation. This current is (VBE2 / R), or approximately 0.7/R. To offset this current, just increase the base current of Q1. Since this Base current x β1 must be equal to 0.7/R, it follows that the base current in Q1 should be increased by (0.7/ (β1 x R)).
MOSFET Low-Side Switch
As with the BJT, a MOSFET comes in two basic flavors: N-Channel and P-Channel. The N-Channel MOSFET is similar to an NPN and is used for low-side switching. Likewise, the P-Channel MOSFET is similar to an PNP BJT, and is used for high-side switching.
The N-Channel enhancement MOSFET is relatively easy to interface to a microcontroller GPIO output pin, subject to certain conditions being met.
Figure 5 shows this type of MOSFET, together with some of its more important aspects when this device is being considered as a low-side switch.
Figure 5 – N-Channel enhancement MOSFET
When a voltage is applied between the Gate and the Source, a current will begin to flow between its Drain and Source if the voltage is higher than a threshold voltage, Vth, that is given in its datasheet.
Above that threshold value, the higher the VGS is, the larger the Drain current ID is, until VGS reaches VGSMax, again given by the datasheet. ID vs VGS is given by a set of curves in the datasheet, and, as in the BJT case, the MOSFET is saturated when the drain current is the maximum that the circuit conditions allow.
Since the MOSFET is a voltage-controlled device, it requires almost no current to keep it turned on. So, a GPIO from a microcontroller can drive a MOSFET that can then control very large currents. There is no need for Darlington arrangements. MOSFETS with low Vth that are fully enhanced at 5V Gate drive are available that can, in turn, control several amps.
Another advantage of the MOSFET over the BJT is that there is no VDSsat. Instead, when the MOSFET is conducting, the Drain-Source connection behaves like a resistor with a value of RDS that is a function of VGS, and can be a very low value for a power MOSFET.
Thus, the power dissipation of the MOSFET when it is conducting, or enhanced, is simply the value of (ID)2, where ID is the drain current, multiplied by the RDS, the same as the power dissipated in a resistor, R, passing a current, I, is given by P = I2R.
So, in many circumstances the power dissipated by a saturated MOSFET will be less than that by an equivalent BJT. This is especially true if ID is fairly high.
One thing to note is that all N-Ch MOSFETS have built-in substrate diodes as shown in figure 5. This is inherent in the construction of the MOSFET. Practically, what this means is that the Drain must be more positive than the Source; otherwise this diode will conduct.
Finally, one big issue with MOSFETs is the Gate-Source capacitance. It can be quite large for a power MOSFET – 3nF or more is not uncommon. Practically, what this means is that before the MOSFET can start conducting, this Gate capacitance must charge up first. Given that most microcontrollers can source limited current, it will take time for this capacitor to charge up.
So, when driven directly by the output of a microcontroller, the MOSFET simply cannot switch very fast. So, using the MOSFET for fast PWM will probably not work.
In such situations, a MOSFET driver such as the TI UCC27511, must be used between GPIO pin and the Gate of the MOSFET. This, of course, adds even more cost to the already higher cost of a MOSFET over a BJT.Finally, don't forget to download your free PDF: Ultimate Guide to Develop and Sell Your New Electronic Hardware Product. You will also receive my weekly newsletter where I share premium content not available on my blog.
Other content you may like:
- Introduction to Transistors
- Introduction to Switch Mode Power Supply Design
- How to Pick the Right Voltage Regulator(s) for Your Design
- Linear and Switching Voltage Regulators – An Introduction
- Introduction to Load Cell Conditioning Circuits