Author Topic: Why does SPICE use a current source for intial capacitor voltage ?  (Read 1685 times)

0 Members and 1 Guest are viewing this topic.

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 2479
  • Country: ca
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
« Last Edit: June 02, 2025, 11:21:04 pm by MathWizard »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 22253
  • Country: gb
  • 0999
Re: Why does SPICE use a current source for intial capacitor voltage ?
« Reply #1 on: June 03, 2025, 10:18:09 am »
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.
 

Online Grandchuck

  • Super Contributor
  • ***
  • Posts: 1187
  • Country: us
Re: Why does SPICE use a current source for intial capacitor voltage ?
« Reply #2 on: June 03, 2025, 12:21:51 pm »
With a current source the change in capacitor voltage is a straight line function.
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 22253
  • Country: gb
  • 0999
Re: Why does SPICE use a current source for intial capacitor voltage ?
« Reply #3 on: June 03, 2025, 12:30:10 pm »
With a current source the change in capacitor voltage is a straight line function.
That'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.
 

Offline MathWizardTopic starter

  • Super Contributor
  • ***
  • Posts: 2479
  • Country: ca
Re: Why does SPICE use a current source for intial capacitor voltage ?
« Reply #4 on: June 05, 2025, 08:05:16 am »
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.

Well 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
 

Offline PGPG

  • Super Contributor
  • ***
  • Posts: 1212
  • Country: pl
Re: Why does SPICE use a current source for intial capacitor voltage ?
« Reply #5 on: June 05, 2025, 08:43:29 am »
But they say for SPICE2 DC analysis, they would actually put in a current source as the cap

I 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.
« Last Edit: June 05, 2025, 08:49:04 am by PGPG »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 22253
  • Country: gb
  • 0999
Re: Why does SPICE use a current source for intial capacitor voltage ?
« Reply #6 on: June 05, 2025, 09:11:16 am »
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.

Well 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
I didn't read the entire attachment.

Looking at it again. It doesn't appear to be right.

Quote
If initial conditions that do not correspond to the equilibrium solution are specified, then energy-storage elements are treated either as voltage sources or current sources. For exampled, if the initial capacitor voltages and inductor currents are specified, then capacitors are treated as voltage sources and inductors are treated as current sources. In SPICE, the capacitor currents and inductor voltages are the initial conditions. Hence, in dc analysis capacitors are treated as current sources and inductors are treated as voltage sources.

I think the I've underlined is correct and the italicized text 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.
 

Offline showman

  • Regular Contributor
  • *
  • Posts: 81
  • Country: 00
Re: Why does SPICE use a current source for intial capacitor voltage ?
« Reply #7 on: June 06, 2025, 12:31:49 am »
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: [Select]
currents and voltages
c1 1 0 1u
r1 1 0 1k
.ic v(1)=1
.op
.end

gives 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 says https://qucs.sourceforge.net/tech/node26.html#SECTION00731000000000000000
Quote
It is also possible to model the ideal inductor as a current source with an internal resistance which would yield a similar equivalent circuit as for the capacitor. But with the proposed model it is possible to use alike computation schemes for capacitors and inductors. Charges become fluxes, capacitances become inductances and finally voltages become currents and the other way around. Everything else (especially the coeffcients in the integration formulas) can be reused.
« Last Edit: June 06, 2025, 12:42:08 am by showman »
 

Offline Zero999

  • Super Contributor
  • ***
  • Posts: 22253
  • Country: gb
  • 0999
Re: Why does SPICE use a current source for intial capacitor voltage ?
« Reply #8 on: June 06, 2025, 07:25:38 am »
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.
 

Offline showman

  • Regular Contributor
  • *
  • Posts: 81
  • Country: 00
Re: Why does SPICE use a current source for intial capacitor voltage ?
« Reply #9 on: June 06, 2025, 02:47:04 pm »
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 algebraically as if you 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) can choose that 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.
« Last Edit: June 06, 2025, 06:05:57 pm by showman »
 

Offline sharow

  • Contributor
  • Posts: 26
  • Country: 00
Re: Why does SPICE use a current source for intial capacitor voltage ?
« Reply #10 on: June 06, 2025, 03:53:39 pm »
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.
« Last Edit: June 07, 2025, 05:58:30 am by sharow »
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf