SPICE on gEDA HOWTO -- introduction and overview
Revision history:
The most recent copy of this document is always available at http://www.brorson.com/gEDA/SPICE/
The purpose of this document is to explain how to use the gEDA tools (running on Linux) to perform SPICE simulations. In particular, this HOWTO documents the usage of spice-sdb, which is an advanced backend for the gEDA netlister (gnetlist) used to create SPICE netlists. This HOWTO also provides advice about using LTSpice and/or ngspice to simulate a circuit netlisted with spice-sdb. I assume that you are already familiar with electronic design, the mechanics of schematic capture using EDA tools, and SPICE simulation in general. I also assume that you are reasonably familiar with the Linux operating system and its development environment.
Note that this is now a multi-page document. To navigate through the document, either use the table of contents as a jump-off point, or use the link at the bottom of each page to get to the next page.
Back to the table of contents.From the top level, SPICE simulation in gEDA proceeds via the following steps:
To create a SPICE netlist, the netlister (gnetlist) iterates through the entire schematic and looks at several parts of each component's symbol in order to create a blob of SPICE code. In general, each component can generate one or more lines of SPICE code. Component information needed by the netlister is held in two places:
Since there are two places the netlister looks for information, you must make sure that the required information is available in both places.
Back to the table of contents.This document was originally written around gEDA/gaf 20030223, and the SPICE netlister spice-SDB. Starting with gEDA/gaf 20030525, my netlister was incorporated into the main gEDA distribution, and renamed spice-sdb (lower case sdb). For smoothest operation, you are best off just downloading and installing the latest version of gEDA. However, if you have a gEDA version predating 20030525, and you want to hack, you can download and install spice-SDB using the instructions provided on http://www.brorson.com/gEDA/SPICE/SPICEonLinux.html. In any event, it's a good idea to make sure that the file gnet-spice-sdb.scm is present in your scheme directory (usually ${prefix}/geda/share/gEDA/scheme) if you are interested in performing SPICE simulations with gEDA as described in this HOWTO.
Back to the table of contents.The detailed steps required to create a circuit and simulate it with gEDA look like this:
The SPICE netlister recognizes a particular symbol in two ways: 1. The symbol's "device" attribute, and 2. The symbol's refdes. Both of these attributes are attached to the symbol when the symbol is created.
Each symbol has a "device" attribute attached to it. The "device" attribute is the first thing the netlister examines when processing the symbol. There are a number of devices which are native to the netlister, meaning that the netlister knows exactly how to deal with these types of devices. Native device types include RESISTOR, CAPACITOR, NPN_TRANSISTOR, etc. The entire list of native devices is present in the appendix.
The "device" attribute is hidden during normal use of gschem. Most often, the symbol's creator has already given the symbol the correct "device" attribute. However, because the "device" attribute is hidden from the ordinary user, it can sometimes cause problems with SPICE netlist creation when it is set to an unexpected value. To view the "device" attribute, go into the symbol editor (select the symbol to edit, and do "Hierarchy" -> "down symbol"), and turn on invisible attributes (Edit -> show/hide inv text). If the "device" attribute is incorrect, you may change it by editing the symbol itself using a text editor.
If a symbol is not native (i.e. the netlister doesn't recognize it as a built-in type), the netlister relies upon the first letter of the refdes to determine how to process the symbol. The refdes prefix is also built into the symbol when it is created. Example refdes prefixes are R for resistors, C for capacitors, Q for transistors, etc. Refdes prefixes correct for SPICE are listed in the appendix. Note that relying upon the refdes to identify the component for SPICE is not foolproof -- for example, the netlister cannot distinguish between NPN and PNP transistors based upon the refdes. Therefore, it is always best to use a native "device" in your symbols.
Back to the table of contents.Files holding complicated SPICE models or other SPICE code may be incorporated into the final SPICE netlist by including appropriate symbols into the schematic. SPICE model files are usually obtained from component vendors. Dealing with these files is straightforward. However, some issues should be kept in mind when preparing models for use during schematic capture:
Please send comments or questions about this HOWTO to Stuart Brorson at sdb@cloud9.net.