Hspice does not give correct energy consumption for a RC circuit connected to a DC supply

Here is the circuit I am trying to simulate - a RC circuit driven by a DC voltage source. I measure the output across the capacitor. Assume Voltage source is 1 V. Assume capacitor is 1fF.

Case 1: Resistor = 0.001 Ohm.

Case 2 : Resistor = 0.01 Ohm

In case 1, initial current will be high, since R is smaller. And the capacitor will get charged fast.

In case 2, initial current will be lower than case 1. And the capacitor will get charged slower than case 1.

How does the energy consumption (from time 0 to the time the capacitor is fully charged) compare between case 1 and case 2? If I simulate this circuit, I get more energy for case 1 than case 2.

Theoretically, the capacitor will always store a energy of 0.5 CV^2 and the energy dissipated in resistor will be equal to 0.5 CV^2 as well making the total energy spent by supply as CV^2. That is, the energy spent in this circuit should not be dependent on the current level or the resistor value. However, the spice simulation does not show that. The energy consumption of the power supply is not always constant irrespective of the value of R.

My question is, if i increase the current and keep the voltage constant (by modifying R), should not the energy consumption remain constant for such a circuit (as shown in the picture above)?

Following is my spice code.

.param VddS=1.0
.param Lcap=1e-15
.param res=0.001

Vsrc   ptA  Gnd  VddS
R1     ptA  out1 res
Cl     out1 Gnd  Lcap

*************************************************************************
* Measurements
*************************************************************************
.PROBE  V(out1) I(Vsrc)
.OPTIONS POST PROBE
.tran 1p 1000n
.IC out1 = 0V

.measure tran tstop WHEN v(out1)='1' td=0ns rise=1 print=1

* Method 1
.measure tran Q INTEG I(Vsrc) from=0ps TO=tstop
.measure tran Eqv Param='-Q*VddS'

* Method 2
.measure tran Iavg avg I(Vsrc) from=0ns TO=tstop
.measure tran Evit Param='VddS*Iavg*(tstop)'

.end

The output from spice for R=0.01 Ohm is below.

******  transient analysis tnom=  25.000 temp=  25.000 *****
tstop=   1.3066p
q= -25.0003p  from=   0.          to=   1.3066p
eqv=  25.0003p
iavg= -19.1342   from=   0.          to=   1.3066p
evit= -25.0003p

The output from spice for R=0.001 Ohm is below.

******  transient analysis tnom=  25.000 temp=  25.000 *****
tstop=   2.1676p
q= -45.4546p  from=   0.          to=   2.1676p
eqv=  45.4546p
iavg= -20.9700   from=   0.          to=   2.1676p
evit= -45.4546p

The output from spice for R=1 Ohm is below.

******  transient analysis tnom=  25.000 temp=  25.000 *****
tstop=   1.2913p
q=-495.6683f  from=   0.          to=   1.2913p
eqv= 495.6683f
iavg=-383.8522m  from=   0.          to=   1.2913p
evit=-495.6683f

The output from spice for R=5 Ohm is below.

******  transient analysis tnom=  25.000 temp=  25.000 *****
tstop=   1.2955p
q=-100.4239f  from=   0.          to=   1.2955p
eqv= 100.4239f
iavg= -77.5151m  from=   0.          to=   1.2955p
evit=-100.4239f
• How big is the difference you see? Please provide the actual values returned by the simulations. – Elliot Alderson Feb 7 at 22:33
• Charge-conserving Spice programs are rare. – jonk Feb 7 at 23:13
• I have edited the post above with the values of energy for cases with R=0.01 and 0.001 Ohm. – sk49 Feb 7 at 23:54
• You know the truth about the energy in the resistor being constant so what is the reason you insist on using spice? – Andy aka Feb 8 at 8:23
• There was a thread, not long ago, about something very similar, on the Yahoo LTspice Group, and the OP there was proven to be mistaken at about every point in the thread. It's a long thread, but worth reading. – a concerned citizen Feb 8 at 9:37

I think your simulation is flawed. When you run a transient analysis the simulator first calculates a dc operating point. As I recall the .IC statement provides a suggestion of possible initial conditions but is not a hard requirement. Since you have just one voltage source and it is a constant value of 1.0V, that is the voltage that the simulator will use to do the operating point analysis. So, when your simulation starts the capacitor is already charged regardless of resistor value. You may be able to get the initial condition to work the way you want it to by adding UIC at the end of your .tran statement. In general, I think it is better to use a source that changes after the simulation starts.

You have set the tstop condition for when the voltage on the capacitor is exactly 1V (if the syntax is correct, I'm not convinced that the value should be in single quotes). The simulator uses floating point arithmetic, and trying to compare two floating point numbers for exact equality is always a bad idea.

So, I would change your voltage source to a pulse or PWL source. Change your stop condition to something reasonable, such as >0.999V Finally, if you are really going to simulate circuits with femtosecond or attosecond time constants then your minimum timestep may need to be much, much smaller in order to get reasonable results.

• Thank you very much @Elliot Alderson. Adding UIC helped getting equal energy values for a range of resistance values. Although I wonder why the tr0 waveform showed the voltage raising from 0V without UIC. – sk49 Feb 8 at 17:22

As pointed out before by Elliot:

.IC statement provides a suggestion of possible initial conditions but is not a hard requirement

You have set the initial condition to 0V at the capacitor node (out1) but you are also letting the simulator find a DC operating point. By only including UIC at the end of the .tran statement you will be sure that at t=0 the voltage at node out1 is indeed 0 and the two methods you listed match completely (ran the simulations myself, they make sense now :D).

Also, resolution might be a problem if you are looking for really accurate results.