Anda di halaman 1dari 14

SPICE Basics

Inside a Typical SPICE file

The heart of your SPICE file is the netlist, which is simply a list of components and
the nets (or nodes) that connect them together. As an example, we'll create a netlist for
a simple low-pass RC filter. Just draw the schematic, then assign names for the resistor,
capacitor, voltage source (R1, C1, VS) and node numbers (1 and 2). Ground is the only
exception whose node is always numbered 0.

Then generate a text file like the one below.


LPFILTER.CIR - SIMPLE RC LOW-PASS FILTER
*
VS 1 0 AC 1 SIN(0VOFF 1VPEAK 2KHZ)
*
R1 1 2 1K
C1 2 0 0.032UF
*
* ANALYSIS
.AC DEC 5 10 10MEG
.TRAN 5US 500US
*
* VIEW RESULTS
.PRINT AC VM(2) VP(2)
.PRINT TRAN V(1) V(2)
*
.PROBE
.END
Components

As you can see, much of the netlist is intuitively obvious: name a component, designate
the nodes where it's connected, and give it a value. For example,
RS 1 2 1000

describes a 1000 ohm resistor connected between nodes 1 and 2. Just follow a few rules
- all resistors names begin with R, capacitors with C, voltage sources with V, etc.

Voltage Source

SPICE has many voltage sources available: SINE, PULSE, AC, DC, etc. For this
example, the voltage source statement has two functions.
VS 1 0 AC 1 SIN(0V 0.2V 10kHz)

First, it creates an AC signal source between nodes 1 and 0 for AC (frequency)


Analysis. Second, it also generates a sinewave source SIN for the Transient (time)
Analysis. This sine wave has a DC offset of 0 V, a peak amplitude of 0.2 V and a
frequency of 10 kHz.

AC & Transient Analysis

SPICE is capable of performing both AC (frequency) Analysis and Transient (time)


Analysis. SPICE also performs a number of other analyses like DC, Sensitivity, Noise
and Distortion. The command
.AC DEC 5 10 10MEG
tells SPICE to run an AC Analysis at 5 points per Decade in the frequency range from
10 Hz to 10 MHz. The command
.TRAN 0.001MS 0.2MS

requests a Transient (time) Analysis TRAN for a duration of 0.2 ms and prints out the
results at 0.001 mS intervals.

Windows Plot Viewer

What analysis results do you want to see? Most SPICE versions today automatically
open a separate plot window after running a simulation. Through pull-down menus
typically named Add Plot or Add Trace, you can enter variables like V(2) or I(R1) to
be plotted.

Some viewers list all of the variables and you just click on the ones you want to see. As
a bonus many plotting windows let you enter calculations like V(2)*I(VS) or V(2)-
V(1). The more sophisticated versions go a step further by providing operations on
variables like AVG( V(2) ) or RMS( V(2)*I(VS) ).

NOTE SPICE Simulator will save the variables for the plot window if you include
the
.PROBE

statement in the netlist.

You can display the magnitude, real part, imaginary, part, phase, etc of the variables for
the AC Analysis. Just add the appropriate suffix as follows:

Voltage Current Variable


V( ) I( ) (no suffix) Magnitude
VM( ) IM( ) Magnitude
VP( ) IP( ) Phase
VR( ) IR( ) Real Part
VI( ) II( ) Imaginary Part
Printing & Plotting Results

Most versions of SPICE also print the results to a text file named filename.OUT. The
PRINT command places the numerical results in a table.
.PRINT AC VM(2)
.PRINT TRAN V(1) V(2)

The statements above prints the voltage magnitude at node 2 for the AC Analysis and
the voltages at nodes 1 and 2 for the Time Analysis.

The PLOT command creates a line-printer like graph of the data.

.PLOT TRAN V(1) V(2)


.PLOT AC VM(2)

Both results are generated in a text file named LPFILTER.OUT

Comments

You can add a comment or ignore any statements by placing a * at the beginning of
the line. This is a great way to label circuit sections, include some simple notes in the
file, or remove a component.
The first line of a netlist is always a comments, regardless of its first character.

Apart from first line Other Lines beginning with * will treats as comments.

$ sign is used for comments that do not begin in the first character position on a line.

For Example

* comment_on_a_line

HSPICE statement $ comment_following HSPICE_Input


Why Use Subcircuits

You can think of a subcircuit as being similar to a subroutine in software programming.


Just as subroutines uses the single definition of code many times over, a subcircuit uses
the definition of a circuit many times over. This saves the tedium of creating multiple
blocks of a circuit used in many places. A model of an op amp is good example of using
a subcircuit. One model can be used in multiple amplifiers of your circuit. If you need
to change all of the op amps, just change the single definition of the subcircuit.

The subcircuit is defined by the statements

.SUBCKT < subcircuit name> <node A> <node B> ...

Subcircuit definition.

.ENDS

The node numbers and component names in the definition will be separate from those
in the main circuit. The only exception is node 0, the global ground reference. To place
your subcircuit into the main circuit use the statements
XCircuitName <node 1> <node 2> ... <definition name>

When the simulation is run, a subcircuit is created with its <node A> connected to
<node 1> of the main circuit and so on.

Subcircuit Example

Heres a quick example to show how a subcircuit called OPAMP1 is used for both
devices XOP1 and XOP2 in a cascaded amplifier circuit. Weve labeled the subcircuit
node numbers in parentheses for clarity.
Heres a SPICE subcircuit schematic for the guts of an op amp.

The complete netlist of the circuit appears below.


AMP2.CIR CASCADED OPAMPS
*
VS 1 0 AC 1 SIN(0 1 10KHZ)
*
R1 1 2 5K
R2 2 3 10K
XOP1 0 2 3 OPAMP1
R3 4 0 10K
R4 4 5 10K
XOP2 3 4 5 OPAMP1
*
* SINGLE-POLE OPERATIONAL AMPLIFIER MACRO-MODEL
* connections: non-inverting input
* | inverting input
* | | output
* | | |
.SUBCKT OPAMP1 1 2 6
* INPUT IMPEDANCE
RIN 1 2 10MEG
* DC GAIN (100K) AND POLE 1 (100HZ)
EP1 3 0 1 2 100K
RP1 3 4 1K
CP1 4 0 1.5915UF
* OUTPUT BUFFER AND RESISTANCE
EOUT 5 0 4 0 1
ROUT 5 6 10
.ENDS
*
* ANALYSIS
.TRAN 0.01MS 0.2MS
* VIEW RESULTS
.PLOT TRAN V(1) V(5)
.END

The subcircuit is defined between the statements

.SUBCKT OPAMP1 1 2 6 and .ENDS

The subcircuit OPAMP1 gets inserted into two places of the main circuit by the
statements
XOP1 0 2 3 OPAMP1
XOP2 3 4 5 OPAMP1

For XOP1, the subcircuit nodes (1), (2) and (6) connect to main circuit nodes 0,
2 and 3. Likewise, for XOP2 the subcircuit nodes (1), (2) and (6) connect to main
circuit nodes 3, 4 and 5.

SPICE Units

The default units for SPICE are volts, amps, ohms, farads, henries, watts etc. You can
specify values in decimal form, 0.0056, or exponential form, 5.6e-3. SPICE also
recognizes the following abbreviations:
F E-15 femto
P E-12 pico
N E-9 nano
U E-6 micro
M E-3 milli

K E+3 kilo
MEG E+6 mega
G E+9 giga
T E+12 tera
For clarity you can add letters to the abbreviation as in 1U or 1UFARADS and both are
read as the value 1e-6. SPICE processes the first letter after the number and ignores the
rest.

Brief SPICE Summary

Here's a brief reference of the SPICE devices and statements. Parameters enclosed by
braces { } are required, while, those in brackets [ ] are optional. Parameters followed
by an asterisk { }* should be repeated as necessary. Each SPICE vendor may have other
parameters or commands unique to their version of SPICE.

DEVICES
C device - Capacitor.
C{name} {+node} {-node} [{model}] {value} [IC={initial}]
Examples:
CLOAD 15 0 20pF
CFDBK 3 33 CMOD 10pF IC=1.5v

D device - Diode.
D{name} {+node} {-node} {model} [area]
Examples:
DCLAMP 14 0 DMOD

I device - Current Source.


I{name} {+node} {-node} [[DC] {value}] [AC {mag} [{phase}]]
Examples:
IBIAS 13 0 2.3mA
IAC 2 3 AC .001
IPULSE 1 0 PULSE(-1mA 1mA 2ns 2ns 2ns 50ns 100ns)
I3 26 77 AC 1 SIN(.002 .002 1.5MEG)
See Input Sources for PULSE, SIN and more.
Top
J device - Junction FET.
J{name} {d} {g} {s} {model} [{area]}
Examples:
JIN 100 1 0 JFAST

K device - Inductor Coupling.


K{name} L{name} { L{name} }* {coupling}
Examples:
KTUNED L3OUT L4IN .8
KXFR1 LPRIM LSEC .99

L device - Inductor.
L{name} {+node} {-node} [model] {value} [IC={initial}]
Examples:
LLOAD 15 0 20mH
L2 1 2 .2e-6
LSENSE 5 12 2uH IC=2mA

M device - MOSFET.
M{name} {d} {g} {s} {sub} {mdl} [L={value}] [W={value}]
+ [AD={value}] [AS={value}]
+ [PD={value}] [PS={value}]
+ [NRD={value}] [NRS={value}]

Examples:
M1 14 2 13 0 PNOM L=25u W=12u
M13 15 3 0 0 PSTRONG

Q device - Bipolar Transistor.


Q{name} {c} {b} {e} [{subs}] {model} [{area}]
Examples:
Q1 14 2 13 PNPNOM
Q13 15 3 0 1 NPNSTRONG 1.5

R device - Resistor.
R{name} {+node} {-node} [{model}] {value}
Examples:
RLOAD 15 0 2k

S device - Voltage-Controlled Switch.


S{name} {+node} {-node} {+control} {-control} {model}
Examples:
S12 13 17 2 0 SMOD

T device - Transmission Line.


T{name} {A+} {A-} {B+} {B-} Z0={value}
[TD={val} | F={val}[NL={val}]]
Examples:
T1 1 2 3 4 Z0=220 TD=115ns
T2 1 2 3 4 Z0=50 F=5MEG NL=0.5

V device - Voltage Source.


V{name} {+node} {-node} [[DC] {value}] [AC {mag} [{phase}]]
Examples:
VBIAS 13 0 2.3mV
VAC 2 3 AC .001
VPULSE 1 0 PULSE(-1mV 1mV 2ns 2ns 2ns 50ns 100ns)
V3 26 77 AC 1 SIN(.002 .002 1.5MEG)
See Input Sources for PULSE, SIN and more.

X device - Subcircuit Call.


X{name} [{node}]* {subcircuit name}
Examples:
X12 100 101 200 201 DIFFAMP

CONTROLLED SOURCES
E device - Voltage Controlled Voltage Source VCVS.
E{name} {+node} {-node} {+cntrl} {-cntrl} {gain}
E{name} {+node} {-node} POLY({value}) {{+cntrl} {-cntrl}}* {{coeff}}*
Examples:
EBUFF 1 2 10 11 1.0
EAMP 13 0 POLY(1) 26 0 500

F device - Current Controlled Current Source CCCS.


F{name} {+node} {-node} {vsource name} {gain}
Examples:
FSENSE 1 2 VSENSE 10.0

G device - Voltage Controlled Current Source VCCS.


G{name} {+node} {-node} {+control} {-control} {gain}
Examples:
GBUFF 1 2 10 11 1.0
H device - Current Controlled Voltage Source CCVS.
H{name} {+node} {-node} {vsource name} {gain}
H{name} {+node} {-node} POLY({value}) { {vsource name} }* {{coeff}}*
Examples:
HSENSE 1 2 VSENSE 10.0
HAMP 13 0 POLY(1) VIN 500

INPUT SOURCES
EXPONENTIAL
EXP( {v1} {v2} {trise_delay} {tau_rise} {tfall_delay} {tau_fall) )
PULSE
PULSE( {v1} {v2} {tdelay} {trise} {tfall} {width} {period} )
PIECE WISE LINEAR
PWL( {time1} {v1} {time2} {v2} ... {time3} {v3} )
SINGLE FREQUENCY FM
SFFM( {voffset} {vpeak} {fcarrier} {mod_index} {fsignal} )
SINE WAVE
SIN( {voffset} {vpeak} {freq} {tdelay} {damp_factor} {phase} )

ANALOG BEHAVIORAL MODELING


VALUE
E|G{name} {+node} {-node} VALUE {expression}
Examples:
GMULT 1 0 VALUE = { V(3)*V(5,6)*100 }
ERES 1 3 VALUE = { I(VSENSE)*10K }

TABLE
E|G{name} {+node} {-node} TABLE {expression} = (invalue, outvalue)*
Examples:
ECOMP 3 0 TABLE {V(1,2)} = (-1MV 0V) (1MV, 10V)
LAPLACE
E|G{name} {+node} {-node} LAPLACE {expression} {s expression}
Examples:
ELOPASS 4 0 LAPLACE {V(1)} {10 / (s/6800 + 1)}
FREQ
E|G{name} {+node} {-node} FREQ {expression} (freq, gain, phase)*
Examples:
EAMP 5 0 FREQ {V(1)} (1KZ, 10DB, 0DEG) (10KHZ, 0DB, -90DEG)
POLY
E|G{name} {+node} {-node} POLY(dim) {inputs X} {coeff k0,k1,...} [IC=value]
Examples:
EAMP 3 0 POLY(1) (2,0) 0 500
EMULT2 3 0 POLY(2) (1,0) (2,0) 0 0 0 0 1
ESUM3 6 0 POLY(3) (3,0) (4,0) (5,0) 0 1.2 0.5 1.2
COEFFICIENTS
POLY(1)
y = k0 + k1X1 + k2X1X1 + k3X1X1X1 + ...
POLY(2)
y = k0 + k1X1 + k2X2 +
+ k3X1X1 + k4X2X1 + k5X2X2 +
+ k6X1X1X1 + k7X2X1X1 + k8X2X2X1 +
+ k9X2X2X2 + ...
POLY(3)
y = k0 + k1X1 + k2X2 + k3X3 +
+ k4X1X1 + k5X2X1 + k6X3X1 +
+ k7X2X2 + k8X2X3 + k9X3X3 + ...

STATEMENTS
AC - AC Analysis.
.AC [LIN][OCT][DEC] {points} {start} {end}
Examples:
.AC LIN 101 10Hz 200Hz
.AC DEC 20 1MEG 100MEG

.DC - DC Analysis.
.DC [LIN] {varname} {start} {end} {incr}
.DC [OCT][DEC] {varname} {start} {end} {points}
Examples:
.DC VIN -.25 .25 .05
.DC LIN I2 5mA -2mA 0.1mA VCE 10V 15V 1V

.FOUR - Fourier Analysis.


.FOUR {freq} {output var}*
Examples:
.FOUR 10KHz v(5) v(6,7)

.IC - Initial Transient Conditions.


.IC { {vnode} = {value} }*
Examples:
.IC V(2)=3.4 V(102)=0

.MODEL Device Model.


.MODEL {name} {type}
Typename Devname Devtype
CAP Cxxx capacitor
IND Lxxx inductor
RES Rxxx resistor
D Dxxx diode
NPN Qxxx NPN bipolar
PNP Qxxx PNP bipolar
NJF Jxxx N-channel JFET
PJF Jxxx P-channel JFET
NMOS Mxxx N-channel MOSFET
PMOS Mxxx P-channel MOSFET
VSWITCH Sxxx voltage controlled switch

Examples:
.MODEL RMAX RES (R=1.5 TC=.02 TC2=.005)
.MODEL QDRIV NPN (IS=1e-7 BF=30)

.NODESET Initial bias point guess.


.NODESET { {node}={value} }*
Examples:
.NODESET V(2)=3.4 V(3)=-1V

.NOISE - Noise Analysis.


.NOISE {output variable} {name} [{print interval}]
Examples:
.NOISE V(5) VIN

.PLOT Plot Output.


.PLOT [DC][AC][NOISE][TRAN] [ [{output variable}*]
Examples:
.PLOT DC V(3) V(2,3) V(R1) I(VIN)
.PLOT AC VM(2) VP(2) VG(2)

.PRINT Print Output.


.PRINT [DC][AC][NOISE][TRAN] [{output variable}*]
Examples:
.PRINT DC V(3) V(2,3) V(R1) IB(Q13)
.PRINT AC VM(2) VP(2) VG(5) II(7)
.PROBE Save simulation output PSPICE COMMAND.
.PROBE [output variable]*
Examples:
.PROBE
.PROBE V(3) VM(2) I(VIN)

.SENS - Sensitivity Analysis.


.SENS {output variable}*
Examples:
.SENS V(9) V(4,3) I(VCC)

.SUBCKT - Subcircuit Definition.


.SUBCKT {name} [{node}*]
Examples:
.SUBCKT OPAMP 1 2 101 102

.TEMP Temperature Analysis.


.TEMP {value}*
Examples:
.TEMP 0 27 125

.TF DC Transfer Function.


.TF {output variable} {input source name}
Examples:
.TF V(5) VIN

.TRAN - Transient Analysis.


.TRAN {print step value} {final time} [{no print time}
[{step ceiling value}]] [UIC]
Examples:
.TRAN 5NS 100NS
POLY (Polynomial Controlled Sources)

Polynomial controlled sources EPOLY<n>, FPOLY<n> GPOLY<n>,


HPOLY<n>
All nonlinear controlled sources are defined in Genesys by xPolyn models where x can be E, F, G, or H,
representing VCVS, CCCS, VCCS, and CCVS accordingly. The n represents the number of controls. These
models may be used with any circuit symbols that have a number of terminals from n/2 to n. If a circuit
symbol used for a model has less than n terminals, all the terminals of the model in excess of the symbols'
number will be grounded.

Genesys uses the following numbering of terminals for the models:

GPOLY<n> (VCCS)
EPOLY<n> (VCVS):

N1+, N2+, ... , Nn+, NC+, N1-, N2-, ..., Nn-, NC-

FPOLY<n> (CCCS)
HPOLY<n> (CCVS)

NC+, NC-

Where NC+, NC- are positive and negative terminals of output current or voltage of the controlled source,
while Nk+, Nk- are positive and negative terminals of the k-th control voltage, k = 1, 2, ..., n.

Controls of the current controlled sources FPOLY<n> and HPOLY<n> are defined by an additional
argument - a list of names of the voltage sources, whose currents control the source. All the controlling
sources must be at the same level of hierarchy of the same design.

All the models have an argument "COEFS" which is a list of polynomial coefficients exactly as the models
re defined in SPICE. For example, for 1-controlled sources it defines a list:

COEFS = a0, a1, a2, ... aN

defining a polynomial function:

For two controls it defines a 2-dimensional polynomial,

COEFS = a00, a10, a01, a20, a11, a02, ...


With n-controls it uses an n-dimensional summation just as in SPICE.

All the sources have the list of negative terminals in the end of the lists; this is done to have a possibility
of using device symbols with less numbers of terminals for the models; all absent terminals are grounded.

For example, the VCCS with 1 control voltage is defined by the model GPOLY1 and has the following list
of terminals:

GPOLY1: N1+, NC+, N1-, NC-

Note:
If we define a 2-terminal part with the model, it will create a part having grounded negative input
and negative output terminals. It defines the grounded current controlled source, not a non-linear
resistor, even if it uses a resistor's symbol (symbols do not affect model functionality beyond
number of nodes). A non-linear resistor may be creates using the GPOLY1 model, when both
positive input and output and negative input and output terminals are connected together.

Parameters:
COEFS - array of coefficients of polynomial formula

Current controlled sources (FPOLY<n> and HPOLY<n>) have additional parameters:

V1, V2, ..., Vn - names of voltage sources controlling the srouce. It may be any voltage source,
including signal ground (SGND model).

Anda mungkin juga menyukai