I'm trying to design a peak detector which can be cleared by using an pin on the arduino. To design the peak detector I was following this guide-How to make a peak detector circuit. I used the circuit shown in that post and it works fine.
I made some changes to the circuit to use mosfet as switches in order to clear the peak value stored and another mosfet to allow the output to the stored value for certain times. The switch s1 is used to clear the stored value and the output across load r2 appears when the clock u1 is high
The problem: Now the problem i'm running into as you can see from the graph is once the switch s1 is closed and opened again, the peak detector stops working. Also how do i remove the spikes appearing at the output whenever the clock u1 is switching?