# How to store the difference of 2 voltages on capacitor?

Suppose we have two voltages V1 and V2 how can we store the voltage difference (V1-V2) on a given capacitor? I tried charging the top plate of the capacitor to V1 and then charged the bottom plate of the capacitor to V2. but the value of the voltage across the capacitor is not V1-V2, how can we do this?

Basically I want to perform subtraction of 2 voltages, with a simple circuit which does not consume much power and area

• Charge both simultaneously? May 29, 2018 at 3:30
• While theoretically sound, this is not going to work in the real world. May 29, 2018 at 3:32
• Connect one terminal of the capacitor to V1, and the other terminal to V2. This must be done simultaneously, not sequentially. May 29, 2018 at 3:33
• Eventually the voltage on the capacitor will change due to leakage of some sort. Also, if you allow any current to flow through the capacitor, then the voltage will change. Also I am assuming that the negative terminals of V1 and V2 are connected together. May 29, 2018 at 3:39
• @user2077648 Is this a theoretical circuit analysis question? Or, are you designing something practical? What are you ultimately trying to accomplish? May 29, 2018 at 3:50

This is standard technique and quite a good way to subtract voltages, as long as they are static/slow moving.

You use analog switches to first connect your capacitor between V1 and V2, now VCAP = V1-V2. Then you switch the capacitor to ground. Now you have V1-V2 referenced to ground. C2 holds the voltage on the output, while the capacitor is sampling. It takes some cycles for the voltages to reach equilibrium.

It is really useful if you are using an ADC in a micro, your ADC can sample the voltage when you switch to single ended, and your micro can control the switches. (C2 is not needed)

This has a lower parts count and low supply current, and lower cost than differential amplifiers. Matched resistors are not needed. It can also have far better balance/common mode performance than a simple opamp differential arrangement.

CD4053 can be used for voltages up to 18V, and 74HC4053 for voltages up to 6V (and both will work with -ve voltages) Other analog switches allow higher voltages, and you can use discrete fets, or opto-fets to do this at hundreds of volts.

simulate this circuit – Schematic created using CircuitLab

This technique is also very good with tiny input voltages, e.g thermocouples, as you can use an AC amplifier to eliminate drift and offset. e.g here we use an LM358 (filthy cheap, big offset and drift) to measure thermocouple voltages, in the presence of a large offset V2. Even though the gain is 1000, the offset is only uV at the input. This can be subtracted by the micro.

simulate this circuit

Or (this depends a bit on the application and so on) use a differential amp. Can the two voltages share the same reference?

simulate this circuit – Schematic created using CircuitLab

You might need buffering, and the time constants could be tweaked, but you get the idea.

• Could you please suggest a simpler circuit for subtracting 2 analog voltages May 29, 2018 at 5:29
• If this is too difficult or complex for you then you need to edit your question to explain what you are really trying to do. "I am trying to subtract 2 analog voltages" is not enough information. May 29, 2018 at 6:27

The problem with your idea with sequential charging is this: you will charge your capacitor to +5v. It is now positively charged in regard to your own convention. However, when you will start the negative charge to do your subtraction, the capacitor will be charge from +5v to let's say -3 volts over some period of time. It will simply swing. Now you could stop the negative charge process at the specific time that you wanted (say +2 volts), but you're not doing a reliable subtraction, you're simply guess working.

To solve this, I propose two ways (there are many more!) One is dead simple and the other is a bit more fancy to get you going further.

1) Put V1 and V2 on the same leg of the capacitor, but in opposite direction. As per this circuit:

simulate this circuit – Schematic created using CircuitLab

2) If you want to be a bit more fancy, you could use a op-amp differentiator circuit to do the mathematical subtraction. The output is then fed to your capacitor. You can take a look at the differential amplifier circuit design

• I want to perform subtraction of voltages using a simple circuit, opAmp consumes lot of power and area May 29, 2018 at 5:22
• To the OP: Are you aware that op-amps are available in small packages such as SOT-23 and even smaller? Just trying to make sure. May 29, 2018 at 6:31