1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272
|
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0//EN">
<html>
<head>
<title>gsch2pcb tutorial</title>
</head>
<body background="./images/paper1.gif">
<center><h2>gschem -> gsch2pcb -> PCB</h2></center>
<hr width=100% size=2>
<blockquote>
This is a tutorial on the process of using gsch2pcb as an
interface between gschem and PCB.
It assumes the gEDA, PCB and gsch2pcb packages
are already installed and ready to use. Starting with gEDA 20030901,
gsch2pcb version 0.9 is packaged with gEDA, but some of the steps below
will require gsch2pcb 1.0. This tutorial is functional and intended to
generate results as quickly as possible. It is not a complete reference
on gschem or PCB, but it does show with a simple example design
all the steps one might need to take.
<p>
The goal is to use gsch2pcb as the bridge between gschem and PCB so
that the schematics can always be in sync with the PCB layout
because all element additions or deletions in the layout will
automatically be driven by changes in the schematics.
</blockquote>
<h3> Tutorial Release Notes </h3>
<blockquote>
<ul>
<li>If you have versions less than gschem 20030525 or PCB 1.99 these
tutorial examples may not work as expected.
</li>
<li>If you have gEDA version 20030901 installed such that you are
using its included gsch2pcb 0.9 and you are getting an error:
<blockquote><pre>
ERROR: Unbound variable: open-output-pipe
</pre></blockquote>
then the problem is syntax in <i>gnet-gsch2pcb.scm</i> that worked
in guile 1.4 but does not work in guile 1.6. You'll need to upgrade to
using at least gsch2pcb 1.0.1 to solve this problem.
</li>
<li>As of about 1/9/2004 CVS PCB versions changed to using a hi
resolution output file format which will require using at
least gsch2pcb-1.4.
</li>
<li><h5> Mini Changelog</h5>
<ul>
<li> 1/10/2004 - corrected my sloppy PCB file elements which had
silkscreen lines overlapping solder pads.
</li>
<li> 12/23/2003 - added comments about new CVS PCB versions which
have the m4 and newlib directories default installed under
/usr/share or /usr/local/share.
</li>
</ul>
</li>
</blockquote>
<h3> Terminology </h3>
<blockquote>
With gschem, you add symbols representing electronic components to a
schematic. A symbol is a group of pins, attributes, and lines showing
an iconic representation of an electronic component.
Pins in symbols are connected to other pins by drawing a net
connection between them. Attributes are just named tags attached to
symbols to convey some bit of information. For using the schematic with PCB,
there are three of these attributes which are relevant and must be
specified. Each added symbol should have a <b>footprint, value,</b> and
<b>refdes</b> attribute.
<p>
The schematic <b>footprint</b> attribute value of a symbol is the name of the
PCB element to be placed on the layout for that instance of the symbol.
A PCB element is a group of pins, pads, and silk layer outlines physically
corresponding
to electronic components. It is probably a source of confusion for
newcomers to PCB that elements are of two different types. There are the
original m4 macro generated PCB elements and since PCB version 1.7
there are also the
newlib style file elements. A file element is a single fixed element
in a single file. However, many m4 macro element definitions may exist in a
single m4 element file. The macros can be given arguments to provide
programmable elements of variable number of pins or spacings.
Using these two types will be covered
in this tutorial and I will be referring to
these distinct element types as
<b>m4 elements</b> and <b>file elements</b>.
When rou run PCB, the gschem <b>footprint</b> attribute
value will appear as the displayed element name when you
select <b>description</b> from the <b>Screen</b> menu because gsch2pcb
uses this field to keep track of which <b>footprint</b> corresponds
to a particular PCB element.
<p>
The gschem <b>refdes</b> attribute value is the reference designator
on the schematic such as Q1, U1, R1, etc. When you run PCB, this
refdes will appear as the displayed element name when you select
<b>name on PCB</b> from the <b>Screen</b> menu.
<p>
The gschem <b>value</b> attribute value is the particular component value
such as BC546, 7400, 1K, etc. When you run PCB, this
<b>value</b> will appear as the displayed element name when you select
<b>value</b> from the <b>Screen</b> menu.
</blockquote>
<h3> Setup </h3>
<blockquote>
You should have a directory structure in mind for organizing your
design projects. The install of gEDA
and PCB gives you a set of default gschem symbols and
default PCB elements, but you can also provide for creating your own custom
libraries of gschem symbols and PCB elements.
<ul>
<li> Somewhere, probably under your home directory, create your
directory structure. Use directory names you like, but
this tutorial will reference the directory name structure
I use:
<blockquote><pre>
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/
gaf/myproject2/
...
</pre></blockquote>
With this organization, your custom gschem symbols and PCB elements can
be common to all of your projects and is good enough to get you started.
However, I'll mention other possibilities which will be revealed
below. There can be project specific PCB <b>file element</b>
subdirectories or <b>m4 element</b> files. Or, CAD administrators can
set up site wide custom PCB <b>file element</b> directories and
<b>m4 element</b> files.
</li>
<p>
<li> <b>gschem setup: </b> So gschem will be able to find any custom
symbols you will make and put in <b>gaf/gschem-sym</b> create the
file <b>~/.gEDA/gschemrc</b> with this content (plus an entry for each
additional <b>gschem-sym </b> subdirectory you want):
<blockquote><pre>
(component-library "${HOME}/gaf/gschem-sym")
(component-library "${HOME}/gaf/gschem-sym/transistors")
</pre></blockquote>
<b>gnetlist setup: </b> gnetlist will also need to find these symbols
so duplicate those lines into <b>~/.gEDA/gnetlistrc</b>.
<p>
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 <b>/etc/gEDA/</b> for settings
you can make.
For example, I like the light gschem background, so I also put in
my <b>~/.gEDA/gschemrc</b> the line:
<blockquote><pre>
(load (string-append gedadatarc "/gschem-lightbg")) ; light background
</pre></blockquote>
</li>
<li> <b>PCB setup: </b> A PCB distribution usually is set up so that
PCB will automatically look in a <b>packages</b> subdirectory of the
working directory. So, to make PCB find all the custom elements I
put in <b>gaf/pcb-elements</b> 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 <b>pcb-elements</b> directory in a
<b>project</b> file. But if you do want to make the link,
in directory <b>gaf/myproject1</b> enter the command:
<blockquote><pre>
ln -s ../pcb-elements packages
</pre></blockquote>
</li>
<li> <b> gsch2pcb setup: </b> In each of your project directories, create
a gsch2pcb project file which can be named anything that does not
end in <i>.sch</i>.
A poject file will be created in the example below.
</li>
</ul>
This is all the setup you need beyond the initial install of the
gschem, gsch2pcb, and PCB packages.
</blockquote>
<a name="SIMPLE_EXAMPLE">
<h3> Simple Example </h3>
<blockquote>
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.
<p>
Assuming you setup the directory structure described
above, go to the <b>gaf/myproject1</b> directory and create
a file named <b>project</b> with this content:
<blockquote><pre>
schematics one.sch two.sch
output-name board
</pre></blockquote>
<h4> Create schematic: one.sch</h4>
<blockquote>
If you are using gschem for the first time, try stepping through
this simple
<a href="gschem-warmup.html" name="gschem-warmup.html">gschem warmup. </a>
<br>
Run <b>gschem one.sch</b> and create this schematic (the second opamp
is redundant, but this is just a tutorial):
<p>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/one-sch-1.png" alt="images/one-sch-1.png"
border="0" align="top"><br> <center>one.sch</center>
</td>
<td>
<ul>
<li> Add component <b>title-B.sym</b> from the <b>titleblock</b>
library. Hit keys <b>ve</b> to zoom to the titleblock extents.
Lock the titleblock with the menu <b>Edit->Lock</b>.
<li> Add components:<br>
From the <b>analog</b> library three <b>resistor-1.sym</b> and
two <b>dual-opamp-1.sym</b>.<br>
From the <b>io</b> library one <b>output-2.sym</b>.<br>
From the <b>power</b> library one <b>gnd-1.sym</b>
two <b>vcc-1.sym</b> and two <b>vee-1.sym</b>
</li>
<li> Move components with the middle mouse button and rotate
selected components by hitting keys <b>er</b> until everything
is placed nicely. Rotate the bottom opamp and mirror it with
the <b>ei</b> keys.
</li>
<li> Use the <b>n</b> key and the mouse to draw net connections.
</li>
</ul>
</td>
</tr>
</table>
<p>
Edit the attributes of the components on the schematic.
<p>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/one-sch-2.png" alt="images/one-sch-2.png"
border="0" align="top"><br> <center>one.sch</center>
</td>
<td>
For each component, select it and bring up its attributes
window by hitting keys <b>ee</b>. Do not edit the <b>refdes</b>
attribute here, but do make these edits:
<ul>
<li> For resistors and the opamps, add visible <b>value</b>
attributes and assign appropriate values to them (10K, TL072).
Move these newly visible attributes to nice locations with the
middle mouse button. Zoom in and repeat clicking the middle mouse
button if it is difficult to select them.
</li>
<li> For the resistors, add a <b>footprint</b> attribute and
give it the value <b>R025</b> which is the PCB <i>m4 element</i>
for a 1/4 watt resistor. Make this attribute invisible.
</li>
<li> For the opamps, edit the already existing <b>footprint</b>
attribute to be <b>DIL 8 300</b>. Yes, include those spaces
because <b>DIL</b> is a <b>m4 element</b> that takes two args.
We're telling it to make a dual in line package with 8 pins in a
300 mil package.
Edit the <b>slot</b> attribute of
the second opamp to be <b>2</b>. Its I/O pin numbers should
change from (1,2,3) to (5,6,7).
</li>
<li> For the output module port, edit its <b>net</b> attribute
to be <b>vmixer:1</b> and make it invisible. Edit its <b>value</b>
attribute to be <b>Vmixer</b>.
</li>
</ul>
</td>
</tr>
</table>
<p>
It may have occurred to you that this editing will be painful for a
schematic with a large number of components that don't have reasonable
initial attribute values. At least for the footprints,
there are a couple of things that could help. You can create your own
library symbols having an initial <b>footprint</b> (and even <b>value</b>)
attribute default that covers most of your uses. Or, when you add your
first component, edit it to have a good footprint default and then copy it
(select it and hit the <b>ec</b> keys) for all
remaining components instead of adding them from the library.<br>
Anyway, we're done for now with <b>one.sch</b>, so save it with
the menu <b>File->Save Page</b> and quit gschem.
</blockquote>
<h4> Create schematic: two.sch</h4>
<blockquote>
This will be really trivial and stupid since we're doing it only to
demonstrate multiple schematic capability. Run <b>gschem two.sch:</b>
<p>
</blockquote>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/two-sch-1.png" alt="images/two-sch-1.png"
border="0" align="top"><br> <center>two.sch</center>
</td>
<td>
<ul>
<li> Add component <b>title-B.sym</b> as you did in one.sch.
<li> Add components:<br>
From the <b>io</b> library one <b>input-2.sym</b>.<br>
From the <b>analog</b> library one <b>resistor-1.sym</b>.<br>
From the <b>transistor</b> library one <b>2N3904-1.sym</b>.<br>
From the <b>power</b> library one <b>gnd-1.sym</b>,
one <b>vcc-1.sym</b> and one <b>vee-1.sym</b>.<br>
From the <b>connector</b> library one <b>BNC-1.sym</b>
</li>
<li> Move components and draw nets as before.
</li>
<li> Edit component attributes:<br>
Input module port: edit <b>net</b> attribute to be invisible
and have value <b>vmixer:1</b>
so this net will be connected
to the <b>vmixer</b> in one.sch.
Make the <b>value</b> attribute be <b>Vmixer</b>.<br>
Resistor: give it invisible <b>footprint</b> attribute
<b>R025</b>
and a visible <b>value</b> attribute 10K.<br>
Transistor: add <b>value</b> attribute <b>2N3904</b> and
invisible <b>footprint</b> attribute <b>TO92</b>.<br>
BNC connector: add invisible <b>footprint</b> attribute
<b>CONNECTOR 2 1</b>.
which is a <b>m4 element</b> that takes arguments
and we're telling it to make a connector with 2 rows and 1 column.
We put a BNC connector on the schematic, but I'm pretending
we'll just jumper wires from this pc board header to a panel
mounted connector.
</li>
</ul>
</td>
</tr>
</table>
<blockquote>
<p>
Unfortunately, the 2N3904 symbol we added has the text "2N3904" as an
integral part of its symbol. So when we add the <b>value</b> attribute
(which we want so the PCB layout will show appropriate values), there are
two "2N3904" designations visible on our schematic unless we would
make the <b>value</b>
attribute invisible. This is not good and for this example
we have to live with it, but note that in most cases it's not a good
idea to hardwire information into symbols like this.
Also the default <b>device</b> attribute
is wrong and should be <b>NPN_TRANSISTOR</b> but it won't affect
this tutorial. This is just to inform you that currently there
are some symbols in gschem that carry over outdated
attribute usage from older versions of gschem. If you get into
running spice on schematics, then your symbols will need to have
proper <b>device</b> attributes.
<p>
Now we are done with the schematics except for assigning <b>refdes</b>
attributes and we can use the command <b>refdes_renum</b> to do this
for both schematics at once. So, save <b>two.sch</b>, quit gschem and run:
<blockquote><pre>
$ refdes_renum --pgskip one.sch two.sch
</pre></blockquote>
and run gschem on the schematics again to see how the components
have been given a <b>refdes</b> attribute. The <i>--pgksip</i> option
makes numbering begin at 101 for one.sch and at 201 for two.sch.
But you should know that
running <b>refdes_renum</b> 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 <b>refdes_renum</b>
that components will keep an
existing <b>refdes</b> 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 <b>refdes_renum</b> and start a PCB
layout, to be safe you will
need to manually add (unique) <b>refdes</b> attributes for any
schematic components you might add. Also note that <b>refdes_renum</b> 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.
</blockquote>
<h4> Generate PCB Files from Schematics</h4>
<blockquote>
We have to fix one thing in <b>one.sch</b> before we can proceed.
Run <b>gschem one.sch</b> and notice that <b>refdes_renum</b> has
given our opamps <b>refdes</b> values of <b>U101</b> and <b>U102</b>
and did not know we really want to be using two opamps out of a single
TL072 package. That's why we edited the <b>slot</b> attribute of the
second opamp. We have to go back and fix this by editing the
<b>refdes</b> attribute of the second opamp to be <b>U101</b> so
both opamps will have the same <b>refdes</b>
and there will be only one TL072 package on our pc board.
<p>
Now, since we have already set up a gsch2pcb <b>project</b> file,
all we need to do to create an initial set of PCB files is to run
gsch2pcb:
<blockquote><pre>
~/gaf/myproject1$ gsch2pcb project
0 file elements and 7 m4 elements added to board.pcb.
</pre></blockquote>
Since the project file specifed <b>board</b> as the output-name,
the PCB files created are named <b>board.pcb</b> and <b>board.net</b>.
<p>
If you get output from gsch2pcb like:
<i>2 unknown elements added to board.pcb.</i>, then run with the -v
flag: <b>gsch2pcb -v project</b> and the gsch2pcb output will tell
you which schematic components don't have a known <b>footprint</b>. 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
<a href="tutorial.html#CUSTOM_M4"> Custom M4 Elements </a> section.
</blockquote>
<h4> Layout PCB Files</h4>
<blockquote>
When you run PCB on a <b>.pcb</b> file for the first time as in Step 1
below, you should set up various intial values. I usually set a
25 mil grid spacing with <b>Screen->25 mil</b> for the bulk of my
layout work and then change grid spacing to smaller values as needed
for tight layout situations. You should also set the default line
and via sizes you
want for Signal, Power, Fat, and Skinny drawing in the
<b>Sizes->adjust...</b> menu. Then select the routing style you want
to use from the <b>Sizes</b> menu. You can set your
board size now or wait until later with <b>Edit->change board size</b>.
And it may be useful to you to set <b>Screen->display grid</b>.
</blockquote>
<table cellspacing=10>
<tr>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/board-1.png" alt="images/board-1.png"
border="0" align="top"><br> <center>Step 1</center>
</td>
<td>
Run <b>pcb board.pcb</b>
<p>
You'll see grouped into a big pile the PCB elements for all
the schematic component footprints.
</td>
</tr></table>
</td>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/board-2.png" alt="images/board-2.png"
border="0" align="top"><br> <center>Step 2</center>
</td>
<td>
Use the middle mouse button to grab and move elements one
at a time until you have separated all the elements.
</td>
</tr></table>
</td>
</tr>
<tr>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/board-3.png" alt="images/board-3.png"
border="0" align="top"><br> <center>Step 3</center>
</td>
<td>
<ul>
<li><b>File->load netlist file</b> and select <b>board.net</b>
</li>
<li><b>Connects->optimize rats-nest</b>
</li>
<li>As you move elements around in later steps,
it will clean up the lines to re-do the optimize rats-nest.
</li>
</ul>
</tr></table>
</td>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/board-4.png" alt="images/board-4.png"
border="0" align="top"><br> <center>Step 4</center>
</td>
<td>
Select the <b>ROT</b> tool and move elements with the
middle mouse button and rotate them with the left mouse
button until the rats-nest lines look minimized. Hit the
<b>f</b> key with the mouse on a pin to highlight
particular routes to help visualize the routes. <b>Shift f</b>
to unhighlight.
</td>
</tr></table>
</td>
</tr>
</table>
<blockquote>
Note: you can use the PCB auto placement feature instead of
manually placing the components as described above. To do this
you would load the netlist, select the components you want to be
autoplaced (if this is the first PCB run, just <b>Select->select all
objects</b>) then do <b>Select->auto place selected elements</b>.
Then you can manually tune the PCB generated placements.
<p>
At this point you can start routing traces between pins connected
by rats nest lines. On the left PCB toolbar,
select the <b>LINE</b> tool, select the layer you want to draw on
(solder, component, etc), and start drawing lines by selecting
endpoints with the left
mouse button. Again, it can help to use the <b>f</b> key to highlight
routes that need to be connected.
If you want to stop the current trace so you can start
drawing a new trace somewhere else, finish the current trace with
a middle mouse click. Or you can play with auto routing here.
<p>
A very useful operation with the <b>SEL</b>
tool is to select multiple objects and then cut or copy them to a
buffer with the menu <b>Buffer->cut selection to buffer</b> (or copy).
You can immediately paste the buffer contents or abort the current
paste by selecting another tool. The buffer contents can be pasted
any time later with <b>Buffer->paste buffer to layout</b>. With
this you can move layout
areas around or step and repeat common trace patterns. To
select multiple objects with the <b>SEL</b> tool, click and drag
to select rectangular regions, and SHIFT click to toggle additional
selections to the currently selected set.
<p>
When you've finished routing the traces (PCB will congratulate you if all
traces are routed when you optimze the rats nest) the board can look
something like this. For this view I've selected <b>Screen->value</b>.
<p>
<center><table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/board-5.png" alt="images/board-5.png"
border="0" align="top">
</td>
</tr>
</table></center>
<p>
You will want more information on using PCB and there is a set
of html docs in the PCB source tarball. I don't know of a link to
put here, but you can get the latest tarball from the
<a href="http://sourceforge.net/projects/pcb/"
name="1.99 development">PCB 1.99 development </a> site.
Or the docs may be installed somewhere on your system.
The Debian package has them installed in <b>/usr/share/doc/pcb/html/</b>.
</blockquote>
<h3>Modifying Schematics</h3>
<blockquote>
The process of transfering schematic modifications to your PCB layout is
made very simple by using gsch2pcb. After the first <b>board.pcb</b>
was created when you initially ran gsch2pcb,
each time you run gschem on
your schematics and make changes, run <b>gsch2pcb project</b>. Then run
<b>pcb board.pcb</b> and do whatever is necessary based on the work
gsch2pcb has done. Each time gsch2pcb is run, this will happen:
<ul>
<li> gsch2pcb always generates a new <b>board.net</b>. If the net
was changed, load the new netlist file when you run pcb.
<li> If you added components (with a footprint attribute) to a schematic
gsch2pcb will generate a <b>board.new.pcb</b> containing all the
new PCB elements corresponding to the footprints.
You then run <b>pcb board.pcb</b> and load the <b>board.new.pcb</b>
with new elements into
the existing layout with <b>File->load layout data to paste-buffer</b>.
Place the new elements, load the new netlist, and route new traces.<br>
</li>
<li> If you deleted components from a schematic, gsch2pcb will delete
the corresponding PCB elements from <b>board.pcb</b>. You only
need to run <b>pcb board.pcb</b> and clean up dangling traces from
around the deleted elements.
</li>
<li> If you change an existing component's <b>footprint</b>, gsch2pcb
will delete the corresponding old element from <b>board.pcb</b>
and add the new element to <b>board.new.pcb</b>.
</li>
<li> If you changed schematic component <b>value</b> attributes, the
value changes will be forward annotated to <b>board.pcb</b> in place.
</li>
</ul>
So by using gsch2pcb, all PCB element changes are driven by the
schematics and you should never need to manually add or delete elements
for schematic components.
<p>
However, you will need to manually add PCB
elements that are not part of the schematics such as pc board mounting
holes. For these manually added PCB elements, make sure you never give
them a <b>name on PCB</b> name because that is reserved for schematic
component <b>refdes</b> attributes and gsch2pcb will want to delete
elements which have a non-empty <b>name on PCB</b> and don't match
any schematic component <b>refdes</b>.
<p>
Now, so far we've only used <b>m4 elements</b> in our layout so let's
modify a schematic to use a <b>file element</b>. But first, it would
help to know about the default elements PCB provides. Depending
on the location of your PCB install there will be a directory
<b>/usr/local/share/pcb/newlib, /usr/share/pcb/newlib</b>, or possibly
something else (depending on the <i>prefix</i> specified when PCB
was installed). PCB versions before 20031113 used <b>pcb_lib</b> instead
of <b>newlib</b> in the locations
<b>/usr/local/pcb_lib, </b> or <b>/usr/lib/pcb_lib,</b>.
Once you find your <b>newlib</b> directory,
look at the file names in each subdirectory. Each file name
is a name which may be used as a <b>footprint</b> attribute
for a schematic component. For example, there is the file
<b>xxx/newlib/2_pin_thru-hole_packages/0.125W_Carbon_Resistor</b>
so if we wanted 1/8 watt resistors on our layout, we could
use <b>0.125W_Carbon_Resistor</b> as the resistor <b>footprint</b>
attribute instead of <b>R025</b>. Try changing, say resistor R101 to
use <b>0.125W_Carbon_Resistor</b> in <b>one.sch</b> and
then run <b>gsch2pcb project</b>. If gsch2pcb does not find
this element, then you need to add your <b>newlib</b>
directory to your <b>project</b> file with a line like:
<blockquote><pre>
elements-dir /usr/lib/newlib
</pre></blockquote>
If gsch2pcb does find it, you will get:
<blockquote><pre>
~/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.
</pre></blockquote>
Now you need to run <b>pcb board.pcb</b>. You will see that the
element for resistor R101 is gone and that you will get the
new element by loading <b>board.new.pcb</b> with
<b>File->load layout data to paste-buffer</b>.
<p>
</blockquote>
<h3>Custom gschem Symbols</h3>
<blockquote>
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 <b>dual-opamp-1.sym</b> 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 <b>net</b> attributes in this tutorial.
It's possible with gschem for symbols to
have <b>net</b> attributes which can assign pins to a particular
net. Instead of hooking up each opamp pin 8 to Vcc and pin 4 to
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 these
steps (however, your gEDA symbol install directory may be something
different like <b>/usr/local/share/gEDA/sym/</b>):
<blockquote><pre>
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
</pre></blockquote>
</blockquote>
<table cellspacing=10>
<tr>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/gschem-sym-1.png" alt="images/gschem-sym-1.png"
border="0" align="top"><br> <center>Step 1</center>
</td>
<td>
<ul>
<li>Hit keys <b>en</b> to make attributes visible.
</li>
<li>Hit keys <b>ve</b> to view extents.
</li>
<li>Left mouse click on pin 8 to select it.
</li>
</ul>
</td>
</tr></table>
</td>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/gschem-sym-2.png" alt="images/gschem-sym-2.png"
border="0" align="top"><br> <center>Step 2</center>
</td>
<td>
<ul>
<li>Hit <b>Delete</b> key to delete pin 8.
</li>
<li>Similarly select and delete pin 4.
</li>
<li>Double click to select and edit the <b>slotdef</b>
lines. Edit them by removing the pins 4 and 8.
</ul>
</td>
</tr></table>
</td>
</tr>
<tr>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/gschem-sym-3.png" alt="images/gschem-sym-3.png"
border="0" align="top"><br> <center>Step 3</center>
</td>
<td>
From the menu <b>Add->Attribute</b>
<ul>
<li>Add a <b>net</b> attribute with value <b>Vcc:8</b>
Select <b>Show Name & Value</b> and make it invisible.
</li>
<li>Add a <b>net</b> attribute with value <b>Vee:4</b>
Make it <b>Show Name & Value</b> and invisible.
</li>
<li>Make the <b>device</b> attribute be just <b>OPAMP</b>.
</li>
</ul>
Clean up by moving these new attributes as shown.<br>
Change the footprint default if you wish.
</tr></table>
</td>
</tr>
</table>
<blockquote>
When all the edits are done, it's very important when editing
symbols to do a <b>Edit->Symbol Translate</b> to zero before saving.
Do that and then save the symbol with <b>File->Save Page</b>
I made the <b>footprint</b> default be <b>DIP8</b> because I have
that as a custom element.
<p>
Run <b>gschem one.sch</b>. Select and delete with the <b>Delete</b>
key both opamps. Also delete the <b>Vcc</b> and <b>Vee</b> symbols that
were connected to them. Bring up the Add Components window
and from the <b>gschem-sym</b> library which should now have your
new custom symbol, place two of the <b>opamp-dual.sym</b>
Move them to the right place on the schematic and don't forget to
mirror and rotate the bottom opamp as before. Edit the attributes
of each opamp giving them the same attributes they had, that
is make the <b>footprint</b> be <b>DIL 8 300</b>, add a <b>value</b>
attribute of <b>TL072</b>, and make the <b>refdes</b> of both
opamps be <b>U101</b>. Make the <b>slot</b> of the second opamp
be <b>2</b>. If you don't make the attributes the same as they were
before, gsch2pcb will think it is a different component and delete the
existing <b>DIL</b> package from the layout. If you did everything
right, running gsch2pcb should give:
<blockquote><pre>
~/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
</pre></blockquote>
Where the gEDA gnetlist program seems a bit excited about finding the new
Vcc and Vee <b>net</b> attributes we just added, and a new netlist
was generated. Now I think the schematic looks
cleaner:
<p>
<center><table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/one-sch-3.png" alt="images/one-sch-3.png"
border="0" align="top"><br> <center>one.sch</center>
</td>
</tr>
</table></center>
<p>
And if you run <b>pcb board.pcb</b> 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 <b>net</b>
attribute has worked.
<p>
For complete details on making symbols, read through the
Symbol Creation Document on the
<a href="http://www.geda.seul.org/docs/index.html"
name="gEDA Documentation"> gEDA Documentation </a> page.<br>
</blockquote>
<h3>Custom <i>file elements</i></h3>
<blockquote>
You can create custom <b>file elements</b>
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.
<p>
Run <b>pcb</b> and the first thing to do is go to the <b>Sizes</b>
menu and select <b>adjust "Signal" sizes</b>. Set the via hole
to 42 and the via size to 70 or larger as you like. Then make
sure you use this via
size by selecting <b>Sizes->use "Signal" routing style</b>. Select
<b>Screen->25 mil</b> and <b>Screen->display grid</b>.
Zoom in a couple of steps, then make the element:
</blockquote>
<table cellspacing=10>
<tr>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/pcb-el-1.png" alt="images/pcb-el-1.png"
border="0" align="top"><br> <center>Step 1</center>
</td>
<td>
<ul>
<li>Select the <b>VIA</b> tool and place two vias 400 mils
apart.</li>
<li>With the mouse on the left via, hit the <b>n</b>
key and give the via the name <b>1</b>. Give the
right via the name <b>2</b>
</li>
<li> Pin 1 will be the cathode and this must agree with the
pin numbers in your diode gschem symbol.
</li>
</ul>
</td>
</tr></table>
</td>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/pcb-el-2.png" alt="images/pcb-el-2.png"
border="0" align="top"><br> <center>Step 2</center>
</td>
<td>
<ul>
<li>Select the <b>Silk</b> layer and the <b>LINE</b> tool.
</li>
<li>Draw the component outline as shown with line width set
to 10 mils and the grid setting set to 10 mils.
</li>
<li>Draw the left fat cathode indicator with three lines after
setting the line width to 20 mils.
</li>
<li> Don't let silk layer lines overlap solder pads. </li>
</ul>
</td>
</tr></table>
</td>
</tr>
</table>
<blockquote>
Select the vias and the outline just drawn using the <b>SEL</b> tool
and finish making the element:
<ul>
<li><b>Buffer->cut selection to buffer</b> and move the cursor
to the center of the left via and click.
</li>
<li><b>Buffer->convert buffer to element</b>
</li>
<li><b>Buffer->save buffer elements to file</b> and navigate to
<b>~/gaf/pcb-elements</b> and save the element as
<b>D400-1A</b> since it's a package for a 1A diode with
400 mil spaced pins. Or give it any descriptive name you like.
</ul>
<b>Note:</b> if you save the element with a name which is the same
as a <b>m4 element</b>, gsch2pcb will preferentially use the m4
element unless you give gsch2pcb the --use-files (or -f) option.
You may put <b>use-files</b> in a project file if you want to always
give priority to using <b>file elements</b>. The m4 element names appear
to use upper case, so you could also avoid the problem by using
lower case in your file element names. Also, the only way I know to make
the pin 1 of the symbol square is to edit the D400-1A file manually and
change the square flag in the Pin "1" line. For example, change the
line:
<blockquote><pre>
Pin(0 0 70 20 70 42 "" "1" 0x00000001)
to:
Pin(0 0 70 20 70 42 "" "1" 0x00000101)
</pre></blockquote>
You can now use <b>D400-1A</b> in a gschem schematic symbol
<b>footprint</b> attribute and gsch2pcb will find it provided
you have made the <b>packages</b> link described in the <b>Setup</b>
section. If you have not made that link, you can still tell gsch2pcb
about the elements directory with a line in a project file:
<blockquote><pre>
elements-dir ~/gaf/pcb-elements
</pre></blockquote>
Possibly you've noticed, but there are some things not right about the
<b>myproject1</b> 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:
<a href="transistor-guide.html" name="transistor-guide.html">
transistor guide.</a>
<p>
From the transistor guide, you can see that the problem here is that
the <b>TO92</b> element has its pins numbered
in the less common (3,2,1) configuration while the <b>2N3904-1.sym</b>
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 <b>en</b> keys
(and don't be confused by the <b>pinseq</b> attribute that nearly
covers up the <b>pinnumber</b>). And in PCB, you can see the <b>TO92</b>
pin numbers by hitting the <b>d</b> key with the mouse over
the element. To be sure you are seeing pin numbers and not pin
names, select <b>Screen->pinout shows number</b>.
<p>
I have libraries with transistor symbols and elements that you might
find useful, so as a convenience you can get your custom
libraries initially populated by installing my
<a href="gsch2pcb-libs-20040110.tar.gz"
name="gsch2pcb-libs-20040110.tar.gz"> gschem/PCB libraries </a>.
Untar them under ~/gaf to mirror the setup of our example
and there will also be a
<b>~/gaf/pcb-elements.Readme</b> which documents the PCB elements.
<blockquote>
<i>Note: as of 1/10/2004 I've corrected the tarball pcb elements
to not overlap solder pads with silk layer lines.</i>
</blockquote>
If you untar them somewhere else,
you will need to make sure that gschem knows about them with
gschemrc/gnetlistrc <b>component-library</b> lines and that
gsch2pcb can find them with <b>elements-dir</b> lines in a
project file.
<p>
If you install them, you can fix Q201 in <b>two.sch</b>
by changing its footprint to <b>TO-92</b> which is my custom
element with (1,2,3) pin numbering.
Then run <b>gsch2pcb project</b>
and then <b>pcb board.pcb</b> and load the new element for
the transistor. In the next images, <b>two.sch</b> is showing
the <b>footprint</b> attribute visible to emphasize it, and it also
shows a new symbol for the 2N3904 which I created from my
custom <b>npn-ebc.sym</b> as described in my transistor guide.
In the updated board.pcb layout,
if you compare the outline appearance of the transistor to the original
layout you see that the orientation is now correct and that silk layer
lines don't overlap the solder pads.
I also changed the <b>footprint</b> attribute for
resistors R102 and R103 in <b>one.sch</b> to my custom
1/8 watt <b>R0w8</b> and 1/4 watt <b>R0w4</b> elements to
illustrate the differences in style you can have with
custom elements. You can also see the R101 style after its
footprint was changed to <b>0.125W_Carbon_Resistor</b> as suggested
above. As you evaluate the differences in these styles, I'll mention
that for my custom elements I wanted to maximize room to display
value and refdes text (the 0.125W... element body could be a little
larger) and I wanted the solder pad diameter a little larger
so it will be more forgiving of board fabrication technique.
Also, the resistor pin spacing for my <b>R0w4</b> is slightly less
than in <b>R025</b> to improve component density.
</blockquote>
<center><table cellspacing=30>
<tr>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/two-sch-2.png" alt="images/two-sch-2.png"
border="0" align="top"><br><center> two.sch</center>
</ul>
</td>
</tr></table>
</td>
<td>
<table border=1>
<tr bgcolor=#b0b0a8>
<td>
<img src="images/board-6.png" alt="images/board-6.png"
border="0" align="top"><br>
</td>
</tr></table>
</td>
</tr>
</table></center>
<blockquote>
</blockquote>
<a name="CUSTOM_M4">
<h3>Custom <i>m4 elements</i> (Requires gsch2pcb >= 1.0)</h3>
<blockquote>
First, some words about how to find out about
the default <b>m4 elements</b>
available in PCB. I think there is some documention forthcoming
in the PCB project, but at this point I don't know of anything
to refer you to
and you can't just look at filenames as you can for
the <b>file elements</b>. Not only that, but many of these elements
require arguments and you need to determine what they are.
So for now all I can say is that the best
way to find out what's available is to read the m4 element files and
for this you need to know where the PCB
m4 files install location is. As of PCB 20031113 this install
directory will most likely be <b>/usr/share/pcb/m4</b> or
<b>/usr/local/share/pcb/m4</b>, while on earlier PCB versions it could be
<b>/usr/X11R6/lib/X11/pcb/m4</b> (run <i>gsch2pcb --help</i> or
<i>gsch2pcb -v project</i> to see which of these directories gsch2pcb
is using). But if your install is somewhere else you will
have to track it down. By the way, if the m4 directory <i>is</i> somewhere
different from the above three, then gsch2pcb won't be finding your
<b>m4 elements</b> in the above examples and you will need to add
the correct m4 directory to your <b>project</b> file with a line like:
<blockquote><pre>
m4-pcbdir /path/to/pcb/m4
</pre></blockquote>
Just read the <b>.inc</b> files in the m4 install directory. For
example, in the <b>misc.inc</b> file you will find the <b>R025</b> element
we've used and it starts out with:
<blockquote><pre>
# -------------------------------------------------------------------
# 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)
(
...
</pre></blockquote>
The information you can extract from this is that a m4 <b>PKG_</b> macro
named <b>R025</b> is being defined and it takes 3 arguments. Now, all PCB
<b>m4 element</b> macros take at least three
arguments and these are automatically
filled in by gsch2pcb with the gschem attributes <b>footprint</b> for
<b>canonical name</b>, <b>refdes</b> for <b>name on PCB</b>, and
<b>value</b> for <b>value</b>. The "canonical name" used in these
m4 files is just an older way of referring to the current PCB usage of
<b>description</b> as mentioned above in the <b>Terminology</b> section.
Since these args are automatically filled in, you don't need to specify
any additional args to <b>R025</b> when you use it as a gschem
<b>footprint</b>. But now look at the very next m4 element define
in <b>misc.inc</b>:
<blockquote><pre>
# -------------------------------------------------------------------
# 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)
(
...
</pre></blockquote>
From this you can determine there is a <b>SIL</b> package you can use
as a <b>footprint</b>. 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 <b>CONNECTOR 2 1</b> element specifying 1 column we used
in our example above, you might think we could have used <b>SIL 2</b>.
But you would be wrong! Because if you read the macro body you will see
that if the argument is <b>2</b> 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 <b>misc.inc</b> here's a summary
of what you will find as possible elements you can use:
<blockquote><pre>
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
</pre></blockquote>
And so on for the other <b>.inc</b> files...
<p>
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
<b>file element</b> approach. So for most of your custom elements I
suggest you are better off staying with <b>file elements</b>. 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 <b>m4 element</b> would be to copy and modify to
our taste the existing
m4 macro for IC packages (the <b>DIL</b> macro) into a m4 file gsch2pcb
will search. The destination m4 file can be any of these:
<ul>
<li><b>pcb.inc</b> in our <b>myproject1</b> directory and the custom
element will be local to this project.
</li>
<li><b>~/.pcb/pcb.inc</b> and the element will be known to all of
our projects.
</li>
<li><b>/path/to/anyfile</b> if this path is made known to gsch2pcb
by adding a line to a project file like:
<blockquote><pre>
m4-file /path/to/anyfile
</pre></blockquote>
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:
<blockquote><pre>
~/gaf/myproject1/project
~/.gsch2pcb
/usr/local/etc/gsch2pcb
/etc/gsch2pcb
</pre></blockquote>
</li>
</ul>
For this tutorial, I'll use the first <b>pcb.inc</b> way, so copy over
the existing macro file:
<blockquote><pre>
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
</pre></blockquote>
Now, edit the <b>pcb.inc</b> 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 <b>60</b>
to <b>70</b> on the <b>PIN</b> lines.
When done, this should
be the entire contents of the new <b>pcb.inc</b> file:
<blockquote><pre>
# -------------------------------------------------------------------
# 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)
)')
</pre></blockquote>
Run <b>gschem one.sch</b> and edit the <b>footprint</b> attribute of
the opamps to be <b>DILFAT 8 300</b>.
Then run <b>gsch2pcb project</b>
and gsch2pcb will remove the <b>DIL</b> element from <b>board.pcb</b>
and add into <b>board.new.pcb</b> a new <b>DILFAT</b> element from your
custom m4 file <b>pcb.inc</b>. Run <b>pcb board.pcb</b> and
load the <b>board.new.pcb</b> into
your layout. Move the new element with its fatter pins to the location
left vacant by the removal of the old element.
</blockquote>
<h3>Multi-user Setup (requires gsch2pcb >= 1.0)</h3>
<blockquote>
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:
<ul>
<li> Put site wide custom PCB <b>file elements</b> under, for example,
<b>/usr/local/share/pcb/pcb-elements</b>. Make this directory
searched by gsch2pcb for all users by putting a line into
<b>/etc/gsch2pcb</b> or <b>/usr/local/etc/gsch2pcb</b>:
<pre>
elements-dir /usr/local/share/pcb/pcb-elements
</pre>
If there are any site wide custom PCB <b>m4 element</b> files,
for example, <b>/usr/local/share/pcb/pcb.inc</b>, add another
line into <b>/etc/gsch2pcb</b> or <b>/usr/local/etc/gsch2pcb</b>:
<pre>
m4-file /usr/local/share/pcb/pcb.inc
</pre>
</li>
<li> If the default PCB m4 install is not
<b>/usr/local/share/pcb/m4, /usr/share/pcb/m4,</b> or
<b>/usr/X11R6/lib/X11/pcb/m4</b>, then make the install location
known to all users of gsch2pcb by putting into
<b>/etc/gsch2pcb</b> or <b>/usr/local/etc/gsch2pcb</b> the line:
<pre>
m4-pcbdir /path/to/pcb/m4
</pre>
If the m4 program is gm4 instead of m4, add to the gsch2pcb file:
<pre>
m4-command gm4
</pre>
</li>
<li> If there are site wide custom gschem symbols under some
directory, you will have to edit the system gschemrc and gnetlistrc
files and add <b>component-library</b> lines for them.
</li>
</ul>
With the above, users will have access to site wide libraries
and only need to put in a design <b>project</b> file
lines for <b>schematics</b> and <b>output-name</b>. But they
also are free to have their own additional user and/or project
specific symbol and element libraries.
</blockquote>
<h3>PC Board Fabrication</h3>
<blockquote>
Someday I may add some notes here on how I make pc boards.
</blockquote>
<hr>
<address>
<p align=center>
<a href="http://web.wt.net/~billw/gsch2pcb/gsch2pcb.html"
name="www.gkrellm.net">gsch2pcb Home</a>
<br>
Bill Wilson <A HREF="mailto:bill--at--gkrellm.net">bill--at--gkrellm.net</A>
<br>
</p>
</address>
</body>
</html>
|