I have been on a quest to figure out how to do pcb milling using the gEDA suite of pcb CAD software. My goal has been to go from schematic to milled pcb with free and open source software, including the operating system - I use Ubuntu/Linux. So far, I have found a way to go from "electronic schematic diagram" to ".dxf file" using the gEDA suite, Inkscape scalable vector graphics editor, and pstoedit. The free software tool chain is broken when I get to the CAM software, but my hope is that gcam and other free CAM programs will progress in their capabilities. After the CAM software, I am back into FOSS with emc2 running the g-code and milling the pcb.
There is one small glitch to the method I am using, which I will explain later. Still, I think I am able to produce acceptable .dxf files for producing milled pcb's.
The only free alternatives for pcb CAD seem to be gEDA, KiCad, and Eagle. I appreciate that Eagle has released a free version of their proprietary software. But, Eagle is not really free, because you are bound by the 100mm x 80mm (4 x 3.2 inch) board size. I do not like that limitation, so I chose to learn the gEDA suite. Also, the Eagle .sch and .brd files are not in ASCII, so there is no looking at the files to learn things and change things. The gEDA suite's file formats are transparent. It is not that hard to learn the file structure of the .sch and .pcb files.
In the 'free' version of Eagle you are only allowed to draw your schematic on a single page. I do not like that limitation either. Gschem, the gEDA suite's schematic capture software, has no sheet restriction, so you can spread your schematic over several pages and get readable printouts on paper. I also think the schematic symbols and printouts are much more elegant and readable in gEDA/gschem than in Eagle.
Another reason I wanted to find out how to use gEDA is that I wanted to end up with a .dxf file, not a g-code file. I want a perfect outline of the pcb traces, pads, and polygons (ground planes) in .dxf file format. Then, in a CAM program I can decide what copper to mill away. I can decide what is 'island' and 'ocean'. The Eagle to g-code method, which converts the Eagle .brd file to a g-code file using 'PCB-Gcode' software, gives you a trace isolation routing. You cannot decide how to remove or (not remove) the excess copper on the board. However, with a .dxf file that contains a perfect outline of the pcb artwork, you can decide in the CAM software exactly what copper is removed and how. I want that kind of control over the milling process.
Here is why I want control over how the ground plane is milled: Often the 'clearance' of several pads and traces will combine to cut off a chunk of the ground plane from any copper connection to the electrical ground source. I have noticed that the gEDA/pcb software will cause a chunk of the ground plane to disappear, if there is no connection to it from the ground source. If gEDA/pcb did not do this, there would be a chunk of copper that has a 'floating' voltage. This 'floating' piece of copper would not be tied to positive or negative, so it's potential could fluctuate and create instability and noise in the circuit. I want a .dxf file of the exact outline as it looks in the gEDA/pcb software. Then the ground plane will be reproduced exactly as it looks in the 'pcb' software, with no floating chunks of copper.
The gEDA suite has a large community of people who are constantly adding to the schematic symbol and pcb symbol libraries, and the software keeps getting better and better. It is relatively easy to make custom symbols, it has auto routing, it can do multi-layer boards, it produces gerber files, it has a gerber viewer (gerbv), you can use it to prepare netlists for spice simulations, etc. There is a bit of a steep learning curve, but there is a lot of documentation on how to use it, and you can ask and answer questions or make suggestions on a very friendly email list.
And did I mention that gEDA, Inkscape, and pstoedit are free, as in liberty? Donations are welcome through the Linux Fund - http://linuxfund.org/projects/pcb and http://www.linuxfund.org/projects/inkscape. I have made a small donation to gEDA/PCB and I plan to give back more to gEDA and Inkscape in the future. Maybe there is a way to send a few buck to the people working on pstoedit, also.
Now that I have made my argument as to why I like to use the gEDA suite and why I want a '.dxf file' step in the software tool chain before producing a g-code file, I will explain how I am getting from schematic capture to .dxf file.
How I get from the schematic capture in 'gschem' to the finished pcb artwork in gEDA/pcb is covered in documentation and tutorials that can be found on the web. So, I will start at the point where I have completed the artwork for a pcb in gEDA/pcb.
With the .pcb file loaded in gEDA/pcb, I choose 'File > Export layout...', a window appears, and I click on the 'ps' button. This produces another window. I make sure 'multi-file' is checked and I click the 'OK' button. This produces multiple PostScript files of all the copper layers, solder mask, silkscreen, drill routing, etc.
Now I need to do some conversion of the .ps files in Inkscape. So after starting Inkscape, I load the <filename>.ps.back.ps or the <filename>.ps.front.ps file. A window called 'PDF Import Settings' pops up. I leave the default settings and click 'OK'.
Now that the .ps file is loaded into Inkscape, I 'Ctrl+A' select all. I now choose from the menu 'Object > Ungroup'. I then select and delete the unnecessary text at the bottom and some empty objects, which have appeared. What is left is the pcb artwork only.
The next operation is why I need to use Inkscape. It is my understanding that lines are stored in .pdf and .ps and .svg files as 'strokes'. These have no thickness. Extra data in the .pdf, .ps, or .svg file determines the stroke's width, joint shape, cap shape, dash style, etc. When I tried converting a .ps file directly to .dxf, I got results like this:
Most of the square pads do not show. The circles are now octagons. And all of the copper traces are now lines with no thickness. The ground plane is not recognizable. This is an unusable file.
Inkscape allows me to solve this by having the ability to convert the 'strokes' (lines) into 'paths' (objects that have a closed outline). To do this, I select the whole pcb image, and I select 'Path > Stroke to Path' from the menu bar. All of the copper traces are now converted to separate objects. All of these objects have borders that are overlapping all over the pcb image; so, I need to combine the separate overlapping objects into single composite objects.
Before doing that, this next step is important. Deselect everything and then reselect everything. If you do not do this, the entire image will disappear on the next step. This is probably a bug in Inkscape.
I then go to the menu and select 'Path > Union' This does a boolean union operation on the objects that are overlapping, and combines them into single objects. At this point you have a complex outline of all of the traces, pads, and polygons. This step also causes the drill holes to disappear, which is good, since that is what the copper layer looks like in its gerber file, anyway. This saves me from removing all of the drill holes in the image by hand. My thought is that you want the tiny drill bits that are used to drill the hole in the pcb to see a clean copper surface when drilling out each hole, not ragged edges of copper and fiberglass.
Inkscape has the ability to save the .ps file as a .dxf. I do not use this feature, though, because all of the curved objects are converted into over-simplified straight-lined polygons. Here is an example .dxf produced by Inkscape and viewed in qcad:
I do not know how Inkscape does the conversion to .dxf, but it is not precise enough for pcb artwork. A workaround is to scale the artwork by 10x or 100x, save the .ps file in Inkscape as a .dxf file, and then in the CAM program rescale the artwork down by the same factor. When saving the file at these larger sizes, the artwork has sufficient detail.
However, I think a better method is to use the open source command line tool 'pstoedit'. Once the .ps image is completed in Inkscape, I save it as a .ps file. I open up a command line terminal and navigate to the directory that contains the .ps file I want to convert. Then I run this command:
$pstoedit -f dxf_s <in>.ps <out>.dxf
The '-f dxf_s' option gets pstoedit to handle curves much more accurately. There is also a '-f dxf' option, but '-f dxf_s' does a better job.
Finally, I am left with a .dxf file that contains perfect outlines of all of the objects in the pcb artwork! Here is a screenshot of a pcb that I designed in the gEDA suite and then converted through this process to a .dxf file:
You can see in the circled area that a portion of the ground plane has been left out of the pcb artwork. This is good, since that chunk of copper would be floating with no connection to the ground source.
Now, for the small glitch in the software tool chain that I mentioned at the beginning of this post:
I am happy with the results I am getting, but I think there is a slight problem with Inkscape that I hope will eventually be improved. I have Inkscape version 0.47, so maybe it has been fixed in the current version. Or maybe there is some setting that I am missing. Or I am doing something wrong. I welcome any advice on this.
The problem is that the 'Stroke to Path' command changes the shape of the rounded ends of the lines (strokes). The perfect half circles at the end of each line are slightly altered in seemingly random ways. Here is an example of a line made in gEDA/pcb, exported as a .ps file, loaded into Inkscape, and given the 'Stroke to Path' command:
As you can see the ends of the lines alter the shape of the 45 degree bend. At first I wondered if it could be an error in the way that gEDA/pcb creates the data contained in the .ps file. But, I did some small experiments and I found that lines (strokes) that are created in a new Inkscape .svg file exhibit the same type of errors when given the 'Stroke to Path' command. Here is an example of a green line drawn in Inkscape showing its nodes as little gray diamonds:
And here is the same green line after the 'Stroke to Path' command:
You can see that the ends are altered, especially on the right end of the line. On the left end the nodes are not spaced equally.
These slight alterations to the ends of the lines show up in the final .dxf file, as well. Here are some close-ups in qcad of what the pcb artwork outlines look like after being converted from .ps to .dxf using 'pstoedit':
The perfect 45 degree rounded corners created in gEDA/pcb are now quite lumpy and bumpy. My hope is that the Inkscape developers improve the results of the 'Stroke to Path' command. Perhaps in future updates, Inkscape could provide the user with some control over increasing the resolution of the conversion from stokes to paths.
Even with these lumpy corners, I think the results are sufficient to produce good milled pcb's. I have not finished building my cnc mill yet, so it will be a while before I can fully test this method. My hope is that some of you who have pcb milling capabilities will try the 'gEDA-Inkscape-pstoedit to dxf' method to mill some pcb's and share your results.
Ultimately, I would like gEDA/pcb to allowed me to export directly to .dxf, with a 'dxf' button in the 'Export layout...' window. The challenge is to convert all of the strokes to properly shaped objects and then 'boolean union' all of the objects together. Maybe 'pstoedit' could be incorporated into gEDA/pcb as the backend program that converts the Postscript data to a .dxf file.
This feature is on my personal gEDA/PCB wishlist, anyway.
Please, let me know what you think.