Difference between revisions of "File format:Pwl"
Jump to navigation
Jump to search
Line 25: | Line 25: | ||
== PWL in different SPICE implementations == | == PWL in different SPICE implementations == | ||
=== LTspice === | === [http://www.linear.com/designtools/software/#LTspice LTspice] === | ||
* [http://www.linear.com/solutions/1814 Description of PWL on the Linear Technology website.] | * [http://www.linear.com/solutions/1814 Description of PWL on the Linear Technology website.] | ||
Line 40: | Line 40: | ||
File:Pwl ltspice time error.png|Error during the simulation if the timestamps are not increasing. | File:Pwl ltspice time error.png|Error during the simulation if the timestamps are not increasing. | ||
</gallery> | </gallery> | ||
=== [http://ngspice.sourceforge.net/ Ngspice] === | |||
* [http://ngspice.sourceforge.net/docs/ngspice-manual.pdf Ngspice user's manual] | |||
* [http://hforsten.com/simulating-audio-effects-with-spice.html Blogpost by Henrik Forstén that involves reading audio data from a file using Ngspice] (by using a Python script to get the data into the correct format, link to source on github at the bottom of the page). | |||
==== Observations ==== | |||
* Ngspice's PWL source can't read from a file, however there is a model called <tt>filesource</tt> instead (section 12.2.8 in the user's manual): | |||
** The input file is read line by line. (The [http://sourceforge.net/p/ngspice/ngspice/ci/master/tree/src/xspice/icm/analog/file_source/cfunc.mod#l203 actual implementation] of the module uses <tt>fgets()</tt> 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 <tt>d_source</tt> (section 12.4.21 in the user's manual): | |||
** Again, the file is read [http://sourceforge.net/p/ngspice/ngspice/ci/master/tree/src/xspice/icm/digital/d_source/cfunc.mod#l723 line by line using <tt>fgets()</tt>]. | |||
** 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 == | == Resources == |
Revision as of 15:54, 11 December 2014
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
- Ngspice user's manual
- Blogpost by Henrik Forstén that involves reading audio data from a file using Ngspice (by using a Python script to get the data into the correct format, link to source on github at the bottom of the page).
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.