Tuesday, January 12, 2010

Spice circuit simulator - part 2

I did it! I made a circuit and I got it to run. I have returned back to Berkeley's 3f5 spice. Using cspice I can input the file circuit.txt:

My first circuit
vcc high 0 dc 10
r1 high bw 3
r2 bw 0 4

This is a very simple circuit with 10v going to a 3 ohm resistor and then a 4 ohm resistor and then back to ground.  10v -- 4ohm -- 3ohm -- gnd

I run this simulation with this command on Windows: cspice.exe < circuit.txt

This results in actual output! Much of this I learned from Berkeley's documentation at http://bwrc.eecs.berkeley.edu/classes/IcBook/SPICE/ under Interactive User Guide. I also referenced Kevin Cosgrove's article 'Analyzing Circuits with SPICE on Linux' at http://www.linuxjournal.com/article/2169.

I am not anywhere near the point of running spice to do transient analyses. I only want very simplistic static results of basic digital circuits. This is what I now feel confident that I can do.

Monday, January 11, 2010

Spice circuit simulator

I'm learning electrical engineering... Pretty tough to understand this stuff, but www.allaboutcircuits.com really helps. Another tool I'm trying to use is a spice simulator. This way I can write tiny circuits and see if I understand what they're supposed to do, and spice can verify that.

Anyhow, I started searching for spice, and that was a bit of a challenge just because of it's name... Google doesn't bring you to what you're looking for directly, so here's a good starting point: http://bwrc.eecs.berkeley.edu/Classes/IcBook/SPICE/ - Homepage
http://bwrc.eecs.berkeley.edu/Classes/IcBook/tools.html - List of available spice simulators

OK. So which one to download. I like to work as manually as possible to increase my understanding as much as possible, so this meant I wanted a tool that was as much like the UNIX version (I'm on Windows) as possible. I also want a text based tool for now. This led me to download Berkeley's spice3f5.tar.gz, and to figure out how to compile this with Visual C++ 2008. A good starting point is http://rayslogic.com/Spice/compile_berkeley_spice_3f5.htm. I did some things differently from what he listed, but I believe his directions will work too. A tip would be to use GnuWin32's find, xargs, and sed tools to perform the necessary changes to the files. Also when following the /OUT: directions you have to add that line to only the files he listed, otherwise the lib files won't get added correctly. I chose a more generic method of modifying the batch files with something like this in the relevant msc51.bat files:
set LIBNAME=..\..\dev1.lib
if not exist %LIBNAME% set LIBPARAM=/OUT:
lib %LIBPARAM%%LIBNAME% @response.lib >> ..\..\..\msc.out

... After getting it to compile I realize that it doesn't create spice3.exe, and only really creates bspice.exe and cspice.exe. I don't currently know much about spice so I don't really know what those files do for you, but from what I can see they aren't what I was looking for.

At this point I started looking for another alternative. I found ngspice: http://ngspice.sourceforge.net/download.html. The download page is http://sourceforge.net/projects/ngspice/files/. I know it says that they only release sources, but that's not true, download the zip file and you'll see it has Windows binaries. I'm guessing that they never bothered to update that information.

Last thing... Seems that spice uses something referred to as decks (input decks). Trouble is no one bothers to tell you what that is. I am once again positing that this term comes from very old systems that accepted commands on actual cards. Each command was put on a card and the cards were fed into a machine. The combined cards were referred to as decks. I found a reference to cards and decks here: http://www.eecg.toronto.edu/~johns/spice/part1.html. So an input deck seems to just be a set of input commands.

Will update as I learn more. At this point I'm still just a fish flapping around on dry land with regards to spice.