Upload
others
View
8
Download
2
Embed Size (px)
Citation preview
METU-DEPARTMENT OF ELECTRICAL AND ELECTRONICS ENGINEERING
EE 313 Analog Electronics
Laboratory SPICE & LTSPICE TUTORIAL
November 2010
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 2
A. What is SPICE? SPICE stands for Simulator Program with Integrated Circuit Emphasis. SPICE origin goes to early
1970s and from these times it is a widely used analog simulator for predicting circuit behavior of ICs
(integrated circuits) and board-level designs.
SPICE can be considered as a high-level programming language which has built-in functions
corresponding to electrical elements such as resistors, capacitors, diodes, transistors and voltage
sources. Using these fundamental electrical elements, circuits are constructed in script based
format. This text based circuit is called netlist. SPICE converts this netlist into equations to be
solved.
This tutorial gives information about the most fundamental issues of SPICE and usage of LT Spice
which is a freeware electrical simulator based on Spice.
B. SPICE Syntax In most of today’s simulators, understanding SPICE syntax is not a mandatory. On the other hand
knowing SPICE syntax is an important tool in your simulations. First of all, all of the circuit elements
are defined in SPICE models. Therefore, if you do not have any idea about SPICE syntax, you cannot
know what you simulate. Besides, if you want to change some parameters of your circuit elements,
such as β of a BJT and KN of a NMOS, you need to know phrases corresponding to the parameter
which you want to edit.
In fact, SPICE has a very simple syntax and all you need to know about SPICE syntax does not take
more than 1 hour. You can learn much more about SPICE from the references. Below, passive
components (resistors, capacitors, inductors and diodes), transistors (MOSFET and BJT) and sources
(voltage sources) are going to be mentioned.
Scale Factors:
T(= 1E12 or 10+12); G(= E9); MEG(= E6); K(= E3); M(= E-3); U(= E-6); N(= E-9); P(= E-12), and F(= E-15)
Resistors: RES_NAME N1 N2 RES_VALUE
N1 and N2 are the terminals of a resistor. In SPICE, first node indicates the positive terminal.
!!! Important note: For resistors and other elements, the first parameter is the name of your
element. They must start with a certain character. For resistor RES_NAME must be in such a form:
RXXX.
Example: R1 1 2 1k
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 3
Capacitors: CAP_NAME N1 N2 CAP_VALUE <INITIAL_VALUE>
<…> implies that this part is optional. If you do not write any information about initial condition, the
initial value is set to 0.
Example: C18 15 22 1p 2
Inductors: L_NAME N1 N2 L_VALUE <INITIAL_VALUE>
Example: L5 8 3 1u 1m
Diodes: D_NAME N1 N2 MODEL_NAME
MODEL_NAME is the name of the model which you want to use. Models must be included in your
SPICE netlist. Model of a diode is expressed in SPICE as:
.MODEL MODEL_NAME D (IS=… RS=… N=… CJO=… TT=… VJ=… M=… BV=… IBV=…)
D indicates that the model is a diode. IS: Saturation current (default = 1E-14A) RS: Series Resistance (default = 0Ω) N: The emission coefficient (default = 1) CJO: Junction Capacitance (default = 0F) TT: Transit Time (default = 0 sec) VJ: Junction Potential (default = 1) M: Grading Coefficient (default = 0.5) BV: Reverse Bias Breakdown Voltage (default = infinite) IBV: Reverse Bias Breakdown Current (default = 1E-10A) !!! Important note: If a parameter is not specified in the model default numbers are used. Example: D16 6 7 D1N4007 .MODEL D1N4007 D(IS=2.55E-9 RS=0.042 N=1.75 CJO=1.85E-11 TT=5.76E-6
+ VJ=0.75 M=0.333 BV=1000 IBV=9.86E-5)
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 4
Note that there is a“+” in the model definition of the diode. You can continue SPICE directive in the next line using “+” in SPICE.
MOSFETs: M_NAME ND NG NS NB MODEL_NAME <W=…> <L=…>
ND, NG, NS and NB are the drain, gate, and source and bulk terminals respectively. Width and length
can be specified in element line as shown in the syntax but they are optional.
As in diodes, model of the MOSFET should be defined. .MODEL MODEL_NAME NMOS (LEVEL=… KP=… VTO=… LAMBDA=… GAMMA=… RD=… RS=… CBD=…
CBS=… CGSO=… CGDO=… )
.MODEL MODEL_NAME PMOS (LEVEL=… KP=… VTO=… LAMBDA=… GAMMA=… RD=… RS=… CBD=…
CBS=… CGSO=… CGDO=… )
LEVEL: Indicates type of model used in SPICE. For example, in LEVEL=1, Shichman-Hodges is
used. In your works with discrete components LEVEL=1 is usually enough for you. KP: Transconductance Parameter (μn,pCOX) (default = 2-5A/V2) VTO: Zero-Bias Threshold Voltage (Default = 0V) LAMBDA: Channel-length modulation (Default = 0 V-1) GAMMA: Bulk-threshold parameter (Default = V1/2) RD: Drain Ohmic Resistance (Default = 0Ω) RS: Source Ohmic Resistance (Default = 0Ω) CBD: zero-bias B-D junction capacitance (Default = 0F) CBS: zero-bias B-S junction capacitance (Default = 0F) CGSO: gate-source overlap capacitance width per meter channel width (Default = 0F) CGDO: gate-drain overlap capacitance width per meter channel width (Default = 0F) CGBO: gate-bulk overlap capacitance width per meter channel width (Default = 0F) Example: M1 10 12 18 22 CD4007 W=30u L=10u
.model CD4007 NMOS
+ Level=1 Gamma= 0 Xj=0
+ Tox=1200n Phi=.6 Rs=0 Kp=111u Vto=2.0 Lambda=0.01
+ Rd=0 Cbd=2.0p Cbs=2.0p Pb=.8 Cgso=0.1p
+ Cgdo=0.1p Is=16.64p N=1
!!! Important note: Note that, while in diode model upper case letters are used, in MOS model lower
case letters are used. This will not lead any problem, because SPICE syntax is case-insensitive. In
addition, in CD4007 model, there are some SPICE parameters which are not mentioned above. You
can learn these parameters from the references.
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 5
BJTs: Q_NAME NC NB NE <NS> MODEL_NAME <AREA>
NC, NB and NE are the collector, base and emitter nodes of the BJT. NS (optional) is the substrate
node. Default connection is ground for this terminal. AREA (optional) is the area factor, and its
default value is 1. The model of a BJT is shown below:
.MODEL MODEL_NAME NPN (IS=… BF=… VAF=… BR=… VAR=… RB=… CJE=… VJE=… MJE=…
CJC=… VJC=… MJC=… TF=… TR=…)
.MODEL MODEL_NAME PNP (IS=… BF=… VAF=… BR=… VAR=… RB=… CJE=… VJE=… MJE=…
CJC=… VJC=… MJC=… TF=… TR=…)
IS: Transport Saturation Current (Default = 1E-16 A) BF: Ideal Maximum Forward Beta (Default = 100) VAF: Forward Early Voltage (Default = infinite V) BR: Ideal Maximum Reverse Beta (Default = 1) RB: Zero Bias Base Resistance (Default = 0Ω) CJE: B-E Zero-Bias Depletion Capacitance (Default = 0F) VJE: B-E Built in Potential (Default = 0.75V) MJE: B-E Junction Exponential Factor (Default = 0.33) CJC: B-C Zero-Bias Depletion Capacitance (Default = 0F) VJC: B-C Built in Potential (Default = 0.75V) MJC: B-C Junction Exponential Factor (Default = 0.33) TF: Ideal Forward Transit Time (Default = 0 sec) TR: Ideal Reverse Transit Time (Default = 0 sec) !!! Important Note: In SPICE, modified Gummel-Poon model is used. The one which you are familiar
with is Ebers-Moll model. Therefore, it is not true to insert parameters from SPICE model into your
analysis. BF is a very good example illustrating the difference. In SPICE (Gummel-Poon model), BF
represents ideal maximum forward beta. The β you use in your analysis is a current independent
parameter and you can only obtain this value from simulation; β is not equal to BF. In other words, β
is a parameter which is affected by not only BF but also other SPICE parameters and biasing.
Example: Q3 30 10 19 CA3046 .MODEL CA3046 NPN (IS=10.000E-15 BF=145.76 VAF=100 IKF=46.747E-3
+ ISE=114.23E-15 NE=1.4830 BR=.1001 VAR=100 IKR=10.010E-3 ISC=10.000E-15
+ RC=10 CJE=1.0260E-12 MJE=.33333 CJC=991.79E-15 MJC=.33333 TF=277.09E-12
+ XTF=309.38 VTF=16.364 ITF=1.7597 TR=10.000E-9)
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 6
When some parameters are not specified, Gummel-Poon model simplifies to Ebers-Moll model as in the following example. Example: .MODEL myNPN NPN (IS = 1E-16 BF=100 VAF = 200) Here BF is the β which you use in your analysis.
Sources:
A single source can be used in transient, DC and AC simulations.
Transient Simulation: Transient simulation is a time-domain simulation. In these simulations, it is
possible to use the source as a function generator which can produce sinusoidal, square and
exponential waveforms. Most commonly used waveforms are sinusoidal and square waveforms
whose syntaxes are shown below.
Sinusoidal waveform: V_NAME N1 N2 SIN (OFFSET AMPLITUDE FREQUENCY)
There are also some other features as delay, number of cycles which you can learn from the references. Pulse Waveform: V_NAME N1 N2 PULSE (V1 V2 TDELAY TRISE TFALL TON TPERIOD NCYCLES)
V1 and V2 are the voltage levels of the square waveform. TON is the duration of V2 and TPERIOD is
the period of the waveform. You can set other parameters to 0 for analog applications.
DC and AC Simulation: For DC simulations, only DC voltage is specified. In DC simulations, the
operating points are obtained. In addition, it is possible to perform DC sweep.
Do not forget that AC simulation is a small-signal simulation whatever your AC magnitude is. Since, it
is a small-signal simulation, it needs operating points therefore simulator performs DC simulation
before AC simulation according to the DC value of the sources. Because of the necessity of DC
simulation, DC voltage must be specified in AC simulations (if not, DC voltage is set to 0V).
Only DC simulation: V_NAME N1 N2 VDC AC simulation: V_NAME N1 N2 VDC AC VACMAG VACPHASE If you want the source have an internal resistance, you can add Rser = … after the above scripts.
V_NAME N1 N2 VDC Rser = 10
Remarks:
1. Do not forget the element names (not model names) must start with certain character.
Resistors: RXXX
Capacitors: CXXX Inductors: LXXX
Diodes: DXXX
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 7
BJTs: QXXX
MOSFETs: MXXX
Voltage Sources: VXXX
2. Be aware that definition of the SPICE elements may base on a different model which you are
not familiar with.
3. AC simulation is a small-signal simulation. Whatever the magnitude of the sources is, this
simulation performs small-signal analysis. In frequency response simulation, AC magnitude is
set to 1 and AC phase is set to 0.
C. LTSPICE LTSpice is a freeware SPICE simulator distributed by Linear Technology. It is simple to use and
reliable for your simulations. In addition, using this program will help you to gain insight about SPICE
and its basics. You can download LTSpice from the following web page.
http://www.linear.com/designtools/software/ltspice.jsp
In this part, we will construct a common emitter amplifier using CA3046 model and make transient,
AC and DC simulations. Each step will be explained in this chapter.
1. Open LTSpice. Select File→New Schematic
2. The schematic editor is same as the ones which you are familiar with. You can insert the
components, connect them, label the nets (wires) and copy/move/delete the items from the Edit
menu or toolbox shown in Figure 1. As you will see in Edit menu, all the operations mentioned
above have hot keys.
3. It is possible to customize the schematic editor from Tools menu. You can change the
appearance settings from the Color Preferences and hot keys from Control Panel.
4. Click Edit→Component (or press F2). Select ‘npn’ from the opened window. Insert NPN
transistor in the schematic. Similarly, insert resistors (press ‘R’) and capacitors (press ‘C’) from
Edit menu. Put also voltage sources from Edit→Component and select ‘voltage’. In this way,
insert all the components shown in Figure 3.
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 8
Figure 1: Inserting components from Edit Menu
5. You can rotate and mirror the components from Edit menu. You can also use hot keys: ctrl+R for
‘rotate’ and ctrl+E for ‘mirror’.
Figure 2: ‘Select Component Symbol’ window
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 9
Figure 3: Elements for CE amplifier
6. Wire the components from Edit→Draw Wire (F3). The final view should be as in Figure 4.
Figure 4: Wired configuration of Figure 3
7. Insert the grounds Edit→Place Ground (‘G’). Use wire naming in the schematics for simplicity.
Same named nets are shorted automatically even if there is no wire between them. In addition,
labeled nets ease understanding simulation results. You can name the nets from Edit→Label Net
(F4). In the opened window, write the name of the net (Figure 5). Final configuration should be
as in Figure 6.
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 10
Figure 5: Net Name Window
8. You can edit the component values by right clicking on the component. If you right click on the
text near the component, you can only edit the parameter which text represents. The transistor
you insert comes from the standard library of LT Spice. In order to use our model, we need to
change the value of the transistor, as well. You can do this by right clicking on the value text of
the transistor (in Figure 4 ‘NPN’ is written on the value text). On the opened window write
‘myNPN’. Edit all component values as in Figure 8.
9. You also need to edit the voltage sources. You can edit them by right clicking on the sources.
Then click on Advanced. You see the panels for Functions, DC values and AC (Figure 7). This
means that for transient simulations, if you need to apply a special waveform you should edit the
Function panel. If you need a DC source, edit the DC panel. If you do not set DC value in DC
panel, offset of the waveform in Functions panel is used for DC simulations. For AC simulations,
edit AC panel. Note that AC source is nothing but a small signal source. Since in most of the
cases we perform AC simulations in order to calculate frequency response, this AC source
magnitude must set to 1, and AC source phase must set to 0. When you plot Vout after AC
simulation, you will get the frequency response (gain and phase).
10. You can insert ‘Spice Directive’ from Edit→SPICE Directive (‘S’). You can write SPICE scripts here.
For example, you can write the model for myNPN as in Figure 8. It is also possible to insert text
files which will not be executed during simulation from Edit→Text (‘T’).
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 11
Figure 6: CE amplifier with grounds and net names
Figure 7: Voltage Source Window
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 12
Figure 8: CE Amplifier with Spice directive and text (Text color is blue and SPICE ignores it)
11. You can also include your models with .inc directive. The text file which includes the models can
be included with this Spice command. All you need to do in schematic is to change the values of
the components as specified in the models. This is illustrated in Figure 9. A text file containing
all the components which you use in EE313 laboratory is given in the website. You can download
this file, and copy to the C:\Program Files\LTC\LTspiceIV\lib\sub directory. With the Spice
directive shown in Figure 10, you can easily simulate your circuits.
Figure 9: Using .inc to include a library
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 13
12. Now, we are ready to simulate our circuit. Before you start the simulation you need to edit
Simulation Info from Simulate→Edit Simulation Cmd. The corresponding window is shown in
Figure 10. Note that our CE amplifier does not operate at DC. Therefore, in transient simulation
we need to wait enough for obtaining steady state response. But this takes significant time. Best
approach in simulation is:
i. Make DC simulation: Observe the operating points. In LT Spice, you can also obtain the
small signal parameters such as gm, rπ, rO, fT. This will be very useful in your works. You
can see these parameters from View→SPICE Error Log (Figure 12). Note that you can
also see SPICE netlist from View→SPICE Netlist.
In order to make the DC simulation, select DC op pnt in Edit Simulation Command
window. After you click on OK, a Spice directive box appears. You should put this box on
your schematic. Then, click Simulate→Run. A window showing the DC signals (voltages
and currents) will appear. This simulation is very fast and you can verify operating points
and small signal parameters of your design (Figure 12-13).
ii. Make AC simulation: AC simulation is also a fast simulation providing the frequency
response of your circuit. Select AC Analysis from the Edit Simulation Command. Select
Decade in Type of Sweep. Enter the Number of points per decade, start and stop
frequencies (Figure 14). Click Simulate→Run. To observe the output voltage, move the
mouse in the node which you want to observe and click on this node. Note that when
you move the mouse on the schematic editor, a probe will appear. When the cursor is
on the component instead of node, the probe shape changes. This means that when you
click, you will obtain the current with the same direction shown of the arrow shown on
the probe.
iii. Make Transient Simulation: After you verify DC and small signal AC operation, you will
make transient simulation. This simulation is useful especially for large signal
performance of your circuit.
Select Transient on Edit Simulation Command. Enter the stop time, time to start saving
data and maximum time step (Figure 16). Stop time should be large enough to observe
steady state response. In some cases, this time may be very large. As a result, saving
data for all the simulation time slows the simulation considerably and consumes a large
disk space. In order to avoid this, specify time to start saving data such that you can
observe the steady state response between time to start saving data and stop time.
Maximum time step is also an important parameter which indicates the worst resolution
in the simulation. This should be much smaller than the period of the fastest signal for a
good resolution.
You may check the check boxes according to your requirements. But, note that for faster
simulation (small settling time) DC voltage sources should not start from 0V. In other
words, you should not check first and last boxes if you want to observe steady state
response. Moreover, before the transient simulation, simulator should find the DC
operating points. You can obtain transient results with the same procedure explained in
(ii).
After you follow the above instructions, your schematic editor should like Figure 11. Note that, only
one spice directive giving information about the simulation starts with dot. Other Spice directives
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 14
start with semi colon. This implies that the former one (starting with dot) is the active simulation
whereas SPICE will ignore the latter ones (starting with semi colon).
Simulation results of the CE amplifier are shown in Figures 12-17. Cursors can be inserted into the
simulation windows by right clicking on the trace name which is available at the top of the simulation
results. You can insert single or delta cursors.
Figure 10: Edit Simulation Command window
Figure 11: Final configuration of the CE amplifier
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 15
Figure 12: .op Simulation: DC currents and voltages
Figure 13: .op Simulation: Small signal parameters (View→SPICE Error Log)
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 16
Figure 14: Simulation Command Window for AC simulation
Figure 15: AC simulation results
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 17
Figure 16: Simulation Command Window for Transient Simulation
Figure 17: Transient Simulation Result
13. Another important simulation type which you will need in EE313 is DC Sweep. From the
Simulation Command window select DC Sweep. Enter the name of the source which you want
to sweep, start-stop values, step size and type of sweep. Figure 19 shows the base current vs.
VCC.
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 18
Figure 18: Simulation Command Window for DC Sweep
Additional Notes:
1. You can follow the same procedure for your Op-amp simulations. Insert the Op-amp symbol
from Edit→Component→Opamps→opamp2. Change the value of this symbol to UA741 (or
the name of the model which you want to use) by right clicking on the ‘opamp’ text. Include
your model as explained above and make your simulations.
2. Help of LTSpice is a powerful tool which you can find most of the things you need.
Figure 19: Simulation Result (base current) for DC Sweep
METU-EEE EE313-Analog Electronics Laboratory
SPICE & LTSPICE Tutorial 19
Conclusion: As electrical engineers, SPICE is one of the most important tools which we should be familiar
with. This tutorial gives the very basics of SPICE and you should read more in order to acquire a
complete insight.
References: 1. http://bwrc.eecs.berkeley.edu/Classes/icbook/SPICE/
2. http://en.wikipedia.org/wiki/SPICE
3. http://www.seas.upenn.edu/~jan/spice/spice.overview.html