1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104
|
<html>
<body>
<h1> 04_passive_tr: time domain simulation: tran </h1>
<h2> Scope </h2>
<p>
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.
<h2> The schematics </h2>
<p>
The single-sheet schematic contains the filter, the voltage source and
the spice command symbol.
<p>
<center>
<a href="04_passive_tr.rs"><img src="04_passive_tr.svg" width=400px></a>
<br>Click the image to get the sch-rnd sheet</center>
<p>
<h2> SPICE: what a tran simulation is </h2>
<p>
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.
<h2> Preparing for simulation </h2>
<h3> V1 </h3>
<p>
In our example, V1 uses a PULSE wave form as the stimulus on the <i>in</I> network.
The SPICE syntax of PULSE is:
<pre>
PULSE(V1 V2 TD TR TF PW PER NP)
</pre>
<p>
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.
<p>
In our example we are only interested in a sharp rising edge:
<pre>
spice/params=PULSE (0 5 1u 1u 1u 1 1)
</pre>
<p>
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.
<h3> Raw spice commands </h3>
<p>
It contains two lines:
<pre>
tran 0.1ms 200ms
plot v(in) v(mid) v(out) xlimit 0 200ms
</pre>
<p>
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.
<h2> Export and run ngspice </h2>
<p>
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).
<p>
<img src="04_passive_tr.png">
<h2> Using other implementations </h2>
<h3> gnucap </h3>
<p>
Gnucap uses a different command syntax. Modify the spice command symbol's
spice/command attribute to:
<pre>
print tran v(in) v(mid) v(out)
tran 0.1ms 200ms > plot.txt
</pre>
<p>
This tells gnucap what to print after a tran simulation then runs the tran
simulation, redirecting the printout to a file called plot.txt.
<p>
After the export, write the single word <b>spice</b> 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 <i>gnucap 04_passive_tr.cir</i> and it will dump a text
table to plot.txt. Run gnuplot and type the following command:
<pre>
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)";
</pre>
<p>
The <a href="gnucap/04_passive_tr.rs">gnucap-modified schematic is also available.</a>
<h3> xyce </h3>
<p>
TODO
|