51
Qucs 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”.

Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

  • Upload
    others

  • View
    6

  • Download
    1

Embed Size (px)

Citation preview

Page 1: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Qucs

A Tutorial

Component, compact device and circuit modelling usingsymbolic equations

Mike Brinson

Copyright c© 2007 Mike Brinson <[email protected]>

Permission is granted to copy, distribute and/or modify this document under theterms of the GNU Free Documentation License, Version 1.1 or any later versionpublished by the Free Software Foundation. A copy of the license is included inthe section entitled ”GNU Free Documentation License”.

Page 2: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Introduction

Qucs releases 0.0.11 and 0.0.12 mark a turning point in the development of theQucs component and circuit modelling facilities. Release 0.0.11 introduced com-ponent values defined by equations and for the first time allowed subcircuits withparameters. Release 0.0.12 extends these features to add model development usingsymbolic equations that are similar to compact device code written in the Verilog-A modelling language. In designing the latest Qucs modelling features the Qucsteam has made a central focus of their work the need to provide the package withan interactive and easy to use modelling system which allows fast model prototypeconstruction. Much of these new aspects have up to now been undocumented andare likely to be very new to most Qucs users. The aim of this tutorial note is tooutline the background to these important package extensions and to provide realhelp to Qucs users who are interested in writing and experimenting with their ownmodels. The text includes a number of illustrative examples for readers to try andexperiment with.

Qucs electronic device and circuit modelling

Circuit simulation packages are complex software systems which often take yearsto mature to a stage where they are capable of analysing the current generation ofintegrated and discrete electronic circuits. Most circuit simulators have a numberof common basic attributes; firstly circuits are represented by a textual netlist ora schematic diagram which contains all the information required by a simulatorto analyse the performance of a circuit, and secondly a simulation engine whichundertakes the calculation of circuit performance in one or more different circuitdomains such as DC, AC or transient, and thirdly a post simulation processingsystem which structures and displays the simulation data in both tabular andgraphical forms. All circuit simulators have one other important attribute, namelythat they represent individual electronic components by a model, or abstraction,in a way that can be understood and analysed by the simulation engine whenundertaking a simulation task. Without component models the science of circuitsimulation would not have developed to the stage it has today. From a users pointof view component models are the key to simulator productivity; the greater thenumber of different models the easier it becomes to analyse mixed analogue anddigital electronic systems.

Shown in Fig. 1 is a block diagram of the analogue component modelling and simu-lation facilities currently provided by the Qucs package. The diagram is structuredas a flow chart which emphasises the different device modelling routes. When Qucs

1

Page 3: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

was first released only two of these were available for users to develop new devicemodels. The first of these has been used extensively by the package developers toconstruct the built-in models that are distributed with each Qucs release. Thisfundamental route involves hand coding the C++ code for a new model1, its com-pilation and linking with the core Qucs C++ code. Obviously, this does requirea specialised knowledge of the Qucs model programming interface2, the necessaryC++ skills, including a good working knowledge of the Trolltech Qt toolkit3. Atthe time of writing these notes the latest device to be added to Qucs using thisapproach is the exponential pulse source4. Models based on hand written C++code are normally restricted to basic devices that form the fundamental compo-nent core of a simulator - particularly where simulation computational efficiencyis important. One disadvantage of this approach, is the obvious one, in that thetime to implement a new model increases disproportionately with increasing modelcomplexity. For most Qucs users this route would not be the most natural to usewhen developing new models. However, for the specialist who spends a significantamount of time researching new device models this has always in the past, been theroute of choice. Unfortunately, modern semiconductor device models are becom-ing so complex that the model development time can stretch into months or evenyears and requires typically thousands of lines of C or C++ code to characterise amodel5. With the more complex models the problem of finding bugs in the modelcode also acts as a limit to fast model development.

For the average Qucs user their first introduction to the software is probablythrough constructing circuit schematics made entirely from the standard com-ponent models built into the package and the testing of their performance bylaunching the simulator from one of the Qucs simulation icons.6 The next naturalstage in the Qucs modelling and simulation learning curve is the use of subcircuitswhere groups of built-in components are collected together to form a higher levelcircuit block. These blocks are often arranged with a common theme, forming

1The technical details of the built-in models are described in: Qucs Technical Papers, StefanJahn, Michael Margraf, Vincent Habchi and Raimund Jacob, http://qucs.sourceforge.net/technical.html.

2Writing the documentation for the Qucs model programming interface is on the to do listand will be completed, when time allows, sometime in the future.

3Qt is a registered trademark of Trolltech, Norway; http://www.trolltech.com/copyright.4Added by Gunther Kraut on 15 April 2007. This device has been added for compatibility

with SPICE.5A good introduction to writing compact device models is given in “How to (and how not to)

write a compact model in Verilog-A”, Geoffrey J. Coram, 2004, Proc. 2004 IEEE InternationalBehavioral Modeling and Simulation Conference (BMAS 2004), pp 97- 106.

6The “Getting Started with Qucs” tutorial by Stefan Jahn outlines a number of basic simula-tion techniques; http://qucs.sourceforge.net/docs.html.

2

Page 4: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

QUCS GUICircuit

entered usingschematic capture

C++ code

Schematiccapturesymbols

SPICEpreprocessor

Nonlinear equationdefined devices

Componentdata processingusing Qucsequations

Userdefinedsubcircuitschematiccapturesymbol

Simulation output data

QUCSATOR

C++ component codecompiled and linkedto Qucsator core C++code via API

User definedsubcircuits

Qucscomponents

Simulate

Symbolicequations

Post simulationdata processingusing Qucsequations

Qucs plotsand tables

Hand codeddevice modelC++ code

ADMScompiler

Verilog-ACompactdevicecode

SPICEnetlist

SPICEparameterised

netlist

QucsLibrary

components

Generate Qucs netlist codefrom GUI schematic, includingconversion of SPICE code toQucs format

Qucs Tools:Line CalculatorAttenuator DesignMatching CircuitsFilter Design

Figure 1: Qucs analogue component modelling and simulation block diagram (notincluding optimisation)

3

Page 5: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

a Qucs library. The process of modelling new devices/circuits is normally doneby connecting existing component models and user defined subcircuits. With thistype of modelling higher level functional models can only be constructed from ex-isting fundamental components or previously constructed subcircuits. Engineersoften call this approach to modelling, macromodelling. Qucs releases up to 0.0.10relied on macromodelling for functional model development via the Qucs schematicinterface. This route remains popular amongst most Qucs users because it is easyto understand, is fully interactive and allows straight forward testing of new mod-els. One feature that is common to all components included in Qucs releases upto 0.0.10 may not be immediately obvious to readers, namely that, with the ex-ception of sweep variables, component values could only be numbers, for exampleR1 = 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 this pointthat during simulation, again performed by Qucs releases up to 0.0.10, componentvalues were required to remain constant and could not be a function of the circuitvariables such as voltage, current or charge.

One way to remove the component value restrictions imposed by early Qucs releasesis to model devices and circuits using preprocessor extended forms of the SPICEnetlist language. Circuit design equations can then be embedded in SPICE netlistsand the calculation of component values completed by the SPICE preprocessor.Both the SPICE to Qucs and OP AMP tutorials7 outline in detail the steps requiredto merge circuit design and simulation in this way. This modelling route is a veryimportant and powerful model development tool. So much so that ongoing tests toidentify how compatible Qucs is with the industrial standard SPICE 2g6 and 3f5syntax are currently being undertaken as part of the Qucs development schedule8.Although perfectly viable as a model development tool the use of an extendedSPICE netlist language has a number of serious disadvantages, namely that not allthe Qucs built-in component models have equivalent SPICE models and secondlytext netlists are the only entry medium for describing models.

The previous paragraphs give a brief statement of the different component mod-elling routes that were available up to release 0.0.11. Qucs 0.0.11 is very much amodelling water shed in that symbolic equations were introduced for the calcula-tion of component values, previously equations were only allowed when structuringsimulation output data for post simulation listing or plotting. Release 0.0.11 allowsthe following types of variable;

7Qucs simulation of SPICE netlists and Modelling Operational Amplifiers, Mike Brinson,http://qucs.sourceforge.net/docs.html.

8Qucs: Report Book; SPICE to Qucs test reports, Mike Brinson, http://qucs.sourceforge.net/docs.html.

4

Page 6: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

1. sweep variables,

2. equations left hand side,

3. component parameter’s 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 process-ing features, included in the Qucs equation set continues to expand9. From release0.0.11 parameters are also allowed with subcircuits so that data can be passedto a model. This allows generalised subcircuit/macromodels to be developed forpopular devices such as operational amplifiers. Through the use of embeddeddesign equations within subcircuits and parameter passing it became possible toconstruct powerful models that mix both circuit design procedures and the cal-culation of individual component values. Qucs 0.0.11 still imposed the restrictionthat equations could not be functions of voltage, current or charge.

With the release of Qucs 0.0.12 the voltage, current and charge restrictions imposedon equations will finally be relaxed. The introduction of a new device modellingcomponent called the equation defined device (EDD) allows firstly device current tobe formulated as a function of voltage, and secondly device charge to be calculatedas a function of voltage and current. The syntax adopted for the new modelborrows heavily on the compact device modelling approach taken by the Verilog-Amodelling language.

Some readers will probably have noted that so far these notes make no referenceto the ADMS model development route illustrated in Fig. 1. ADMS stands forAutomated device model synthesizer10 and includes a Verilog-A to C/C++ com-piler. It allows compact device models to be described in the Verilog-A languagethen compiled to C/C++ and the resulting code linked with the Qucs core simula-tion code11. Model development using ADMS is similar to the fundamental handcoded C++ model development route except that model development is greatlysimplified by the power of the high level Verilog-A language. A strong relation-ship exists between the ADMS and EDD modelling procedures in that EDD can

9See Measurement Expressions Reference Manual, Gunther Kraut and Stefan Jahn, http://qucs.sourceforge.net/docs.html.

10L.Lemaitre, C.C. McAndrew, and S. Hamm, ADMS - Automated Device Model Synthesizer,Proc. IEEE CICC, 2002.

11For more details see, Qucs Description: Verilog-AMS interface, Stefan Jahn and HeleneParruitte, http://qucs.sourceforge.net/docs.html.

5

Page 7: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

be considered a fast interactive model prototyping method whose equations caneasily be expressed in Verilog-A and compiled into C/C++ code for permanentinclusion in the Qucs simulator12.

The opening paragraphs attempt to outline the available device modelling tech-niques that are central to the functioning of the Qucs package. The remainingsections of this tutorial note are devoted to illustrating the power of Qucs mod-elling through the introduction of a number of illustrative examples. Initially thesestart from a simple, and hopefully familiar, point and then proceed to more com-plex examples which present many of the concepts lightly touched upon in theopening text.

Extending circuit simulation capabilities with equa-

tions

Just adding component value calculations, via equations, to a circuit simulatorimmediately increases the underlying design and simulation capabilities way be-yond that found in earlier generation simulators. Consider the simple RC circuitshown in Fig. 2. Capacitor Cap is stepped from 0.1µF to 1.1µF and the smallsignal AC response of the network calculated. In this example the values for bothR1 and Cap are given as numeric values. The simulation test shows the effect ofstepping the value of one component through a series of values and recording theeffect of component changes on circuit performance. In other words this is a clas-sical circuit analysis use of a circuit simulator. In a real design situation differentdata is often required. Most designers would prefer to find the value of Cap thatgives a specific RC cut-off frequency (fc) for a specified value of R1. This is thetype of investigative problem where adding equations into the simulation processgenerates more informative results. Shown in Fig. 3 is a similar RC network tothat illustrated in Fig. 2.Capacitor voltage V Cap is given by:

VCap =V1√

1 + ω2 ·C21 ·R2

1

(1)

where the cut-off frequency in the voltage transfer function is

fc =1

2π ·R1 ·C1

(2)

Hence, by expressing Cap as a function of fc and stepping fc through a range offrequencies, the effect of capacitance changes on the voltage transfer function can

12Appendix A gives an operator and function comparison table for Qucs and Verilog-A.

6

Page 8: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

be found. More importantly a nomogram of Cap values against fc can be plottedgiving the circuit designer a visual aid for determing the value of Cap required forgiven values of R1 and fc. Although the circuits shown in Figs. 2 and 3 are verybasic they do demonstrate how much more powerful a circuit simulator becomeswhen component values are calculated using equations.

Low pass active filter design with embedded design equa-tions

In this section a more advanced circuit design example is introduced to illustratethe power of embedded design equations in a Qucs simulation schematic. A secondorder Sallen-Key low pass filter is employed for this task because it is so well knownand most readers are likely to have met it’s design in the past. A second order lowpass filter is represented by the voltage transfer function:

A(S) =VoutVin

=A0

(1 + a2 ·S + b2 ·S2)(3)

where A0 is the passband DC gain and coefficients a2, b2 are for Bessel, Butter-worth, Tschebyscheff or similar polynomials.

The following list13 gives the second order coefficients for the Bessel → 1.3617,0.618; Butterworth → 1.4142, 1.000; and 3dB ripple Tschebyscheff → 1.065,1.9305, polynomials. The second order Sallen-Key low pass filter circuit is shownin Fig. 4. This circuit has a voltage gain transfer function given by:

A(S) =A0

1 + ωc · [C1 · (R1 +R2) + (1− A0) ·R1 ·C2] ·S + ω2c ·R1 ·R2 ·C1 ·C2 ·S2

(4)where

A0 = 1 +R3

R4

(5)

This can be simplified by letting R1 = R2 = R and C1 = C2 = C; the transferfunction then becomes:

A(S) =A0

1 + [ωc ·R ·C · (3− A0)] ·S +[(ωc ·R ·C)2

]·S2

. (6)

13See OP Amps for everyone, Chapter 16: Active filter design technology, Texas Instruments,August 2002, SL0D006B, PP 16.1,16.63.

7

Page 9: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

V1U=1 V

C1C=Cap

Parametersweep

SW1Sim=AC1Type=linParam=CapStart=0.1uStop=1.1uPoints=11

ac simulation

AC1Type=logStart=1HzStop=1 MHzPoints=61

R1R=1k

VCap

1 10 100 1e3 1e4 1e5 1e6

0

0.5

1

acfrequency

VCap.v

2 4 6 8 100

5e-7

1e-6

number

Cap

Figure 2: A simple RC circuit simulation using numerical component values

8

Page 10: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

V1U=1 V

C1C=CapR1

R=Rvalue

Parametersweep

SW1Sim=AC1Type=logParam=fcStart=10Stop=1000Points=21

ac simulation

AC1Type=logStart=1HzStop=1 MHzPoints=61

Equation

Eqn1Rvalue=1000Cap=1/(2*pi*Rvalue*fc)

VCap

1 10 100 1e3 1e4 1e5 1e6

0

0.5

1

acfrequency

VCap.v

10 100 1e31e-7

1e-6

1e-5

fc

Cap

Figure 3: A simple RC circuit simulation employing equation determined compo-nent values

9

Page 11: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

-

+

OPA27(TI)

VCC

VEE

SUB1

V2U=15 V

V3U=15 V

V1U=1 V R2R1

C1

C2

R3 R4

Vout

Figure 4: The Sallen-Key lowpass active filter circuit

By comparisona2 = ωc ·R ·C · (3− A0) (7)

andb2 = (ωc ·R ·C)2 (8)

Fixing C and solving for R and A0, yields

R =

√b2

ωc ·C, and A0 = 3− a2√

b2. (9)

Also once A0 is known the value for R4 can be calculated using equation

A0 = 1 +R3

R4. (10)

Hence by providing values for C and R3 the values for R and A0, and of courseR4, can be determined for a specified cut off frequency fc. Figure 5 shows thefinal design schematic and the simulation results for this example. A number ofimportant observations can be made from Fig. 5:

1. One or more equation blocks hold both design and post simulation dataprocessing equations plus assignments for named items: C, fc and R3 aregiven numerical values, the a and b polynomial coefficients are set to thevalues introduced in the text, and finally the design equations for R, A0 andR4 calculations are listed.

10

Page 12: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

-

+

OPA27(TI)

VCC

VEE

SUB1

V2U=15 V

V3U=15 V

V1U=1 V R2

R=RR1R=R

C2C=C

C1C=C

R3R=R3_calc

R4R=R4_calc

Equation

Eqn1C=22e-9a2=1.065b2=1.9305fc=3000R=sqrt(b2)/(2*pi*fc*C)A0=3-a2/(sqrt(b2))R3_calc=4700R4_calc=(A0-1)*R3_calcgain_dB=dB(Vout.v)gain_phase=rad2deg(unwrap(angle(Vout.v)))

ac simulation

AC1Type=logStart=1 HzStop=100 kHzPoints=101

dc simulation

DC1

Vout

1 10 100 1e3 1e4 1e5

0

2

4

acfrequency

Vou

t.v

1 10 100 1e3 1e4 1e5

-200

-100

0

acfrequency

gain

_pha

se

1 10 100 1e3 1e4 1e5

-50

0

acfrequency

gain

_dB

Figure 5: The Sallen-Key lowpass active filter schematic with embedded designequations

11

Page 13: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

2. The order of entries in equation blocks is not important because Qucs auto-matically sorts out the data it requires when calculating equations.

3. The lefthand quantities in the assignment entries in the equation blocks arelinked to the component values in the schematic, see for example C and R.

4. The OP27 operational amplifier model is from the modified Qucs 0.0.11OPAMP library. This model was generated using the SPICE to Qucs mod-elling route.

5. To design and simulate a Sallen-Key low pass filter with a different cut offfrequency14 simply change the value of fc and rerun the Qucs simulator.

6. On completion of a simulation, pressing key F5 (Show last messages) causesthe simulation log to be displayed. This includes the calculated values of thecomponents and the netlist for the circuit, see Fig. 6.

7. One final point of significance that some readers may have noticed - allnumerical values in equation blocks must be specified in scientific notation;electronic notation like 1k or 3nF is not allowed15.

14If the design calculations result in impractical values for the filter components then the valueof C should be changed and the simulation repeated.

15In long term it is expected that electronic notation will be allowed. The changes for this areon the to do list but at the moment the work has a low priority.

12

Page 14: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Output :−−−−−−−n e t l i s t content

13 R i n s t a n c e s5 C i n s t a n c e s2 VCCS i n s t a n c e s5 CCCS i n s t a n c e s2 VCVS i n s t a n c e s1 CCVS i n s t a n c e s8 Vdc i n s t a n c e s1 Idc i n s t a n c e s1 Vac i n s t a n c e s4 Diode i n s t a n c e s2 BJT i n s t a n c e s1 DC i n s t a n c e s1 AC i n s t a n c e s

c r e a t i n g n e t l i s t . . .checker not i ce , v a r i a b l e ‘ Vout . v ’ in equat ion ‘ ga in dB’ not yet de f inedchecker not i ce , v a r i a b l e ‘ Vout . v ’ in equat ion ‘ ga in phase ’ not yet de f inedkB = 1 . 38065e−23e = 2 . 71828p i = 3 . 14159C = 2 . 2e−08a2 = 1 . 065b2 = 1 . 9305f c = 3000R = 3350 . 51A0 = 2 . 2335R3 c a l c = 4700R4 c a l c = 5797 . 43kB = 1 . 38065e−23e = 2 . 71828p i = 3 . 14159kB = 1 . 38065e−23e = 2 . 71828p i = 3 . 14159kB = 1 . 38065e−23e = 2 . 71828p 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

13

Page 15: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Introduction to Qucs subcircuit parameters

Subcircuits are a concept that has been part of the simulation scene for a longtime. All circuit simulators based on SPICE have subcircuits as part of theirbasic device compliment. This is not surprising because they form a natural wayof breaking an electronic system down into a number of smaller self containedfunctional blocks. What is surprising however, is the fact that a significant numberof simulators, including SPICE 2g6 and 3f516, do not allow parameters to be passedto a subcircuit. Parameter passing appears to have been first introduced when anumber of the popular commercial circuit simulators were being developed17. Qucsreleases up to version 0.0.10 are similar to SPICE in that they also did not allowparameters with subcircuits.

This very important limitation has been removed with release 0.0.11, which allowsparameters to be attached to component symbols and used in subcircuit equa-tion calculations. Shown in Fig. 7 are the circuit schematic and user generatedsymbol for a simple harmonic generator with a fundamental and three harmonicsinusoidal components. Parameters f1 to f4 determine these frequency compo-nents. Notice that an equation block, at the circuit schematic level, is used tocalculate the harmonic frequencies. Parameters ph1 to ph4 set the phase of theindividual sinusoidal oscillators. The process of attaching parameters, and theirdefault values, to a subcircuit symbol is straightforward; simply right click on thesymbol subcircuit name, SUB1 in Fig. 7, and an Edit Subcircuit Properties dialogbox appears allowing parameter names and their default values to be entered18.Subcircuit parameters and their values are normally displayed as a list underneaththe subcircuit name. Changing parameter values is done in a similar fashion tochanging the values of the standard built-in components. The diagram and sim-ulation results illustrated in Fig. 8 show a waveform formed from a fundamentaland two harmonics.

An equation block is employed to calculate and plot the amplitude and power spec-tral densities of the harmonic waveform. By changing the fundamental frequency,signal amplitudes and phases different wave shapes can be generated by resimulat-ing the circuit. In this example transient analysis is used to generate the harmonicwaveform with the run time set to 10ms and the number of points equal to 50019.

16One of the reasons SPICE preprocessors were developed was to allow parameter passing tosubroutines, for more details see Qucs Tutorial: Qucs simulation of SPICE netlists, Mike Brinson,http://qucs.sourceforge.net/.

17See, for example, the extended netlist format originally designed by the MicroSim Corpora-tion for the PSpice circuit simulator.

18See Appendix B for a more detailed description of the procedure.19Qucs function length() determines the correct data length in equation block Eqn1 calcula-

14

Page 16: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

P_sigV1U=f1_ampf=f1Phase=ph1

V2U=f2_ampf=f2Phase=ph2

V4U=f4_ampf=f4Phase=ph4

V3U=f3_ampf=f3Phase=ph3

Equation

Eqn1f2=2*f1f3=3*f1f4=4*f1

HG1

SUB1f1=1000f1_amp=1.0f2_amp=0.0ph1=0.0ph2=0.0f3_amp=0.0f4_amp=0.0ph3=0.0ph4=0.0

Figure 7: Harmonic generator subcircuit schematic and symbol

This gives a sampling time of 20µs and a sampling frequency of 50kHz. Equationblock Eqn1 demonstrates how the Qucs functions20 can be used to postprocesssimulation generated data - in this example they are used to compute the DFT ofthe harmonic generator waveform, convert the resulting spectra from double sidedto single sided form, compute and plot the amplitude and power spectral densities.

tions.20If you have used a program like Octave, or indeed Matlab, many of these functions should

be familiar to you. These functions provide Qucs with powerful numerical resource which signif-icantly extends the range of problems that Qucs can analyse.

15

Page 17: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

HG1

SUB1f1=1000f1_amp=5.0f2_amp=2.0ph1=0ph2=0f3_amp=2f4_amp=0ph3=0ph4=90

R1R=50 Ohm

transientsimulation

TR1Type=linStart=0Stop=10 msPoints=500

Equation

Eqn1ts=(max(time)-min(time))/length(time)fs=1/tsAdft=dft(hg_sig.Vt)LAdft=length(hg_sig.Vt)Amp2=2*Adft[1:(LAdfto2)-1]LAdfto2=LAdft/2Amp_squared=Adft[:LAdfto2]*conj(Adft[:LAdfto2])Amp=sqrt(Amp_squared)f_bin=linspace(1, LAdfto2, LAdfto2)f=(f_bin-1)*fs/LAdftPLAmp=PlotVs(2*Amp/LAdft,f)PLPower=PlotVs(4*Amp*Amp/(LAdft*LAdft),f)

hg_sig

0 1e-3 0.002 0.003 0.004 0.005 0.006 0.007 0.008 0.009 0.01

-5

0

5

time

hg_sig.Vt

0 5e3 1e4 1.5e4 2e4 2.5e4

0

10

20

30

Frequency Hz

Pow

er Spectral density (V

^2) PLP

ower

0 5e3 1e4 1.5e4 2e4 2.5e4

0

2

4

6

Frequency Hz

Amplitude Spectral density (V

) PLA

mp

Figure 8: Harmonic generator subcircuit test circuit and simulation waveforms

16

Page 18: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Building universal macromodels using subcircuits

and parameters

Passing parameters to subcircuits allows universal macromodels to be built. Oneobvious application of this technique is the modelling of operational amplifiers(OP AMP) and other integrated circuits. The approach adopted is similar to thatoutlined in the last section. However, because of the complexity of the modelsit is advisable to break a model into a series of smaller blocks. These are thencombined to form a complete subcircuit macromodel. Two techniques are possi-ble when partitioning models, these are demonstrated next. Shown in Fig. 9 is asimple AC OP AMP model21 consisting of an input stage, an intermediate gainstage and an output stage22. An equation block, if needed, is associated with eachstage. These blocks contain the equations for calculating the component valuesin a given stage. A single schematic symbol represents the model. This has alist of parameters attached. The flow of information into a macromodel startswith parameters passed into a subcircuit, via a schematic symbol, then onto theequation blocks, where it is finally used to calculate the component values. Hence,by simply changing the subcircuit parameters different OP AMPs can be simu-lated using a single generalised macromodel. However, please note that differentOP AMP circuit structures, or indeed technologies, naturally result in a series ofgeneralised subcircuit macromodels to cover all possible types in a given devicefamily. The second technique involves breaking a model down into smaller blocksand associating subcircuit symbols with each block. This approach is illustratedin Fig. 10. Again parameters are passed from the top level symbol (called AC inthe schematic) to the inner subcircuits. These pass their own parameters downa subcircuit level where the component calculations are completed. The secondtechnique results in two levels of subcircuit, accounting for the change in param-eter name when passing a parameter from top to lower hierarchy. A second moredetailed example showing how to construct nested subcircuits is presented later inthese notes.

In reality the macromodel for a typical OP AMP that models DC, AC and transientdomains is much more complex than the model given in Fig. 9. The schematic fora typical multi-domain OP AMP modular macromodel is shown in Fig. 11, where

21The term AC here refers to the fact that the OP AMP model chosen for demonstrationpurposes is a simplified version of a multi-domain OP AMP model. It only models small signalAC parameters and device input stage bias and offset properties.

22The schematic shown in Fig. 9 forms part of a modular OP AMP macromodel. A de-tailed description of the function of individual networks and the derivation of the compo-nent equations is given in Qucs tutorial Modelling Operational Amplifiers, Mike Brinson,http://qucs.sourceforge.net/docs.html.

17

Page 19: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

P_INN1

Voff1U=voff1

Ib1I=ib

Ib2I=ib

Ioff1I=ioff1

R1R=r1

R2R=r2

Cin1C=cd

P_INP1

Voff2U=voff2

EOS1G=1

ROS1R=ro

P_OUT1

Equation

Eqn1voff1=voff/2voff2=voff/2ioff1=ioff/2r1=rd/2r2=rd/2

RSRT1R=1

GMSRT1G=0.01 S

GMP1G=1 S

CP1C=cp1

RADO1R=aoldc

Equation

Eqn2cp1=1/(2*pi*gbp)

AC-+

SUB1voff=0.7e-3ioff=80e-3rd=2e6cd=1.4e-12aoldc=200e3gbp=1e6ro=75

Input Stage

Intermediate gain stage

Output stage

Figure 9: Expanded AC OP AMP model showing circuitry and equation blocks

each section of the macromodel is represented, if needed, by it’s own equationblock.

The test schematics shown in Figures. 12 and 13 show two OP AMPs with differentsubcircuit parameters. In Fig. 12 the small signal characteristics of unity gainclosed loop amplifiers clearly show the difference in performance of the OP AMPs.Figure 13 is particularly interesting in that it illustrates how Qucs can be usedto determine the effect of amplifier offset voltage on integrator DC saturation bystepping resister rp through a series of values. The low offset voltage of the OP27makes this device much more suitable for integrator circuits when compared tothe popular UA741. These results can be confirmed by a simple calculation: theoffset voltage for the UA741 is set at 0.7 mV and the amplifier open loop DC gainat roughly 200, 000. The UA741 goes into saturation when rp is approximately20 MΩ. In saturation the OP AMP gain becomes open loop giving a DC outputvoltage of roughly 0.7e-3 · 2e5 or 14 V, which agrees with the Qucs simulationresults.

18

Page 20: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

ON

InputStage

OP

IN

IP

SUB2voff=v_offioff=i_offrd=r_dib=i_bcd=c_d

IN

Interstage

IP

O

SUB3gbp=g_bpaoldc=a_oldc

P_INN1

P_INP1

P_OUT1

P_INN2

Voff1U=voff1

Ib1I=ib

Ib2I=ib

Ioff1I=ioff1

R1R=r1

R2R=r2

Cin1C=cd

P_INP2

Voff2U=voff2

Equation

Eqn1voff1=voff/2voff2=voff/2ioff1=ioff/2r1=rd/2r2=rd/2

P_INP3

P_INN3

RSRT1R=1

GMSRT1G=0.01 S

GMP1G=1 S

RADO1R=aoldc

Equation

Eqn2cp1=1/(2*pi*gbp)

P_OUT2

P_INP4

P_INN4

-AC

+

SUB1v_off=0.7e-3i_off=20e-9r_d=2e6c_d=1.4e-12i_b=80e-9g_bp=1e6a_oldc=200e3r_o=75

ON

InputStage

OP

IN

IP

SUB7voff=v_offioff=i_offrd=r_dib=i_bcd=c_d

IN

Interstage

IP

O

SUB8gbp=g_bpaoldc=a_oldc

EOS1G=1

PO1 ROS1R=ro

P_OUT3

IN O

output

Stage

SUB4ro=r_o

IN O

output

Stage

SUB9ro=r_o

CP1C=cp1

Figure 10: Modular AC OP AMP model showing subcircuits

19

Page 21: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

RDCMZR=650M

RCM1R=1M

SRC2G=1 S

SRC3G=1 S

RSRT1R=1

GMSRT1G=0.01 S

RSCALE1R=100

SRC1G=1 S

RSUM1R=1

GMP1G=1 S

P_INN

P_INP

Voff1U=voff1

Voff2U=voff2

Ib1I=ib

Ib2I=ib

Ioff1I=ioff1

ECM1G=ecm1

VSR1U=p1

CP1C=cp1

RADOR=aoldc

ECLG=1

RP2R=1

EOS1G=1

RDCCL1R=100M

CP2C=cp2

P_VCC

P_VEE

DVLM2Is=8e-16 A

DVL1Is=8e-16 A

ROS1R=ro

D3Is=1e-15 ACj0=0.0

D2Is=1e-15 ACj0=0.0

HCL1G=hcl1

VLIM1U=vlim1

VLIM2U=vlim2

R1R=r1

R2R=r2

Cin1C=cd

Equation

Eqn1voff1=voff/2voff2=voff/2ioff1=ioff/2r1=rd/2r2=rd/2

Equation

Eqn2ecm1=1e6/cmrrdcccm1=1/(2*pi*1e6*fcmz)

D1Is=1e-12 ABv=psumIbv=20 mA

Equation

Eqn4cp1=1/(2*pi*gbp)

Equation

Eqn6hcl1=0.9/idcoutm

Equation

Eqn7vlim1=vcc-vccm+1vlim2=-vee+veem+1

RCM2R=1

Equation

Eqn3p1=(100*pslewr)/(2*pi*gbp)-0.7p2=(100*nslewr)/(2*pi*gbp)-0.7psum=p1+p2

Equation

Eqn5cp2=1/(2*pi*fp2)

CCM1C=ccm1

GMP2G=1 S

P_OUT

Figure 11: Modular OP AMP subcircuit schematic with embedded componentcalculation equations

20

Page 22: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

-

+

VCC

VEE

MOD

SUB2voff=0.7e-3ib=80e-9ioff=10e-9rd=2e6cd=1.4e-12cmrrdc=31622.77fcmz=200.0aoldc=199526.3gbp=1e6fp2=3e6pslewr=0.5e6nslewr=0.5e6vcc=15vee=-15vccm=14veem=-14ro=75idcoutm=34e-3

-

+

VCC

VEE

MOD

SUB1voff=30e-6ib=15e-9ioff=12e-9rd=4e6cd=1.4e-12cmrrdc=1778279.4fcmz=2009.0aoldc=1778279.4gbp=8e6fp2=17e6pslewr=2.8e6nslewr=2.8e6vcc=15vee=-15vccm=14veem=-14ro=75idcoutm=32e-3

R1R=4.7k

R2R=4.7k

R4R=4.7k

R3R=4.7k

V1U=15 V

V2U=15 V

V3U=1 V

Equation

Eqn1gain_ua741=dB(vout_ua741.v)phase_ua741=phase(vout_ua741.v)phase_op27=phase(vout_op27.v)gain_op27=dB(vout_op27.v)

ac simulation

AC1Type=logStart=1 HzStop=100MHzPoints=161

dc simulation

DC1

vout_ua741

vout_op27

number

1

vout_op27.V

-3.87e-05

vout_ua741.V

0.001

1 10 100 1e3 1e4 1e5 1e6 1e7 1e8

0

0.5

1

Frequency Hz

vout_op27.v

vout_ua741.v

1 10 100 1e3 1e4 1e5 1e6 1e7 1e8-60

-40

-20

0

Frequency Hz

gain_op27

gain_ua741

1 10 100 1e3 1e4 1e5 1e6 1e7 1e8-100

0

100

200

Frequency Hz

phase_op27

phase_ua741

Figure 12: Unity gain OP AMP test circuit and waveforms

21

Page 23: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

-

+

VCC

VEE

MOD

SUB2voff=30e-6ib=15e-9ioff=12e-9rd=4e6cd=1.4e-12cmrrdc=1778279.4fcmz=2009.0aoldc=1778279.4gbp=8e6fp2=17e6pslewr=2.8e6nslewr=2.8e6vcc=15vee=-15vccm=14veem=-14ro=75idcoutm=32e-3

-

+

VCC

VEE

MOD

SUB1voff=0.7e-3ib=80e-9ioff=10e-9rd=2e6cd=1.4e-12cmrrdc=31622.77fcmz=200.0aoldc=199526.3gbp=1e6fp2=3e6pslewr=0.5e6nslewr=0.5e6vcc=15vee=-15vccm=14veem=-14ro=75idcoutm=34e-3

V1U=15 V

V3U=15 V

V4U=15 V

V2U=15 V

R1R=1k

R2R=1k

C1C=1 uF

C2C=1 uF

R4R=rp

R3R=rp

Parametersweep

SW1Sim=DC1Type=logParam=rpStart=1e3Stop=1e9Points=31

dc simulation

DC1

vout_op27

vout_ua741

1e3 1e4 1e5 1e6 1e7 1e8 1e9

0

5

10

15

rp

vout_ua741.V

vout_op27.V

Figure 13: Integrator test circuits for determining DC saturation

22

Page 24: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

More complex nested subcircuit models

In the previous two sections the example circuits only included subcircuits nestedto one or two levels. Qucs does however, allow subcircuits to be nested to anarbitrary level and parameters can be passed down the nested chain to any depthrequired. Some care is needed when setting up the parameter passing sequence.Shown in Fig. 14 is a top level subcircuit with temperature swept between 10and 110 centigrade. A simple resistor voltage divider network is at the bottom ofa series of linked subcircuits, three levels down. R2 in the divider is a functionof temperature. A schematic representation of the coupled subcircuits parameterpassing sequence is also given in the right hand side of Fig. 14. Each level passesthe value of temperature to it’s next lower member in the hierarchy. The Qucsgenerated netlist given in Fig. 15 clearly shows the parameter passing mechanismemployed by Qucs. The ability to nest subcircuits and pass parameters down ahierarchy is an important feature in Qucs because it allows both circuit designand device data to be passed to different sections of the circuit/system beingsimulated. These parameters can, of course, be at different levels in a problemhierarchy providing a very flexible and powerful design/analysis tool.

V1U=1 V

dc simulation

DC1

Parametersweep

SW1Sim=DC1Type=linParam=tsweepStart=10Stop=110Points=100

SUB 3OUTIN

SUB1sp1=tsweep

R1R=10kTemp=tscanTc1=0.01Tc2=0.015

R2R=10kTemp=26.85

P2P1

vp01

20 40 60 80 1000.4

0.6

0.8

1

tsweep

vp01

.V

IN

IN OUT

OUT

SUB3

SUB2

SUB1

OUTIN

Sp1 = tsweep

Sp2=Sp1

tscan=Sp2

Figure 14: A nested subcircuit showing parameter passing sequence

23

Page 25: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

# Qucs 0 . 0 . 12 /media/hda2/Qucs equat ion mode l l ing p r j / rd iv t e s t tsweep 3 l . sch. Def : rd iv sub1 temp net1 net0 tscan=”27 ”R:R2 gnd net0 R=”10k ” Temp=”tscan ” Tc1=”0 . 01 ” Tc2=”0 . 015 ” Tnom=”26 . 85 ”R:R1 net1 net0 R=”10k ” Temp=”26 . 85 ” Tc1=”0 . 0 ” Tc2=”0 . 0 ” Tnom=”26 . 85 ”. Def :End

. Def : rd iv t e s t 6 temp net1 net0 sp2=”27 ”Sub :SUB1 net1 net0 Type=”rd iv sub1 temp ” tscan=”sp2 ”. Def :End

. Def : rd iv sub3 temp net0 net1 sp1=”27 ”Sub :SUB1 net0 net1 Type=”rd iv t e s t 6 temp ” sp2=”sp1 ”. Def :End

Vdc :V1 net0 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” vnto l=”1 uV”saveOPs=”no ” MaxIter=”150 ” saveAl l=”no ” convHelper=”none ” So lve r=”CroutLU ”.SW:SW1 Sim=”DC1” Type=” l i n ” Param=”tsweep ” Start=”10 ” Stop=”110 ” Points=”100 ”Sub :SUB1 net0 vp01 Type=”rd iv sub3 temp ” sp1=”tsweep ”

Figure 15: Qucs netlist for nested subcircuit showing parameter passing sequence

Introduction to equation defined devices (EDD)

Although adding symbolic equations to a simulator merges circuit design and anal-ysis, it is by making these equations functions of circuit variables that the realpower of modern circuit simulator is fully exploited. Equations that are functionsof voltage, current and charge have to be continuously evaluated as a simulationprogresses. This is in contrast to the type of equations previously introduced,which are only evaluated at the start of a simulation sequence. When componentproperties are functions of circuit variables considerable complexity is added toa simulation engine and as a result most simulators restrict such properties toa small number of component types, the most common being controlled currentand voltage generators23. Qucs version 0.0.12 introduces an equation defined de-vice (EDD) which allows it’s terminal currents to be functions of voltage, and it’sstored charge to be functions of voltage and current. The EDD is similar, but more

23Probably the most well known non-linear controlled generators are the SPICE 2g6 and 3f5forms, see A. Vladimirescu, Kaihe Zhang, A.R. Newton, D.O. Pederson and A. Sangiovanni-Vincentelli, SPICE Version 2G User’s Guide, 1981, Department of Electrical Engineering andComputer Sciences, University of California, Berkeley, Ca. 94720, section 11, Appendix B: Non-linear dependent sources., and B. Johnson, T. Quarles, A.R. Newton, D.O. Pederson and A.Sangiovanni-Vincentelli, SPICE3 Version f User’s Manual, 1992, Department of Electrical Engi-neering and Computer Sciences, University of California, Berkeley, Ca. 94720, section 3.2.2.4,Non-linear dependent sources.

24

Page 26: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

advanced, to the B type controlled source implemented in SPICE 3f5. It is capableof realising the same models as the SPICE B type device plus an extensive rangeof more complex compact device models. At this stage in Qucs development onlythe explicit form of EDD is implemented24. EDD is an advanced component thatallows Qucs users to construct their own device models from a set of equations de-rived from the physical properties that characterise a device. The explicit form ofEDD can only be used to develop models for devices where their defining equationscan be transformed into the explicit analysis form required by Qucs25. A rangeof functions similar to those defined in the Verilog-A compact device modellinglanguage are provided by Qucs, making the equation modelling language easy touse and powerful. The ternary ? : form of the C language if statement has alsobeen implemented to allow selection of model equations that change with differingdevice voltage, current and charge conditions. Before introducing the EDD symboland it’s properties consider the following circuit simulation modelling problem: amodel for a device is required where the output voltage is a function of two inputvoltages V IN1 and V IN2, such that

Vout (V IN1, V IN2) = V IN1 ·V IN2, (11)

where V IN1 and V IN2 can be arbitrary varying voltages.

This type of model is difficult to simulate at functional level26 using the pre-version0.0.12 built-in devices. A linear voltage controlled voltage source can be used tomultiply a voltage by a constant. Multiplying by a second voltage is not possiblewith the linear controlled sources. Qucs AM modulated and PM modulated sourcesare the nearest that Qucs has to the source defined above. These sources however,only allow sinusoidal carrier signals. Illustrated in Fig. 16 is a four quadrantmultiplier EDD which allows multiplication of two varying signals27. The EDDdevice generates current I1 = V 2 ·V 3. This in turn is transformed to the outputvoltage by a unity gain current controlled voltage source SRC1. An EDD devicecan consist of up to 8 branches. The branches have currents, I1 to I8, voltages V1to V8 and internal charges Q1 to Q8 respectively. Overall the total device currentdepends how these branches are connected. A similar comment applies to the totaldevice charge. In Fig. 16 currents I2 and I3 are set to zero, charges Q2 and Q3 are

24See Qucs Technical Papers, Section 10.7: Equation defined models, Stefan Jahn, MichaelMargraf, Vincent Habchi and Raimund Jacob, http://qucs.sourceforge.net/technical.

html.25The Y parameters of the device being modelled must also exist for the explicit form of the

EDD to be valid.26It is, of course, possible to model the multiplier operation at discrete component level e.g.

using a Gilbert cell mixer circuit.27This model is based on an idea suggested by Stefan Jahn, during the EDD development

phase.

25

Page 27: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

also zero, and voltages V 2 = V IN1 and V 3 = V IN2. Hence current I1 becomesthe multiplication of V IN1 and V IN2. The fact that currents I2 and I3 are set tozero implies that the terminals connected to the external input voltages have highimpedance and act as voltage probes. The test circuit in Fig. 16 is shown withsignal inputs generated by sinusoidal oscillators; V1 acts as a modulating signaland V2 as a carrier signal. The bottom right hand corner of Fig. 16 includes asecond graph which illustrates the effect of changing signal V2 to a square wavesource with 0.05ms period.

V1U=1 Vf=1 kHz

V2U=5 Vf=10 kHz VMULT1

SRC1G=1

Out1Num=1

In1Num=2

In2Num=3

1

2

3

D1I1=V2*V3Q1=0I2=0Q2=0I3=0Q3=0

transientsimulation

TR1Type=linStart=0Stop=1 msPoints=401

R1R=50 Ohm

Out

0 2e-4 4e-4 6e-4 8e-4 1e-3

-5

0

5

timeOut.Vt

0 2e-4 4e-4 6e-4 8e-4 1e-3

-1

0

1

time

vmul_2_tb:Out.Vt

Figure 16: Qucs EDD four quadrent multiplier model and test circuit

The Qucs EDD component

A two terminal model for a universal non-linear component with resistive, capac-itive and inductive parallel branches is shown in Fig. 17. All three branches have

26

Page 28: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

elements that can be functions of either voltage or current or charge28. The QucsEDD component can be used to model this nonlinear device. One EDD element isneeded to model the resistive and capacitive branches. A second EDD device, plusa gyrator, models the inductive branch. The total terminal current is the sum ofthe individual branch currents. Equations for the three branch currents are givenby the following equations:

I = I1 + IC + IL, (12)

where

I1 = f(V ), IC = C(V, I) · dV 1

dt=dQ1

dt(13)

Also

V 1 = i2, V 2 = −IL, i2 = −L(I) · dV 2

dt, V 1 = L(I) · dIL

dt(14)

Giving

IL =1

L(I)·∫V 2 · dt (15)

and

V L = V 2 = V 1 =dΦ

dt(16)

Hence

I = f(V ) + C(V, I) · dV 1

dt+

1

L(I)·∫V 1 · dt (17)

The EDD is characterised by eight parallel branches each comprising a currentcomponent In and a charge component Qn, where n ranges from 1 to 8. Thecurrents may be constants or defined by equations that are functions of the EDDbranch voltages (these are designated V 1 to V 8). This form of the EDD compo-nent is known as the explicit EDD model. Please note, EDD currents cannot befunctions of current. However, with release 0.0.12 implementation of the explicitEDD the device charge can be a function of either voltage or current29. The cur-rent in the resistive branch being a function of EDD voltage allows a range of twoterminal30 devices to be modelled, allowing, for example, nonlinear resistors anddiode models to be easily developed. Similarly, the fact that the EDD charge canbe a function of voltage or current extends the range of allowed Qucs capacitor

28Each branch can be a function of one or more of these circuit variables but not necessarilyall three at the same time.

29This allows modelling of semiconductor capacitive effects where the amount of stored chargeis either a function of voltage (depletion layer capacitance), or a function of current (diffusioncapacitance).

30The number of device terminals can be increased to model transistors and other devices.

27

Page 29: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

types opening new areas of application. The same comments apply to the nonlin-ear inductors where components that have inductance values which are functionsof current allow modelling of nonlinear transformer and coupled inductor effects.This was not possible with earlier Qucs releases. The EDD current and chargevalues may be defined by symbolic equations that include the operators and func-tions listed in the “Short description of mathematical functions“ entry in the Qucshelp index31.

31The Qucs operators and functions are a superset of those defined in the Verilog-A languagemanual. However, in some cases the name of the operator or function differs slightly. For exampleVerilog-A uses pow(x, y) for the power function whilst Qucs uses ∧ to denote xy. An example ofdiffering function names are the inverse trigonometric functions. A list of the available functionsis given in Appendix A.

28

Page 30: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

X1R=1

1

D1I1=I1Q1=C(V,I)*V1 1

D2I1=0Q1=L(I)*V2

C1C=f(V,I)

L1L=f(I)

R1R=f(V)

I1+IC IL

V2

I

V1

i2

I

V1

I1 IC IL

Q

Gyrator

Equationdefineddevice(EDD)

Equationdefineddevice(EDD)

Figure 17: A non-linear two terminal branch with parallel resistive, capacitive andinductive components

29

Page 31: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Modelling nonlinear resistors

In many measurement applications a transducer is employed to transform changingvalues of a physical quantity to, say, changes in resistance. Often the resistivecharacterstics of these devices are nonlinear. To demonstrate how the EDD can beused to model a nonlinear resistance the example shown in Fig. 18 is introduced.In this schematic an EDD represents a resistance that is a function of the appliedvoltage across it’s terminals. This example deliberately shows an extreme casewhere the resistance changes in a resistive pulse like fashion as the terminal voltageincreases. The example also introduces for the first time the ternary ? : operatorand illustrates how it can be nested to give an ”if then else“ structure to define thecomponent properties. A point of note with these very nonlinear devices centresaround the fact that it is possible to define components that have discontinuities intheir I-V characteristics32. The EDD current equation defines how the resistanceof this device changes with changing terminal voltage. This equation is given by

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)

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 )

32One effect of such a discontinuity is the introduction of rapidly changing circuit conditionswhich can cause the simulator difficulties in converging to a correct solution. Sometimes, if thishappens, simulation run times may be dramatically increased or simulation fails altogether.

30

Page 32: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

V1

U=V

s

dc s

imul

atio

n

DC

1

Pr1

Equ

atio

n

Eqn

1R

=Vs/

Pr1

.I

Par

amet

ersw

eep

SW

1Sim

=DC

1Typ

e=lin

Par

am=V

sSta

rt=0

Sto

p=7

Poi

nts=

100

1

D1

I1=V

1/((V1<

1.0)

? 1

000

: (V1<

2.0)

? 1

000+

4000

*(V1-

1) :

(V1<

5.0)

? 5

000

: ((V

1 >=

5.0)

&& (

V1<

6.0)

) ? 5

000-

4500

*(V1-

5.0)

: 50

0)

Vs

01

23

45

67

1e-6

1e-5

1e-4

1e-3

0.010.

1

Vs

Pr1.I

01

23

45

67

0

1e3

2e3

3e3

4e3

5e3

Vs

R

Figure 18: Qucs nonlinear resistor model

31

Page 33: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Modelling nonlinear capacitors and inductors

Nonlinear capacitors, who’s C value is a function of terminal voltage, and nonlin-ear inductors, who’s L value is a function of terminal current, commonly act ascontrol elements in electronic systems. SPICE 2g6 includes a nonlinear symbolicpolynomial form of C and L33. The schematic shown in Fig. 19 illustrates how anonlinear capacitor can be modelled by an EDD. This model is based on a SPICElike polynomial function with four coefficients; C0, C1, C2 and C334. The test cir-cuit is a simple RC network with nominally identical R and C component valuesto those shown in Fig. 2. Increasing the value of DC source V1 also increases Cwhich in turn decreases the RC low pass filter -3dB frequency. This effect is veryvisible in Fig. 19. The nonlinear changes in C are also clearly illustrated in theoutput voltage and phase curves. The schematic symbol for the nonlinear capaci-tor is shown in Fig. 19 with a red ring drawn around the normal capacitor symbol.This denotes an EDD based component. An alternative convention is to use redlettering within a symbol. The test circuit and simulation results for a nonlinearinductance are shown in Fig. 20. The EDD model is similar to the SPICE 2g6nonlinear inductance model with four coefficients. This number can be increased,if required, by extending the EDD polynomial expression. A gyrator is employedwith the EDD to model the nonlinear inductance. The effect of nonlinear induc-tance on the inductance current is shown by the difference between probe currentsPr1 and Pr2.

33The details of these polynomial functions are presented in Test Reports 4 and 5 of the SPICEto Qucs testing Series, Mike Brinson, http://qucs.sourceforge.net/docs.html.

34SPICE 2g6 allows up to twenty coefficients. Simply add more higher order terms to the Qucspolynomial if required.

32

Page 34: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

V2U=1 V

V1U=Vb R1

R=1k

dc simulation

DC1

ac simulation

AC1Type=logStart=1 HzStop=10kHzPoints=201

Equation

Eqn1Ph_Vout=phase(Vout.v)Vout_dB=dB(Vout.v)

Parametersweep

SW1Sim=AC1Type=linParam=VbStart=1Stop=10Points=10

V

SUB1C0=1uC1=0.5uC2=0.2uC3=0.1u

PIN1

POUT11

D1I1=0Q1=C0*V1+(C1/2)*V1^2+(C2/3)*V1^3+(C3/4)*V1^4

Vout

1 10 100 1e3 1e4

0

0.5

1

acfrequency

Vout.v

1 10 100 1e3 1e4

-80

-60

-40

-20

0

acfrequency

Vout_dB

1 10 100 1e3 1e4

100

150

200

acfrequency

Ph_Vout

Vb12345678910

Vout.V12345678910

Figure 19: Qucs nonlinear capacitor model

33

Page 35: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

V1U=vinf=1 MHz

Pr1

Pr2 L1L=1e-6

transientsimulation

TR1Type=linStart=0Stop=4 us

Parametersweep

SW1Sim=TR1Type=linParam=vinStart=0Stop=100Points=3

dc simulation

DC1

X1R=1

P_inp1

P_inn1

1

D1I1=0Q1=L*V1+(L2/2)*V1^2+(L3/3)*V1^3+(L4/4)*V1^4

IND=L+L2*I(L)+L3*I(L)^2+L4*I(L)^3

SUB1L=1e-6L2=5e-7L3=1e-7L4=5e-8

in

0 5e-7 1e-6 1.5e-6 2e-6 2.5e-6 3e-6 3.5e-6 4e-6

-100

0

100

time

in.Vt

0 5e-7 1e-6 1.5e-6 2e-6 2.5e-6 3e-6 3.5e-6 4e-6

0

2

4

6

time

Pr1.It

0 5e-7 1e-6 1.5e-6 2e-6 2.5e-6 3e-6 3.5e-6 4e-6

0

20

40

time

Pr2.It

Figure 20: Qucs nonlinear inductor model

34

Page 36: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Compact device modelling using EDD

Semiconductor device models are a corner stone of all circuit simulators. Oftenthey are characterised by the same parameters as those found in the SPICE 2g6 and3f5 diode, BJT, FET and MOS models.35. Since the original SPICE semiconductordevice models where first developed many new extensions to these models havebeen proposed. Unfortunately, adding such models to a circuit simulator is acomplex process, being both time consuming and requiring specialised knowledge.For the average Qucs user the hand coded C++ model generation route is onethat they would not contemplate attempting because of the depth of knowledgeand specialised skills required. The Qucs EDD was devised to promote fast, andstraight forward, prototyping of semiconductor compact models, allowing a widerQucs population the opportunity to try their hand at device model construction.To demonstrate the stages needed to generate an EDD model of a semiconductordevice a compact model of a diode is introduced in this section36.

The DC diode current Id is given by the following functions of diode voltage Vd37.

Id = Is · (exp (Vd/(n ·V t)− 1) + Vd ·GMIN, ∀ (−5 ·n ·V t ≤ Vd) (18)

Id = −Is + Vd ·GMIN, ∀ (−BV < Vd) and (Vd < −5 ·n ·V t ≤ Vd) (19)

Id = −IBV, ∀ (Vd = −BV ) (20)

Id = −Is · (exp (−(BV + Vd)/V t)− 1 +BV/V t) , ∀ (Vd < −BV ). (21)

In these equations:

• Is = the saturation current.

• n = the emission coefficient.

• GMIN = a small conductance in parallel with the diode38

35The SPICE 2g6 and 3f5 device parameters are a subset of those commonly provided withcurrent generation of circuit simulators, including Qucs.

36A second three terminal MESFET transistor example is available for downloading from theQucs Web site.

37These 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 byPaolo Antognetti, Giuseppe Massobrio, 1988, McGraw-Hill,Inc, ISBN 0-07-002107-4.

38GMIN is added to help Qucs DC convergence. The SPICE default value is 1e-12S.

35

Page 37: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

• V t = kB ·T/q, where T is the diode temperature in Kelvin, kB is Boltz-mann’s constant and q the charge on the electron.

• BV = reverse breakdown voltage (positive number)

• IBV = reverse breakdown current (positive number).

Figure 21 gives the EDD model for the experimental semiconductor diode. Theternary operator ?: is used to select the correct equation for each diode operatingregion. The diode current Id is the sum of EDD branch currents I1 to I4, whereI1 represents the diode forward bias region, I2 the reverse bias region and I3plus I4 the diode reverse bias breakdown region. When calculating diode currenta special form of the exponential function exp(), called limexp(), is employed toassist Qucs to converge to a solution during DC and transient large signal analysis.The function limexp() linearises the exponential function at large argument valuesminimising the possibility of floating point overflow and generation of softwareexceptions. The Id − Vd characteristic curves shown in Fig. 21 are for the forwardbias region with series resistance rs set to 0.01Ω. For completeness the simulationdata for the Qucs built-in diode are also given. Clearly the two sets of results arevery similar. The DC simulation results for the diode reverse breakdown region ofoperation are shown in Fig. 22. Again for comparison an Id−Vd plot for the Qucsbuilt-in diode is also provided. In this region of operation some slight differencesare apparent: although for both devices the reverse breakdown is very close to100V the slope of the Id− V d curve at negative voltages beyond -BV is different,emphasising that the SPICE diode model does not model breakdown or zenereffects well39.

The next stage in the development of the diode model is to add capacitance effects:depletion layer capacitance for the reverse bias region and diffusion capacitancefor the forward bias region. Diode capacitance is given by:

• Depletion layer capacitance

Cdep =dQdep

dVd= Area ·Cj0

(1− Vd

Vj

)−m

(22)

• Diffusion capacitance

Cdiff =dQdiff

dVd= tt · dId

dVd(23)

39See Steven M. Sandler, SPICE subcircuit accurately models zener characteristics, PersonalEngineering, November 1998, pp 45-48 for more information on this subject.

36

Page 38: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

dc simulation

DC1

Pr1VsU=Vd

Equation

Eqn1Id=Pr1.IId_Q=Pr2.IlnId=ln(Pr1.I)lnId_Q=ln(Pr2.I)

SUB1n=1.0rs=0.01Is=1e-14BV=100.0IBV=1e-3Vj=1.0

Parametersweep

SW1Sim=DC1Type=linParam=VdStart=0Stop=1Points=190

Pr2

D1Is=1e-14 AN=1Vj=1.0Rs=0.01Bv=100.00Ibv=1e-3

PCATHODE1

1234

D2I1=(V1>-5.0*n*Vt) ? Is*(limexp(V1/(n*Vt))-1.0)+V1*GMIN : 0Q1=0I2=(-BV<V1) ? (V1<-5.0*n*Vt) ? -Is+V1*GMIN : 0 : 0Q2=0I3=(V1==-BV) ? -IBV : 0Q3=0I4=(V1<-BV) ? -Is*(limexp(-(BV+V1)/Vt)-1.0+BV/Vt) : 0Q4=0

Equation

Eqn2GMIN=1e-12Vt=vt(300)

RS1R=rs

PANODE1

0 0.2 0.4 0.6 0.8 1-40

-20

0

Vd (V)

ln(Id)

0 0.2 0.4 0.6 0.8 1

0

5

10

Vd (V)

Id (A

)

0 0.2 0.4 0.6 0.8 1

0

5

10

Vd (V)

ID_Q

(A)

0 0.2 0.4 0.6 0.8 1-40

-20

0

Vd (V)

ln(ID

_Q)

Figure 21: Compact diode model DC test circuit and simulation results: SUB1 isthe EDD diode model and D1 the Qucs diode model with the same parameters asSUB1.

37

Page 39: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

-101 -100.5 -100 -99.5

-10

-5

0

Vd (V)

Id (A

)-101 -100.5 -100 -99.5

-50

0

Vd (V)

ID_Q

(A)

Figure 22: Compact diode model DC simulation results for the reverse breakdownregion of operation

Where the total stored charge Qd = Qdep +Qdiff . Using the same notation as theSPICE diode model:

Qdiff = tt · Id (24)

Qdep = Area ·Cj0Vd∫0

(1− Vd

Vj

)−m

dV, ∀ (Vd <= FC ·Vj) (25)

Using integration formula∫

(ax+ b)ndx =1

a

(ax+ b)1+n

1 + nand simplifying yields:

Qdep =Area ·Cj0 ·Vj

1−m

[1−

(1− Vd

Vj

)1−m]

(26)

Also, in the forward bias region

Qdep = Area ·Cj0 ·F1+Area ·Cj0

F2

Vd∫FC ·Vj

(F3 +

m ·VdVj

)dV, ∀ (Vd >= FC ·Vj)

(27)On integrating

Qdep = Area ·Cj0[F1 +

(1

F2

)·F3 · (Vd − FC ·Vj) +

(m

2 ·Vj

)·(V 2d + (FC ·Vj)2

)](28)

Where

F1 =Vj

1−m[1− (1− FC)1−m , F2 = (1− FC)1+m , F3 = 1− FC · (1 +m)

(29)In these equations:

38

Page 40: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

• FC = Coefficient for forward-bias depletion capacitance.

• m = Grading coefficient.

• tt = Transit time.

• Area = Device area.

• Cj0 = Zero-bias junction capacitance.

Figure 23 shows the extended diode model. The Cdep and Cdiff components ofthe device capacitance have been included in the EDD model as stored charge Q1and Q2. Again the ternary operator ?: is employed to select the correct equationfor each section of the diode DC operating range. An equation block is used tosimplify the charge equations through the use of factors F1, F2 and F3.40. An areafactor has also been added to the EDD model in Fig. 23. This is introduced toallow simulation of two or more equivalent parallel devices. The diode variablesscaled 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 resistancecan be determined as a function of diode bias voltage. Firstly, the diode S param-eters are determined at a given bias voltage, secondly these are converted to Yparameters and the diode capacitance (Cap) and resistance (RD) extracted fromY [1, 1], and finally the variation of Cap and RD with diode voltage Vd plottedusing the Qucs plotting function PlotVs. Notice that the value of Cap at Vd = 0Vagrees with the value of Cj0.

To complete the demonstration EDD diode model all that remains to do is to addtemperature dependence to the current and capacitance equations. Circuit simula-tors normally use two temperatures to determine device temperature dependence;the first called Tnom represents the temperature that the device parameters weremeasured, 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 ofparameters Is, V j and Cj0 will be included in the model. Adding extra tempera-ture dependence to the diode model is left to readers as an exercise41. One of the

40In complex current and charge expressions precalculating subexpressions in equation blocksensures that they are only calculated once at the beginning of a simulation, ensuring minimumrun times for an EDD model.

41For example, parameters m and BV are both temperature dependent.

39

Page 41: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Pr1

P1Num=1Z=50 Ohm

X1

Vs1U=Vs

dc simulation

DC1

S parametersimulation

SP1Type=constValues=[100 kHz]

Parametersweep

SW1Sim=SP1Type=linParam=VsStart=-4Stop=0.8Points=200

Equation

Eqn1Y=stoy(S)LN_RD=ln(RD)RD=PlotVs(1/(real(Y[1,1])),Vs)Cap=PlotVs(imag(Y[1,1])/Omega,Vs)Omega=2*pi*frequency

SUB1n=1.0rs=0.01Is=1e-14BV=100.0IBV=1e-3Vj=1.0Cj0=1e-12FC=0.5tt=1e-12Area=1m=0.5

RS1R=rs

PANODE1

PCATHODE1Equation

Eqn2GMIN=1e-12F1=(Vj/(1-m))*(1-(1-FC)^(1-m))F2=(1-FC)^(1+m)F3=1-FC*(1+m)Vt=vt(300)

1234

D1I1=(V1>-5.0*n*Vt) ? Is*(limexp(V1/(n*Vt))-1.0)+V1*GMIN : 0Q1=(V1 < FC*Vj) ? tt*I1+Area*(Cj0*Vj/(1-m))*(1-(1-V1/Vj)^(1-m)) : 0I2=(-BV<V1) ? (V1<-5.0*n*Vt) ? -Is+V1*GMIN : 0 : 0Q2=(V1 >= FC*Vj) ? tt*I1+Area*Cj0*(F1+(1/F2)*(F3*(V1-FC*Vj)+(m/(2*Vj))*(V1*V1-FC*FC*Vj*Vj))) : 0I3=(V1==-BV) ? -IBV : 0Q3=0I4=(V1<-BV) ? -Is*(limexp(-(BV+V1)/Vt)-1.0+BV/Vt) : 0Q4=0

Vd

-4 -3 -2 -1 0 1

0

5e-12

1e-11

Vd (V)

Cap

(F)

-4 -3 -2 -1 0 1

0

5e11

1e12

Vd (V)

Rd (

)

-4 -3 -2 -1 0 1

0

20

VD (V)

LN_R

D

Figure 23: Compact diode model capacitance and resistance simulation

40

Page 42: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

great advantages of the EDD style of modelling is that it is interactive allowingeasy experimentation with models to any given level. The following equations listthe temperature dependence of Is, V j and Cj0.

Let T1 = Tnom and T2 = Temp, then

Is(T2) = Is(T1)

T2

T1

XTIn

exp

[−q ·Eg(300)

kB ·T2

(1− T2

T1

)](31)

V j(T2) =T2

T1·V j(T1)− 2 · kB ·T2

qln

(T2

T1

)1.5

−[T2

T1·Eg(T1)− Eg(T2)

](32)

Cj0(T2) = Cj0(T1)

[1 +m

400 · 10−6 (T2− T1)− V j(T2)− V j(T1)

V j(T1)

](33)

In these equations:

• XTI = Saturation current temperature exponent.

• Eg(T ) = EG(0)− 7.02e− 4 ·T 2

1108 + T, the energy gap.

Figure 24 shows the extended EDD for the experimental diode model. Again thelimexp() function is used in preference to the standard exp() function in the tem-perature calculations listed in equations block Eqn2. The test circuit in Fig. 24sweeps the device temperature from 20 to 80 degrees Centigrade. The graph inlayillustrates the experimental diode current Id plotted as a function of temperature.The temperature of the built-in Qucs diode is held constant, at room tempera-ture, and it’s current Id Q plotted as an overlay. The two curves cross at roomtemperature, indicating identical currents at this temperature.

41

Page 43: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Pr1

Pr2

Equation

Eqn1Id=Pr1.IId_Q=Pr2.IlnId=ln(Pr1.I)lnId_Q=ln(Pr2.I)

VsU=0.6

D1Is=1e-14 AN=1Cj0=1e-12Vj=1.0Rs=0.01Bv=100.00Ibv=1e-3Temp=26.85Xti=3.0Eg=1.11Tnom=26.85Area=1

dc simulation

DC1

Parametersweep

SW2Sim=DC1Type=linParam=Temp_swStart=-20Stop=80Points=100

SUB1n=1.0rs=0.01Is=1e-14BV=100.0IBV=1e-3Vj=1.0Cj0=1e-12m=0.5Area=1FC=0.5tt=1e-12XTI=3.0Tnom=26.85Temp=Temp_swEg=1.16

Equation

Eqn2Cj0_T2=Cj0*(1+m*(400e-6*(T2-T1)-(Vj_T2-Vj)/Vj))rs_AREA=rs/AREAGMIN=1e-12A=7.02e-4B=1108T1=Tnom+273.15Vj_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

Equation

Eqn3F1=(Vj/(1-m))*(1-(1-FC)^(1-m))F2=(1-FC)^(1+m)F3=1-FC*(1+m)Vt=vt(300)

PCATHODE1

PANODE1

RS1R=rs_AREA

1234

D2I1=(V1>-5.0*n*Vt) ? Area*Is_T2*(limexp(V1/(n*Vt))-1.0)+V1*GMIN : 0Q1=(V1 < FC*Vj) ? tt*I1+Area*(Cj0_T2*Vj_T2/(1-m))*(1-(1-V1/Vj_T2)^(1-m)) : 0I2=(-BV<V1) ? (V1<-5.0*n*Vt) ? -Area*Is_T2+V1*GMIN : 0 : 0Q2=(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))) : 0I3=(V1==-BV) ? -IBV : 0Q3=0I4=(V1<-BV) ? -Area*Is_T2*(limexp(-(BV+V1)/Vt)-1.0+BV/Vt) : 0Q4=0

-20 0 20 40 60 801e-8

1e-7

1e-6

1e-5

1e-4

1e-3

0.01

0.1

Temp (Centigrade)

IdId_Q

Figure 24: Compact diode model with temperature dependence

42

Page 44: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Constructing EDD compact device models and

circuit macromodels

Component equations, subcircuits with parameters and EDD models are majordevelopments for the Qucs circuit simulator. They provide advanced modellingcapabilities with enough power and flexibility to allow a much greater range ofmodels to be developed than the ones currently provided with each Qucs release.In the future it is proposed to add new models to the Qucs Web site. The Qucsteam is very keen to encourage all Qucs users to support the modelling effort. Ifyou have constructed a new model and would like to share it with other Qucsusers please post your model on the qucs-devel or qucs-help mailing lists. Boththe model schematic file and a brief outline of its operation and specification arerequested. An example model specification for the Curtice MESFET device canbe found on the Qucs Web site. Please use the same format when writing modeldescriptions.

End Note

This tutorial note introduces a large number of new modelling concepts and showshow equations, subcircuits with parameters and the new equation defined deviceperform a central role in constructing Qucs models. The EDD approach to mod-elling makes possible, for the first time, the construction of equation defined com-pact device models and circuit macromodels using the Qucs schematic capturefacilities as an interactive modelling medium. This is a major step forward forQucs. Once again these notes are very much a record of work in progress: muchstill remains to be done in the future to improve the modelling capabilities pro-vided by Qucs. A major short term task will be the development of additionalmodels covering as wide a range of applications as possible. If Qucs is to fulfill it’smission to become a truly universal circuit simulator then it must be supportedby models. Some readers will have noticed that these notes include very littleinformation about the ADMS-Verlog-A and hand coded C++ model developmentroutes. This was a deliberate decision on my part. Sometime in the future I intendto return to these subjects and update the tutorial. A very special thank you mustgo to Stefan Jahn for all his hard work, skill, and dedication during the period hehas worked on programming the amazing modelling capabilities now embedded inQucs.

43

Page 45: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Appendix A: Qucs constants, operators and func-

tions

This appendix lists the constants, operators and a number of functions that areavailable for constructing Qucs equations. Items in [...] indicate the equivalentobject in the Verilog-A language. The functions listed are common to Qucs andVerilog-A. A number of other functions have been implemented in Qucs. Thefull list can be found in the Qucs help system; ”Short Description of mathematicalFunctions”or in the Qucs ”Measurement Expression Reference Manual“ by GuntherKraut and Stefan Jahn, http://qucs.sourceforge.net/docs.html.

• Constants

1. pi = 3.141593...

2. e = 2.718282...

3. kB = 1.380651e-23 J/K

4. -q = -1.602177e-19 C

• Operators

1. +x unary plus

2. -x unary minus

3. x+y addition

4. x-y subtraction

5. x*y multiplication

6. x/y division

7. x%y modulo (remainder)

8. x^y power [pow(x,y)]

9. ?: ternary (condition) ? (expression if true) : (expression if false)

10. || logical or

11. && logical and

12. == equal

13. < less than

14. <= less than or equal to

15. > greater than

16. >= greater than or equal to

17. != not equal to

18. ( ) brackets

44

Page 46: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

• Functions

1. ln(x) natural logarithm

2. log10(x) decimal logarithm [log(x)]

3. exp(x) exponential function base e

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 [asin(x)]

12. arccos(x) inverse cosine [acos(x)]

13. arctan(x[,y]) inverse tangent [atan2(x,y)]

14. sinh(x) hyperbolic sine

15. cosh(x) hyperbolic cosine

16. tanh(x) hyperbolic tangent

17. arsinh(x) inverse hyperbolic sine [asinh(x)]

18. arcosh(x) inverse hyperbolic cosine [acosh(x)]

19. artanh(x0 inverse hyperbolic tangent [atanh(x)]

20. limexp(x) argument limited exponential function

21. hypot(x,y) Euclidean distance function

45

Page 47: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Appendix B: Constructing subcircuits with pa-

rameters

In this appendix a series of screen dumps illustrate the sequence needed to con-struct a subcircuit with parameters. A simple series resonance circuit has beenchosen for the demonstration.

Enter the series resonance circuit and add input and outputpins

Figure 25: Stage 1: screen dump showing LCR circuit

46

Page 48: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Change the component names to Ls, Cs and Rs

Figure 26: Stage 2: screen dump showing LRC circuit

Figure 27: Stage 2: screen dump after name changes

47

Page 49: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Construct symbol for new subcircuit

Right click on the Qucs drawing area and select Edit Circuit symbol or press keyF9. Edit the drawing symbol to give the design shown in Fig. 28.

Figure 28: Stage 3: the subcircuit symbol

48

Page 50: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Add the names of the subcircuit parameters to the LCRsymbol

Right click on the SUB / File=name caption and enter names of subcircuit pa-rameters with their default values.

Figure 29: Stage 4: entering subcircuit parameter names and default values

Figure 30: Stage 4: resulting subcircuit and parameter list with default values

49

Page 51: Qucs - A Tutorial · 2018. 4. 30. · Qucs releases up to 0.0.10 relied on macromodelling for functional model development via the Qucs schematic interface. This route remains popular

Test the LCR subcircuit

Figure 31 gives a simple AC transfer function test circuit and resulting waveforms.Parameter R SW is swept over the range 1Ω to 10Ω and the AC transfer functionrecorded and plotted.

V1U=1 V

dc simulation

DC1

I OLCR

SUB1Rs=R_SWCs=1uLs=1m

Parametersweep

SW1Sim=AC1Type=linParam=R_SWStart=1Stop=10Points=10

ac simulation

AC1Type=logStart=100 HzStop=100kHzPoints=100Equation

Eqn1gain=dB(Vout.v)phase=phase(Vout.v)

Vin Vout

100 1e3 1e4 1e5

-100

0

100

acfrequency

phase

100 1e3 1e4 1e5

0

0.5

1

acfrequency

Vout.v

100 1e3 1e4 1e5

-50

0

acfrequency

gain

Figure 31: Stage 5: Subcircuit test circuit and output waveforms

50