gaf/
gaf/gschem-sym/ Where I put the custom gschem symbols I create.
gaf/gschem-sym/transistors/ You can organize your custom symbols into subdirectories.
gaf/pcb-elements/ Where I put the custom PCB file elements I create.
These can also be organized into subdirectories.
gaf/myproject1/ And finally, separate directories for each
gaf/myproject2/ design project.
...
With this organization, any custom gschem symbols and PCB elements you make can be common to all of your projects and this is good enough to get you started. However, I'll mention other possibilities which will be revealed below: There can be project specific PCB **file element** subdirectories or **m4 element** files. Or, CAD administrators can set up site wide custom PCB **file element** directories and **m4 element** files.
* **gEDA setup:** the gschem, gnetlist, and other programs you may use such as gattrib, etc, all need to be able to find any custom symbols you will make, so you need to make your custom gschem symbol directories known to these programs in a gEDA gafrc file by adding **component-library** lines to either a user **${HOME}/.gEDA/gafrc** file or a project specific **gafrc** file in the project directory. There is also a system wide **${GEDADATA}/system-gafrc** file administrators can set up. The **HOME** and **GEDADATA** environment variables must be respectively set for those **gafrc** files to be found. For our directory structure setup above, we could add these lines to **${HOME}/.gEDA/gafrc** (plus lines for each additional **gschem-sym** subdirectory you want): (component-library "${HOME}/gaf/gschem-sym")
(component-library "${HOME}/gaf/gschem-sym/transistors")
or, in each project directory (like myproject1 and myproject2) there could be a **gafrc** file with the lines: (component-library "../gschem-sym")
(component-library "../gschem-sym/transistors")
More modern versions of gEDA (since 1.7.2) let you specify only one command to achieve this: (component-library-search "../gschem-sym")
which will recursively scan all subdirectories for symbol libraries. See the [[geda:gschem_ug:config|gEDA gschem User Guide]] for further information on how to setup gEDA programs.
* If you want a more detailed customization of gschem and gnetlist, you can override other initializations that are setup in the global rc files. In Debian, look at rc files in **/etc/gEDA/** for settings you can make. For example, I like the light gschem background, so I also put in my **~/.gEDA/gschemrc** the line: (load (build-path geda-rc-path "gschem-colormap-lightbg")) ; light background
* **PCB setup: ** A PCB distribution usually is set up so that PCB will automatically look in a **packages** subdirectory of the working directory. So, to make PCB find all the custom elements I put in **gaf/pcb-elements** I make a link in each of my project directories. Note that this link is actually not required when using gsch2pcb because, as described below, you may alternatively specify the **pcb-elements** directory in a **project** file. But if you do want to make the link, in directory **gaf/myproject1** enter the command: ln -s ../pcb-elements packages
* ** gsch2pcb setup: ** In each of your project directories, create a gsch2pcb project file which can be named anything that does not end in //.sch//. A project file will be created in the example below.
This is all the setup you need beyond the initial install of the gschem, gsch2pcb, and PCB packages.
===== Simple Example =====
Let's generate a trivial design from schematics to PCB layout
almost as quickly as possible and then we can use it as a base for
doing some more advanced stuff. I'll complicate it just a bit by
making it a two schematic design.
Assuming you setup the directory structure described
above, go to the **gaf/myproject1** directory and create
a file named **project** with this content:
schematics one.sch two.sch
output-name board
==== Create schematic: one.sch ====
If you are using gschem for the first time, try stepping through
this simple [[geda:gschem_warmup|gschem warmup]].
{{geda:one-sch-1.png |one.sch}} Run **gschem one.sch** and create this schematic (the second opamp is redundant, but this is just a tutorial):
* Open the select components dialog (type $ refdes_renum --pgskip one.sch two.sch
Run gschem on the schematics again to see how the components
have been given a **refdes** attribute. The //--pgksip// option
makes numbering begin at 101 for one.sch and at 201 for two.sch.
But you should know that
running **refdes_renum** is really only useful for an initial
numbering. If you later edit your schematics and add or delete
components, there is no guarantee when rerunning **refdes_renum**
that components will keep an
existing **refdes** value. If in the meantime you've generated
a pc board using gsch2pcb, this reference designator number mixup
will put your schematics out of sync with your PCB layout. So,
after you initially run **refdes_renum** and start a PCB
layout, to be safe you will
need to manually add (unique) **refdes** attributes for any
schematic components you might add. Also note that **refdes_renum** may
number your resistors differently than it did for my examples here
depending on the order in which resistors were added. Keep that in
mind when comparing your eventual PCB layout to what you see in the
images below.
==== Generate PCB Files from Schematics ====
We have to fix one thing in **one.sch** before we can proceed.
Run **gschem one.sch** and notice that **refdes_renum** has
given our opamps **refdes** values of **U101** and **U102**
and did not know we really want to be using two opamps out of a single
TL072 package. That's why we edited the **slot** attribute of the
second opamp. We have to go back and fix this by editing the
**refdes** attribute of the second opamp to be **U101** so
both opamps will have the same **refdes**
and there will be only one TL072 package on our pc board.
Now, since we have already set up a gsch2pcb **project** file,
all we need to do to create an initial set of PCB files is to run
gsch2pcb:
~/gaf/myproject1$ gsch2pcb project
0 file elements and 7 m4 elements added to board.pcb.
Since the project file specified **board** as the output-name,
the PCB files created are named **board.pcb** and **board.net**.
NB: more recent advice is to create an empty board using pcb first; then every use of gsch2pcb will generate changes to that layout as described below ([[#Modifying Schematics]]).
The reason for this is that gsch2pcb's default settings are quite different than pcb's these days,
and the consensus is that pcb's defaults are better for most uses.
One caveat with this is that if you use pcb2panel to combine multiple layouts into a single panelized layout,
you will get unusable results if the boards were created with a mix of gsch2pcb and [recent] pcb defaults
without editing the layer stacks, which may require further work. (mjm, Aug 2008)
If you get output from gsch2pcb like:
//2 unknown elements added to board.pcb.//, then run with the -v
flag: **gsch2pcb -v project** and the gsch2pcb output will tell
you which schematic components don't have a known **footprint**. Either
you forgot to add the attribute, the
attribute value is wrong,
or the PCB element for it is missing from your installation. But if
gsch2pcb can't find any elements and all 7 are unknown, then probably
gsch2pcb can't find your PCB m4 install directory. In this case,
look at the first part of the
[[#Custom M4 Elements]] section.
==== Layout PCB Files ====
=== Set the defaults ===
{{geda:board-1.png |pcb, step 1}}Run **pcb board.pcb**. You'll see grouped into a big pile the PCB elements for all
the schematic component footprints. This is ok, we will clean up this mess later.
When you run PCB on a **.pcb** file for the first time, you should set up various initial values.
I usually set a 25 mil grid spacing with **Screen->Grid Setting->25 mil**
for the bulk of my layout work and then change grid spacing to smaller values as needed
for tight layout situations. Note that if you have enabled millimeter
units with **Screen->Enable millimeter grid units** you will see
a set of millimeter size options to select from instead of mils in the
**Screen->Grid Setting** menu. You may change between millimeter
and mil grid units at any time when doing a layout.
You should also set the default line and via sizes you
want for the Signal, Power, Fat, and Skinny drawing route styles.
Simply select one of these four route styles at the
lower left of the PCB window and then press the **Route Style**
button to edit the sizes. You can set your
board size now or wait until later while working on the layout.
To change the board size, bring up the **File->Preferences**
window and select the **Sizes** page. Other design rule
checking and increment sizes can also be edited in the Preferences
window. You should review PCB documentation for definitions of
these items. And you may find it useful to select **Screen->Enable visible grid**.
=== Disperse the Components ===
{{ geda:board-2.png|step 2}}
Use the middle mouse button to grab and move elements one
at a time until you have separated all the elements.
Or, you can let PCB spread out the elements with
**Select->Disperse all elements** before you fine tune
the positions with the middle mouse button.
=== Load the Netlist ===
{{geda:board-3.png |Step 3}}
* Go to **File->load netlist file** and select **board.net**
* Do **Connects->optimize rats-nest**. Now, the pins and pads of components should be connected with straight lines according to the schematic. These are "rats".
To minimize confusion, PCB tries to draw the rats of complex connections such that the sum of all rats is as short as possible. Try to drag an element to the other side of the working area. The rats will follow like a rubber band, but the end of the rats will not jump to a different node, although the resulting length might be shorter. The action **optimize rats-nest** rats will make the rats jump to this "better" geometry. This action can be applied conveniently anytime with a stroke of the key
changesize(selectedlines, +3, mils)
and the selected lines
will increase by 3 mils. This command is now in a history list
which you can recall and quickly edit in the command window to change
sizes by other values.
=== Look at the other side of the board ===
In some layouts it is important to put components on either side of
the board, although not for the preceding example. In such a case
the elements-dir /usr/lib/newlib
If gsch2pcb does find it, you will get:
~/gaf/myproject1$ gsch2pcb project
board.pcb is backed up as board.pcb.bak1.
1 elements deleted from board.pcb.
1 file elements and 0 m4 elements added to board.new.pcb.
Now you need to run **pcb board.pcb**. You will see that the
element for resistor R101 is gone and that you will get the
new element by loading **board.new.pcb** with
**File->load layout data to paste-buffer**.
===== Custom gschem Symbols =====
A common way to generate a custom symbol is to start with an
existing symbol and modify it. One thing I don't like about
the **dual-opamp-1.sym** we used is that the power pins are
repeated on each symbol. While some will prefer this, I
think it makes a page full of opamps
look a little cluttered and it presents a good opportunity to
learn about **net** attributes in this tutorial.
It's possible with gschem for symbols to
have **net** attributes which can assign pins to a particular
net. Instead of hooking up each opamp pin 8 to Vcc and pin 4 to
Vee on the schematic, we can have that happen automatically and
eliminate the pins on the schematic. To do this, just copy the
original symbol to our custom gschem symbol directory, giving it
a new name, and edit it. Do the steps described below. (Your gEDA symbol install directory may be something
different like **/usr/local/share/gEDA/sym/**):
== Make Attributes Visible ==
{{geda:gschem-sym-1.png |Step 1}}cd /usr/share/gEDA/sym/analog/
cp dual-opamp-1.sym ~/gaf/gschem-sym/opamp-dual.sym
cd ~/gaf/gschem-sym
gschem opamp-dual.sym
* Hit keys ~/gaf/myproject1$ gsch2pcb project
Found a cpinlist head with a netname! [Vcc]
Found a cpinlist head with a netname! [Vee]
Found a cpinlist head with a netname! [Vcc]
Found a cpinlist head with a netname! [Vee]
Found a cpinlist head with a netname! [Vcc]
Found a cpinlist head with a netname! [Vee]
Found a cpinlist head with a netname! [Vcc]
Found a cpinlist head with a netname! [Vee]
No elements to add so not creating board.new.pcb
Where the gEDA gnetlist program
seems a bit "excited" about finding the new
Vcc and Vee **net** attributes we just added, and a new netlist
was generated. Now I think the schematic looks
cleaner. And if you run **pcb board.pcb** and load the new netlist and then
optimize the rats nest, PCB should tell you the board is complete
which means connecting the opamp power pins via the **net**
attribute has worked.
For complete details on making symbols, read through the
[[geda:gschem_symbol_creation|Symbol Creation Document]] on the
[[geda:documentation|gEDA Documentation]] page.
===== Custom file elements =====
You can create custom **file elements**
in the middle of running PCB on any layout or you can run PCB
just for making the element. As a demonstration, lets make a
custom element for a 1N4004 diode. There are axial packages
provided by PCB, but we want to be sure the drill size will be
right for this 1 amp
diode with slightly fatter leads. It needs about a 42 mil (#58) drill.
Run **pcb** and the first thing to do is select the **Signal**
routing style and edit its sizes (press the **Route Style** button)
Set the **Via hole** size
to 42 and the **via size** to 70 or larger as you like.
Select
**Screen->Grid setting->25 mil** and
**Screen->Enable visible grid**.
Zoom in a couple of steps, then make the element:
{{geda:pcb-el-1.png |Step 1}}
* Select the **VIA** tool and place two vias 400 mils apart.
* With the mouse on the left via, hit the
Pin(0 0 70 20 70 42 "" "1" 0x00000001)
to:
Pin(0 0 70 20 70 42 "" "1" 0x00000101)
You can now use **D400-1A** in a gschem schematic symbol
**footprint** attribute and gsch2pcb will find it provided
you have made the **packages** link described in the **Setup**
section. If you have not made that link, you can still tell gsch2pcb
about the elements directory with a line in a project file:
elements-dir ~/gaf/pcb-elements
Possibly you've noticed, but there are some things not right about the
**myproject1** example. For one thing, silk layer lines are
overlapping solder pads on some of the elements, and for another,
the transistor is backwards on the layout!
You otherwise shouldn't have a problem like this when working
with gschem and PCB, but transistor pin numbering can be confusing.
If you will be using transistors in your designs, here's a description
of my approach to
making sure my gschem transistor symbol pin numbering is
coordinated with PCB element pin numbers:
[[gEDA:transistor_guide|transistor guide.]]
From the transistor guide, you can see that the problem here is that
the **TO92** element has its pins numbered
in the less common (3,2,1) configuration while the **2N3904-1.sym**
is like a npn-ebc symbol which needs a (1,2,3) numbering. You can
see the 2N3904 pin numbers in gschem by hitting the m4-pcbdir /path/to/pcb/m4
Just read the **.inc** files in the m4 install directory. For
example, in the **misc.inc** file you will find the **R025** element
we've used and it starts out with:
# -------------------------------------------------------------------
# the definition of a resistor (0.25W) package
# 1ドル: canonical name
# 2ドル: name on PCB
# 3ドル: value
define(`PKG_R025',
`Element(0x00 "1ドル" "2ドル" "3ドル" 120 30 0 100 0x00)
(
...
The information you can extract from this is that a m4 **PKG_** macro
named **R025** is being defined and it takes 3 arguments. Now, all PCB
**m4 element** macros take at least three
arguments and these are automatically
filled in by gsch2pcb with the gschem attributes **footprint** for
**canonical name**, **refdes** for **name on PCB**, and
**value** for **value**. The "canonical name" used in these
m4 files is just an older way of referring to the current PCB usage of
**description** as mentioned above in the **Terminology** section.
Since these args are automatically filled in, you don't need to specify
any additional args to **R025** when you use it as a gschem
**footprint**. But now look at the very next m4 element define
in **misc.inc**:
# -------------------------------------------------------------------
# the definition of a SIL package without a common pin
# 1ドル: canonical name
# 2ドル: name on PCB
# 3ドル: value
# 4ドル: number of pins
define(`PKG_SIL',
`define(`MAXY', `eval(`4ドル' * 100 -50)')
Element(0x00 "1ドル" "2ドル" "3ドル" 160 10 3 100 0x00)
(
...
From this you can determine there is a **SIL** package you can use
as a **footprint**. It has 4 arguments, but only the first three are
handled automatically so there is one argument you must give when using it.
You get a flash of insight and realize this is a "Single In Line" package!
So, instead of the **CONNECTOR 2 1** element specifying 1 column we used
in our example above, you might think we could have used **SIL 2**.
But you would be wrong! Because if you read the macro body you will see
that if the argument is **2** the second forloop can't handle it.
In fact, it will only work for arguments>= 4. If you ever run gsch2pcb
and it appears stuck in an infinite loop, a m4 macro argument problem
is likely the cause. As you look through **misc.inc** here's a summary
of what you will find as possible elements you can use:
Package Args you need to supply
SD 1 number of pins of a ZIP package
MULTIWATT15 0
R025 0
SIL 1 number of pins (we know now must be>= 4)
CSIL 1 number of pins
QFP132 0
LED 1 diameter of LED
DIODE_LAY 1 pin separation
AXIAL_LAY 1 pin separation
CRYSTAL 1 package width
OSC 0
ISA8 0
OVEN_OSC 0
RADIAL_CAN 1
SMD_BASE 2 length and width of surface mount device
SMD_CHIP 1 package length
And so on for the other **.inc** files...
The reality is that the m4 setup is less user friendly (you can't create
the elements graphically) and more complicated (you need to understand
m4 macros) than the simple
**file element** approach. So for most of your custom elements I
suggest you are better off staying with **file elements**. However,
with the m4 macro method a single element
definition that takes arguments gives you a programmable
element which can be very useful for large pin count packages.
It is particularly nice for IC packages with variable widths
and number of pins, so a good example
of using a custom **m4 element** would be to copy and modify to
our taste the existing
m4 macro for IC packages (the **DIL** macro) into a m4 file gsch2pcb
will search. The destination m4 file can be any of these:
* **pcb.inc** in our **myproject1** directory and the custom element will be local to this project.
* **~/.pcb/pcb.inc** and the element will be known to all of our projects.
* **/path/to/anyfile** if this path is made known to gsch2pcb by adding a line to a project file like: m4-file /path/to/anyfile
Depending on whether you want the file known only to this project, to all of your projects, or to all projects of all users, this line may be added to any of the project files:~/gaf/myproject1/project
~/.gsch2pcb
/usr/local/etc/gsch2pcb
/etc/gsch2pcb
For this tutorial, I'll use the first **pcb.inc** way, so copy over
the existing macro file:
cd /usr/local/share/pcb/m4 (or /usr/share/pcb/m4 or /usr/X11R6/lib/X11/pcb/m4)
cp dil.inc ~/gaf/myproject1/pcb.inc
cd ~/gaf/myproject1
Now, edit the **pcb.inc** file you just copied and cut everything
out except for the PKG_DIL macro. Change the name of
the package to something like PKG_DILFAT because the change we'll make
will be to make larger diameter pins. Actually, we could leave the name
alone and our new definition would override the old one, but for now
let's go with the new name. Change the pin diameter from **60**
to **70** on the **PIN** lines.
When done, this should
be the entire contents of the new **pcb.inc** file:
# -------------------------------------------------------------------
# the definition of a dual-inline package N and similar types
# 1ドル: canonical name
# 2ドル: name on PCB
# 3ドル: value
# 4ドル: number of pins
# 5ドル: package size (300, 600, 900 + 100 for socket space)
#
define(`PKG_DILFAT',
`define(`MAXY', `eval(`4ドル' / 2 * 100)')
define(`MAXX', `eval(`5ドル' + 100)')
define(`CENTERX', `eval(MAXX / 2)')
Element(0x00 "1ドル" "2ドル" "3ドル" eval(CENTERX + 20) 100 3 100 0x00)
(
forloop(`i', 1, eval(4ドル / 2),
`PIN(50, eval(i * 100 -50), 70, 28, i)
')
forloop(`i', 1, eval(4ドル / 2),
`PIN(eval(MAXX -50), eval(MAXY - i * 100 +50), 70, 28, eval(i + 4ドル/2))
')
ElementLine(0 0 0 MAXY 10)
ElementLine(0 MAXY MAXX MAXY 10)
ElementLine(MAXX MAXY MAXX 0 10)
ElementLine(0 0 eval(CENTERX - 50) 0 10)
ElementLine(eval(CENTERX + 50) 0 MAXX 0 10)
ElementArc(CENTERX 0 50 50 0 180 10)
Mark(50 50)
)')
Run **gschem one.sch** and edit the **footprint** attribute of
the opamps to be **DILFAT 8 300**.
Then run **gsch2pcb project**
and gsch2pcb will remove the **DIL** element from **board.pcb**
and add into **board.new.pcb** a new **DILFAT** element from your
custom m4 file **pcb.inc**. Run **pcb board.pcb** and
load the **board.new.pcb** into
your layout. Move the new element with its fatter pins to the location
left vacant by the removal of the old element.
===== Multi-user Setup =====
The above examples are oriented towards a single user with projects and
custom gschem and PCB libraries under his home directory. Here's a
way to set up for multiple users who need to share resources:
* Put site wide custom PCB **file elements** under, for example, **/usr/local/share/pcb/pcb-elements**. Make this directory searched by gsch2pcb for all users by putting a line into **/etc/gsch2pcb** or **/usr/local/etc/gsch2pcb**:elements-dir /usr/local/share/pcb/pcb-elements
If there are any site wide custom PCB **m4 element** files, for example, **/usr/local/share/pcb/pcb.inc**, add another line into **/etc/gsch2pcb** or **/usr/local/etc/gsch2pcb**:m4-file /usr/local/share/pcb/pcb.inc
* If the default PCB m4 install is not **/usr/local/share/pcb/m4, /usr/share/pcb/m4,** or **/usr/X11R6/lib/X11/pcb/m4**, then make the install location known to all users of gsch2pcb by putting into **/etc/gsch2pcb** or **/usr/local/etc/gsch2pcb** the line:m4-pcbdir /path/to/pcb/m4
If the m4 program is gm4 instead of m4, add to the gsch2pcb file:m4-command gm4
* If there are site wide custom gschem symbols under some directory, you will have to edit the **system-gafrc** file and add **component-library** lines for them.
With the above, users will have access to site wide libraries
and only need to put in a design **project** file
lines for **schematics** and **output-name**. But they
also are free to have their own additional user and/or project
specific symbol and element libraries.
===== PC Board Fabrication =====
The tutorial should cover pcb fabrication too.
== Photo-lithography ==
Use File->Export layout->ps to make a postscript file suitable for printing
on a transparency. Note the presence of the 'mirror' and 'ps-invert' options
which you may need depending on your process.
Open the ps file and print only the pages that you will actually need for
fabrication. There are a large number of pages here, many of which you may
not need.
If you find that your pads and traces don't print on the same page, or are
placed on the wrong side you need to check the settings under File->Preferences->Layers
to group the layers appropriately and place them on the correct side.
== Machining ==
[[http://www.lpkf.com|LPKF]] (and probably other companies) have a pcb plotting machines that accept gerber files.
These files can be produced by choosing File->Export Layout->gerber which produces a large number of files. The files
can be viewed using [[http://geda.seul.org/tools/gerbv/index.html|gerbv]] and the visualization saved. Once you are satisfied with the output gerber files just
hand them off to whomever controls the pcb plotting machine and wait for the boards to be completed!