Spice3f5

.param: parameters and expressions

Name values with .param, and use expressions for element and model values.

General form

.param name=value [name=value ...]
.param name='expression' ...
.param name(arg, ...)='expression'

Examples

.param rval=1k fc=1meg
.param cval='1/(2*pi*rval*fc)'
.param bin3(bin,k0,k1,k2)='bin==0 ? k0 : (bin==1 ? k1 : k2)'
r1 in out 'rval'
c1 out 0 'cval'

.param

A .param card defines one or more named values. A value may be a number, with the usual scale factors, or an expression in single quotes. Expressions are those of the interactive interpreter, which include HSPICE's operators and functions such as c ? a : b, ==, **, pwr() and agauss(). They can use other parameters, the built-in constants such as pi, and functions such as sqrt and exp.

As in HSPICE, the cards may be in any order: each parameter is evaluated once those it uses have been, so a parameter may be used before the card that defines it. If a name is defined more than once, the last definition is the one used, also by the parameters that use it. Parameters that use each other in a circle, or names that are never defined, are reported as errors.

They are evaluated as the input file is read, before the rest of the circuit. Each parameter is kept as a vector of the same name among the constants, so it can also be used in interactive commands and expressions after the circuit is loaded:

print rval cval
let x = rval * 2

Because they are evaluated as the file is read, variables that change how they are evaluated, such as hspicelog (natural logarithms, as HSPICE) and montecarlo (random values from agauss() etc.), must be set before the circuit is loaded, for example in spinit or .spiceinit, not in its .control section.

Functions

A name with arguments in parentheses defines a function, as the define command does:

.param sel(x,lo,hi)='x<lo ? 0 : x<hi ? 1 : 2'
.param band='sel(freq, 1k, 1meg)'

Functions are defined before the other parameters are evaluated, so they may be used anywhere. An argument name hides a parameter of the same name.

temper

temper is HSPICE's name for the circuit temperature in °C, and can be used in any expression. It is the temperature the devices are simulated at: the TEMP of a .OPTIONS card if the circuit has one, otherwise 27. A .step temp sets it for each step. It is evaluated when the circuit is loaded, so a set temp in the .control section afterwards changes the devices' temperature but not temper. (A set temp before the circuit is loaded, e.g. in .spiceinit, changes neither.) A .param temper= card replaces it.

Expressions in element and model lines

A value on an element or .model line written in single quotes is evaluated as an expression, and the result used as the value:

r1 in out 'rval'
r2 out 0 '2*rval'
.model dmod d is='1e-14*area_scale'

The result is used at full (15 significant digit) precision, so r1 in 0 'rval' with rval=1.23456789k gives the same resistance, 1234.56789Ω, as r1 in 0 1.23456789k.

The value of a resistor, capacitor or inductor can also be given as r=, c= or l=, and there the name of a parameter may be written without quotes: r1 in out r=rval is the same as r1 in out 'rval'. A name that is not a parameter is reported as an error on that line. Other keyword values, such as a MOSFET's w=, need the quotes: w='wval', except inside a subcircuit (below).

A line of just ) ends the .model card above it, as in HSPICE model libraries.

Subcircuit parameters

Each call of a subcircuit has its own parameters, as in HSPICE: those on its .SUBCKT line, with the values given in the call or the defaults, and the .param cards inside the subcircuit, which may be in any order and use each other and the global parameters:

.subckt rdiv a b rv=1k k=2
.param rbot='rtop/2'
.param rtop='rv*k'
r1 a m r='rtop'
r2 m b rbot
.model dm d (is='1e-14*k')
d1 m b dm
.ends
x1 in 0 rdiv rv=2k k=4

A name that is one of the subcircuit's parameters means that parameter, even if there is a global parameter of the same name; any other name is a global parameter. Inside the subcircuit the parameters can be used in quoted expressions, as the value of any keyword=value field (including a .model's name = value), and as the value of a resistor, capacitor or inductor. Node and model names are not changed. In a B source's expression the global parameters can be used too.

Stepping parameters

A parameter can be stepped with .step param name; for each step the circuit is read again, the parameters that depend on it are evaluated again, and the subcircuits are expanded again, so their parameters follow it too. A .step temp of a circuit that uses temper does the same. See .step. The optimise command varies device and model parameters directly, not .params.

Limitations