# Stability (phase margin) analysis in real feedback circuits

So I had a bright idea of using negative feedback to control offset current in my data acquisition circuit. Sure, you could do this in software, but removing the offset at the input stage would reduce the swing and allow more gain in the pre-ADC amplifier without saturation, thus improving SNR.

So I designed this feedback loop, and my company built it. And it oscillated at about 50kHz, which probably comes as no surprise to most of the experts, because the only stability analysis I did was to triple-check that I had negative feedback.

The actual loop includes a sample-and-hold amplifier (this section, which includes $C_{\text{track}}$ and both $R_{\text{track}}$ resistors, has been proven in a previous iteration), but oscillation occurs only during the track phase, so I've reproduced the loop as it exists during the track phase.

The core idea is that the feedback loop should force the two inputs of OA2 to the same voltage (well, the output voltage divided by OA2 open-loop gain), so that $V_{\text{out}}$'s offset voltage is forced to $V_{\text{offset}}$. Then the sample-and-hold switches to hold mode and I acquire $V_{\text{out}}$.

I studied gain margin and phase margin in school, but I'm haven't had any recent practice with that and am not really sure how to go about creating a Bode plot for this real circuit. OA1 and OA2 are a OPA2376 and OA3 is a OPA340. There are additional connections for supply bypassing, etc., which I left off because I don't think they're relevant to the signal path. But feel free to ask about those if there's a reason they would matter to stability. And the $I_1$ supply represents the current from the sensor, which isn't really an ideal current source.

How does one develop a Bode-plot for circuits such as this using non-ideal op-amps that contain important poles in addition to the ones created by my passive components? Just read the ones from the datasheets and superimpose

I'm worried because the oscillation frequency is so low and close to my desired passband.

Am I right to think that the phase shift problem is caused by the op-amps' corner frequencies below 10Hz? If I use a resistor feedback network, I will truncate the open loop gain, moving the corner frequency to the right (where the open-loop plot intersects my new gain)? And the phase shift will also start at a higher frequency?

My impression is that both OA1 and OA3 have unity voltage gain (inverting), due to the existing feedback. Which leaves OA2 as the problem. What would be a good feedback loop for OA2 to stabilize the overall loop, while keeping the offset error small and settling time no more than $250 \mu s$ (because then I have to switch into hold mode)? Or should I be adjusting $C_{\text{tia}}$ and/or $R_{\text{track}}$ instead, to move my existing poles instead of creating new ones?

• You understand, don't you, that full-bandwidth negative feedback is also going to wipe out your signal as well as the offset? You want to restrict the bandwidth of your offset-cancelling feedback to a very low value, typically less than 1 Hz. This is called a "DC servo loop", and you can find lots of information using that as a search term. Feb 21, 2013 at 22:26
• @Dave: That's what the sample-and-hold is for. Perhaps "input offset" isn't exactly the right term, but I'm measuring time-varying optical coupling between an LED and phototransistor, the LED is modulated by square wave. This circuit is supposed to zero the response to ambient/external light, which may change faster than 1Hz. Sample-and-hold amplifier OA3 is synchronized to the LED excitation. Feb 21, 2013 at 22:33
• In that case, what you're building is known as a "chopper-stabilized amplifier" -- another good search term. Feb 22, 2013 at 1:55
• @Kaz: Look closer, the input is a current source. Mar 19, 2013 at 22:27
• Ah, my bad. I see the little arrow now behind the sinusoidal.
– Kaz
Mar 19, 2013 at 23:00

## 2 Answers

Wow, it is impressive that you would ask this question, it shows admirable courage.

Loop Stability Analysis in the Real World.

"How does one develop a Bode-plot for circuits such as this using non-ideal op-amps that contain important poles in addition to the ones created by my passive components?"

Two questions should be kept in mind while developing circuit designs:

1. Does this design do what it needs to do?
2. Does this design do what it is supposed (designed) to do?

The first question is the most important, but we'll bypass it now to look at the second, which is where stability analysis would fit into the design process. This will be a demonstration of a well known technique, Bode analysis, applied to simple loops consisting of OpAmps, resistors, capacitors, and left half plane poles and zeros. While this can be extended to more complicated loop types, it won't be here, because this will be long enough as it is. So, you will find no discussion of loop topologies that switch periodically during an operating cycle, no disappearing poles, no wandering right half plane zeros, and no other dirty tricks.

Stability analysis involves three steps:

1. Quick and dirty (QnD) evaluation.
• Look for red flags. Uncover any obvious mistakes.
• Perform a survey of poles and zeros and loop gain.
• Use a Bode asymptotic model to get a rough evaluation of phase margin. Pay the most attention to the phase margin since it is the most reliable tell of stability, while the gain just has to be greater than 0dB.
2. Numerical model and simulation. Use this to get a more precise and accurate picture of loop gain and phase margin than QnD provides. Plus you can also do a montecarlo analysis of loop stability.
3. Physical measurement. I'll only (barely) talk about this here in the introduction, since it is just too big a subject. Anyone who works with high performance loops, and is serious about stability will do a physical loop measurement of their circuit. For loop measurement you will need a network analyzer (like a E5061 or AP300 for example), and a summing amplifier to break the loop and inject the perturbing signal. It is really nice to build the summing amp, along with some micro connectors, into your design so you can run a loop any time.

Some things to keep in mind about Bode analysis:

• This is a linear technique only. No frequency multiplication allowed in the loop ... the swept source frequency has to be compared at the input and output without any energy having been put into other frequencies for the results to be useful.
• This is also really an AC small signal type of analysis.
• Analysis is done only on open loops. All a closed loop analysis would get you would be a flat response of zero dB until the open loop gain falls below zero dB. So, you have to break the loop and then you can see the contribution of all poles and zeros in the loop.
• Any loop with gain that crosses zero dB at > 20dB/decade (more than 1 uncompensated pole) is going to be unstable.
• You really want a phase margin > 35 degrees.

We'll go through steps 1 and 2 using your loop as example.

1. Quick and Dirty

Red Flags

Take a quick global look at the loop for anything that stands out.

• In this case we see OA2, uncompensated with uncontrolled gain. Having an uncompensated amp in the loop is always questionable, and usually a bad idea. If high gain is needed at DC, an integrator should be used.
• No zeros at all. This is bad since there is more than 1 pole (actually there are 3 poles) ... loop will be unstable with adequate gain (and since OA2 has maximum gain, things aren't looking too good).

Remember that this is a flash impression, looking for things that stand out glaringly. It works best if you see what there is in 5 or 10 seconds. It is often hard to do this with your own circuit, an outside view can be very valuable.

Pole, Zero, and Gain Survey

The asymptotic Bode analysis works best with simple poles and zeros and is less accurate with complex poles and zeros because of the damping factor. Usually OpAmp loops have mostly simple poles and zeros. Go ahead and account for any complex pairs, but be aware that this approximate analysis is likely to be inaccurate and overly optimistic when those are present. In this case though, all the poles are simple.

It is usually best to break things up by OpAmp stage, so:

• OA1: Pole at 36kHz, Gain = 26dB
• OA2: Pole at 1Hz, Gain = 120dB Note, this is a guess at the LFP and gain of OA2 since I haven't bothered to look yet
• OA3: Pole at 6kHz, Gain = 0dB

Asymptotic Bode Model

Using the pole locations from the survey, tally the phase margin using the asymptotic Bode model. Recall the left half plane pole and zero characteristics according to Bode are:

• Poles: Gain falls at 20dB/decade (6dB/octave) starting at the pole frequency. Phase falls at 45deg/decade (13.5deg/octave) for a total of 90deg centered at the pole frequency.
• Zeros: Gain rises at 20dB/decade (6dB/octave) starting at the zero frequency. Phase rises at 45deg/decade (13.5deg/octave) for a total of 90deg centered at the zero frequency.

First, we know that we only have to pay attention to the phase in this case due to the high gain of OA2. Just add up the phase for a few frequencies until we find where the phase margin is zero. To keep things neat, I'll put it in a table.

\begin{array}{cccccc} \text{Freq} & \text{OA1} & \text{OA2} & \text{OA3} & \phi_T\ & \phi _M\ \\ \text{DC} & -180 & -180 & -180 & -540 & 180 \\ \text{6kHZ} & -190 & -270 & -225 & -685 & 35 \\ \text{18kHZ} & -212 & -270 & -247 & -729 & -9 \\ \text{36kHZ} & -225 & -270 & -260 & -755 & -35 \end{array}

Based on the phase margin ($\phi _M$) result, the loop will oscillate at about 15kHz (because that's where $\phi _M$ is zero).

Calculation using QnD to reach this conclusion took about 4 minutes. Now, this is sort of a special simplified case, since there was no need to consider the loop gain (gain was so high there was no question that the loop would be unstable, just where $\phi _M$ would be zero) so, other loops might take a little longer.

Using approximate Bode analysis can be a very quick way to understand a loop. You can scribble it out on a napkin in a cool dark bar ... ah, never mind, that's a horrible waste of a happy hour. But, you can scribble it out in the margin of a design review slide of the loop while the presenter talks about it, and then before the slide is flipped ask them if they are worried about all that phase shift. (Start asking questions like that in design reviews, and you probably won't be wasting much time in them any more.)

So, who does this kind of analysis? It seems like almost nobody does. Most people just dive into the numerical model, which is too bad. The QnD approach can cause you to think about the loop in a way that you otherwise might not. After QnD you will know basically what the loop should do, and you will sidestep the biggest problem with numerical simulation which is blind credulity and acceptance of a magic answer.

2. Numerical Model and Simulation

Now that you've got a good idea what the loop should do it's time for a numerical model and simulation. This will result in a real Bode plot. For stability analysis, your opamp model needs to account for input resistance ($R_i$), output resistance ($R_o$), open loop gain ($A_v$), and low frequency pole (LFP). You can do this with what is often called a level 1 amplifier model using 3 resistors, 2 voltage controlled voltage sources, and a capacitor. An example of a level 1 model can be found here. For an AC small signal analysis a level one type model is all you need.

For the two amplifiers used here the model parameters are:

\begin{array}{ccc} \text{Parameter} & \text{OPA2376} & \text{OPA340} \\ A_v\ & \text{126dB} & \text{115 dB} \\ \text{LFP} & \text{0.6 Hz} & \text{4 Hz} \\ \text{Ri} & 10^{12}\text{ Ohm} & 10^{13}\text{ Ohm} \\ \text{Ro} & \text{150 Ohm} & \text{10 Ohm} \end{array}

You can break the loop anywhere (except an amplifier summing junction) while building the model. I chose to break it at the node common with Rfb, Rtrack2, and OA3out by separating Rfb to explicitly make it the input for the 1st stage (OA1). So, the oscillator (and loop input) would go into OA1 through Rfb and the loop output would be at the OA3 output. Build the model in a SPICE like simulator of your choice, and plot magnitude and phase of OA3out/Oscin.

Here are the results that I got from 1Hz to 1MHz.

QnD analysis showed $\phi _M$ = 0 at 15kHz, but the numerical model shows $\phi _M$ =0 at about 10kHz. That is too big a difference between the two results. What's going on here?

It turns out that the OPA2376 used for OA1 does not have enough open loop gain to support 26dB of closed loop gain near 36kHz. This should have noticed much earlier (slightly embarrassed shrug). Near 36kHz the OPA2376 has only about 29dB of gain (open loop gain only 3dB more than the closed loop gain), and the LFP interferes with the feedback pole placed at 36kHz. You always want open loop gain to be at least 20dB higher than the closed loop gain of the OpAmp. The theoretical feedback equation breaks down when there is not enough gain. In the small signal numerical model the low frequency pole and the 36kHz pole kind of mush together causing $\phi _M$ to fall off early and dropping the phase crossover frequency by about 4kHz from what was expected.

It is great that this happened, because it illustrates some limitations of modelling and benefit of having done a QnD analysis to start. If there had not been a difference between the two $\phi _M$ results, the problem might not have been noticed. One of the most interesting things here is the difference that you would likely see between a real circuit where the LFP interfered with a feedback pole and a numerical model of the circuit. The numerical model shows the effect of the two poles as having the phase margin fall off earlier that it should, almost like the pole is distributed. But, real amplifier behavior becomes spooky when there is insufficient open loop gain to support the closed loop gain, and unusual things happen. A real circuit, by measurement, would show the poles interacting more like a complex pair. You would see a gain lobe near the feedback pole location where gain would go up to nearer the open loop gain, and the phase margin would increase temporarily and push out to a higher frequency crossover point. After the gain and phase extension, both gain and phase would crash quickly. In this case it makes sense that $\phi _M$ crossover point would be pushed out from 15kHz to somewhere nearer 40kHz.

How to Fix This Loop?

In this loop OA2 is effectively an error amp, whose function is to minimize the error (or difference) between a reference and some controlled quantity. Normally you would want OA2 to have as high of gain as possible at DC to minimize the error, so basic structure of OA2 would be an integrator. Best case performance would be for the open loop to have a 20dB/decade gain out past the zero gain crossover, with a phase margin of more than 45 degrees. If there are n poles in the loop you would want (n-1) zeros to cover the poles that would effect the gain at frequencies lower than the desired bandwidth. In this case you would add zeros to OA2 stage to cover the poles in OA1 and OA3. You would also want to add 2 high frequency poles to OA2 to manage the closed loop gain (of the OA2 stage) as the open loop gain of the OPA2376 was approached. Oh, and don't forget, OA1 either needs an OpAmp with wider bandwidth or the 36kHz pole needs to be moved to a lower frequency.

Bonus Material

Back to design question 1: Does this design do what it needs to do? The answer is probably not. In the comments you say you are trying to eliminate a back ground or ambient level from the signal. This is usually done with a correlated double sampler (CDS) or something that is sometimes called a DC restore circuit. The first step in either case would be to convert the current signal to a voltage signal source, basically like you did with the OA1 stage, but without the feedback from OA3.

In a CDS, following the current to voltage conversion, there would be two sampler circuits. One would sample during the background period, while the other would sample during the active period. The difference between the two sampled output would be then be taken as the new signal.

In DC restore, the voltage representation of the signal would pass through an AC coupled following amplifier. During the background period the the coupling capacitor terminal connecting to the follow amplifier input would be grounded (or tied to a reference), that puts the background voltage across the capacitor. Then during the active period that capacitor terminal would be released from the ground or reference and allowed to float, and that's the signal voltage with background removed.

• Thanks a bunch. This will take me a while to digest. I'm aware of a double-sampling technique, but this makes the transimpedance amplifier see the full DC current which saturates it. So I was trying to come up with a mechanism to divert the DC current and thus reduce the dynamic range at the TIA input. Moving the gain later in the circuit (i.e. low gain TIA, ambient cancellation, high gain, ADC) has poor noise performance. May 7, 2013 at 22:46
• Wow, @endolith thanks for the bounty and edit. I've learned a new word. I see that a fumble finger error in the second table confused LFP (low frequency pole, of the OpAmps) with LPF. Jul 24, 2015 at 23:49
• @gsills Oh, sorry for my miscorrection. You should probably spell it out then? Jul 25, 2015 at 0:30
• @endolith It's OK. I'd have been confused too, reading it the way it was. LFP is mentioned as an important OpAmp parameter in section 2 in the paragraph before the table, but then I miss-typed it (reversing the F and P) in the table, to mess things up. I hope it's clear now. I do appreciate the edit. Jul 25, 2015 at 3:25

It looks like you may have basically built a phase shift oscillator around OA2.

Look at it from the point of view of OA2. Locally, OA2 is operating as a comparator with no local feedback around the amp, which just means it is a gain stage with very high gain.

Negative feedback is supplied to OA2 via the OA3 and OA1 stages. Both these stages have high frequency roll off, which means that there is an area of their operation, in the frequency domain, in which they pass some signal, but at some phase shift.

Because OA2 has a huge gain, very little feedback is required to sustain oscillation (i.e. very little signal has to pass through OA3 and OA1). We need $A\beta = 1$, but if $A$ is huge, then $beta$ need be small.

At only 50 Khz though, there is only about 83 degrees of shift in the OA3 stage, and around 55 degrees in OA1. That's far from 180. To make up the slack, the loop must be picking up quite a few degrees of phase shift from some op-amp non-ideal behaviors, like the internal compensation poles. But that belief is hard to justify. Looking at the datasheets, the op-amps you are using have next to no phase shift up to 1 Mhz.

Something else is at play: parasitic capacitances outside of the op amp, or feedback paths which are not obvious from the schematic (perhaps through the power supply). Because OA2 is wide open, it will amplify the faintest signal that rides on top of the reference voltage.

The amps are CMOS, so they have very high input impedance, making them sensitive to parasitic shunt capacitances. Say you have a $10^{12}\Omega$ input impedance. A mere 0.001 pF stray capacitance creates a pole with a 3dB frequency of 160 Hz!

If the circuit is not oscillating at all, attaching an oscilloscope probe to Vout could add enough shunt capacitance to create a pole at the input of OA1 that adds the necessary phase shift to make it oscillate.

Do you have evidence that the circuit is oscillating at 50 Khz (or oscillating at all) when you're not scoping it, and have you tried tapping in at more than one point in the loop?

• My ADC connected to Vout shows oscillation also. Also, I did simulate this circuit with TINA-TI and transient analysis also predicts oscillation, as long as the step size is reasonably small. Mar 20, 2013 at 3:44