Appendix: ngspice Cheatsheet

Analog (Integrated) Circuit Design

21 Appendix: ngspice Cheatsheet

21.1 Commands

Commands

  • ac dec|lin points fstart fstop performs a small-signal ac analysis with either linear or decade sweep
  • dc sourcename vstart vstop vincr [src2 start2 stop2 incr2] runs a dc-sweep, optionally across two variables
  • display shows the available data vectors in the current plot
  • echo can be used to display text, $variable or $&vector, can be useful for debugging
  • let name = expr to create a new vector; unlet vector deletes a specified vector; access vector data with $&vec
  • linearize vec linearizes a vector on an equidistant time scale, do this before an FFT; with set specwindow=windowtype a proper windowing function can be set

Commands

  • meas can be used for various evaluations of measurement results (see ngspice manual for details)
  • noise v(output <ref>) src (dec|lin) pts fstart fstop runs a small-signal noise analysis
  • op calculates the operating point, useful for checking bias points and device parameters
  • plot expr vs scale to plot something
  • print expr to print it, use print all to print everything
  • remzerovec can be useful to remove vectors with zero length, which otherwise cause issues when saving or plotting data
  • rusage plot information about resource usage like memory

Commands

  • save all or save signal specifies which data is saved during simulation; this lowers RAM usage during simulation and size of RAW file; do save before the actual simulation statement
  • setplot show a list of available plots
  • set var = value to set the value of a variable; use variable with $var; unset var removes a variable
  • set enable_noisy_r to enable noise of behavioral resistors; usually, this is a good idea
  • shell cmd to run a shell command
  • show : param, like show : gm shows the \(g_\mathrm{m}\) of all devices after running an operating point with op

Commands

  • spec plots a spectrum (i.e. frequency domain plot)
  • status shows the saved parameters and nodes
  • tf runs a transfer function analysis, returning transfer function, input and output resistance
  • tran tstep tstop <tstart <tmax>> runs a transient analysis until tstop, reporting results with tstep step size, starting to plot at tstart and performs time steps not larger then tmax
  • wrdata writes data into a file in a tabular ASCII format; easy to further process

Commands

  • write writes simulation data (the saved nodes) into a RAW file; default is binary, can be changed to ASCII with set filetype=ascii; with set appendwrite data is added to an existing file

21.2 Options

Options

  • abstol sets the absolute current error tolerance (default is 1pA)
  • gmin is the conductance applied at every node for convergence improvement (default is 1e-12); this can be critical for very high impedance circuits
  • klu sets the KLU matrix solver
  • list print the summary listing of the input data
  • maxord sets the numerical order of the integration method (default is 2 for Gear)
  • method set the numerical integration method to gear or trap (default is trap)
  • node prints the node table

Options

  • noinit suppresses printing of the initial transient solution (to quiet the output)
  • nomod suppresses printing of the model table (to quiet the output)
  • opts prints the option values
  • temp sets the simulation temperature
  • reltol set the relative error tolerance (default is 0.001 = 0.1%)
  • savecurrents saves the terminal currents of all devices
  • sparse sets the sparse matrix solver, which can run noise analysis, but is slower than klu
  • vntol sets the absolute voltage error tolerance (default is 1µV)
  • warn enables the printing of the SOA warning messages

21.3 Convergence Helper

Convergence Helper

  • option gmin can be used to increase the conductance applied at every node
  • option method=gear can lead to improved convergence
  • .nodeset can be used to specify initial node voltage guesses
  • .ic can be used to set initial conditions

21.4 Internal Variables

Internal Variables

  • To set the fontsize of plots, use xfont_size
  • To append data to an existing RAW file, use appendwrite=1
  • Get the name of the current plot with curplot
  • The filetype of the RAW file can be set with filetype, either binary (default) or ascii
  • The number of threads can be set with num_threads
  • The noise PSDs will be given in V^2/Hz or A^2/Hz when setting sqrnoise=1 (otherwise V/rtHz or A/rtHz)

Internal Variables