Update wiki pages
[geda-gaf.git] / docs / wiki / geda-faq-simulation.html
blob79151516e94c756931a32983998e73c8ed3994ce
1 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
2 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
3 <html>
4 <head>
5 <link rel="stylesheet" media="screen" type="text/css" href="./style.css" />
6 <link rel="stylesheet" media="screen" type="text/css" href="./design.css" />
7 <link rel="stylesheet" media="print" type="text/css" href="./print.css" />
9 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
10 </head>
11 <body>
13 <p>
14 <em>Translations of this page are also available in the following languages:</em> <a href="geda-faq-simulation.fr.html" class="wikilink1" title="geda-faq-simulation.fr.html">Français</a>, <a href="geda-faq-simulation.ru.html" class="wikilink1" title="geda-faq-simulation.ru.html">Русский</a>.
15 </p>
17 <h1 class="sectionedit1" id="simulation">Simulation</h1>
18 <div class="level1">
20 </div>
21 <!-- EDIT1 SECTION "Simulation" [150-175] -->
22 <h2 class="sectionedit2" id="i_want_to_simulate_my_analog_circuit_design_what_are_my_options">I want to simulate my analog circuit design. What are my options?</h2>
23 <div class="level2">
25 <p>
26 Within the canonical gEDA Suite apps there are two analog circuit simulators: ngspice and gnucap. In (slightly) more detail:
27 </p>
28 <ul>
29 <li class="level1"><div class="li"> <a href="http://ngspice.sourceforge.net/" class="urlextern" title="http://ngspice.sourceforge.net/" rel="nofollow">Ngspice</a> is a port/clean-up of classical SPICE 3f5 to the GNU/Linux platform. It is fully functional, includes the XSpice extensions (such as SPICE 2 POLY constructs), and the CIDER framework.</div>
30 </li>
31 <li class="level1"><div class="li"> <a href="http://www.gnucap.org/" class="urlextern" title="http://www.gnucap.org/" rel="nofollow">Gnucap</a> is a new circuit simulator written from the ground up. It offers the ability to perform event-driven – as well as continuous time – simulations. It is the work of Al Davis. If you wish to download it, make sure you grab the latest version, available through the “development releases” link on the gnucap website.</div>
32 </li>
33 </ul>
35 <p>
36 Both are CLI (command line interface) programs, meaning that you interact with the simulator by typing commands at a command line. It also means that you need to learn the simulator-specific command set.
37 </p>
39 <p>
40 If you prefer a graphical interface, the new gEDA app GSpiceUI provides a nice <abbr title="Graphical User Interface">GUI</abbr> front-end to drive the simulation programs. However, GSpiceUI is not a complete schematic-to-simulation-output simulator like LTSpice or PSpice. Rather, it just provides a <abbr title="Graphical User Interface">GUI</abbr> menu which helps you navigate the commands you need to perform your ngspice/gnucap simulation.
41 </p>
43 </div>
44 <!-- EDIT2 SECTION "I want to simulate my analog circuit design. What are my options?" [176-1526] -->
45 <h2 class="sectionedit3" id="what_about_tclspice_what_is_it_should_i_use_it">What about tclspice? What is it? Should I use it?</h2>
46 <div class="level2">
48 <p>
49 <a href="http://tclspice.sourceforge.net/" class="urlextern" title="http://tclspice.sourceforge.net/" rel="nofollow">Tclspice</a> was a fork off the ngspice development path. It was begun in the 2002 timeframe. In principle, tclspice would export the SPICE command set to a TCL <abbr title="Application Programming Interface">API</abbr>, allowing you to embed SPICE analyses into a TCL program. This vision is certainly very attractive since TCL is a powerful scripting language – much more powerful than the scripting constructs available from within SPICE itself. Using TCL, one could imagine writing complex circuit optimizers, adding behavioral elements to a simulation, and finally gaining control over SPICE&#039;s graphical output.
50 </p>
52 <p>
53 As it turns out, this goal was partially met – with tclspice you can indeed do something like this:
54 </p>
55 <pre class="code">#! tclsh
56 package require spice
57 spice::codemodel /usr/local/src/tclspice-0.2.12/src/xspice/icm/spice2poly.cm
59 spice::source netlistname.cir
60 spice::tran 0.1ns 40ns
61 spice::run
62 spice::plot Vout
63 puts &quot;All done now!&quot;</pre>
65 <p>
66 Unfortunately, tclspice lacks certain important features, like providing you a return code which tells you whether your simulation actually worked or errored out instead. Also, the graphics functionality never seemed to work (at least for me … and the developers admit that the graphics stink). Converting TCL variables to and from SPICE vectors never seemed to work – again at least for me. Finally, ngspice (at least) has a lot of memory leaks, making long simulation runs difficult. Therefore, tclspice doesn&#039;t meet the promise it originally held out: a convenient, scriptable way to drive SPICE simulations.
67 </p>
69 <p>
70 Development on tclspice effectively stopped in 2004. Perhaps some day somebody will pick it up again. In the meantime, the main <a href="http://ngspice.sourceforge.net/" class="urlextern" title="http://ngspice.sourceforge.net/" rel="nofollow">ngspice</a> development branch has picked up the tclspice features if you want them (they require separate configuration options), and the code is fresher.
71 </p>
73 </div>
74 <!-- EDIT3 SECTION "What about tclspice? What is it? Should I use it?" [1527-3447] -->
75 <h2 class="sectionedit4" id="where_are_the_models">Where are the models?</h2>
76 <div class="level2">
78 <p>
79 There are only very few open source models made available by enthusiasts. This is why there is no extensive library of models included in the gnucap or ngspice package. If you rolled your own and feel like contributing to the project, this would be an excellent opportunity (hint, hint…).
80 </p>
82 <p>
83 Although many manufacturers provide SPICE models free of charge, they keep the license proprietary. This means, that the models can&#039;t be distributed with the gEDA suite. In addition, different implementations of SPICE have slightly different ideas about the correct syntax. As a consequence, some models as supplied by the manufacturer need to be tweaked to work with specific implementation.
84 </p>
86 <p>
87 Spicelib provides a way to receive models tweaked for gnucap and ngspice. It is a set of scripts that will fetch vendors&#039; models directly from the source, solving the redistribution problem. Then it will patch them for compatibility with gnucap and ngspice. You can download spicelib from <a href="http://www.h-renrew.de/h/spicelib/doc/index.html" class="urlextern" title="http://www.h-renrew.de/h/spicelib/doc/index.html" rel="nofollow">http://www.h-renrew.de/h/spicelib/doc/index.html</a>.
88 </p>
90 </div>
91 <!-- EDIT4 SECTION "Where are the models?" [3448-4511] -->
92 <h2 class="sectionedit5" id="isn_t_there_a_nice_graphical_schematic_capture_front_end_so_i_can_just_place_components_and_press_a_simulate_button">Isn&#039;t there a nice graphical (schematic capture) front end so I can just place components and press a &quot;simulate&quot; button?</h2>
93 <div class="level2">
95 <p>
96 No. The best you can do is use <a href="http://www.geda.seul.org/tools/gspiceui/index.html" class="urlextern" title="http://www.geda.seul.org/tools/gspiceui/index.html" rel="nofollow">GSpiceUI</a>.
97 </p>
99 </div>
100 <!-- EDIT5 SECTION "Isn't there a nice graphical (schematic capture) front end so I can just place components and press a simulate button?" [4512-4741] -->
101 <h2 class="sectionedit6" id="how_do_i_create_my_schematic_to_facilitate_analog_simulation">How do I create my schematic to facilitate analog simulation?</h2>
102 <div class="level2">
105 The usual design path is “gschem” → “gnetlist -g spice-sdb” → [“ngspice” | “gnucap”]. You need to attach attributes to the components in your schematic to provide attributes needed by SPICE/Gnucap. You can also attach attributes using gattrib.
106 </p>
109 The <a href="geda-csygas.html" class="wikilink1" title="geda-csygas.html">Circuit Simulation using gEDA and SPICE - HOWTO</a> describes all this in great detail.
110 </p>
113 Some <a href="http://www.brorson.com/gEDA/SPICE/" class="urlextern" title="http://www.brorson.com/gEDA/SPICE/" rel="nofollow">SPICE resources</a> will help you understand how to use spice-sdb.
114 </p>
116 </div>
117 <!-- EDIT6 SECTION "How do I create my schematic to facilitate analog simulation?" [4742-5278] -->
118 <h2 class="sectionedit7" id="which_spice_netlister_backend_to_gnetlist_should_i_use_there_are_several_of_them">Which spice netlister backend to gnetlist should I use? There are several of them. . . .</h2>
119 <div class="level2">
122 Use spice-sdb. It is by far the most advanced and feature rich. The others are there only for reasons of history. Note that spice-sdb is an extension of one of the other SPICE backends, so you aren&#039;t missing anything by using spice-sdb.
123 </p>
125 </div>
126 <!-- EDIT7 SECTION "Which spice netlister backend to gnetlist should I use? There are several of them. . . ." [5279-5617] -->
127 <h2 class="sectionedit8" id="how_about_if_i_want_to_use_gnucap_can_i_use_spice-sdb_to_create_my_gnucap_netlists">How about if I want to use gnucap, can I use spice-sdb to create my gnucap netlists?</h2>
128 <div class="level2">
131 Yes. Also, you can draw your schematic using gnucap directives available in the “spice” symbol directory.
132 </p>
135 It is better to just draw the circuit, without directives, and run the simulator interactively.
136 </p>
138 </div>
139 <!-- EDIT8 SECTION "How about if I want to use gnucap, can I use spice-sdb to create my gnucap netlists?" [5618-5918] -->
140 <h2 class="sectionedit9" id="why_not_reuse_my_simulation_schematic_for_layout">Why not reuse my simulation schematic for layout?</h2>
141 <div class="level2">
144 Newbies commonly want to create a single schematic for both design simulation/validation as well as layout. This vision seems very attractive at first, since your layout will have been tested &amp; validated before committing it to FR-4. However, the devil is in the details; using a single schematic for simulation and layout usually doesn&#039;t work for the following reasons:
145 </p>
146 <ul>
147 <li class="level1"><div class="li"> Components required for simulation and layout are normally very different. For example, simulation often requires a schematic holding a bunch of SPICE-related devices such as voltage sources, dependent sources, SPICE directives, and so on. On the other hand, layout requires non-SPICEable components such as connectors, logic devices, and even things like voltage regulators which might have no SPICE models available, but will pollute your SPICE netlist, possibly making the netlister and the simulator unhappy.</div>
148 </li>
149 <li class="level1"><div class="li"> Some real electronic components don&#039;t have built-in SPICE models. There are plenty of components which don&#039;t have native SPICE models like potentiometers, transformers, thermistors, EMI filters, logic gates, crystals, vacuum tubes, and on and on. Therefore, if your design uses any of these components, you must mock up the device using an equivalent circuit for simulation. This makes it very difficult to reuse the simulation schematic for layout.</div>
150 </li>
151 <li class="level1"><div class="li"> Usually, you only really need to simulate a subset of your design. For example, you might want to simulate the behavior of a filter or oscillator circuit, but don&#039;t care about (or can&#039;t simulate) your power supply, glue logic, or other part of your design. If you insist upon creating a SPICE model for these circuit subsections, you might need to jump through a lot of hoops – and do a lot of unnecessary hard work – in order to find or create SPICE models for parts of your design which aren&#039;t important.</div>
152 </li>
153 </ul>
156 Therefore, I (SDB) normally recommend that you shouldn&#039;t try too hard to use the same schematic for simulation and for layout. If you can do it, great! But usually you can&#039;t.
157 </p>
160 Personally, I tend to create SPICE models of only the critical analog sections of my design. A larger project might therefore have a couple of simulation schematics validating a couple of analog subcircuits. Besides the simulation schematics, I&#039;ll have a main schematic which is used for layout.
161 </p>
163 </div>
164 <!-- EDIT9 SECTION "Why not reuse my simulation schematic for layout?" [5919-] --></body>
165 </html>