Hardware Academy
PCB Design

Active components: regulators, op-amps, MCUs

LDOs vs bucks, op-amp rules, and what a microcontroller needs around it on a board.

Day 4 · 50 min

After this lesson

  • You can choose between an LDO and a buck converter by computing the losses.
  • You can apply the op-amp golden rules to gain and comparator circuits.
  • You can list the support circuitry a microcontroller needs.

Regulators, op-amps and the MCU on a board

Two ways to step a voltage down

A linear regulator (LDO) is a variable resistor in series with the load: an error amplifier compares the output with a reference and adjusts a pass transistor until Vout is right. Everything the transistor drops becomes heat, P = (Vin − Vout) · I, and the efficiency is just Vout / Vin. From 12 V to 3.3 V at 500 mA that is 8.7 V × 0.5 A = 4.35 W at 27.5% efficiency, inside a part the size of a fingernail whose junction rises 60 to 90 °C per watt. Its virtues are real: two capacitors, no switching noise, and 60 dB or more of supply rejection. The dropout voltage, the smallest Vin − Vout it can regulate, is 1.1 V typical and 1.3 V maximum at 0.8 A for the classic AMS1117 (Advanced Monolithic Systems datasheet) and 100 to 300 mV for modern PMOS parts.

A buck converter never lets a resistive element carry the difference. A switch connects the input to an inductor for a fraction D of each period, and the inductor and output capacitor average the pulses, so Vout = D · Vin: 3.3 V from 12 V needs D = 27.5%. While the switch is on, the inductor current rises by (Vin − Vout) · D / (L · f); while it is off, the low-side switch or a diode carries the current as it falls. Efficiency is typically 85 to 95% at moderate load, so the same 0.5 A job wastes about 0.2 W. The price is a 100 kHz to 2 MHz switching frequency, an inductor, input and output capacitors, a few millivolts of ripple, EMI, and a layout that needs care, because the loop of input capacitor and two switches carries amps in nanoseconds.

Boost, buck-boost and choosing

A boost converter makes Vout = Vin / (1 − D) and draws more current than it delivers: a 3.7 V cell producing 5 V at 1 A with 90% efficiency pulls 1.5 A. A buck-boost or SEPIC handles inputs that cross the output, as a Li-ion cell does around 3.3 V. The decision rule is simple. If (Vin − Vout) · I exceeds a watt or two, use a switcher. If the rail feeds a noise-sensitive analog circuit, follow the switcher with a low-noise LDO. If the drop is small and the current low, an LDO is cheaper and quieter.

Block diagram of a linear regulator that turns 4.35 watts into heat next to a buck converter with a switch, inductor and controller that wastes about 0.2 watts for the same 12 to 3.3 volt, 0.5 amp jobLinear regulator (LDO): the difference becomes heat12 V inPass transistora variable resistorLoad3.3 V, 0.5 AError ampVrefVout = 3.3 Vheat = (12 − 3.3) V × 0.5 A = 4.35 Wη = 3.3 / 12 = 27.5%Iin = IoutBuck converter: chops the input, then averages it12 V inHigh-side switchon for D = 27.5%L stores energySWLow-sideor diodeCoutLoad3.3 V, 0.5 AVout = D · VinPWM controllercompares Vout with Vreffeedback from Voutη ≈ 90%heat ≈ 0.2 W
The same 12 V to 3.3 V, 0.5 A job. The LDO converts 4.35 W into heat; the buck converter moves energy through an inductor and wastes about 0.2 W.

Op-amps and comparators

An op-amp is a differential amplifier with enormous open-loop gain, so with negative feedback two golden rules hold: the output does whatever it takes to make the two inputs equal, and the inputs draw no current. The non-inverting amplifier then has gain 1 + Rf / Rg and the inverting one −Rf / Rin. A 10 mΩ shunt carrying 3 A drops 30 mV, and Rf = 99 kΩ with Rg = 1 kΩ gives a gain of 100, so an ADC sees 3.0 V. Respect the gain-bandwidth product: a 1 MHz part such as the LM358 has only 10 kHz of bandwidth at a gain of 100, and its few millivolts of input offset become hundreds of millivolts at the output. A comparator is the same triangle without feedback: the output slams to a rail depending on which input is higher. Add positive feedback for hysteresis, use a real comparator such as the open-collector LM393 (with a pull-up) instead of an op-amp, and never leave an input floating.

A microcontroller on a board

A bare MCU needs five things. Power: 100 nF at every supply pin, bulk capacitance per rail and a filtered analog supply. Reset: a 10 kΩ pull-up on the reset or EN pin, often with a capacitor and a button to ground. Boot configuration: strapping pins at defined levels, such as IO0 and IO12 on an ESP32. Clock: the internal RC oscillator is good to a few percent, but USB, CAN and accurate timing need a crystal, which uses the MCU's inverting amplifier plus two load capacitors, C1 = C2 = 2 · (CL − Cstray), about 10 pF for an 8 pF crystal with 3 pF of stray capacitance. An oscillator module is a powered clock with a buffered output; it costs more but removes the tuning. Programming: a header for SWD (SWDIO, SWCLK, reset, 3V3, ground), or UART plus the boot pins, or USB.

Interfaces and protection

For level shifting, a 5 V signal into a 3.3 V pin needs a resistor divider (1 kΩ over 2 kΩ for a slow signal such as the HC-SR04 echo), a BSS138 MOSFET stage with pull-ups for I²C, or a translator IC such as the 74LVC245. TVS diodes clamp surges and ESD: pick a standoff voltage above the working voltage, for example an SMBJ12A (12 V standoff, about 20 V clamp) on a 12 V input, place it at the connector, and give it a short, wide path to ground. Connectors carry the current and the abuse: a JST-XH is rated about 3 A per pin, and keyed housings stop reversed plugs. Add a P-FET or diode for reverse-battery protection on any supply that people plug in by hand.

Interactive: the buck converter in slow motion

Buck converter in slow motion

The duty cycle sets Vout = D · Vin. Watch the two switches alternate, the inductor current ramp up and down around the load current, and what the same job would cost as heat in an LDO.

Synchronous buck converter: 12.0 volts in, 3.30 volts out at 0.50 amps, high-side switch on+−S1 high side ONS2 low side offSWL 22 µHiL 0.39 AVout 3.30 VCout22 µF0.50 AloadVin 12.0 VOn: Vin pushes current through S1 and L, so iL ramps upWaveforms over three switching periods: switch node voltage, inductor current and output rippleSwitch node SW (V)120Inductor current iL (A)0.610.39average = load 0.50 AOutput ripple, zoomed and AC-coupled+1.42 mV−1.42 mVcentred on Vout = 3.30 V02 µs4 µs6 µs
Output voltage D · Vin
3.30 V
Inductor ripple ΔIL
0.218 A

44% of the load current

Peak inductor current
0.61 A

Isat must exceed this

Output ripple (ideal C)
2.47 mV

ΔI / (8 · f · Cout)

LDO from 12.0 V: (Vin − Vout) · I4.35 W

efficiency 27.5%

Buck converter: conduction + switching + gate + quiescent190 mW

efficiency 89.7%

LDO junction rise
+261 °C

at 60 °C/W

LDO verdict
Thermal shutdown

about 286 °C at 25 °C ambient

Heat saved by the buck
4.16 W
Switching share of buck loss
47%

grows with frequency

Inductor
Switching frequency
Loss model: 180 mΩ and 120 mΩ switches, inductor DCR by value, 60 ns edges, 40 nJ gate charge per cycle and 1.5 mA quiescent current. The LDO figure ignores ground-pin current and assumes 60 °C/W for a SOT-223 on a modest copper pad. Below half the ripple current the inductor current dips negative: that is forced-PWM operation.

In practice

Practice

Pick the regulator for the robot's logic rail

The robot's logic rail is 3.3 V at 500 mA for an ESP32 and its sensors, fed from a 12 V, 2000 mAh pack. (a) Compute the LDO's dissipation, efficiency and junction rise at 60 °C/W. (b) Estimate the loss of a buck converter at 90% efficiency, and the current each option draws from the pack. (c) Estimate the run time for each. (d) Choose an inductor for 30% ripple at 500 kHz.

Answer: show the worked solution
text
(a) LDO     P = (12 - 3.3) x 0.5 = 4.35 W,  efficiency 3.3 / 12 = 27.5%
            junction rise = 4.35 W x 60 °C/W = 261 °C  -> far past 150 °C shutdown
(b) Buck    Pout = 3.3 x 0.5 = 1.65 W,  Pin = 1.65 / 0.9 = 1.83 W,  loss = 0.18 W
            pack current: LDO 500 mA, buck 1.83 W / 12 V = 153 mA
(c) Runtime LDO 2000 mAh / 500 mA = 4 h,  buck 2000 mAh / 153 mA = 13 h
(d) Inductor dI = 0.3 x 0.5 = 0.15 A
            L = (12 - 3.3) x 0.275 / (0.15 x 500 kHz) = 31.9 µH -> choose 33 µH
            peak = 0.5 + 0.075 = 0.575 A -> Isat of 1 A or more
            ripple voltage = 0.15 / (8 x 500 kHz x 22 µF) = 1.7 mV

The LDO is not just inefficient here, it is impossible: 261 °C of rise means thermal shutdown within seconds. The buck costs an inductor and a careful layout but runs about 3.3 times longer on the same pack. If the ADC needs a very quiet 3.3 V, put a small LDO after a 5 V buck rail, where it only dissipates 1.7 V × 0.5 A = 0.85 W at full load.

Real-world scenario

Real-world scenario

The robot reboots every two minutes and the regulator is too hot to touch

A robot controller runs from a 3S Li-ion pack that sits near 12 V. An AMS1117-3.3 in a SOT-223 turns that into 3.3 V for an ESP32 with Wi-Fi, a few sensors and status LEDs, which together average about 200 mA. The board boots and drives normally for roughly two minutes, then resets; half a minute later it boots again and the cycle repeats. The regulator burns a finger, yet the pack voltage looks perfectly healthy on the meter.

Symptoms

  • The board resets about two minutes after power-up, restarts roughly 30 seconds later, and repeats.
  • The 3V3 rail collapses to 0 V at the moment of failure while the 12 V input stays steady.
  • The SOT-223 is too hot to touch, and a thermal camera reads about 140 °C on its tab.
  • The failure arrives later in a cold room and sooner inside the closed enclosure.

Interview questions

screenWhen would you choose an LDO over a buck converter, and when the reverse?
I decide with numbers. An LDO loses (Vin − Vout) × I as heat and has an efficiency of Vout / Vin, so 12 V to 3.3 V at 500 mA wastes 4.35 W, while a buck at about 90% wastes under 0.2 W. An LDO wins when the dropout is small, the current is low, noise matters or space is tight: it needs one or two capacitors, has no switching ripple, and gives 60 dB or more of supply rejection. A buck wins whenever the voltage drop or the current is large, because efficiency, heat and battery life then dominate. A common answer is both: a buck brings the rail close to the target and a low-noise LDO cleans it up for ADCs and sensors.
screenState the two golden rules of op-amps and use them to derive the gain of an inverting amplifier.
With negative feedback the output moves until the two inputs are at the same voltage, and the inputs themselves draw no current. In an inverting amplifier the non-inverting input is grounded, so the inverting input sits at 0 V, a virtual ground. The input current is Vin / Rin and, because none of it enters the op-amp, all of it flows through Rf, which gives Vout = −Vin × Rf / Rin. For example Rf = 100 kΩ and Rin = 10 kΩ give a gain of −10. The same two rules give 1 + Rf / Rg for the non-inverting amplifier.
screenWhat does a microcontroller need on a board to start up reliably?
First, clean power: a 100 nF capacitor at every supply pin plus a bulk capacitor, and a filtered supply for the analog pins. Second, a defined reset and boot configuration, for example a 10 kΩ pull-up on the reset or EN pin, often with a capacitor and a button to ground, and the correct level on the boot-mode strap pins. Third, a clock: many MCUs run from an internal oscillator, but USB, CAN and accurate timing need a crystal with the right load capacitors. Finally, a way in: a programming and debug header such as SWD with SWDIO, SWCLK, reset, 3V3 and ground, or a USB-UART bridge with auto-reset.
screenHow do you connect a 5 V sensor output to a 3.3 V microcontroller input?
It depends on direction and speed. For a slow one-way signal such as the HC-SR04 echo, a resistor divider like 1 kΩ over 2 kΩ turns 5 V into 3.3 V for two cheap parts. For a bidirectional bus such as I²C I use a MOSFET level shifter, a BSS138 per line with pull-ups on both sides, or a dedicated translator. For fast push-pull signals I use a buffer such as a 74LVC245 powered at 3.3 V. Before any of that I check whether the MCU pin is 5 V tolerant, and many are not, including the ESP32.
deepA buck converter makes 3.3 V from 12 V. What is the duty cycle, and what sets the inductor value and the output ripple?
In continuous conduction the ideal duty cycle is Vout / Vin = 3.3 / 12 = 27.5%. The inductor current ramps by (Vin − Vout) × D / (L × f) over the on-time, so L sets the ripple current, and I usually target 20 to 40% of the load current. For 0.5 A at 500 kHz that is about 0.15 A, so L = 8.7 V × 0.275 / (0.15 A × 500 kHz) = 32 µH and I would pick 33 µH. The output ripple voltage is roughly ΔI / (8 × f × Cout), which is 1.7 mV for 22 µF, plus ΔI × ESR. Finally I check that the saturation current exceeds the peak, Iload + ΔI / 2, with margin.
deepWhy does a buck converter layout matter so much, and which loops and nodes do you worry about?
The switching edges carry amps in nanoseconds, so any loop inductance turns into voltage spikes and radiated noise. The most critical is the hot loop: input capacitor, high-side switch and low-side switch back to the input capacitor. I make it as small as possible with the capacitor right at the IC pins on the same layer. Next is the switch node, which swings the full input voltage with fast edges, so I keep its copper as small as the inductor pad allows and keep the feedback divider and other sensitive traces away from it. I give the converter an unbroken ground plane, take the feedback trace from the output capacitor, and follow the datasheet's reference layout.

Quiz

1. An LDO drops 12 V to 3.3 V while supplying 0.5 A. How much power does it dissipate?
2. What is the efficiency of an ideal LDO with 12 V in and 3.3 V out, ignoring its ground-pin current?
3. A buck converter makes 3.3 V from a 12 V input. In continuous conduction, what duty cycle does it run?
4. In a buck converter, what happens to the inductor ripple current when you raise the inductance at the same frequency and duty cycle?
5. A non-inverting op-amp stage uses Rf = 99 kΩ and Rg = 1 kΩ. What is its gain?
6. Why must a 5 V HC-SR04 echo pin not be wired straight to an ESP32 GPIO?
7. A boost converter turns a 3.7 V Li-ion cell into 5 V at 1 A with 90% efficiency. About how much current does it draw from the cell?

References and further reading

Where the ideas in this lesson come from, and what to read next. Books are the standard texts; papers are the original sources; standards are what employers work to.

  1. Documentationfree online

    Espressif Systems (2025). ESP32 Hardware Design Guidelines: Schematic Checklist. docs.espressif.com.

    Read: A real reset and boot-strap checklist for the MCU-on-a-board section.

  2. Documentationfree online

    Advanced Monolithic Systems (2012). AMS1117: 1A Low Dropout Voltage Regulator (datasheet). advanced-monolithic.com (free PDF at advanced-monolithic.com/pdf/ds1117.pdf, http only).

    Read: Page 3 for dropout and quiescent current, page 4 for why it needs a 22 µF tantalum output capacitor.

  3. Book

    Paul Horowitz and Winfield Hill (2015). The Art of Electronics. Cambridge University Press, 3rd edition.

    Read: The voltage-regulator and op-amp chapters.

  4. Bookfree online

    Hank Zumbahlen (editor), Analog Devices (2008). Linear Circuit Design Handbook. Newnes.

    Read: The op-amp basics chapter.

  5. Book

    Ned Mohan, Tore M. Undeland and William P. Robbins (2003). Power Electronics: Converters, Applications, and Design. Wiley, 3rd edition.

    Read: The DC-DC converter chapter for the buck converter in the viz.