by
Wenton L. Davis
This page is meant to be specific to dealing with eccentricities of NGSPICE. If you are looking for more generalized SPICE, please look here.
There used to be a very powerful version of SPICE that was created at UC at Berkeley. This version was shared under the name "spice3f5" and was fairly readily available online. Spice3f5 eventually evolved into NGSPICE. It can be downloaded from https://ngspice.sourceforge.io where you can also find compile/install instructions for Windoze and Linux, as well as a pretty decent online beginner's tutorial and the higher-level tutorials top-level page.
NGSPICE is a very powerful implimentation of SPICE that seems to me to be the most fully implimented SPICE I've found so far. That is important in terms of having all the features available from SPICE; some implimentations of SPICE, particularly free versions, seem to leave out some of the capabilities that companies/developers felt were unnecessary. I used to use GNUcap all the time, just because I used it for so long, but while trying to model some transconductance op-amps (OTAs) I found that the B card was not implimented. When I tried to use alternative methods for OTAs, they all lead to dead ends as well. This lead me to look for SPICE alternatives, and NGSPICE seems to fit my needs, better.
However, there is a price to pay. At least it's not a financial price! NGSPICE is pretty powerful to use, but as you might expect, that makes it a little more difficult to use. In GNUcap, once the circuit is defined, you just put in the commands to .PRINT or .PLOT what ever outputs and analysis you want. NGSPICE seems to need a slightly more formalized description of what you want to see, and it is way more demanding in therms of "do it my way or I won't help you!" So here is a little imformation on coping with that...
In the specification for SPICE, there is a .TITLE card that is used, typically as the first card, to identify the name of the circuit. This is usually something fairly simple like "CMOS Inverter" of "Lab 1 Part 3."
NGSPICE seems to be written to simply assume that line 1 is almost always assumed to be a .TITLE card, so the use of the .TITLE command is suddenly optional. NGSPICE seems to be flexible for the first line, and assume (unless it sees something specific) that line 1 is a title/name, with or without the .TITLE command leading it. This allows a somewhat cleaner file: (from the tutorial page mentioned earlier)
CMOS Inverter .include ./bsim4soi/nmos4p0.mod .include ./bsim4soi/pmos4p0.mod .option TEMP=27C Vpower VD 0 1.5 Vgnd VS 0 0 Vgate Ein VS PULSE(0 1.5 100p 50p 50p 200p 500p) MN0 Aus Ein VS VS N1 W=10u L=0.18u MP0 Aus Ein VD VS P1 W=20u L=0.18u .tran 3p 600ps
This is where NGSPICE seems to diverge from pure SPICE a little. NGSPICE seems to need a control section that contains all of the simulation and display information to be formally kept inside it, enclose within .control and .endc cards. Continuing the example started above (again from the earlier mentioned tutorial page)
.control run plot Ein Aus .endc
The indenting is not important, other than making it a little easier to read. The commands for NGSPICE to run the simulation and display the results are required in this .control section.
However, some of their examples do not have the simulation commands inside any .control section. If I include these commands without the .control section, nothing seems to happen (no results displayed), so I clearly don't understand something. It is probably best to include them in the .control section, just as good practice.
Don't forget the .end card. Just don't. It's meaningful to remember that the reason we call these commands "cards" is because SPICE originated at a time where a program was stored as a deck of punch-cards, each with one line of code. Pretty much all programs were required to have and END statement so that the computer know that really was the last card of the deck/program. Since then, most programs no longer require an END statement, and just for legacy support, leave it as an optional statement. NGSPICE does NOT consider this optional, and will generate an error if you leave it out! So, the final example CMOS Inverter file looks like this:
CMOS Inverter .include ./bsim4soi/nmos4p0.mod .include ./bsim4soi/pmos4p0.mod .option TEMP=27C Vpower VD 0 1.5 Vgnd VS 0 0 Vgate Ein VS PULSE(0 1.5 100p 50p 50p 200p 500p) MN0 Aus Ein VS VS N1 W=10u L=0.18u MP0 Aus Ein VD VS P1 W=20u L=0.18u .tran 3p 600ps .control run plot Ein Aus .endc .end
Normally, SPICE, itself does not produce any graphics. Everything is text-mode in SPICE, includeing its output. NGSPICE goes significanly farther, partially because of its roots going back to the older spice3f5. Because spice3f5 had been around for so long, many developers integrated it into larger projects that did include graphics. As an example, on the NGSPICE tutorials page, they specifically suggest using KiCAD for schematic entry.
Many of the examples in the tutorial pages include commands in the .control section that have a remarkably strong resemblance to GNUplot commands:
plot vdb(out) xlimit 1 100K ylabel 'small signal gain'
The beginner's tutorial even shows a specific example showing that in Linux, you might add a .control section:
.control run gnuplot gp v(out) v(in) .endc
There really is very little I can add to the incredible list of resources already online. NGSPICE is far more popular and widely-used than I ever expected. It is also integrated into many other applications.
I think we all joke about RTFM from time to time, but NGSPICE is one that really makes it more important. There are a lot of capabilities and features that require some extra research to use.