Suppose you want to switch on and off a relais, LED or a small electric motor controlled by an electronic circuit or a microcontroller. The microcontroller outputs nowadays can often sink or source enough current to directly drive a LED. But when you want to switch a relais or a small electric motor, the microcontroller output needs some help in providing enough current to do so. Additionally, it is always good to take it easy on outputs. Outputs that have to work hard, cause higher temperatures. Higher temperature cause more stress and lower lifetime. Sounds familiar?
In that case, you can use a MOSFET or a transistor as a switch to “amplify” the current needed to control the relais or motor. Let's stick with transistors (aka BJT = bipolar junction transistor) and see how we can use them as a switch.
At the left in the image below, a LED is controlled directly by a microcontroller output of a 5V microcontroller. The LED has a series resistor to define and limit the current that will run through the LED. With the 270 Ohm resistor and a 5V high on the microcontroller output, the current through the LED (I_LED) will be: (5V - (LED forward voltage drop)) / 270 = (5V - 2.2V) / 270 = ca. 10 mA.
So our microcontroller output has to provide a current of 10mA (I_uC) to drive the LED. Not a problem for most of the microcontrollers.
At the right in the image below, we use a NPN transistor in a grounded emitter configurartion to switch the LED on and off, using the microcontroller output to control the NPN transistor. When the microcontroller output is high (5V), the transistor will conduct and the LED will go on. The transistor functions as a current booster for the microcontroller output. The microcontroller now provides the current to drive the base of the transistor. Because we are using the transistor as a switch, we need to provide enough base current to drive the transistor into saturation. When the transistor is in saturation, the collector-emitter voltage is minimal, being ca. 0.3V. That means that the collector will almost be at ground level when the transistor is switched on . To make sure that the transistor is driven into saturation and can provide a collector current of 10mA for the LED, we need a base current of roughly 1mA (1o times lower than the collector current that we need).
The microcontroller output voltage is 5V, so to get a 1mA base current to switch on the transistor, we need a resistor of: ((5V microcontroller output) - (base/emitter junction forward voltage)) / 0.001 = (5V - 0.6V) / 1000 = ca. 4k7.
With the transistor as a switch, we draw 1mA from the microcontroller output when switching the transistor on. The transistor will draw the necessary current for the LED from the power supply and not from the microcontroller output. Without the transistor, the microcontroller has to provide all the current for the LED, being 10mA. That is a factor 10x more than in the right scenario with the transistor.
In the case of a LED, the microcontroller would easily survive the left scenario. But when we want to drive a consumer needing much higher currents, then we need a current booster like a transistor or a MOSFET to draw current from the power supply instead of from the microcontroller or other output. Using a MOSFET is even better, because a MOSFET gate draws virtually no current and generally has a higher switching speed than a transistor.
What about the 47k resistor in the right scenario?
This high value resistor functions as a pull-down resistor that pulls down the microcontroller output, so the transistor base is not floating when the microcontroller is still booting up and the pin is not configured as an output yet. When a microcontroller pin is not configured yet, it is by default configured as an input, and thus floating. When the transistor base is floating, a very small amount of current is already enough to partially or fully switch on the transistor. The pull-down resistor provides a path to ground to redirect small parasitic currents away from the base while the microcontroller pin is still floating.
We can also use a PNP transistor as a switch:
Note that with the circuit above, the microcontroller output has to be low (0V) to switch on the PNP transistor and illuminate the LED. The microcontroller output has to be made high (5V) to switch the LED off again. With the PNP transistor, the microcontroller output has to sink the base current instead of sourcing it as in the NPN version. The 47k functions as a pull-up resistor to make sure that the base stays high when the microcontroller is still booting and didn't configure the pin as an output yet.
All the above circuits are fine when you need to switch something on and off occasionally or at a relative low repetition speed (< 100kHz). When dealing with higher frequencies, like controlling the intensity of a LED using a microcontroller PWM output, the transistor will have trouble to follow the high speeds (> 100kHz).
This is because, when driving a transistor into saturation, it takes time for the excess charge, that has accumulated in the base, to drain off and be removed. So the transistor has trouble to switch off fast enough. Switching on will be fine, but switching off will be delayed at high frequencies
The result of this is shown in the image below:
The higher the input frequency, the more it becomes obvious that the transistor has trouble to switch off fast enough to follow the input when this one goes low. We see a delay between the input going low and the transistor going out of saturation and switching off again. When the input becomes high, the transistor goes into conduction fast without any delay.
To solve this problem, you can replace the transistor with a low current MOSFET (f.e. BS170), which is much faster and won't have trouble following high speed signals.
But you can also use a trick to speed up the bipolar transistor, by preventing it from going into deep saturation. The trick is called a “Baker clamp”, named after Richard H. Baker.
In the image below, the Baker clamp is shown using either 2x standard diodes or 1x Schottky diode:
This trick avoids that the transistor goes into deep saturation by redirecting current away from the base and thus reducing base current when the transistor is being switched on.
The middle and right circuits are the easiest ones, because they only need 1x Schottky diode. Let's see what happens with the middle circuit when the input becomes high and the transistor is switched on: The collector-emitter voltage will become ca. 0.3V when the transistor is conducting. The voltage drop over the Schottky diode will be roughly 0.3V. So, the Schottky diode prevents the base-emitter voltage of the transistor from rising above 0.6V (= forward voltage of the Schottky diode + collector-emitter voltage of the transistor). The Schottky diode clamps the base voltage to 0.6V, hence the name “Baker clamp”. The clamping of the base voltage to 0.6V prevents the transistor from going into deep saturation.
When the input becomes low again, the Schottky diode is reversed biased and the transistor switches off. The transistor will now switch off much faster, since it was prevented from going into deep saturation by the clamping effect of the Schottky diode while the transistor was conducting. The otherwise excessive charge accumulation in the base was avoided.
The right circuit is the PNP version, that works the same. But the PNP transistor switches on when the input is low, making the output high, which is the opposite compared to the NPN version.
The left circuit does exactly the same, but requires 2x standard diodes to do the trick.
Another trick to speed up a transistor is putting a small value capacitor (in the range of 10pF to 100pF) in parallel with the base resistor. This enhances the switching speed of the bipolar transistor. When the input voltage goes to 0, the base voltage is swung negative by the negative going transient caused by the capacitance. This helps the base with getting rid of the excessive accumulated charge that was built up while the transistor was saturating. As a result, the transistor is able to switch off faster.
When you want to switch on and off a load that requires a relative high current, you can use a configuration that is called a “high-side switch”. The name “high-side” comes from the fact that the actual switch transistor (Q1) is connected in series with the power supply that we want to switch to the output. Q1 is a power transistor that can switch relative high currents. Q1 can also be replaced by a power P-channel MOSFET or a PNP power Darlington transistor.
How does it work?
First, let's check what happens if the input is low (0V). With 0V at the base of Q2, Q2 is cut off, so the collector of Q2 is floating. When the collector of Q2 is floating, R1 will pull the base of Q1 to the positive power supply. This means that no current can flow from the emitter to the base of Q1, since the emitter-base voltage of Q1 is 0V. Thus, Q1 can not conduct and is also cut off. When Q1 is cut off, no current will flow into the load (R3) and the output voltage will be 0V.
Now let's make the input high (5V). When the input is high, Q2 gets base current and starts conducting. When Q2 conducts, the base of Q1 is pulled to ground and current can start flowing through the emitter-base junction of Q1 and R2 to ground. So Q1 is conducting, meaning that the emitter-collector voltage drop is virtually 0V. This means that the collector of Q1 will have about the same voltage as the emitter of Q2, being 12V. So now current flows into the load and the output voltage will be 12V.
Both the Schottky diodes are added to speed up the transistors in case the circuit is used for higher speed switching, like f.e. with a 5V PWM input.
R1 is a rather low value to help Q1 switch off faster. R2 is a low value because power transistor have a lower current gain (hFE). When switching high currents (f.e. in the range of 1A to 2A), you need to provide enough base current for Q1 so it is able to carry the required collector current. R2 can have a higher value when the circuit is used to switch lower currents.
The circuit can be adapted to provide current limiting, so it doesn't run into problems when the output gets short-circuited. In the circuit below, you see how this is done. R6 is added as a current sense resistor. The value of R6 determines at which current the current limiter comes into action. When the current reaches a value of 2A, the voltage over R6 reaches 0.6V. This voltage is at the same time the emitter-base voltage of PNP transistor Q3. When the voltage over R6 reaches 0.6V, Q3 will start conducting. When Q3 is conducting, it starts pinching down the emitter-base voltage of Q1 until the current is low enough such that the voltage over R6 becomes lower than 0.6V. So we made ourselves a current sensing loop that automatically limits the current through Q1 to a safe value that lies within the power capabilities of Q1.
Now we can safely short-circuit the output without damaging Q1.
Note that Q1 will need cooling to be able to dissipate enough power when the maximum current is being drawn by the load or due to a short-circuit. When the output is short-circuited, Q1 will have to dissipate a maximum of roughly 12V × 2A = 24W of power.