SPICE 3 User's Manual - Section 2


0. TABLE OF CONTENTS 1. INTRODUCTION 2. CIRCUIT DESCRIPTION
3. CIRCUIT ELEMENTS AND MODELS 4. ANALYSES AND OUTPUT CONTROL 5. INTERACTIVE INTERPRETER
6. BIBLIOGRAPHY APPENDIX A APPENDIX B

2 CIRCUIT DESCRIPTION

2.1 GENERAL STRUCTURE AND CONVENTIONS

A SPICE input file, called source file, consists of three parts.
  1. Data statements: description of the components and the interconnections.
  2. Control statements: tells SPICE what type of analysis to perform on the circuit.
  3. Output statements: specifies what outputs are to be printed or plotted.
The circuit to be analyzed is described to SPICE by a set of element lines, which define the circuit topology and element values, and a set of control lines, which define the model parameters and the run controls. The first line in the input file must be the title, and the last line must be ".END". The order of the remaining lines is arbitrary (except, of course, that continuation lines must immediately follow the line being continued).

Each element in the circuit is specified by an element line that contains 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. The format for the SPICE element types is given in what follows. The strings XXXXXXX, YYYYYYY, and ZZZZZZZ denote arbitrary alphanumeric strings. 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. Details of each type of device are supplied in a following section.

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 line may be continued by entering a '+' (plus) in column 1 of the following line; SPICE continues reading beginning with column 2.

A name field must begin with a letter (A through Z) and cannot contain any delimiters.

A number field may be an integer field (12, -44), a floating point field (3.14159), either an integer or floating point number followed by an integer exponent (1e-14, 2.65e3), or either an integer or a floating point number followed by 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.

Note the difference in SPICE3 where the nodes are treated as character strings and not evaluated as numbers, thus '0' and '00' are distinct nodes in SPICE3 but not in SPICE2. 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).

2.2 TITLE LINE, COMMENT LINES AND .END LINE

2.2.1 Title Line

Examples:
     POWER AMPLIFIER CIRCUIT
     TEST OF CAM CELL
The title line must be the first in the input file. Its contents are printed verbatim as the heading for each section of output.

2.2.2 .END Line

Examples:
     .END
The "End" line must always be the last in the input file. Note that the period is an integral part of the name.

2.2.3 Comments

General form:
     * <any comment>
Examples:
     * RF=1K      Gain should be 100
     * Check open-loop gain and phase margin
The asterisk in the first column indicates that this line is a comment line. Comment lines may be placed anywhere in the circuit description. Note that SPICE3 also considers any line with leading white space to be a comment.

2.3 DEVICE MODELS

General form:
     .MODEL MNAME TYPE(PNAME1=PVAL1 PNAME2=PVAL2 ... )
Examples:
     .MODEL MOD1 NPN (BF=50 IS=1E-13 VBF=50)
Most simple circuit elements typically require only a few parameter values. However, some devices (semiconductor devices in particular) that are included in SPICE require many parameter values. Often, many devices in a circuit are defined by the same set of device model parameters. For these reasons, a set of device model parameters is defined on a separate .MODEL line and assigned a unique model name. The device element lines in SPICE then refer to the model name.

For these more complex device types, each device element line contains the device name, the nodes to which the device is connected, and the device model name. In addition, other optional parameters may be specified for some devices: geometric factors and an initial condition (see the following section on Transistors and Diodes for more details).

MNAME in the above is the model name, and type is one of the following fifteen types:

RSemiconductor resistor model
CSemiconductor capacitor model
SW Voltage controlled switch
CSW Current controlled switch
URC Uniform distributed RC model
LTRALossy transmission line model
DDiode model
NPN NPN BJT model
PNP PNP BJT model
NJF N-channel JFET model
PJF P-channel JFET model
NMOSN-channel MOSFET model
PMOSP-channel MOSFET model
NMF N-channel MESFET model
PMF P-channel MESFET model

Parameter values are defined by appending the parameter name followed by an equal sign and the parameter value. Model parameters that are not given a value are assigned the default values given below for each model type. Models, model parameters, and default values are listed in the next section along with the description of device element lines.

2.4 SUBCIRCUITS

A subcircuit that consists of SPICE elements can be defined and referenced in a fashion similar to device models. The subcircuit is defined in the input file by a grouping of element lines; the program then automatically inserts the group of elements wherever the subcircuit is referenced. There is no limit on the size or complexity of subcircuits, and subcircuits may contain other subcircuits. An example of subcircuit usage is given in Appendix A.

2.4.1 .SUBCKT Line

General form:
     .SUBCKT subnam N1 <N2 N3 ...>
Examples:

An example of the first approach (linear AC model) is given below for the uA741 opamp. We defined a subcircuit for the opamp. SPICE code for the 741 opamp (see also: Macromodeling with Spice, by J.A. Connelly/P. Choi; and SPICE for Circuits and Electronics Using PSpice, 2nd Ed., Muhammad H. Rashid, Prentice Hall, 1995.)
  • Input resistance=2 MegaOhm,
  • Output resistance=75 Ohm,
  • Open loop gain=1E5 (100 dB)
  • Gain-bandwith product of 1MHz or a bandwidth of 10 Hz.
  • This is a linear AC model and does not model slewing.
   * 741 opamp subcircuit (Choi) 
   * +in(=1) -in(=2) out(=7) 
   .subckt ua741 1 2 7 
   Rin  1 2       2meg 
   Ein  4 0 1 2   100k 
   Rbw  4 5       0.5meg 
   Cbw  5 0       31.85nf 
   Eout 6 0 5 0   1 
   Rout 6 7       75 
   .ends ua741 
   * 741 opamp (Rashid) 
   .subckt ua741 1 2 7 
   Ri 1 2      2.0meg 
   *voltage controlled current source 
   GB 0 3 1 2  0.1M 
   R1 3 0      10K 
   C1 3 0      1.5619UF 
   * voltage controlled voltage source 
   EA 0 5 3 0  2E+5 
   Ro 5 7      75 
   .ends ua741
A circuit definition is begun with a .SUBCKT line. SUBNAM is the subcircuit name, and N1, N2, ... are the external nodes, which cannot be zero. The group of element lines which immediately follow the .SUBCKT line define the subcircuit. The last line in a subcircuit definition is the .ENDS line (see below). Control lines may not appear within a subcircuit definition; however, subcircuit definitions may contain anything else, including other subcircuit definitions, device models, and subcircuit calls (see below). Note that any device models or subcircuit definitions included as part of a subcircuit definition are strictly local (i.e., such models and definitions are not known outside the subcircuit definition). Also, any element nodes not included on the .SUBCKT line are strictly local, with the exception of 0 (ground) which is always global.

2.4.2 .ENDS Line

General form:
     .ENDS <SUBNAM>
Examples:
     .ENDS ua741
The "Ends" line must be the last one for any sub-circuit definition. The subcircuit name, if included, indicates which subcircuit definition is being terminated; if omitted, all subcircuits being defined are terminated. The name is needed only when nested subcircuit definitions are being made.

2.4.3 Subcircuit Calls

General form:
     XYYYYYYY N1 <N2 N3 ...> SUBNAM
Example:

   * Inverting Amplifier
   Vin   1   0      DC 0 AC 1
   R1    1   2      1K
   R2    2   3      2K
   RL    3   0      10k 
   Xop1  0   2   3  ua741

   .subckt ua741 1 2 7
   Rin  1 2       2meg
   Ein  4 0 1 2   100k
   Rbw  4 5       0.5meg
   Cbw  5 0       31.85nf
   Eout 6 0 5 0   1
   Rout 6 7       75
   .ends ua741
   .END

Subcircuits are used in SPICE by specifying pseudo-elements beginning with the letter X, followed by the circuit nodes to be used in expanding the subcircuit.

[Note: the letter X used to specify subcircuits can be set via the variable subinvoke. CDHW]

2.5 COMBINING FILES: .INCLUDE LINES

General form:
     .INCLUDE filename
Examples:

   * Inverting Amplifier

   .include /home/users/spice/opamps/ua741.subckt

   Vin   1   0      DC 0 AC 1
   R1    1   2      1K
   R2    2   3      2K
   RL    3   0      10k       
   Xop1  0   2   3  ua741

   .END
Frequently, portions of circuit descriptions will be reused in several input files, particularly with common models and subcircuits. In any spice input file, the ".INCLUDE" line may be used to copy some other file as if that second file appeared in place of the ".INCLUDE" line in the original file. There is no restriction on the file name imposed by spice beyond those imposed by the local operating system.
 
0. TABLE OF CONTENTS 1. INTRODUCTION 2. CIRCUIT DESCRIPTION
3. CIRCUIT ELEMENTS AND MODELS 4. ANALYSES AND OUTPUT CONTROL 5. INTERACTIVE INTERPRETER
6. BIBLIOGRAPHY APPENDIX A APPENDIX B