Xschem cheatsheet
Ming Sun / November 04, 2022
18 min read • ––– views
Most often used bindkeys in Xschem[1]
Hotkeys | Descriptions |
---|---|
m | move |
xschem test.sym | Start Xschem and create a new symbol named test.sym |
xschem test.sch | Start Xschem and create a new schematic named test.sch |
select layer 4 and press l | draw lines |
select layer 4 and press shift-c | draw arcs |
select layer 4 and press ctrl-shift-c | draw circles |
g | decrease grid by 2x |
shift-g | increase grid by 2x |
Alt-p or option-p | place symbol pin |
t | place text |
@name | get instance name |
@symname | get symbol name |
q | get property or attribute |
@#0:pinnumber or @#A:pinnumber | get property or attribute |
shift-A | toggle showing the netlist window |
shift-V | toggle netlist method |
press ctrl select component => then m | stretch |
r | draw rectangles |
ctrl-w | polygons |
a | create symbol |
space while in schematic | pan |
space while in wiring mode | wiring mode toggle |
shift-f | flip |
u | undo |
k | highlight wire |
shift-k | clear all highlighted wire |
5 | only show highlighted wire |
alt-g or option-g | send selector net to waveform viewer |
Commonly used cells
Cell name | Descriptions |
---|---|
lab_pin.sym | pin / port |
ipin.sym | input pins |
opin.sym | output pins |
iopin.sym | I/O pins |
Symbol properties
type=nand
tedax_format="footprint @name @footprint
device @name @device"
template="name=U1 device=CD4011B footprint=\"dip(14)\" numslots=4 power=VCC ground=GND"
extra="power ground"
extra_pinnumber="14 7"
Pin properties
name=A dir=in pinnumber=1:5:8:12
Bus and multiple instances[2]
Syntax | Descriptions |
---|---|
AAA,BBB,CCC | a bundle of 3 signals, AAA, BBB, CCC |
AAA[3:0] | describes the set AAA[3],AAA[2],AAA[1],AAA[0] |
x22[15:0] | describes the set 16 instances of x22 |
Line, arc, circle, polygon properties
fill=true
dash=10
bus=true
Text properties
layer=6
hcenter=true
vcenter=true
weight=bold
slant=oblique
font="Liberation Sans"
Save gm
, id
, vgs
, vds
, vdsat
, cgg
for backannotation
name=NGSPICE
only_toplevel=true
value="
.control
save all
save @m.xm11.msky130_fd_pr__pfet_01v8[gm]
save @m.xm11.msky130_fd_pr__pfet_01v8[id]
save @m.xm11.msky130_fd_pr__pfet_01v8[vgs]
save @m.xm11.msky130_fd_pr__pfet_01v8[cgg]
save @m.xm11.msky130_fd_pr__pfet_01v8[vds]
save @m.xm11.msky130_fd_pr__pfet_01v8[vdsat]
save @m.xm11.msky130_fd_pr__pfet_01v8[vth]
save @m.xm11.msky130_fd_pr__pfet_01v8[gds]
save @m.xm1.msky130_fd_pr__nfet_01v8[gm]
save @m.xm1.msky130_fd_pr__nfet_01v8[id]
save @m.xm1.msky130_fd_pr__nfet_01v8[vgs]
save @m.xm1.msky130_fd_pr__nfet_01v8[vds]
save @m.xm1.msky130_fd_pr__nfet_01v8[cgg]
save @m.xm1.msky130_fd_pr__nfet_01v8[vdsat]
save @m.xm1.msky130_fd_pr__nfet_01v8[vth]
save @m.xm1.msky130_fd_pr__nfet_01v8[gds]
dc Vin 0 1.8 1m
write Sim_inv.raw
set appendwrite
*op
write Sim_inv.raw
.endc
"
Add more proporties in symbol
tcleval(vgs=[to_eng [ngspice::get_node [subst -nocommand {v(\@m.${path}@spiceprefix@name\.msky130_fd_pr__@model\[vgs])}]]], vds=[to_eng [ngspice::get_node [subst -nocommand {v(\@m.${path}@spiceprefix@name\.msky130_fd_pr__@model\[vds])}]]])
tcleval(vdsat=[to_eng [ngspice::get_node [subst -nocommand {v(\@m.${path}@spiceprefix@name\.msky130_fd_pr__@model\[vdsat])}]]] )
tcleval(cgg=[to_eng [ngspice::get_node [subst -nocommand {\@m.${path}@spiceprefix@name\.msky130_fd_pr__@model\[cgg]}]]] )
Derivative to calculate capacitance
Usage: 100e-9 is because that we are sourcing 100nA
current into the cap. g1
is the voltage across the capacitor.
"Varactor cap;100e-9 g1 deriv0() /"
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
"
name=h4
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 dc
"
If you have multiple simulation results in the same file, we can use the following command.
name=h1
descr="Load tran waves"
tclcommand="
xschem raw_read $netlist_dir/[file tail [file rootname [xschem get current_name]]].raw tran
"
name=h17
descr="Load dc waves"
tclcommand="
xschem raw_read $netlist_dir/[file tail [file rootname [xschem get current_name]]].raw dc
"
Append write
Usage: write multiple simulation results into the same file
name=COMMANDS1
simulator=ngspice
only_toplevel=false
value="
.control
save all
dc i1 1p 50u 0.1u
write test_diode.raw
set appendwrite
tran 100p 22n
write test_diode.raw
.endc
"
Calculate BJT beta
Usage: from folder xschem_library/devices
import ngspice_get_expr.sym
symbol. Change its property to the following content:
name=r1
node="[format %.4g [expr {
[ngspice::get_node {i(@q.xq1.qsky130_fd_pr__pnp_05v5_W3p40L3p40[ic])}]
/
[ngspice::get_node {i(@q.xq1.qsky130_fd_pr__pnp_05v5_W3p40L3p40[ib])}]
}]]"
descr="Beta="
Backannotation operating point
Usage: from folder xschem_library/devices
import launcher.sym
symbol. Change its property to the following content:
name=h1
descr="Annotate OP"
tclcommand="set show_hidden_texts 1; xschem annotate_op"
Save BJT Vbe information
Usage: from folder xschem_library/devices
import code_shown.sym
symbol. Change its property to the following content:
name=NGSPICE
only_toplevel=true
value="
.option savecurrents
.control
save all
save @q.xq1.qsky130_fd_pr__pnp_05v5_W3p40L3p40[vbe]
dc i0 5n 100u 0.05u
* plot vc1#branch / vb1#branch
* plot e1
write test_bipolar.raw
set appendwrite
op
write test_bipolar.raw
.endc
"
Save current
Usage: from folder xschem_library/devices
import ammeter.sym
symbol. Put the ammeter
in series with the device whose current you are interested. The current will be saved and you can add it to the plot from waveform graph.
Or you can automatically plot the current as follows by using the code_shown.sym
stimulus.
name=NGSPICE
only_toplevel=true
value="
vp P 0 1.8
vm M 0 0
vb B 0 0
.control
save all
* dc vp 0 3 0.01
dc temp -40 140 1
*plot v(p,m) / vr1#branch
*plot v(p,m) / vr2#branch
*plot v(p,m) / vr3#branch
plot v(p,m) / vr4#branch
plot v(p,m) / vr5#branch
plot v(p,m) / vr6#branch
*plot v(p,m) / vr7#branch
*plot v(p,m) / vr8#branch
plot v(p,m) / vr9#branch
plot v(p,m) / vr10#branch
*plot v(p,m) / vr11#branch
*plot v(p,m) / vr12#branch
plot v(p,m) / vr13#branch
write test_res.raw
.endc
"
Temperature sweep
Usage: from folder xschem_library/devices
import code_shown.sym
symbol. Change its property to the following content:
name=NGSPICE
only_toplevel=true
value="
vp P 0 1.8
vm M 0 0
vb B 0 0
.control
save all
* dc vp 0 3 0.01
dc temp -40 140 1
*plot v(p,m) / vr1#branch
*plot v(p,m) / vr2#branch
*plot v(p,m) / vr3#branch
plot v(p,m) / vr4#branch
plot v(p,m) / vr5#branch
plot v(p,m) / vr6#branch
*plot v(p,m) / vr7#branch
*plot v(p,m) / vr8#branch
plot v(p,m) / vr9#branch
plot v(p,m) / vr10#branch
*plot v(p,m) / vr11#branch
*plot v(p,m) / vr12#branch
plot v(p,m) / vr13#branch
write test_res.raw
.endc
"
Nested DC sweep
dc vd 0 1.8 0.005 vg 0 1.8 0.2
Monte carlo simulation
- Step1: import
corner.sym
fromxschem/sky130_fd_pr
folder. Change its content as follows:
name=CORNER only_toplevel=true corner=tt_mm
- Step 2: import
code_shown.sym
fromxschem_library/devices
folder. Change its content as follows. The below stimulus basically will have a 30 runs of simulation.
For each run, it is going to use the tt_mm
mismatch model and a new temperature as well.
name=stimulus
only_toplevel=false
place=end
value="
.option chgtol=4e-16 method=gear
.param TEMPGAUSS = agauss(40, 30, 1)
.option temp = 'TEMPGAUSS'
.control
option seed = 8
let run = 1
save all
op
write SIM_current_mirror.raw
reset
set appendwrite
dowhile run < = 30
save @m.xm1.msky130_fd_pr__nfet_01v8[gm]
+ @m.xm1.msky130_fd_pr__nfet_01v8[id]
+ @m.xm1.msky130_fd_pr__nfet_01v8[vgs]
+ @m.xm1.msky130_fd_pr__nfet_01v8[cgg]
+ @m.xm1.msky130_fd_pr__nfet_01v8[vds]
+ @m.xm1.msky130_fd_pr__nfet_01v8[vdsat]
+ @m.xm1.msky130_fd_pr__nfet_01v8[vth]
+ @m.xm2.msky130_fd_pr__nfet_01v8[gm]
+ @m.xm2.msky130_fd_pr__nfet_01v8[id]
+ @m.xm2.msky130_fd_pr__nfet_01v8[vgs]
+ @m.xm2.msky130_fd_pr__nfet_01v8[cgg]
+ @m.xm2.msky130_fd_pr__nfet_01v8[vds]
+ @m.xm2.msky130_fd_pr__nfet_01v8[vdsat]
+ @m.xm2.msky130_fd_pr__nfet_01v8[vth]
* save all
tran 1n 1u uic
write SIM_current_mirror.raw
let run = run + 1
reset
end
.endc
"
Netlist and run
Usage: import launcher.sym
from xschem_library/devices
library and change the property as follows:
name=h3
descr="Netlist & sim"
tclcommand="xschem netlist; xschem simulate"
Plot magnitude in db
Usage: in waveform graph, add "Vout db20()"
. This will plot signal Vout
magnitude in dB
format.
Plot phase
Usage: in waveform graph, add ph(Vout)
. This will plot signal Vout
phase.