I'm just starting out with NGSpice, and so far I have been able to model simple DC circuits with only a voltage source and resistors and have gotten the expected currents and voltages. Now I'm trying to model the transient response of an RC circuit and am having a lot of problems.

Here is my netlist, called test-transient.cir:

Test transient circuit file for NGSpice.  2/4/2017 
* Testing transient modelling with a capacitor
* The RC time constant is 680ohms * 1 uF = 0.68ms

v1 1 0 dc 10V 
r1 1 2 680ohm
c1 2 0 1u


I start ngspice and type the following commands:

source test-transient.cir
tran 0.5us 2ms 0

and I get the following output:

Here are the vectors currently active:

Title: test transient circuit file for ngspice.  2/4/2017 
Name: tran1 (Transient Analysis)
Date: Sun Feb  5 20:08:33  2017

V(1)                : voltage, real, 4008 long
V(2)                : voltage, real, 4008 long
time                : time, real, 4008 long [default scale]
v1#branch           : current, real, 4008 long

Then I type "print V(2)" and every one of the 4008 elements in the vector is 1.000000e+01, i.e. 10V. This can't be right, I expected to see a charge-up curve of the capacitor from 0 to 10V. I also get the same result from typing "print V(1)", which in this case is expected.

Then I typed

plot v1#branch xlimit 0 2ms

and got this display:


The current drops from 0 to -600 (mA??) in less than 0.1 ms, which also looks wrong.

For the record, I had no problem modelling this circuit using the applet at http://www.falstad.com/circuit/, I got a voltage ramp-up across the capacitor in the expected time of 680us to 6.3V.

Any help would be much appreciated.

TIA, Carsten

  • \$\begingroup\$ The display "v1branch" is supposed to link to imgur.com/a/XkXNe \$\endgroup\$
    – Carsten1
    Feb 6, 2017 at 1:31

2 Answers 2


You have V1 as a DC voltage source. There is no transient switching. You can change it to a PWL or pulse source and then you will get the expected response.

  • \$\begingroup\$ Ok, I changed the voltage source line to "v1 1 0 PULSE(0 10 0.0 2NS 2NS 10S 100NS )" and things look much better now! Thank you W5VO! \$\endgroup\$
    – Carsten1
    Feb 6, 2017 at 3:49

In your codes you have forgotten to set the initial condition of the capacitor. You need to set it as 0v to inform Ngspice that the capacitor is totally discharged at the beginning. Also, as a rule of thumb, you need to give the capacitor at least 6 * TC time period (i.e. 6 * Time Constant) to fully charge.

enter image description here

Use the following codes for the simulation with your component values.

RC Charging

v1 1 0 dc 10V 
r1 1 2 680
c1 2 0 1u ic=0
.tran 50u 5m uic

plot v(2)


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.