Capacitor Charging-Discharging Simulation

Hi everyone, Has anyone tried to simulate 2 positions of switches? I am trying simulate capacitor charging-discharging. I have a switch that controls charging and relays to activate discharging.

Thanks!

by Kzzzzzt
January 17, 2013

Um, …

Do you have a circuit, too?

Regards, Sancho

by Sancho_P
January 17, 2013

CL has a Search box.

Terms like:

charge capacitor switch

can be quite helpful when typed into it.

https://www.circuitlab.com/circuit/jddv93/forcing-initial-capacitor-voltage-0/

https://www.circuitlab.com/circuit/2xpye8/sweeping-a-switch-parameter-01/

https://www.circuitlab.com/circuit/954hs2/sweeping-a-switch-parameter-02/

https://www.circuitlab.com/circuit/d66f6n/voltage-controlled-spdt-switch-01/

:)

by signality
January 18, 2013

Here is the circuit. It would be nice if the wires stick to components for easier reorganization of wires.

https://www.circuitlab.com/circuit/9mf83r/capacitor-charger/

SW3 position A charges 2 capacitors. SW3 position B allows 2 capacitors to go in series and go on discharge mode.

Is there a way to simulate this behavior? Voltmeter cannot read anything after switching to position B. It seems the charge is not held by capacitor.

by Kzzzzzt
January 18, 2013

After seeing the Loading a Capacitor circuit and simulation by Sancho, I guess this can work.. How do you set a time delay switch?

Thanks!

by Kzzzzzt
January 18, 2013

Your SW3 isn't a time delayed switch. You need to use the dedicated one from the menu or use a voltage controlled switch driven by a signal source that turns it on and off at the times you want.

Voltmeters are only of any real use for DC Solver runs.

To see dynamic behaviour you need to set up and run a time domain simulation and probe some voltages and/or currents.

Suggest you start with a much simpler example and get the hang of driving CL and using the various switches and sources before you try to simulate more complex things.

You probably need to re-read all the Documentation and FAQ a few times and play with some examples before it all starts to make sense.

Hint: your circuit is hard to follow. Drawing circuits clearly with the minimum of looping around of wires makes them much easier to understand and for other people to help debug.

by signality
January 18, 2013

Have a look at this. Is uses a voltage controlled switch:

by mrmuh
January 20, 2013

@mmuh,

Nice, simple example but it may be a good plan to (i) give SW4 a little hysteresis (VH=1.5V VT=0.5) so that it definitely switches ON and then OFF as opposed to instantaneously turning ON-OFF right at the VT voltage and (ii) give the switch and C1 some series resistance. Otherwise your circuit generates a theoretically instantaneous switching action that also has infinite dv/dt and di/dt because the switch and cap have zero resistances. None of those things are good for getting reliable, stable results out of a simulator.

:)

by signality
January 21, 2013

Thanks for the comment!

I update the example. Is it better now?

by mrmuh
January 21, 2013

Along the right lines ...

Although it helps make the diagram readable for the novices, you don't need to explicitly add R2.

If you right click on C1 and select

Edit Parameters

then you can enter a value of, say, 10m for the R_ESR parameter. This is about right for the ESR of a ceramic cap.

Similarly you can add a small resistance to SW4 using the R_ON parameter. Depending on whether you want to represent the ON resistance of a relay, a MOSFET or maybe an analogue switch, you can set R_ON to anywhere between about 10m to 100.

Double clicking on a component gets you to the same

Edit Parameters

option.

:)

by signality
January 21, 2013

When I add 10m R_ESR to C1, the time domain simulation does not work. "Running transient solver...", but the does not make any progress.

Adding 10m R_ON to SW4 works.

by mrmuh
January 21, 2013

Hmmmm.

That took a bit of thinking about.

It turns out that there is an interesting relationship between R_ON and R_ESR.

Stop reading now if you don't want to get splashed by some very grubby stuff about simulator and device internals.

At the instant when the the voltage at the control input to the switch reaches (VT+VH), the switch turns on. There is then an attenuator between the internal voltage across the cap and the external voltage across the cap, i.e. at the input to the switch, formed by R_ESR and R_ON.

If the resulting voltage at the control input to the switch is < (VT-VH) then the switch will turn off again.

SInce this happens extremely fast (effectively it is instantaneous but in CL space it happens at the shortest step time that CL can use during that particular simulation) we can consider that the reduction in the internal capacitor voltage during the switch ON time is negligible. Hence the voltage at the control input to the switch jumps back up to (VT+VH) instantaneously and the switch closes again, repeating the cycle indefinitely.

This is why CL gets stuck. It is having to do calculations on a circuit that is self oscillating at the minimum timestep available to CL. It is not clear how CL's solvers work but this may be somewhere in the ns or shorter period.

Now in fact this is not exactly right because the voltage across the capacitor does drop very slightly when the switch turns on and it rises very slightly when the switch turns off due to the charging current through the 100k resistor. However, to all practical intents and purposes, over the time intervals being considered, their effects can be considered negligible or self-cancelling.

So, here are the sums describing the condtitions for which the switch will just self oscillate at the frequency set by the simulator minimum timestep.

(Vt+Vh)*R_ON/(R_ON+R_ESR) = Vt-Vh

R_ON = (vt-vh)/(vt+vh)*(R_ON+R_ESR)

let (vt-vh)/(vt+vh) = k

R_ON-k*R_ON = k*R_ESR

R_ON = k*R_ESR/(1-k)

So for example, with

VT = 2V;

VH = 0.5V;

and

R_ESR = 10m,

then for

R_ON > 15m,

the circuit should oscillate at somewhere below the maximum frequency set by the minimum step time.

For the same values with;

R_ON < 15m,

the example should run at the minimum time step and may just appear to have stopped or be hogging all the (in CL's case) browser resources.

The exact behaviour will vary from one simulator to another depending on how the minimum step time is set and/or adjusted during a simulation run and how the simulator handles running continuously at this timestep.

by signality
January 21, 2013

I found the time delay switch and voltage controlled switch.. I can't believe I missed those 2 - too excited to simulate.

Thanks everyone.

By the way, is there a way to make the wire snap unto a component? So that when you move around the component, there is no need to rewire the circuit.

Thanks!

by Kzzzzzt
January 21, 2013

"By the way, is there a way to make the wire snap unto a component? So that when you move around the component, there is no need to rewire the circuit."

Sadly, no.

It has been raised several times under Feature Requests.

by signality
January 21, 2013

I was able to try timed switch in conjunction with relays in another circuit. However below, I am getting "Solver returned no data".

https://www.circuitlab.com/circuit/mr93yb/voltage-adder/

The circuit charges the 2 capacitors in parallel in the first stage. Then when the switch changes, the 2 capacitors become in series and disconnected from source, thereby doubling the voltage.

I can't seem to simulate this. Any ideas guys?

Thanks!

by Kzzzzzt
January 21, 2013

You have set zero inductance and inductance in both relays.

Compare this with (a) the default values in the CL models and (b) manufacturer's datasheet values.

Put in realisitc values and it will run.

:)

by signality
January 22, 2013

Post a Reply

Please sign in or create an account to comment.