Export netlist and simulate on external Spice Engines

A complete newbie for both electronics and KiCad. I understand KiCad does not support DC operating point analysis. Is it possible to do schematic design on Kicad and then:

  1. Export a Netlist containing an .op directive and run that by a local ngspice installation(linux)?
  2. Offload spice simulation jobs to LTSPICE completely via wine on Linux?

I really don’t want to use neither wine/LTSPICE or my unis. godforsaken “virtuallab” remote access to Multisim. I LOVE Kicad and this is by far the only thing I have been unable to setup so far.
Thanks for any help in advance

Using internal ngspice:
Add a .control section to your eeschema diagram as a text file. It may look like this:

.control
* wait with the following commands until simulation has finished
set controlswait
* save the name of the current plot into a variable
set prevplot = $curplot
* do an operating point evaluation
op
* print the data
echo Data from $curplot
print all
* go back to the previous plot
setplot $prevplot
.endc

For the notion of ‘plot’, please have a look at the ngspice maual, chapt. 17.3.

External ngspice (if you are with KiCad 5.1.5):
Eeschema->Tools->Gernerate Netlist File->Spice
Enter path and name of ngspice simulator
Run Simulation
ngspice window opens up
Run
Evaluate the data

You need the allowance to write to the directory where the project is located. I have tested this with MS Windows.

Dear Holger,
I tried this on Linux Mint 19.2 with KiCAD 5.1.5-52549c5~84~ubuntu18.04.1
Eeschema->Tools->Gernerate Netlist File->Spice
Enter path and name of ngspice simulator
Run Simulation

But even though the path is recognized, unfortunately no ngspice spice window opens up.

This is the version I used:
Application: Eeschema
Version: 5.1.5-52549c5~84~ubuntu18.04.1, release build
Libraries:
wxWidgets 3.0.4
libcurl/7.58.0 OpenSSL/1.1.1 zlib/1.2.11 libidn2/2.0.4 libpsl/0.19.1 (+libidn2/2.0.4) nghttp2/1.30.0 librtmp/2.3
Platform: Linux 4.15.0-58-generic x86_64, 64 bit, Little endian, wxGTK
Build Info:
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.22
Boost: 1.65.1
OpenCASCADE Community Edition: 6.9.1
Curl: 7.58.0
Compiler: GCC 7.4.0 with C++ ABI 1011

Build settings:
USE_WX_GRAPHICS_CONTEXT=OFF
USE_WX_OVERLAY=ON
KICAD_SCRIPTING=ON
KICAD_SCRIPTING_MODULES=ON
KICAD_SCRIPTING_PYTHON3=ON
KICAD_SCRIPTING_WXPYTHON=ON
KICAD_SCRIPTING_WXPYTHON_PHOENIX=ON
KICAD_SCRIPTING_ACTION_MENU=ON
BUILD_GITHUB_PLUGIN=ON
KICAD_USE_OCE=ON
KICAD_USE_OCC=OFF
KICAD_SPICE=ON

Only thing I can add here is that I’ve successfully pushed the Netlist to LTspice within Windows. Here is a timestamped video showing it in action:

1 Like

Dear Ste,
Thanks for referring to the Youtube Video. The reason I posted my message was to give feedback concerning the matter concerning KiCAD specifically on Linux at the moment.

kind regards,
Hugo

Right. I was just sharing it in case the same method translates over to LTspice on Wine as well. I’d try it myself, but I don’t use Linux.

When ngspice is started under Linux, it has to have a console app for its input/output.

I do not have KiCad under Linux, but I manage to start ngspice from the standard Linux console (that has been cd’d to ngspice/examples/Monte_Carlo) to run in its own new console by

konsole -e ngspice OpWien.sp &

where ‘konsole’ is the console app of the German SUSE Linux. Alternatively one may use

xterm -e ngspice OpWien.sp &

if xterm is available.
In KiCad it might be o.k. to just enter

xterm -e ngspice

(not tested, so there is room for experimentation)!

EDIT:
tested, it does do!

Now that we have solutions for Windows and Linux (see updated http://ngspice.sourceforge.net/ngspice-eeschema.html#external), I wonder if we could find a solution for macOS as well. I have entered
open -a Terminal -e /usr/local/bin/ngspice
and I get an error message (rough translation) “sallen_key_bp.cir cannot be opened, because Sandbox may not open documents in Terminal.” sallen_key_bp.cir is the netlist created by eeschema and sent to ngspice.

Is there anybody around with some suggestion?

https://forums.developer.apple.com/thread/13901 seems to tell me that it is difficult if not impossible. KiCad and ngspice are at least not macOS certified apps. Maybe that some scripting may help, but for now I did not delve into macOS scripting.

I was able to run op analysis using the second suggested approach via xterm. For those on a Mac OS, they can try using PySpice project, which I think can be used to push netlist to ngspice using a python script. I have not experimented with this approach yet but it’s definitely one I want to explore next. I will update if all goes well.
Thank you!!

This is awesome and thank you. I did not know pin order was an issue.