by
Wenton L. Davis
This page is meant to be specific to dealing with eccentricities of GNUcap. If you are looking for more generalized SPICE, please look here.
Nearly all of your questions can be answered in the gnucap-man.pdf
GNUcap is a free circuit analysis program that is available from several different sources, although gnucap.org is the primary source. When you run gnucap, you might notice the message
Never trust any version less than 1.0
in his program's output. The versions used to be up to version 0.35 before other version naming/numbering schemes were adopted, and even after that, the same message leads to output. I have no idea why that message is still there; it just is. The current version (although this may have changed since I wrote this) is "Gnucap 2009.12.07 RCS 26.136" That being said, we'll move on...
By Default, GNUCAP wants to work in interactive mode, making it seem much more like a shell. I guess this is OK, but it gives a bit of a peculiar feel since it's really not a shell; it just kinda has that feel. In this interactive mode, the control cards that typically start with a dot (.) such as .PLOT actually cause errors; the same command in interactive mode would only mb just plain old PLOT... no preceding dot.
Also in interactive mode, you can not directly define components. if you type in "R1 1 2 1K" it responds with "what's this?" So apparently, you still have to define the circuit in a text file, then use the load myfile.ckt to load the circuit. But, I just find it easier to run in batch mode anyway...
Batch mode for gnucap is really simple. Assuming you have the SPICE program written in "mycircuit.ckt," the program is run with the command:
$> gnucap -b mycircuit.ckt
The -b is what tells GNUcap to work in batch mode.
Another peculiarity to using GNUcap is the need for .PRINT OP Iter(0) to be included before any of the other analysis commands. This is a known bug, and it's been around for a long time, so I have to assume there is something about it that is very convoluted in the code to fix. Without using this, GNUcap will sometimes completely refuse to perform any analysis at all. other times, it will pretend to do tha analysis, but nodes will still default to either the maximim (positive or negative) voltage, or to ground.
Several of the SPICE cards (commands) are either not implemented at all, or only partially implemented. This particularly bit me while I was trying to use the B element in the model for a transconductance op-amp circuit because the B element is not implimented at all in GNUcap. This, specifically, is what made me switch over to the far superior (and still free) ngspice tools instead.
Here is GNUcap's user manual.
Now that we can get the output, let's go back and look at that header:
Gnucap 2009.12.07 RCS 26.136 The Gnu Circuit Analysis Package Never trust any version less than 1.0 Copyright 1982-2006, Albert Davis Gnucap comes with ABSOLUTELY NO WARRANTY This is free software, and you are welcome to redistribute it under certain conditions according to the GNU General Public License. See the file "COPYING" for details. .TITLE Lab 5 #Time V(1) V(2) V(3) 50.u 0.80902 0.4542 0.46065 51.u 0.74174 0.42064 0.42672 52.u 0.66601 0.38249 0.38824 53.u 0.58269 0.34017 0.34563 etc...
OK, Dr. Davis, thank you for providing gnucap, and for warning us that it is not a completed project. Now, MAKE THAT MESSAGE GO AWAY!!! No, OK, fine, we'll do it ourselves. We can just use the tail command:
gnucap -b lab5.ckt | tail -n +10
This will throw away the first 9 lines, and continue the text output, beginning with the 10th line.
Next, we might want to translate the Meg, M (milli), u, n, p, and f to their appropriate x10n values. We can use the "stream editor," sed, to search for each of these:
gnucap -b lab5.ckt | tail -n +10 | sed s/Meg/E+06/g | sed s/K/E+03/g | sed s/M/E-03/g | sed s/u/E-06/g | sed s/n/E-09/g | sed s/p/E-12/g | sed s/f/E-15
Yes, it's a lot of typing; either deal with it, or write a script to perform the filtering. But this is still important because we can direct the output to a file, using the `> filename` to save the filtered results to a file. If, for example, you save the output to something called "lab5.out" then you can use gnuplot to plot the output in a much nicer output than the .PLOT command in gnucap will show:
gnuplot> plot 'lab5.out' using 1:4 with lines
will open the file, 'lab5.out' and use column 1 as the X-axis coordinate value and column 4 as the Y-axis coordinate value, and connect the dots with lines. (The default is to use '+' symbols.)
Now that you are all edumicatified in SPICE, you can try it out for yourself! Just go here to try it online!
gnucap setup for Slackware 14.1:
First, download 32-bit
package or 64-bit
package. You can also check
32-bit
slackware pkgs 14.1 site or 64-bit slackware pkgs 14.1 site
for download links.
Then, install the package:
revised Dec 13, 2012: add info about gnuplot
revised Oct 2, 2018: add Slackware 32- and 64-bit packages
revised Feb 28, 2025: be GNUcap-specific, move basic SPICE stuff to
basics.
/root# upgradepkg --install-new gnucap-20091207-i486-1_slack.txz