SPICE Control Cards

by
Wenton L. Davis

SPICE control cards are commands to a SPICE program that control the operation and output of a SPICE program.  I am differentiating a little bit, here; although the analysis cards are control cards, I am leaving those commands to the seperate analysis page.  Here, I am focusing on the rest:

.CONTROL/.ENDC

ngspice only

Define the control section of a SPICE program.  A .CONTROL section must be ended by a .ENDC card. 

.control
<... commands >
.endc

The .CONTROL section typically contains all of the analysis and .PRINT ant .PLOT commands for a simulation.

.control
AC LIN 101 10 10K
plot v(2)
plot vdb(2)
plot phase(v(2))   * in radians
set units = degrees
plot phase(v(2))   * in degrees
.endc

There are a lot of commands that can be included in the control section.  See the ngspice manual (Chapter 13) for additional commands.

.CSPARAM

Experimental, ngspice only

Create a constant vector from a parameter in plot const.

Examples:

.param pippo=5
.param pp=6
.csparam pippo={pippo + pp}
.param p={pp}
.csparam pap='pp+p'

.END

Most SPICE programs include an .END command to mark the end of the program.  Not all versions of SPICE require this, so check the documentation for your particular implimentation.  For versions that do require it, the line must typically also end with with a CR/LF or whatever end-of-line marker is used for your operating system.  (Windoze uses CR/LF pairs, Linux uses LF, etc.)

.IF/.ELSE/.ELSEIF/.ENDIF

Conditional netlisting can be accomplished using boolean expressions in .IF/.ELSE/.ELSEIF/.ENDIF structures:

.param m0=0 m1=1

M1 1 2 3 4 N1 W=1 L=0.5

.if(m0==1)
.model N1 NMOS level=49 Version=3.1
.elseif(m1==1)
.model N1 NMOS level=49 Version=3.2.4  * <-- selected
.else
.model N1 NMOS level=49 Version=3.3.0
.endif

Some commands are not supported within .IF-.ELSE(IF)->ENDIF blocks: .SUBCKT, .INC, .LIB, and .PARAM.

.SUBCKT/.ENDS

Subcircuits are a useful way to provide repeated sections of a circuit without providing multiple explicit declarations of components.  As an example, a voltage divider might be defined so that its input is node 1, output is node 2, and relative ground is node 3:

.subckt vdiv 1 2 3
R1 1 2 10K
R2 2 3 5K
.ends

Now that the subcircuit has been defined, a circuit may use it multiple times:

xdiv1 5 7 0 vdiv   *input node 5, output node 7
xdiv2 8 4 0 vdiv   *input node 8, output node 4

Note that the node numbers used in a subsircuit are local nodes; nodes 1, 2, and 3 are not the same nodes as main circuit's nodes 1, 2, and 3.

Ever subcircuit MUST be terminated with a .ENDS card.  Hoever, see .GLOBAL

.FOUR

.four freq ov1 <ov2 ov3 ... >

Control whether ngspice perfoems a Fourier analysis as part of the transient analysis.  freq is the fundamental frequency. If selected, the FOurier analysis is performed over the interval from TSTOP-period to TSTOP, where period is one period of the fundamental frequency.  The DC component and first nine harmonics are datermined.  For optimal results, TMAX (see .TRAN) should be set to period/100.0 or less.

Example:

.four 100K v(5)

.FUNC

The .FUNC control card can be used to define a user-definable function.

.func icos(x) {cox(x) - 1}
.func f(x,y)  {x*y}
.func foo(a,b) = {a + b}

.GLOBAL

The .GLOBAL control card marks nodes that may be accessible in the top-level circuit as well as in subcircuits without explicit node connections.

.GLOBAL gnd vcc

.IC

.ic v(nodenum)=val v(nodenum)=val

Set initial conditions for a transient analysis:

.ic v(11)=5 v(4)=-5 v(2)=2.2

NOTE: Do not confuse .IC for the .NODESET command, which only aids DC convergence.

.INCLUDE

The .INCLUDE control card allows a SPICE program to read an external file and insert it into the current location of a program, seeming as if the external file was written into the main fail at the current location.

.INCLUDE /users/spice/common/LM741.mod

.INCPSLT (ngspice only)

This command is the same as .INCLUDE excpet that the file is read in 'pslt' compatibility mode.  See ngspice documentation for more information.

.LIB (ngspice only)

The .LIB control card acts similarly to the .INCLUDE card, except that it selectively only a particular library section from the file.  See ngspice documentation for more information.

.lib /users/spice/common/mosfets mos1

.MODEL

Many devices (particularly semiconductors) require more complex model information to be simulated appropriately.  The .MODEL control card provides this information.

.MODEL mname type(pname=pval1 pnmae2=pval2 ...)

Example:

.model MOD1 npn (bf=50 is=1e-13 vbf=50)

.NODESET

.nodeset v(nodenum)=val v(nodenum)=val ...
.nodeset all=val

Helps DC convergence by providing a hint for specified node voltages.  In general, this command should not be needed.  NOTE: This does not have the same function as .IC, and will not have any result in a transient analysis.

.OPTIONS

.options opt1 opt2 ... (or opt=optval ...)

Various parameters of the simulation can be accessed and controlled.  These can control optimizations, accuracy, speed, or default values for some devices.  They vary from one version of SPICE to another, so check with the documentation for your particular version of SPICE.

.PARAM

ngspice allows parameteric attributes to be defined using the .PARAM command:

.param ident1=expr ident2=exper ...

identifiers must begin with an alphabetic character, and all other characters must be alphanumeric, or ! # $ % [ ] _ as special characters.  The names time, temper, and hertz are reserved names.  expressions must be included within braces {p+p2} or single quotes 'this=that'.  expressions may not reference themselves: count='count+1' will not work.

.param a = 123 * 3   b = sqrt(9)  *won't work, a <= 123
.param a = '123 * 3' b = sqrt(9)  *will  work
.param c = a + 123                *won't work
.param c = 'a + 123'              *ok
.param c = a+123                  *ok

The following operations are allowed in expressions.  operators of equal precedence are evaluated from left to right.
OperatorAliasPrecedenceDescription
-1unary -
!1unary NOT
**^2power, like pwr
*3multiplication
/3division
%3modulo
\3integer division
+4addition
-4subtraction
==5equality
!=<>5non-equality
<=5less or equal
>=5greater or equal
<5less than
>5greater than
&&5boolean AND
||5boolean OR
? : 5ternary operator

Experssions cal also include built-in functions:
Built-in FunctionNotes
sqrt(x)
sin(x), cos(x), tan(x)
sinh(x), cosh(x), tanh(x)
asin(x), acos(x), atan(x)
asinh(x), acosh(x), atanh(x)
arctan(x)Same as atan(x)
exp(x)
ln(x), log(x)
abs(x)
nint(x)Nearest integer
int(x)Nearest integer, round down
floor(x)Nearest integer, round to -∞
ceil(x)Nearest integer, round to +∞
pow(x,y)x raised to power y, from C runtime library
pwr(x,y)pow(abs(x),y)
min(x,y)
max(x,y)
sgn(x)1.0 for x > 0, 0.0 for x == 0, -1.0 for x < 0
ternary_fcn(x,y,z)x ? y : z
gauss(nom,rvar,sigma)nominal value plus variation drawn from Gaussian distribution with mean 0 and standard deviation rvar (relative to nominal, divided by sigma
agauss(nom,avar,sigma)nominal value plus variation drawn from Gaussian distribution with mean 0 and standard deviation avar (absolute), divided by sigma
unif(nom,rvar)nominal value plus relative variation uniformly distributed +/-rvar
aunif(nom,avar)nominal value plus absolute variation uniformly distributed +/-avar
limit(nom,avar)nominal value +/-avar, depending on random number in [-1,1] being > 0 or < 0

.PLOT

.plot pltype ov1 <plo1, phi1> <ov2 <(plo2, phi2)> ... ov8>

Define the contents of one plot of up to 8 output variables.  pltype is the type if analysis (DC, AC, TRAN, NOISE, or DISTO) and the specified outputs.

Examples:

.plot dc v(4) v(5) v(1)
.plot tran v(17,5) (2,5) i(vin) v(17) (1,9)
.plot ac vm(5) mv(31, 24) vdb(5) vp(5)
.plot disto hd2 hd3(R) sim2
.plot tran v(5, 3) v(4) (0, 5) v(7) (0, 10)

.PRINT

.print prtype ov1 <ov2 ... ov8>

Define the contents of a tabular listing (up to 8 outputs) variables.  prtype is the type of analysis (DC, AC, TRAN, NOISE, or DISTO) and the specified outputs.

Examples:

.print tran v(4) i(vin)
.print dc v(2) i(vsrc) v(23,17)
.print ac vm(4,2) vr(7) vp(8,3)

The variables must be in the form:
V(N1<,N2>) specifies difference between nodes N1-N2.  If N2 is ommited, ground (0) is assumed.  For ac analysis, V may be replaced by:
  • VR Real part
  • VI Imaginary part
  • VM Magnitude
  • VP Phase
  • VDB 10log10(magnitude)
I(VXXXXXXX) specifies current through an independent voltage source.  Positive current flows from the positive node, through the source, to the negative node.

There is no limit on the number of .PRINT lines for each type of analysis.

.PROBE

.probe alli
.probe I(device)
.probe I(device,node)

The .PROBE command enables current measurement at device nodes provided, as well as differential voltage measurements between nodes.

Exammples:

.probe <alli>       * requires lots of memory
.probe I(R1)              * two-terminal device
.probe I(XU1)             * measure current at all nodes of a subcircuit
.probe I(MQ4,3)           * measure current at node 3 of multi-terminal device MQ4

Results in vectors:

r1#branch
mq4:s#branch

For voltages:

.probe v(node1)
.probe vd(device:node1:node2)
.probe vd(device1:node1, device2:node2)

Examples:

.probe v(nR1)             * voltage at node named vR1
.probe vd(R1)             * voltage across a two-terminal device, R1
.probe vd(m4:1:0)         * voltage at instance node 1 of device m4
.probe vd(m4:1:3)         * voltage between nodes 1 and 3 of device m4
.probe vd(m4:1, m5:3)     * voltage between node 1 of device m4 and node 3 of device m5
.probe vd(m4:d, m5:s)     * equivalent to last probe

Results in vectors:

nR1
vd_R1
vd_m4:d:0
vd_m4:d:s
vd_m4:d_m5:s

.SAVE (batch mode only)

Save selected vectors to a raw file for ngspice to use later.  See ngspice manual (Chapters 13, 27) for additional information.

Examples:

.save i(vin) node1 v(node2)
.save @m1[id] vsource#branch
.save all @m2[vdsat]

.TEMP

Sets the circut temperature.  (°C)

.temp 27

.TITLE

The first line in most SPICE programs is the title line.  Using ngspice, the first line is assumed to be a title, and does not need to include the .TITLE command.  If a .TITLE command is encountered anywhere in the deck, it will override the current title.

.TITLE Power Supply Design 1
* rest of program...

In ngspice:

Power Supply Design 1
* rest of program...

.WIDTH

Set the (maximum) width of a print-out

.width out = 256

Wenton's email (wenton@ieee.org)

home