Why does SPICE use a current source for intial capacitor voltage ? - Page 1
Forum section: electronics / beginners

author: MathWizard
author_rank: Super Contributor
timestamp: June 02, 2025, 11:12:02 pm
content: I'm just reading some SPICE manual and they say for DC analysis, when the initial capacitor voltage or inductor current is specified, then at some point after they work out the initial IC or VL, they then use a current source for the cap, and Vsource for the inductor. So what's the point of that ?I know an off current source would be open like the cap, and an off Vs would be short for the inductor. Ok I probably answered then, and for DC analysis once the cap current decays, or the inductor voltage decays, then those sources would be zero, like the DC model.https://www2.eecs.berkeley.edu/Pubs/TechRpts/1975/ERL-520.pdf

author: Zero999
author_rank: Super Contributor
timestamp: June 03, 2025, 10:18:09 am
content: No, the opposite is true. If the initial voltage is specified on a capacitor, then it's treated as a voltage source and if the initial current is specified for an inductor, then it's treated as a current source.The reason for this is, at time = zero, a capacitor is a voltage source and an inductor is a current source. For example, 10V across a charged capacitor, always is 10V at the instant a load is connected, irrespective of the capacitance and load impedance.

author: Grandchuck
author_rank: Super Contributor
timestamp: June 03, 2025, 12:21:51 pm
content: With a current source the change in capacitor voltage is a straight line function.

author: Zero999
author_rank: Super Contributor
timestamp: June 03, 2025, 12:30:10 pm
content: Quote from: Grandchuck on June 03, 2025, 12:21:51 pmThat's irrelevant as far as DC analysis is concerned, because the simulator is modeling what happens when the circuity is initially powered i.e. it's startup state.

author: MathWizard
author_rank: Super Contributor
timestamp: June 05, 2025, 08:05:16 am
content: Quote from: Zero999 on June 03, 2025, 10:18:09 amWell that's also how I do ODE's of this stuff, and I would come up with some initial currents for a capacitor, or voltage for some inductor with a given current that can't change instantaneously. But I never bother to replace the cap with a current source.But they say for SPICE2 DC analysis, they would actually put in a current source as the cap, instead of a charged cap, like below. So I was thinking that if for any reason, they wanted to ignore the cap again, in their DC analysis, they would just make that current source zero, just like an open cap.Well I don't know where LTSpice gets the extra 3.3uV from in this example below

author: PGPG
author_rank: Frequent Contributor
timestamp: June 05, 2025, 08:43:29 am
content: Quote from: MathWizard on June 05, 2025, 08:05:16 amI understand that text that if you specify as initial condition voltage at capacitor than it is replaced with Vsource, but if you specify as initial condition the current in capacitor it is replaced with Isource.

author: Zero999
author_rank: Super Contributor
timestamp: June 05, 2025, 09:11:16 am
content: Quote from: MathWizard on June 05, 2025, 08:05:16 amI didn't read the entire attachment.Looking at it again. It doesn't appear to be right.QuoteI think the I'veunderlinedis correct and theitalicizedtext is wrong.The extra 3.3µV in your results, is most likely a rounding error.I've also simulated it and can confirm it treats capacitors as voltage sources and inductors are treated as current sources.

author: showman
author_rank: Contributor
timestamp: June 06, 2025, 12:31:49 am
content: LTSpice is not SPICE2. I think the text is likely correct. First it describes what a generic simulation program might do and then says what specifically SPICE2 does. Quick test with it shows that the same circuit,Code:currents and voltagesc1 1 0 1ur1 1 0 1k.ic v(1)=1.op.endgives 0 V at node (1). Actual transient analysis is needed to start from 1 V and even then only if UIC is set and in that case the initial operating point calculation is skipped altogether. Without UIC it is skipped too and instead it finds the "initial transient solution", in which case according to the manual,"the node voltages specified on the .IC card will be forced to the desired initial values during the bias solution.". However actually it does something which can result in lower initial voltage. For example with this circuit it starts from 0.9990 V, but with 1ohm resistor only at 0.5 V (some series resistor? large initial timestep? I don't know).As for why the capacitor as a current source, it might be kind of arbitrary. For example qucs manual sayshttps://qucs.sourceforge.net/tech/node26.html#SECTION00731000000000000000Quote

author: Zero999
author_rank: Super Contributor
timestamp: June 06, 2025, 07:25:38 am
content: But that only makes sense when the components are non-ideal. SPICE models inductors and capacitors as ideal components i.e. no series/parallel resistance. The user has to manually add resistors, if they want non-ideal components.

author: showman
author_rank: Contributor
timestamp: June 06, 2025, 02:47:04 pm
content: What specifically did you mean by "that"? Regardless, yes, the components are ideal.Let me recap. There is no singular DC analysis in SPICE2 which can make interpreting this text under question confusing.When you use .op, the capacitors are open and the inductors shorted and unlike LTSpice, the initial conditions are ignored. That's easy.When you use .tran, the capacitors and inductors are dynamic, but since the equations are not solved analytically, but numerically with finite timesteps, those components behave quasi-statically. This also leads to those behaving algebraicallyas ifyou had non-ideal current/voltage sources. It is not a physical non-idealness, but an apparent/effective one, since it depends on time step for example. Now the author of the code (not you as a user) canchoosethat capacitors be represented in that quasi-static model as current sources with internal resistances in which case the capacitor current is indeed needed for the initial conditions. In SPICE2 .op does not do it, but as the first step of .tran another type of "DC analysis" is done that finds this initial current.

author: sharow
author_rank: Contributor
timestamp: June 06, 2025, 03:53:39 pm
content: Author is 100% correct. Most circuit simulators are implemented in that way.Current through capacitor at time \$t_n\$ is$$i(t_n) = C\ v'(t_n) \qquad (\ v'(t_n)={dv \over dt}\ )$$shift \$t\$ forward by one$$i(t_{n+1}) = C\ v'(t_{n+1})$$As an aside, backward euler approximation is$$y_{n+1} = y_n + h f(t_{n+1}, y_{n+1})$$solve for \$f\$$$f(t_{n+1}, y_{n+1}) = \cfrac{y_{n+1} - y_n}{h} = \cfrac{y_{n+1}}{h} - \cfrac{y_n}{h}$$Putting these together, backward euler approximation of capacitor is$$i_{n+1} = C v'_{n+1}$$$$ = C ( \frac{v_{n+1}}{h} - \frac{v_n}{h} )$$therefore$$i_{n+1} =\frac{C}{h} v_{n+1} - \frac{C}{h} v_n$$Note that \$\frac{C}{h} v_n\$ is the dependent current source depends on the voltage across the capacitor at the previous time step.Given an initial condition, \$v_n = v_0\$.I hope this clears things up.