In this simulation we are going to look at how a multi-stage RC filter behaves when the input voltage is switched from 0 to 5V.
The single-sheet schematic contains the filter, the voltage source and the spice command symbol.
In the tran(sient) analysis a DC solution is calculated first then a simulation is run with a fixed time stepping, updating the internal states of components (e.g. capacitor charges) and networks (voltages). The result is typically a graph with time along the X axis and voltages/currents on the Y axis.
In our example, V1 uses a PULSE wave form as the stimulus on the in network. The SPICE syntax of PULSE is:
PULSE(V1 V2 TD TR TF PW PER NP)
Voltage is changed from V1 to V2 after a delay of TD with a rising time of TR. Later the output will fall back to V1 with the falling time of TF. Pulse width is PW. All the T's and P's are in seconds. The process is repeated NP times and the period of the wignal is PER (in seconds). The last few parameters are optional.
In our example we are only interested in a sharp rising edge:
spice/params=PULSE (0 5 1u 1u 1u 1 1)
Initial delay and rise time are set very short (1 microsec) then the pulse width and period are set to 1s. The circuit will reach its steady state in a fraction of a second, so this means we are really doing only a rising edge from 0 to 5V.
It contains two lines:
tran 0.1ms 200ms plot v(in) v(mid) v(out) xlimit 0 200ms
The first line instructs spice to do the "transient analysis" with 0.1ms time stepping up to 200ms. The second tells it plot (draw) three voltages; our X axis is time (because of tran), and to display the plot between 0 and 200ms.
Because of the plot command the output is a drawing (if ngspice is run on X), consisting of a graph with three curves. Fastest is v(in), a slower, curvy trace is mid's voltage and the slowest to follow is v(out).
Gnucap uses a different command syntax. Modify the spice command symbol's spice/command attribute to:
print tran v(in) v(mid) v(out) tran 0.1ms 200ms > plot.txt
This tells gnucap what to print after a tran simulation then runs the tran simulation, redirecting the printout to a file called plot.txt.
After the export, write the single word spice in the first line of the file (e.g. using a text editor), otherwise gnucap won't know the file is in spice syntax. Then run gnucap 04_passive_tr.cir and it will dump a text table to plot.txt. Run gnuplot and type the following command:
plot "plot.txt" using 1:2 with lines title "v(in)", \ "plot.txt" using 1:3 with lines title "v(mid)", \ "plot.txt" using 1:4 with lines title "v(out)";
The gnucap-modified schematic is also available.
TODO