Spice and KiCad

Found a way. Add the following to your ngspice text comment in the schematic:

.control
listing
.endc

The full circuit text will be displayed in the simulator log window, very useful to see what’s going on under the hood.

3 Likes

FYI spice has ben enabled for the windows nightlies from now on. And as mentioned last week, they are also enabled for OS X.

Remember – bug reports are not to be posed here, but on the bug tracker on launchpad.net.

2 Likes

Bugtracker direct link:

Ok, I’ve installed the 4505896 from 05-10-2016 and ngspice is included, now I want to know where I can find the ngspice library working with it and if they are a very simple example demo (AC_Gen/R/C) to make some trail with this tool ? Thanks ! Vince.

Please check here “C:\Program Files\KiCad\share\kicad\demos\simulation”

1 Like

Thanks, I will check …

Ok, it works, now I need to understand how to set the tool, very nice tools, thanks again !!!

This is really good. I was trying it out but am unable to ding the sources that I can use for simulation. Which library contains all these current sources, voltage sources that can be used in a simulation schematic?

I used the sources from the kicad simulations demo examples .
eg in windows: C:\Program Files\KiCad\share\kicad\demos\simulation - edited the symbol with library editor and saved it into my local library.

1 Like

Thanks! How can I create a dependent source like a Voltage control voltage source or a voltage controlled current source. I basically want my source symbol to appear as a particular statement in the netlist.

I tried today to learn a bit more about the spice support in Kicad by myself since I was not able to find any documentation yet.

I’m using the /usr/share/kicad/demos/simulation/sallen_key project.

I was able to run the simulation, and plot graphics. but I would like to know which is the netlist is being used by ngspice…

Is there any way to see it ?

I tried to export a netlist for spiece but the system just crashed without any error message.

anyone knows if there is already a created bug item for this kind of issue?

Add the following to a textblock:

  .control
  listing
  .endc

and it will dump the actual netlist used in the ngspice simulator window console

1 Like

Fantastic work on this new ngspice simulation feature!
Just have a couple of comments to add:

  • Installed the 2017-01-06 nightly for OSX and simulation works but you do still need to run KiCad from the command line like in kymatica’s post. I installed ngspice from brew so had to do:

    export SPICE_LIB_DIR=/usr/local/Cellar/ngspice/26/share/ngspice/
    /Applications/Kicad/kicad.app/Contents/MacOS/kicad

  • Demos can be found in /Library/Application Support/kicad/demos/simulation/, but:
    laser_driver & sallen_key crash on running the simulation with “Segmentation fault: 11”
    rectifier works fine

  • It appears if using the diode component from the pspice library without reordering the nodes (“2 1” like in the rectifier demo) it is simulated upside down

  • For any newbies reading this, make sure you watch the whole of the KiCAD Spice Simulation tutorial video first!

  • To output the spice netlist as a one-off, you can still use the “Generate netlist” button from eeschema, Spice tab, Generate. Suspect it might have different rules for reading spice commands from schematic text blocks than the new simulator tool though…

  • It would be great if schematic component fields could somehow be passed into spice models for use in subcircuits and for the tuning tool. Suggestion: a Field named “Spice_Vars” which can contain key-value pairs, e.g. Pind=10uH,Sind=20uH,K=0.98. As an example I’ve just successfully created a transformer model, but there appeared to be no way to pass in some useful parameters:

    And for those interested, this worked perfectly:
    .subckt XFRM_LINEAR 1 2 3 4
    K_TX1 L1_TX1 L2_TX1 0.99
    L1_TX1 1 2 10uH
    L2_TX1 3 4 10uH
    .ends XFRM_LINEAR

Are there plans to start some spice model libraries?

Spice libraries are much harder to create than PCB parts. This is why we still hang on to closed source but freeware LTSpice and the Simetrix demo

If you are especially serious about simulating the behavior of a product’s circuit you may have several models for a single part. One will be based on “nominal” datasheet values of course, but you may also have models for best-case and worst-case examples of the part. Or a model which combines best- and worst-case values for various parameters to create a part representing a “corner-case” for a particular design. Or models representing behavior at high, or low, temperatures. Or a model optimized for accuracy under certain operating conditions (e.g., low current, high voltage, etc). Or models based on experience with the particular strengths, weaknesses, and quirks of parts from a particular manufacturer. Or a model that strips a device’s behavior down to the bare essentials, to reduce simulation time - or a model that incorporates every parasitic element and blemish that characterize a particular device.

[quote]This is why we still hang on to closed source but freeware LTSpice and the Simetrix demo
[/quote]
While some of the SPICE-based simulators have impressive features or unique capabilities the underlying models themselves are quite portable from one vendor’s program to another. Occasionally you may do a little text editing to circumvent a particular vendor’s “extension” to the SPICE syntax but this is fairly rare.

The Component’s manufacturer is probably the best source of SPICE models, though even some of these are of dubious quality. After the manufacturer, I look at the LTSpice User Group on Yahoo ( https://groups.yahoo.com/neo/groups/LTspice/info ), and then to specialized discussion forums like www.diyaudio.com .

Dale

Simulators are notorious for generating unrealistically good predictions.
Some models to look out for are the Cordell models, http://www.diyaudio.com/forums/software-tools/266655-better-power-mosfet-models-ltspice.html that model high current gain drop properly and the improved mosfet models here http://www.diyaudio.com/forums/software-tools/266655-better-power-mosfet-models-ltspice.html that model the sub threshold region and show realistic crossover distortion

@racitup

I am trying to reproduce the crashes you had on osx and am unable to reproduce. Just a couple of things… Can you brew libngspice instead of and see if you can reproduce the issues using that for the SPICE_LIB_DIR (for me was SPICE_LIB_DIR=/usr/local/opt/libngspice/share/ngspice/ )

@xzcvczx
yep that fixed it thanks! I’ll update my bug…

@davidsrsb
I think you miss the point of KiCAD. It doesn’t claim to be an enterprise-grade, does everything for everyone suite. It aims to cover 90-99% of people’s needs without restriction, which it does an excellent job at. The bonus being it’s open source, so if someone wants to maintain or contribute to a spice library, they can; and they can contribute a simple or complex model. Just like the bundled schematic, pcb and 3d component libraries of KiCAD, they are a bit patchy, but a fantastic start for free. And if we don’t start somewhere, we can’t improve…
Chances are if you’re doing complex electronic simulations, you’ll also have the resources to purchase one of the enterprise packages.

KiCAD is for all those that think “if it’s good enough for CERN, it’s good enough for me” :slight_smile:

I’m happy to have the spice interface for a quick simulation. My only concern is the new users who already are surprised that they sometimes have to learn how to create their own symbols and footprints, who will be puzzled why there isn’t a simulation model for their favourite opamp.:wink:

An even greater concern are the users who find a model for that favo(u)rite opamp, then accept - without question - simulation results which show it putting out enough voltage to throw lightning bolts across the lab, or enough current to jump-start a locomotive.

Dale

2 Likes