220 Spice Notes
220 Spice Notes
tex
Page 1
ECE 220
introduction to
Phyllis R. Nelson
220-spice-notes.tex
Page 2
The first line of this file is used as a title on output files. It is not included in the circuit
description. A common and frustrating error is caused by omitting the title.
The file must end with the command .END followed by a newline.
Comment entire lines by beginning them with * or the rest of a line by using a ;
Continue a statement on a new line with +
Phyllis R. Nelson
220-spice-notes.tex
Page 3
Phyllis R. Nelson
220-spice-notes.tex
Page 4
Sign Conventions
Two-terminal elements (including sources!) assume the load sign convention
I
The power P
Phyllis R. Nelson
220-spice-notes.tex
Page 5
Passive Elements
The <letter> that begins an element instance denotes the circuit element. The passive
elements are
Examples:
R1 5 0 20k
cload nIN GND 250pF
L4 122 21 4mH
Phyllis R. Nelson
220-spice-notes.tex
Page 6
Powers of Ten
spice .
MEG
MIL
femto
pico
nano
micro
milli
kilo
mega
giga
tera
1015
1012
109
106
103
10+3
10+6
10+9
10+12
25.4 106
MIL is used to convert distances in thousands of an inch, since spice uses metric lengths.
Phyllis R. Nelson
220-spice-notes.tex
Page 7
Independent Sources
Examples:
Vdd 4 0 5
ibias 18 4 DC 15m
V2 3 0 25V
Phyllis R. Nelson
220-spice-notes.tex
Page 8
The voltage-controlled dependent sources are defined using statements of the form
Examples:
Ex 5 1 4 3 10
v3 )
G1 2 1 (5,8) 50m
v8 )
Phyllis R. Nelson
220-spice-notes.tex
Page 9
Fds 11 9 Vsens 1.25 defines a current source connected from node 11 to node 9
that generates a current 1.25 times the current flowing through the source Vsens.
H1 30 20 v5 100k defines a voltage source connected from node 30 to node 20 and
supplying a voltage 100 k times the current through the source v5.
It is frequently necessary to add a voltage source with value 0 V to the circuit to sense
the control current for these sources!
Phyllis R. Nelson
220-spice-notes.tex
Page 10
Diodes
Diodes are defined using two statements. The netlist definition is of the form
Example:
D1 4 2 my-diode
corresponds to
D1
Phyllis R. Nelson
220-spice-notes.tex
Page 11
Parameter
Description
Units
Default
IS
Amp
1014
XTI
Temperature exponent of IS
BV
Volt
RS
Ohm
CJO
Farad
Phyllis R. Nelson
220-spice-notes.tex
Page 12
Q3 6 3 0 my-npn corresponds to
3
Q3
0
Phyllis R. Nelson
220-spice-notes.tex
Page 13
MOSFETs
The BJT again requires both a netlist statement and a .MODEL. A MOSFET is included in the
netlist with a statement of the form
Vdd
10
Md
L=1.5
W=4
Phyllis R. Nelson
220-spice-notes.tex
Page 14
Subcircuits
A subcircuit simplifies spice netlists by allowing re-use of a set of circuit elements. The
syntax is
Phyllis R. Nelson
220-spice-notes.tex
Page 15
* subcircuit example
.subckt inverter 1 2 3
*
input | |
*
output |
*
dc supply
mp 2 1 3 3 mypmos
mn 2 1 0 0 mynmos
.model mypmos pmos( ... )
.model mynmos nmos( ... )
.ends
Vdd
3
1
Vdd 30 0 dc 3.6V
vin 10 0 dc 0V
30
10
20
+
vin Xinv1 Xinv2
40
Rload
Xinv1 10 20 30 inverter
Xinv2 20 40 30 inverter
Rload 40 0 100k
.dc vin 0 3.6 0.1
.end
Phyllis R. Nelson
220-spice-notes.tex
Page 16
LIN (linear sweep) The analysis is repeated at <npts> linearly-spaced frequencies starting at
<f-start> and ending at <f-end>.
DEC (log sweep by decades) The analysis is repeated at frequencies starting with <f-start>
and ending with <f-end>. The frequencies are equally-spaced on a log10 scale with
<npts> per decade.
OCT (log sweep by octaves) The analysis frequencies start at <f-start> and end with
<f-end>, with <npts> points per octave.
A source whose frequency is swept has a type designation AC included in its element
description.
Phyllis R. Nelson
220-spice-notes.tex
Page 17
.AC Example
1
RC circuit
r1 1 2 10k
c1 2 0 1n
vin 1 0 ac 1 dc 0
.ac dec 10 .01 10
.probe
.end
vin
10k
2
1n
Phyllis R. Nelson
220-spice-notes.tex
Page 18
.DC Sweep
.DC calculates the DC voltages and currents in a circuit for a range of values of a chosen
variable or variables. The .DC command has three forms.
.DC [LIN] <var1> <s1> <e1> <d1> [<var2> <s2> <e2> <d2>]
sweeps var1 from s1 to e1 with a linear increment d1. If the second set of values is present,
the entire first analysis will be done for each value of var2.
[<var2> ...]
performs the analysis for a list of values. Again, the entire first analysis is performed for every
value in the second list.
A source whose value is used in a .DC sweep has a type designation
DC included in its
element description.
Phyllis R. Nelson
220-spice-notes.tex
Page 19
.DC Example
3
2k
1 transistor inverter
vbias 3 0 5V
vs 1 0 dc 0V
rb 1 2 20k
rc 3 4 2k
q 4 2 0 gennpn
...
.dc vs 0 5 0.05
...
.end
1
vs +
20k
2
vbias
Phyllis R. Nelson
220-spice-notes.tex
Page 20
5k
tf example
vin 1 0 dc 0.5 Vac 0.1 V
rin 1 2 5k
ro 2 0 10k
...
tf v(2) vin
...
.end
vin
10k
Phyllis R. Nelson
220-spice-notes.tex
Page 21
print-inc is the time step for the output (not the time step for the calculation!), and
t-end is the end of the simulation time period.
The optional argument print-start only reports results after that time, and UIC
indicates that the simulation should use initial conditions. (Initial conditions are set either with a
.IC command or by following the element definition of a capacitor with IC=<voltage> and
that for an inductor with IC=<current>.
Phyllis R. Nelson
220-spice-notes.tex
Page 22
T1, has rise time Tr and fall time Tf, holds v2 for a time pw, and has a period tau.
PWL ( <t1> <v1> [t2 v2 [t3 v3 ...]]
describes a piecewise-linear waveform with each t
v defining a corner.
Phyllis R. Nelson
220-spice-notes.tex
Page 23
.TRAN Example
tran example
vin 1 0 pulse(0V 5V 0 0.1n 0.1n
+ 1u 2u)
vcontrol 2 0 dc 5V
mpass 1 2 3 0 mynmos L=5u W=5u
cl 3 0 10p
...
.model mynmos nmos(kp=0.01m
+ vto-0.8)
...
.tran 0.1u 2.5u
...
.end
vcontrol
2
1
+
vin
3
CL
Phyllis R. Nelson
220-spice-notes.tex
Page 24
Phyllis R. Nelson
220-spice-notes.tex
Page 25
Phyllis R. Nelson