2024-10-26 10:38:00
lcamtuf.substack.com
This article assumes some familiarity with signal amplification and the knowledge of basic op-amp circuits. If you need a refresher, start here.
In a recent write-up on photodiodes, I mentioned that adding a capacitance in an op-amp’s feedback loop can spell trouble: it might cause ringing, sustained oscillations, or excessive gain.
It’s easy to offer a hand-wavy explanation of this phenomenon, but the mechanics of amplifier feedback loops are worth a closer look: control feedback is ubiquitous in analog signal processing and can be tricky to get right. Alas, the underlying theory is rather inaccessible to hobbyists; you’re either getting sucked into the discussion of zeroes and poles of complex-number transfer functions, or into obtuse jargon along the lines of this snippet from Analog Devices:
“The amplifier’s stability in a circuit is determined by the noise gain, not the signal gain.”
What does noise have to do with stability? Not much! If you’re curious, the term has to do with the habit of modeling real-world op-amps as an ideal amplifier with a voltage noise source attached to one of its legs. For some reason, Texas Instruments insists it has to be the non-inverting leg:
“Input voltage noise is always represented by a voltage source in series with the noninverting input.”
So… is “noise gain” just any amplification on that leg? Do op-amps have different gains on each input? How do you set this gain, or where do you find it in the spec?…
All these abstractions make sense in the context of mathematical models, but they don’t build intuition about the real world. In today’s article, let’s talk about feedback loops in a more accessible way. We’ll get to the same results, but hopefully in a less confusing way.
Before we proceed, let’s revisit the following rudimentary op-amp circuit:
If you’re here, you should already know the basic behavior of an op-amp: it takes the difference between the two input voltages, amplifies that by some very large number (open-loop gain, AOL), and then outputs the amplified difference as another voltage. Strictly speaking, the output is typically referenced to the midpoint between the power supply rails — let’s call it Vmid — so the complete formula is:
\(V_{out} = V_{mid} + (V_{in+} – V_{in-}) \cdot A_{OL} \)
Because AOL is normally huge — 100,000 or more — there’s only a microvolt-range linear region when Vin+ ≈ Vin-. Any input difference larger than that is bound to send the output all the way toward one of the supply rails.
Equipped with this knowledge, we can trivially simulate the behavior of our circuit, keeping in mind that Vin- is permanently tied to 2.5 V:
That said, there is a kink in this model: the capacitances, inductances, and resistances inside any real-world op-amp will limit the chip’s response speed. One prominent effect is that past a certain point, the apparent internal amplification of the device starts halving with every doubling of the frequency of an input sine wave. It eventually reaches 1x (unity gain) — and past that point, you’re stuck with an attenuator instead of an amplifier:
(Although the detail is unimportant, some readers might recognize that this is the curve of a first-order RC lowpass filter — as discussed in one of the earlier articles.)
Because constantly swinging between the supply rails is not a particularly useful feat, op-amps are typically employed with some form of a negative feedback loop. The simplest example — a voltage follower with an apparent 1x (unity) gain — is shown below:
At a glance, the circuit seems simple. The output voltage is looped back onto the inverting input, so if Vin+ > Vout, the differential signal is positive and the output starts creeping up; conversely if Vin+ , the voltage starts moving down. The process stops once the circuit reaches an equilibrium between all three voltages — essentially forcing Vout to march in the lockstep with the input signal:
Alas, the reality is more complicated than that! We sometimes take the mental shortcut of assuming that the equilibrium is reached at Vin+ = Vin- = Vout — but that’s not actually possible. Remember that at its core, the op-amp is doing the following math:
\(V_{out} = V_{mid} + (V_{in+} – V_{in-}) \cdot A_{OL}
\)
If the differential voltage is zero, then Vout is constant, no matter the value of AOL. But if Vout (and by extension, Vin-) are stuck in place, then not only is the circuit not doing anything useful, but the differential voltage can’t actually be zero, at least not for most of the possible Vin+ voltages. Oops!
What happens in reality that the balance is reached with Vin- and Vout at a slight offset from the input signal. This offset acts to nudge the amplifier just enough to reproduce the input signal when the “error” between Vin+ and Vin- is multiplied by AOL. Crucially, if the error signal is too large or too small, the negative feedback loop rectifies the problem in the blink of an eye, pulling Vout in the opposite direction until the balance is restored.
We can figure out the exact magnitude of these differential-voltage nudges if we take the op-amp equation and just substitute Vin- with Vout. This substitution is fair game because in the follower circuit, the two pins are tied together:
\(\begin{array}{c}
V_{out} = V_{mid} + (V_{in+} – V_{out}) \cdot A_{OL} \\
V_{out} = V_{mid} + V_{in+} \cdot A_{OL} – V_{out} \cdot A_{OL} \\
\\
\textrm{…moving }V_{out}\textrm{ stuff to the left:} \\
V_{out} + V_{out} \cdot A_{OL}= V_{mid} + V_{in+} \cdot A_{OL} \\
\\
\textrm{…splitting out common term on the left:} \\
V_{out} \cdot (1+A_{OL}) = V_{mid} + V_{in+} \cdot A_{OL} \\
\\
\textrm{…dividing both sides by (}1 + A_{OL}\textrm{) and tidying up:} \\
V_{out} = {1 \over {1 \ + \ A_{OL}}} \cdot V_{mid} + {A_{OL} \over {1 \ + \ A_{OL}}} \cdot V_{in+}
\end{array}\)
The analysis partly vindicates the mental shortcut we have talked about before: when AOL is very high, it follows that 1 / (1 + AOL) ≈ 0 and AOL / (1 + AOL) ≈ 1, so the last expression is kinda-sorta equivalent to:
\(V_{out} \approx 0 \cdot V_{mid} + 1 \cdot V_{in+} = V_{in+}\)
That said, although the scale of the “error” nudges is often negligible, ignoring the phenomenon makes the behavior of op-amps difficult to grasp. Just as importantly, as the input signal frequency increases, the op-amp’s internal gain drops, so Vout must drift farther away from the target for the sufficient differential voltage to appear across the input pins. In other words, at high frequencies, the output voltage error caused by feedback can get quite high.
One important observation we ought to make is that the addition of a feedback loop did nothing to change the op-amp’s gain. We just make Vin- track Vin+ very closely to muzzle the IC’s wild instincts. That said, even in the closed-loop configuration, the chip’s internal amplification remains the same — AOL — and as discussed earlier, for the sake of signal accuracy, we want it to stay that way!
As we established earlier, the control signal — the error piggybacking on Vout — is always as small as the op-amp’s internal gain permits. In effect, the feedback loop can be thought of having its own gain, separate from the configured signal amplification. And although what’s going on in in the feedback loop is typically hidden from view, any noise picked up there will appear on the output pin too.
Conceptually, the magnitude of loop gain is inversely proportional to the vertical distance between the op-amp’s intrinsic amplification curve and the circuit’s configured signal gain (in our example, 1x):
It might not be immediately obvious why loop gain is reduced when signal gain goes up, but it’s informative to look at the usual way of adding gain to a voltage follower:
The operating principle of this circuit is simple: the resistors attenuate the output signal fed back at Vin- by a factor of two, so Vout has to swing twice as much to achieve the same result on Vin-. We get twice the output amplitude — but the gotcha is that we also attenuated the “error” signal that piggybacks on Vout and actually makes the circuit work!
At this point, we also have a preliminary explanation of one of the more counterintuitive properties of op-amps: that instability and some types of noise problems can get worse at lower signal amplification rates because of higher loop gain.
Next, let’s consider the following unorthodox design:
It’s a voltage follower — except for a contraption that records output voltages and plays them back some time later on the Vin- side, delaying the feedback signal by a preset amount.
To explore this circuit, I built a toy discrete-time model with a limited bandwidth and a feedback loop that lags by five “ticks”. I then supplied a single input pulse on Vin+ and let the simulation run:
For the first five ticks, Vin+ (blue) is seeing a positive pulse while Vin- (red) is staying put due to the delay. As a consequence, Vout shoots up — although because of the baked-in bandwidth limit, it does not immediately jump all the way to +5 V.
After five ticks, Vin+ goes back to the mid-point and stays there for the rest of the simulation — but all of sudden, the delayed echo of the last pulse arrives on Vin-. It pulls the differential voltage negative, thus producing an inverted echo on the output. This back-and-forth process continues for a while, with gradually decaying amplitude.
The most important observation is that past the initial stimulus, the entire action is contained to the feedback loop. There is no movement on the signal input (Vin+), so the configured signal gain plays no role. The only reason the oscillations decay over time is that the gain of the feedback loop itself happened to be a tad below one.
If we increase loop gain a tiny bit, we get this result:
In the end, there are two conditions that must be met for sustained oscillation:
-
There must be a feedback delay of about one-half of a wavelength (180°) at some sine-wave frequency.
-
The feedback loop gain at that frequency must be at least one.
The first requirement means that higher frequencies are of more concern, because it’s easier to accidentally introduce comparatively large delays when the wavelength you’re working with is short. The second requirement means that we generally only have to worry about the frequencies below the IC’s internal unity-gain point.
Right. Tape-delay mechanisms are not commonly employed in op-amp circuits. Non-negligible transmission delays can sometimes crop up in electronic designs, but feedback loops are usually pretty compact on any sensibly-designed PCB. In other words, unless you’re working with ultra-high frequencies, signal propagation times a relatively remote concern.
Yet, there is another, more ubiquitous form of a “delay” mechanism: the capacitor. To be clear, a capacitor is not really a time delay device: it can’t store and replay past waveforms. Instead, it’s an integrator — that is, its terminal voltage is a function of the charging currents that flowed through it over time. It just so happens that this transform a sine into its phase-shifted image:
Because op-amps can only supply limited output currents, any shunt capacitance in the feedback loop will essentially form a lowpass filter in conjunction with the output’s equivalent series resistance. The filter will exhibit a voltage-to-voltage phase shift that depends on the signal frequency. A detailed discussion of this phenomenon can be found in an earlier article on RC filters, so I won’t repeat all the gory details — but in essence, a single capacitor can add from ~0° to ~90° phase shift.
On the surface of it, that shift is nowhere near the ~180° offset needed for sustained oscillation — but op-amps have some internal phase shifts too. The devices are usually designed so that their bandwidth rolls off just ahead of the danger zone. With some op-amps, even as little as an extra -45° can be enough to put you in the red.
When that happens, short of reducing the capacitance, some of the hacks may involve reducing the bandwidth of the feedback loop; bumping up signal gain; or switching to an amplifier that has more of a phase margin at the frequencies of concern.
If you liked this article, please subscribe! Unlike most other social media, Substack is not a walled garden and not an addictive doomscrolling experience. It’s just a way to stay in touch with the writers you like.
For a thematic catalog of articles on electronics and other topics, click here.
Support Techcratic
If you find value in Techcratic’s insights and articles, consider supporting us with Bitcoin. Your support helps me, as a solo operator, continue delivering high-quality content while managing all the technical aspects, from server maintenance to blog writing, future updates, and improvements. Support Innovation! Thank you.
Bitcoin Address:
bc1qlszw7elx2qahjwvaryh0tkgg8y68enw30gpvge
Please verify this address before sending funds.
Bitcoin QR Code
Simply scan the QR code below to support Techcratic.
Please read the Privacy and Security Disclaimer on how Techcratic handles your support.
Disclaimer: As an Amazon Associate, Techcratic may earn from qualifying purchases.