Simulation examples for KiCad/Eeschema/ngspice

Attached you will find some simulation examples for audio amplifiers, oscillators, power supplies, and other circuits.

All have been designed/tested with KiCad 6.0.2 / ngspice-36 or KiCad 6.0.10 and ngspice-38.

All will run with internal ngspice,
Inspect → Simulator → Run —> Add Signals
some (Tian probes) will require an additional external ngspice (mostly for its more complex interface and output capability)
File → Export → Netlist… → Create Netlist and Run Simulator Command
after having added the path to external ngspice into the ‘External Simulator Command’ text box (in my case for Windows 10 I have added C:\Spice64\bin\ngspice-36 "%I" ).

I have put the examples here without comments, more info is due later on the ngspice web pages (as time allows).

There is no PCB work available, just schematic capture and simulation.

It may be necessary to do the following step (setting the compatibility):
Inspect → Simulator → Sim Parameters → Compatibility mode → PSPICE and LTSPICE

More circuits, now using KiCad 7.99, are available at More simulation examples for KiCad/Eeschema/ngspice

Integrated linear amp (LM3886), simple, real, Tian Probe

LM3886_simple.7z (9.8 KB)

LM3886.7z (14.2 KB)

LM3886-Tian.7z (17.4 KB)

The Tian probe may be used for a stability analysis of the feedback amplifier. More info is available in the attached project, file Tian.readme.

Pass Labs F5 Class A Audio Amplifier

PassLabsF5.7z (22.7 KB)

Information on this amplifier stems from https://www.firstwatt.com/pdf/art_f5_turbo.pdf, and there are extensive threads how to build it at F5 Turbo Builders Thread | diyAudio and F5Turbo Illustrated Build Guide | diyAudio . Electro-thermal simulation is used, as not only electrical signals are considered, but also self-heating of the power transistors and their cooling by heat sinks.

Simple VDMOS Audio Amplifier

Dual-NMOS-Amp-VDMOS.7z (13.9 KB)

VDMOS Audio Amplifier with OpAmp, Optional Tian Probe

MOSAMP_VDMOS_601.7z (16.3 KB)

MOSAMP_VDMOS_601-TIAN.7z (18.6 KB)

A bipolar 741 operational amplifier
Including a desription and example how to generate a subcircuit model for the 741 with help of the Eeschema internal circuit.

741.7z (17.9 KB)

Sallen-Key-Bandpass Filter (Dual OpAmp)

sallen_key-bandpass-072.7z (10.1 KB)

Q17, a redesign of the famous QUAD405 High-End Audio Amplifier,
made by Tiberiu Vicol (Q17 - an audiophile approach to perfect sound | diyAudio). He designed circuit and PCB with KiCad, I have modified his files to enable simulation with KiCad/ngspice.
Q17.7z (39.3 KB)

19 Likes

Some examples for power supplies:

SMPS, step up, with MC34063
33063-KiCad-StepUp.7z (10.5 KB)

SMPS, step down, with MC34063
33063-KiCad-StepDown.7z (10.2 KB)

Detailed circuit descriptions (in German, you may use Google translate for any other language): https://www.mikrocontroller.net/articles/MC34063

A linear regulator (LM317)
LM317.7z (5.3 KB)

A complete power supply with LM317, mains to dc
LM317_power_supply.7z (9.8 KB)


Some reading on Power Supply Simulation .

A modern LDO regulator, filtering noise



The TI model is slightly modified, corrected:
TPS7A54.7z (10.9 KB)

A 50W, 48V to 5V DC to DC Converter with UC1825
1.5MHz clock frequency, and pulse width modulation
Slide6-Orig.7z (24.8 KB)

This circuit has been presented in the UC1825 data sheet at https://www.ti.com/lit/gpn/uc1825 . More details are available at https://www.ti.com/lit/pdf/slua053 .

Hybrid Switched Capacitor converter, 28 to 700 V using current GaN switching transistor and SiC Schottky multiplier diodes. Please see Design and Evaluation of Hybrid Switched Capacitor Converters for High Voltage High Power Density Applications. (Conference) | OSTI.GOV for its description.


HSCC-1-pub.7z (16.4 KB)

Simulation results, voltages at the different stages, input is 28 V, efficiency is around 90%:


Details plus inductor current I(RESR1):

A simple TRIAC circuit


TRIAC.7z (27.8 KB)

Full-bridge, 200 V, 20 A
Just a demo, not a productive circuit.
Uses Infineon SOI half-bridge drivers with integrated bootstrap.


Full-Bridge.7z (15.9 KB)

Digital

Some examples for digital devices (NAND, INV, FF) based on CMOS,
Original (KiCad 5) is found here: GitHub - bobc/kicad-simulation-examples: Example projects for spice simulation in KiCad
Updated to KiCad 6.0.2 and slightly improved:
digital-by-bobc.7z (22.6 KB)

Miscellaneous
You love tubes? ECC83 is here:
ECC83.7z (6.6 KB)

A CMOS Operational amplifier
CMOSOpAmp.7z (10.7 KB)

A CMOS version of the famous 555 timer circuit
CMOS555_2.7z (21.5 KB)

Using the 555, a police “Dee-Dah” Siren


CMOS555_3.7z (9.1 KB)

The simulation reveals the two frequencies:


With the additional discrete ngspice (by exporting the netlist together with the .control scipt), a fft is performed, clearly showing the two frequencies (and some harmonics)
fft-out

A 555 with bipolar transistors


555-bipolar.7z (19.0 KB)

Various ring oscillators, demonstrating the power of subcircuit models
(7404, CMOS inverter, inverter made of switches which replace the MOS)
RO.7z (8.2 KB)

Monte Carlo simulation is applied in the next three examples, to a Wien Bridge Oscillator. The ngspice control language is used to modify two resistors, run the loops, evaluate and print the data. Some more info is available in mc_info.txt.

In the first example the resistors R1 and R2 are modified directly.
MC1.7z (8.6 KB)

In the second exampl the resistor values are modified by using the ‘alter’ command.
MC2.7z (7.8 KB)

In the third example random values are generated at constant time steps, to modify the resistors. So you have all data available in a single transient simulation run.
MC3.7z (9.4 KB)

A simple Phase Shift Oscillator


bip-osc.7z (7.3 KB)

Phase shift oscillator with OpAmp
Including frequency measurement with FFT


OpAmp-Osc.7z (10.4 KB)
Some reading about Phase-Shift (or RC-) oscillators: https://www.electronics-tutorials.ws/oscillator/rc_oscillator.html

A quartz crystal oscillator


clapp-crystal-oscillator.7z (8.0 KB)

Astable multivibrator
provided by paulvdh, slightly modified:


astable.7z (6.5 KB)

Comparator Oscillator
Circuit idea by BobZ


Comp-Osc.7z (7.8 KB)

Schmitt trigger relaxation oscillator with 40106


relax.7z (9.5 KB)

0V to 5V Bar Graph Meter with LM3914 including a ‘home-made’ LM3914 Spice model


3914.7z (12.4 KB)

S-Parameter Analysis
(RF simulation using external ngspice-37)


S-Param.7z (5.0 KB)

Mixed Signal (Analog + Digital) Simulation
The next project is sort of preview, as it will need ngspice-39, which is just out today. It is a mixed analog/digital simulation and uses gtkwave for plotting the digital signals.


QEI_public.7z (22.5 KB)

6 Likes

Thanks for your example.

Thanks!

(I think the LM317 – at least the LM317L – should have in practice some 10µF cap on ADJ pin, besides the usual caps on input and output, and maybe some diode as well…)

Hi,

Could do some explaination about:

Compatibility mode → PSPICE and LTSPICE

Please see 16.14 in the manual (and it also means model_mode is set to 4 in *.kicad_pro).

I have added a complete power supply, mains to dc via transformer and LM317, using input from Ste and franzee.

3 Likes

There is an update to the power supply, with a somewhat more realistic transformer model (still an estimate, not a model of a real device).

You may start the simulation (including plotting) by
Inspect → Simulator → File → Open → selecting power_supply.wbk —> Siumulation runs, plot shows up, but sometimes not to scale so —> right click, select ‘Fit on Screen’.

You will see the rectified and the stabilized voltages, and the output current jumping up, because the load switches from 90 to 9 Ohms at 350ms. The LM317 nonetheless keeps the output voltage stable at 9 V.

2 Likes

Some reading for simulating power supplis: Power Supply Simulations

1 Like

I try to run the Slide6-Orig.7z’s simulabtion circuit, but it shows the error in the below:

Did you see this remark?

1 Like

Oh sorry, I missed it.

Thank you very much.

I have made some updates (for the Amp section for now):
Added circuit diagram pictures, added the compatibility flag ‘LTSPICE and PSPICE’, where appropriate.

1 Like

This is an incredible help for me as a total noob to simulation.

I have some basic questions:
1: you seem to be using both the “pspice” and the “Simulation_SPICE” libraries. Is that right?
2: how do you set the components up for simulation? Until now, my only solution was to build local libraries and add supplier models manually. Is there a smarter way?

Thanks.

To 1) That’s right.

To 2) No, there is currently no other way. It is being discussed among the developers to improve it. You will find a basic set, very complete lists and external links of models and model parameters here: Spice models and model parameters for ngspice circuit simulator

Thanks, that link was great.

Another question: is there any difference in using “pspice” vs. “Simulation_SPICE”? Anything to look out for?

That’s a matter of taste. I prefer the Simulation_Spice lib.

There is a new example on Monte Carlo simulation in this thread.

2 Likes

I believe that for the DIODE symbol, it’s best to avoid them both, if you want to create a PCB later (they are fine if you want to stay compatible with e.g. LTspice). Use a regular symbol from Diode library and specify alternate node sequence 2 1, or use some symbol installed with the content manager that has it specified already (like in Elektuur Style or Generic Symbol Library).

i love your work. Could you do a bit of explanation on it? It might be helpful. Thanks.

I have added some missing links to the origin of the circuits, containing also much more detailed explanations.

If there are questions concerning the circuits, please consult the links given. If there are questions on setting of one of the projects displayed here, please just post them here.

2 Likes