Op-Amps and Amplification
The ideal op-amp has infinite gain and no opinions. The real one has offset, a bandwidth limit, and rails it cannot reach.
🎯 By the end you'll understand
Why negative feedback turns a wild, high-gain amplifier into a precise, predictable one, and the two golden rules that let you analyse any op-amp circuit in your head. The three configurations you will actually use (inverting, non-inverting, buffer). The five real-world limits — input offset, bias current, gain-bandwidth product, slew rate, and output swing — and how each one turns into a measurement error at the ADC. How to pick a part for a sensor front-end from three archetypes, and why Beacon itself needs none of this while a sibling product cannot live without it.
KEY INSIGHTGain is free; accuracy is what you pay for
Amplifying a signal by 100 is a two-resistor job. Amplifying it by 100 without also amplifying the amplifier's own mistakes by 100 is the entire discipline.
The bench scenario. A learner builds a current logger for a bench supply: a 0.1 Ω shunt in the ground return, 0 to 150 mA, so 0 to 15 mV. They want 0 to 1.5 V for the ADC, so they wire an LM358 as a non-inverting amplifier with a gain of 100 and power it from the 3.3 V rail. The reading with nothing connected is 70 mA. The reading with a 1 kHz load is fine; with a 20 kHz switching load the ripple has vanished and the average looks suspiciously smooth. And nothing above about 1.8 V of output ever appears, so every current above roughly 110 mA reads as 110 mA and the top of the range simply flattens. Three separate limits, one part, one circuit — and not one of them is a wiring error.
An op-amp circuit's gain is set by resistors and is almost exactly what you calculate. Its errors are set by the part: offset voltage (a fixed wrong reading), bias current (a wrong reading that depends on your source resistance), gain-bandwidth product (a low-pass filter you did not ask for), slew rate (a speed limit on large signals), and output swing (a ceiling and a floor). Each error gets multiplied by the same gain as the signal — or worse. Design the circuit by choosing the gain; design the measurement by choosing the part.
CORE CONCEPTNegative feedback and the two golden rules
An op-amp is a differential amplifier with an enormous open-loop gain — 100 000 or more at DC. On its own that is useless: a few microvolts of difference between its inputs slams the output into a rail. The trick is negative feedback: route a fraction of the output back to the inverting (−) input. Now if the output rises too far, the − input rises, the difference shrinks, and the output comes back down. The amplifier spends its huge gain correcting its own output until the two inputs match. Everything about op-amp circuits follows from that self-correction, and it compresses into two rules you apply as long as feedback is present and the output is not stuck at a rail:
Rule 1: the output does whatever is necessary to make the voltage difference between the inputs zero. (V+ = V−, the "virtual short".) Rule 2: the inputs draw no current. Both are idealisations; the whole second half of this lesson is about how far real parts stray from them, and what that costs.
Three observations that matter at the bench. First, the non-inverting amplifier's input impedance is the op-amp's own (enormous), so it does not load a sensor; that is why it is the default for a divider or a shunt. Second, the inverting amplifier's input impedance is just Rin, which loads the source — but its inputs sit at the reference voltage, which makes it the natural choice when the signal must be summed or when the source is a current rather than a voltage. Third, the buffer has a gain of one and exists purely to change impedance: it lets a 1 MΩ divider drive an ADC that wants to see less than 10 kΩ. Lesson 2.4 shows why that need arises and when a capacitor is cheaper than a buffer.
Most op-amp textbooks draw ±15 V supplies and signals that swing around 0 V. Embedded boards have one rail (3.3 V) and ground. Two consequences. A ground-referenced signal that is always positive (a shunt in the ground return, a thermistor divider) can be amplified directly, provided the part's input common-mode range includes ground — the LM358's does, which is why that 50-year-old part is still everywhere. A signal that swings both ways needs a mid-rail reference: a divider making 1.65 V, buffered, used as the "ground" of the inverting amplifier. Forgetting this is how people build an amplifier that only reproduces the positive half of a sine.
HOW IT WORKSWhere the ideal breaks: five limits, five errors
Here are three parts that between them cover most embedded front-ends. The numbers are from their datasheets' specification tables; where a figure is "typical" it is marked, and you should design to the maximum where one is given.
| Parameter | LM358 (bipolar, 1975) | MCP6001 (CMOS, RRIO) | OPA333 (zero-drift CMOS) | Turns into… |
|---|---|---|---|---|
| Input offset voltage VOS | 2 mV typ, 7 mV max | 4.5 mV max | 10 µV max | A fixed error at the output of VOS × gain |
| Input bias current IB | tens of nA (bipolar) | ≈ 1 pA typ | ≈ 70 pA typ | A voltage error of IB × source resistance, then × gain |
| Gain-bandwidth product GBW | ≈ 1 MHz | 1 MHz | 350 kHz | A low-pass corner at GBW ÷ gain |
| Slew rate SR | ≈ 0.5 V/µs typ | 0.6 V/µs typ | 0.16 V/µs typ | A ceiling on large-signal speed: fmax = SR ÷ (2π·Vpeak) |
| Output swing (high) | V+ − 1.5 V | within ≈ 25 mV of rail (light load) | within ≈ 50 mV of rail | Clipping: everything above the ceiling reads as the ceiling |
| Input common-mode range | 0 V to V+ − 1.5 V | rail to rail | rail to rail | Inputs outside the range: output is wrong, sometimes inverted |
| Supply / quiescent current | 3–32 V, ≈ 0.5–1 mA per package | 1.8–6 V, 100 µA | 1.8–5.5 V, 17 µA typ | Battery cost of keeping the amplifier alive |
Now walk each row into a measurement.
Offset voltage: the amplifier lies by a constant
The inputs are never exactly matched; VOS is the voltage you would have to apply between them to make the output truly zero. The feedback loop cannot tell VOS from signal, so it amplifies it by the same gain. An LM358 at gain 100 can put 0.7 V of pure fiction on the output. Referred back to a 0.1 Ω shunt, 7 mV of offset is 70 mA of phantom current — and note that this current error does not depend on the gain you chose, because the signal and the offset scale together. Offset also drifts with temperature (the LM358's by several µV/°C), so calibrating it out once at 25 °C is not the same as removing it.
Bias current: the inputs do draw current, and your source resistance turns it into voltage
A bipolar input needs base current — tens of nanoamps for the LM358. Flowing through a 1 MΩ source, 45 nA becomes 45 mV of error before the gain. Through a 100 Ω shunt it is 4.5 µV and irrelevant. CMOS inputs (MCP6001, OPA333) sit at picoamps, which is why they are the parts that get to sit behind high-impedance dividers. Rule: multiply IB by the Thevenin resistance the input sees, compare to VOS, and worry about whichever is bigger.
Gain-bandwidth product: gain and bandwidth are the same budget
An op-amp's open-loop gain falls at 20 dB per decade above a few hertz, and the frequency where it reaches 1 is the GBW. With feedback, the closed-loop bandwidth is approximately GBW ÷ (noise gain), and for a non-inverting stage the noise gain is the gain. A 1 MHz part at gain 100 is a 10 kHz low-pass filter. At gain 1000 it is a 1 kHz filter. This is the brief's "gain-of-100 stage that is a 10 kHz filter in disguise": nothing is broken, but the 20 kHz ripple you wanted to see has been attenuated by 7 dB, and its phase has shifted by 63°, before the ADC ever saw it. If you need both gain and bandwidth, split the gain across two stages (two stages of 10 each give 100 kHz), or buy GBW.
Slew rate: large signals have a separate speed limit
GBW is a small-signal limit. Separately, the output can only change so fast — 0.5 V/µs for the LM358 — because an internal capacitor is charged by a fixed current. A sine of peak amplitude Vp at frequency f has a maximum slope of 2πf·Vp; when that exceeds SR the output becomes a triangle and the amplitude collapses. For a 1 V peak output, an LM358 slews cleanly to about 80 kHz; an OPA333 (0.16 V/µs) only to about 25 kHz. The zero-drift part that fixed your offset problem has just become your speed problem.
Output swing: the rails you cannot reach
The LM358's output stage cannot pull within 1.5 V of its positive supply. On a 3.3 V rail the ceiling is about 1.8 V; everything the signal does above that is flattened to 1.8 V, and an ADC with a 2.5 V range sees a lie with no warning flag. Rail-to-rail output parts (MCP6001, OPA333) get within tens of millivolts — at light load; check the swing-vs-load curve, because "rail to rail" into 2 kΩ is not "rail to rail" into 600 Ω. There is a separate input rail-to-rail specification, and a part can have one without the other.
SEE ITDesign a front-end and count the bits you lose
The signal is the bench-scenario current sense: a 0.1 Ω shunt carrying 0–200 mA, so 0–20 mV, modelled here as 10 mV of DC with a 10 mV-peak sine on top at a frequency you choose. The ADC is an ESP32-C3 input at the 11 dB attenuation setting, 12 bits over its recommended 0–2.5 V range (LSB = 0.61 mV). Pick gain, part, and supply, and watch the errors — worst-case datasheet offsets — become bits.
Try the sequence the bench story followed. LM358, ×100, 3.3 V, 1 kHz: the offset alone is 0.7 V and the ceiling at 1.8 V flattens the top of a 2 V signal. Switch to 5 V: the ceiling moves out of the way, the offset stays. Switch to the OPA333: the offset vanishes into a single LSB, and the bandwidth drops to 3.5 kHz — now drag the frequency up and watch the signal shrink and then, as slewing takes over, triangulate. The MCP6001 gets the bandwidth back and gives up the offset. There is no part on this list that wins every row, which is the actual lesson.
EXAMPLEThe worked example: 0.1 Ω, 0–200 mA, one 12-bit ADC
Do the design once on paper so the widget's numbers stop being magic.
Step 1 — decide the gain from the ADC, not from taste. The full-scale input is 200 mA × 0.1 Ω = 20 mV. The ADC's useful range at 11 dB attenuation is 0–2.5 V. The gain that fills the range is 2.5 V / 20 mV = 125. Leave headroom for offset and a rail-to-rail output that stops 50 mV short: choose ×100, so full scale is 2.0 V. That is Rf = 99 kΩ and Rg = 1 kΩ in the non-inverting circuit; in practice 100 kΩ and 1 kΩ, gain 101, close enough — but write the 101 in the firmware constant, not 100.
Step 2 — offset, worst case. LM358: 7 mV × 100 = 0.70 V at the output = 1147 LSBs of the 4096. That is 28 % of full scale, and in current terms 70 mA of the 200 mA range. The zero reading is meaningless. MCP6001: 4.5 mV × 100 = 0.45 V, 738 LSBs, 45 mA. OPA333: 10 µV × 100 = 1 mV, 1.6 LSBs, 0.1 mA. Only one of these is a current meter.
Step 3 — bias current. The source is a 0.1 Ω shunt, so even the LM358's tens of nanoamps produce nanovolts. Irrelevant here; it would dominate behind a 1 MΩ divider. Check it anyway; the habit is the point.
Step 4 — bandwidth. Gain 100 gives closed-loop corners of 10 kHz (LM358, MCP6001) and 3.5 kHz (OPA333). If the logger must see 20 kHz switching ripple, the OPA333 attenuates it to 17 % (−15 dB) and the 1 MHz parts to 45 % (−7 dB). Neither is a measurement of the ripple; both are a measurement of the filter. Fix: two stages of ×10 (corners at 100 kHz and 35 kHz respectively), or a faster part, or accept that this logger measures average current and say so in the spec.
Step 5 — slew rate. At 20 kHz with a 1 V-peak output, the required slope is 2π × 20 kHz × 1 V = 0.126 V/µs. LM358 (0.5) and MCP6001 (0.6) are fine; OPA333 (0.16) is at 79 % of its limit, which is already visible as a slightly flattened peak. At 50 kHz the OPA333 is slewing and the amplitude reading is garbage.
Step 6 — swing. LM358 on 3.3 V: ceiling ≈ 1.8 V, and with the 0.7 V offset riding underneath it, anything above 110 mA reads as 110 mA. On 5 V the ceiling is 3.5 V and the ADC's 2.5 V full scale becomes the limit instead. Rail-to-rail parts on 3.3 V reach ≈ 3.25 V and clear the 2.5 V ADC range with margin.
For a bench current logger that cares about DC and low-frequency accuracy: OPA333, ×100, 3.3 V, and a note in the spec that the bandwidth is 3.5 kHz. Errors: offset 1.6 LSB, gain error set by resistor tolerance (1 % resistors give up to ≈ 2 % of gain error — swamping the offset, so use 0.1 % for Rf and Rg if you care), quiescent cost 17 µA. For a logger that must see switching ripple: MCP6001 in two ×10 stages, calibrate the offset in firmware at zero load, and accept that the calibration drifts. The wrong answer is the one the bench story built: the part that happened to be in the drawer, at the gain that happened to be convenient, on the rail that happened to be there.
IN PRACTICEChoosing a part, and choosing not to
The selection procedure is a checklist, in this order, because each item eliminates parts faster than the next:
Supply: will it run on your rail, and does the input range cover your signal?
A 3.3 V board wants a part specified down to 2.7 V or lower and with input common-mode that includes whichever rail your signal sits against. This alone removes most classic ±15 V parts.
Precision: VOS × gain vs your LSB
Decide how many LSBs of DC error you can tolerate, divide by the gain, and that is the maximum VOS. If it comes out below 100 µV you are shopping for zero-drift (chopper) parts, which have their own tax: a small amount of switching noise near the chopping frequency (tens to hundreds of kHz) and lower bandwidth.
Speed: GBW ÷ gain vs the highest frequency you must pass, and SR vs 2πf·Vp
Both, always. A part can pass the bandwidth check and fail the slew check on large signals.
Source: IB × Rsource vs VOS
Behind anything above ~100 kΩ, CMOS inputs only.
Power: quiescent current vs the sleep budget, and whether you can shut it down
A part that draws 100 µA continuously on a device budgeted at 38 µA average has just tripled the battery drain. Either pick a micropower part, or power the front-end from a switched rail and accept its start-up settling time.
And the more important skill: recognising when the op-amp should not exist. A digital sensor (SHT40, LIS2DH12, any I2C or SPI part) has its own front-end inside, designed by people with a wafer fab; you cannot improve it from outside. A thermistor in a divider already produces a volt-scale signal; it needs a filter capacitor, not gain. Many ADCs have a programmable-gain amplifier built in. And a high-side current measurement — sensing in the positive lead rather than the ground return — needs a difference amplifier with a common-mode range above the rail, which is a different part class (current-sense amplifiers such as the INA family) rather than a general-purpose op-amp and a prayer.
An op-amp driving a capacitive load — a long cable, or the ADC's own input capacitor plus a filter — can oscillate at a frequency you cannot see on a slow scope, which shows up as a reading that is mysteriously noisy or offset. A small series resistor (22–100 Ω) between the output and the capacitance isolates it. And a 100 nF capacitor across the supply pins, within a few millimetres, is part of the circuit, not a courtesy; Lesson 2.5 explains why distance is measured in nanohenries.
BEACONBeacon has no op-amp — and here is the argument for that
Everything Beacon measures is digital at the source. The SHT40 returns temperature and humidity as 16-bit values with its own CRC; its analog front-end, its reference, and its calibration are inside the package and traceable to Sensirion's factory test. The LIS2DH12 returns acceleration the same way. The only analog quantity Beacon measures is its own battery voltage, and that path is a 2 × 1 MΩ divider straight into the ESP32-C3 ADC with a 100 nF capacitor doing the impedance-matching job a buffer would otherwise do. Lesson 2.4 works that path in detail.
Could a buffer improve the battery reading? Marginally — it would let the divider be read at any sampling rate without the settling constraint the capacitor imposes. What it would cost: a part (against R5's IDR 150 000 BOM), board area (against R8's 35 × 25 mm), and quiescent current. An OPA333 at 17 µA would triple Beacon's 8 µA sleep floor unless it were powered from the same switched node as the divider, at which point its own start-up time replaces the capacitor's settling time and you have gained nothing. The divider plus capacitor plus a firmware wait is the right answer for a once-a-minute measurement with 1 % accuracy needs. This is what "when NOT to" looks like on a real BOM.
Imagine Beacon's cousin: same ESP32-C3, same BLE reporting, but its job is to monitor the current a piece of equipment draws — a "is this machine actually running?" tag. That product measures 0–2 A through a 10 mΩ shunt (0–20 mV, same range as this lesson's example, ten times the current) and needs the front-end designed above: a low-side or high-side sense amplifier, gain chosen from the ADC range, offset chosen from the required resolution, bandwidth chosen from whether it must see motor start-up transients or just averages. Its sleep budget would carry the amplifier's quiescent current or the complexity of switching it. Beacon's schematic v0 (Lesson 2.9) leaves a note where that stage would go: "no analog front-end; all sensors digital; battery sense via divider — see 2.4." A note saying why something is absent is as much part of the argument as a part that is present.
WEAKNESSWhere this bites
The LM358 datasheet says 2 mV typical offset. Your bench part probably has about that, and your gain-100 logger reads about 20 mA at zero, which you calibrate out and forget. The production run uses parts at 6 mV. The calibration constant is now wrong by 40 mA on a third of the units, and it drifts differently on each one with temperature. Design to the maximum column, and if the maximum is unacceptable, change the part, not the number.
A 1 MHz GBW sounds enormous next to a 20 kHz signal. It is not the bandwidth of your circuit; it is the bandwidth of your circuit at gain 1. At gain 100 you have 10 kHz, and a signal at 20 kHz arrives attenuated and phase-shifted. The tell is a reading that is smoother than the real signal and an average that seems right. Nothing looks broken. Always divide GBW by your noise gain before believing it, and remember that the inverting configuration's noise gain is 1 + Rf/Rin, one more than its signal gain.
The rail-to-rail output figure is measured into a light load (often 10 kΩ or more). Drive a 1 kΩ load, or a filter capacitor at high frequency, and the swing collapses by hundreds of millivolts. The top of your range disappears, silently, exactly like the LM358's 1.5 V headroom but with a better datasheet headline. Read the "output voltage swing vs load current" graph, and give the output a series resistor before any capacitance.
KEY INSIGHTHow this connects
- Kirchhoff's Laws and Circuit Analysis by Hand (1.3) — the golden rules are KVL and KCL applied to a component that forces one node equal to another. The gain formulas are that lesson's divider, read backwards; the bias-current error is its Thevenin resistance, multiplied by a current.
- Filters: RC, Noise, and Bandwidth (2.3) — next: the low-pass corner that GBW forced on you here becomes a corner you choose on purpose, and the noise that the amplifier faithfully amplified gets a name and a remedy.
- ADCs and DACs: Sampling the Real World (2.4) — the ADC that turned every error here into LSBs has its own: quantisation, reference error, and the sample capacitor that makes source impedance matter, with Beacon's battery divider as the case.
The habit this lesson installs — for every stage between a sensor and a number, ask "what error does this add, in the units of the thing I am measuring?" — is the habit that makes Stage 3's driver code honest and Stage 6's field data interpretable. An amplifier is just the first place it is easy to see.
GLOSSARYKey terms introduced
- Negative feedback
- Returning a fraction of the output to the inverting input so the amplifier corrects its own output until the inputs match. Trades raw gain for precision, linearity, and predictable bandwidth.
- Golden rules
- With feedback and an unsaturated output: the input difference is zero, and the inputs draw no current. The two idealisations from which every configuration's gain is derived in one line.
- Input offset voltage (VOS)
- The input difference needed to make the output zero; a fixed error that the circuit multiplies by its gain. Millivolts in general-purpose parts, microvolts in zero-drift parts.
- Input bias current (IB)
- The current the inputs actually draw. Becomes a voltage error through the source resistance; nanoamps for bipolar inputs, picoamps for CMOS.
- Gain-bandwidth product (GBW)
- The frequency at which the open-loop gain falls to one. Closed-loop bandwidth ≈ GBW ÷ noise gain, so gain and bandwidth are one budget.
- Slew rate (SR)
- The maximum rate of change of the output, in V/µs. Limits large signals at fmax = SR/(2π·Vpeak) independently of GBW.
- Rail-to-rail
- An input or output (specify which) that can operate to within tens of millivolts of the supply rails. Output swing is load-dependent; read the graph.
- Zero-drift (chopper) amplifier
- A part that continuously measures and cancels its own offset, achieving microvolt VOS and very low drift at the cost of bandwidth and some switching noise.
ACTIVE RECALLCheck your understanding
Answer in your own words first, then reveal.
1A non-inverting stage with Rf = 47 kΩ and Rg = 1 kΩ uses an op-amp with 1 MHz GBW and 3 mV max offset. What is the gain, the bandwidth, and the worst-case DC error at the output?›
Gain = 1 + 47/1 = 48. Closed-loop bandwidth ≈ GBW ÷ noise gain = 1 MHz / 48 ≈ 21 kHz. Worst-case output offset = 3 mV × 48 = 144 mV. If that feeds a 12-bit ADC over 2.5 V (LSB 0.61 mV), the DC error is about 236 LSBs — roughly 6 % of full scale, before the signal has done anything. Whether that matters depends on whether you can calibrate it out and how much it drifts; the datasheet's offset drift figure answers the second question.
2Why does the phantom-current error from offset voltage not depend on the gain you choose, while the error in ADC LSBs does?›
The offset and the signal enter at the same place (the inputs) and are multiplied by the same gain, so their ratio is fixed by the part and the shunt alone: Ierror = VOS / Rshunt. A 7 mV offset on a 0.1 Ω shunt is 70 mA whether you amplify by 10 or by 1000. The ADC, however, sees the offset in absolute volts — VOS × G — so in LSBs the error scales with gain, and so does the signal's full scale. In LSBs both grow together; in current they are constant. The practical consequence is that you cannot fix an offset problem by changing the gain; only a better part (lower VOS) or a larger shunt (more signal per amp, at the cost of burden voltage and heat) changes the phantom current.
3An OPA333 fixed your offset problem, but a colleague reports the amplified 30 kHz signal now looks like a triangle wave at half the expected amplitude. What happened, and what are your options?›
Two limits stacked. The OPA333's GBW is 350 kHz, so at gain 100 the closed-loop corner is 3.5 kHz and a 30 kHz signal is already attenuated by about 19 dB — but attenuation alone would leave it a smaller sine. The triangle is slew limiting: the output cannot change faster than 0.16 V/µs, and a sine of even 0.5 V peak at 30 kHz demands 2π × 30 kHz × 0.5 V ≈ 0.094 V/µs — close to the limit, so any larger signal turns into a ramp between the peaks. Options: split the gain into two stages so each runs at lower gain and higher corner (does nothing for slew); reduce the output amplitude the stage must produce (lower gain, which also helps slew); or use a different part with higher SR and GBW for the AC path and keep the OPA333 for a DC path — two front-ends for two questions, which is often the honest design.
4Beacon measures battery voltage through a 2 × 1 MΩ divider. Make the case for and against adding a unity-gain buffer, and reach a decision.›
For: the ADC's sample capacitor draws a gulp of charge each conversion; through a 500 kΩ Thevenin source it cannot be replenished in the sample window, so readings depend on sampling rate. A buffer presents a near-zero source impedance and removes the effect entirely; a CMOS part's picoamp bias current adds negligible error even behind 500 kΩ. Against: a part and its footprint against R5 (IDR 150 000) and R8 (35 × 25 mm); a quiescent current — even a micropower 17 µA part triples the 8 µA sleep floor — unless it shares the divider's switched supply, in which case its start-up time replaces the settling time you were trying to avoid. Decision: no buffer. A 100 nF capacitor across the lower divider resistor supplies the sample-charge gulp (100 nF ≫ the ADC's picofarads), and firmware gives the switched divider a few time constants (τ = 500 kΩ × 100 nF = 50 ms) before reading. One passive, a timing rule, zero microamps. Lesson 2.4 makes this quantitative.