Spice Primer
Throughout Circuit Exchange, and in particular, many of my Schematic pages and the analysis, design and theory section, there are graphs or charts presenting some quantity from the circuit. The data will have been produced using one of the simulation programs, Circuit Maker, Tina, LTspice or Qucs. All of these programs are based on SPICE.
This section is an introduction to the standard Berkeley Spice-2 and Spice-3 programs. Although old compared to some of the graphical programs they can still be used for analysis and have graphical output from the Interactive Inpterpreter, Nutmeg.

The origin of SPICE traces back to another circuit simulation program called CANCER. Developed by professor Ronald Rohrer of U.C. Berkeley along with some of his students in the late 1960's, CANCER continued to be improved through the early 1970's. When Rohrer left Berkeley, CANCER was re-written and re-named to SPICE, released as version 1 to the public domain in May of 1972. Version 2 of SPICE was released in 1975 (version 2g6 is a minor revision of this 1975 release).

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 thouroughly. 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.

Please Note. All screen shots on this page are taken from Spice3f5 running on PCLinuxOS. The results will be the same if Spice3 is run on Unix, FreeBSD, Windows or Mac computers.

Differences Between SPICE-2 and SPICE-3
SPICE-2 consists of two parts, a calculation engine and a graphical interpreter called 'NUTMEG' to display results. SPICE-2 can only be run in batch mode from a command prompt (windows) or a terminal (unix). It can only process one simulation and the input file needs to be altered to perform a different analysis. Spice 2 is case sensitive and any commands must be in Upper Case. Results from the calculation engine are directed to an output file and then redirected as input to NUTMEG.

Spice 2G6 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.

SPICE Netlists and Source Files
A SPICE netlist or source file is the input file containing the actual circuit. The source file is a text file which has the following structure:

  1. Title line: the first line of the file will be printed, but otherwise ignored;
  2. Circuit Elements: describe the components used by SPICE
  3. Node Numbers: describe how the circuit elements are connected. (Node 0 is always the ground terminal.)
  4. Comment lines: start with a '*' and are ignored by SPICE
  5. Analysis lines: tell SPICE what type(s) of analysis to perform on the circuit
  6. Final line: must be '.end'.
  7. Continuation lines: Any long lines starting with a '+' are continuations of the statement on the pre-ceding line;

Circuit Elements
Each element in the circuit is specified in the source file by a line that gives the element name, the circuit nodes to which the element is connected, and the values of the parameters that determine the electrical characteristics of the element. The first letter of the element name specifies the element type. For example, a resistor name must begin with the letter 'r' and can contain one or more characters. Hence, r, r1, rse,rout, and r3ac2zy are valid resistor names. Spice is not case sensitive so RLoad, rload and RLOAD are all equivalent.

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 = 1012G = 109Meg = 106K = 103mil = 25.4x10-6
m = 10-3u = 10-6n = 10-9p = 10-12f = 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 Elements
Circuit elements are identified by names. The name must start with a letter symbol that corresponds to the element, but after can contain letters or numbers to identify the element. Names can be up to 8 characters long e.g. R1, C212, Rload. The following table conatins a list of circuit elements:
First 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.

Syntax: rxxxxxxx N1 N2 VALUE

r1 1 2 100
rc1 12 17 1K
N1 and N2 are the two element nodes. VALUE is the resistance (in ohms) and may be positive or negative but not zero.

Syntax: cxxxxxxx n+ n- VALUE <ic=incond> where N+ and N- represent positive and negative nodes and VALUE is the capacitance (in Farads).

cbyp 13 0 1uF
cosc 17 23 10u ic=3V

The (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 Sources
Syntax: vxxxxxxx N+ N- TYPE SOURCE MODEL

vin 10 0 SIN (0 5 1kHz)
vcc 5 0 DC 12 iin 13 2 AC 1
vmeas 12 9 0

N+ 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.

Positive current is assumed to flow from the positive node, through the source, to the negative node. A current source of positive value forces current to flow into the N+ node, through the source, and out from the N− node.

The elements that have been described above require only a few parameters to specify their electrical characteristics. The models of semiconductor devices have many parameters. A set of parameters is assigned a unique name and defined in a separate .MODEL line. Thus a semiconductor device is specified by two command lines: an element and model statement.

The syntax for the model statement is:

.MODEL Modelname Type (parameter values)

Modelname is the name of the model for the device. The parameter Type specifies the type of device from a list including:

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)

Junction Diodes
Syntax: dxxxxxxx N+ N- MNAME where N+ and N- are the positive and negative nodes, and MNAME is the model name.
dbridge 2 10 d1n4148

Bipolar Junction Transistors (BJTs)
Syntax: qxxxxxxx NC NB NE MNAME

q23 10 24 13 qmod

NC, NB, and NE are the collector, base, and emitter nodes and MNAME is the model name.

Junction Field-Effect Transistors (JFETs)
Syntax: jxxxxxxx ND NG NS MNAME

j1 7 2 3 jm1

ND, NG, and NS are the drain, gate, and source nodes and MNAME is the model name.

A subcircuit allows you to define a collection of elements as a subcircuit (e.g. an operational amplifier) and then to use this subcircuit one or times as an element in a larger circuit. A subcircuit is defined by a .SUBCKT control statement as follows:

.subckt SUBNAM N1 N2 N3 ...
.ends SUBNAM

where SUBNAM is the subcircuit name and N1, N2, N3 are its external nodes. There can be any number of external nodes with aritrary names (but not 0). The node names used inside the subcircuit are strictly local, except for node 0 which is always global. Once defined, a subcircuit is used in a similar way to any other element:

Syntax: xyyyyyyy N1 <N2 N3 ...> SUBNAM

x1 2 4 17 OPAMP

which connects nodes N1, N2, N3 of the subcircuit OPAMP to nodes 2, 4, and 17 respectively in the main circuit.

Stored Results
The results from each analysis are stored on a data array. The data array contains a set of vectors which store the numerical results. Results can be displayed as a table or in graphical form. The command "display" will list all available vectors. The command "destroy" erases all results and vectors. To load a new circuit use the "source command.

For 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 Commands
SPICE has a set of interactive commands which execute immediately. A quick summary of some popular commands are described below:

Source: Read a Spice3 input file
Syntax: source

Reads 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 simulation
Syntax: run

Syntax: display

Prints out a list of all available vectors and notes that can be printed or plotted.

Syntax: show

Show prints out a list of model parameters for any active component that contains a .model statement.

Analysis Commands
Op: Perform an operating point analysis
Syntax: op

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 analysis
Syntax: dc Source-Name Vstart Vstop Vincr [ Source2 Vstart2 Vstop2 Vincr2 ]

During 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.

dc vin 0.25 5.0 0.25
dc vin 0 10 .5 vgs 0 5 1
dc vce 0 10 .25 ib 0 10u 1u

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 Analysis
The ac small-signal portion of SPICE computes the ac output variables as a function of frequency. The program first computes the dc operating point of the circuit and determines linearized, small-signal models for all of the nonlinear devices in the circuit. The resultant linear circuit is then analyzed over a user-specified range of frequencies. The desired output of an ac small-signal analysis is usually a transfer function (voltage gain, transimpedance, etc). If the circuit has only one ac input, it is convenient to set that input to unity and zero phase, so that output variables have the same value as the transfer function of the output variable with respect to the input.

Syntax: ac ( DEC | OCT | LIN ) N Fstart Fstop

ac dec 10 1 10K
ac dec 10 1k 100meg
ac lin 100 1 100HZ

Use: '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 analysis
The transient analysis portion of SPICE computes the transient output variables as a function of time over a user-specified time interval. The initial conditions are automatically determined by a dc analysis. All sources which are not time dependent (for example, power supplies) are set to their dc value.

Syntax: tran Tstep Tstop [ Tstart [ Tmax ] ] [ uic ]

tran 1ns 100ns 0ns 2ns
tran 1ns 1000ns 500ns 10ns
tran 10ns 1us 0us 20ns uic

Tstep 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 display
plot exprs [ylimit ylo yhi] [xlimit xlo xhi] [xindices xilo xihi]
[xcompress comp] [xdelta xdel] [ydelta ydel] [xlog] [ylog] [loglog]
[vs xname] [xlabel word] [ylabel word] [title word] [samep]
[linear] [polar] [smith]

Plot 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 values
Syntax: print expr

Prints 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
Syntax: quit

Quits the SPICE application.

Spice Circuit Examples
Basic DC Example
Spice will not show the schematic so in the following examples, I have drawn the circuit and included node numbers. The first example, figure 1 below is a basic DC circuit. The voltage across R3 will be calculated.

Spice Netlist
The netlist for the basic DC circuit in Figure 1 is shown below. The first line beginning with * is a comment line and is the name of the circuit. The next few lines contain the circuit, the spice elements and node numbers. The lines can go in any particular order but to make it easier I have labelled figure 1 with node numbers from left to write which should make the netlist easier to read.

* Basic DC circuit
V1 1 0 20
R1 3 1 4k
R2 3 2 10k
V2 2 0 -10
R3 3 0 8k

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
The basic DC circuit is available here as a netlist called basicdc.cir
This file is loaded into spice2 using the command:
spice2 < basicdc.cir
Spice2 will execute all commands and display results in the command prompt (windows) or terminal (linux). Alternatively you can redirect the output to be saved as a text file using the command:
spice2 < basicdc.cir > basicdc.out
After executing the basicdc.cir the output from spice 2 is shown below:
[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


 v1 1 0 20       
 r1 3 1 4k       
 r2 3 2 10k      
 v2 2 0 -10      
 r3 3 0 8k       
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


  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
         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 Spice3
Spice3 is interactive, it is started in a terminal (linux) or command prompt (windows) with command spice3 (linux) or spice3.exe (windows). Once executed, Spice will produce a spice prompt which will show the current command number. The prompt will look like:-

Spice 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 Circuit
This next circuit will introduce the graph capabilities of Spice and the graphical interpreter, Nutmeg. A simple series RLC circuit is shown below, the node numbers are in blue.

The Spice Netlist is shown below:

* Series_RLC Circuit
V1 1 0 SIN(0 5 1k) AC 1
R1 2 1 50
L1 2 3 100mH
C1 3 0 1uF
.AC DEC 100 1 10k

Line 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, clcik on Interactive Interpreter and then Expression Functions and contstants. The help window is scrollable using the cursor keys and is shown below.

Creating a Bode Plot
A bode plot can easily be produced in spice3. Spice calculates angular velocity in radians. The units must first be converted to degrees, so at a spice prompt type the command:

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:
plot vdb(3) vp(3)

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
The final circuit is an example of the DC sweep command to produce the collector character istic curves for a BJT in common emitter mode. The circuit is shown below with node numbers (blue) and model data (red).

A couple of points about this circuit. Spice computes the current through any voltage source. To measure Q1 collector current a zero volt source, Vc, is placed in series with Q1 collector. As Q1 collector is in series with the supply Vcc, the current flow in Vc will be equal, so this is unneccasary and is there for example only.
Normally to produce the collector characteristic, the base is swept by a constant current source. In this circuit, V1 is a constant voltage source incremented in 2V steps from 2 to 10V the base current supplied via R1. The netlist is shown below:

* 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)

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.

The Berkeley Spice Page
Spice3 Help Pages