An amplifier you design with resistors
The previous lesson showed how much care one transistor stage takes: a bias network, a gain that depends on the bias current and the temperature, and a bandwidth fixed by stray capacitances. Now imagine a single part that you never bias, whose gain you choose with the ratio of two resistors to an accuracy of 0.1%, and which also adds, subtracts, integrates, filters and converts current to voltage, all with the same handful of rules. That part is the operational amplifier, or op-amp: an integrated circuit of dozens of transistors, starting with a differential pair, that amplifies the difference between its two inputs by a very large factor.
The name comes from the 1940s, when vacuum-tube amplifiers performed mathematical operations in analog computers. Today op-amps sit in almost every sensor interface, audio path, battery charger, motor drive and measuring instrument, and cost from a few cents to tens of dollars. This lesson explains the rules everyone uses, why they are true, the circuits built on them, and the real limits that separate a working design from a disappointing one.
The ideal op-amp and why feedback makes it work
An op-amp has a non-inverting input , an inverting input , and an output. Within its supply rails its output is where the open-loop gain is enormous: to at low frequencies. Used like this, without feedback, a difference of a few microvolts drives the output to a rail, which is how a comparator works but is useless as an amplifier. The trick is to feed part of the output back to the inverting input.
Theorem— Negative feedback makes the closed-loop gain depend only on the feedback
Suppose a fraction of the output is fed back to the inverting input, so , and the signal is applied to the non-inverting input. Then the closed-loop gain is and the voltage between the inputs is , which tends to zero.
Proof
Substitute into : , so and . Dividing numerator and denominator by gives , which tends to , with relative error about . Finally is a finite output divided by a huge gain.
∎
This gives the two golden rules of the ideal op-amp, valid when there is negative feedback and the output is not at a rail:
- The inputs draw no current. (Real inputs draw picoamperes to nanoamperes.)
- The output does whatever it must to make . This "virtual short" between the inputs is not a property of the chip; it is a consequence of high gain inside a negative feedback loop.
# A non-inverting amplifier: feedback fraction beta = Rg / (Rf + Rg) = 1/10
beta = 1 / 10
print("open-loop gain A closed-loop gain error vs 1/beta (v+ - v-) for a 5 V output")
for A in [10, 100, 1e3, 1e4, 1e5, 1e6]:
G = A / (1 + A * beta)
print(f"{A:16,.0f} {G:16.5f} {100 * (G - 1 / beta) / (1 / beta):+14.4f} % {5 / A * 1e6:14.1f} uV")
# Desensitivity: halve A and watch the closed-loop gain barely move.
for A in [2e5, 1e5]:
print(f"A = {A:,.0f}: G = {A / (1 + A * beta):.5f}")With the gain is 9.999, within 0.01% of the ideal 10, and the inputs differ by only 50 µV for a 5 V output. Halving from 200 000 to 100 000, a huge change in the chip, moves the gain from 9.99950 to 9.99900. That indifference to the amplifier is what feedback buys; Feedback, stability and oscillators studies its price.
The basic circuits
Every circuit in this section is solved the same way: set , assume no input current, and apply Kirchhoff's current law at the inverting input.
Inverting amplifier. The non-inverting input is grounded, so the inverting input is held at 0 V too: a virtual ground. The input current cannot enter the op-amp, so it flows on through , and the output must sit at :
Non-inverting amplifier. The divider makes ; setting that equal to gives with an input resistance of hundreds of megohms or more. With and no it becomes the voltage follower, , the ideal buffer.
Summing amplifier. Several inputs, each through its own resistor, into one virtual ground: the currents add, so . With equal resistors this is an analog adder, and with different ones a weighted sum: the heart of an audio mixer, and of a simple digital-to-analog converter.
Difference amplifier. Four resistors, into each input, from the inverting input to the output and from the non-inverting input to ground, give . Its ability to ignore a voltage common to both inputs depends on how well the two resistor ratios match: with 1% resistors at unity gain, the worst-case common-mode rejection is only about 50, or 34 dB.
Instrumentation amplifier. Put a non-inverting buffer in front of each input of a difference amplifier, and connect the buffers' two inverting inputs through a single gain resistor , each buffer having a feedback resistor . Common-mode voltages pass through the buffers with gain one, while the difference is amplified by ; the difference amplifier then removes the common mode. The result has very high input resistance on both inputs, a gain set by one resistor (with kΩ, gives 100), and a common-mode rejection of 100 dB or more when built on one chip with trimmed resistors. It is the standard front end for bridges and strain gauges, thermocouples and electrocardiograms, whose millivolt signals ride on volts of common-mode interference.
Example— A transimpedance amplifier for a photodiode
In Semiconductors and diodes, 10 µW of 850 nm light gave a photodiode current of about 5.5 µA. Connect the photodiode from the inverting input to ground and a resistor from the inverting input to the output. The virtual ground holds the photodiode at 0 V, the ideal condition for a linear response, and all its current flows through , so in magnitude. With kΩ the output is 1.1 V. A small capacitor across , typically a few picofarads, is needed to keep the circuit stable against the photodiode's own capacitance, a first taste of the next lesson.
Integrators
Replace in the inverting amplifier by a capacitor . The input current now charges the capacitor, so With kΩ and nF, a steady 1 V input makes the output ramp down at 1 V per millisecond. Integrators generate triangle waves, measure charge, and form the I in the PI and PID controllers of Feedback control. A real integrator integrates its own offset voltage too and drifts to a rail, so practical circuits put a large resistor across (limiting the gain at DC) or a switch that resets it.
Active filters: the Sallen–Key low-pass
Passive RC filters, from Frequency response and filters, can only fall off gently: cascading RC sections loads each with the next and gives a soft, drooping corner. Inductors would sharpen the corner but are bulky at audio frequencies. Active filters use op-amps and capacitors to build the same second-order responses as an RLC circuit, with buffered outputs that can be cascaded freely.
The most popular is the Sallen–Key circuit, published by R. P. Sallen and E. L. Key of MIT Lincoln Laboratory in 1955. In its unity-gain low-pass form, two resistors in series lead to the op-amp's non-inverting input, wired as a follower; one capacitor goes from that input to ground and the other, , from the junction of the resistors back to the output.
Nodal analysis at the two internal nodes, with the follower making equal to the voltage on , gives For the flattest passband, the Butterworth response, . With equal resistors , that needs , and .
import math
def sallen_key(R1, R2, C1, C2):
"""Unity-gain Sallen-Key low-pass: C1 from the middle node to the output, C2 to ground."""
w0 = 1 / math.sqrt(R1 * R2 * C1 * C2)
Q = math.sqrt(R1 * R2 * C1 * C2) / (C2 * (R1 + R2))
return w0 / (2 * math.pi), Q
def response(f, R1, R2, C1, C2):
s = 2j * math.pi * f
return 1 / (1 + s * C2 * (R1 + R2) + s * s * R1 * R2 * C1 * C2)
# Design: Butterworth (Q = 1/sqrt 2), 1 kHz, equal resistors of 10 kilohms.
R, f0 = 10e3, 1e3
c = 1 / (2 * math.pi * f0 * R) # the geometric mean sqrt(C1 C2)
C1, C2 = c * math.sqrt(2), c / math.sqrt(2) # Q = sqrt(C1/C2)/2 = 1/sqrt 2
print(f"ideal values: C1 = {C1 * 1e9:.2f} nF, C2 = {C2 * 1e9:.2f} nF")
E12 = [1.0, 1.2, 1.5, 1.8, 2.2, 2.7, 3.3, 3.9, 4.7, 5.6, 6.8, 8.2]
def nearest_e12(x):
candidates = [v * 10 ** d for d in range(-12, -3) for v in E12]
return min(candidates, key=lambda v: abs(math.log(v / x)))
C1s, C2s = nearest_e12(C1), nearest_e12(C2)
for name, (a, b) in [("ideal", (C1, C2)), ("E12", (C1s, C2s))]:
f, Q = sallen_key(R, R, a, b)
print(f"{name:5}: C1 = {a * 1e9:5.1f} nF, C2 = {b * 1e9:5.1f} nF -> f0 = {f:6.1f} Hz, Q = {Q:.3f}")
print("\n f (Hz) ideal (dB) E12 parts (dB)")
for f in [100, 500, 1000, 2000, 5000, 10000]:
g1 = 20 * math.log10(abs(response(f, R, R, C1, C2)))
g2 = 20 * math.log10(abs(response(f, R, R, C1s, C2s)))
print(f"{f:9.0f} {g1:10.2f} {g2:14.2f}")
lo, hi = 100.0, 10000.0 # where the E12 version is 3 dB down
for _ in range(60):
mid = math.sqrt(lo * hi)
if abs(response(mid, R, R, C1s, C2s)) > 1 / math.sqrt(2):
lo = mid
else:
hi = mid
print(f"\n-3 dB frequency with E12 parts: {mid:.1f} Hz")The ideal design needs 22.51 nF and 11.25 nF. Real capacitors come in the E12 series, so we take 22 nF and 12 nF, which moves to 979.5 Hz and to 0.677, putting the −3 dB point at 936.1 Hz. Above the corner the response falls 40 dB per decade, twice as steeply as one RC section: −28 dB at 5 kHz and −40 dB at 10 kHz.
Simulating with a behavioural op-amp
To simulate op-amp circuits you need an op-amp model. Manufacturers publish detailed models of their parts; here we write a small behavioural one of our own, which captures the essentials with three elements. A transconductance stage converts the input difference into a current, limited to ±0.5 mA by a tanh function; that current charges a 1 nF capacitor, shunted by a resistor that sets the DC gain; and a unity-gain voltage source buffers the result. The numbers give an open-loop gain of , a gain–bandwidth product of 1 MHz () and a slew rate of 0.5 V/µs (), typical of a modest general-purpose op-amp.
* Unity-gain Sallen-Key low-pass filter, 1 kHz Butterworth design with E12 capacitors
.subckt OPAMP inp inn out
B1 0 n1 I = 0.5m * tanh(6.2832m * (v(inp) - v(inn)) / 0.5m)
R1 n1 0 15.915Meg
C1 n1 0 1n
E1 out 0 n1 0 1
.ends
VIN in 0 DC 0 AC 1
R1 in a 10k
R2 a b 10k
C1 a out 22n
C2 b 0 12n
XU b out out OPAMP
.control
ac dec 100 10 100k
let gdb = vdb(out)
meas ac g1k FIND gdb AT=1k
meas ac g10k FIND gdb AT=10k
meas ac f3 WHEN gdb=-3 FALL=1
echo "gain at 1 kHz $&g1k dB, at 10 kHz $&g10k dB, -3 dB at $&f3 Hz"
.endc
.endngspice gives −3.57 dB at 1 kHz and −40.38 dB at 10 kHz, matching the Python, and a −3 dB frequency of 934.9 Hz against the ideal op-amp's 936.1 Hz: the finite gain–bandwidth product already matters by about 0.1% at one-thousandth of it.
Real op-amps: the limits that matter
Gain–bandwidth product. An op-amp's open-loop gain is huge only at low frequencies. Almost all general-purpose op-amps are internally compensated: a capacitor inside creates a single dominant pole, often at only a few hertz, so the gain falls by 10 for every tenfold rise in frequency, reaching 1 at the gain–bandwidth product (GBW), also called the unity-gain frequency. Closed around such an op-amp, a feedback loop with noise gain has a bandwidth of about : an op-amp with GBW 1 MHz gives 100 kHz at a gain of 10 and only 10 kHz at a gain of 100. (Noise gain is for both the inverting and the non-inverting configuration; for the inverting one it is one more than the magnitude of the signal gain.)
Slew rate. The internal compensation capacitor is charged by a limited current, so the output can change no faster than the slew rate (SR), typically 0.1 to 1000 V/µs. A sine wave of peak at frequency changes at up to , so a sine larger than comes out as a triangle. This full-power bandwidth limit is separate from GBW, and for large signals it usually bites first.
Offset voltage and bias currents. Mismatched input transistors make the output behave as if a small input offset voltage , from microvolts to a few millivolts, were in series with an input, and it is multiplied by the noise gain. The inputs also draw small bias currents (picoamperes for CMOS and JFET inputs, nanoamperes for bipolar ones), which develop error voltages across the resistances they flow through. Both drift with temperature.
import math
GBW, SR = 1e6, 0.5e6 # gain-bandwidth product (Hz) and slew rate (V/s) of a modest op-amp
VOS, IB = 2e-3, 50e-9 # worst-case input offset voltage and input bias current
print("noise gain closed-loop bandwidth")
for g in (1, 10, 100, 1000):
print(f"{g:10d} {GBW / g / 1e3:10.1f} kHz")
print("\nlargest undistorted sine at the output (slew-rate limit SR / (2 pi f)):")
for f in (1e3, 10e3, 20e3, 100e3):
print(f" {f / 1e3:5.0f} kHz: {SR / (2 * math.pi * f):6.2f} V peak")
# A gain-of-100 non-inverting amplifier, Rf = 99k, Rg = 1k, fed from a 10k source
RF, RG, RS = 99e3, 1e3, 10e3
noise_gain = 1 + RF / RG
print(f"\noutput error from a {VOS * 1e3:.0f} mV offset: {VOS * noise_gain * 1e3:.0f} mV")
print(f"output error from {IB * 1e9:.0f} nA of bias current in the 10k source: {IB * RS * noise_gain * 1e3:.0f} mV")
print(f"the same amplifier with a zero-drift op-amp (offset 5 uV, bias 0.2 nA): "
f"{5e-6 * noise_gain * 1e3:.1f} mV and {0.2e-9 * RS * noise_gain * 1e3:.1f} mV")A modest op-amp with a slew rate of 0.5 V/µs can deliver only about 4 V peak at 20 kHz, the top of the audio band; an audio design driving line levels needs a faster part. In the gain-of-100 amplifier, a 2 mV offset becomes 200 mV at the output, which may be fine for an AC-coupled audio signal and ruinous for a precision weighing scale, where a zero-drift (chopper-stabilised or auto-zero) op-amp cuts the error to under a millivolt.
The behavioural model shows both dynamic limits. Below, the same model forms a non-inverting amplifier with a gain of 10. The AC analysis finds its bandwidth; then a 0.4 V input step (a 4 V output step) and a 0.01 V step (0.1 V output) show the difference between slewing and linear settling.
* Behavioural op-amp: A0 = 100 000 (100 dB), GBW = 1 MHz, slew rate 0.5 V/us
* A transconductance stage with a limited output current charges C1:
* DC gain = GM * R1, GBW = GM / (2 pi C1), slew rate = IMAX / C1.
.subckt OPAMP inp inn out
B1 0 n1 I = 0.5m * tanh(6.2832m * (v(inp) - v(inn)) / 0.5m)
R1 n1 0 15.915Meg
C1 n1 0 1n
E1 out 0 n1 0 1
.ends
* Non-inverting amplifier, gain 1 + 9k/1k = 10
VIN in 0 DC 0 AC 1 PULSE(0 0.4 10u 10n 10n 40u 100u)
XA in fb out OPAMP
RF out fb 9k
RG fb 0 1k
* The same amplifier fed a small step, to see the linear response
VSM ins 0 DC 0 PULSE(0 0.01 10u 10n 10n 40u 100u)
XB ins fbs outs OPAMP
RFS outs fbs 9k
RGS fbs 0 1k
.control
ac dec 50 1 10Meg
let g = abs(v(out))
meas ac g0 FIND g AT=10
let g3 = g0 / sqrt(2)
meas ac fbw WHEN g=g3 FALL=1
echo "closed-loop gain $&g0, -3 dB bandwidth $&fbw Hz"
tran 10n 40u
meas tran tbig TRIG v(out) VAL=0.4 RISE=1 TARG v(out) VAL=3.6 RISE=1
meas tran tsmall TRIG v(outs) VAL=0.01 RISE=1 TARG v(outs) VAL=0.09 RISE=1
let dvdt = deriv(v(out))
meas tran srate MAX dvdt
echo "4 V output step: 10-90 % rise $&tbig s, steepest slope $&srate V/s"
echo "0.1 V output step: 10-90 % rise $&tsmall s (0.35 / bandwidth = 3.5e-06 s)"
.endc
.endThe closed-loop gain is 9.999 with a bandwidth of 100.0 kHz, exactly GBW divided by the noise gain. The small step rises from 10% to 90% in 3.50 µs, the of a single-pole system. The large step takes 7.13 µs, and its steepest slope is 0.500 V/µs: the output is slewing, at a rate set by the internal current limit, not by the bandwidth.
Inputs, outputs and rails
An op-amp's inputs work only over a common-mode range, and its output can swing only so close to the supply rails. Older designs lose a volt or two at each end, which on a 3.3 V supply leaves almost nothing. Rail-to-rail output stages swing to within tens of millivolts of each rail at light loads (less closely as the load current rises). Rail-to-rail input stages use two differential pairs, one of n-type and one of p-type transistors, so that one of them works at any input voltage; the offset changes as the input crosses from one pair to the other, which precision designs avoid. Remember too that the output can supply only a limited current, typically 10 to 50 mA, and that a large capacitive load, such as a long cable, can make the feedback loop ring or oscillate.
Choosing an op-amp
Thousands of op-amps are in production, from makers such as Analog Devices, Texas Instruments, STMicroelectronics, Microchip, onsemi, Renesas, Nisshinbo Micro Devices and 3PEAK, and every maker's website has a parametric search. Start from what the application needs, then read the datasheet's guaranteed (minimum or maximum) values, not the typical ones:
| Need | Look at | Typical choice |
|---|---|---|
| Battery-powered sensor | supply current, supply range, rail-to-rail input and output | CMOS op-amp drawing microamperes |
| Precision DC measurement (scales, thermocouples) | offset voltage and its drift, 1/f noise | zero-drift op-amp, or an instrumentation amplifier |
| Photodiode or high-impedance sensor | input bias current, input capacitance | CMOS or JFET input, picoampere bias |
| Audio | voltage noise density, distortion, slew rate | low-noise bipolar or JFET input |
| Fast signals (video, radio, data conversion) | GBW, slew rate, settling time, output current | high-speed or current-feedback amplifier |
Then check the supply voltage the part needs, the output current and the load, the package and the temperature range, the price and, as the shortages of the early 2020s taught everyone, whether more than one manufacturer makes something equivalent. Before building, simulate with the maker's own SPICE model, which captures far more than our three-element one.
A short history
Op-amps began as vacuum-tube circuits in the analog computers of the 1940s; in 1947 John Ragazzini and his colleagues at Columbia University named the "operational amplifier" in a paper on solving the equations of dynamics electronically. George A. Philbrick's company sold the K2-W, a plug-in tube op-amp, from 1952. The integrated op-amp arrived at Fairchild Semiconductor, where Bob Widlar designed the µA702 and the µA709 in the mid-1960s. In 1968 David Fullagar's µA741 put the compensation capacitor on the chip, so that the op-amp was stable at any gain without external parts; descendants of that design are still made. Since then op-amps have gained JFET and CMOS inputs, rail-to-rail operation on single low-voltage supplies, auto-zeroing for microvolt offsets, and bandwidths beyond a gigahertz.
Common misconceptions
Misconception
"The op-amp's inputs are always at the same voltage." Only with negative feedback and an output that is not at a rail. In a comparator, a Schmitt trigger or a saturated amplifier, the inputs can differ by volts.
Misconception
"A virtual ground is connected to ground." No current flows from it to ground. It is held at 0 V by the feedback, and current arriving through the input resistor leaves through the feedback resistor.
Misconception
"An op-amp with GBW 10 MHz amplifies by 1000 up to 10 MHz." At a gain of 1000 its bandwidth is about 10 kHz. The product of gain and bandwidth, not each separately, is what the part offers.
Misconception
"Rail-to-rail means the output reaches the rails exactly, at any current." It reaches within millivolts at very light loads and within a few hundred millivolts at its rated current. Leave headroom.
Exercises
1. Operational amplifiers
Warm-upHumanAn inverting amplifier has kΩ and kΩ, with ±12 V supplies. The input is a steady +0.2 V. What is the output, in millivolts? (Include the sign.)
2. Operational amplifiers
Warm-upHumanYou need a non-inverting amplifier with a gain of 25, and you have chosen kΩ from the inverting input to ground. What value of , in ohms, do you need?
3. Operational amplifiers
CoreHumanA summing amplifier has kΩ. Input 1 is +0.5 V through 10 kΩ; input 2 is −0.2 V through 5 kΩ. What is the output, in millivolts? (Include the sign.)
4. Operational amplifiers
CoreHumanAn op-amp with a gain–bandwidth product of 3 MHz is used as an inverting amplifier with gain −20. What is the closed-loop bandwidth, in kilohertz, to the nearest whole number?
5. Operational amplifiers
CoreHumanAn op-amp has a slew rate of 0.5 V/µs. What is the highest frequency, in hertz, at which it can deliver an undistorted 10 V peak sine wave? Round to the nearest hertz.
6. Operational amplifiers
CoreHumanIn which of these situations can you correctly assume ? Select all that apply.
7. Operational amplifiers
CoreHumanYou are building a transimpedance amplifier with a 10 MΩ feedback resistor, to measure photodiode currents down to 1 nA from a single 3.3 V supply. Which specification matters most when choosing the op-amp?
8. Operational amplifiers
CoreComputationalWrite sallen_key_butterworth(f0, r) returning the capacitors (c1, c2) (in farads) for a unity-gain Sallen–Key low-pass filter with , a Butterworth response () and natural frequency f0 in hertz. As in the lesson, goes from the middle node to the output and from the op-amp's input to ground, so
Further reading and resources
- Analysis of problems in dynamics by electronic circuits · John R. Ragazzini, Robert H. Randall and Frederick A. Russell · 1947The paper that named the operational amplifier, as a building block of analog computers.
- A practical method of designing RC active filters · R. P. Sallen and E. L. Key · 1955The original Sallen–Key filter paper, from MIT Lincoln Laboratory.
- Analog DevicesA major op-amp maker, with free design tools, application notes and SPICE models.
- Texas InstrumentsAnother major maker, publishing op-amp datasheets, reference designs and simulation models.
- STMicroelectronicsA European maker of general-purpose and precision op-amps.
- ngspice documentationBehavioural sources (B, E and G elements) used for this lesson's op-amp model are described in the manual.