next up previous contents index
Next: Exponential Up: Voltage and Current Sources Previous: POLY Expressions   Contents   Index


Tran Functions

There are several built-in source functions, which are based on and extend the source specifications in SPICE2. These generally produce time-dependent output for use in transient analysis. For brevity, these functions are referred to as ``tran functions''.

The tran functions are listed in the table below. If parameters other than source amplitudes are omitted, default values will be assumed. The tran functions, which require multiple space or comma separated arguments in a particular order, are:

exp exponential specification
texp exponential specification
gauss gaussian noise specification
tgauss gaussian noise specification
interp interpolation specification
pulse pulse specification
gpulse gaussian pulse specification
pwl piecewise-linear specification
sffm single frequency fm specification
am amplitude modulated specification
sin sinusoidal specification
tsin sinusoidal specification
spulse sinusoidal pulse specification
table reference to a .table specification

The the texp, tgauss, and tsin are aliases to exp, gauss, and sin tran functions that avoid possible ambiguity with math functions of the same name.

Unlike the math functions, the tran functions have variable-length argument lists. If arguments are omitted, default values are assumed.

The tran functions are most often used to specify voltage/current source output, however in WRspice these can be used in general expressions. The sin, exp, gauss tran functions have names that conflict with math functions. There seems to be no way to absolutely reliably distinguish the tran vs. math functions by context, nor is it possible to exclusively rename the functions without causing huge compatibility problems.

Although the sin and exp functions are generally distinguishable except for one unlikely case, with the additional arguments to the gauss function for HSPICE compatibility in WRspice release 3.0.0, the problem is more acute.

It may be necessary to edit legacy WRspice input files to avoid this problem.

That being said, new intelligence has been added to differentiate between the two species. As in older releases, the argument count will in many cases resolve ambiguity.

First of all, to guarantee that the tran functions are used in an expression, they can be called by the synonym names tsin, texp, and tgauss.

If sin, exp, or gauss use white-space delimiting in the argument list, then they will be called as tran functions. The math functions always use commas to separate arguments. Commas are also legal argument separators in tran functions, but (perhaps) are not as frequently used. If comma argument separators are used, the math functions are assumed.

Note that almost all math functions (whith the exception of gauss and a few others) take a single complex vector argument. It is possible to give these functions multiple comma-separated ``arguments'', but in evaluation these are collapsed by evaluation of the comma operator:

a,b = (a + j*b)
So, sin(1,1) is equivalent to sin((1+j)), which returns a complex value.

In earlier WRspice releases, sin(a,b) was always interpreted as the tran sin function, which has a minimum of two arguments (and similar for exp). Presently.

sin(a,b) comma delimiter implies math
sin(a b) space delimiter implies tran

If ambiguity occurs in a function specification for a voltage or current source, the tran function is favored if the specification is ambiguous.

The tran functions implicitly use time as an independent variable, and generally return 0 in dc analysis. Exceptions are the pwl and interp forms, which implicitly use the value of ``x'' which is context-specific. In dependent sources, this is the controlling value of the source rather than time. The table function takes its input directly from the second argument.

The tran functions can also be used in regular vector expressions. They generate a vector corresponding to the current scale, which must exist, be real, and monotonically increasing. The length of the returned vector is equal to the length of the scale.

For example:

(do a tran analysis to establish a reasonable scale)
let a = pulse(0 1 10n 10n 10n 20n)
plot a (plots a pulse waveform)
The construct can be used like any other token in a regular vector expression.

The tran functions (other than table and interp) take constant expressions as arguments. The argument list consists of comma or space separated expressions. Arguments are parsed as follows:

  1. The outer parentheses, if these exist, are stripped from the list. WRspice can recognize most instances where parentheses are not included, since these are optional in standard SPICE syntax for the tran functions.
  2. Commas that are not enclosed in parentheses or square brackets are converted to spaces.
  3. Minus signs (`-') that are not enclosed in parentheses or square brackets, and are not followed by white space, and are preceded by white space, are assumed to be the start of a new token (argument). An expression termination character (semicolon) is added to the end of the previous argument.
  4. The string is parsed into individual expression units, which are the arguments. The separation is determined by context.

There is no provision for a unary `+', thus, func(a, +b) is taken as func(a+b). Parenthesis can be added to enforce precedence. The minus sign handling implies that func(a, -b) and func(a -b) are taken as func((a), (-b)), whereas f(a-b), f(a- b), f(a - b), etc are taken as func((a)-(b)).

In addition to the built-in functions, expressions used in sources can include user defined functions, which must have been defined previously with the define command. These may be useful for encapsulating the tran functions.

Example:
define mypulse(delay, width) pulse(0 1 delay 1n 1n width)
...
v1 1 0 mypulse(5n, 10n)

Recall that a line in the deck starting with ``*@" will be executed before the deck is parsed.

title line
*@ define mypulse(delay, width) pulse(0 1 delay 1n 1n width)
v1 1 0 mypulse(5n, 10n)
r1 1 0 100
.end

The following paragraphs describe the tran functions in detail.



Subsections
next up previous contents index
Next: Exponential Up: Voltage and Current Sources Previous: POLY Expressions   Contents   Index
Stephen R. Whiteley 2022-09-18