What is a Piecewise Linear (PWL) function in LTspice and when it should be used?

Voltage and current sources in LTspice® can make simple waveforms like pulses or sine waves. But if you need a waveform that is more complicated or has a custom shape, you can use a Piecewise Linear (PWL) function.

A Piecewise Linear (PWL) function in LTspice are a series of straight-line segments that can be used to create custom voltage or current waveforms.
PWL segments are defined as time/value pairs and are one of the many ways to define a voltage or current waveform for transient simulations.

Adding a PWL Function to a Voltage or Current Source
To add a PWL function to a newly placed voltage or current source, right-click on the voltage or current source symbol in the schematic. Next, click Advanced to view all settings, and select PWL(t1 v1 t2 v2…) in the Functions section.


Figure 1. Defining time and value points in a PWL function.

After selecting PWL(t1 v1 t2 v2…), enter time/value pairs into the input fields (only enter as many as you need). Click Additional PWL Points if you need more than four points. Click OK when done.

A PWL statement will be constructed using the values entered in the Advanced setting dialog:

Example syntax

PWL (0 0 1m 1 2m 1 3m 0)

This means:

Time Voltage/Current
0 0
1 ms 1
2 ms 1
3 ms 0

LTspice automatically connects these points with straight lines to form the waveform.


Figure 2. Resulting PWL syntax for a voltage source displayed in the schematic.

Figure 1 and Figure 2 show an example with four point pairs with the PWL function syntax.

Using Relative Time Values in a PWL Waveform:

Time values can also be defined relative to the previous time point by prefixing the time with a + sign.

PWL (0 0 +1m 1 +1m 1 +1m 0)

Figure 3 shows both absolute and relative times that result in identical waveforms.


Figure 3. Identical PWL waveforms using absolute and relative times.

When transient simulations require an arbitrary source waveform, PWL functions provide flexibility to define (or import) waveform data.

Related Articles:
What is LTspice?
An Introduction to LTSpice
LTspice Tips - Mathematical Integration
LTspice Tips - Plot Manually Entered Functions