Downloaded and integrated latest wiki documentation from the geda website.
[geda-gaf/whiteaudio.git] / docs / wiki / geda_sdb_howto.html
blob5f3a06aa10b84724ef85fa3b74fcb3a24b649f2c
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en"
4 lang="en" dir="ltr">
5 <head>
6 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7 <title>geda:sdb_howto</title>
8 <meta name="generator" content="DokuWiki Release rc2007-05-24" />
9 <meta name="robots" content="index,follow" />
10 <meta name="date" content="2007-05-24T22:27:25-0400" />
11 <meta name="keywords" content="geda,sdb_howto" />
12 <link rel="search" type="application/opensearchdescription+xml" href="http://geda.seul.org/wiki/lib/exe/opensearch.php" title="geda Wiki" />
13 <link rel="start" href="http://geda.seul.org/wiki/" />
14 <link rel="contents" href="http://geda.seul.org/wiki/geda:sdb_howto?do=index" title="Index" />
15 <link rel="alternate" type="application/rss+xml" title="Recent Changes" href="http://geda.seul.org/wiki/feed.php" />
16 <link rel="alternate" type="application/rss+xml" title="Current Namespace" href="http://geda.seul.org/wiki/feed.php?mode=list&ns=geda" />
17 <link rel="alternate" type="text/html" title="Plain HTML" href="http://geda.seul.org/wiki/_export/xhtml/geda:sdb_howto" />
18 <link rel="alternate" type="text/plain" title="Wiki Markup" href="http://geda.seul.org/wiki/_export/raw/geda:sdb_howto" />
19 <link rel="stylesheet" media="all" type="text/css" href="lib/exe/css" />
20 <link rel="stylesheet" media="screen" type="text/css" href="lib/exe/001css" />
21 <link rel="stylesheet" media="print" type="text/css" href="lib/exe/002css" />
22 </head>
23 <body>
24 <div class="dokuwiki export">
25 <div class="toc">
26 <div class="tocheader toctoggle" id="toc__header">Table of Contents</div>
27 <div id="toc__inside">
29 <ul class="toc">
30 <li class="level1"><div class="li"><span class="li"><a href="#spice_on_geda_howto" class="toc">SPICE on gEDA HOWTO</a></span></div>
31 <ul class="toc">
32 <li class="level2"><div class="li"><span class="li"><a href="#introduction" class="toc">Introduction</a></span></div>
33 <ul class="toc">
34 <li class="level3"><div class="li"><span class="li"><a href="#overview" class="toc">Overview</a></span></div></li>
35 <li class="level3"><div class="li"><span class="li"><a href="#spice-sdb_netlister_installation_and_configuration" class="toc">Spice-sdb netlister installation and configuration</a></span></div></li>
36 <li class="level3"><div class="li"><span class="li"><a href="#design_simulation_flow_summary" class="toc">Design/simulation flow summary</a></span></div></li>
37 </ul>
38 </li>
39 <li class="level2"><div class="li"><span class="li"><a href="#preliminary_notes_about_symbols_and_spice_model_files" class="toc">Preliminary notes about symbols and SPICE model files</a></span></div>
40 <ul class="toc">
41 <li class="level3"><div class="li"><span class="li"><a href="#symbol_creation_for_spice_netlisting" class="toc">Symbol creation for SPICE netlisting.</a></span></div></li>
42 <li class="level3"><div class="li"><span class="li"><a href="#spice_file_configuration" class="toc">SPICE file configuration</a></span></div></li>
43 </ul>
44 </li>
45 <li class="level2"><div class="li"><span class="li"><a href="#schematic_capture" class="toc">Schematic capture</a></span></div>
46 <ul class="toc">
47 <li class="level3"><div class="li"><span class="li"><a href="#gschem_attributes_for_spice_netlisting" class="toc">Gschem attributes for spice netlisting</a></span></div></li>
48 <li class="level3"><div class="li"><span class="li"><a href="#handling_hierarchical_models" class="toc">Handling hierarchical models</a></span></div></li>
49 </ul>
50 </li>
51 <li class="level2"><div class="li"><span class="li"><a href="#spice_netlist_generation" class="toc">SPICE netlist generation</a></span></div></li>
52 <li class="level2"><div class="li"><span class="li"><a href="#creating_the_netlist" class="toc">Creating the netlist</a></span></div></li>
53 <li class="level2"><div class="li"><span class="li"><a href="#common_netlisting_problems" class="toc">Common netlisting problems</a></span></div></li>
54 <li class="level2"><div class="li"><span class="li"><a href="#spice_simulation" class="toc">SPICE simulation</a></span></div>
55 <ul class="toc">
56 <li class="level3"><div class="li"><span class="li"><a href="#ltspice" class="toc">LTSpice</a></span></div></li>
57 <li class="level3"><div class="li"><span class="li"><a href="#ngspice_and_tclspice" class="toc">Ngspice and tclspice</a></span></div></li>
58 </ul>
59 </li>
60 <li class="level2"><div class="li"><span class="li"><a href="#appendix" class="toc">Appendix</a></span></div>
61 <ul class="toc">
62 <li class="level3"><div class="li"><span class="li"><a href="#component_attribute_summary" class="toc">Component attribute summary</a></span></div></li>
63 <li class="level3"><div class="li"><span class="li"><a href="#valid_type_values" class="toc">Valid &quot;type&quot; values</a></span></div></li>
64 </ul>
65 </li>
66 <li class="level2"><div class="li"><span class="li"><a href="#document_history" class="toc">Document History</a></span></div></li></ul>
67 </li></ul>
68 </div>
69 </div>
73 <h1><a name="spice_on_geda_howto" id="spice_on_geda_howto">SPICE on gEDA HOWTO</a></h1>
74 <div class="level1">
76 </div>
77 <!-- SECTION "SPICE on gEDA HOWTO" [1-34] -->
78 <h2><a name="introduction" id="introduction">Introduction</a></h2>
79 <div class="level2">
81 <p>
82 The purpose of this document is to explain how to use the gEDA tools (running on Linux) to perform SPICE simulations. In particular, this HOWTO documents the usage of spice-sdb, which is an advanced backend for the gEDA netlister (gnetlist) used to create SPICE netlists. This HOWTO also provides advice about using LTSpice and/or ngspice to simulate a circuit netlisted with spice-sdb. I assume that you are already familiar with electronic design, the mechanics of schematic capture using EDA tools, and SPICE simulation in general. I also assume that you are reasonably familiar with the Linux operating system and its development environment.
83 </p>
85 </div>
86 <!-- SECTION "Introduction" [35-708] -->
87 <h3><a name="overview" id="overview">Overview</a></h3>
88 <div class="level3">
90 <p>
91 From the top level, SPICE simulation in gEDA proceeds via the following steps:
92 </p>
93 <ol>
94 <li class="level1"><div class="li"> Creation and gathering of schematic symbols and SPICE model files. Oftentimes, the SPICE model files are obtained from the component vendor.</div>
95 </li>
96 <li class="level1"><div class="li"> Schematic capture using symbols and SPICE models created in step 1.</div>
97 </li>
98 <li class="level1"><div class="li"> Netlist generation from the schematic created in step 2.</div>
99 </li>
100 <li class="level1"><div class="li"> SPICE simulation of the circuit described by the netlist created in step 3.</div>
101 </li>
102 </ol>
105 To create a SPICE netlist, the netlister (gnetlist) iterates through the entire schematic and looks at several parts of each component’s symbol in order to create a blob of SPICE code. In general, each component can generate one or more lines of SPICE code. Component information needed by the netlister is held in two places:
106 </p>
107 <ol>
108 <li class="level1"><div class="li"> The symbol itself, in the “device” attribute, which is attached when the symbol is created, and is typically accessed through the symbol editor.</div>
109 </li>
110 <li class="level1"><div class="li"> In attributes manually attached to the component during schematic capture using gschem.</div>
111 </li>
112 </ol>
115 Since there are two places the netlister looks for information, you must make sure that the required information is available in both places.
116 </p>
118 </div>
119 <!-- SECTION "Overview" [709-1877] -->
120 <h3><a name="spice-sdb_netlister_installation_and_configuration" id="spice-sdb_netlister_installation_and_configuration">Spice-sdb netlister installation and configuration</a></h3>
121 <div class="level3">
124 This document was originally written around gEDA/gaf 20030223, and the SPICE netlister spice-SDB. Starting with gEDA/gaf 20030525, my netlister was incorporated into the main gEDA distribution, and renamed spice-sdb (lower case sdb). <strong>For smoothest operation, you are best off just downloading and installing the latest version of gEDA.</strong> However, if you have a gEDA version predating 20030525, and you want to hack, you can download and install spice-SDB using the instructions provided on <a href="http://www.brorson.com/gEDA/SPICE/SPICEonLinux.html" class="urlextern" title="http://www.brorson.com/gEDA/SPICE/SPICEonLinux.html" rel="nofollow">http://www.brorson.com/gEDA/SPICE/SPICEonLinux.html</a>. In any event, it’s a good idea to make sure that the file gnet-spice-sdb.scm is present in your scheme directory (usually <strong><code>${prefix}/geda/share/gEDA/scheme</code></strong>) if you are interested in performing SPICE simulations with gEDA as described in this HOWTO.
125 </p>
127 </div>
128 <!-- SECTION "Spice-sdb netlister installation and configuration" [1878-2744] -->
129 <h3><a name="design_simulation_flow_summary" id="design_simulation_flow_summary">Design/simulation flow summary</a></h3>
130 <div class="level3">
133 The detailed steps required to create a circuit and simulate it with gEDA look like this:
134 </p>
135 <ol>
136 <li class="level1"><div class="li"> Schematic symbol creation with correct “device” attribute. (Usually, the symbols have already been created with the correct “device” attribute, but if you are having problems, it doesn’t hurt to check them.)</div>
137 </li>
138 <li class="level1"><div class="li"> Schematic capture using gschem.</div>
139 </li>
140 <li class="level1"><div class="li"> Assignment of SPICE attributes (value, model, file, type, etc.) to components using gschem.</div>
141 </li>
142 <li class="level1"><div class="li"> Assignment of <strong><code>refdes</code></strong> using e.g. refdes_renum.</div>
143 </li>
144 <li class="level1"><div class="li"> Creation of netlist using “gnetlist -g spice-sdb”.</div>
145 </li>
146 <li class="level1"><div class="li"> Check netlist for correctness (manually open and inspect netlist).</div>
147 </li>
148 <li class="level1"><div class="li"> Run spice using a simulator such as LTSpice or ngspice.</div>
149 </li>
150 <li class="level1"><div class="li"> Plot/analyze results (often plotting/analysis tools are incorporated in the simulator).</div>
151 </li>
152 </ol>
155 The purpose of this HOWTO is to provide the detailed understanding necessary to successfully navigate this process.
156 </p>
158 </div>
159 <!-- SECTION "Design/simulation flow summary" [2745-3673] -->
160 <h2><a name="preliminary_notes_about_symbols_and_spice_model_files" id="preliminary_notes_about_symbols_and_spice_model_files">Preliminary notes about symbols and SPICE model files</a></h2>
161 <div class="level2">
163 </div>
164 <!-- SECTION "Preliminary notes about symbols and SPICE model files" [3674-3739] -->
165 <h3><a name="symbol_creation_for_spice_netlisting" id="symbol_creation_for_spice_netlisting">Symbol creation for SPICE netlisting.</a></h3>
166 <div class="level3">
169 The SPICE netlister recognizes a particular symbol in two ways:
170 </p>
171 <ol>
172 <li class="level1"><div class="li"> The symbol’s “device” attribute</div>
173 </li>
174 <li class="level1"><div class="li"> The symbol’s <strong><code>refdes</code></strong>. Both of these attributes are attached to the symbol when the symbol is created.</div>
175 </li>
176 </ol>
179 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 RESISTOR, CAPACITOR, NPN_TRANSISTOR, etc. The entire list of native devices is present in the <a href="#appendix" title="geda:sdb_howto &crarr;" class="wikilink1">Appendix</a>.<br/>
180 The <strong><code>device</code></strong> attribute is hidden during normal use of gschem. Most often, the symbol’s creator has already given the symbol the correct <strong><code>device</code></strong> attribute. However, because the <strong><code>device</code></strong> attribute is hidden from the ordinary user, it can sometimes cause problems with SPICE netlist creation when it is set to an unexpected value. To view the <strong><code>device</code></strong> attribute, go into the symbol editor (select the symbol to edit, and do “Hierarchy” &rarr; “down symbol”), and turn on invisible attributes (Edit &rarr; show/hide inv text). If the <strong><code>device</code></strong> attribute is incorrect, you may change it by editing the symbol itself using a text editor.<br/>
181 If a symbol is not native (i.e. the netlister doesn’t recognize it as a built-in type), the netlister relies upon the first letter of the <strong><code>refdes</code></strong> to determine how to process the symbol. The <strong><code>refdes</code></strong> prefix is also built into the symbol when it is created. Example <strong><code>refdes</code></strong> prefixes are R for resistors, C for capacitors, Q for transistors, etc. <strong><code>refdes</code></strong> prefixes correct for SPICE are listed in the <a href="#appendix" title="geda:sdb_howto &crarr;" class="wikilink1">Appendix</a>. Note that relying upon the <strong><code>refdes</code></strong> to identify the component for SPICE is not foolproof &ndash; 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 “device” in your symbols.
182 </p>
184 </div>
185 <!-- SECTION "Symbol creation for SPICE netlisting." [3740-5819] -->
186 <h3><a name="spice_file_configuration" id="spice_file_configuration">SPICE file configuration</a></h3>
187 <div class="level3">
190 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:
191 </p>
192 <ul>
193 <li class="level1"><div class="li"> It is usually prudent to place these files into a dedicated directory distinct from the symbol directories.</div>
194 </li>
195 <li class="level1"><div class="li"> Make sure that the SPICE files pin assignments correctly correspond to the pins as defined in the component’s symbol.</div>
196 </li>
197 <li class="level1"><div class="li"> Make sure that the last character in a SPICE model file is a carriage return. 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>
198 </li>
199 </ul>
201 </div>
202 <!-- SECTION "SPICE file configuration" [5820-6689] -->
203 <h2><a name="schematic_capture" id="schematic_capture">Schematic capture</a></h2>
204 <div class="level2">
207 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 “gschem”. I assume you already know how to use gschem. For the purposes of creating SPICE netlists, you must use gschem to attach attributes to components, and possibly also incorporate other SPICE directives into your netlist. After you are done with schematic capture, you create the SPICE netlist by running gEDA’s netlister “gnetlist” on your design.
208 </p>
210 </div>
211 <!-- SECTION "Schematic capture" [6690-7282] -->
212 <h3><a name="gschem_attributes_for_spice_netlisting" id="gschem_attributes_for_spice_netlisting">Gschem attributes for spice netlisting</a></h3>
213 <div class="level3">
216 There are several ways that spice attributes may be associated with a component using gschem. 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.
217 </p>
219 </div>
221 <h4><a name="component_attributes_and_meanings" id="component_attributes_and_meanings">Component attributes and meanings</a></h4>
222 <div class="level4">
225 The following attributes are meaningful for SPICE netlisting, and may be attached from within gschem:
226 </p>
227 <table class="inline">
228 <tr>
229 <td><strong><code>refdes</code></strong></td><td>The reference designator of the component. Valid values depend upon the component type and are given in the appendix.</td>
230 </tr>
231 <tr>
232 <td><strong><code>value</code></strong></td><td>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 “value” attribute holds the name of the spice model.</td>
233 </tr>
234 <tr>
235 <td><strong><code>model</code></strong></td><td>This holds a one line spice model for the component.</td>
236 </tr>
237 <tr>
238 <td><strong><code>file</code></strong></td><td>This holds the name of a file. Typically, this is a file holding e.g. a SPICE .MODEL, .SUBCKT, or other SPICE code.</td>
239 </tr>
240 <tr>
241 <td><strong><code>model-name</code></strong></td><td>This holds the name of the spice model referred to in a .MODEL or .SUBCKT statement. “model-name” is mainly used to identify the spice model name in the symbol “spice-model-1.sym”. Active components should call out this name in the “device” attribute to associate the component with its particular spice model or subcircuit.</td>
242 </tr>
243 <tr>
244 <td><strong><code>type</code></strong></td><td>This specifies the type of component and is used by spice when interpreting the model parameters. Valid values depend upon the device being modeled.</td>
245 </tr>
246 </table>
248 </div>
250 <h4><a name="refdes_conventions" id="refdes_conventions">refdes conventions</a></h4>
251 <div class="level4">
254 As a prerequisite to handling SPICE-related attributes, the SPICE netlister requires that all components must have a refdes attached to them. The refdes may be attached either by hand (which is laborious), or using the program refdes_renum included in the gEDA distribution.<br/>
255 Note that the first letter of the refdes must correspond to the appropriate letter for spice simulation. The refdes convention is given in the <a href="#appendix" title="geda:sdb_howto &crarr;" class="wikilink1">Appendix</a>.
256 </p>
258 </div>
260 <h4><a name="passives" id="passives">Passives</a></h4>
261 <div class="level4">
263 </div>
265 <h5><a name="basic_passives" id="basic_passives">Basic passives</a></h5>
266 <div class="level5">
269 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:
270 </p>
271 <table class="inline">
272 <tr>
273 <td><strong><code>refdes</code></strong></td><td>The correct <strong><code>refdes</code></strong> for the component.</td>
274 </tr>
275 <tr>
276 <td><strong><code>value</code></strong></td><td>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).</td>
277 </tr>
278 </table>
281 If only a <strong><code>refdes</code></strong> and value attribute are encountered, the netlister will write a single line into the output file.<br/>
282 Example resistor:
283 </p>
284 <pre class="code">refdes = R2
285 value = 220
286 SPICE line generated: R2 0 4 220</pre>
289 Note that “0” and “4” correspond to the net nodes connected to the component, and are generated automatically by gnetlist.<br/>
290 Example capacitor:
291 </p>
292 <pre class="code">refdes = C22
293 value = 1UF
294 SPICE line generated: C22 4 23 1UF</pre>
296 </div>
298 <h5><a name="passives_with_additional_attributes" id="passives_with_additional_attributes">Passives with additional attributes</a></h5>
299 <div class="level5">
302 Oftentimes, passive components have additional attributes attached to them for spice simulation. Examples of such attributes are temperature coefficients (for resistors) and initial conditions (for reactive components). These additional components may be incorporated into the SPICE file by simply attaching them to the component’s “model” attribute. Specifically, the required attributes are:
303 </p>
304 <table class="inline">
305 <tr>
306 <td><strong><code>refdes</code></strong></td><td>Correct component <strong><code>refdes</code></strong>.</td>
307 </tr>
308 <tr>
309 <td><strong><code>value</code></strong></td><td>Numerical component value, as always.</td>
310 </tr>
311 <tr>
312 <td><strong><code>model</code></strong></td><td>One line string holding additional parameters, formatted as a valid SPICE string.</td>
313 </tr>
314 </table>
317 This string is placed after the component value in the line generated by gnetlist. Therefore, it is important to format the string placed in the <strong><code>model</code></strong> line to be valid SPICE code. Otherwise, you will risk causing the SPICE simulator to barf.<br/>
318 Example resistor:
319 </p>
320 <pre class="code">refdes = R5
321 value = 1MEG
322 model = TC=0.001,0.015
323 SPICE line generated: R2 0 4 220 TC=0.001,0.015</pre>
325 </div>
327 <h4><a name="transistors_and_diodes" id="transistors_and_diodes">Transistors and diodes</a></h4>
328 <div class="level4">
331 Transistors and diodes are generally accompanied by a device-specific model &ndash; 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:
332 </p>
334 </div>
336 <h5><a name="one_line_string_of_spice_parameters" id="one_line_string_of_spice_parameters">One line string of SPICE parameters</a></h5>
337 <div class="level5">
340 To incorporate a one line string of SPICE parameters into the netlist, the following attributes must be attached to the component:
341 </p>
342 <table class="inline">
343 <tr>
344 <td><strong><code>refdes</code></strong></td><td>Correct component refdes.</td>
345 </tr>
346 <tr>
347 <td><strong><code>value</code></strong></td><td>The model number or part number of the component.</td>
348 </tr>
349 <tr>
350 <td><strong><code>model-name</code></strong></td><td>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 “value” attribute to the component, this parameter is optional.</td>
351 </tr>
352 <tr>
353 <td><strong><code>model</code></strong></td><td>One line string holding additional parameters. Do not place the model parameters in parentheses &ndash; gnetlist will do this for you.</td>
354 </tr>
355 </table>
358 Example diode:
359 </p>
360 <pre class="code">refdes = D5
361 model-name = 1N1004
362 model = IS=0.5UA RS=6 BV=5.20
363 SPICE lines generated:
364 D5 2 6 1N1004
365 MODEL 1N1004 D (IS=0.5UA RS=6 BV=5.20)</pre>
367 </div>
369 <h5><a name="spice_model_file" id="spice_model_file">SPICE model file</a></h5>
370 <div class="level5">
373 To incorporate a file-full of SPICE parameters into the netlist, the following attributes must be attached to the component:
374 </p>
375 <table class="inline">
376 <tr>
377 <td><strong><code>refdes</code></strong></td><td>Correct component refdes.</td>
378 </tr>
379 <tr>
380 <td><strong><code>value</code></strong></td><td>The model number or part number of the component.</td>
381 </tr>
382 <tr>
383 <td><strong><code>model-name</code></strong></td><td>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 “value” attribute to the component, this parameter is optional.</td>
384 </tr>
385 <tr>
386 <td><strong><code>file</code></strong></td><td>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.</td>
387 </tr>
388 </table>
391 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.
392 </p>
394 </div>
396 <h4><a name="actives_--_integrated_circuits" id="actives_--_integrated_circuits">Actives -- integrated circuits</a></h4>
397 <div class="level4">
400 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.
401 </p>
403 </div>
405 <h5><a name="one_line_string_of_spice_parameters1" id="one_line_string_of_spice_parameters1">One line string of SPICE parameters</a></h5>
406 <div class="level5">
409 To incorporate a one line string of SPICE parameters into the netlist, the following attributes must be attached to the component:
410 </p>
411 <table class="inline">
412 <tr>
413 <td><strong><code>refdes</code></strong></td><td>Correct component refdes.</td>
414 </tr>
415 <tr>
416 <td><strong><code>value</code></strong></td><td>The model number or part number of the component.</td>
417 </tr>
418 <tr>
419 <td><strong><code>model-name</code></strong></td><td>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 “value” attribute to the component, this parameter is optional.</td>
420 </tr>
421 <tr>
422 <td><strong><code>model</code></strong></td><td>One line string holding additional parameters. Do not place the model parameters in parentheses &ndash; gnetlist will do this for you.</td>
423 </tr>
424 </table>
426 </div>
428 <h5><a name="spice_.model_or_.subckt_file" id="spice_.model_or_.subckt_file">SPICE .MODEL or .SUBCKT file</a></h5>
429 <div class="level5">
432 To incorporate a file-full of SPICE parameters into the netlist, the following attributes must be attached to the component:
433 </p>
434 <table class="inline">
435 <tr>
436 <td><strong><code>refdes</code></strong></td><td>Correct component refdes. <strong>Note that if the file holds a .MODEL, the refdes should start with U; if the file holds a .SUBCKT, the refdes should start with X.</strong> The netlister checks for the file type and tries to “do the right thing”, but problems can arise if you don’t follow this rule.</td>
437 </tr>
438 <tr>
439 <td><strong><code>value</code></strong></td><td>The model number or part number of the component.</td>
440 </tr>
441 <tr>
442 <td><strong><code>model-name</code></strong></td><td>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 “value” attribute to the component, this parameter is optional.</td>
443 </tr>
444 <tr>
445 <td><strong><code>file</code></strong></td><td>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.</td>
446 </tr>
447 </table>
449 </div>
451 <h4><a name="independent_sources" id="independent_sources">Independent sources</a></h4>
452 <div class="level4">
455 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:
456 </p>
457 <ol>
458 <li class="level1"><div class="li"> Place the independent source on your schematic. (Do “Add” &rarr; “Component” &rarr; “spice” &rarr; &quot;&lt;independent source name&gt;.sym”)</div>
459 </li>
460 <li class="level1"><div class="li"> Double click on the block and add/edit the following attributes:</div>
461 <ul>
462 <li class="level2"><div class="li"> <strong><code>refdes</code></strong>: V? or I?</div>
463 </li>
464 <li class="level2"><div class="li"> <strong><code>value</code></strong>: A one line string in SPICE format describing the source.</div>
465 </li>
466 </ul>
467 </li>
468 </ol>
470 </div>
472 <h4><a name="dependent_sources" id="dependent_sources">Dependent sources</a></h4>
473 <div class="level4">
476 There are four dependent sources:
477 </p>
478 <ul>
479 <li class="level1"><div class="li"> This section remains TBD.</div>
480 </li>
481 </ul>
483 </div>
485 <h4><a name="spice_components" id="spice_components">SPICE components</a></h4>
486 <div class="level4">
488 </div>
490 <h5><a name="spice_model_block" id="spice_model_block">Spice model block</a></h5>
491 <div class="level5">
494 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 “value” attribute calling out for a spice model. Depending upon whether the spice block is one line or multi-line, you may embed the code in one of two ways:
495 </p>
496 <ol>
497 <li class="level1"><div class="li"> One line SPICE model:</div>
498 <ol>
499 <li class="level2"><div class="li"> Place a spice model block on your schematic. (Do “Add” &rarr; “Component” &rarr; “spice” &rarr; “spice-model-1.sym”)</div>
500 </li>
501 <li class="level2"><div class="li"> Double click on the block and add/edit the following attributes:</div>
502 <ul>
503 <li class="level3"><div class="li"> <strong><code>refdes</code></strong>: a?</div>
504 </li>
505 <li class="level3"><div class="li"> <strong><code>model</code></strong>: model name (i.e. the model name used in the components being modeled.)</div>
506 </li>
507 <li class="level3"><div class="li"> <strong><code>type</code></strong>: One of the valid spice component types defined in the spice <acronym title="specification">spec</acronym>.</div>
508 </li>
509 <li class="level3"><div class="li"> <strong><code>value</code></strong>: The corresponding one-line spice model</div>
510 </li>
511 </ul>
512 </li>
513 </ol>
514 </li>
515 <li class="level1"><div class="li"> Multi-line SPICE model:</div>
516 <ol>
517 <li class="level2"><div class="li"> Place a spice model block on your schematic.(Do “Add” &rarr; “Component” &rarr; “spice” &rarr; “spice-model-1.sym”)</div>
518 </li>
519 <li class="level2"><div class="li"> Double click on the block and add/edit the following attributes:</div>
520 <ul>
521 <li class="level3"><div class="li"> <strong><code>refdes</code></strong>: a?</div>
522 </li>
523 <li class="level3"><div class="li"> <strong><code>model-name</code></strong>: model name</div>
524 </li>
525 <li class="level3"><div class="li"> <strong><code>file</code></strong>: Name of file holding SPICE model code (i.e. .MODEL or .SUBCKT).</div>
526 </li>
527 </ul>
528 </li>
529 </ol>
530 </li>
531 </ol>
533 </div>
535 <h5><a name="include_block" id="include_block">Include block</a></h5>
536 <div class="level5">
539 The include block places a .INCLUDE directive into your netlist.
540 </p>
541 <ol>
542 <li class="level1"><div class="li"> Place a spice model block on your schematic. (Do “Add” &rarr; “Component” &rarr; “spice” &rarr; “spice-include-1.sym”)</div>
543 </li>
544 <li class="level1"><div class="li"> Double click on the block and add/edit the following attributes:</div>
545 <ul>
546 <li class="level2"><div class="li"> <strong><code>refdes</code></strong>: a?</div>
547 </li>
548 <li class="level2"><div class="li"> <strong><code>file</code></strong>: The name of the file to include.</div>
549 </li>
550 </ul>
551 </li>
552 </ol>
554 </div>
556 <h5><a name="spice_directive_block" id="spice_directive_block">SPICE directive block</a></h5>
557 <div class="level5">
560 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 “model” attribute. Examples of situations where this is useful include:
561 </p>
562 <ul>
563 <li class="level1"><div class="li"> .TEMP statement</div>
564 </li>
565 <li class="level1"><div class="li"> .IC statement</div>
566 </li>
567 <li class="level1"><div class="li"> Other SPICE statements for which gschem has no symbol.</div>
568 </li>
569 </ul>
572 To place a SPICE directive on your schematic, do the following:
573 </p>
574 <ol>
575 <li class="level1"><div class="li"> Place a SPICE directive block on your schematic. (Do “Add” &rarr; “Component” &rarr; “spice” &rarr; “spice-directive-1.sym”)</div>
576 </li>
577 <li class="level1"><div class="li"> Double click on the block and add/edit the following attributes:</div>
578 <ul>
579 <li class="level2"><div class="li"> <strong><code>refdes</code></strong>: a?</div>
580 </li>
581 <li class="level2"><div class="li"> <strong><code>file</code></strong>: The name of the file to include.</div>
582 </li>
583 </ul>
584 </li>
585 </ol>
587 </div>
588 <!-- SECTION "Gschem attributes for spice netlisting" [7283-18697] -->
589 <h3><a name="handling_hierarchical_models" id="handling_hierarchical_models">Handling hierarchical models</a></h3>
590 <div class="level3">
593 In SPICE modeling, there are often situations where you wish to create a schematic representation of some particular component as a .SUBCKT, and then embed that component’s model in a higher level schematic. A common example might be as follows: You are doing a microwave simulation, and want to use a capacitor model which includes parasitic inductances and resistances, as well as the capacitance. Capacitor manufacturers often supply a printed schematic showing a circuit topology incorporating parasitics, and specify values for the parasitics. You would like to draw the capacitor model using gschem, netlist it to create a .SUBCKT, and then use the .SUBCKT to model capacitors in a higher lever schematic.<br/>
594 Since this kind of task is very common in SPICE simulation, gnet-spice-sdb now supports it (starting with rev 20030331). To create a lower level .SUBCKT and use it in a higher level schematic, do the following:
595 </p>
596 <ol>
597 <li class="level1"><div class="li"> Draw the schematic of the lower level component (e.g. the capacitor + parasitics) using gschem.</div>
598 </li>
599 <li class="level1"><div class="li"> On the lower level schematic, place a spice-subcircuit-LL block (spice-subcircuit-LL-1.sym). This alerts the netlister that the schematic is a Lower Level .SUBCKT. Attach the following attributes to the symbol:<br/>
600 <br/>
601 <strong><code>model-name</code></strong> = cap_with_parasitics<br/>
602 <br/>
603 (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 &quot;.SUBCKT cap_with_parasitics &quot; into the first line of the netlist file.</div>
604 </li>
605 <li class="level1"><div class="li"> On the lower level schematic, attach a spice-subcircuit-IO symbol (spice-subcircuit-IO-1.sym) 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>
606 </li>
607 <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 cap_with_parasitics.sch, netlist it by saying:<br/>
608 <br/>
609 <strong><code>gnetlist -g spice-sdb -o cap_with_parasitics.cir cap_with_parasitics.sch</code></strong><br/>
610 <br/>
611 This will dump the SPICE netlist into the file called “cap_with_parasitics.cir”. Visually inspect the .cir file to make sure that netlisting worked correctly.</div>
612 </li>
613 <li class="level1"><div class="li"> Next, create a symbol for the upper level schematic which will point to the .SUBCKT. Note that the symbol must have a refdes starting with the letter “X”. To ensure that this happens, do the following:</div>
614 <ul>
615 <li class="level2"><div class="li"> Use gschem 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>
616 </li>
617 <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 “PINSEQ” attribute. The netlister will output the pins in the order determined by the “PINSEQ” attribute.</div>
618 </li>
619 <li class="level2"><div class="li"> Using a text editor, give the symbol a “DEVICE” attribute like “capacitor-model”. Do not assign the symbol one of the native device types listed in the appendix! The goal is to create a symbol whose refdes starts with “X”, and if the “DEVICE” is a recognized type, this will not happen.</div>
620 </li>
621 <li class="level2"><div class="li"> Using a text editor, give the symbol the “REFDES” attribute “X?&quot;</div>
622 </li>
623 </ul>
624 </li>
625 <li class="level1"><div class="li"> Create the upper level schematic. Place your newly created symbol on the schematic as many times as required &amp; wire up the schematic in the usual way.</div>
626 </li>
627 <li class="level1"><div class="li"> To point your symbol to the lower level .SUBCKT, double click on the symbol and set the following attributes:<br/>
628 <br/>
629 <strong><code>file</code></strong> = cap_with_parasitics.cir<br/>
630 <strong><code>model-name</code></strong> = cap_with_parasitics<br/>
631 <br/>
632 as well as any other attributes required (e.g. refdes).</div>
633 </li>
634 <li class="level1"><div class="li"> Now netlist your upper level schematic the usual way. The contents of each .SUBCKT file is dumped into the main netlist. Inspect your netlist visually using a text editor to ensure that it is correct. It is a good idea to pay particular attention to the following:</div>
635 <ul>
636 <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>
637 </li>
638 <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>
639 </li>
640 </ul>
641 </li>
642 </ol>
645 Once the netlist is created, you may simulate your design using any SPICE simulator desired.<br/>
647 </p>
650 One final note: The netlister writes the contents of the lower level .SUBCKT file into the main netlist <strong>every time</strong> it encounters a component with “FILE” attribute pointing to that file. Therefore, if you use the same component with the same model more than once in a design you should instantiate the model file using a “spice-model” symbol and point to it with each component. This is described in the “multi-line SPICE model block” section above.
651 </p>
653 </div>
654 <!-- SECTION "Handling hierarchical models" [18698-23545] -->
655 <h2><a name="spice_netlist_generation" id="spice_netlist_generation">SPICE netlist generation</a></h2>
656 <div class="level2">
659 Once the schematic is captured, a SPICE netlist can be generated running the gEDA utility “gnetlist” on the schematic files. Gnetlist is built to be customizable, and is able to generate a netlist of any desired format using a Scheme back-end, which does the real heavy-lifting of creating the netlist. The back-end Scheme file which implements SPICE netlisting is called gnet-spice-sdb.scm, and it lives in the ${PREFIX}/geda/share/gEDA/scheme directory.
660 </p>
662 </div>
663 <!-- SECTION "SPICE netlist generation" [23546-24039] -->
664 <h2><a name="creating_the_netlist" id="creating_the_netlist">Creating the netlist</a></h2>
665 <div class="level2">
668 Creating a netlist from a schematic is easy. To generate a SPICE netlist, just do the following:
669 </p>
670 <ul>
671 <li class="level1"><div class="li"> Save your schematic to &lt;filename.sch&gt;</div>
672 </li>
673 <li class="level1"><div class="li"> Create the SPICE netlist by doing “gnetlist –g spice-sdb &lt;filename.sch&gt;&quot;. The output is a netlist held in the file output.net. Alternatively, if you wish to give your output file a different name, set the output name using the -o switch. For example:<br/>
674 <br/>
675 <strong><code>gnetlist -g spice-sdb -o amplifier.cir amplifier.sch</code></strong> <br/>
676 <br/>
677 takes the design schematic called “amplifier.sch” and outputs a SPICE netlist named “amplifier.cir”.</div>
678 </li>
679 <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>
680 </li>
681 </ul>
683 </div>
684 <!-- SECTION "Creating the netlist" [24040-24765] -->
685 <h2><a name="common_netlisting_problems" id="common_netlisting_problems">Common netlisting problems</a></h2>
686 <div class="level2">
689 It is important to manually inspect your SPICE netlist prior to using it in simulation. Please remember that the netlister is still “alpha” quality, and some problems may still exist in netlist generation. The following list attempts to catalog common problems with the netlist and the associated fixes.
690 </p>
691 <ul>
692 <li class="level1"><div class="li"> ERROR_INVALID_<acronym title="Personal Identification Number">PIN</acronym>: This can happen if the symbol’s PINSEQ attributes don’t start at 1, or have gaps in the numbering. This must be fixed by editing the symbol itself in a text editor.</div>
693 </li>
694 </ul>
696 </div>
697 <!-- SECTION "Common netlisting problems" [24766-25301] -->
698 <h2><a name="spice_simulation" id="spice_simulation">SPICE simulation</a></h2>
699 <div class="level2">
702 There are several options for doing SPICE simulations under Linux; I will highlight two:
703 </p>
704 <ul>
705 <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. LTSpice has been tweaked to run under Linux using wine; I recommend using it if you need a robust, <strong>professional-quality</strong> SPICE simulator.</div>
706 <ul>
707 <li class="level2"><div class="li"> <strong>Ngspice/tclspice</strong>, which is a component of the gEDA distribution. Ngspice provides a simulation engine, a command-line driven front-end, and the capability to plot simulation results graphically under X. The main branch of ngspice development has been arrested since late 2001. However, a fork of the development tree, called “tclspice”, remains under active development. Tclspice is the package I recommend if you want to use a <strong>Linux-native</strong> SPICE simulator. </div>
708 </li>
709 </ul>
710 </li>
711 </ul>
714 There is also a <acronym title="GNU General Public License">GPL</acronym>‘ed simulator called “gnucap”, which is based upon (or is the descendent of) Al’s Circuit Simulator (ACS). I haven’t used it at all; information about gnucap is therefore TBD.
715 </p>
717 </div>
718 <!-- SECTION "SPICE simulation" [25302-26547] -->
719 <h3><a name="ltspice" id="ltspice">LTSpice</a></h3>
720 <div class="level3">
723 LTSpice was written by Mike Englehardt at Linear Technologies, and was originally given away by LinearTech as a design aid for engineers wishing to simulate the performance of LinearTech’s switch mode power supply controllers. The package incorporates a schematic capture front end, fast and powerful SPICE engine, and the capability for plotting the results of many different types of SPICE analysis. Personally, I think the schematic capture front-end is hard to use and clunky; gschem knocks its socks off for ease of use and features. However, the SPICE engine and analysis stuff in LTSpice is simply great.<br/>
724 LTSpice was originally developed to run under Windows, but Mike has tweaked it so that it runs fairly well on Linux under wine. (Only the help menu system is broken &ndash; the rest of the package runs well.) Another good feature of LTSpice is that it is well supported &ndash; Mike reads the newsgroup sci.electronics.cad 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.
725 </p>
727 </div>
729 <h4><a name="installation_and_configuration_of_ltspice" id="installation_and_configuration_of_ltspice">Installation and configuration of LTSpice</a></h4>
730 <div class="level4">
733 To install and configure LTSpice, do the following:
734 </p>
735 <ol>
736 <li class="level1"><div class="li"> Download and install wine. I have had success using Wine-20030219.</div>
737 </li>
738 <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>
739 </li>
740 <li class="level1"><div class="li"> Run the LTSpice installer under wine.</div>
741 </li>
742 </ol>
744 </div>
746 <h4><a name="running_ltspice_with_geda_designs" id="running_ltspice_with_geda_designs">Running LTSpice with gEDA designs</a></h4>
747 <div class="level4">
750 LTSpice can read a file holding a gEDA SPICE netlist. I have had success doing LTSpice sumulations in the following way:
751 </p>
752 <ol>
753 <li class="level1"><div class="li"> First of all, make sure that you are logged in as a normal user &ndash; Wine doesn’t like to run when invoked by root.</div>
754 </li>
755 <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>
756 </li>
757 <li class="level1"><div class="li"> Place a SPICE include block into your schematic. For the file attribute, type in “Simulation.cmd”.</div>
758 </li>
759 <li class="level1"><div class="li"> Netlist your design.</div>
760 </li>
761 <li class="level1"><div class="li"> Create a link from your netlist “output.net” and a netlist in the directory in which SwCADIII lives. Make the netlist suffix .cir. For example: ln -s ${DESIGN_HOME}/output.net ${WINE_HOME}/.wine/fake_windows/Program Files/LTC/SwCADIII/MyDesign.cir</div>
762 </li>
763 <li class="level1"><div class="li"> Run LTSpice: cd into the directory where SwCADIII lives and say “wine scad3.exe”</div>
764 </li>
765 <li class="level1"><div class="li"> From the SwCADIII <acronym title="Graphical User Interface">GUI</acronym>, do: File &rarr; Open &rarr; (files of type netlist [.cir]), and select your file.</div>
766 </li>
767 <li class="level1"><div class="li"> Run the simulator by clicking on the run button, or doing: Simulate &rarr; Run.</div>
768 </li>
769 <li class="level1"><div class="li"> Select the variables to graph, and then click OK. SwCADIII does the rest of the work.</div>
770 </li>
771 </ol>
774 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.
775 </p>
777 </div>
778 <!-- SECTION "LTSpice" [26548-29363] -->
779 <h3><a name="ngspice_and_tclspice" id="ngspice_and_tclspice">Ngspice and tclspice</a></h3>
780 <div class="level3">
783 Ngspice was started at the University of Rome by Paolo Nenzi as an attempt to create a <acronym title="GNU General Public License">GPL</acronym>‘ed version of the standard Berkeley SPICE version 3 by re-writing the entire SPICE package. Plans were also laid to create better, more robust computational algorithms for the simulation engine. More information is available at the <a href="http://ngspice.sourceforge.net/" class="urlextern" title="http://ngspice.sourceforge.net/" rel="nofollow">ngspice website</a>. Unfortunately, development on ngspice seems to have ceased at the end of 2001. Moreover, my initial experiences with ngspice were not good &ndash; it crashed and burned when run on many of my netlists, and it couldn’t deal with SPICE 2’s POLY construct in dependent sources. Dependent sources with PLOY attributes are common in vendor models, so this represents a real deficiency.
784 </p>
787 Fortunately, some friendly people at <a href="http://www.multigig.com/" class="urlextern" title="http://www.multigig.com" rel="nofollow">MultiGig Ltd.</a> were busy developing a branch of ngspice which they called “tclspice”. The purpose of tclspice is to enable SPICE commands to be embedded into TCL scripts, thereby enabling automated circuit optimization. The project homepage is at <a href="http://tclspice.sourceforge.net/" class="urlextern" title="http://tclspice.sourceforge.net/" rel="nofollow">http://tclspice.sourceforge.net/</a>. Since the tclspice branch of the code was alive, I decided to work on it, instead of the seemingly dead main ngspice branch. During spring 2003, I fixed tclspice in three useful (IMNSHO) ways:
788 </p>
789 <ol>
790 <li class="level1"><div class="li"> I fixed the parser so that it would handle netnames with non-numeric/non-alphabetic characters like &quot;+&quot; or &quot;-&quot; which are common in real netlists (e.g. “Vin+&quot;, or “Vout1_pull-up”).</div>
791 </li>
792 <li class="level1"><div class="li"> I fixed the parser so that it would correctly handle hierarchical schematics, and correctly deal with the netnames inside the blocks.</div>
793 </li>
794 <li class="level1"><div class="li"> I got the POLY translation code (which exists in XSPICE) working so that one can now run SPICE 2 netlists with tclspice.</div>
795 </li>
796 </ol>
799 Tclspice seems to work nicely now (although there are still some issues with memory leaks). Moreover, because the tclspice code is a superset of ngspice, <strong>if you build tclspice, you will also build the command-line driven ngspice program</strong>. Therefore, I recommend getting and installing tclspice if you want to do Linux-native SPICE simulations.
800 </p>
802 </div>
804 <h4><a name="installation_and_configuration_of_ngspice_and_tclspice" id="installation_and_configuration_of_ngspice_and_tclspice">Installation and configuration of ngspice and tclspice</a></h4>
805 <div class="level4">
808 To install ngspice and tclspice, do the following:
809 </p>
810 <ol>
811 <li class="level1"><div class="li"> Get the latest tclspice distribution from <a href="http://tclspice.sourceforge.net/" class="urlextern" title="http://tclspice.sourceforge.net/" rel="nofollow">http://tclspice.sourceforge.net/</a>. As of this writing, the latest version is tclspice-0.2.12. This version incorporates the fixes I mentioned above, as well as other improvements made by the hard-working people at MultiGig, so make sure that your version is equal or greater than 0.2.12.</div>
812 </li>
813 <li class="level1"><div class="li"> Do the usual “gunzip ; tar -xvf” dance to create a source directory for tclspice.</div>
814 </li>
815 <li class="level1"><div class="li"> First build ngspice. Do &quot;./configure &ndash;enable-xspice &ndash;prefix=/usr/local/geda” in the source directory. Of course, &quot;&ndash;prefix=&quot; should point to the place where you put your geda stuff. Note that you also must do &quot;&ndash;enable-xspice” to be able to use SPICE 2 POLYs (and other XSpice goodies).</div>
816 </li>
817 <li class="level1"><div class="li"> Do “make &amp;&amp; make install” to compile and install ngspice. As always, you will probably need to be root in order to install the packages in a public directory.</div>
818 </li>
819 <li class="level1"><div class="li"> At this point, you should be able to use ngspice. You can test your installation by trying one of the test circuits held in the tests directory. I recommend running the TransImpedanceAmp test, since it tests the SPICE2 POLY functionality. Information how to use ngspice is provided in the next section below.</div>
820 </li>
821 <li class="level1"><div class="li"> If you only want to use ngspice, you can stop now. Otherwise, next build tclspice. To build tclspice, you need to have the following other packages already installed:<br/>
822 <br/>
823 * TclX (tclx8.3.5 works for me.)<br/>
824 * tclreadline (tclreadline-2.1.0 works for me.)<br/>
825 * BLT for TCL (blt2.4z works for me.)<br/>
826 <br/>
827 If you don’t have these packages already on your Linux box, you need to get them and build them. Note that building TclX requires having the sources for TCL and Tk, so you will also need to get those sources if you don’t have them installed already. I am running successfully with TCL/Tk 8.4.3, although 8.3.X versions are also supposed to work.</div>
828 </li>
829 <li class="level1"><div class="li"> Assuming you have gotten the additional packages mentioned above installed, Do &quot;./configure &ndash;enable-xspice &ndash;prefix=/usr/local/geda &ndash;enable-tcl &ndash;enable-experimental &ndash;disable-shared” to configure the Makefiles for tclspice. (If you don’t have the additional packages installed correctly , configure will complain and barf, so this step acts as a check on your installation.)</div>
830 </li>
831 <li class="level1"><div class="li"> Do “make tcl &amp;&amp; make install-tcl” to compile and install tclspice.</div>
832 </li>
833 <li class="level1"><div class="li"> Now you will be ready to write TCL scripts which incorporate SPICE commands. Information about using tclspice is given below.</div>
834 </li>
835 </ol>
838 Finally, if you are interested in hacking tclspice (or even if you are not), it’s a good idea to read the NOTES file living in the top source directory for a couple of useful pointers.
839 </p>
841 </div>
843 <h4><a name="use_of_ngspice" id="use_of_ngspice">Use of ngspice</a></h4>
844 <div class="level4">
847 Running ngspice is very simple. Just issue the command “ngspice filename.net” at the unix command prompt, and ngspice will load the SPICE netlist called “filename.net” 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>.<br/>
848 To make use of the SPICE2 POLY codemodel, you need to load it into ngspice <strong>before</strong> you load your netlist. (If you load it after loading your netlist, POLYs in your netlist are not translated, and therefore won’t be simulated correctly.) To load the codemodel, just say “codemodel /usr/local/src/tclspice-0.2.12/src/xspice/icm/spice2poly.cm” at the ngspice prompt. Note that you must provide the <strong>absolute path</strong> to the location of the codemodel; ngspice isn’t smart enough to look for it in any default locations. (Also note that you should specify the location where spice2poly.cm lives on your machine; the path above is for mine.)<br/>
849 A better way to read in the spice2poly codemodel is to include it in the ngspice initialization file, “spinit”. The initialization file lives in the directory /usr/local/geda/share/ng-spice-rework/scripts (or where ever you placed your geda installation). Other ngspice customizations may also be placed into the spinit file.
850 </p>
852 </div>
854 <h4><a name="use_of_tclspice" id="use_of_tclspice">Use of tclspice</a></h4>
855 <div class="level4">
858 The tclspice package is a superset of ngspice. Not only does the package include the ngspice interactive environment; tclspice also provides a facility which exports the ngspice command set as TCL commands for inclusion into a TCL script. 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.<br/>
859 To use tclspice, you just need to say “package require spice” at the beginning of your TCL program. Thereafter, to invoke a SPICE command, you just call it in the spice namesapce. 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:
860 </p>
861 <pre class="code">#! tclsh
862 package require spice
863 spice::codemodel /usr/local/src/tclspice-0.2.12/src/xspice/icm/spice2poly.cm
865 spice::source netlistname.cir
866 spice::tran 0.1ns 40ns
867 spice::run
868 spice::plot Vout
869 puts &quot;All done now!&quot;</pre>
872 Note that since tclspice doesn’t read the ngspice initialization file “spinit”, 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>.<br/>
873 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.<br/>
874 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 TaskMgr.tcl 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 TaskMgr.tcl program is shown here:
875 </p>
876 <pre class="code">#! tclsh
877 package require Tclx
878 while {1} {
880 set PID [fork]
881 if {$PID} {
883 # Parent
884 after 300000
885 puts &quot;About to kill child PID = $PID . . . .&quot;
886 kill $PID
887 wait $PID
889 } else {
891 # Child
892 source Optimize.tcl
893 # If we ever get through this, we can print out the following:
894 error &quot;We are done now!!!!!!&quot;
898 }</pre>
901 Note that TaskMgr.tcl needs the TclX package you already installed to run tclspice. Also, you may want to change the wait time to a different value depending upon the memory and speed of your machine. Finally, the parent has to wait on $PID because that causes the child process’s corpse to be taken off the Linux kernal’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 &ndash; a long optimization could turn your system into “the night of the living dead”!<br/>
902 This method of waiting a specific amout of time for the child process is preferable if a single analysis run takes a relativly 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.
903 </p>
905 </div>
906 <!-- SECTION "Ngspice and tclspice" [29364-40393] -->
907 <h2><a name="appendix" id="appendix">Appendix</a></h2>
908 <div class="level2">
910 </div>
911 <!-- SECTION "Appendix" [40394-40415] -->
912 <h3><a name="component_attribute_summary" id="component_attribute_summary">Component attribute summary</a></h3>
913 <div class="level3">
916 Native components and their attributes are given in the table below. <strong>Bold faced</strong> attributes are <strong>required</strong>, normal typeface attributes are optional. Note that the “device” 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 gschem.
917 </p>
918 <table class="inline">
919 <tr>
920 <th><strong><code>device</code></strong></th><th><strong><code>refdes</code></strong></th><th><strong><code>value</code></strong></th><th><strong><code>model</code></strong></th><th><strong><code>file</code></strong></th><th><strong><code>model-name</code></strong></th><th><strong><code>type</code></strong></th><th>Comment</th>
921 </tr>
922 <tr>
923 <td><strong>RESISTOR</strong></td><td><strong>R?</strong></td><td><strong>Numeric comp. value</strong></td><td>One line of spice model parameters (e.g. TC)</td><td> </td><td>Name of model.</td><td> </td><td>“model” parameters are placed inside parentheses after the component value.</td>
924 </tr>
925 <tr>
926 <td><strong>CAPACITOR</strong></td><td><strong>C?</strong></td><td><strong>Numeric comp. value</strong></td><td>One line of spice model parameters (e.g. IC, POLY, etc.)</td><td> </td><td>Name of model.</td><td> </td><td>“model” parameters are placed inside parentheses after the component value.</td>
927 </tr>
928 <tr>
929 <td><strong>POLARIZED_CAPACITOR</strong></td><td><strong>C?</strong></td><td><strong>Numeric comp. value</strong></td><td>One line of spice model parameters (e.g. IC, POLY, etc.)</td><td> </td><td>Name of model.</td><td> </td><td>“model” parameters are placed inside parentheses after the component value.</td>
930 </tr>
931 <tr>
932 <td><strong>INDUCTOR</strong></td><td><strong>L?</strong></td><td><strong>Numeric comp. value</strong></td><td>One line of spice model parameters (e.g. IC, POLY, etc.)</td><td> </td><td>Name of model.</td><td> </td><td>“model” parameters are placed inside parentheses after the component value.</td>
933 </tr>
934 <tr>
935 <td><strong>SPICE-ccvs</strong></td><td><strong>H?</strong></td><td><strong>String describing source behavior</strong></td><td> </td><td> </td><td> </td><td> </td><td> </td>
936 </tr>
937 <tr>
938 <td><strong>SPICE-cccs</strong></td><td><strong>F?</strong></td><td><strong>String describing source behavior</strong></td><td> </td><td> </td><td> </td><td> </td><td> </td>
939 </tr>
940 <tr>
941 <td><strong>SPICE-vcvs</strong></td><td><strong>E?</strong></td><td><strong>String describing source behavior</strong></td><td> </td><td> </td><td> </td><td> </td><td> </td>
942 </tr>
943 <tr>
944 <td><strong>SPICE-vccs</strong></td><td><strong>G?</strong></td><td><strong>String describing source behavior</strong></td><td> </td><td> </td><td> </td><td> </td><td> </td>
945 </tr>
946 <tr>
947 <td><strong>SPICE-nullor</strong></td><td><strong>E?</strong></td><td><strong>String describing source behavior</strong></td><td> </td><td> </td><td> </td><td> </td><td> </td>
948 </tr>
949 <tr>
950 <td><strong>DIODE</strong></td><td><strong>D?</strong></td><td>Part number</td><td>One line SPICE model.</td><td>Model file name.</td><td><strong>Name of model.</strong></td><td> </td><td>For modeling, one must include either “model” or “file”.</td>
951 </tr>
952 <tr>
953 <td><strong>PMOS_TRANSISTOR</strong></td><td><strong>M?</strong></td><td>Part number</td><td>One line SPICE model.</td><td>Model file name.</td><td><strong>Name of model.</strong></td><td> </td><td>For modeling, one must include either “model” or “file”.</td>
954 </tr>
955 <tr>
956 <td><strong>NMOS_TRANSISTOR</strong></td><td><strong>M?</strong></td><td>Part number</td><td>One line SPICE model.</td><td>Model file name.</td><td><strong>Name of model.</strong></td><td> </td><td>For modeling, one must include either “model” or “file”.</td>
957 </tr>
958 <tr>
959 <td><strong>PNP_TRANSISTOR</strong></td><td><strong>Q?</strong></td><td>Part number</td><td>One line SPICE model.</td><td>Model file name.</td><td><strong>Name of model.</strong></td><td> </td><td>For modeling, one must include either “model” or “file”.</td>
960 </tr>
961 <tr>
962 <td><strong>NPN_TRANSISTOR</strong></td><td><strong>Q?</strong></td><td>Part number</td><td>One line SPICE model.</td><td>Model file name.</td><td><strong>Name of model.</strong></td><td> </td><td>For modeling, one must include either “model” or “file”.</td>
963 </tr>
964 <tr>
965 <td><strong>PFET_TRANSISTOR (JFET)</strong></td><td><strong>J?</strong></td><td>Part number</td><td>One line SPICE model.</td><td>Model file name.</td><td><strong>Name of model.</strong></td><td> </td><td>For modeling, one must include either “model” or “file”.</td>
966 </tr>
967 <tr>
968 <td><strong>NFET_TRANSISTOR (JFET)</strong></td><td><strong>J?</strong></td><td>Part number</td><td>One line SPICE model.</td><td>Model file name.</td><td><strong>Name of model.</strong></td><td> </td><td>For modeling, one must include either “model” or “file”.</td>
969 </tr>
970 <tr>
971 <td><strong>MESFET_TRANSISTOR</strong></td><td><strong>B?</strong></td><td>Part number</td><td>One line SPICE model.</td><td>Model file name.</td><td><strong>Name of model.</strong></td><td> </td><td>For modeling, one must include either “model” or “file”.</td>
972 </tr>
973 <tr>
974 <td><strong>IC</strong></td><td><strong>U?</strong></td><td>Part number</td><td>One line SPICE model.</td><td>Model file name.</td><td><strong>Name of model.</strong></td><td> </td><td>IC with .MODEL file</td>
975 </tr>
976 <tr>
977 <td><strong>IC</strong></td><td><strong>X?</strong></td><td>Part number</td><td> </td><td>Model file name.</td><td><strong>Name of model.</strong></td><td> </td><td>IC with .SUBCKT file</td>
978 </tr>
979 <tr>
980 <td><strong>model</strong></td><td colspan="2"><strong>A?</strong></td><td>One line spice model</td><td>Model file name.</td><td><strong>Name of model pointed to by other components.</strong></td><td><strong>Corresponding SPICE model type (valid types given below)</strong>.</td><td>For modeling, one must include either “model” or “file”.</td>
981 </tr>
982 <tr>
983 <td><strong>include</strong></td><td><strong>A?</strong></td><td> </td><td> </td><td><strong>Include file name.</strong></td><td> </td><td> </td><td>Places .INCLUDE directive in SPICE netlist.</td>
984 </tr>
985 <tr>
986 <td><strong>options</strong></td><td><strong>A?</strong></td><td><strong>Line of options to include.</strong></td><td> </td><td> </td><td> </td><td> </td><td>Places .OPTIONS directive in SPICE netlist.</td>
987 </tr>
988 <tr>
989 <td><strong>directive</strong></td><td><strong>A?</strong></td><td><strong>One line string holding SPICE statements for inclusion in netlist.</strong></td><td> </td><td> </td><td> </td><td> </td><td>For modeling, one must include either “model” or “file”.</td>
990 </tr>
991 <tr>
992 <td><strong>VOLTAGE_SOURCE</strong></td><td><strong>V?</strong></td><td><strong>One line string holding voltage source behavior.</strong></td><td> </td><td> </td><td> </td><td> </td><td>Independent voltage source</td>
993 </tr>
994 <tr>
995 <td><strong>CURRENT_SOURCE</strong></td><td><strong>I?</strong></td><td><strong>One line string holding current source behavior.</strong></td><td> </td><td> </td><td> </td><td> </td><td>Independent current source</td>
996 </tr>
997 </table>
1000 “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.
1001 </p>
1003 </div>
1004 <!-- SECTION "Component attribute summary" [40416-45184] -->
1005 <h3><a name="valid_type_values" id="valid_type_values">Valid &quot;type&quot; values</a></h3>
1006 <div class="level3">
1009 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:
1010 </p>
1011 <table class="inline">
1012 <tr>
1013 <th>Component</th><th>“type”</th><th>Comment</th>
1014 </tr>
1015 <tr>
1016 <td>RESISTOR</td><td>RES</td><td> </td>
1017 </tr>
1018 <tr>
1019 <td>CAPACITOR</td><td>CAP</td><td> </td>
1020 </tr>
1021 <tr>
1022 <td>POLARIZED_CAPACITOR</td><td>CAP</td><td> </td>
1023 </tr>
1024 <tr>
1025 <td>INDUCTOR</td><td>IND</td><td> </td>
1026 </tr>
1027 <tr>
1028 <td>DIODE</td><td>D</td><td> </td>
1029 </tr>
1030 <tr>
1031 <td>PMOS_TRANSISTOR</td><td>PMOS</td><td> </td>
1032 </tr>
1033 <tr>
1034 <td>NMOS_TRANSISTOR</td><td>NMOS</td><td> </td>
1035 </tr>
1036 <tr>
1037 <td>PNP_TRANSISTOR</td><td>PNP</td><td> </td>
1038 </tr>
1039 <tr>
1040 <td>NPN_TRANSISTOR</td><td>NPN</td><td> </td>
1041 </tr>
1042 <tr>
1043 <td>PFET_TRANSISTOR</td><td>PJF</td><td> </td>
1044 </tr>
1045 <tr>
1046 <td>NFET_TRANSISTOR</td><td>NJF</td><td> </td>
1047 </tr>
1048 <tr>
1049 <td>MESFET_TRANSISTOR</td><td> </td><td> </td>
1050 </tr>
1051 </table>
1053 </div>
1054 <!-- SECTION "Valid type values" [45185-45703] -->
1055 <h2><a name="document_history" id="document_history">Document History</a></h2>
1056 <div class="level2">
1057 <table class="inline">
1058 <tr>
1059 <td>Revision 1.0</td><td>3.10.2003</td><td>SDB</td><td>Document creation.</td>
1060 </tr>
1061 <tr>
1062 <td>Revision 1.1</td><td>3.19.2003</td><td>SDB</td><td>Added .SUBCKT stuff &amp; stuff about LTSpice</td>
1063 </tr>
1064 <tr>
1065 <td>Revision 1.2</td><td>3.31.2003</td><td>SDB</td><td>Added stuff about creating hierarchical projects (i.e. creating .SUBCKTs using gschem and incorporating a lower level .SUBCKT into a higher level schematic).</td>
1066 </tr>
1067 <tr>
1068 <td>Revision 2.0</td><td>7.23.2003</td><td>SDB</td><td>Split doc into sections. Edited netlisting stuff to correspond to gEDA-20030525, which now includes spice-sdb in the distribution. Added new section about ngspice/tclspice.</td>
1069 </tr>
1070 </table>
1073 The most recent copy of this document is always available at <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>
1074 </p>
1076 </div>
1077 <!-- SECTION "Document History" [45704-] --></div>
1078 </body>
1079 </html>