Lessons In Electric Circuits -- Volume V Chapter 7 (Part 2)


Lessons In Electric Circuits -- Volume V Chapter 7 (Part 1)

Lessons In Electric Circuits -- Volume V Chapter 7 (Part 3)

Active components

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

DIODES


General form:  d[name] [anode] [cathode] [model]
Example:       d1 1 2 mod1
 
DIODE MODELS:
General form:  .model [modelname] d [parmtr1=x] [parmtr2=x] . . .
Example:       .model mod1 d
Example:       .model mod2 d vj=0.65 rs=1.3
 
diodeparameter 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.

TRANSISTORS, bipolar junction -- BJT


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

JFET, junction field-effect transistor


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)

MOSFET, transistor


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.

Sources

AC SINEWAVE VOLTAGE SOURCES (when using .ac card to specify frequency):
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
Comments: Nothing noteworthy here!


PULSE VOLTAGE SOURCES
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)  


DC CURRENT SOURCES (when using .dc card to specify current):
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):

Analysis options

AC ANALYSIS:
General form:  .ac [curve] [points] [start] [final]
Example 1:     .ac lin 1 1000 1000
Comments: The [curve] field can be "lin" (linear), "dec" (decade), or "oct" (octave), specifying the (non)linearity of the frequency sweep. specifies how many points within the frequency sweep to perform analyses at (for decade sweep, the number of points per decade; for octave, the number of points per octave). The [start] and [final] fields specify the starting and ending frequencies of the sweep, respectively. One final note: the "start" value cannot be zero!


DC ANALYSIS:
General form:     .dc [source] [start] [final] [increment]
Example 1:        .dc vin 1.5 15 0.5
Comments: The .dc card is necessary if you want to print or plot any voltage between two nonzero nodes. Otherwise, the default "small-signal" analysis only prints out the voltage between each nonzero node and node zero.


TRANSIENT ANALYSIS:
General form:  .tran [increment] [stop_time] [start_time] 
+                    [comp_interval]
Example 1:     .tran 1m 50m uic 
Example 2:     .tran .5m 32m 0 .01m 
Comments: Example 1 has an increment time of 1 millisecond and a stop time of 50 milliseconds (when only two parameters are specified, they are increment time and stop time, respectively). Example 2 has an increment time of 0.5 milliseconds, a stop time of 32 milliseconds, a start time of 0 milliseconds (no delay on start), and a computation interval of 0.01 milliseconds.
Default value for start time is zero. Transient analysis always beings at time zero, but storage of data only takes place between start time and stop time. Data output interval is increment time, or (stop time - start time)/50, which ever is smallest. However, the computing interval variable can be used to force a computational interval smaller than either. For large total interval counts, the itl5 variable in the .options card may be set to a higher number. The "uic" option tells SPICE to "use initial conditions."


PLOT OUTPUT:
General form:  .plot [type] [output1] [output2] . . . [output n]
Example 1:     .plot dc v(1,2) i(v2)
Example 2:     .plot ac v(3,4) vp(3,4) i(v1) ip(v1)
Example 3:     .plot tran v(4,5) i(v2)
Comments: SPICE can't handle more than eight data point requests on a single .plot or .print card. If requesting more than eight data points, use multiple cards!
Also, here's a major caveat when using SPICE version 3: if you're performing AC analysis and you ask SPICE to plot an AC voltage as in example #2, the v(3,4) command will only output the real component of a rectangular-form complex number! SPICE version 2 outputs the polar magnitude of a complex number: a much more meaningful quantity if only a single quantity is asked for. To coerce SPICE3 to give you polar magnitude, you will have to re-write the .print or .plot argument as such: vm(3,4).


PRINT OUTPUT:
General form:  .print [type] [output1] [output2] . . . [output n]
Example 1:     .print dc v(1,2) i(v2)
Example 2:     .print ac v(2,4) i(vinput) vp(2,3)
Example 3:     .print tran v(4,5) i(v2)
Comments: SPICE can't handle more than eight data point requests on a single .plot or .print card. If requesting more than eight data points, use multiple cards!


FOURIER ANALYSIS:
General form:  .four [freq] [output1] [output2] . . . [output n]
Example 1:     .four 60 v(1,2)
Comments: The .four card relies on the .tran card being present somewhere in the deck, with the proper time periods for analysis of adequate cycles. Also, SPICE may "crash" if a .plot analysis isn't done along with the .four analysis, even if all .tran parameters are technically correct. Finally, the .four analysis option only works when the frequency of the AC source is specified in that source's card line, and not in an .ac analysis option line.
It helps to include a computation interval variable in the .tran card for better analysis precision. A Fourier analysis of the voltage or current specified is performed up to the 9th harmonic, with the [freq] specification being the fundamental, or starting frequency of the analysis spectrum.


MISCELLANEOUS:
General form:  .options [option1] [option2]
Example 1:     .options limpts=500
Example 2:     .options itl5=0
Example 3:     .options method=gear
Example 4:     .options list
Example 5:     .options nopage
Example 6:     .options numdgt=6
Comments: There are lots of options that can be specified using this card. Perhaps the one most needed by beginning users of SPICE is the "limpts" setting. When running a simulation that requires more than 201 points to be printed or plotted, this calculation point limit must be increased or else SPICE will terminate analysis. The example given above (limpts=500) tells SPICE to allocate enough memory to handle at least 500 calculation points in whatever type of analysis is specified (DC, AC, or transient).
In example 2, we see an iteration variable (itl5) being set to a value of 0. There are actually six different iteration variables available for user manipulation. They control the iteration cycle limits for solution of nonlinear equations. The variable itl5 sets the maximum number of iterations for a transient analysis. Similar to the limpts variable, itl5 usually needs to be set when a small computation interval has been specified on a .tran card. Setting itl5 to a value of 0 turns off the limit entirely, allowing the computer infinite iteration cycles (infinite time) to compute the analysis. Warning: this may result in long simulation times!
Example 3 with "method=gear" sets the numerical integration method used by SPICE. The default is "trapezoid" rather than "gear," trapezoid being a simple geometric approximation of area under a curve found by slicing up the curve into trapezoids to approximate the shape. The "gear" method is based on second-order or better polynomial equations and is named after C.W. Gear (Numerical Integration of Stiff Ordinary Equations, Report 221, Department of Computer Science, University of Illinois, Urbana). The Gear method of integration is more demanding of the computer (computationally "expensive") and will sometimes give slightly different results from the trapezoid method.
The "list" option shown in example 4 gives a verbose summary of all circuit components and their respective values in the final output.
By default, SPICE will insert ASCII page-break control codes in the output to separate different sections of the analysis. Specifying the "nopage" option (example 5) will prevent such pagination.
The "numdgt" option shown in example 6 specifies the number of significant digits output when using one of the ".print" data output options. SPICE defaults at a precision of 4 significant digits.


WIDTH CONTROL:
General form:  .width in=[columns] out=[columns]
Example 1:     .width out=80
Comments: The .width card can be used to control the width of text output lines upon analysis. This is especially handy when plotting graphs with the .plot card. The default value is 120, which can cause problems on 80-character terminal displays unless set to 80 with this command.

Quirks

"Garbage in, garbage out."
Anonymous
SPICE is a very reliable piece of software, but it does have its little quirks that take some getting used to. By "quirk" I mean a demand placed upon the user to write the source file in a particular way in order for it to work without giving error messages. I do not mean any kind of fault with SPICE which would produce erroneous or misleading results: that would be more properly referred to as a "bug." Speaking of bugs, SPICE has a few of them as well.
Some (or all) of these quirks may be unique to SPICE version 2g6, which is the only version I've used extensively. They may have been fixed in later versions.

A good beginning

SPICE demands that the source file begin with something other than the first "card" in the circuit description "deck." This first character in the source file can be a linefeed, title line, or a comment: there just has to be something there before the first component-specifying line of the file. If not, SPICE will refuse to do an analysis at all, claiming that there is a serious error (such as improper node connections) in the "deck."

A good ending

SPICE demands that the .end line at the end of the source file not be terminated with a linefeed or carriage return character. In other words, when you finish typing ".end" you should not hit the [Enter] key on your keyboard. The cursor on your text editor should stop immediately to the right of the "d" after the ".end" and go no further. Failure to heed this quirk will result in a "missing .end card" error message at the end of the analysis output. The actual circuit analysis is not affected by this error, so I normally ignore the message. However, if you're looking to receive a "perfect" output, you must pay heed to this idiosyncrasy.

Must have a node 0

You are given much freedom in numbering circuit nodes, but you must have a node 0 somewhere in your netlist in order for SPICE to work. Node 0 is the default node for circuit ground, and it is the point of reference for all voltages specified at single node locations.
When simple DC analysis is performed by SPICE, the output will contain a listing of voltages at all non-zero nodes in the circuit. The point of reference (ground) for all these voltage readings is node 0. For example:


node    voltage    node     voltage
(  1)   15.0000    (  2)    0.6522


In this analysis, there is a DC voltage of 15 volts between node 1 and ground (node 0), and a DC voltage of 0.6522 volts between node 2 and ground (node 0). In both these cases, the voltage polarity is negative at node 0 with reference to the other node (in other words, both nodes 1 and 2 are positive with respect to node 0).

Avoid open circuits

SPICE cannot handle open circuits of any kind. If your netlist specifies a circuit with an open voltage source, for example, SPICE will refuse to perform an analysis. A prime example of this type of error is found when "connecting" a voltage source to the input of a voltage-dependent source (used to simulate an operational amplifier). SPICE needs to see a complete path for current, so I usually tie a high-value resistor (call it rbogus!) across the voltage source to act as a minimal load.

Avoid certain component loops

SPICE cannot handle certain uninterrupted loops of components in a circuit, namely voltage sources and inductors. The following loops will cause SPICE to abort analysis:

netlist
l1 2 4 10m
l2 2 4 50m
l3 2 4 25m



netlist
v1 1 0 dc 12  
l1 1 0 150m 



netlist
c1 5 6 33u  
c2 6 7 47u 


The reason SPICE can't handle these conditions stems from the way it performs DC analysis: by treating all inductors as shorts and all capacitors as opens. Since short-circuits (0 Ω) and open circuits (infinite resistance) either contain or generate mathematical infinitudes, a computer simply cannot deal with them, and so SPICE will discontinue analysis if any of these conditions occur.
In order to make these component configurations acceptable to SPICE, you must insert resistors of appropriate values into the appropriate places, eliminating the respective short-circuits and open-circuits. If a series resistor is required, choose a very low resistance value. Conversely, if a parallel resistor is required, choose a very high resistance value. For example:
To fix the parallel inductor problem, insert a very low-value resistor in series with each offending inductor.

original netlist
l1 2 4 10m
l2 2 4 50m
l3 2 4 25m


fixed netlist
rbogus1 2 3 1e-12
rbogus2 2 5 1e-12
l1 3 4 10m
l2 2 4 50m
l3 5 4 25m


The extremely low-resistance resistors Rbogus1 and Rbogus2 (each one with a mere 1 pico-ohm of resistance) "break up" the direct parallel connections that existed between L1, L2, and L3. It is important to choose very low resistances here so that circuit operation is not substantially impacted by the "fix."
To fix the voltage source / inductor loop, insert a very low-value resistor in series with the two components.

original netlist
v1 1 0 dc 12
l1 1 0 150m


fixed netlist
v1 1 0 dc 12
l1 2 0 150m
rbogus 1 2 1e-12


As in the previous example with parallel inductors, it is important to make the correction resistor (Rbogus) very low in resistance, so as to not substantially impact circuit operation.
To fix the series capacitor circuit, one of the capacitors must have a resistor shunting across it. SPICE requires a DC current path to each capacitor for analysis.

original netlist
c1 5 6 33u
c2 6 7 47u


fixed netlist
c1 5 6 33u
c2 6 7 47u
rbogus 6 7 9e12


The Rbogus value of 9 Tera-ohms provides a DC current path to C1 (and around C2) without substantially impacting the circuit's operation.

Current measurement

Although printing or plotting of voltage is quite easy in SPICE, the output of current values is a bit more difficult. Voltage measurements are specified by declaring the appropriate circuit nodes. For example, if we desire to know the voltage across a capacitor whose leads connect between nodes 4 and 7, we might make out .print statement look like this:

c1 4 7 22u
.print ac v(4,7)


However, if we wanted to have SPICE measure the current through that capacitor, it wouldn't be quite so easy. Currents in SPICE must be specified in relation to a voltage source, not any arbitrary component. For example:

c1 4 7 22u
vinput 6 4 ac 1 sin
.print ac i(vinput)


This .print card instructs SPICE to print the current through voltage source Vinput, which happens to be the same as the current through our capacitor between nodes 4 and 7. But what if there is no such voltage source in our circuit to reference for current measurement? One solution is to insert a shunt resistor into the circuit and measure voltage across it. In this case, I have chosen a shunt resistance value of 1 Ω to produce 1 volt per amp of current through C1:

c1 4 7 22u
rshunt 6 4 1
.print ac v(6,4)


However, the insertion of an extra resistance into our circuit large enough to drop a meaningful voltage for the intended range of current might adversely affect things. A better solution for SPICE is this, although one would never seek such a current measurement solution in real life:

c1 4 7 22u 
vbogus 6 4 dc 0
.print ac i(vbogus)


Inserting a "bogus" DC voltage source of zero volts doesn't affect circuit operation at all, yet it provides a convenient place for SPICE to take a current measurement. Interestingly enough, it doesn't matter that Vbogus is a DC source when we're looking to measure AC current! The fact that SPICE will output an AC current reading is determined by the "ac" specification in the .print card and nothing more.
It should also be noted that the way SPICE assigns a polarity to current measurements is a bit odd. Take the following circuit as an example:

example    
v1 1 0    
r1 1 2 5k 
r2 2 0 5k  
.dc v1 10 10 1  
.print dc i(v1) 
.end    


With 10 volts total voltage and 10 kΩ total resistance, you might expect SPICE to tell you there's going to be 1 mA (1e-03) of current through voltage source V1, but in actuality SPICE will output a figure of negative 1 mA (-1e-03)! SPICE regards current out of the negative end of a DC voltage source (the normal direction) to be a negative value of current rather than a positive value of current. There are times I'll throw in a "bogus" voltage source in a DC circuit like this simply to get SPICE to output a positive current value:

example
v1 1 0      
r1 1 2 5k   
r2 2 3 5k        
vbogus 3 0 dc 0   
.dc v1 10 10 1    
.print dc i(vbogus)     
.end    


Notice how Vbogus is positioned so that the circuit current will enter its positive side (node 3) and exit its negative side (node 0). This orientation will ensure a positive output figure for circuit current.

Fourier analysis

When performing a Fourier (frequency-domain) analysis on a waveform, I have found it necessary to either print or plot the waveform using the .print or .plot cards, respectively. If you don't print or plot it, SPICE will pause for a moment during analysis and then abort the job after outputting the "initial transient solution."
Also, when analyzing a square wave produced by the "pulse" source function, you must give the waveform some finite rise and fall time, or else the Fourier analysis results will be incorrect. For some reason, a perfect square wave with zero rise/fall time produces significant levels of even harmonics according to SPICE's Fourier analysis option, which is not true for real square waves.

0 comments:

Post a Comment

 

Free Download Engineering Books - IEEE Books | Copyright 2009-2013 All right reserved | Design by BMW Automobiles | Created by Umair Sheikh