# Modeling op-amps with saturation

Discussion in 'General Electronics Chat' started by dsharlet, Oct 30, 2013.

1. ### dsharlet Thread Starter New Member

Oct 15, 2013
6
0
I'm trying to build an op-amp model with saturation. I've made some progress on this goal, I'm using the following code to generate my system of equations for the circuit (my apologies for the non-standard notation/syntax):

Code ( (Unknown Language)):
1.
2. // The input terminals are connected by a resistor Rin, add that to the MNA system.
3. Resistor.Analyze(p, n, Rin);
4.
5. // Compute Vout using Vout = A*Vin
6. Expression Vout = Aol * (p.V - n.V);
7.
8. // Saturate the output if the power supply terminals are connected.
9. Expression Vmax = vpp.V - vnn.V;
10. Vout = (Vmax / Pi) * ArcTan(Vout / Vmax);
11.
12. // Output current = (Vout - Out.V) / Rout
13. AddTerminal(o, (Vout - o.V) / Rout);
14.
In this code here, 'p', 'n', and 'o' are the terminals of the op-amp, 'vpp' and 'vnn' are the power supply terminals of the op-amp. Terminals have a property 'V' that is a variable representing the voltage at the node that terminal is connected to. So for example, 'p.V - n.V' means the voltage differential between the positive and negative inputs of the op-amp.

Now, this model works great when vpp and vnn are equal to +/-X, where X is some constant voltage from some other nodes in the circuit. However, when vpp and vnn are not equal in magnitude (for example, +9V and 0V, a typical case I'm trying to simulate unsuccessfully...), the output is not correct.

Now, it's pretty obvious why the above will not work when vpp and vnn are not equally balanced around 0. The computation to saturate the voltage with ArcTan clearly is not correct in this case; it is only considering the difference between vpp and vnn, and the result is saturated around 0. However, my problem is I cannot figure out what it should be. My first naive guess was to add (vpp.V + vnn.V) /2 to Vout after saturating it, and this actually works for some input signals (it appears to work when the signal is large enough to actually saturate), but it is clearly wrong as well.

A bonus question: I'm trying to simulate this all in real time, meaning I don't have a lot of time to spend finding roots of these equations. The above is challenging because the derivative of arctan is very near zero for most of its domain, causing newton's method to not converge easily. I'd like to replace ArcTan with something that isn't quite as correct, but maybe helps newton's method converge more easily. I'm thinking something based on log instead of arctan, like maybe something along the lines of ln(1 + abs(x)) * sign(x). This is much easier to deal with when finding roots. I realize this won't saturate as "strongly", but I'm hoping it will still sound mostly correct while being much faster to solve...

I'd appreciate any thoughts on this topic!

2. ### WBahn Moderator

Mar 31, 2012
23,093
6,945
You pretty much lost me at the claim that using Arctan() was somehow "correct" to begin with.

Let's say that I have an opamp with ±10V rails, so your Vmax is 20V.

Now let's say that I compute that Vout should be 5V based on Vout=A*Vin.

You are claiming that the actual voltage will be

Vout = (20V/∏)*atan(5V/20V) = 1.56V.

What's the basis for this claim?

3. ### dsharlet Thread Starter New Member

Oct 15, 2013
6
0
Between my code and the post box (I had to rearrange some stuff to make it easier to post), I lost a factor of ∏ (this causes the derivative of the model to be 1 near 0), it should be:

Vout = (20V/∏)*atan(∏*5V/20V) = 4.2V.

It's clearly not a physically correct model, but it's at least somewhat qualitatively correct, and it's easier to deal with numerically than stronger saturation models.

For what it's worth, when I crank up the iterations and oversampling in my solver to deal with the numerical issues previously mentioned, my output is nearly identical to LTspice for most of my test signals and test circuits.