A major improvement came about in March of 1985 with version 3 of SPICE (also released under public domain). Written in the C language rather than FORTRAN, version 3 incorporated additional transistor types (the MESFET, for example), and switch elements. Version 3 also allowed the use of alphabetical node labels rather than only numbers. Instructions written for version 2 of SPICE should still run in version 3, though.
Spice is an analog-circuit simulator that is used to calculate and display the circuit behaviour. It was originally developed at the Electronics Research Laboratory of the University of California, Berkeley (1975). The source code was made freely available and has been used as the basis of many commercial simulators, and academic projects.
Like any simulator, SPICE is a useful tool, but not a magic wand:- it will not create the circuit for you, and all results should always be examined thoroughly. Sometimes simulations may not run at all, and occasionally results may be misleading.
This article details basic information required to analyse a circuit using SPICE-3. It has descriptions of the most commonly used features of Spice-3 . Further information can be found on the SPICE Page and the Spice-3 User Manual.
SPICE-3 is interactive and is started with a single command and can process multiple simulations for the same input file. SPICE-3 also interacts with Nutmeg to display graphs of various types of simulations. Spice 3 is not case sensitive.
Fields on a line are separated by one or more blanks, a comma, an equal ('=') sign, or a left or right parenthesis; extra spaces are ignored. A name field must begin with a letter (A through Z).
Note: Some versions of SPICE use case sensitive element and node names during analysis, others are case-insensitive. The interactive processor is usually case sensitive and it does not consider, for example, r1 and R1 to be synonyms. One can avoid a lot of confusion by typing source files in lower-case characters.
Number fields may be integers or floating-point numbers. A floating-point number can be followed by an integer exponent or one of the following scale factors:
T = 1012 | G = 109 | Meg = 106 | K = 103 | mil = 25.4x10-6 |
m = 10-3 | u = 10-6 | n = 10-9 | p = 10-12 | f = 10-15 |
Letters immediately following a number that are not scale factors are ignored, and letters immediately following a scale factor are ignored. Hence, 10, 10V, 10Volts, and 10Hz all represent the same number, and M, MA, MSec, and MMhos all represent the same scale factor. Note that 1000, 1000.0, 1000Hz, 1e3, 1.0e3, 1KHz, and 1K all represent the same number.
Don't forget: Spice is not case-sensitive, so both scale-factors 'M' and 'm' mean 'milli-'; use 'MEG' to represent 'mega-'.
Node names can be arbitrary character strings. The 'ground' node must be present and named '0'. The circuit cannot contain a loop of voltage sources and/or inductors and cannot contain a cut-set of current sources and/or capacitors. Each node in the circuit must have a dc path to ground. Every node must have at least two connections except for transmission line nodes (to permit unterminated transmission lines) and MOSFET substrate nodes (which have two internal connections anyway).
Common Circuit ElementsFirst Letter | Circuit Element |
B | GaAs MES Field Effect Transistor |
C | Capacitor |
D | Diode |
E | Voltage-controlled voltage source |
F | Current-controlled current source |
G | Voltage-controlled current source |
H | Current-controlled voltage source |
I | Independent current source |
J | Junction Field Effect Transistor |
K | Mutual inductors (transformer) |
L | Inductor |
M | MOS Field Effect Transistor |
Q | Bipolar Junction Transistor |
R | Resistor |
S | Voltage-controlled switch |
T | Transmission Line |
V | Independent Voltage Source |
W | Current controlled switch |
Below is a brief syntax of how circuit elements are used in a Spice netlist.
ResistorsThe (optional) initial condition is the initial (time-zero) value of capacitor voltage (in volts). Note that the initial conditions (if any) apply 'only' if a transient analysis specifies the UIC option.
Independent Current / Voltage SourcesN+ and N− are the positive and negative nodes, respectively. Note that voltage sources need not be grounded. Voltage sources, in addition to being used for circuit excitation, are the 'ammeters' for SPICE, that is, zero-valued voltage sources may be inserted into the circuit for the purpose of measuring current. They, of course, have no effect on circuit operation since they represent short-circuits.
Source Model describes the type of waveform for the source. The source can be DC, sinusoidal, pulse, exponential, polynomial, piece-wise linear, or single frequency frequency modulation. In the examples, 'vin' is a 5V peak sinusoidal source of 1KHz frequency. 'vcc' is a 12V DC source connected between ground and node 5, 'iin' is an AC source of magnitude 1A (used during AC analysis), 'vmeas' is a 0 Volt DC source which can be used as an ammeter to measure current through a node.
PolarityThe syntax for the model statement is:
.MODEL Modelname Type (parameter values)For example, the spice data for a 1N4148 may be similar to:
.model d1n4148 D (IS=0.1PA, RS=16 CJO=2PF TT=12N BV=100 IBV=0.1PA)which connects nodes N1, N2, N3 of the subcircuit OPAMP to nodes 2, 4, and 17 respectively in the main circuit.
Stored ResultsFor example, a vector called "ampgain" contained in a plot called "bodeplot" must be referred to by using its full name bodeplot.ampgain To save typing the plot explicitly every time, it is possible to set a default 'current plot' by using the "setplot" command.
Interactive CommandsReads the input file amp.cir which contains a circuit netlist and/or interactive commands enclosed between the lines. Any .control statements are executed immediately.
Run: Executes the commands in the netlist and performs the simulationPrints out a list of all available vectors and notes that can be printed or plotted.
Show:Show prints out a list of model parameters for any active component that contains a .model statement.
Causes SPICE to perform an operating-point analysis to determine the the quiescent state of the circuit with inductors shorted and capacitors opened. The results of this analysis are used to calculate values for the the linearised, small-signal models of nonlinear devices.
DC: Perform a DC-sweep analysisDuring a DC-sweep analysis SPICE steps the value of a specified independent voltage or current source over the user-specified range and performs an operating point analysis at each value. This permits the evaluation of the DC transfer function, and also provides a mechanism for plotting the characteristic curves of devices and models.
Examples:The parameters define the dc transfer-curve source and sweep limits. Source-Name is the name of an independent voltage or current source. Vstart, Vstop, and Vincr are the starting, final, and incrementing values respectively. The first example causes the value of the voltage source vin to be swept from 0.25 volts to 5.0 volts in increments of 0.25 volts. A second source (Source2) may optionally be specified with associated sweep parameters. In this case, the first source is swept over its range for each value of the second source.
AC: Small-Signal AC AnalysisUse: 'dec' for decade variation, in which case N is the number of points per decade; 'oct' for octave variation, in which case N is the number of points per octave; 'lin' for linear variation, when N is the total number of points. Fstart is the starting frequency, and Fstop is the final frequency.
Tran: Perform a transient analysisTstep is the printing or plotting increment for line-printer output. For use with the post-processor, Tstep is the suggested computing increment. Tstop is the final time, and Tstart is the initial time. If Tstart is omitted, it is assumed to be zero. The transient analysis always begins at time zero. In the interval <zero, Tstart>, the circuit is analyzed (to reach a steady state), but no outputs are stored. In the interval <Tstart, Tstop>, the circuit is analyzed and outputs are stored. Tmax is the maximum step-size that SPICE uses; try Tmax=(Tstop-Tstart)/50.0 to start with.
The optional keyword 'uic' (use initial conditions) indicates that the user wants interfere with how SPICE solves for the quiescent operating point before beginning the transient analysi
Plot: Plot values on the displayPlot the given exprs on the screen (if you are on a graphics terminal). The xlimit and ylimit arguments determine the high and low x- and y-limits of the axes, respectively. The xindices arguments determine what range of points are to be plotted - everything between the xilo'th point and the xihi'th point is plotted. The xcompress argument specifies that only one out of every comp points should be plotted. If an xdelta or a ydelta parameter is present, it specifies the spacing between grid lines on the X- and Y-axis. These parameter names may be abbreviated to xl, yl, xind, xcomp, xdel, and ydel respectively.
The xname argument is an expression to use as the scale on the x-axis. If xlog or ylog are present then the X or Y scale, respectively, is logarithmic (loglog is the same as specifying both). The xlabel and ylabel arguments cause the specified labels to be used for the X and Y axes, respectively.
If samep is given, the values of the other parameters (other than xname) from the previous plot, hardcopy, or asciiplot command is used unless re-defined on the command line.
The title argument is used in the place of the plot name at the bottom of the graph.
The linear keyword is used to override a default log- scale plot (as in the output for an AC analysis).
Finally, the keyword polar to generate a polar plot. To produce a smith plot, use the keyword smith. Note that the data is transformed, so for smith plots you will see the data transformed by the function (x-1)/(x+1). To produce a polar plot with a smith grid but without performing the smith transform, use the keyword smithgrid.
Print: Print valuesPrints the vector described by the expression expr. If the expression is all, all of the vectors available are printed. Thus the command 'print col all > myfile' prints everything into the file 'myfile' (in SPICE2 format). The scale vector (time, frequency, etc) is printed in the first column.
Quit: Leave Spice3 or Nutmeg
* Basic DC circuit
V1 1 0 20
R1 3 1 4k
R2 3 2 10k
V2 2 0 -10
R3 3 0 8k
.OP
.END
The .OP command requests the operating point and Spice will computer the voltages at each circuit node, and currents through any voltage source(s). The final line is the .END statement. The netlist can be wrote in any text editor, notepad for windows, or vi, emacs or any favourite text editor in linux. The file format is ASCII text and can be saved with any extension, although .cir or .ckt is commonly used.
Loading the Netlist in Spice2[anc@orac spice_ccts]$ spice2 < basic_dc.cir 1*******08/05/11 ******** spice 2g.6 3/15/83 ********22:57:59***** 0* basic dc circuit 0**** input listing temperature = 27.000 deg c 0*********************************************************************** v1 1 0 20 r1 3 1 4k r2 3 2 10k v2 2 0 -10 r3 3 0 8k .op .end 1*******08/05/11 ******** spice 2g.6 3/15/83 ********22:57:59***** 0* basic dc circuit 0**** small signal bias solution temperature = 27.000 deg c 0*********************************************************************** node voltage node voltage node voltage ( 1) 20.0000 ( 2) -10.0000 ( 3) 8.4211 voltage source currents name current v1 -2.895E-03 v2 1.842E-03 total power dissipation 7.63E-02 watts 0 job concluded 0 total job time 0.00
The results from spice2 first display the circuit title, then the circuit netlist. Then the voltages at each node are displayed (as requested by the .OP command). The currents supplied by each voltage source are printed, followed by total power dissipation. Finally time taken to run the simulation is shown.
Loading the Netlist in Spice3Spice 1 ->
After each instruction the spice prompt increments by 1. Below is a sequence of commands used in spice3. The first command source basic_dc.cir loads the circuit (make sure that the spice netlist is on your PATH or provide the full file location. E.G. source /home/user/basic_dc.cir (linux) or source C:\spice_ccts\basic_dc.cir (windows).
[anc@orac spice_ccts]$ spice3 Program: Spice, version: 3f5 Date built: Mon Aug 26 08:06:26 UTC 2002 Type "help" for more information, "quit" to leave. Spice 1 -> source basic_dc.cir Warning: premature EOF Circuit: * Basic DC circuit Spice 2 -> run Spice 3 -> display Here are the vectors currently active: Title: * Basic DC circuit Date: Fri Aug 5 23:06:39 2011 V(1) : voltage, real, 1 long [default scale] V(2) : voltage, real, 1 long V(3) : voltage, real, 1 long v1#branch : current, real, 1 long v2#branch : current, real, 1 long Spice 4 -> print all v(1) = 2.000000e+01 v(2) = -1.00000e+01 v(3) = 8.421053e+00 v1#branch = -2.89474e-03 v2#branch = 1.842105e-03 Spice 5 -> quit
After the source command has loaded the netlist, you could view the netlist with the "listing" command. In the second command "run" is executed followed by "display". Display shows all the variables available to print, the fourth command "print all" shows all results, the v1# and v2# are currents through the voltage sources. The next example will show graphical output using nutmeg.
Series RLC CircuitThe Spice Netlist is shown below:
* Series_RLC CircuitLine 2 describes the voltage source V1 as connected between nodes 1 and 0. The waveform type is a Sinusoidal Wave and the number in parentheses (0 5 1k) represent 0 DC offset, 5V peak amplitude and frequency 1KHz. The .AC command performs an AC analysis. This will provide a decade sweep from 1Hz to 10kHz with 100 points per decade. The netlist can be copied from this page but is available here as rlc.cir The file is save and loaded into spice. Spice2 must be used with print and plot commands and the output from spice 2 is displayed as an ASCII graph. For this reason the output from spice3 will be shown below. Spice2 output can be exported as a rawfile and then imported and displayed in nutmeg but its faster to use spice 3. The main commands to run the simulation are as before, source, listing, run, display the new commands are plot as can be seen below.
[anc@orac spice_ccts]$ spice Program: Spice, version: 3f5 Date built: Mon Aug 26 08:06:26 UTC 2002 Type "help" for more information, "quit" to leave. Spice 1 -> source rlc.cir Circuit: * Series_RLC Circuit Spice 2 -> listing * Series_RLC Circuit 2 : v1 1 0 dc 0 sin(0 5 1k) ac 1 3 : r1 2 1 50 4 : l1 2 3 100mh 5 : c1 3 0 1uf 6 : .ac dec 100 1 10k 7 : .plot ac vbd(3) vp(3) 9 : .end Spice 3 -> run Spice 4 -> display Here are the vectors currently active: Title: * Series_RLC Circuit Name: ac1 (AC Analysis) Date: Mon Aug 8 18:22:33 2011 V(1) : voltage, complex, 401 long V(2) : voltage, complex, 401 long V(3) : voltage, complex, 401 long frequency : frequency, complex, 401 long, grid = xlog [default scale] l1#branch : current, complex, 401 long v1#branch : current, complex, 401 long Spice 5 -> plot v(3) Spice 6 -> plot vdb(3)
The new command issued at Spice 5 is to plot the variable v(3). This is drawn in Cartesian form, the x-axis representing frequency and y-axis representing amplitude in volts, the output from Nutmeg, run on Linux is shown below.
Nutmeg also has built-in commands and expressions. A full list can be found be typing help at the spice prompt, click on Interactive Interpreter and then Expression Functions and contstants. The help window is scrollable using the cursor keys and is shown below.
set units=degress
The built in expression db transforms any variable by 20 x log10 and is required to produce the amplitude plot.
The above graph has been resized for clarity and the two traces are shown in different colours, red for the magnitude in dB and blue for the phase in degrees. The y-axis is the same units, the voltage peaking about 15dB at about 500Hz. The phase at 10kHz (10^4) is about -180°
The command to produce the two plots was:where db is the built in expression to convert node 3 to decibels and vp is the phase of the voltage at node 3.
BJT Characteristic Curve* Common Emitter Characteristic Curve
Q1 3 2 0 Q2N3904
VCC 5 0 dc 10
R2 5 4 0.1
VC 3 4 0
V1 1 0 dc 10
R1 1 2 100k
* Sweep
.DC VCC 0 10 0.01 V1 2 10 2
.model Q2N3904 NPN (IS=1E-14 VAF=100 Bf=300 IKF=0.4 XTB=1.5 BR=4 CJC=4E-12 CJE=8E-12
+ RB=20 RC=0.1 RE=0.1 TR=250E-9 TF=350E-12 ITF=1 VTF=2 XTF=3)
.end
The sweep statement increments the Supply Voltage, Vcc from 0 to 10 Volts on 0.01 V increments, for each value of V1. The .model data for Q1 a NPN BJT can be found from manufacturers datasheets or various sources on the Internet. As in the previous examples, the circuit is loaded into spice3 and run.
Spice 1 -> source ce_char.cir Circuit: * Common Emitter Characteristic Curve Spice 2 -> run Spice 3 -> display Here are the vectors currently active: Title: * Common Emitter Characteristic Curve Name: dc1 (DC transfer characteristic) Date: Tue Aug 9 22:58:17 2011 V(1) : voltage, real, 5005 long V(2) : voltage, real, 5005 long V(3) : voltage, real, 5005 long V(4) : voltage, real, 5005 long V(5) : voltage, real, 5005 long q1#base : voltage, real, 5005 long q1#collector : voltage, real, 5005 long q1#emitter : voltage, real, 5005 long sweep : voltage, real, 5005 long [default scale] v1#branch : current, real, 5005 long vc#branch : current, real, 5005 long vcc#branch : current, real, 5005 long Spice 4 -> plot -vc#branch ylimit 0 30m
The last command plot -vc#branch displays the collector curve shown below. The - indicator is used because spice calculates current flow from positive to negative and the ylimit limits y-axis values from 0 to 30 mA. The plot is shown below.
Spice3 can also use xgraph to produce graphs of better quality. Assuming xgraph is installed on your system to use xgraph, just prefix "xgraph"
before the plot command. For example to use xgraph in the spice 4 command above you would type:
xgraph plot -vc#branch ylimit 0 30m
Other Programs using Spice3
The commands in this spice primer tutorial can be used with other simulators listed below:
NGspice this is a rework of the original spice3 and has the ability for high quality graphs using
gnuplot
SpiceOpus another Spice rework by the University of Slovenia.
References
The Berkeley Spice Page
Spice3 Help Pages