Expressions (expressions)
Description
An expression is a construct that combines operands with operators to produce a result that is a function of the values of the operands and the semantic meaning of the operators. Any legal operand is also an expression in itself. Legal operands include numeric constants and references to the top-level netlist parameters or subcircuit parameters. Calls to algebraic and trigonometric functions are also supported. The supported operators, algebraic, and trigonometric functions are listed after the examples.
simulator lang=spectre
parameters p1=1 p2=2 // declare some top-level parameters
r1 (1 0) resistor r=p1 // the simplest type of expression
r2 (1 0) resistor r=p1+p2 // a binary (+) expression
r3 (1 0) resistor r=5+6/2 // expression of constants, = 8
x1 s1 p4=8 // instantiate a subcircuit, defined in the following lines
subckt s1
parameters p1=4 p3=5 p4=6 // subcircuit parameters
r1 (1 0) resistor r=p1 // another simple expression
r2 (1 0) resistor r=p2*p2 // a binary multiply expression
r3 (1 0) resistor r=(p1+p2)/p3 // a more complex expression
r4 (1 0) resistor r=sqrt(p1+p2) // an algebraic function call
r5 (1 0) resistor r=3+atan(p1/p2) // a trigonometric function call
r6 (1 0) RESMOD r=(p1 ? p4+1 : p3) // the ternary operator
ends
// a model card, containing expressions
model RESMOD resistor tc1=p1+p2 tc2=sqrt(p1*p2)
// some expressions used with analysis parameters
time_sweep tran start=0 stop=(p1+p2)*50e-6 // use 5*50e-6 = 150 us
// a vector of expressions (see notes on vectors below)
dc_sweep dc param=p1 values=[0.5 1 +p2 (sqrt(p2*p2)) ] // sweep p1
The Spectre native netlist language allows expressions to be used where numeric values are expected on the right-hand side of an "=" sign, or within a vector, where the vector itself is on the right-hand side of an "=" sign. Expressions can be used when specifying device or analysis instance parameter values (for example, specifying the resistance of a resistor or the stop time of a transient analysis, as outlined in the preceding example), when specifying model parameter values in model cards (for example, specifying bf=p1*0.8 for a bipolar model parameter, bf), or when specifying initial conditions and nodesets for individual circuit nodes.
Operators
The following operators are supported, listed in the order of decreasing precedence. Parentheses can be used to change the order of evaluation. For a binary expression, such as a+b, a is the first operand and b is the second operand. All operators are left associative, with the exceptions of the "to the power of" operator (**) and the ternary operator ( ? : ), which are right associative. For logical operands, any nonzero value is considered true. The relational and equality operators return a value of 1 to indicate true, or 0 to indicate false. There is no short circuiting of logical expressions involving && and ||.
Algebraic and Trigonometric Functions
The trigonometric and hyperbolic functions expect their operands to be specified in radians. The atan2() and hypot() functions are useful for converting from Cartesian to polar form.
User-defined functions are also supported. See spectre -h functions for a description of user-defined functions.
A large number of built-in mathematical and physical constants are available for use in expressions. See spectre -h constants for a list of these constants.
The table_param() function is also supported. This function can be used to return the target column value that matches the integer inputs and the interpolation of the float inputs.
table_param( str, n, int1 ,..., intn, m, float1 ,..., floatm, offsetOut)
.param p1 = 'table_param( str("example.table"), 3, 4, 5, 6, 3, 0.01, 0.02, 0,03, 1 )'
#int1 int2 int3 float1 float2 float3 out1 out2 out3 out4
In this table_param function, the value of n and m is 3, which means there are three integer columns, three float columns, and four output columns. In addition, offsetOut = 1 indicates that we are refrerring to the out1 column
Using Expressions in Vectors
Expressions can be used as vector elements, as in the following example:
dc_sweep dc param=p1 values=[0.5 1 +p2 (sqrt(p2*p2)) ] // sweep p1
When expressions are used within vectors, anything other than constants, parameters, or unary expressions (unary +, unary -) must be surrounded by parentheses. Vector elements should be space separated for clarity, though this is not mandatory. The preceding "dc_sweep" example shows a vector of four elements, namely 0.5, 1, +p2, and sqrt(p2*p2).
Return to top