Simulation examples for KiCad8/KiCad9/Eeschema/ngspice

@holger, FYI I have created a repository on GitHub containing the simulation projects from this post and embedded the documentation and screenshots in README files.

See https://github.com/labtroll/KiCad-Simulations

PS: I have added your GitHub profile @holvo as a maintainer on the repository.

1 Like

many thanks for your efforts.

Unfortunately I will not have any resources to act as maintainer of your GitHub repository. This should be your task, and I hope that you are able to run this for some time.

I have made an update on the QEI project.

@holger, I had no expectations of you maintaining my repository with your content. But I didn’t want to prevent you from doing so, which is why I gave you maintenance privileges to the repo.
I will do my best to keep my KiCad Simulations repository up to date with your good work.
If you ping me of any changes, updates or new simulations I will make sure to update.

Thanks,

Morten

PS: I have updated the QEI simulation (799 → 8)

@hatte , I have posted a new circuit with an old device, still interesting for newcomers, the 555 with a model which I have derived from the bipolar circuit diagram in https://forum.kicad.info/uploads/short-url/vd016SrcYFrWfWgNdIcwl5Y8EfC.7z.

2 Likes

@holger, I have added 555-bipolar at https://github.com/labtroll/KiCad-Simulations/tree/main/555-bipolar

1 Like

I have made an update to the LLC converter and added aa example of a logic simulation, a full adder comparison.

I have updated LLC files and README in https://github.com/labtroll/KiCad-Simulations/tree/main/LLC

2 Likes

I have lost the ‘Edit’ button for the primary post of this thread

I would still like to use ‘Edit’ to upgrade examples or to add new ones in the top post.

Could somebody with access rights please re-instate the editing capability for me?

I have promoted you to “leader”, maybe it helps.

I also made the first post a wiki.

I like the Idea of turning this into a Wiki.
Wiki pages are also editable by a lot more people. (This forum logs changes in GIT or similar, so vandalism can be reversed).
I think it’s also a good idea to clean up this thread a bit. Delete all posts not directly showing examples and such.

2 Likes

Better yet: store KiCad simulation example source files in a Git repository, so they can easily be maintained, downloaded, synched and tagged and checked for changes. And documentation can follow along in associated markdown files.
Like any other source code :wink:

3 Likes

A new circuit at the top: A recently published high efficiency, high power RF generator for 13.56 MHz.

Thanks for making the examples. It is delightful to be able to model circuits this way.

While testing your “Step down converter with LM2576” with the nightly build from docker, I found a problem. The LM2576.7z file contains a pspice model in LM2576_TRANS.LIB.

On line 27 there are some non-UTF8 characters that will cause KiCad to fail to read the spice files. It won’t say much about the problem. The first sign that something is wrong is that no models will appear in the UI after you select the .LIB file. If you try to simulate the netlist will be empty.

I suspect the issue is with the definition of the spice parser in kicad. I suspect SafeReadFile() in common/richio.cpp is returning a blank string without giving the user feedback about the bad characters or their location.

Until this can be fixed it might be good to tell simulation users to check their spice files for non-UTF8 characters if they have problems simulating.

You can see there are two bytes with the value 0x96 on line 27.

$ (echo; cat -n LM2576_TRANS.LIB | grep -a Datash ; echo; cat -n LM2576_TRANS.LIB | grep -a Datash | hexdump -C )

27	* Datasheet: SNVS107D JUNE 1999REVISED MAY 2016

00000000 20 20 20 20 32 37 09 2a 20 44 61 74 61 73 68 65 | 27.* Datashe|
00000010 65 74 3a 20 53 4e 56 53 31 30 37 44 20 96 4a 55 |et: SNVS107D .JU|
00000020 4e 45 20 31 39 39 39 96 52 45 56 49 53 45 44 20 |NE 1999.REVISED |
00000030 4d 41 59 20 32 30 31 36 0d 0a |MAY 2016…|
0000003a

I tried to track down the files from TI to see if they had this problem. I was not able to find anything from TI.

Once I fixed the file the simulation worked nicely.

Thanks for the report. Would you mind to file a bug report at Issues · KiCad / KiCad Source Code / kicad · GitLab ?

The model is in https://www.ti.com/de/lit/zip/snvmb27 from page LM2576 Datenblatt, Produktinformationen und Support | TI.com. It has this problem.

Obviously my Windows parser is not that critical.

I will exchange the LM2576_TRANS.LIB.

Done!

I had trouble with the following files in simulation examples repo. I am using the nightly docker container and the repo files:

./MAX9000/max9000_LT.lib
line 35 - legacy micro character (‘µ’) with hex value = 0xB5

./gain-ctrl-amp/vca810.lib
line 21 - some non-printables with hex value = 0x96.

I open the schematic and simulate. Those two won’t simulate. The FullBridge example (see below) will work when I open it and simulate. But if I edit the properties and re-specify the same spice file it breaks.

Unfortunately, for reasons I don’t understand, it seems that even if I remove the exotic characters, FullBridge/2ED2109S06F_ng.lib doesn’t work for me. After I select the file KiCad can’t seem to parse the spice files.

When I remove the exotic characters from MAX9000/max9000_LT.lib and gain-ctrl-amp/vca810.lib, I am able to simulate things.

The nightly build I used doesn’t provide much information about what has gone wrong.

Potentially non-UTF8 characters:

FullBridge/2ED2109S06F_ng.lib lines 44, 46, 67, 68, 72, 130, 132 and 135
MAX9000/max9000_LT.lib line 35
gain-ctrl-amp/vca810.lib line 21

I found this via a bash script that included

function Z { LC_ALL=C grep ‘[^[:cntrl:][:print:]]’ ; }
function X { (cat -n $1 | Z > /dev/null) && (echo FAIL $1 ; cat -n $1 | Z && echo; cat $1 | Z | hexdump -C ; echo ); }

Here is some of the output.

FAIL ./FullBridge/2ED2109S06F_ng.lib
44 * INFINEON’S MODEL TERMS OF USE
46 * BY DOWNLOADING AND/OR USING THIS INFINEON MODEL (“MODEL”), THE USER
67 * 2.1 Infineon Technologies AG (“Infineon”) is not and cannot be aware of the

00000000 2a 20 49 4e 46 49 4e 45 4f 4e e2 80 99 53 20 4d |* INFINEON…S M|
00000010 4f 44 45 4c 20 54 45 52 4d 53 20 4f 46 20 55 53 |ODEL TERMS OF US|
00000020 45 0a 2a 20 42 59 20 44 4f 57 4e 4c 4f 41 44 49 |E.* BY DOWNLOADI|

FAIL ./MAX9000/max9000_LT.lib
35 * single +2.5V to +5.5V supply and draw less than 500A of

00000000 2a 20 73 69 6e 67 6c 65 20 2b 32 2e 35 56 20 74 |* single +2.5V t|
00000010 6f 20 2b 35 2e 35 56 20 73 75 70 70 6c 79 20 61 |o +5.5V supply a|
00000020 6e 64 20 64 72 61 77 20 6c 65 73 73 20 74 68 61 |nd draw less tha|
00000030 6e 20 35 30 30 b5 41 20 6f 66 0a |n 500.A of.|
0000003b

FAIL ./gain-ctrl-amp/vca810.lib
21 * Datasheet: SBOS275F JUNE 2003REVISED DECEMBER 2010

00000000 2a 20 44 61 74 61 73 68 65 65 74 3a 20 53 42 4f |* Datasheet: SBO|
00000010 53 32 37 35 46 20 96 4a 55 4e 45 20 32 30 30 33 |S275F .JUNE 2003|
00000020 96 52 45 56 49 53 45 44 20 44 45 43 45 4d 42 45 |.REVISED DECEMBE|
00000030 52 20 32 30 31 30 0a |R 2010.|
00000037

Thanks very much!

You replied before I could finish my message to Hatte about the repo.

I didn’t mean to bother you with more messages in this thread. I will add an issue in git.

Also, I just figured out that if I edit FullBridge/2ED2109S06F_ng.lib to try to fix things, even if I remove the exotic chars I can’t seem to get it to simulate. If I just open up the project though and click simulate, it works.

I will be trying to move on use ngspice now instead of trying to track down the problem. I figured I should mention this to you in case it matters.

The repo by Hatte is just a (seemingly unmaintained) copy of my circuits presented here. So it is of no use to post any issues there.

Obviously the appearance of of non-UTF8 characters is a common “feature” of commercial models. And KiCad cannot cope with this, at least on Linux (On my Windows it has been o.k.). So this is a KiCad bug. KiCad bug reports have to be placed at Issues · KiCad / KiCad Source Code / kicad · GitLab, following some specific format. Otherwise KiCad developers might not became aware of the problems.

I have uploaded a new 555 circuit example, this time switching to KiCad 9.

3 Likes

An example of a transistor curve tracer.


It’s a simple circuit. About the simplest you can create with a BJT, but none the less, I believe it’s useful for posting here. Not only as a beginners example, but also to verify that the both the BJT model, and the ngSpice simulator work.

In Schematic Editor / Inspect / Simulator / Simulation / Edit Analysis Tab the BJT is set up with base current increments of 1uA (See “sweep type”, even though the “Increment step” shows V as units) and for each step the collector voltage is swept from 0 to 8V, resulting in a plot for each of the 1uA base current steps.

I also added a small selection of spice models in the “bjt.lib” library. It’s just a selection of commonly used BJT’s taken from bigger libraries on the ngSpice website.
To get it to work, (after fiddling with the library) I also had to fix the pin assignment (again). To do that, go to: Symbol properties (of the BJT in the schematic), then Simulation Model / Pin Assignments, and then match the symbol pins with the model pins. You probably have to change this too if you try another transistor model.

image

And of course, the zipped up project, made in KiCad V8:

2024-10-15_bjt_curve_tracer.zip (10.3 KB)

3 Likes