Yahoo Groups archive

Homebrew PCBs

Index last updated: 2026-04-28 23:05 UTC

Message

Re: [Homebrew_PCBs] 1 and 3 mil lines

2009-03-08 by DJ Delorie

Adam Seychell <a_seychell@...> writes:
> What that a separate command line tool you used to generate the .grb, 
> .drl and .pdf files from the .pcb file ?

PCB itself has command line options, which we use extensively in
Makefiles to automate things like web pages, etch prints, and fab
submissions.  For example, I added a "photo mode" sample export from
the tool to the web page, an export we use for all our documentation.
The same PNG export I used for the red/blue image, in inverted
monochrome at 2880 DPI, produces my photo masks:

%-f.png : %.pcb
	pcb -x png --dpi 2880 --outfile $*-f.tmp --monochrome --as-shown --layer-stack 0,pins,vias $<
	pngtopnm $*-f.tmp | ppmtopgm | pgmtopbm | pnminvert | pamflip -lr | pnmtopng > $*-f.pnm.tmp
	mv $*-f.pnm.tmp $*-f.pnm
	rm $*-f.tmp

The wrapper script looks like this ("pcb" is the board layout tool):

-----------------------------------------------------------------------------
#!/bin/bash

echo > index.html

sp()
{
  ./make-spiral $1 $2
  pcb -x gerber spiral-$1$2.pcb
  pcb -x ps --xcalib 1 --ycalib 1 --ps-bloat 0 --multi-file spiral-$1$2.pcb
  ps2pdf spiral-$1$2.front.ps

  echo "<tr><td>$1 $2</td>" >> index.html
  echo "<td><a href=spiral-$1$2.pcb>pcb</a></td>" >> index.html
  echo "<td><a href=spiral-$1$2.gbr>gbr</a></td>" >> index.html
  echo "<td><a href=spiral-$1$2.drl>drl</a></td>" >> index.html
  echo "<td><a href=spiral-$1$2.pdf>pdf</a></td>" >> index.html
  echo "</tr>" >> index.html
}

echo "<tr><td colspan=5><h2>Imperial</h2></td></tr>" >> index.html
for i in 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
do
  sp $i mil
done

echo "<tr><td colspan=5><h2>Metric</h2></td></tr>" >> index.html
for i in 0.05 0.10 0.15 0.20 0.25 0.30 0.35
do
  sp $i mm
done

echo "<tr><td colspan=5><h2>600 dpi</h2></td></tr>" >> index.html
for i in 1.66 3.33 6.67 8.33
do
  sp $i mil
done

-----------------------------------------------------------------------------

And the script which picks out the files I want for the web page
looks like this:

-----------------------------------------------------------------------------

#!/bin/bash
# -*- sh -*-

web=/home/web/pcb/spirals/
test -d $web || mkdir $web

for i in spiral-*.pcb
do
  base=`echo $i | sed s/.pcb//`;
  cp $i $web
  cp $base.front.gbr $web/$base.gbr
  cp $base.plated-drill.cnc $web/$base.drl
  cp $base.front.pdf $web/$base.pdf
done

cp index.html $web/options.html

-----------------------------------------------------------------------------

And, for the really hard core, here's the perl script which generates
the spiral layouts:

-----------------------------------------------------------------------------

#!/usr/bin/perl
# -*- perl -*-

$mil = 100;
$in = 1000 * $mil;
$cm = $in / 2.54;
$mm = $cm / 10;

$max = 10 * $cm;

$w = shift;
$wu = shift;
$wname = "$w$wu";
$wu = ($wu eq "mm") ? $mm : $mil;
$w = int ($w * $wu + 0.5);
$pw = 80 * $mil;
$pd = 30 * $mil;

#$pw = 240 * $mil;
#$pd = 90 * $mil;

$cx = $max * 1.1 / 2;
$cx = int($cx/$w)*$w;
$cy = $cx;
$pcb = int($cx * 2);

$loops = ($max/2 - $pw) / ($w*2);
$loops = int ($loops/2) * 2;

$w2 = $w * 2;

#-----------------------------------------------------------------------------

&pcb_start();

&pin(-$w/2-$pw/2, -$w);
&pin( $w/2+$pw/2,  $w);

&pin(-$pw/2-$w2-$w/2-$w2*($loops-1), -$pw-$w2*$loops);
&pin($pw/2+$w/2+$w2*$loops, -$pw-$w2*($loops-1));

&pcb_layer();

for ($i=0; $i<$loops; $i++) {

    &hline (-$pw-$w2-$w2*$i, $pw+$w2*$i, $pw/2+$w/2+$w2*$i);
    &vline (-$pw-$w2-$w2*$i, $pw/2+$w/2+$w2*$i, -$pw/2-$w/2-$w2*($i+1));

    &hline (-$pw-$w2*$i, $pw+$w2+$w2*$i, -$pw/2-$w/2-$w2*$i);
    &vline ($pw+$w2*$i, $pw/2+$w/2+$w2*$i, -$pw/2-$w/2-$w2*($i-1));
}

$w = 100 * $mil;
$cx = $cy = 0;

&vline ($w/2, $pcb-$w/2, $w/2);
&vline ($pcb-$w/2, $pcb-$w/2, $w/2);
&hline ($w/2, $pcb-$w/2, $w/2);
&hline ($w/2, $pcb-$w/2, $pcb-$w/2);

&pcb_end();

#-----------------------------------------------------------------------------

sub pcb_start {
    open(PCB, "> spiral-$wname.pcb");
    select PCB;
    print <<EOF;
FileVersion[20070407]

PCB["" $pcb $pcb]

Grid[500.000000 0 0 1]
Cursor[0 0 0.000000]
PolyArea[200000000.000000]
Thermal[0.500000]
DRC[1000 1000 1000 1000 1500 1000]
Flags("rubberband,nameonpcb,uniquename,clearnew,snappin")
Groups("1,c:2,s:3:4:5:6:7:8")
Styles["Signal,1000,8000,2800,1000:Power,2500,6000,3500,1000:Fat,4000,6000,3500,1000:Skinny,600,2402,1181,600"]

Element["" "" "" "" 0 0 0 0 0 100 ""]
(
EOF
}

sub pcb_layer {
    print <<EOF;
	)
Layer(1 "component")
(
EOF
}

sub pcb_end {
    print <<EOF;
)
Layer(2 "solder")
(
)
Layer(3 "silk")
(
)
Layer(4 "silk")
(
)
EOF
    select STDOUT;
    close PCB;
}

sub pin {
    my ($x, $y) = @_;
    printf("\tPin[%d %d %d %d %d %d \"\" \"\" \"square\"]\n",
	   $x+$cx, $y+$cy, $pw, $w, $pw, $pd);
}

sub hline {
    my ($x1, $x2, $y) = @_;
    &line($x1, $y, $x2, $y);
}
sub vline {
    my ($x, $y1, $y2) = @_;
    &line($x, $y1, $x, $y2);
}

sub line {
    my ($x1, $y1, $x2, $y2) = @_;
    printf("  Line[%d %d %d %d %d %d \"\"]\n",
	   $x1+$cx, $y1+$cy, $x2+$cx, $y2+$cy, $w, $w);
}

Attachments

Move to quarantaine

This moves the raw source file on disk only. The archive index is not changed automatically, so you still need to run a manual refresh afterward.