← Commit history

Source for 0.3.0: calculators, schematics, tests, README screenshots, standards register, calculator-standards dev skill and release publish skill

Caleb ·0788d52fbf · ·parent 4530b6d
12 files changed +197−12
README.md+10−10
@@ -30,16 +30,16 @@ Or from the terminal, no server needed: `hwcalc calc trace I=3 dT=20 oz=2`, `hwc  ✎ = draws the circuit or cross-section. -- **Basics** — Ohm's law & power · Voltage divider ✎ · LED series resistor ✎-- **Signal** — RC / RL / LC time constants & cut-off ✎ · Rise time, bandwidth & critical length · Skin depth · Reactance & RLC resonance ✎ · Op-amp gain & bandwidth ✎ · 555 timer ✎-- **PCB** — Trace width for current (IPC-2152 / IPC-2221) ✎ · Microstrip / stripline impedance (IPC-2141) ✎ · Conductor spacing for voltage (IPC-2221 Table 6-1) ✎ · Differential pair impedance (edge-coupled) ✎ · Via: resistance, current, parasitics ✎ · Fusing current (Onderdonk)-- **Power** — Linear regulator dissipation ✎ · Buck converter: inductor & ripple ✎ · Boost converter: inductor & ripple ✎ · Hold-up / bulk capacitor ✎ · Battery life (duty-cycled load) · Adjustable regulator feedback resistors ✎ · MOSFET conduction & switching loss ✎ · PDN target impedance-- **Interfaces** — I²C pull-up resistor range ✎ · Crystal oscillator load capacitors (CL) ✎ · Frequency tolerance (ppm)-- **Measurement** — Current-sense shunt ✎ · ADC resolution & ideal SNR · NTC thermistor (β model) ✎-- **Thermal** — Junction temperature & heatsink ✎-- **Wiring** — Wire gauge: resistance & drop-- **RF** — dBm · watts · volts · Wavelength & antenna lengths · Resistive attenuator (Pi / Tee) ✎ · VSWR · return loss · mismatch loss · Planar spiral inductor ✎-- **Components** — Standard values & resistor codes · Series / parallel combinations ✎ · Two-resistor combination finder ✎ · Length & copper unit converter+- **Basics**: Ohm's law & power · Voltage divider ✎ · LED series resistor ✎+- **Signal**: RC / RL / LC time constants & cut-off ✎ · Rise time, bandwidth & critical length · Skin depth · Reactance & RLC resonance ✎ · Op-amp gain & bandwidth ✎ · 555 timer ✎+- **PCB**: Trace width for current (IPC-2152 / IPC-2221) ✎ · Microstrip / stripline impedance (IPC-2141) ✎ · Conductor spacing for voltage (IPC-2221 Table 6-1) ✎ · Differential pair impedance (edge-coupled) ✎ · Via: resistance, current, parasitics ✎ · Fusing current (Onderdonk)+- **Power**: Linear regulator dissipation ✎ · Buck converter: inductor & ripple ✎ · Boost converter: inductor & ripple ✎ · Hold-up / bulk capacitor ✎ · Battery life (duty-cycled load) · Adjustable regulator feedback resistors ✎ · MOSFET conduction & switching loss ✎ · PDN target impedance+- **Interfaces**: I²C pull-up resistor range ✎ · Crystal oscillator load capacitors (CL) ✎ · Frequency tolerance (ppm)+- **Measurement**: Current-sense shunt ✎ · ADC resolution & ideal SNR · NTC thermistor (β model) ✎+- **Thermal**: Junction temperature & heatsink ✎+- **Wiring**: Wire gauge: resistance & drop+- **RF**: dBm · watts · volts · Wavelength & antenna lengths · Resistive attenuator (Pi / Tee) ✎ · VSWR · return loss · mismatch loss · Planar spiral inductor ✎+- **Components**: Standard values & resistor codes · Series / parallel combinations ✎ · Two-resistor combination finder ✎ · Length & copper unit converter  ## Why you can trust it 
bin/hwcalc

  
dev-skills/hwcalc-calculator-standards/SKILL.mdadded+127
@@ -0,0 +1,127 @@+---+name: hwcalc-calculator-standards+description: >+  How to add, change or fix a calculator in the Hardware Calculator (hwcalc) source so it meets the bar every existing one+  meets: each formula, constant and table verified against the governing standard or a trusted primary source fetched in the+  same session (current revision confirmed), a hand-checked test that reproduces the source's own worked example, a cited+  `ref`, and a labelled schematic or cross-section for any calculator that describes a circuit or physical structure. Use+  when someone says add a calculator to hwcalc / Hardware Calculator, new hardware calculation, update a formula, a standard+  changed (new IPC revision), fix a wrong result, add or fix a schematic drawing, or review a hwcalc pull request.+---++# Changing a Hardware Calculator calculator++The app's value is that engineers can trust every number without re-deriving it. A calculator that is quick to add but+unverified damages the other 40. So each change follows the six gates below, in order, and the pull request or commit message+states how each gate was met. If a gate cannot be met (the standard is paywalled and has no independent reproduction), the+calculator does not ship: say so rather than approximate.++Files: `calcs.js` (every formula, one `def({...})` per calculator), `schematics.js` (drawings), `test.js`,+`docs/standards.md` (hand-maintained standards register), `SOURCES.md` (generated), `CHANGELOG.md`.++## Gate 1 — find the governing source and confirm its revision++Rank sources in this order and use the highest one available:++1. **The governing standard**: IPC (2221, 2152, 2141, 2222 …), IEC (60063 E-series, 60062 codes), JEDEC, IEEE, bus+   specifications (NXP UM10204 I²C, USB-IF, JESD). Confirm the CURRENT revision from the publisher (shop.ipc.org,+   webstore.iec.ch, nxp.com …) or a dated release announcement, and write it down with today's date.+2. **Manufacturer primary documents**: application notes and datasheets (TI, ST, ADI, Microchip, NXP, Infineon, crystal+   makers). Cite the document number, revision and section, for example "ST AN2867 Rev 10 §3.4".+3. **Peer-reviewed papers and standard textbooks**: IEEE journals; Johnson & Graham, *High-Speed Digital Design*; Horowitz &+   Hill. Cite the author, title, year, and the equation or figure.+4. **A paywalled standard with no public text**: accept it only with TWO independent reproductions that agree (as+   IPC-2221 Table 6-1 was checked). Record both URLs.++Not acceptable as the source: memory (including an AI's), a single forum post, a calculator website that does not cite its+own source, or vendor tools with undisclosed fits (for example Sierra Circuits' IPC-2152 tool). These are fine as a+cross-check of the result, never as the reference.++Fetch the source in THIS session and read the equation from it. Tips that have worked from an Adom container:++- st.com PDFs are unreachable: search for a vendor-hosted mirror of the same document (for example a crystal maker hosting+  AN2867), download it, run `pdftotext -layout file.pdf out.txt` and read the section. Check the `DocID … Rev` footer to+  confirm the revision.+- IPC tables: publisher store pages confirm the revision; reproductions give the numbers.++## Gate 2 — implement exactly what the source says++In `calcs.js` add or edit a `def({...})` block:++- `formula`: every equation used, in the source's notation, one per line (`\n`).+- `ref`: document + revision + section/equation, and the accuracy the source claims (for example "±5–10 %").+- `notes`: what is NOT modelled (for example "IPC-2152 modifiers not applied: conservative") and the valid range.+- `warnings`: the source's own pass/fail rules (for example "gain margin < 5 (AN2867 §3.4)").+- Inputs: engineering units with SI prefixes (`unit: 'F'`); dimensionless or non-SI values set `si: false` (mm, %, °C,+  AWG, oz). Optional inputs default to `''` and the compute function skips the outputs that need them.+- No fudge factors, no "typical" constants the source does not give. If you round a published constant, say so in `ref`.+- Keep calculator ids stable: users hold `#<id>?k=v` links and AIs call `hwcalc open <id>`. Extend an existing calculator+  (new mode or optional inputs) rather than renaming it; the crystal CL upgrade kept the id `crystal`.++## Gate 3 — tests from the source's own numbers++In `test.js`:++- At least one check reproduces a **worked example printed in the cited source** (for example AN2867's 8 MHz / C0 7 pF /+  CL 10 pF / ESR 80 Ω → gm_crit 0.23 mA/V and gain margin ≈ 107; UM10204 Fast-mode 200 pF → 967 Ω–1.77 kΩ). Put the+  source and its page or section in a comment.+- Hand-computed checks written as the formula itself in the test (not copied from the calculator's output), plus the+  error and warning paths (a bad input yields `error`; a failing design yields a warning).+- Every mode of every select input runs; the schematic render test covers drawings automatically.++`node test.js` must print `N/N checks passed`.++## Gate 4 — the relevant circuit++If the calculator describes a circuit, a PCB structure or a physical layout, it gets a drawing in `schematics.js`:++```js+D.<id> = (k, { vin, vo, v }) => {+  // vin(key) = the live input with its unit; vo('Label prefix') = a live output's text; v = parsed inputs (modes)+  k.rail(140, 38, 'Vin', vin('Vin')).part('R', 140, 38, 140, 108, 'R1', vin('R1')).dot(140, 108)+   .part('R', 140, 108, 140, 178, 'R2', vin('R2')).gnd(140, 178);+  return k.svg(440, 202, 'Vout = Vin · R2 / (R1 + R2)');   // caption: the key relation or the headline result+};+```++- Kit: `part('R'|'C'|'L'|'X'|'D'|'LED'|'SW'|'NTC', x1,y1,x2,y2, name, value, side)` (axis-aligned; side `'l'`,+  `'b'`, `'r2'` move labels), `wire`, `dot`, `rail`, `gnd`, `term(x,y,label,value,'l'|'r')`, `opamp`, `inverter`, `nmos`,+  `box`, `pinLabel`, `dim` (dimension arrows), `rect(..., 'cu'|'fr4'|'air'|'box'|'dash')`, `text(x,y,s,'n'|'v'|'pin')`.+- Draw the topology the formula assumes (for example the Pierce oscillator for crystal CL, with C1 on OSC_IN) and draw+  every mode (`if (v.mode === …)`). Label parts with the SAME names as the inputs (R1, C1, Rf) and show live values.+- Cross-sections are "not to scale" and say so in the caption.+- `vin()` already includes the unit: never append it again ("dB dB", "oz oz" were real bugs).+- Pure calculators (unit conversion, ppm, dBm) get no drawing; do not invent one.++Then LOOK at it. The render test only proves it does not crash. Render a contact sheet of every mode with headless Chrome+and read the image:++```bash+node -e "const S=require('./schematics.js');require('fs').writeFileSync('/tmp/s.html','<body style=background:#0d1117>'+[['<id>',{}],['<id>',{mode:'<other>'}]].map(([i,v])=>S.draw(i,v)).join(''))"+C=$(find ~/.cache/puppeteer/chrome -name chrome -type f -perm -u+x | head -1)+$C --headless=new --no-sandbox --disable-gpu --window-size=1500,1200 --screenshot=/tmp/s.png file:///tmp/s.html+```++Check for: labels clipped at the left edge (terminal labels anchor to the left of x, so keep terminals at x ≥ 70), labels+overlapping a part or wire, missing values (an output label prefix that does not match), and wrong topology.++## Gate 5 — see it in the app++```bash+hwcalc --ai-thread "<name>" shutdown --reason "reload changed calculator"; hwcalc --ai-thread "<name>" start+hwcalc --ai-thread "<name>" open <id> key=value …+adom-cli hydrogen screenshot panel --name "Hardware Calculator" --reason "verify <id>"+```++Read the screenshot: the results, the warning and note boxes, and the drawing under Results.++## Gate 6 — record it++- `docs/standards.md`: add or update the source's row (revision, date checked, how it is used).+- `node scripts/sources.js` regenerates `SOURCES.md` (every calculator with its formula, ref and drawing status).+- `CHANGELOG.md`: what changed and which source verified it. Changing an existing formula also says what the old one was+  and why it was wrong.+- Bump `package.json` version: a new calculator or drawing is a minor bump; a fix is a patch.+- Update the calculator list and the trigger words in `skills/hwcalc/SKILL.md` and `README.md` if a calculator was added.++Releasing the new version to the wiki is the `hwcalc-release` publish skill.
docs/buck-converter.pngadded
⋯ 1 unchanged line ⋯
docs/crystal-oscillator.pngadded
⋯ 1 unchanged line ⋯
docs/showcase-crystal.pngadded
⋯ 1 unchanged line ⋯
docs/standards.mdadded+16
@@ -0,0 +1,16 @@+## Standards register++Every row was checked against the publisher or two independent reproductions on the date shown. Re-check a row+before relying on it for a change, and update the date when you do.++| Standard / source | Current revision | Checked | How hwcalc uses it |+|---|---|---|---|+| IPC-2221 Generic Standard on Printed Board Design | Rev C, Dec 2023 (supersedes B, 2012) | 2026-09-25 | Table 6-1 conductor spacing B1/B2/B4 (sea-level values unchanged from B, cross-checked against two reproductions); legacy trace-width formula k = 0.048 / 0.024. B5 and A5–A7 not modelled. |+| IPC-2152 Current-Carrying Capacity | Rev 0, 2009 (still current; chart-only) | 2026-09-25 | Default trace width: published baseline-chart curve fit (smps.us). Modifiers (board thickness, planes) not modelled: conservative. |+| IPC-2141A Controlled Impedance Design | 2004 | 2026-09-25 | Microstrip / stripline and edge-coupled differential closed forms (±5–10 %; confirm with a field solver). |+| IEC 60063 preferred number series | E3–E192 | 2026-09-25 | E-series values, including the E192 920 exception; full E96 table under test. |+| IEC 60062 marking codes | — | 2026-09-25 | Resistor colour bands; EIA-96 SMD codes. |+| NXP UM10204 I²C-bus specification | Rev 7.0, 1 Oct 2021 (title of nxp.com/docs/en/user-guide/UM10204.pdf) | 2026-09-25 | Pull-up min/max from VOL/IOL and rise time. |+| ST AN2867 Oscillator design guide | Rev 10, Aug 2015 | 2026-09-25 | Crystal CL, gm_crit, gain margin ≥ 5, drive level (§3.3–3.5). Read from a vendor-hosted mirror PDF (st.com is unreachable from Adom containers). |+| Onderdonk fusing equation | classical | 2026-09-25 | Fusing current for traces and wires. |+| Mohan, Hershenson, Boyd & Lee, IEEE JSSC 34(10), 1999 | — | 2026-09-25 | Planar spiral inductance (modified Wheeler). |
install.sh

  
package.json+1−2
@@ -44,8 +44,7 @@     "package.json",     "README.md",     "SOURCES.md",-    "CHANGELOG.md",-    "docs/hero.png"+    "CHANGELOG.md"   ],   "changelog": "0.3.0: AN2867-verified crystal oscillator CL calculator; live schematics for 26 calculators; sources register",   "discovery_triggers": [
publish-skills/hwcalc-release/SKILL.mdadded+29
@@ -0,0 +1,29 @@+---+name: hwcalc-release+description: >+  Release a new version of the Hardware Calculator (hwcalc) to the Adom Wiki page adom/hardware-calculator: run the tests,+  regenerate SOURCES.md, bump the version, publish the package and push the source (including dev and publish skills).+  Use when someone says release hwcalc, publish the hardware calculator, ship the new calculator, or update the wiki page.+---++# Releasing the Hardware Calculator++Only release a change that passed every gate in the `hwcalc-calculator-standards` dev skill (verified source, source+worked-example test, drawing checked by eye, app screenshot). Anyone in the adom org can publish; that trust is why the gates+exist.++```bash+cd <source checkout>                       # adom-wiki repo clone adom/hardware-calculator+node test.js                               # must print N/N checks passed+node scripts/sources.js                    # regenerate SOURCES.md+# bump "version" in package.json (new calculator/drawing = minor, fix = patch) and add a CHANGELOG.md entry+adom-wiki pkg publish --org adom           # the installable: CLI, server, UI, user skill+adom-wiki repo push adom/hardware-calculator -m "<version>: <what changed and which source verified it>"+```++`pkg publish` ships only the user skill (`skills/`); `repo push` puts the whole source on the page, including+`dev-skills/` and `publish-skills/`. Do both on every release, or the Files tab and the installable drift apart.++Verify: `adom-wiki page stats adom/hardware-calculator` shows the new version; `adom-wiki pkg install+adom/hardware-calculator` then `hwcalc --version` prints it; the hero still renders. A new hero needs a human in Hero Studio+(`hero-studio --ai-thread "<name>" pose adom/hardware-calculator`, then the human clicks Generate); never fake one.
scripts/sources.jsadded+14
@@ -0,0 +1,14 @@+#!/usr/bin/env node+/* Regenerates SOURCES.md: every calculator with its formula, cited reference and drawing status, under the+ * hand-maintained standards register in docs/standards.md. Run after any calculator change: node scripts/sources.js */+'use strict';+const fs = require('fs'), path = require('path');+const ROOT = path.join(__dirname, '..');+const H = require(path.join(ROOT, 'calcs.js')), S = require(path.join(ROOT, 'schematics.js')), PKG = require(path.join(ROOT, 'package.json'));+const esc = s => String(s).replace(/\|/g, '\\|').replace(/\n/g, '<br>');+let md = `# Hardware Calculator — sources register\n\nGenerated by \`node scripts/sources.js\` for v${PKG.version}. Do not edit the calculator table by hand;\nedit \`ref\` / \`formula\` in calcs.js and regenerate. The standards register above it is maintained by hand in\n\`docs/standards.md\`.\n\n`;+md += fs.readFileSync(path.join(ROOT, 'docs', 'standards.md'), 'utf8').trim() + '\n\n';+md += `## Calculators (${H.CALCS.length})\n\n| id | Calculator | Drawing | Formula | Reference |\n|---|---|---|---|---|\n`;+for (const c of H.CALCS) md += `| \`${c.id}\` | ${esc(c.title)} | ${S.has(c.id) ? 'yes' : '—'} | \`${esc(c.formula)}\` | ${esc(c.ref)} |\n`;+fs.writeFileSync(path.join(ROOT, 'SOURCES.md'), md);+console.log(`SOURCES.md: ${H.CALCS.length} calculators, ${S.ids.length} drawings`);
uninstall.sh