Current state of Spice in KiCad

I have an exremely limited experience with Spice in general and with Spice in KiCad.
I once opened an example, and run a simulation on it and saw some fancy graphs, and that’s about it.

At the momen I’m curuos what the current state of Spice simulation in KiCad is.
Is it highly experimental and are some important features missing, or is it pretty mature and usable for “serious” simulations.

I know there are hardly any spice models in KiCad, and there are problems with encrypted models an licencing issues, but I’ve also read spice models can be found elsewhere (Yahoo, internet in general) and as long as attching spice models to KiCad symbols is easy it’s good enough for me.

I also know that a schematic for spice simulation is different compared to a schematic for PCB design, but I find the single user interface and being able to copy schematics between Spice and PCB design attractive.

The sort of thing I’m after is for example a microcontroller ciruit with some AD and DA converters, opamps and power electronics.
I would like to be able to examine loop stability of analog power supply circuits (programmable power supply, electronic load) and power stages for motor controllers.

Is Spice in KiCad mature and reliable enough for such things, or am I going to spend a month to learn how to use it and then get stuck because of missing functionality?

Edit:

Eeschema / help / Eeschema Manual

also has a chapter about spice, and how to control ngSpice from within Eeschema.
Reminder to Self: RTFM Duh!

KiCad is not the program that does the simulation. ngspice is. KiCad only provides an interface to it.

This means most of your questions are answered with: Not KiCads responsibility.
This does include the following:

  • simulation feature set (responsibility of ngspice with the exception of possible restrictions on the interface side.)
  • availability of models (responsibility of part manufacturers with exception of simple models for idealized parts. For the later it is the responsibility of the ngspice community to include models for this and possibly kicad library team to provide preconfigurated symbols. See for example the voltage and current sources already in the lib.)
  • encrypted model support (by definition not possible -> would not really be encryption if anybody but the intended recipient of information can read it, pressure manufacturers to provide open models.)
  • licensing and patents (pressure manufacturers to provide open models. pressure politicians to make patent law less of an issue for open sharing of critical information.)

ngspice is mature. It is used by several commercial or open source tools (see http://ngspice.sourceforge.net/resources.html). Still there is room for continous improvement.
The KiCad - ngspice interface currently is rather limited. Transient (voltages/currents versus time), ac (small signal analysis versus frequency) and dc transfer (voltages and currents versus input voltage or current) simulations are supported.
KiCad simulation examples are available in folder /KiCad/share/kicad/demos/simulation.
Tutorials for ngspice are listed in http://ngspice.sourceforge.net/tutorials.html. You may find a general ngspice introduction in http://ngspice.sourceforge.net/ngspice-tutorial.html, for ngspice in KiCad especially there is a tutorial at http://ngspice.sourceforge.net/ngspice-eeschema.html. Both also include some hints where to find models.

Definitely you will have to climb up a learning curve, but that is true for any simulator.

Simulation of a mixed signal circuit (microcontroller + analog periphery) is a very ambitious task. There are people around performing this with ngspice and other open source tools (e.g.
https://www.isotel.eu/mixedsim/intro/index.html or https://www.avrfreaks.net/forum/ngspice-and-digital-simulator-avr8).

If you are new to simulation, better start with pure analog first and try to simulate your periphery. This forum, or the ngspice discussion forums at https://sourceforge.net/p/ngspice/discussion/ may provide help.

5 Likes

Glad to hear that ngspice is mature.

In the last few hours I’ve managed to get the sallen_key demo working.
https://www.youtube.com/watch?v=A2_-hdRcf4U

I also already found the ngspice turorial on sourceforge, and had to do an “sudo apt install ngspice” to have the simulator make some sensible results.

As a test of how the link between KiCad’s schematic symbols and ngspice works I exchanged the spice model with a model found at digikey:
https://www.digikey.com/product-detail/en/stmicroelectronics/LM358DT/497-1591-1-ND/592083

And after juggling a bit with the pin numbers I’ve managed to build a simple non-inverting amplifier with it, and it starts so roll-off at a frequency that seems reasonable for a LM358. So that’s hopefull.

I’m definately at the bottom of a learning curve here. I understand that ngspice integration in KiCad is not a big selling point at the moment, but still I find it a (very little bit) dissapointing that basic resistors and capacitors do not have the spice attributes, but using the symbols for the examples work ok.

My intentions are a bit less ambitious than I may have implied.
I have no intention of simulating the microcontroller and DAC / ADC part, only the analog stuff.

Now I’m getting some confidence that ngspice integration in KiCad is usable, it encourages me to start hunting for a decent spice tutorial and learning how those spice directives, and netlist work. I also found: http://web.engr.oregonstate.edu/~traylor/ece391/smith_NGSPICE_USERGUIDE_ECE391.pdf and it seems to be a nice introduction to the very basic principles of spice and it’s syntax, but I have not yet studied it.

After today I’ve become interested enough in Spice simulation that I’ve downloaded the 631 page user manual of NG spice for some quality bedtime reading.

When I did KiCad’s Sallen_Key demo, the graphics were draw with zero-order-hold while on the youtube video from 2016 the lines are smooth, with the same resolution settings. Because on the youtube vid the 180 degree crossing is slanted line I’m almost certain they simply use linear interpolation for smoother graphs.
I could not find a setting to reproduce this.
Is there a setting for this somewhere, or is it a bug in the KiCad graphs?
Compare my screenshot with 1:50 into the Youtube vid from my post above.

This has been a KiCad bug, introduced somewhere between releases 5.0 and 5.1. It is fixed in the new release 5.1.1 that should be available soon.

It is already available for many (possibly even most) platforms. (windows, ubuntu and fedora for example)
There is a problem with mac however which means the official announcement is postponed until mac has a package as well.

2 Likes

@paulvdh
I think there is some decent information regarding encrypted models found in this post/thread:

Also, there will be a SPICE talk at next week’s KiCon 2019. Hopefully it doesn’t suck!

@Rene_Poschl, @holger
Speaking of which, if one were giving a KiCad SPICE talk next week, which version of KiCad should be used? It seems like the main website only has download links for 5.1.0. If there’s a big bug like this in 5.1.0, would it be advisable to use 5.0.1 instead? Or is it better to instruct users to the more obscure link where you can find 5.1.1? https://kicad-downloads.s3.cern.ch/index.html?prefix=windows/stable/

5.1.0 should be fine. It looks like 5.1.1 might be skipped as a serious bug with netlist generation is in it. (The next release might be 5.1.2 that seems to be released very soon instead of 5.1.1.)

See https://lists.launchpad.net/kicad-developers/msg40218.html

But 5.1.0 has the zero-order-hold bug highlighted above. Seems like 5.0.2 is the safest at this point and it’s what @holger 's ngspice setup tutorial still calls for: http://ngspice.sourceforge.net/ngspice-eeschema.html

Is it safe to assume that 5.1.2 won’t be out by this Friday?

The “zero-order-hold” bug is a very minor and mostly cosmetic thing. I mostly just ignore it (though it looks ugly), or I just upped the measurements from 10 measurements / decade to 50 measurements/decade, IE:

.ac dec 50 1 1G

For the other posters:
I appreciate your comments but have nothing to add (yet) at the moment.

1 Like

That’s a good point. I can just add more data points, and if I have to zoom in I can just explain the bug and that “the fix is in” already. Thanks!

Or you can quietly explain that there isn’t a bug, rather analog smoothing (introducing unmeasured, interpolated data) has not been applied to the plot. :wink: