# OpAmp comparator circuit having unexpected behavior

I'm working with the following circuit. It integrates a constant current, and when the output reachs a threshold, another circuit activates the switch, discharging the capacitor. The switch is simplemented with a transmission gate, and it is on long enough for the capacitor to discarge through the transmission's gate resistance. What I'm expecting, is that when the switch is on, the capacitor is discharged to 0V, thus taking the output to Vref1 (1,3V). This is what happens when I simulate with an ideal opamp In red is the control signal, when it turns on, the capacitor voltage (cyan signal) goes to zero, making the output signal equal the voltage of the non inverting terminal, 1.3V.

However, when I replace the ideal opamp by another one designed by me (a simple two stage opamp), the signals behave unexpectedly, as shown in the following figures The capacitor indeed discharges completley to zero, but the output signal does not change to 1.3V as expected. After the control signal goes to zero, all signals start to grow, until the ouput reachs almost Vdd (1.8V), as seen in the following figure I suspect this is being caused by one of the parameters of the custom opamp not being ideal, but I don't know which one. I thought of the gain not being enough, but a simulation with another opamp with less gain resulted in an overshoot not so big, as it can be seen in this figure With an opamp with less gain, the output is not settling at 1.3V as expected, but it settling at a much closer value than the opamp with higher gain. So, apparently, less gain gives a better result.

Any help is appreciated.

EDIT:

Here is the opamp implementation • Show us the circuit of your custom opamp. Otherwise the question becomes much like. Why does the car I built myself run properly? :-) – Russell McMahon Feb 11 at 7:38
• I just added it! – MPA95 Feb 11 at 18:15

Your system is unstable because you have a pole in the right half plane, and the result is that the output grows unbounded.

Any non-ideal op-amp has a finite DC gain $$\\ A_0 \$$ and a finite bandwith (crossover frequency $$\\ \omega_c\$$ below infinity) such a non ideal op-amp can be approximated as a single pole low pass filter, with the following transfer function;

$$G(s)=\frac{A_0}{1+\frac{s}{\omega_c}}$$

Any non-ideal op-amp also has a finite input impedance $$\\ Z_{in}\$$, which can be approximated by a parallel RC circuit;

$$Z_{in}=\frac{1}{C_{in}\cdot s+\frac{1}{R_{in}}}$$

Where $$\\ C_{in} \$$ is the input capacitance, and $$\\ R_{in} \$$ is the input resistance of your op-amp. Your feedback path is not just a capacitor, but a voltage divider consisting of $$\\ C_1\$$, $$\\ C_{in}\$$ and $$\\ R_{in}\$$. This means that the feedback transfer function of your circuit is;

$$H(s)=\frac{C_{1}s}{(C_{1}+C_{in})s+\frac{1}{R_{in}}}$$

And the input transfer function is;

$$I(s)=\frac{-1}{(C_{1}+C_{in})\cdot s+\frac{1}{R_{in}}}$$

Now let's combine it all to get the closed loop transfer function of the system;

$$T(s)=I(s)\frac{G(s)}{1+H(s)G(s)}=\frac{-1}{(C_{1}+C_{in})\cdot s+\frac{1}{R_{in}}}\frac{\frac{A_0}{1+\frac{s}{\omega_c}}}{1+\frac{C_{1}s}{(C_{1}+C_{in})s+\frac{1}{R_{in}}}\frac{A_0}{1+\frac{s}{\omega_c}}}=\frac{-A_0}{\frac{(C_{in}+C_{1})}{\omega_c}s^2+((1+A_0)C_{1}+C_{in}+\frac{1}{R_{in}\omega_c})s+\frac{1}{R_{in}}}$$

Solving for the poles of the closed loop transfer function you will find that at least one situation where you have a pole in the right half plane (your system is unstable) is if;

$$0<4\cdot \frac{(C_{in}+C_{1})}{\omega_c R_{in}}<((1+A_0)C_{1}+C_{in}+\frac{1}{R_{in}\omega_c})^2<1$$

(Which will be true at least as long as $$\\ 0, $$\\ 0, $$\\ R_{in}>>1\$$, $$\\ A_{0}>>1\$$ and $$\\ \omega_{c}>1\$$)

This is easy to prove using simple (but painstaking) algebra, so I want bother with it here..

To sum it up; Your system is unstable because you have a pole in the right half plane.

The most simple solution would be to add a resistor in parallel with $$\\ C_1\$$ which is sufficiently small to make the system stable, while being sufficiently large to not cause an unacceptable error in your system. In general in order to be able to rely on the assumptions/simplifications we use when we design op-amp circuit, such as your integrator circuit, one of the things we require is that $$\\ Z_{feedback}< which is not true for your circuit.

• Would you like to add a comment re most reasonable solution to his problem. – Russell McMahon Feb 11 at 21:48
• @RussellMcMahon Good point, I've added a small comment about how to solve the problem at the end of my answer. – Vinzent Feb 11 at 21:51
• I simulated with a resistor in parallel with the feedback capacitor and it is still not working... and also, the output is not growing unbounded. In both cases I showed, the output reaches a finite value, it is not being limited by Vdd. Could the problem still be a RHP? – MPA95 Feb 14 at 23:45
• @MPA95 "I simulated with a resistor in parallel with the feedback capacitor and it is still not working..." then either you didn't make it small enough, or your homemade opamp isn't an opamp at all. think of it like this; if you made the parallel resistor = 0 then you would have a unity gain amplifier, and if your opamp is any good it will be stable in this configuration, now increase the resistance until the circuit again becomes unstable, and that is the limit to how large a feedback resistance the opamp will be stable with. But you should also increase the value of C1 if you want a function – Vinzent Feb 15 at 9:44
• ..if you want a functional integrator circuit, because the input capacitance of your opamp is likely to be much larger than C1, again read the last thing I write in my answer; "In general in order to be able to rely on the assumptions/simplifications we use when we design op-amp circuit, such as your integrator circuit, one of the things we require is that Zfeedback<<Zin which is not true for your circuit.".. All that sayed what you really should do is modify the equations I wrote to include the resistor and then solve for stability. – Vinzent Feb 15 at 9:45