Skip to Content

Reading Netlists

I’ve realized that I kind of just assumed everyone knew what those strange grey code boxes were on my posts, which is probably in error. This post is going to be about reading and writing netlists, as well as a little info on SPICE and simulation. While it definitely looks like an archaic language compared to something new and pretty like Python or Swift, there’s nothing yet that beats in terms analog circuitry + command line integration. Of course, design tools like Cadence, Orcad, or ADS have GUI’s that are basically just as powerful, but with a [debateably] nice front end.

SPICE is an acronym for Simulation Program with Integrated Circuit Emphasis. It started off as a FORTRAN based circuit simulator, which takes in a list of circuits, determines the equivalent transfer functions between nodes, and then uses numerical matrix methods to solve for an approximate answer. There’s been a huge number of variants since then, and the one I happen to use is called ngspice. It’s open source, handles mixed signals, and written in C. (I follow the GitHub, and hope to contribute eventually once I get some more familiarity).

Enough background, let’s learn how to read a netlist. A netlist is exactly that, a list of nets, or nodes, in the circuit. All we do is draw the circuit on paper, and label every node. Then we just write each part, it’s value, and the nodes it occupies. Let’s jump into a simple one from before:

* Simple Diode Rectifier

Vin n0 0 SIN(0 3 5 0 0) 
d1 n0 n1 DIODE1
r1 n1 0 5

.tran 2m 1
.print tran v(n0) v(n1) i(Vin)
.end

diode-rect-sch

The line starting with the asterisk is just a comment, and doesn’t do anything. Depending on which version of SPICE you have, the first line could always be interpreted as a comment, so just put one in there to be safe. The next set of lines has our three components: a voltage source, a diode, and a resistor. The format of each line is “Name, Nodes, Parameters”.

As you can see, it’s different for each item. The name tells SPICE a little info - sometimes what kind of part, sometimes nothing. The next two spots on each are the defined nodes. These all get reduced to a table in the simulator, so their names don’t mean anything as long as they’re consistent! The only one that matters is the 0 - that provides our ground reference. Following that, we have the actual part type/value, which finally says exactly what we’re working with.

First, I attached a voltage sine wave source. There’s a lot of options to choose from, but the only ones that matter are the first 3: DC offset, Amplitude, Frequency. The next component is a diode, which is a slightly complex semiconductor device. Since the equations governing that are ugly and complex, I just said to use one of the several models available in ngspice. If I wanted to go, I could individually go in and tune the various parameters and coefficients to get an exact diode. Lastly is the resistor, which is the simplest one. For RLC, all you need to do is put a number, and then either none/H/F as the unit. Again, you can tune the individual component parameters if you want, but I definitely don’t need to for this simple example.

The last part is the analysis lines. All commands start with a . (period) and tell ngspice exactly how we want to simulate the circuit. The one I used here is Transient Analysis, which just tells the circuit to go in the time domain. The rest involve sweeps of some sort, either DC level, AC magnitude, frequency, noise level, distortion, or stability. We then print whatever values we want, here some voltages and currents. Then finally we (literally) end the simulation file.

Since it’s a command line program, it just dumps to terminal, but we can put it wherever we want. There’s a whole lot more to SPICE, like subcircuits and optimizations and plenty else, but this is enough for an intro!