Skip to content

Spice: wrong netlist for uniform random voltage sources

Description

The spice model editor gives the wrong parameter names for uniform random voltage/current sources and netlists them with some extra values tacked onto the end. Looks like a copypasta here that should be pretty quick to fix (famous last words).

The ngspice manual says:

TRRANDOM(TYPE TS <TD <PARAM1 <PARAM2>>>)

Confusingly, ts is a duration of time for each random value (step length), and td is a start (delay) time. For uniform noise (type=1) PARAM1 is range and PARAM2 is offset.

If we go to the SME we get params Min. value (min), Max. value (max), Time step (dt), and Delay (td). Delay is correct, time step is probably fine but has a mnemonic that doesn't match the docs, and min/max don't match the docs.

For our example, we'll use type=1 (uniform), ts=2u (hold each value for 2us), td=0 (start immediately), PARAM1=3 (range of 3V), and PARAM2=5 (offset of 5V). These are all unique to hopefully make this clearer.

Assuming min is PARAM1 and max is PARAM2 and plugging in the values accordingly, we mostly get the expected netlist, but with two extra values tacked on:

V1 VOUT GND TRRANDOM( 1 2u 0 3 5 2.000000 4.000000 )

Reading the tea leaves for min/max here, it looks like the intention was to hide range/offset from the user and instead present min/max parameters and calculate range/offset from that. However, instead we add min/max to the netlist in the position of range/offset, followed by the calculated range/offset values. Personally I don't think we should be clever here - it's easier all around when the SME parameters match the parameters described in the ngspice manual.

I also see a TODO regarding dt here. Tstep seems like a reasonable change to me.

Steps to reproduce

  1. Open demo project
  2. Open SME for the source
  3. compare parameters to ngspice manual
  4. Open simulator
  5. View spice netlist
  6. Look at number of parameters on V1 line

KiCad Version

Application: KiCad Schematic Editor arm64 on arm64

Version: 7.99.0-3899-g931cec862e, release build

Libraries:
	wxWidgets 3.2.4
	FreeType 2.13.2
	HarfBuzz 8.2.0
	FontConfig 2.14.2

Platform: macOS Monterey Version 12.7.1 (Build 21G920), 64 bit, Little endian, wxMac

	wxWidgets: 3.2.4 (wchar_t,wx containers)
	Boost: 1.82.0
	OCC: 7.7.2
	Curl: 7.87.0
	ngspice: 41
	Compiler: Clang 14.0.3 with C++ ABI 1002

Build settings:
Edited by Graham Keeth