|
| 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. |
0 commit comments