1 <!DOCTYPE html PUBLIC
"-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
6 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./style.css" />
7 <link rel=
"stylesheet" media=
"screen" type=
"text/css" href=
"./design.css" />
8 <link rel=
"stylesheet" media=
"print" type=
"text/css" href=
"./print.css" />
10 <meta http-equiv=
"Content-Type" content=
"text/html; charset=utf-8" />
15 <div class=
"tocheader toctoggle" id=
"toc__header">Table of Contents
</div>
16 <div id=
"toc__inside">
19 <li class=
"level1"><div class=
"li"><span class=
"li"><a href=
"#spice_on_geda_howto" class=
"toc">SPICE on gEDA HOWTO
</a></span></div>
21 <li class=
"level2"><div class=
"li"><span class=
"li"><a href=
"#introduction" class=
"toc">Introduction
</a></span></div>
23 <li class=
"level3"><div class=
"li"><span class=
"li"><a href=
"#overview" class=
"toc">Overview
</a></span></div></li>
24 <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>
25 <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>
28 <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>
30 <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>
31 <li class=
"level3"><div class=
"li"><span class=
"li"><a href=
"#spice_file_configuration" class=
"toc">SPICE file configuration
</a></span></div></li>
34 <li class=
"level2"><div class=
"li"><span class=
"li"><a href=
"#schematic_capture" class=
"toc">Schematic capture
</a></span></div>
36 <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>
37 <li class=
"level3"><div class=
"li"><span class=
"li"><a href=
"#handling_hierarchical_models" class=
"toc">Handling hierarchical models
</a></span></div></li>
40 <li class=
"level2"><div class=
"li"><span class=
"li"><a href=
"#spice_netlist_generation" class=
"toc">SPICE netlist generation
</a></span></div></li>
41 <li class=
"level2"><div class=
"li"><span class=
"li"><a href=
"#creating_the_netlist" class=
"toc">Creating the netlist
</a></span></div></li>
42 <li class=
"level2"><div class=
"li"><span class=
"li"><a href=
"#common_netlisting_problems" class=
"toc">Common netlisting problems
</a></span></div></li>
43 <li class=
"level2"><div class=
"li"><span class=
"li"><a href=
"#spice_simulation" class=
"toc">SPICE simulation
</a></span></div>
45 <li class=
"level3"><div class=
"li"><span class=
"li"><a href=
"#ltspice" class=
"toc">LTSpice
</a></span></div></li>
46 <li class=
"level3"><div class=
"li"><span class=
"li"><a href=
"#ngspice_and_tclspice" class=
"toc">Ngspice and tclspice
</a></span></div></li>
49 <li class=
"level2"><div class=
"li"><span class=
"li"><a href=
"#appendix" class=
"toc">Appendix
</a></span></div>
51 <li class=
"level3"><div class=
"li"><span class=
"li"><a href=
"#component_attribute_summary" class=
"toc">Component attribute summary
</a></span></div></li>
52 <li class=
"level3"><div class=
"li"><span class=
"li"><a href=
"#valid_type_values" class=
"toc">Valid
"type
" values
</a></span></div></li>
55 <li class=
"level2"><div class=
"li"><span class=
"li"><a href=
"#document_history" class=
"toc">Document History
</a></span></div></li></ul>
62 <h1><a name=
"spice_on_geda_howto" id=
"spice_on_geda_howto">SPICE on gEDA HOWTO
</a></h1>
66 <!-- SECTION "SPICE on gEDA HOWTO" [1-34] -->
67 <h2><a name=
"introduction" id=
"introduction">Introduction
</a></h2>
71 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.
75 <!-- SECTION "Introduction" [35-708] -->
76 <h3><a name=
"overview" id=
"overview">Overview
</a></h3>
80 From the top level, SPICE simulation in gEDA proceeds via the following steps:
83 <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>
85 <li class=
"level1"><div class=
"li"> Schematic capture using symbols and SPICE models created in step
1.
</div>
87 <li class=
"level1"><div class=
"li"> Netlist generation from the schematic created in step
2.
</div>
89 <li class=
"level1"><div class=
"li"> SPICE simulation of the circuit described by the netlist created in step
3.
</div>
94 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:
97 <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>
99 <li class=
"level1"><div class=
"li"> In attributes manually attached to the component during schematic capture using gschem.
</div>
104 Since there are two places the netlister looks for information, you must make sure that the required information is available in both places.
108 <!-- SECTION "Overview" [709-1877] -->
109 <h3><a name=
"spice-sdb_netlister_installation_and_configuration" id=
"spice-sdb_netlister_installation_and_configuration">Spice-sdb netlister installation and configuration
</a></h3>
113 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.
117 <!-- SECTION "Spice-sdb netlister installation and configuration" [1878-2744] -->
118 <h3><a name=
"design_simulation_flow_summary" id=
"design_simulation_flow_summary">Design/simulation flow summary
</a></h3>
122 The detailed steps required to create a circuit and simulate it with gEDA look like this:
125 <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>
127 <li class=
"level1"><div class=
"li"> Schematic capture using gschem.
</div>
129 <li class=
"level1"><div class=
"li"> Assignment of SPICE attributes (value, model, file, type, etc.) to components using gschem.
</div>
131 <li class=
"level1"><div class=
"li"> Assignment of
<strong><code>refdes
</code></strong> using e.g. refdes_renum.
</div>
133 <li class=
"level1"><div class=
"li"> Creation of netlist using “gnetlist -g spice-sdb”.
</div>
135 <li class=
"level1"><div class=
"li"> Check netlist for correctness (manually open and inspect netlist).
</div>
137 <li class=
"level1"><div class=
"li"> Run spice using a simulator such as LTSpice or ngspice.
</div>
139 <li class=
"level1"><div class=
"li"> Plot/analyze results (often plotting/analysis tools are incorporated in the simulator).
</div>
144 The purpose of this HOWTO is to provide the detailed understanding necessary to successfully navigate this process.
148 <!-- SECTION "Design/simulation flow summary" [2745-3673] -->
149 <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>
153 <!-- SECTION "Preliminary notes about symbols and SPICE model files" [3674-3739] -->
154 <h3><a name=
"symbol_creation_for_spice_netlisting" id=
"symbol_creation_for_spice_netlisting">Symbol creation for SPICE netlisting.
</a></h3>
158 The SPICE netlister recognizes a particular symbol in two ways:
161 <li class=
"level1"><div class=
"li"> The symbol’s “device” attribute
</div>
163 <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>
168 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.txt ↵" class=
"wikilink1">Appendix
</a>.
<br/>
169 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”
→ “down symbol”), and turn on invisible attributes (Edit
→ 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/>
170 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.txt ↵" class=
"wikilink1">Appendix
</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 “device” in your symbols.
174 <!-- SECTION "Symbol creation for SPICE netlisting." [3740-5819] -->
175 <h3><a name=
"spice_file_configuration" id=
"spice_file_configuration">SPICE file configuration
</a></h3>
179 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:
182 <li class=
"level1"><div class=
"li"> It is usually prudent to place these files into a dedicated directory distinct from the symbol directories.
</div>
184 <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>
186 <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>
191 <!-- SECTION "SPICE file configuration" [5820-6689] -->
192 <h2><a name=
"schematic_capture" id=
"schematic_capture">Schematic capture
</a></h2>
196 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.
200 <!-- SECTION "Schematic capture" [6690-7282] -->
201 <h3><a name=
"gschem_attributes_for_spice_netlisting" id=
"gschem_attributes_for_spice_netlisting">Gschem attributes for spice netlisting
</a></h3>
205 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.
210 <h4><a name=
"component_attributes_and_meanings" id=
"component_attributes_and_meanings">Component attributes and meanings
</a></h4>
214 The following attributes are meaningful for SPICE netlisting, and may be attached from within gschem:
216 <table class=
"inline">
218 <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>
221 <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>
224 <td><strong><code>model
</code></strong></td><td>This holds a one line spice model for the component.
</td>
227 <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>
230 <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>
233 <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>
239 <h4><a name=
"refdes_conventions" id=
"refdes_conventions">refdes conventions
</a></h4>
243 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/>
244 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.txt ↵" class=
"wikilink1">Appendix
</a>.
249 <h4><a name=
"passives" id=
"passives">Passives
</a></h4>
254 <h5><a name=
"basic_passives" id=
"basic_passives">Basic passives
</a></h5>
258 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:
260 <table class=
"inline">
262 <td><strong><code>refdes
</code></strong></td><td>The correct
<strong><code>refdes
</code></strong> for the component.
</td>
265 <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>
270 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/>
273 <pre class=
"code">refdes = R2
275 SPICE line generated: R2
0 4 220</pre>
278 Note that “
0” and “
4” correspond to the net nodes connected to the component, and are generated automatically by gnetlist.
<br/>
281 <pre class=
"code">refdes = C22
283 SPICE line generated: C22
4 23 1UF
</pre>
287 <h5><a name=
"passives_with_additional_attributes" id=
"passives_with_additional_attributes">Passives with additional attributes
</a></h5>
291 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:
293 <table class=
"inline">
295 <td><strong><code>refdes
</code></strong></td><td>Correct component
<strong><code>refdes
</code></strong>.
</td>
298 <td><strong><code>value
</code></strong></td><td>Numerical component value, as always.
</td>
301 <td><strong><code>model
</code></strong></td><td>One line string holding additional parameters, formatted as a valid SPICE string.
</td>
306 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/>
309 <pre class=
"code">refdes = R5
311 model = TC=
0.001,
0.015
312 SPICE line generated: R2
0 4 220 TC=
0.001,
0.015</pre>
316 <h4><a name=
"transistors_and_diodes" id=
"transistors_and_diodes">Transistors and diodes
</a></h4>
320 Transistors and diodes are generally accompanied by a device-specific model
– 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:
325 <h5><a name=
"one_line_string_of_spice_parameters" id=
"one_line_string_of_spice_parameters">One line string of SPICE parameters
</a></h5>
329 To incorporate a one line string of SPICE parameters into the netlist, the following attributes must be attached to the component:
331 <table class=
"inline">
333 <td><strong><code>refdes
</code></strong></td><td>Correct component refdes.
</td>
336 <td><strong><code>value
</code></strong></td><td>The model number or part number of the component.
</td>
339 <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>
342 <td><strong><code>model
</code></strong></td><td>One line string holding additional parameters. Do not place the model parameters in parentheses
– gnetlist will do this for you.
</td>
349 <pre class=
"code">refdes = D5
351 model = IS=
0.5UA RS=
6 BV=
5.20
352 SPICE lines generated:
354 MODEL
1N1004 D (IS=
0.5UA RS=
6 BV=
5.20)
</pre>
358 <h5><a name=
"spice_model_file" id=
"spice_model_file">SPICE model file
</a></h5>
362 To incorporate a file-full of SPICE parameters into the netlist, the following attributes must be attached to the component:
364 <table class=
"inline">
366 <td><strong><code>refdes
</code></strong></td><td>Correct component refdes.
</td>
369 <td><strong><code>value
</code></strong></td><td>The model number or part number of the component.
</td>
372 <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>
375 <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>
380 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.
385 <h4><a name=
"actives_--_integrated_circuits" id=
"actives_--_integrated_circuits">Actives -- integrated circuits
</a></h4>
389 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.
394 <h5><a name=
"one_line_string_of_spice_parameters1" id=
"one_line_string_of_spice_parameters1">One line string of SPICE parameters
</a></h5>
398 To incorporate a one line string of SPICE parameters into the netlist, the following attributes must be attached to the component:
400 <table class=
"inline">
402 <td><strong><code>refdes
</code></strong></td><td>Correct component refdes.
</td>
405 <td><strong><code>value
</code></strong></td><td>The model number or part number of the component.
</td>
408 <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>
411 <td><strong><code>model
</code></strong></td><td>One line string holding additional parameters. Do not place the model parameters in parentheses
– gnetlist will do this for you.
</td>
417 <h5><a name=
"spice_.model_or_.subckt_file" id=
"spice_.model_or_.subckt_file">SPICE .MODEL or .SUBCKT file
</a></h5>
421 To incorporate a file-full of SPICE parameters into the netlist, the following attributes must be attached to the component:
423 <table class=
"inline">
425 <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>
428 <td><strong><code>value
</code></strong></td><td>The model number or part number of the component.
</td>
431 <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>
434 <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>
440 <h4><a name=
"independent_sources" id=
"independent_sources">Independent sources
</a></h4>
444 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:
447 <li class=
"level1"><div class=
"li"> Place the independent source on your schematic. (Do “Add”
→ “Component”
→ “spice”
→ "<independent source name
>.sym”)
</div>
449 <li class=
"level1"><div class=
"li"> Double click on the block and add/edit the following attributes:
</div>
451 <li class=
"level2"><div class=
"li"> <strong><code>refdes
</code></strong>: V? or I?
</div>
453 <li class=
"level2"><div class=
"li"> <strong><code>value
</code></strong>: A one line string in SPICE format describing the source.
</div>
461 <h4><a name=
"dependent_sources" id=
"dependent_sources">Dependent sources
</a></h4>
465 There are four dependent sources:
468 <li class=
"level1"><div class=
"li"> This section remains TBD.
</div>
474 <h4><a name=
"spice_components" id=
"spice_components">SPICE components
</a></h4>
479 <h5><a name=
"spice_model_block" id=
"spice_model_block">Spice model block
</a></h5>
483 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:
486 <li class=
"level1"><div class=
"li"> One line SPICE model:
</div>
488 <li class=
"level2"><div class=
"li"> Place a spice model block on your schematic. (Do “Add”
→ “Component”
→ “spice”
→ “spice-model-
1.sym”)
</div>
490 <li class=
"level2"><div class=
"li"> Double click on the block and add/edit the following attributes:
</div>
492 <li class=
"level3"><div class=
"li"> <strong><code>refdes
</code></strong>: a?
</div>
494 <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>
496 <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>
498 <li class=
"level3"><div class=
"li"> <strong><code>value
</code></strong>: The corresponding one-line spice model
</div>
504 <li class=
"level1"><div class=
"li"> Multi-line SPICE model:
</div>
506 <li class=
"level2"><div class=
"li"> Place a spice model block on your schematic.(Do “Add”
→ “Component”
→ “spice”
→ “spice-model-
1.sym”)
</div>
508 <li class=
"level2"><div class=
"li"> Double click on the block and add/edit the following attributes:
</div>
510 <li class=
"level3"><div class=
"li"> <strong><code>refdes
</code></strong>: a?
</div>
512 <li class=
"level3"><div class=
"li"> <strong><code>model-name
</code></strong>: model name
</div>
514 <li class=
"level3"><div class=
"li"> <strong><code>file
</code></strong>: Name of file holding SPICE model code (i.e. .MODEL or .SUBCKT).
</div>
524 <h5><a name=
"include_block" id=
"include_block">Include block
</a></h5>
528 The include block places a .INCLUDE directive into your netlist.
531 <li class=
"level1"><div class=
"li"> Place a spice model block on your schematic. (Do “Add”
→ “Component”
→ “spice”
→ “spice-include-
1.sym”)
</div>
533 <li class=
"level1"><div class=
"li"> Double click on the block and add/edit the following attributes:
</div>
535 <li class=
"level2"><div class=
"li"> <strong><code>refdes
</code></strong>: a?
</div>
537 <li class=
"level2"><div class=
"li"> <strong><code>file
</code></strong>: The name of the file to include.
</div>
545 <h5><a name=
"spice_directive_block" id=
"spice_directive_block">SPICE directive block
</a></h5>
549 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:
552 <li class=
"level1"><div class=
"li"> .TEMP statement
</div>
554 <li class=
"level1"><div class=
"li"> .IC statement
</div>
556 <li class=
"level1"><div class=
"li"> Other SPICE statements for which gschem has no symbol.
</div>
561 To place a SPICE directive on your schematic, do the following:
564 <li class=
"level1"><div class=
"li"> Place a SPICE directive block on your schematic. (Do “Add”
→ “Component”
→ “spice”
→ “spice-directive-
1.sym”)
</div>
566 <li class=
"level1"><div class=
"li"> Double click on the block and add/edit the following attributes:
</div>
568 <li class=
"level2"><div class=
"li"> <strong><code>refdes
</code></strong>: a?
</div>
570 <li class=
"level2"><div class=
"li"> <strong><code>file
</code></strong>: The name of the file to include.
</div>
577 <!-- SECTION "Gschem attributes for spice netlisting" [7283-18697] -->
578 <h3><a name=
"handling_hierarchical_models" id=
"handling_hierarchical_models">Handling hierarchical models
</a></h3>
582 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/>
583 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:
586 <li class=
"level1"><div class=
"li"> Draw the schematic of the lower level component (e.g. the capacitor + parasitics) using gschem.
</div>
588 <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/>
590 <strong><code>model-name
</code></strong> = cap_with_parasitics
<br/>
592 (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>
594 <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>
596 <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/>
598 <strong><code>gnetlist -g spice-sdb -o cap_with_parasitics.cir cap_with_parasitics.sch
</code></strong><br/>
600 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>
602 <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>
604 <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>
606 <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>
608 <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>
610 <li class=
"level2"><div class=
"li"> Using a text editor, give the symbol the “REFDES” attribute “X?
"</div>
614 <li class=
"level1"><div class=
"li"> Create the upper level schematic. Place your newly created symbol on the schematic as many times as required
& wire up the schematic in the usual way.
</div>
616 <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/>
618 <strong><code>file
</code></strong> = cap_with_parasitics.cir
<br/>
619 <strong><code>model-name
</code></strong> = cap_with_parasitics
<br/>
621 as well as any other attributes required (e.g. refdes).
</div>
623 <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>
625 <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>
627 <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>
634 Once the netlist is created, you may simulate your design using any SPICE simulator desired.
<br/>
639 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.
643 <!-- SECTION "Handling hierarchical models" [18698-23545] -->
644 <h2><a name=
"spice_netlist_generation" id=
"spice_netlist_generation">SPICE netlist generation
</a></h2>
648 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.
652 <!-- SECTION "SPICE netlist generation" [23546-24039] -->
653 <h2><a name=
"creating_the_netlist" id=
"creating_the_netlist">Creating the netlist
</a></h2>
657 Creating a netlist from a schematic is easy. To generate a SPICE netlist, just do the following:
660 <li class=
"level1"><div class=
"li"> Save your schematic to
<filename.sch
></div>
662 <li class=
"level1"><div class=
"li"> Create the SPICE netlist by doing “gnetlist –g spice-sdb
<filename.sch
>". 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/>
664 <strong><code>gnetlist -g spice-sdb -o amplifier.cir amplifier.sch
</code></strong> <br/>
666 takes the design schematic called “amplifier.sch” and outputs a SPICE netlist named “amplifier.cir”.
</div>
668 <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>
673 <!-- SECTION "Creating the netlist" [24040-24765] -->
674 <h2><a name=
"common_netlisting_problems" id=
"common_netlisting_problems">Common netlisting problems
</a></h2>
678 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.
681 <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>
686 <!-- SECTION "Common netlisting problems" [24766-25301] -->
687 <h2><a name=
"spice_simulation" id=
"spice_simulation">SPICE simulation
</a></h2>
691 There are several options for doing SPICE simulations under Linux; I will highlight two:
694 <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>
696 <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>
703 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.
707 <!-- SECTION "SPICE simulation" [25302-26547] -->
708 <h3><a name=
"ltspice" id=
"ltspice">LTSpice
</a></h3>
712 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/>
713 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
– the rest of the package runs well.) Another good feature of LTSpice is that it is well supported
– 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.
718 <h4><a name=
"installation_and_configuration_of_ltspice" id=
"installation_and_configuration_of_ltspice">Installation and configuration of LTSpice
</a></h4>
722 To install and configure LTSpice, do the following:
725 <li class=
"level1"><div class=
"li"> Download and install wine. I have had success using Wine-
20030219.
</div>
727 <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>
729 <li class=
"level1"><div class=
"li"> Run the LTSpice installer under wine.
</div>
735 <h4><a name=
"running_ltspice_with_geda_designs" id=
"running_ltspice_with_geda_designs">Running LTSpice with gEDA designs
</a></h4>
739 LTSpice can read a file holding a gEDA SPICE netlist. I have had success doing LTSpice sumulations in the following way:
742 <li class=
"level1"><div class=
"li"> First of all, make sure that you are logged in as a normal user
– Wine doesn’t like to run when invoked by root.
</div>
744 <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>
746 <li class=
"level1"><div class=
"li"> Place a SPICE include block into your schematic. For the file attribute, type in “Simulation.cmd”.
</div>
748 <li class=
"level1"><div class=
"li"> Netlist your design.
</div>
750 <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>
752 <li class=
"level1"><div class=
"li"> Run LTSpice: cd into the directory where SwCADIII lives and say “wine scad3.exe”
</div>
754 <li class=
"level1"><div class=
"li"> From the SwCADIII
<acronym title=
"Graphical User Interface">GUI
</acronym>, do: File
→ Open
→ (files of type netlist [.cir]), and select your file.
</div>
756 <li class=
"level1"><div class=
"li"> Run the simulator by clicking on the run button, or doing: Simulate
→ Run.
</div>
758 <li class=
"level1"><div class=
"li"> Select the variables to graph, and then click OK. SwCADIII does the rest of the work.
</div>
763 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.
767 <!-- SECTION "LTSpice" [26548-29363] -->
768 <h3><a name=
"ngspice_and_tclspice" id=
"ngspice_and_tclspice">Ngspice and tclspice
</a></h3>
772 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
– 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.
776 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:
779 <li class=
"level1"><div class=
"li"> I fixed the parser so that it would handle netnames with non-numeric/non-alphabetic characters like
"+
" or
"-
" which are common in real netlists (e.g. “Vin+
", or “Vout1_pull-up”).
</div>
781 <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>
783 <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>
788 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.
793 <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>
797 To install ngspice and tclspice, do the following:
800 <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>
802 <li class=
"level1"><div class=
"li"> Do the usual “gunzip ; tar -xvf” dance to create a source directory for tclspice.
</div>
804 <li class=
"level1"><div class=
"li"> First build ngspice. Do
"./configure
–enable-xspice
–prefix=/usr/local/geda” in the source directory. Of course,
"–prefix=
" should point to the place where you put your geda stuff. Note that you also must do
"–enable-xspice” to be able to use SPICE
2 POLYs (and other XSpice goodies).
</div>
806 <li class=
"level1"><div class=
"li"> Do “make
&& 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>
808 <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>
810 <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/>
812 * TclX (tclx8.3
.5 works for me.)
<br/>
813 * tclreadline (tclreadline-
2.1.0 works for me.)
<br/>
814 * BLT for TCL (blt2.4z works for me.)
<br/>
816 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>
818 <li class=
"level1"><div class=
"li"> Assuming you have gotten the additional packages mentioned above installed, Do
"./configure
–enable-xspice
–prefix=/usr/local/geda
–enable-tcl
–enable-experimental
–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>
820 <li class=
"level1"><div class=
"li"> Do “make tcl
&& make install-tcl” to compile and install tclspice.
</div>
822 <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>
827 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.
832 <h4><a name=
"use_of_ngspice" id=
"use_of_ngspice">Use of ngspice
</a></h4>
836 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/>
837 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/>
838 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.
843 <h4><a name=
"use_of_tclspice" id=
"use_of_tclspice">Use of tclspice
</a></h4>
847 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/>
848 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:
850 <pre class=
"code">#! tclsh
851 package require spice
852 spice::codemodel /usr/local/src/tclspice-
0.2.12/src/xspice/icm/spice2poly.cm
854 spice::source netlistname.cir
855 spice::tran
0.1ns
40ns
858 puts
"All done now!
"</pre>
861 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/>
862 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/>
863 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:
865 <pre class=
"code">#! tclsh
874 puts
"About to kill child PID = $PID . . . .
"
882 # If we ever get through this, we can print out the following:
883 error
"We are done now!!!!!!
"
890 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
– a long optimization could turn your system into “the night of the living dead”!
<br/>
891 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.
895 <!-- SECTION "Ngspice and tclspice" [29364-40393] -->
896 <h2><a name=
"appendix" id=
"appendix">Appendix
</a></h2>
900 <!-- SECTION "Appendix" [40394-40415] -->
901 <h3><a name=
"component_attribute_summary" id=
"component_attribute_summary">Component attribute summary
</a></h3>
905 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.
907 <table class=
"inline">
909 <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>
912 <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>
915 <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>
918 <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>
921 <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>
924 <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>
927 <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>
930 <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>
933 <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>
936 <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>
939 <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>
942 <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>
945 <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>
948 <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>
951 <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>
954 <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>
957 <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>
960 <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>
963 <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>
966 <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>
969 <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>
972 <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>
975 <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>
978 <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>
981 <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>
984 <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>
989 “Native to the netlister” means that there is a corresponding blob of scheme code which knows exactly how to handle these components and is guaranteed (almost) to generate correct spice code. Symbols having “device” attributes not on the above list are handled using the scheme function “spice-sdb:write-default-component”, which looks at the refdes of the component to make a decision about how to treat the component. In general, this function will “do the right thing” when generating spice code, but it is not guaranteed. In particular, this function cannot distinguish between N and P type transistors, and will generate an
<unknown
> type for the .MODEL string in the netlist. This will probably cause your SPICE simulator to barf. Therefore, it is best to make sure that all devices used have the proper “device” attribute.
993 <!-- SECTION "Component attribute summary" [40416-45184] -->
994 <h3><a name=
"valid_type_values" id=
"valid_type_values">Valid
"type
" values
</a></h3>
998 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:
1000 <table class=
"inline">
1002 <th>Component
</th><th>“type”
</th><th>Comment
</th>
1005 <td>RESISTOR
</td><td>RES
</td><td> </td>
1008 <td>CAPACITOR
</td><td>CAP
</td><td> </td>
1011 <td>POLARIZED_CAPACITOR
</td><td>CAP
</td><td> </td>
1014 <td>INDUCTOR
</td><td>IND
</td><td> </td>
1017 <td>DIODE
</td><td>D
</td><td> </td>
1020 <td>PMOS_TRANSISTOR
</td><td>PMOS
</td><td> </td>
1023 <td>NMOS_TRANSISTOR
</td><td>NMOS
</td><td> </td>
1026 <td>PNP_TRANSISTOR
</td><td>PNP
</td><td> </td>
1029 <td>NPN_TRANSISTOR
</td><td>NPN
</td><td> </td>
1032 <td>PFET_TRANSISTOR
</td><td>PJF
</td><td> </td>
1035 <td>NFET_TRANSISTOR
</td><td>NJF
</td><td> </td>
1038 <td>MESFET_TRANSISTOR
</td><td> </td><td> </td>
1043 <!-- SECTION "Valid type values" [45185-45703] -->
1044 <h2><a name=
"document_history" id=
"document_history">Document History
</a></h2>
1045 <div class=
"level2">
1046 <table class=
"inline">
1048 <td>Revision
1.0</td><td>3.10.2003</td><td>SDB
</td><td>Document creation.
</td>
1051 <td>Revision
1.1</td><td>3.19.2003</td><td>SDB
</td><td>Added .SUBCKT stuff
& stuff about LTSpice
</td>
1054 <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>
1057 <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>
1062 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>
1066 <!-- SECTION "Document History" [45704-] --></body>