Skip to the content.

E30 — LOGIC0..7 bus at speed and skew

   
ID E30
Date 2026-12-04
Status done: CH32 → RP Gray sequence clean at 4.8 M steps/s (RAM loop), skew ≤ 1 sample (6.7 ns) within GPIOD, ~27 ns PD → PC; RP → CH32 clean up to 6 M steps/s (the CH32 polls at 7.4 MS/s); one line carries a clean 48 MHz timer output
Decisions D112 (DECISIONS.md)
Board #1 (rev A), CH32 ×32 (HCLK 96 MHz), RP 150 MHz
Firmware + results fw/tests/2026-12-04-1-links, raw: logic.txt
Scripts links_logic.py; CH32 lgray, lskew, lcap, lpwm; RP lsamp, ldrv, freq

Summary: The 8 LOGIC lines (RP GPIO12–19 ↔ CH32 PD12 PD13 PD14 PD15 PD10 PD11 PC6 PC7, 33 Ω) were tested in both directions with a Gray-code count, so each step changes exactly one line and any sample is either the old or the new value. The CH32 writes 4.8 M steps/s from a RAM loop and the RP’s 150 MS/s PIO sampler sees every step (0 bad). Lines on the same port switch within one RP sample. Lines on PD and PC switch ~27 ns apart, because they are two writes. In the other direction the CH32’s polling loop (7.4 MS/s) is the limit, not the lines.

Results

CH32 → RP (lgray RAM loop writing BSHR tables, RP lsamp 65536 1 = 150 MS/s, lsamp gray checks every step is 0 or +1):

CH32 delay steps/µs steps seen bad samples per step (min/mean/max)
0 4.80 2097* 0 24 / 31.3 / 38
1 µs 3.00 1310 0 43 / 50.0 / 57
5 µs 1.20 524 0 118 / 125.0 / 132
20 µs 0.36 161 0 399 / 406.3 / 413

*one scripted run caught the sequence after it ended (0 steps); the manual run above it saw 2097 steps, 0 bad. The ±7-sample spread at every rate is the RP’s 150 MHz sampling against the CH32 loop, i.e. ±47 ns of jitter in the loop timing (flash/RAM bus arbitration).

Skew (lskew: all lines toggled together, RP counts samples that are neither all-0 nor all-1, 6.67 ns each):

lines edges mixed samples max per edge
LOGIC0–5 (one GPIOD write) 166 6–10 1
LOGIC0–7 (GPIOD write + GPIOC write) 166 531–539 4
LOGIC6–7 only (GPIOC) 167 0–1 1

So one port switches within ≤ 6.7 ns; the second port’s write follows 3–4 samples (20–27 ns) later.

RP → CH32 (ldrv gray <hz> DMA-fed PIO, CH32 lcap 14336 polls GPIOD/GPIOC INDR at 7.38 MS/s):

RP step rate 1–6 MHz 7.5 MHz 10 MHz ≥ 15 MHz
bad steps 0 237 5077 all

Above the CH32 sampling rate the samples skip Gray codes, which reads as errors: this is the poll loop limit, not a line limit. A DMA capture (as the DVP does at 75 MS/s on other pins) would be the next step.

One line at speed (lpwm <div>: TIM3_CH1 PWM on PC6 = LOGIC6, AF2; RP freq 18): 1, 4, 12, 24, 32 and 48 MHz (HCLK/2) all counted at −27 ppm, the HSE offset measured in E4. A 48 MHz square wave passes the 33 Ω line cleanly.

Lesson

A Gray code makes a bus test self-checking at any sampling phase. The CH32 side should not poll above a few MS/s: use a timer or DMA when the bus has to move faster.

Chip facts and numbers: fw/LEARNINGS.md. All experiments: index.