Professional Documents
Culture Documents
R
1
------------------
\ .
| |
I
2
V
1
V
2
+ ( )
R1
-----------------------
0 V
2
( )
R
2
-------------------- + + 0 =
V
1
V
2
V
1
V
2
V
1
V
2
V
1
1.2 = V
2
0.2 =
How SPICE Works
J uly 2003
Page 3 of 11
SIMetrix Technologies Ltd
sources and resistors. Voltage sources can also be implemented using an elaboration of the above known as
Modified Nodal Analysis or MNA for short.
The procedure the software uses to build the above equations differs somewhat from the above but the
resulting equations are the same; they are just expressed differently. For a more detailed discussion, please
see the references at the end of this note.
DEAL I NG WI TH NON- L I NEAR DEVI CES
As described above, we can solve circuits containing non-linear devices by using an iterative method called
Newton-Raphson iteration. The technique makes use of the fact that a non-linear device can be treated as
linear over a small range. You are probably already familiar with small signal models for semiconductor
devices. For example, the following small-signal model for a bipolar transistor is found in most text books
on analog circuit theory:
But, as this model only works for changes in signal voltage, it cannot be used for a DC analysis as its bias
conditions are not included. We can accommodate this, however, by adding a DC current source in parallel
with rpi and an additional DC current term to the collector current. These additions will account for the bias
conditions. This is what we have after these changes:
Ib and Ic in the above are worked out so that the bias conditions are maintained.
The model above is linear and therefore any circuit using it can be solved using nodal analysis as described
in the previous section. Such an analysis will not straight away give us the correct answer as this simple
model is only valid for a small range of operating conditions. But the model can be used to provide us with a
better answer than an initial guess. So this is the procedure:
1. Assign an initial guess to the terminal voltages of non-linear devices
C
i =vbe * gm
rpi
E
B
B
E
rpi
i =vbe * gm+Ic
C
Ib
How SPICE Works
J uly 2003
Page 4 of 11
SIMetrix Technologies Ltd
2. From their terminal voltages, work out a modified small signal model for each non-linear device. For
example, for the small signal BJ T above, the values of rpi and gm can be calculated from collector cur-
rent and the gain of the device. Once we have those, the values of Ib and Ic can be calculated.
3. Perform nodal analysis as described in the previous section
4. The nodal analysis will yield new values for all the terminal voltages. Reapply and repeat from step 2.
This procedure is repeated until a result of sufficient accuracy is reached. Accuracy is measured by
comparing the results of successive iterations. The values returned for each node voltage will be become
increasingly close the values returned by the previous iteration as the solution converges. When the values
for consecutive iterations differ by less than a certain tolerance, the sequence is considered to be complete.
AN EXAMPLE
Lets consider our diode circuit once again. You are probably familiar with the concept of dynamic
resistance and probably also know that the dynamic resistance of a diode at 25C is approximately
where is the diode current measured in mA. A single resistor equal to the dynamic resistance is therefore
our small signal model for a diode. As described for the transistor above, we must also account for the DC
conditions and to do this, we place a fixed current source in parallel with the resistor.
This is what results:
The diode has been replaced by Rd and Ieq.
What we now have is a circuit that can be solved using nodal analysis. When this solution is completed we
will have a new value for the diode voltage which, although unlikely to be the right answer, will be closer
than our original guess.
By repeating this procedure we will ultimately converge on the desired solution.
To demonstrate the method, we have prepared an Excel spreadsheet to solve the simple diode circuit. The
results are shown below.
25.8
i
d
----------
i
d
42.50461516
Rd
5
V1
1K
R1
-0.015861807
Ieq
How SPICE Works
J uly 2003
Page 5 of 11
SIMetrix Technologies Ltd
.
In the above example, we started with a guess of 0.7 for the diode voltage. The Id column above is the diode
current calculated from its voltage drop Vd. Ieq is the equivalent current, that is the value of the current
source placed in parallel with Rd to maintain the original voltage drop and diode current. Ieq has a value of
Id-Vd/Rd.
The last column is the new value for the diode voltage and this is used as the starting point for the following
iteration. So from an initial guess of 0.7V we calculated a new estimate of 0.85057. This value is then
entered in the following row and the process is repeated. The final answer of 0.75021 is accurate to at least 5
digits and was achieved after 10 iterations.
HOW WAS THE DIODES CURRENT CALCULATED?
In the above we glossed over how we calculated the diodes current from its voltage. In the spreadsheet
example we used the simple formula:
where =25.8mV @ 25C
IS is a model parameter and is typically 1e-15.
In general, it is a requirement for all SPICE device models to provide a means to calculate all the devices
pin currents given its terminal voltages. It is also a requirement to provide the dynamic resistance term given
its terminal voltages.
REACTI VE EL EMENTS
We will look at how SPICE deals with capacitors but the manner in which SPICE implements other devices
such as inductors is the same.
Note that we are referring to how SPICE deals with capacitors in transient analysis. In AC analysis,
VD ID RD IEQ NEWV
0.7 0.000607 42.50462 -0.01586 0.85057
0.85057 0.207848 0.124129 -6.64444 0.825288
0.825288 0.078014 0.330709 -2.4175 0.800877
0.800877 0.030287 0.851853 -0.90987 0.778673
0.778673 0.012808 2.014318 -0.37376 0.761411
0.761411 0.00656 3.932815 -0.18704 0.752316
0.752316 0.004611 5.594931 -0.12985 0.750293
0.750293 0.004264 6.051335 -0.11972 0.75021
0.75021 0.00425 6.070856 -0.11933 0.75021
0.75021 0.00425 6.070888 -0.11933 0.75021
I
d
I S e
V
d
VT
-------
\ .
| |
1
\ .
|
| |
=
VT
q
KT
------- =
How SPICE Works
J uly 2003
Page 6 of 11
SIMetrix Technologies Ltd
capacitors are treated in the same way as resistors but with a complex value. Implementing capacitors in
transient analysis is an altogether more difficult problem.
To understand the method used, consider the following circuit
We wish to find a method of calculating the voltage on C1 at some time in the future using only the
information we know about the capacitor at t=0. This is:
1. The value of the capacitance =C
2. The current in the capacitor =
3. The voltage across the capacitor =
Although in the above circuit we also know that the capacitor is being driven by a fixed voltage via a fixed
resistor this is just a simple example. In reality the capacitor could be connected via a non-linear diode, or
the voltage might be ramping or all sorts of other situations.
So with this information alone, what might we do. One very simple way of arriving at an approximate value
is to assume that the current at will remain constant and use this to find the rate of rise of the voltage.
So:
Eqn 1
this can be rearranged to:
Eqn 2
Where is the capacitor voltage at
We could implement this by replacing the capacitor with a voltage source with a value equal to as shown
below.
1n
C1
1K
R1
5V
i
0
v
0
t 0 =
i
0
C
v
1
v
0
( )
At
--------------------- ~
v
1
v
0
i
0
At
C
---------- + ~
v
1
t At =
v
1
How SPICE Works
J uly 2003
Page 7 of 11
SIMetrix Technologies Ltd
The voltage source would need to be recalculated at each time step. This approach is reasonably accurate as
long as is kept small. Unfortunately, this method has a fundamental flaw that makes it almost useless in a
circuit simulator. To understand this flaw, consider the situation when the voltage on the capacitor is 4.999V.
In this case the capacitor is, for all intents and purposes, fully charged so we no longer want to be using
small time steps to be simulating it. So lets consider the result if we made the timestep 1mS:
From the above eqn.
This clearly not a very useful result! What we have done here is assume that the capacitors current - 1A -
will remain constant for the entire 1mS period. Clearly this is not the case. In reality the capacitors current
will decay exponentially to near zero in this time.
What this means is that even though the capacitor has stabilised, we will need to maintain small time steps in
the simulator to keep its voltage stable. In mathematical jargon the method is not stiffly stable. Also in
mathematical jargon, this technique is known as the Forward Euler integration method. SPICE does not use
this technique, we have only included it to help understand why it uses other slightly more complicated
methods. The simplest method it uses is called the Backward Euler integration method. We explain this now.
In Eqn 1 we said:
But the following is just as valid
Eqn 3
This is a little trickier to understand as is unknown so we cant directly derive an expression for . This
is isnt actually a problem. It simply means we cant implement the capacitor as a fixed voltage source. We
can however implement the above by replacing the capacitor with a current source in parallel with a resistor.
This is of course the same network we used to implement our non-linear diode.
This is what we will present to the simulator:
v1
1K
R1
5
At
v
1
4.999
i
0
1 e
3
1e
9
--------------------- + =
i
0
5 4.999
1000
---------------------- 1e
6
= =
v
1
5.999 =
i
0
C
v
1
v
0
( )
At
--------------------- ~
i
1
C
v
1
v
0
( )
At
--------------------- ~
i
1
v
1
How SPICE Works
J uly 2003
Page 8 of 11
SIMetrix Technologies Ltd
At the current in our capacitor will be:
Eqn 4
Expanding Eqn 3
Eqn 5
Eqn 4 and Eqn 5 are equivalent if:
and
So we can therefore implement this method by replacing the capacitor with the parallel combination of a
resistor of value and a current source of value
Do this and we have implemented the Backward Euler integration method. Now lets consider the same
scenario that we described earlier where the capacitor is at 4.999V and we set the time step to 1mS. From the
above:
This is the result:
Req
1K
R1
5
V1
Ieq
At
i
1
v
1
1
r
eq
------- i
eq
+ =
i
1
v
1
C
At
-----
v
0
C
At
--------- ~
1
r
eq
-------
C
At
----- =
i
eq
v
0
C
At
--------- =
At
C
-----
v
0
C
At
---------
r
eq
At
C
-----
1e
3
1e
9
---------- 1e
6
= = =
i
eq
v
0
C
At
---------
4.999 1e
9
1e
3
------------------------------ 4.999e
6
= = =
How SPICE Works
J uly 2003
Page 9 of 11
SIMetrix Technologies Ltd
When we work this out we get a value of 4.999999001 which is very accurate. So this method is said to be
stiffly stable.
SPICE doesn't often use this method unless you set MAXORD to 1 in which case it uses it all the time. It
uses this technique for the first time point and also after every breakpoint. These occur at turning points on
waveforms such as the beginning of a pulse. With default settings, SPICE usually uses another method
known as trapezoidal rule. This is also stiffly stable but has the advantage of producing a more accurate
answer for a given time step. We describe this method next.
TRAPEZOIDAL RULE
From Eqns 1 and Eqn 3
These approximate the current in the capacitor at and using the voltages at and . However, the
expression would seem to be a more accurate approximation to the average of the currents at
and so:
Rearranging we get:
Using the same transformations to get and :
1Meg
R2
1K
R1
5
V1
-4.999e-6
I1
i
0
C
v
1
v
0
( )
At
--------------------- ~
i
1
C
v
1
v
0
( )
At
--------------------- ~
t
0
t
1
t
0
t
1
C
v
1
v
0
( )
At
--------------------- t
0
t
1
i
0
i
1
+ ( )
2
-------------------
C v
1
v
0
( )
At
------------------------- =
i
1
2Cv
1
At
------------
2Cv
0
At
------------ i
0
=
r
eq
i
eq
r
eq
At
2C
------- =
How SPICE Works
J uly 2003
Page 10 of 11
SIMetrix Technologies Ltd
This is the trapezoidal rule or the trapezoidal integration method. SPICE uses this most of the time when
METHOD=TRAP (the default) and MAXORD=2 (also the default).
We have used a somewhat informal method to derive this formula but in fact the formal derivation is done
by using the trapezoidal method to numerically integrate the differential equation that describes a capacitor.
This is where it gets its name from.
RESULTS
The following graph shows the results obtained using the two methods used along with the exact theoretical
result. The values were calculated using a fixed time step of 500nS. As you can see, the trapezoidal result is
considerably more accurate than Backward Euler. The Excel spreadsheet used to create this graph is
provided - see How SPICE Works.XLW on the resources page.
WHERE NEXT?
This technical note has explained some of the basics but there is a lot we havent covered. We havent
i
eq
2Cv
0
At
------------ i
0
=
Int egrat i on Met hods
0
1
2
3
4
5
6
0 1 2 3 4 5 6 7 8 9 10
Backward Euler Result
Exact Result
Trapezoidal
How SPICE Works
J uly 2003
Page 11 of 11
SIMetrix Technologies Ltd
mentioned how the time step size is controlled to maintain accuracy; we havent mentioned the limiting
algorithm needed to cope with exponential functions found in diodes and other devices; we havent
mentioned that the Newton-Raphson iteration doesnt always converge on a solution and how this problem
is dealt with; we havent mentioned Gear integration. We also havent explained how AC, noise and other
small signal analyses work.
If you are interested in any of these topics, you might like to look at some of these references:
The SPICE Book - Andrei Vladimirescu, J ohn Wiley and Sons, ISBN 0-471-60926-9.
Probably the best general book on SPICE. Not everything is relevant to SIMetrix but provides much detail
including a chapter on how SPICE works.
SPICE2: A Computer Program to Simulate Semiconductor Circuits - Laurence W. Nagel, University of
California, Berkeley. Memorandum No, ERL-M520. Follow this URL for information on how to obtain this
document - http://www.eecs.berkeley.edu/IPRO/Software/
This is the original doctorate thesis describing the SPICE algorithms.