1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164
|
<html>
<body>
<h1> 01_dc: sheet preparation and DC op point </h1>
<h2> Scope </h2>
<p>
In this simulation we are going to calculate the DC operating point of a
simple voltage divider. This is also an introduction to setting up a
sheet for circuit simulation. This tutorial deals with differences between
spice implementations by describing the process for ngspice and then any
differences for other implementations are described at the bottom.
<h2> The schematics </h2>
<p>
The single-sheet schematic contains the voltage divider with all networks
named and two extra symbols for the simulation:
<ul>
<li> a 5V voltage source, V1
<li> a spice command symbol
</ul>
<p>
Note: these symbols do not have a footprint attribute so they are not exported
in the PCB workflow.
<p>
<center>
<a href="01_dc.rs"><img src="01_dc.svg" width=400px></a>
<br>Click the image to get the sch-rnd sheet</center>
<p>
<h2> SPICE: what is a DC op point </h2>
<p>
In SPICE simulation there are different <i>analysis</i> options available: these
are different simulation actions or operations or modes. Basically each
analysis is a different algorithm to run on the circuit. The simplest
analysis is called the "DC operating point analysis".
<p>
In the op point analysis, the simulator will apply all sources, assume
all inductors are shorted and assume all capacitors are open and then calculate
the voltage for all nodes. (Node is the spice terminology for an equipotential
electrical network.) This simulation is not time or frequency dependent, and
represents a single DC operating point once the circuit has already stabilized.
<p>
In our example, this means V1's 5V is applied and the voltages at in, out1 and
out2 are calculated. Since V1 is an ideal voltage source capable of supplying
any amount of current, the voltage on the in network will be 5V; but the
voltages on out1 and out2 will depend on the resistor values of R1, R2 and R3.
<h2> Preparing for simulation </h2>
<h3> Symbols and nets </h3>
<p>
Draw the schematics as usual; make sure there is a gnd network, spice won't
work without that. Ideally, use the stock gnd symbol for that. Make sure
all resistors have a unique name and a value. Spice understands the normal
SI suffixes such as k for kilo, but as it is generally not case sensitive,
m and M are both milli, so you will need to write meg to get mega.
<p>
Your symbols also need to have the proper spice pin numbers. First switch
your view from the default pcb to spice_raw: there's a button for this on
the top right part of the main window, on the left of the help/support button.
This pops up a view selector; click raw_spice twice and the selector will close
and the view will change. The new view will show pin numbers as seen by the
spice target. For plain resistors, pin ordering does not matter, but it is
important for polarized parts like diodes, transistors, and sources. The
stock library has spice pin numbers set up and should work without
modification. Later chapters of this tutorial will explain how to deal with
spice pin numbers in symbols.
<h3> V1 </h3>
<p>
In the raw spice approach, the voltage source needs to be specified in the
concrete model. The easiest way is to place a source-DC symbol from the
stock library in between the <i>in</i> network and the ground. The name
of the symbol does not matter; as we are using it as a voltage source,
it is best to name it V1. To make it produce a steady 5V output, create
an attribute called <i>spice/params</i> and set it to <i>DC 5V</i>. It is
also a good idea to make this visible in the form of a floater.
<p>
External resource:
<a href="https://ngspice.sourceforge.io/docs/ngspice-html-manual/manual.xhtml#magicparlabel-4120">ngspice manual on voltage and current sources</a> explains all the different parameter options; spice/params is the part that gets written after N-; later chapters will demonstrate using more complex waveforms than plain flat DC.
For a DC operating point we are only interested in the DC component, tho.
<h3> Raw spice commands </h3>
<p>
The circuit is complete. It could be exported and the simulator could read it,
but command to start any simulation would need to be specified by hand, on the
simulator's command line. It is more convenient for now to specify these
commands in the schematics. For that, the spice_command symbol is placed from
the stock library. The actual spice commands are stored in the spice/command
attribute. This is typically a multiline string attribute. Use the attribute
editor (accessible from the right click menu over the symbol), select the
attribute and click on the "edit multiline" button.
<p>
It contains two lines:
<pre>
op
print v(out1) v(out2)
</pre>
<p>
The first line instructs spice to do the "DC operating point analysis",
the second tells it to print the voltage of out1 and the voltage of out2
(each measured to ground) on stdout. You can list more voltages here by
v(netname) and it is possible to print currents and other properties,
as will be shown in later chapters of this tutorial.
<p>
Note: this symbol has no name attribute, so it is not exported as a normal
component.
<h2> Export the netlist </h2>
<p>
GUI export: make sure your view is set to spice_raw, as it affects not only
how the circuit is displayed on the GUI but also how it is exported. Open
the file menu, click on export project (hotkey: {f j}). Select spice in
the export dialog, verify the file name and click the export button.
<p>
CLI export:
<pre>
sch-rnd -x spice --view spice_raw 01_dc.rs
</pre>
<p>
<h2> Run ngspice </h2>
<p>
From a shell run this command (assuming the exported netlist is called 01_dc.cir):
<pre>
ngspice 01_dc.cir
</pre>
<p>
This will print a lot of noise and these two lines:
<pre>
v(out1) = 2.380952e+00
v(out2) = 1.190476e+00
</pre>
<p>
These are the voltages (in V) measured on the networks out1 and out2 in
steady state. Type quit to exit the spice prompt.
<h2> Using other implementations </h2>
<h3> gnucap </h3>
<p>
Gnucap uses a different command syntax. Modify the spice command symbol's
spice/command attribute to:
<pre>
print dc v(out1) v(out2)
dc
</pre>
<p>
This tells gnucap what to print after a dc simulation then runs the dc simulation.
<p>
After the export, write the single word <b>spice</b> in the first line of the
file (e.g. using a text editor), otherwise gnucap won't know the file is in spice
syntax. Then run <i>gnucap 01_dc.cir</i> and it will print (among tons of
noise) the two voltages.
<p>
The <a href="gnucap/01_dc.rs">gnucap-modified schematic is also available.</a>
<h3> xyce </h3>
<p>
TODO
|