spice using ltspice dr. aslan texas state university

29
SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

Upload: gina-jacklin

Post on 14-Dec-2015

222 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SPICE USING LTSPICEDR. ASLAN

TEXAS STATE UNIVERSITY

Page 2: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

OUTLINE

• Introduction to SPICE

• DC Analysis

• Transient Analysis

• AC Analysis

• Subcircuits

• Optimization

• Power Measurement

Page 3: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

INTRODUCTION TO SPICE

•Simulation Program with Integrated Circuit Emphasis

• Developed in 1970’s at Berkeley

• Many commercial versions are available

• HSPICE is a robust industry standard

• Has many enhancements that we will use

•Written in FORTRAN for punch-card machines

• Circuits elements are called cards

• Complete description is called a SPICE deck

Page 4: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

WRITING SPICE DECKS

•Writing a SPICE deck is like writing a good program• Plan: sketch schematic on paper or in editor

• Modify existing decks whenever possible

• Code: strive for clarity

• Start with name, email, date, purpose

• Generously comment

• Test:• Predict what results should be

• Compare with actual

• Garbage In, Garbage Out!

Page 5: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SOME FACTS AND RULES ABOUT SPICE

• Spice is not case sensitive.  Rsource and RsOuRcE and RSOURCE are equivelent.

• All element names must be unique.  You can't have two capacitors that both are named “C1”.

• The first line in the data file is used as a title.  Spice will ignore this line as circuit data. Put your name and title.

• There must be a node designated "0" (Zero). This is the reference node against which all voltages are calculated.

• Each node must have at least two elements attached to it.

• The last line in any data file must be ".END"  (a period followed by the word "end.")

• All lines that are not blank (except for the title line) must have a character in column 1, the leftmost position on the line.

• Use "*" (an asterisk) in column 1 in order to create a comment line.

• Use "+" (plus sign) in column 1 in order to continue the previous line (for better readability of very long lines).

• Use "." (period) in column 1 followed by the rest of the "dot command" to pass special instructions to the program.

• Use the designated letter for a part in column 1 followed by the rest of the name for that part (no spaces in the part name).

• Use "whitespace" (spaces or tabs) to separate data fields on a line.

• Use ";" (semicolon) to terminate data on a line if you wish to add commentary information on that same line.

Page 6: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SPICE ELEMENTSLetter ElementR Resistor

C Capacitor

L Inductor

K Mutual Inductor

V Independent voltage source

I Independent current source

M MOSFET

D Diode

Q Bipolar transistor

W Lossy transmission line

X Subcircuit

E Voltage-controlled voltage source

G Voltage-controlled current source

H Current-controlled voltage source

F Current-controlled current source

Page 7: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

UNITSLetter Unit Magnitude

a atto 10-18

f fempto 10-15

p pico 10-12

n nano 10-9

u micro 10-6

m mili 10-3

k kilo 103

x mega 106

g giga 109

Ex: 100 femptofarad capacitor = 100fF, 100f, 100e-15

Page 8: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SOURCES - DC

<source name> <positive node> <negative node> <source model>

• DC SourceVname N1 N2 Type Value

Iname N1 N2 Type Value

Vs 1 0 DC 20V

Is 0 4 DC 50MA

Va    4     2      DC     16.0V ; "V" after "16.0" is optionalvs    qe    qc dc     24m   ; "QE" is +node & "qc" is -nodeVWX   23    14 18k   ; "dc" not really neededvwx   14    23     DC   -1.8E4 ; same as aboveVdep  15    27     DC    0V     ; V-source used as ammeter

Page 9: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SOURCES - AC

• DC SourceVname n+ n- Type Value Phase (Deg)

Iname n+ n- Type Value Phase (Deg)

Vac   4   1    AC   120V    30Vba   2   5    AC   240               ; phase angle 0 degreesIx    3   6    AC   10.0A  -45        ; phase angle -45 degreesIsv  12   9    AC   25mA              ; 25 milliamps @ 0 degrees

Page 10: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SOURCES – DEPENDENT

• Voltage controlled voltage source:

Ename n+ n- nc+ nc- Voltage Gain ValueEbar 17 8 42 18 24.0; gain is 24

efix 3 1 0 11 -20.0; same as above

Ellen 12 0 20 41 16.0

• Voltage controlled current source:

Gname n+ n- nc+ nc- ValueGlab  23   17     8     3    2.5G1    12    9     1     0    4E-2Grad  19   40     6    99    0.65Grad  19   40    99     6   -0.65 ; same as aboveGrad  40   19    99     6    0.65 ; etc.

Page 11: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SOURCES – DEPENDENT (CONT.)• Current controlled voltage source:

Hname N1 N2 Vcontrol Value

Hvx  20  12  Vhx       50.0Vhx  80  76  DC        0V ; controls Hvx

Hab  10   0  V20       75.0V20  15   5  DC        0V ; controls Hab

HAL  20  99  Vuse      10.0Vuse  3   5  DC       20V ; actual voltage source

• Current controlled current source:

Fname N1 N2 Vcontrol Value

Ftrn   81   19   Vctl         50.0Vclt   23   12   DC           0V ; controls Ftrn

Fcur   63   48   Vx           20.0Vx     33   71   DC           0V ; controls Fcur

F3      2    0   V1           15.0V1      3    1   DC           0V ; controls F3

Page 12: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SOURCES – PULSE

Vname n+ n- Pulse(V1 V2 Td Tr Tf Tw Period)V1 : Initial voltage

V2 : Peak voltage

Td : Initial delay time

Tr : Rise time;

Tf : Fall time;

Tw : Pulse width

Period : Period.

Vs 1 0 Pulse(0V 10V 0 0.1 0.1 0.9 2)

Vs 1 0 Pulse(0V 10V 0s 100ms 100ms 900ms 2s)

Vs 1 0 Pulse(0 10 0 100m 100m 900m 2)

Page 13: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SOURCES – SINUSOIDAL

Vname n+ n- Sin(Vo Va fr Td Theta phase)

 Vname = Vo + Va e[-Theta.(t - Td)] sin[2pi.fr (t - Td) + (Phase/360)]

Vo : Offset voltage in volt.

Va : Amplitude in volt.

fr : The frequency in Hz.

Td : Delay in seconds

Theta : Damping factor per second

Phase : Phase in degrees

Vs 1 0 SIN(2V 5V 2Hz 200ms 2Hz 30d)

VG 1 2 SIN(5 10 50 0.2 0.1)

VG2 3 4 SIN(0 10 50)

Page 14: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SOURCES – PIECEWISE LINEAR SOURCE

Vname n+ n- PWL(T1 V1 T2 V2 T3 V3 ...) 

T1 : Time for the first point

V1 : Voltage for the first point

T2 : Time for the second point

V2 : Voltage for the second point

Vgpwl 1 2 PWL(0 0 10U 5 100U 5 110U 0)

Page 15: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

CIRCUIT ANALYSIS - .OP

• .OP (Operating Point Analysis)Example_OP.CIRVs   1   0   DC   20.0V ; note the node placementsRa   1   2   5.0kRb   2   0   4.0kRc   3   0   1.0kIs   3   2   DC   2.0mA ; note the node placements.OP

.END

If you need some values use

.PRINT DC V(3,2) I(Ra)

Page 16: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

CIRCUIT ANALYSIS - .TRAN

• .TRAN Transient Analysis *      prt_stp  t_max  prt_dly   max_stp.TRAN  20us     20ms   8ms       10us     UIC

1. The following example performs and prints the transient analysis every 1 ns for 100 ns.

.TRAN 1NS 100NS

2. The following example performs the calculation every 10 ns for 1 µs; the initial DC operating point calculation is bypassed, and the nodal voltages specified in the .IC statement (or by IC parameters in element statements) are used to calculate initial conditions.

.TRAN 10NS 1US UIC

Page 17: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

CIRCUIT ANALYSIS - .TRAN

Example_TRAN.cirRp   0   1   1.0Lp   1   0   8mH   IC=20ACp   1   0   10mF  IC=0V.TRAN 500us 100ms 0s 500us UIC.PROBE.END

Page 18: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

DATA TRANSFER TO MATLAB

Assume I have the previous circuit Example_TRAN.cir. After you run Simulate now you can import your data to MATLAB for further analysis. In LTSpice go to

File → Export

Now you can open your MATLAB and relocate MATLAB directory where you saved “Example_ TRAN.txt” file.

Highlight the data values(Transient analysis time will be added)

Change the file name. Keep the extension (mace it .xls if you want to open in excel)

Page 19: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

DATA TRANSFER TO MATLAB (CONT.)

Now you can open your MATLAB and relocate MATLAB directory where you saved “Example_ TRAN.txt” file. In MATLAB command window type

>> load Example_TRAN.txt

will create and error. This is due to forst line of the txt file.

MATLAB cannot read that first line as data. Delete that line and save your file. Do not forget the order of the columns. (1st Column is time, 2nd I(Cp) and 3rd one is I(Lp))

>> load Example_TRAN.txt

In workspace of MATLAB you will see the loaded data. It hae 202 rows and 3 columns. Next step we will save the data as time, I(Cp) and I(Lp).

Txt file

xls file

Page 20: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

DATA TRANSFER TO MATLAB (CONT.)

In workspace of MATLAB you will see the loaded data. It hae 202 rows and 3 columns. Next step we will save the data as time, I(Cp) and I(Lp).

>> t=Example_TRAN(:,1); %This will save t as time variable

>> I_Cp=Example_TRAN(:,2); %This will save I_Cp as time I(Cp)

>> I_Lp=Example_TRAN(:,3); %This will save I_Lp as time I(Lp)

Your work place shoul look like this

Now we can plot these

>> >> plot (t, I_Cp, t,I_Lp)

Page 21: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

CIRCUIT ANALYSIS - .AC

*     type #points  start stop.AC  LIN  1 60Hz  60Hz;  <== what we want now..AC  LIN  11 100  200;    <== a linear range sweep.AC  DEC  20  1Hz  10kHz; <== a logarithmic range sweep

.PRINT AC VM(30,9) VP(30,9); magnitude & angle of voltage

.PRINT AC IR(Rx) II(Rx); real & imag. parts Rx current

.PRINT AC VM(17) VP(17) VR(17) VI(17); the whole works on node 17

Page 22: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

CIRCUIT ANALYSIS - .ACExample_AC.cirVs 1 0 AC 120V 0Rg 1 2 0.5Lg 2 3 3.183mHRm 3 4 16.0Lm 4 0 31.83mHCx 3 0 132.8uF.AC LIN 1 60 60.PRINT AC VM(3) VP(3) IM(Rm) IP(Rm) IM(Cx) IP(Cx).END

Page 23: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

CIRCUIT ANALYSIS - .ACFirst-order low-pass RC filterVin 1  0 AC 1.0VRf  1  2 1.59Cf  2  0 100uF.AC DEC 20 100Hz 100kHz.PROBE.END

Second-Order High-Pass Filter Vin 1 0 AC 10V Rf 1 2 4.0 CF 2 3 2.0uF Lf 3 0 127uH .AC DEC 20 100Hz 1MEG .PROBE .END

Page 24: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SUBCIRCUITS*       name        nodelist.SUBCKT Example_1   5   12   18Iw   10   12   DC   10ARa    5   12   5.0Rb    5   13   4.0Rc   12   13   2.0Rd    5   18   8.0Re   13   18   3.0Rf   10   13   1.0Rg   10   18   6.0.ENDS

Subcircuit Example No. 1*       name        nodelist.SUBCKT Example_1   5   12   18Iw   10   12   DC   10ARa    5   12   2.0Rb    5   13   5.0Rc   12   13   2.0Rd    5   18   8.0Re   13   18   3.0Rf   10   13   1.0Rg   10   18   6.0.ENDSVs    1    0   DC   50VRa    1    2   1.0  ; different from Ra aboveRb    3    4   3.0  ; different from Rb aboveRc    7    0  25.0  ; different from Rc aboveRd    6    0  45.0  ; different from Rd above*     nodelist      nameX1    2    7    3   Example_1X2    4    6    5   Example_1.END

Page 25: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

SUBCIRCUITS.SUBCKT OpAmp p_in n_in com outEx int com p_in n_in 1e5Ri p_in n_in 500kRo int out 50.0.ENDS

Subcircuit Example No. 2 - Inverting OpAmp.SUBCKT OpAmp p_in n_in com outEx   int   com   p_in   n_in   1e5Ri   p_in  n_in  500kRo   int   out   50.0.ENDSVg   1     0     DC      50mVRg   1     2     5kRf   2     3     50kRL   3     0     20kX1   0     2     0      3    OpAmp.END

Page 26: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

CIRCUIT ANALYSISVoltage Divider CircuitVCC 4 0 DC 12VR1 4 1 10KR2 1 0 RMOD 1.MODEL RMOD RES(R=1).STEP RES RMOD(R) .1k, 15k, 1kRC 4 3 2.7KRE 2 0 1KQ1 3 1 2 Q2N3904Model for 2N3904 NPN BJT (from Eval library in Pspice).model Q2N3904 NPN(Is=6.734f Xti=3 Eg=1.11 Vaf=74.03 Bf=416.4 Ne=1.259+ Ise=6.734f Ikf=66.78m Xtb=1.5 Br=.7371 Nc=2 Isc=0 Ikr=0 Rc=1+ Cjc=3.638p Mjc=.3085 Vjc=.75 Fc=.5 Cje=4.493p Mje=.2593 Vje=.75+ Tr=239.5n Tf=301.2p Itf=.4 Vtf=4 Xtf=2 Rb=10).OP.PRINT DC I(VCC) I(RC).END

Page 27: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

CIRCUIT ANALYSISVoltage Divider CircuitVCC 4 0 DC 12VR1 4 1 10KR2 1 0 RMOD 1.MODEL RMOD RES(R=1).STEP RES RMOD(R) .1k, 15k, 1kRC 4 3 2.7KRE 2 0 1KQ1 3 1 2 Q2N3904.include bjt.lib.OP.PRINT DC I(VCC) I(RC).END

Page 28: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

THEVENIN’S THEOREMThevenin Example No. 1Vs 2 5 DC 100VVc 2 3 DC 0V; controls FxFx 6 7 Vc 4.0; gain = 4* n+ n- NC+ NC gainEx 2 1 5 4 3.0; gain = 3 R1 3 4 5.0R2 4 7 5.0R3 5 4 4.0R4 7 0 4.8R5 5 6 1.0R10 1 0 1MEG; satisfies PSpice* out_var input_source.TF V(1,0) Vs.END

Page 29: SPICE USING LTSPICE DR. ASLAN TEXAS STATE UNIVERSITY

REFERENCES

• http://www.uta.edu/ee/hw/pspice/

• http://cmosedu.com/

• http://www.seas.upenn.edu/~jan/spice/spice.overview.html#Output