PME320200
LTSpice & Matlab Tutorial
TA: Shang-Wei Wang, Zhong-Wei Lin
Instructor: Sheng-Shian Li
RF Microsystems Lab
Institute of NanoEngineering and MicroSystems
National Tsing Hua University, Taiwan
Sep. 2020
1
Part1. LTSpice
Sep. 2020
2
Objective
NATIONAL TSING HUA UNIVERSITY
• Understand basic elements for circuit simulation
• Learn the basic usage of circuit simulators
• Know the concepts of device models
3
Circuit simulation background
NATIONAL TSING HUA UNIVERSITY
4
Spice topology
NATIONAL TSING HUA UNIVERSITY
• HSpice as an example
Ref: National Chip Implementation Center, Hsinchu, Taiwan 5
Construct Circuit In Spice
NATIONAL TSING HUA UNIVERSITY
• Take RLC Series Circuit as example
6
Start your program
NATIONAL TSING HUA UNIVERSITY
• Install LTSpice IV
• File → Open → Browse your netlist
– Name your netlist as [Link]
– Ex: [Link]
• What is “netlist”?
– “Netlist" describes the connectivity of an electronic
design
– Interface between user and LTSpice
Comparison with C Language : Command Window
7
Save As .sp File
NATIONAL TSING HUA UNIVERSITY
8
Netlist Commands (simplified)
NATIONAL TSING HUA UNIVERSITY
TITLE First line is input file title
* Asterisk is a command to describe circuit
.LIB / .INCLUDE Cell library of general input files
.OPTIONS Set conditions for simulation
.PARAM Specify parameters
.IC / .NODESET Set initial states
.SUBCKT .ENDS Define subcircuits
.AC / .DC / .TRAN / .TEMP Statement to set sweep variables
.OP Show DC operating points
.MEAS Provide measurement capability
.STEP Sweep variables
.END Required statement to terminate simulation
9
Library input statement
NATIONAL TSING HUA UNIVERSITY
• Syntax
– .lib “filename” entryname
• Entryname is used to define the process corner
(TT, FF, SS…) in foundry CMOS
• No process corners is used in our simple homeworks.
• To use our “Free035.l” library, use the following:
– .lib “Free035.l”
Comparison with C Language : #include<stdio.h> #include<stdlib.h>
“Free035.l” and .sp file have to be saved in the same folder
10
Node naming
NATIONAL TSING HUA UNIVERSITY
• Either characters or numbers (ex: n1, 12, vout1, ….)
• Ground can be 0, gnd, or !gnd
• 0 is always ground
• All nodes are assumed to be local
• “Node Names” can be made across all subcircuits by
a “.GLOBAL” Statement (ex: .GLOBAL VDD VSS )
Suggestion: Name the nodes in a meaningful way
11
Source and Element names
NATIONAL TSING HUA UNIVERSITY
• Keyword + names
• VDD Cfeedback R_01
Element names
Keyword, “V” denotes voltage source
12
Element names and units
NATIONAL TSING HUA UNIVERSITY
All length and widths are in
meters
13
Source Element
NATIONAL TSING HUA UNIVERSITY
n1 vin
– Vxxx n+ n- <voltage>
• Vs n1 n2 dc 3.3
• Vs vin n3 dc 1.3 ac 1
n2 n3
nb2
– Ixxx n+ n- <current>
• Is nb1 nb2 dc 30uA
nb1
14
Passive elements
NATIONAL TSING HUA UNIVERSITY
– Rxx n1 n2 <value>
• Rbias VDD nbias 20k
– Lxx n+ n- <inductance>
• Ltune n1 n2 19u
– Cxx n+ n <capacitance>
• Cdec Vinx vss 20n
15
Transistor
NATIONAL TSING HUA UNIVERSITY
– Qxx C B E <model>
– .model BJTNAME NPN (BF=200 CJC=20pf CJE=20pf IS=1E-16)
• Q1 vdd 2 vss BJTNAME
– Mxx D G S B <model> [L=<len>] [W=<width>] [M=<fingers>]
– In this course, model NM for NMOS, PM for PMOS
• M26 n1 n3 n2 0 NM L=0.35u W=10u m=4
16
Analysis type
NATIONAL TSING HUA UNIVERSITY
• .OP
– DC operation point
• .DC
– Sweep DC parameter
• .AC
– Sweep AC parameter, frequency domain
• .TRAN
– Time domain response
17
.DC Analysis
NATIONAL TSING HUA UNIVERSITY
• Syntax
– .dc <srcnam> <Vstart> <Vstop> <Vincr>
+ [<srcnam2> <Vstart2> <Vstop2> <Vincr2>]
• .dc VDD 0 3.3 0.1
Major variable (x-axis)
18
.AC analysis
NATIONAL TSING HUA UNIVERSITY
• Syntax
– .ac <oct, dec, lin> <Nsteps> <StartFreq> <EndFreq>
– Oct = no. of steps per octave
– Dec = no. of steps per decade
– Lin = Total number of linearly spaced steps between
StartFreq and EndFreq
• Example
– .ac dec 10 100k 10G
19
.Tran Analysis
NATIONAL TSING HUA UNIVERSITY
• Syntax
– .TRAN <Tstep> <Tstop> [Tstart [dTmax]] [modifiers]
• Example
– .tran 0.1n 20u
20
Example
NATIONAL TSING HUA UNIVERSITY
• Common-source Amplifier, AC and DC simulation
• Nodes: VDD, Vin, Vout
• Assume W=5u, L=0.5u, m=4 for M1
• Assume RD=1.0kΩ, and CL=1.0pF
21
Example for .AC simulation
NATIONAL TSING HUA UNIVERSITY
Comparison with C Language : Function
22
Example for .AC simulation
NATIONAL TSING HUA UNIVERSITY
23
Output control
NATIONAL TSING HUA UNIVERSITY
• After simulation (left click “Run” at the toolbar) you
can see a black window
• Right click the black window, you can see:
列出所有能
觀察的資料
加入新的曲線
刪除曲線
在視窗中分隔出
子視窗
在圖中加入網格
在曲線上標出格點
24
Output control
NATIONAL TSING HUA UNIVERSITY
• Select “Add trace”, you can see:
• Select “V(Vout)” and OK, you can get frequency
response.
25
V(Vout)
NATIONAL TSING HUA UNIVERSITY
26
Check Spice Error Log
NATIONAL TSING HUA UNIVERSITY
• View -> Spice Error Log
27
Check Spice Error Log
NATIONAL TSING HUA UNIVERSITY
• Tools -> Color Preferences -> Selected items : Background
• Tune 3 color to maximum
28
Example for .DC simulation
NATIONAL TSING HUA UNIVERSITY
29
Part2. Matlab
Sep. 2020
30
Objective
NATIONAL TSING HUA UNIVERSITY
• Understand some basic functions of Matlab
31
Naming Rules
NATIONAL TSING HUA UNIVERSITY
32
Basic Math Functions
NATIONAL TSING HUA UNIVERSITY
33
Scalar
NATIONAL TSING HUA UNIVERSITY
• Understand some basic functions of Matlab
34
Vector
NATIONAL TSING HUA UNIVERSITY
35
Plot
NATIONAL TSING HUA UNIVERSITY
36
Plot
NATIONAL TSING HUA UNIVERSITY
37
If & For
NATIONAL TSING HUA UNIVERSITY
38
THANK YOU
39