Qucs Circuit Simulator Tutorial
Qucs Circuit Simulator Tutorial
A Tutorial
Component, compact device and circuit modelling using symbolic equations
Mike Brinson
Copyright c 2007 Mike Brinson <[email protected]> Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.1 or any later version published by the Free Software Foundation. A copy of the license is included in the section entitled GNU Free Documentation License.
Introduction
Qucs releases 0.0.11 and 0.0.12 mark a turning point in the development of the Qucs component and circuit modelling facilities. Release 0.0.11 introduced component values dened by equations and for the rst time allowed subcircuits with parameters. Release 0.0.12 extends these features to add model development using symbolic equations that are similar to compact device code written in the Verilog-A modelling language. In designing the latest Qucs modelling features the Qucs team has made a central focus of their work the need to provide the package with an interactive and easy to use modelling system which allows fast model prototype construction. Much of these new aspects have up to now been undocumented and are likely to be very new to most Qucs users. The aim of this tutorial note is to outline the background to these important package extensions and to provide real help to Qucs users who are interested in writing and experimenting with their own models. The text includes a number of illustrative examples for readers to try and experiment with.
The technical details of the built-in models are described in: Qucs Technical Papers, Stefan Jahn,
code. Obviously, this does require a specialised knowledge of the Qucs model programming interface2 , the necessary C++ skills, including a good working knowledge of the Trolltech Qt toolkit3 . At the time of writing these notes the latest device to be added to Qucs using this approach is the exponential pulse source4 . Models based on hand written C++ code are normally restricted to basic devices that form the fundamental component core of a simulator - particularly where simulation computational eciency is important. One disadvantage of this approach, is the obvious one, in that the time to implement a new model increases disproportionately with increasing model complexity. For most Qucs users this route would not be the most natural to use when developing new models. However, for the specialist who spends a signicant amount of time researching new device models this has always in the past, been the route of choice. Unfortunately, modern semiconductor device models are becoming so complex that the model development time can stretch into months or even years and requires typically thousands of lines of C or C++ code to characterise a model5 . With the more complex models the problem of nding bugs in the model code also acts as a limit to fast model development. For the average Qucs user their rst introduction to the software is probably through constructing circuit schematics made entirely from the standard component models built into the package and the testing of their performance by launching the simulator from one of the Qucs simulation icons.6 The next natural stage in the Qucs modelling and simulation learning curve is the use of subcircuits where groups of built-in components are collected together to form a higher level circuit block. These blocks are often arranged with a common theme, forming a Qucs library. The process of modelling new devices/circuits is normally done by connecting existing component models and user dened subcircuits. With this type of modelling higher level functional models can only be constructed from existing fundamental components or previously constructed subcircuits. Engineers often call this approach to modelling, macromodelling. Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular amongst most Qucs users because it is easy to understand, is fully interactive and allows straight forward testing of new models. One feature that is common to all components included in Qucs releases up to 0.0.10 may not be immediately obvious to readers, namely that, with the exception of sweep variables, component values could only be numbers, for example R1 = 1k, and were not allowed to be represented by algebraic expressions like R1 = Value1, where Value1 = 100.0+50 X. Its also worth pointing out at
Michael Margraf, Vincent Habchi and Raimund Jacob, http://qucs.sourceforge.net/technical.html. 2 Writing the documentation for the Qucs model programming interface is on the to do list and will be completed, when time allows, sometime in the future. 3 Qt is a registered trademark of Trolltech, Norway; http://www.trolltech.com/copyright. 4 Added by Gunther Kraut on 15 April 2007. This device has been added for compatibility with SPICE. 5 A good introduction to writing compact device models is given in How to (and how not to) write a compact model in Verilog-A, Georey J. Coram, 2004, Proc. 2004 IEEE International Behavioral Modeling and Simulation Conference (BMAS 2004), pp 97- 106. 6 The Getting Started with Qucs tutorial by Stefan Jahn outlines a number of basic simulation techniques; http://qucs.sourceforge.net/docs.html.
SPICE netlist
SPICE preprocessor
ADMS compiler Schematic capture symbols QUCS GUI Circuit entered using schematic capture
C++ code
Qucs components
Simulate
Generate Qucs netlist code from GUI schematic, including conversion of SPICE code to Qucs format
Qucs Tools: Line Calculator Attenuator Design Matching Circuits Filter Design
QUCSATOR C++ component code compiled and linked to Qucsator core C++ code via API
Figure 1: Qucs analogue component modelling and simulation block diagram (not including optimisation)
this point that during simulation, again performed by Qucs releases up to 0.0.10, component values were required to remain constant and could not be a function of the circuit variables such as voltage, current or charge. One way to remove the component value restrictions imposed by early Qucs releases is to model devices and circuits using preprocessor extended forms of the SPICE netlist language. Circuit design equations can then be embedded in SPICE netlists and the calculation of component values completed by the SPICE preprocessor. Both the SPICE to Qucs and OP AMP tutorials7 outline in detail the steps required to merge circuit design and simulation in this way. This modelling route is a very important and powerful model development tool. So much so that ongoing tests to identify how compatible Qucs is with the industrial standard SPICE 2g6 and 3f5 syntax are currently being undertaken as part of the Qucs development schedule8 . Although perfectly viable as a model development tool the use of an extended SPICE netlist language has a number of serious disadvantages, namely that not all the Qucs built-in component models have equivalent SPICE models and secondly text netlists are the only entry medium for describing models. The previous paragraphs give a brief statement of the dierent component modelling routes that were available up to release 0.0.11. Qucs 0.0.11 is very much a modelling water shed in that symbolic equations were introduced for the calculation of component values, previously equations were only allowed when structuring simulation output data for post simulation listing or plotting. Release 0.0.11 allows the following types of variable; 1. sweep variables, 2. equations left hand side, 3. component parameters left hand side (e.g. R1.R), 4. subcircuit parameters and 5. simulation output data. With each Qucs release the number of analysis functions, and other data processing features, included in the Qucs equation set continues to expand9 . From release 0.0.11 parameters are also allowed with subcircuits so that data can be passed to a model. This allows generalised subcircuit/macromodels to be developed for popular devices such as operational ampliers. Through the use of embedded design equations within subcircuits and parameter passing it became possible to construct powerful models that mix both circuit
7 Qucs simulation of SPICE netlists and Modelling Operational Ampliers, Mike Brinson, http://qucs. sourceforge.net/docs.html. 8 Qucs: Report Book; SPICE to Qucs test reports, Mike Brinson, http://qucs.sourceforge.net/ docs.html. 9 See Measurement Expressions Reference Manual, Gunther Kraut and Stefan Jahn, http://qucs. sourceforge.net/docs.html.
design procedures and the calculation of individual component values. Qucs 0.0.11 still imposed the restriction that equations could not be functions of voltage, current or charge. With the release of Qucs 0.0.12 the voltage, current and charge restrictions imposed on equations will nally be relaxed. The introduction of a new device modelling component called the equation dened device (EDD) allows rstly device current to be formulated as a function of voltage, and secondly device charge to be calculated as a function of voltage and current. The syntax adopted for the new model borrows heavily on the compact device modelling approach taken by the Verilog-A modelling language. Some readers will probably have noted that so far these notes make no reference to the ADMS model development route illustrated in Fig. 1. ADMS stands for Automated device model synthesizer10 and includes a Verilog-A to C/C++ compiler. It allows compact device models to be described in the Verilog-A language then compiled to C/C++ and the resulting code linked with the Qucs core simulation code11 . Model development using ADMS is similar to the fundamental hand coded C++ model development route except that model development is greatly simplied by the power of the high level Verilog-A language. A strong relationship exists between the ADMS and EDD modelling procedures in that EDD can be considered a fast interactive model prototyping method whose equations can easily be expressed in Verilog-A and compiled into C/C++ code for permanent inclusion in the Qucs simulator12 . The opening paragraphs attempt to outline the available device modelling techniques that are central to the functioning of the Qucs package. The remaining sections of this tutorial note are devoted to illustrating the power of Qucs modelling through the introduction of a number of illustrative examples. Initially these start from a simple, and hopefully familiar, point and then proceed to more complex examples which present many of the concepts lightly touched upon in the opening text.
recording the eect of component changes on circuit performance. In other words this is a classical circuit analysis use of a circuit simulator. In a real design situation dierent data is often required. Most designers would prefer to nd the value of Cap that gives a specic RC cut-o frequency (fc ) for a specied value of R1. This is the type of investigative problem where adding equations into the simulation process generates more informative results. Shown in Fig. 3 is a similar RC network to that illustrated in Fig. 2. Capacitor voltage V Cap is given by: VCap = V1
2 2 1 + 2 C1 R1
(1)
Hence, by expressing Cap as a function of fc and stepping fc through a range of frequencies, the eect of capacitance changes on the voltage transfer function can be found. More importantly a nomogram of Cap values against fc can be plotted giving the circuit designer a visual aid for determing the value of Cap required for given values of R1 and fc . Although the circuits shown in Figs. 2 and 3 are very basic they do demonstrate how much more powerful a circuit simulator becomes when component values are calculated using equations.
where A0 is the passband DC gain and coecients a2 , b2 are for Bessel, Butterworth, Tschebysche or similar polynomials. The following list13 gives the second order coecients for the Bessel 1.3617, 0.618; Butterworth 1.4142, 1.000; and 3dB ripple Tschebysche 1.065, 1.9305, polynomials. The second order Sallen-Key low pass lter circuit is shown in Fig. 4. This circuit has a voltage gain transfer function given by:
See OP Amps for everyone, Chapter 16: Active lter design technology, Texas Instruments, August 2002, SL0D006B, PP 16.1,16.63.
13
VCap
Parameter sweep
SW1 Sim=AC1 Type=lin Param=Cap Start=0.1u Stop=1.1u Points=11
V1 U=1 V
R1 R=1k
C1 C=Cap
ac simulation
AC1 Type=log Start=1Hz Stop=1 MHz Points=61
VCap.v
0.5
1e-6
Cap
5e-7
0 2 4 6 number 8 10
VCap
ac simulation
AC1 Type=log Start=1Hz Stop=1 MHz Points=61
Parameter sweep
SW1 Sim=AC1 Type=log Param=fc Start=10 Stop=1000 Points=21
V1 U=1 V
R1 R=Rvalue
C1 C=Cap
VCap.v
0.5
1e-5
Cap
1e-6
A(S) = where
(4)
R3 (5) R4 This can be simplied by letting R1 = R2 = R and C1 = C2 = C; the transfer function then becomes: A(S) = By comparison a2 = c R C (3 A0) and b2 = (c R C)2 Fixing C and solving for R and A0, yields a2 b2 , and A0 = 3 . R= c C b2 Also once A0 is known the value for R4 can be calculated using equation A0 = 1 + R3 . R4 (10) (8) (7) A0 . 1 + [c R C (3 A0)] S + (c R C)2 S 2 (6)
(9)
Hence by providing values for C and R3 the values for R and A0, and of course R4, can be determined for a specied cut o frequency f c. Figure 5 shows the nal design schematic and the simulation results for this example. A number of important observations can be made from Fig. 5: 1. One or more equation blocks hold both design and post simulation data processing equations plus assignments for named items: C, f c and R3 are given numerical values, the a and b polynomial coecients are set to the values introduced in the text, and nally the design equations for R, A0 and R4 calculations are listed. 2. The order of entries in equation blocks is not important because Qucs automatically sorts out the data it requires when calculating equations. 3. The lefthand quantities in the assignment entries in the equation blocks are linked to the component values in the schematic, see for example C and R. 4. The OP27 operational amplier model is from the modied Qucs 0.0.11 OPAMP library. This model was generated using the SPICE to Qucs modelling route. 9
C2
SUB1
+
V1 U=1 V R1 R2 C1 OPA27(TI)
VEE Vout
V2 U=15 V
VCC V3 U=15 V
R3
R4
Figure 4: The Sallen-Key lowpass active lter circuit 5. To design and simulate a Sallen-Key low pass lter with a dierent cut o frequency14 simply change the value of f c and rerun the Qucs simulator. 6. On completion of a simulation, pressing key F5 (Show last messages) causes the simulation log to be displayed. This includes the calculated values of the components and the netlist for the circuit, see Fig. 6. 7. One nal point of signicance that some readers may have noticed - all numerical values in equation blocks must be specied in scientic notation; electronic notation like 1k or 3nF is not allowed15 .
14 If the design calculations result in impractical values for the lter components then the value of C should be changed and the simulation repeated. 15 In long term it is expected that electronic notation will be allowed. The changes for this are on the to do list but at the moment the work has a low priority.
10
C2 C=C SUB1
+
V1 U=1 V R2 R=R R1 R=R C1 C=C OPA27(TI)
VEE Vout
V2 U=15 V
dc simulation
DC1
VCC V3 U=15 V
ac simulation
Equation AC1 Type=log Start=1 Hz Stop=100 kHz Points=101 R3 R=R3_calc 4 R4 R=R4_calc
Eqn1 C=22e-9 a2=1.065 b2=1.9305 fc=3000 R=sqrt(b2)/(2*pi*fc*C) A0=3-a2/(sqrt(b2)) R3_calc=4700 R4_calc=(A0-1)*R3_calc gain_dB=dB(Vout.v) gain_phase=rad2deg(unwrap(angle(Vout.v)))
Vout.v
0 0 gain_phase -50 -200 1 10 100 1e3 acfrequency 1e4 1e5 1 10 100 1e3 acfrequency 1e4 1e5 gain_dB
-100
Figure 5: The Sallen-Key lowpass active lter schematic with embedded design equations
11
Output : n e t l i s t content 13 R i n s t a n c e s 5 C instances 2 VCCS i n s t a n c e s 5 CCCS i n s t a n c e s 2 VCVS i n s t a n c e s 1 CCVS i n s t a n c e s 8 Vdc i n s t a n c e s 1 Idc i n s t a n c e s 1 Vac i n s t a n c e s 4 Diode i n s t a n c e s 2 BJT i n s t a n c e s 1 DC i n s t a n c e s 1 AC i n s t a n c e s creating netlist . . . c h e c k e r n o t i c e , v a r i a b l e Vout . v in e q u a t i o n g a i n dB not y e t d e f i n e d c h e c k e r n o t i c e , v a r i a b l e Vout . v in e q u a t i o n g a i n phase not y e t d e f i n e d kB = 1 . 38065 e 23 e = 2 . 71828 p i = 3 . 14159 C = 2 . 2 e 08 a2 = 1 . 065 b2 = 1 . 9305 f c = 3000 R = 3350 . 51 A0 = 2 . 2335 R3 c a l c = 4700 R4 c a l c = 5797 . 43 kB = 1 . 38065 e 23 e = 2 . 71828 p i = 3 . 14159 kB = 1 . 38065 e 23 e = 2 . 71828 p i = 3 . 14159 kB = 1 . 38065 e 23 e = 2 . 71828 p i = 3 . 14159
Figure 6: Message output log for the simulation of the Sallen-key low pass circuit: for brevity only the component value section is given
12
13
V1 U=f1_amp P_sig f=f1 Phase=ph1 Equation V2 U=f2_amp f=f2 Phase=ph2 V3 U=f3_amp f=f3 Phase=ph3 V4 U=f4_amp f=f4 Phase=ph4 Eqn1 f2=2*f1 f3=3*f1 f4=4*f1
HG1
SUB1 f1=1000 f1_amp=1.0 f2_amp=0.0 ph1=0.0 ph2=0.0 f3_amp=0.0 f4_amp=0.0 ph3=0.0 ph4=0.0
Figure 7: Harmonic generator subcircuit schematic and symbol spectra from double sided to single sided form, compute and plot the amplitude and power spectral densities.
14
Equation hg_sig Eqn1 ts=(max(time)-min(time))/length(time) fs=1/ts Adft=dft(hg_sig.Vt) LAdft=length(hg_sig.Vt) Amp2=2*Adft[1:(LAdfto2)-1] LAdfto2=LAdft/2 Amp_squared=Adft[:LAdfto2]*conj(Adft[:LAdfto2]) Amp=sqrt(Amp_squared) f_bin=linspace(1, LAdfto2, LAdfto2) f=(f_bin-1)*fs/LAdft PLAmp=PlotVs(2*Amp/LAdft,f) PLPower=PlotVs(4*Amp*Amp/(LAdft*LAdft),f)
transient simulation
TR1 Type=lin Start=0 Stop=10 ms Points=500
HG1
R1 R=50 Ohm SUB1 f1=1000 f1_amp=5.0 f2_amp=2.0 ph1=0 ph2=0 f3_amp=2 f4_amp=0 ph3=0 ph4=90
5 hg_sig.Vt
-5
1e-3
0.002
0.003
0.004
0.005 time
0.006
0.007
0.008
0.009
0.01
6 Power Spectral density (V^2) PLPower Amplitude Spectral density (V) PLAmp
30
20
10
15
16
Voff1 U=voff1 Ib1 I=ib Ioff1 I=ioff1 Ib2 I=ib R1 R=r1 Cin1 C=cd R2 R=r2
P_INN1
GMSRT1 G=0.01 S
Voff2 U=voff2
GMP1 G=1 S
P_INP1
AC
+
SUB1 voff=0.7e-3 ioff=80e-3 rd=2e6 cd=1.4e-12 aoldc=200e3 gbp=1e6 ro=75 EOS1 G=1
ROS1 R=ro
P_OUT1
Output stage
Input Stage
Figure 9: Expanded AC OP AMP model showing circuitry and equation blocks of amplier oset voltage on integrator DC saturation by stepping resister rp through a series of values. The low oset voltage of the OP27 makes this device much more suitable for integrator circuits when compared to the popular UA741. These results can be conrmed by a simple calculation: the oset voltage for the UA741 is set at 0.7 mV and the amplier open loop DC gain at roughly 200, 000. The UA741 goes into saturation when rp is approximately 20 M. In saturation the OP AMP gain becomes open loop giving a DC output voltage of roughly 0.7e-3 2e5 or 14 V, which agrees with the Qucs simulation results.
17
IN AC P_INN1
ON
+
SUB1 v_off=0.7e-3 i_off=20e-9 r_d=2e6 c_d=1.4e-12 i_b=80e-9 g_bp=1e6 a_oldc=200e3 r_o=75 P_INP1
Input Stage IP OP
P_INN3
IN
ON
P_INN2
P_INP2
GMSRT1 G=0.01 S RSRT1 R=1 RADO1 R=aoldc CP1 C=cp1 P_OUT2 GMP1 G=1 S
output IN O Stage SUB9 ro=r_o PO1 ROS1 R=ro EOS1 G=1 P_OUT3
18
Voff1 U=voff1
P_INN
RSUM1 R=1
SRC1 G=1 S
Voff2 U=voff2
P_INP RDCMZ R=650M RCM1 R=1M RCM2 R=1 SRC2 G=1 S Equation ECM1 G=ecm1 CCM1 C=ccm1 GMSRT1 G=0.01 S RSCALE1 R=100 VSR1 U=p1 RSRT1 R=1 RADO R=aoldc CP1 C=cp1 Eqn4 cp1=1/(2*pi*gbp)
SRC3 G=1 S
RP2 R=1
CP2 C=cp2
GMP2 G=1 S
VLIM1 U=vlim1 Equation DVL1 Is=8e-16 A Eqn7 vlim1=vcc-vccm+1 vlim2=-vee+veem+1 P_OUT DVLM2 Is=8e-16 A
D2 Is=1e-15 A Cj0=0.0
RDCCL1 R=100M
ECL G=1
P_VEE
Figure 11: Modular OP AMP subcircuit schematic with embedded component calculation equations 19
R1 R=4.7k
vout_op27
V3 U=1 V
R2 R=4.7k MOD
V1 U=15 V VCC
VEE
V2 U=15 V
SUB1 voff=30e-6 ib=15e-9 ioff=12e-9 rd=4e6 cd=1.4e-12 cmrrdc=1778279.4 fcmz=2009.0 aoldc=1778279.4 gbp=8e6 fp2=17e6 pslewr=2.8e6 nslewr=2.8e6 vcc=15 vee=-15 vccm=14 veem=-14 ro=75 idcoutm=32e-3
vout_ua741
R3 R=4.7k
R4 R=4.7k MOD
VCC
VEE
Equation
dc simulation
DC1
number 1
vout_op27.V -3.87e-05
vout_ua741.V 0.001
ac simulation
AC1 Type=log Start=1 Hz Stop=100MHz Points=161
SUB2 voff=0.7e-3 ib=80e-9 ioff=10e-9 rd=2e6 cd=1.4e-12 cmrrdc=31622.77 fcmz=200.0 aoldc=199526.3 gbp=1e6 fp2=3e6 pslewr=0.5e6 nslewr=0.5e6 vcc=15 vee=-15 vccm=14 veem=-14 ro=75 idcoutm=34e-3
vout_ua741.v vout_op27.v
0.5
gain_ua741 gain_op27
-20
-40
200
phase_ua741 phase_op27
100
R3 R=rp
vout_ua741
R4 R=rp
vout_op27
C2 C=1 uF V3 U=15 V
R1 R=1k MOD
VCC
MOD
VCC
V2 U=15 V VEE
V4 U=15 V VEE
SUB1 voff=0.7e-3 ib=80e-9 ioff=10e-9 rd=2e6 cd=1.4e-12 cmrrdc=31622.77 fcmz=200.0 aoldc=199526.3 gbp=1e6 fp2=3e6 pslewr=0.5e6 nslewr=0.5e6 vcc=15 vee=-15 vccm=14 veem=-14 ro=75 idcoutm=34e-3
Parameter sweep
SW1 Sim=DC1 Type=log Param=rp Start=1e3 Stop=1e9 Points=31
dc simulation
DC1
SUB2 voff=30e-6 ib=15e-9 ioff=12e-9 rd=4e6 cd=1.4e-12 cmrrdc=1778279.4 fcmz=2009.0 aoldc=1778279.4 gbp=8e6 fp2=17e6 pslewr=2.8e6 nslewr=2.8e6 vcc=15 vee=-15 vccm=14 veem=-14 ro=75 idcoutm=32e-3
15
vout_op27.V vout_ua741.V
10
21
Sp1 = tsweep
Parameter sweep
SW1 Sim=DC1 Type=lin Param=tsweep Start=10 Stop=110 Points=100
0.6
Sp2=Sp1
tscan=Sp2
P1
R2 R=10k Temp=26.85
22
# Qucs 0 . 0 . 12 / media / hda2 /Qucs e q u a t i o n m o d e l l i n g p r j / r d i v t e s t tsweep 3 l . s c h . Def : r d i v sub1 temp n e t 1 n e t 0 t s c a n=27 R: R2 gnd n e t 0 R =10 k Temp= t s c a n Tc1=0 . 01 Tc2=0 . 015 Tnom=26 . 85 R: R1 n e t 1 n e t 0 R =10 k Temp=26 . 85 Tc1=0 . 0 Tc2=0 . 0 Tnom=26 . 85 . Def : End . Def : r d i v t e s t 6 temp n e t 1 n e t 0 sp2=27 Sub : SUB1 n e t 1 n e t 0 Type= r d i v sub1 temp t s c a n=sp2 . Def : End . Def : r d i v sub3 temp n e t 0 n e t 1 sp1=27 Sub : SUB1 n e t 0 n e t 1 Type= r d i v t e s t 6 temp sp2=sp1 . Def : End Vdc : V1 n e t 0 gnd U =1 V .DC:DC1 Temp=26 . 85 r e l t o l=0 . 001 a b s t o l=1 pA v n t o l=1 uV saveOPs=no MaxIter=150 s a v e A l l=no c o n v H e l p e r=none S o l v e r=CroutLU .SW:SW1 Sim=DC1 Type= l i n Param=tsweep Start=10 Stop=110 P o i n t s=100 Sub : SUB1 n e t 0 vp01 Type= r d i v sub3 temp sp1=tsweep
Figure 15: Qucs netlist for nested subcircuit showing parameter passing sequence
23
form of EDD is implemented24 . EDD is an advanced component that allows Qucs users to construct their own device models from a set of equations derived from the physical properties that characterise a device. The explicit form of EDD can only be used to develop models for devices where their dening equations can be transformed into the explicit analysis form required by Qucs25 . A range of functions similar to those dened in the Verilog-A compact device modelling language are provided by Qucs, making the equation modelling language easy to use and powerful. The ternary ? : form of the C language if statement has also been implemented to allow selection of model equations that change with diering device voltage, current and charge conditions. Before introducing the EDD symbol and its properties consider the following circuit simulation modelling problem: a model for a device is required where the output voltage is a function of two input voltages V IN1 and V IN2 , such that Vout (V IN1 , V IN2 ) = V IN1 V IN2 , where V IN1 and V IN2 can be arbitrary varying voltages. This type of model is dicult to simulate at functional level26 using the pre-version 0.0.12 built-in devices. A linear voltage controlled voltage source can be used to multiply a voltage by a constant. Multiplying by a second voltage is not possible with the linear controlled sources. Qucs AM modulated and PM modulated sources are the nearest that Qucs has to the source dened above. These sources however, only allow sinusoidal carrier signals. Illustrated in Fig. 16 is a four quadrant multiplier EDD which allows multiplication of two varying signals27 . The EDD device generates current I1 = V 2 V 3. This in turn is transformed to the output voltage by a unity gain current controlled voltage source SRC1. An EDD device can consist of up to 8 branches. The branches have currents, I1 to I8, voltages V1 to V8 and internal charges Q1 to Q8 respectively. Overall the total device current depends how these branches are connected. A similar comment applies to the total device charge. In Fig. 16 currents I2 and I3 are set to zero, charges Q2 and Q3 are also zero, and voltages V 2 = V IN1 and V 3 = V IN2 . Hence current I1 becomes the multiplication of V IN1 and V IN2 . The fact that currents I2 and I3 are set to zero implies that the terminals connected to the external input voltages have high impedance and act as voltage probes. The test circuit in Fig. 16 is shown with signal inputs generated by sinusoidal oscillators; V1 acts as a modulating signal and V2 as a carrier signal. The bottom right hand corner of Fig. 16 includes a second graph which illustrates the eect of changing signal V2 to a square wave source with 0.05ms period. (11)
24 See Qucs Technical Papers, Section 10.7: Equation dened models, Stefan Jahn, Michael Margraf, Vincent Habchi and Raimund Jacob, http://qucs.sourceforge.net/technical.html. 25 The Y parameters of the device being modelled must also exist for the explicit form of the EDD to be valid. 26 It is, of course, possible to model the multiplier operation at discrete component level e.g. using a Gilbert cell mixer circuit. 27 This model is based on an idea suggested by Stefan Jahn, during the EDD development phase.
24
transient simulation
TR1 Type=lin Start=0 Stop=1 ms Points=401
5 V1 U=1 V f=1 kHz Out.Vt Out V2 U=5 V f=10 kHz R1 R=50 Ohm VMULT1 0
SRC1 G=1
2
1 vmul_2_tb:Out.Vt
In1 Num=2
3
In2 Num=3
Figure 16: Qucs EDD four quadrent multiplier model and test circuit
(12)
Each branch can be a function of one or more of these circuit variables but not necessarily all three at the same time.
25
where I1 = f (V ), IC = C(V, I) Also V 1 = i2, V 2 = IL, i2 = L(I) Giving IL = and VL=V2=V1= Hence I = f (V ) + C(V, I) 1 L(I)
dV 1 dQ1 = dt dt
(13)
dV 2 dIL , V 1 = L(I) dt dt
(14)
V 2 dt d dt V 1 dt
(15)
(16)
dV 1 1 + dt L(I)
(17)
The EDD is characterised by eight parallel branches each comprising a current component In and a charge component Qn, where n ranges from 1 to 8. The currents may be constants or dened by equations that are functions of the EDD branch voltages (these are designated V 1 to V 8). This form of the EDD component is known as the explicit EDD model. Please note, EDD currents cannot be functions of current. However, with release 0.0.12 implementation of the explicit EDD the device charge can be a function of either voltage or current29 . The current in the resistive branch being a function of EDD voltage allows a range of two terminal30 devices to be modelled, allowing, for example, nonlinear resistors and diode models to be easily developed. Similarly, the fact that the EDD charge can be a function of voltage or current extends the range of allowed Qucs capacitor types opening new areas of application. The same comments apply to the nonlinear inductors where components that have inductance values which are functions of current allow modelling of nonlinear transformer and coupled inductor eects. This was not possible with earlier Qucs releases. The EDD current and charge values may be dened by symbolic equations that include the operators and functions listed in the Short description of mathematical functions entry in the Qucs help index31 .
29 This allows modelling of semiconductor capacitive eects where the amount of stored charge is either a function of voltage (depletion layer capacitance), or a function of current (diusion capacitance). 30 The number of device terminals can be increased to model transistors and other devices. 31 The Qucs operators and functions are a superset of those dened in the Verilog-A language manual. However, in some cases the name of the operator or function diers slightly. For example Verilog-A uses pow(x, y) for the power function whilst Qucs uses to denote xy . An example of diering function names are the inverse trigonometric functions. A list of the available functions is given in Appendix A.
26
I IC Q C1 C=f(V,I)
I1 R1 R=f(V)
IL L1 L=f(I)
V1
V1
D2 I1=0 Q1=L(I)*V2
1
V2
Gyrator
Figure 17: A non-linear two terminal branch with parallel resistive, capacitive and inductive components
27
Which in terms of an if then else type statement is equivalent to: I1 = V1/( if (V1 < 1.0) then 1000 else if (V1 < 2.0) then 1000 + 4000*(V1-1) else if (V1 < 5.0) then 5000 else if ((V1 >= 5.0) && (V1 < 6.0)) then 5000 - 4500*(V1-5.0) else 500 )
One eect of such a discontinuity is the introduction of rapidly changing circuit conditions which can cause the simulator diculties in converging to a correct solution. Sometimes, if this happens, simulation run times may be dramatically increased or simulation fails altogether.
32
28
Parameter sweep
Equation Eqn1 R=Vs/Pr1.I
dc simulation
DC1
Vs
V1 U=Vs
Pr1
D1 I1=V1/((V1<1.0) ? 1000 : (V1<2.0) ? 1000+4000*(V1-1) : (V1<5.0) ? 5000 : ((V1 >=5.0) && (V1<6.0)) ? 5000-4500*(V1-5.0) : 500)
1
Pr1.I
1e-4
R 2e3 1e3 2 Vs 3 4 5 6 7 0 0 1 2 3 Vs 4 5 6 7
29
5e3 4e3 3e3
0.1
0.01
1e-3
1e-5
1e-6
33 The details of these polynomial functions are presented in Test Reports 4 and 5 of the SPICE to Qucs testing Series, Mike Brinson, http://qucs.sourceforge.net/docs.html. 34 SPICE 2g6 allows up to twenty coecients. Simply add more higher order terms to the Qucs polynomial if required.
30
V2 U=1 V V1 U=Vb
Vout
R1 R=1k
dc simulation
DC1
Vb 1 2 3 4 5 6 7 8 9 10
Vout.V 1 2 3 4 5 6 7 8 9 10
ac simulation
AC1 Type=log Start=1 Hz Stop=10kHz Points=201
Parameter sweep
SW1 Sim=AC1 Type=lin Param=Vb Start=1 Stop=10 Points=10
PIN1
Vout.v
0.5
200
Ph_Vout
150
P_inp1
1
P_inn1
IND=L+L2*I(L)+L3*I(L)^2+L4*I(L)^3
Pr1
transient simulation
TR1 Type=lin Start=0 Stop=4 us
Parameter sweep
SW1 Sim=TR1 Type=lin Param=vin Start=0 Stop=100 Points=3
dc simulation
DC1
Pr2
L1 L=1e-6
100
in.Vt
-100 0 5e-7 1e-6 1.5e-6 2e-6 time 2.5e-6 3e-6 3.5e-6 4e-6
Pr1.It
Pr2.It
20
Id = IBV,
Id = Is (exp ((BV + Vd )/V t) 1 + BV /V t) , In these equations: Is = the saturation current. n = the emission coecient.
GM IN = a small conductance in parallel with the diode38 V t = kB T /q, where T is the diode temperature in Kelvin, kB is Boltzmanns constant and q the charge on the electron.
The SPICE 2g6 and 3f5 device parameters are a subset of those commonly provided with current generation of circuit simulators, including Qucs. 36 A second three terminal MESFET transistor example is available for downloading from the Qucs Web site. 37 These equations are for the SPICE 2g6 diode model, see Giuseppe Massobrio, Chapter 1, Pn-junction diode and Schottky diode, Semiconductor device modeling with SPICE, Edited by Paolo Antognetti, Giuseppe Massobrio, 1988, McGraw-Hill,Inc, ISBN 0-07-002107-4. 38 GMIN is added to help Qucs DC convergence. The SPICE default value is 1e-12S.
35
33
BV = reverse breakdown voltage (positive number) IBV = reverse breakdown current (positive number). Figure 21 gives the EDD model for the experimental semiconductor diode. The ternary operator ?: is used to select the correct equation for each diode operating region. The diode current Id : content.tex, v1.22007/06/0316 : 58 : 59elaExp is the sum of EDD branch currents I1 to I4, where I1 represents the diode forward bias region, I2 the reverse bias region and I3 plus I4 the diode reverse bias breakdown region. When calculating diode current a special form of the exponential function exp(), called limexp(), is employed to assist Qucs to converge to a solution during DC and transient large signal analysis. The function limexp() linearises the exponential function at large argument values minimising the possibility of oating point overow and generation of software exceptions. The Id Vd characteristic curves shown in Fig. 21 are for the forward bias region with series resistance rs set to 0.01. For completeness the simulation data for the Qucs built-in diode are also given. Clearly the two sets of results are very similar. The DC simulation results for the diode reverse breakdown region of operation are shown in Fig. 22. Again for comparison an Id Vd plot for the Qucs built-in diode is also provided. In this region of operation some slight dierences are apparent: although for both devices the reverse breakdown is very close to 100V the slope of the Id V d curve at negative voltages beyond -BV is dierent, emphasising that the SPICE diode model does not model breakdown or zener eects well39 . The next stage in the development of the diode model is to add capacitance eects: depletion layer capacitance for the reverse bias region and diusion capacitance for the forward bias region. Diode capacitance is given by: Depletion layer capacitance Cdep Diusion capacitance Cdif f = dQdif f dId = tt dVd dVd (23) Vd dQdep = = Area Cj0 1 dVd Vj
m
(22)
Where the total stored charge Qd = Qdep + Qdif f . Using the same notation as the SPICE diode model: Qdif f = tt Id
Vd
Vd Vj
dV,
See Steven M. Sandler, SPICE subcircuit accurately models zener characteristics, Personal Engineering, November 1998, pp 45-48 for more information on this subject.
34
PANODE1
RS1 R=rs
D2 I1=(V1>-5.0*n*Vt) ? Is*(limexp(V1/(n*Vt))-1.0)+V1*GMIN : 0 Q1=0 I2=(-BV<V1) ? (V1<-5.0*n*Vt) ? -Is+V1*GMIN : 0 : 0 Q2=0 I3=(V1==-BV) ? -IBV : 0 Q3=0 I4=(V1<-BV) ? -Is*(limexp(-(BV+V1)/Vt)-1.0+BV/Vt) : 0 Q4=0
Vs U=Vd
dc simulation
DC1
PCATHODE1
Pr2 Pr1 SUB1 n=1.0 rs=0.01 Is=1e-14 BV=100.0 IBV=1e-3 Vj=1.0 D1 Is=1e-14 A N=1 Vj=1.0 Rs=0.01 Bv=100.00 Ibv=1e-3
Parameter sweep
SW1 Sim=DC1 Type=lin Param=Vd Start=0 Stop=1 Points=190
10
Id (A)
-20
10
ID_Q (A)
-20
Figure 21: Compact diode model DC test circuit and simulation results: SUB1 is the EDD diode model and D1 the Qucs diode model with the same parameters as SUB1. 35
-5
Id (A)
-50
Figure 22: Compact diode model DC simulation results for the reverse breakdown region of operation Using integration formula (ax + b)n dx = Qdep = 1 (ax + b)1+n and simplifying yields: a 1+n
1m
Vd Area Cj0 Vj 1 1 1m Vj
(26)
Qdep
F3 +
F C Vj
m Vd Vj
dV,
On integrating 1 F2 m 2 Vj
F 3 (Vd F C Vj ) +
Vd2 + (F C Vj )2 (28)
F1 =
Vj 1 (1 F C)1m , F 2 = (1 F C)1+m , F 3 = 1 F C (1 + m) 1m
(29)
In these equations: F C = Coecient for forward-bias depletion capacitance. m = Grading coecient. tt = Transit time. Area = Device area. Cj0 = Zero-bias junction capacitance.
36
Figure 23 shows the extended diode model. The Cdep and Cdif f components of the device capacitance have been included in the EDD model as stored charge Q1 and Q2. Again the ternary operator ?: is employed to select the correct equation for each section of the diode DC operating range. An equation block is used to simplify the charge equations through the use of factors F1, F2 and F3.40 . An area factor has also been added to the EDD model in Fig. 23. This is introduced to allow simulation of two or more equivalent parallel devices. The diode variables scaled by area are: Is (A) = Is Area, Cj0(A) = Cj0 Area, and rs (A) = rs/Area. (30)
The test circuit shown in Fig. 23 illustrates how device capacitance and resistance can be determined as a function of diode bias voltage. Firstly, the diode S parameters are determined at a given bias voltage, secondly these are converted to Y parameters and the diode capacitance (Cap) and resistance (RD) extracted from Y [1, 1], and nally the variation of Cap and RD with diode voltage Vd plotted using the Qucs plotting function PlotVs. Notice that the value of Cap at Vd = 0V agrees with the value of Cj0. To complete the demonstration EDD diode model all that remains to do is to add temperature dependence to the current and capacitance equations. Circuit simulators normally use two temperatures to determine device temperature dependence; the rst called Tnom represents the temperature that the device parameters were measured, and the second called Temp represents the current device temperature. A high percentage of the diode parameters are temperature dependent. However, to simplify the demonstration diode model only the temperature dependence of parameters Is , V j and Cj0 will be included in the model. Adding extra temperature dependence to the diode model is left to readers as an exercise41 . One of the great advantages of the EDD style of modelling is that it is interactive allowing easy experimentation with models to any given level. The following equations list the temperature dependence of Is , V j and Cj0. Let T1 = Tnom and T2 = Temp, then Is (T 2) = Is (T 1) T2 T1
XT I n
exp T2 T1
q Eg(300) kB T 2
1.5
T2 T1
(31)
V j(T 2) =
T2 2 kB T 2 V j(T 1) ln T1 q
(32) (33)
In complex current and charge expressions precalculating subexpressions in equation blocks ensures that they are only calculated once at the beginning of a simulation, ensuring minimum run times for an EDD model. 41 For example, parameters m and BV are both temperature dependent.
40
37
Equation
PCATHODE1
Eqn2 GMIN=1e-12 F1=(Vj/(1-m))*(1-(1-FC)^(1-m)) F2=(1-FC)^(1+m) F3=1-FC*(1+m) Vt=vt(300) X1 Vs1 U=Vs P1 Num=1 Z=50 Ohm
D1 I1=(V1>-5.0*n*Vt) ? Is*(limexp(V1/(n*Vt))-1.0)+V1*GMIN : 0 Q1=(V1 < FC*Vj) ? tt*I1+Area*(Cj0*Vj/(1-m))*(1-(1-V1/Vj)^(1-m)) : 0 I2=(-BV<V1) ? (V1<-5.0*n*Vt) ? -Is+V1*GMIN : 0 : 0 Q2=(V1 >= FC*Vj) ? tt*I1+Area*Cj0*(F1+(1/F2)*(F3*(V1-FC*Vj)+(m/(2*Vj))*(V1*V1-FC*FC*Vj*Vj))) : 0 I3=(V1==-BV) ? -IBV : 0 Q3=0 I4=(V1<-BV) ? -Is*(limexp(-(BV+V1)/Vt)-1.0+BV/Vt) : 0 Q4=0
Cap (F)
1e12 Rd ( ) 5e11 0 -4 -3 -2
LN_RD
dc simulation
DC1
S parameter simulation
SP1 Type=const Values=[100 kHz] Equation
Vd (V)
Vd
Pr1 SUB1 n=1.0 rs=0.01 Is=1e-14 BV=100.0 IBV=1e-3 Vj=1.0 Cj0=1e-12 FC=0.5 tt=1e-12 Area=1 m=0.5
Parameter sweep
SW1 Sim=SP1 Type=lin Param=Vs Start=-4 Stop=0.8 Points=200
1e-11
5e-12
0 -4 -3 -2 Vd (V) -1 0 1
20
0 -1 0 1 -4 -3 -2 -1 VD (V) 0 1
38
XT I = Saturation current temperature exponent. Eg(T ) = EG(0) 7.02e 4 T 2 , the energy gap. 1108 + T
Figure 24 shows the extended EDD for the experimental diode model. Again the limexp() function is used in preference to the standard exp() function in the temperature calculations listed in equations block Eqn2. The test circuit in Fig. 24 sweeps the device temperature from 20 to 80 degrees Centigrade. The graph inlay illustrates the experimental diode current Id plotted as a function of temperature. The temperature of the built-in Qucs diode is held constant, at room temperature, and its current Id Q plotted as an overlay. The two curves cross at room temperature, indicating identical currents at this temperature.
39
Pr2
dc simulation
DC1
Vs U=0.6
Pr1 SUB1 n=1.0 rs=0.01 Is=1e-14 BV=100.0 IBV=1e-3 Vj=1.0 Cj0=1e-12 m=0.5 Area=1 FC=0.5 tt=1e-12 XTI=3.0 Tnom=26.85 Temp=Temp_sw Eg=1.16
D1 Is=1e-14 A N=1 Cj0=1e-12 Vj=1.0 Rs=0.01 Bv=100.00 Ibv=1e-3 Temp=26.85 Xti=3.0 Eg=1.11 Tnom=26.85 Area=1
Parameter sweep
SW2 Sim=DC1 Type=lin Param=Temp_sw Start=-20 Stop=80 Points=100
1e-8 -20
20 40 Temp (Centigrade)
60
80
D2 I1=(V1>-5.0*n*Vt) ? Area*Is_T2*(limexp(V1/(n*Vt))-1.0)+V1*GMIN : 0 Q1=(V1 < FC*Vj) ? tt*I1+Area*(Cj0_T2*Vj_T2/(1-m))*(1-(1-V1/Vj_T2)^(1-m)) : 0 I2=(-BV<V1) ? (V1<-5.0*n*Vt) ? -Area*Is_T2+V1*GMIN : 0 : 0 Q2=(V1 >= FC*Vj) ? tt*I1+Area*Cj0_T2*(F1+(1/F2)*(F3*(V1-FC*Vj_T2)+(m/(2*Vj_T2))*(V1*V1-FC*FC*Vj_T2*Vj_T2))) : 0 I3=(V1==-BV) ? -IBV : 0 Q3=0 I4=(V1<-BV) ? -Area*Is_T2*(limexp(-(BV+V1)/Vt)-1.0+BV/Vt) : 0 Q4=0
PCATHODE1 Equation Equation Eqn2 Cj0_T2=Cj0*(1+m*(400e-6*(T2-T1)-(Vj_T2-Vj)/Vj)) rs_AREA=rs/AREA GMIN=1e-12 A=7.02e-4 B=1108 T1=Tnom+273.15 Vj_T2=(T2/T1)*Vj-(2*kB*T2/q)*ln((T2/T1)^1.5)-((T2/T1)*Eg_T1-Eg_T2) Is_T2=Is*(T2/T1)^(XTI/n)*limexp((-(q*Eg)/(kB*T2))*(1-T2/T1)) Eg_T1=Eg-A*T1*T1/(B+T1) Eg_T2=Eg-A*T2*T2/(B+T2) T2=Temp+273.15
40
End Note
This tutorial note introduces a large number of new modelling concepts and shows how equations, subcircuits with parameters and the new equation dened device perform a central role in constructing Qucs models. The EDD approach to modelling makes possible, for the rst time, the construction of equation dened compact device models and circuit macromodels using the Qucs schematic capture facilities as an interactive modelling medium. This is a major step forward for Qucs. Once again these notes are very much a record of work in progress: much still remains to be done in the future to improve the modelling capabilities provided by Qucs. A major short term task will be the development of additional models covering as wide a range of applications as possible. If Qucs is to fulll its mission to become a truly universal circuit simulator then it must be supported by models. Some readers will have noticed that these notes include very little information about the ADMS-Verlog-A and hand coded C++ model development routes. This was a deliberate decision on my part. Sometime in the future I intend to return to these subjects and update the tutorial. A very special thank you must go to Stefan Jahn for all his hard work, skill, and dedication during the period he has worked on programming the amazing modelling capabilities now embedded in Qucs.
41
Functions 1. ln(x) natural logarithm 2. log10(x) decimal logarithm 4. sqrt(x) square root 5. min(x,y) minimum 6. max(x,y) maximum 7. abs(x) absolute value 8. sin(x) sine 9. cos(x) cosine 10. tan(x) tangent 11. arcsin(x) inverse sine 12. arccos(x) inverse cosine 14. sinh(x) hyperbolic sine 15. cosh(x) hyperbolic cosine 16. tanh(x) hyperbolic tangent 17. arsinh(x) inverse hyperbolic sine 18. arcosh(x) inverse hyperbolic cosine 19. artanh(x0 inverse hyperbolic tangent 21. hypot(x,y) Euclidean distance function [asinh(x)] [acosh(x)] [atanh(x)] [asin(x)] [acos(x)] [atan2(x,y)] [log(x)] 3. exp(x) exponential function base e
43
Enter the series resonance circuit and add input and output pins
44
45
46
Figure 29: Stage 4: entering subcircuit parameter names and default values
Figure 30: Stage 4: resulting subcircuit and parameter list with default values
47
LCR
O
Vout
dc simulation
DC1
ac simulation
AC1 Type=log Start=100 Hz Stop=100kHz Points=100
Parameter sweep
SW1 Sim=AC1 Type=lin Param=R_SW Start=1 Stop=10 Points=10
Vout.v
0.5
100
gain
48