This provides a true hierarchical PCB layout engine in KiCad, mirroring its hierarchical schematic capabilities.
Instead of laying out everything in your final file, you can define a sub-PCB next to your sub-schematic file, and HierarchicalPCB will automatically force the sub-PCB to be laid out exactly like that in the final PCB. There's no depth limitation to the nesting -- in fact, we encourage organizing your PCB layouts for maximum reusability.
This is inspired by the venerable ReplicateLayout
plugin, and is intended to be a more modular, powerful, and flexible replacement.
Installation:
This requires KiCad 8 to run. For now, you have to manually download or clone this repository to the plugin directory. On Windows, this is C:\Users\<Username>\Documents\KiCad\8.0\3rdparty\plugins
.
I'm working on getting this deployed to the official repository or on hosting my own.
In summary:
Organize your schematic into hierarchical sheets, as you would normally do.
Create a .kicad_pcb
file next to a hierarchical sheet and set up the placement of the sub-PCB there.
a. You should create a project file to help with the placement. b. Any footprints missing from the sub-PCB (but present in the schematic) will be ignored during automatic placement. c. Any footprints present in the sub-PCB but missing from the main PCB will be ignored. d. Any footprints placed off to the left or above the origin will be ignored during automatic placement.
Open the main PCB and run the plugin.
Select which hierarchical sheets you want to enforce the layout of, and configure which footprint to use as the anchor for each sub-PCB.
Click OK and watch the magic happen.
If you wish to see a project that uses this, check out AngloDox, my keyboard project. We use HierarchicalPCB to provide for rich per-key circuitry.
Begin by preparing your hierarchical schematic as per normal. In this example, we have a simple circuit for a single key in a keyboard, including an LED and an RC debouncing circuit:
This would be an absolute nightmare to layout ~90 different times; that's where HierarchicalPCB comes in: after creating the schematic inside the main project, we:
sch
file,When complete, this should look like:
Great! Now we're ready to propagate this layout to every key on the main PCB. To do that, create a new PCB in the main project (i.e., at the root level), and lay out the "anchor" component in each. The anchor component is the component around which all other components will be moved into position and all traces will be drawn. Here we choose the switch (SW???01
) to be the anchor component and lay it out in the shape of our keyboard:
This layout was done using my KLEPlacement plugin from this KLE file. Note that only the switch components are moved into position, all other components are unmoved.
To enforce our desired layout around each key we invoke the plugin. Click on the button in the top bar to start:
This opens up the menu where you configure the plugin. The window is split into two panes: the upper lets you pick which sub-schematics to enforce the layout for; the lower lets you pick the anchor for each sub-PCB you define. The plugin remembers the last selections you made (writing it to a file next to the .pcb
file).
First, we select which sub-schematics to enforce the layout for. The plugin allows you to arbitrarily nest PCBs, so one sub-PCB can itself have sub-sub-PCBs, but at any one time the contents of each schematic may only be arranged according to one sub-PCB. You can select which sub-schematics to arrange by double-clicking each element. If you click "Reset to Default", it automatically selects the outermost PCB for each possible schematic.
Next, you select the anchor element for each PCB. You do this by clicking on the row and picking a new anchor in the drop-down box below.
Once you've done both, click "Apply" and watch the magic happen:
Ta-da!
And since the plugin remembers your settings you can propagate any change in just two clicks.
The algorithm works as follows: