D138 — Generated pours and the layer-count advisor¶
Context¶
M20's C3 item (doc 18 §4): "Create a ground (or power) pour on a free inner or back layer when a board has none; try
2, 4 and 6 layers and report the least that completes". Gate: on PCBench boards with no zones, the count completed with a
generated pour against without, DRC clean; the advisor's answer matches a brute-force run. Doc 05 §18 had called pour
creation "a possible feature (not built); it would close a few boards, not most". PCBench boards have no zones and no
stackup; most are KiCad 5 files with two copper layers. The records are in bench/records/m20-c3/.
Decision¶
route --pour auto|NET@LAYER(repeatable;passes::plan_pours).autoapplies only to a board without copper zones: the ground net by name (GND, GNDD, VSS, ...; the one with the most pads) on In1.Cu when the board has inner layers, else on B.Cu. The zone covers the outline's box plus 0.5 mm (the refill clips it to the board), clearance the net class clearance but at least 0.3 mm, minimum width 0.25 mm, islands removed, and solid pad connections.- A pour turns on soft zones (doc 05 §36): it is filled before routing, other nets route through it, and the refill,
refill repair and thermal check after routing decide what it connects. The output holds the zone with the engine's
final fill (
BoardEditor::add_zone,set_zone_fills); the summary lists it underpours. route --copper-layers Nandtracemaker layers BOARD --count N -o OUT(BoardEditor::set_copper_layer_count): inner layers are added after the last inner entry in the file's own numbering (KiCad 9's even ordinals or the older 1..30), or removed from the top inner layer down when nothing names them (tracks, arcs, blind or micro vias, zones, graphics, texts, pads); otherwise the edit is refused and the document is untouched. A stackup block is removed, so KiCad builds its default one for the new count.route --try-layers 2,4,6(app::run_layer_advisor): the counts are routed fewest first, a count the board cannot take is recorded as not tried, and the advisor stops at the first count the engine judges complete (exit 0: every connection routed and, with zones, nothing unconnected after the refill). It writes that board, or else the count with the fewest open connections (ties to fewer layers); the summary'slayerslists every count tried.
Alternatives¶
- Thermal reliefs, KiCad's default for a new zone. The first run (
c3-bd-pour) used them: 22 of the 33 boards gained KiCadstarved_thermalerrors (up to 18 on one board), because routed tracks of other nets cut spokes off the pour. The thermal repair of D137 rerouted pad by pad with the first pass's full budget each, which took Aleste from 28 s to 3,708 s and still left 12. A solid connection only needs the fill to touch the pad. The cost is hand soldering of through-hole ground pins; the designer can switch the zone to reliefs in KiCad and see what starves. - A pour on F.Cu or on every free layer. On a two-layer board the back layer carries fewer pads, so it is cut less.
More than one generated pour is possible with
NET@LAYERentries. - The advisor judged by KiCad. It would need kicad-cli in the route; the engine's own count after a refill is the same judge the route summary uses, and the check against KiCad is the brute force of the gate.
- The advisor trying every count and keeping the best. The question is the cheapest board that completes, so it stops at the first count that does.
Consequences¶
Measured in bench/records/m20-c3 (doc 05 §53):
- The advisor's answer equals the brute force's on 28 of 28 board-and-option pairs (14 two-layer boards, with and without a pour): MicroMaple at 4 layers without a pour (the written board is byte-identical to the brute force's), serial_gw at 4 and MicroMaple at 6 with one; the other boards complete at none of 2, 4, 6.
- A pour closes no board of the 33 non-clean tier B to D boards; open connections after KiCad's refill 1,368 → 1,290 (18 boards better, 10 worse). On 4 and 6 layers it is 1 against 1 and 2 against 1 boards on the 14.
- The pour run is about three times slower (1,267 s → 3,905 s for the 33 boards): the first pass checks the soft fills and the refill repair routes against them as fixed copper.
- Open: two
solder_mask_bridgeon the Teensy test layout (tracks across a net-less B.Mask opening that the pour now fills; §48's openings are not kept out of the pour); D137's thermal repair still gives each starved pad the first pass's whole budget, which is slow on boards with many starved reliefs in designer zones. - Options off, the quick tier is byte-identical (30/30). Docs: 05 §53 (and §18), 18 §10, 11.