Newbie: Can't simulate LPF

Hello, all,

I’m trying to create my first ngspice simulation, without success. I was successful in following the tutorial to create the ‘rcrc’ filter, but get errors such as “no frequency vector found” when I probe the ‘out’ net of my circuit.

I’m using KiCAD 7.0.11. I don’t know how to display the version of ngspice used. Here’s the full version information:

Application: KiCad Schematic Editor x86_64 on x86_64

Version: 7.0.11~rc4-202402191806~3dedd899f7~ubuntu22.04.1, release build

Libraries:
	wxWidgets 3.2.2
	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.17

Platform: Ubuntu 22.04.4 LTS, 64 bit, Little endian, wxGTK, ubuntu-xorg, x11

Build Info:
	Date: Feb 19 2024 18:06:38
	wxWidgets: 3.2.1 (wchar_t,wx containers) GTK+ 3.24
	Boost: 1.74.0
	OCC: 7.6.3
	Curl: 7.88.1
	ngspice: 42
	Compiler: GCC 11.4.0 with C++ ABI 1016

Build settings:
	KICAD_SPICE=ON

Thanks for any help getting me unstuck. I’m sure it’s something simple.

-Kevin

rcrc.kicad_pro (5.7 KB)
FilterExample.kicad_pro (5.7 KB)

It is missing the .kicad_sch with schematic files.

Thanks. Didn’t know the .proj file didn’t contain the schematic. Here they are.

FilterExample.kicad_sch (17.8 KB)
rcrc.kicad_sch (17.1 KB)

Thanks, again.

-Kevin

You’re using a DC voltage source for your filter.

Well, yes, it’s a DC source with a DC value of 0V and an AC value of 1 or 70.7 (can’t remember which version I uploaded).

What should I be using? I wasn’t successful with the VSIN source, if I remember correctly.

Anyhow, see my next post.

Thanks for replying.

-Kevin

Well, VSIN is the one you should be using for a magnitude/phase plot.

I upgraded from KiCAD 7 to 8.0.3 and now I’m having more success. I’m now able to plot the output responses of the LPF. However, I’m still not able to observe the information that I’m searching for.

Ultimately, I’m trying to model a LPF for the 40m radio amateur band, from 7.00 to 7.30MHz. I want to calculate the maximum current flow through the inductor L1 (to size the wire used to wind it) and the maximum voltage across capacitor C1 (to spec the capacitor).

I can choose to view the output of “V(out) (gain)” which is the voltage across the capacitor, but the scale is in dBV; I’d prefer just volts. Also, I would have thought there would be some interaction between the capacitor and inductor, leading to voltages greater than the input. Am I mistaken in this assumption?

Also, I’d like to measure the maximum current flow through L1. I thought I could choose the probe tool, whose icon would change to a current clamp when over a component. I never see this. Furthermore, when I plot “I(L1) (gain)” I get something that seems to be measured in phase and not amps.

Any suggestions for what I’m doing wrong, or what I don’t understand correctly?

Thanks for your help and advice.

-Kevin

FilterExample.kicad_sch (21.9 KB)
FilterExample.wbk (770 Bytes)

Substituting VSIN didn’t seem to change anything; all the comments I made in my last reply to the list still exist.

Thanks for the suggestion.

-Kevin
FilterExample.kicad_sch (21.9 KB)

This is interesting. I can’t get it to simulate either.
I recreated your circuit like this:

And the result is this:

I upgraded from 7.0.10 to 7.0.11 a few days ago. Never had this issue before.

After mucking around a bit (mostly deleting suspicious texts) I got this schematic:

image

Which produced this output:

From this project:
2024-06-13_FilterExample.zip (6.3 KB)

Sorry for answering my own post. But the solution is, that VSIN source was missing a parameter.
Adding “ac=1” made the simulation work.

I did not add the “ac=1” in my copy of this project, It already was present, and the simulation still did not run. I’m not very proficient with ngSpice, and am not sure which text change did it (either the references or the values) I also changed the simulation to 100 points per decade to get a bit smoother curves.

File - Archive Project…

I have tried (only few simple tries) Spice with 7.0.11 and had no problems with such simple circuits. As I have also upgraded to V8 I will not try what was wrong with your V7 simulations.

R1 and R2 lower your LC resonance quality. There are simple Q equations when you have only one R.
If you set R1=0 you will get a circuit with Q= 50 * SQRT(620p/1.5u) = 1.017 (paralel RLC circuit).
You will see little hill at V(out).
Change R2 to 5k to get Q around 100 and you will see high peak.
Change R1 back to 50.
Assuming only R1 affects Q you get (serial RLC circuit) Q = (1/50)*SQRT(1.5u/620p) = 0.984
And you see small hill again.

@paulvdh , thanks so much for looking at and experimenting with my circuit.

I got this output, too, without making any changes to any text:

However, I still don’t understand how to get the answers to my two questions:

  1. What is the maximum voltage experience by C1? From this graph, it seems to be about 31 dBV which I think is 35.35 volts (1/2 of the source voltage of 70.7v). Is this correct?

  2. What is the maximum current through L1? When I place the cursor on the peak of the “I (L1) (gain)” curve, it reads “-844m°” which I don’t know what it means (meter degrees?), but at the least isn’t in amperes, which I would expect for a current. How can I find the answer to my question of the current through L1?

Thanks, again, for taking the time to try to help me.

-Kevin

Of course. If you don’t have any resonance peak than at low frequency L and C don’t work so you have voltage divider consisting of two 50Ω.

It is clearly a bug. It is not a Phase (as it is written at chart). At chart you see that your peak has Phase shown as about -0.84. So I suppose that -844m = -844E-3 = -0.844. Then I assumed it is not Phase but current.
10^(-0.844/20)=0.907A.
If we can measure the voltage over R1 we could confirm it, but I don’t know how to get voltage between two points. I have tried to write something in Measurement box, but it didn’t worked for me. Probably using some voltage driven voltage source (I don’t know if we have it here) with K=1 you will be able to see this voltage difference at its output with one pin connected to GND.
But I found simpler way. I moved R1 under V1 so I get directly voltage at R1. I got peak value of 33.1dBV so it is 10^(33.1/20)=45.186V. 45.186/50=0.904A.
I think it is enough close to my previous result to confirm that I am probably right.

If you really will have 70.7V and 6MHz in such circuit I think not the max L current and not the max C voltage are what you should be care about, but the power dissipated in L and C.

@Piotr , thank you for your analysis. It helped me a lot.

What I’m trying to do is correctly size the wire used to construct L1 and the voltage specification for C1, to design a practical and realizable LPF for a 40m 100W amateur radio transmitter. I think the maximum current in L1 will tell me the lower limit of the wire size, and the maximum voltage across C1 will tell me the lower limit of the voltage rating for C1. That’s what I care about.

Thanks, again, for your help.

-Kevin

  1. I’m affraid the voltage is not ½ conceptually, but rather 10^(31/20), i.e., 31 dB over one volt, as the voltage is against 1 volt. The result is similar, about 35 V.

  2. I concur with Piotr computation for the current in L1, although it is weird the ref be one ampere.

Pertaining your intent to use the simulation for a real world 40 m band ham radio 100 W LPF, I suggest you find a more real model for the capacitors and obtain the Spice model of the inductors you’ll use as the Q of these components will have a say in the dissipation of your filter.

For a thorough discussion on LC matching networks (albeit not filters, the topology is the same) and some ideas on how to compute the actual values, give a look at KC6JCA blog.

Just an update:

In the “measurement” subwindow it is possible (according to manual) to select predefined measurements right clicking the line of the signal.

I could not figure out from the Kicad documentation what measure point it selects in an AC sweep.

However for the Kevin circuit I got 750 mA RMS in L1 as shown in the figure attached.

If someone has further info on the meaning of this measurement it would be helpful!

I dug just a little bit in this issue and I’m starting to have new doubts on how Kicad brings the NGspice results to the ploting canvas.

I’ve exported the circuit and run command line ngspice¹, and the plots for the inductor current and capacitor voltage are attached.

Whereas Kicad imports and displays in dB these quantities, even so it shows the peak for current seems to occur at different frequencies!

The attenuation in the C2 (and the load) seems more like, although as well does not match exactly.


[1] As per Holger’s fine tutorials, so I skip the details here to keep this short.

@csrabak , thank you very much for your continued efforts to help me answer my question.

Regarding your suggestion that I need specific Q values for inductors and capacitors, this again seems like a circular argument: To choose specific components, I need Q values, but to find Q values, I need to look up specific components. I don’t know how to break out of this circle.

Regarding reading K6JCA’s blog (at K6JCA: 2022), there’s so much there that I was overwhelmed. There’s eight mentions of ‘matching’ on just the first page. I’ll have to spend some time with this.

Thanks, again, for your advice.

-Kevin