p1 Ngspice 41 Manual
p1 Ngspice 41 Manual
Introduction
Ngspice is a general-purpose circuit simulation program for nonlinear and linear analyses.
Circuits may contain resistors, capacitors, inductors, mutual inductors, independent or
dependent voltage and current sources, loss-less and lossy transmission lines, switches,
uniform distributed RC lines, and the five most common semiconductor devices: diodes,
BJTs, JFETs, MESFETs, and MOSFETs.
Some introductory remarks on how to use ngspice may be found in Chapt. 21.
Ngspice is an update of Spice3f5, the last Berkeley’s release of Spice3 simulator family.
Ngspice is being developed to include new features to existing Spice3f5 and to fix its bugs.
Improving a complex software like a circuit simulator is a very hard task and, while some
improvements have been made, most of the work has been done on bug fixing and code
refactoring.
Ngspice has built-in models for the semiconductor devices, and the user need specify only
the pertinent model parameter values.
Ngspice supports mixed-level simulation and provides a direct link between technology pa-
rameters and circuit performance. A mixed-level circuit and device simulator can provide
greater simulation accuracy than a stand-alone circuit or device simulator by numerically
modeling the critical devices in a circuit. Compact models can be used for all other de-
vices. The mixed-level extensions to ngspice is CIDER, a mixed-level circuit and device
simulator integrated into ngspice code.
Ngspice supports mixed-signal simulation through the integration of XSPICE code. XSPICE
software, developed as an extension to Spice3C1 by GeorgiaTech, has been enhanced and
ported to ngspice to provide ‘board’ level and mixed-signal simulation.
New devices can be added to ngspice by several means: behavioral B-, E- or G-sources,
the XSPICE code-model interface for C-like device coding, and the ADMS interface based
on Verilog-A and XML.
Finally, numerous small bugs have been discovered and fixed, and the program has been
ported to a wider variety of computing platforms.
35
36 CHAPTER 1. INTRODUCTION
The semiconductor diode model can be used for either junction diodes or Schottky barrier
diodes. There are two models for JFET: the first (JFET) is based on the model of
Shichman and Hodges, the second (JFET2) is based on the Parker-Skellern model. All
the original six MOSFET models are implemented: MOS1 is described by a square-law
I-V characteristic, MOS2 [1] is an analytical model, while MOS3 [1] is a semi-empirical
model; MOS6 [2] is a simple analytic model accurate in the short channel region; MOS9,
is a slightly modified Level 3 MOSFET model - not to confuse with Philips level 9; BSIM
1 [3, 4]; BSIM2 [5] are the old BSIM (Berkeley Short-channel IGFET Model) models.
MOS2, MOS3, and BSIM include second-order effects such as channel-length modulation,
subthreshold conduction, scattering-limited velocity saturation, small-size effects, and
charge controlled capacitances. The recent MOS models for submicron devices are the
BSIM3 (Berkeley BSIM3 web page) and BSIM4 (Berkeley BSIM4 web page) models.
Silicon-on-insulator MOS transistors are described by the SOI models from the BSIMSOI
family (Berkeley BSIMSOI web page) and the STAG [18] one. There is partial support
for a couple of HFET models and one model for MESA devices.
and its Code Model Subsystem) allow use of all the standard SPICE models, provide a
pre-defined collection of the most common analog and digital functions, and provide an
extensible base on which to build additional models.
Ngspice supports creation of ‘User-Defined Node’ types. User-Defined Node types allow
you to specify nodes that propagate data other than voltages, currents, and digital states.
Like digital nodes, User-Defined Nodes use event-driven simulation, but the state value
may be an arbitrary data type. A simple example application of User-Defined Nodes is
the simulation of a digital signal processing filter algorithm. In this application, each
node could assume a real or integer value. More complex applications may define types
that involve complex data such as digital data vectors or even non-electronic data.
Ngspice digital simulation is actually implemented as a special case of this User-Defined
Node capability where the digital state is defined by a data structure that holds a Boolean
logic state and a strength value.
Ngspice implements mixed-level simulation through the merging of its code with CIDER
(details see Chapt. 30).
CIDER is a mixed-level circuit and device simulator that provides a direct link between
technology parameters and circuit performance. A mixed-level circuit and device simula-
tor can provide greater simulation accuracy than a stand-alone circuit or device simulator
by numerically modeling the critical devices in a circuit. Compact models can be used
for noncritical devices.
CIDER couples ngspice to a internal C-based device simulator, thus providing circuit
analyses, compact models for semiconductor devices, and an interactive user interface.
CIDER provides accurate, one- and two-dimensional numerical device models based on
the solution of Poisson’s equation, and the electron and hole current-continuity equa-
tions. CIDER incorporates many of the same basic physical models found in the the
Stanford two-dimensional device simulator PISCES [PINT85]. Input to CIDER consists
of a SPICE-like description of the circuit and its compact models, and PISCES-like de-
scriptions of the structures of numerically modeled devices. As a result, CIDER should
seem familiar to designers already accustomed to these two tools.
The CIDER input format has great flexibility and allows increased access to physical
model parameters. New physical models have been added to allow simulation of state-
of-the-art devices. These include transverse field mobility degradation [GATE90] that
is important in scaled-down MOSFETs and a polysilicon model for poly-emitter bipolar
transistors. Temperature dependence has been included for most physical models over
the range from -50°C to 150°C. The numerical models can be used to simulate all the
basic types of semiconductor devices: resistors, MOS capacitors, diodes, BJTs, JFETs
and MOSFETs. BJTs and JFETs can be modeled with or without a substrate contact.
Support has been added for the management of device internal states. Post-processing
of device states can be performed using the control language user interface of ngspice.
1.2. SUPPORTED ANALYSES 39
Previously computed states can be loaded into the program to provide accurate initial
guesses for subsequent analyses.
Details of the basic semiconductor equations and the physical models used by CIDER are
not provided in this manual. Unfortunately, no other single source exists that describes
all of the relevant background material. Comprehensive reviews of device simulation can
be found in [PINT90] and the book [SELB84]. CODECS (predecessor to CIDER) and its
inversion-layer mobility model are described in [MAYA88] and [LGATE90], respectively.
PISCES and its models are described in [PINT85]. Temperature dependencies for the
PISCES models used by CIDER are available in [SOLL90].
For Linux users the cooperation of the TCAD software GSS with ngspice might be of
interest, see https://ngspice.sourceforge.io/gss.html. This project is no longer maintained
however, but has moved into the Genius simulator, still available as open source cogenda
genius.
2. AC Small-Signal Analysis
3. Transient Analysis
4. Pole-Zero Analysis
6. Sensitivity Analysis
7. Noise Analysis
Applications that are exclusively analog can make use of all analysis modes with the
exception of Code Model subsystem that do not implements Pole-Zero, Distortion, Sensi-
tivity and Noise analyses. Event-driven applications that include digital and User-Defined
Node types may make use of DC (operating point and DC sweep) and Transient only.
In order to understand the relationship between the different analyses and the two un-
derlying simulation algorithms of ngspice, it is important to understand what is meant
by each analysis type. This is detailed below.
1.2.1 DC Analysis
The DC analysis portion of ngspice determines the dc operating point of the circuit with
inductors shorted and capacitors opened. DC analysis options are specified on the .DC,
.TF, and .OP control lines.
DC analysis does not consider any time dependence on any of the sources within the sys-
tem description. The simulator algorithm subdivides the circuit into those portions that
40 CHAPTER 1. INTRODUCTION
require the analog simulator algorithm and those that require the event-driven algorithm.
Each subsystem block is then iterated to solution, with the interfaces between analog
nodes and event-driven nodes iterated for consistency across the entire system.
Once stable values are obtained for all nodes in the system, the analysis halts and the
results may be displayed or printed out as you request them.
A dc analysis is automatically performed prior to a transient analysis to determine the
transient initial conditions, and prior to an ac small-signal analysis to determine the
linearized, small-signal models for nonlinear devices. If requested, the DC small-signal
value of a transfer function (ratio of output variable to input source), input resistance,
and output resistance is also computed as a part of the DC solution. DC analysis can also
be used to generate DC transfer curves: a specified independent voltage, current source,
resistor or temperature is stepped over a user-specified range and the DC output variables
are stored for each sequential source value.
circuit model is then used to find the poles and zeros of the transfer function. Two types
of transfer functions are allowed: one of the form (output voltage)/(input voltage) and
the other of the form (output voltage)/(input current). These two types of transfer func-
tions cover all the cases and one can find the poles/zeros of functions like input/output
impedance and voltage gain. The input and output ports are specified as two pairs of
nodes. The pole-zero analysis works with resistors, capacitors, inductors, linear-controlled
sources, independent sources, BJTs, MOSFETs, JFETs and diodes. Transmission lines
are not supported.
The method used in the analysis is a sub-optimal numerical search. For large circuits it
may take a considerable time or fail to find all poles and zeros. Please note, that for some
circuits, the method becomes “lost” and may find an excessive number of poles or zeros.
• Diodes (DIO),
• BJT,
• JFET (level 1),
• MOSFETs (levels 1, 2, 3, 9, and BSIM1),
• MESFET (level 1).
All linear devices are automatically supported by distortion analysis. If there are switches
present in the circuit, the analysis continues to be accurate provided the switches do not
change state under the small excitations used for distortion calculations.
If a device model does not support direct small signal distortion analysis, please use the
Fourier of FFT statements and evaluate the output per scripting.
Noise analysis in ngspice measures the device-generated noise for a given circuit. When
provided with an input source and an output port, the analysis calculates the noise con-
tributions of each device, and each noise generator within each device, as measured as a
voltage at the output port. Noise analysis also calculates the equivalent input noise of
the circuit, based on the output noise. This is done for every frequency point in a spec-
ified range - the calculated value of the noise corresponds to the spectral density of the
circuit variable viewed as a stationary Gaussian stochastic process. After calculating the
spectral densities, noise analysis integrates these values over the specified frequency range
to arrive at the total noise voltage and current over this frequency range. The calculated
values correspond to the variance of the circuit variables viewed as stationary Gaussian
processes.
Experimental code.
PSS is a radio frequency periodical large-signal dedicated analysis. The implementation
is based on a time domain shooting method that make use of transient analysis. As
it is in early development stage, PSS performs analysis only on autonomous circuits,
meaning that it is able to predict fundamental frequency and (harmonic) amplitude(s)
for oscillators, VCOs, etc.. The algorithm is based on a search of the minimum error
vector defined as the difference of RHS vectors between two occurrences of an estimated
period. Convergence is reached when the mean of this error vector decreases below a given
threshold parameter. Results of PSS are the basis of periodical large-signal analyses like
PAC or PNoise.
1.3.1 Introduction
Temperature dependent support is provided for all devices except voltage and current
sources (either independent and controlled) and BSIM models. BSIM MOSFETs have an
alternate temperature dependency scheme that adjusts all of the model parameters before
input to ngspice.
For details of the BSIM temperature adjustment, see [6] and [7]. Temperature appears
explicitly in the exponential terms of the BJT and diode model equations. In addition,
saturation currents have a built-in temperature dependence. The temperature dependence
of the saturation current in the BJT models is determined by:
XT I
T1 Eg q (T1 − T0 )
IS (T1 ) = IS (T0 ) exp (1.1)
T0 k (T1 T0 )
where k is Boltzmann’s constant, q is the electronic charge, Eg is the energy gap model
parameter, and XT I is the saturation current temperature exponent (also a model pa-
rameter, and usually equal to 3).
The temperature dependence of forward and reverse beta is according to the formula:
XT B
T1
B (T1 ) = B (T0 ) (1.2)
T0
XT I
T1 N Eg q (T1 − T0 )
IS (T1 ) = IS (T0 ) exp (1.3)
T0 N k (T1 T0 )
where N is the emission coefficient model parameter, and the other symbols have the
same meaning as above. Note that for Schottky barrier diodes, the value of the saturation
current temperature exponent, XT I, is usually 2. Temperature appears explicitly in the
value of junction potential, U (in Ngspice PHI), for all the device models.
The temperature dependence is determined by:
kT Na Nd
U (T ) = ln (1.4)
q Ni (T )2
44 CHAPTER 1. INTRODUCTION
M0 (T0 )
M0 (T ) = 1.5 (1.5)
T
T0
The effects of temperature on resistors, capacitor and inductors is modeled by the formula:
R (T ) = R (T0 ) 1 + T C1 (T − T0 ) + T C2 (T − T0 )2 (1.6)
where T is the circuit temperature, T0 is the nominal temperature, and T C1 and T C2 are
the first and second order temperature coefficients.
.temp 40
.options temp=60
will set the overall temperature to 60 °C (15.1.1). Both commands are equivalent, however
.temp will override .options temp.
The temperature of an individual device may be determined by the instance parameters
temp or dtemp.
M1 d g s b MOSN temp=35
M2 d g s b MOSN dtemp=20
will set the temperature of device M2 at a delta of 20° above the overall temperature.
The temperatures thus set are static throughout the simulation. It is possible, however,
to sweep the temperature by a command like
.dc temp 25 49 2
1.4. CONVERGENCE 45
The nominal temperature, a reference temperature where device model parameters have
been measured, is called tnom.
.options tnom=25
will set the nominal temperature for all devices to 25 °C (15.1.1). Tnom sometimes may
be set as a model parameter in a .model line (3.2.2), depending on the specific class of
devices and its model parameter set.
1.4 Convergence
Ngspice uses the Newton-Raphson algorithm to solve nonlinear equations arising from
circuit description. The NR algorithm is interactive and terminates when both of the
following conditions hold:
where
vnmax = max vn(k+1) , vn(k) . (1.8)
The RELTOL (RELative TOLerance) parameter, which default value is 10−3 , specifies
how small the solution update must be, relative to the node voltage, to consider the
solution to have converged. The VNTOL (absolute convergence) parameter, which has 1µV
as default value, becomes important when node voltages have near zero values. The
relative parameter alone, in such case, would need too strict tolerances, perhaps lower
than computer round-off error, and thus convergence would never be achieved. VNTOL
forces the algorithm to consider as converged any node whose solution update is lower
than its value.
46 CHAPTER 1. INTRODUCTION
\(k+1) (k)
ibranch − ibranch ≤ RELTOL ibrmax + ABSTOL, (1.9)
where
\
(k+1) (k)
ibrmax = max ibranch , ibranch . (1.10)
Circuit Description
The circuit to be analyzed is described to ngspice by a set of element instance lines, which
define the circuit topology and element instance values, and a set of control lines, which
define the model parameters and the run controls. All lines are assembled in an input file
to be read by ngspice. Two lines are essential:
• The first line in the input file must be the title, which is the only comment line that
does not need any special character in the first place.
The order of the remaining lines is alomost arbitrary (except, of course, that continuation
lines must immediately follow the line being continued, .subckt ... .ends, .if ... .endif,
or .control ... .endc have to enclose their specific lines). Leading white spaces in a
line are ignored, as well as empty lines.
The lines described in sections 2.1 to 2.12 are typically used in the core of the input file,
outside of a .control section (see 16.4.3). An exception is the .include includefile
line (2.7) that may be placed anywhere in the input file. The contents of includefile
will be inserted exactly in place of the .include line.
A very preliminary syntax check has been added to the input parser.
The input file will be scanned for valid utf-8 characters. If non-valid characters are found,
reading the input is stopped.
47
48 CHAPTER 2. CIRCUIT DESCRIPTION
If the first character in a netlist or .control line is one of =[]?()&%$§\"!:, then ngspice
replaces it by ’*’ and issues a warning. Command set strict_errorhandling will force
ngspice to exit.
Check for .control ... .endc, .subckt ... .ends, .if ... .endif.
Each element in the circuit is a device instance specified by an instance line that con-
tains:
• and the values of the parameters that determine the electrical characteristics of the
element.
The first letter of the element instance name specifies the element type. The format
for the ngspice element types is given in the following manual chapters. In the rest of
the manual, the strings XXXXXXX, YYYYYYY, and ZZZZZZZ denote arbitrary alphanumeric
strings.
For example, a resistor instance 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 3. Table 2.1 lists the element
types available in ngspice, sorted by their first letter.
2.1. GENERAL STRUCTURE AND CONVENTIONS 49
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; ngspice continues reading beginning with
50 CHAPTER 2. CIRCUIT DESCRIPTION
column 2. Lines may also be continued in Unix shell style, when the final two characters
are backslashes. A device name field must begin with a letter (A through Z) and cannot
contain any delimiters.
2.1.4.2 Numbers
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:
Suffix Name Factor
T Tera 1012
G Giga 109
Meg Mega 106
K Kilo 103
mil Mil 25.4 × 10−6
m milli 10−3
u micro 10−6
n nano 10−9
p pico 10−12
f femto 10−15
a atto 10−18
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 that ‘M’ or ‘m’ denote ‘milli’, i.e. 10−3 . Suffix meg has to be used for
106 . If compatibility mode LT (16.14.6) is set, ngspice will accept the RKM notation for
entering resistance or capacitance values, e.g. 2K7 or 100R.
Node names may be arbitrary character strings (exceptions see below) and are case in-
sensitive, if ngspice is used in batch mode (16.4.1). If in interactive (16.4.2) or control
(16.4.3) mode, node names may either be plain numbers or arbitrary character strings,
not starting with a number. The following characters = % ( ) , [ ] < > ~ are not allowed
in a node name, especially when XSPICE code models are used (they have their special
meanings then and act as string delimiters).
The ground node must be named ‘0’ (zero). For compatibility reason gnd is accepted as
ground node, and will internally be treated as a global node and be converted to ‘0’. If
2.2. DOT COMMANDS 51
this is not feasible, you may switch the conversion off by setting set no_auto_gnd in one
of the configuration files spinit or .spiceinit. Each circuit has to have a ground node (gnd
or 0)! Note the difference in ngspice where the nodes are treated as character strings
and not evaluated as numbers, thus ‘0’ and 00 are distinct nodes in ngspice 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.
• 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).
The title line must be the first in the input file. Its contents are printed verbatim as the
heading for each section of output.
As an alternative, you may place a .TITLE <any title> line anywhere in your input
deck. The first line of your input deck will be overridden by the contents of this line
following the .TITLE statement.
.TITLE line example:
** ** ****************** ** ******
* additional lines following
*...
. TITLE Test of CAM cell
* additional lines following
*...
. end
The .end line must always be the last in the input file. Note that the period is an integral
part of the name.
54 CHAPTER 2. CIRCUIT DESCRIPTION
2.3.3 Comments
General Form:
Examples:
The asterisk in the first column indicates that this line is a comment line. Comment lines
may be placed anywhere in the circuit description.
Examples:
ngspice supports comments that begin with double characters ‘$ ’ (dollar plus space) or
‘//’. For readability you should precede each comment character with a space. ngspice
will accept the single character ‘$’.
Please note that the ‘$’ character is not a valid end-of-line comment delimiter, if the
PSPICE compatibility mode (16.14.5) has been chosen. Then ’$’ becomes an ordinary
character.
If input lines get overly long, they may be split into two or more lines (e.g. for better
readability). Internally they will be merged into a single line. Each follow-up line starts
with character ’+’ plus additional space. Follow-up lines have to follow immediately after
each other. End-of-line comments will be ignored. Lines may also be continued by ending
the line with two backslashes, as used in Unix shells. The following lines do not allow
using continuation lines: .title, .lib, and .include.
Examples:
Most simple circuit elements typically require only a few parameter values. However,
some devices (semiconductor devices in particular) that are included in ngspice 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 ngspice then refer to the model name.
For these more complex device types, each device element line contains the device name,
the nodes the device is connected to, 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 (8 to 11) and Diodes (7) for more
details). mname in the above is the model name, and type is one of the following fifteen
types:
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 are listed in the section on each
device along with the description of device element lines. Model parameters and their
default values are given in Chapt. 31.
options (see 17.7)); the program then automatically inserts the defined group of elements
wherever the subcircuit is referenced. Instances of subcircuits within a larger circuit are
defined through the use of an instance card that begins with the letter ‘X’. A complete
example of all three of these cards follows:
Example:
The above specifies a subcircuit with ports numbered ‘1’, ‘2’ and ‘3’:
• Resistor ‘R1’ is connected from port ‘1’ to port ‘2’, and has value 10 kOhms.
• Resistor ‘R2’ is connected from port ‘2’ to port ‘3’, and has value 5 kOhms.
The instance card, when placed in an ngspice deck, will cause subcircuit port ‘1’ to be
equated to circuit node ‘10’, while port ‘2’ will be equated to node ‘7’ and port ‘3’ will
equated to node ‘0’.
2.5. .SUBCKT SUBCIRCUITS 57
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 Chapt. 21.6.
General form:
Examples:
. SUBCKT OPAMP 1 2 3 4
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
that immediately follow the .SUBCKT line define the subcircuit. The last line in a sub-
circuit 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 defi-
nition). Also, any element nodes not included on the .SUBCKT line are strictly local, with
the exception of 0 (ground) that is always global. If you use parameters, the .SUBCKT line
will be extended (see 2.9.3).
General form:
Examples:
. ENDS OPAMP
The .ENDS line must be the last one for any subcircuit definition. The subcircuit name,
if included, indicates which subcircuit definition is being terminated; if omitted, all sub-
circuits being defined are terminated. The name is needed only when nested subcircuit
definitions are being made.
58 CHAPTER 2. CIRCUIT DESCRIPTION
Examples:
X1 2 4 17 3 1 MULTI
Subcircuits are used in ngspice by specifying pseudo-elements beginning with the letter
X, followed by the circuit nodes to be used in expanding the subcircuit. If you use
parameters, the subcircuit call will be modified (see 2.9.3).
2.6 .GLOBAL
General form:
Examples:
Nodes defined in the .GLOBAL statement are available to all circuit and subcircuit blocks
independently from any circuit hierarchy. After parsing the circuit, these nodes are ac-
cessible from top level.
2.7 .INCLUDE
General form:
. INCLUDE filename
Examples:
Frequently, portions of circuit descriptions will be reused in several input files, particularly
with common models and subcircuits. In any ngspice 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 ngspice beyond those imposed by the
local operating system.
2.8. .LIB 59
2.8 .LIB
General form:
Examples:
The .LIB statement allows including library descriptions into the input file. Inside the
*.lib file a library libname will be selected. The statements of each library inside the
*.lib file are enclosed in .LIB libname <...> .ENDL statements.
If the compatibility mode (16.14) is set to ’ps’ by set ngbehavior=ps (17.7) in spinit
(16.5) or .spiceinit (16.6), then a simplified syntax .LIB filename is available: a warning
is issued and filename is simply included as described in Chapt. 2.7.
General form:
. param < ident > = < expr > < ident > = < expr > ...
Examples:
. param pippo =5
. param po =6 pp =7.8 pap ={ AGAUSS ( pippo , 1 , 1.67)}
. param pippp ={ pippo + pp }
. param p ={ pp }
. param pop = ’ pp +p ’
This line assigns numerical values to identifiers. More than one assignment per line
is possible using a separating space. Parameter identifier names must begin with an
alphabetic character. The other characters must be either alphabetic, a number, or ! #
$ % [ ] _ as special characters. The variables time, temper, and hertz (see 5.1.1) are
not valid identifier names. Other restrictions on naming conventions apply as well, see
2.9.6.
60 CHAPTER 2. CIRCUIT DESCRIPTION
The .param lines inside subcircuits are copied per call, like any other line. All assignments
are executed sequentially through the expanded circuit. Before its first use, a parameter
name must have been assigned a value. Expressions defining a parameter should be put
within braces {p+p2}, or alternatively within single quotes ’AGAUSS(pippo, 1, 1.67)’.
An assignment cannot be self-referential, something like .param pip = ’pip+3’ will not
work.
The current ngspice version does not always need quotes or braces in expressions, es-
pecially when spaces are used sparingly. However, it is recommended to do so, as the
following examples demonstrate.
Parameters may also have string values, but support is limited. String-valued parameters
can be defined by .param and used in the same ways as numeric parameters. The only
operation on string values is concatenation and that is possible only in top-level .param
assignments.
General form:
Examples:
These are allowed in .model lines and in device lines. A SPICE number is a floating
point number with an optional scaling suffix, immediately glued to the numeric tokens
(see Chapt. 2.9.5). Brace expressions ({..}) cannot be used to parameterize node names
or parts of names. All identifiers used within an <expr> must have known values at the
time when the line is evaluated, else an error is flagged.
2.9. .PARAM PARAMETRIC NETLISTS 61
. subckt < identn > node node ... < ident >= < value > < ident >= < value > ...
Examples:
<identn> is the name of the subcircuit given by the user. node is an integer number
or an identifier, for one of the external nodes. The first <ident>=<value> introduces an
optional section of the line. Each <ident> is a formal parameter, and each <value> is
either a SPICE number or a brace expression. Inside the .subckt ... .ends context, each
formal parameter may be used like any identifier that was defined on a .param control
line. The <value> parts are default values of the parameters.
The syntax of a subcircuit call (invocation) is:
General form:
X < name > node node ... < identn > < ident >= < value > < ident >= < value > ...
Examples:
Here <name> is the symbolic name given to that instance of the subcircuit, <identn>
is the name of a subcircuit defined beforehand. node node ... is the list of actual
nodes where the subcircuit is connected. <value> is either a SPICE number or a brace
expression { <expr> } .
Subcircuit example with parameters:
* Param - example
. param amplitude = 1 V
*
. subckt myfilter in out rval =100 k cval =100 nF
Ra in p1 {2* rval }
Rb p1 out {2* rval }
C1 p1 0 {2* cval }
Ca in p2 { cval }
Cb p2 out { cval }
R1 p2 0 { rval }
. ends myfilter
*
X1 input output myfilter rval =1 k cval =1 n
V1 input 0 AC { amplitude }
. end
62 CHAPTER 2. CIRCUIT DESCRIPTION
< atom > where < atom > is either a spice number or an identifier
< unary - operator > < atom >
< function - name > ( < expr > [ , < expr > ...] )
< atom > < binary - operator > < expr >
( < expr > )
As expected, atoms, built-in function calls and stuff within parentheses are evaluated
before the other operators. The operators are evaluated following a list of precedence
close to the one of the C language. For equal precedence binary ops, evaluation goes left
to right. Functions operate on real values only!
Operator Alias Precedence Description
- 1 unary -
! 1 unary not
** ^ 2 power, like pwr
* 3 multiply
/ 3 divide
% 3 modulo
\ 3 integer divide
+ 4 add
- 4 subtract
== 5 equality
!= <> 5 non-equal
<= 5 less or equal
>= 5 greater or equal
< 5 less than
> 5 greater than
&& 6 boolean and
|| 7 boolean or
c?x:y 8 ternary operator
2.9. .PARAM PARAMETRIC NETLISTS 63
The evaluation of the power functions ** or ^ depends on the compatibility mode (16.14.1)
chosen.
The number zero is used to represent boolean False. Any other number represents boolean
True. The result of logical operators is 1 or 0. An example input file is shown below:
* Logical operators
v1or 1 0 {1 || 0}
v1and 2 0 {1 && 0}
v1not 3 0 {! 1}
v1mod 4 0 {5 % 3}
v1div 5 0 {5 \ 3}
v0not 6 0 {! 0}
. control
op
print allv
. endc
. end
64 CHAPTER 2. CIRCUIT DESCRIPTION
suffix value
g 1e9
meg 1e6
k 1e3
m 1e-3
u 1e-6
n 1e-9
p 1e-12
f 1e-15
Note: there are intentional redundancies in expression syntax, e.g. x^y , x**y and
pwr(x,y) all have nearly the same result.
2.10. .FUNC 65
In addition to the above function names and to the verbose operators ( not and or div
mod ), other words are reserved and cannot be used as parameter names: or, defined,
sqr, sqrt, sin, cos, exp, ln, log, log10, arctan, abs, pwr, time, temper, hertz.
The historical parameter notation using & as the first character of a line as equivalence
to .param. is deprecated and will be removed in a coming release.
Confusion may arise in ngspice because of its multiple numerical expression features. The
.param lines and the brace expressions (see Chapt. 2.10) are evaluated in the front-
end, that is, just after the subcircuit expansion. (Technically, the X lines are kept as
comments in the expanded circuit so that the actual parameters can be correctly sub-
stituted). Therefore, after the netlist expansion and before the internal data setup, all
number attributes in the circuit are known constants. However, there are circuit elements
in Spice that accept arithmetic expressions not evaluated at this point, but only later
during circuit analysis. These are the arbitrary current and voltage sources (B-sources,
5), as well as E- and G-sources and R-, L-, or C-devices. The syntactic difference is that
‘compile-time’ expressions are within braces, but ‘run-time’ expressions have no braces.
To make things more complicated, the back-end ngspice scripting language accepts arith-
metic/logic expressions that operate only on its own scalar or vector data sets (17.2).
Please see Chapt. 2.14.
It would be desirable to have the same expression syntax, operator and function set,
and precedence rules, for the three contexts mentioned above. In the current Numparam
implementation, that goal is not achieved.
2.10 .FUNC
This keyword defines a function. The syntax of the expression is the same as for a .param
(2.9.5).
General form:
Examples:
.func will initiate a replacement operation. After reading the input files, and before
parameters are evaluated, all occurrences of the icos(x) function will be replaced by
66 CHAPTER 2. CIRCUIT DESCRIPTION
cos(x)-1. All occurrences of f(x,y) will be replaced by x*y. Function statements may
be nested to a depth of t.b.d..
2.11 .CSPARAM
Create a constant vector (see 17.8.2) from a parameter in plot (17.3) const.
General form:
Examples:
. param pippo =5
. param pp =6
. csparam pippp ={ pippo + pp }
. param p ={ pp }
. csparam pap = ’ pp +p ’
In the example shown, vectors pippp, and pap are added to the constants that already
reside in plot const, having length one and real values. These vectors are generated dur-
ing circuit parsing and thus cannot be changed later (same as with ordinary parameters).
They may be used in ngspice scripts and .control sections (see Chapt. 17).
The use of .csparam is still experimental and has to be tested. A simple usage is shown
below.
* test csparam
.param TEMPS = 27
.csparam newt = {3*TEMPS}
.csparam mytemp = ’2 + TEMPS’
.control
echo $&newt $&mytemp
.endc
.end
2.12 .TEMP
Sets the circuit temperature in degrees Celsius.
General form:
. temp value
Examples:
. temp 27
2.13. .IF CONDITION-CONTROLLED NETLIST 67
This card overrides the circuit temperature given in an .option line (15.1.1).
General form:
. if ( boolean expression )
...
. elseif ( boolean expression )
...
. else
...
. endif
Example 1:
v1 1 0 1
R1 1 0 2
. if ( ok && ok2 )
R11 1 0 2
. else
R11 1 0 0.5 $ <-- selected
. endif
Example 2:
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
2.14.1 Parameters
Parameters (Chapt. 2.9.1) and functions, either defined within the .param statement or
with the .func statement (Chapt. 2.10) are evaluated before any simulation is started,
that is during the setup of the input and the circuit. Therefore these statements may not
contain any simulation output (voltage or current vectors), because it is simply not yet
available. The syntax is described in Chapt. 2.9.5. During the circuit setup all functions
are evaluated, all parameters are replaced by their resulting numerical values. Thus it will
not be possible to get feedback from a later stage (during or after simulation) to change
any of the parameters.
output using expressions, change some of the element or model parameters with the
alter and altermod statements (see Chapt. 17.5.3) and then automatically start a new
simulation.
Expressions and scripting are powerful tools within ngspice, and we will enhance the
examples given in Chapt. 21 continuously to describe these features.
Chapter 3
Data fields that are enclosed in less-than and greater-than signs (‘< >’) are optional.
All indicated punctuation (parentheses, equal signs, etc.) is optional but indicate the
presence of any delimiter. Further, future implementations may require the punctuation
as stated. A consistent style adhering to the punctuation shown here makes the input
easier to understand. With respect to branch voltages and currents, ngspice uniformly
uses the associated reference convention (current flows in the direction of voltage drop).
The input to ngspice is a netlist, which lists all circuit elements, their interconnects and
model parameters.
71
72 CHAPTER 3. CIRCUIT ELEMENTS AND MODELS
bipolar amplifier
R3 vcc intc 10 k
R1 vcc intb 68 k
R2 intb 0 10 k
Cout out intc 10 u
Cin intb in 10 u
RLoad out 0 100 k
Q1 intc intb 0 BC546B
VCC vcc 0 5
Vin in 0 dc 0 ac 1 sin (0 1 m 500)
. model BC546B npn ( IS =7.59 E -15 VAF =73.4 BF =480 IKF =0.0962
+ NE =1.2665 ISE =3.278 E -15 IKR =0.03 ISC =2.00 E -13 NC =1.2 NR =1
+ BR =5 RC =0.25 CJC =6.33 E -12 FC =0.5 MJC =0.33 VJC =0.65
+ CJE =1.25 E -11 MJE =0.55 VJE =0.65 TF =4.26 E -10 ITF =0.6 VTF =3
+ XTF =20 RB =100 IRB =0.0001 RBM =10 RE =0.5 TR =1.50 E -07)
. end
After the first line, which is always a title line only, the netlist starts. Each line here is a
device instance (except for lines starting with a dot ’.’). We have simple circuit elements
that consist of a single line only, e.g. resistors like R3. In its simplest implementation,
the resistor model does not need any model parameters except for the resistance value
(same for capacitors like Cout). Netlist lines like R3 vcc intc 10k are called instance lines,
as each line is the representation of an instance of a generic model hard-coded into the
ngspice simulator (here: resistor). R3 denotes the device name. Its first character R
denotes a resistor. The next two tokens vcc intc are the two nodes of the resistor, 10k is
the resistance value. Equal node names on different devices denote a connection between
these nodes.
A more complex device is described by the instance line Q1 intc intb 0 BC546B. Q denotes
a bipolar transistor, intc intb 0 are the three nodes collector, base, and emitter. BC546B is
the name of a model parameter set, named after a real transistor and describing (together
with the implemented bipolar transistor model) its electrical behavior. The associated
model parameters are given in the line .model BC546B npn (IS=7.59E-15 ...). This is not an
instance line, because starting with a dot. It contains the model parameters as supplied by
the device manufacturer or by people having them extracted from the electrical behavior
and data sheet (to be found e.g. on his or her web pages). BC546B is the name of the
model parameter set and relates it to the device instance. npn is the type of the device.
The parameters (name=value) are given in brackets.
The instance Q1... requires model parameters. For a quick test one may do without
device maker’s model parameters.
3.2. GENERAL OPTIONS 73
If you enter the bipolar transistor instance as shown above, you make use of a default
model parameter set supplied by ngspice. defaultmod is an arbitrary name. This procedure
models a generic bipolar transistor, not resembling any commercial device. The default
parameter values may be assessed by the command showmod Q1.
You will get more information on devices, instances and models in the following chapters
3.3 to 12.
When it is needed to simulate several devices of the same kind in parallel, use the ‘m’
(parallel multiplier) instance parameter available for the devices listed in Table 3.1. This
multiplies the value of the element’s matrix stamp with m’s value. The netlist below shows
how to correctly use the parallel multiplier:
d1 2 0 mydiode m =10
d01 1 0 mydiode
d02 1 0 mydiode
d03 1 0 mydiode
d04 1 0 mydiode
d05 1 0 mydiode
d06 1 0 mydiode
d07 1 0 mydiode
d08 1 0 mydiode
d09 1 0 mydiode
d10 1 0 mydiode
...
The d1 instance connected between nodes 2 and 0 is equivalent to the 10 parallel devices
d01-d10 connected between nodes 1 and 0.
When the X line (e.g. x1 a b sub1 m=5) contains the token m=value (as shown) or
m=expression, subcircuit invocation is done in a special way. If an instance line of the
subcircuit sub1 contains any of the elements shown in table 3.1, then these elements are
instantiated with the additional parameter m (in this example having the value 5). If such
an element already has an m multiplier parameter, the element m is multiplied with the
m derived from the X line. This works recursively, meaning that if a subcircuit contains
another subcircuit (a nested X line), then the latter m parameter will be multiplied by the
former one, and so on.
Example 1:
. param madd = 6
X1 a b sub1 m =5
. subckt sub1 a1 b1
Cs1 a1 b1 C =5 p m = ’ madd -2 ’
. ends
. param madd = 4
X1 a b sub1 m =3
. subckt sub1 a1 b1
X2 a1 b1 sub2 m = ’ madd -2 ’
. ends
. subckt sub2 a2 b2
Cs2 a2 b2 3 p m =2
. ends
Using m may fail to correctly describe geometrical properties for real devices like MOS
transistors.
M1 d g s nmos W=0.3u L=0.18u m=20
is probably not be the same as
M1 d g s nmos W=6u L=0.18u
because the former may suffer from small width (or edge) effects, whereas the latter is
simply a wide transistor.
Instance parameters are listed in each of the following device descriptions. Model pa-
rameters sometimes are given below as well, for complex models like the BSIM transistor
models, they are available in the model makers documentation. Instance parameters may
also be placed in the .model line. Thus they are recognized by each device instance refer-
ring to that model. Their values may be overridden for a specific instance of a device by
placing them additionally onto its instance line.
state. If a device is specified OFF, the dc operating point is determined with the terminal
voltages for that device set to zero. After convergence is obtained, the program continues
to iterate to obtain the exact value for the terminal voltages. If a circuit has more than
one dc stable state, the OFF option can be used to force the solution to correspond to a
desired state. If a device is specified OFF when in reality the device is conducting, the
program still obtains the correct solution (assuming the solutions converge) but more
iterations are required since the program must independently converge to two separate
solutions.
The .NODESET control line (see Chapt. 15.2.1) serves a similar purpose as the OFF option.
The .NODESET option is easier to apply and is the preferred means to aid convergence. The
second form of initial conditions are specified for use with the transient analysis. These
are true ‘initial conditions’ as opposed to the convergence aids above. See the description
of the .IC control line (Chapt. 15.2.2) and the .TRAN control line (Chapt. 15.3.10) for a
detailed explanation of initial conditions.
3.3.1 Resistors
General form:
RXXXXXXX n + n - < resistance | r = > value < ac = val > <m = val >
+ < scale = val > < temp = val > < dtemp = val > < tc1 = val > < tc2 = val >
+ < noisy =0|1 >
Examples:
R1 1 2 100
RC1 12 17 1 K
R2 5 7 1 K ac =2 K
RL 1 4 2 K m =2
Ngspice has a fairly complex model for resistors. It can simulate both discrete and semi-
conductor resistors. Semiconductor resistors in ngspice means: resistors described by
geometrical parameters. So, do not expect detailed modeling of semiconductor effects.
n+ and n- are the two element nodes, value is the resistance (in ohms) and may be
positive or negative1 but not zero.
Simulating small valued resistors: If you need to simulate very small
resistors (0.001 Ohm or less), you should use CCVS (transresistance).
It is less efficient but improves overall numerical accuracy. Consider a
small resistance as a large conductance.
Ngspice can assign a resistor instance a different value for AC analysis, specified using the
ac keyword. This value must not be zero as described above. The AC resistance is used
1
A negative resistor modeling an active element can cause convergence problems, please avoid it.
3.3. ELEMENTARY DEVICES 77
in AC analysis only (neither Pole-Zero nor Noise). If you do not specify the ac parameter,
it is defaulted to value.
Ngspice calculates the nominal resistance as
VALUE scale
Rnom = m
(3.1)
ac scale
Racnom = m
.
If you want to simulate temperature dependence of a resistor, you need to specify its tem-
perature coefficients, using a .model line or as instance parameters, like in the examples
below:
Examples:
The temperature coefficients tc1 and tc2 describe a quadratic temperature dependence
(see equation 1.6) of the resistance. If given in the instance line (the R... line) their
values will override the tc1 and tc2 of the .model line (3.3.3). Ngspice has an additional
temperature model equation 3.2 parameterized by tce given in model or instance line. If
all parameters are given (quadratic and exponential) the exponential temperature model
is chosen.
R (T ) = R (T0 ) 1.01T CE·(T −T0 ) (3.2)
If you are interested in temperature effects or noise equations, read the next section on
semiconductor resistors.
2
Flicker noise can be used to model carbon resistors.
78 CHAPTER 3. CIRCUIT ELEMENTS AND MODELS
RXXXXXXX n + n - < value > < mname > <l = length > <w = width >
+ < temp = val > < dtemp = val > <m = val > < ac = val > < scale = val >
+ < noisy = 0|1 >
Examples:
RLOAD 2 10 10 K
RMOD 3 7 RMODEL L =10 u W =1 u
This is the more general form of the resistor presented before (3.3.1) and allows the
modeling of temperature effects and for the calculation of the actual resistance value from
strictly geometric information and the specifications of the process. If value is specified,
it overrides the geometric information and defines the resistance. If mname is specified,
then the resistance may be calculated from the process information in the model mname
and the given length and width. If value is not specified, then mname and length must
be specified. If width is not specified, then it is taken from the default width given in
the model.
The (optional) temp value is the temperature at which this device is to operate, and
overrides the temperature specification on the .option control line and the value specified
in dtemp.
l − SHORT
Rnom = rsh (3.3)
w − NARROW
DEFW is used to supply a default value for w if one is not specified for the device. If either
rsh or l is not specified, then the standard default resistance value of 1 mOhm is used.
TNOM is used to override the circuit-wide value given on the .options control line where
the parameters of this model have been measured at a different temperature. After the
nominal resistance is calculated, it is adjusted for temperature by the formula:
R(T ) = R(TNOM) 1 + T C1 (T − TNOM) + T C2 (T − TNOM)2 (3.4)
where R(TNOM) = Rnom |Racnom . In the above formula, ‘T ’ represents the instance
temperature, which can be explicitly set using the temp keyword or calculated using the
circuit temperature and dtemp, if present. If both temp and dtemp are specified, the latter
is ignored. Ngspice improves SPICE’s resistors noise model, adding flicker noise (1/f ) to
it and the noisy (or noise) keyword to simulate noiseless resistors. The thermal noise
in resistors is modeled according to the equation:
4kT
i¯2R = ∆f (3.5)
R
¯ = KFIRAF
i2Rf n ∆f (3.6)
W W F LLF f EF
A small list of sheet resistances (in Ω/) for conductors is shown below. The table repre-
sents typical values for MOS processes in the 0.5 - 1 um
range. The table is taken from: N. Weste, K. Eshraghian - Principles of CMOS VLSI
Design 2nd Edition, Addison Wesley.
General form:
RXXXXXXX n + n - R = ’ expression ’ < tc1 = value > < tc2 = value > < noisy =0 >
RXXXXXXX n + n - ’ expression ’ < tc1 = value > < tc2 = value > < noisy =0 >
Examples:
r2_cmc
v1 1 0 10
Rr2_cmc 1 0 rmodel w =1 u l =20 u isnoisy =1
. model rmodel r ( level =2 rsh =200 xl =0.2 u xw = -0.05 u
+ p3 =0.12 q3 =1.6 p2 =0.015 q2 =3.8 tc1 =1.5 e -4 tc2 =7 e -7)
. control
op
let res = v (1) / - v1 # branch
print res . endc
. end
3.3.6 Capacitors
General form:
CXXXXXXX n + n - < value > < mname > <m = val > < scale = val > < temp = val >
+ < dtemp = val > < tc1 = val > < tc2 = val > < ic = init_condition >
Examples:
CBYP 13 0 1 UF
COSC 17 23 10 U IC =3 V
Ngspice provides a detailed model for capacitors. Capacitors in the netlist can be specified
giving their capacitance or their geometrical and physical characteristics. Following the
original SPICE3 ‘convention’, capacitors specified by their geometrical or physical char-
acteristics are called ‘semiconductor capacitors’ and are described in the next section.
In this first form n+ and n- are the positive and negative element nodes, respectively and
value is the capacitance in Farads.
Capacitance can be specified in the instance line as in the examples above or in a .model
line, as in the example below:
C1 15 5 cstd
C2 2 7 cstd
. model cstd C cap =3 n
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 the uic option is specified
on the .tran control line.
The temperature coefficients tc1 and tc2 describe a quadratic temperature dependence
(see equation17.14) of the capacitance. If given in the instance line (the C... line) their
values will override the tc1 and tc2 of the .model line (3.3.8).
General form:
CXXXXXXX n + n - < value > < mname > <l = length > <w = width > <m = val >
+ < scale = val > < temp = val > < dtemp = val > < ic = init_condition >
Examples:
CLOAD 2 10 10 P
CMOD 3 7 CMODEL L =10 u W =1 u
This is the more general form of the Capacitor presented in section (3.3.6), and allows
for the calculation of the actual capacitance value from strictly geometric information
and the specifications of the process. If value is specified, it defines the capacitance and
both process and geometrical information are discarded. If value is not specified, the
capacitance is calculated from information contained model mname and the given length
and width (l, w keywords, respectively).
It is possible to specify mname only, without geometrical dimensions and set the capaci-
tance in the .model line (3.3.6).
The capacitor model contains process information that may be used to compute the
capacitance from strictly geometric information.
3.3. ELEMENTARY DEVICES 83
If neither value nor CAP are specified, then geometrical and physical parameters are take
into account:
CJ can be explicitly given on the .model line or calculated by physical parameters. When
CJ is not given, is calculated as:
If THICK is not zero:
DI ϵ0
CJ = THICK
if DI is specified,
(3.11)
ϵSiO2
CJ = THICK
otherwise.
If the relative dielectric constant is not specified the one for SiO2 is used. The values
of the constants are ϵ0 = 8.854214871e − 12 m F
and ϵSiO2 = 3.4531479969e − 11 m
F
. The
nominal capacitance is then computed as:
After the nominal capacitance is calculated, it is adjusted for temperature by the formula:
C(T ) = C(TNOM) 1 + T C1 (T − TNOM) + T C2 (T − TNOM)2 (3.13)
84 CHAPTER 3. CIRCUIT ELEMENTS AND MODELS
In the above formula, ‘T ’ represents the instance temperature, which can be explicitly set
using the temp keyword or calculated using the circuit temperature and dtemp, if present.
General form:
CXXXXXXX n + n - C = ’ expression ’ < tc1 = value > < tc2 = value >
CXXXXXXX n + n - ’ expression ’ < tc1 = value > < tc2 = value >
CXXXXXXX n + n - Q = ’ expression ’ < tc1 = value > < tc2 = value >
Examples:
Behavioral Capacitor
. param Cl =5 n Ch =1 n Vt =1 m Il =100 n
. ic v ( cc ) = 0 v ( cc2 ) = 0
* capacitor depending on control voltage V ( cc )
C1 cc 0 c = ’V ( cc ) < { Vt } ? { Cl } : { Ch } ’
I1 0 1 { Il }
Exxx n1 - copy n2 n2 cc2 1
Cxxx n1 - copy n2 1
Bxxx cc2 n2 I = ’( V ( cc2 ) < { Vt } ? { Cl } : { Ch }) ’ * i ( Exxx )
I2 n2 22 { Il }
vn2 n2 0 DC 0
* measure charge by integrating current
aint1 % id (1 cc ) 2 time_count
aint2 % id (22 cc2 ) 3 time_count
. model time_count int ( in_offset =0.0 gain =1.0
+ out_lower_limit = -1 e12 out_upper_limit =1 e12
+ limit_range =1 e -9 out_ic =0.0)
. control
unset askquit
tran 100 n 100 u
plot v (2)
plot v ( cc ) v ( cc2 )
. endc
. end
3.3.10 Inductors
General form:
LYYYYYYY n + n - < value > < mname > < nt = val > <m = val >
+ < scale = val > < temp = val > < dtemp = val > < tc1 = val >
+ < tc2 = val > < ic = init_condition >
Examples:
LLINK 42 69 1 UH
LSHUNT 23 51 10 U IC =15.7 MA
The inductor device implemented into ngspice has many enhancements over the original
one.n+ and n- are the positive and negative element nodes, respectively. value is the
inductance in Henry. The initial condition (a curremt through L) becomes effective when
the uic parameter is set on the .tran line. Inductance can be specified in the instance
line as in the examples above or in a .model line, as in the example below:
86 CHAPTER 3. CIRCUIT ELEMENTS AND MODELS
L1 15 5 indmod1
L2 2 7 indmod1
. model indmod1 L ind =3 n
The (optional) initial condition is the initial (time zero) value of inductor current (in
Amps) that flows from n+, through the inductor, to n-. Note that the initial conditions
(if any) apply only if the UIC option is specified on the .tran analysis line.
Ngspice calculates the nominal inductance as described below:
value scale
Lnom = (3.14)
m
value scale
Lnom = (3.15)
m
If model inductance is specified then
IND scale
Lnom = (3.16)
m
3.3. ELEMENTARY DEVICES 87
If neither value nor IND are specified, then geometrical and physical parameters are taken
into account. In the following formulas
NT refers to both instance and model parameter (instance parameter overrides model
parameter):
If LENGTH is not zero:
(
MU µ0 NT2 π DIA2
Lnom = 4 LENGTH
if DIA is specified,
MU µ0 NT2 CSECT (3.17)
Lnom = LENGTH
otherwise.
with µ0 = 1.25663706143592 µH m
. DIA takes preference over CSECT. kl is the geometry
correction factor according to Lundin (see D. W. Knight, pp. 35-36), which is important
when inductor length and diameter have the same order of magnitude. After the nominal
inductance is calculated, it is adjusted for temperature by the formula
L(T ) = L(TNOM) 1 + T C1 (T − TNOM) + T C2 (T − TNOM) , 2
(3.18)
where L(TNOM) = Lnom . In the above formula, ‘T ’ represents the instance tempera-
ture, which can be explicitly set using the temp keyword or calculated using the circuit
temperature and dtemp, if present.
Examples:
LYYYYYYY and LZZZZZZZ are the names of the two coupled inductors, and value is
the coefficient of coupling, K, which must be greater than 0 and less than or equal to 1.
Using the ‘dot’ convention for drawing the coupled inductors, place a ‘dot’ on the first
node of each inductor. If you have more than two inductors interacting, pairwise coupling
is supported.
Pairwise coupling of more than two inductors:
L1 1 0 10 u
L2 2 0 11 u
L3 3 0 10 u
K12 L1 L2 0.99
K23 L2 L3 0.99
K13 L1 L3 0.98
88 CHAPTER 3. CIRCUIT ELEMENTS AND MODELS
When there are more than two inductors coupled for interaction, some combination of
coupling constants are not possible physically because the magnetic fields then would
violate energy conservation. ngspice checks the coupling matrix for such conditions and
issues a warning.
General form:
LXXXXXXX n + n - L = ’ expression ’ < tc1 = value > < tc2 = value >
LXXXXXXX n + n - ’ expression ’ < tc1 = value > < tc2 = value >
Examples:
Variable inductor
. param Ll =0.5 m Lh =5 m It =50 u Vi =2 m
. ic v ( int21 ) = 0
* fixed inductor
L3 33 331 { Ll }
* measure current through inductor
vm33 331 0 dc 0
* voltage on inductor
V3 33 0 { Vi }
. control
unset askquit
tran 1 u 100 u uic
plot i ( Vm ) i ( vm33 )
plot i ( vm21 ) i ( vm33 )
plot i ( vm ) - i ( vm21 )
. endc
. end
*
* This circuit contains a capacitor and an inductor with
90 CHAPTER 3. CIRCUIT ELEMENTS AND MODELS
3.3.15 Switches
Two types of switches are available: a voltage controlled switch (type SXXXXXX, model
SW) and a current controlled switch (type WXXXXXXX, model CSW). A switching
hysteresis may be defined, as well as on- and off-resistances (0 < R < ∞).
General form:
Examples:
s1 1 2 3 4 switch1 ON
s2 5 6 3 0 sm2 off
Switch1 1 2 10 0 smodel1
w1 1 2 vclock switchmod1
W2 3 0 vramp sm1 ON
wreset 5 6 vclck lossyswitch OFF
Nodes 1 and 2 are the nodes between which the switch terminals are connected. The model
name is mandatory while the initial conditions are optional. For the voltage controlled
switch, nodes 3 and 4 are the positive and negative controlling nodes respectively. For
the current controlled switch, the controlling current is that through the specified voltage
source. The direction of positive controlling current flow is from the positive node, through
the source, to the negative node.
The instance parameters ON or OFF are required, when the controlling voltage (cur-
rent) starts inside the range of the hysteresis loop (different outputs during forward vs.
3.3. ELEMENTARY DEVICES 91
backward voltage or current ramp). Then ON or OFF determine the initial state of the
switch.
The switch model allows an almost ideal switch to be described in ngspice. The switch is
not quite ideal, in that the resistance can not change from 0 to infinity, but must always
have a finite positive value. By proper selection of the on and off resistances, they can
be effectively zero and infinity in comparison to other circuit elements. The parameters
available are shown below.
Name Parameter Units Default Switch model
VT threshold voltage V 0.0 SW
IT threshold current A 0.0 CSW
VH hysteresis voltage V 0.0 SW
IH hysteresis current A 0.0 CSW
RON on resistance Ω 1.0 SW,CSW
ROFF off resistance Ω 1.0e+12 (*) SW,CSW
(*) Or 1/GM IN , if you have set GM IN to any other value, see the .OPTIONS control
line (15.1.2) for a description of GM IN , its default value results in an off-resistance of
1.0e+12 ohms.
The use of an ideal element that is highly nonlinear such as a switch can cause large
discontinuities to occur in the circuit node voltages. A rapid change such as that associated
with a switch changing state can cause numerical round-off or tolerance problems leading
to erroneous results or time step difficulties. The user of switches can improve the situation
by taking the following steps:
• First, it is wise to set the ideal switch impedance just high or low enough to be
negligible with respect to other circuit elements. Using switch impedances that
are close to ‘ideal’ in all cases aggravates the problem of discontinuities mentioned
above. Of course, when modeling real devices such as MOSFETS, the on resistance
should be adjusted to a realistic level depending on the size of the device being
modeled.
• When switches are placed around capacitors, then the option CHGTOL should also
be reduced. Suggested values for these two options are 1.0 and 1e-16 respectively.
These changes inform ngspice to be more careful around the switch points so that
no errors are made due to the rapid change in the circuit.
92 CHAPTER 3. CIRCUIT ELEMENTS AND MODELS
Switch test
. tran 2 us 5 ms
* switch control voltage
v1 1 0 DC 0.0 PWL (0 0 2e -3 2 4e -3 0)
* switch control voltage starting inside hysteresis window
* please note influence of instance parameters ON , OFF
v2 2 0 DC 0.0 PWL (0 0.9 2e -3 2 4e -3 0.4)
* switch control current
i3 3 0 DC 0.0 PWL (0 0 2e -3 2 m 4e -3 0) $ <--- switch control current
* load voltage
v4 4 0 DC 2.0
* input load for current source i3
r3 3 33 10 k
vm3 33 0 dc 0 $ <--- measure the current
* ouput load resistors
r10 4 10 10 k
r20 4 20 10 k
r30 4 30 10 k
r40 4 40 10 k
*
s1 10 0 1 0 switch1 OFF
s2 20 0 2 0 switch1 OFF
s3 30 0 2 0 switch1 ON
. model switch1 sw vt =1 vh =0.2 ron =1 roff =10 k
*
w1 40 0 vm3 wswitch1 off
. model wswitch1 csw it =1 m ih =0.2 m ron =1 roff =10 k
*
. control
run
plot v (1) v (10)
plot v (10) vs v (1) $ <-- get hysteresis loop
plot v (2) v (20) $ <--- different initial values
plot v (20) vs v (2) $ <-- get hysteresis loop
plot v (2) v (30) $ <--- different initial values
plot v (30) vs v (2) $ <-- get hysteresis loop
plot v (40) vs vm3 # branch $ <--- current controlled switch hysteresi
. endc
. end
Chapter 4
VXXXXXXX N + N - <<DC > DC / TRAN VALUE > < AC < ACMAG < ACPHASE > > >
+ < DISTOF1 < F1MAG < F1PHASE > > > < DISTOF2 < F2MAG < F2PHASE > > >
IYYYYYYY N + N - <<DC > DC / TRAN VALUE > < AC < ACMAG < ACPHASE > > >
+ < DISTOF1 < F1MAG < F1PHASE > > > < DISTOF2 < F2MAG < F2PHASE > > >
Examples:
VCC 10 0 DC 6
VIN 13 2 0.001 AC 1 SIN (0 1 1 MEG )
ISRC 23 21 AC 0.333 45.0 SFFM (0 1 10 K 5 1 K )
VMEAS 12 9
VCARRIER 1 0 DISTOF1 0.1 -90.0
VMODULATOR 2 0 DISTOF2 0.01
IIN1 1 5 AC 1 DISTOF1 DISTOF2 0.001
n+ and n- are the positive and negative nodes, respectively. Note that voltage sources
need not be grounded. 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
out of the n+ node, through the source, and into the n- node. Voltage sources, in addition
to being used for circuit excitation, are the ‘ammeters’ for ngspice, 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.
DC/TRAN is the dc and transient analysis value of the source. If the source value is zero
both for dc and transient analyses, this value may be omitted. If the source value is
time-invariant (e.g., a power supply), then the value may optionally be preceded by the
letters DC.
The keyword AC together with its value ACMAG (and optional value ACPHASE) are required
when the voltage or current source is intended to become the small signal source in an
93
94 CHAPTER 4. VOLTAGE AND CURRENT SOURCES
ac simulation. ACMAG is the ac magnitude and ACPHASE is the ac phase. The voltage or
current source then will become a reference for all nodes. All small signal node amplitude
values obtained after the simulation have been divided by the reference ACMAG. A typcal
ACMAG value thus may be unity. Any measured phase has been shifted by ACPHASE. If
ACPHASE is omitted, a value of zero is assumed. If the source is not an ac small-signal
input, the keyword AC and the ac values are to be avoided.
DISTOF1 and DISTOF2 are the keywords that specify that the independent source has
distortion inputs at the frequencies F1 and F2 respectively (see the description of the
.DISTO control line). The keywords may be followed by an optional magnitude and
phase. The default values of the magnitude and phase are 1.0 and 0.0 respectively.
Any independent source can be assigned a time-dependent value for transient analysis. If
a source is assigned a time-dependent value, the time-zero value is used for dc analysis.
There are nine independent source functions:
• pulse,
• exponential,
• sinusoidal,
• piece-wise linear,
• single-frequency FM,
• AM,
• transient noise,
• and RF port
If parameters other than source values are omitted or set to zero, the default values shown
are assumed. TSTEP is the printing increment and TSTOP is the final time – see the .TRAN
control line for an explanation.
4.1.1 Pulse
General form:
PULSE ( V1 V2 TD TR TF PW PER NP )
Examples:
4.1.2 Sinusoidal
General form:
Examples:
(
V0 if 0 ≤ t < T D
V (t) =
V 0 + V A e−(t−T D)T HET A sin (2π · F REQ · (t − T D) + P HASE) if T D ≤ t < T ST OP.
(4.1)
4.1.3 Exponential
General form:
Examples:
VIN 3 0 EXP ( -4 -1 2 NS 30 NS 60 NS 40 NS )
V 1
if 0 ≤ t < T D1,
(t−T D1)
− T AU 1
V (t) = V 1 + V 21 1 − e if T D1 ≤ t < T D2,
(t−T D1) (t−T D2)
V 1 + V 21 1 − e− T AU 1 + V 12 1 − e− T AU 2 if T D2 ≤ t < T ST OP.
(4.2)
General form:
PWL ( T1 V1 < T2 V2 T3 V3 T4 V4 ... >) <r = value > < td = value >
Examples:
Each pair of values (Ti , Vi ) specifies that the value of the source is Vi (in Volts or Amps)
at time = Ti . The value of the source at intermediate values of time is determined by
using linear interpolation on the input values. The parameter r determines a repeat time
point. If r is set to -1 or is not given, the whole sequence of values (Ti , Vi ) is issued once
only, then the output stays at its final value. If r = 0, the whole sequence from time 0 to
time Tn is repeated forever. If r = 10ns, the sequence between 10ns and 50ns is repeated
forever. The r value has to be one of the time points T1 to Tn of the PWL sequence. If
td is given, the whole PWL sequence is delayed by the value of td. Please note that for
now r and td are available only with the voltage source, not with the current source.
4.1.5 Single-Frequency FM
General Form:
Examples:
V1 12 0 SFFM (0 1 M 20 K 5 1 K )
General form:
AM ( VA VO MF FC TD PHASES )
Examples:
V1 12 0 AM (0.5 1 20 K 5 MEG 1 m )
98 CHAPTER 4. VOLTAGE AND CURRENT SOURCES
Examples:
Transient noise is an experimental feature allowing (low frequency) transient noise injec-
tion and analysis. See Chapt. 15.3.11 for a detailed description. NA is the Gaussian noise
rms voltage amplitude, NT is the time between sample values (breakpoints will be en-
forced on multiples of this value). NALPHA (exponent to the frequency dependency), NAMP
(rms voltage or current amplitude) are the parameters for 1/f noise, RTSAM the random
telegraph signal amplitude, RTSCAPT the mean of the exponential distribution of the trap
capture time, and RTSEMT its emission time mean. White Gaussian, 1/f, and RTS noise
may be combined into a single statement.
Name Parameter Default value Units
NA Rms noise amplitude (Gaussian) - V, A
NT Time step - sec
NALPHA 1/f exponent 0<α<2 -
NAMP Amplitude (1/f) - V, A
RTSAM Amplitude - V, A
RTSCAPT Trap capture time - sec
RTSEMT Trap emission time - sec
If you set NT and RTSAM to 0, the noise option TRNOISE ... is ignored. Thus you may
switch off the noise contribution of an individual voltage source VNOI by the command
alter @vnoi[trnoise] = [ 0 0 0 0 ] $ no noise
4.1. INDEPENDENT SOURCES FOR VOLTAGE OR CURRENT 99
The TRRANDOM option yields statistically distributed voltage values, derived from the
ngspice random number generator. These values may be used in the transient simula-
tion directly within a circuit, e.g. for generating a specific noise voltage, but especially
they may be used in the control of behavioral sources (B, E, G sources 5, voltage control-
lable A sources 12, capacitors 3.3.9, inductors 3.3.13, or resistors 3.3.4) to simulate the
circuit dependence on statistically varying device parameters. A Monte-Carlo simulation
may thus be handled in a single simulation run.
General form:
TRRANDOM ( TYPE TS < TD < PARAM1 < PARAM2 > > >)
Examples:
EXTERNAL
Examples:
Vex 1 0 dc 0 external
Iex i1 i2 dc 0 external <m = xx >
Voltages or currents may be set from the calling process, if ngspice is compiled as a shared
library and loaded by the process. See Chapt. 19.6.3 for an explanation.
4.1.11 RF Port
A voltage source VSRC may be defined as RF Port. To do so, there are at least two
more parameters required. The first is portnum (integer) which defines the VSRC as a
RF Port. Portnum of all VSRCs defined as RF ports must start from 1 and count up to
the number of RF ports. You cannot have duplicate portnums. Then you have Z0 (real)
which defines the internal impedance. If not provided, its default value is 50Ohm. When
declaring a RF ports, the VSRC now become a VSRC with Z0 Ohm in series. This extra
resistor affects all simulations.
General form:
4.2. LINEAR DEPENDENT SOURCES 101
Examples:
V1 in 0 dc 0 ac 1 portnum 1 z0 100
At least two ports are required for the S-parameter simulation with the command .sp
(15.3.8). If portnum is not provided, the voltage source VRSC behaves as normal.
Examples:
G1 2 0 5 0 0.1
n+ and n- are the positive and negative nodes, respectively. Current flow is from the
positive node, through the source, to the negative
node. nc+ and nc- are the positive and negative controlling nodes, respectively. value
is the transconductance (in mhos). m is an optional multiplier to the output current. val
may be a numerical value or an expression according to 2.9.5 containing references to
other parameters. Instance parameters are listed in chapt. 31.3.6.
EXXXXXXX N + N - NC + NC - VALUE
Examples:
E1 2 3 14 1 2.0
102 CHAPTER 4. VOLTAGE AND CURRENT SOURCES
n+ is the positive node, and n- is the negative node. nc+ and nc- are the positive and
negative controlling nodes, respectively. value is the voltage gain. Instance parameters
are listed in chapt. 31.3.7.
Examples:
F1 13 5 VSENS 5 m =2
n+ and n- are the positive and negative nodes, respectively. Current flow is from the
positive node, through the source, to the negative node. vnam is the name of a voltage
source through which the controlling current flows. The direction of positive controlling
current flow is from the positive node, through the source, to the negative node of vnam.
value is the current gain. m is an optional multiplier to the output current. Instance
parameters are listed in chapt. 31.3.4.
Examples:
HX 5 17 VZ 0.5 K
n+ and n- are the positive and negative nodes, respectively. vnam is the name of a voltage
source through which the controlling current flows. The direction of positive controlling
current flow is from the positive node, through the source, to the negative node of vnam.
value is the transresistance (in ohms). Instance parameters are listed in chapt. 31.3.5.