FOSSlab

Chapter 4 of 14 · about 45 min

Testbenches and simulation

A testbench is a cell of its own that uses the op-amp’s symbol, adds supplies, sources and load, and tells ngspice what to do. Two testbenches check every specification.

1. The open-loop AC testbench

  1. In the Library Manager right-click opamp > New testbench for this cell…, name tb_opamp_ac. FOSSLab creates the cell with the op-amp’s symbol placed, a label on every pin, the IHP model block and an ngspice control block.
  2. Add (Insert, library devices): vsource VVDD = {vdd}, isource IB = {ibias} from vdd into IBIAS, vsource VIN = dc {vcm} ac 1 on INP, capa CL = {cl} on OUT.
  3. Close the loop for DC only: RFB = 1 GΩ from OUT to INN and CFB = 1 F from INN to ground. At DC the op-amp is a follower, so it finds its own operating point; at any frequency above a few mHz CFB grounds INN and we see the open-loop gain.
  4. Edit the two code blocks (q on them):
MODELS:   .lib cornerMOSlv.lib mos_tt
          .lib cornerCAP.lib cap_typ

NGSPICE:  .param vdd=1.2 vcm=0.8 ibias=10u cl=1p
          .control
          op
          let vos = v(out) - v(inp)          * the follower's output offset
          let pdiss = -v(vdd) * i(vvdd)
          print vos
          print pdiss
          write tb_opamp_ac.raw
          set appendwrite
          ac dec 50 1 10G
          let gain = vdb(out)
          let phase = 180/PI*cph(out)
          meas ac a0 find gain at=10
          meas ac ugf when gain=0
          meas ac phu find phase when gain=0
          let pm = phu + 180
          print pm
          write tb_opamp_ac.raw
          .endc

The .param values are the testbench’s design variables: the Simulation Environment (chapter 8) can change them without editing the schematic.

Add two graphs (Simulation > Graphs > Add waveform graph, then double-click the graph to edit it): node gain for the first; for the second phase (deg);phase -1 * (xschem draws the magnitude of AC vectors, so the phase, negative here, is plotted as −|phase|: label;expression, with the expression in reverse Polish notation). x axis logarithmic, Auto load ticked, and the property rawfile=[fosslab_simdir]/tb_opamp_ac.raw, so the graphs load this testbench’s last simulation. Then Simulate (xschem’s button, or the Library Manager’s Simulate, which shows the log and the result in a window). The results go to ~/fosslab/sim/opamp_tut/tb_opamp_ac/.

AC testbench with gain and phase
tb_opamp_ac after the simulation: open-loop gain and phase of the op-amp.

2. The transient testbench

Cell tb_opamp_tran: the op-amp as a unity-gain follower (OUT wired to INN), a 0.7 → 1.0 V pulse on INP. The control block measures the slew rate between 20 % and 80 % of the step and the settling time into a ±1 mV band:

tran 1n 4u
meas tran t20r when v(out)=0.76 rise=1
meas tran t80r when v(out)=0.94 rise=1
let srp = 0.18/(t80r-t20r)
...
meas tran vfin find v(out) at=1.95u
let vband = vfin - 1m
meas tran tset_r when v(out)=$&vband cross=last from=1u to=1.95u
let tsettle = tset_r - 1u
Transient testbench
tb_opamp_tran: the follower’s output tracks the input steps, limited by the slew rate.

3. The results

SpecificationTargetSimulated (typical, 27 °C)
DC gain≥ 55 dB57.6 dB
Unity-gain frequency≥ 15 MHz16.17 MHz
Phase margin≥ 55°60.4°
Slew rate, rising / falling≥ 10 V/µs10.6 / 10.3 V/µs
Settling to 1 mV37 ns
Output offset (follower)±5 mV1.73 mV
Power≤ 100 µW90.8 µW

The hierarchy browser (Hierarchy button, or FOSSLab > Hierarchy browser in xschem) shows the whole design: the testbench, the op-amp inside it, and its eight transistors and capacitor.

Hierarchy browser
The hierarchy of tb_opamp_ac. Double-click any block to open its schematic; right-click for its layout or symbol.