1. Skip to navigation
  2. Skip to content
  3. Skip to sidebar

LTspice: Piecewise Linear Functions for Voltage & Current Sources

Gabino Alonso - Strategic Marketing Engineer Jun 10th 2013

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.

LTspiceIV: Piecewise Linear (PWL) Functions for Voltage & Current Sources

To add a PWL function to a voltage or current source:

  1. Right-click on the symbol in the schematic editor
  2. Click Advanced
  3. Select either PWL(t1, v1, t2, v2…) or PWL File:
  4. 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:

LTspiceIV: Piecewise Linear (PWL) Functions for Voltage & Current Sources

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)

LTspiceIV: Piecewise Linear (PWL) Functions for Voltage & Current Sources

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.

 


Software

LTspice

LTspice® software is a powerful, fast and free simulation tool, schematic capture and waveform viewer with enhancements and models for improving the simulation of switching regulators. Click here to download LTspice