Thursday, December 31, 2020

KiCAD - Sonnet interop flow

I've been using KiCAD as my PCB design tool of choice for years, and as my designs grew in complexity I began using Sonnet for EM field simulation prior to manufacturing boards.

Unfortunately, interoperability between these tools was less than ideal.

KiCAD export formats

  • Gerber/Excellon: Stable and reliable
  • DXF: Generates one file per layer. Drill hits can be plotted as Xs, but there's no obvious way to plot hole boundaries. Seems to sometimes generate polygons which are not closed (missing the last vertex).

Sonnet import formats

  • DXF: Standard feature with all (paid) Sonnet editions. Expects one file, with a separate pen type for each conductor or drill layer. Minimal tolerance to malformed files.
  • GDSII: Extra-cost option, but reasonably priced (about 25% of the cost of L2 Basic)
  • Gerber/Excellon: Extra-cost option, absurdly priced (five digits). Only runs on Windows, not available in the Linux edition at all. Apparently this is because it's a third-party conversion tool they license as a binary, so they have no ability to port it or offer less extravagant pricing.

I spent a while tinkering and came up with a flow using KLayout that seems to work well, so I thought I'd do a quick writeup so other folks could benefit from it. This might be of interest to users of other PCB CAD tools as well. Although KLayout is nominally an IC mask layout editor, it can also read Gerber!

Step 1: Gerber generation

Nothing special here. Export your gerbers just like you would for manufacturing a board.


Step 2: KLayout import

Launch KLayout and select File | Import | Gerber PCB | New Project - Free Layer Mapping. Specify the location of the exported gerbers.


On the next page, if asked to automatically populate the project, say "no". Answering yes will result in all of your soldermask, silkscreen, etc files being imported as well, which you probably don't want.

Click the plus sign button in the top right of the dialog and select all of the copper and drill layers of interest for your simulation.


On the next page, you should see one GDS layer generated for each of the files you're importing. There's no need to touch any settings.

 
On the next page, map gerber files to GDS layer IDs in a logical order. I suggest top to  bottom with blind/buried vias in sequence and through-board vias at the end. Each gerber file should be mapped to exactly one GDS layer.

Leave all settings on the next page as default.

On the next page, make sure the database unit is 1.0 micron. Coordinates are rounded to multiples of the database unit internally, so it needs to be small enough to avoid round-off errors. Microns are the most convenient unit to use with Sonnet's DXF importer.

Check the "merge polygons" box. This flattens all overlapping polygons, which is important because KiCAD likes to generate extra gerber flashes in vias and zone fills.

While not merging, or merging in Sonnet, will ultimately produce the same simulation result, Sonnet's geometry editor (xgeom) gets really slow if your geometry has too many polygons. Flattening before Sonnet sees the board avoids this.

Now the gerber conversion is done! Click "import" and you should see the PCB in the KLayout editor view.

Step 3: KLayout export

Select File | Save As. Choose file type DXF and pick a file name. Select "no compression", scaling factor 1.0, database unit 1 micron, and polygons as POLYLINE.

Step 4: Sonnet import

Create a new, empty Sonnet project and configure your desired stackup so that all layers and metal types are available for import. Select File | Import | DXF and choose the generated DXF file.
 
Choose "Import using present project as template".

On the next page, enter the layer mappings you selected in KLayout.

On the next page, select units as microns.

For the remainder of the Sonnet import wizard, enter settings as appropriate for your design. Converting vias to rectangular greatly reduces memory requirements for simulation and is normally OK as long as the vias are electrically small.

If you have large via fences, coplanar waveguides, or similar, the "simplify via arrays" option may be of use as well. This one needs to be used with caution because it sometimes merges more vias than desired. I generally prefer to import individual vias and merge manually to avoid unexpected results.