.PARAM — User-Defined Parameters

The .param directive allows the creation of user-defined constants. This is useful for associating a name with a value for the sake of clarity and parameterizing subcircuits so that abstract circuits can be saved in libraries.

The .param statement can be included inside a subcircuit definition to limit the scope the parameter value to that subcircuit.

From version 24.1 on, LTspice requires no curly braces (nor apostrophes) for parameter substitution and expression evaluation anymore, except for those cases where omitting them would cause a syntactical ambiguity, for instance for circuit element values that are not specified as named parameters, like the value of a resistor.

The order in which user-defined constants are defined is irrelevant. Circular dependencies are not permitted. Every name must be defined, except for the following defaults:

Name Value
PI 3.14159265358979323846
BOLTZ 1.3806503e-23
ECHARGE 1.602176462e-19
PLANCK 6.62620e-34
KELVIN -273.15
GMIN 10-12

These defaults are provided for backwards compatibility. They can be redefined, which is why relying on them is not recommended.

"temp" is a reserved name on the top level. It is always defined and represents temperature in °C.

A user-defined constant introduced with .param can either be a numerical value, e.g.

.param length = 20µ

or a text string, e.g

.param name = "U125D"

Strings can be used to parameterize models or subcircuits, in particular when combined with the select() function. For example, the following snippet uses a stepped numerical parameter n to alter the model of a diode D1:

.param diode = select(n, "1N4148", "1N4007", "1N914")
D1 N1 N2 {diode}
.step param n 0 2 1

Note that numerical parameters implicitly convert to strings. The conversion of non-integers is unspecified. Implicit conversion takes place before performing any operations, for instance

.param text = 1 + 3 + "text"

yields "13text", not "4text".

Below is an example using both a .param statement and directly passing parameters on the subcircuit invocation line.

* This is the circuit definition
.param x=y y=z z=1k*tan(pi/4+.1)
X1 a b 0 divider top=x bot=z
V1 a 0 pulse(0 1 0 .5μ .5μ 0 1μ)

* this is the definition of the subcircuit
.subckt divider n1 n2 n3
r1 n1 n2 {top}
r2 n2 n3 {bot}
.ends

The following functions are available for numerical parameters:

Function Name Description
abs(x) Absolute value of x
acos(x) Real part of the arc cosine of x, e.g., acos(-5) returns 3.14159, not 3.14159+2.29243i
arccos(x) Synonym for acos()
acosh(x) Real part of the arc hyperbolic cosine of x, e.g., acosh(.5) returns 0, not 1.0472i
asin(x) Real part of the arc sine of x, e.g., asin(-5) returns -1.57080, not -1.57080+2.29243i
arcsin(x) Synonym for asin()
asinh(x) Arc hyperbolic sine
atan(x) Arc tangent of x
arctan(x) Synonym for atan()
atan2(y,x) Four quadrant arc tangent of y/x
atanh(x) Arc hyperbolic tangent
buf(x) 1 if x > .5, else 0
cbrt(x) Cube root of (x)
ceil(x) Integer equal or greater than x
cos(x) Cosine of x
cosh(x) Hyperbolic cosine of x
exp(x) e to the x
fabs(x) Same as abs(x)
flat(x) Random number between -x and x with uniform distribution
floor(x) Integer equal to or less than x
gauss(x) Random number from Gaussian distribution with sigma of x.
hypot(x,y) sqrt(x**2 + y**2)
if(x,y,z) If x > .5, then y else z
int(x) Convert x to integer
inv(x) 0. if x > .5, else 1.
limit(x,y,z) Intermediate value of x, y, and z
ln(x) Natural logarithm of x
log(x) Alternate syntax for ln()
log10(x) Base 10 logarithm
max(x,y) The greater of x or y
mc(x,y) A random number between x*(1+y) and x*(1-y) with uniform distribution.
min(x,y) The smaller of x or y
mod(x,y) Remainder of the division operation x / y
pow(x,y) Real part of x**y, e.g., pow(-.5,1.5) returns 0., not 0.353553i
pwr(x,y) abs(x)**y
pwrs(x,y) sgn(x)*abs(x)**y
rand(x) Random number between 0 and 1 depending on the integer value of x.
random(x) Similar to rand(), but smoothly transitions between values.
round(x) Nearest integer to x
select(x,a,b,c,d,...) Rounds x to the nearest integer and uses the result as index into the table [a,b,c,d,...], where the first element has index 0.
sgn(x) Sign of x
sin(x) Sine of x
sinh(x) Hyperbolic sine of x
sqrt(x) Real part of the square root of x, e.g., sqrt(-1) returns 0, not 0.707107i
table(x,a,b,c,d,...) Interpolate a value for x based on a look up table given as a set of pairs of points.
table(x, .include "<filename>") Interpolate a value for x based on a look up table given as a set of pairs of points listed as numbers in the file <filename>.
tan(x) Tangent of x.
tanh(x) Hyperbolic tangent of x
u(x) Unit step, i.e., 1 if x > 0., else 0.
uramp(x) x if x > 0., else 0.
xor(x,y) Converts x and y to Boolean and returns x xor y.

Numerical parameters support the following operations, grouped in reverse order of precedence of evaluation:

Operand Description
& Convert the expressions to either side to Boolean, then AND.
| Convert the expressions to either side to Boolean, then OR.
^ Convert the expressions to either side to Boolean, then XOR.
   
> True if expression on the left is greater than the expression on the right, otherwise false.
< True if expression on the left is less than the expression on the right, otherwise false.
>= True if expression on the left is greater than or equal the expression on the right, otherwise false.
<= True if expression on the left is less than or equal the expression on the right, otherwise false.
   
+ Floating point addition
- Floating point subtraction
   
* Floating point multiplication
/ Floating point division
% Remainder of floating point division, same as mod(x,y) function
   
** Raise left hand side to power of right hand side, only real part is returned, e.g., -2**1.5 returns zero, not 2.82843i

The following functions are available for string parameters:

Function Name Description
select(x,a,b,c,d,...) Rounds x to the nearest integer and uses the result as index into the table [a,b,c,d,...], where the first element has index 0.
table(x,a,b,c,d,...) Returns b if x==a, or d if x==c, etc. No rounding or interpolation is performed. It is recommended to use select() instead.

String parameters only support the "+" operator for string concatenation, e.g:

.param variant = "_fast"
X23 PIN1 PIN2 {"U125D" + variant}

All parameter substitution evaluation is done before the simulation begins.