Skip to content

Commit 362edc5

Browse files
committed
Add xschem write-up draft
1 parent ce2e9f8 commit 362edc5

File tree

3 files changed

+207
-1
lines changed

3 files changed

+207
-1
lines changed

README.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,5 @@
11
# learn-sky130
2-
Learning to do things with the Skywater 130nm process
2+
Learning to do things with the Skywater 130nm process.
3+
4+
* [Designing and simulating an inverter schematic using xschem and ngspice](schematic/xschem/getting-started.md)
5+

schematic/xschem/getting-started.md

Lines changed: 161 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
# Getting started with xschem with sky130
2+
3+
Let's build an inverter using xscheme in the
4+
[Skywater 130nm process](https://skywater-pdk.readthedocs.io).
5+
6+
## Background
7+
8+
You are working for Inverter-Tech Inc. which specializes in taking
9+
something and doing the opposite. So far the company has made a living
10+
by producing batteries that have their polarities inverted. Sales have been
11+
going down, and they now want to break into the digital era. All the rage
12+
in the year 2020 is digital inverters. Taking a 0 and turning it into a 1 seems
13+
to be what all the kids are talking about.
14+
15+
You have been tasked to use the newly open-source'd process called
16+
[sky130](https://skywater-pdk.readthedocs.io) to design the company's new
17+
crown jewel - the Digital(TM) Inverter(R).
18+
19+
### What is Schematic Capture and why do we need it?
20+
21+
It is the process where you *capture* an idea as a *schematic*. It is a term
22+
used to describe producing a schematic which can be used to describe some
23+
electronic circuit. When simulating the component or later designing the
24+
full chip you will use the output of the schematic to verify that the final
25+
result is what your schematic describes. This output is called a *netlist*.
26+
27+
Alternativly you can also design your component in a
28+
Hardware Description Language (HDL) such as Verilog or VHDL. This can the
29+
be used to automatically produce the netlist. It is a very good way to make
30+
large digital designs, but for analog designs it quickly becomes complicated.
31+
32+
In order to design our inverter, we will have to describe it as an electronic
33+
circuit in some form of schematic editor. Here we will use xschem for this
34+
purpose. We could have described it in HDL as explained earlier, but the goal
35+
of this tutorial is to learn how to manually design an inverter using analog
36+
components.
37+
38+
### What is a process?
39+
40+
A process commonly refers to a fabrication process for which chips are made.
41+
Skywater 130 nm is the name of the process we use here, which is usually
42+
shortened to `sky130`. There are hoards of other processes out there but what
43+
makes sky130 special is that it is open-source and does not require signing of
44+
an non-disclosure agreement (NDA) in order for it to be used.
45+
46+
Every process has so called *primitives* that are the basic building blocks
47+
we can use to define a chip in that process. It is crucial that we use those
48+
blocks and when we simulate that we use *models* that describe how those blocks
49+
work in an environment that is as close to what we will have our chip running in
50+
as possible.
51+
52+
The collection of files needed to use a process is called a Process Design Kit
53+
or *PDK*. In our case the PDK we will use is `sky130_fd_pr` which stands for
54+
Skywater 130nm Foundry Primitives.
55+
56+
## Installation
57+
58+
NOTE: The following assumes Ubuntu 20.04. For other Linux distributions the
59+
steps might differ somewhat. Versions might have been updated since the writing
60+
of this guide and you might need to adopt some steps accordingly. Fixes are
61+
very much welcomed!
62+
63+
The tools we will install are:
64+
65+
* xscheme - The schematic capture tool
66+
* ngspice - The circuit simulator
67+
* gaw - A waveform viewer to view the simulation results
68+
69+
### Installation of ngspice
70+
71+
A decently recent version of ngsice is present in the Ubuntu repository so
72+
installing it as easy as:
73+
74+
```
75+
sudo apt install ngspice
76+
```
77+
78+
### Installation of gaw
79+
80+
Gaw is not packaged for Ubuntu so we will have to build it ourselves.
81+
82+
**TODO**: Write this in a nicer way, this is just a dump right now
83+
84+
```
85+
wget http://download.tuxfamily.org/gaw/download/gaw3-20200922.tar.gz
86+
sudo apt install libgtk-3-dev
87+
make -j$(nproc)
88+
sudo make install
89+
90+
# Important!
91+
# Start gaw once and exit it
92+
gaw
93+
# Now change the rcfile
94+
$EDITOR ~/.gaw/gawrc
95+
# Find up_listenPort = 0 and set it to 2020.
96+
# This is needed for xschem to integrate well with gaw
97+
```
98+
99+
Optional: `gaw examples/rlc_lpf_trans.dat` to figure out how the tool works.
100+
101+
### Installation of xschem
102+
103+
**TODO**: Write this in a nicer way, this is just a dump right now
104+
105+
```
106+
sudo apt build-dep xschem # todo: expand to what is actually needed
107+
sudo apt install xterm graphicsmagick ghostscript
108+
# GraphicsMagick is needed for PNG export, ghostscript for pdf
109+
git clone https://github.com/StefanSchippers/xschem.git
110+
./configure
111+
make -j$(nproc)
112+
sudo make install
113+
```
114+
115+
1) Go into Simulation -> Configure simulators and tools.
116+
1) Make sure "Ngpsice Batch"[1] and Gaw is selected.
117+
**Tip**: I like ngspice batch to be the following which allows you to see the status:
118+
`$terminal -e 'set -o pipefail; (ngspice -b -r "$n.raw" "$N" | tee "$n.out") || (echo -e "\n** ngspice exited with error code $? **\nPress enter to close"; read)'`
119+
1) Keep Fg checked and Status unchecked.
120+
1) Press "Accept and close"
121+
122+
[1] Ngspice batch is needed for the raw-file to be created which Gaw uses to populate its table.
123+
124+
### Installation of sky130 primitives
125+
126+
**TODO**: Describe why we are doing this maybe.
127+
128+
```
129+
cd /usr/local/share/
130+
sudo mkdir sky130_fd_pr
131+
chown $USER sky130_fd_pr
132+
git clone https://foss-eda-tools.googlesource.com/skywater-pdk/libs/sky130_fd_pr sky130_fd_pr
133+
```
134+
135+
## Basics of xschem
136+
137+
These two videos of using xschem are well worth the time. Watch them and follow
138+
along.
139+
140+
* [Editing and Simulation in xschem](https://xschem.sourceforge.io/stefan/xschem_man/video_tutorials/editing_and_sim.mp4)
141+
* [Probing signals with gaw](https://xschem.sourceforge.io/stefan/xschem_man/video_tutorials/probe_to_gaw.mp4)
142+
143+
Congrats! You simulated a schematic using open-source tools!
144+
145+
## Designing an inverter
146+
147+
TODO: Describe the process
148+
149+
**NOTE**: To use the pmos4/nmos4 components, you should use these parameters:
150+
```
151+
model=sky130_fd_pr__pfet_01v8 w=1 l=1 m=1 spiceprefix=X
152+
```
153+
154+
The `spiceprefix=X` is needed because the FET is defined as a so called
155+
subcircuit and will not be correctly located otherwise. If you get
156+
an error like `could not find a valid modelname` you might have forgotten to
157+
add this property.
158+
159+
The final result is available in `inverter.sch`.
160+
If you installed the PDK somewhere else make sure to update the `.lib` statement
161+
in the SPICE component in the lower-right corner.

schematic/xschem/inverter.sch

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
v {xschem version=2.9.8 file_version=1.2}
2+
G {}
3+
K {}
4+
V {}
5+
S {}
6+
E {}
7+
N 150 -600 560 -600 { lab=vcc}
8+
N 150 -340 420 -340 { lab=GND}
9+
N 560 -360 560 -340 { lab=GND}
10+
N 420 -340 560 -340 { lab=GND}
11+
N 560 -550 560 -540 { lab=vcc}
12+
N 560 -510 580 -510 { lab=vcc}
13+
N 560 -600 560 -550 { lab=vcc}
14+
N 560 -460 640 -460 { lab=inv_out}
15+
N 420 -360 420 -340 { lab=GND}
16+
N 420 -460 520 -460 { lab=in}
17+
N 420 -460 420 -420 { lab=in}
18+
N 560 -370 560 -360 { lab=GND}
19+
N 560 -480 560 -460 { lab=inv_out}
20+
N 520 -510 520 -460 { lab=in}
21+
N 520 -460 520 -410 { lab=in}
22+
N 560 -460 560 -440 { lab=inv_out}
23+
N 580 -560 580 -510 { lab=vcc}
24+
N 560 -560 580 -560 { lab=vcc}
25+
N 560 -410 580 -410 { lab=GND}
26+
N 580 -410 580 -360 { lab=GND}
27+
N 560 -360 580 -360 { lab=GND}
28+
N 560 -380 560 -370 { lab=GND}
29+
N 150 -600 150 -490 { lab=vcc}
30+
N 150 -430 150 -340 { lab=GND}
31+
C {vsource.sym} 420 -390 0 1 {name=V.100MHz value="pulse(0 1.8 1ns 1ns 1ns 5ns 10ns)"}
32+
C {code_shown.sym} 680 -170 0 0 {name=SPICE only_toplevel=false value=".lib /usr/local/share/sky130_fd_pr/models/sky130.lib.spice tt
33+
.tran 0.1n 1u
34+
.save all"}
35+
C {lab_pin.sym} 150 -570 0 0 {name=lsupply sig_type=std_logic lab=vcc}
36+
C {title.sym} 170 -50 0 0 {name=l5 author="Christian 'bluecmd' Svensson"}
37+
C {pmos4.sym} 540 -510 0 0 {name=M1 model=sky130_fd_pr__pfet_01v8 w=1 l=1 spiceprefix=X m=1}
38+
C {nmos4.sym} 540 -410 0 0 {name=M2 model=sky130_fd_pr__nfet_01v8 w=1 l=1 spiceprefix=X m=1}
39+
C {gnd.sym} 240 -340 0 0 {name=l1 lab=GND}
40+
C {vsource.sym} 150 -460 0 1 {name=V1.8 value="pwl 0 1.8"}
41+
C {lab_pin.sym} 420 -450 0 0 {name=l3 sig_type=std_logic lab=in}
42+
C {lab_pin.sym} 640 -460 2 0 {name=l4 sig_type=std_logic lab=inv_out}

0 commit comments

Comments
 (0)