kicad2ems.core.coupling¶
kicad2ems.core.coupling - a board's coupling, one layer at a time: many nets
named by patterns (a DDR bus, its byte lanes), each signal layer solved with
its reference planes alone, and for each victim its worst aggressors
python -m kicad2ems.core.coupling board.kicad_pcb --nets 'DQ*,DQS*'
--out out/cpl [--layers F.Cu,In2.Cu] [--solvers mom25d|lines]
[--rise 100] [--limit 3] [--mode both|next|fext] [--top 3]
[--min-length 5] [--near U1] [--z0 50] [--fmax GHz] [--sigma S/m]
The nets are those whose names match a pattern (fnmatch: DQ*, DQS?_[PN]; a
name alone is a pattern too), the board's poured nets (planes) left out. On
each copper layer where they run, each net's stretch there (its tracks on that
layer, kicad2ems.core.si.trace_ends with the layer: ended where it leaves the
layer, at a via or a pad) gets a port at its two ends; a stretch shorter than
--min-length mm (a breakout) is left out, and said. The board is imported once
with every layer's ports, and each layer is then solved on its own board file:
that layer's stretches and the ground copper of every layer (the reference
planes; mom25d takes solid planes as PEC), the selected nets' vias and their
copper on the other layers left out. So a layer's figures are its own coupling:
what crosses between layers (a via's field, a plane's gap, broadside traces) is
not in them, and the result says so.
A differential pair (its legs by their names: D0_P / D0_N, TX+ / TX-) is one
channel (--legs: two nets): it drives, and its receiver sees, in its
differential mode; crosstalk between channels of other modes is the voltage
share (S scaled by the modes' reference impedances), and each pair's own
conversion to common mode is reported. With each channel's near end driven in
turn (the near end: the one at a part
--near names, else the end nearest the layer's first net's first end), a
victim's NEXT is S(victim near, aggressor near) and its FEXT S(victim far,
aggressor near), each ports' termination z0; in time, the largest share of the
aggressor's swing at that end for an edge of --rise ps (kicad2ems.core.si's
edge response). Each layer gets the matrices of NEXT and FEXT (victim by
aggressor), each victim its --top worst aggressors and their sum (the worst
case: every aggressor's peak at once), and the worst pairs; --limit judges
the worst victim's sum (--mode: of NEXT, FEXT or the larger).
mom25d is the default solver (lumped ports: a wave port's fit takes a
neighbour's coupling out); the line model (--solvers lines) answers in seconds
for a first look, coupling only within its coupled sections on a layer.
Results: <out>/coupling.json, <out>/coupling_<layer>.png (the matrices, and
the layer's stretches coloured by each victim's sum), and each layer's run in
<out>/<layer>/.
- class kicad2ems.core.coupling.Coupling[source]¶
A board's coupling, a layer at a time (this module).
- check_with(sets)[source]¶
(usable, one line) of one of its variants (the settings `sets` fixes): its own check.
- command(values, board, out, preview=False, results=None)[source]¶
[program, argument ...] that runs it into folder `out`; ValueError: what is missing.
- figures(folder)[source]¶
The figures of the answer in `folder`, by name: [dict(name, value, unit)], or [].
- kicad2ems.core.coupling.across(ends)[source]¶
The nets of one layer's stretches ({net: (end, end)}) in their order across the way they run (the mean direction from end to end): neighbours next to each other, as the matrices are read.
- kicad2ems.core.coupling.channels(nets, pairs=True)[source]¶
The channels of a layer's nets, in their order: [dict(name, legs, kind)], kind 'single' (one net) or 'pair' (the two legs of a differential pair by their names, si._legs: D0_P / D0_N, TX+ / TX-; the positive leg first), its name the legs' common stem. pairs False: every net single.
- kicad2ems.core.coupling.groups(kb, layer, nets, apart, run=0.0)[source]¶
A layer's nets in groups: those whose tracks there come within `apart` mm of each other (through others) one group, in the nets' order; run > 0: only where one runs that near the other over `run` mm of its length or more (a close approach at a connector's pads does not chain two buses that couple nowhere else: a CM5 carrier's D-PHY, PCIe and USB-C). apart <= 0: one group.
- kicad2ems.core.coupling.layer_board(full, layer, nets, port_names)[source]¶
A board file's dict (Board.to_dict) cut to one layer's question: the `nets`' copper on `layer`, the ground nets' copper on every layer (the reference planes) and their vias, the ports `port_names`; the selected nets' vias and their copper elsewhere, and the parts, left out.
- kicad2ems.core.coupling.matrix(f, S, names, rise_s, pairs=True, z0=50.0)[source]¶
The coupling of one layer's S (nf x n x n, ports `names`: {port: (net, end)} in S's order, terminated in z0) between its channels (channels: a differential pair one, in its differential mode, as it drives and as a receiver sees it; pairs False: every net single-ended): dict(nets (the channels' names), kinds, legs, next_pct, fext_pct (victim x aggressor, % of the aggressor's swing in its mode, as voltage, for the edge; the diagonal 0), next_db, fext_db (the modes' S peaks over f, dB), next_sign, fext_sign, conversion {pair: dict(near_db, far_db, near_pct, far_pct)}: its own differential drive at its near end seen in common mode at either end).
- kicad2ems.core.coupling.merged(mats)[source]¶
Groups' matrices (matrix's dicts) as one: their channels in turn, the coupling between groups none (0 %, -300 dB).
- kicad2ems.core.coupling.modal(S, names, chans, z0=50.0)[source]¶
S of the channels' modes at their two ends from single-ended S (ports `names`: {port: (net, end)} in S's order, each terminated in z0): (Sm (nf, m, m), rows [(channel, mode, end)], zref per row). A single net is its own mode 'se' (z0); a pair its differential 'd' (2 z0) and common 'c' (z0 / 2) modes, (p - n) / sqrt 2 and (p + n) / sqrt 2 (power waves: the core's sparams.mixed_mode convention).
- kicad2ems.core.coupling.plot(res, L, path)[source]¶
A layer's figure: its NEXT and FEXT matrices, and its stretches drawn from end to end, coloured by each victim's sum.
- kicad2ems.core.coupling.ports(by_layer, near=())[source]¶
(the --port specs, {layer: {port: (net, 'near' | 'far')}}, {layer: {net: (near end, far end)}}): every layer's stretches, numbered across the layers (P1, P2, ...), each layer's ends ordered (si.order_ends).
- kicad2ems.core.coupling.run(a, echo=<built-in function print>)[source]¶
The question for parsed arguments `a`; returns coupling.json's dict.
- kicad2ems.core.coupling.select_nets(kb, patterns)[source]¶
The routed nets of board kb whose names match one of `patterns` (fnmatch, case-sensitive as KiCad's names are), in the board's order of their tracks; nets with zones (planes, pours) are not traces.
- kicad2ems.core.coupling.stretches(kb, nets, layers=None, min_length=5.0)[source]¶
({layer: {net: (end, end)}}, left out [dict(net, layer, length_mm, why)]): each net's stretch on each copper layer it has tracks on (layers: those alone), its two ends (si.trace_ends on the layer), the copper order of the board's layers.
- kicad2ems.core.coupling.summary(m, top=3, pairs=20)[source]¶
Each victim's worst aggressors and their sums, and the worst pairs, of a matrix (matrix's dict): (victims [dict(victim, worst [dict(aggressor, next_pct, fext_pct)], next_sum_pct, fext_sum_pct[, pair_leg])], pairs [dict(aggressor, victim, next_pct, fext_pct)]). A differential pair's other leg (si._legs: D0_P / D0_N) is not an aggressor: pair_leg names it.