Piecewise linear (PWL) functions are used to construct a waveform from a series of straight line segments connecting points defined by the user in LTspice. Since PWL functions are useful in creating custom waveforms, they are typically used in defining voltage or current sources.
To add a PWL function to a voltage or current source:
- Right-click on the symbol in the schematic editor
- Click Advanced
- Select either PWL(t1, v1, t2, v2…) or PWL File:
- Depending on your choice in step 3, either enter the PWL values or choose a file.
If you choose to enter the values directly, the PWL statement will be built from your values. The syntax of a PWL statement is a list of two-dimensional points that represent time and value data pairs where the time value is in ascending order:
PWL (0 0 1m 1 2m 1 3m 0)
Time values can also be defined relative to the previous time value by prefixing the time value with a + sign:
PWL (0 0 +1m 1 +1m 1 +1m 0)
Here’s an example of the nonrelative value pairs in the dialog:
The list of two-dimensional points that represent time and value data pairs can be encapsulated in a file and used in a PWL statement:
PWL (file = data.txt)
Other Forms of PWL Statement
LTspice IV supports many other forms of PWL statement. To explore these you will have to directly edit your statement by right-clicking on the text line with the PWL statement (not the component symbol), in the schematic editor. Some examples of alternate PWL forms:
- Repeating data pairs a specified number of cycles, or forever:
PWL REPEAT FOR 5 (0 0 1m 1 2m 1 3m 0) ENDREPEAT
PWL REPEAT FOREVER (0 0 1m 1 2m 1 3m 0) ENDREPEAT
- A trigger expression that turns the source on as long as the expression is true:
PWL (0 0 1m 1 2m 1 3m 0) TRIGGER V(n003)>1
- Scaled time or source values:
PWL TIME_SCALE_FACTOR=0.5 VALUE_SCALE_FACTOR=2 (0 0 1m 1 2m 1 3m 0)
Try using one of these forms of PWL expressions in your next simulation.