Please note that before attempting to edit device models, it is essential that the user is familiar with and understands the relationship between spice pin names and numbering, described in this section.
Device and subcircuit symbols created for use in schematics that are intended to be run as spice simulations, in addition to having a PCB Prefix that is used for the reference designator in the schematic, also have a Spice Prefix. They also have two sets of pin numbers: PCB pins and Spice pins.
The rules on the assignment of the PCB Prefix or reference designator of a schematic symbol are somewhat dependent on the EDA tool and on the user’s preferences. Depending on how a device is graphically represented by it’s schematic symbol it may have a different PCB Prefix or reference designator. For example, a single discrete MOSFET device may have a PCB Prefix of Q, M or perhaps TR, whereas if it is part of a monolithic multiple transistor array it may have a PCB Prefix of U or IC.
The rules on the assignment of the Spice Prefix of a schematic symbol are strict. This is because the Spice Prefix is used to tell the simulator which circuit element the symbol represents and therefore which simulation model it is to use.
Simulation models for most of the spice circuit elements are in the form of a single-line .model statement however some of them may be in the form of a multi-line .subckt subcircuit definition.
For example, some MOSFETs may be described by a .model statement in which case their Spice Prefix is M but many MOSFETs are described by a .subckt and so their Spice Prefix is X.
Therefore, irrespective of the PCB Prefix chosen for a schematic symbol, the Spice Prefix for a schematic symbol representing a given circuit element must match the type of model required to simulate that instance of that circuit element in your schematic.
For example, if there are two different n-channel MOSFETs in a schematic;
Q1, a BSS123 which is modelled by a .model statement:
and Q2, a BSS127S which is modelled by a .subckt:
then even though both have the same PCB Prefix of Q: Q1 must have a Spice Prefix of M and Q2 must have a Spice Prefix of X.
A list of Spice Prefixes and their associated circuit elements is given in the table below.
|Element description||Spice Prefix||Spice pin orde||Comment|
|A||XSPICE code model||Depends on model||analogue, digital, mixed signal|
|B||Behavioural (arbitrary) source||Source+, Source-,
|C||Capacitor||Fixed by model but has no polarity|
|E||Voltage-controlled voltage source (VCVS)||Source+, Source-,
|F||Current-controlled current source (CCCS)||Source+, Source-,
Vsrcname is for a voltage source external to the switch.
|G||Voltage-controlled current source (VCCS)||Source+, Source-,
|H||Current-controlled voltage source (CCVS)||Source+, Source-,
Vsrcname is for a voltage source external to the switch.
|I||Current source||Source+, Source-|
|J||Junction field effect transistor (JFET)||D G S|
|K||Coupled (Mutual) Inductors||Fixed but must respect winding phases|
|L||Inductor||Fixed by model but has no polarity|
|M||Metal oxide field effect transistor (MOSFET)||D G S|
|N||Numerical device for GSS|
|O||Lossy transmission line||Fixed by model|
|P||Coupled multiconductor line (CPL)||Fixed by model|
|Q||Bipolar junction transistor (BJT)||C B E|
|R||Resistor||Fixed by model but has no polarity|
|S||Switch (voltage-controlled)||Switch+, Switch-,
|T||Lossless transmission line||Fixed by model|
|U||Uniformly distributed RC line||Fixed by model|
|V||Voltage source||Source+, Source-|
|W||Switch (current-controlled)||Switch+, Switch-,
|Vsrcname is for a voltage source external to the switch.|
|X||Subcircuit||Depends on subckt|
|Y||Single lossy transmission line (TXL)||Fixed by model|
|Z||Metal semiconductor field effect transistor (MESFET)||D G S|
For more information on circuit elements in Ngspice, please refer to:
The two sets of pin numbers are:
PCB pin number: these are the numbers for the real, physical device pins in its package. They are required so that the pins of a device symbol in a schematic can be mapped onto the physical pins of a PCB footprint. In other words, so that the connections shown in the schematic, end up connected properly by copper on the PCB.
Spice pin number or pin order: these are the numbers that map the pins on the symbol to their respective functions in the spice model or subcircuit.
The spice pin ordering of .model defined models is fixed as shown in the table above.
The spice pin ordering of .subckt defined models is determined by the .subckt line in the subcircuit.
Actually the spice pin ordering has a slightly deeper meaning.
Spice has no concept of component symbols: they are a construct of the schematic editor.
When a spice netlist is generated, the symbol in the schematic editor is either - in the case of model defined devices such as resistors, capacitors, inductors, diodes, transistors and sources - mapped directly to the relevant models (defined by the device prefix such as R, C, L, D, Q and so on), or in the case of a subcircuit, converted into a subcircuit call statement.
The spice pin ordering for the majority of built-in models such as resistors, capacitors, inductors, diodes, transistors and sources are defined and generally taken care of by the schematic editor, more care has to be taken with the spice pin ordering of subcircuits.
This can be illustrated by a simple opamp with 5 pins: inverting and non-inverting inputs; output and positive and negative supply pins but the principle applies to all spice subcircuits.
The subcircuit call for this opamp might look like this in the spice netlist:
X1 input feedback vpos vneg output opamp_ANF01
X1 is the name of the subcircuit in the top level (i.e. the calling) circuit;
input feedback vpos vneg output are the netnames in the circuit calling (i.e. containing) the subcircuit and:
opamp_ANF01 is the name of the subcircuit being called.
- Pay special attention to the order of the netnames in the subcircuit call.
The spice pin ordering for the majority of opamp subcircuits is like that shown in the example below:
Note that the spice pin order of the subcircuit call is in exactly the same order as that of the pins in the .subckt line of the subcircuit.
Although the physical pin numbering of any device is critical for successfully mapping the pins on a schematic symbol onto a physical package footprint when laying out the PCB, because spice only knows about single devices and does not care about how they are physically packaged, each instance of any device in a spice schematic has to be mapped onto its own copy of the spice model or subcircuit, irrespective of where it is in any physical package.
Therefore, for the physical, package pin numbering of the four opamps in a quad opamp in say, a SOIC14 or a DIP14 package, as shown below, to work with the example subcircuit above, the spice pin ordering would be:
|Opamp A||Pin Number||Spice Pin Order|
|Opamp B||Pin Number||Spice Pin Order|
|Opamp C||Pin Number||Spice Pin Order|
|Opamp D||Pin Number||Spice Pin Order|
The physical package pin numbering reflects that of each opamp in the package.
The spice pin ordering is the same for each instance of the individual opamps.
Of course there is only one physical instance of each supply pin on the schematic symbol for the quad opamp in this example but each spice subcircuit must have the supply pins explicitly defined.
Exactly how this is handled is at the schematic symbol level depends on how the schematic capture package handles symbols for multiple devices with shared supply pins but the generation of a spice netlist from the schematic will always generate the complete set of pins required in the subcircuit calls.
In cases where the subcircuit is built by the user as opposed to where it is supplied by a vendor for a particular device, exactly the same rules apply except that it is up to the user to specify the subcircuit pin order and to construct the symbol appropriately.
Although as described earlier, built-in spice models usually have defined spice pin orders, not all subcircuits have the same spice pin numbering. Therefore if your spice circuit throws errors - especially if there are warnings about pin numbers or pin names - it is worth remembering to check that the pin order of the symbol that is netlisted to form the calling statement matches that of the subcircuit that is being called!