agentleFS
someboxsomebox/pcb-kit/skills/power-sim/SKILL.md

power-sim

Skill4 starsChanged 28 days agoMITView on GitHub

Simulate a board's power path in ngspice (load steps, start-up, switchover, brown-out and reset margins) to choose parts and check design notes. Use when a question is "does the rail stay above X when Y happens", "does the reset/supervisor trip", or "which of these parts behaves better", and a hand calculation is not convincing.

  • Installs packages

The file

We split this skill into the rules it gives an agent

4 rules. About 0 are common, 3 are distinctive, and 1 is very specific to this project.

  • ≈0

    Common · estimate

    Many files like this have a rule of this kind.

  • ≈3

    Distinctive · estimate

    This author's own choices. Worth a look.

  • 1

    Very specific

    Tied to their project's names, files or tools. Probably skip.

  • Common
  • Distinctive
  • Very specific
  1. Distinctive:

    Write the question and the pass/fail number first, in the design note it belongs to.

    line 26
  2. Distinctive:

    Write the result into the design note with the plot link, and add the simulated deviation to the tolerance analysis for worst cases.

    line 32
  3. Very specific:

    Switch: use ngspice's SW element. Its VT/VH give the comparator hysteresis (e.g.

    line 38
  4. Distinctive:

    Delay: add an RC on the control node for the comparator delay.

    line 40

≈ “Common” is an estimate: at least 1 in 5 of the 364,980 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.

Keep what fits and drop the rest. Your version, ready for your agents.
Files
SKILL.md

Power simulation with ngspice

The point is to answer one design question per script, with a number and a plot, and to write the answer back into the design notes. The dodeca control board v1.3 (~/src/dodeca-v2-hardware/hardware/control-board/v1.3/sim/) is the worked example: boost load steps, a supply-mux trace test that found a false result, and an options sweep that picked the replacement part.

Setup

brew install ngspice                 # KiCad ships the library only, not the CLI
pcbkit spice deck.cir --gear-retry   # runs in a scratch dir with -D ngbehavior=psa, prints .meas values

From a project script: from pcbkit.spice import run; run(text, sim_dir=..., vendor=..., gear_retry=True) returns measurements, ngspice's output, the wrdata files and an aborted flag. Keep vendor models out of git (sim/vendor/, fetched by a script) and the results in sim/results/ as text and PNG.

Way of working

  1. Write the question and the pass/fail number first, in the design note it belongs to.
  2. Pick the model: the vendor's transient model if it runs, otherwise an averaged model built from the vendor's control constants (error amp, current-sense gain, clamps) plus the board's real L, C and ESR. Parts without models become stand-ins (a current sink for a charger, R and C for a microcontroller's input).
  3. One script per question, printing a table; a sweep over the tolerances or the options when choosing.
  4. Plot the cases side by side (voltage solid, inductor or load current dotted on a second axis).
  5. Write the result into the design note with the plot link, and add the simulated deviation to the tolerance analysis for worst cases. Say what the model leaves out (switching ripple, temperature).

Parts with no model

A controller with a simple control law can be written from its datasheet. Example: rgb-spotlight sim/channel.py, a PT4115 hysteretic LED buck.

  • Switch: use ngspice's SW element. Its VT/VH give the comparator hysteresis (e.g. on below 85 mV, off above 115 mV across Rs).
  • Control: drive it from a B-source of the sense voltage, gated by the enable/DIM pin with u().
  • Delay: add an RC on the control node for the comparator delay; state it as an assumption.
  • Around it: the board's real L with DCR, a fitted diode model (IS, N, RS from two datasheet VF points), the caps at their DC-bias capacitance, and the supply cable.
  • Loads: an LED is an ideal diode + knee voltage + series R, at the datasheet VF.
  • Checks: in-loop powers (let p = v(a,b)*i(vsense), then meas avg) should add up to the input power. If they don't, the model is wrong.

What has gone wrong before

  • Switch-level TI models (TPS61178, TPS2121) stall within nanoseconds ("timestep too small"). Averaged models fix it.
  • LM66200 runs only from a powered operating point; ramps from 0 V make it chatter. A floating input needs a bleeder.
  • TPS2116 started with both supplies up can latch either channel: plug the second supply in after start-up.
  • An aborted run still prints meas = 0. Trust aborted, give the operating point time to settle before measuring.
  • B-source brace expansion: {a - b} * x becomes a - b*x; write ({a - b}) * x.
  • Instance names from an included file can't be reused in the deck.

Download now (ZIP)

Does it work?

Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.

No reviews yet

People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.

  • It worked
  • Partly
  • It didn't
What did you use it for? e.g. Reviewing pull requests in a Rails app

Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.

Your trail

Files you open will collect here, so you can find them again.

Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.

Now do this for your own.

Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.