In development. It changes without notice.
The bench meter firmware — architecture
The design as it stands, at firmware 0.16.6. This page is kept current: a change to the firmware that makes a statement here false corrects it in the same commit. Where the page and the code disagree, the code and the SCPI command set win and the page is the bug; the changelog lists every change on the wire. The design as it was settled before the first image is the first design, frozen on 2026-11-22 as the record of firmware 0.1.0: a comment or a document cites this page's sections, never that one's (tests/
firmware/ test_ no_ stale_ references.py fails on a citation of the record's sections anywhere but the record and the changelog).
| Scope | The firmware of the DAQ instrument: an ESP32-S3-N16R8 on a DSX063-1 carrier, reading a TI INA228 on an R100 shunt, with a relay pair that nulls it without hands. What it does at boot, how it samples, what it keeps where, what runs on which core, and what it deliberately does not do. |
| Depends on | The INA228 reference (registers, LSBs, the range arithmetic), the carrier board's guide (GPIOs, the two USB ports, the LED), the wiring guide (the rig as wired, rev D), the SCPI command set (the protocol), the MISRA record (the coding rules and what ESP-IDF allocates), the testing guide (the host tests) |
| Sources | [DS] is TI's INA228 datasheet SLYS021A, through ina228-reference.md; ESP-IDF is the pinned 6.1.1 tree (framework-espidf 4.60101.0); the sources of the 0.1.0 design are listed in firmware-design.md's last section. |
1. The design in one page
| Question | Decision | Where |
|---|---|---|
| The sensor and its wires | TI INA228 at 0x40, SDA GPIO4, SCL GPIO5, ALE GPIO6 by the default pin map, a stored map's otherwise; the address is checked by a scan or pinned by the map, not assumed | §2.1, §2.6 |
| Bus speed | The map's boot clock, 400 kHz by default, settable from 50 kHz to 1 MHz (SYSTem:COMMunicate:I2C:FREQuency); BURST needs 1 MHz; the clock is a rewrite of the own I2C master's timing registers, nothing allocated | §2.1, §2.4 |
| Which core talks to the INA228 | Core 1 only, the sampler's, where the bus was opened; the console's transactions are routed there one at a time, and the own I2C master refuses any other core | §2.2, §2.4 |
| Bring-up | Identity, reset defaults and MEMSTAT verified; a failure is carried and every command that would invent a number is refused | §2.3 |
| Range and SHUNT_CAL | ADCRANGE = 0 by default, 1 by command; SHUNT_CAL = 0x1000 always; the shunt is corrected in software, per range | §3.1 |
| Profiles | BURST 100 µs · TRACE 280 µs · STATE 1152 µs · SLEEP 67.52 ms | §3.2 |
| Pacing | STATE, SLEEP: the ALE pin with a DIAG_ALRT read per edge, probed at every INITiate, the host timer if the probe fails; TRACE, BURST: the host timer | §3.3 |
| Primary quantity and arithmetic | VSHUNT, integer picovolts and nanoamps; floats never, not even at the print boundary of the report keys | §3.5, §3.6 |
| Null and quality | A per-range offset null with its die temperature; every report says q=uncal, stale, cal or invalid | §3.7 |
| Statistics | Computed in the loop from every sample: deviation, batch means, the maximum's place, voltage, power, the CHARGE mean, a threshold | §3.8 |
| Sinks | TRACE, BURST → a 1,048,576-sample ring in PSRAM; STATE, SLEEP → a live stream; any profile → statistics only | §3.9, §4.1 |
| The line | UART0 through the CH343P at 6 Mbps; a stream above 80 % of it is refused, never absorbed | §4.2 |
| Tasks | meter-sample (Core 1, priority 10, over static storage) and the console on ESP-IDF's main task, main (Core 0, raised to priority 5; FW-17: app_main() becomes the console and never returns), both supervised by the firmware's own watchdog on Timer Group 0 (5 s, a system reset) | §5.1 |
| The hot path | From IRAM: everything a conversion executes on Core 1, ours and ESP-IDF's, held by a gate on the linked image | §5.2 |
| The null without hands | K1 (HW-316, GPIO7) opens the DUT's lead, K2 (Relay 2 Click, GPIO15) bypasses the shunt, where the pin map puts them; released at boot before anything but the map's read, make-before-break, checked on the shunt, held 120 s at most | §6 |
| Self-test and health | *TST? reads every part back; SYSTem:HEALth? reads nothing of the device and is safe under a capture | §7 |
| The LED | Blanked at boot and never lit again | §8 |
| Radio | None, ever: serial-only, and every unused GPIO parked | §9 |
| Memory | Nothing allocates or frees from app_main()'s first line, for any command (allocs_ | §5.1, §10 |
2. The sensor, its bus and its bring-up
2.1 Pins, bus and address
| Signal | GPIO | Carrier terminal | Source |
|---|---|---|---|
| SDA | GPIO4 | left rail 4 | carrier-board.md §3, first choice |
| SCL | GPIO5 | left rail 5 | idem |
| ALE | GPIO6 | left rail 6 | idem |
| VCC | 3.3 V | left rail 1 | carrier-board.md §3, never 5 V |
| GND | ground | left rail 22 | idem |
These are the default pin map's (pinmap::
Address 0x40, the breakout's A0 and A1 straps both at ground ([DS] Table 7-2). The firmware does not trust the straps: unless the pin map pins an address, when that one alone is probed, the bring-up probes the whole space of 0x40 to 0x4F and refuses (NoDevice, §2.3) when nothing answers, and DIAGnostic:I2C:SCAN? lists every address that acknowledged, so a cold joint shows up as a wandering address instead of a silent instrument.
Bus speed. The pin map's boot clock, 400 kHz by default (PinMap::sclHz), settable at runtime from 50 kHz to 1 MHz with SYSTem:COMMunicate:I2C:FREQuency <hz> and read back by its query; *RST returns it to the map's boot clock. BURST needs 1 MHz (docs/scpi.md). Fast-mode plus is the ceiling: the own I2C master (§2.4) sets any rate of that range by rewriting its timing registers, the range ESP-IDF 6.0.3's driver offered until FW-14 (it had no high-speed-mode master code: i2c_
Two timing facts make the bus deterministic: the INA228 does not clock-stretch and does not support PEC ([DS] Figure 7-8 notes). It does not auto-increment its register pointer either: the pointer is retained ([DS] §7.5.1.1), which is what makes TRACE's read affordable (§3.5).
2.2 One core owns the bus (0.16.4, 0.16.5)
Every transaction the driver makes (a probe, a register transfer, a change of the bus clock) runs on the core that opened the bus: the sampler's, Core 1 (§5.1). Ina228Driver holds the rule by construction. Each transaction entry compares the calling core with the one openBus() ran on; there it makes its call in place, and from the other core it hands that one call to the bus's core through esp_
- What ESP-IDF's driver did (until FW-14). A probe of an address that does not answer receives the NACK interrupt, waits for the bus to go idle, masks the interrupt and returns (i2c_
master_ probe(), ESP-IDF's esp_ driver_ i2c/ i2c_ master.c). The STOP it sent after the NACK raises TRANS_ COMPLETE as the bus goes idle. When the interrupt runs on the probe's own core it preempts the wait and clears that bit while it is still enabled. When it runs on the other core, the probe has masked it first, and the bit stays latched in the peripheral. The next transaction unmasks it, the interrupt on the far core posts I2C_ EVENT_ DONE after the transaction has reset its event queue, and the transaction takes it for its own completion: it returns ESP_OK at once with its transfer still on the wire. A probe so answered reports a device that is not there; a register read returns its zeroed buffer, and its own completion stays latched for the next one. A register transfer that meets a NACK (a breakout that stops answering, a loose header wire) takes the same path in the driver (s_ i2c_ send_ commands(), then the interrupt masked in s_ i2c_ transaction_ start()), so from the far core it leaves the same latch. - What the bench showed (2026-11-21, a diagnostic image reading I2C0's INT_RAW before and after each probe): from Core 0, every probe of a silent address ended with TRANS_
COMPLETE latched (INT_RAW 0x8292 where a probe of 0x40 left 0x8212), the probe after it returned ESP_OK, and the scan listed seven or eight of 0x40…0x4F, a different set each time, at 400, 100 and 50 kHz. Every DIAGnostic:REGister? after it read 0x0000 with no error until a transaction failed, or one ran on Core 1 (*TST?'s probe), and reset the state; the second scan of one session rebooted the chip (reset=panic). Run on Core 1, every probe of a silent address left 0x8212, as the probe of 0x40 does, and six scans at 400 and 50 kHz listed 0x40 alone with the identity reading right after each. - What moved to Core 1 in 0.16.5. Every transaction the console made from Core 0: DIAGnostic:REGister? and DIAGnostic:ALERt?; *TST?'s identity, SHUNT_CAL and DIAG_ALRT reads and the writes its pacing probe needs; the null path's V_SHUNT reads around each relay step (ROUTe:NULLpath ON, with its ADC_CONFIG writes); a range change (CONFIG, RSTACC and the two DIAG_ALRT reads around the discarded period, from SENSe:CURRent:RANGe and *RST); SENSe:CHARge? and SENSe:CHARge:RESet; a capture's and a null's setup in beginCapture() (the profile's ADC_CONFIG, DIAG_ALRT and clip limits, the consistency read, the boundary temperature with its triggered conversion, the charge read, the stale-flag clear) and their close in stop() and finishZero(); and a change of the bus speed (SYSTem:COMMunicate:I2C:FREQuency, *RST), the device handle's re-creation until FW-14 and a rewrite of the timing registers since. The capture loop, which takes every sample of a capture and of a null, the pacing probe and the boot's bring-up already ran on Core 1 and make their calls in place, as before.
- What the host tests hold. Until FW-14 the harness modeled ESP-IDF's driver: its bus remembered the core that created it, a NACKed probe or register transfer from the other core latched a completion the next transaction from that core took, and every call into the I2C master from the other core was counted; before 0.16.5's change 103 of the 208 firmware cases failed on it, among them a register read after a failed one returning 0x0000 as ESP_OK. From FW-14 it models I2C0's registers (§2.4), and every case that boots a Bench fails when they were reached from a core other than the one that clocked them; the driver's own cases ask each transaction from the far core by name and check that it reached the wire. The harness sees only the paths a test runs, so a source gate (tests/
firmware/ test_ i2c_ on_ bus_ core.py, every test run) reads firmware/src and fails on a call into I2C master anywhere but where the routing owns it: begin() in openBus(), the transfers, the probe and the clock change in makeCall(), and the in-place branch of onBusCoreNow() ? in the three IRAM entries; and on any call of ESP-IDF's I2C master, which the image no longer links (scripts/ check_ drivers_ absent.py). A planted call of each kind proves it still sees one.
On the bench (2026-11-21, 0.16.5's clean build, ELF 44038b5fc6701826, the T-Deck asleep behind K1 at about 41 µA): 100 of 100 *TST? answered 0; 20 scans listed 0x40 alone; 200 rounds of DIAGnostic:REGister? 0x3E and 0x3F and DIAGnostic:ALERt? read 0x5449, 0x2281 and memstat=1 every time; a range change to 1 and back, MEASure:CURRent? on both ranges (40.7 to 41.6 µA), STATE and SLEEP statistics captures of 15 s (pace=alert, 8 edges, pace_err_ppm +100 and +103, 0 dropped, 0 stale, 0 read errors) and a null-path cycle all ended with no error, allocs_
What a routed transaction costs. ESP-IDF's IPC call takes two static semaphores and allocates nothing, and the IPC task polls the own master's transaction to its end on Core 1 (§2.4). It runs at the caller's priority (CONFIG_
Should the IPC call be refused, nothing is made: the scan reports nothing (found=- n=0) and a transaction returns the refusal (ESP_
2.3 Bring-up and identity
Ina228Driver::
| Step | Action | Verdict if it fails |
|---|---|---|
| 1 | probe 0x40 to 0x4F, or the one address the pin map pins | NoDevice |
| 2 | CONFIG ← 0x8000 (RST, self-clearing), then a settle longer than TPOR ([DS] §6.5) | BusError |
| 3 | MANUFACTURER_ | NotIna228 |
| 4 | ADC_CONFIG == 0xFB68 and SHUNT_CAL == 0x1000, the documented reset values, which also prove MSB-first framing ([DS] §7.5.1.1) | BadResetDefaults |
| 5 | DIAG_ALRT bit 0 MEMSTAT == 1: the trim memory's checksum ([DS] Table 7-16) | TrimChecksum, a hard stop |
| 6 | SHUNT_CAL ← 0x1000 explicitly, as every power-up of the part requires ([DS] §8.2.2.3), then CONFIG for range 0 | BusError |
The verdict is carried, not thrown away. On anything but Ok the console queues one -241 (Hardware missing) at boot with the reason in its detail (bringUpReason(); a stored bus that could not fall back is one 117 in its place, §2.6), *TST? says so, and every command that would report a number from a part that did not come up is refused by name.
A free consistency check, at every INITiate. CURRENT_LSB is V_LSB / R exactly in both ranges (§3.1), so CURRENT counts track VSHUNT counts one for one up to the device's own rounding; the capture header reports the difference as vs_cur_delta=, and anything beyond ±2 counts says SHUNT_CAL is not what the firmware wrote.
2.4 The own I2C master (FW-13, FW-14)
ESP-IDF's I2C master keeps its bus object, five semaphores, a queue, the port's handle slot and each device's object on the heap, claims its interrupt through the allocator, and changes the bus clock by removing the device's object and allocating it again: 12 allocations at boot (allocs_
- Set-up. i2c_
bus:: begin() gates I2C0's bus clock on and pulses its reset under ESP-IDF's peripheral clock lock, selects the 40 MHz crystal (I2C_ CLK_ SRC_ DEFAULT), sets master mode with open-drain pads and no arbitration, both FIFOs in FIFO mode and most significant bit first, a glitch filter of 7 cycles and the SCL time-out at 2 ms (2^17 cycles, ESP-IDF's driver's default for a device), enables the four statuses a transaction waits for (the controller's interrupt source is routed to no CPU line, so no interrupt is raised), sets the clock, and gives the two pads to the controller through the GPIO matrix as ESP-IDF's driver does: driven high, open drain, the internal pull-ups on, the output enable the peripheral's, both input signals read back from the pads. It records the core it ran on as the bus's. - The clock. Any rate from 50 kHz to 1 MHz, the range of SYSTem:COMMunicate:I2C:FREQuency, is set by rewriting the timing registers with the HAL's own arithmetic (i2c_
ll_ master_ cal_ bus_ clk()) and latching them (i2c_ ll_ update()): i2c_ bus:: setClock() resets nothing and frees and allocates nothing, so the command kept its range through FW-14 and the protocol did not change. Ina228Driver:: setBusSpeed() makes it on the bus's core, and *RST makes it only when the clock is not 400 kHz already. - A transaction. probe(), write(), read() and writeRead() each write one command list into the controller's eight command registers and its bytes into the 32-byte transmit FIFO: a START, the address byte, the bytes written, a repeated START and the read address for a read, the bytes read with the last one not acknowledged, and a STOP (at most 30 bytes each way). The caller then polls the interrupt status until the STOP's completion, a NACK, the controller's time-out or a lost arbitration, within 20 ms of esp_
timer_ get_ time() (the xfer_ timeout_ ms Ina228Driver gives ESP-IDF's calls). A NACK ends the transaction once the bus is idle again, after the STOP the controller sends, and every status is cleared before the next one starts: no completion is left latched for a later transaction to take for its own, the fault of ESP-IDF's driver §2.2 records. A NACK answers ESP_ ERR_ INVALID_ RESPONSE (ESP_ ERR_ NOT_ FOUND from a probe), as ESP-IDF's driver does; a command that meets one reports i2c ESP_ ERR_ INVALID_ RESPONSE. - Recovery. A time-out, a lost arbitration, a bus still busy after a NACK's budget, and a bus busy before a transaction starts reset the controller and restore its configuration, clock nine SCL pulses so that a device holding SDA low inside a byte finishes it and lets go, wait the pulses out, and reset and configure it again; the second reset also clears the pulse generator's enable, which ESP-IDF's LL says cannot be read back on this chip. The transaction answers ESP_
ERR_ TIMEOUT, or is not started when the bus stays busy through the pulses. i2c_ bus:: clearBus() asks for the same recovery. It is out of IRAM, a cold exit of the gate. - One core, one at a time. Every call but begin() is refused from the other core with ESP_
ERR_ INVALID_ STATE before it touches a register, and so is one that starts while another runs on the bus's core (a task or an IPC call that preempted it): the preempted transaction completes untouched. The protocol already keeps the console's transactions and a capture apart (the R flag of docs/scpi.md, above); the refusal makes a breach visible as an error instead of two command lists interleaved in the registers. - On the bench (FW-14, 2026-11-22, ELF 45c88011a4310051, against FW-12's image b7f6e739ae8cee1f on the same rig an hour before, the T-Deck asleep behind the shunt at about 44 µA): 0.16.5's acceptance (§2.2) repeated, 100 of 100 *TST? 0, 20 scans at each of 400, 100 and 50 kHz with 0x40 alone, 200 rounds of the identity right; 15 s statistics captures with 0 read errors, dropped and stale edges, pace_err_ppm +86 (STATE), +87 (SLEEP), 0 (TRACE) and 0 (BURST at 1 MHz), where FW-12's image read +90, +88, 0 and 0; the null path's STATE floor 18.85 µA, where FW-12's read 18.81 and 18.86. Polling the transaction on Core 1 instead of waiting for ESP-IDF's interrupt moved neither the pacing nor the noise, so the fallback the plan kept (an interrupt on the static route, with a static semaphore) was not needed. allocs_
since_ main fell from 35 to 23, and three clock changes leave every heap count as it was (tests/ bench/ test_ i2c_ bench.py). - The host tests. The harness models I2C0's registers (sim::I2c, firmware/
test/ native/ harness/ sim.h): the clock and reset, the configuration, the timing staged and latched, both FIFOs, the command registers, the statuses appearing at the bit times the latched clock gives each transaction, and the INA228 model on the far side, whose own faults (a transaction failed by count or by register, a caller stalled) are NACKs and waits on the wire since FW-14, when the fake of ESP-IDF's driver went; and it can arm NACKs on an address or a data byte, a time-out that leaves the state machine stuck until a reset, a NACK whose STOP never comes, a device that holds SDA low until the pulses (or for good), and a controller that never answers. Every Bench and Scope fails a case that reached I2C0 from a core other than the one that clocked it, unclocked, or its clock outside the lock, started a transaction unconfigured, over another or from a command list the hardware would not run as meant, or overran or underran a FIFO. firmware/ test/ native/ test_ i2c_ bus.cpp holds the set-up and its refusals, the clock across its range, each transaction's list on the wire, NACKs, the time-out, a stuck bus, a silent controller, the recovery and both refusals; i2c_bus.cpp is at 100 % of lines, branches and MC/DC conditions (the branch baseline was 122 after FW-14; it is 0 since FW-29, docs/ testing.md). firmware/ test/ native/ test_ ina228.cpp holds the driver on it: every transaction from the far core reaches the wire on Core 1, a clock change at every rate of the range rewrites the timing and asks ESP-IDF for nothing, and a pin or clock begin() refuses leaves the bus closed. tests/ firmware/ test_ i2c_ on_ bus_ core.py holds I2C0's registers to i2c_bus.cpp alone.
2.5 The pin map's record (FW-03)
The pin map (firmware/
The record (firmware/
2.6 The boot from the pin map (FW-04)
app_main() reads the stored map before it drives a pin (pin_
What the read adds before the relays are released: 196 µs with an empty log, 537 µs with one record, and 13.0 ms with 135 records in the log, one short of both sectors full, of which each record's header, bytes and CRC-32 cost about 95 µs (esp_timer around pin_
The fallback. The bus is the one part of a map a boot can prove, because the INA228 answers on it or it does not. When a stored map's bus gets no answer (NoDevice, or a transaction that fails), the default bus (SDA on GPIO4, SCL on GPIO5, both pulls, the address scanned, 400 kHz) takes its place if the map with that bus is still one pinmap::
On the bench (FW-04, 2026-11-25, ELF d64cfbef9f136e24, the first image with the pins partition of §2.5 to run on the meter): SYSTem:PINS? read the default map, src=default verified=1 table=0x90072FE9, *TST? 0, kleidos-meter calibration verify applied before and after the bench suite (the partition table's change left the calibration log as it was), and DIAGnostic:HEAP? pre_
2.7 A map applied, proved, or put back (FW-05)
SYSTem:PINS:APPLy and SYSTem:PINS:DEFault change the map without a reflash (the SCPI command set, "The pin map"). The console refuses them under a window, with any coil energized and for a map the rules refuse, so a move starts with every relay released and the sampler asleep. pin_
- The relays (relay::
Bank:: move()), on the console's core: each new pin's latch at its released level before the pad is an output, as at the boot (§6.1). A pin a relay leaves, unless another role takes it, is parked toward the level that released that relay: pull-up for an active-low part, pull-down for an active-high one. A pull-down on an active-low module's input is a path through its input LED, so the pin is parked the other way; the next boot parks it low like any other no role holds, which leaves Relay 1 released on the rig (below, "On the bench"). - On the bus's core, through Ina228Driver::
runOnBusCore() (esp_ ipc_ call_ blocking(); in place when the bus is the console's core's, §2.2): ALERT moves (Sampler:: moveAlert(): the old pin's enable, status and edge type cleared, the new one set as begin() sets it, the CPU line and its handler unchanged); the bus is forgotten (closeBus()); every pin no role holds any longer is parked, which takes the old pads off the controller's outputs so that they carry nothing of the bus that moves; and pin_ boot:: bringUpOn() opens the bus on its new pads and brings the INA228 up, the boot's own sequence. Two roles may change places: each step configures its own pads whole, and a pad another role of the new map holds is never parked.
The proof is the bring-up (§2.3) and the self-test's parts a map reaches (Console::
The one exception is an IPC call the bus's core refuses, which ESP-IDF does only before its scheduler runs: ALERT and the bus have then not moved, so even DEFault is put back rather than report a map the bus is not on.
firmware/
On the bench (FW-05, 2026-11-25, ELF 0e07120e923709dd, the T-Deck asleep behind the shunt): SDA on GPIO18, SCL on GPIO18, the pair swapped and the address pinned to 0x41 were each put back with one 117 (reason=no_
3. What is measured, and how
3.1 Range and calibration
| Register | Value | Why |
|---|---|---|
| CONFIG (0x0) | 0x0000 on range 0, ADCRANGE set on range 1 | TEMPCOMP = 0, CONVDLY = 0 |
| SHUNT_CAL (0x2) | 0x1000 = 4096, always | Exact in both ranges; also the reset value |
| SHUNT_TEMPCO (0x3) | 0x0000 | Left off (§11) |
ADCRANGE = 0 is the default and the range a campaign needs. It covers 10 µA to 1.6384 A in one setting, range 1 clips at 409.6 mA, and across [DS] Table 8-2 the noise ratio of range 1 to range 0 has median 1.000: the quantizer is dithered by 16 LSB of noise, so averaging recovers resolution far below the LSB either way (ina228-reference.md §8.2). SENSe:CURRent:RANGe:INDex 1 stays a manual choice for a run guaranteed to stay under 409.6 mA, refused while a window runs, because a switch costs a discarded conversion period, an RSTACC and that range's own null.
What range 1 buys is a smaller margin, and the Kleidos campaign takes it where it is safe. The host's uncertainty model charges the INL as ±2 m% of the range's full scale, 32.8 µA on range 0 and 8.2 µA on range 1, and half a count of quantum, 1.56 against 0.39 µA. So the Kleidos QA harness selects SENSe:CURRent:RANGe:INDex 1 itself for the captures whose stored windows its power store has shown could not hide a conversion past 300 mA (TD-08's floor and TD-16's lsleep and c3 plans), with a null of that range; refuses any capture that reaches 73 % of its range's full scale or clips (the clip detector, §3.5); repeats such a range-1 capture once on range 0, with range 0's null, when the run needs no hands; and puts the instrument back on range 0 when the row ends (the Kleidos firmware repository's qa/
SHUNT_CAL is never corrected. The ×4 the datasheet asks for ADCRANGE = 1 cancels exactly the 4× smaller CURRENT_LSB of that range, so 4096 is right in both ([DS] §8.1.2 Equations 2–3, worked in ina228-reference.md §8.3).
The measured shunt is applied in software, as shunt_uohm, one value per range (SENSe:CURRent:SHUNt:RANGe<n>, from 0.4.0). A SHUNT_CAL correction would have 1/4096 granularity where shunt_uohm has 1/100000, and it would apply to CURRENT, POWER and CHARGE and not to VSHUNT, the primary path (§3.5), which is a split brain in the one place an instrument must not have one. The factor 100000 / shunt_uohm is applied on the device to every quantity it reports but the raw CHARGE count (§3.6), and the capture header names it.
3.2 The four profiles
The requirements are five orders of magnitude apart in current and in time, and no single AVG setting both resolves 10 µA and shows a BLE peak (ina228-reference.md §8.4), so they are four configurations of one instrument, chosen per run (SENSe:PROFile). Each ADC_CONFIG word is derived from the [DS] §7.6.1.2 field encodings by adcConfigWord() and checked by a static_assert against the value stated here; none is a copied literal (kProfileSpecs, firmware/
| BURST | TRACE | STATE | SLEEP | |
|---|---|---|---|---|
| The job | Resolve a transient | Shape a burst | Measure a state | Measure deep sleep |
| MODE | Ah shunt only | Ah shunt only | Fh bus + shunt + temp | Fh bus + shunt + temp |
| Period | 100 µs (two conversions) | 280 µs | 1152 µs | 67,520 µs |
| Sink | ring | ring | stream | stream |
| Pacing | timer | timer | alert pin | alert pin |
| Bus | 1 MHz | 400 kHz | 400 kHz | 400 kHz |
A conversion lasts ( VBUSCT + VSHCT + VTCT ) × AVG over the inputs the mode enables, because they convert sequentially and averaging repeats the whole sequence ([DS] §7.3.4), and a sample is one conversion on every profile but BURST, which takes every second one: its loop cannot read a 50 µs conversion inside 50 µs, so its period is stated as two (conversionsPerSample), which keeps t0 + index × period honest. The reasons behind the choices, each kept beside its row in kProfileSpecs:
- AVG = 1 on the ring profiles. Averaging dilutes an event shorter than its window: at AVG = 16 a 1 ms, +100 mA burst shows up once, as +22 mA. At AVG = 1 it spans three to four TRACE samples. Average afterwards, on the host, where the raw samples are still there.
- Temperature on STATE and SLEEP, for 50 µs a period: the die temperature is what says the null has gone stale (§3.7). TRACE and BURST take it at the boundaries instead, one triggered conversion (MODE = 4h) before the first sample and one after the last, outside the capture, because writing ADC_CONFIG restarts a conversion in progress ([DS] §7.3.4); the header carries die_mc_start= and the close die_mc_end=.
- BURST buys time resolution and nothing else. The 50 µs conversion is noisier per point, its mean is not a level, and its offset is its own (§3.4): a null taken on another profile does not apply to it. Use BURST to see an event and STATE to put a number on a level.
What each profile is worth. A shorter conversion is noisier per point by roughly the square root of the ratio of the windows, so the mean of a whole second is no better on BURST than on TRACE:
| BURST | TRACE | STATE | SLEEP | |
|---|---|---|---|---|
| Sample rate | 9,898 Sa/s | 3,571 Sa/s | 868 Sa/s | 14.81 Sa/s |
| Per-sample noise | ≈84 µA rms | ≈35 µA rms | ≈21 µA rms | ≈2.3 µA rms |
| After 1 s of host averaging | ≈0.84 µA rms | 0.59 µA rms | 0.73 µA rms | 0.60 µA rms |
BURST needs a 1 MHz bus, and the rule is half the period. One retained read costs about 38 µs at 1 MHz and 95 µs at the 400 kHz default (§3.5). INITiate refuses a ring profile whose read does not come in under half its period (firmware/
The averaging override (0.18.0, FW-06). A profile's averaging count and shunt conversion time are its definition, and they can be overridden as a measurement setting, off by default, for a run that wants the INA228 to average (SENSe:AVERage, docs/scpi.md "The averaging override"). The sampler keeps one override per profile (Sampler::
What paces a profile says what it can be given, and a setting outside it is refused before it changes anything:
- BURST has no override. Its 50 µs conversion is its definition, and its loop already takes every second one.
- The shortest period is over twice the bus time a sample's reads take at the running clock, the margin the ring profiles' rule above measured: 525 µs of reads on STATE and SLEEP at 400 kHz (four registers, §3.5) and 210 µs at 1 MHz, so 1051 and 421 µs; one retained read on TRACE, so 191 µs at 400 kHz. On TRACE it is never under 100 µs, the period BURST's loop keeps (§3.4) and the shortest shown. It is judged when the override is set and again at INITiate, because the bus clock moves at run time. At the fastest clock it keeps a four-channel stream inside its share of the line (a static_assert, as for the profiles' own).
- The longest period is 200 ms, kCaptureFeedUs: the loop then checks in with the watchdog at least once a sample, a stop is acknowledged inside its 500 ms even on a dead ALERT wire (two periods and 10 ms, §3.3), and INITiate's first conversion and eight probed ones hold the console 1.8 s, under half the watchdog's 5 s. static_asserts hold the three. Averaging longer than that is the host's, which loses nothing by it (§3.8).
*TST?'s probe is STATE's own word whatever the override.
On the bench (FW-06, 2026-11-25, ELF 512499c7a306c77a, the T-Deck asleep behind the shunt, tests/
| STATE | ADC_CONFIG | period_us | pace_err_ppm streamed | Null path sd_na (samples) | Against AVG 1 | The square root says |
|---|---|---|---|---|---|---|
| off (AVG 1) | 0xF140 | 1,152 | (+96 on the null path) | 18,850 (13,101) | 1 | 1 |
| AVG 16 | 0xF142 | 18,432 | +98 | 4,854 (819) | 1 / 3.88 | 1 / 4 |
| AVG 64 | 0xF143 | 73,728 | +96 | 2,378 (204) | 1 / 7.93 | 1 / 8 |
The periods next to each limit were kept too, 15 s of statistics each with nothing lost: STATE 4 × 50 µs (600 µs) and 1 × 540 µs (640 µs) at 1 MHz at +102 and +100 ppm, STATE 4 × 280 µs (1,520 µs) at 400 kHz at +102, TRACE 4 × 50 µs (200 µs) at 400 kHz and 1 × 150 µs at 1 MHz at 0, SLEEP 512 × 280 µs (194.56 ms) at +103, every ALERT-paced one on ALERT. A second run of the suite an hour later read 18,819, 4,685 and 2,553 nA on the null path and kept every period again. In both runs the STATE 4 × 280 µs capture counted one stale edge, where 25 one-second captures and a 60 s one of the same override counted none: its first sample came 1,619 and 1,616 µs after the start at a 1,520 µs period, so a conversion had ended while the start's own DIAG_ALRT read released the pin, and its edge found no flag. Only that conversion is lost, and the profiles' own periods have the same window.
The conversion time changes the offset. The null path's means above were −3.2, −2.7 and −2.1 µA at AVG 1, 16 and 64, and CHARGE, which sums every conversion whatever the count, read −3.5, −3.1 and −2.4 beside them: a drift along the three captures that the count had no part in. The conversion time is another matter. At AVG 16, the sleeping T-Deck, three interleaved 6 s captures of each time, read 41.6 µA at 2,074 µs, 41.4 at 1,052, 41.3 at 540, 40.8 at 280, 40.5 at 150, 39.2 at 84 and 25.8 at 50 µs: the 50 µs conversion's own offset that BURST shows (§3.4), 15.6 µA below the others, whatever it is averaged by, and 2 µA at 84 µs. So an override of 50 or 84 µs is for seeing an event, not for a level, and a null taken on another time does not apply to it.
3.3 Pacing
Two ways to know a conversion is ready: the ALE pin (DIAG_ALRT CNVR = 1, APOL = 0: active low, open drain), whose falling edge an interrupt on Core 1 turns into a binary semaphore the sampler takes; and the host timer at the profile's nominal period, esp_
What the pin does (bench, 2026-11-20, a probe build that counted and timed the edges). CNVRF is set "after all conversions and averaging is completed" and clears on reading DIAG_ALRT or writing ADC_CONFIG ([DS] §7.3.4), and the pin follows CNVRF: it goes low at a conversion's end and stays low until DIAG_ALRT is read, in either ALATCH mode. A reader that reads DIAG_ALRT after each edge sees one edge per conversion:
| Profile, ALATCH = 1, one DIAG_ALRT read per edge | Edges per second | Expected | Missed, extra | Interval sd | CNVRF set at the read |
|---|---|---|---|---|---|
| STATE (1,152 µs) | 868.0 | 868.06 | 0, 0 | 0.5 µs | 100 % |
| SLEEP (67.52 ms) | 14.81 | 14.81 | 0, 0 | 3.5 µs | 100 % |
| TRACE (280 µs) | 3,171 | 3,571 | 4,000 in 10 s | 92 µs | — |
TRACE cannot be paced so: the edge, the wake and a DIAG_ALRT read take about 145 µs at 400 kHz, the loop misses one conversion in nine, and the read would move the retained VSHUNT pointer the profile's period rests on (§3.5). BURST is shorter still. So the instrument paces by profile and measures the pin at every INITiate (0.9.0):
On pace = alert the loop takes the semaphore, stamps the sample with the time it woke (the conversion's end, before the reads' bus time), reads DIAG_ALRT first (which releases the pin for the next conversion and ORs the latched clip bits into flags=), then the profile's registers. An edge whose DIAG_ALRT read finds CNVRF clear had no conversion behind it: it takes no sample and is counted as stale_edges= in FETCh:STATistics?. Starting the loop also reads DIAG_ALRT once after enabling the interrupt, because a conversion that ended since the start's last read left the pin low with no edge. A wait that times out (two periods and 10 ms) means the pin stopped: the capture falls back to the timer from there and says pace_
On pace = timer the INA228's oscillator (±0.5 % at 25 °C, ±1 % over temperature, [DS] §6.5 FOSC_TOL; about +90 ppm on this part) and the S3's crystal drift apart, so a long ring occasionally repeats or skips a conversion at a rate bounded by that skew; the drift anchors (§4.1) let the host see the real times. pace_err_ppm in FETCh:STATistics? compares the achieved period, from the first sample to the last over samples - 1 (0.15.0), with the nominal one: on a timer-paced capture it measures whether the loop kept its own deadline, on an alert-paced one the INA228's oscillator. A timer-paced loop that arrives more than a period past its deadline re-bases the deadline to the arrival instead of reading back to back, and counts it in rebased= (0.14.0).
Where and in what order the probe runs (0.16.2, 0.16.3). Up to 0.16.1 the console ran the probe on Core 0 and released the pin before arming the interrupt; a late read there let a conversion end on a pin still low, which makes no edge, and a conversion that ended between the release and the arm left the pin low for the whole window. On the NW-00 spike's image (2026-11-21, 40 probes a state) the console's probe chose timer in 6 of 40 with the station sending 200 kB/s and in 20 of 40 with the SoftAP sending; run in the sampler task and armed first, it chose alert in every probe under either radio, waking 15–17 µs after the edge at the median. Since 0.16.2 the console asks the sampler task for the probe and waits for its answer (8 periods and 500 ms), and an answer that does not come is pace=timer; since 0.16.3 it asks only a task that is waiting for a start, so a stop the loop has not acknowledged (107) makes the probe say timer at once.
*TST? lets a conversion end before its probe (0.16.4). A conversion that ends inside the ADC_CONFIG write pulls ALE low, and the write clears CNVRF behind it ([DS] §7.3.4): the pin stays low, no read releases it, and the probe counts no edge. On the bench 6 of 60 *TST? calls failed so; Sampler::
3.4 The sampler task on the bench (0.9.0)
Measured on 2026-11-20 on instrument KM-0000000000, firmware 0.9.0 (image meter, ELF 9f812041835d2a89, a clean build), in the real sampler task (Core 1, priority 10), the DUT a T-Deck behind K1 and also on its USB supply (about 38 µA through the shunt), the bus at 400 kHz except for BURST at 1 MHz. STATE and SLEEP streamed i_ua for 60 s each, three times; the intervals are the stream's own t=; a gap over 1.5 periods counts as missed conversions, one under half a period as an extra.
| Capture | Header | Samples | stale_edges | Missed, extra | Interval mean, sd (min–max) | pace_err_ppm |
|---|---|---|---|---|---|---|
| STATE × 3, 60 s | pace=alert pace_edges=8 pace_expect=8 | 52,156 / 52,142 / 52,145 | 0 | 0, 0 | 1,152.11 µs, 2.2 µs (1,018–1,283 µs) | +78 / +82 / +74 |
| SLEEP × 3, 60 s | pace=alert pace_edges=8 pace_expect=8 | 889 / 889 / 890 | 0 | 0, 0 | 67,526.2 µs, 3.6–3.8 µs (67,516–67,539 µs) | +57 / +55 / +60 |
| TRACE × 3, 10 s | pace=timer pace_edges=0 pace_expect=0 | 35,912 / 35,912 / 35,887 | 0 | — | 280.008 µs (dur_us / samples) | +28 / +28 / +25 |
| BURST × 3, 10 s, 1 MHz | pace=timer pace_edges=0 pace_expect=0 | 99,202 / 99,162 / 99,171 | 0 | — | 101.36 µs | +13,590 / +13,600 / +13,600 |
Every capture closed with dropped=0 read_err=0 pace_
BURST does not keep its period, and that is the loop. A timer-paced pace_err_ppm compares the achieved period with the S3's own clock, so it cannot see the INA228's oscillator: TRACE on the same loop reads +28 ppm. BURST's +13,600 ppm is its loop costing 101.36 µs a sample against a 100 µs deadline. One more esp_
-O2 keeps BURST's period (0.14.0). Every image before 0.14.0 was built at IDF's default -Og; the per-sample work 0.10.0 to 0.12.0 added had put BURST's loop at 103.5 µs against its 100 µs deadline (+35,000 ppm). Moving the interrupts to Core 1 gave back 0.4 µs (103.1 µs, +31,000 ppm); CONFIG_
A late timer-paced loop is re-based (0.14.0). Before, the deadline only ever advanced by a period (nextDeadlineUs_ += periodUs), so a loop that came late by more than one, a stalled read or a preemption, read back to back until the deadline caught up, taking the same conversion more than once. waitUntil() now returns the clock as it first read it, at no extra read, and an arrival more than a period past the deadline re-bases the deadline to the arrival and counts it in FETCh:STATistics?'s rebased=. A ring's implicit t0 + index × period is off after a re-base until the next anchor, which the count says.
pace_err_ppm from the first sample, not the start (0.15.0). Up to 0.14.0 the achieved period was dur_us / samples, and dur_us runs from the capture's start: on an alert-paced capture the first edge comes at the part's own phase, anywhere up to a period after the start (65.8 ms of SLEEP's 67.5 ms on this rig, 0.5 ms of STATE's 1.15 ms), so the figure read that phase as an error of up to 1 / samples. That is why SLEEP read 30 to 60 ppm below STATE above, on one oscillator. Measured on 2026-11-21 (T-Deck asleep, 2 × 20 s STATE, 2 × 30 s SLEEP): the streams' own intervals gave +94.3 to +95.9 ppm on both profiles; 0.14.0 reported +61 and +63 (STATE), +35 and +37 (SLEEP); 0.15.0, which takes the span from the first sample to the last over samples - 1, reported +94, +95, +93 and +90, each within 1 ppm of its stream. On a timer-paced capture the first sample's own read latency is all that is left at the span's ends (TRACE: −18 ppm over 5 s, a 95 µs read against 5 s). The pace_err_ppm figures of the tables above are the earlier estimate's.
BURST reads its own offset. The 0.8.0 session's BURST mean of −4.3 µA beside +11 to +13 µA on the other profiles repeated here: under the DUT, BURST read 20.6 to 21.0 µA where TRACE, STATE and SLEEP read 36.8 to 41.5 µA, and on the null path −7.5 µA where the others read −3.4 to −5.3 µA. The hardware CHARGE accumulator says the same with the bus silent: after a capture closes the device keeps converting on its word, so SENSe:CHARge:RESet, 20 s with no I²C traffic and SENSe:CHARge? integrate one conversion time alone. Raw (no null applied), twice each, the 50 µs conversion integrated 32.1 and 32.3 µA where 280 µs and 1,052 µs integrated 58.4 to 60.3 µA under the DUT, and 5.8 and 6.1 µA where they integrated 15.0 to 16.2 µA on the null path (whose check said unverified, the DUT drawing microamps). So the deficit belongs to the 50 µs conversion itself, not to the bus traffic or the loop: its offset differs from the longer conversion times' by about 1 µV on the null path and by 2.7 µV under the DUT (the common-mode and the load differ between the two). A null taken on another profile does not apply to BURST, and its mean is not a level, as its entry in the profile table of sampler.cpp already says ("use it to see an event, not to put a number on a level"); a per-conversion-time null is the registry's question, not this change's.
3.5 What is read per sample
| Profile | Per sample | Bus time | At the window's boundaries |
|---|---|---|---|
| BURST | VSHUNT only, pointer retained | about 38 µs at 1 MHz | DIETEMP (triggered), DIAG_ALRT, CHARGE |
| TRACE | VSHUNT only, pointer retained | about 95 µs at 400 kHz | DIETEMP (triggered), DIAG_ALRT, CHARGE |
| STATE | DIAG_ALRT (it releases the ALE pin, §3.3), VSHUNT, VBUS, DIETEMP | about 526 µs | CHARGE |
| SLEEP | DIAG_ALRT, VSHUNT, VBUS, DIETEMP | about 526 µs | CHARGE |
VSHUNT, not CURRENT, is the primary. CURRENT_LSB = V_LSB / R exactly in both ranges (§3.1), so CURRENT carries no information VSHUNT does not; VSHUNT is untouched by SHUNT_CAL, so a mis-programmed calibration cannot corrupt the primary number, only be detected (§2.3); and it is the raw quantity the software shunt correction divides and the null subtracts, in the units it was measured in.
POWER is never read. TRACE and BURST do not produce it (MODE = Ah, [DS] §7.3.2), and on the bus profiles it is computed from VBUS and the corrected current (§3.6), which costs no bus time and sidesteps the register whose 24 bits have no reserved nibble ([DS] §7.6.1.9).
DIAG_ALRT is read every sample on SLEEP and on every alert-paced capture, and at every close, to catch MATHOF (bit 9, "current and power data may be invalid", latched until a new conversion or RSTACC, [DS] Table 7-16) and the clip detector's SHNTOL and SHNTUL (below); the close reports flags=0x…, and a window with MATHOF set is q=invalid.
The clip detector. On SLEEP a sample averages 16 conversions, so a sample well under full scale can hide one conversion that clipped. The INA228's shunt comparator sees every raw conversion (SLOWALERT = 0), and the firmware arms it at full scale: SOVL = 7FF8h and SUVL = 8008h, eight limit counts (128 VSHUNT counts, 0.024 %) inside each end on either range, written at every INITiate and CALibration:ZERO, with ALATCH = 1 so that SHNTOL and SHNTUL hold until the next DIAG_ALRT read and reach the close's flags= (firmware/
The boundary CHARGE reads are the capture's own, charge_
The retained pointer is what makes the ring profiles affordable: "If repeated reads from the same register are desired, it is not necessary to continually send the register pointer bytes" ([DS] §7.5.1.1). The driver writes the pointer once (setPointer()) and then only reads three bytes a sample (readRetained()); the bus profiles change pointers and use a write-read per register. That one write must take: the start's last read leaves the pointer on DIAG_ALRT, so a failed write would make every read return DIAG_ALRT's bytes as shunt counts, with no read failing. Sampler::
3.6 The conversion arithmetic — integer, exact, no float
The measurement path carries no floating point, and neither does the print boundary: every value on the wire is formatted from integers in the device's own units (firmware/
Decoding the wide registers ([DS] §7.6.1.5–7.6.1.11): VSHUNT, VBUS and CURRENT carry a 20-bit signed value in bits 23 to 4 with four reserved bits below, POWER uses all 24, and CHARGE is 40 bits signed. decode20() and decode40() sign-extend them.
The LSBs, as exact integers, from [DS] §7.6.1 and §8.1.2 with SHUNT_CAL = 4096:
| Quantity | ADCRANGE = 0 | ADCRANGE = 1 | Integer constant |
|---|---|---|---|
| VSHUNT | 312.5 nV | 78.125 nV | 312500 / 78125 pV |
| VBUS | 195.3125 µV | same | 195312500 pV |
| DIETEMP | 7.8125 m°C | same | 125/16 m°C |
| CURRENT | 3.125 µA | 0.78125 µA | 3125000 / 781250 pA |
| Charge | 3.125 µC | 0.78125 µC | 3125000 / 781250 pC |
The conversions, each exact:
With the nominal shunt_uohm = 100000, one count of range 0 gives exactly 312500 · 1000 / 100000 = 3125 nA, which is CURRENT_LSB: the arithmetic checks itself. The voltage is reduced to microvolts before the product with the current, which would otherwise reach 3.8e20 at 3.8 V and 100 mA and overflow int64_t.
CHARGE is the one quantity not shunt-corrected on the device. A full-scale count in nanocoulombs is 1.7e15, and × 100000 / shunt_uohm on top of it overflows 64 bits; so SENSe:CHARge? reports the raw count beside a conversion at the nominal 100 mΩ, and the host applies the factor. The capture's own CHARGE mean (§3.8) is a current, small enough to correct on the device, and is.
Two voltages, and the key names which. vbus_uv is what the INA228 measured on the source side of the shunt; the stream's v_mv is v_dut_pv, what the DUT sees, less the burden voltage (13 mV at 130 mA). The burden voltage is free: it is the offset-corrected shunt voltage itself, provided VBUS is wired upstream of the shunt, which it must be anyway, because the pin's 1 MΩ input ([DS] §6.5 ZVBUS) draws 3.8 µA at 3.8 V and would put it through the shunt downstream. The header's vbus_side= says which terminal the owner recorded (CALibration:VBUSside), and rig-wiring.md records the rig's.
3.7 The offset null and the quality token
At 0.100 Ω, 10 µA is 1 µV, exactly the part's maximum offset (Vos ±1 µV, [DS] §6.5). The null is not a refinement; it is the measurement. CALibration:ZERO <seconds> runs the live profile over a window of up to 600 s on a circuit whose shunt carries no DUT current, the source still on IN+ so that the null is taken at the common mode it will be measured at, and stores the mean VSHUNT in picovolts for the live range with the die temperature it was taken at, reporting the sample standard deviation so that a bad null is visible. With the relays, the lead is opened by K1 and the DUT stays fed through K2 (ROUTe:NULLpath ON, §6.1); by hand, the DUT's lead is unmated.
What is kept, and where. One blob, the newest record of the calibration record log (written by CalibrationStore, firmware/
The record log (FW-15, used from FW-16). Every NVS save allocated, so the blob is kept by firmware/
What the store takes. The mount is given the store's judgment of a record (flash_
Where it lives, and how it is written (FW-16). The log's sectors are the calib partition of firmware/
The quality token, q=, carried by SYSTem:STATus?, the capture header, the close, FETCh:STATistics? and every relay reply:
| q= | Meaning |
|---|---|
| uncal | No null for the live range, or the shunt never measured |
| stale | Nulled, but die_mc has moved more than ±5 °C since the null |
| cal | Nulled for the live range, shunt measured, within ±5 °C |
| invalid | MATHOF was set during the window, or the shunt was off the DUT's current (path=both or path=bypass) at any moment of it (§6.1) |
The ±5 °C is the offset drift (dVos/dT ±10 nV/°C max, ±0.1 µA/°C at 0.100 Ω) reaching the ±0.5 µA floor that ina228-reference.md §8.5 sets for the instrument: about ±5 % on a 10 µA reading. Nothing in the range or AVG choice improves that floor; a larger shunt would, at the cost of the burden voltage, and that is a second rig, not a change to this one.
3.8 The capture statistics (0.10.0)
The uncertainty model in the Kleidos QA harness needs more of a window than its mean: the spread of the samples, how many of them are independent, where the peak fell, and how far the battery sagged under it. Every figure here is computed in the sampling loop on Core 1, from every sample the loop took, so a sample the stream dropped is still in them, and the same loop serves a ring, a stream, a null and a statistics-only capture alike.
- The standard deviation is the sample standard deviation of the current, from the deviations of every sample's raw shunt count from the first: a 20-bit count differs from another by under 2^20, so each square is under 2^40 and the variance too (kMaxVarianceCounts). Their sum is carried in 128 bits (firmware/
src/ wide.h: two 64-bit words, an addition with a carry per sample), because 2^24 of those squares, 78 minutes of TRACE, fill 64. The variance, ( sum(d^2) - sum(d)^2 / n ) / ( n - 1 ), is formed once when the capture closes, by a shift-and-subtract division; scaled by 10^6 before that division so that it keeps six decimals of a count squared (the null's, which divided first and truncated to whole counts, read 1.2 % low at six counts and nothing below one; the null now shares this computation), and its root is the integer one, in thousandths of a count, and the conversion to picoamps uses the capture's own LSB and shunt. - The batch means. 64 slots, each the sum of one batch of samples. A batch starts as one sample; when every slot holds a complete one, the slots are merged pairwise into 32 and the batch doubles. So a closed capture of 32 samples or more reports between 32 and 63 complete batches of equal size, whatever its length, and FETCh:STATistics:BATCh? gives their means; a partial last batch is left out. From their spread a host estimates the effective sample size without the instrument guessing an autocorrelation time.
- The maximum's place: its sample index and its timestamp (max_n, max_t_us), the first sample to reach the highest current.
- The DUT's voltage and power: the sums for the means and the extremes, on a profile that converts the bus. FETCh:VOLTage?, :POWer?, :ENERgy? and :TEMPerature? now read these, not the console's sums over the samples that reached it; the energy is the mean power times the capture's own duration (dur_us), where before it was times the samples the console saw, so a dropped sample shortened it ("R1" of the review).
- The CHARGE mean: the pair of boundary reads divided by the time between those two reads (charge_us), not by dur_us: the pair integrates from before the pacing probe to after the stop, a few milliseconds more than the samples span, which on a one-second capture is a 1 % bias (found by the host tests). Corrected for the measured shunt, in nanoamps, and not for the null: the INA228 integrates its own CURRENT, so the figure carries the sense loop's offset, offset_pv / shunt_uohm above mean_na (on the bench, 2026-11-20, 57.8 µA against a sample mean of 37.3 µA with a stored null of 2.076 µV, 20.7 µA at 0.1 Ω). It is the hardware's independent check of the integral, and the offset is what it checks the null against.
- A threshold (SENSe:CURRent:THReshold, :HYSTeresis): a two-state counter. It rises when a sample reaches the level and falls when one is below the level less the hysteresis; the capture reports the rises, the samples taken in the high state and that count times the period (above_us). That is a duty cycle and a wake count without a stream.
- The statistics-only capture (SENSe:CAPTure STATistics): the same loop with nothing queued for the line and nothing written to the ring, on any profile for any duration. TRACE's rate for hours fits neither the 293 s ring nor the line budget; this keeps its statistics.
What a sample costs in the loop: one 64-bit square, two additions with a carry, a comparison for the maximum, one addition to a batch slot, the threshold's comparison when it is set, and on a bus profile the voltage and power of the sample (the console used to compute them per streamed sample). On BURST, whose loop ran past its 100 µs period until the hot path moved to IRAM (§3.4, §5.2), the cost is measured on the bench rather than assumed.
3.9 The triggered ring, marks in order, a capture that ends itself (0.11.0)
- The ring runs circular under a level trigger. TRIGger:SOURce LEVel starts a ring capture (Sampler::
startTriggered()) whose ring wraps from INITiate on: the write position is a head that wraps at the ring's size, and ringAt() unrolls it from the oldest held sample. Every index the instrument reports is the capture's own sample index, never a place in the ring, so t0 + index × period and the drift anchors stay unambiguous across a wrap; the oldest held sample is first = samples - held. The anchors are a circular array too, the last kAnchorSlots of them: every regular anchor a full ring's span holds and up to kMaxForcedAnchors forced ones (0.15.0; before, a forced anchor pushed out the oldest regular one, the t0 anchor of an untriggered ring). The trigger fires on the first sample at or beyond the level after one on its other side (a current already beyond it at INITiate primes nothing), keeps TRIGger:PRETrigger samples from before it and ends the capture after the ring's size less those. The check is one comparison per sample until it fires. - Marks travel the stream queue. A streamed sample is counted after it is queued, so when the console records a TRACe:MARK (or a LIVE relay move) at index n, every sample below n is already in the queue; the mark is queued behind them as a record (RecordKind::
Mark, its slot) and printed when the console reaches it. A full queue prints it at once: the line is then dropping samples anyway. Threshold crossings (SENSe:CURRent:THReshold:MARK ON) are queued by the sampler right behind the sample they were seen at, at most kMaxThresholdMarks (1,024) a capture, so a level set inside the noise cannot flood the line. - A capture that ends itself. SENSe:CAPTure:LIMit ON hands SAMPle:COUNt to the stream or statistics-only capture as its sample limit, the one the null window already had. *OPC is pending while a window that ends by itself runs (Sampler::
endsItself()), and the console's loop sets the ESR's bit 0 once the sampler stops; *OPC? and *WAI stay immediate, because a blocking query cannot be interrupted by ABORt on this line. - The dump's CRC-32. Console::
write() feeds every byte of the block into an IEEE CRC-32 (crc32.h, a compile-time table) while the rows before METER_ DUMP_ END are written, in the counting pass and in the writing pass alike, and the closing row carries it with the byte count. The bench's 6 Mbps line has no parity; a filed dump can now be held to its bytes (the garbled tokens of queue item 47 are the case it detects).
4. Where samples go
4.1 The ring and the stream
The sink is forced by arithmetic. The line carries 600,000 B/s (§4.2), and a METER t=… ch=i_ua v=… line is bounded at 48 bytes, derived in sampler.h (kStreamLineBytes) from the widest each field can print and held by a static_assert:
| Profile | Rate | One channel costs | Sink |
|---|---|---|---|
| BURST | 10,000 Sa/s | 480 kB/s (80 %) | the ring: no headroom for a second channel |
| TRACE | 3,571 Sa/s | 171 kB/s (29 %) | the ring: it would fit the line, but the ring keeps a burst's shape off the host's scheduler |
| STATE | 868 Sa/s | 41.7 kB/s (7 %) | the stream: three channels are 21 % |
| SLEEP | 14.81 Sa/s | 0.71 kB/s | the stream |
The ring. A sample is 4 bytes, the sign-extended 20-bit VSHUNT count; the timestamps are implicit, the period being fixed. The ring holds kTraceSamples = 1,048,576 samples (4 MiB, 293 s of TRACE, 105 s of BURST) in PSRAM's .ext_ram.bss, reserved at link time in app_main() (CONFIG_
Drift anchors. Every kAnchorEvery = 1024 samples the loop stores { n, t_us }, 1,024 anchors over a full ring, and a forced one at the sample after a failed read, at most kMaxForcedAnchors = 16 a capture, in an array sized for both, so a forced anchor never pushes out a regular one (0.15.0). The host reconstructs the real timestamps by interpolation and sees a stall or the oscillator's skew instead of trusting the nominal period. The dump interleaves them as A n=<idx> t=<us>.
Marks. TRACe:MARK "<label>" stores { n, label[16] }, up to kMaxMarks = 16 a capture, with two more slots for the hold's own marks (§6.3), so a trace aligns to an event on the DUT's own console; LIVE relay moves are marked the same way (§6.1). A ring prints them in the dump as K n=<idx> label=<text>, a stream as mark records in sample order (§3.9).
The stream. The sampler never prints. It hands each finished sample to the console task through a static FreeRTOS queue of kStreamQueueDepth = 256 records, and the console formats and writes them; a slow line can never stall the cadence, it can only raise dropped=.
Back-pressure is refused, never absorbed. No stream may need more than kLineBudgetPercent = 80 % of the line, and that is a fact of the profile table rather than a check at INITiate: sampler.cpp asserts at compile time that every channel at once on each streaming profile fits (167 kB/s on STATE against 480 kB/s), so a profile that broke it would not build (FW-27; the run-time refusal it replaces, -221 stream too fast, could not be reached). At runtime the console counts what uart0::
4.2 The line is 6 Mbps, and that is measured
The console is UART0 on GPIO43/44 behind the carrier's CH343P bridge, not the S3's native USB (carrier-board.md §7), so the baud rate is a real divider and not a USB formality. It was 921600, then 2 Mbps; a timed TRACe:DATA? showed 2 Mbps delivering 196 kB/s — 98 % of its own ceiling, i.e. saturated, so the line and not the firmware's formatting was what bounded a dump.
The CH343P is rated to 6 Mbps and the S3's fractional divider puts 6 Mbps 0.08 % off exact from the 80 MHz APB, inside any UART's tolerance. Measured on a 7.85 MB dump of 209,936 samples: 582.6 kB/s, 97 % of the line, every one of the 209,936 sample lines parsing in full, zero non-ASCII bytes, and timestamp gaps forming the exact arithmetic progression the declared period predicts. A dump that would have taken 195 s at 921600 takes 13 s.
On its registers, with no driver (FW-12). ESP-IDF's UART driver kept its object, a 1 KiB receive ring buffer, an event queue, its mutexes and its interrupt's records on the heap (docs/misra.md D1). firmware/
- Receiving. The interrupt is raised when the receive FIFO holds more than 64 bytes (half of it: 107 µs before it overflows at 6 Mbps, where the driver's 120 left 13 µs), when the line has idled for ten frames after a byte (17 µs), and when the FIFO overflows. The handler moves the FIFO into a static ring of 1,024 bytes and gives a static binary semaphore, on which uart0::read() waits for a first byte (Console::
receive()); a read returns as soon as anything is there. A full ring leaves the rest in the FIFO and turns the two data interrupts off; the next read moves what the FIFO holds into the room it made and turns them back on once the FIFO is empty. So the ring and the FIFO hold 1,152 bytes the console has not read before anything is lost, as the driver's ring and FIFO did, and only an overflow loses bytes: the handler latches it and empties the FIFO, as the driver did, and Console:: noteOverrun() turns the latch into one -363 and discards the message it fell in (docs/scpi.md), as it did the driver's UART_FIFO_OVF event. - Transmitting is polled. uart0::
write() puts each byte into the 128-byte transmit FIFO as it has room; the console is the only writer, and the driver, given no transmit ring, blocked it the same way. A line that takes nothing for 10 ms (6,000 bytes' time; with no flow control the FIFO empties in 213 µs) ends the write with what it placed, which the console counts as dropped= (§4.1). - One core, and IRAM. The ring and its two flags are plain variables of one static object: the handler runs on Core 0, and the console task, pinned there, touches them only with the core's interrupts masked. The handler is in IRAM, and a root of the IRAM gate (§5.2): its line is not the allocator's, and ESP-IDF masks during a flash write only the lines its allocator gave a handler outside IRAM (esp_
intr_ noniram_ disable()), so it runs with the cache off while a calibration is saved. The driver's handler was in flash and its line masked then.
The host harness models UART0's registers (firmware/
On the bench (2026-11-22, FW-12's image, ELF b7f6e739ae8cee1f; tests/
5. Tasks, cores and the hot path
5.1 Tasks, cores and the watchdog
| Task | Core | Priority | Job |
|---|---|---|---|
| meter-sample | 1 | 10 | Pace, read, decode, append to the ring or hand to the writer |
| main (the console) | 0 | 5 | Read UART0 lines, dispatch, print |
The console is the main task (FW-17). ESP-IDF creates main before app_main(), on Core 0 at priority 1 with CONFIG_
The split mirrors the fleet's own: the latency-critical loop gets a core to itself, and everything that blocks runs on the other (the Kleidos firmware repository's AGENTS.md §8). The interrupts follow the sampler (0.14.0). ESP-IDF allocates an interrupt on the core that installs it, and app_main() runs on Core 0, so until 0.14.0 the I2C master's ISR and the ALERT pin's GPIO ISR ran beside UART0's at 6 Mbps while the task they wake runs on Core 1: every transfer's completion crossed cores. (From FW-14 the bus takes no interrupt at all: the own master polls each transaction to its end, §2.4.) app_main() now runs the bring-up and Sampler::
The ALERT pin's interrupt is routed statically (FW-09). ESP-IDF's GPIO ISR service allocated a table of 49 handlers and the interrupt allocator a record for its line and its handler, three allocations at boot (docs/misra.md D1). Sampler::
Supervision (0.14.0). Both tasks subscribe to the watchdog from their own task (the console from Console::
The watchdog is the firmware's own (FW-11). Until FW-11 the supervision was ESP-IDF's task watchdog, which kept its subscribers on the heap (its object and Core 0's idle task's entry before app_main(), an entry per task after) and claimed its timer's interrupt through the allocator (docs/misra.md D1). CONFIG_
Core 1's idle task is not supervised. A spinning sampler on Core 1 starves IDLE1, so only Core 0's idle task has a check-in bit. The spin only exists on the pace = timer path; on the pace = alert path the task blocks on a semaphore and IDLE1 runs normally. The interrupt watchdog is left alone.
A queue or semaphore that both tasks may reach is created before the consumer task exists, never by a bare if ( handle == nullptr ) create — both cores can pass that check and build it twice into one control block (the Kleidos firmware repository's AGENTS.md §8).
5.2 The hot path in IRAM (0.16.1)
Why. The ESP32-S3 fetches code and constants from flash through one instruction cache and one data cache, both shared by the two cores. Code that runs from flash on Core 1 waits for every line Core 0's work has evicted, and a radio on Core 0 evicts a great deal. The NW-00 radio spike (branch spike/nw00, never merged: Wi-Fi linked into the image, a station sending CSV to a LAN client) measured what that costs an alert-paced capture: STATE statistics-only captures of 15 s read pace_err_ppm +85 with the radio off, +83 with the station idle, +33,740 sending 50 kB/s and +171,658 sending 200 kB/s, with dropped=0, 723 samples a second instead of 868 and the floor's sd up from 19.0 to 25.8 µA. Wi-Fi's and lwIP's buffers in internal RAM instead of PSRAM gave the same or worse, so the data cache was not the cause. The conversions are lost without a count because of how the pin works (§3.3): ALE stays low from a conversion's end until DIAG_ALRT is read, so a loop that comes back to its read more than a period after the edge leaves the pin low through the next conversion, which then makes no edge of its own; the next sample is a period late, and pace_err_ppm is the only figure that sees it.
What moved. Everything a conversion executes on Core 1, found from the relocations of every object the image is linked from rather than guessed (scripts/
- Ours, IRAM_ATTR: Sampler::
runCapture() (the loop), waitForConversion(), readSample(), accumulate(), addToBatch(), storeInRing(), queueThresholdMark(), retainShuntPointer(), alertIsr() (the ALERT pin's handler), and waitUntil(), alertPacing(), currentNanoamps() and noteDieMilliCelsius(), which the compiler inlines into them; the driver's readRegister(), read16(), read24(), readDiagAlrt(), readRetained(), setPointer() and note(). The profile table the loop reads every sample, kProfileSpecs, is DRAM_ATTR: it was the one named constant of the hot path in flash. - FreeRTOS (CONFIG_
FREERTOS_ IN_ IRAM): ESP-IDF 6 places every FreeRTOS function in flash but those an interrupt calls, and the loop blocks on xQueueSemaphoreTake() for every edge, sends to the stream queue (xQueueGenericSend()), delays (vTaskDelay()), and until FW-14 ESP-IDF's I2C driver took its bus lock, reset and waited on its event queue (xQueueGenericReset(), xQueueReceive()), each with the list and scheduler functions behind them. The option moves all of FreeRTOS, the idle task's included. - The I2C master's transactions (FW-14): the own master's i2c_
bus:: write(), read(), writeRead() and transact() are IRAM_ATTR, and their register access is ESP-IDF's hal/i2c_ll.h's inline functions. Until FW-14 the path was ESP-IDF's driver's: CONFIG_ I2C_ ISR_ IRAM_ SAFE moved the command builders the task and the interrupt share and the HAL's i2c_ hal_ master_ trans_ start(), and firmware/ src/ linker.lf the synchronous path the option left in flash (i2c_ master_ transmit_ receive(), i2c_ master_ receive(), i2c_ master_ transmit(), i2c_ master_ multi_ buffer_ transmit(), s_ i2c_ synchronous_ transaction(), s_ i2c_ transaction_ start(), s_ i2c_ send_ commands(), _ i2c_ hal_ set_ bus_ timing(), i2c_ hal_ master_ set_ scl_ timeout_ val()); the option and the fragment went with the driver.
Already in IRAM by the pinned ESP-IDF's defaults, and so not set: esp_
The cost (xtensa-esp32s3-elf-objdump -h of the clean builds of 0.16.0 and 0.16.1): .iram0.text 60,967 → 76,475 bytes (+15,508), .flash.text 163,864 → 148,164 (−15,700); DIAGnostic:HEAP? at the end of the bench sessions below, free_internal 330,543 → 313,695, min_
The gate (scripts/
On the bench, radio off (2026-11-21, instrument KM-0000000000, the DUT a T-Deck behind K1 and on its USB supply, about 37 µA through the shunt; clean builds of main, 0.16.0 at e4ade81, ELF 697a09218f7e0dec, and 0.16.1, ELF 14986195a0d8ec35, flashed and measured one after the other). STATE and SLEEP streamed i_ua for 60 s each, three times; missed and extra are counted from the stream's own t= as in §3.4; TRACE and BURST (1 MHz) filled their rings for 10 s, three times:
| Capture | 0.16.0 | 0.16.1 |
|---|---|---|
| STATE × 3, 60 s, pace=alert | 0 missed, 0 extra, 0 stale; interval sd 6.4–6.7 µs (980–1,315 µs); pace_err_ppm +97, +94, +99 | 0 missed, 0 extra, 0 stale; interval sd 0.80–0.82 µs (1,147–1,167 µs); +99, +99, +96 |
| SLEEP × 3, 60 s, pace=alert | 0, 0, 0; sd 4.1–4.8 µs (67,517–67,541 µs); +97, +96, +99 | 0, 0, 0; sd 3.5 µs (67,520–67,539 µs); +95, +94, +96 |
| STATE statistics-only × 2, 30 s | 869.30 samples/s; +99, +96 | 869.17 samples/s; +98, +104 |
| TRACE × 3, 10 s | 280.009 µs a sample; −5, −4, −3 ppm; 0 re-based | 280.007 µs; 0, 0, 0 ppm; 0 re-based |
| BURST × 3, 10 s, 1 MHz | 100.013–100.014 µs; +105 to +112 ppm; 7 re-based each | 100.002 µs; 0, 0, 0 ppm; 0 re-based |
Every capture closed with dropped=0 read_err=0 pace_
With the radio (the same day, the spike image de088408924084af, 0.15.0 with Wi-Fi, against the same image with this change applied, ELF 48e8884358274b99; station joined to the lab network, sending the spike's CSV stream to the bench host at the rate shown, measured at the host as 49.4 kB/s and 196 to 199.6 kB/s; STATE statistics-only, 15 s each):
| State | spike, 2 runs | spike + IRAM, 3 runs |
|---|---|---|
| Radio off | +96, +90 ppm; 870.5 samples/s | +94, +93, +89; 870.4 |
| Station idle | +94, +92; 870.6 | +95, +96, +93; 870.5 |
| Sending 50 kB/s | +26,280, +40,610; 848 and 837 samples/s | +96, +97, +94; 870.4 |
| Sending 200 kB/s | +182,712 (736 samples/s); one run pace=timer | +94, +92 (870.1); one run pace=timer |
The conversions the radio cost are all back: every alert-paced capture with the station sending reads the INA228's own oscillator, as with the radio off. One capture of each image at 200 kB/s started on the timer instead (pace=timer, pace_err_ppm +7 and 0, still 869.7 and 869.9 samples/s): the pacing probe of §3.3 did not count 7 to 9 edges in its eight periods. The probe ran in the console task on Core 0, beside the Wi-Fi tasks, and 0.16.2 moved it into the sampler task (§3.3); the header names the pace every capture used, so such a capture is never mistaken for an alert-paced one.
6. The relays
6.1 The null without hands
The one step of a campaign that needed hands was the null of §3.7: the DUT lead open, the source still on IN+. A relay pair now does it, and does it without the DUT losing power: K1 opens the lead while a bypass feeds the DUT around the shunt. firmware/
The lead, K1, is one SRD-05VDC-SL-C Form C relay (COM / NC / NO, 10 A at 30 VDC) of an HW-316 module, behind a 1 kΩ input resistor, an IN LED, a PC817 opto and an S8050 driver with a 1N4148 flyback diode; VCC on carrier terminal 21 (5V), GND on 22 (G), the JD-VCC jumper fitted. Its input is low-level triggered: driven low, it sinks about 2 mA through the IN LED and the opto LED in series and energizes the coil; driven high at 3.3 V, or left floating, the coil stays off, because those two LEDs need about 3 V between them and 5 − 3.3 V cannot light them. It stays a mechanical relay on purpose: closed at rest, so the DUT stays fed with the meter off, and with no PhotoMOS on-resistance in series with the DUT.
The bypass, k2 on the wire, is one LCA717 PhotoMOS (OptoMOS) of a MikroE Relay 2 Click, its RL2 channel, normally open, between the VIN+ node and K1's NC (the DUT's battery +). Its input is active high: GPIO15 sources current into the LCA717's LED to close it, and an LED with no current is an open bypass, so low at rest and at boot (docs/
| Channel | Part | Input | GPIO (default map) | Left-rail terminal | Role | Contacts |
|---|---|---|---|---|---|---|
| K1, the map's Relay 1 | HW-316 relay K1 | IN1, active low | 7 | 7 | lead | COM on VIN−, the shunt's DUT end; NC to the DUT battery + |
| K2, the map's Relay 2 | Relay 2 Click RL2 | its control pin, active high | 15 | 8 | bypass | the VIN+ node (cell +) and K1's NC (DUT battery +) |
| K3 | none (the HW-316's IN3 is not wired) | none | spare, unwired | |||
| K4 | none (the HW-316's IN4 is not wired) | none | spare, unwired |
Until 2026-11-20 (rev C, the meter image until 0.7.0) the bypass was the HW-316's own K2 on IN2, active low; its silver contacts did not close the dry circuit of a few millivolts across the shunt and K1, and the bypass moved to the Click (calibration/
GPIO4/5/6 are the INA228's SDA/SCL/ALE (§2.1), so the relays take the next four terminals of the same rail; all four are free on this board (carrier-board.md §2), and GPIO15/16 are free of their 32 kHz crystal role because the image runs the RTC on its internal RC (CONFIG_
Released is the safe state, and the wiring makes it the measuring one. K1's NC contact is in series with the shunt and the normally open bypass is across it, so every coil off is the DUT on the shunt with the bypass open — the circuit before the module was fitted. That is what a meter reset, a reflash, a meter with no firmware, or a pin the driver failed to configure all leave behind. The two contacts make four circuits, which every relay line names:
| path= | K1 | K2 | The DUT is fed | The shunt carries |
|---|---|---|---|---|
| shunt | closed | open | through the shunt | everything: the measuring circuit and the boot state |
| bypass | open | closed | around the shunt | nothing of a DUT that is running: the null, and no place for a capture |
| both | closed | closed | both ways | a fraction, so every reading is q=invalid |
| none | open | open | not at all from the battery | nothing, which is what the DUT draws: a capture there is valid |
relay::
The boot order. gRelays.begin( gPins.map ) is the first call of app_main() that reaches a pin, ahead of the LED frame of §8; only the pin map's read comes before it (§2.6). For each relay pin of the map it writes the GPIO output latch to that relay's released level, high for an active-low input such as K1's and low for an active-high one such as the Click's LED, before gpio_config() makes the pad an output: in 4.60003.0, as in 4.60101.0, gpio_
Orders are planned before they are driven. Each command becomes a plan of at most two steps, each a coil change and the settle time after it. The plans and the interlocks are constexpr, and the orders this module exists for are static_asserts beside them, so a change that breaks make-before-break fails the meter's own build:
| Order | From rest (path=shunt) | Steps |
|---|---|---|
| ROUTe:NULLpath ON | → bypass | read the shunt; energize K2 (bypass closes), settle, read; energize K1 (lead opens), settle, read — each reading judged below |
| ROUTe:NULLpath OFF | from bypass → shunt | release K1 (lead recloses), settle; release K2 (bypass opens), settle |
| ROUTe:LEAD OPEN\|CLOSE | K1 alone | |
| ROUTe:BYPass ON\|OFF | K2 alone | |
| ROUTe:RELay3\|RELay4 ON\|OFF | a spare alone, refused since 0.13.0 because neither is wired (§6.2); ROUTe:RELay1 and RELay2 are refused by name (-114), so each role has one spelling and one set of interlocks |
From any other state ROUTe:NULLpath runs only the steps still missing, in the same order, and no step of either direction ever passes through path=none.
The settle times. There is no contact sense on the module, so every order waits out the relay's own bounds before it answers, and these are bounds, not observations; what the rig measured against them, every move well inside its wait, is docs/
| Value | Source | |
|---|---|---|
| Operate time | 10 ms max | Songle SRD sheet; LCSC and JLCPCB listings of part C35449 |
| Release time | 10 ms max used | Songle's sheet says 5 ms, the LCSC and JLCPCB listings 10 ms; the larger is used |
| Flyback diode | 30 ms allowance on a release | The bounds are for a bare coil; a plain diode across the coil gives "the slowest" current decay (TE Connectivity, coil suppression), and no source gives the figure for this part. Three times the release bound. Measured on 2026-11-21: the release, diode and all, took 11.20 ms (docs/ |
| Bounce | 10 ms margin | No source states one; the margin equals the operate bound. The record of 2026-11-21 shows the operate's step at 1.96 to 2.52 ms and the release's at 11.20 ms, bounce included (docs/ |
| Settle after energizing | 20 ms | kOperateSettleMs |
| Settle after releasing | 50 ms | kReleaseSettleMs |
| Relay 2 Click bypass (the one image from 0.8.0; meter_relay2 before) | 10 ms each way | kSsrOperateSettleMs, kSsrReleaseSettleMs: IXYS's 3 ms LCA717 bound at 5 mA, doubled for the Click's unstated LED current, plus 4 ms; the TRACE run of docs/ |
The release wait is the one make-before-break rests on when it opens the bypass: ROUTe:NULLpath OFF must not open K2 before K1's NC contact has reclosed. ROUTe:NULLpath is therefore about 100 ms each way, ON's checks included. Every reply's settle_us is the time the order actually took, on esp_timer. Two bench runs check the bounds: a TRACE across LIVE, FORCe orders, which shows each contact's real time against its mark (run on 2026-11-21 and filed in docs/
The checks: what ROUTe:NULLpath ON sees. A commanded state is not evidence: a module with no 5 V (carrier-board.md §6 makes that the likely first-power case), a loose IN wire or a coil below its 3.75 V pull-in leaves every relay where it was while the console reports the order done — and a null taken through such a "null path" measures the DUT's own current through the shunt and would be stored as the offset. So ROUTe:NULLpath ON, when no capture is open and the INA228 is up, reads the shunt before the first step and after each one. Each reading is a 16.8 ms average (continuous shunt-only, 1052 µs × 16, read 20 ms after ADC_CONFIG is written, the profile's word written back afterwards: continuous rather than triggered, so the accumulators stay valid), and its share is the reading less the stored null for the live range. The verdicts are constexpr in relay.h, with static_asserts on the T-Deck's own numbers:
| Step | Passes when | Why that bound |
|---|---|---|
| K2 closes | the share falls to ≤ ¾ of the share before, and to no less than 1/16 of it (0.18.0) | K2's branch is a contact and two short wires, the shunt's 0.100 Ω plus a contact and one wire; with every contact at its 100 mΩ maximum against the other at nothing, a closed K2 leaves the shunt 55 % at worst. The lower bound tells a bypass that closed from a lead that opened, which leaves the shunt nothing but its offset: the bypass branch measured about 34 mΩ (2026-11-20), so a closed K2 leaves the shunt 25 % with K1's contact and wire at nothing and 13 % with them at 120 mΩ, twice a sixteenth; a share that falls under it is refused as the shunt lost all of the dut's current (Relay 2 driving Relay 1's part, as relays swapped onto each other's wires with matching levels do) |
| K1 opens (or any step that lands on path=bypass) | the reading is ≤ 50 µV and, when the first share was judged, the share is ≤ ½ of the one before; a first share judged with K1 already open fails it (0.18.0) | 50 µV is seven times the largest null this rig has measured (−6.85 µV, 2026-10-27) and 500 µA through the shunt. The half test catches a K1 that never moved but whose leftover share happens to sit under the limit. With K1 open before the order only K2 moves, and no step shows K1 leave the shunt dead: the DUT's current in the first reading is what says it is stuck closed |
| Judged at all | the first share is ≥ 200 µV (2 mA) | below it neither move stands clear of the offset and of the DUT's own variation between readings |
A failed step releases the path again, make-before-break, and refuses with every reading it rests on (103, bypass check failed; 104, lead check failed). A passed order carries its verdict in the relay tokens as check=: ok (both moves seen), unverified (under 2 mA: only the 50 µV limit applied), skipped (ROUTe:NULLpath ON,LIVE under a capture, which reads nothing), or - (any other order, or boot). ROUTe:NULLpath OFF is not checked: both of its steps are spring releases, which need no coil supply to happen.
The last line of defense is in CALibration:ZERO: a window opened with K1 commanded open (path=bypass or path=none) whose offset comes out beyond 50 µV reports its numbers and queues 102 (Null not stored), and neither RAM nor the flash takes it. The hand null (path=shunt) is not bounded: the relays cannot see that lead.
The hold. A release nobody commanded — a meter reset, a panic, a brown-out, the meter's USB lost, a port opened with RTS and DTR in the wrong order — drops both coils at once, and with the null path held K2's NO can open before K1's NC recloses. So the null path is held at most kNullPathHoldS = 120 s: armed by any order that ends on path=bypass, re-armed whenever a window closes. When it expires the console loop runs ROUTe:NULLpath OFF itself and prints nothing; every relay reply says hold_s=, and ROUTe:STATe? counts the releases in hold_
The interlocks.
- No order disconnects a powered DUT unless it says FORCe. A step that takes the circuit into path=none from a powered one — ROUTe:LEAD OPEN with the bypass open, ROUTe:BYPass OFF with the lead open — is refused with 109 (Order disconnects the DUT) unless it says FORCe. The test is a transition into none, so a spare switched while a cold power cycle has the DUT disconnected is not refused again. ROUTe:LEAD OPEN,FORCe with the DUT's USB port cut at the hub is the hands-free cold power cycle.
- No contact moves under a running capture unless the order says LIVE, and none moves under a running CALibration:ZERO even then, because a null assumes one circuit for its whole window. A LIVE move records a mark per coil at the sample index it was driven at, and writes it as TRACe:MARK's are written, a mark record (METER_MARK mark=k1:open n=… t=… in TEXT, docs/scpi.md "Stream records") before the relay reply: a streamed capture has no TRACe:DATA? to replay a K line from, and the marks share TRACe:MARK's table of kMaxMarks. The reply says live=1 and how many marks it stored. An order that changes nothing is answered with the state whatever is running.
- A shunt off the DUT's current is never measured silently. INITiate is refused on path=both and on path=bypass (101) unless it says FORCe, naming the order that gives the shunt the whole current back (ROUTe:BYPass OFF, ROUTe:NULLpath OFF). CALibration:ZERO is refused on path=both with no override, because nothing makes that a null. A LIVE move that would take a running capture's shunt off the DUT's current (relay::
bypassesShunt(): every ROUTe:NULLpath order, ROUTe:BYPass ON) needs FORCe too (110), because the header has already gone out with its q=. A capture that was off the DUT's current at any moment then says q=invalid on its ABORt, in SYSTem:STATus? and in every relay reply — and in its header too when it was so at INITiate. SYSTem:STATus? and SYSTem:INFormation? say q=invalid for as long as the shunt is off the DUT's current. - Every record says which circuit it was taken in. Each capture header carries relays=1 k1=… k2=… k3=… k4=… path=… (FETCh:HEADer?, docs/scpi.md "The capture header"), and both CALibration:ZERO lines carry the same tokens as the window's start found them — the result line too, so an order between the window's last sample and ABORt cannot rewrite the circuit the null was taken in. path=bypass there is a null taken with the lead opened by K1, path=shunt one that rests on a lead opened by hand, which the relays cannot see, and check= what ROUTe:NULLpath ON saw of the path.
Nothing waits on a relay but the console. Orders run on the console task (Core 0). A settle wait drains the stream queue every millisecond instead of sleeping through it, so a LIVE order never holds back a capture's samples, and the sampler task on Core 1 never sees a relay at all. The checks read the device only with no capture open, so they never move the register pointer out from under a TRACE. The console is the bank's only user after boot, so no order can interleave with another.
The RTC slow clock stays on the internal RC. GPIO15 and GPIO16 are the 32 kHz crystal pins; sdkconfig.defaults states CONFIG_
What the relays cannot do. They cannot see whether the DUT is also fed by USB. They cannot order a release they did not command: while the null path is held, a meter reset releases both coils at once, K2's NO contact can open before K1's NC recloses, and the DUT can lose its battery for a few milliseconds; a slow fall of the 5 V can even release K2 first and leave path=none with the firmware still reporting bypass. The hold bounds the exposure, and a host should still close the path in a finally. They cannot see below 2 mA (the checks above). And each energized coil draws about 71 mA from the carrier's 5 V terminal (Songle's coil chart: 70 Ω, 71.4 mA), so holding the null path costs about 145 mA there — which assumes the terminal carries 5 V with only the USB cable attached, measured loaded as carrier-board.md §10 check 6 asks. The module's 5 V must also never outlive the meter's 3.3 V: an unpowered ESP32-S3 clamps every IN toward ground through its protection diodes (carrier-board.md §6).
6.2 The lead cycle, the open lead's hold, the unwired spares (0.13.0)
- ROUTe:LEAD:CYCLe opens K1 with ROUTe:LEAD OPEN's interlocks and arms a deadline; the console's loop recloses it when the deadline passes, waiting for input no longer than the time left, so the reclose is late by the loop's own work only. The deadline runs from the opening's drive. A capture started meanwhile does not hold the battery back: the reclose is marked as a LIVE move.
- The hold covers an open lead. updateHold() arms the 120 s hold on path=bypass and, from 0.13.0, on path=none; when it fires on an open lead it recloses K1 alone and queues 114. Every order and every release calls updateHold(), so an armed hold always stands on a path off the shunt (from 0.16.0 path=both as well, §6.3).
- K3 and K4 are not wired (ChannelSpec::
wired): their pins are never driven, their pads not read, their tokens unwired, and their orders refused. Until 0.16.5 GPIO16 and GPIO17 were left as reset made them; from 0.16.6 they are parked, inputs with the internal pull-down (§9), so that neither floats. The temporary load NW-00 wired to GPIO16 (the Relay 2 Click's RL1) was removed on 2026-11-21. - Relay timing is measured by a host tool and filed in docs/
relay-timing.md; the settle waits change only from such a record.
6.3 The hold is the teardown, and a reset says what it released (0.16.0)
Before 0.16.0 the hold waited for every open capture, so a host that died with a stream open and K1 open left the DUT without its battery for as long as nobody came: the gap A7 of the review was written for. Now the hold is what puts the rig back to its safe state, K1 closed and the bypass open, whatever is running:
- Every path but the shunt is held. updateHold() arms on path != shunt: the null path, an open lead and a bypass across a closed lead (path=both, released with 115). Any relay order arms it again, one that moves nothing included, so a host that keeps a path past 120 s says so by sending its order again; a capture's or a null window's close re-arms it, as before.
- Only a sampling null window suspends it. A null assumes one circuit for its whole window, and the window is bounded (600 s), so while one samples serviceHold() keeps pushing the deadline out; once the window stops sampling, by itself or by ABORt, the hold has its whole 120 s. A window that ended by itself and waits for ABORt does not hold the relays: its null rests on the samples already taken, and on the circuit the window's start recorded, so the release cannot spoil it.
- The release runs under a capture and is marked in it. releaseHeld() drives planNullPath( state, false ), make-before-break from any of the three paths, and when a capture is sampling it marks each move as a LIVE move is marked, labeled hold:k1:closed and hold:k2:open, through Sampler::
addHoldMark(), which writes into two slots beyond TRACe:MARK's sixteen. It counts the release in the capture (hold_ teardowns= in FETCh:STATistics?, QUEStionable bit 10 for the open or last capture) and queues 113, 114 or 115 with under a capture, marked hold: in the detail. A capture that ended by itself is not marked: no sample follows the move. - A reset says what it released. A reset drops every coil at once, which is safe by wiring but can open K2 before K1 recloses, and the capture it fell in ends with the stream. Bank::drive() writes every commanded state into a ResetRecord in RTC slow memory (RTC_
NOINIT_ ATTR: a software reset, a panic and a watchdog reset leave it, a power-on leaves noise), with a magic number and an inverted copy. Bank::begin() reads it once every pin is released, keeps it unless the chip powered on, and records the released state; announce() queues 116 naming the reset, the coils and their path, and SYSTem:HEALth? reports them as reset_ released. - What stays out of the hold's reach. An acquisition (MEASure, READ, CALibration:SHUNt) holds the console for its whole window, at most twice 600 s plus one, and the hold runs right after it; an acquisition is refused off the shunt's whole current, so only an open lead can be under one. A dump holds it for seconds. *RST is an order: it closes the window, then releases make-before-break, and queues nothing.
7. Self-test, health and status (0.12.0)
- *TST? reads, never assumes. The bring-up's three verdicts stay, and the self-test adds what a running instrument can lose: the INA228's identity and SHUNT_CAL read back against the bring-up's, MEMSTAT, the ALE wire probed with STATE's own pacing probe (Sampler::
probeAlert(), two periods after its writes since 0.16.4, §3.3), each relay pad read back against its drive, the stored calibration read back from the flash without touching the one in RAM (CalibrationStore:: storedReadable(), §3.7), and both tasks' stack high-water marks against a 512-byte floor. It is refused under an open window because it reads registers and reprograms the conversion. - SYSTem:HEALth? reads nothing of the device: esp_
reset_ reason(), the uptime, the ELF hash, the stacks, the heap counts, the hold's releases and the queue's length, so it is safe under a capture and is the one query a host polls to see that the instrument it talks to has not rebooted. - QUEStionable bits for what used to reach only the closing statistics: TIME (bit 2) for a fallen-back pace, a failed read or a missed period, data lost (bit 9) for dropped=. They describe the open capture or, once it is closed, the last one, and the transition filters (:PTRansition, :NTRansition) let a host latch a fall as well as a rise.
- An asynchronous error has one way to the host, the queue: the hold's release of a null path queues 113 with the ESR's device-dependent bit, so a host that reads *ESR? or the queue between its own messages learns of it (and from 0.16.0 114, 115 and 116 the same way, §6.3).
8. The LED goes dark
The carrier's addressable RGB LED latches: a WS2812-class part keeps its last frame for as long as its 3.3 V supply stays up, so a reset, an esptool auto-reset or a flash leaves the previous firmware's color lit, and holding the data line low is a reset code, not a color. led::
On the RMT's registers, with no driver (FW-10). The frame is written through ESP-IDF's low-level layer (hal/rmt_ll.h, inline functions on the registers), not its RMT driver, which allocated a channel, a transaction queue, a group, an encoder and an interrupt for a frame sent once and freed them again (docs/misra.md D1). The RMT's bus clock goes on (and its reset is pulsed) under ESP-IDF's peripheral clock lock; transmit channel 0 runs on the 80 MHz APB clock divided by 4, so a tick is 50 ns, owns one memory block and idles low; its RAM holds one 0 bit (6 ticks high, 19 low) and an end marker; and the channel sends it in loop mode, counting 96 passes (four pixels of 24 bits) and stopping by itself. Each line in turn is given to the channel through the GPIO matrix while it idles low, which holds the leading reset code for 1 ms; the end of the count is polled in the raw interrupt status (no interrupt is enabled), with a budget of 1 ms after which the channel is stopped by hand; the idle level holds the trailing reset code for 1 ms; and only then does the matrix give the line back to the GPIO's output register, already low. The RMT is left as the driver left it: group clock off, memory in low power, bus clock gated. Each line costs about 2.1 ms, once, at boot.
The loop-count path keeps the waveform SYSTem:LED? reports (t0h_ns=300 t0l_ns=950, the same as 0.16.6's driver): on the meter, on 2026-11-22, a temporary build looped each line back into RMT receive channel 4 through the matrix and captured the frame at 12.5 ns (the APB clock, undivided): on both lines 96 high halves of exactly 24 ticks (300 ns) and 95 lows between them of exactly 76 ticks (950 ns), so a pass's end marker adds nothing between two bits. The cycle-counted bit-bang the plan kept as a fallback was not needed. The host harness models the registers (firmware/
9. Serial-only, and the hardware it does not use parked (0.16.6)
The file the build reads is firmware/
- Wi-Fi, Bluetooth, the PHY, coexistence: not linked, and from FW-16 not built: the project's component list holds only the firmware's component and what it requires (firmware/
CMakeLists.txt, COMPONENTS), so esp_wifi, bt, esp_phy and esp_coex are not in the build and their options not in the generated config (CONFIG_ BT_ ENABLED=n stays in sdkconfig.defaults as the statement of what an absent symbol means). ESP-IDF's esp_ perip_ clk_ init() gates the Wi-Fi, Bluetooth and SDIO clocks at a power-on reset. Until FW-16 the image kept one symbol of theirs, include_ esp_ phy_ override, an empty link anchor (esp_phy's CMakeLists passed -u for it); it is gone with the component. - The USB-Serial-JTAG: off. CONFIG_
ESP_ CONSOLE_ SECONDARY_ NONE=y and CONFIG_ USJ_ ENABLE_ USB_ SERIAL_ JTAG=n (from FW-16 its driver's component is not in the build, and the option is absent, which esp_ perip_ clk_ init() reads as off just the same). Until 0.16.5 the secondary console defaulted to it, so its pad and bus clock stayed on, its VFS and connection monitor were linked, and the monitor's start-of-frame hook ran from every FreeRTOS tick (1 kHz). Flashing is the ROM's download mode over UART0 and the CH343, and the console is UART0, so nothing is lost but the native port's console and JTAG, which the rig never used (its native port is unplugged, carrier-board.md §7). - The unused GPIOs: parked once at boot, inputs with the internal pull-down, by relay::
Bank:: begin() after it has released every relay: every free or caution pin of the board's table (firmware/ board/ pins.toml) that no role of the live map holds (pinmap:: parkedSet() in firmware/ src/ pinmap.h, from FW-04). For the default map that set is relay.h's kParkedPins, GPIO1, 2, 8 to 14, 16, 17, 18, 21, 39 to 42 and 47, and a static_assert holds the two equal, pin for pin. GPIO16 and GPIO17 are the unwired spares K3 and K4, which reach nothing since the temporary load NW-00 wired to GPIO16 was removed (2026-11-21). Left alone, with the reasons in relay.h: the strapping pins (0, 3, 45, 46), the flash and PSRAM lines (26 to 37), UART0 (43, 44), the native USB pair (19, 20: ESP-IDF disables its pad, and a gpio_config() on them writes the USB-Serial-JTAG's registers with its clock gated), the INA228's 4, 5 and 6, the relays' 7 and 15 and the LED lines 38 and 48 (held low by status_ led.cpp). static_asserts in relay.h and pinmap.h refuse a table that parks a reserved pin, an LED line or a pin of the default map. When a boot falls back to the default bus (§2.6), the pads the stored bus had are parked the same way before the default bus is opened (relay:: Bank:: park()). Under a stored map the rig's own pins are parked like any other no role holds, GPIO7 among them: an HW-316 input still wired to it would meet a pull-down, which sinks current through its LEDs, so move the wire before the map (§6.1).
The gate (scripts/
10. The project
Nothing here includes anything from the Kleidos firmware repository. Build from the repository root, with the PlatformIO virtualenv active: pio run --project-dir firmware -e meter (on the Kleidos bench, through that repository's scripts/
firmware/
No dynamic memory in our code. Every object of the instrument is static (constinit in app_main()); every task the firmware creates, every queue and every semaphore is made over static storage (xTaskCreateStaticPinnedToCore, xQueueCreateStatic, xSemaphoreCreateBinaryStatic), the console runs on the main task ESP-IDF created before app_main() (§5.1), over a static stack and control block its creation is linked wrapped onto (firmware/
11. What the instrument deliberately does not do
| Left out | Why |
|---|---|
| ENERGY | POWER integrated, and the instrument reports voltage and current at full rate; the host integrates them, and the capture's own energy is its mean power times its duration (§3.8) |
| Triggered conversions (MODE 0h–7h) | The accumulators are invalid in triggered mode ([DS] §7.3.4) and each sample would cost a write. The one use is deliberate: the boundary temperature of TRACE and BURST (§3.2) |
| Threshold alerts (BOVL, BUVL, TEMP_LIMIT, PWR_LIMIT, SOVL/SUVL as limits) | The limit registers are 16× coarser than the measurements ([DS] §7.6.1.13–18): 50 µA a step in range 0, a quarter of the whole sleep band. Verdicts belong on the host. The one use kept is the clip detector: SOVL = 7FF8h, SUVL = 8008h, eight limit counts inside each end of the field, written at every capture and null (ina228_regs.h kShuntOverLimitClip), with ALATCH = 1 so SHNTOL and SHNTUL reach flags=. The instrument's own threshold (SENSe:CURRent:THReshold) is a comparison in the loop (§3.8) |
| Auto-ranging | One range does both jobs (§3.1); a switch mid-capture costs a discarded period, an RSTACC, the other range's null and a 4× scale |
| SHUNT_TEMPCO / TEMPCOMP | The shunt's tempco is unmarked, the compensation follows the die, centimeters from the shunt, and can under-report at high shunt voltage ([DS] §7.3.5). The die temperature tells the host when the null has gone stale instead (§3.7) |
| CONVDLY | It aligns several monitors in time ([DS] §7.3.4); there is one |
| High-speed I²C | ESP-IDF has no master code for it (6.0.3, nor 6.1.1) (§2.1) |
| A radio | Never: the NW-00 A/B failed, and the meter is serial-only (§9) |
| A panel of its own, sessions, a lock | One opener holds a serial port, so there is nobody to share it with: the panel is the host's (kleidos-meter serve, the panel's guide), and lends the line to one client at a time |
| The LED as a status light | §8 |
11.1 CHARGE stays, as a probe
CHARGE is out of the sampling path, but SENSe:CHARge? and SENSe:CHARge:RESet stay, and every capture carries the pair of boundary reads (§3.5). The accumulator sums every conversion regardless of AVG ([DS] §7.3.2), so over a long window it would integrate away quantization, which makes it the natural number for a long sleep; but whether it accumulates at all at 10 µA, where one conversion contributes 0.0132 counts, is not stated by [DS] (ina228-reference.md §10 q1). So no number the protocol reports depends on it: every current comes from the VSHUNT path, and CHARGE is the hardware's independent check, its mean reported beside the samples' (§3.8). SENSe:CHARge? reports the raw count, the nominal conversion and of= (CHARGEOF, read in the same breath because reading CHARGE clears it); SENSe:CHARge:RESet writes RSTACC.