File format:pwl

From sigrok
Jump to navigation Jump to search
pwl
Pwl source.png
A voltage source using values from a PWL file.
Name Piecewise linear function
Status unsupported
Common extension(s) .txt
ASCII format yes
Compression none

pwl is a file format that can be used to define the signal of voltage/current sources in a SPICE simulation.

Format

The file consists of multiple time/value pairs. The individual values are separated by whitespace, therefore all values can be in one long line, or on multiple lines (much more convenient). The time values have to be in increasing order. SI prefixes are supported for both the time and the value.

The content in the file is then accessed with the PWL file=… statement from the simulation.

PWL in different SPICE implementations

LTspice

Observations

  • A space (0x20) or different newline indicators (CR (0x0D), LF (0x0A) and CR+LF) can be used to separate the times/values.
  • When editing the properties of a voltage/current source in the LTspice editor and choosing the PWL file, the "Open File" dialog uses "ASCII File (*.txt)" as the default filter (but the simulation can use every other file extension too).

Screenshots

Ngspice

Observations

  • Ngspice's PWL source can't read from a file, however there is a model called filesource instead (section 12.2.8 in the user's manual):
    • The input file is read line by line. (The actual implementation of the module uses fgets() to read the individual lines.)
    • The characters '#' and ';' start a comment, the rest of the line after them is ignored.
    • A line can contain two or more values, the first is the timestamp, the other values are the outputs of the model.
  • Ngspice also has a digital source called d_source (section 12.4.21 in the user's manual):
    • Again, the file is read line by line using fgets().
    • The character '*' starts a comment.
    • A line contains a timestamp an one or more digital values.
    • A digital value consists of two characters, the first defines the actual value (0/1/undefined) and the second the "strength" of the state (strong/resistive/hi-impedance/undetermined), as documented in section 12.5.1 "Digital Node Type" of the user's guide.

Resources