Skip to content
242 changes: 242 additions & 0 deletions specs/blog/sar_adc_netlist.t27
Original file line number Diff line number Diff line change
@@ -0,0 +1,242 @@
// SPDX-License-Identifier: Apache-2.0
; specs/blog/sar_adc_netlist.t27 -- blog entry: a public SAR ADC netlist, read into .t27 and run on the AX7203
; The post answers three questions about the analog emulation work (epic #10486): what the reference circuit
; is, what problem it solves, and what was measured when its ngspice netlist became .t27 specs and an FPGA
; design. Pattern: specs/blog/t27b_progress.t27 (PostBlock body, ID for the specs/i18n/blog-ru.t27 bundle).
; -
; WHERE EVERY NUMBER COMES FROM (all public in this repository):
; netlist size, tables, comparator, speed, non-claims docs/analog/v0.1-release-notes.md (2026-10-24)
; acceptance rows per block docs/analog/accept-sar-2026-10-20.md, table of rows
; five-corner board receipts docs/analog/board-psp103-inv-buildb-2026-10-24.md
; and docs/analog/board-psp103-inv-2026-10-20.md (tt)
; the deck's timing, input and code formula header of specs/analog/sar_adc.t27
; The acceptance checks are an external team's report of 2026-10-16; the team confirmed on 2026-10-20 that
; the checks and limits may be used and published (release notes, section Acceptance). The deck is the
; golden deck of uberWAVE (GPL-2.0), read at run time and never vendored; sar_adc.t27 names its URL and hash.
; -
; WHAT THE TESTS HOLD: the shown acceptance counts are the sums of the per-block rows; a block passes only
; when none of its rows is NOT MODELLED or FAIL; every corner receipt line is a PASS; the comparator's
; percentage is its two times; the board step is slower than real time; the converter count and the
; conversion count follow from the deck's timing. Reads are array indexes, so no assert folds to vacuous.
; -
; NOT IN THIS FILE: a speed, power or chip claim; any name, price or message of a partner; the Russian body
; (it lives in trinity apps/website/i18n/blog.ru.json under ID, per specs/i18n/blog-ru.t27).

module BlogSarAdcNetlist;

; The 13 blocks of the external team's report, in the order of accept-sar-2026-10-20.md, with the number
; of rows (checks) per block and how many of those rows are NOT MODELLED or FAIL.
pub const BLOCKS: u32 = 13;
pub const BLOCK_NAME: [13]str = [
"inverter",
"nand",
"nor",
"tgate",
"dff",
"dynamic_comparator",
"tracking_switch",
"clock_gen",
"SAR_logic",
"DAC_control",
"DAC_control_top",
"neg_bottom_plate_logic",
"integration",
];
pub const ROWS: [13]u32 = [2, 2, 2, 3, 3, 4, 3, 4, 2, 1, 1, 1, 2];
pub const ROWS_NM: [13]u32 = [0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 1, 1, 0];
pub const ROWS_FAIL: [13]u32 = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0];

pub const SHOWN_BLOCKS_PASS: u32 = 9;
pub const SHOWN_BLOCKS_FAIL: u32 = 0;
pub const SHOWN_BLOCKS_NM: u32 = 4;
pub const SHOWN_ROWS: u32 = 30;
pub const SHOWN_ROWS_PASS: u32 = 26;
pub const SHOWN_ROWS_FAIL: u32 = 0;
pub const SHOWN_ROWS_NM: u32 = 4;

; The PSP103 inverter on the board, 400 steps of 100 ps into 500 fF: receipt lines and PASS lines per corner.
pub const CORNERS: u32 = 5;
pub const CORNER_NAME: [5]str = ["tt", "ss", "ff", "fs", "sf"];
pub const CORNER_LINES: [5]u32 = [1217, 1216, 1218, 1219, 1217];
pub const CORNER_PASS: [5]u32 = [1217, 1216, 1218, 1219, 1217];

; Comparator decision time at +2 mV in hundredths of a picosecond: ours (PSP103 tables with the devices'
; charge and the body effect), then ngspice's own run. The shown difference is in hundredths of a percent.
pub const CMP_PS100: [2]u32 = [61307, 60254];
pub const SHOWN_CMP_DIFF_BP: u32 = 175;

; One 100 ps backward Euler inverter step on the board: clocks at 100 MHz (10 ns each), lowest and highest,
; and the same in nanoseconds of wall time. The simulated step is 100 ps.
pub const BOARD_STEP_CLOCKS: [2]u32 = [1700, 1960];
pub const BOARD_STEP_NS: [2]u32 = [17000, 19600];
pub const SIM_STEP_PS: [2]u32 = [100, 100];

; The routed comparator evaluator unit against the board clock, in hundredths of a MHz.
pub const CMP_UNIT_FMAX_CMHZ: [2]u32 = [5946, 10000];

; The deck's timing in ns: one conversion period, the track phase, the run length, the input sine period.
pub const DECK_NS: [4]u32 = [500, 84, 16000, 16000];
pub const SHOWN_CONVERSIONS: u32 = 31;

; The behavioural converter against our ngspice run of the deck: codes matched, codes run, fitted numbers.
pub const CONVERTER: [3]u32 = [30, 31, 2];

; The post. A block is a paragraph ("p") or a heading ("h"), the two shapes trinity's blog Block type shares.
pub struct PostBlock {
kind: str,
text: str,
}

; Key of this post in a specs/i18n bundle (specs/i18n/blog-ru.t27).
pub const ID: str = "blog/sar-adc-netlist-to-fpga";
pub const SLUG: str = "sar-adc-netlist-to-fpga";
pub const TITLE: str = "A SAR ADC from its SPICE netlist to an FPGA: what the circuit is and what was measured";
pub const SUMMARY: str = "[numbers from the analog v0.1 release notes of 2026-10-24 and the corner receipts of the same day; no speed, power or chip claim] We took a public SAR ADC netlist, an 11-bit converter of 1265 transistors in the IHP SG13G2 open process, read it into .t27 specs and ran its blocks on an AX7203 FPGA bit for bit against the spec, with ngspice-47 and PSP103 as the judge. Of the 13 blocks of an external team's acceptance report, 9 pass, 0 fail and 4 are not modelled yet. The post says what the circuit does, what was measured and what is still missing.";
pub const DATE_ISO: str = "2026-11-07";
pub const TAGS: [3]str = ["t27", "Analog", "FPGA"];

pub const RECEIPT_LABEL: [9]str = [
"Analog emulation v0.1 release notes: every number with its source",
"The acceptance table: every row, its value, its limit and its function",
"Board receipts of the inverter on the ss, ff, fs and sf corners (2026-10-24)",
"Board receipt of the inverter on the tt corner (2026-10-20)",
"specs/analog/accept_sar.t27: the external team's checks as a .t27 evaluator",
"specs/analog/sar_adc.t27: the converter conversion by conversion, with the deck's source and hash",
"specs/tools/t27o/spice_convert.t27: the netlist reader and the subset it accepts",
"t27#10486: the analog emulation epic",
"IHP-Open-PDK: the SG13G2 process and its PSP103 models",
];
pub const RECEIPT_HREF: [9]str = [
"https://github.com/Trinity-S-AI-DNA/t27/blob/master/docs/analog/v0.1-release-notes.md",
"https://github.com/Trinity-S-AI-DNA/t27/blob/master/docs/analog/accept-sar-2026-10-20.md",
"https://github.com/Trinity-S-AI-DNA/t27/blob/master/docs/analog/board-psp103-inv-buildb-2026-10-24.md",
"https://github.com/Trinity-S-AI-DNA/t27/blob/master/docs/analog/board-psp103-inv-2026-10-20.md",
"https://github.com/Trinity-S-AI-DNA/t27/blob/master/specs/analog/accept_sar.t27",
"https://github.com/Trinity-S-AI-DNA/t27/blob/master/specs/analog/sar_adc.t27",
"https://github.com/Trinity-S-AI-DNA/t27/blob/master/specs/tools/t27o/spice_convert.t27",
"https://github.com/Trinity-S-AI-DNA/t27/issues/10486",
"https://github.com/IHP-GmbH/IHP-Open-PDK",
];

pub const OPEN_QUESTIONS: [4]str = [
"A board receipt compares the board with the spec, not with ngspice. The distance to ngspice is measured block by block in software, and the converter as a whole is scored by code match against one ngspice run.",
"No error(h/2) over error(h) order check exists yet for a nonlinear block. For the comparator and the SAR clock our time grid is ngspice's by construction, so agreeing with ngspice does not measure the time-step error.",
"The report's corner smoke suite (5 corners, -40 to 125 C) is not modelled, and the ss, ff, fs and sf board receipts are each from a single run.",
"Is a table model on an FPGA ever faster than SPICE for this circuit? Not measured. v0.1 is slower than real time and makes no speed claim.",
];

pub const body: [22]PostBlock = [
PostBlock { kind: "p", text: "This is a progress post about one task of t27: taking an analog circuit exactly as its designer wrote it, an ngspice netlist with foundry device models, and turning it into a .t27 specification that is at once the software reference and the FPGA design. The reference circuit is a real one, public under GPL-2.0, and every number below has its source in the repository." },
PostBlock { kind: "h", text: "The circuit" },
PostBlock { kind: "p", text: "The circuit is the SAR ADC of the golden deck of uberWAVE (wp2-parser/golden/top.spice, GPL-2.0): an 11-bit successive-approximation analog-to-digital converter in the IHP SG13G2 open process, with PSP103 transistor models. Expanded, it is 16 subcircuits, 1265 MOS transistors and 128 MIM capacitors. We read the deck at run time and never copy it into our repository." },
PostBlock { kind: "p", text: "Its blocks: two tracking switches that sample the differential input; a differential split capacitive DAC; a dynamic comparator; SAR logic built from eleven D flip-flops; a clock generator that issues the eleven bit clocks CK11 down to CK1; and a delay cell that times the comparator clock." },
PostBlock { kind: "h", text: "What problem it solves" },
PostBlock { kind: "p", text: "A SAR ADC turns an analog voltage into a number by binary search. It holds the input on its capacitor array, then asks the comparator eleven questions, most significant bit first: is the held input above the current guess? Each answer fixes one bit and moves the DAC plates to the next guess. After eleven decisions the eleven bits are the code. The deck reads the code out as V(out) = 1.5 V x code / 2048." },
PostBlock { kind: "p", text: "The deck's own test drives the input with a 0.6 V sine around 0.75 V, period 16 us, and converts every 500 ns: the first 84 ns of each period track the input, the eleven decisions follow. In 16 us that is 31 finished conversions." },
PostBlock { kind: "h", text: "The task: one netlist, three judges" },
PostBlock { kind: "p", text: "SPICE is the judge of analog design, and a run of a block like this one is long: our ngspice-47 run of this deck, 16 us of circuit time, took 65 minutes of wall time on a shared Mac. The task is to take the same netlist, unchanged, and make it a hardware design whose every step is fixed by a spec, so the result can be checked three ways: the board against the spec bit for bit, the spec against ngspice block by block, and both against an external team's acceptance checks. The designer keeps the netlist, and ngspice stays the reference: nothing here replaces SPICE." },
PostBlock { kind: "h", text: "What we built" },
PostBlock { kind: "p", text: "The pipeline is .t27 end to end. A netlist reader (specs/tools/t27o/spice_convert.t27) parses the supported ngspice subset, expands the subcircuits, and refuses anything else with its line number instead of approximating it. The linear part becomes an exact state-space cell. Each PSP103 transistor becomes a table model, 25 x 25 tables per process corner, generated from ngspice with the OSDI PSP103 models. t27 writes the Verilog, yosys and nextpnr-xilinx build the bitstream for the ALINX AX7203 board, and the board prints receipt lines over UART that are compared with the spec bit for bit." },
PostBlock { kind: "h", text: "What was measured" },
PostBlock { kind: "p", text: "[measured] Netlist: the golden deck parses and flattens to 16 subcircuits, 1265 MOS and 128 capacitors. Device tables against the full PSP103 evaluation in ngspice: 0.56 % and 0.41 % on the tt current tables where the drain current is at least 100 uA, and each of the five corners within 0.734 % at worst on its log tables." },
PostBlock { kind: "p", text: "[measured] Comparator: with the devices' charge and the body effect, the modelled decision time is 613.07 ps against 602.54 ps in ngspice's own run (+1.75 %). With the charge removed the model decides in 5.40 ps, and the acceptance evaluator refuses it." },
PostBlock { kind: "p", text: "[measured] On the board: the PSP103 inverter, 400 steps of 100 ps into 500 fF, gives 1217, 1216, 1218, 1219 and 1217 receipt lines on the tt, ss, ff, fs and sf corners, every line equal to the spec; the ss, ff, fs and sf receipts are each from a single run. The behavioural SAR converter top gives 549 of 549 receipt lines. A PASS on the board says the board equals the spec bit for bit, not that it equals ngspice; the spec's distance to ngspice is what the rows above state." },
PostBlock { kind: "p", text: "[measured] Acceptance: an external team's report of 2026-10-16 lists, for each of the 13 blocks of this converter, a check and its limit, and the team confirmed on 2026-10-20 that the checks and limits may be used and published. specs/analog/accept_sar.t27 applies them to our models. 9 blocks PASS (clock_gen, SAR_logic, integration, nand, nor, tgate, dynamic_comparator, inverter, tracking_switch), 0 FAIL, 4 NOT MODELLED (dff, DAC_control, DAC_control_top, neg_bottom_plate_logic). By rows: 26 of 30 PASS, 0 FAIL, 4 NOT MODELLED. A row we do not compute never counts as a pass." },
PostBlock { kind: "h", text: "What is not claimed" },
PostBlock { kind: "p", text: "No speed claim: one 100 ps inverter step on the board takes 17.0 to 19.6 us, slower than real time, and no speedup against SPICE has been measured. No power, noise, mismatch or temperature claim. The converter is not predicted end to end: the behavioural converter matches 30 of the 31 codes of our ngspice run only with two fitted numbers. The comparator step is not on the board: one routed evaluator unit reaches 59.46 MHz, misses timing at 100 MHz and was never loaded. The external team's own evaluator and testbenches were not run by us. This is a SAR ADC and its blocks, not a chip." },
PostBlock { kind: "h", text: "What comes next" },
PostBlock { kind: "p", text: "The four NOT MODELLED blocks; the comparator step on the board with several evaluator units (t27#11380); the converter loop with the PSP103 comparator and switch inside it, so the two fitted numbers go away; and a second circuit, once its block and its pass criterion are named. Each step lands as a .t27 spec with its tests first." },
PostBlock { kind: "h", text: "Can it be seen" },
PostBlock { kind: "p", text: "Not yet as a live view. T27F, the visual form of .t27 specs, does not draw specs/analog today; a circuit view of this netlist, each subcircuit coloured by its acceptance verdict, is the open work item, and this post will link it when it is published." },
];

test the_shown_acceptance_counts_are_the_rows {
var i: u32 = 0;
var rows: u32 = 0;
var nm: u32 = 0;
var fail: u32 = 0;
var bpass: u32 = 0;
var bnm: u32 = 0;
var bfail: u32 = 0;
while (i < BLOCKS) {
rows = rows + ROWS[i];
nm = nm + ROWS_NM[i];
fail = fail + ROWS_FAIL[i];
if (ROWS_NM[i] == 0 and ROWS_FAIL[i] == 0) {
bpass = bpass + 1;
}
if (ROWS_FAIL[i] > 0) {
bfail = bfail + 1;
}
if (ROWS_FAIL[i] == 0 and ROWS_NM[i] > 0) {
bnm = bnm + 1;
}
i = i + 1;
}
assert_eq(rows, SHOWN_ROWS);
assert_eq(nm, SHOWN_ROWS_NM);
assert_eq(fail, SHOWN_ROWS_FAIL);
assert_eq(rows - nm - fail, SHOWN_ROWS_PASS);
assert_eq(bpass, SHOWN_BLOCKS_PASS);
assert_eq(bnm, SHOWN_BLOCKS_NM);
assert_eq(bfail, SHOWN_BLOCKS_FAIL);
assert_eq(bpass + bnm + bfail, BLOCKS);
}

test no_block_has_more_open_rows_than_rows {
var i: u32 = 0;
while (i < BLOCKS) {
assert(ROWS[i] > 0);
assert(ROWS_NM[i] + ROWS_FAIL[i] <= ROWS[i]);
i = i + 1;
}
}

test every_corner_receipt_line_is_a_pass {
var i: u32 = 0;
while (i < CORNERS) {
assert(CORNER_LINES[i] > 0);
assert_eq(CORNER_PASS[i], CORNER_LINES[i]);
i = i + 1;
}
}

test the_comparator_percentage_is_its_two_times {
var ours: u32 = CMP_PS100[0];
var ng: u32 = CMP_PS100[1];
assert(ours > ng);
assert_eq(((ours - ng) * 10000 + ng / 2) / ng, SHOWN_CMP_DIFF_BP);
}

test the_board_step_is_slower_than_real_time {
var i: u32 = 0;
while (i < 2) {
assert_eq(BOARD_STEP_CLOCKS[i] * 10, BOARD_STEP_NS[i]);
assert(BOARD_STEP_NS[i] * 1000 > SIM_STEP_PS[i]);
i = i + 1;
}
assert(BOARD_STEP_NS[0] < BOARD_STEP_NS[1]);
}

test the_comparator_unit_misses_the_board_clock {
assert(CMP_UNIT_FMAX_CMHZ[0] < CMP_UNIT_FMAX_CMHZ[1]);
}

test the_conversion_count_follows_from_the_deck_timing {
var period: u32 = DECK_NS[0];
var track: u32 = DECK_NS[1];
var run: u32 = DECK_NS[2];
var sine: u32 = DECK_NS[3];
assert(track < period);
assert_eq(run / period - 1, SHOWN_CONVERSIONS);
assert_eq(sine / period, 32);
}

test the_converter_is_not_end_to_end {
var matched: u32 = CONVERTER[0];
var total: u32 = CONVERTER[1];
var fitted: u32 = CONVERTER[2];
assert_eq(total, SHOWN_CONVERSIONS);
assert(matched < total);
assert(fitted > 0);
}
Loading