1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./style.css" />
7 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./design.css" />
8 <link rel=
"stylesheet" media=
"print" type=
"text/css" href=
"./print.css" />
10 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
15 <h1 class=
"sectionedit36"><a name=
"circuit_simulation_using_geda_and_spice_-_howto" id=
"circuit_simulation_using_geda_and_spice_-_howto">Circuit Simulation using gEDA and SPICE - HOWTO
</a></h1>
20 Electroniscript, inc.
<br/>
21 sdb@electroniscript.com
<br/>
27 <strong>abstract
</strong><br/>
29 Linux will become an increasingly popular engineering platform in the future. Professional-quality CAD applications for circuit design are becoming available from programmers within the free-software community. For electronics, the gEDA suite is the preferred tool set for circuit design. Analog circuit simulation using SPICE is also now available on Linux. This HOWTO describes the design flow employed to perform SPICE simulations using gEDA tools on Linux.
33 Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version
2 or any later version published by the Free Software Foundation with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. You may obtain a copy of the GNU Free Documentation License from the Free Software Foundation by visiting their Web site (
<a href=
"http://www.fsf.org/" class=
"urlextern" title=
"http://www.fsf.org/" rel=
"nofollow">http://www.fsf.org/
</a>) by writing to: Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA
02110-
1301 USA.
<sup><a href=
"#fn__1" name=
"fnt__1" id=
"fnt__1" class=
"fn_top">1)
</a></sup>.
37 <!-- EDIT36 SECTION "Circuit Simulation using gEDA and SPICE - HOWTO" [1-1359] -->
38 <h2 class=
"sectionedit37"><a name=
"introduction" id=
"introduction">Introduction
</a></h2>
42 Modern engineering is a computer-intensive discipline. Like professionals in other engineering disciplines, electrical engineers and electronics designers are heavy users of all kinds of CAD software, including software for circuit design and simulation, as well as PCB and chip production. Electrical engineers have a special name for the CAD software they use: EDA, which stands for “Electronic Design Automation”. Under this rubric fall many different kinds of CAD software. For example, during the front-end stages of a design, an electrical engineer will use a program called a “schematic capture” package to enter his design into the computer. A schematic capture program is basically a specialized drawing program incorporating symbols used in creating a circuit design. After drawing his schematic, the electrical engineer may choose to simulate the behavior of his circuit in order to verify that his design will work as desired. The most popular program for this purpose is SPICE (Simulation Program with Integrated Circuit Emphasis), which was developed at Berkeley starting in the
1970s, and is widely available in multiple forms today. SPICE is now considered a fundamental engineering tool, and is an essential part of the repertoire of most practicing engineers.
46 The
<a href=
"http://www.geda.seul.org/" class=
"urlextern" title=
"http://www.geda.seul.org/" rel=
"nofollow">gEDA project
</a> is an open-source effort to create a
<acronym title=
"GNU General Public License">GPL
</acronym>'ed EDA suite running on Linux. GEDA has developed to the point where the power and quality of the tools is quite high; using the gEDA suite, you can now create complex SPICE netlists (files) incorporating vendor model files. You can then use various simulators running on Linux to perform SPICE simulations of your netlists. The purpose of this document is to explain how to use the gEDA tools (typically running on GNU/Linux) to perform SPICE simulations. In particular, this HOWTO documents the usage of
<strong>spice-sdb
</strong>, which is an advanced backend for the gEDA netlister (
<strong>gnetlist
</strong>) used to create SPICE netlists.
<strong>spice-sdb
</strong> is bundled with the gEDA tool suite; if you have installed gEDA, you are ready to create SPICE netlists. This HOWTO also provides advice about using ngspice/tclspice and/or LTSpice to simulate a circuit netlisted with
<strong>spice-sdb
</strong>.
50 <!-- EDIT37 SECTION "Introduction" [1360-3625] -->
51 <h3 class=
"sectionedit38"><a name=
"target_audience_for_this_howto" id=
"target_audience_for_this_howto">Target audience for this HOWTO
</a></h3>
55 This HOWTO is not a tutorial about circuit design or SPICE simulation. Rather, it is designed to help the practicing engineer begin using gEDA to perform SPICE simulations on the Linux platform. Therefore, 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 GNU/Linux operating system and its development environment. Finally, I assume that you have already installed gEDA, and know how to use it. If you need to come up to speed on any of these subjects, further information is available at the following websites:
58 <li class=
"level1"><div class=
"li"> The gEDA project:
<a href=
"http://www.geda.seul.org" class=
"urlextern" title=
"http://www.geda.seul.org" rel=
"nofollow">http://www.geda.seul.org
</a></div>
60 <li class=
"level1"><div class=
"li"> <a href=
"geda-faq-simulation.html" class=
"wikilink1" title=
"geda-faq-simulation.html">faq-simulation
</a></div>
62 <li class=
"level1"><div class=
"li"> SPICE3 syntax and commands:
<a href=
"http://newton.ex.ac.uk/teaching/CDHW/Electronics2/userguide/" class=
"urlextern" title=
"http://newton.ex.ac.uk/teaching/CDHW/Electronics2/userguide/" rel=
"nofollow">http://newton.ex.ac.uk/teaching/CDHW/Electronics2/userguide/
</a></div>
64 <li class=
"level1"><div class=
"li"> Ngspice:
<a href=
"http://ngspice.sourceforge.net/" class=
"urlextern" title=
"http://ngspice.sourceforge.net/" rel=
"nofollow">http://ngspice.sourceforge.net/
</a></div>
66 <li class=
"level1"><div class=
"li"> Tclspice:
<a href=
"http://tclspice.sourceforge.net/" class=
"urlextern" title=
"http://tclspice.sourceforge.net/" rel=
"nofollow">http://tclspice.sourceforge.net/
</a></div>
68 <li class=
"level1"><div class=
"li"> LTSpice:
<a href=
"http://www.linear.com/software/" class=
"urlextern" title=
"http://www.linear.com/software/" rel=
"nofollow">http://www.linear.com/software/
</a></div>
70 <li class=
"level1"><div class=
"li"> Spice on Linux resources:
<a href=
"http://www.brorson.com/gEDA/SPICE/" class=
"urlextern" title=
"http://www.brorson.com/gEDA/SPICE/" rel=
"nofollow">http://www.brorson.com/gEDA/SPICE/
</a></div>
72 <li class=
"level1"><div class=
"li"> Free Dog – The Free EDA Users Group:
<a href=
"http://www.freeedaug.org/" class=
"urlextern" title=
"http://www.freeedaug.org/" rel=
"nofollow">http://www.freeedaug.org/
</a></div>
74 <li class=
"level1"><div class=
"li"> Starting with gEDA – slightly out of date, but a great resource
<a href=
"http://www-mdp.eng.cam.ac.uk/CD/engapps/geda/starting_gEDA_long.pdf" class=
"urlextern" title=
"http://www-mdp.eng.cam.ac.uk/CD/engapps/geda/starting_gEDA_long.pdf" rel=
"nofollow">http://www-mdp.eng.cam.ac.uk/CD/engapps/geda/starting_gEDA_long.pdf
</a></div>
79 <!-- EDIT38 SECTION "Target audience for this HOWTO" [3626-4973] -->
80 <h3 class=
"sectionedit39"><a name=
"acknowledgements" id=
"acknowledgements">Acknowledgements
</a></h3>
84 This document does not live in isolation. Several active members of the free EDA community were instrumental in helping me to creat this HOWTO. First and foremost, Paolo Nenzi, the author of ngspice, took my original HOWTO and turned it into a Lyx document which I could then make a DocBook. Thanks, Paolo, for helping with this HOWTO, and more importantly, thanks for all the great work on ngspice! Also at the top of the list stands Ales Hvezda, who is the driving force behind the gEDA project. Without Ales, none of this would have been possible; his contribution of
<strong>gschem
</strong> is invaluable. Thanks, Ales, for creating gEDA and distributing it worldwide under the
<acronym title=
"GNU General Public License">GPL
</acronym> – you
've started a revolution! Stefan Jones deserves a deep thank-you for his work on tclspice, and his graceous support and integration efforts when I submitted patches to the tclspice project. I should also thank W. Kazubski and S. Gieltjes – they wrote the original SPICE netlisters upon which I based gnet-spice-sdb.scm. I also want to thank Ken Healy for contributing the netlist sorting patch, and Peter Kaiser for pushing me to include some features useful for chip simulation. Peter also deserves thanks for writing some of the device-oriented sections of this document. Finally, I should acknolwedge the contributions and suggestions I receive from readers of the geda-user e-mail list. The beauty of free software is that it encourages collaboration, which means that the end product is greater than what one individual could acheive alone.
88 <!-- EDIT39 SECTION "Acknowledgements" [4974-6528] -->
89 <h3 class=
"sectionedit40"><a name=
"the_big_picturethe_design_flow_in_geda" id=
"the_big_picturethe_design_flow_in_geda">The big picture: the design flow in gEDA
</a></h3>
93 In EDA, the concept of “design flow” is important. GEDA is a suite of tools used to do electronic design – it is not a single application. “Design flow” refers to the order in which you use the tools to acheive your goal. Depending upon whether you are doing analog or digital design, designing boards or chips, the type of files required by the manufacturer of your boards, and a number of other factors, you will use different tools from the gEDA suite to acheive your goal.
97 A flow diagram of the gEDA design flow is shown in the figure below. The diagram shows a simple flow suitable for designing, simulating, and laying out PC boards. As can be seen, the simulation activitiy (blue blocks) is a loop. That is, you create your design and simulate it repeatedly until it behaves according to your desired specifications.
98 <a href=
"media/geda/geda_flow.png" class=
"media" target=
"_blank" title=
"geda:geda_flow.png"><img src=
"media/geda/geda_flow.png" class=
"mediacenter" alt=
"" /></a>
99 The design flow used in gEDA. Shown under “simulation” are several different types of simulator available. In this HOWTO, we are interested only in the SPICE variants (e.g. ngspice, tclspice).
103 <!-- EDIT40 SECTION "The big picture: the design flow in gEDA" [6529-7625] -->
104 <h3 class=
"sectionedit41"><a name=
"overview_of_spice_usage_with_geda" id=
"overview_of_spice_usage_with_geda">Overview of SPICE usage with gEDA
</a></h3>
108 Conceptually, SPICE simulation in gEDA proceeds via the following steps:
111 <li class=
"level1"><div class=
"li"> Creation and gathering of schematic symbols and SPICE model files. Often, the SPICE model files are obtained from your component vendor. You can generally find most models by checking the component vendor
's website.
</div>
113 <li class=
"level1"><div class=
"li"> Schematic capture using symbols and SPICE models created in step
1.
</div>
115 <li class=
"level1"><div class=
"li"> Netlist generation from the schematic created in step
2.
</div>
117 <li class=
"level1"><div class=
"li"> SPICE simulation of the circuit described by the netlist created in step
3.
</div>
123 These steps are illustrated by the blue boxes in the flow diagram above.
127 To create a SPICE netlist, the netlister (
<strong>gnetlist
</strong>) 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:
130 <li class=
"level1"><div class=
"li"> The symbol itself, in the attribute, which is attached when the symbol is created, and is typically accessed through the symbol editor.
</div>
132 <li class=
"level1"><div class=
"li"> In attributes manually attached to the component during schematic capture using
<strong>gschem
</strong>.
</div>
138 Since there are two places the netlister looks for information,
<strong><em>you must make sure that the required information is available in both places
</em></strong>.
142 <!-- EDIT41 SECTION "Overview of SPICE usage with gEDA" [7626-8969] -->
143 <h3 class=
"sectionedit42"><a name=
"detailed_design_simulation_flow_summary" id=
"detailed_design_simulation_flow_summary">Detailed design/simulation flow summary
</a></h3>
147 The detailed steps required to design and simulate a circuit using gEDA look like this:
150 <li class=
"level1"><div class=
"li"> Schematic symbol creation with correct
<strong><code>device
</code></strong> attribute. (Usually, the symbols have already been created with the correct
<strong><code>device
</code></strong> attribute, but if you are having problems, it doesn
't hurt to check them.)
</div>
152 <li class=
"level1"><div class=
"li"> Schematic capture using
<strong>gschem
</strong>.
</div>
154 <li class=
"level1"><div class=
"li"> Assignment of SPICE attributes (
<strong><code>value
</code></strong>,
<strong><code>model
</code></strong>,
<strong><code>file
</code></strong>,
<strong><code>type
</code></strong>, , etc.) to components using
<strong>gschem
</strong> or
<strong>gattrib
</strong>.
</div>
156 <li class=
"level1"><div class=
"li"> Assignment of
<strong><code>refdes
</code></strong> using e.g.
<strong>refdes_renum
</strong>.
</div>
158 <li class=
"level1"><div class=
"li"> Creation of netlist using:
<strong><code>gnetlist -g spice-sdb
</code></strong></div>
160 <li class=
"level1"><div class=
"li"> Check netlist for correctness (manually open and inspect netlist).
</div>
162 <li class=
"level1"><div class=
"li"> Run spice using a simulator such as
<strong>LTSpice
</strong>,
<strong>ngspice
</strong>, or
<strong>tclspice
</strong>.
</div>
164 <li class=
"level1"><div class=
"li"> Plot/analyze results (often plotting/analysis tools are incorporated in the simulator).
</div>
166 <li class=
"level1"><div class=
"li"> If you are not happy with your circuit
's performance as revealed by simulation, go back to step
2, fix it using
<strong>gschem
</strong> and iterate.
</div>
172 The purpose of this HOWTO is to provide the detailed understanding necessary to successfully navigate this process.
176 <!-- EDIT42 SECTION "Detailed design/simulation flow summary" [8970-10149] -->
177 <h2 class=
"sectionedit43"><a name=
"preliminary_workpreparing_your_symbols_and_spice_files" id=
"preliminary_workpreparing_your_symbols_and_spice_files">Preliminary work: preparing your symbols and SPICE files
</a></h2>
181 When you create schematic symbols for inclusion into your schematic, you must make sure that certain built-in attributes are correctly configured. The steps outlined below are done by editing the symbol itself using the symbol editor in
<strong>gschem
</strong>, or by editing the symbol file itself using a text editor.
185 <!-- EDIT43 SECTION "Preliminary work: preparing your symbols and SPICE files" [10150-10528] -->
186 <h3 class=
"sectionedit44"><a name=
"configuring_your_symbols" id=
"configuring_your_symbols">Configuring your symbols
</a></h3>
191 <h4><a name=
"identifying_the_component_to_the_netlister" id=
"identifying_the_component_to_the_netlister">Identifying the component to the netlister
</a></h4>
195 The SPICE netlister can recognize any particular symbol in two ways:
198 <li class=
"level1"><div class=
"li"> The symbol
's
<strong><code>device
</code></strong> attribute, and
</div>
200 <li class=
"level1"><div class=
"li"> The symbol
's
<strong><code>refdes
</code></strong>.
</div>
206 Both of these attributes are attached to the symbol when the symbol is created.
210 Each symbol has a
<strong><code>device
</code></strong> attribute attached to it. The
<strong><code>device
</code></strong> 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
<strong>RESISTOR
</strong>,
<strong>CAPACITOR
</strong>,
<strong>NPN_TRANSISTOR
</strong>, etc. The entire list of native devices is present in
<a href=
"#appendix_a" title=
":geda:csygas.txt ↵" class=
"wikilink1">Appendix A
</a> - Native components and their attributes.
214 The
<strong><code>device
</code></strong> attribute is hidden during normal use of
<strong>gschem
</strong>. Most often, the symbol
's creator has already given the symbol the correct
<strong><code>device
</code></strong> attribute. However, because the
<strong><code>device
</code></strong> 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
<strong><code>device
</code></strong> attribute, go into the symbol editor (select the symbol to edit, and do
<strong><em>Hierarchy
</em></strong> →
<strong><em>down symbol
</em></strong>, and turn on invisible attributes (
<strong><em>Edit
</em></strong> →
<strong><em>show/hide inv text
</em></strong>). If the
<strong><code>device
</code></strong> attribute is incorrect, you may change it by editing the symbol itself using a text editor.
218 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
<strong><code>refdes
</code></strong> to determine how to process the symbol. The
<strong><code>refdes
</code></strong> prefix is also built into the symbol when it is created. Example
<strong><code>refdes
</code></strong> prefixes are
<strong>R
</strong> for resistors,
<strong>C
</strong> for capacitors,
<strong>Q
</strong> for transistors, etc.
<strong><code>refdes
</code></strong> prefixes correct for SPICE are listed in
<a href=
"#appendix_a" title=
":geda:csygas.txt ↵" class=
"wikilink1">Appendix A
</a> - Native components and their attributes. Note that relying upon the
<strong><code>refdes
</code></strong> to identify the component for SPICE is not foolproof – for example, the netlister cannot distinguish between NPN and PNP transistors based upon the
<strong><code>refdes
</code></strong>. Therefore, it is always best to use a native
<strong><code>device
</code></strong> in your symbols.
223 <h4><a name=
"setting_the_pin_order" id=
"setting_the_pin_order">Setting the pin order
</a></h4>
227 The netlister emits component pins in the order set by the
<strong><code>pinseq
</code></strong> attribute. Note that this is not the same as the physical pin location. To set the
<strong><code>pinseq
</code></strong> attribute, first determine the pin ordering you want. SPICE uses a specific pin order for many components, including diodes and transistors. For example, a bipolar transistor
's pins listed in CBE order. Another example: if your symbol is meant to represent an IC modeled with a vendor
's
<strong><code>.subckt
</code></strong>, the order of the connections to the subcircuit is set by the
<strong><code>.subckt
</code></strong> line in the file.
231 Once you know the order in which to emit the pins, simply set the
<strong><code>pinseq
</code></strong> attribute with the correct order for the part. This will ensure that the part
's pins are emitted in the correct order.
235 <!-- EDIT44 SECTION "Configuring your symbols" [10529-13605] -->
236 <h3 class=
"sectionedit45"><a name=
"configuring_your_spice_files" id=
"configuring_your_spice_files">Configuring your SPICE files
</a></h3>
240 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:
243 <li class=
"level1"><div class=
"li"> It is usually prudent to place these files into a dedicated directory distinct from the symbol directories.
</div>
245 <li class=
"level1"><div class=
"li"> <em>Make sure that the SPICE files pin assignments correctly correspond to the pins as defined in the component
's symbol!
</em> This is hard to over-emphasize. The order in which pins are listed in a .subckt file do not necessarily correspond to the physical pin ordering of the part. As described above, pins are emitted from the netlister in the order given by the
<strong><code>pinseq
</code></strong> attribute.
</div>
247 <li class=
"level1"><div class=
"li"> <em>Make sure that the last character in a SPICE model file is a carriage return.
</em> If no carriage return exists, then the next component listed in the netlist may be placed on the same line as the last line of the SPICE model file.
</div>
252 <!-- EDIT45 SECTION "Configuring your SPICE files" [13606-14752] -->
253 <h2 class=
"sectionedit46"><a name=
"creating_your_circuitschematic_capture" id=
"creating_your_circuitschematic_capture">Creating your circuit: schematic capture
</a></h2>
257 Schematic capture is the process by which one uses a special-purpose drawing program to draw a schematic diagram of the circuit under design. In the gEDA environment, the schematic capture program is called
<strong>gschem
</strong>. I assume you already know how to use
<strong>gschem
</strong>. If not, consult the documentation available at the gEDA website:
<a href=
"http://www.geda.seul.org/" class=
"urlextern" title=
"http://www.geda.seul.org/" rel=
"nofollow">http://www.geda.seul.org/
</a>. For the purposes of creating SPICE netlists, you must use
<strong>gschem
</strong> to attach attributes to components, and possibly also incorporate other SPICE directives into your netlist. After you are done with schematic capture, you create the SPICE netlist by running gEDA
's netlister
<strong>gnetlist
</strong> on your design.
261 <!-- EDIT46 SECTION "Creating your circuit: schematic capture" [14753-15476] -->
262 <h3 class=
"sectionedit47"><a name=
"gschem_attributes_for_spice_netlisting" id=
"gschem_attributes_for_spice_netlisting">Gschem attributes for spice netlisting
</a></h3>
266 There are several ways that spice attributes may be associated with a component using
<strong>gschem
</strong>. The way you choose to do this depends upon many factors, including the type of component, and the size and format of the SPICE model.
270 <!-- EDIT47 SECTION "Gschem attributes for spice netlisting" [15477-15758] -->
271 <h3 class=
"sectionedit48"><a name=
"component_attributes_and_meanings" id=
"component_attributes_and_meanings">Component attributes and meanings
</a></h3>
275 The following attributes are meaningful for SPICE netlisting, and may be attached from within
<strong>gschem
</strong>:
278 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong>: The reference designator of the component. Valid values depend upon the component type and are given in
<a href=
"#appendix_a" title=
":geda:csygas.txt ↵" class=
"wikilink1">Appendix A
</a> - Native components and their attributes.
</div>
280 <li class=
"level1"><div class=
"li"> <strong><code>value
</code></strong>: For passives, this is the component value. For actives, this is the type (model no.) of the component (e.g.
2N3904, uA741). When a model for an active is instantiated separately from the component itself, the
<strong><code>value
</code></strong> attribute holds the name of the spice model.
</div>
282 <li class=
"level1"><div class=
"li"> <strong><code>model
</code></strong>: This holds a one line spice model for the component.
</div>
284 <li class=
"level1"><div class=
"li"> <strong><code>file
</code></strong>: This holds the name of a file. Typically, this is a file holding e.g. a SPICE .MODEL, .SUBCKT, or other SPICE code.
</div>
286 <li class=
"level1"><div class=
"li"> <strong><code>model-name
</code></strong>: This holds the name of the spice model referred to in a .MODEL or .SUBCKT statement.
<strong><code>model-name
</code></strong> is mainly used to identify the spice model name in the symbol
<strong><code>spice-model-
1.sym
</code></strong>. Active components should call out this name in the
<strong><code>device
</code></strong> attribute to associate the component with its particular spice model or subcircuit.
</div>
288 <li class=
"level1"><div class=
"li"> <strong><code>type
</code></strong>: This specifies the type of component and is used by spice when interpreting the model parameters. Valid values depend upon the device being modeled.
</div>
293 <!-- EDIT48 SECTION "Component attributes and meanings" [15759-17118] -->
294 <h3 class=
"sectionedit49"><a name=
"refdes_conventions" id=
"refdes_conventions">refdes conventions
</a></h3>
298 As a prerequisite to handling SPICE-related attributes, the SPICE netlister requires that all components must have a
<strong><code>refdes
</code></strong> attached to them. The
<strong><code>refdes
</code></strong> may be attached either by hand (which is laborious), or using the program
<strong>refdes_renum
</strong> included in the gEDA distribution.
302 Note that the first letter of the
<strong><code>refdes
</code></strong> must correspond to the appropriate letter for spice simulation. The
<strong><code>refdes
</code></strong> convention is given in the appendix.
306 <!-- EDIT49 SECTION "refdes conventions" [17119-17613] -->
307 <h3 class=
"sectionedit50"><a name=
"passives" id=
"passives">Passives
</a></h3>
312 <h4><a name=
"basic_passives" id=
"basic_passives">Basic passives
</a></h4>
316 The most basic components which one encounters in SPICE are passive components like resistors and capacitors which have numeric values, but no other modeling attributes. In this case the following attributes must be filled in:
319 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong>: The correct
<strong><code>refdes
</code></strong> for the component.
</div>
321 <li class=
"level1"><div class=
"li"> <strong><code>value
</code></strong>: For passives, this is the numeric value of the component (e.g.
100pF). For actives, this attribute may be filled in, but if no model attribute is available elsewhere in the schematic, the value is not used (in SPICE netlisting, anyway).
</div>
323 <li class=
"level1"><div class=
"li"> If only a
<strong><code>refdes
</code></strong> and
<strong><code>value
</code></strong> attribute are encountered, the netlister will write a single line into the output file.
</div>
329 <h4><a name=
"example_resistor" id=
"example_resistor">Example resistor:
</a></h4>
332 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong> = R2
</div>
334 <li class=
"level1"><div class=
"li"> <strong><code>value
</code></strong> =
220</div>
340 SPICE line generated:
<strong><code>R2
0 4 220</code></strong>
344 (note that “
0” and “
4” correspond to the net nodes connected to the component, and are generated automatically by
<strong>gnetlist
</strong>.)
349 <h4><a name=
"example_capacitor" id=
"example_capacitor">Example capacitor:
</a></h4>
352 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong> = C22
</div>
354 <li class=
"level1"><div class=
"li"> <strong><code>value
</code></strong> =
1UF
</div>
360 SPICE line generated:
<strong><code>C22
4 23 1UF
</code></strong>
364 <!-- EDIT50 SECTION "Passives" [17614-18709] -->
365 <h3 class=
"sectionedit51"><a name=
"passives_with_additional_attributes" id=
"passives_with_additional_attributes">Passives with additional attributes
</a></h3>
369 Oftentimes, passive components have additional attributes attached to them for spice simulation. Examples of such attributes are temperature coefficients (for resistors) and initial conditions (for reactive components). These additional components may be incorporated into the SPICE file by simply attaching them to the component
's
<strong><code>model
</code></strong> attribute. Specifically, the required attributes are:
372 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong>: Correct component
<strong><code>refdes
</code></strong>.
</div>
374 <li class=
"level1"><div class=
"li"> <strong><code>value
</code></strong>: Numerical component
<strong><code>value
</code></strong>, as always.
</div>
376 <li class=
"level1"><div class=
"li"> <strong><code>model
</code></strong>: One line string holding additional parameters, formatted as a valid SPICE string.
</div>
382 This string is placed after the component value in the line generated by gnetlist. Therefore, it is important to format the string placed in the
<strong><code>model
</code></strong> line to be valid SPICE code. Otherwise, you will risk causing the SPICE simulator to barf.
387 <h4><a name=
"example_resistor1" id=
"example_resistor1">Example resistor:
</a></h4>
390 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong> = R5
</div>
392 <li class=
"level1"><div class=
"li"> <strong><code>value
</code></strong> =
1MEG
</div>
394 <li class=
"level1"><div class=
"li"> <strong><code>model
</code></strong> = TC=
0.001,
0.015</div>
400 SPICE line generated:
<strong><code>R2
0 4 220 TC=
0.001,
0.015</code></strong>
404 <!-- EDIT51 SECTION "Passives with additional attributes" [18710-19795] -->
405 <h3 class=
"sectionedit52"><a name=
"passives_for_semiconductor_design" id=
"passives_for_semiconductor_design">Passives for semiconductor design
</a></h3>
409 The values for resistors and capacitors are often given as dimensions in an ASIC design. SPICE takes from the technology library the typical value per square and calculates the actual value in Ohm or Farad by itself. Therefor the following attributes are required:
412 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong>: The correct refdes for the component.
</div>
414 <li class=
"level1"><div class=
"li"> <strong><code>model-name
</code></strong>: corresponds to the model in the technology library.
</div>
416 <li class=
"level1"><div class=
"li"> <strong><code>w
</code></strong>,
<strong><code>l
</code></strong>: dimensions of the device.
</div>
422 The technology library must be included with an
<strong><code>.include
</code></strong> line in the SPICE input file.
427 <h4><a name=
"example_semiconductor_resistor" id=
"example_semiconductor_resistor">Example semiconductor resistor:
</a></h4>
430 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong> = R6
</div>
432 <li class=
"level1"><div class=
"li"> <strong><code>model-name
</code></strong> = rpoly
</div>
434 <li class=
"level1"><div class=
"li"> <strong><code>w
</code></strong> =
3u</div>
436 <li class=
"level1"><div class=
"li"> <strong><code>l
</code></strong> =
100u</div>
442 SPICE line generated:
<strong><code>R6
0 5 rpoly w=
3u l=
100u</code></strong>
447 <h4><a name=
"example_semiconductor_resistor_model" id=
"example_semiconductor_resistor_model">Example semiconductor resistor model:
</a></h4>
450 <li class=
"level1"><div class=
"li"> model rpoly R rsh=
300</div>
456 This should be part of the technology library from your ASIC vendor.
460 <!-- EDIT52 SECTION "Passives for semiconductor design" [19796-20722] -->
461 <h3 class=
"sectionedit53"><a name=
"transistors_and_diodes" id=
"transistors_and_diodes">Transistors and diodes
</a></h3>
465 Transistors and diodes are generally accompanied by a device-specific model. Each model attempts to capture the detailed nonlinear dynamics of its particular device; otherwise, SPICE simulation is pointless. The SPICE model may be either a short, one-line string of parameters, or a multi-line set of SPICE parameters. A typical one-line parameter string is a short list of parameters describing a small-signal diode. Typical multi-line models come from component vendors, who often provide models for their components in a text file. Since there are two broad formats of SPICE information, there are two approaches to incorporating these parameters into the schematic:
470 <h4><a name=
"one_line_string_of_spice_parameters" id=
"one_line_string_of_spice_parameters">One line string of SPICE parameters
</a></h4>
474 To incorporate a one line string of SPICE parameters into the netlist, the following attributes must be attached to the component:
477 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong>: Correct component
<strong><code>refdes
</code></strong>.
</div>
479 <li class=
"level1"><div class=
"li"> <strong><code>value
</code></strong>: The model number or part number of the component.
</div>
481 <li class=
"level1"><div class=
"li"> <strong><code>model-name
</code></strong>: The name you wish to give the SPICE model. This is usually the model number or part number of the component. If you have already attached a
<strong><code>value
</code></strong> attribute to the component, this parameter is optional.
</div>
483 <li class=
"level1"><div class=
"li"> <strong><code>model
</code></strong>: One line string holding additional parameters. Do not place the model parameters in parentheses –
<strong>gnetlist
</strong> will do this for you.
</div>
489 <h4><a name=
"example_diode" id=
"example_diode">Example diode:
</a></h4>
492 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong> = D5
</div>
494 <li class=
"level1"><div class=
"li"> <strong><code>model-name
</code></strong> =
1N1004
</div>
496 <li class=
"level1"><div class=
"li"> <strong><code>model
</code></strong> = IS=
0.5UA RS=
6 BV=
5.20</div>
502 SPICE lines generated:
<strong><code>D5
2 6 1N1004 MODEL
1N1004 D (IS=
0.5UA RS=
6 BV=
5.20)
</code></strong>
507 <h4><a name=
"spice_model_file" id=
"spice_model_file">SPICE model file
</a></h4>
511 To incorporate a file-full of SPICE parameters into the netlist, the following attributes must be attached to the component:
514 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong>: Correct component
<strong><code>refdes
</code></strong>.
</div>
516 <li class=
"level1"><div class=
"li"> <strong><code>value
</code></strong>: The model number or part number of the component.
</div>
518 <li class=
"level1"><div class=
"li"> <strong><code>model-name
</code></strong>: the name you wish to give the SPICE model. This is usually the model number or part number of the component. If you have already attached a
<strong><code>value
</code></strong> attribute to the component, this parameter is optional.
</div>
520 <li class=
"level1"><div class=
"li"> <strong><code>file
</code></strong>: The file name of the SPICE model which you wish to incorporate into the netlist. This file name may specify either a relative or an absolute path, but it is probably better to use an absolute path to avoid problems if you ever move your schematic directory.
</div>
526 Note that you need to make sure that the model name held in your SPICE model file is the same as the
<strong><code>value
</code></strong> or
<strong><code>model-name
</code></strong> attributes you attached to the component. It is also a good idea to verify that the pin assignments in the model file correspond to the pin assignments made by the component symbol.
530 <!-- EDIT53 SECTION "Transistors and diodes" [20723-23423] -->
531 <h3 class=
"sectionedit54"><a name=
"actives_--_integrated_circuits" id=
"actives_--_integrated_circuits">Actives -- integrated circuits
</a></h3>
535 Integrated circuits are incorporated into the netlist similarly to transistors and diodes. As such, you may incorporate the spice information either as a one-line parameter string, or as a model file.
540 <h4><a name=
"one_line_string_of_spice_parameters1" id=
"one_line_string_of_spice_parameters1">One line string of SPICE parameters
</a></h4>
544 To incorporate a one line string of SPICE parameters into the netlist, the following attributes must be attached to the component:
547 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong>: Correct component
<strong><code>refdes
</code></strong>.
</div>
549 <li class=
"level1"><div class=
"li"> <strong><code>value
</code></strong>: The model number or part number of the component.
</div>
551 <li class=
"level1"><div class=
"li"> <strong><code>model-name
</code></strong>: the name you wish to give the SPICE model. This is usually the model number or part number of the component. If you have already attached a
<strong><code>value
</code></strong> attribute to the component, this parameter is optional.
</div>
553 <li class=
"level1"><div class=
"li"> <strong><code>model
</code></strong>: One line string holding additional parameters. Do not place the model parameters in parentheses –
<strong>gnetlist
</strong> will do this for you.
</div>
559 <h4><a name=
"spice_model_or_subckt_file" id=
"spice_model_or_subckt_file">SPICE .MODEL or .SUBCKT file
</a></h4>
563 To incorporate a file-full of SPICE parameters into the netlist, the following attributes must be attached to the component:
566 <li class=
"level1"><div class=
"li"> <strong><code>refdes
</code></strong>: Correct component
<strong><code>refdes
</code></strong>.
<em>Note that if the file holds a .MODEL, the
</em> <strong><code>refdes
</code></strong> <em>should start with U; if the file holds a .SUBCKT, the refdes should start with X.
</em> The netlister checks for the file type and tries to “do the right thing”, but problems can arise if you don
't follow this rule.
</div>
568 <li class=
"level1"><div class=
"li"> <strong><code>value
</code></strong>: The model number or part number of the component.
</div>
570 <li class=
"level1"><div class=
"li"> <strong><code>model-name
</code></strong>: The name you wish to give the SPICE model. This is usually the model number or part number of the component. If you have already attached a
<strong><code>value
</code></strong> attribute to the component, this parameter is optional.
</div>
572 <li class=
"level1"><div class=
"li"> <strong><code>file
</code></strong>: The name of the file holding the SPICE .MODEL or .SUBCKT which you wish to incorporate into the netlist. This file name may specify either a relative or an absolute path, but it is probably better to use an absolute path to avoid problems if you ever move your schematic directory.
</div>
578 Note that you need to make sure that the model name held in your SPICE model file is the same as the
<strong><code>value
</code></strong> or
<strong><code>model-name
</code></strong> attributes you attached to the component. It is also a good idea to verify that the pin assignments in the model file correspond to the pin assignments made by the component symbol.
582 <!-- EDIT54 SECTION "Actives -- integrated circuits" [23424-25767] -->
583 <h3 class=
"sectionedit55"><a name=
"independent_sources" id=
"independent_sources">Independent sources
</a></h3>
587 There are two independent sources: voltage sources and current sources. For incorporation into a SPICE netlist, they both work the same way. To incorporate an independent source into your SPICE netlist, do the following:
590 <li class=
"level1"><div class=
"li"> Place the independent source on your schematic. (Do
<strong><em>Add
</em></strong> →
<strong><em>Component
</em></strong> →
<strong><em>spice
</em></strong> →
<strong><independent source name
>.sym
</strong>)
</div>
592 <li class=
"level1"><div class=
"li"> Double click on the block and add/edit the following attributes:
</div>
594 <li class=
"level2"><div class=
"li"> <strong><code>refdes
</code></strong>: V? or I?
</div>
596 <li class=
"level2"><div class=
"li"> <strong><code>value
</code></strong>: A one line string in SPICE format describing the source.
</div>
603 <!-- EDIT55 SECTION "Independent sources" [25768-26341] -->
604 <h3 class=
"sectionedit56"><a name=
"dependent_sources" id=
"dependent_sources">Dependent sources
</a></h3>
608 There are four dependent sources:
612 This section remains TBD.
616 <!-- EDIT56 SECTION "Dependent sources" [26342-26431] -->
617 <h3 class=
"sectionedit57"><a name=
"spice_components" id=
"spice_components">SPICE components
</a></h3>
622 <h4><a name=
"spice_model_block" id=
"spice_model_block">Spice model block
</a></h4>
626 In certain situations, you may wish to embed a spice model block directly into your schematic.
627 This is done when you have several devices with a “value” attribute calling out for a spice model. Depending upon whether the spice block is one line or multi-line, you may embed the code in one of two ways:
632 <h4><a name=
"one_line_spice_model" id=
"one_line_spice_model">One line SPICE model:
</a></h4>
635 <li class=
"level1"><div class=
"li"> Place a spice model block on your schematic. (Do
<strong><em>Add
</em></strong> →
<strong><em>Component
</em></strong> →
<strong><em>spice
</em></strong> →
<strong>spice-model-
1.sym
</strong>)
</div>
637 <li class=
"level1"><div class=
"li"> Double click on the block and add/edit the following attributes:
</div>
639 <li class=
"level2"><div class=
"li"> <strong><code>refdes
</code></strong>: A?
</div>
641 <li class=
"level2"><div class=
"li"> <strong><code>model
</code></strong>: model name (i.e. the model name used in the components being modeled)
</div>
643 <li class=
"level2"><div class=
"li"> <strong><code>type
</code></strong>: One of the valid spice component types defined in the spice
<acronym title=
"specification">spec
</acronym>.
</div>
645 <li class=
"level2"><div class=
"li"> <strong><code>value
</code></strong>: The corresponding one-line spice model
</div>
653 <h4><a name=
"multi-line_spice_model" id=
"multi-line_spice_model">Multi-line SPICE model:
</a></h4>
656 <li class=
"level1"><div class=
"li"> Place a spice model block on your schematic.(Do
<strong><em>Add
</em></strong> →
<strong><em>Component
</em></strong> →
<strong><em>spice
</em></strong> →
<strong>spice-model-
1.sym
</strong>)
</div>
658 <li class=
"level1"><div class=
"li"> Double click on the block and add/edit the following attributes:
</div>
660 <li class=
"level2"><div class=
"li"> <strong><code>refdes
</code></strong>: A?
</div>
662 <li class=
"level2"><div class=
"li"> <strong><code>model
</code></strong>: model name
</div>
664 <li class=
"level2"><div class=
"li"> <strong><code>file
</code></strong>: Name of file holding SPICE model code (i.e. .MODEL or .SUBCKT).
</div>
672 <h4><a name=
"include_block" id=
"include_block">Include block
</a></h4>
676 The include block places a .INCLUDE directive into your netlist.
679 <li class=
"level1"><div class=
"li"> Place a spice model block on your schematic. (Do
<strong><em>Add
</em></strong> →
<strong><em>Component
</em></strong> →
<strong><em>spice
</em></strong> →
<strong>spice-include-
1.sym
</strong>)
</div>
681 <li class=
"level1"><div class=
"li"> Double click on the block and add/edit the following attributes:
</div>
683 <li class=
"level2"><div class=
"li"> <strong><code>refdes
</code></strong>: A?
</div>
685 <li class=
"level2"><div class=
"li"> <strong><code>file
</code></strong>: Name of file to include.
</div>
693 <h4><a name=
"spice_directive_block" id=
"spice_directive_block">SPICE directive block
</a></h4>
697 Placing a SPICE directive block into your schematic creates an arbitrary block of SPICE code in the netlist. The directive may be either statements held in a file, or a one-line string held in the
<strong><code>model
</code></strong> attribute. The netlister will simply dump the contents of the string or the file into your netlist verbatim. Examples of situations where this is useful include:
700 <li class=
"level1"><div class=
"li"> .TEMP statement
</div>
702 <li class=
"level1"><div class=
"li"> .IC statement
</div>
704 <li class=
"level1"><div class=
"li"> Other SPICE statements for which
<strong>gschem
</strong> has no symbol.
</div>
710 To place a SPICE directive on your schematic, do:
713 <li class=
"level1"><div class=
"li"> Place a SPICE directive block on your schematic. (Do
<strong><em>Add
</em></strong> →
<strong><em>Component
</em></strong> →
<strong><em>spice
</em></strong> →
<strong>spice-directive-
1.sym
</strong>)
</div>
715 <li class=
"level1"><div class=
"li"> Double click on the block and add/edit the following attributes:
</div>
717 <li class=
"level2"><div class=
"li"> <strong><code>refdes
</code></strong>: A?
</div>
719 <li class=
"level2"><div class=
"li"> <strong><code>file
</code></strong>: Name of file to include.
</div>
726 <!-- EDIT57 SECTION "SPICE components" [26432-28841] -->
727 <h3 class=
"sectionedit58"><a name=
"handling_hierarchical_models" id=
"handling_hierarchical_models">Handling hierarchical models
</a></h3>
731 In SPICE modeling, there are often situations where you wish to create a schematic representation of some particular component as a .SUBCKT, and then embed that component
's model in a higher level schematic. A common example might be as follows: You are doing a microwave simulation, and want to use a capacitor model which includes parasitic inductances and resistances, as well as the capacitance. Capacitor manufacturers often supply a printed schematic showing a circuit topology incorporating parasitics, and specify values for the parasitics. You would like to draw the capacitor model using gschem, netlist it to create a .SUBCKT, and then use the .SUBCKT to model capacitors in a higher lever schematic.
735 Since this kind of task is very common in SPICE simulation,
<strong>gnet-spice-sdb
</strong> now supports it (starting with rev
20030331). To create a lower level .SUBCKT and use it in a higher level schematic, do the following:
738 <li class=
"level1"><div class=
"li"> Draw the schematic of the lower level component (e.g. the capacitor + parasitics) using
<strong>gschem
</strong>.
</div>
740 <li class=
"level1"><div class=
"li"> On the lower level schematic, place a
<strong><code>spice-subcircuit-LL
</code></strong> block (
<strong>spice-subcircuit-LL-
1.sym
</strong>). This alerts the netlister that the schematic is a Lower Level .SUBCKT. Attach the following attributes to the symbol:
<br/>
742 *
<strong><code>model-name
</code></strong> = cap_with_parasitics
<br/>
744 (Of course, “cap_with_parasitics” is the example we use here. Use your own model name in your schematic.) Upon netlisting, this schematic symbol will cause the netlist to insert ”.SUBCKT cap_with_parasitics” into the first line of the netlist file.
</div>
746 <li class=
"level1"><div class=
"li"> On the lower level schematic, attach a
<strong><code>spice-subcircuit-IO
</code></strong> symbol (
<strong>spice-subcircuit-IO-
1.sym
</strong>) to each IO net (i.e. connection to the upper level). Number the refdeses of the IO symbols in the same order as you would like the IO nets to be listed in the .SUBCKT line in the output file. (i.e. P1 = first, P2 = second, etc.)
</div>
748 <li class=
"level1"><div class=
"li"> When you are done with the lower level schematic, netlist it in the usual way. For example, if your schematic is called
<strong><code>cap_with_parasitics.sch
</code></strong>, netlist it by saying:
<br/>
750 <strong><code>gnetlist -g spice-sdb -o cap_with_parasitics.cir cap_with_parasitics.sch
</code></strong><br/>
752 This will dump the SPICE netlist into the file called “
<strong>cap_with_parasitics.cir
</strong>”. Visually inspect the .cir file to make sure that netlisting worked correctly.
</div>
754 <li class=
"level1"><div class=
"li"> Next, create a symbol for the upper level schematic which will point to the .SUBCKT. Note that the symbol must have a starting with the letter “X”. To ensure that this happens, do the following:
</div>
756 <li class=
"level2"><div class=
"li"> Use
<strong>gschem
</strong> to draw the symbol. I usually draw a box around a model symbol to distinguish it from a normal component. Make any other annotations desired.
</div>
758 <li class=
"level2"><div class=
"li"> In the symbol, make sure that the pins are ordered identically to the order in which you have placed the pins in the .SUBCKT. This is done by editing the symbol with a text editor and setting the
<strong><code>pinseq
</code></strong> attribute. The netlister will output the pins in the order determined by the
<strong><code>pinseq
</code></strong> attribute.
</div>
760 <li class=
"level2"><div class=
"li"> Using a text editor, give the symbol a
<strong><code>device
</code></strong> attribute like “capacitor-model”. Do
<strong>not
</strong> assign the symbol one of the native device types listed in the appendix! The goal is to create a symbol whose
<strong><code>refdes
</code></strong> starts with “X”, and if the
<strong><code>device
</code></strong> is a recognized type, this will not happen.
</div>
762 <li class=
"level2"><div class=
"li"> Using a text editor, give the symbol the
<strong><code>refdefs
</code></strong> attribute “X?”
</div>
766 <li class=
"level1"><div class=
"li"> Create the upper level schematic. Place your newly created symbol on the schematic as many times as required and wire up the schematic in the usual way.
</div>
768 <li class=
"level1"><div class=
"li"> To point your symbol to the lower level .SUBCKT, double click on the symbol and set the following attributes:
<br/>
770 *
<strong><code>file
</code></strong> = cap_with_parasitics.cir
<br/>
771 *
<strong><code>model-name
</code></strong> = cap_with_parasitics
<br/>
773 as well as any other attributes required (e.g.
<strong><code>refdes
</code></strong>).
</div>
775 <li class=
"level1"><div class=
"li"> Now netlist your upper level schematic the usual way. The contents of each .SUBCKT file is dumped into the main netlist. Inspect your netlist visually using a text editor to ensure that it is correct. It is a good idea to pay particular attention to the following:
</div>
777 <li class=
"level2"><div class=
"li"> Verify that the ordering of the nets connecting the upper level netlist to the lower level .SUBCKT is correct.
</div>
779 <li class=
"level2"><div class=
"li"> Make sure that the upper level model-name and the lower level model name (on the .SUBCKT declaration line) are the same.
</div>
787 Once the netlist is created, you may simulate your design using any SPICE simulator desired. Some simulators running on Linux are covered below.
791 <!-- EDIT58 SECTION "Handling hierarchical models" [28842-33382] -->
792 <h2 class=
"sectionedit59"><a name=
"spice_netlist_generation" id=
"spice_netlist_generation">SPICE netlist generation
</a></h2>
796 <!-- EDIT59 SECTION "SPICE netlist generation" [33383-33419] -->
797 <h3 class=
"sectionedit60"><a name=
"using_gnetlist" id=
"using_gnetlist">Using gnetlist
</a></h3>
801 Once the schematic is captured, a SPICE netlist can be generated running gEDA
's command-line program
<strong>gnetlist
</strong> on the schematic files.
<strong>gnetlist
</strong> is architected in two sections: a front-end processor written in C which reads in the .sch file and creates from it an internal, generic representation of your design, and a back-end netlister written in SCHEME. Using this architecture,
<strong>gnetlist
</strong> is highly customizable; different SCHEME backends are used to write out different netlist formats. The beauty of this scheme (pun intended) is that gEDA users can easily write their own netlisters to suit their own applications. The back-end Scheme file which implements advanced SPICE netlisting is called
<strong><code>gnet-spice-sdb.scm
</code></strong>, and it lives in the
<strong><code>${PREFIX}/geda/share/gEDA/scheme
</code></strong> directory.
805 <strong>gnetlist
</strong> with
<strong>spice-sdb
</strong> is invoked from the command line in the following way:
<strong><code>gnetlist [OPTIONS] -g spice-sdb filename1 … filenameN
</code></strong>. The following command-line options are available with spice-sdb:
808 <pre class=
"code">-i Interactive scheme mode
809 -I Put .INCLUDE
<filename
> in output file instead of model file
's contents
811 -l filename Load scheme file before loading backend
812 -m filename Load scheme file after loading backend, but still before executing procedure
813 -g proc Scheme procedure to execute (i.e. spice-sdb)
814 -o filename Output netlist filename
815 -c string Execute string as a scheme script
817 -s Sort output netlist (for Gnucap)
</pre>
820 <!-- EDIT60 SECTION "Using gnetlist" [33420-34980] -->
821 <h3 class=
"sectionedit61"><a name=
"creating_the_netlist_using_gnetlist_and_spice-sdb" id=
"creating_the_netlist_using_gnetlist_and_spice-sdb">Creating the netlist using gnetlist and spice-sdb
</a></h3>
825 Creating a netlist from a schematic is easy. To generate a SPICE netlist, just do the following:
828 <li class=
"level1"><div class=
"li"> Save your schematic to
<<strong><code>filename.sch
</code></strong>></div>
830 <li class=
"level1"><div class=
"li"> Create the SPICE netlist by doing “
<strong><code>gnetlist -g spice-sdb
<filename.sch
></code></strong>”. The output is a netlist held in the file
<strong><code>output.net
</code></strong>. Alternatively, if you wish to give your output file a different name, set the output name using the
<strong>-o
</strong> switch. For example:
<br/>
832 <strong><code>gnetlist -g spice-sdb -o amplifier.cir amplifier.sch
</code></strong><br/>
834 takes the design schematic called “
<strong><code>amplifier.sch
</code></strong>” and outputs a SPICE netlist named “
<strong><code>amplifier.cir
</code></strong>”.
</div>
836 <li class=
"level1"><div class=
"li"> Inspect your SPICE netlist using a text editor. Verify that there are no missing attributes or other netlist problems.
</div>
841 <!-- EDIT61 SECTION "Creating the netlist using gnetlist and spice-sdb" [34981-35774] -->
842 <h3 class=
"sectionedit62"><a name=
"common_netlisting_problems" id=
"common_netlisting_problems">Common netlisting problems
</a></h3>
846 The following list attempts to catalog common problems with the netlist and the associated fixes:
849 <li class=
"level1"><div class=
"li"> ERROR_INVALID_
<acronym title=
"Personal Identification Number">PIN
</acronym>:
<br/>
850 This can happen if the symbol
's
<strong><code>pinseq
</code></strong> attributes don
't start at
1, or have gaps in the numbering. This must be fixed by editing the symbol itself in a text editor.
</div>
852 <li class=
"level1"><div class=
"li"> ERROR: In procedure caddr:
<br/>
853 This error is quite common. It usually occurs when you forget to add a mandatory attribute. To rectify the problem, try running gnetlist in verbose mode (
<strong><code>gnetlist -v -g spice-sdb
<filename.sch
></code></strong>). The netlister will stop processing and bomb out at the part with the missing attribute. Having therefore identified the offending part, you can re-open the schematic in gnetlist and fix the attributes.
</div>
859 Finally, remember that it is important to manually inspect your SPICE netlist prior to using it in simulation. Please keep in mind that the netlister is still “beta” quality, and some problems may still exist in netlist generation.
863 <!-- EDIT62 SECTION "Common netlisting problems" [35775-36780] -->
864 <h2 class=
"sectionedit63"><a name=
"spice_simulation" id=
"spice_simulation">SPICE simulation
</a></h2>
868 There are several options for doing SPICE simulations under GNU/Linux; I will highlight three:
871 <li class=
"level1"><div class=
"li"> <strong>LTSpice
</strong>, which is a freeware SPICE simulator originally released by Linear Technologies as a component selection/design tool running under Windows. Because its SPICE engine is very fast and powerful, it has become a popular SPICE simulator amongst hobbyists and design engineers who prefer to use free tools. Originally written for Windows, LTSpice has been tweaked to run under GNU/Linux using wine; I recommend using it if you need a robust, professional-quality SPICE simulator.
</div>
873 <li class=
"level1"><div class=
"li"> <strong>Ngspice
</strong>, which is the “official” SPICE simulator of the gEDA suite. Ngspice is a revival of the SPICE
3 code for Linux. It provides a simulation engine, a command-line driven front-end, and the capability to plot simulation results graphically under the X Windows System. Ngspice is Linux-native and open-source. It is the SPICE of choice for those who want to do SPICE simulations easily on Linux, or want to hack and improve SPICE
's internals.
</div>
875 <li class=
"level1"><div class=
"li"> <strong>Tclspice
</strong>, is a fork off the ngspice development path. Tclspice is a superset of ngspice which (in theory) exports the SPICE command set to a TCL
<acronym title=
"Application Programming Interface">API
</acronym>, allowing you to embed SPICE analyses into a TCL program. This is useful for automating a design optimization, amongst other things. Tclspice is the simulator to use if you are interested in advanced, scripted design.
</div>
881 There is also a
<acronym title=
"GNU General Public License">GPL
</acronym>'ed simulator called
<strong>gnucap
</strong>, which is based upon (or is the descendant of) Al
's Circuit Simulator (
<strong><code>ACS
</code></strong>). I haven
't used it very much; information about gnucap is therefore TBD.
885 <!-- EDIT63 SECTION "SPICE simulation" [36781-38433] -->
886 <h3 class=
"sectionedit64"><a name=
"ltspice" id=
"ltspice">LTSpice
</a></h3>
890 LTSpice was written by Mike Englehardt and others at Linear Technologies, and is given away by LinearTech as a design aid for engineers wishing to simulate the performance of LinearTech
's switch mode power supply controllers. The package incorporates a schematic capture front end, fast and powerful SPICE engine, and the capability for plotting the results of many different types of SPICE analysis. Personally, I think the schematic capture front-end is hard to use and clunky;
<strong>gschem
</strong> knocks its socks off for ease of use and features. However, the SPICE engine and analysis stuff in LTSpice is simply great.
894 LTSpice was originally developed to run under Windows, but Mike has tweaked it so that it runs fairly well on GNU/Linux under wine. (Only the help menu system is broken – the rest of the package runs well). Another good feature of LTSpice is that it is well supported – Mike reads the newsgroup
<strong><code>sci.electronics.cad
</code></strong> regularly and is generally happy to help people who experience problems with it. Therefore, despite its Windoze heritage, I recommend LTSpice as a powerful, professional-quality simulation and analysis back end for gEDA.
899 <h4><a name=
"installation_and_configuration_of_ltspice" id=
"installation_and_configuration_of_ltspice">Installation and configuration of LTSpice
</a></h4>
903 To install and configure LTSpice, do the following:
906 <li class=
"level1"><div class=
"li"> Download and install wine. I have had success using Wine-
20030219. Later versions probably also work.
</div>
908 <li class=
"level1"><div class=
"li"> Download LTSpice. It is available under
<a href=
"http://www.linear.com/software" class=
"urlextern" title=
"http://www.linear.com/software" rel=
"nofollow">http://www.linear.com/software
</a> under the name SwitcherCAD-III.
</div>
910 <li class=
"level1"><div class=
"li"> Run the LTSpice installer under wine.
</div>
916 <h4><a name=
"running_ltspice_with_geda_designs" id=
"running_ltspice_with_geda_designs">Running LTSpice with gEDA designs
</a></h4>
920 LTSpice can read a file holding a gEDA SPICE netlist. I have had success doing LTSpice simulations in the following way:
923 <li class=
"level1"><div class=
"li"> First of all, make sure that you are logged in as a normal user – Wine doesn
't like to run when invoked by root.
</div>
925 <li class=
"level1"><div class=
"li"> Create a file in your project directory called “Simulation.cmd”. In this file place your spice analysis commands (e.g. .OP, .AC, .DC, etc.)
</div>
927 <li class=
"level1"><div class=
"li"> Place a SPICE include block into your schematic. For the file attribute, type in “Simulation.cmd”.
</div>
929 <li class=
"level1"><div class=
"li"> Netlist your design.
</div>
931 <li class=
"level1"><div class=
"li"> Create a link from your netlist
<strong><code>output.net
</code></strong> and a netlist in the directory in which SwCADIII lives. Make the netlist suffix
<strong><code>.cir
</code></strong>. For example:
<br/>
933 ln -s ${DESIGN_HOME}/output.net ${WINE_HOME}/.wine/fake_windows/Program Files/LTC/SwCADIII/MyDesign.cir
<br/>
937 <li class=
"level1"><div class=
"li"> Run LTSpice: cd into the directory where SwCADIII lives and say “
<strong><code>wine scad3.exe
</code></strong>”
</div>
939 <li class=
"level1"><div class=
"li"> From the SwCADIII
<acronym title=
"Graphical User Interface">GUI
</acronym>, do:
<strong><em>File
</em></strong> →
<strong><em>Open
</em></strong> →
<strong><em>(files of type netlist [.cir])
</em></strong>, and select your file.
</div>
941 <li class=
"level1"><div class=
"li"> Run the simulator by clicking on the run button, or doing:
<strong><em>Simulate
</em></strong> →
<strong><em>Run
</em></strong>.
</div>
943 <li class=
"level1"><div class=
"li"> Select the variables to graph, and then click OK. SwCADIII does the rest of the work.
</div>
949 Naturally, it is very important to play around with LTSpice to understand how to use it effectively, but the above description should suffice to get you started.
953 <!-- EDIT64 SECTION "LTSpice" [38434-41373] -->
954 <h3 class=
"sectionedit65"><a name=
"ngspice" id=
"ngspice">Ngspice
</a></h3>
958 Ngspice was started at the University of Rome “La Sapienza” by Paolo Nenzi as an attempt to create a
<acronym title=
"GNU General Public License">GPL
</acronym>'ed version of the standard Berkeley SPICE version
3 by re-writing the entire SPICE package. Plans were also laid to create better, more robust computational algorithms for the simulation engine. More information is available at the ngspice website:
<a href=
"http://ngspice.sourceforge.net/" class=
"urlextern" title=
"http://ngspice.sourceforge.net/" rel=
"nofollow">http://ngspice.sourceforge.net/
</a>. In light of his lofty plans, what Paolo did, however, was a little different: He took the SPICE
3 code which had been floating around the internet for many years, refactored it, and hacked the build system so that it would compile using the normal GNU make procedure. This was a major achievement for which Paolo deserves great praise. Unfortunately, from the look of the webpage, development on
<strong>ngspice
</strong> seems to have ceased at the end of
2001. Indeed, development did slow down considerably after
2001, but recently Paolo has been working on
<strong>ngspice
</strong> again. He released the latest version,
<strong>ngspice-rework-
15</strong>, in February
2004. This version is available only on the Sourceforge download page; Paolo hasn
't updated the rest of the project
's website.
963 <h4><a name=
"installation_and_configuration_of_ngspice" id=
"installation_and_configuration_of_ngspice">Installation and configuration of ngspice
</a></h4>
967 I generally find it best to download, configure, and compile the source of
<strong>ngspice
</strong> instead of trying to install a binary package. That
's the approach I outline here.
972 <h4><a name=
"downloading_the_source_code" id=
"downloading_the_source_code">Downloading the source code
</a></h4>
976 Get the latest distribution from:
<a href=
"http://sourceforge.net/projetcs/ngspice" class=
"urlextern" title=
"http://sourceforge.net/projetcs/ngspice" rel=
"nofollow">http://sourceforge.net/projetcs/ngspice
</a>. Make sure that you get the latest version for best performance and the most features. As of May
2004, the latest release is
<strong>ngspice-rework-
15</strong>. Install the source in the place you typically put your sources. I like to keep my gEDA sources in a separate directory, for example
<strong><code>/usr/local/geda/sources/ngspice
</code></strong>. You might adopt a similar system.
981 <h4><a name=
"extracting_the_source_code" id=
"extracting_the_source_code">Extracting the source code
</a></h4>
985 The source code you downloaded is distributed in a “tarball”, a compressed archive. You have to extract archived files by doing:
988 <pre class=
"code">user@host:~$ cd
<directory where you want to extract the source
>
989 user@host:~sources$ tar -xvzf
</path/to/package.tar.gz
>
990 user@host:~sources$ cd
<extracted dir
></pre>
993 At this point you are in the top level directory of ngspice. Read the usual files, like
<strong><code>README
</code></strong>, and
<strong><code>INSTALL
</code></strong>, to learn about the simulator and the installation process. Reading
<strong><code>NOTES
</code></strong> file is also a good idea; it holds information valuable if you want to hack or debug features present in ngspice.
998 <h4><a name=
"configuration_and_compilation_of_ngspice" id=
"configuration_and_compilation_of_ngspice">Configuration and compilation of ngspice.
</a></h4>
1002 Ngspice uses the typical “
<strong><code>configure
&& make
&& make install
</code></strong>” sequence used by other GNU software. There are numerous configure time options available for ngspice. A complete listing with attendant documentation is TBD; the best way to see them all is to look at
<strong><code>configure.ac
</code></strong> itself. Many of the configure time options pertain to debugging the simulator, or are to enable experimental analyses. For newbies, three configure time options are worth mentioning:
1005 <li class=
"level1"><div class=
"li"> <strong><code>–enable-xspice
</code></strong>: This flag compiles in support for XSpice extensions. These extensions allow you to define devices whose behavior is given by arbitrary “code models”. Arguably, the most important code model is
<strong><code>spice2poly
</code></strong>, which is a model which translates SPICE2 style POLY constructs into an XSpice model usable by SPICE
3.
</div>
1007 <li class=
"level1"><div class=
"li"> <strong><code>–with-readline
</code></strong>: This flag compiles GNU readline support into
<strong>ngspice
</strong>, which means that you can use emacs-style key commands, as well as the arrow keys to move around in the command line interface (CLI). Without this feature, the command line interface can be hostile, meaning that if you make a mistake in typing a long command, you have no choice but to type it all over again. Paolo discourages use of the readline feature because it mixes
<acronym title=
"GNU General Public License">GPL
</acronym> code (readline) with BSD code (
<strong>ngspice
</strong>), but he left the option open to other to decide for themselves how pure they wanted to be.
</div>
1009 <li class=
"level1"><div class=
"li"> <strong><code>–prefix
</code></strong>: This flag point to the base directory where you want your binaries to be installed.
</div>
1015 Before you run configure, you should check the options you want to include, a brief description is given in appendix TBD. Once ready type:
1018 <pre class=
"code">user@host:~sources/
<tld
>$./configure --enable-xspice --with-readline --prefix=/usr/local/geda
<other configure options
></pre>
1021 Of course, “
<strong><code>–prefix=
</code></strong>” should point to the place where you put
<strong>your
</strong> gEDA stuff. After issuing the command, your simulator is configured and ready to be compiled. Compilation is straightforward:
1024 <pre class=
"code">user@host:~sources/
<tld
>$ make
&& make install
</pre>
1027 As always, you will probably need to be root in order to install the packages in a public directory, in such case you should do:
1030 <pre class=
"code">user@host:~sources/
<tld
>$ make
1031 user@host:~sources/
<tld
>$ su -c make install
</pre>
1035 <h4><a name=
"testing_the_installation" id=
"testing_the_installation">Testing the installation
</a></h4>
1036 <div class=
"level4">
1039 At this point, you should be able to use ngspice. You can test your installation by trying one of the test circuits held in the tests directory. I recommend running the TransImpedanceAmp test, since it tests the SPICE2 POLY functionality.
1044 <h4><a name=
"using_ngspice" id=
"using_ngspice">Using ngspice
</a></h4>
1045 <div class=
"level4">
1048 Running ngspice is very simple. Just issue the command:
1051 <pre class=
"code">user@host:~$ ngspice filename.net
</pre>
1054 at the unix command prompt, and ngspice will load the SPICE netlist called
<strong><code>filename.net
</code></strong> into its workspace, and leave you at an ngspice command prompt. You can run the simulator by saying “run”. Your results will be stored in SPICE vectors for later printing or plotting. The command set available to you is documented at:
<a href=
"http://newton.ex.ac.uk/teaching/CDHW/Electronics2/userguide/sec5.html#5" class=
"urlextern" title=
"http://newton.ex.ac.uk/teaching/CDHW/Electronics2/userguide/sec5.html#5" rel=
"nofollow">http://newton.ex.ac.uk/teaching/CDHW/Electronics2/userguide/sec5.html#
5</a>
1058 To make use of the SPICE2 POLY codemodel, you need to load it into
<strong>ngspice
</strong> <strong><em class=
"u">before
</em></strong> you load your netlist. (If you load it after loading your netlist, POLYs in your netlist are not translated, and therefore won
't be simulated correctly.) To load the codemodel, just say:
1061 <pre class=
"code">codemodel /usr/local/geda/lib/spice/spice2poly.cm
</pre>
1064 (or wherever you put your codemodels) at the ngspice prompt. Note that you must provide the
<strong>absolute path
</strong> to the location of the codemodel; ngspice isn
't smart enough to look for it in any default locations. (Also note that you should specify the location where
<strong><code>spice2poly.cm
</code></strong> lives on your machine; the path above is for mine).
1068 A better way to read in the
<strong><code>spice2poly
</code></strong> codemodel is to include it in the ngspice initialization file,
<strong><code>spinit
</code></strong>. The initialization file lives in the directory
<strong><code>/usr/local/geda/share/ng-spice-rework/scripts
</code></strong> (or where ever you placed your gEDA installation). Other ngspice customizations may also be placed into the
<strong><code>spinit
</code></strong> file.
1072 <!-- EDIT65 SECTION "Ngspice" [41374-48078] -->
1073 <h3 class=
"sectionedit66"><a name=
"tclspice" id=
"tclspice">Tclspice
</a></h3>
1074 <div class=
"level3">
1077 While the main branch of ngspice development hibernated in
2002, some friendly people at MultiGig Ltd. (
<a href=
"http://www.multigig.com/" class=
"urlextern" title=
"http://www.multigig.com/" rel=
"nofollow">http://www.multigig.com/
</a>) were busy developing a branch of ngspice which they called
<strong>tclspice
</strong>. Tclspice is a superset of ngspice in which much of the SPICE command set is exported as an
<acronym title=
"Application Programming Interface">API
</acronym> to TCL. The purpose of this is to facilitate scripting of SPICE analyses. This is a very powerful tool: With tclspice you can write a TCL script which runs a loop, tweaks component values, runs an analysis, and then evaluates the circuit performance with the tweaked components before looping again. Obviously, this ability can be used to perform automated, multi-dimensional circuit optimization. When complete, tclspice might possibly become a “killer-app” for open-source EDA.
1082 <h4><a name=
"downloading_installing_and_building_tclspice" id=
"downloading_installing_and_building_tclspice">Downloading, installing, and building tclspice
</a></h4>
1083 <div class=
"level4">
1086 Tclspice
's project homepage is at:
<a href=
"http://tclspice.sourceforge.net/" class=
"urlextern" title=
"http://tclspice.sourceforge.net/" rel=
"nofollow">http://tclspice.sourceforge.net/
</a>. The tclspice source lives at
<a href=
"http://sourceforge.net/projects/tclspice" class=
"urlextern" title=
"http://sourceforge.net/projects/tclspice" rel=
"nofollow">http://sourceforge.net/projects/tclspice
</a>. Download and installation of tclspice follow the same steps as those detailed for ngspice above. Since tclspice is a superset of ngspice, you can install ngspice alone from the tclspice sources if desired. To build the entire package requires a couple of extra steps. Here, I present a series of steps which will build both ngspice (the stand-alone, CLI driven program) and the TCL
<acronym title=
"Application Programming Interface">API
</acronym> from the tclspice source.
1090 Before building tclspice, you need to have the following packages already installed:
1093 <li class=
"level1"><div class=
"li"> TclX (tclx8.3
.5 works for me.)
</div>
1095 <li class=
"level1"><div class=
"li"> tclreadline (tclreadline-
2.1.0 works for me.)
</div>
1097 <li class=
"level1"><div class=
"li"> BLT for TCL (blt2.4z works for me.)
</div>
1099 <li class=
"level1"><div class=
"li"> TCL/Tk (
8.4.3. works for me)
</div>
1105 If you don
't have these packages already on your Linux box, you need to get and build them. Note that building TclX requires having the sources for TCL and Tk, so you will also need to get those sources if you don
't have them installed already. I am running successfully with TCL/Tk
8.4.3, although
8.3.X versions are also supposed to work. Also, if you want to run spice in the background you need to recompile TCL and Tk to enable thread support if they haven
't got it enabled already (redhat packages haven
't).
1109 Assuming you have downloaded and installed the additional packages mentioned above, the following steps will build both ngspice and the TCL
<acronym title=
"Application Programming Interface">API
</acronym> on your machine:
1112 <pre class=
"code">user@host:~sources/
<tld
>$ ./configure --enable-xspice --with-readline --prefix=/usr/local/geda
1113 user@host:~sources/
<tld
>$ make
&& make install (this makes and installs regular old ngspice)
1114 user@host:~sources/
<tld
>$ ./configure --enable-xspice --prefix=/usr/local/geda --enable-tcl --enable-experimental --disable-shared
1115 user@host:~sources/
<tld
>$ make tcl
&& make install-tcl
</pre>
1118 As always, you will probably need to be root in order to install the packages in a public directory, in such case you should do:
1121 <pre class=
"code">user@host:~sources/
<tld
>$ su -c make install
1122 user@host:~sources/
<tld
>$ su -c make install-tcl
</pre>
1125 to install your packages. Now you will be ready to write TCL scripts which incorporate SPICE commands. Information about using tclspice is given below. Finally, if you are interested in hacking tclspice (or even if you are not), it
's a good idea to read the
<strong><code>NOTES
</code></strong> file living in the top source directory for a couple of useful pointers.
1130 <h4><a name=
"use_of_tclspice" id=
"use_of_tclspice">Use of tclspice
</a></h4>
1131 <div class=
"level4">
1134 Tclspice is designed to export SPICE commands to TCL programs. To use tclspice, you just need to say “
<strong><code>package require spice
</code></strong>” at the beginning of your TCL program. Thereafter, to invoke a SPICE command, you just call it in the spice namespace. For example, the following TCL program will read in a SPICE netlist, command a transient analysis, run the simulation, and then plot the voltage observed over time on net Vout:
1137 <pre class=
"code">#! tclsh
1138 package require spice
1139 spice::codemodel /usr/local/src/tclspice-
0.2.12/src/xspice/icm/spice2poly.cm
1140 spice::source netlistname.cir
1141 spice::tran
0.1ns
40ns
1144 puts
"All done now!
"</pre>
1147 Note that since tclspice doesn
't read the ngspice initialization file
<strong><code>spinit
</code></strong>, you will need to put any initialization commands directly into the TCL program. For example, in the above example we read the spice2poly codemodel directly into the workspace. Many other commands are also available; the entire tclspice commandset is documented at:
<a href=
"http://tclspice.sourceforge.net/docs/tclspice_com.html" class=
"urlextern" title=
"http://tclspice.sourceforge.net/docs/tclspice_com.html" rel=
"nofollow">http://tclspice.sourceforge.net/docs/tclspice_com.html
</a>
1152 <h4><a name=
"tclspice_problems" id=
"tclspice_problems">Tclspice problems
</a></h4>
1153 <div class=
"level4">
1156 A major problem with tclspice (which was inherited from ngspice) is that it leaks memory. Therefore, the time over which you may run a simulation is limited. This means that if you want to do an optimization by looping through a circuit many, many times, you may run out of memory before your program has completed its optimization. This is a known issue with tclspice, and efforts are underway to plug the leaks.
1160 Meanwhile, there are some workarounds which can be used on moderate-sized designs to facilitate long optimization runs. One method I have employed is to have the optimizer write its current state into a file after every circuit analysis, and read its starting state from the same file. The optimizer also stores the current list of best components in another file, and reads this file at the start of every run. Then, I have a TCL program called
<strong><code>TaskMgr.tcl
</code></strong> which runs in a loop; at each iteration of the loop it forks a child process to run the optimizer. Meanwhile, the parent process waits for
5 minutes (a heuristically determined time), and then issues a “KILL” signal to the child before looping and starting the optimizer again. This way, the optimizer never runs long enough to consume all the memory in my machine. The
<strong><code>TaskMgr.tcl
</code></strong> program is shown here:
1163 <pre class=
"code">#! tclsh
1164 package require Tclx
1170 puts
"About to kill child PID = $PID . . . .
"
1176 # If we ever get through this, we can print out the following:
1177 error
"We are done now!!!!!!
"
1182 Note that
<strong><code>TaskMgr.tcl
</code></strong> needs the TclX package you already installed to run tclspice. Also, you may want to change the wait time to a different value depending upon the memory and speed of your machine. Finally, the parent has to wait on $PID because that causes the child process
's corpse to be taken off the Linux kernel
's task list when it dies. Otherwise, you will end up with a lot of zombie processes lurking around your machine as the optimizer runs – a long optimization could turn your system into “the night of the living dead”!
1186 This method of waiting a specific amount of time for the child process is preferable if a single analysis run takes a relatively short time compared to the time required to eat all memory in the machine. If the analysis time is comparable to the time taken to eat all memory in the machine, a better approach is to have the parent keep track of the analysis state, kick off a single analysis run, and then have the run terminate after every iteration. Whether this is preferable depends upon the size and complexity of your design; you may want to experiment with your analysis to see just how long it takes and how much memory it consumes. I have found that a design comprised of six op amps (with corresponding vendor models) and
50 or so passives will run in under
10 seconds on a PIII
333MHz with
128MB RAM. Therefore, your design must be very big before a single analysis will eat a significant amount of RAM.
1190 <!-- EDIT66 SECTION "Tclspice" [48079-55610] -->
1191 <h1 class=
"sectionedit67"><a name=
"appendix_a" id=
"appendix_a">Appendix A
</a></h1>
1192 <div class=
"level1">
1195 <strong>Native components and their attributes
</strong>
1199 Presented in table
1 are the devices and associated attributes used with spice-sdb. Bold faced attributes are required, normal typeface attributes are optional. Note that the
<strong><code>device
</code></strong> attribute is invisible, and is normally attached to the symbol when it is created. The other attributes are attached to the symbol during schematic capture using
<strong>gschem
</strong>.
1203 When dealing with simple actives (diodes, transistors) having SPICE models held in files, you only need to set the
<strong><code>model-name
</code></strong> and
<strong><code>file
</code></strong> attributes; you don
't need to set the
<strong><code>model
</code></strong> attribute. However, if your simple active has a one-line SPICE model which you wish to enter directly into the schematic, then set the
<strong><code>model
</code></strong> and
<strong><code>model-name
</code></strong> attribures; you don
't need to set the
<strong><code>file
</code></strong> attribute.
1206 <div class=
"table sectionedit68"><table class=
"inline">
1208 <th class=
"col0">device
</th><th class=
"col1">refdes
</th><th class=
"col2">value
</th><th class=
"col3">model
</th><th class=
"col4">file
</th><th class=
"col5">model-name
</th><th class=
"col6">type
</th><th class=
"col7">comment
</th>
1211 <td class=
"col0">RESISTOR
</td><td class=
"col1 centeralign"> R?
</td><td class=
"col2 centeralign"> (
4)
</td><td class=
"col3 centeralign"> (
2)
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
11)
</td>
1214 <td class=
"col0">CAPACITOR
</td><td class=
"col1 centeralign"> C?
</td><td class=
"col2 centeralign"> (
4)
</td><td class=
"col3 centeralign"> (
3)
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
11)
</td>
1217 <td class=
"col0">POLARIZED_CAPACITOR
</td><td class=
"col1 centeralign"> C?
</td><td class=
"col2 centeralign"> (
4)
</td><td class=
"col3 centeralign"> (
3)
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
11)
</td>
1220 <td class=
"col0">INDUCTOR
</td><td class=
"col1 centeralign"> L?
</td><td class=
"col2 centeralign"> (
4)
</td><td class=
"col3 centeralign"> (
3)
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
11)
</td>
1223 <td class=
"col0">SPICE-ccvs
</td><td class=
"col1 centeralign"> H?
</td><td class=
"col2 centeralign"> (
5)
</td><td class=
"col3 centeralign"> -
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> -
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 leftalign"> </td>
1226 <td class=
"col0">SPICE-cccs
</td><td class=
"col1 centeralign"> F?
</td><td class=
"col2 centeralign"> (
5)
</td><td class=
"col3 centeralign"> -
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> -
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 leftalign"> </td>
1229 <td class=
"col0">SPICE-vscs
</td><td class=
"col1 centeralign"> E?
</td><td class=
"col2 centeralign"> (
5)
</td><td class=
"col3 centeralign"> -
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> -
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 leftalign"> </td>
1232 <td class=
"col0">SPICE-vccs
</td><td class=
"col1 centeralign"> G?
</td><td class=
"col2 centeralign"> (
5)
</td><td class=
"col3 centeralign"> -
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> -
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 leftalign"> </td>
1235 <td class=
"col0">SPICE-nullor
</td><td class=
"col1 centeralign"> E?
</td><td class=
"col2 centeralign"> (
5)
</td><td class=
"col3 centeralign"> -
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> -
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 leftalign"> </td>
1238 <td class=
"col0">DIODE
</td><td class=
"col1 centeralign"> D?
</td><td class=
"col2 centeralign"> Part number
</td><td class=
"col3 centeralign"> One line SPICE model
</td><td class=
"col4 centeralign"> Model file name
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
12)
</td>
1241 <td class=
"col0">PMOS_TRANSISTOR
</td><td class=
"col1 centeralign"> M?
</td><td class=
"col2 centeralign"> Part number
</td><td class=
"col3 centeralign"> One line SPICE model
</td><td class=
"col4 centeralign"> Model file name
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
12)
</td>
1244 <td class=
"col0">NMOS_TRANSISTOR
</td><td class=
"col1 centeralign"> M?
</td><td class=
"col2 centeralign"> Part number
</td><td class=
"col3 centeralign"> One line SPICE model
</td><td class=
"col4 centeralign"> Model file name
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
12)
</td>
1247 <td class=
"col0">PNP_TRANSISTOR
</td><td class=
"col1 centeralign"> Q?
</td><td class=
"col2 centeralign"> Part number
</td><td class=
"col3 centeralign"> One line SPICE model
</td><td class=
"col4 centeralign"> Model file name
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
12)
</td>
1250 <td class=
"col0">NPN_TRANSISTOR
</td><td class=
"col1 centeralign"> Q?
</td><td class=
"col2 centeralign"> Part number
</td><td class=
"col3 centeralign"> One line SPICE model
</td><td class=
"col4 centeralign"> Model file name
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
12)
</td>
1253 <td class=
"col0">PFET_TRANSISTOR
</td><td class=
"col1 centeralign"> J?
</td><td class=
"col2 centeralign"> Part number
</td><td class=
"col3 centeralign"> One line SPICE model
</td><td class=
"col4 centeralign"> Model file name
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
12)
</td>
1256 <td class=
"col0">NFET_TRANSISTOR
</td><td class=
"col1 centeralign"> J?
</td><td class=
"col2 centeralign"> Part number
</td><td class=
"col3 centeralign"> One line SPICE model
</td><td class=
"col4 centeralign"> Model file name
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
12)
</td>
1259 <td class=
"col0">MESFET_TRANSISTOR
</td><td class=
"col1 centeralign"> B?
</td><td class=
"col2 centeralign"> Part number
</td><td class=
"col3 centeralign"> One line SPICE model
</td><td class=
"col4 centeralign"> Model file name
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
12)
</td>
1262 <td class=
"col0">IC
</td><td class=
"col1 centeralign"> U?
</td><td class=
"col2 centeralign"> Part number
</td><td class=
"col3 leftalign"> </td><td class=
"col4 centeralign"> .model file name
</td><td class=
"col5 centeralign"> Name of model
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> For IC with .model file
</td>
1265 <td class=
"col0">IC
</td><td class=
"col1 centeralign"> X?
</td><td class=
"col2 centeralign"> Part number
</td><td class=
"col3 leftalign"> </td><td class=
"col4 centeralign"> .subckt file name
</td><td class=
"col5 centeralign"> Name of .subckt
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> For IC with .subckt file
</td>
1268 <td class=
"col0">model
</td><td class=
"col1 centeralign"> A?
</td><td class=
"col2 centeralign"> -
</td><td class=
"col3 centeralign"> One line SPICE model
</td><td class=
"col4 centeralign"> .model file name
</td><td class=
"col5 centeralign"> (
9)
</td><td class=
"col6 centeralign"> (
10)
</td><td class=
"col7 centeralign"> (
12)
</td>
1271 <td class=
"col0">include
</td><td class=
"col1 centeralign"> A?
</td><td class=
"col2 centeralign"> -
</td><td class=
"col3 centeralign"> -
</td><td class=
"col4 centeralign"> .include file name
</td><td class=
"col5 centeralign"> -
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
13)
</td>
1274 <td class=
"col0">options
</td><td class=
"col1 centeralign"> A?
</td><td class=
"col2 centeralign"> (
8)
</td><td class=
"col3 centeralign"> -
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> -
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
13)
</td>
1277 <td class=
"col0">directive
</td><td class=
"col1 centeralign"> A?
</td><td class=
"col2 centeralign"> (
1)
</td><td class=
"col3 centeralign"> -
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> -
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> (
12)
</td>
1280 <td class=
"col0">VOLTAGE_SOURCE
</td><td class=
"col1 centeralign"> V?
</td><td class=
"col2 centeralign"> (
6)
</td><td class=
"col3 centeralign"> -
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> -
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> Independent voltage source
</td>
1283 <td class=
"col0">CURRENT_SOURCE
</td><td class=
"col1 centeralign"> I?
</td><td class=
"col2 centeralign"> (
7)
</td><td class=
"col3 centeralign"> -
</td><td class=
"col4 centeralign"> -
</td><td class=
"col5 centeralign"> -
</td><td class=
"col6 centeralign"> -
</td><td class=
"col7 centeralign"> Independent current source
</td>
1286 <!-- EDIT68 TABLE [56483-58746] -->
1289 (
1) One line string holding SPICE statements for inclusion in netlist
<br/>
1291 (
2) One line of SPICE model parameters (e.g. TC, etc.)
<br/>
1293 (
3) One line of SPICE model parameters (e.g. IC, POLY, etc.)
<br/>
1295 (
4) Component numeric value
<br/>
1297 (
5) String describing source behavior
<br/>
1299 (
6) One line string holding voltage source behavior
<br/>
1301 (
7) One line string holding current source behavior
<br/>
1303 (
8) line of options to include
<br/>
1305 (
9) Name of model pointed to by other components
<br/>
1307 (
10) Corresponding SPICE model type (valid types given below)
<br/>
1309 (
11) Model parameters are placed inside parentheses after component value
<br/>
1311 (
12) For modeling, one must include either model or file
<br/>
1313 (
13) Places .include directive in SPICE netlist
<br/>
1318 “Native to the netlister” means that there is a corresponding blob of scheme code which knows exactly how to handle these components and is guaranteed (almost) to generate correct spice code. Symbols having “device” attributes not on the above list are handled using the scheme function “spice-sdb:write-default-component”, which looks at the refdes of the component to make a decision about how to treat the component. In general, this function will “do the right thing” when generating spice code, but it is not guaranteed. In particular, this function cannot distinguish between N and P type transistors, and will generate an
<unknown
> type for the .MODEL string in the netlist. This will probably cause your SPICE simulator to barf. Therefore, it is best to make sure that all devices used have the proper “device” attribute.
1322 <!-- EDIT67 SECTION "Appendix A" [55611-60282] -->
1323 <h1 class=
"sectionedit69"><a name=
"appendix_b" id=
"appendix_b">Appendix B
</a></h1>
1324 <div class=
"level1">
1327 <strong>Valid “type” values.
</strong>
1331 The “type” attribute is a flag signaling the spice engine the component type, and prepares it to accept model parameters specific to that component type. The following values are valid SPICE “type”s:
1334 <div class=
"table sectionedit70"><table class=
"inline">
1336 <th class=
"col0 centeralign"> Component
</th><th class=
"col1 centeralign"> “type”
</th><th class=
"col2 centeralign"> Comment
</th>
1339 <td class=
"col0 centeralign"> RESISTOR
</td><td class=
"col1 centeralign"> RES
</td><td class=
"col2 leftalign"> </td>
1342 <td class=
"col0 centeralign"> CAPACITOR
</td><td class=
"col1 centeralign"> CAP
</td><td class=
"col2 leftalign"> </td>
1345 <td class=
"col0 centeralign"> POLARIZED_CAPACITOR
</td><td class=
"col1 centeralign"> CAP
</td><td class=
"col2 leftalign"> </td>
1348 <td class=
"col0 centeralign"> INDUCTOR
</td><td class=
"col1 centeralign"> IND
</td><td class=
"col2 leftalign"> </td>
1351 <td class=
"col0 centeralign"> DIODE
</td><td class=
"col1 centeralign"> D
</td><td class=
"col2 leftalign"> </td>
1354 <td class=
"col0 centeralign"> PMOS_TRANSISTOR
</td><td class=
"col1 centeralign"> PMOS
</td><td class=
"col2 leftalign"> </td>
1357 <td class=
"col0 centeralign"> NMOS_TRANSISTOR
</td><td class=
"col1 centeralign"> NMOS
</td><td class=
"col2 leftalign"> </td>
1360 <td class=
"col0 centeralign"> PNP_TRANSISTOR
</td><td class=
"col1 centeralign"> PNP
</td><td class=
"col2 leftalign"> </td>
1363 <td class=
"col0 centeralign"> NPN_TRANSISTOR
</td><td class=
"col1 centeralign"> NPN
</td><td class=
"col2 leftalign"> </td>
1366 <td class=
"col0 centeralign"> PFET_TRANSISTOR
</td><td class=
"col1 centeralign"> PJF
</td><td class=
"col2 leftalign"> </td>
1369 <td class=
"col0 centeralign"> NFET_TRANSISTOR
</td><td class=
"col1 centeralign"> NJF
</td><td class=
"col2 leftalign"> </td>
1372 <td class=
"col0 centeralign"> MESFET_TRANSISTOR
</td><td class=
"col1 centeralign"> -
</td><td class=
"col2 leftalign"> </td>
1375 <!-- EDIT70 TABLE [60535-60967] -->
1378 Table
2: Valid “type” attributes for components.
1383 <!-- EDIT69 SECTION "Appendix B" [60283-] --><div class=
"footnotes">
1384 <div class=
"fn"><sup><a href=
"#fnt__1" id=
"fn__1" name=
"fn__1" class=
"fn_bot">1)
</a></sup>
1385 This HOWTO is released under the GNU Free Documentation License thanks to the generosity of Electroniscript, inc. The most recent copy can always be found at
<a href=
"http://www.brorson.com/gEDA/HOWTO/" class=
"urlextern" title=
"http://www.brorson.com/gEDA/HOWTO/" rel=
"nofollow">http://www.brorson.com/gEDA/HOWTO/
</a></div>