1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# Placement check
`tools/placement_check.py` rates a KiCad board's component placement before routing. Use it after every placement change.
## Run
Needs KiCad's Python (for `pcbnew`). It reads the saved file, so the board can stay open in KiCad; save first.
``` sh
. tools/kicad_env.sh
$KPY tools/placement_check.py board.kicad_pcb --pair U2:J2 --svg /tmp/overlay.svg
rsvg-convert -w 1100 /tmp/overlay.svg -o /tmp/overlay.png # to look at it
```
Options:
- `--ignore J3,...`: leave out parts whose long ratsnest lines would swamp the result, e.g. an off-board connector.
- `--pair A:B[:max]`: courtyard gap between two parts that must sit close together, e.g. an Ethernet IC and its jack. With a maximum it is scored.
- `--fill REGEX`: nets left out of the ratsnest. The default is GND-like names; nets with a copper zone are added automatically.
- `--svg`: overlay with:
- courtyards (grey front, purple back);
- pads (green = fill net);
- ratsnest (blue);
- crossings (red circles);
- flagged parts (orange).
- `--json`: all findings, for scripts.
- `--apply-rotations OUT`: writes a copy with the suggested rotations. Turns that would hit another courtyard are never suggested.
## What it checks
- **Crossings** of ratsnest lines (MST per net, fill nets left out). On two layers each one costs a via or a detour.
- **Length** of the ratsnest, total and per net class.
- **Decoupling.** For every cap with one pad on a fill net:
- Its other pad must be within 3 mm of the nearest IC pin (a part with at least 4 pads) on the same net. Bulk caps (≥ 4.7 µF) get 8 mm and may also sit at an inductor or ferrite.
- Its ground pad must be within that limit + 2 mm of a ground pin of the same IC, as a proxy for the loop area.
- Each IC pin on a decoupled net must have a cap within 3 mm. Crystal nets are excluded.
- **Rotation** of 2-pad parts: turns of 90/180/270° in place that cross less or shorten the ratsnest by more than 0.5 mm.
- **Courtyards:** front and back overlaps, and THT pads inside another footprint's back courtyard. With `HW:DIN_Post` or `HW:DIN_Housing_<k>TE` on the board, that covers parts on housing posts, ribs and spacers ([DIN-rail board format](../topics/din-rail-format.md)).
Score: 100, minus a penalty per finding, down to a minimum of 0:
| Finding | Penalty |
| ------------------- | ------------------------------------ |
| crossing | 1 |
| decoupling overshoot | 1 per mm, at most 5 per cap |
| uncovered pin | 1 |
| rotation suggestion | 2 |
| courtyard conflict | 10 |
| failed pair | 5 |
## Reading the result
- **Compare scores between variants of the same board;** the absolute number means little. Some crossings come from the pinout and no placement removes them, e.g. a swapped differential pair or a USB-C's two pad rows.
- **Look at the overlay, not just the number.** The ratsnest is straight lines between pads, so it cannot see routing channels.
- **Rotation suggestions cover only 2-pad parts.** For ICs and connectors, try the turns by hand.
- `tools/placement_slots.py board.kicad_pcb slots.json [--out moved.kicad_pcb]` hill-climbs which part sits in which of a set of fixed slots (and which way it faces) against this checker's penalties. See the script's docstring for the format. It does not replace setting decoupling caps by hand: it can swap two caps out of pin order, because the ratsnest does not care.
Related: [Placer](placer.md), [Router](router.md).
|