I am using an op amp configured as an integrator, as shown in the schematic below. There is an input signal which can go both positive and negative [+1V ... -1V], and then depending on this input signal polarity the output of the integrator will ramp up or down until it reaches the supply rail of the op amp (±12V in my application). This all works fine:
I would now like to use a control signal from a microcontroller (~5V DC) to be able to reset the capacitor charge to zero at any arbitrary time, and keep it shorted out to prevent further charging. I tried to do this using a simple MOSFET, as shown below:
As can be seen in the SPICE calculation, this doesn't work properly - the charge is reset to zero correctly, but the negative part of the waveform is now clipped. I am not sure I understand why this is the case.
Can anyone tell me what mistake I have made, and suggest a way to achieve what I am looking for? Thanks!
EDIT ------------------------------------------------------------------------
After reading Caleb's answer, I have also tried to place a switch across the capacitor (a classic toggle switch here, but in practice could be an analog switch such as the DG417, as suggested). I have also placed a 1 kΩ resistor in series, to keep the discharge current through the switch at around 10 mA, as recommended in the comments (discharge response time is not an issue or requirement for me at all):
However, now a new problem arises as seen above. I didn't realise the need to specify in the original question, but whenever the capacitor is shorted I would also like the integrator output to be zero, regardless if the input signal is still applied. It can be seen here that the output is non-zero, as the input resistor and series discharge resistor effectively form a potential divider. Does this mean that I also need to add some MOSFET to short the output of the op amp down to ground whenever this "discharge control signal" is applied?