Remember that this tutorial is not exhaustive by any means, and that all descriptions for elements in the SPICE language are documented here in condensed form. SPICE is a very capable piece of software with lots of options, and I’m only going to document a few of them. All components in a SPICE source file are primarily identified by the first letter in each respective line. Characters following the identifying letter are used to distinguish one component of a certain type from another of the same type (r1, r2, r3, rload, rpullup, etc.), and need not follow any particular naming convention, so long as no more than eight characters are used in both the component identifying letter and the distinguishing name. For example, suppose you were simulating a digital circuit with “pullup” and “pulldown” resistors. The name rpullup would be valid because it is seven characters long. The name rpulldown, however, is nine characters long. This may cause problems when SPICE interprets the netlist. You can actually get away with component names in excess of eight total characters if there are no other similarly-named components in the source file. SPICE only pays attention to the first eight characters of the first field in each line, so rpulldown is actually interpreted as rpulldow with the “n” at the end being ignored. Therefore, any other resistor having the first eight characters in its first field will be seen by SPICE as the same resistor, defined twice, which will cause an error (i.e. rpulldown1 and rpulldown2 would be interpreted as the same name, rpulldow). It should also be noted that SPICE ignores character case, so r1 and R1 are interpreted by SPICE as one and the same. SPICE allows the use of metric prefixes in specifying component values, which is a very handy feature. However, the prefix convention used by SPICE differs somewhat from standard metric symbols, primarily due to the fact that netlists are restricted to standard ASCII characters (ruling out Greek letters such as µ for the prefix “micro”) and that SPICE is case-insensitive, so “m” (which is the standard symbol for “milli”) and “M” (which is the standard symbol for “Mega”) are interpreted identically. Here are a few examples of prefixes used in SPICE netlists: r1 1 0 2t (Resistor R1, 2t = 2 Tera-ohms = 2 TΩ) r2 1 0 4g (Resistor R2, 4g = 4 Giga-ohms = 4 GΩ) r3 1 0 47meg (Resistor R3, 47meg = 47 Mega-ohms = 47 MΩ) r4 1 0 3.3k (Resistor R4, 3.3k = 3.3 kilo-ohms = 3.3 kΩ) r5 1 0 55m (Resistor R5, 55m = 55 milli-ohms = 55 mΩ) r6 1 0 10u (Resistor R6, 10u = 10 micro-ohms 10 µΩ) r7 1 0 30n (Resistor R7, 30n = 30 nano-ohms = 30 nΩ) r8 1 0 5p (Resistor R8, 5p = 5 pico-ohms = 5 pΩ) r9 1 0 250f (Resistor R9, 250f = 250 femto-ohms = 250 fΩ) Scientific notation is also allowed in specifying component values. For example: r10 1 0 4.7e3 (Resistor R10, 4.7e3 = 4.7 x 103 ohms = 4.7 kilo-ohms = 4.7 kΩ) r11 1 0 1e-12 (Resistor R11, 1e-12 = 1 x 10-12 ohms = 1 pico-ohm = 1 pΩ) The unit (ohms, volts, farads, henrys, etc.) is automatically determined by the type of component being specified. SPICE “knows” that all of the above examples are “ohms” because they are all resistors (r1, r2, r3, . . . ). If they were capacitors, the values would be interpreted as “farads,” if inductors, then “henrys,” etc.
General form: c[name] [node1] [node2] [value] ic=[initial voltage] Example 1: c1 12 33 10u Example 2: c1 12 33 10u ic=3.5
Comments: The “initial condition” (ic=) variable is the capacitor’s voltage in units of volts at the start of DC analysis. It is an optional value, with the starting voltage assumed to be zero if unspecified. Starting current values for capacitors are interpreted by SPICE only if the .tran analysis option is invoked (with the “uic” option).
General form: l[name] [node1] [node2] [value] ic=[initial current] Example 1: l1 12 33 133m Example 2: l1 12 33 133m ic=12.7m
Comments: The “initial condition” (ic=) variable is the inductor’s current in units of amps at the start of DC analysis. It is an optional value, with the starting current assumed to be zero if unspecified. Starting current values for inductors are interpreted by SPICE only if the .tran analysis option is invoked.
General form: k[name] l[name] l[name] [coupling factor] Example 1: k1 l1 l2 0.999
Comments: SPICE will only allow coupling factor values between 0 and 1 (non-inclusive), with 0 representing no coupling and 1 representing perfect coupling. The order of specifying coupled inductors (l1, l2 or l2, l1) is irrelevant.
General form: r[name] [node1] [node2] [value] Example: rload 23 15 3.3k
Comments: In case you were wondering, there is no declaration of resistor power dissipation rating in SPICE. All components are assumed to be indestructible. If only real life were this forgiving!
All semiconductor components must have their electrical characteristics described in a line starting with the word “.model”, which tells SPICE exactly how the device will behave. Whatever parameters are not explicitly defined in the .model card will default to values pre-programmed in SPICE. However, the .model card must be included, and at least specify the model name and device type (d, npn, pnp, njf, pjf, nmos, or pmos).
General form: d[name] [anode] [cathode] [model] Example: d1 1 2 mod1
General form: .model [modelname] d [parmtr1=x] [parmtr2=x] . . . Example: .model mod1 d Example: .model mod2 d vj=0.65 rs=1.3
Parameter definitions: is = saturation current in amps rs = junction resistance in ohms n = emission coefficient (unitless) tt = transit time in seconds cjo = zero-bias junction capacitance in farads vj = junction potential in volts m = grading coefficient (unitless) eg = activation energy in electron-volts xti = saturation-current temperature exponent (unitless) kf = flicker noise coefficient (unitless) af = flicker noise exponent (unitless) fc = forward-bias depletion capacitance coefficient (unitless) bv = reverse breakdown voltage in volts ibv = current at breakdown voltage in amps Comments: The model name must begin with a letter, not a number. If you plan to specify a model for a 1N4003 rectifying diode, for instance, you cannot use “1n4003” for the model name. An alternative might be “m1n4003” instead.
General form: q[name] [collector] [base] [emitter] [model] Example: q1 2 3 0 mod1
BJT TRANSISTOR MODELS:
General form: .model [modelname] [npn or pnp] [parmtr1=x] . . . Example: .model mod1 pnp Example: .model mod2 npn bf=75 is=1e-14
The model examples shown above are very nonspecific. To accurately model real-life transistors, more parameters are necessary. Take these two examples, for the popular 2N2222 and 2N2907 transistors (the “+”) characters represent line-continuation marks in SPICE, when you wish to break a single line (card) into two or more separate lines on your text editor:
Example: .model m2n2222 npn is=19f bf=150 vaf=100 ikf=.18 + ise=50p ne=2.5 br=7.5 var=6.4 ikr=12m + isc=8.7p nc=1.2 rb=50 re=0.4 rc=0.4 cje=26p + tf=0.5n cjc=11p tr=7n xtb=1.5 kf=0.032f af=1
Example: .model m2n2907 pnp is=1.1p bf=200 nf=1.2 vaf=50 + ikf=0.1 ise=13p ne=1.9 br=6 rc=0.6 cje=23p + vje=0.85 mje=1.25 tf=0.5n cjc=19p vjc=0.5 + mjc=0.2 tr=34n xtb=1.5
Parameter definitions: is = transport saturation current in amps bf = ideal maximum forward Beta (unitless) nf = forward current emission coefficient (unitless) vaf = forward Early voltage in volts ikf = corner for forward Beta high-current rolloff in amps ise = B-E leakage saturation current in amps ne = B-E leakage emission coefficient (unitless) br = ideal maximum reverse Beta (unitless) nr = reverse current emission coefficient (unitless) bar = reverse Early voltage in volts ikrikr = corner for reverse Beta high-current rolloff in amps iscisc = B-C leakage saturation current in amps nc = B-C leakage emission coefficient (unitless) rb = zero bias base resistance in ohms irb = current for base resistance halfway value in amps rbm = minimum base resistance at high currents in ohms re = emitter resistance in ohms rc = collector resistance in ohms cje = B-E zero-bias depletion capacitance in farads vje = B-E built-in potential in volts mje = B-E junction exponential factor (unitless) tf = ideal forward transit time (seconds) xtf = coefficient for bias dependence of transit time (unitless) vtf = B-C voltage dependence on transit time, in volts itf = high-current parameter effect on transit time, in amps ptf = excess phase at f=1/(transit time)(2)(pi) Hz, in degrees cjc = B-C zero-bias depletion capacitance in farads vjc = B-C built-in potential in volts mjc = B-C junction exponential factor (unitless) xjcj = B-C depletion capacitance fraction connected in base node (unitless) tr = ideal reverse transit time in seconds cjs = zero-bias collector-substrate capacitance in farads vjs = substrate junction built-in potential in volts mjs = substrate junction exponential factor (unitless) xtb = forward/reverse Beta temperature exponent eg = energy gap for temperature effect on transport saturation current in electron-volts xti = temperature exponent for effect on transport saturation current (unitless) kf = flicker noise coefficient (unitless) af = flicker noise exponent (unitless) fc = forward-bias depletion capacitance formula coefficient (unitless) Comments: Just as with diodes, the model name given for a particular transistor type must begin with a letter, not a number. That’s why the examples given above for the 2N2222 and 2N2907 types of BJTs are named “m2n2222” and “q2n2907” respectively. As you can see, SPICE allows for very detailed specification of transistor properties. Many of the properties listed above are well beyond the scope and interest of the beginning electronics student, and aren’t even useful apart from knowing the equations SPICE uses to model BJT transistors. For those interested in learning more about transistor modeling in SPICE, consult other books, such as Andrei Vladimirescu’s The Spice Book (ISBN 0-471-60926-9).
General form: j[name] [drain] [gate] [source] [model] Example: j1 2 3 0 mod1
JFET TRANSISTOR MODELS:
General form: .model [modelname] [njf or pjf] [parmtr1=x] . . . Example: .model mod1 pjf Example: .model mod2 njf lambda=1e-5 pb=0.75
Parameter definitions: vto = threshold voltage in volts beta = transconductance parameter in amps/volts2 lambda = channel length modulation parameter in units of 1/volts rd = drain resistance in ohms rs = source resistance in ohms cgs = zero-bias G-S junction capacitance in farads cgd = zero-bias G-D junction capacitance in farads pb = gate junction potential in volts is = gate junction saturation current in amps kf = flicker noise coefficient (unitless) af = flicker noise exponent (unitless) fc = forward-bias depletion capacitance coefficient (unitless)
General form: m[name] [drain] [gate] [source] [substrate] [model] Example: m1 2 3 0 0 mod1
MOSFET TRANSISTOR MODELS:
General form: .model [modelname] [nmos or pmos] [parmtr1=x] . . . Example: .model mod1 pmos Example: .model mod2 nmos level=2 phi=0.65 rd=1.5 Example: .model mod3 nmos vto=-1 (depletion) Example: .model mod4 nmos vto=1 (enhancement) Example: .model mod5 pmos vto=1 (depletion) Example: .model mod6 pmos vto=-1 (enhancement)
Comments: In order to distinguish between enhancement mode and depletion-mode (also known as depletion-enhancement mode) transistors, the model parameter “vto” (zero-bias threshold voltage) must be specified. Its default value is zero, but a positive value (+1 volts, for example) on a P-channel transistor or a negative value (-1 volts) on an N-channel transistor will specify that transistor to be a depletion (otherwise known as depletion-enhancement) mode device. Conversely, a negative value on a P-channel transistor or a positive value on an N-channel transistor will specify that transistor to be an enhancement mode device. Remember that enhancement mode transistors are normally-off devices, and must be turned on by the application of gate voltage. Depletion-mode transistors are normally “on,” but can be “pinched off” as well as enhanced to greater levels of drain current by applied gate voltage, hence the alternate designation of “depletion-enhancement” MOSFETs. The “vto” parameter specifies the threshold gate voltage for MOSFET conduction.
General form: v[name] [+node] [-node] ac [voltage] [phase] sin Example 1: v1 1 0 ac 12 sin Example 2: v1 1 0 ac 12 240 sin (12 V ∠ 240o)
Comments: This method of specifying AC voltage sources works well if you’re using multiple sources at different phase angles from each other, but all at the same frequency. If you need to specify sources at different frequencies in the same circuit, you must use the next method! AC SINEWAVE VOLTAGE SOURCES (when NOT using .ac card to specify frequency):
General form: v[name] [+node] [-node] sin([offset] [voltage] + [freq] [delay] [damping factor]) Example 1: v1 1 0 sin(0 12 60 0 0)
Parameter definitions: offset = DC bias voltage, offsetting the AC waveform by a specified voltage. voltage = peak, or crest, AC voltage value for the waveform. freq = frequency in Hertz. delay = time delay, or phase offset for the waveform, in seconds. damping factor = a figure used to create waveforms of decaying amplitude. Comments: This method of specifying AC voltage sources works well if you’re using multiple sources at different frequencies from each other. Representing phase shift is tricky, though, necessitating the use of the delay factor. DC VOLTAGE SOURCES (when using .dc card to specify voltage):
General form: v[name] [+node] [-node] dc Example 1: v1 1 0 dc
Comments: If you wish to have SPICE output voltages not in reference to node 0, you must use the .dc analysis option, and to use this option you must specify at least one of your DC sources in this manner. DC VOLTAGE SOURCES (when NOT using .dc card to specify voltage):
General form: v[name] [+node] [-node] dc [voltage] Example 1: v1 1 0 dc 12
General form: v[name] [+node] [-node] pulse ([ i ] [p] [td] [tr] + [tf] [pw] [pd])
Parameter definitions: i = initial value p = pulse value td = delay time (all time parameters in units of seconds) tr = rise time tf = fall time pw = pulse width pd = period
Example 1: v1 1 0 pulse (-3 3 0 0 0 10m 20m)
Comments: Example 1 is a perfect square wave oscillating between -3 and +3 volts, with zero rise and fall times, a 20 millisecond period, and a 50 percent duty cycle (+3 volts for 10 ms, then -3 volts for 10 ms). AC SINEWAVE CURRENT SOURCES (when using .ac card to specify frequency):
General form: i[name] [+node] [-node] ac [current] [phase] sin Example 1: i1 1 0 ac 3 sin (3 amps) Example 2: i1 1 0 ac 1m 240 sin (1 mA ∠ 240o)
Comments: The same comments apply here (and in the next example) as for AC voltage sources. AC SINEWAVE CURRENT SOURCES (when NOT using .ac card to specify frequency):
General form: i[name] [+node] [-node] sin([offset] + [current] [freq] 0 0) Example 1: i1 1 0 sin(0 1.5 60 0 0)
General form: i[name] [+node] [-node] dc Example 1: i1 1 0 dc
DC CURRENT SOURCES (when NOT using .dc card to specify current):
General form: i[name] [+node] [-node] dc [current] Example 1: i1 1 0 dc 12
Comments: Even though the books all say that the first node given for the DC current source is the positive node, that’s not what I’ve found to be in practice. In actuality, a DC current source in SPICE pushes current in the same direction as a voltage source (battery) would with its negative node specified first. PULSE CURRENT SOURCES
General form: i[name] [+node] [-node] pulse ([i] [p] [td] [tr] + [tf] [pw] [pd])
Parameter definitions: i = initial value p = pulse value td = delay time tr = rise time tf = fall time pw = pulse width pd = period
Example 1: i1 1 0 pulse (-3m 3m 0 0 0 17m 34m)
Comments: Example 1 is a perfect square wave oscillating between -3 mA and +3 mA, with zero rise and fall times, a 34 millisecond period, and a 50 percent duty cycle (+3 mA for 17 ms, then -3 mA for 17 ms). VOLTAGE SOURCES (dependent):
General form: e[name] [out+node] [out-node] [in+node] [in-node] + [gain] Example 1: e1 2 0 1 2 999k
Comments: Dependent voltage sources are great to use for simulating operational amplifiers. Example 1 shows how such a source would be configured for use as a voltage follower, inverting input connected to output (node 2) for negative feedback, and the noninverting input coming in on node 1. The gain has been set to an arbitrarily high value of 999,000. One word of caution, though: SPICE does not recognize the input of a dependent source as being a load, so a voltage source tied only to the input of an independent voltage source will be interpreted as “open.” See op-amp circuit examples for more details on this. CURRENT SOURCES (dependent):
In Partnership with Samtec
by Jake Hertz
In Partnership with Mouser Electronics