Monday, October 26, 2026

Simulation Plan Library - Basic

Analog Sim-Plan Finder: Core Analog Blocks is a free search app over simulation plans for analog IC blocks. For every row of a block's Electrical Characteristics table it names the simulation that produces the number, with testbench, stimulus, load, PVT corners or Monte Carlo setup, measurement expression, quantitative pass criteria and the pitfalls that give a wrong number or a false pass. This edition covers the core analog IC building blocks at a generic 1.8 V / 180 nm CMOS profile: bandgap and bias references, op-amps and OTAs, comparators and level shifters, LDOs, power-on reset and charge pumps, ring, relaxation and crystal oscillators, switches and switched-capacitor circuits, filters, and ADCs and DACs of every common architecture. 37 blocks · 1,008 characteristic rows · 679 simulations · 16 methods pages; simulator-agnostic (ngspice, Spectre, HSPICE).

Simulation plans in this edition

References & Bias: Bandgap Voltage Reference · Constant-gm (Beta-Multiplier) Bias Generator · Current Mirror and Cascode Bias Distribution.

Amplifiers: Five-Transistor OTA (Differential Pair with Current-Mirror Load) · Folded-Cascode OTA (Single-Ended Output) · Fully Differential OTA with Common-Mode Feedback · Source Follower Buffer · Telescopic Cascode OTA (Single-Ended Output) · Two-Stage Miller-Compensated Op-Amp.

Comparators & Logic Interfaces: CMOS Schmitt Trigger · Continuous-Time Comparator · Dynamic Latch Comparator (StrongARM / Double-Tail) · Voltage-Domain Level Shifter (Low-to-High).

Regulators & Power: Low-Dropout Linear Regulator (PMOS pass device) · Power-On Reset and Brown-Out Detector · Switched-Capacitor Charge Pump (Voltage Doubler / Dickson).

Oscillators & Clocking: Pierce Crystal Oscillator · RC Relaxation Oscillator · Ring Oscillator VCO · Two-Phase Non-Overlapping Clock Generator.

Switches & Sampling: Bootstrapped NMOS Sampling Switch · CMOS Switch and Transmission Gate (sampling switch) · Switched-Capacitor Integrator (parasitic-insensitive, bottom-plate sampled).

Filters: Active-RC Biquad Low-Pass Filter.

Data-Converter Building Blocks: Capacitive (Charge-Redistribution) DAC Array · SAR ADC Comparator (dynamic preamplifier + regenerative latch, offset-trimmed).

Data Converters: Charge-Redistribution SAR ADC · Continuous-Time Delta-Sigma Modulator · Current-Steering DAC · Delta-Sigma (Oversampling) DAC, Analog Back End · Discrete-Time (Switched-Capacitor) Delta-Sigma Modulator · Flash ADC · Integrating (Dual-Slope) ADC · Pipelined ADC · R-2R Ladder DAC · Resistor-String (Kelvin Divider) DAC · Time-Interleaved ADC.

What each plan contains

Summary, topologies covered and design notes; ports and operating conditions; a datasheet-style table of 20–35 electrical characteristics with conditions, min/typ/max, unit and the producing simulation; and 15–22 simulations (functional, characterisation, robustness, statistical), each with purpose, testbench, stimulus, load, conditions, sweep, measures, pass criteria, pitfalls, runtime and methods references. Any block's table downloads as CSV, and the whole plan as a self-contained HTML datasheet or a PDF print.

How to use it

Click “Open Analog Sim-Plan Finder: Core Analog Blocks ↗”: the finder opens in a new window. It is built from data embedded in this page, so there is nothing to install and no account; it needs a current browser (Chrome, Edge, Firefox or Safari from 2023 on). Type a symbol (PSRR, VOS, TC, PN_1M), a question (startup, settling, mismatch, jitter) or a block name, then narrow with the drop-downs for type, category, block, analysis, kind and priority. Back and Forward work, and every view can be bookmarked.

Source: GitHub repository (the plans as YAML under an MIT licence, the generated site and this finder) · hosted site and finder with the whole library. The companion edition, “Analog Sim-Plan Finder: High-Speed & AI Hardware”, is a separate post and covers the rest of the library.

Saturday, October 24, 2026

Dear Skywater, If You Could Please Fix the 130 nm Model File

sky130 .lib mc process Monte Carlo is broken under ngspice Four separate defects in the shipped model cards. Mismatch Monte Carlo is unaffected.
Status
Open  workaround available (mismatch only)
Severity
High  silent wrong results, no error or warning
Component
sky130 PDK SPICE models, libs.tech/combined/sky130.lib.spice, section .lib mc
Simulator
ngspice 45.2 (stock) and an ngspice 46 development build; both behave identically
Not affected
.lib tt (and other corners) with .param mc_mm_switch=1, i.e. mismatch-only Monte Carlo
Found
2026-10-24, while measuring ngspice for 1000+ sample Monte Carlo runs; every point below was reproduced by an independent second check

Summary

The sky130 model library offers a mc section meant to give per-die process variation: each Monte Carlo sample should draw one set of global process parameters (sheet resistances, oxide thickness, threshold shifts) shared by every device on the die. Under ngspice it does not do that. Most of the process terms are effectively zero, one is about double what it should be, nothing is shared die-wide, and the VT and oxide-thickness terms are switched off in the file.

None of this produces an error. A process Monte Carlo run completes, the histograms look plausible, and the spread is wrong.

Defects

1. Every GAUSS(0, rel, 1) process term is dead

Process terms are written like this (continuous/parameters_res_nom.spice):

.param sw_sky130_fd_pr__res_xhigh_po_rs = {2000.0+corner_factor*0.0} + process_mc_factor*MC_PR_SWITCH*GAUSS(0,0.04,1)

In ngspice, gauss(nom, rvar, sigma) is a relative distribution: the random part is nom × rvar × N(0,1)/sigma. With nom = 0 the term is always exactly 0. Each call still consumes a random number, so the stream advances, but the parameter never moves. The intent was clearly an absolute or relative-to-2000 spread; as written it is neither.

In the files that .lib mc includes, 19 process parameters have this shape and never vary: every resistor sheet resistance (res_high_po, res_xhigh_po, metals 1–4, poly head, sw_rl1, sw_rnw, sw_rp1, sw_rdn, sw_rdp), the five junction capacitances (sw_nsd_pw_cj, sw_psd_nw_cj, sw_nw_pw_cj, sw_pw_dnw_cj, sw_dnw_sub_cj), sw_nldd and the MIM capacitance sw_cap_mim_ca. The other corner files carry the same pattern.

2. sw_nw_rs_mult adds where it should multiply

.param sw_nw_rs_mult = {1.0+corner_factor*0.0} + process_mc_factor*MC_PR_SWITCH*EXP(AGAUSS(0,0.12,1))

A lognormal multiplier should be 1.0 * EXP(AGAUSS(...)), centred on 1. Written with +, it is 1 + ex, centred on 2. Measured values fell between 1.86× and 2.09× the intended multiplier. Through the n-well sheet resistance this moves the PNP current gain: bf goes from 18.4 nominal to 29–34 under .lib mc, which is a corner shift, not a spread.

3. No die-level correlation: every reference redraws

A "global" process parameter should be drawn once per sample. ngspice cannot hold a random value in a .param; it rewrites any .param containing agauss/gauss into a .func (inp_fix_agauss_in_param in inp.c), so every textual reference evaluates it again. Two identical resistors that both use sw_nw_rs_mult get two different values in the same sample. Process variation is therefore turned into uncorrelated per-device noise, which is the one thing it must not be.

4. VT and tox process variation is hard-coded to zero

In continuous/models_global.spice the per-sample terms are constants, and the Spectre-style vary statements that would have driven them are commented out:

.param
+ sw_tox_lv_mc = 0
+ sw_tox_hv_mc = 0
+ sw_vth0_sky130_fd_pr__nfet_01v8_mc = 0
+ sw_vth0_sky130_fd_pr__pfet_01v8_mc = 0
  ...
*    statistics{
*       process{
*          vary sw_tox_lv_mc   dist=gauss   std=0.375e-10*process_mc_factor
*          vary sw_tox_hv_mc   dist=gauss   std=1.25e-10*process_mc_factor
  ...

So even with defects 1–3 fixed, threshold voltage and oxide thickness, usually the dominant process terms for analog work, would not vary.

Expected vs actual

PropertyExpected under .lib mcActual (ngspice 45.2 and 46-dev)
Sheet-resistance and other GAUSS process termsVary sample to sampleConstant at nominal (19 parameters)
sw_nw_rs_multLognormal around 1.01.86–2.09 (around 2.0)
PNP bf (W0p68)Spread around 18.429–34
Two devices sharing a global parameterSame value in one sampleDifferent values
VT, tox process shiftGaussian per die0
Error or warning—None

How to reproduce

Two identical resistors per process parameter, plus two PNPs. Run once with process variation off and then for a few seeds. Set the .lib path to your PDK.

* sky130 .lib mc: process globals
.lib /path/to/sky130A/libs.tech/combined/sky130.lib.spice mc
Ra n1 0 r={1000*sw_nw_rs_mult}
Rb n1 0 r={1000*sw_nw_rs_mult}
Rc n1 0 r={1e6*sw_nsd_pw_cj}
Rd n1 0 r={1e6*sw_nsd_pw_cj}
Re n1 0 r={1000+1e9*sw_polycd}
Rf n1 0 r={1000+1e9*sw_polycd}
V1 n1 0 1
I5 0 e1 10u
XQ1 0 0 e1 sky130_fd_pr__pnp_05v5_W0p68L0p68
I6 0 e2 10u
XQ2 0 0 e2 sky130_fd_pr__pnp_05v5_W0p68L0p68
.control
set noaskquit
set numdgt=12
alterparam mc_pr_switch=0
reset
op
echo SEED off
print @ra[r] @rb[r] @rc[r] @rd[r] @re[r] @rf[r] @xq1:sky130_fd_pr__pnp_05v5_w0p68l0p68_model[bf] @xq2:sky130_fd_pr__pnp_05v5_w0p68l0p68_model[bf]
alterparam mc_pr_switch=1
foreach k 1 2 3 4 5
  setseed $k
  reset
  op
  echo SEED $k
  print @ra[r] @rb[r] @rc[r] @rd[r] @re[r] @rf[r] @xq1:sky130_fd_pr__pnp_05v5_w0p68l0p68_model[bf] @xq2:sky130_fd_pr__pnp_05v5_w0p68l0p68_model[bf]
end
.endc
.end

What to look for:

  • @ra[r] and @rb[r] sit near 2 kΩ rather than 1 kΩ (defect 2), and differ from each other within one seed (defect 3).
  • @rc[r] and @rd[r] (built on sw_nsd_pw_cj, a GAUSS(0,…) term) print the nominal value for every seed (defect 1).
  • @re[r] and @rf[r] (built on sw_polycd, an AGAUSS term) do vary, but differently from each other in the same seed (defect 3).
  • The two PNP bf values sit around 29–34 instead of 18.4 (defect 2).
Seeding trap. Use setseed before reset, and do not put any .option seed=… card in the deck. A seed option silently overrides setseed on every reset and makes every sample identical, which would hide all of the above.

Workaround

Use mismatch-only Monte Carlo, which is sound. Load a corner and switch mismatch on:

.lib /path/to/sky130A/libs.tech/combined/sky130.lib.spice tt
.param mc_mm_switch=1

Checked: mismatch draws are per instance as intended, read back exactly for MOS, resistors, MIM caps, PNP and NPN, and sample k is bit-identical whether it runs in a long loop, alone in a fresh process, or on another ngspice build. Combine it with the deterministic corners (ss, ff, sf, fs) for a corners-times-mismatch sweep until process MC is fixed.

Suggested fix

The defects are in the model cards, so they belong in the PDK, not in ngspice. Patching ngspice to accept the files as written would make it disagree with every other simulator that reads them.

  1. Defect 1: rewrite each {nom} + … GAUSS(0, rel, 1) as an absolute spread, AGAUSS(0, nom*rel, 1), or put the nominal inside: GAUSS(nom, rel, 1).
  2. Defect 2: sw_nw_rs_mult = {1.0+corner_factor*…} * EXP(process_mc_factor*MC_PR_SWITCH*AGAUSS(0,0.12,1)).
  3. Defect 3: draw the global process parameters once per sample, outside the model files, and pass them in as plain numbers. In a control-language loop that means computing them with sgauss(0) or similar and setting them with alterparam before reset. A plain .param x = agauss(…) can never be shared in ngspice.
  4. Defect 4: drive the *_mc parameters from the same per-sample draw, using the standard deviations already present in the commented vary lines.

Defects 3 and 4 together mean the cleanest route is a small process model of our own that draws one die per sample and feeds the existing sw_* parameters. That is the path we are taking.

Notes

  • Draws depend on netlist order. Inserting one device ahead of another shifts which random numbers every later device gets (measured: 40 of 40 seeds). A re-run reproduces sample k only on a byte-identical deck, so samples before and after a netlist edit are not paired.
  • The commented statistics{ process{ … } } blocks show where the files came from: a Spectre deck, where vary statements give a correlated per-die draw. That mechanism was dropped in translation and nothing replaced it.

Thursday, October 22, 2026

Measurements on Simulation Output - in Xschem

Keeping the schematic tool out of the optimizer loop: where do waveform measurements actually happen?

I'm setting up a circuit optimization in our xschem fork. The topology is fixed; only device sizes and resistor values change from one iteration to the next. So the optimizer can edit the SPICE netlist directly, run ngspice, and never touch the schematic editor. That leaves one question: how does the optimizer get the measurements back? The phase margin, rise time and crossing times we define in ASE-L (our ADE-L-style simulation environment) have to come from somewhere.

My first idea was a menu item, Tools > Write measures.py, that turns the ASE-L setup into a standalone Python script. Before building it, I asked how measurements are computed today. The answer changed the design.

Two kinds of measurement, computed in two different places

1. Measurements ngspice understands. Rows defined under Outputs > Measurements are written into the netlist as ngspice meas lines. ngspice computes them during the run and writes plain name = value lines to a .meas file next to the raw file. The schematic tool only reads that file back. These rows cover:

  • delay between two edges (TRIG … TARG);
  • the value of a signal at a time, or when another signal crosses a level;
  • the time of the n-th rising, falling or either-way crossing of a value;
  • average, RMS, min, max, peak-to-peak and integral over a window;
  • unwrapped phase, Fourier/THD, and expressions over other measurements.

2. Measurements only the Calculator knows. ngspice has no built-in idea of a Cadence-style riseTime, slewRate, settlingTime, overshoot, dutyCycle, frequency, bandwidth, gainBwProd, gainMargin or phaseMargin. The same goes for cross as the Calculator defines it (every crossing, or a chosen one, with its own edge rules), and for any ASE-L Outputs expression built from these. You could approximate some of them with chains of meas lines, but they would not agree with the Calculator to the last digit. That matters when the optimizer is chasing a spec you also check by eye in ASE-L.

For this second kind, nothing outside the editor is involved. After a run, the xschem process reads the raw file into memory and evaluates every Outputs row itself.

The architecture, in one picture

                       ┌──────────────────── xschem process ────────────────────┐
 ASE-L Outputs pane ──►│ result_probe ──► calc::eval_texts  (plans each row)    │
 Calculator window  ──►│                     │                                  │
                       │                     ▼                                  │
                       │   calc::riseTime / cross / phaseMargin …   (Tcl)       │
                       │        │ build a column        ▲ samples                │
                       │        ▼                       │                        │
                       │   ┌──── `xschem raw …` commands (scheduler.c) ───────┐ │
                       │   │ raw read    raw add    raw values    raw index   │ │
                       │   └────┬───────────┬──────────────▲──────────────────┘ │
                       │        ▼           ▼              │              (C)   │
                       │   raw_read    expression engine (plot_raw_custom_data) │
                       │   (save.c) ──► the raw file as arrays of doubles in RAM│
                       └───────▲────────────────────────────────────────────────┘
                               │ reads
   netlist ──► ngspice ──► <cell>_ase.raw
                    └────► <cell>_ase.meas   (ngspice's own `meas` results)

There are three layers in two languages:

  • A raw-file reader in C (src/save.c). It loads ngspice's output into memory, splitting AC data into magnitude, phase, real and imaginary columns.
  • An expression engine in C, also in save.c. It does point-by-point maths that builds new columns, such as v(out)/v(in), db20() and integ().
  • The measurement verbs in Tcl (src/calculator.tcl). They ask the engine for a column, pull its samples into Tcl, and do the crossing, interpolation and margin arithmetic there. The only way they reach the data is through the xschem raw … commands.

Why not a standalone Python script?

A Python measures.py that recomputes everything would be a second copy of the raw reader, the expression engine and about 4,600 lines of measurement code. This code has edge cases that already took several careful fixes in our own tree:

  • a threshold that lands exactly on a rail inventing a crossing;
  • a rise-time edge pairing up with the wrong transition;
  • stateful functions such as integ() leaking across sweep boundaries.

A second copy drifts, and then the optimizer and the GUI disagree about whether a design meets spec.

Why not call just the measurement part?

That was my next question, and today the honest answer is that you can't. The Tcl measurement code only reaches the data through C commands compiled into the editor, and those keep their data in the editor's global state. Carving it out is possible:

  1. Build the raw reader, the expression engine and the raw command into a small Tcl extension.
  2. Move the measurement procs into a file that loads without any GUI.
  3. Load both from Python through the window-less Tcl interpreter that ships with Python (tkinter.Tcl()).

The editor would compile the same files, so the numbers would still match.

But it is a refactor of the file every simulation result passes through, and one measurement makes it unnecessary for now. Headless xschem starts and exits in about 0.06 seconds, using about 21 MB (three runs, no display). Any simulation worth optimizing takes far longer. So "launch the editor headless" really is "run the measurement part" plus about 60 ms. It reads the raw file once; it loads no GUI, schematic or display.

The plan

A menu item, Tools > Export for optimizer, writes three things:

  1. The netlist ASE-L would run, with the design variables marked for substitution. It keeps the write lines that produce the raw file and the meas block.
  2. A manifest saying where the raw and .meas files land, and where each measurement comes from.
  3. A small measures.py that the optimizer calls after each ngspice run. It returns one dictionary of name → value:
    • ngspice-native rows are parsed from the .meas file, with no xschem involved;
    • Calculator-only rows are evaluated by xschem --nogui --pipe --script measures.tcl <raw>, which runs the same code the Outputs pane uses.

The export also lists which rows need the Calculator, so anything ngspice can compute can be moved over.

If 60 ms per iteration ever matters, or the optimizer has to run where xschem isn't installed, the measurement layer can be carved out later behind the same measures.py interface, and the optimizer won't notice.

If you're doing this with an AI coding assistant

The useful move was asking where the numbers come from before asking for the script. Prompts that got me there:

  • "Before you build it: how are these measurements computed today? Is the waveform loaded into memory by the tool, or does an external script produce the number?"
  • "Which measurements can the simulator compute itself, and which exist only in our Calculator?"
  • "Where is that code, which files? And why can't I call just that part?"
  • "Measure the cost of the simple option before proposing a refactor." The 60 ms figure settled the design in one line.
  • "Draw the architecture as an ASCII block diagram."

Getting a Useful VcXsrv Crash Dump

Winner of the first Nobel Prize in Physics ❯ tell me how to do the VcXsrv shortcut that I currently have in my Startup folder so that we get...