Appendix
Appendix
Introduction to SPICE
The circuits encountered in microelectronics may contain a few devices or a few million de-
vices.1 How do we analyze and design these circuits? As the number of devices in a circuit
increases, hand analysis becomes more difficult, eventually reaching a point where other
methods are required. For example, one can build a prototype using discrete components
and observe its behavior. However, discrete devices provide a poor approximation of mod-
ern integrated circuits. Furthermore, even for a few hundred devices, discrete prototypes
become prohibitively complex.
Today’s microelectronics employs simulation programs extensively. A versatile tool
used to predict the behavior of circuits is Simulation Program with Integrated Circuit
Emphasis (SPICE). While orginally developed as a public-domain tool (at University of
California, Berkeley), SPICE has evolved into commercial tools such as PSPICE, HSPICE,
etc., most of which retain the same format. This appendix provides a tutorial overview
of SPICE, enabling the reader to perform basic simulations. More details can be found
in [1].
1
Recent microprocessors contain one billion MOS transistors.
873
874 Appendix A Introduction to SPICE
Vout
R1 V in
V in Vout
1 kΩ
1 pF C1
1 ω
R 1 C1
(a) (b)
r1 r1
in
in out out
1 kΩ 1 kΩ
vin
1 pF c1 1 pF c1
0 0
(c) (d)
Figure A.1 (a) Simple RC circuit, (b) its frequency response, (c) with nodes labeled, (d) with
elements labeled.
should carry some information about their respective nodes so as to facilitate reading
the SPICE description of the circuit.
(2) Label each element in the circuit. Defining the type of the element (resistors, ca-
pacitors, etc.), each of these labels must begin with a specific letter so that SPICE
recognizes the element. For example, resistor labels must begin with r, capacitor la-
bels with c, inductor labels with l, diode labels with d, and voltage sources with v.2
Our simple circuit now appears as shown in Fig. A.1(d).
(3) Construct the “netlist,” i.e., a precise description of each element along with the nodes
to which it is tied. The netlist consists of text lines, each describing one element, with
the following format for two-terminal devices:
r1 in out 1k
c1 out 0 1p
Note that the units are specified as a single letter (k for 103 , p for 10−12 , etc.). For the
input voltage source, we write
vin in 0 ac 1
2
SPICE does not distinguish between lower-case and upper-case letters.
A.1 Simulation Procedure 875
where ac denotes our desire to determine the frequency (ac) response and hence
designates Vin as a sinusoidal voltage source whose frequency will be varied. The
value 1 at the end represents the peak amplitude of the sinusoid. Also note
that the first node, “in,” is assumed to be the positive terminal of the voltage
source.
The netlist must also include the “type of analysis” that we wish SPICE to perform.
In our example, SPICE must vary the frequency from one value to another, e.g., 1 MHz to
50 MHz. The corresponding command appears as
Note that each “command” line begins with a period. The first entry, “ac,” requests SPICE
to perform an “ac analysis,” i.e., determine the frequency response. The second and third
entries, “dec 200,” tell SPICE to simulate the circuit at 200 frequency values in every decade
of frequency (e.g., from 1 MHz to 10 MHz). The last two entries, “1meg 50meg,” set the
lower and upper values of the frequency range, respectively. Note that “meg” denotes 106
and should not be confused with “m,” which stands for 103 .
We need two more lines to complete our netlist. The first line of the file is called the
“title” and carries no information for SPICE. For example, the title line may read “My
Amplifier.” Note that SPICE always ignores the first line of the file, encountering errors
if you forget to include the title. The last line of the file must be a “.end” command. Our
netlist now appears as:
Note that, except for the first and last lines, the order of other lines in the netlist is unim-
portant.
What do we do with the above netlist? We must “run” SPICE on this file, which we
call, for example, [Link]. Depending on the operating system, running SPICE may entail
clicking on an icon in a graphics interface or simply typing:
spice [Link]
After the simulation is successfully run, various node voltages can be plotted using
the graphics interface that accompanies SPICE.
Figure A.2 summarizes the SPICE simulation procedure. The definition of (voltage
or current) sources in the netlist must be consistent with the type of analysis. In the above
example, the input voltage source definition contains the entry “ac” so that SPICE applies
the frequency sweep to Vin rather than to other sources.
At this point, the reader may raise many questions: How are other elements defined
in the netlist? How are the units specified? Is the order of the node labels in the netlist
important? How are other types of analysis specified? We answer these questions in the
following sections.
876 Appendix A Introduction to SPICE
Source Definitions
.Type of Analysis
.end
R1 batt R1
x
1 kΩ 1 kΩ
1.5 V v1
R2 2 kΩ R2 2 kΩ
y
R3 2 kΩ R 4 3 kΩ R3 2 kΩ R 4 3 kΩ
(a) (b)
Figure A.3
A.2 Types of Analysis 877
Solution We label the nodes as shown in Fig. A.3(b) and construct the netlist as follows:
V1 V2 Tdel Tr Tf Tw
vin in 0 pulse(0 1 0 1n 2n 5n)
where V1 , . . . , Tw are defined as depicted in Fig. A.4(a).3 We say Vin is a pulse that goes
from 0 V to 1 V with zero delay (Tdel ), a rising transition of 1 ns (TR ), a falling transistion
of 2 ns (TF ), and a width of 5 ns (Tw ). Note that the first node, “in,” is assumed to be the
positive terminal of the voltage source.
How do we tell SPICE to perform a transient analysis? The command is as follows:
where 0.2n indicates the increments (“time steps”) that SPICE must use in calculating the
response, and 10n the total time of interest [Fig. A.4(b)].
TR TF
V2
V1
10 ns
0 T del t t
0.2 ns
(a) (b)
Figure A.4 (a) Definition of pulse parameters, (b) illustration of time step.
3
The parentheses following the pulse description are for clarity and not essential.
878 Appendix A Introduction to SPICE
Example Construct a SPICE netlist for the pulse response of the circuit shown in Fig. A.5(a).
A.2
5 pF 5 pF
V in in
Vout out
c1
2 MΩ r1 2 MΩ
vin
0
(a) (b)
Figure A.5
Solution We begin with labeling the nodes and the elements [Fig. A.5(b)]. Given the time constant
R1C1 = 10 μs, we postulate that the rising and falling transitions of the input pulse can be
as long as approximately 1 μs and still appear “abrupt” to the circuit. For the pulsewidth,
we choose 30 μs to allow the output to “settle.” We therefore have
(The letter u in the pulse description denotes 10−6 .) Note that the timestep is chosen
sufficiently smaller than the pulse transition times, and the overall transient time long
enough to reveal the response after the input falls to zero.
Example Revise the SPICE netlist constructed in Example A.2 so as to observe the step response
A.3 of the circuit.
Solution We wish Vin to jump to 1 V and remain at this level. The pulse description, however,
requires a pulsewidth value. Thus, we choose the pulsewidth sufficiently larger than our
“observation window.”
vin in 0 pulse(0 1 1u 1u 1)
.tran 0.2u 30u
A.2 Types of Analysis 879
A pulsewidth of 1 s proves quite versatile for step response analyses because most of
our circuits exhibit a much faster response. Note that the overall transient time is now
30 μs, just long enough to show the response to the input rising edge.
Example Construct a SPICE netlist for the step response of the circuit depicted in Fig. A.6(a).
A.4
20 nH l1
V in in
Vout out
30 Ω r1
vin
mid
1 pF c1
0
(a) (b)
Figure A.6
Solution We begin with labeling the nodes and the elements [Fig. A.6(b)]. How do we choose the
transition time of the step? Ignoring the damping behavior of the circuit for now, we
may consider R1 /(2L1 ) = 1.5 ns as the time constant of the response and hence choose
the transition time to be about 150 ps. The netlist is as follows:
My RLC Circuit
l1 in out 20n
r1 out mid 30
c1 mid 0 1p
vin in 0 pulse(0 1 0 150p 150p 1)
.tran 25p 500p
.end
Example Suppose we wish to determine the frequency response of the RLC circuit illustrated in
A.5 Fig. A.6(a). Revise the netlist accordingly.
Solution We must often study both the transient and the ac response of circuits. For convenience,
only one file should serve both purposes. Fortunately, SPICE allows us to “comment
out” lines of the file by inserting a ∗ at the beginning of each line. We therefore repeat
the netlist from the above example, comment out the lines related to transient analysis,
and add the lines necessary for ac analysis:
880 Appendix A Introduction to SPICE
My RLC Circuit
l1 in out 20n
r1 out mid 30
c1 mid 0 1p
∗
vin in 0 pulse(0 1 0 150p 150p 1)
∗
.tran 25p 500p
∗
Added next two lines for ac analysis.
vin in 0 ac 1
.ac dec 100 1meg 1g
.end
(The letter g at the end of the .ac line denotes 109 .) As seen above, comment lines can
also serve as reminders.
A.2.3 DC Analysis
In some cases, we wish to plot the output voltage (or current) of a circuit as a function of
the input voltage (or current). Called “dc analysis,” this type of simulation requires that
SPICE sweep the input across a range in sufficiently small steps. For example, we may
write
vin in 0 dc 1
Lower Upper Step
End End Size
.dc vin 0.5 2 1m
The vin description specifies the type as dc with a nominal value of 1 V.4 The dc sweep
command begins with .dc and specifies vin as the source that must be swept. The following
two entries denote the lower and upper ends of the range, respectively, and the last entry
indicates the step size.
Example Construct a netlist to plot Vout as a function of Vin for the circuit shown in Fig. A.7(a).
A.6 Assume an input range of −1 V to +1 V with 2-mV steps.
100 Ω 100 Ω
V in in
Vout out
200 Ω
vin 200 Ω
(a) (b)
Figure A.7
4
This nominal value is arbitrary and unimportant in dc analysis.
A.3 Element Descriptions 881
Solution We label the nodes and the elements as illustrated in Fig. A.7(b). The netlist can be
written as:
Voltage Divider
r1 in out 100
r2 out 0 200
vin in 0 dc 1
.dc vin -1 +1 2m
.end
Note that the values of r1 and r2 are not followed by a unit so that SPICE assumes they
are expressed in ohms.
iin in 0 ac 1
for ac analysis.
If the circuit is configured as shown in Fig. A.8(b), then we must write
iin 0 in ac 1
Similarly, for pulse response, the current source in Fig. A.8(a) can be expressed as
where the current jumps from 0 to 1 mA with zero delay and a rising transition time
of 0.1 ns.
R1 R1
in in
out out
iin iin
C1 C1
(a) (b)
Figure A.8 Circuits for illustrating the polarity of current sources in SPICE.
882 Appendix A Introduction to SPICE
Example Study the response of the circuit depicted in Fig. A.9(a) to an input current step.
A.7
in
I in 1 kΩ 1 pF iin r1 c1
0
(a) (b)
Figure A.9
Solution Labeling the circuit as shown in Fig. A.9(b) and noting a time constant of 1 ns, we write
A.3.2 Diodes
Unlike passive elements studied thus far, diodes cannot be specified by a “value.” Rather,
the equation ID = IS [exp (VD /VT ) − 1] suggests that the value of IS must be provided.
Thus, in the example illustrated in Fig. A.10, we have
Anode Cathode Is
d1 in out is=1f
where the element name begins with d to denote a diode, the first node indicates the anode,
and the second represents the cathode. The last entry specifies the value of IS as 1 × 10−15
A.5
In some cases, a reverse-biased diode may serve as a voltage-dependent capac-
itor, requiring that the value of the junction capacitance be specified. Recall that
D1
in out
R1
5
Note that f stands for femto and not for farad. That is, a capacitor expressed as 1f in SPICE description
assumes a value of 1 fF.
A.3 Element Descriptions 883
C j = C j0 / 1 + |VR |/V0 , where VR < 0 is the reverse-biase voltage. We must therefore
provide the values of C j0 and V0 to SPICE.
The above diode line may then evolve to
(Note that the third letter in cjo is an o rather than a zero.) SPICE recognizes vj as V0 for
diodes.
Example Determine the step response of the circuit shown in Fig. A.11 if Vin jumps from 0 to 1 V
A.8 and D1 satisfies the parameters given above.
1 kΩ
V in Vout
D1
Figure A.11
Solution The voltage dependence of the junction capacitance of D1 makes the analysis of this
circuit difficult. For Vout near zero, D1 experiences a small reverse bias, exhibiting a
capacitance close to C j0 . As Vout rises, however, the capacitance falls, and so does the
time constant of the circuit. Thus, SPICE proves quite useful here.
Labeling the circuit in our mind, we write the netlist as:
d1 in out mymodel
.model mymodel d (is=1f, cjo=1p, vj=0.7)
Upon reaching the fourth entry in the diode line, SPICE recognizes that this is not a
value, but a model name and hence seeks a .model command that defines the details of
“mymodel.” The letter “d” in the .model line specifies a diode model. As seen below,
this letter is replaced with “npn” for an npn bipolar transistor and “nmos” for an NMOS
device.
884 Appendix A Introduction to SPICE
Example Plot the input/output characteristic of the circuit shown in Fig. A.12(a). Assume D1 and
A.9 D2 follow the above diode model.
D1
V in Vout
D2 1 kΩ
Figure A.12
Solution Labeling the circuit in our mind, we write the netlist as:
Diode Circuit
d1 in out mymodel
d2 out in mymodel
r1 out 0 1k
vin in 0 dc 1
.dc vin -3 +3 2m
.end
where the device name begins with the letter q to indicate a bipolar transistor, and the
first four nodes represent the collector, base, emitter, and substrate terminals, respectively.
(In most cases, the substrate of npn transistors is tied to ground.) As with diodes, the
parameters of the transistor are expressed in a model called, for example, bimod:
VCC = 2.5 V
1 kΩ
out
in Q1
emi
100 Ω
Example Construct the SPICE netlist for the circuit of Fig. A.13. Assume the input must be swept
A.10 from 0.8 V to 0.9 V.
Simple CE Stage
q1 out in emi 0 bimod
remi emi 0 100
rout out vcc 1k
vcc vcc 0 2.5
vin in 0 dc 1
.dc 0.8 0.9 1m
.model bimod npn (beta=100, is=10f)
.end
Two observations prove useful here. (1) The two resistors are labeled according to
the nodes to which they are attached. This approach allows us to find each resistor more
readily than if it is simply labeled by a number, e.g., r1. (2) In the above netlist, the term
“vcc” refers to two distinct entities: a voltage source (the first entry on the vcc line), and a
node (the second entry on the vcc line).
The model of a bipolar transistor can contain high-frequency effects. For exam-
ple, the base-emitter and base-collector junction capacitances are denoted by cje and
cjc, respectively. The effect of charge storage in the base region is represented by a
transit time, tf (equivalent to τF ). Also, for integrated bipolar transistors, the collector-
substrate junction capacitance, cjs, must be specified. Thus, a more complete model may
read:
Example Construct the netlist for the circuit shown in Fig. A.14(a), and obtain the frequency
A.11 response from 100 MHz to 10 GHz. Use the above transistor model.
(a) (b)
Figure A.14
886 Appendix A Introduction to SPICE
Two-Stage Amp
cin in inb 0.5p
rinb inb vcc 50k
q1 x inb emi 0 newmod
rx x vcc 1k
remi emi 0 2k
cemi emi 0 0.5p
q2 vcc x out 0 newmod
iout out 0 1m
vcc vcc 0 2.5
vin in 0 ac 1
.ac dec 100 100meg 10g
.model newmod npn (beta=100, is=10f, cje=5f, cjc=6f,
cjs=10f, tf=5p)
.end
A.3.4 MOSFETs
The definition of MOSFETs is somewhat similar to that of bipolar transistors but contains
more details regarding the dimensions of the device. Unlike bipolar transistors, MOSFETs
are both biased and “sized” so as to achieve certain smal-signal properties. For example,
both the transconductance and the output resistance of MOSFETs depend on the channel
length.
In order to understand how the device dimensions are specified, we first consider
the top view illustrated in Fig. A.15(a). In addition to the channel width and length,
we must also provide the source/drain dimensions so that SPICE can calculate the as-
sociated capacitances. To this end, we specify the “area” and “perimeter” of the source
and drain junctions. Denoted by “as” and “ps” for the source, respectively (and “ad”
and “pd” for the drain), the area and perimeter are computed as follows: as = X1 · W,
ps = 2X1 + 2W, ad = X2 · W, pd = 2X2 + 2W. In most cases, X1 = X2 and hence
as = ad and ps = pd.
VDD
Source Drain
RD 1 kΩ
out
Gate
M1
W as ad
in W 10
=
L 0.18
mid
X1 X2
L
(a) (b)
The value of X1,2 is determined by “design rules” for each specific technology. As a rule
of thumb, we assume X1,2 ≈ 3Lmin , where Lmin denotes the minimum allowable channel
length (e.g., 0.18 μm). In this section, we assume X1,2 = 0.6 μm.
Now consider the example shown in Fig. A.15(b), where the dashed line attached to
M1 indicates its substrate. Before considering the dimensions, we have:
As with the bipolar transistor, the terminal names appear in a certain order: drain, gate,
source, and substrate. Now we add the dimensions:
(The + sign allows continuing a line on the next.) The order of the dimensions is unimpor-
tant, but it is helpful to maintain a consistent pattern throughout the netlist so as to make
it more readable. Note that
as=6p
Note that the default unit of mobility is cm2 /s, whereas the units of other parameters are
based on the metric system. For example,
tox=0.4n
Example Figure A.16(a) shows a two-stage amplifier. Construct a SPICE netlist to plot the input/
A.12 output characteristic of the circuit. The substrate connections are not shown with
the understanding that the default is ground for NMOS devices and VDD for PMOS
transistors.
VDD = 1.8 V vdd
1 kΩ rx
10
x m2
5 0.18
V in Vout in m1 out
0.18
500 Ω rout
(a) (b)
Figure A.16
888 Appendix A Introduction to SPICE
MOS Amplifier
m1 x in 0 0 nmos w=5u l=0.18u as=3p ps=11.2u ad=3p
pd=11.2u
rx x vdd 1k
m2 out x vdd vdd pmos w=10u l=0.8u as=6p ps=21.2u ad=6p
pd=21.2u
rout out 0 500
vdd vdd 0 1.8
vin in 0 dc 1
.dc vin 0 1 1m
.model mymod nmos (uo=360, tox=0.4n, vth=0.5, lambda=0.4)
.end
For high-frequency analysis, we must specify the junction capacitance of the source
and drain areas. As illustrated in Fig. A.17, this capacitance is partitioned into two com-
ponents: the “area” capacitance, C j , and the “sidewall” capacitance, C jsw . This separation
is necessary because the values of C j and C jsw (e.g., per unit area) are typically unequal.
C jsw
Cj
In SPICE, the above capacitance components are defined differently. The area ca-
pacitance is specified per unit area, e.g., C j = 3 × 10−4 F/m2 (= 0.3 fF/μm2 ), whereas the
sidewall capacitance is defined per unit width, e.g., C jsw = 4 × 10−10 F/m (= 0.4 fF/μm).
With these specifications, SPICE simply calculates the overall junction capacitance as
C j · ad + C jsw · pd. For example, with the above values of C j and C jsw , the drain junction
capacitance of M1 in Example A.12 is equal to:
Note that, if the area and perimeter values are absent in the netlist, SPICE may use a
default value of zero, thus underestimating the capacitances in the circuit.
The source/drain junction capacitances exhibit a voltage dependence that may not
follow the square-root equation associated with “abrupt” pn junctions. SPICE allows an
A.4 Other Elements and Commands 889
(cjo, mj)
and
(cjswo, mjsw)
where the “level” denotes a certain complexity for the model. In practice, higher levels
with many more parameters are used. Similarly, a PMOS model may be constructed as
follows:
A C
3 V AB
B D
Note the element name begins with the letter “e” to signify a voltage-dependent voltage
source. The next two entries are the output nodes, with the first representing the positive
terminal. The entry poly(1) indicates a first-order polynomial relationship between VC D
and VAB . Next, the controlling (input) nodes are specified, and the zero is entered to
denote a zero additional dc voltage. Finally, the gain is specified. In a more general case,
this expression can realize VC D = α + βVAB , where α is the dc value (zero in the above
example) and β is the gain (3 in the previous example).
Example The circuit of Fig. A.19(a) employs an op amp with a gain of 500. Construct a SPICE
A.13 netlist for the circuit.
10 k Ω 10 k Ω
1 kΩ 1 kΩ rf
in out
X Vout r1 X
V in eopamp
(a) (b)
Figure A.19
Solution We first draw and label the circuit as shown in Fig. A.19(b). Thus,
r1 in x 1k
rf x out 5k
eopamp out 0 poly(1) x 0 0 -500
For the voltage-dependent current source depicted in Fig. A.20, the description is as
follows:
g1 c d poly(1) a b 0 0.05
where the letter g denotes a voltage-dependent current source and the gain is specified as
1/(20 ) = 0.05 −1 .
Current-controlled voltage and current sources are also described in a similar manner,
but they are rarely used.
A C
Gm V AB
B D
Gm = ( 20 Ω )–1
.ic v(x)=0.5
REFERENCE
1. G. Roberts and A. S. Sedra, SPICE, Oxford University Press, 1997.