Вы находитесь на странице: 1из 47

Introduction to

SPICE

Analog Electronics Laboratory

Introduction
SPICE: Simulation Program with Integrated
Circuit Emphasis
p
SPICE is program that simulates electronic
circuits on your PC
You can view any voltage or current waveform
in your circuit. SPICE calculates these voltages
and currents versus time (Transient Analysis)
or versus frequency (AC Analysis).
SPICE
C
was deve
developed
oped at U
University
ve s ty oof
S
California Berkeley.
SPICE3 is the latest version that UCB offers.
Analog Electronics Laboratory

SPICE Versions
Various SPICE based circuit simulators are available:
Commercial:
- HSpice
- Spectre Widely used in Industry
- Eldo
- PSpice
Free:
- WinSpice
- LTSPICE
- ngSpice
S i

Analog Electronics Laboratory

How SPICE Works?


SPICE operates like this:
1 Describe a circuit in a text file (.cir
1.
( cir
extension) called a netlist OR draw the circuit
using graphical symbols on a schematic page.
2. Run a simulation. SPICE reads the netlist and
then performs the requested analysis: AC, DC,
or TRANSIENT RESPONSE.
3. Plot or print the simulation results
In this lab we will be using the text file
(N t
(Notepad
d document)
d
t) to
t describe
d
ib the
th circuit
i it

Analog Electronics Laboratory

SPICE File Format


SPICE file consists of three parts.
Data Statements describe the
p
and the interconnections.
components
Analysis Statements tell SPICE what
type of analysis to perform on the circuit
circuit.
Output Statements specify what outputs
are to be printed or plotted.
plotted

Analog Electronics Laboratory

SPICE File Format cont


contd
d
Title statement
circuit description
Power Supplies / Signal Sources
Element Descriptions
Model Statements
Analysis Requests
Output Requests
E d Line
End
Li
Analog Electronics Laboratory

SPICE File Format cont


contd
d
Th
The first
fi line
li is
i always
l
the
h TITLE andd can contain
i any
information.
End statement is always .END.
Extra spaces are ignored.
Comment statements must begin with an asterisk (*) and
are ignored by SPICE except *DEFINE and *INCLUDE.
The datum (ground) node must be named '0'.
The
Th order
d off the
th remaining
i i lines
li
is
i arbitrary.
bit
If you want to continue a statement to the next line, then
use a "+" sign at the beginning of the next line.
Analog Electronics Laboratory

Voltage Divider Example


SIMPLE TWO RESISTOR VOLTAGE DIVIDER
*Title line
V1 1 0 10
*Connect a DC power supply Vin between node
*11 and 0
R1 2 1 10K
*Connect a 10K resistor between node 1 and 2
R2 2 0 10K
*Connect a 10K resistor between node 2 and 0
.TRAN 1NS 100NS 0NS
*Perform Transient Analysis from 0ns to 100ns
* ith a step
*with
t off 1ns
1
.PLOT TRAN V(2)
*Plot the Voltage at node 2 of transient analysis
.END
END
*End of SPICE File
Analog Electronics Laboratory

Output

Analog Electronics Laboratory

Representing basic circuit


elements
Letter
Description
An element line specifies
R
Resistor
- The circuit nodes to
C
C
Capacitor
it
which
hi h the
h element
l
is
i connected.
d
L
Inductor
-Values of the parameters
I
Independent current source
that determine the electrical
V
Independent Voltage source
characteristics.
D
Diode
The first letter of the element
Q
Bipolar Junction Transistor
name specifies
ifi the
h element
l
type.
(BJT)
M

MOSFET

Analog Electronics Laboratory

10

Scale Factors
A number field may be an
integer field (e
(e.g.
g 12,
12 -44)
44),
a floating point field
(3.14159), either an
i t
integer
or floating
fl ti point
i t
number followed by an
integer exponent (1e-14,
2.65e3), or an integer or a
floating point number
followed by one of the
scale factors.

Analog Electronics Laboratory

11

Representing basic circuit


elements
Resistors
General form is Rxxx N1 N2 VALUE
Rxxx is the name of the resistor in circuit.
N1 and
d N2 are the
h two element
l
nodes.
d
VALUE is the resistance (in ohms).
For example:
R1 1 2 100k
Analog Electronics Laboratory

12

Representing basic circuit


elements

Capacitors

Generall form
G
f
:
Cxxx N+ N- VALUE <IC=INCOND>
Cxxx is the name of the resistor in circuit.
N+ and N- are the two element nodes.
VALUE is the capacitance in Farads.
The
he (optional) initial condition is the initial (time
(time-zero)
e o) value of
capacitor voltage.

Example:

C1 32 33 1U
CSHUNT 50 51 10U IC=3 V
Analog Electronics Laboratory

13

Representing basic circuit


elements
Inductors
General form :
Lxxx N+ N- VALUE <IC=INCOND>
L
Lxxx
is the name of the resistor in circuit.
circ it
N+ and N- are the two element nodes.
VALUE is
i the
h inductance
i d
i Henries.
in
i
The (optional) initial condition is the initial (time-zero) value of
i d
inductor
current (in
(i Amps)
A
) that
h flows
fl
f
from
N+ through
N+,
h
h the
h iinductor,
d
to N-.

Example:
p

L1 32 33 1U
LSHUNT 50 51 10U IC=13.1MA
Analog Electronics Laboratory

14

Independent DC Sources
Voltage source: Vname N+ N- <DC=> DCValue
Current source: Iname N+ N- <DC=> DCValue
N+ is the positive terminal & N is the negative
terminal.
DCValue gives the value of the source.
g and current source must
The name of a voltage
start with V and I, respectively.

Analog Electronics Laboratory

15

Independent Sources
VXXXXXXX N+ N- <<DC> DCVALUE> <AC
<ACMAG <ACPHASE>>>
IYYYYYYY N+ N- <<DC> DCVALUE> <AC
<ACMAG <ACPHASE>>>
The name of a
voltage and
current source
must start with
ihV
and I,
respectively.
p
y
Analog Electronics Laboratory

16

Independent Sources (Contd)


VXXXXXXX N+ N
N- <<DC>
DC DCVALUE>
DCVALUE <AC
AC <ACMAG
ACMAG
<ACPHASE>>>
IYYYYYYY N+ N- <<DC> DCVALUE> <AC <ACMAG
<ACPHASE>>>
DC/TRAN is the DC and transient analysis value of the
source. If the source value is zero both for DC and transient
analysis, this value may be omitted. If the source value is
time-invariant (e.g., a power supply),then the value may
optionally
ti ll be
b preceded
d d by
b the
th lletters
tt DC
DC.
ACMAG is the AC magnitude and ACPHASE is the AC
phase. The source is set to this value in the AC analysis. If
ACMAG is
i omitted
itt d following
f ll i the
th keyword
k
d AC,
AC a value
l off
unity is assumed. If ACPHASE is omitted, a value of zero is
assumed. If the source is not an AC small-signal input, the
keyword AC and the AC values are omitted
omitted.
Analog Electronics Laboratory

17

Examples
VCC 10 0 DC 12
ISRC 23 21 AC 0.333 45.0
V2 28 41 DC 5 AC 00.333
333 45
45.0
0

Analog Electronics Laboratory

18

Pulse Source: PULSE()


General form:
PULSE(V1 V2 TD TR TF PW PER)
Where
Wh
V1=initial value
V2=pulsed
p
value
TD=delay time
TR=rise time
TF=fall
f ll time
i
PW=pulse width
PER=period
period
PER
Analog Electronics Laboratory

19

Example
p
VIN 3 0 PULSE(-1 1 2NS 2NS 2NS 50NS 100NS)
PULSE(V1
( V2 TD TR TF PW PER))

Analog Electronics Laboratory

20

Sin Source: Sin()


General form:
SIN(VO VA FREQ TD Theta)
VO ff t
VO=offset
VA=amplitude
TD delay
TD=delay
Theta=Damping Factor
Example:
VIN 3 0 SIN(0 1 100MEG )
Analog Electronics Laboratory

21

EXAMPLE

V1 is the amplitude
VO
VO iis th
the offset
ff t voltage
lt
To is the time delay
fo is the frequency
a is damping factor in perseconds
Analog Electronics Laboratory

22

Device Models
For Semiconductor devices we use device models
Each model specify different parameters of a device
This line appears any where in your netlist
D/Q/Mxxx N1 N2 N3.. MODName
Then any where you write
For diode
.MODEL MODName D (IS= N= Rs= CJO= ..)
For NPN/PNP BJT
.MODEL MODName NPN/PNP (BETA= VA= CJBE=)
For NMOS/PMOS MOSFET
.MODEL
MODEL MODName NMOS/PMOS (VTO
(VTO= ))
N1, N2, N3 are the terminals of the device:
N1, N2 are Anode and Cathode nodes of Diode respectively
N1,, N2,, N3,, <N4> are the Collector,, Base,, Emitter nodes of BJT respectively.
p
y
N4 is the (optional) Substrate node
N1, N2, N3, N4 are the Drain, Gate, Source and Body nodes of MOSFET
respectively.
Analog Electronics Laboratory

23

Analysis Request lines


.DC
DC Statement
S
.DC SRCNAME START STOP STEP
SRCNAME name is the name of the source.
source START and
STOP are the starting and ending value, respectively.
STEP is the size of the increment.
Example: .DC V1 1 20 2.5
When the Start and Stop values are identical (and the Step is
non-zero), .DC command produces only one value
A DC analysis
y
is automaticallyy pperformed pprior to a transient
analysis with capacitors open circuit inductors short circuit and
all time varying sources set to zero to determine the transient
initial conditions or dc operating conditions in the circuit
Analog Electronics Laboratory

24

.DC
DC Statement
Another form is
.DC
DC SRCNAM VSTART VSTOP VINCR <SRC2
SRC2
START2 STOP2 INCR2>
Example
.DC VDS 0 10 .5 VGS 0 5 1
This causes the value of the voltage source VDS
to be swept from 0 Volts to 10.0 Volts in
increments of 0.5 Volts. For each increment in the
secondd source, first
fi source is
i swept over its
i range.

Analog Electronics Laboratory

25

Example
NMOS VDS-ID CURVES
VDD 4 0 5
VDUM 4 3 0
VGS 2 0 1
M1 3 2 0 0 MN L
L=0.25U
0.25U W
W=1U
1U
.MODEL MN NMOS (LEVEL=1 TOX=2.6N VT0=0.3 GAMMA=0.2
+PHI=0.6 U0=250 LD=0.025U CJ=8E-4 CJSW=8E-12
+CGSO = 3.365E-10 CGDO=3.365E-10 LAMBDA=0.2)
.DC VDD 0 5 0.01 VGS 0 0.7 0.1
.PLOT DC I(VDUM)
.END

Analog Electronics Laboratory

26

Output

Analog Electronics Laboratory

27

Transient Analysis
.TRAN
.TRAN TSTEP TSTOP<TSTART><UIC>
TSTEP is the increment or step size.
size TSTOP is the final
time, and TSTART is the initial time. If TSTART is
omitted, it is assumed to be zero. UIC (use initial
conditions)) indicates that the user does not want SPICE to
solve for the quiescent operating point before beginning
the transient analysis. SPICE then uses the values specified
using IC=... on the various elements as the initial transient
condition.
di i
Example :
.TRAN 1NS 100NS
.TRAN 1NS 1000NS 500NS
Analog Electronics Laboratory

28

AC Statement: .AC
This statement is used to specify the frequency (AC) analysis. The format is as
follows:
.AC
AC LIN NP FSTART FSTOP
.AC DEC ND FSTART FSTOP
.AC OCT NO FSTART FSTOP
LIN stands for a linear frequency
q
y variation.
DEC and OCT for a decade and octave variation respectively.
NP stands for the number of points and ND and
NO for the number of frequency points per decade and per octave respectively.
FSTART and FSTOP are the start and stopping frequencies in Hertz.
Examples:
.AC
AC DEC 10 1 10K
.AC DEC 10 1K 100MEG
.AC LIN 100 1 100HZ

Analog Electronics Laboratory

29

.OP: Operating Point Analysis


General form:
.OP
OP
determines the DC operating point of the
circuit with inductors shorted and
capacitors opened. The output of this
analysis is automatically printed. i.e. no
explicit print command is required

Analog Electronics Laboratory

30

OUTPUT STATEMENTS
.PRINT and .PLOT
.PRINT TYPE OV1 OV2 OV3 ...
.PLOT TYPE OV1 OV2 OV3 ...
.PLOT DC V(1,2) V(3)
.PLOT TRAN I(V1)
In the original SPICE version (and the one that we will use
in the lab) we must place a DC dummy voltage source i.e.
Vdum = 0 V,
V source to measure current.
current
We then use I(Vdum) to print or plot current through the
dummy voltage source.The current entering the positive
terminal is taken as positive.
In one .PLOT statement OV1 OV2can be current or
voltage variables but not both.
Analog Electronics Laboratory

31

Example
+15V

R1
33k
CB
10uF

RC
1.2k
CC
10uF
10
F
Q1
NPN

+
-

R2
18k

RE
1.2k

Analog Electronics Laboratory

VIN

RL
1k
CE
100uF

32

Example (contd)
VDB AMP
.MODEL QMOD NPN (Is=6.734f Xti=3 Eg=1.11 Vaf=74.03 Bf=100
+Ne=1.259 Ise=0 Ikf=66.78m Xtb=1.5 Br=.7371 Nc=2 Isc=0 Ikr=0
+Rc=1 Cjc=3.638p Mjc=.3085 Vjc=.75 Fc=.5 Cje=4.493p Mje=.2593
+Vje=.75 Tr=239.5n Tf=301.2p Itf=.4 Vtf=4 Xtf=2 Rb=10)
VCC 12 0 15
VDUM 12 10 0
RC 10 9 1.2k
Q1 9 8 7 QMOD
RE 7 0 1.2K
R1 12 8 33K
R2 8 0 18K
CE 7 0 100U
CB 6 8 10U
CC 9 11 10U
RL 11 0 1K
Analog Electronics Laboratory

33

Example (contd)
VIN 6 0 AC SIN(0 10M 10000 0 0)
* Note the AC keyword in the above line which specifies that the
* VSIN has magnitude 1 for the AC analysis. Omitting the AC
* keyword will set the magnitude of VSIN to 0 for AC analysis and
*hence will result in incorrect output for the AC analysis
.OP
.TRAN 100N 1M
.PLOT TRAN V(6) V(11)
.AC DEC 100 1 1000MEG
.PLOT AC V(11)
.END
END

Analog Electronics Laboratory

34

Output:
p TRAN analysis
y

Analog Electronics Laboratory

35

Output:
p AC analysis
y

Analog Electronics Laboratory

36

Output:
p OP analysis
y

Analog Electronics Laboratory

37

Circuit Restrictions
1
+
100mA

1uF
u

0
1uF
+

1uF

+
10V

1
+

Every node in the circuit


defined for SPICE must
have a DC path to
ground
d ((node
d 0)
0).
A DC path to ground
can be through a
resistor,
i t inductor
i d t or
voltage source but not
through a capacitor or
current source.
source
In figures node 1 does
not have a valid DC path
to ground

1uF

Analog Electronics Laboratory

0
38

Circuit Restrictions
SPICE does not permit any loop to consist
exclusively of inductance(s) and/or voltage
sources.
1
+
10V

1k

1uH

SPICE does not permit series combination of


capacitors
p
and current sources.
Analog Electronics Laboratory

39

Subcircuits

A complex
l electronic
l
i circuit
i i often
f contain
i severall components, or
subsections of circuitry that are identical to each others
Examples
- opamps
- logic gates
SPICE allows a user to create subcircuits that are created once and
then can be inserted into a larger system at as many places as desired.
A subcircuit definition starts with .SUBCKT

.SUBCKT
SUBCKT SUBNAM N1 <N2,N3.>
N2 N3
SUBNAM is the subcircuit name N1,N2,N3are the node numbers in
the subcircuit that will be joined to other nodes in the main circuit and
cannot contain datum(0) node.
Examples:
.SUBCKT OPAMP 1 2 3
.SUBCKT INV IN OUT VCC
Analog Electronics Laboratory

40

Subcircuits contd
A subcircuit can contain other subcircuits, device models
and subcircuit calls.
Analysis
A l i andd output lines
li
suchh as .AC,
AC .DC,
DC .PLOT,
PLOT
cannot appear within a subcircuit definition
Any device models or subcircuit definitions included as
partt off a subcircuit
b i it definition
d fi iti are strictly
t i tl local
l l i.e.
i suchh
models and definitions are not known outside the
subcircuit definition.
Nodes not included on the .SUBCKT
SUBCKT line are strictly local,
local
with the exception of 0 (ground) which is always global.
Local nodes can be made global by using the .GLOBAL
directive (see User Manual) .

Analog Electronics Laboratory

41

Calling Subcircuits
The last statement in a subcircuit must be
.ENDS <SUBNAM>
if a subcircuit itself contains subcircuits,
subcircuits the SUBNAM
must be given in the .ENDS to specify which subcircuit
definition has been ended.
To insert a subcircuit into the main circuit,
circuit we must write a
subcircuit call
X**** N1, <N2,N3.> SUBNAM
N1 N2 are the node numbers in the main circuit that are
N1,N2
joined to subcircuit nodes specified in the .SUBCKT line
in exactly the order. SUBNAM is the name of the
subcircuit to be inserted.
Examples:
X1 6 7 8 OPAMP
X13 11 12 VCC INV
Analog Electronics Laboratory

42

Example
+5V

RC1
1k

RC2
1k
RB2
100 ohms

RB1
100 ohms

Q1
NPN

RC3
1k
RB3
100 ohms

Q2
NPN

Q3
NPN

+
PULSE
0-5V

Analog Electronics Laboratory

43

Example (contd)
3 CASCADED INVERTERS
VSUPPLY VCC 0 5
VIN 1 0 PULSE (0 5 0 0 0 10N 20N)
X1 1 2 VCC INVERTER
X2 2 3 VCC INVERTER
X3 3 4 VCC INVERTER
.SUBCKT INVERTER IN OUT VCC
Q1 OUT BASE 0 NPNMOD
RB IN BASE 100
RC VCC OUT 1K
.MODEL NPNMOD NPN(BF 100)
.ENDS
ENDS
.TRAN 1N 100N
.PLOT TRAN V(1)
( ) V(4)
( )
.END
Analog Electronics Laboratory

44

OUTPUT

Analog Electronics Laboratory

45

Download
Download and install WinSpice. Its Free
www.winspice.com
To check, double click on WinSpice icon, a
command window will open
p then ggo to
File>Open>C:\Program Files\ Ouse
Tech\WinSpice\Examples and then double click
on any .cir file.
WinSpice also has a very well written User
M
Manual.
l Go
G to start menu>All
All
Programs>WinSpice>User Manual
Analog Electronics Laboratory

46

References
11. WinSpice User Manual
Man al
2. Spice and PSpice an appendix chapter
in El
Electronic
t i Devices
D i
andd Circuits
Ci it by
Theodore F. Bogart.
In these slides we have presented only a
small subset of all SPICE capabilities. For
a complete discussion on SPICE see
WinSpice User Manual.
Analog Electronics Laboratory

47

Вам также может понравиться