Diodes, Transistors, and MOSFETs as Switches
A MOSFET is not on or off. It is a resistor whose value you set with the gate — and in between, it is a heater.
🎯 By the end you'll understand
Why a diode's forward drop is a curve rather than a constant, what Schottky buys and what it costs in reverse leakage, and why an inductive load without a freewheel path generates kilovolts. How to size a BJT's base resistor for hard saturation, and why that base current disqualifies BJTs from Beacon's sleep budget. What Vgs(th) actually means (it is measured at a quarter of a milliamp, and it is not the voltage that turns a FET on), why Rds(on) is meaningless without the Vgs it was measured at, and what a half-enhanced FET does to a 12 V motor and to itself. Low-side versus high-side switching, the P-channel gate-drive trap that a 3.3 V GPIO walks straight into, and how that trap produced one of Beacon Rev A's three known defects.
KEY INSIGHTBetween on and off there is a region where the transistor absorbs the power instead of passing it
The motor turned slowly. The firmware was writing a solid logic 1 to the gate. The FET was rated for thirty-three amps and it was too hot to touch at less than one.
This is a bench scene that repeats itself somewhere in the world every day. Someone needs to switch a 12 V motor from a 3.3 V microcontroller pin. They find an N-channel MOSFET in a drawer — an IRF540N, a genuinely excellent part — and read the headline: 100 V, 33 A, 44 mΩ on-resistance. All three numbers dwarf the requirement. They wire the source to ground, the drain to the motor, the gate to a GPIO, and the motor barely turns while the transistor's tab climbs past a hundred degrees. Nothing has failed. The datasheet is not lying. The part is doing precisely what its physics requires, because the 44 mΩ was specified at Vgs = 10 V, and at 3.3 V on the gate this device is not a switch at all — it is a current source, dropping most of the supply across itself and converting the difference into heat. The whole lesson lives in the gap between "the gate is high" and "the channel is fully enhanced".
A MOSFET has three regions. Cutoff: Vgs below threshold, no channel, no current, no heat. Triode (ohmic): the channel is strongly enhanced and the device behaves as a resistor of value Rds(on), dissipating I²·Rds(on) — small, which is why we like switches. Saturation: the channel is only weakly enhanced, so the device limits current to roughly K(Vgs − Vth)² regardless of what the load asks for, and it takes the entire remaining supply voltage across itself. In saturation the dissipation is Vds · Id, which can be hundreds of times the on-state loss. The gate voltage decides which region you are in. Rds(on) printed on the front page is only available at the Vgs printed beside it — and Vgs(th), the number people reach for instead, is defined at a drain current of about 250 µA, which is nowhere near "on".
CORE CONCEPTDiodes: the drop is a curve, and the leakage is the price
A PN-junction diode conducts one way. The relationship between current and forward voltage is exponential — the Shockley equation, I = IS(eV/(n·VT) − 1), where VT = kT/q ≈ 25.9 mV at room temperature and n is an ideality factor between 1 and 2. You will never solve that equation at the bench. What you will use are its two consequences:
- The forward drop moves about 60 mV per decade of current (for n ≈ 1). A 1N4148 sits near 0.72 V at 5 mA and near 1.0 V at 100 mA. "0.7 V" is a useful shorthand and a bad specification.
- At a fixed current, the forward drop falls about 2 mV per °C. A diode is therefore a decent temperature sensor and a poor voltage reference, and a diode carrying serious current in a hot enclosure drops noticeably less than it did on your bench.
Schottky versus silicon
A Schottky diode replaces the PN junction with a metal-semiconductor junction. Two things change, and they are a package deal.
| Property | Silicon PN (1N4148 class) | Schottky (BAT54 class) | Why you care |
|---|---|---|---|
| Forward drop, small signal | ≈ 0.72 V at 5 mA | ≈ 0.32 V at 10 mA | Series loss in a supply path, and headroom |
| Forward drop, 100 mA | ≈ 1.0 V | ≈ 0.7–0.8 V | The advantage shrinks at high current |
| Reverse leakage at 25 °C | tens of nanoamps | a few microamps | Beacon's whole sleep budget is 8 µA |
| Reverse leakage, hot | tens of microamps at 150 °C | tens to hundreds of microamps at 100 °C | Leakage roughly doubles every 10 °C |
| Reverse recovery | nanoseconds (fast switching types) | essentially none (majority carrier) | Switching converters, rectifiers |
Read the leakage row twice. The reflex "always use a Schottky, it drops less" is fine on a mains-powered board and can be a design error on a battery product. A BAT54 blocking reverse current on Beacon's battery path, at a few microamps of reverse leakage, would consume a meaningful fraction of an 8 µA sleep budget — and it gets worse in a warm enclosure. This is a genuine trade, not a ranking, and the correct question is always "which loss does my circuit actually pay?"
The freewheel diode, and the arithmetic that makes it non-negotiable
An inductor resists changes in current: V = L · di/dt. Open a switch carrying current through a relay coil and di/dt is enormous, so the coil generates whatever voltage it needs to keep the current flowing — which means whatever voltage it takes to break down your switch. Put numbers on it: a small relay coil of 100 mH carrying 50 mA, interrupted in 1 µs, wants V = 0.1 × 0.05 / 10⁻⁶ = 5,000 V. It will not reach five kilovolts, because something breaks down first, and that something is your transistor.
The fix is a diode across the coil, cathode to the positive end, so that when the switch opens the current continues to circulate through the diode and decays through the coil's own resistance. It is called a freewheel, flyback, catch, or snubber diode depending on who taught you. Two practical notes: a plain diode makes the current decay slowly, so the relay releases slowly, and adding a series resistor or a Zener in the freewheel path speeds the release at the cost of a higher (but bounded and known) voltage. And integrated drivers often have these diodes built in — check before adding your own, but never assume.
Series diode: one part, foolproof, costs Vf × I forever. At Beacon's 40 mA active current a Schottky's 0.4 V costs 16 mW and, worse, eats 0.4 V of headroom from a cell that is already down at 3.0 V when empty. Series P-channel MOSFET: source to the battery, drain to the load, gate pulled to the load side through a resistor. When the battery is the right way round, the gate sits far below the source and the FET turns on hard; the drop is I × Rds(on), which at 40 mA through a 60 mΩ part is 2.4 mV. When the battery is reversed, the gate cannot get below the source and the FET stays off, with the body diode also pointing the safe way. It costs one FET, one resistor, and one Zener if the input can exceed the gate's rating. Beacon's canon uses the PMOS, and the reason is the 0.4 V of headroom, not the 16 mW.
HOW IT WORKSBJTs: current-controlled, and that is the whole problem
A bipolar junction transistor amplifies current: the collector current is roughly β times the base current, where β (hFE) is somewhere between 30 and 300 depending on the part, the current, and the individual device. To use one as a switch you deliberately overdrive the base so that the transistor runs out of collector voltage and enters saturation, where Vce collapses to 0.1–0.3 V and stays there.
Sizing the base resistor
Do not use the datasheet's β. Use a forced beta of 10 to 20 — that is, deliberately supply ten to twenty times more base current than the minimum, so that every device in the batch is saturated even at the temperature and current where β is worst. Worked example, a 2N3904 switching 50 mA from a 3.3 V GPIO:
- Choose forced β = 10 → Ib = 50 mA / 10 = 5 mA.
- Rb = (Vdrive − Vbe) / Ib = (3.3 − 0.7) / 5 mA = 520 Ω → use 470 Ω, giving 5.5 mA.
- Check the GPIO: 5.5 mA is within the ESP32-C3's per-pin capability but it is not free, and it is drawn the entire time the switch is on.
- Check the transistor: Vce(sat) ≈ 0.3 V at that current, so P = 0.3 × 0.05 = 15 mW. Fine in SOT-23.
The circuit works and has worked for sixty years. Now look at it from Beacon's side of the table. The whole sleep budget is 8 µA. A BJT switch consumes 5.5 mA of base current continuously while conducting — six hundred times the entire sleep budget. Even if the switch is only on during the 45 ms active window, that base current adds 5.5 mA × 0.045 s / 60 s ≈ 4 µA to the average, half the sleep budget, for a switch. A MOSFET's gate takes current only while it is being charged: a nanocoulomb-scale gate charge at 60 wakes per hour is a rounding error.
That is the practical rule, and it is not about BJTs being obsolete. BJTs remain excellent where you need a small, cheap, robust level shift or a current source, where Vbe's predictability is an asset, or where you are switching something rarely and the base current does not matter. They are disqualified from battery-powered continuous switching, and that is the only reason Beacon has none.
DEFINITIONMOSFETs: what the datasheet's two headline numbers really mean
An enhancement-mode MOSFET has no channel until you make one. Raise the gate above the source (N-channel) and an inversion layer forms under the oxide, connecting drain to source. The gate itself is a capacitor onto an insulator — it takes charge to change its voltage and essentially no current to hold it. That is the entire reason MOSFETs took over from BJTs in switching.
Vgs(th) is not the turn-on voltage
The threshold voltage on a datasheet is defined by a test condition, and that condition is almost always a drain current of about 250 µA (sometimes 1 mA) at Vds = Vgs. It is the gate voltage at which the device begins to conduct a quarter of a milliamp. It tells you where the channel starts to exist. It tells you nothing about whether the device can carry an amp with a low drop.
It also has an enormous spread. An IRF540N specifies Vgs(th) as 2.0 to 4.0 V — a factor of two between two parts from the same reel. That spread is why a design that "worked on the prototype" can fail on half the production units: the prototype happened to have a low-threshold device. And threshold voltage falls with temperature, roughly 2–5 mV/°C, so a device that is marginally off when cold can be leaking when hot.
Rds(on) is a function, quoted at one point
The on-resistance is specified at a stated gate voltage, a stated drain current, and 25 °C. A useful first-order model is that the channel resistance is inversely proportional to the overdrive voltage Vov = Vgs − Vth:
Rds(on)(Vgs) ≈ Rspec · (Vgs,spec − Vth) / (Vgs − Vth)
Take the IRF540N: 44 mΩ at Vgs = 10 V, and take a typical Vth of 3.0 V. The specified overdrive is 7.0 V. Drive it from a 3.3 V GPIO and the overdrive is 0.3 V, so the model predicts 44 mΩ × 7.0 / 0.3 ≈ 1.03 Ω — twenty-three times worse — and only if the device stays in the triode region at all, which at any real current it does not. This is where the second half of the model matters.
The three regions, and why saturation is the dangerous one
With Vov = Vgs − Vth:
- Vov ≤ 0 — cutoff. Drain current is leakage, nanoamps to microamps. No heat. The load gets nothing.
- Vds < Vov — triode. Id = K(2·Vov·Vds − Vds²). Near the origin this is a resistor of value 1/(2K·Vov) = Rds(on). The load gets nearly the full supply; the FET dissipates I²R.
- Vds ≥ Vov — saturation. Id = K·Vov², independent of Vds. The device is a current source. Whatever supply voltage the load does not use, the FET takes — and P = Vds · Id.
Note the vocabulary trap: "saturation" in a MOSFET means the current has saturated (constant current, high Vds) — the opposite of what "saturation" means for a BJT, where it denotes the fully-on, low-Vce state. Textbooks disagree with each other about which word to use for the fully-on MOSFET region; "triode", "ohmic", and "linear" are all in circulation for it, and "linear" is also used by power-electronics people to mean the current-source region. When someone says a FET is "in linear mode", ask which one they mean.
Logic-level versus standard-level
A logic-level MOSFET is one whose Rds(on) is specified at Vgs = 4.5 V or lower — often 2.5 V or 1.8 V for modern parts. A standard-level MOSFET is specified at 10 V. The distinction is not a marketing tier; it is a real difference in gate-oxide thickness and doping, and it is visible in the datasheet as the gate voltage in the Rds(on) row. If the only Rds(on) figure on the front page is at 10 V, that part is telling you it was not designed for your microcontroller.
For 3.3 V systems the practical test is stricter than "logic level": look for a part with an Rds(on) specification at Vgs = 2.5 V, because the ESP32-C3's output high is not exactly 3.3 V, the rail droops during the burst, and you want margin over the worst-case threshold. An AO3400A specifies about 28 mΩ at 4.5 V and about 40 mΩ at 2.5 V, with a threshold of 0.65–1.45 V. Drive that from 3.3 V and it is genuinely on, with margin, at every device in the distribution.
SEE ITMOSFET switch bench — find the heater
Pick a real part, drive its gate from a real rail, hang a real load on it, and the bench solves the load line for the operating point, then iterates the thermal loop until the junction temperature settles. Threshold voltage is a slider over the datasheet's own min/typ/max range, because that spread is the difference between a prototype that works and a production run that does not. Datasheet figures are representative of these part numbers; confirm against the revision in your hand before committing a design.
Things to try. Start at the defaults and confirm the boring case: an AO3400A on a 3.3 V gate switching 1 A into a 3.3 V rail is a switch, a few tens of milliwatts, barely warm. Now change only the part to the IRF540N and read every number again — the region flips to saturation, the load gets a fraction of what it asked for, and the dissipation jumps by more than an order of magnitude. Change the gate drive to 10 V and it becomes the best part on the list, which is the honest summary of the IRF540N: an excellent transistor being asked to do a job it was never specified for. Next, put the IRF540N back on 3.3 V, set the load supply to 12 V, and drag the threshold slider from minimum to maximum: at the low end of the distribution the circuit half-works and at the high end it does nothing at all, which is precisely the failure mode where one prototype works and the next ten do not. Then switch to the 2N7002 at 1 A and notice that the operating point is impossible for a different reason — that part's continuous current rating is a hundred and change milliamps, and the bench says so. Finally choose the AO3401A P-channel with a 4.2 V load supply and a 3.3 V drive rail, and read the last verdict row: that is Beacon Rev A's leaking battery divider, computed rather than described.
COMPARISONLow side, high side, and the gate you cannot reach
Low-side switching with an N-channel FET
The load sits between the supply and the drain; the source goes to ground. Because the source is at a fixed, known 0 V, Vgs is simply the gate voltage, and a 3.3 V GPIO gives you a genuine 3.3 V of gate drive. This is why low-side N-channel is the default and why nearly every beginner circuit uses it.
The cost is that the load's low side is not ground when the switch is off — it floats up to the supply through the load. For an LED or a motor, fine. For anything with a shared ground reference — a sensor, an I2C device, an audio path — the "off" state is now a mystery voltage on a node that other circuits are referenced to, and current can sneak in through protection diodes on the signal pins. That is the reason to reach for high-side switching, and it is a functional reason, not an aesthetic one.
High-side switching with a P-channel FET
The FET sits between the supply and the load, source to the supply. To turn it on you pull the gate below the source by more than the threshold magnitude; to turn it off you must bring the gate back up to the source voltage. Turning on is easy: any open-drain or push-pull output pulling to ground gives you |Vgs| = Vsupply. Turning off is the trap.
If the PMOS source is on a 4.2 V battery rail and the GPIO's high level is 3.3 V, then in the "off" state |Vgs| = 4.2 − 3.3 = 0.9 V. For a typical small logic-level PMOS with a threshold magnitude of 0.45–0.95 V, that is at or above threshold: the transistor is not off. It is weakly on, and it will pass whatever current the rest of the circuit allows. Worse, the obvious patch trades one problem for another: add a pull-up from the gate to VBAT and the gate does rest at the source, but releasing the pin then lets a 4.2 V node reach a 3.3 V pad, whose protection diode has to absorb it — which on some parts prevents the chip from entering deep sleep at all. The correct circuit is a small N-channel FET or NPN as a level shifter: the GPIO drives the small FET, the small FET pulls the PMOS gate to ground, and a resistor (1–10 MΩ on a battery product) pulls the PMOS gate back up to the source when the small FET is off. Or use a purpose-built load-switch IC, which is one part instead of three and has the level shift inside.
High-side N-channel, and why bucks need a bootstrap
You can use an N-channel FET on the high side, and it is what every synchronous buck converter does, because N-channel devices have lower on-resistance per unit area than P-channel. But the source now sits at the switching node, which rises to the input voltage when the FET is on — so to keep the channel enhanced the gate must be driven above the input supply. That requires a charge pump or a bootstrap capacitor that is refreshed each switching cycle. It is entirely standard, it is inside every buck regulator IC, and it is the reason a buck cannot hold 100 % duty cycle indefinitely without a special provision: the bootstrap capacitor needs the switch node to go low occasionally to recharge. File that; it explains a footnote you will meet in Lesson 4.2.
BEACONBeacon's two P-channel switches, and the one that leaks
Beacon has exactly two high-side switches in the canon, and they are instructive because they are the same circuit in two different places, with one of them working and the other producing a documented Rev A defect.
The RGB LED switch — on the 3.3 V rail, and therefore fine
The canon's WS2812B-2020 is an addressable LED with a controller inside it, and that controller draws current whenever it is powered, even when it is displaying black — commonly around 0.6–1 mA per device. Against an 8 µA sleep budget that is roughly a hundred times the entire allowance, so telling the LED to be dark is not enough; it must be unpowered. A P-channel MOSFET between the 3.3 V rail and the LED's supply pin does that, with its gate on GPIO10 and the WS2812B's data on GPIO5 (canon pin map). The switch is active-low and the gate is driven directly — no level shifter, because the source sits on the 3.3 V rail and the GPIO's high level is that same 3.3 V rail, so the off-state |Vgs| is zero and the FET is genuinely off. A 100 kΩ pull-up on the gate holds it off through reset and through sleep, which is the pull-resistor habit from this lesson's third warning applied to the one switch that must never come on by accident. The on-state |Vgs| is 3.3 V, comfortably above a logic-level PMOS's threshold, and at 20 mA through 60 mΩ the drop is 1.2 mV. Nothing here is subtle, and that is the point: the circuit is safe because the two rails are the same rail.
The battery-divider switch — on the cell, and therefore Rev A's defect
Lesson 1.3 established the circuit: a 2 × 1 MΩ divider across the cell with a 100 nF hold capacitor, connected only during a measurement by a small PMOS on GPIO1, sensed on GPIO4 (ADC1_CH4), so that it does not drain the battery for the other 59.75 seconds of every minute. The PMOS's source must be on the battery, because that is what is being measured — and the battery reaches 4.2 V when full. Drive that gate straight from a GPIO whose high level is 3.3 V and the off-state |Vgs| is 0.9 V, inside the threshold band of every small logic-level PMOS on the market. The FET does not turn off. Because the divider is 2 MΩ, the leak is not dramatic: the current is set by the divider, not the FET, at 3.7 V / 2 MΩ ≈ 1.85 µA. The canon records the Rev A post-mortem as "the battery divider leaks 1.8 µA more than planned", and this is the mechanism, to within rounding.
Why the product survived it, and what Rev B does
1.85 µA against an 8 µA sleep budget is a 23 % overrun on sleep — but sleep is only 8 of the 38 µA average, so the average becomes about 39.9 µA and the projected life falls from roughly 3.0 years to roughly 2.9. The six-month requirement (R1) is untouched. The reason the defect is survivable is the resistor value chosen in Lesson 1.3 for exactly this reason: with a 22 kΩ divider the same gate-drive mistake would have leaked 84 µA and ended the product in the field. Defense in depth worked. Rev B's fix is the level-shifted drive from the diagram above: a small N-channel FET pulling the PMOS gate to ground, with a 4.7 MΩ pull-up to the cell. That pull-up costs 4.2 V / 4.7 MΩ ≈ 0.9 µA, but only during the 250 ms measurement window, so its contribution to the average is 0.9 µA × 0.25 s / 60 s ≈ 0.004 µA. Two parts, the 1.85 µA leak recovered, and the failure mode removed rather than tolerated.
The reverse-battery PMOS, and why it is not a diode
The canon specifies a reverse-battery PMOS rather than a series diode. The reason is headroom, not efficiency. A LiPo is considered empty around 3.0 V; the 3.3 V rail needs its regulator's dropout below that, and Stage 4's buck can boost nothing, so every millivolt between the cell and the regulator input is life you do not get. A Schottky in that path costs 0.3–0.4 V, which pushes the effective cutoff up to roughly 3.4 V and throws away a real slice of the discharge curve. A PMOS in the same place costs 40 mA × 60 mΩ = 2.4 mV. The FET is oriented so that its intrinsic body diode also points the harmless way — source to the battery's positive terminal, drain to the load — so that a reversed cell finds both the channel off and the body diode blocking.
/* Both high-side switches are active-LOW: GPIO low turns the PMOS on. * The LED switch sits on the 3.3 V rail, so a GPIO high genuinely turns it off. * The divider switch sits on VBAT (up to 4.2 V). On Rev A the gate is driven * directly, so "off" is |Vgs| = VBAT - 3.3 V and the FET stays weakly on. * Rev B adds an NMOS level shifter; the API below does not change. */ #define BEACON_LED_PWR_N GPIO_NUM_10 // high-side PMOS gate, 100k pull-up #define BEACON_VDIV_EN_N GPIO_NUM_1 // divider PMOS gate; sense on GPIO4 static void beacon_enter_deep_sleep(void) { gpio_set_level(BEACON_LED_PWR_N, 1); // LED rail off: saves ~0.8 mA gpio_set_level(BEACON_VDIV_EN_N, 1); // divider off: saves 1.85 uA -- on Rev B /* A floating gate in deep sleep is an undefined switch. Hold the pad * states through sleep or the FETs decide for themselves. */ gpio_hold_en(BEACON_LED_PWR_N); gpio_hold_en(BEACON_VDIV_EN_N); gpio_deep_sleep_hold_en(); esp_deep_sleep_start(); }
For every high-side switch on the board, write two numbers next to the symbol: |Vgs| when on and |Vgs| when off. The first must be comfortably above the worst-case threshold magnitude; the second must be zero, or at least far below the minimum threshold across the datasheet's spread and across temperature. Beacon's LED switch passes trivially (3.3 V on, 0 V off). The Rev A divider switch fails the second test on inspection, in five seconds, with no simulation. Almost every gate-drive bug in embedded hardware is caught by writing down the off-state gate voltage, and almost nobody does it.
WEAKNESSWhere this bites
The instinct is reasonable: "my gate drive is 3.3 V, the threshold is 2.0 V, therefore it turns on." It is wrong because Vgs(th) is measured at roughly 250 µA of drain current. At threshold the device conducts a quarter of a milliamp; you want it to conduct amps. The correct selection criterion is the presence of an Rds(on) specification at or below your gate drive voltage, and the correct margin check is against the datasheet's maximum threshold, not its typical, at your highest operating temperature. If a part's front page only quotes Rds(on) at 10 V, it is not a candidate for a 3.3 V system regardless of what its threshold row says.
A half-enhanced FET is a current source. At 20 mA the difference between "fully on" and "current-limited at 90 mA" is invisible: the LED lights, the FET dissipates perhaps 30 mW, and everything looks correct. The circuit then goes into production driving a motor or a heater and the same transistor at 1 A drops three volts and burns three watts. Bench-testing a switch at a fraction of its design current does not test the switch, it tests the LED. Test at the real current, or at least compute the operating point at the real current before believing the bench. This is also why the failure so often escapes review: it works, right up until it is asked to do the actual job.
A MOSFET gate is a capacitor onto an insulator. Left unconnected it holds whatever charge it was last given, drifts with leakage and coupling from neighbouring traces, and can sit anywhere between the rails. Two habits fix this. First, every gate driven by a microcontroller gets a pull resistor to its safe state, so the FET is off during reset, during programming, and during the seconds before firmware runs. Second — the one that catches people on the ESP32 family specifically — GPIO states are not automatically maintained through deep sleep; the pads are released unless you hold them. A switch you carefully turned off before sleeping can turn itself back on the moment the core powers down, and you will only find it by measuring sleep current, which is Lesson 1.7's job.
KEY INSIGHTHow this connects
- Voltage, Current, Resistance, and Power (1.2) — P = V·I is the whole diagnosis here. The half-on FET is a component being asked to dissipate power it has no package for, and the thermal derating logic is identical to the resistor's.
- Passive Components for Real (1.4) — the same "the number came with conditions" discipline. Rds(on) at 10 V is exactly like 10 µF at 0 V: a true measurement of a condition your circuit does not satisfy.
- Reading a Datasheet Without Getting Fooled (1.6) — the Vgs(th) min/max spread and the conditions on the Rds(on) row are the next lesson's entire subject, demonstrated here on one part family.
- Measurement (1.7) — a gate that turns itself on during deep sleep is only visible as sleep current, and measuring 8 µA correctly is harder than it sounds.
- Protection: ESD, Reverse Polarity, Overcurrent, and Inrush (2.6) — the reverse-battery PMOS is drawn properly there, with the gate Zener and the inrush question.
- Switching Things: Driving LEDs, Motors, and Relays (2.7) — gate charge, switching losses, gate resistors, and the level shifters this lesson sketched become real circuits.
The reflex to carry forward is small and cheap: whenever you see a transistor used as a switch, ask what the gate voltage is in both states, and what the datasheet's on-resistance was measured at. Two questions, ten seconds, and they catch the majority of switching failures in embedded hardware before a board exists.
GLOSSARYKey terms introduced
- Schottky diode
- A metal-semiconductor diode with a lower forward drop and no reverse-recovery charge, paid for with reverse leakage that is orders of magnitude higher than a silicon PN diode's and that roughly doubles every 10 °C.
- Freewheel (flyback) diode
- A diode across an inductive load that gives the coil's current a path when the switch opens, preventing the L·di/dt voltage spike from destroying the switch.
- Vgs(th)
- The gate-source voltage at which a MOSFET conducts a small stated test current, usually about 250 µA. Marks where the channel begins to exist; it is not the voltage at which the device is usefully on. Specified as a wide min/max range and falls with temperature.
- Rds(on)
- Drain-source on-resistance, specified at a stated Vgs, drain current, and 25 °C. Scales roughly as 1/(Vgs − Vth) and rises with junction temperature by roughly 0.4–0.7 % per °C.
- Triode (ohmic) region
- The MOSFET region where Vds < Vov and the device behaves as a resistor. The only region in which a MOSFET is a good switch.
- Saturation region (MOSFET)
- The region where Vds ≥ Vov and drain current is roughly constant at K·Vov². The device is a current source and dissipates Vds·Id. Note the opposite meaning of the same word for BJTs.
- Logic-level MOSFET
- A MOSFET whose on-resistance is specified at a gate voltage of 4.5 V or less — often 2.5 V or 1.8 V. The practical requirement for direct drive from a 3.3 V microcontroller pin.
- Body diode
- The intrinsic diode formed between a MOSFET's body and drain. Conducts in the reverse direction regardless of gate state, which decides the orientation of a reverse-polarity or load-disconnect FET.
ACTIVE RECALLCheck your understanding
Answer in your own words first, then reveal.
1An IRF540N (Rds(on) = 44 mΩ at Vgs = 10 V, Vgs(th) = 2.0–4.0 V) is driven from a 3.3 V GPIO to switch 1 A into a 12 V motor. Estimate what happens for a device at the typical threshold, and say what changes at each end of the threshold spread.›
Take Vth = 3.0 V typical, so overdrive Vov = 0.3 V. From Rds(on) = 44 mΩ at Vov,spec = 7.0 V, the transconductance parameter is K = 1/(2 · 0.044 · 7.0) ≈ 1.62 A/V². The saturation current is K·Vov² = 1.62 × 0.09 ≈ 0.15 A. The motor asked for 1 A and gets about a seventh of it, so it barely turns. The transistor holds essentially the whole 12 V, dissipating roughly 12 × 0.15 ≈ 1.8 W — in a TO-220 with no heatsink at about 62 °C/W, that is 110 °C of rise, so a junction near 135 °C. That is the room-temperature hand calculation, and it is optimistic: as the junction heats, Vth falls by a few millivolts per degree, so the overdrive grows, the saturation current rises, and the dissipation rises with it. The widget above iterates that loop and settles nearer 3 W and 200 °C — well past the 150 °C limit. The hand calculation tells you the part is in the wrong region; the thermal iteration tells you how fast it fails. At the minimum threshold of 2.0 V the overdrive is 1.3 V, saturation current is about 2.7 A, and the device drops into triode and works — this is the unit your prototype had. At the maximum threshold of 4.0 V the gate is below threshold and the motor does not move at all. Same schematic, same firmware, three completely different products.
2Why does Beacon use a P-channel MOSFET rather than an NPN transistor to switch the RGB LED's supply, given that the LED only draws about 20 mA?›
Two separate reasons, and the current is not one of them. First, gate current versus base current. A BJT switching 20 mA with a forced beta of 10 needs 2 mA of base current continuously while on. Beacon's active window is 45 ms per minute, so even a well-behaved BJT adds 2 mA × 0.045 / 60 ≈ 1.5 µA to the average — nearly 20 % of the entire sleep budget, spent on the act of holding a switch closed. A MOSFET gate needs charge only at the transitions, which at 60 wakes an hour is negligible. Second, high side versus low side. The job is to remove power from the WS2812B entirely, because its internal controller draws roughly 0.6–1 mA whenever it is powered even while displaying black. That requires interrupting the supply, which is a high-side switch, and a PNP on the high side has the same base-current problem plus a Vce(sat) drop of a couple of hundred millivolts against the PMOS's 1.2 mV. On a mains-powered board either choice is fine; on an 8 µA budget only one is.
3A colleague wants to save two parts by driving the battery-divider PMOS's gate directly from a GPIO, arguing that the leak is only 1.85 µA and the product still meets its six-month requirement. Give the strongest counter-argument and the honest case for their side.›
Counter-argument, in three parts. First, the leak is not the only symptom: with the PMOS partially on, the 4.2 V cell is connected through the channel to a GPIO whose high level is 3.3 V, so current also flows into the pin's protection structure. On some parts that prevents the deep-sleep state from being entered at all, turning a 1.85 µA overrun into a 5 µA one or worse — and it is a symptom that only appears with a fully charged battery, which is exactly the condition a bench test with a 3.7 V supply never reproduces. Second, the number is only small because Lesson 1.3 chose 1 MΩ resistors for unrelated reasons; the circuit is relying on an accident. Third, it is a defect that must be documented, explained to every future maintainer, and re-checked on every board revision, and that is a permanent tax. Honest case for their side: two parts on a 35 × 25 mm board (R8) is real area, real cost against R5's IDR 150,000 target, and two more things to place and solder at 25 units. The measured overrun costs about a month of the projected three-year life and nothing against the actual requirement. If the schedule is the binding constraint, shipping Rev A with this documented and fixing it in Rev B — which is exactly what the canon records — is a defensible engineering decision rather than a mistake. The mistake would be not knowing.
4You measure Beacon's sleep current at 8 µA on the bench, deploy 25 units, and three of them show roughly 800 µA. The firmware is identical. What class of cause does this lesson point at, and how would you confirm it?›
The pattern — identical firmware, a minority of units, a current roughly a hundred times the budget — points at a gate whose state is not deterministic across the device distribution or across the sleep transition. Three candidates in order of likelihood. (a) A pad not held through deep sleep: if the LED-supply PMOS gate is released when the core powers down, the gate floats and some units' FETs sit partially on, which would deliver roughly the WS2812B's own quiescent draw — close to the observed number. This is deterministic per unit because it depends on that unit's threshold and leakage, which is exactly why only some units show it. (b) A missing pull resistor on a gate, so the state during and after reset depends on the individual pad's leakage. (c) A threshold outlier on the divider PMOS — but that one is current-limited by the 2 MΩ divider to under 2 µA, so it cannot explain 800 µA, and ruling it out by arithmetic rather than by probing is the point. To confirm: on a failing unit, measure the LED rail voltage during sleep (it should be at zero; if it is near 3.3 V the switch is on), then measure the gate voltage itself. If the gate is somewhere between the rails rather than at one of them, it is floating and the fix is gpio_hold_en() plus a pull resistor. Lesson 1.7 covers how to measure microamps and millivolts on a sleeping board without the instrument changing the answer.