Python – How does a negative feedback amplifier reach steady state

feedbackoperational-amplifierpythonsimulationsteady state

I tried to simulate a negative feedback non-inverting op-amp, and got incorrect results.

I ran the following time-stepping code in python:

A = 100000                      #open-loop gain  
B = 0.75                        #the feedback factor  
V_out = 0                       #initial output of op-amp is zero  
V_in = 2                        #input voltage of 5V (DC)  
for t in range(1000):  
    feedback = B*V_out  
    V_out = A*(V_in - feedback)  
    if V_out > 10:                    #saturation
        V_out = 10                    #hits rails at 10V
    elif V_out < -10:                   #saturation
        V_out = -10                   #hits rails at -10V

But this model doesn't behave like a practical op-amp.
V_out saturates at -10V, and feedback goes to 7.5V, and not 2V, thus violating the second summing point constraint.

Why is this happening?

NOTE: I've used the standard general feedback model for reference.

Best Answer

Your first tick of time "t" produces an end-stopped output voltage at plus or minus 10V. It doesn't matter which because your next iteration will also produce an end-stopped output voltage of opposite polarity then you are back to the start again and you'll just produce end-stopped voltages each tick of time "t".

If you don't get alternate end-stops of plus then minus 10V then your code is wrong.

But, of course alternate end stops of 10V isn't how an op-amp works so you then have to look at what has gone wrong and build a small integrator into the code so that it more closely represents an op-amp. You have no mechanism for producing a value that can converge on 0V and that is your basic problem.