Tutorial 1
Tutorial 1
Tutorial - NGSPICE
TAs:
Adithya Sunil Edakkadan
Ishan Acharyya
Circuit description
Models used to describe circuit elements may be included
Type of analysis to be done on the circuit
Control commands to run the simulation and plot/save the results
Note: Commands in NGSPICE are case insensitive
2 / 10
Example to illustrate NGSPICE usage
5.0
.control 3.0
run
plot v(in) v(out) 2.0
time
30.0
us
40.0 50.0 60.0
3 / 10
Example to illustrate DC analysis
MOS IDS -VGS curve
IDS
G D
MN + V
(1.8u/0.18u) − DS
VGS
Netlist to evaluate MOS ID -VGS characteristics S
.include TSMC_180nm.txt
.param SUPPLY=1.8
.param LAMBDA=0.09u uA -vds#branch
PD={10*LAMBDA+2*width_N}
.dc VGS 0 1.8 0.05 400.0
.control
run
plot -VDS#branch 200.0
v-sweep V
4 / 10
Figure: I Vs V
Example to illustrate Transient analysis
Vdd
CMOS Inverter transient analysis
MP
(1.8u/0.18u)
Vin Vout
CMOS inverter transient response x y
.include TSMC_180nm.txt
.param SUPPLY=1.8 MN
.param LAMBDA=0.09u (0.9u/0.18u) 100 fF
.param width_P=20*LAMBDA
.param width_N=10*LAMBDA
.global gnd vdd V v(y) v(x)
AS={5*width_N*LAMBDA} PS={10*LAMBDA+2*width_N}
AD={5*width_N*LAMBDA} PD={10*LAMBDA+2*width_N}
M2 y x vdd vdd CMOSP W={width_P} L={2*LAMBDA} + 1.0
AS={5*width_P*LAMBDA} PS={10*LAMBDA+2*width_P}
AD={5*width_P*LAMBDA} PD={10*LAMBDA+2*width_P}
0.5
run
plot v(y) v(x)
set hcopypscolor = 1 -0.5
0.0 50.0 100.0 150.0 200.0
2.0
M1 y x gnd gnd CMOSN W={width_N} L={2*LAMBDA} +
AS={5*width_N*LAMBDA} PS={10*LAMBDA+2*width_N}
AD={5*width_N*LAMBDA} PD={10*LAMBDA+2*width_N} 1.5
.ends inv
x1 b a vdd gnd inv width_P=20*LAMBDA width_N=10*LAMBDA 0.5
run
plot v(b) v(a) -0.5
0.0 50.0 100.0 150.0 200.0
set hcopypscolor = 1 time ns
To launch NGSPICE
ngspice : It will take you to ngspice shell
ngspice file_name.<cir or sp> : It will execute the specified
net-list
Type quit or exit to end the ngspice shell
To execute a net-list in ngspice shell
ngspice —> source filename
To edit in ngspice shell
ngspice —> edit file_name ; :wq! to save and quit editing
To run an analysis specified in net-list in ngspice shell
ngspice —> run
To plot in ngspice shell
use ‘plot’ command
7 / 10
Quick keys II
To plot voltages
ngspice —> plot v(node_name)
Ex. plot v(out) v(in)
To plot branch currents
plot voltage_source_name#btranch
Ex. plot VDS#branch
– Note that direction of current is entering into the positive
terminal of a voltage source
– If required a dummy 0 V DC source can be inserted in the
net-list to plot branch current
To save plots as ps
hardcopy file_name.eps variables_to_plot
Ex. hardcopy inv_transient_resp.eps v(x) v(y)
To change background colour of saved plot
set hcopypscolor = 1 *White background
8 / 10
Quick keys III
Transient analysis
.tran step_size stop_time < start_time >
Ex: .tran 10n 60u
AC analysis
.ac lin number_of_points start stop
.ac lin 100 1 100Hz
Measure statement example (sec 15.4.5):
.measure tran tpdf
+ TRIG v(1) VAL=’SUPPLY/2’ RISE=1
+ TARG v(2) VAL=’SUPPLY/2’ Fall=1
measures the time difference between v(1) reaching ’SUPPLY/2’ V
for the first time on its first rising slope (TRIG) versus v(2)
reaching ’SUPPLY/2’ V for the first time on its first falling slope
(TARG), i.e. it measures the fall time delay between v(1) and v(2).
Refer NGSPICE manual for more details
10 / 10