OT: gEDA, SPICE, electronic cad/simulation

Tom Russo russo at bogodyn.org
Sun Oct 28 17:55:18 UTC 2012


Date: Sun, 14 Oct 2012 22:26:34 +1000
From: Da Rock <freebsd-questions at herveybayaustralia.com.au>
Subject: OT: gEDA, SPICE, electronic cad/simulation
> I'm struggling with this damn gEDA/SPICE thing - I think I have gEDA
> schem figured, but I can't be sure because I can't test it. For the life
> of me I can't seem to get my head around it, but then I might just be
> too tired.

> Can anyone point out what I'm missing? I open geda, create a sch file
> (circuit), and then run gnetlist -g spice-sdb <sch-file>. I then run
> ngspice (or gspiceui) but it comes up with errors over the 555 (U1) and
> diodes (d?) I'm running like this:
> 
> Error on line 9 : d1 2 0 unknown
>       unable to find definition of model unknown - default assumed
> Error on line 13 : u1 0 4 3 +9v 1 4 5 +9v unknown
>       unable to find definition of model +9v - default assumed

>       unknown parameter (4)

I see some folks have tried to answer you, but it seems that it's expected
that these models somehow already exist on your system and you're just not
finding them.  That's not the case.

Without seeing the entire netlist, I can't be precise, but there are several
important things to know about SPICE and device models:

1) SPICE provides only the infrastructure for simulating diodes, i.e. a module
   that lets you specify all the parameters of a diode and which will then
   simulate the circuit using the parameters you provide.  A "model" in this
   case means a set of parameters, which is specified in a .model "card".

   Basically, your schematic has defined a diode without telling the simulator
   the name of a model card to look for, so gnetlist has inserted "unknown" as
   the model name.  You then did not provide a ".model unknown d" card to define
   "unknown" as a diode model.

   No open-source SPICE-like simulator provides model "cards" for common 
   devices.  You either have to find one from a manufacturer's web site, 
   find one someone has posted on a web site somewhere, or extract the 
   relevant parameters yourself (this list sorted in order of increasing 
   complexity).  Commercial spice packages do come with enormous model,
   libraries, but you pay big, big bucks for those versions.

   Werner Hoch wrote a system called "spicelib" for gEDA that attempts to
   download a large number of spice-compatible models from vendor web sites
   and massage them to work with ng-spice.  I have run it once, and found that
   it needed a little patching up to make it work on FreeBSD instead of Linux
   (for example, the "md5sum" program is used througout, and this doesn't 
   exist on BSD --- I had to hand-edit scripts all over the place to make it
   use md5 instead).  Even so, there are few basic parts in these model 
   libraries.  

   Once in a while I have found cool web sites with hundreds of spice models
   for common discrete parts.  They disappear after a year or five.

   You *COULD* try adding ".model unknown d" to your netlist to let ng-spice
   use all the default parameters for the diode.  It might not work well, but
   it *will* shut up the error.  It's what SPICE wound up doing itself when
   it couldn't find the model named "unknown."

   For details about spice diode models, see, for example, 
http://www.acsu.buffalo.edu/~wie/applet/spice_pndiode/spice_diode_table.html

2) There is no 555 model in SPICE, ng-spice, or any other spice.  Such devices
   are always simulated by creating a subcircuit model (.subckt).  gschem will
   gleefully create a line in your netlist for such a device, but unless you
   also provide a subcircuit model for it, you won't be able to  simulate it, 
   no way, no how.  ng-spice does NOT come with a 555 subcircuit model, nor 
   does geda/gschem.  gschem merely provides a symbol for such a device.

   Try googling for "spice 555 model subcircuit" and go from there.  One post
   in the thread on this site:
 http://www.electro-tech-online.com/general-electronics-chat/5806-spice-555-timer.html
   has a UA555 subcircuit model that you may be able to use, if you make sure
   that the subcircuit "pins" match the pins gschem/gnetlist are assigning.

3) SPICE (and ng-spice) always uses the first character of a device line to 
   determine the type of the device.  While most designers will draw a 
   circuit with an IC in it and give the IC a name like "U1", the character
   "u" in the first position on a device line means "lossy transmission line"
   in spice, not "IC."  Thus, in your netlist you're simply telling the 
   simulator to create a lossy transmission line using nodes "0", "4", "3"
   and "+9v" as its four ports, and it's getting confused by all the extra
   parameters on the line.

   To create a subcircuit instance (which is what you want), you need to use
   the "X" device.  The format of the X device is:
     X<name> [nodes] <subcircuit definition name>

   so, in your case, you would want something like:
     XU1  0 4 3 +9v 1 4 5 +9v UA555
   and a .subckt UA555 card like the one in the post I mentioned in point 2
   above.

   Note that I can't be absolutely certain that gschem's 555 symbol has 
   its pins defined so that it maps exactly onto the input nodes of the UA555
   subcircuit model in the forums post I pointed you at.  You will have to
   check for yourself.

4) Your circuit as is is having a really hard time in the solvers (not 
   surprising, given all the errors), so SPICE is using its "gmin stepping"
   process trying to force a solution.

5) You are attempting to use expressions somewhere (on a print line?) and this
   is not a supported feature in most free versions of spice.


6) gnetlist will dutifully produce a netlist from the schematic you give it, but
   unless you've prepared the netlist with an understanding of how gnetlist 
   is going to process it, you can get garbage.

While gEDA/gschem/gnetlist/ng-spice are cool tools, they are not easy to dive
into without a previous knowledge of spice.

You can try looking at the internal help in ngspice.  Just fire up ngspice
and type help, then explore.  This will not teach you the answers to your
specific issue, but *will* let you know what the format of various netlist
features are.

For more detail, you're better off with a textbook on SPICE simulation, and 
probably need to ask more detailed questions on a gEDA mailing list.

HTH,
T.

-- 
Tom Russo    KM5VY   SAR502   DM64ux          http://www.swcp.com/~russo/
Tijeras, NM  QRPL#1592 K2#398  SOC#236        http://kevan.org/brain.cgi?DDTNM
"And, isn't sanity really just a one-trick pony anyway? I mean all you get is
 one trick, rational thinking, but when you're good and crazy, oooh, oooh,
 oooh, the sky is the limit!"  --- The Tick



More information about the freebsd-questions mailing list