missing NULL terminator in set_config_x
[geda-gaf.git] / docs / wiki / geda-csygas.html
blobb71860e575c85962999c65e8feaf0eadd92a37ac
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html>
4 <head>
5 <link rel="stylesheet" media="screen" type="text/css" href="./style.css" />
6 <link rel="stylesheet" media="screen" type="text/css" href="./design.css" />
7 <link rel="stylesheet" media="print" type="text/css" href="./print.css" />
9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10 </head>
11 <body>
13 <p>
14 <em>Translations of this page are also available in the following languages:</em> <a href="geda-csygas.ru.html" class="wikilink1" title="geda-csygas.ru.html">Русский</a>.
15 </p>
17 <h1 class="sectionedit1" id="circuit_simulation_using_geda_and_spice_-_howto">Circuit Simulation using gEDA and SPICE - HOWTO</h1>
18 <div class="level1">
20 <p>
21 Stuart Brorson<br/>
22 Electroniscript, inc.<br/>
23 sdb@electroniscript.com<br/>
24 <br/>
25 5th January 2006
26 </p>
28 <p>
29 <strong>abstract</strong><br/>
31 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.
32 </p>
34 <p>
35 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__21" id="fnt__21" class="fn_top">21)</a></sup>.
36 </p>
38 </div>
39 <!-- EDIT1 SECTION "Circuit Simulation using gEDA and SPICE - HOWTO" [109-1467] -->
40 <h2 class="sectionedit2" id="introduction">Introduction</h2>
41 <div class="level2">
43 <p>
44 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.
45 </p>
47 <p>
48 The <a href="http://www.geda-project.org/" class="urlextern" title="http://www.geda-project.org/" rel="nofollow">gEDA project</a> is an open-source effort to create a <abbr title="GNU General Public License">GPL</abbr>&#039;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>.
49 </p>
51 </div>
52 <!-- EDIT2 SECTION "Introduction" [1468-3736] -->
53 <h3 class="sectionedit3" id="target_audience_for_this_howto">Target audience for this HOWTO</h3>
54 <div class="level3">
56 <p>
57 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 </p>
59 <ul>
60 <li class="level1"><div class="li"> The gEDA project: <a href="http://www.geda-project.org" class="urlextern" title="http://www.geda-project.org" rel="nofollow">http://www.geda-project.org</a></div>
61 </li>
62 <li class="level1"><div class="li"> <a href="geda-faq-simulation.html" class="wikilink1" title="geda-faq-simulation.html">faq-simulation</a></div>
63 </li>
64 <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>
65 </li>
66 <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>
67 </li>
68 <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>
69 </li>
70 <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>
71 </li>
72 <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>
73 </li>
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/web/CD/engapps/geda/starting_gEDA_long.pdf" class="urlextern" title="http://www-mdp.eng.cam.ac.uk/web/CD/engapps/geda/starting_gEDA_long.pdf" rel="nofollow">http://www-mdp.eng.cam.ac.uk/web/CD/engapps/geda/starting_gEDA_long.pdf</a></div>
75 </li>
76 </ul>
78 </div>
79 <!-- EDIT3 SECTION "Target audience for this HOWTO" [3737-5019] -->
80 <h3 class="sectionedit4" id="acknowledgements">Acknowledgements</h3>
81 <div class="level3">
83 <p>
84 This document does not live in isolation. Several active members of the free EDA community were instrumental in helping me to create 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 <abbr title="GNU General Public License">GPL</abbr> – you&#039;ve started a revolution! Stefan Jones deserves a deep thank-you for his work on tclspice, and his gracious 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 acknowledge 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 achieve alone.
85 </p>
87 </div>
88 <!-- EDIT4 SECTION "Acknowledgements" [5020-6575] -->
89 <h3 class="sectionedit5" id="the_big_picturethe_design_flow_in_geda">The big picture: the design flow in gEDA</h3>
90 <div class="level3">
92 <p>
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 achieve 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 achieve your goal.
94 </p>
96 <p>
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 activity (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).
100 </p>
102 </div>
103 <!-- EDIT5 SECTION "The big picture: the design flow in gEDA" [6576-7671] -->
104 <h3 class="sectionedit6" id="overview_of_spice_usage_with_geda">Overview of SPICE usage with gEDA</h3>
105 <div class="level3">
108 Conceptually, SPICE simulation in gEDA proceeds via the following steps:
109 </p>
110 <ol>
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&#039;s website.</div>
112 </li>
113 <li class="level1"><div class="li"> Schematic capture using symbols and SPICE models created in step 1.</div>
114 </li>
115 <li class="level1"><div class="li"> Netlist generation from the schematic created in step 2.</div>
116 </li>
117 <li class="level1"><div class="li"> SPICE simulation of the circuit described by the netlist created in step 3.</div>
118 </li>
119 </ol>
122 These steps are illustrated by the blue boxes in the flow diagram above.
123 </p>
126 To create a SPICE netlist, the netlister (<strong>gnetlist</strong>) iterates through the entire schematic and looks at several parts of each component&#039;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:
127 </p>
128 <ol>
129 <li class="level1"><div class="li"> The symbol itself, in the <strong><code>device</code></strong> attribute, which is attached when the symbol is created, and is typically accessed through the symbol editor.</div>
130 </li>
131 <li class="level1"><div class="li"> In attributes manually attached to the component during schematic capture using <strong>gschem</strong>.</div>
132 </li>
133 </ol>
136 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>.
137 </p>
139 </div>
140 <!-- EDIT6 SECTION "Overview of SPICE usage with gEDA" [7672-9030] -->
141 <h3 class="sectionedit7" id="detailed_design_simulation_flow_summary">Detailed design/simulation flow summary</h3>
142 <div class="level3">
145 The detailed steps required to design and simulate a circuit using gEDA look like this:
146 </p>
147 <ol>
148 <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&#039;t hurt to check them.)</div>
149 </li>
150 <li class="level1"><div class="li"> Schematic capture using <strong>gschem</strong>.</div>
151 </li>
152 <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>
153 </li>
154 <li class="level1"><div class="li"> Assignment of <strong><code>refdes</code></strong> using e.g. <strong>refdes_renum</strong>.</div>
155 </li>
156 <li class="level1"><div class="li"> Creation of netlist using: <strong><code>gnetlist -g spice-sdb</code></strong></div>
157 </li>
158 <li class="level1"><div class="li"> Check netlist for correctness (manually open and inspect netlist).</div>
159 </li>
160 <li class="level1"><div class="li"> Run spice using a simulator such as <strong>LTSpice</strong>, <strong>ngspice</strong>, or <strong>tclspice</strong>.</div>
161 </li>
162 <li class="level1"><div class="li"> Plot/analyze results (often plotting/analysis tools are incorporated in the simulator).</div>
163 </li>
164 <li class="level1"><div class="li"> If you are not happy with your circuit&#039;s performance as revealed by simulation, go back to step 2, fix it using <strong>gschem</strong> and iterate.</div>
165 </li>
166 </ol>
169 The purpose of this HOWTO is to provide the detailed understanding necessary to successfully navigate this process.
170 </p>
172 </div>
173 <!-- EDIT7 SECTION "Detailed design/simulation flow summary" [9031-10208] -->
174 <h2 class="sectionedit8" id="preliminary_workpreparing_your_symbols_and_spice_files">Preliminary work: preparing your symbols and SPICE files</h2>
175 <div class="level2">
178 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.
179 </p>
181 </div>
182 <!-- EDIT8 SECTION "Preliminary work: preparing your symbols and SPICE files" [10209-10587] -->
183 <h3 class="sectionedit9" id="configuring_your_symbols">Configuring your symbols</h3>
184 <div class="level3">
186 </div>
188 <h4 id="identifying_the_component_to_the_netlister">Identifying the component to the netlister</h4>
189 <div class="level4">
192 The SPICE netlister can recognize any particular symbol in two ways:
193 </p>
194 <ol>
195 <li class="level1"><div class="li"> The symbol&#039;s <strong><code>device</code></strong> attribute, and</div>
196 </li>
197 <li class="level1"><div class="li"> The symbol&#039;s <strong><code>refdes</code></strong>.</div>
198 </li>
199 </ol>
202 Both of these attributes are attached to the symbol when the symbol is created.
203 </p>
206 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_--_native_components_and_their_attributes" title=":geda:csygas.txt ↵" class="wikilink1">Appendix A -- Native components and their attributes</a>.
207 </p>
210 The <strong><code>device</code></strong> attribute is hidden during normal use of <strong>gschem</strong>. Most often, the symbol&#039;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.
211 </p>
214 If a symbol is not native (i.e. the netlister doesn&#039;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_--_native_components_and_their_attributes" title=":geda:csygas.txt ↵" class="wikilink1">Appendix A -- Native components and their attributes</a>. 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.
215 </p>
217 </div>
219 <h4 id="setting_the_pin_order">Setting the pin order</h4>
220 <div class="level4">
223 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&#039;s pins listed in CBE order. Another example: if your symbol is meant to represent an IC modeled with a vendor&#039;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.
224 </p>
227 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&#039;s pins are emitted in the correct order.
228 </p>
230 </div>
231 <!-- EDIT9 SECTION "Configuring your symbols" [10588-13665] -->
232 <h3 class="sectionedit10" id="configuring_your_spice_files">Configuring your SPICE files</h3>
233 <div class="level3">
236 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:
237 </p>
238 <ul>
239 <li class="level1"><div class="li"> It is usually prudent to place these files into a dedicated directory distinct from the symbol directories.</div>
240 </li>
241 <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&#039;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>
242 </li>
243 <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>
244 </li>
245 </ul>
247 </div>
248 <!-- EDIT10 SECTION "Configuring your SPICE files" [13666-14812] -->
249 <h2 class="sectionedit11" id="creating_your_circuitschematic_capture">Creating your circuit: schematic capture</h2>
250 <div class="level2">
253 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-project.org/" class="urlextern" title="http://www.geda-project.org/" rel="nofollow">http://www.geda-project.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&#039;s netlister <strong>gnetlist</strong> on your design.
254 </p>
256 </div>
257 <!-- EDIT11 SECTION "Creating your circuit: schematic capture" [14813-15539] -->
258 <h3 class="sectionedit12" id="gschem_attributes_for_spice_netlisting">Gschem attributes for spice netlisting</h3>
259 <div class="level3">
262 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.
263 </p>
265 </div>
266 <!-- EDIT12 SECTION "Gschem attributes for spice netlisting" [15540-15821] -->
267 <h3 class="sectionedit13" id="component_attributes_and_meanings">Component attributes and meanings</h3>
268 <div class="level3">
271 The following attributes are meaningful for SPICE netlisting, and may be attached from within <strong>gschem</strong>:
272 </p>
273 <ul>
274 <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_--_native_components_and_their_attributes" title=":geda:csygas.txt ↵" class="wikilink1">Appendix A</a>.</div>
275 </li>
276 <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>
277 </li>
278 <li class="level1"><div class="li"> <strong><code>model</code></strong>: This holds a one line spice model for the component.</div>
279 </li>
280 <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>
281 </li>
282 <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>
283 </li>
284 <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>
285 </li>
286 </ul>
288 </div>
289 <!-- EDIT13 SECTION "Component attributes and meanings" [15822-17193] -->
290 <h3 class="sectionedit14" id="refdes_conventions">refdes conventions</h3>
291 <div class="level3">
294 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.
295 </p>
298 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 <a href="#appendix_a_--_native_components_and_their_attributes" title=":geda:csygas.txt ↵" class="wikilink1">Appendix A</a>.
299 </p>
301 </div>
302 <!-- EDIT14 SECTION "refdes conventions" [17194-17744] -->
303 <h3 class="sectionedit15" id="passives">Passives</h3>
304 <div class="level3">
306 </div>
308 <h4 id="basic_passives">Basic passives</h4>
309 <div class="level4">
312 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:
313 </p>
314 <ul>
315 <li class="level1"><div class="li"> <strong><code>refdes</code></strong>: The correct <strong><code>refdes</code></strong> for the component.</div>
316 </li>
317 <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>
318 </li>
319 </ul>
322 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.
323 </p>
325 </div>
327 <h5 id="example_resistor">Example resistor:</h5>
328 <div class="level5">
329 <ul>
330 <li class="level1"><div class="li"> <strong><code>refdes</code></strong> = R2</div>
331 </li>
332 <li class="level1"><div class="li"> <strong><code>value</code></strong> = 220</div>
333 </li>
334 </ul>
337 SPICE line generated: <strong><code>R2 0 4 220</code></strong><br/>
339 (note that “0” and “4” correspond to the net nodes connected to the component, and are generated automatically by <strong>gnetlist</strong>.)
340 </p>
342 </div>
344 <h5 id="example_capacitor">Example capacitor:</h5>
345 <div class="level5">
346 <ul>
347 <li class="level1"><div class="li"> <strong><code>refdes</code></strong> = C22</div>
348 </li>
349 <li class="level1"><div class="li"> <strong><code>value</code></strong> = 1UF</div>
350 </li>
351 </ul>
354 SPICE line generated: <strong><code>C22 4 23 1UF</code></strong>
355 </p>
357 </div>
359 <h4 id="passives_with_additional_attributes">Passives with additional attributes</h4>
360 <div class="level4">
363 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 attributes may be incorporated into the SPICE file by simply attaching them to the component&#039;s <strong><code>model</code></strong> attribute. Specifically, the required attributes are:
364 </p>
365 <ul>
366 <li class="level1"><div class="li"> <strong><code>refdes</code></strong>: Correct component <strong><code>refdes</code></strong>.</div>
367 </li>
368 <li class="level1"><div class="li"> <strong><code>value</code></strong>: Numerical component <strong><code>value</code></strong>, as always.</div>
369 </li>
370 <li class="level1"><div class="li"> <strong><code>model</code></strong>: One line string holding additional parameters, formatted as a valid SPICE string.</div>
371 </li>
372 </ul>
375 This string is placed after the component value in the line generated by <strong>gnetlist</strong>. 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.
376 </p>
378 </div>
380 <h5 id="example_resistor1">Example resistor:</h5>
381 <div class="level5">
382 <ul>
383 <li class="level1"><div class="li"> <strong><code>refdes</code></strong> = R5</div>
384 </li>
385 <li class="level1"><div class="li"> <strong><code>value</code></strong> = 1MEG</div>
386 </li>
387 <li class="level1"><div class="li"> <strong><code>model</code></strong> = TC=0.001,0.015</div>
388 </li>
389 </ul>
392 SPICE line generated: <strong><code>R5 0 2 1MEG TC=0.001,0.015</code></strong>
393 </p>
395 </div>
397 <h4 id="passives_for_semiconductor_design">Passives for semiconductor design</h4>
398 <div class="level4">
401 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:
402 </p>
403 <ul>
404 <li class="level1"><div class="li"> <strong><code>refdes</code></strong>: The correct refdes for the component.</div>
405 </li>
406 <li class="level1"><div class="li"> <strong><code>model-name</code></strong>: corresponds to the model in the technology library.</div>
407 </li>
408 <li class="level1"><div class="li"> <strong><code>w</code></strong>, <strong><code>l</code></strong>: dimensions of the device.</div>
409 </li>
410 </ul>
413 The technology library must be included with an <strong><code>.include</code></strong> line in the SPICE input file.
414 </p>
416 </div>
418 <h5 id="example_semiconductor_resistor">Example semiconductor resistor:</h5>
419 <div class="level5">
420 <ul>
421 <li class="level1"><div class="li"> <strong><code>refdes</code></strong> = R6</div>
422 </li>
423 <li class="level1"><div class="li"> <strong><code>model-name</code></strong> = rpoly</div>
424 </li>
425 <li class="level1"><div class="li"> <strong><code>w</code></strong> = 3u</div>
426 </li>
427 <li class="level1"><div class="li"> <strong><code>l</code></strong> = 100u</div>
428 </li>
429 </ul>
432 SPICE line generated: <strong><code>R6 0 5 rpoly w=3u l=100u</code></strong>
433 </p>
435 </div>
437 <h5 id="example_semiconductor_resistor_model">Example semiconductor resistor model:</h5>
438 <div class="level5">
439 <ul>
440 <li class="level1"><div class="li"> model rpoly R rsh=300</div>
441 </li>
442 </ul>
445 This should be part of the technology library from your ASIC vendor.
446 </p>
448 </div>
449 <!-- EDIT15 SECTION "Passives" [17745-20842] -->
450 <h3 class="sectionedit16" id="transistors_and_diodes">Transistors and diodes</h3>
451 <div class="level3">
454 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:
455 </p>
457 </div>
459 <h4 id="one_line_string_of_spice_parameters">One line string of SPICE parameters</h4>
460 <div class="level4">
463 To incorporate a one line string of SPICE parameters into the netlist, the following attributes must be attached to the component:
464 </p>
465 <ul>
466 <li class="level1"><div class="li"> <strong><code>refdes</code></strong>: Correct component <strong><code>refdes</code></strong>.</div>
467 </li>
468 <li class="level1"><div class="li"> <strong><code>value</code></strong>: The model number or part number of the component.</div>
469 </li>
470 <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>
471 </li>
472 <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>
473 </li>
474 </ul>
476 </div>
478 <h5 id="example_diode">Example diode:</h5>
479 <div class="level5">
480 <ul>
481 <li class="level1"><div class="li"> <strong><code>refdes</code></strong> = D5</div>
482 </li>
483 <li class="level1"><div class="li"> <strong><code>model-name</code></strong> = 1N1004</div>
484 </li>
485 <li class="level1"><div class="li"> <strong><code>model</code></strong> = IS=0.5UA RS=6 BV=5.20</div>
486 </li>
487 </ul>
490 SPICE lines generated: <strong><code>D5 2 6 1N1004 MODEL 1N1004 D (IS=0.5UA RS=6 BV=5.20)</code></strong>
491 </p>
493 </div>
495 <h4 id="spice_model_file">SPICE model file</h4>
496 <div class="level4">
499 To incorporate a file-full of SPICE parameters into the netlist, the following attributes must be attached to the component:
500 </p>
501 <ul>
502 <li class="level1"><div class="li"> <strong><code>refdes</code></strong>: Correct component <strong><code>refdes</code></strong>.</div>
503 </li>
504 <li class="level1"><div class="li"> <strong><code>value</code></strong>: The model number or part number of the component.</div>
505 </li>
506 <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>
507 </li>
508 <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>
509 </li>
510 </ul>
513 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.
514 </p>
516 </div>
517 <!-- EDIT16 SECTION "Transistors and diodes" [20843-23541] -->
518 <h3 class="sectionedit17" id="actives_--_integrated_circuits">Actives -- integrated circuits</h3>
519 <div class="level3">
522 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.
523 </p>
525 </div>
527 <h4 id="one_line_string_of_spice_parameters1">One line string of SPICE parameters</h4>
528 <div class="level4">
531 To incorporate a one line string of SPICE parameters into the netlist, the following attributes must be attached to the component:
532 </p>
533 <ul>
534 <li class="level1"><div class="li"> <strong><code>refdes</code></strong>: Correct component <strong><code>refdes</code></strong>.</div>
535 </li>
536 <li class="level1"><div class="li"> <strong><code>value</code></strong>: The model number or part number of the component.</div>
537 </li>
538 <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>
539 </li>
540 <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>
541 </li>
542 </ul>
544 </div>
546 <h4 id="spice_model_or_subckt_file">SPICE .MODEL or .SUBCKT file</h4>
547 <div class="level4">
550 To incorporate a file-full of SPICE parameters into the netlist, the following attributes must be attached to the component:
551 </p>
552 <ul>
553 <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&#039;t follow this rule.</div>
554 </li>
555 <li class="level1"><div class="li"> <strong><code>value</code></strong>: The model number or part number of the component.</div>
556 </li>
557 <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>
558 </li>
559 <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>
560 </li>
561 </ul>
564 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.
565 </p>
567 </div>
568 <!-- EDIT17 SECTION "Actives -- integrated circuits" [23542-25885] -->
569 <h3 class="sectionedit18" id="independent_sources">Independent sources</h3>
570 <div class="level3">
573 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:
574 </p>
575 <ol>
576 <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>&lt;independent source name&gt;.sym</strong>)</div>
577 </li>
578 <li class="level1 node"><div class="li"> Double click on the block and add/edit the following attributes:</div>
579 <ul>
580 <li class="level2"><div class="li"> <strong><code>refdes</code></strong>: V? or I?</div>
581 </li>
582 <li class="level2"><div class="li"> <strong><code>value</code></strong>: A one line string in SPICE format describing the source.</div>
583 </li>
584 </ul>
585 </li>
586 </ol>
588 </div>
589 <!-- EDIT18 SECTION "Independent sources" [25886-26459] -->
590 <h3 class="sectionedit19" id="dependent_sources">Dependent sources</h3>
591 <div class="level3">
594 There are four dependent sources:
595 </p>
596 <ul>
597 <li class="level1"><div class="li"> current controlled voltage source</div>
598 </li>
599 <li class="level1"><div class="li"> current controlled current source</div>
600 </li>
601 <li class="level1"><div class="li"> voltage controlled voltage source</div>
602 </li>
603 <li class="level1"><div class="li"> voltage controlled current source</div>
604 </li>
605 </ul>
608 For incorporation into a SPICE netlist, they all work the same way. To incorporate a dependent source into your SPICE netlist, do the following:
609 </p>
610 <ol>
611 <li class="level1"><div class="li"> Place the dependent source on your schematic. (Do <strong><em>Add</em></strong><strong><em>Component</em></strong><strong><em>spice</em></strong><strong>&lt;dependent source name&gt;.sym</strong>). Appropriate symbol names are abbreviations of the source type (i.e. <strong>ccvs-1.sym</strong>, <strong>cccs-1.sym</strong>, <strong>vcvs-1.sym</strong>, and <strong>vccs-1.sym</strong>)</div>
612 </li>
613 <li class="level1 node"><div class="li"> Double click on the block and add/edit the following attributes:</div>
614 <ul>
615 <li class="level2"><div class="li"> <strong><code>refdes</code></strong>: H?, F?, E?, or G?. Correct <strong><code>refdes</code></strong> prefixes for each source are listed in <a href="#appendix_a_--_native_components_and_their_attributes" title=":geda:csygas.txt ↵" class="wikilink1">Appendix A -- Native components and their attributes</a>.</div>
616 </li>
617 <li class="level2"><div class="li"> <strong><code>value</code></strong>: A one line string in SPICE format describing the source. Typically the <strong><code>value</code></strong> attribute represents the gain of the source given in appropriate measuring units.</div>
618 </li>
619 </ul>
620 </li>
621 </ol>
623 </div>
624 <!-- EDIT19 SECTION "Dependent sources" [26460-27516] -->
625 <h3 class="sectionedit20" id="nullor">Nullor</h3>
626 <div class="level3">
629 A <a href="https://en.wikipedia.org/wiki/nullor" class="interwiki iw_wp" title="https://en.wikipedia.org/wiki/nullor">nullor</a> is an ideal element composed of a <em>nullator</em> and
630 a <em>norator</em>. It has zero input resistance and infinite output
631 resistance, as well as infinite current, voltage,
632 transconductance and transimpedance gain and transmission
633 parameters equal to zero.
634 It is a universal active element, that is, ideally it can be
635 used for implementation of any linear and nonlinear functions,
636 if a suitable set of linear and nonlinear passive elements
637 is available. In particular the nullor, resistors and
638 capacitors form a complete set for linear circuits.
639 </p>
642 Depending on connections of the nullor terminals, the nullor
643 can be used to analyze and synthesize real circuits, which
644 is achieved by replacing of real opamps, current conveyors,
645 amplifying triodes (vacuum tubes and transistors) with the nullor
646 and a small set of passives reflecting their parameters.
647 Nullor based ideal transistors have been successfully used
648 in ac modeling for synthesis of various composite transistor
649 configurations and composite transistors.
650 Nullor based operational amplifier circuits have been used
651 for filter implementations.
652 There are also methods using the nullor for verification,
653 automatic fault diagnosis, automatic biasing analog
654 circuits and so on.
655 </p>
657 </div>
659 <h4 id="nullor_in_spice">Nullor in SPICE</h4>
660 <div class="level4">
663 In the general-purpose circuit simulators which have no nullor
664 model, the nullor element can be modeled using a <a href="#dependent_sources" title=":geda:csygas.txt ↵" class="wikilink1">dependent source</a> with a large gain, for example
665 10<sup>9</sup>. The controlled source can be of type VCVS, VCCS,
666 CCVS, or CCCS; the choice depends on the sensitivity issue and
667 what output you want to have. An infinite-gain controlled source
668 of any of the four types of dependent sources is exactly
669 equivalent to a nullor.
670 </p>
673 A three terminal nullor allows ac modeling of <em>ideal
674 transistors</em> and other <em>triodes</em>. An <em>ideal operational
675 amplifier</em> is realized by a voltage controlled voltage source
676 having an infinite (actually, large enough) gain.
677 <em>Current conveyor</em> (CCII) is equivalent to the already mentioned
678 three terminal nullor.
679 </p>
682 Usually the nullor is used for simulation in AC small-signal
683 analysis (in the frequency domain). When a negative feedback
684 is used, the nullor can be used as an ideal opamp even in
685 transient simulation (see the
686 <a href="#example_schematic_-_summing_amplifier" title=":geda:csygas.txt ↵" class="wikilink1">example</a> below).
687 </p>
689 </div>
691 <h4 id="nullor_in_geda">Nullor in gEDA</h4>
692 <div class="level4">
695 <strong>ngspice</strong> and <strong>gnucap</strong> have no special models for the nullor.
696 Therefore to represent the nullor, the <strong>spice-sdb</strong> backend
697 uses VCVS with a high gain.
698 </p>
701 To incorporate a nullor into your SPICE netlist, do the following:
702 </p>
703 <ol>
704 <li class="level1"><div class="li"> Place the nullor on your schematic. (Do <strong><em>Add</em></strong><strong><em>Component</em></strong><strong><em>spice</em></strong><strong>nullor-1.sym</strong>).</div>
705 </li>
706 <li class="level1 node"><div class="li"> Double click on the block and add/edit the following attributes:</div>
707 <ul>
708 <li class="level2"><div class="li"> <strong><code>refdes</code></strong>: N?</div>
709 </li>
710 <li class="level2"><div class="li"> <strong><code>value</code></strong>: the voltage gain of the nullor, typically 1000Meg (not needed since geda-gaf 1.9.2)</div>
711 </li>
712 </ul>
713 </li>
714 </ol>
716 </div>
718 <h5 id="examplenullor">Example: nullor</h5>
719 <div class="level5">
720 <ul>
721 <li class="level1"><div class="li"> <strong><code>refdes=N1</code></strong></div>
722 </li>
723 <li class="level1"><div class="li"> <strong><code>value=1000Meg</code></strong></div>
724 </li>
725 </ul>
728 SPICE lines generated:
729 </p>
730 <pre class="code">E_N1 1 2 3 4 1000Meg
731 IMeasure_N1 3 4 dc 0
732 IOut_N1 1 2 dc 0</pre>
735 This code contains:
736 </p>
737 <ul>
738 <li class="level1"><div class="li"> The controlled voltage source E_N1.</div>
739 </li>
740 <li class="level1"><div class="li"> The voltage measuring current source IMeasure_N1.</div>
741 </li>
742 <li class="level1"><div class="li"> The output current source IOut_N1.</div>
743 </li>
744 </ul>
747 So the nullor in <strong>gnet-spice-sdb</strong> is just a voltage controlled
748 voltage source with two zero current sources connected to its
749 input and output in order to prevent fails of the simulator
750 program when the nullor input or output has no connections to
751 anything.
752 </p>
755 Please note: after some experiments I (vzh) have found that the
756 presence or absence of those current sources doesn&#039;t affect
757 simulation and doesn&#039;t solve the mentioned issue in modern
758 versions of <strong>ngspice</strong>. <strong>ngspice</strong> still outputs an error in the
759 case where either the nullor input or its output is floating, that
760 is, not somehow connected to the ground. To avoid such an error
761 you can connect one of those nullor terminals to the ground using
762 a high ohm resistor.
763 <strong>gnucap</strong> always works well; however, in such a case the nodes
764 not connected to the ground will have an arbitrary varying
765 large voltage, so you have to measure not the potential on
766 the separate nullor terminals but the voltage just across
767 the input or the output.
768 </p>
771 If you want to make your own nullor component (with
772 another type of sensitivity), you can use the controlled
773 source symbol you want (one of vcvs-1.sym, vccs-1.sym,
774 cccs-1.sym, ccvs-1.sym) and just change its <strong><code>value</code></strong>
775 attribute to a large value, say 1000Meg.
776 </p>
778 </div>
780 <h4 id="example_schematic_-_summing_amplifier">Example schematic - summing amplifier</h4>
781 <div class="level4">
784 In this example, the nullor is used as a model of an ideal opamp.
785 </p>
788 <a href="media/geda/summing.png" class="media" target="_blank" title="geda:summing.png"><img src="media/geda/summing.png" class="mediacenter" alt="" /></a>
789 </p>
792 Schematic file for <strong>gschem</strong>: <a href="media/geda/summing.sch" class="media" target="_blank" title="geda:summing.sch">geda:summing.sch</a>
793 </p>
796 Command file for simulation in <strong>gnucap</strong> and/or <strong>ngspice</strong>:
797 </p>
798 <dl class="file">
799 <dt><a href="/./_export/code/:geda:csygas.txt?codeblock=0" title="Download Snippet" class="mediafile mf_cmd">summing.cmd</a></dt>
800 <dd><pre class="code file spice">.print tran v(nodes)
801 .tran .0001 1 0 &gt;summing.dat</pre>
802 </dd></dl>
805 Note the <code>&gt;summing.dat</code> thing in the command file. It is
806 ignored by <strong>ngspice</strong> while <strong>gnucap</strong> uses it to output data to
807 the specified file in the batch mode (using shell redirection would output
808 <strong>gnucap</strong> prompt together with data, which is not what we want).
809 </p>
812 Command line to make netlist (note the <code>sort_mode</code> flag, we need
813 it to make <strong>gnucap</strong> work right):
814 </p>
815 <pre class="code">gnetlist -g spice-sdb -O sort_mode -o summing.net summing.sch</pre>
818 Command line to simulate using <strong>ngspice</strong>:
819 </p>
820 <pre class="code">ngspice -b -r summing.dat summing.net</pre>
823 Command line to simulate using <strong>gnucap</strong>:
824 </p>
825 <pre class="code">gnucap -b summing.net</pre>
828 Command line to see the output waveforms:
829 </p>
830 <pre class="code">gwave summing.dat</pre>
832 </div>
833 <!-- EDIT20 SECTION "Nullor" [27517-32970] -->
834 <h3 class="sectionedit21" id="spice_components">SPICE components</h3>
835 <div class="level3">
837 </div>
839 <h4 id="spice_model_block">Spice model block</h4>
840 <div class="level4">
843 In certain situations, you may wish to embed a spice model block directly into your schematic. This is done when you have several devices with a <strong><code>value</code></strong> 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:
844 </p>
846 </div>
848 <h5 id="one_line_spice_model">One line SPICE model:</h5>
849 <div class="level5">
850 <ol>
851 <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>
852 </li>
853 <li class="level1 node"><div class="li"> Double click on the block and add/edit the following attributes:</div>
854 <ul>
855 <li class="level2"><div class="li"> <strong><code>refdes</code></strong>: A?</div>
856 </li>
857 <li class="level2"><div class="li"> <strong><code>model-name</code></strong>: model name (i.e. the model name used in the components being modeled)</div>
858 </li>
859 <li class="level2"><div class="li"> <strong><code>type</code></strong>: One of the valid spice component types defined in the spice <abbr title="specification">spec</abbr>.</div>
860 </li>
861 <li class="level2"><div class="li"> <strong><code>model</code></strong>: The corresponding one-line spice model</div>
862 </li>
863 </ul>
864 </li>
865 </ol>
867 </div>
869 <h5 id="multi-line_spice_model">Multi-line SPICE model:</h5>
870 <div class="level5">
871 <ol>
872 <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>
873 </li>
874 <li class="level1 node"><div class="li"> Double click on the block and add/edit the following attributes:</div>
875 <ul>
876 <li class="level2"><div class="li"> <strong><code>refdes</code></strong>: A?</div>
877 </li>
878 <li class="level2"><div class="li"> <strong><code>model-name</code></strong>: model name</div>
879 </li>
880 <li class="level2"><div class="li"> <strong><code>file</code></strong>: Name of file holding SPICE model code (i.e. .MODEL or .SUBCKT).</div>
881 </li>
882 </ul>
883 </li>
884 </ol>
886 </div>
888 <h4 id="include_block">Include block</h4>
889 <div class="level4">
892 The include block places a .INCLUDE directive into your netlist.
893 </p>
894 <ol>
895 <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>
896 </li>
897 <li class="level1 node"><div class="li"> Double click on the block and add/edit the following attributes:</div>
898 <ul>
899 <li class="level2"><div class="li"> <strong><code>refdes</code></strong>: A?</div>
900 </li>
901 <li class="level2"><div class="li"> <strong><code>file</code></strong>: Name of file to include.</div>
902 </li>
903 </ul>
904 </li>
905 </ol>
907 </div>
909 <h4 id="spice_directive_block">SPICE directive block</h4>
910 <div class="level4">
913 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>value</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:
914 </p>
915 <ul>
916 <li class="level1"><div class="li"> .TEMP statement</div>
917 </li>
918 <li class="level1"><div class="li"> .IC statement</div>
919 </li>
920 <li class="level1"><div class="li"> Other SPICE statements for which <strong>gschem</strong> has no symbol.</div>
921 </li>
922 </ul>
925 To place a SPICE directive on your schematic, do:
926 </p>
927 <ol>
928 <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>
929 </li>
930 <li class="level1 node"><div class="li"> Double click on the block and add/edit the following attributes:</div>
931 <ul>
932 <li class="level2"><div class="li"> <strong><code>refdes</code></strong>: A?</div>
933 </li>
934 <li class="level2"><div class="li"> <strong><code>file</code></strong>: Name of file to include.</div>
935 </li>
936 </ul>
937 </li>
938 </ol>
940 </div>
941 <!-- EDIT21 SECTION "SPICE components" [32971-35392] -->
942 <h3 class="sectionedit22" id="handling_hierarchical_models">Handling hierarchical models</h3>
943 <div class="level3">
946 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&#039;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 <strong>gschem</strong>, netlist it to create a .SUBCKT, and then use the .SUBCKT to model capacitors in a higher level schematic.
947 </p>
950 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:
951 </p>
952 <ol>
953 <li class="level1"><div class="li"> Draw the schematic of the lower level component (e.g. the capacitor + parasitics) using <strong>gschem</strong>.</div>
954 </li>
955 <li class="level1 node"><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:</div>
956 <ul>
957 <li class="level2"><div class="li"> <strong><code>model-name</code></strong> = cap_with_parasitics<br/>
958 (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>
959 </li>
960 </ul>
961 </li>
962 <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>
963 </li>
964 <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: <pre class="code">gnetlist -g spice-sdb -o cap_with_parasitics.cir cap_with_parasitics.sch</pre>
967 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.
968 </p>
969 </div>
970 </li>
971 <li class="level1 node"><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 <strong><code>refdes</code></strong> starting with the letter “X”. To ensure that this happens, do the following:</div>
972 <ul>
973 <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>
974 </li>
975 <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>
976 </li>
977 <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 <a href="#appendix_a_--_native_components_and_their_attributes" title=":geda:csygas.txt ↵" class="wikilink1">appendix</a>! 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>
978 </li>
979 <li class="level2"><div class="li"> Using a text editor, give the symbol the <strong><code>refdes</code></strong> attribute “X?”</div>
980 </li>
981 </ul>
982 </li>
983 <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>
984 </li>
985 <li class="level1 node"><div class="li"> To point your symbol to the lower level .SUBCKT, double click on the symbol and set the following attributes:</div>
986 <ul>
987 <li class="level2"><div class="li"> <strong><code>file</code></strong> = cap_with_parasitics.cir</div>
988 </li>
989 <li class="level2"><div class="li"> <strong><code>model-name</code></strong> = cap_with_parasitics<br/>
990 as well as any other attributes required (e.g. <strong><code>refdes</code></strong>).</div>
991 </li>
992 </ul>
993 </li>
994 <li class="level1 node"><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>
995 <ul>
996 <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>
997 </li>
998 <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>
999 </li>
1000 </ul>
1001 </li>
1002 </ol>
1005 Once the netlist is created, you may simulate your design using any SPICE simulator desired. Some simulators running on Linux are covered below.
1006 </p>
1008 </div>
1009 <!-- EDIT22 SECTION "Handling hierarchical models" [35393-39997] -->
1010 <h2 class="sectionedit23" id="spice_netlist_generation">SPICE netlist generation</h2>
1011 <div class="level2">
1013 </div>
1014 <!-- EDIT23 SECTION "SPICE netlist generation" [39998-40034] -->
1015 <h3 class="sectionedit24" id="using_gnetlist">Using gnetlist</h3>
1016 <div class="level3">
1019 Once the schematic is captured, a SPICE netlist can be generated running gEDA&#039;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.
1020 </p>
1023 <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>. Among other options described in the <a href="geda-gnetlist_ug-command_line.html" class="wikilink1" title="geda-gnetlist_ug-command_line.html">gnetlist User Guide</a>, <strong>gnetlist</strong> supports using of backend specific options. A backend specific option can be enabled using the <code>-O OPTION</code> switch. The following specific options are available with <strong>spice-sdb</strong>:
1024 </p>
1025 <ul>
1026 <li class="level1"><div class="li"> <code>include_mode</code>: put <code>.INCLUDE &lt;filename&gt;</code> in output file instead of model file&#039;s contents</div>
1027 </li>
1028 <li class="level1"><div class="li"> <code>embedd_mode</code>: force embedding of .include file contents</div>
1029 </li>
1030 <li class="level1"><div class="li"> <code>nomunge_mode</code>: do not automatically correct component refdes</div>
1031 </li>
1032 <li class="level1"><div class="li"> <code>sort_mode</code>: sort output netlist</div>
1033 </li>
1034 </ul>
1036 </div>
1037 <!-- EDIT24 SECTION "Using gnetlist" [40035-41577] -->
1038 <h3 class="sectionedit25" id="creating_the_netlist_using_gnetlist_and_spice-sdb">Creating the netlist using gnetlist and spice-sdb</h3>
1039 <div class="level3">
1042 Creating a netlist from a schematic is easy. To generate a SPICE netlist, just do the following:
1043 </p>
1044 <ul>
1045 <li class="level1"><div class="li"> Save your schematic to &lt;<strong><code>filename.sch</code></strong>&gt;</div>
1046 </li>
1047 <li class="level1"><div class="li"> Create the SPICE netlist by doing “<strong><code>gnetlist -g spice-sdb &lt;filename.sch&gt;</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: <pre class="code">gnetlist -g spice-sdb -o amplifier.cir amplifier.sch</pre>
1050 takes the design schematic called “<strong><code>amplifier.sch</code></strong>” and outputs a SPICE netlist named “<strong><code>amplifier.cir</code></strong>”.
1051 </p>
1052 </div>
1053 </li>
1054 <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>
1055 </li>
1056 </ul>
1058 </div>
1059 <!-- EDIT25 SECTION "Creating the netlist using gnetlist and spice-sdb" [41578-42366] -->
1060 <h3 class="sectionedit26" id="common_netlisting_problems">Common netlisting problems</h3>
1061 <div class="level3">
1064 The following list attempts to catalog common problems with the netlist and the associated fixes:
1065 </p>
1066 <ul>
1067 <li class="level1"><div class="li"> ERROR_INVALID_PIN:<br/>
1068 This can happen if the symbol&#039;s <strong><code>pinseq</code></strong> attributes don&#039;t start at 1, or have gaps in the numbering. This must be fixed by editing the symbol itself in a text editor.</div>
1069 </li>
1070 <li class="level1"><div class="li"> ERROR: In procedure caddr:<br/>
1071 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 &lt;filename.sch&gt;</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 <strong>gschem</strong> and fix the attributes.</div>
1072 </li>
1073 </ul>
1076 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.
1077 </p>
1079 </div>
1080 <!-- EDIT26 SECTION "Common netlisting problems" [42367-43374] -->
1081 <h2 class="sectionedit27" id="spice_simulation">SPICE simulation</h2>
1082 <div class="level2">
1085 There are several options for doing SPICE simulations under GNU/Linux; I will highlight three:
1086 </p>
1087 <ul>
1088 <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>
1089 </li>
1090 <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&#039;s internals.</div>
1091 </li>
1092 <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 <abbr title="Application Programming Interface">API</abbr>, 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>
1093 </li>
1094 </ul>
1097 There is also a <abbr title="GNU General Public License">GPL</abbr>&#039;ed simulator called <strong>gnucap</strong>, which is based upon (or is the descendant of) Al&#039;s Circuit Simulator (<strong><code>ACS</code></strong>). I haven&#039;t used it very much; information about gnucap is therefore TBD.
1098 </p>
1100 </div>
1101 <!-- EDIT27 SECTION "SPICE simulation" [43375-45027] -->
1102 <h3 class="sectionedit28" id="ltspice">LTSpice</h3>
1103 <div class="level3">
1106 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&#039;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.
1107 </p>
1110 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.
1111 </p>
1113 </div>
1115 <h4 id="installation_and_configuration_of_ltspice">Installation and configuration of LTSpice</h4>
1116 <div class="level4">
1119 To install and configure LTSpice, do the following:
1120 </p>
1121 <ol>
1122 <li class="level1"><div class="li"> Download and install wine. I have had success using Wine-20030219. Later versions probably also work.</div>
1123 </li>
1124 <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>
1125 </li>
1126 <li class="level1"><div class="li"> Run the LTSpice installer under wine.</div>
1127 </li>
1128 </ol>
1130 </div>
1132 <h4 id="running_ltspice_with_geda_designs">Running LTSpice with gEDA designs</h4>
1133 <div class="level4">
1136 LTSpice can read a file holding a gEDA SPICE netlist. I have had success doing LTSpice simulations in the following way:
1137 </p>
1138 <ol>
1139 <li class="level1"><div class="li"> First of all, make sure that you are logged in as a normal user – Wine doesn&#039;t like to run when invoked by root.</div>
1140 </li>
1141 <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>
1142 </li>
1143 <li class="level1"><div class="li"> Place a SPICE include block into your schematic. For the file attribute, type in “Simulation.cmd”.</div>
1144 </li>
1145 <li class="level1"><div class="li"> Netlist your design.</div>
1146 </li>
1147 <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: <pre class="code">ln -s ${DESIGN_HOME}/output.net ${WINE_HOME}/.wine/fake_windows/Program Files/LTC/SwCADIII/MyDesign.cir</pre>
1148 </div>
1149 </li>
1150 <li class="level1"><div class="li"> Run LTSpice: cd into the directory where SwCADIII lives and say <pre class="code">wine scad3.exe</pre>
1151 </div>
1152 </li>
1153 <li class="level1"><div class="li"> From the SwCADIII <abbr title="Graphical User Interface">GUI</abbr>, 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>
1154 </li>
1155 <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>
1156 </li>
1157 <li class="level1"><div class="li"> Select the variables to graph, and then click OK. SwCADIII does the rest of the work.</div>
1158 </li>
1159 </ol>
1162 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.
1163 </p>
1165 </div>
1166 <!-- EDIT28 SECTION "LTSpice" [45028-47973] -->
1167 <h3 class="sectionedit29" id="ngspice">Ngspice</h3>
1168 <div class="level3">
1171 Ngspice was started at the University of Rome “La Sapienza” by Paolo Nenzi as an attempt to create a <abbr title="GNU General Public License">GPL</abbr>&#039;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&#039;t updated the rest of the project&#039;s website.
1172 </p>
1174 </div>
1176 <h4 id="installation_and_configuration_of_ngspice">Installation and configuration of ngspice</h4>
1177 <div class="level4">
1180 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&#039;s the approach I outline here.
1181 </p>
1183 </div>
1185 <h4 id="downloading_the_source_code">Downloading the source code</h4>
1186 <div class="level4">
1189 Get the latest distribution from: <a href="http://sourceforge.net/projects/ngspice" class="urlextern" title="http://sourceforge.net/projects/ngspice" rel="nofollow">http://sourceforge.net/projects/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.
1190 </p>
1192 </div>
1194 <h4 id="extracting_the_source_code">Extracting the source code</h4>
1195 <div class="level4">
1198 The source code you downloaded is distributed in a “tarball”, a compressed archive. You have to extract archived files by doing:
1199 </p>
1200 <pre class="code">user@host:~$ cd &lt;directory where you want to extract the source&gt;
1201 user@host:~sources$ tar -xvzf &lt;/path/to/package.tar.gz&gt;
1202 user@host:~sources$ cd &lt;extracted dir&gt;</pre>
1205 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.
1206 </p>
1208 </div>
1210 <h4 id="configuration_and_compilation_of_ngspice">Configuration and compilation of ngspice.</h4>
1211 <div class="level4">
1214 Ngspice uses the typical “<strong><code>configure &amp;&amp; make &amp;&amp; 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:
1215 </p>
1216 <ul>
1217 <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 <a href="geda-spice_polys.html" class="wikilink1" title="geda-spice_polys.html">POLY</a> constructs into an XSpice model usable by SPICE 3.</div>
1218 </li>
1219 <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 <abbr title="GNU General Public License">GPL</abbr> 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>
1220 </li>
1221 <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>
1222 </li>
1223 </ul>
1226 Before you run configure, you should check the options you want to include, a brief description is given in appendix TBD. Once ready type:
1227 </p>
1228 <pre class="code">user@host:~sources/&lt;tld&gt;$ ./configure --enable-xspice --with-readline --prefix=/usr/local/geda &lt;other configure options&gt;</pre>
1231 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:
1232 </p>
1233 <pre class="code">user@host:~sources/&lt;tld&gt;$ make &amp;&amp; make install</pre>
1236 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:
1237 </p>
1238 <pre class="code">user@host:~sources/&lt;tld&gt;$ make
1239 user@host:~sources/&lt;tld&gt;$ su -c make install</pre>
1241 </div>
1243 <h4 id="testing_the_installation">Testing the installation</h4>
1244 <div class="level4">
1247 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 <a href="geda-spice_polys.html" class="wikilink1" title="geda-spice_polys.html">POLY</a> functionality.
1248 </p>
1250 </div>
1252 <h4 id="using_ngspice">Using ngspice</h4>
1253 <div class="level4">
1256 Running ngspice is very simple. Just issue the command:
1257 </p>
1258 <pre class="code">user@host:~$ ngspice filename.net</pre>
1261 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>.
1262 </p>
1265 To make use of the SPICE2 <a href="geda-spice_polys.html" class="wikilink1" title="geda-spice_polys.html">POLY</a> 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, <a href="geda-spice_polys.html" class="wikilink1" title="geda-spice_polys.html">POLYs</a> in your netlist are not translated, and therefore won&#039;t be simulated correctly.) To load the codemodel, just say:
1266 </p>
1267 <pre class="code">codemodel /usr/local/geda/lib/spice/spice2poly.cm</pre>
1270 (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&#039;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.)
1271 </p>
1274 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.
1275 </p>
1277 </div>
1278 <!-- EDIT29 SECTION "Ngspice" [47974-54760] -->
1279 <h3 class="sectionedit30" id="tclspice">Tclspice</h3>
1280 <div class="level3">
1283 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 <abbr title="Application Programming Interface">API</abbr> 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.
1284 </p>
1286 </div>
1288 <h4 id="downloading_installing_and_building_tclspice">Downloading, installing, and building tclspice</h4>
1289 <div class="level4">
1292 Tclspice&#039;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 <abbr title="Application Programming Interface">API</abbr> from the tclspice source.
1293 </p>
1296 Before building tclspice, you need to have the following packages already installed:
1297 </p>
1298 <ul>
1299 <li class="level1"><div class="li"> TclX (tclx8.3.5 works for me.)</div>
1300 </li>
1301 <li class="level1"><div class="li"> tclreadline (tclreadline-2.1.0 works for me.)</div>
1302 </li>
1303 <li class="level1"><div class="li"> BLT for TCL (blt2.4z works for me.)</div>
1304 </li>
1305 <li class="level1"><div class="li"> TCL/Tk (8.4.3. works for me)</div>
1306 </li>
1307 </ul>
1310 If you don&#039;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&#039;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&#039;t got it enabled already (redhat packages haven&#039;t).
1311 </p>
1314 Assuming you have downloaded and installed the additional packages mentioned above, the following steps will build both ngspice and the TCL <abbr title="Application Programming Interface">API</abbr> on your machine:
1315 </p>
1316 <pre class="code">user@host:~sources/&lt;tld&gt;$ ./configure --enable-xspice --with-readline --prefix=/usr/local/geda
1317 user@host:~sources/&lt;tld&gt;$ make &amp;&amp; make install (this makes and installs regular old ngspice)
1318 user@host:~sources/&lt;tld&gt;$ ./configure --enable-xspice --prefix=/usr/local/geda --enable-tcl --enable-experimental --disable-shared
1319 user@host:~sources/&lt;tld&gt;$ make tcl &amp;&amp; make install-tcl</pre>
1322 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:
1323 </p>
1324 <pre class="code">user@host:~sources/&lt;tld&gt;$ su -c make install
1325 user@host:~sources/&lt;tld&gt;$ su -c make install-tcl</pre>
1328 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&#039;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.
1329 </p>
1331 </div>
1333 <h4 id="use_of_tclspice">Use of tclspice</h4>
1334 <div class="level4">
1337 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:
1338 </p>
1339 <pre class="code">#! tclsh
1340 package require spice
1341 spice::codemodel /usr/local/src/tclspice-0.2.12/src/xspice/icm/spice2poly.cm
1342 spice::source netlistname.cir
1343 spice::tran 0.1ns 40ns
1344 spice::run
1345 spice::plot Vout
1346 puts &quot;All done now!&quot;</pre>
1349 Note that since tclspice doesn&#039;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>.
1350 </p>
1352 </div>
1354 <h4 id="tclspice_problems">Tclspice problems</h4>
1355 <div class="level4">
1358 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.
1359 </p>
1362 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:
1363 </p>
1364 <pre class="code">#! tclsh
1365 package require Tclx
1366 while {1} {
1367 set PID [fork]
1368 if {$PID} {
1369 # Parent
1370 after 300000
1371 puts &quot;About to kill child PID = $PID . . . .&quot;
1372 kill $PID
1373 wait $PID
1374 } else {
1375 # Child
1376 source Optimize.tcl
1377 # If we ever get through this, we can print out the following:
1378 error &quot;We are done now!!!!!!&quot;
1380 }</pre>
1383 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&#039;s corpse to be taken off the Linux kernel&#039;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”!
1384 </p>
1387 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.
1388 </p>
1390 </div>
1391 <!-- EDIT30 SECTION "Tclspice" [54761-62290] -->
1392 <h2 class="sectionedit31" id="appendix_a_--_native_components_and_their_attributes">Appendix A -- Native components and their attributes</h2>
1393 <div class="level2">
1396 Presented in table 1 are the devices and associated attributes used with spice-sdb. <strong>Bold faced</strong> attributes are <strong>required</strong>, 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>.
1397 </p>
1400 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&#039;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> attributes; you don&#039;t need to set the <strong><code>file</code></strong> attribute.
1401 </p>
1404 <strong>Table 1:</strong> Attributes required for SPICE netlisting
1405 </p>
1406 <div class="table sectionedit32"><table class="inline">
1407 <thead>
1408 <tr class="row0">
1409 <th class="col0 centeralign"> <code>device</code> </th><th class="col1 centeralign"> <code>refdes</code> </th><th class="col2 centeralign"> <code>value</code> </th><th class="col3 centeralign"> <code>model</code> </th><th class="col4 centeralign"> <code>file</code> </th><th class="col5 centeralign"> <code>model-name</code> </th><th class="col6 centeralign"> <code>type</code> </th><th class="col7 centeralign"> Comment </th>
1410 </tr>
1411 </thead>
1412 <tr class="row1">
1413 <td class="col0"><strong>RESISTOR</strong></td><td class="col1 centeralign"> <strong>R?</strong> </td><td class="col2 centeralign"> <strong>(4)</strong> </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>
1414 </tr>
1415 <tr class="row2">
1416 <td class="col0"><strong>CAPACITOR</strong></td><td class="col1 centeralign"> <strong>C?</strong> </td><td class="col2 centeralign"> <strong>(4)</strong> </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>
1417 </tr>
1418 <tr class="row3">
1419 <td class="col0"><strong>POLARIZED_CAPACITOR</strong></td><td class="col1 centeralign"> <strong>C?</strong> </td><td class="col2 centeralign"> <strong>(4)</strong> </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>
1420 </tr>
1421 <tr class="row4">
1422 <td class="col0"><strong>INDUCTOR</strong></td><td class="col1 centeralign"> <strong>L?</strong> </td><td class="col2 centeralign"> <strong>(4)</strong> </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>
1423 </tr>
1424 <tr class="row5">
1425 <td class="col0"><strong>SPICE-ccvs</strong></td><td class="col1 centeralign"> <strong>H?</strong> </td><td class="col2 centeralign"> <strong>(5)</strong> </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"> Current controlled voltage source </td>
1426 </tr>
1427 <tr class="row6">
1428 <td class="col0"><strong>SPICE-cccs</strong></td><td class="col1 centeralign"> <strong>F?</strong> </td><td class="col2 centeralign"> <strong>(5)</strong> </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"> Current controlled current source </td>
1429 </tr>
1430 <tr class="row7">
1431 <td class="col0"><strong>SPICE-vcvs</strong></td><td class="col1 centeralign"> <strong>E?</strong> </td><td class="col2 centeralign"> <strong>(5)</strong> </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"> Voltage controlled voltage source </td>
1432 </tr>
1433 <tr class="row8">
1434 <td class="col0"><strong>SPICE-vccs</strong></td><td class="col1 centeralign"> <strong>G?</strong> </td><td class="col2 centeralign"> <strong>(5)</strong> </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"> Voltage controlled current source </td>
1435 </tr>
1436 <tr class="row9">
1437 <td class="col0"><strong>SPICE-nullor</strong></td><td class="col1 centeralign"> <strong>N?</strong> </td><td class="col2 centeralign"> <strong>(15)</strong> </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>
1438 </tr>
1439 <tr class="row10">
1440 <td class="col0"><strong>DIODE</strong></td><td class="col1 centeralign"> <strong>D?</strong> </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"> <strong>Name of model</strong> </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> (12) </td>
1441 </tr>
1442 <tr class="row11">
1443 <td class="col0"><strong>PMOS_TRANSISTOR</strong></td><td class="col1 centeralign"> <strong>M?</strong> </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"> <strong>Name of model</strong> </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> (12) </td>
1444 </tr>
1445 <tr class="row12">
1446 <td class="col0"><strong>NMOS_TRANSISTOR</strong></td><td class="col1 centeralign"> <strong>M?</strong> </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"> <strong>Name of model</strong> </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> (12) </td>
1447 </tr>
1448 <tr class="row13">
1449 <td class="col0"><strong>PNP_TRANSISTOR</strong></td><td class="col1 centeralign"> <strong>Q?</strong> </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"> <strong>Name of model</strong> </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> (12) </td>
1450 </tr>
1451 <tr class="row14">
1452 <td class="col0"><strong>NPN_TRANSISTOR</strong></td><td class="col1 centeralign"> <strong>Q?</strong> </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"> <strong>Name of model</strong> </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> (12) </td>
1453 </tr>
1454 <tr class="row15">
1455 <td class="col0"><strong>PFET_TRANSISTOR</strong></td><td class="col1 centeralign"> <strong>J?</strong> </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"> <strong>Name of model</strong> </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> (12) </td>
1456 </tr>
1457 <tr class="row16">
1458 <td class="col0"><strong>NFET_TRANSISTOR</strong></td><td class="col1 centeralign"> <strong>J?</strong> </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"> <strong>Name of model</strong> </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> (12) </td>
1459 </tr>
1460 <tr class="row17">
1461 <td class="col0"><strong>MESFET_TRANSISTOR</strong></td><td class="col1 centeralign"> <strong>B?</strong> </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"> <strong>Name of model</strong> </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> (12) </td>
1462 </tr>
1463 <tr class="row18">
1464 <td class="col0"><strong>IC</strong></td><td class="col1 centeralign"> <strong>U?</strong> </td><td class="col2 centeralign"> Part number </td><td class="col3 centeralign"> - </td><td class="col4 centeralign"> .model file name </td><td class="col5 centeralign"> <strong>Name of model</strong> </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> For IC with .model file </td>
1465 </tr>
1466 <tr class="row19">
1467 <td class="col0"><strong>IC</strong></td><td class="col1 centeralign"> <strong>X?</strong> </td><td class="col2 centeralign"> Part number </td><td class="col3 centeralign"> - </td><td class="col4 centeralign"> .subckt file name </td><td class="col5 centeralign"> <strong>Name of .subckt</strong> </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> For IC with .subckt file </td>
1468 </tr>
1469 <tr class="row20">
1470 <td class="col0"><strong>model</strong></td><td class="col1 centeralign"> <strong>A?</strong> </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"> <strong>(9)</strong> </td><td class="col6 centeralign"> <strong>(10)</strong> </td><td class="col7 centeralign"> (12) </td>
1471 </tr>
1472 <tr class="row21">
1473 <td class="col0"><strong>include</strong></td><td class="col1 centeralign"> <strong>A?</strong> </td><td class="col2 centeralign"> - </td><td class="col3 centeralign"> - </td><td class="col4 centeralign"> <strong>.include file name</strong> </td><td class="col5 centeralign"> - </td><td class="col6 centeralign"> - </td><td class="col7 centeralign"> (13) </td>
1474 </tr>
1475 <tr class="row22">
1476 <td class="col0"><strong>options</strong></td><td class="col1 centeralign"> <strong>A?</strong> </td><td class="col2 centeralign"> <strong>(8)</strong> </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"> (14) </td>
1477 </tr>
1478 <tr class="row23">
1479 <td class="col0"><strong>directive</strong></td><td class="col1 centeralign"> <strong>A?</strong> </td><td class="col2 centeralign"> <strong>(1)</strong> </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>
1480 </tr>
1481 <tr class="row24">
1482 <td class="col0"><strong>VOLTAGE_SOURCE</strong></td><td class="col1 centeralign"> <strong>V?</strong> </td><td class="col2 centeralign"> <strong>(6)</strong> </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>
1483 </tr>
1484 <tr class="row25">
1485 <td class="col0"><strong>CURRENT_SOURCE</strong></td><td class="col1 centeralign"> <strong>I?</strong> </td><td class="col2 centeralign"> <strong>(7)</strong> </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>
1486 </tr>
1487 </table></div>
1488 <!-- EDIT32 TABLE [63222-65984] -->
1490 (1) One line string holding SPICE statements for inclusion in netlist<br/>
1492 (2) One line of SPICE model parameters (e.g. TC, etc.)<br/>
1494 (3) One line of SPICE model parameters (e.g. IC, POLY, etc.)<br/>
1496 (4) Component numeric value<br/>
1498 (5) String describing source behavior<br/>
1500 (6) One line string holding voltage source behavior<br/>
1502 (7) One line string holding current source behavior<br/>
1504 (8) line of options to include<br/>
1506 (9) Name of model pointed to by other components<br/>
1508 (10) Corresponding SPICE model type (valid types given below)<br/>
1510 (11) Model parameters are placed inside parentheses after component value<br/>
1512 (12) For modeling, one must include either model or file<br/>
1514 (13) Places .INCLUDE directive in SPICE netlist<br/>
1516 (14) Places .OPTIONS directive in SPICE netlist<br/>
1518 (15) A large enough gain value, e.g. 1000Meg; it is not required in the recent geda-gaf versions (since 1.9.2)
1519 </p>
1522 “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 &lt;unknown&gt; 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.
1523 </p>
1525 </div>
1526 <!-- EDIT31 SECTION "Appendix A -- Native components and their attributes" [62291-67680] -->
1527 <h2 class="sectionedit33" id="appendix_b_--_valid_type_values">Appendix B -- Valid &quot;type&quot; values</h2>
1528 <div class="level2">
1531 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:
1532 </p>
1535 <strong>Table 2:</strong> Valid “type” attributes for components
1536 </p>
1537 <div class="table sectionedit34"><table class="inline">
1538 <thead>
1539 <tr class="row0">
1540 <th class="col0 centeralign"> Component </th><th class="col1 centeralign"> “type” </th><th class="col2 centeralign"> Comment </th>
1541 </tr>
1542 </thead>
1543 <tr class="row1">
1544 <td class="col0 leftalign">RESISTOR </td><td class="col1 centeralign"> RES </td><td class="col2"> </td>
1545 </tr>
1546 <tr class="row2">
1547 <td class="col0 leftalign">CAPACITOR </td><td class="col1 centeralign"> CAP </td><td class="col2"> </td>
1548 </tr>
1549 <tr class="row3">
1550 <td class="col0 leftalign">POLARIZED_CAPACITOR </td><td class="col1 centeralign"> CAP </td><td class="col2"> </td>
1551 </tr>
1552 <tr class="row4">
1553 <td class="col0 leftalign">INDUCTOR </td><td class="col1 centeralign"> IND </td><td class="col2"> </td>
1554 </tr>
1555 <tr class="row5">
1556 <td class="col0 leftalign">DIODE </td><td class="col1 centeralign"> D </td><td class="col2"> </td>
1557 </tr>
1558 <tr class="row6">
1559 <td class="col0 leftalign">PMOS_TRANSISTOR </td><td class="col1 centeralign"> PMOS </td><td class="col2"> </td>
1560 </tr>
1561 <tr class="row7">
1562 <td class="col0 leftalign">NMOS_TRANSISTOR </td><td class="col1 centeralign"> NMOS </td><td class="col2"> </td>
1563 </tr>
1564 <tr class="row8">
1565 <td class="col0 leftalign">PNP_TRANSISTOR </td><td class="col1 centeralign"> PNP </td><td class="col2"> </td>
1566 </tr>
1567 <tr class="row9">
1568 <td class="col0 leftalign">NPN_TRANSISTOR </td><td class="col1 centeralign"> NPN </td><td class="col2"> </td>
1569 </tr>
1570 <tr class="row10">
1571 <td class="col0 leftalign">PFET_TRANSISTOR </td><td class="col1 centeralign"> PJF </td><td class="col2"> </td>
1572 </tr>
1573 <tr class="row11">
1574 <td class="col0 leftalign">NFET_TRANSISTOR </td><td class="col1 centeralign"> NJF </td><td class="col2"> </td>
1575 </tr>
1576 <tr class="row12">
1577 <td class="col0 leftalign">MESFET_TRANSISTOR </td><td class="col1 centeralign"> - </td><td class="col2"> </td>
1578 </tr>
1579 </table></div>
1580 <!-- EDIT34 TABLE [67980-68350] -->
1581 </div>
1582 <!-- EDIT33 SECTION "Appendix B -- Valid type values" [67681-] --><div class="footnotes">
1583 <div class="fn"><sup><a href="#fnt__21" id="fn__21" class="fn_bot">21)</a></sup>
1584 <div class="content">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></div>
1585 </div>
1586 </body>
1587 </html>