# Charging one capacitor with another capacitor in LTspice

I'm trying to simulate charging of one capacitor $C_2$ by another $C_1$ using LTspice. Following the derivations in this video, I found that in the end, both capacitors $C_1$ and $C_2$ should end up with a voltage of $\frac{C_1*V_0}{C_1 + C_2}$, where $V_0$ is the voltage to which $C_1$ is initially charged. I have attached figures here showing my simulation and my result.

Initially, $C_1$ and $C_2$ are both at 0 V, as expected. After 10 ms, when S1 is closed, $C_1$ charges. With a time constant of 1 ms, $C_1$ charges fully in about 5 ms, as expected. After 20 ms, S2 is opened back up, and, as expected, $C_2$ retains its charge. (At this point, $C_2$ has already begun to charge slightly, which contradicts my expectations.) After 30 ms, when S2 is closed (while S1 is still open), I expect $C_2$ to charge up while $C_1$ discharges until they meet somewhere in the middle. However, I see a rapid drop in voltage on $C_1$ and a sharp increase and decrease in voltage on $C_2$.

I am not sure why this is but I have tried a couple of modifications. First I added a 1 k-ohm resistor in series with C2. The simulation and results are shown below. I'm not sure why how or why closing S2 causes the voltage on $C_1$ to change so rapidly (that too, for $C_1$, up to 16 V, which is well beyond the voltage Vin = 5V to which the capacitor was charged) and why the simulation abruptly stops displaying the voltage across $C_2$ at around 33 ms.

Finally, I decided to try a buffer amplifier instead of a resistor. The simulation and results are shown below. I'm again unable to explain why the voltages across $C_1$ and $C_2$ behave so erratically.

Could someone please explain what prevents the second capacitor from charging off the first?

Is there a way I could modify my simulation to get this to work?

This is actually a small part of a much larger circuit that I need to get working, so any help would be greatly appreciated.

I got yours to work, but I had to change a few things:

I had to change the timestep of the solver, this might be a problem because of the low amount of resistance the solver is seeing which would create a very large current between the caps. This is hard for the solver as it creates a ~200kA signal.

In a sense, the matrix has a 'dynamic range' if you put in signals that are too large in with signals that are small, it can have a hard time finding the solution. If you see spices that are anomalously high or low, you might want to insert parasitics into your design (especially physical parasitics such as plane to plane capacitances and resistances that of the copper running through a wire or a trace). What you have created here are two super capacitors separated by a superconducting switch.

The first thing I tried was a very fine timestep, which worked well with a different simulation (which I'll show below). The second thing I did was separate the models of the switches, I think this might help the matrix be a little more stable, in case it doesn't copy the model.

Now that I've written what I had above, another thing I did was drop the resistances down to 1e-7 (which is something more physical) but more importantly it's going to create currents and voltages that are below the abstol and voltol settings for the solver which are usually around 1e-12 or 1e-15. A resistance of 1e-15 is going to hit the lower tolerance limit for the solver and it won't be able to resolve the voltage. Just changing the resistance solved it for me also. (notice it dropped the current also and the shape of the spike is different.

Here is an interesting way to simulate cap to cap charging if you're interested:

• good spot on the e-15 switch resistance! – Neil_UK Jun 15 '18 at 5:29
• This happens again and again, people simply ignore the underlying numerical solver which is built in a programming language working with a CPU that deals with IEEE floats. If I'm not mistaken, this is even specified in the manual, to avoid using more than 6 orders of magnitude between adjacent values. Either there or on the ltwiki.org, I can't find it now. Honestly, people should downvote, not upvote, it happens too often. – a concerned citizen Jun 15 '18 at 6:37
• In such situations setting numdgt to a high enough value to force double instead of float can be helpful too – PlasmaHH Jun 15 '18 at 7:33
• There are multiple ways to solve this problem, but it's hard to know what the actually problem is since multiple solutions solve the problem, I think any kind of tweeking to the solver is going to get you ahead, I really like that numdgt tip that is amazing and I was not aware of that. – Voltage Spike Jun 15 '18 at 15:33
• @laptop2d, thanks so much for your explanation. I am able to replicate your results on my computer (by changing just the resistance to 1 ohm). To make sure I understand, once S2 is closed, voltages across both capacitors match almost instantly because they are in parallel and the time constant is effectively zero, correct? Also, do the voltages across both capacitors continue to increase even after both switches are opened because a switch is just represented by a large resistor (1 M-ohm here)? If so, is it alright to change this to 1 G-ohm, or would that be numerically unstable? – Vivek Subramanian Jun 15 '18 at 16:16

I don't know what's wrong with your simulation, but I tried it (somewhat differently- with time controlled switches rather than the voltage controlled switches) and it worked as expected right off.

You are seeing C2 start to charge in your simulation because the off resistance of the switch is 1M, not infinity. Modelling something as nonlinear as a switch can cause problems, however they'll typically show up as a lack of convergence.

• Thanks, @Spehro. For my larger circuit inside which this is embedded, I need to use voltage-controlled switches. Do you have any idea why the voltage-controlled switches are not doing what the time-controlled switches are? – Vivek Subramanian Jun 15 '18 at 5:09
• Your switch resistance is too low, and the solver can't resolve the currents your trying to push through it on the timescales you have – Voltage Spike Jun 15 '18 at 5:13
• What @laptop2d said, the first one is difficult, however it doesn't explain the 2nd one which should have no short times or high currents. You can also try the alternate solver, which might work better. Control Panel->Spice->Solver. – Spehro Pefhany Jun 15 '18 at 5:27
• Gotta love those superconducting circuits, too bad most of us don't have the opportunity to build any of them – Voltage Spike Jun 15 '18 at 15:35
• @laptop2d Almost everything about them is horribly expensive, unfortunately. – Spehro Pefhany Jun 15 '18 at 18:43