I have a capacitor charging circuit which is connected to a comparator that stops the charging process once the capacitor reaches a certain voltage. The circuit I have built is shown below in Fig 1

Circuit diagram

The problem I am facing is that once I cut off the input power supply, the capacitors discharge even though there isn't a closed path.

A brief explanation of the circuit:

  1. I have a 12V 1.5A rated adapter for the input. I only need 5V but at the moment I do not have an appropriate power source so I am using this one.
  2. The 7805 power regulator maintains a constant 5V at it's output and this 5V is connected to the drain of the IRFZ44N MOSFET which is the switch that toggles the charging circuit of the capacitor.
  3. The Op Amp shown here is a LM358 which I have used as a comparator. The non inverting input is connected to a <5V supply which is created through the voltage divider circuit. The measured voltage was about 5.3V so I added a diode between the op amp and the voltage divider to bring a 0.7V drop. The inverting input is connected to the positive terminal of the capacitor (the capacitors are arranged as 3 capacitors of 1000uF in series).
  4. The output of the comparator is then connected to the gate of the MOSFET as well as the base of a BC547 transistor which is a switch to an LED which indicates if the capacitors are still charging

The idea here is to stop the charging once the voltage across the capacitors reaches a certain value (5V in this case) and re-trigger if it drops below that.

The problem I am facing is that the capacitor drains out when I cut the power supply. I am not able to understand where it is getting a closed path to do so. I figured it can only discharge through the 10K ohm resistor so I added a diode between it and the capacitor in reverse bias as in Fig 2 to prevent discharge, but it is still happening.

Can someone please help me with this?


2 Answers 2


The problem I am facing is that the capacitor drains out when I cut the power supply.

The MOSFET has a body diode that will start conducting if the drain falls below the source voltage by about 0.7 volts. With the power removed, the output of the 7805 will not be powered and this will cause the drain voltage to fall.

Current will discharge through the body diode and into the 7805 output and you might damage the 7805 hence why we put a reverse diode across it. Anyway, if the 7805 isn't damaged (experience suggests it could be), current can flow through 7805 from output to its input and, you get a discharged capacitor.

If you want to prevent this from happening use a diode in series with the MOSFET drain. But, then, you'll barely charge the capacitor above 4.5 volts.

I figured it can only discharge through the 10K ohm resistor so I added a diode between it and the capacitor in reverse bias as in Fig 2 to prevent discharge, but it is still happening.

And of course, electrolytic capacitors are notoriously poor on self-discharging except if you buy decent components. But, because the op-amp is no longer powered, you cannot rely on its inverting input not to draw several mA of current and discharge the capacitor this way.

This is also another thing we have to protect against and we might choose to use a resistor in series with the op-amp input but, it won't prevent a slow discharge of the output capacitor.

As an aside, the BC547 and LED are going to cause problems the way you connected them. Use a current limit resistor in series with the LED and probably a base series resistor of 10 kΩ.

  • \$\begingroup\$ I implemented the suggested changes. I added a diode in series with the drain of the MOSFET and to compensate for the voltages being much below 5, I replaced the 7805 with a 7809 and added a voltage divider circuit to bring the output voltage to roughly 6V so the 0.7 drop will keep it slightly above 5. The capacitors are still discharging at a fast rate though. I checked the op-amp and the comparator doesn't seem to be working as I expected it to, so it could be a fault in that. I am going to replace the op amp and try with a different one. I also added the resistor to the inverting input \$\endgroup\$
    – RishiC
    Aug 5, 2023 at 5:29
  • \$\begingroup\$ A fast rate? From what voltage to what voltage in how many seconds? Have you tried them on their own to see what the self-discharge rate is? \$\endgroup\$
    – Andy aka
    Aug 5, 2023 at 9:07
  • \$\begingroup\$ Yes, what I mean by fast rate is as if they're connected in a discharging circuit. In about 15 seconds or so the capacitors are discharging almost completely and I cannot pinpoint the fault in the circuit for it. They go from about 5.3V to 1.2 or so in that time \$\endgroup\$
    – RishiC
    Aug 8, 2023 at 4:09
  • \$\begingroup\$ And that's the self-discharge rate? \$\endgroup\$
    – Andy aka
    Aug 8, 2023 at 7:58
  • \$\begingroup\$ No it shouldn't be that high. I had developed a simple circuit before this one in which I charged the capacitors to 5.5V, disconnected the charging circuit, and after I measured the voltage after about an hour or so it was close 5.3 \$\endgroup\$
    – RishiC
    Aug 8, 2023 at 8:15

So it's a capacitor and connected to op-amp input.

Capacitors self-discharge, some leak more and some less, depending on the type, chemistry and construction of the capacitor.

The op-amp input also is not ideal and perfect. Also having voltages present on inputs of unpowered chips meand there will be leakage currents.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.