Simulation examples for KiCad/Eeschema/ngspice

I have added a simple TRIAC circuit and a quartz crystal oscillator.

3 Likes

These are great. Thank you so much!

I am really pleased that this thread exists. Simulation examples are far harder to find for KiCad than for its PCBs

2 Likes

I am new to KiCad and I am very happy to find out these examples in this forum.

I tried the first one - LM3886-simple. I could open it smoothly in KiCad 6.0.4 (Linux). But when I simulated it, Vout stayed at -91.97V which I think was abnormal.

I also tried LM3886. The simulation result was similar with Vout stayed at an unrealistically high voltage.

Is there anything I just overlooked?

What is your ngspice version?

What’s the easiest way to check in Linux? Can you type something in the terminal to spit it out? Or does it say somewhere explicitly in the GUI? I only know how to check using version within a .control / .endc block, and wondering if there’s an easier way Linux users may be able to do it.

It should say in Help → About KiCad → Version on all operating systems, although maybe that’s only be true for relatively recent versions of ngspice?

1 Like

Below is the KiCad version info for your reference.

Application: KiCad Schematic Editor

Version: 6.0.4-6f826c9f35~116~ubuntu20.04.1, release build

Libraries:
wxWidgets 3.0.4
libcurl/7.68.0 OpenSSL/1.1.1f zlib/1.2.11 brotli/1.0.7 libidn2/2.2.0 libpsl/0.21.0 (+libidn2/2.2.0) libssh/0.9.3/openssl/zlib nghttp2/1.40.0 librtmp/2.3

Platform: Linux 5.13.0-39-generic x86_64, 64 bit, Little endian, wxGTK, pantheon, x11

Build Info:
Date: Mar 21 2022 17:21:29
wxWidgets: 3.0.4 (wchar_t,wx containers,compatible with 2.8) GTK+ 3.24
Boost: 1.71.0
OCC: 7.5.2
Curl: 7.81.0
ngspice: 31
Compiler: GCC 9.4.0 with C++ ABI 1013

Build settings:
KICAD_USE_OCC=ON
KICAD_SPICE=ON

But somehow, I tweaked for a while and finally got LM3886 as well as the next example (Nelson Pass F5) working. Below is what I have done.

  1. I just notice that my ngspice is of version 3.1. It is the latest version available from Ubuntu packages. With this version, I cannot get the Nelson Pass F5 example to work because ngspice 3.1 does not recognize the VDMOS thermal model.

  2. So I follow the user manual of ngspice to compile ngspice 3.6. It took me some time to sort out all development libraries required because I did not specify to install development environments in my ElementaryOS. But finally, I can make it compiled.

  3. Furthermore in KiCad I have to choose compatibility with PSpice and LTSpice in order to make the LM3886 and PassF5 examples work.

Conclusion: Versions of KiCad and ngspice are important.

I will continue to try the other examples in the forum.

1 Like

Type /usr/local/bin/ngspice. It will show the version info as below.


** ngspice-36 : Circuit level simulation program
** The U. C. Berkeley CAD Group
** Copyright 1985-1994, Regents of the University of California.
** Copyright 2001-2020, The ngspice team.
** Please get your ngspice manual from Ngspice, the open source Spice circuit simulator - Documentation: manual and control flow
** Please file your bug-reports at Ngspice circuit simulator - Reporting Bugs
** Creation Date: Sat Apr 16 05:46:43 UTC 2022


1 Like

I have already requested and ask for adding ngspice-36 to the Ubuntu PPA KiCad distribution. The maintainer has agreed. So hopefully the next release (KiCad 6.0.5), due by end of April, will contain ngspice-36.

1 Like

Great news! Thanks, holger.

I have added another demo, a 200 V, 20 A full bridge.

Several oscillators are available now in the example section on the top of this thread:

  • Using dual LM555 for switching the frequency
  • Ring oscillators (either with 7404 inverters, CMOS inverters or inverters made from switches.
  • Wien bridge oscillator (with device parameter variations for Monte-Carlo simulation)
  • Simple phase shift oscillator with bipolar amplifier
  • Phase shift oscillator with OpAmp and frequency measurement
  • Quartz crystal oscillator
2 Likes

We have two more oscillators, an astable multivibrator and a comparator oscillator.

2 Likes

I have followed the Sallen-Key-Bandpass Filter example. It demonstrates the use of a Dual OpAmps chip. Details are provided here.

What I would like to do: develop a board (with simulation and PCB design) that contains several MCP6002 chips (again, dual op amp).

On a side note : I was able to adapt the Sallen-Key-Bandpass Filter example for the MCP6001 model, with a few adjustments detailed here.

The problem that I face is when I want a second Dual OpAmp chip on the scheme. Simulation gives me:

Too few parameters for subcircuit type “tl072c” (instance: xxu2)

It may have to do with the syntax of the TL072c: “XU1A …”. I tried to write a new model that just substitutes “XU1” for “XU2” (U2 being the reference of the second chip), with no success.

Any idea ?

How may I set a NGSPICE compatibility mode when using “external” simulation ?

Create a file .spiceinit (see ngspice manual chapter 16.6 for further info on its location) and add the line
set ngbehavior=ltpsa
into the file.

Attach the model to all three units of U2 (A, B, and C): Doubl Click on unit U2A → Spice Model… → Select file → TL072-dual.lib, TL072c, Subcircuit.
This has to be done for all three units of U2.

Create a file .spiceinit (see ngspice manual chapter 16.6 for further info on its location) and add the line
set ngbehavior=ltpsa
into the file.

@holger Thanks. I unsuccessfully tried this method with the .spiceinit located in the directory of my Kicad project. With .spiceinit located at the root of the user directory, it works (running Linux here).

Attach the model to all three units of U2 (A, B, and C): Doubl Click on unit U2A → Spice Model… → Select file → TL072-dual.lib, TL072c, Subcircuit.
This has to be done for all three units of U2.

Fantastic! Apparently, the issue was related to the fact that UnitB was missing. Thanks a lot @holger