Simulation examples for KiCad8/Eeschema/ngspice

New simulation examples are following here.

This time I am using KiCad 8. The new simulator interface is offering a lot of enhancements, which make it absolutely worthwile to have a look at this development. ngspice-41 is typically involved. Sometimes I am using ngspice-42 to benefit from the ngspice improvements.

The previous examples (KiCad 6, ngspice-38) are visible at Simulation examples for KiCad/Eeschema/ngspice .

The examples provided should run out-of-the-box: Extract the *.7z file into a directory of your choice. Open the project (or directly open the *.kicad_sch in Eeschema 7.99) → Inspect → Simulator → Run (green triangle).

The circuits shown below are not optimized, but may serve as a good starting point.

Potentiometer with tunable control


epot.7z (4.7 KB)
How to set up the tuner tool:

Potentiometer models
Attached you will find a small collection of potentiometer models
potentiometers.7z (6.8 KB)

How to use ngspice parameters to set device parameters and the .control section for printing values.


params.7z (4.9 KB)

Boost Converter
The first example is a simple boost converter, powering up 2.5 V to about 6 to 7 V. The switch is a power MOS device, the load is switched from 120 to 60 Ohms.



Boost.7z (7.2 KB)

Regulated boost converter
The previous example has been a ‘free-running’ converter. Load-switching and variation in input voltage will require some regulation. The following example adds a reference voltage, an error amplifier and a PWM (pulse-width modulation) stage to the simple boost converter. Here ngspice-42 is required, as it contains an improved PWM generator.


The output load is switched at 13ms from 60 to 20 Ohms. The two cursors clearly show that the output voltage regulation is working.

boost-complete.7z (12.8 KB)
Here is a version which does not need ngspice-42, as it relies on a pwm generator made with the vernerable one-shot code model.
boost-regulated-os.7z (12.6 KB)

Buck Converter
A simple buck converter with power NMOS


Buck.7z (7.1 KB)

Royer Converter
The next one is a Royer converter, as described in Royer Converter – Mikrocontroller.net (in German).


Royer.7z (10.6 KB)

LLC Converter
The next one is a resonant LLC converter:


This is an update, now using the switch symbol from library Simulation_SPICE, and there are ngspice switch models attached to these symbols.
LLC.7z (10.5 KB)

Digital PWM amplifier
This is the very basic prototype of a digital amplifier. You have a sine source, a PWM modulator with digital ouput, an anlog filter and the analog load.


The digital output consists of two inverse digital signals dn and dp:

The analog plot compares the sine input versus the differential output voltage on the load resistor R1:

pwm-audio.7z (6.9 KB)

Digital PWM amplifier update
This is an update to the basic class D amplifier: Use parameters for the PWM modulator, increase the output voltage to 200V: this yields in an output power of 2.7 kW. And nothing explodes (a benefit of the simulation)!

pwm-audio-2.7z (7.0 KB)

This one benefits again from the new PWM generator in ngspice-42, as the old one shows some dimples in the output, due to missing pulses.

Another Class-D 2.5 kW audio amplifier
with half bridge MOS driver and a ‘home made’ audio driver circuit model (pwm, non-inverted and inverted outputs, dead-time, hi-side and low-side outputs).


The simple Class-D-s uses the one-shot PWM (already available in ngspice-41 and older), the slightly more complex Class-D uses the somewhat faster new PWM from ngspice-42.

Class-D.7z (20.4 KB)

Analog multiplier
A circuit to demonstrate using a code model inside of a subcircuit.


The ouput is dressed in beautiful colors:

analog-multiplier.7z (5.0 KB)
You may do amplitude modulation studies, e.g. by setting V2 to dc=0 ampl=1 f=100k and V1 to dc=0.6 ampl=0.4 f=1k, just to obtain

Generic symbols with generic models
The next circuit uses symbols and models from the Simulation_Spice library (opamp and npn transistor). So for a quick analysis there is no need to search for specific device models. Transient and small signal ac is simulated.

intro4.7z (8.9 KB)

IBIS interface simulation
Some “finger execises” in the new IBIS module are shown next. IBIS allows to simulate drivers and receivers (the I/O of ICs and their connections) without resorting to the inner functions of the participating ICs. Typically a sequence “Driver – Interconnecting tracks – Receiver” is simulated. Still somewhat experimental.

ibis-test.7z (61.8 KB)

Amplifier with controlled gain
using the TI TCA810.


gain-ctrl-amp.7z (8.1 KB)

Up-Down Counter
The up-down counter uses a home-made symbol, a home-made counter model exploiting the ngspice/XSPICE state machine, and user-defined signals for plotting. Please have a look at README before starting the project.



up-down-counter.7z (6.2 KB)

Triangle generator with MAX9000


MAX9000.7z (45.9 KB)

The venerable ICL8038
THis project contains a new spice model for the ICL8038, some info how to create such a model from the circuit diagram in the data sheet, the project to create a subcircuit for the model and an example circuit.
ICL8038.7z (72.6 KB)

The model circuit

The example circuit


The output, scaled

Generating a negative voltage from a positive supply with LTC1044
LTC1044.lib contains a new behavioral ngspice model. The project is
LTC1044.7z (7.6 KB)
The circuit


and some output of a transient simulation

Another 555 circuit example


The resulting output is

and the project (including a bipolar 555 model generated by KiCad).
555bip.7z (7.5 KB)

Logic simulation: comparison of full adders
ngspice event based logic simulation to compare a ripple carry approach with NAND gates with an integrated 74HC283.


The simulation project (gtkwave is required for plotting)
FullAdd.7z (22.9 KB)
The ouput looks like

Logic simulation: divide by 4 with 7474
digi7474.7z (7.9 KB)


Step-Down converter with LM2576



LM2576.7z (10.3 KB)

Step-Down converter with LMR33630
LMR33630-StepDown.7z (21.2 KB)

This is one of the more delicate simulation examples. The original LMR33630 model contained bugs and incompatibilities, so needed to be edited. Simulation is slow as we need very short time steps. It will simulate only with the appropriate ngspice options chosen, and it will need about 6 GB of memory for the results, as all nodes also from inside of the model will be saved at each time step.


Results are however good: Changing the load by a factor of 5 will be regulated quickly, changing the input voltage by 2 V is barely to be seen at the output.

This example also has led to some improvements to KiCad/ngspice: The incompatibilty and the excessive memory usage will be removed in ngspice-43.

14 Likes

2 posts were split to a new topic: Is there any digital logic capability in ngspice 41 or newer

Some more circuits from my previous post, here now tested/updated for KiCad 8:
Q17.7z (39.4 KB)
LM3886-Tian.7z (17.1 KB)
rel_osc.7z (13.7 KB)
bip-osc-2.7z (8.6 KB)
CMOS555_4.7z (10.4 KB)
PassLabsF5.7z (23.2 KB)
FullBridge.7z (16.7 KB)
741.7z (19.2 KB)
QEI_public_8_mod.7z (22.1 KB)
MC3.7z (10.0 KB)
33063-KiCad-StepDown.7z (11 KB)
UC1825.7z (26.0 KB)

7 Likes

Hi guys
Was anyone able to run the ibis.test.7z project from holger (see above)?
I run only into a couple of error messages

Can't open viewport for graphics.
\Users\***********
ngspice-42 done
Note: 'quit' asks for detaching ngspice.dll.
Note: can't find the initialization file spinit.
******
** ngspice-42 shared library
** Creation Date: Dec 31 2023   07:13:41
******
Note: No compatibility mode selected!
Circuit: *
Note: No compatibility mode selected!
Circuit: KiCad schematic
Error on line:
v.xu1.vku xu1.ku 0 pwl ( )
parameter value out of range or the wrong type
Error: circuit not parsed.
Error: vector time not found!
Error: vector time not found!

With today’s nightly I do not see any problems (two different machines running MS Windows). My previous nightly from Jan. 3rd seemed to have some problem.

No way for me to run the ibis example. Other projects work fine.

I created a new schematic from the scratch and it fails with the same errors.
Do you need some more informations? Shall I open a ticket in gitlab?

Btw.
Is it intentional that you share KICAD6 files?

Another point…
I would expect to see real values from the ibis file here.
grafik

Typ, Min or max could be chosed in a separate box

grafik

just an idea…

In this thread: no.

I have presented KiCad6 examples in Simulation examples for KiCad/Eeschema/ngspice .

4 posts were split to a new topic: Falstad simulator fo simple tasks

@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