C12 · Lesson 22 · Driving loads
Transistor switches, inductive kicks and switching losses
A pin supplies 3.3 V and about 8 mA: enough for an LED, nowhere near enough for a relay, a motor, a solenoid or a strip of lights. Between the pin and the load goes a transistor, and choosing it is where firmware meets power electronics. The pin must turn the transistor fully on, the transistor must not overheat, and when an inductive load turns off, the current it was carrying has to go somewhere, or the voltage spike destroys the transistor within a few switchings.
- A GPIO pin (0 to 3.3 V) drives a logic-level MOSFET switching a 12 V relay coil (100 mH, 100 Ω). The scope shows the drain and the gate.
- RD is in series with the flyback diode. At 1 Ω, the diode catches the coil's current when the switch opens, and the drain only rises to about 12.9 V: the supply plus the diode's drop.
- Raise RD to 1 MΩ, as if the diode were missing: the coil drives the drain up until the MOSFET avalanches at 60 V, every cycle.
Predict
A 12 V, 100 Ω relay coil is switched by an NPN transistor with a minimum β of 100. Can a GPIO pin's 8 mA drive it into saturation reliably?
The coil takes 120 mA. For a hard, reliable saturation the base gets = 6 mA, well below the β limit, through Ω. A logic-level MOSFET needs no steady gate current at all, which is why it's the usual choice above a few hundred milliamps.
Name it
Low-side switches
The load goes from the supply to the transistor, and the transistor to ground, so the pin drives it relative to ground.
- BJT: saturate it with a forced β of 10 to 20: , . It drops , about 0.2 V.
- MOSFET: choose a logic-level part whose is specified at = 2.5 or 3.3 V; a part rated at 10 V may barely turn on from 3.3. It drops .
Losses
Conduction: for duty . Switching: each transition passes through full voltage and full current at once for , so
The transition takes about , the gate charge over the gate current. A pin's few milliamps make microsecond transitions; a gate-driver chip's amperes make nanosecond ones.
Inductive loads
A coil's current can't stop instantly. With nowhere to go, drives the switch's voltage up until something breaks down. A flyback diode across the coil carries the current around it, and it decays with . That's slow: a relay releases late. A Zener in series with the diode lets the coil's voltage reach , so the current falls faster:
to fall from to , at the price of the switch seeing .
H-bridges
Four switches let a motor run both ways. If both switches on one side conduct together, they short the supply: shoot-through. Drivers add dead time between turning one off and the other on.
Worked example
Size the base resistor for a 12 V, 100 Ω relay coil switched by an NPN from a 3.3 V pin with an 8 mA limit.
Show the solution
- Collector current.
- Base current. A forced β of 20 needs 6 mA, under the pin's limit.
- Base resistor. It drops 2.6 V: so 430 Ω.
- Why not drive it harder. A forced β of 10 would need 12 mA, more than the pin can give.
Answer 430 Ω, for a forced β of 20.
Worked example
A MOSFET with 2 µs of total transition time switches 2 A at 12 V and 20 kHz. Compare its switching loss with its conduction loss at 50 mΩ and 50% duty.
Show the solution
- Switching loss.
- Conduction loss.
- Compare. Driven straight from a pin, the switching loss dominates, five times the conduction loss.
- With a gate driver. A driver making 10 ns transitions, 20 ns in all, cuts the switching loss to 4.8 mW.
Answer 0.48 W of switching loss against 0.1 W of conduction loss, so switching dominates, about five times larger.
Worked example
A relay (100 mH, 100 Ω, 120 mA) releases when its current falls to 30%. How long does release take with a plain flyback diode, and with a 24 V Zener in series?
Show the solution
- Time constant.
- Diode only.
- With the Zener. Here 3.6 V is 30% of the coil's 12 V: four and a half times faster.
- The cost. The drain sees 36 V instead of about 13.
Answer 1.20 ms with a plain diode, and 0.27 ms with the 24 V Zener, which puts 36 V on the drain.
Check
An NPN switches a 12 V, 50 Ω coil from a 3.3 V pin, with a forced β of 20.
(a)
What collector current flows (ignore )?
Write units the way you normally would: 1.5 mA, 1500 µA and 0.0015 A are the same answer.
(b)
What base resistor?
Check
A MOSFET with = 20 mΩ carries 2 A at 75% duty; its package has 60 °C/W to ambient.
(a)
What is its conduction loss?
Write units the way you normally would: 1.5 W, 1500 mW and 0.0015 kW are the same answer.
(b)
How far above ambient does it run?
Check
A switch turns 1 A at 24 V on and off at 100 kHz, with 2 µs per transition.
(a)
What is its switching loss?
Write units the way you normally would: 1.5 W, 1500 mW and 0.0015 kW are the same answer.
(b)
What fraction of the power it switches is that?
Check
A MOSFET's gate needs 15 nC and is driven with 8 mA.
(a)
About how long is each transition?
Write units the way you normally would: 1.5 ns, 1500 ps and 0.0015 µs are the same answer.
(b)
What gate-drive power does 20 kHz switching at 3.3 V take?
Check
A coil of 100 mH and 50 Ω carries its full 12 V current when the switch opens; it releases at 30% of that.
(a)
How long does release take with a plain flyback diode?
Write units the way you normally would: 1.5 ms, 1500 µs and 0.0015 s are the same answer.
(b)
And with a 48 V Zener in series with the diode?
(c)
What peak voltage does the switch see then?
Check
A pin-driven MOSFET has = 30 mΩ at 3.3 V gate drive and carries 0.5 A continuously.
(a)
What voltage does it drop?
Write units the way you normally would: 1.5 mV, 1500 µV and 0.0015 V are the same answer.
(b)
What does it dissipate?
Check
An H-bridge's firmware switches the high side off and the low side on in the same instruction. What goes wrong?
Check
Write switch_losses(v, i, rds, qg, ig, f, d): a MOSFET switching current i at voltage v, on-resistance rds, gate charge qg driven by ig amperes (each transition takes qg/ig), at f Hz and duty d. Return (conduction, switching, total) in watts.
Python 3.14 with numpy and matplotlib, running in your browser. Tab indents; press Esc and then Tab to move on.
Explain why
Why does turning off a relay coil without a flyback diode damage the transistor that switches it?
The coil stores energy in its magnetic field, ½LI², and its current can't change instantly: . When the transistor opens, the current tries to drop to zero in nanoseconds, so the coil generates whatever voltage it takes to keep it flowing. That voltage climbs past the supply until the transistor's junction breaks down and the coil's energy is dumped into it as an avalanche, every time it switches off. A diode across the coil gives the current a path around the coil instead, so the voltage stays at the supply plus a diode drop while the energy decays harmlessly in the coil's own resistance.
Practice
Keep practicing
9 kinds of problem on this topic, dealt one at a time with new numbers every time, for as long as you like.