Circuit Simulation with SPICE - Auburn University



CHAPTER 3

Introduction

to Numerical

Analysis of

Electronic

Circuits

There are two general approaches for analysis of linear circuits: mesh analysis and nodal analysis. Mesh analysis is basically limited to planar circuits, i.e., circuits which can be drawn on a sheet of paper in such a way that there are no crossing branches. In this case there is always one unique set of equations corresponding to meshes described by Kirchhoff’s voltage law. It is also possible to solve non planar circuits using a mesh type approach, but in this case many different loops (meshes) are possible and it is not a trivial task to track them by a computer. In contrast to mesh analysis, nodal analysis always has one unique set of corresponding equations whether the circuit is planar or not. Nodal analysis is therefore the basis for most of the computer methods of circuit analysis.

For linear circuits, the analysis consists of two basic steps: automatic formation of the node equations, and the solution of these linear equations. For frequency analysis, each reactive element, such as an inductor or a capacitor, is described by complex numbers, but the method is basically the same, using complex numbers instead of real numbers. When a sweep frequency analysis is required, the appropriate complex number describing each circuit element is first found, and then the set of linear equations with complex coefficients is solved repeatedly for each frequency point.

Practical circuits usually contain many nonlinear elements such as diodes and transistors, and nonlinear analysis is required. In this case, the common approach uses a linearization of the circuit. This circuit linearization leads directly to the Newton-Raphson method for solution of a set of nonlinear equations. This method is known to be very fast and efficient but sometimes has convergence problems. The problem of convergence is therefore a common one for SPICE programs - especially in early program versions.

1 Matrix Formation for Nodal Analysis

Each real voltage source always has internal series resistance, and therefore its Thévenin equivalent can be transformed to the Norton equivalent as Fig. 3.1.1 shows. A traditional nodal analysis can deal only with current sources and resistive elements.

[pic]

Fig. 3.1.1. Thévenin and Norton equivalents

The dc solution of a linear circuit requires a formulation of the matrix Y and the vector I of the current sources. Node voltages v are solutions of the set of linear equations:

[pic] (3.1.1)

Formation of the Y matrix and I vector can be done automatically. For resistors, independent current sources, and voltage-controlled current sources values are added to the Y matrix and I vector. In the case of other elements such as independent voltage sources and other dependent sources, a modified Y matrix and modified I vector must be used.

In theory each ideal voltage source could reduce the circuit complexity by eliminating from analysis one of the two nodes coupled by the voltage source. Of the two nodes coupled by the voltage source, one node could remain in the analysis and the second could become a virtual node whose voltage differs by the fixed voltage of the independent voltage source. However, this approach is difficult to implement on the computer.

In the approach used in SPICE, each voltage source, instead of reducing the number of equations, adds more equations to the system by treating the current through the voltage source as a new unknown. This approach is known as MNA (modified nodal analysis). In this case, currents through voltage sources are treated as additional variables. There are n + m independent variables: n node voltages and m currents through voltage sources, both independent and dependent.

[pic] (3.1.2)

The modified Y matrix consists of various types of elements, and the forcing vector I has both currents and voltages. Even though it does not follow the traditional convention in which the Y matrix has only conductances, we still use the symbol Y for the modified matrix and the symbol I for the modified vector. The u elements are always equal to zero, with the exception of the current-controlled voltage sources. The formation of the Y matrix and I vector can be done automatically.

1 Resistors

[pic]

Each resistor, described by the SPICE statement Rxxx i j Rk, connected between nodes i and j will add four values to the Y matrix:

[pic] (3.1.3)

Node voltages vi and vj are the independent variables affected by the resistor Rk connected between nodes i and j.

2 Independent current sources

[pic]

Each current source, described by the SPICE statement Ixxx i j Ik, with current flowing from node i to node j , will add two elements to the I vector:

[pic] (3.1.4)

A constant current source changes only components of the forcing vector I.

3 Voltage-controlled current sources

[pic]

Each voltage-controlled current source, described by the SPICE statement Gxxx i j p q Gk, will add four elements to the Y matrix:

[pic] (3.1.5)

4 Example with the standard Y matrix approach

Let us consider the circuit example shown in Fig. 3.1.2. The Y matrix and the I vector for this circuit are included in Figure 3.1.3. Resistors are included using formula (3.1.3), the independent current source using formula (3.1.4), and the voltage-controlled current source using formula (3.1.5). Note that the equation for the zero (grounded) node is not formed. Independent voltage sources, current controlled-current sources, and dependent voltage sources cannot be incorporated into the Y matrix. Only resistors, independent current sources, and voltage-controlled current sources can be incorporated into the standard Y matrix and into the vector I of current excitations. Other dependent sources require the modified nodal analysisapproach.

[pic]

Fig. 3.1.2. Example of a circuit with independent and dependent current sources.

[pic]

Fig. 3.1.3. Y matrix and I vector for the example of Figure 3.1.2.

5 Independent voltage sources

[pic][pic]

Each voltage source, as shown above, is described by the SPICE statement Vxxx i j Vk, where i and j are the positive and negative nodes, respectively, and will add additional equations to the modified nodal analysisof Eq. (3.1.2):

[pic] (3.1.6)

where k is the index of the additional equation related to the additional variable ik.

6 Current-controlled current sources

[pic]

The current source shown is controlled by the current of independent voltage source VK and the kth equation for the independent voltage source already exists. To incorporate the current-controlled current source, additional values must be added to existing elements of the modified Y matrix. The current-controlled current source is described by the SPICE statement Fxxx i j VK Ai where source current flows from node i to node j, VK is the name of independent voltage source, and Ai is the current gain. The following elements of the Y matrix must be modified:

[pic] (3.1.7)

where the index k corresponds to the already existing equation of the independent voltage source, whose current is used to control the dependent current source.

7 Voltage-controlled voltage sources

[pic]

The voltage-controlled voltage source, shown above, is described by the SPICE statement Exxx i j p q Av where i and j are the positive and negative nodes of the controlled voltage source, p and q are the positive and negative control nodes, and Av is the voltage gain. The voltage-controlled voltage source adds an additional equation, with index k, to the modified nodal analysis of Eq. (3.1.2):

[pic] (3.1.8)

Index k corresponds to the additional equation representing additional current variable ik.

8 Current-controlled voltage sources

[pic]

The current-controlled voltage source shown is described by the SPICE statement Hxxx i j VK Rl where i and j are the positive and negative nodes of the controlled voltage source, VK is the name of the independent voltage source with control current ik, and Rl is the transresistance. The voltage-controlled voltage source adds an additional equation with index l to the modified nodal analysis, which corresponds to the dependent voltage source between nodes i and j. Note that the equation describing control voltage source VK, with the index k, must be incorporated earlier into the equation set.

[pic] (3.1.9)

k is the index of the independent source equation with the additional variable ik, and l is the index of the dependent voltage source with additional variable il.

9 Example with the modified Y matrix approach

[pic]

Fig. 3.1.4. Example of circuit with various dependent sources

Let us consider the circuit example shown in Fig. 3.1.4, which consists of various controlled voltage and current sources. The circuit contain six independent nodes and four currents through the voltage sources, and it is described by ten linear equations:

[pic] (3.1.10)

[pic] (3.1.11)

[pic] (3.1.12)

[pic] (3.1.13)

[pic] (3.1.14)

[pic] (3.1.15)

[pic] (3.1.16)

[pic] (3.1.17)

[pic] (3.1.18)

[pic] (3.1.19)

Above equations corresponds to the matrix equation shown in Fig. 3.1.5:

[pic]

Fig. 3.1.5. Y matrix and I vector for the example of Figure 3.1.4.

The Y matrix and I vector shown in Fig. 3.1.5 can be formed automatically using equations (3.1.3) through (3.1.9). Note that the modified matrix Y has many zeros on the main diagonal. This situation is not desired when LU decomposition or Gaussian elimination is used to solve this equations but can be corrected by reordering the equations. Another possible approach is to pack equations by adding them together and eliminating independent current variables.

10 Capacitors and inductors

For frequency analysis, .AC, capacitors and inductors are incorporated into the Y matrix the same way as resistors. The only difference is that complex numbers are used instead of real numbers. For each frequency, a different value is used for capacitors (-j/2pfC ) and inductors (j2pfL). For the transient analysis case, both capacitors and inductors are represented by equivalent resistances and current sources. The parameters of these current sources and resistors are modified at each time step. Various equivalent diagrams are used depending on the integration scheme.

2 dc Analysis

When a circuit consists only of linear elements, as in Sections 3.1.1 and 3.1.2, then results can be obtained in one iteration by solving the set of linear equations. In the case of nonlinear elements such as diodes and transistors, many iterations may be required. At each iteration, the nonlinear elements are linearized using the dc solution from the previous iteration. This approach is also known as the Newton-Raphson method. Figure 3.2.1 illustrates the linearization process for a diode.

[pic]

Fig. 3.2.1. Linearization of a diode.

The bipolar transistor can be modeled using nonlinear diodes and linear dependent current sources. FETs and MOS transistors exhibit a different type of nonlinearity, but the approach is similar. Note that at each iteration, a solution is found only for a linearized circuit.

The described approach has several problems:

• For some circuits, such as an oscillator there are no stable dc solutions.

• Bistable circuits such as flip-flops usually converge to one of two possible states, but with perfectly symmetrical circuits a solution can be obtained only when the initial starting point is unbalanced.

• The Newton-Raphson method is known as very fast, but for some types of nonlinearities it will oscillate without converging to the solution. Choosing a different starting point closer to the solution will usually solve this difficulty. Lowering supply voltages may sometimes help.

• Semiconductor junctions, which are described by exponential relationships, may lead to huge values of currents that exceed the computer’s computational range.

3 ac Analysis

The ac analysis of linear circuits is similar to the dc analysis of linear circuits, but complex numbers must be used instead of real numbers. Each reactive element such as capacitance, inductance or a transformer is described by an imaginary number. For each frequency point, the Y matrix has to be modified using the imaginary value -j/2pfC for each capacitance and j2pfL for each inductance. Complex arithmetic must be used to solve the set of linear equations with complex coefficients.

When ac analysis is performed for a nonlinear circuit, the circuit is first linearized around the bias point and then imaginary values of reactive elements are added. Since this is a linear problem, a solution will be obtained for any magnitude of the input signal. The commonly used 1V input magnitude often leads to large values of the output voltages. These large values are often misleading because they do not mean that the actual voltages can be that large.

[pic]

Fig. 3.4.1. Comparison of various integration methods: (a) forward Euler, (b) backward Euler, (c) trapezoidal, and (d) Gear 2d order.

4 Transient Analysis

Transient analysis requires performing a nonlinear analysis at every given time step. Various integration schemes are used such as forward Euler, backward Euler, trapezoidal or Gear methods. Commonly used integration schemes are shown in Fig. 3.4.1.

The simplest integration method is the forward Euler method. It uses the present values of voltages and currents[pic]and the present value of the time derivatives [pic]

[pic] (3.4.1)

The forward Euler integration scheme allows for explicit calculations of subsequent time steps without the necessity of a solution to a set of equations. This method works only for very small time steps, and if the time step is increased too far, it leads to unstable oscillatory solutions.

The backward Euler method is unconditionally stable for any size of the time step [pic] but being an implicit method, it requires solution of a set of equations for each time step.

[pic] (3.4.2)

During transient analysis, with the backward Euler integration scheme at each time step, the capacitances and inductances are replaced by independent current sources and resistors. The substitution method is shown in Fig. 3.4.2

[pic]

Fig. 3.4.2. Capacitor and inductor equivalent diagrams for transient analysis using the backward Euler integration formula.

The trapezoidal method is also unconditionally stable for any size of the time step [pic] and since it is also an implicit method, it requires solution of a set of equations for each time step. The trapezoidal method calculates the new value as the average of results obtained using the forward and backward Euler formulas

[pic] (3.4.3)

[pic] (3.4.4)

With the trapezoidal integration scheme, the capacitances and inductances are replaced by independent current sources and resistors at each time step. The substitution method is shown in Fig. 3.4.3. As Fig. 3.4.1(c) illustrates, the trapezoidal method is much more accurate than Euler methods. Although it is stable for any size of time step, it leads to larger errors for large time steps than does the backward Euler method. For very large time steps, the backward Euler integration scheme converges to the dc solution, while the trapezoidal method leads to an inaccurate solution.

[pic]

Fig. 3.4.3. Capacitor and inductor equivalent diagrams for transient analysis using the trapezoidal integration formula.

Gear methods use information from the previous steps. This way the new value can be predicted more accurately. Although the idea is simple, it works well in analog-type circuits without step excitations, such as oscillators. In the case of digital circuits, where many step-type stimulations occur, a high order Gear method does not work very well because the information from the past becomes irrelevant due to the changing excitation. The first-order Gear method is the same as the backward Euler integration formula. The second-order Gear method uses the information from the previous time step [pic]

[pic] (3.4.5)

[pic] (3.4.6)

With the second-order Gear method the capacitances and inductances are replaced by independent current sources and resistors at each time step. The substitution method is shown in Fig. 3.4.4. This method leads to slightly better results than the trapezoidal method but only when the computation process is continuous and is not disturbed by rapid changes from external excitations, as is often the case for digital circuits. Using the .OPTION statement, the SPICE user may chose the integration method by specifying METHOD=GEAR or METHOD=TRAP.

Note that during transient analysis, the circuit is reduced to a circuit of only sources and resistors for each time step. Both nonlinear elements and reactive elements are replaced by an independent current source and a parallel resistor. Depending upon of the type of elements and the integration methods the values of current sources and resistors are computed differently, as shown in Figs. 3.2.1, 3.4.2, 3.4.3, and 3.4.4.

[pic]

Fig. 3.4.4. Capacitor and inductor equivalent diagrams for transient analysis using the second-order Gear integration formula.

5 Writing Your Own Code for dc Analysis

Various software packages or programming languages, or even a programmable calculator, can be used for dc analysis. We will use the MATLAB code as being most compact. The methods described above are general, and they are implemented in SPICE programs. Although they are general, they are not always the most efficient. Depending on the specific circuitry, other approaches can be easier to use for your own computations. A few simple methods for circuit analysis, which are not implemented in SPICE, will be described.

1 Resistive ladder-type circuit

The circuit shown in Fig. 3.5.1 has seven nodes, and traditional nodal analysis will lead to a set of seven equations with seven unknowns. A similar set of equations would be required for mesh analysis. This circuit can be solved very efficiently with a “try and correction” method.

[pic]

Fig. 3.5.1. Ladder-type resistive circuit.

In the circuit we would like to find the voltage VO for a given excitation VB. The simple method starts with the assumption that voltage VO is given, say, equal 1V. The current through resistor R14 is I(R14)=Vo/R14, and the voltage across resistor R12 is V(R12) = I(R14)*(R13+R14). The current through R12 is I(R12)=V(R12)/R12, and the current through R11 is I(R11) = I(R12)+I(R14); therefore, the voltage across resistor R10 is V(R10) = V(R12)+I(R11)*R11. This explicit computation process continues until a value VB’ for voltage VB is obtained. Obviously, the value VB’ differs from VB, since we have arbitrarily assumed that VO =1V. Now we may calculate the value of VO needed in order to obtain VB’=VB

[pic] (3.5.1)

Figure 3.5.2 shows the MATLAB code written for this example. Note that with the described approach there is no need for solution of a set of linear equations. When currents and voltages are required, the computation should be repeated using the correct value of the voltage VO.

|% Computation of Resistive Ladder |

|VB=12; R1=4.3; R2=12.2; R3=5.7; R4=8.9; R5=3.5; R6=9.7; R7=8.6; |

|R8=11.3; R9=9.2; R10=7.4; R11=5.8; R12=9.1; R13=7.4; R14=9.3; |

|VO=1; %assume 1V for VO |

|i14=VO/R14; i13=i14; v12=VO+i13*R13; |

|i12=v12/R12; i11=i12+i13; v10=v12+i11*R11; |

|i10=v10/R10; i9=i10+i11; v8=v10+i9*R9; |

|i8=v8/R8; i7=i8+i9; v6=v8+i7*R7; |

|i6=v6/R6; i5=i6+i7; v4=v6+i5*R5; |

|i4=v4/R4; i3=i4+i5; v2=v4+i3*R3; |

|i2=v2/R2; i1=i2+i3; VBP=v4+i3*R3 % value of VB' calculated |

|VO=VO*VB/VBP % finding required value of Vo |

|% verification and calculation of all currents and voltages |

|i14=VO/R14; i13=i14; v12=VO+i13*R13; |

|i12=v12/R12; i11=i12+i13; v10=v12+i11*R11; |

|i10=v10/R10; i9=i10+i11; v8=v10+i9*R9; |

|i8=v8/R8; i7=i8+i9; v6=v8+i7*R7; |

|i6=v6/R6; i5=i6+i7; v4=v6+i5*R5; |

|i4=v4/R4; i3=i4+i5; v2=v4+i3*R3; |

|i2=v2/R2; i1=i2+i3; VBP=v4+i3*R3 % value of VB' verified |

| |

Fig. 3.5.2. MATLAB code for the circuit of Figure 3.5.1.

The code of Fig. 3.5.2. produced the following result:

VO = 1

VBP = 92.6374

VO = 0.1295

VBP = 12.0000

Assuming VO = 1 V the voltage VB’ is calculated as 92.6374 V. Therefore VO is reduced by 92.6374/12 times to 0.1295. With the second round of calculations, VB’ is equal to 12 V as required.

2 Nonlinear circuit with resistor and diode

A simple resistor and diode circuit is shown in Fig. 3.5.3(a). This nonlinear circuit has to be solved using the iterative approach. Various solution methods can be used. Let us start with the algorithm used in the SPICE program, described in Section 3.2. The diode characteristics are linearized and replaced by the voltage source and series resistor shown in Fig. 3.5.3(b), and then by the Norton equivalent. The equivalent circuit is shown in Fig. 3.5.3(c). By solving node equations, the node voltages can be obtained. In our example, voltage v is found from a one-node problem. The next step is to find actual currents in the nonlinear elements and the linearized parameters around the bias point. The diode current is calculated using the nonlinear diode equation, and then this current is used to find the small-signal diode conductance. The MATLAB code for this case is shown in Fig. 3.5.4. Results are presented in the second column of Fig. 3.5.7. Note that the voltage change from one iteration to another never changes by more than VT = 25mV. The algorithm requires 10 iteration steps before it converges to the solution within computer accuracy.

[pic]

Fig. 3.5.3. Diode and resistor circuit: (a) actual circuit, (b) diode equivalent circuit, (c) linearized equivalent diagram used in SPICE programs, and (d) equivalent diagram for the modified algorithm with very fast convergence.

For hand calculations it is much simpler to use the Gauss-Seidel algorithm. The current through the resistor and then the voltage drop on the diode are calculated in each iteration step. For the circuit shown in Fig. 3.5.3(a), this algorithm is not only simpler but also converges much faster than the algorithm used in the SPICE program. The MATLAB code for the Gauss-Seidel algorithm is presented in Fig. 3.5.5. The algorithm works well for large VS voltages; in our example it reaches solution with 6 iterations as shown in the third column in Fig. 3.5.7. Unfortunately, when VS is small, this algorithm will fail.

|%Resistor-diode circuit calculations using Newton-Raphson method |

|similar to this implemented in SPICE programs |

|Is = 1e-14; n=1; VT=0.025; R=1000; VS=5; |

|VD=0.8; r=0; %initial conditions |

|for j=1:10 |

|ID=Is*exp(VD/VT); |

|r=VT/ID; |

|i=VS/R+(VD-VT)/VT*ID; |

|VD=i*R*r/(R+r); |

|Vdiode(j)=VD; |

|end; |

|format long; Vdiode' |

Fig. 3.5.4. MATLAB code for the circuit of Fig. 3.5.3(a) using the Newton-Raphson approach as implemented in SPICE programs.

It is possible to combine both approaches, by using the linearized model and the logarithmic function for computation of the diode voltage. The MATLAB code for this combined approach is shown in Fig. 3.5.6. First the current between the two voltage sources shown in Fig. 3.5.3(d) is calculated. Then using the current, the voltage drop on the diode is calculated. This algorithm converges very rapidly, and it is stable for any biasing voltage VS. In our example, the solution is obtained with three iterations, as shown in the fourth column of Fig. 3.5.7. Note that by using the Gauss-Seidel or the combined approach, the solution can be obtained with three-digit accuracy after the first iteration, while the approach used in SPICE programs would require 6-7 iterations for the same accuracy.

|%Resistor-diode circuit calculations using Gauss-Seidel approach |

|Is = 1e-14; n=1; VT=0.025; R=1000; VS=5; |

|Vd=0.8; r=0; %initial conditions |

|for i=1:7 |

|Id=(VS-Vd)/R; |

|Vd=VT*log(Id/Is); |

|Vdiode(i)=Vd; |

|end; |

|format long; Vdiode' |

Fig. 3.5.5. MATLAB code for the circuit of Fig. 3.5.3 using the iterative Gauss-Seidel algorithm, which is easy to use for hand calculations.

|%Resistor-diode circuit calculations |

|%using combination of Newton-Raphson and Gauss-Seidel methods |

|Is = 1e-14; n=1; VT=0.025; R=1000; VS=5; |

|Vd=0.8; r=0; %initial conditions |

|for i=1:4 |

|vD=Vd-VT; Id=(VS-vD)/(R+r); |

|Vd=VT*log(Id/Is); |

|r=VT/Id; |

|Vdiode(i)=Vd; |

|end; |

|format long; Vdiode' |

Fig. 3.5.6. MATLAB code for the circuit of Fig. 3.5.3 using the combined approach.

|iteration |SPICE approach |Gauss-Seidel approach |Combined approach |

|0 |0.80000000000000 0.77513376101368 |0.80000000000000 |0.80000000000000 |

|1 |0.75049752984841 |0.66908801370560 |0.66923638209359 |

|2 |0.72647758058525 |0.66985535407907 |0.66985090596360 |

|3 |0.70405266089891 |0.66985092424789 |0.66985094967660 |

|4 |0.68539476914791 |0.66985094982341 | |

|5 |0.67380756133803 |0.66985094967575 | |

|6 |0.67014670368126 |0.66985094967660 | |

|7 |0.66985268232125 | | |

|8 |0.66985094973629 | | |

|9 |0.66985094967660 | | |

|10 | | | |

Fig. 3.5.7. Diode voltages for subsequent iterations for three different algorithms.

3 Bipolar transistor biasing

The bipolar transistor biasing circuit shown in Fig. 3.5.8(a) can be represented by its linearized equivalent shown in Fig. 3.5.8(b). Note a similarity to the circuit shown in Fig. 3.5.3(d). Therefore, for the bipolar biasing circuit the same combined algorithm can be used as for the diode circuit. The MATLAB code is presented in Fig. 3.5.9, with the results given in Fig. 3.5.10.

[pic]

Fig. 3.5.8. Bipolar transistor biasing circuit: (a) actual circuit and (b) equivalent diagram for the combined algorithm.

|%Bipolar transistor circuit biasing |

|%using combination of Newton-Raphson and Gauss-Seidel methods |

|Ieo=1e-14; n=1; VT=0.025; beta=200; Vdd=12; |

|R1=1E5; R2=2E4; RC=5.6E3; RE=1.0E3; |

|VBE=0.7; r=0; VT=n*VT; % initial conditions |

|VS=R2/(R1+R2)*Vdd; RS=R1*R2/((R1+R2)*(beta+1)); % Thevenin equivalent |

|for i=1:5 |

|vj=VBE-VT; IE=(VS-vj)/(RS+r+RE); |

|VBE=VT*log(IE/Ieo); r=VT/IE; |

|Ie(i)=IE; Ib(i)=IE/(1+beta); Ic(i)=Ie(i)-Ib(i); Vbe(i)=VBE |

|end; |

|format long; 1e3*Ie', 1e3*Ic', 1e6*Ib', Vbe' |

Fig. 3.5.9. MATLAB code for the circuit of Fig. 3.5.8 using the combined approach.

|iteration |IE [mA] |IC [mA] |IB [mA] |VBE [V] |

|0 |- |- |- |0.70000000000000 |

|1 |1.22354517611026 |1.21745788667688 |6.08728943338438 |0.63825471374559 |

|2 |1.25684852258536 |1.25059554486105 |6.25297772430525 |0.63892608595473 |

|3 |1.25685677065783 |1.25060375189834 |6.25301875949170 |0.63892625001677 |

|4 |1.25685677065832 |1.25060375189883 |6.25301875949413 |0.63892625001678 |

|5 |1.25685677065832 |1.25060375189883 |6.25301875949413 |0.63892625001678 |

Fig. 3.5.10. Results for the bipolar transistor biasing circuit for subsequent iterations using the combined algorithm

4 MOS transistor biasing without substrate effect

The MOS transistor biasing circuit shown in Fig. 3.5.11(a) can be represented by its linearized equivalent shown in Fig. 3.5.11(b). Note a similarity to the circuit shown in Fig. 3.5.3(d). The same combined algorithm can be used as for the diode circuit. The MATLAB code is presented in Fig. 3.5.12, and results are given in Fig. 3.5.13.

[pic]

Fig. 3.5.11. MOS transistor biasing circuit: (a) actual circuit and (b) equivalent diagram for the combined algorithm.

|%MOS transistor circuit biasing without body effect |

|%using combination of Newton-Raphson and Gauss-Seidel methods |

|Vcc=10; R1=40000; R2=60000; RL=80000; RS=40000; |

|Kn=25e-6; VTN=1; |

|VG=Vcc*R1/(R1+R2); VL=0; rs=0; % initial conditions |

|for i=1:6 |

|ID=(VG-VTN-VL)/(RS+rs); |

|rs=1/sqrt(2*Kn*ID); |

|VL=sqrt(2*ID/Kn)-rs*ID; |

|Id(i)=ID; Vs(i)=VL+rs*ID; |

|end; |

|format long; 1e3*Id', Vs' |

Fig. 3.5.12. MATLAB code for the circuit of Fig. 3.5.11 using the combined approach.

|iteration |ID [mA] |VGS [V] |VS [V] |

|1 |0.07500000000000 |1.00000000000000 |3.00000000000000 |

|2 |0.03151530771650 |2.73938769133981 |1.26061230866019 |

|3 |0.03384001580252 |2.64639936789916 |1.35360063210084 |

|4 |0.03385621649051 |2.64575134037942 |1.35424865962058 |

|5 |0.03385621722339 |2.64575131106459 |1.35424868893541 |

|6 |0.03385621722339 |2.64575131106459 |1.35424868893541 |

Fig. 3.5.13. Results for the MOS transistor biasing circuit for subsequent iterations using the combined algorithm.

5 MOS transistor biasing with substrate effect

Let us consider the same circuit as in the previous example but with the body (substrate) effect. The MOS transistor biasing circuit shown in Fig. 3.5.14(a) can be represented by its linearized equivalent shown in Fig. 3.5.14(b). This equivalent circuit is basically the same, with the exception that the threshold voltage VTH is modified at each iteration step. The MATLAB code is presented in Fig. 3.5.15. The abrupt modification of the threshold voltage during the iteration process obviously leads to much slower convergence, as shown in Fig. 3.5.16.

[pic]

Fig. 3.5.14. MOS transistor biasing circuit: (a) actual circuit and (b) equivalent diagram for the combined algorithm.

|%MOS transistor circuit biasing with body effect |

|%using combination of Newton-Raphson and Gauss-Seidel methods |

|Vdd=10; R1=40000; R2=60000; RL=80000; RS=40000; |

|Kn=25e-6; VTN0=1; gama=1; phi=0.6; |

|VG=Vdd*R1/(R1+R2); VL=0; rs=0; VTN=VTN0; % initial conditions |

|for i=1:10 |

|ID=(VG-VTN-VL)/(RS+rs); |

|rs= 1/sqrt(2*Kn*ID); |

|VTN=VTN0 + gama*(sqrt(RS*ID+phi)-sqrt(phi)); |

|VL=sqrt(2*ID/Kn)-rs*ID; |

|Id(i)=ID; Vs(i)=RS*ID; Vgs(i)=VG-Vs(i); |

|end; |

|format short; 1e6*Id', Vs' , Vgs' |

Fig. 3.5.15. MATLAB code for the circuit of Fig. 3.5.14

|iteration |ID [mA] |VGS [V] |VS [V] |

|1 |75.00000000000000 |1.00000000000000 |3.00000000000000 |

|2 |11.58327700745770 |3.53666891970169 |0.46333108029831 |

|3 |27.73790037732012 |2.89048398490720 |1.10951601509280 |

|4 |25.76271121446836 |2.96949155142127 |1.03050844857873 |

|5 |26.22762756846172 |2.95089489726153 |1.04910510273847 |

|6 |26.12109239498374 |2.95515630420065 |1.04484369579935 |

|7 |26.14567125244922 |2.95417314990203 |1.04582685009797 |

|8 |26.14000929772171 |2.95439962809113 |1.04560037190887 |

|9 |26.14131404052244 |2.95434743837910 |1.04565256162090 |

|10 |26.14101339964740 |2.95435946401410 |1.04564053598590 |

Fig. 3.5.16. Results for the MOS transistor biasing circuit including the body effect.

6 Writing Your Own Code for ac Analysis

The ac analysis usually requires solution of a set of linear equations using complex arithmetic. The set of equations can be formed using the node or mesh analysis approach. It can also be set automatically using the procedure described in Sections 3.3 and 3.4. The SPICE approach is illustrated with an example in Section 3.6.1. Section 3.6.2 presents a simpler approach which can be used for some applications where there is no need for solution of the full set of equations.

1 Frequency response using the SPICE type of algorithm

Let us consider the circuit presented in Fig. 3.6.1. The Y matrix and forcing vector I for this circuit can be formed automatically using the approach described in Sections 3.3 and 3.4.

[pic]

Fig. 3.6.1. Bipolar transistor resonant circuit.

The Y matrix and forcing vector I for the circuit of Fig. 3.6.1 are:

[pic] (3.6.1)

and the MATLAB code is shown in Fig. 3.6.2. Note that in the case of the MATLAB program, the solution of the set of linear equations can be obtained with a simple statement using the symbol “\” for matrix left division.

|% Computation of Bipolar Transitor Resonant Circuit |

|VS=0.001+0j; R1=1E3; L1=0.001; C1=100E-9; |

|h11=5000; gm=0.04; % IC=1mA and BETA=200 |

|I=[0, 0, VS]'; |

|for i=1:200, |

|f=2E2*i; w=2*pi*f; s=1i*w; ff(i)=f; % set frequency |

|Y=[ 1/h11, 0 , 1 ; |

|gm , 1/R1+1/(s*L1)+s*C1, 0 ; |

|1, 0 0 ]; |

|v=Y\I; % solution of the set of linear equations |

|magnitude(i)=abs(v(2,1)); |

|end; |

|plot(ff,magnitude); |

| |

Fig. 3.6.2. MATLAB code for the circuit of Fig. 3.6.1.

[pic]

Fig. 3.6.3. Magnitude as a function of frequency for the circuit of Fig. 3.6.1.

2 Frequency response of LC ladder circuit

The efficient algorithm for resistive ladder calculation, described in Section 3.5, can also be used for the frequency analysis of ladder-type filters. The only difference is that instead of real numbers, complex arithmetic must be used. The circuit example is shown in Fig. 3.6.4. The MATLAB code for the circuit is shown in Fig. 3.6.5. Note that there is no need for second a calculation through the circuit, because we are interested only in the output voltage.

[pic]

Fig. 3.6.4. Circuit diagram of single terminated ladder filter.

|% Computation of Single Terminated Ladder Filter |

|VB=10+0i; C1=1.0918; L2=1.4817; C3=2.0645; L4=1.6961; C5=2.1658; |

|RL=1; L6=1.7306; C7=2.1803; L8=1.7215; C9=2.1111; L10=1.3801; |

|% L and C element values were found using the LADDER program |

|% which can be found on |

|for i=1:200, |

|f=0.001*i; w=2*pi*f; s=1i*w; ff(i)=f; % set frequency |

|Vo=1+0i; %assume 1V for Vo |

|iC1=Vo*s*C1; iRL=Vo/RL; vC3=Vo+(iRL+iC1)*s*L2; |

|iC3=vC3*s*C3; iL2=iC1+iRL; vC5=vC3+(iC3+iL2)*s*L4; |

|iC5=vC5*s*C5; iL4=iC3+iL2; vC7=vC5+(iC5+iL4)*s*L6; |

|iC7=vC7*s*C7; iL6=iC5+iL4; vC9=vC7+(iC7+iL6)*s*L8; |

|iC9=vC9*s*C9; iL8=iC7+iL6; VBP=vC9+(iC9+iL8)*s*L10; |

|Vo=Vo/VBP; magnitude(i)=abs(Vo); phase(i)=angle(Vo); |

|end; |

|phase=180/pi*unwrap(phase); |

|figure(1);plot(ff,magnitude); figure(2); plot(ff,phase); |

Fig. 3.6.5. MATLAB code for the circuit of Fig. 3.6.4.

[pic]

Fig. 3.6.6. Magnitude as a function of frequency for the circuit of Fig. 3.6.4.

[pic]

Fig. 3.6.7. Phase as a function of frequency for the circuit of Figure 3.6.4.

7 Writing Your Own Code for Transient Analysis

Algorithms for transient analysis of electronic circuits which are implemented in SPICE programs are unconditionally stable for any size of the time step, but they are very computationally intensive. At each time step, the full number of equations corresponding to the circuit size have to be solved. For many practical circuits a simple, explicit method works equally well and is much faster.

The method follows the very well known fact that the voltage on a capacitor and the current through inductor cannot change rapidly. The voltage or current change is proportional to the external excitation. In the case of a capacitor, this is a charging (or discharging) current, and in the case of an inductor, it is the instantaneous voltage on the inductor terminals:

[pic] (3.7.1)

For a fixed time increment (t, the above equations can be written in the form

[pic] (3.7.2)

In order to find values of IC and VL, capacitors are considered to be voltage sources equal to the capacitor voltage from the previous time step, and inductors are considered to be current sources equal to the current through the inductor from the previous time step. This method corresponds to the forward Euler integration scheme. Being an explicit method, it does not require solution of a large set of equations. In order to secure convergence, the time step must be smaller than the smallest time constant in the circuit. Therefore, the method is not suitable for circuits having very different time constants, because a huge number of time steps will be required.

1 Transient response of the resonant circuit

Let us illustrate the method with the simple resonant circuit shown in Fig. 3.7.1. Assuming zero initial conditions IL=0 and VC=0, the initial voltage across the inductor is V1, and initial current through the capacitor is zero. Subsequent values of voltages and currents can be found using formulas (3.7.2). The MATLAB code is shown in Fig. 3.7.2. Node the simplicity of this code. Fig. 3.7.3 shows the result.

[pic]

Fig. 3.7.1. Simple resonant circuit.

|%Transient response of simple resonant circuit |

|V1=5; R1=100; L=0.005; C=100e-9; dt=5e-6; |

|IL=0; VC=0; t(1)=0; %initial conditions |

|for i=1:200 |

|VL=V1-IL*R1-VC; IC=IL; % calculating VL and IC |

|VC=VC+dt*IC/C; IL=IL+dt*VL/L; |

|t(i)=i*dt; Vc(i)=VC; Il(i)=IL; |

|end; |

|figure(1); hold on; plot(t,Vc); plot(t,Il*1e3); hold off |

Fig. 3.7.2. MATLAB code for the circuit of Fig. 3.7.1.

[pic]

Fig. 3.7.3. Result of transient analysis of simple resonant circuit using the MATLAB code

of Fig. 3.7.2. Voltage on capacitor (in V) stabilizes at 5 V,

and current (in mA) stabilizes at 0 mA.

2 Transient response of RC circuit

Another example of transient analysis is shown in Fig. 3.7.4. The MATLAB code appears in Fig. 3.7.5, and the results are shown in Fig. 3.7.6.

[pic]

Fig. 3.7.4. Switching RC circuit

|%Transient response of switching circuit |

|V1=5; V2=10; R1=1000; R2=4000; C=50e-9; dt=10e-6; |

|VC=5; t(1)=0; %initial conditions |

|for i=1:200 |

|if i ................
................

In order to avoid copyright disputes, this page is only a partial summary.

Google Online Preview   Download