SPICE on gEDA HOWTO -- SPICE netlist creation

Schematic capture

Schematic capture is the process by which one uses a special-purpose drawing program to draw a schematic diagram of the circuit under design. In the gEDA environment, the schematic capture program is called "gschem". I assume you already know how to use gschem. For the purposes of creating SPICE netlists, you must use gschem to attach attributes to components, and possibly also incorporate other SPICE directives into your netlist. After you are done with schematic capture, you create the SPICE netlist by running gEDA's netlister "gnetlist" on your design.

Back to the table of contents.

Gschem attributes for spice netlisting

There are several ways that spice attributes may be associated with a component using gschem. The way you choose to do this depends upon many factors, including the type of component, and the size and format of the SPICE model.

Back to the table of contents.

Component attributes and meanings

The following attributes are meaningful for SPICE netlisting, and may be attached from within gschem:

Back to the table of contents.

Refdes conventions

As a prerequisite to handling SPICE-related attributes, the SPICE netlister requires that all components must have a refdes attached to them. The refdes may be attached either by hand (which is laborious), or using the program refdes_renum included in the gEDA distribution.

Note that the first letter of the refdes must correspond to the appropriate letter for spice simulation. The refdes convention is given in the appendix

Back to the table of contents.

Passives

Basic passives

The most basic components which one encounters in spice are passive components like resistors and capacitors which have numeric values, but no other modeling attributes. In this case the following attributes must be filled in:

If only a refdes and value attribute are encountered, the netlister will write a single line into the output file.

Example resistor:
refdes = R2
value = 220
SPICE line generated: R2 0 4 220

(note that "0" and "4" correspond to the net nodes connected to the component, and are generated automatically by gnetlist.)

Example capacitor:
refdes = C22
value = 1UF
SPICE line generated: C22 4 23 1UF

Passives with additional attributes

Oftentimes, passive components have additional attributes attached to them for spice simulation. Examples of such attributes are temperature coefficients (for resistors) and initial conditions (for reactive components). These additional components may be incorporated into the SPICE file by simply attaching them to the component's "model" attribute. Specifically, the required attributes are:

This string is placed after the component value in the line generated by gnetlist. Therefore, it is important to format the string placed in the "model" line to be valid SPICE code. Otherwise, you will risk causing the SPICE simulator to barf.

Example resistor:
refdes = R5
value = 1MEG
model = TC=0.001,0.015
SPICE line generated: R2 0 4 220 TC=0.001,0.015

Back to the table of contents.

Transistors and diodes

Transistors and diodes are generally accompanied by a device-specific model -- otherwise, SPICE simulation is pointless. The SPICE model may be either a short, one-line string of parameters, or a multi-line set of SPICE parameters. A typical one-line parameter string is a short list of parameters describing a small-signal diode. Typical multi-line models come from component vendors, who often provide models for their components in a text file. Since there are two broad formats of SPICE information, there are two approaches to incorporating these parameters into the schematic:

One line string of SPICE parameters

To incorporate a one line string of SPICE parameters into the netlist, the following attributes must be attached to the component:

Example diode:
refdes = D5
model-name = 1N1004
model = IS=0.5UA RS=6 BV=5.20
SPICE lines generated:
D5 2 6 1N1004
MODEL 1N1004 D (IS=0.5UA RS=6 BV=5.20)

SPICE model file

To incorporate a file-full of SPICE parameters into the netlist, the following attributes must be attached to the component:

Note that you need to make sure that the model name held in your SPICE model file is the same as the "value" or "model-name" attributes you attached to the component.It is also a good idea to verify that the pin assignments in the model file correspond to the pin assignments made by the component symbol.

Back to the table of contents.

Actives -- integrated circuits

Integrated circuits are incorporated into the netlist similarly to transistors and diodes. As such, you may incorporate the spice information either as a one-line parameter string, or as a model file.

One line string of SPICE parameters

To incorporate a one line string of SPICE parameters into the netlist, the following attributes must be attached to the component:

SPICE .MODEL or .SUBCKT file

To incorporate a file-full of SPICE parameters into the netlist, the following attributes must be attached to the component:

Note that you need to make sure that the model name held in your SPICE model file is the same as the "value" or "model-name" attributes you attached to the component. It is also a good idea to verify that the pin assignments in the model file correspond to the pin assignments made by the component symbol.

Back to the table of contents.

Independent sources

There are two independent sources: voltage sources and current sources. For incorporation into a SPICE netlist, they both work the same way. To incorporate an independent source into your SPICE netlist, do the following:

  1. Place the independent source on your schematic. (Do "Add" -> "Component" -> "spice" -> "<independent source name>.sym")
  2. Double click on the block and add/edit the following attributes:
Back to the table of contents.

Dependent sources

There are four dependent sources:

This section remains TBD.

Back to the table of contents.

SPICE components

Spice model block

In certain situations, you may wish to embed a spice model block directly into your schematic. This is done when you have several devices with a "value" attribute calling out for a spice model. Depending upon whether the spice block is one line or multi-line, you may embed the code in one of two ways:

One line SPICE model:
  1. Place a spice model block on your schematic. (Do "Add" -> "Component" -> "spice" -> "spice-model-1.sym")
  2. Double click on the block and add/edit the following attributes:
Multi-line SPICE model:
  1. Place a spice model block on your schematic.(Do "Add" -> "Component" -> "spice" -> "spice-model-1.sym")
  2. Double click on the block and add/edit the following attributes:

Include block

The include block places a .INCLUDE directive into your netlist.

  1. Place a spice model block on your schematic. (Do "Add" -> "Component" -> "spice" -> "spice-include-1.sym")
  2. Double click on the block and add/edit the following attributes:

SPICE directive block

Placing a SPICE directive block into your schematic creates an arbitrary block of SPICE code in the netlist. The directive may be either statements held in a file, or a one-line string held in the "model" attribute. Examples of situations where this is useful include:

To place a SPICE directive on your schematic, do:

  1. Place a SPICE directive block on your schematic. (Do "Add" -> "Component" -> "spice" -> "spice-directive-1.sym")
  2. Double click on the block and add/edit the following attributes:

Back to the table of contents.

Handling hierarchical models

In SPICE modeling, there are often situations where you wish to create a schematic representation of some particular component as a .SUBCKT, and then embed that component's model in a higher level schematic. A common example might be as follows: You are doing a microwave simulation, and want to use a capacitor model which includes parasitic inductances and resistances, as well as the capacitance. Capacitor manufacturers often supply a printed schematic showing a circuit topology incorporating parasitics, and specify values for the parasitics. You would like to draw the capacitor model using gschem, netlist it to create a .SUBCKT, and then use the .SUBCKT to model capacitors in a higher lever schematic.

Since this kind of task is very common in SPICE simulation, gnet-spice-sdb now supports it (starting with rev 20030331). To create a lower level .SUBCKT and use it in a higher level schematic, do the following:

  1. Draw the schematic of the lower level component (e.g. the capacitor + parasitics) using gschem.
  2. On the lower level schematic, place a spice-subcircuit-LL block (spice-subcircuit-LL-1.sym). This alerts the netlister that the schematic is a Lower Level .SUBCKT. Attach the following attributes to the symbol: (Of course, "cap_with_parasitics" is the example we use here. Use your own model name in your schematic.) Upon netlisting, this schematic symbol will cause the netlist to insert ".SUBCKT cap_with_parasitics " into the first line of the netlist file.
  3. On the lower level schematic, attach a spice-subcircuit-IO symbol (spice-subcircuit-IO-1.sym) to each IO net (i.e. connection to the upper level). Number the refdeses of the IO symbols in the same order as you would like the IO nets to be listed in the .SUBCKT line in the output file. (i.e. P1 = first, P2 = second, etc.)
  4. When you are done with the lower level schematic, netlist it in the usual way. For example, if your schematic is called cap_with_parasitics.sch, netlist it by saying:
    gnetlist -g spice-sdb -o cap_with_parasitics.cir cap_with_parasitics.sch
    This will dump the SPICE netlist into the file called "cap_with_parasitics.cir". Visually inspect the .cir file to make sure that netlisting worked correctly.
  5. Next, create a symbol for the upper level schematic which will point to the .SUBCKT. Note that the symbol must have a refdes starting with the letter "X". To ensure that this happens, do the following:
    1. Use gschem to draw the symbol. I usually draw a box around a model symbol to distinguish it from a normal component. Make any other annotations desired.
    2. In the symbol, make sure that the pins are ordered identically to the order in which you have placed the pins in the .SUBCKT. This is done by editing the symbol with a text editor and setting the "PINSEQ" attribute. The netlister will output the pins in the order determined by the "PINSEQ" attribute.
    3. Using a text editor, give the symbol a "DEVICE" attribute like "capacitor-model". Do not assign the symbol one of the native device types listed in the appendix! The goal is to create a symbol whose refdes starts with "X", and if the "DEVICE" is a recognized type, this will not happen.
    4. Using a text editor, give the symbol the "REFDES" attribute "X?"
  6. Create the upper level schematic. Place your newly created symbol on the schematic as many times as required & wire up the schematic in the usual way.
  7. To point your symbol to the lower level .SUBCKT, double click on the symbol and set the following attributes: as well as any other attributes required (e.g. refdes).
  8. Now netlist your upper level schematic the usual way. The contents of each .SUBCKT file is dumped into the main netlist. Inspect your netlist visually using a text editor to ensure that it is correct. It is a good idea to pay particular attention to the following:

Once the netlist is created, you may simulate your design using any SPICE simulator desired.

One final note: The netlister writes the contents of the lower level .SUBCKT file into the main netlist every time it encounters a component with "FILE" attribute pointing to that file. Therefore, if you use the same component with the same model more than once in a design you should instantiate the model file using a "spice-model" symbol and point to it with each component. This is described in the "multi-line SPICE model block" section above.

Back to the table of contents.

SPICE netlist generation

Once the schematic is captured, a SPICE netlist can be generated running the gEDA utility "gnetlist" on the schematic files. Gnetlist is built to be customizable, and is able to generate a netlist of any desired format using a Scheme back-end, which does the real heavy-lifting of creating the netlist. The back-end Scheme file which implements SPICE netlisting is called gnet-spice-sdb.scm, and it lives in the ${PREFIX}/geda/share/gEDA/scheme directory.

Back to the table of contents.

Creating the netlist

Creating a netlist from a schematic is easy. To generate a SPICE netlist, just do the following:

Back to the table of contents.

Common netlisting problems

It is important to manually inspect your SPICE netlist prior to using it in simulation. Please remember that the netlister is still "alpha" quality, and some problems may still exist in netlist generation. The following list attempts to catalog common problems with the netlist and the associated fixes.


Back to the table of contents.


Continue on to performing a SPICE simulation.

Please send comments or questions about this HOWTO to Stuart Brorson at sdb@cloud9.net.