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.
Here is the opamp implementation