4. Creating your circuit: 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. If not, consult the documentation available at the gEDA website: http://www.geda.seul.org/. 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.

4.1. 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.

4.2. Component attributes and meanings

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

4.3. 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.

4.4. Passives

4.4.1. 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:

  • refdes: The correct refdes for the component.

  • value: For passives, this is the numeric value of the component (e.g. 100pF). For actives, this attribute may be filled in, but if no model attribute is available elsewhere in the schematic, the value is not used (in SPICE netlisting, anyway).

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

4.4.2. 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.)

4.4.3. Example capacitor:

  • refdes = C22

  • value = 1UF

SPICE line generated: C22 4 23 1UF

4.5. 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.

4.5.1. Example resistor:

  • refdes = R5

  • value = 1MEG

  • model = TC=0.001,0.015

SPICE line generated: R2 0 4 220 TC=0.001,0.015

4.6. Passives for semiconductor design

The values for resistors and capacitors are often given as dimensions in an ASIC design. SPICE takes from the technology library the typical value per square and calculates the actual value in Ohm or Farad by itself. Therefor the following attributes are required:

The technology library must be included with an .include line in the SPICE input file.

4.6.1. Example semiconductor resistor:

  • refdes = R6

  • model-name = rpoly

  • w = 3u

  • l = 100u

SPICE line generated: R6 0 5 rpoly w=3u l=100u

4.6.1.1. Example semiconductor resistor model:

  • model rpoly R rsh=300

This should be part of the technology library from your ASIC vendor.

4.7. Transistors and diodes

Transistors and diodes are generally accompanied by a device-specific model. Each model attempts to capture the detailed nonlinear dynamics of its particular device; 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:

4.7.1. 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:

  • refdes: Correct component refdes.

  • value: The model number or part number of the component.

  • model-name: The name you wish to give the SPICE model. This is usually the model number or part number of the component. If you have already attached a value attribute to the component, this parameter is optional.

  • model: One line string holding additional parameters. Do not place the model parameters in parentheses -- gnetlist will do this for you.

4.7.2. 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)

4.7.3. SPICE model file

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

  • refdes: Correct component refdes.

  • value: The model number or part number of the component.

  • model-name: the name you wish to give the SPICE model. This is usually the model number or part number of the component. If you have already attached a value attribute to the component, this parameter is optional.

  • file: The file name of the SPICE model which you wish to incorporate into the netlist. This file name may specify either a relative or an absolute path, but it is probably better to use an absolute path to avoid problems if you ever move your schematic directory.

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.

4.8. 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.

4.8.1. 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:

  • refdes: Correct component refdes.

  • value: The model number or part number of the component.

  • model-name: the name you wish to give the SPICE model. This is usually the model number or part number of the component. If you have already attached a value attribute to the component, this parameter is optional.

  • model: One line string holding additional parameters. Do not place the model parameters in parentheses -- gnetlist will do this for you.

4.8.2. 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:

  • refdes: Correct component refdes. Note that if the file holds a .MODEL, the refdes should start with U; if the file holds a .SUBCKT, the refdes should start with X. The netlister checks for the file type and tries to “do the right thing”, but problems can arise if you don't follow this rule.

  • value: The model number or part number of the component.

  • model-name: The name you wish to give the SPICE model. This is usually the model number or part number of the component. If you have already attached a value attribute to the component, this parameter is optional.

  • file: The name of the file holding the SPICE .MODEL or .SUBCKT which you wish to incorporate into the netlist. This file name may specify either a relative or an absolute path, but it is probably better to use an absolute path to avoid problems if you ever move your schematic directory.

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.

4.9. 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:

    • refdes: V? or I?

    • value: A one line string in SPICE format describing the source.

4.10. Dependent sources

There are four dependent sources:

This section remains TBD.

4.11. SPICE components

4.11.1. 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:

4.11.2. 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:

    • refdes: A?

    • model: model name (i.e. the model name used in the components being modeled.)

    • type: One of the valid spice component types defined in the spice spec.

    • value: The corresponding one-line spice model

4.11.3. 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:

    • refdes: A?

    • model-name: model name

    • file: Name of file holding SPICE model code (i.e. .MODEL or .SUBCKT).

4.11.4. 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:

    • refdes: A?

    • file: The name of the file to include.

4.11.5. 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. The netlister will simply dump the contents of the string or the file into your netlist verbatim. Examples of situations where this is useful include:

  • .TEMP statement

  • .IC statement

  • Other SPICE statements for which gschem has no symbol.

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:

    • refdes: A?

    • file: The name of the file to include.

4.12. 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:

    • model-name = cap_with_parasitics

    (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 refdefs attribute “X?”

  6. Create the upper level schematic. Place your newly created symbol on the schematic as many times as required and 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:

    • file = cap_with_parasitics.cir

    • model-name = cap_with_parasitics

    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:

    • Verify that the ordering of the nets connecting the upper level netlist to the lower level .SUBCKT is correct.

    • Make sure that the upper level model-name and the lower level model name (on the .SUBCKT declaration line) are the same.

Once the netlist is created, you may simulate your design using any SPICE simulator desired. Some simulators running on Linux are covered below.