Ngspice cheatsheet

Ming Sun

Ming Sun / November 04, 2022

4 min read––– views

Operating point

Usage: DC operating point simulation.

name=SPICE only_toplevel=false value="
.op
.save all
"

DC sweep with Xschem and Ngspice

Usage: Sweep Vin from 0V to 1.8V with 1mV per step.

name=SPICE only_toplevel=false value="
.dc Vin 0 1.8 0.001
.save all
"

Transient sim with Xschem and Ngspice

Usage: 1µs transient simulation with 0.01ns step size.

name=SPICE only_toplevel=false value="
.tran 10p 20n
.save all
"

Voltage pulse with Xschem and Ngspice

Usage: 0V~1.8V, 1ns delay time, 1ns rise time, 1ns fall time, 4ns duration, 10ns period.

name=Vin 
value="pulse(0 1.8 1ns 1ns 1ns 4ns 10ns)"

Write simulation result to *.raw file

Usage: write simulation result to *.raw file for waveform viewer.

name=NGSPICE
only_toplevel=true
value="
.control
save all
tran 100p 2u
write SIM_nand2.raw
set appendwrite
.endc
" 

Load/unload simulation data

Usage: right click to load/unload simulation data. Symbol: devices/launcher.sym

name=h1 
descr="Select arrow and 
Ctrl-Left-Click to load/unload
simulation .raw file" 
tclcommand="
xschem raw_read $netlist_dir/[file tail [file rootname [xschem get current_name]]].raw
"

Automatic plot in Ngspice

Usage: automatic plot in Ngspice after the simulation is done.

name=NGSPICE
only_toplevel=true
value="
.control
save all
tran 10n 6u
plot g g2
write test_mim_cap.raw
.endc
" 

PWL (piece wise linear) current

name=I2 value="pwl 0 0 1p 100n"

Simple diode spice model[3]

IS: saturation current VJ: junction potential

.model diode D (IS=1e-12 VJ=0.7)

Simple switch model with hysteresis[4]

Ron: on impedance Roff: off impedance Vt: turn on threshold Vh: hysteresis

.model switch SW(Ron=1m Roff=1G Vt=1.2 Vh=0.2)

References and materials

[1] Ngspice website

[2] Xschem cheatsheet

[3] Diode spice model

[4] Voltage and current controlled switch


HomeWikis
SnippetsAbout
Google ScholarLinkedIn