RLC KiCad circuit simulation

Hi everyone

I am trying to simulate an AC RLC circuit to play with frequencies : I have found a youtube example for LTSPICE but I am unable to do the same with ngspice/kicad, in particular showing the resonance frequency. I can do a transient simulation but it fails with AC.

Any hint ?

image

Please be more specific. What is the ngspice response? Any error message?

What is your operating system and your KiCad/ngspice versions?

A first quick answer: Your circuit is missing a ground connection. Spice always needs a ground connection (GND).

Holger, yo’re right … I mistakenly deleted it … I am now trying with ground

Application: KiCad Schematic Editor x86_64 on x86_64
Version: 7.0.9-7.0.9~ubuntu22.04.1, release build
Libraries:
wxWidgets 3.2.1
FreeType 2.11.1
HarfBuzz 6.0.0
FontConfig 2.13.1
libcurl/7.81.0 OpenSSL/3.0.2 zlib/1.2.11 brotli/1.0.9 zstd/1.4.8 libidn2/2.3.2 libpsl/0.21.0 (+libidn2/2.3.2) libssh/0.9.6/openssl/zlib nghttp2/1.43.0 librtmp/2.3 OpenLDAP/2.5.16
Platform: Ubuntu 22.04.3 LTS, 64 bit, Little endian, wxGTK, LXQt, x11
Build Info:
Date: Nov 8 2023 19:01:25
wxWidgets: 3.2.1 (wchar_t,wx containers) GTK+ 3.24
Boost: 1.74.0
OCC: 7.5.2
Curl: 7.88.1
ngspice: 38
Compiler: GCC 11.4.0 with C++ ABI 1016
Build settings:
KICAD_SPICE=ON

With Ground I can use AC simulation : 230 V 50 Hz

I am for sure doing something wrong with the power source …

image

Next problem:
You are powering your circuit with the ideal voltage source V1. This source has an internal resistance of 0. So what ever your circuit is, V1 will enforce its voltage onto your circuit. To see the effect of the resonant circuit, you will need a voltage divider, e.g. a resistor in series with V1.

In addition: a transient simulation starts with searching for the dc operating point. This is done by opening all capacitors and short-circuiting all inductors, and then look for currents flowing and the resulting voltages. Only after that transient simulation starts. In your case the indctor shortens V1, which is not allowed (short circuit on a voltage source with internal resistance 0 will yield a current towards infinity).
LTSPICE probably uses an RSER for the inductor.
You may place a series resistance to the inductor (or use the series resistance of V1 from above).

1 Like

Thank you holger : I am a total noob, taking advantage of learning thanks to ngspice and kicad. I’ve now got something and will now try to get to the final result

If in your first scheme you change voltage source to current source you will see what you expected.

Small correction.
I started to learn KiCad Spice a week ago and a week was enough for me to forget that in Simulation_SPICE library the ISIN source doesn’t work for ac simulation. There is lack of ac=1 in its parameters. The text: “dc=0 ampl=1 f=1k” should be “dc=0 ampl=1 f=1k ac=1”.
I just didn’t remembered that I corrected it and my ISIN simply works :slight_smile:

And here is my first simulation where I just couldn’t see what I expected until I found that ISIN symbol has bug in it:


Many years ago I found the Murata program that generated real capacitor parameters and since then I use them in my simulations. I used PSpice from 90s but it is ‘gone’ together with Windows XP :frowning: so when needed to simulate something I decided to check KiCad.

Good point. I just opened an MR to fix this: Simulation_SPICE: add ac=1 to ISIN (!4142) · Merge requests · KiCad / KiCad Libraries / KiCad Symbols · GitLab

I finally got it :slight_smile: (I guess) after slightly changing values and adding AC manually …

.title KiCad schematic
.save all
.probe alli
.ac dec 100 1 500k
C1 Net-C1-Pad1 0 1m
L1 Net-C1-Pad1 0 0.01
V1 Net-R1-Pad1 0 DC 0 SIN( 0 10 1000k 0 0 0 1 ) AC 1
R1 Net-R1-Pad1 Net-C1-Pad1 10k
.end

I am too much of a novice but this kind of classic circuit could well be added to the ngspice tutorials (or is ir probably there already).

I see you are 1E9 times faster than me :slight_smile:
I’d ask you to check the other Spice problem and may be make MR from it. Now I am writing from memory so not 100% sure.

I got NPN model and I couldn’t assign it to npn transistor symbol. Not by copying parameters to text symbol parameters (didn’t checked, but it may work), but by inserting a model into *.lib file and selecting that file and then that model.
I got message about unhandled excpetion.
I found that a source of problem is first (IS) parameter specification. In original file it was IS=10.2f.
I suppose that from following models:
.MODEL TEST1 NPN (IS=10.2f)
.MODEL TEST2 NPN (IS=10.2E-15)
.MODEL TEST1 NPN (IS=1.02E-14)
only the last one will not generate that error.
It is surprising as other parameters in model use m, n, p specifiers and if you replace the text describing the model with IS specified in f it probably will work.
10.2E-15 is also surprising. Later in the same model there is CJE=26.8p and it is no problem that there are 2 digits before dot.

I am surprised. You use VSIN and in VSIN the AC=1 was there (I use KiCad 7.0.9).

Thanks for your input piotr

I have entered it manually

You have to have different library. I have library installed together with KiCad 7.0.9 at Windows. And in Simulation_SPICE VSIN has ac=1 originally set.

This indeed is a double-edged issue.

If you have more than one VDC or IDC, and both have ac=1, then the simulation results may become ugly, perhaps unwanted, as you have the linear superposition of two or more sources at each output.

With ISIN or VSIN, well it may be o.k…

Yeah, only the SIN sources have an ac amplitude given by default. I think most people would usually only use one sine source, as opposed to many DC sources, so it makes sense for the sine sources to have an ac amplitude. But making symbols work out of the box for most cases isn’t a substitute for needing to understand how SPICE works.

Let my try with a new circuit : I could be mistaken …

I have added a SIN : to get the AC I had to fill the DC as well

image

.title KiCad schematic
.save all
.probe alli
V1 unconnected-V1-Pad1 unconnected-V1-Pad2 DC 0 SIN( 0 230 50 0 0 0 1 ) AC 1
.end

This is probably “working as designed” : no clue