.control section compatibility

The handling of ngspice in KiCad is somewhat special:
KiCad is using the ngspice shared library (simulator in a dll, so). The netlist is sent to ngspice.dll upon entering the simulator window, a .control section is executed immediately, upon pushing the Eeschema ‘run’ button a command bg_run is sent to ngspice and the simulation is run in a second thread, data are accessed and plotted during the simulation. User defined signals, fft etc. are started only after the simulation has finished. ngspice.dll has some restrictions, for example it does not have any graphical interface. Graphics is handled by Eeschema. Thus the command ‘plot’ is not available. Simulation capability of ngspice however is fully supported.

That’s the background for any further action.
A command ‘set controlswait’ in the .control section will postpone any following command of the section to after the simulation has finished.
Looping is possible, simulation commands like ‘run’ may be executed. However, the data thus generated, are not visible to the Eeschema graphics facilities (something in need of a change in the future).
Instead of putting the .control section onto the Eeschema canvas, it is possible to just give an ‘.include fipath/filename’ command to load a ngspice script from a file. An example (KiCad6) is given in Simulation examples for KiCad/Eeschema/ngspice Pass Labs F5 Class A Audio Amplifier.
Plotting is possible via ngspice command ‘gnuplot tmpfile, vec 1, vec2 …’ , or writing a PS or SVG file. A viewer may be started with a ‘shell …’ command.
Creating loops in plain ngspice is explained in ngspice control language tutorial.
Running external ngspice is supported by KiCad. .control loops may be formulated to support both internal and external simulation, each with its own capabilities. Please have a look at my various KiCad8 simulation examples given in Simulation examples for KiCad8/Eeschema/ngspice .

1 Like