next up previous contents index
Next: Single-Frequency FM Up: Tran Functions Previous: Gaussian Pulse   Contents   Index

Piecewise Linear

General Form:
pwl(t1 v1 [t2 v2 t3 v3 t4 v4 ...] [r [[=] ti]] [td [=] delay]
pwl(vec1 [vec2] [r [[=] ti]] [td [=] delay]
vclock 7 5 pwl(0 -7 10ns -7 11ns -3 17ns -3 18ns -7 50ns -7)
vin 2 0 pwl(times amplitudes td=1ns)

Each pair of values (ti, vi) specifies that the value of the source is vi (in volts or amps) at time = ti. The value of the source at intermediate values of time is determined by using linear interpolation on the input values. For times before the initial time value, the return is the initial value, and for times after the final time value, the return is the final value.

In the second form, the values are provided in the named vectors, which must be in scope when the deck is parsed (which most often happens just before a simulation is run, and not when the file is read into WRspice). If a single vector name is given, its values are expected to be the same as would be provided in the first form, i.e., an alternating sequence of times and amplitudes. If two vector names are given, the first vector is expected to contain time values only, and the second vector contains the corresponding amplitudes. If vectors are used, all values are obtained from the vectors, as it is presently not possible to mix vectors and explicit values.

In the example below, both voltage sources provide the same output. Note that if the vectors are saved in the constants plot, they will be resolved by name in any context.


* PWL Test

compose constants.pwlvals values 0 0 10p 0 20p 1 40p 1 50p 0
compose constants.tvals values 0 10p 20p 40p 50p
compose constants.xvals values 0 0 1 1 0

v1 1 0 pwl(pwlvals)
v2 2 0 pwl(tvals xvals)

Use of vectors can simplify and make more efficient the handling of very long PWL lists. For example, suppose that one has just run a long simulation of a circuit, and one would like to apply the output of this circuit to another circuit. Suppose that the output is in vector v(1). First, save this vector as a binary rawfile. The binary format is faster to read/write than the default ASCII.

set filetype=binary
write myfile.raw v(1)

Then, on a subsequent run, one can load the saved vectors (the vector and its scale are both saved), and for convenience add them to the constants plot.

load myfile.raw
let constants.tvals = time constants.xvals = v(1)

This needs to be done once only per session. If the circuit file contains a line like

vin 2 0 pwl(tvals xvals)

Then one can run any number of simulations while avoiding the need to repeatedly parse and recreate the long PWL list from an input file.

The pwl function is currently the only tran function that takes parameters. These parameters belong to the pwl function, and must be included inside the parentheses when parentheses are used. The parameters are specified with an identifier, optionally followed by an equal sign, and a number. The parameters must appear following the values list or vector names.

The r (repeat) option forces the wave function to repeat periodically. A time value can optionally follow r, which if given must be one of the ti given but not the final time value, or it can be zero. If the time value is omitted, it is taken as zero. This time value is ``mapped'' to the final time value when the sequence repeats.

For example, after the circuit time slightly exceeds the final time value given, the next output value will be the value following the time given with r, and its time will be the final time plus the difference between the r point time and the point that follows.

The td parameter can be set to a delay time, that will be added to all time values, including those generated with the r parameter.

The two parameters are intended to behave in the same manner as similar parameters defined in HSPICE. There is one difference between WRspice and HSPICE pwl behavior: if the first time value is nonzero, in HSPICE the time zero value will be the source dc value, in WRspice is will be the value at the first given time point.

In dependent sources where the controlling input is specified, a pwl construct if used in the expression for the source will take as input the value of the controlling input, and not time. This is one means by which a piecewise-linear transfer function can be implemented. A similar capability exists through the table function.


e1 1 0 2 0 pwl(-1 1 0 0 1 1)

The example above implements a perfect rectifier (absolute value generator) for voltages between -1 and 1V. Outside this range, the output is clipped to 1V.

The r and td parameters work in this case as well, doing the same things, but with respect to the controlling input. For example:

e1 1 0 2 0 pwl(0 0 .5 1 1 0 R)
v1 2 0 pwl(0 0 100p 5)

The output of e1 is a periodic triangular wave, generated by linearly sweeping the periodic transfer function.

next up previous contents index
Stephen R. Whiteley 2018-08-26