Netlist Syntax Reference

Note

Example netlists introducing most of the netlist syntax are available as Netlist Cheat Sheets.

The following is a technical documentation of the supported syntax.

Throughout this section, you will frequently find the option to switch between two tabs: Recommended and Legacy. The Recommended tabs contain clear and unambiguous netlist syntax. Syntax that we support for compatibility with various dialects is listed in the Legacy tab.

Fundamentals

Syntax conventions

  • All netlist statements are case-insensitive.

  • Any line starting with * is treated as a comment.

  • Anything after a ; is treated as a comment.

  • Statements can be continued on the next line using the + character.

  • Use spaces for separation. Use = to assign parameters.

* This is a comment.
.PARAM a=1; This is also a comment.
R1 n1 N1 1; Since n1=N1, this resistor is short-circuited.
R2 n1 n2
+ {1e6*12}; this defines the resistance of R2
  • We do not differentiate between tabs and spaces.

  • Leading spaces are ignored in each line.

  • SPICE traditionally treats (, ), ,, = as space. Some dialects use = to identify assignments. PLECS Spice is capable of dealing with both.

Nodes

Node names can be integers or alphanumeric strings, with node 0 always reserved for ground. We recommend to use descriptive names that clearly distinguish themselves from the names of circuit elements, parameters and functions to make the netlist more readable.

Constants

Constant numbers should be specified using scientific notation.

R1 n1 n2 4.356e4

It is possible to use the multipliers listed in Table 23 instead of scientific notation. Any number can be followed by an arbitrary string of characters. Further, it is possible to skip the leading zeros before ..

R1 n1 n2 43K56
R2 n1 n2 43.56K
R3 n1 n2 43K56Ohm
R4 n1 n2 43.56KOhm

R5 n1 n2 .5; = 0.5
R6 n1 n2 .5K; = 500
Table 23 Multipliers

f

p

n

µ, u

mil

m

K

MEG

G

T

1e-15

1e-12

1e-9

1e-6

25.4e-6

1e-3

1e3

1e6

1e9

1e12

Expressions

Instead of assigning a constant value, mathematical expressions can be used. These mathematical expressions should be put into curly braces. Expressions can evaluate parameters and functions.

.PARAM a=1 b={a} c={a+b}
.FUNC f(x,y)={x+y}
R1 n1 n2 {a}
R2 n1 n2 {f(b,c)}

Some SPICE dialects use = to identify assignments instead of requiring curly braces. We recommend to always provide both the = and the curly braces.

Predefined Parameters and Functions

PLECS Spice provides a rich set of built-in mathematical operators, functions, and constants that you can use in expressions. In user defined source expressions, certain circuit values can be accessed (see Circuit State Access).

Mathematical Operators

All standard arithmetic and comparison operators are supported:

.PARAM a={1+2}     ; Addition
.PARAM b={1-2}     ; Subtraction
.PARAM c={1*2}     ; Multiplication
.PARAM d={1/2}     ; Division
.PARAM e={1+(2*3)} ; Curly braces for grouping

* Both ** and ^ perform exponentiation:
.PARAM a={3**2}    ; 3 squared
.PARAM b={3^0.5}   ; square root of 3

Note

Some SPICE versions treat ^ as logical XOR. In PLECS Spice ^ is always exponentiation.

Mathematical Functions

All standard functions are available:

* Trigonometric functions (angles in radians)
sin(x)    cos(x)    tan(x)
asin(x)   acos(x)   atan(x)   atan2(y,x)

* Hyperbolic functions
sinh(x)   cosh(x)   tanh(x)

* Exponential and logarithm
exp(x)                    ; e^x
log(x)   ln(x)            ; Natural logarithm (base e)
log10(x)                  ; Logarithm base 10

* Power and root
pow(x,y)                  ; x^y
sqrt(x)                   ; Square root
abs(x)                    ; Absolute value

* Rounding and extrema
floor(x)  ceil(x)  round(x) sign(x)
min(x,y)  max(x,y)

Note

To avoid convergence issues, we ensure that the domains of all functions are extended to the real numbers \(\mathbb R\). Further, for extremely large or undefined values, we modify the following functions:

  • exp(x) for values of x exceeding approximately 70.

  • log(x), ln(x) and log10(x) for values of x below approximately 1e-30.

  • pow(x,y) for x < 0 and y not an integer.

Via the “invalid netlist function evaluation” setting in SPICE Simulation Parameters, you can throw warnings or errors when this occurs.

SPICE-Specific Functions

Certain special functions are commonly used in SPICE:

limit(x,y,z)
* Sorts the values x, y, z and returns the value in the middle.
* This is equivalent to clamping/limiting x such that is not larger than y and not smaller than z.

table(x, a1, b1, a2, b2, ...)
* Linear interpolation through points (a1,b1), (a2,b2), ... evaluated at x.
* The values a1, a2, a3, ... must be in ascending or descending order.

pwr(x,y)  ;= pow(abs(x), y)
pwrs(x,y) ;= sign(x) * pwr(x,y)
Logical Expressions

You can use if(condition, true_value, false_value) or condition ? true_value : false_value to either use true_value when condition is true or false_value when condition is false.

The condition should be the result of a comparison == != < > <= >=. Multiple comparison results can be combined using & as “and” or using | as “or”.

.FUNC custom_max(a,b)={if(a>b, a, b)}
.FUNC custom_min(a,b)={a<b ? a : b}
.FUNC custom_limit(x,y,z)={if(x>=y & x<=z, x, if(x<y && y<z, y, z))}

Note

Some SPICE versions support ~ or ! as “not”. Neither of these is currently supported in PLECS Spice.

Comparisons do not return true or false, instead they return 0 and 1. When evaluating the condition, the input is compared against >0.5. This might lead to unexpected behavior:

if(x, 1, 0)    ; Legacy: checks if x > 0.5
if(x>0, 1, 0)  ; Clear: checks if x > 0
Constants

The parameter pi gives access to the mathematical constant \(\pi \approx 3.14159\).

.PARAM freq=50
.PARAM omega={2*pi*freq}

Although pi is predefined, you can override its value.

.PARAM pi=3.14; Override built-in pi.
Circuit State Access

In function based source expressions, you can access voltages, currents and the simulation time.

* Voltage measurements
V(n1)                   ; Voltage at node relative to ground
V(n1, n2)               ; Voltage difference V(n1) - V(n2)

* Current measurements
I(V1)                   ; Current through voltage source V1

* Simulation time
TIME                    ; Current simulation time

* Time derivatives of voltages and currents
ddt(V(n))               ; dV/dt
ddt(I(L1))              ; dI/dt
* Note: ddt() can be applied to arbitrary expressions, but this is not recommended.
* Note: ddt() uses numerical differentiation and may introduce numerical noise.

Currents can be accessed for the following elements:

Scopes and Shadowing

Outside the Main Subcircuit

As explained in Fundamentals, PLECS Spice treats the first subcircuit in a netlist component as main subcircuit. In the global scope outside of this main subcircuit, you can define .SUBCKT, .MODEL, .PARAM and .FUNC. Anything defined like this can be used in the main subcircuit or overwritten there. If a definition is unused, it is not parsed and syntax errors will not be reported.

Other text outside of the main subcircuit will be ignored.

.SUBCKT main n1 n2
R1 n1 n2 {a} ; This accesses the parameter a defined outside of the main subcircuit.
.ENDS

.PARAM a=1

R2 n 0 1; This will be ignored.

.SUBCKT unused m1 m2
* This subcircuit is unused - anything in here is not parsed.
.ENDS

Scopes

When defining .SUBCKT, .MODEL, .PARAM and .FUNC inside of a subcircuit, these definitions are only accessible in its scope, i.e. between the subcircuit’s .SUBCKT and .ENDS.

.SUBCKT main n1 n2
X n1 n2 helper
* The parameter b defined in helper is not accessible here.
.ENDS

.SUBCKT helper m1 m2
.PARAM b=2
R1 m1 m2 {b}
.ENDS

You may only define each .SUBCKT, .MODEL, .PARAM and .FUNC once per scope. Any .SUBCKT, .MODEL, .PARAM and .FUNC definitions within a subcircuit can be freely placed and can be used before they are defined.

.PARAM a=1;

.SUBCKT main n1 n2
R n1 n2 {a} ; Uses a=2 even though it is defined after this line.
.PARAM a=2 ; This overwrite the a=1 from outside the main subcircuit.
.ENDS

Shadowing

When X statements are used to instantiate a subcircuit, this instantiated subcircuit has access to all definitions available in the subcircuit where the X statement is located. Inside the instantiated subcircuit these definitions can be overwritten. Such shadowing does not apply to node names. Node names are always local to their subcircuit. Shadowing also works recursively when instances of subcircuits create other instances of subcircuits.

.SUBCKT main n1 n2
.PARAM a=1
.PARAM b=2
X n1 n2 helper
.ENDS

.SUBCKT helper m1 m2
R1 m1 0 {a}; Resistance is 2 using b=2 from the main subcircuit.
.PARAM a=3; This overwrites a to be 3 while inside this subcircuit.
R2 m1 0 {a}; Resistance is 3.
.ENDS
Subtleties of Shadowing

Whenever definitions contain an expression, they will be evaluated only in the scope of their actual use. When using PARAMS: in X statements, this causes an evaluation in the scope of the X statement.

.SUBCKT sub1 n
.PARAM a=1 b={a}
X1 n sub2
X2 n sub2 PARAMS: b={b}
.ENDS

.SUBCKT sub2 n
.PARAM a=2
R1 n 0 {b}
.ENDS

In the netlist above:

  • X1 creates a resistor with resistance {b} evaluated in sub2. This evaluates to 2 as b=a=2 in the scope of sub2.

  • X2 creates a resistor with the resistance value b={b} passed after PARAMS:. This is evaluated in sub1 and evaluates to 1 as b=a=1 in the scope of sub1.

Note

To avoid shadowing subtleties, we recommend to:

  • Define each .SUBCKT, .MODEL, and .FUNC only once and in the global scope.

  • When passing parameters to subcircuits, only pass parameters that are listed with a default value after PARAMS: in the subcircuit definition.

List of Statements

Each non-empty line represents a statement whose type is determined by its first character(s):