Source code coming soon. The GitHub repository is private for now and opens to everyone very soon.
BetterSPICE Beta 0.8.0 Join the beta Download soon
Part VI  Parts and modelsReferenceContentsIndex
33

Devices: amplifiers, power blocks and ICs

These parts are behavioural models: fast enough for the live simulation and good for design, measured against vendor models and reference circuits (Exact and approximate). When a vendor model is assigned, Simulate runs the vendor model instead. In a Simulate run that goes to ngspice because of another part's vendor model, behavioural parts without their own vendor model are left out with a warning, so give every IC a vendor model when you need ngspice results.

33.1Op-amp

Op-amp
TypeKeyPinsVariantsClass
opamp (U)Uin+, in-, out (3-pin), v+, v- (5-pin), null1, null2 (8-pin), en (shutdown)3pin (ideal, internal ±15 V rails), 5pin (supplies), 8pin (offset null pins, not loaded), sd (with shutdown)approximate

A macromodel with gain, bandwidth, slew rate, offset, output swing and supply current. A slew-limited transconductance drives a dominant pole set so that the DC gain is gain and the unity-gain frequency gbw. The output follows, limited to the supplies minus rail, behind rout. The 3-pin variant has internal ±15 V rails. The shutdown variant turns its output off when en is below v- + 0.8 V.

Op-amp
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Gain-bandwidthgbwHz1 MHz> 0. Slider 1 kHz to 1 GHz.Default, inspector, Quick model, vendor fitUnity-gain frequency.
Slew rateslewV/s1 V/µs> 0Default, inspector, Quick model, vendor fitType 0.5 V/µs as 500k.
Rail headroomrailV0 (rail to rail)≥ 0Default, inspector, Quick model, vendor fitThe output reaches each supply minus this.
OffsetvosV0anyDefault, inspector, Quick model, vendor fitInput offset voltage.
Open-loop gaingainV/V105> 0Default, inspector, Quick model (avol_db)Not in dB.
Supply currentiqA1 mA≥ 0Default, inspector, Quick model5-pin and shutdown variants.
Output resistanceroutΩ50> 0Default, inspector, Quick model

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Typical values shown for an ideal op-amp: gain 106, gbw 10 MHz, slew 10 V/µs, rout 1 Ω. General purpose: gbw 1 MHz, slew 0.5 V/µs, vos 2 mV, rail 1.5 V. Rail to rail: gbw 5 MHz, slew 3 V/µs, rail 20 mV. A vendor op-amp placed from the library uses parameters fitted by running its model, while Simulate runs the model itself.

33.2Comparator

Comparator
TypeKeyPinsVariantsClass
comparator (U)libraryin+, in-, out, v+, v-noneapproximate

The output switches when V(in+) - V(in-) crosses +hyst/2 going up or -hyst/2 going down, and moves between the supplies in tpd behind 10 Ω. With opendrain it only pulls low.

Comparator
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
HysteresishystV0≥ 0. Slider 0 to 1 V.Default, inspector, Quick modelTotal band.
Propagation delaytpds100 ns≥ 0Default, inspector, Quick modelOutput transition time.
Open drainopendrainNo / YesNoDefault, inspector, Quick model

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

33.3Voltage reference

Voltage reference
TypeKeyPinsVariantsClass
vref (U)libraryout, gnd (series), cathode, anode, ref (shunt)default (series reference), shunt (TL431 style)approximate

The series reference is an ideal voltage behind rout. The shunt variant regulates V(ref) - V(anode) to v by sinking current from cathode to anode, like a TL431, and needs about 1 V of headroom.

Voltage reference
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
VoltagevV2.5any. Slider 0.5 to 10 V.Default, inspector, vendor fitTL431: 2.495 V.
Output resistanceroutΩ0.1> 0Default, inspectorSeries reference only.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

33.4555 timer

timer
TypeKeyPinsVariantsClass
timer555 (U)librarygnd, trig, out, reset, ctrl, thr, dis, vccnoneapproximate

The classic bipolar 555. Three 5 kΩ resistors from vcc to gnd set ctrl at 2/3 of the supply. The trigger comparator works at ctrl/2 and the threshold comparator at ctrl. An SR latch, a reset below 0.7 V and a discharge transistor complete it. The output sits about 1.7 V below vcc when high, and the supply current is 3 mA. Driving the ctrl pin moves both thresholds. It has no parameters.

Try it
An astable at 1 kHz
  1. Open Timing and the 555 astable example, or build it with RA = 1 kΩ, RB = 6.8 kΩ, C = 100 nF.
  2. Probe the output and the capacitor.

You should seeThe capacitor swings between 1/3 and 2/3 of the supply and the output toggles at f = 1.44 / ((RA + 2 RB) C) ≈ 990 Hz.

33.5Power block

Power block
TypeKeyPinsVariantsClass
reg (U)Bin, out, gnd (iso: in, out, gnd1, gnd2, the two sides joined only by r_iso and c_iso)ldo, buck, boost, buckboost, chargepump, iso, ref (the kind)approximate

A fast averaged regulator for system-level design: the output follows a target with a first-order lag, with a current limit, efficiency, quiescent current and ripple. Targets: LDO = min(vset, vin - vdo). Buck = min(vset, 0.95 vin). Boost = max(vset, vin - 0.4 V). Buck-boost and isolated = vset. Charge pump = mult · vin (-1 inverting, 2 doubler). Reference = vset. The block is off below its UVLO. A switcher adds a triangle ripple at fsw only when the timestep is short enough to show it. An LDO passes input ripple attenuated by its PSRR.

For real IC pinouts with enable, feedback and switching nodes, use the LDO, buck and boost ICs (Power ICs).

Power block
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Kindkindldoldo, buck, boost, buckboost, chargepump, iso, refDefault, inspectorSet by the variant when placed.
Output voltagevsetV5any. Slider 0.5 to 48 V.Default, inspector
DropoutvdoV0.3≥ 0Default, inspectorLDO.
Current limitilimA1> 0Default, inspector
Output resistanceroutΩ0.05> 0Default, inspectorLoad regulation.
Quiescent currentiqA1 mA≥ 0Default, inspector
PSRRpsrr_dbdB60≥ 0Default, inspectorLDO ripple rejection.
Efficiencyeff0.90.01 to 1Default, inspectorSwitchers. Input power = output power / eff.
Switching frequencyfswHz500 kHz> 0Default, inspectorRipple frequency.
Rippleripple0.02≥ 0Default, inspectorPeak to peak, as a fraction of the output.
Response timetaus20 µs> 0Default, inspectorOutput lag.
Charge pump gainmult-1 (2 for doubler)File or All parameters only
UVLOuvloV1File or All parameters onlyInput voltage for full operation.

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Typical values shown per kind: LDO vset 3.3 V, vdo 250 mV, iq 55 µA, ilim 750 mA, PSRR 65 dB. Buck and buck-boost 5 V, boost 12 V, eff 0.9, fsw 500 kHz, ilim 2 A.

33.6Mixed-signal building blocks

The blocks below measure every voltage relative to their own gnd pin. Their digital inputs switch at vth (default half of vhi) with hysteresis hyst (default 2 % of vhi) and load their net with 1 GΩ. Their outputs are vhi (default 5 V) behind rout with smooth edges of tr (default 10 ns). Sample instants and edges are exact breakpoints. They all show in the logic analyzer.

Mixed-signal building blocks
ParameterKeyUnitDefaultRangeValue comes fromWhat it does
Output highvhiV5anyDefault, inspector
Input thresholdvthVvhi / 2anyDefault, inspector
Input hysteresishystV2 % of vhi≥ 0Default, inspector
Output resistanceroutΩ50 (1 for DAC, S/H, PID, filter, LUT)> 0Default, inspector
Edge timetrs10 ns> 0Default, inspector

Key: the name in the circuit file, in a parameter step (R1.r) and for AI agents. Range: a value outside it is refused with E_PARAM. Value comes from: where you can set it. The All parameters tab and agents can set every parameter.

Mixed-signal building blocks
BlockTypePinsWhat it doesIts own parameters (default)
PWM generatorpwmgenctrl, out, gndA sawtooth at freq compared with the control voltage. Duty = (V(ctrl) - vramp_lo) / (vramp_hi - vramp_lo).freq (100 kHz), vramp_lo (0 V), vramp_hi (1 V), vhi (5 V), rout (10 Ω), tr (10 ns)
ADCadcain, clk, d0 … d(bits-1), gndSamples at fs, or on each rising clk edge when fs = 0. Code = round(V / LSB), LSB = vref / 2bits, ready after tconv. arch = sigma_delta makes a first-order modulator with sinc decimation.bits (8), fs (100 kHz, placed 1 MHz), vref (= vhi, placed 3.3 V), tconv (half a sample), osr (64), arch (sar)
DACdacd0 … d(bits-1), out, gndOutput = code · vref / 2bits, settling in tsettle.bits (8), vref (= vhi, placed 3.3 V), tsettle (1 µs), rout (1 Ω)
Sample and holdshin, ctrl, out, gndTracks while ctrl is high, holds on an internal 1 nF while low.tacq (1 µs), droop (0 V/s)
VCOvcoctrl, out, gndf = f0 + kvco · V(ctrl), clamped to fmin and fmax, square output.f0 (1 kHz, placed 100 kHz), kvco (1 kHz/V, placed 10 kHz/V), fmin, fmax, duty (0.5)
Phase-frequency detectorpfdref, fb, up, dn, gndA ref edge sets up, an fb edge sets dn, both reset when both are set.none
Frequency dividerdividerin, out, gndDivides the input edge count by n.n (2)
PID controllerpidin, sp, out, gndDiscrete PID at fs on e = V(sp) - V(in), clamped with anti-windup.kp (1), ki (0), kd (0), fs (10 kHz, placed 100 kHz), out_min (0), out_max (5 V, placed 1 V)
Digital filterfilterin, out, gndSamples at fs and runs an FIR, IIR or biquad cascade. coeffs: a list of taps, {"b": […], "a": [1, …]}, or [b0, b1, b2, a1, a2] per section.kind (fir, placed iir), coeffs (none = pass through), fs (10 kHz, placed 100 kHz)
Lookup tablelutin, out, gndout = table(V(in)), continuous. x must rise. Ends hold.table ([[0, 0], [1, 1]]), interp (linear, cubic, step)
Dead-time generatordeadtimein, outA, outB, gndoutA follows the input, outB is its complement, every rising edge delayed by td.td (100 ns)
Soft-startsoftstarten, out, gndRamps to vset in tss when en goes high, down in tdis when low.vset (1 V), tss (1 ms), tdis (10 µs)
UVLOuvloin, out, gndOutput high above von, low below voff, after tpd.von (4.5 V), voff (von - 0.5 V), tpd (100 ns)
Over-current protectionocpcs, out, gndFaults when V(cs) ≥ vth for tdelay. Latches, or retries after tretry.vth (0.1 V), tdelay (1 µs), latch (1), tretry (1 ms), invert (0)
State machinefsmin0 …, out0 …, gndStates with output bits and transitions with a condition over the inputs and an optional dwell time.inputs (2), outputs (2), states, transitions, initial, clk (0 = event driven)

33.7Editing the filter, lookup table and state machine

The filter coefficients, the lookup table and the state machine are edited as tables in the inspector, under the block's own fields, in the same look as the PWL points table. You don’t write the JSON. An old circuit that stores them as JSON text opens in the tables too.

Editing the filter, lookup table and state machine
BlockWhat the inspector shows
Digital filterThe table follows the Kind. FIR: one row per tap h, with the sum of the taps under it (the DC gain). IIR: a table of the numerator b and one of the denominator a, with the difference equation under them. a[0] may not be 0. Biquad: a table of sections with columns b0 b1 b2 a1 a2 (a0 = 1), run in series.
Lookup tableTwo columns, In (V) and Out (V), at least two rows. The rows sort themselves by input, and outside the table the end values hold.
State machineStates: a name and the output bits for each state (out0 first, as many bits as Outputs), and a Starts in list for the initial state. Transitions: two lines each. The first has From (a state, or * for any) and To. The second has After (the dwell time, such as 5m) and When (the condition over in0, in1 …, empty means always).
  • Each cell takes a number with SI prefixes (1k, 5m). Enter or Tab applies it, Esc puts the stored value back. + on a row inserts a copy of it after the row, × deletes it, + Add row (+ Add state, + Add transition) appends one. One change is one undo step.
  • Renaming a state renames it in the transitions and in Starts in. Deleting a state drops the transitions that use it.
  • A bad entry isn’t saved. A line in red says why: a state name must be letters, digits and underscores, and unique. The output bits must be as many 0 and 1 as Outputs says. A time must be 0 or more. A condition may use only in0 …, !, &&, ||, parentheses, true and false.
An IIR digital filter: the numerator b and denominator a as tables.
Figure 33.1An IIR digital filter: the numerator b and denominator a as tables.
A state machine: the states with their output bits, the starting state, and the transitions on two lines each.
Figure 33.2A state machine: the states with their output bits, the starting state, and the transitions on two lines each.

State machine example

"states": [ { "name": "idle", "out": "00" }, { "name": "run", "out": "10" }, { "name": "done", "out": "01" } ],
"transitions": [
  { "from": "idle", "to": "run",  "when": "in0 && !in1" },
  { "from": "run",  "to": "done", "after": 0.002 },
  { "from": "*",    "to": "idle", "when": "in1" } ]

The same machine in the file. A condition uses in0, in1 …, true, false, !, &&, || and parentheses. after is the time in the state before the transition may fire. The first matching transition wins. "*" matches every state.

33.8Generic IC box (subcircuit)

Generic IC box (subcircuit)
TypeKeyPinsVariantsClass
subckt (X)XFrom its pinout, for example 1:l 2:l 3:r 4:rnoneapproximate

A box with any number of pins for a vendor subcircuit. It is the one Generic IC tile of the library. pinout lists the pins as name:side (l, r, t, b) and title is drawn in the box. In the inspector they are the Pins field (one entry for each pin, with the count, names and sides shown) and Title on the symbol. A space can be typed in them, and the text is tidied when you leave the field. Assign model takes a vendor subcircuit, and Move pins opens the symbol editor to drag the pins to new places. With no model its pins are open and it warns W_NO_MODEL. Double-click it, or right-click it and choose Edit subcircuit, to build its inside yourself: it becomes a sheet with one port per pin (Editing a subcircuit). With a vendor model and no behavioural equivalent it runs only in Simulate, and the live simulation leaves its pins open with a message. With equiv (a behavioural part and a pin list) the live simulation runs that equivalent. Placing a vendor model from the library normally places it as the fitted device type instead, so the IC box is mainly for models with their own pins.