Professional Documents
Culture Documents
How Spice Simulates Aug 2010
How Spice Simulates Aug 2010
Hemanshu R. Pota
August 23, 2019
1 Introduction
For the half-wave rectifier shown in Figure 1, plot vL , vD , and iL for R = 10 Ω, Ls = 100 mH
when (a) vs = 50 sin 2π50t V, and (b) vs is a 50 V peak 50 Hz square waveform. For the diode use
Is = 10−14 A and VT = 26 mV.
iD D1 R iL
+ −
vD +
vs +
− Ls vL
Starting from the given initial value, we can obtain new values of iL using the following equation
inew
L = iold
L + (rate of change of iL ) × ∆t
! !
∆t iold
inew
L = iold
L + vs − VT ln L + 1 − RioldL (2)
Ls Is
t = 0:dt:tf;
Is = 10ˆ(-14); % reverse saturation current;
VT = 0.026;
gmin = 0.1;
R = 10;
Ls = 0.1;
il = zeros(1,length(t));
vs = zeros(1,length(t));
vd = zeros(1,length(t));
for k = 1:length(t)-1
vs(k) = 50*sin(2*pi*50*t(k));
if il(k) == -Is
il(k) = il(k) + 10ˆ(-10); %to make sure il(k)/Is > -1.
end;
vd(k) = VT*log(il(k)/Is + 1);
il(k+1) = il(k) + ((vs(k) - vd(k) - R*il(k))/Ls)*dt;
if il(k+1) <= -Is
vd(k) = vs(k);
il(k+1) = Is*(exp(vd(k)/VT) - 1);
end;
end;
fignum=0;
fignum = fignum + 1; figure(fignum);
plot(t,il); grid on;
xlabel(’Time (s)’); ylabel(’i_L (A)’); title(’Simple Integration’);
fignum = fignum + 1; figure(fignum);
plot(t,vs,’g’,t,vd,’r’); grid on;
legend(’vs’,’vd’);
xlabel(’Time (s)’); ylabel(’v_D (V) and v_s (V)’);
title(’Simple Integration’);
2
30
20
1.5
10
vD (V) and vs (V)
i (A)
1 0
L
−10
0.5
−20
−30
0
−40
−0.5 −50
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04
Time (s) Time (s)
The above mentioned ‘fix’ for the stiff diode nonlinearity needs a good knowledge of the circuit
How SPICE Works
A Simple Example
configuration, etc. SPICE routinely solves circuits with thousands of nonlinear elements like the
diode in Figure 1. It will be very instructive to see how SPICE handles the nonlinear elements during
its nonlinear transient analysis. Based on the material in books [1, 2] and journal papers [3, 4, 5],
written by the original researchers who helped develop SPICE, I have put together this note to explain
exactly how SPICE solves a circuit such as shown in Figure 1. I hope in this short note the genius of
the developers of the original SPICE is made clear.
for the (k + 1)st step, with known iD (k) and vD (k), the values of GD and IQ are obtained as
diD Is vD /VT
GD (k) = = e (4)
dvD iD =iD (k)
vD =vD (k) VT iD =iD (k)
vD =vD (k)
i + i + i +
+ iL
+ iD 1 +
iC
vD vD vL L vL 2L h
GD IQ h
ILQ vC C vC 2C
ICQ
− −
− − − −
j j j
3 A Simple Example
The transient analysis for the half-wave rectifier shown in Figure 1 is performed here as SPICE would
do it. The first step is to replace the diode and the inductor by their equivalents given in Figure 4.
We obtain Figure 5 after replacing the original elements in Figure 1 with SPICE equivalents from
Figure 4.
IQ (k)
R 2
1 1
+ GM +GD (k) iL (k + 1)
2Ls
vs (k + 1) h
h
v (k) + iL (k)
2Ls L
−
The nodal equations for the circuuit in Figure 5 can be written as:
v1 (k + 1) − v2 (k + 1)
At node 1: (v1 (k + 1) − vs (k + 1)) (GD (k) + GM ) + = IQ (k) (17)
R
v2 (k + 1) − v1 (k + 1) h h
At node 2: + v2 (k + 1) + v2 (k) + iL (k) = 0 (18)
R 2Ls 2Ls
In compact matrix notation the above two equations (17) and (18) can be written as
GD (k) + GM + R1 − R1
v1 (k + 1) IQ (k) + vs (k + 1) (GD (k) + GM )
= (19)
− R1 h
2Ls
+ R1 v2 (k + 1) − 2Lh s v2 (k) − iL (k)
Y (k)V (k + 1) = I(k)
The above matrix equation (19) is solved for v1 (k + 1) and v2 (k + 1). The obtained values
of the node voltages
vD (k+1)/VT
v1 (k + 1) and v2 (k + 1) must also satisfy diode equation, i.e., iD (k + 1) =
Is e − 1 . The values of iD (k + 1) and vD (k + 1) can be obtained from the node voltages
v1 (k + 1) and v2 (k + 1). If iD (k + 1) and vD (k + 1) do not satisfy the diode equation then these
new values of iD (k + 1) and vD (k + 1) are used to obtain an updated estimate of GD (k) and IQ (k)
using equations (4) and (5). With these updated values of GD (k) and IQ (k) the matrix equation (19)
is solved again and the process is continued till there is a convergence. Note that GM is not a standard
part of the diode equivalent circuit but it a term added by SPICE to improve the convergence.
Using the above described algorithm, the obtained current iL is shown in Figure 6 and the voltages
vD and vs are shown in Figure 7. The matlab script used to obtain these plots is included below.
2
30
20
1.5
10
1 0
L
−10
0.5
−20
−30
0
−40
−0.5 −50
0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04 0 0.005 0.01 0.015 0.02 0.025 0.03 0.035 0.04
Time (s) Time (s)
forms of a complete description of an electrical network and devised the A matrix [2].
This in part emanated out of his studies of dynamical systems as described in Whittaker
and Watson. The A matrix is widely accepted as the forerunner of the state-variable de-
scription of an electrical network and was used in the early years of CAD as the basis of
equation formulation in CAD programs [38]. With subsequent developments, however,
it became clear that the state-variable approach, although very significant for theoretical
studies, is not the best basis for computer programs for circuit analysis. As brought out
below, the modified-nodal and sparse-tableau formulations are better. For one who has
observed the developments in this field throughout the 30 years of its existence, the fierce
disagreements of just ten years ago on this subject make for interesting and frustrating
memories.
The above paragraph is of special interest to people with control theory background. The genius
of the nodal matrix approach is that the Y matrix, such as in equation (19) above, can be assembled by
inspection. In a computer program one has to only read the nodes to which the element is connected
and then “update” the entries corresponding to those nodes from the Y matrix of each element. The
code needed to do this would be perhaps less than a few dozen lines. As compared to this, creating an
‘A’ matrix would be quite a challenge. SPICE would not have been able to analyse integrated circuits
with hundreds of thousands of transistors had it not taken the Y matrix approach.
For an N node network referenced to a ground node, normally called the Node 0, the Y matrix is
an N × N matrix. To build the Y matrix, individual element Y matrices shown in equation (16) are
used. The update algorithm for the system Y matrix, due to an element connected between nodes i
and j, is as follows:
eq
1. Y11 term is added to Yii
eq
2. Y12 term is added to Yij
eq
3. Y21 term is added to Yji
eq
4. Y22 term is added to Yjj
This means that as each SPICE line is read, the Y matrix is built by modification of the existing
terms or adding new terms. In addition to the Y matrix, a list of all nonlinear element must also be
How SPICE Works
A Simple Example
maintained and used at each new transient analysis step. And that is about it. The transient analysis
algorithm is then solving a linear algebraic equation repeatedly and checking for the convergence
with nonlinear relationships like the diode equation. Nothing could be simpler. This simplicity of
SPICE is a work of genius.
5 Exercise
For the half-wave rectifier shown in Figure 8, plot vo , vD , iL , and is for R = 1 kΩ, C = 10 µF
when (a) vs = 50 sin 2π50t V, and (b) vs is a 50 V peak 50 Hz square waveform. For the diode use
Is = 10−14 A and VT = 26 mV.
D1
+ −
vD iL
+
+
vs + is vC C vo
− − R
Use the integration method and also the SPICE method and compare your answers.
References
[1] Andrei Vladimirescu. The SPICE Book. John Wiley & Sons, Inc., Brisbane, 1994.
[2] Ron M. Kielkowski. Inside SPICE: Overcoming the obstacles of circuit simulation. McGraw-
Hill, Inc., Sydney, 1994. ISBN 0-07-911525-X.
[3] Donald O. Pederson. A historical review of circuit simulation. IEEE Trans on Circuits and
Systems, CAS-31(1):103–111, January 1984.
[4] William J. McCalla and Donald O. Pederson. Elements of computer-aided circuit analysis. IEEE
Trans on Circuits Theory, CT-18(1):14–26, January 1971.
[5] Arthur Richard Newton and Alberto L. Sangiovanni-Vincentelli. Relaxation-based electrical sim-
ulation. IEEE Trans on Computer-Aided Design, CAD-3(4):308–331, October 1984.