Simulation Plot XY

Hi,

I’m using KiCAD 8, and I’m currently trying to create a plot XY (Vout versus Vin) in simulation but without success for the following circuit.

image

Any ideas on how can I manage this?

What kind of simulation do you intend to do?

In AC simulation you are plotting Vout/Vin versus frequency. Vin is 1 due to ac=1.

In transient simulation you are plotting Vout and Vin versus time.

Plotting Vout versus Vin in DC simulation does not make sense, as you have blocking capacitors C1 and C2.

Thank you for your response!

I am in the process of transitioning to an open-source simulation software for the electronic courses I teach.

My objective is to conduct a transient analysis and produce a plot of Vin versus Vout.

You can view the example I created using falstad at the following link: https://tinyurl.com/26l4jufd.

I have used Spice in KiCad only few days half year ago, but I suppose that getting something like Lissajous figures is not possible yet. I didn’t noticed any way to change X-axis to something other than default.
I think higher chance for this is in only Spice software like LTspice. I also don’t know the possibilities of Spice used in KiCad. I suppose KiCad uses only a fragment of its possibilities.

I don’t understand your Falstad plot at all, it makes no sense.
What exactly are you trying to show with that plot?

Actually Vin is 1 Vpp due to ampl=500m (assuming the intention is a transient analysis).

This type of plot is useful for assessing the linearity of an amplifier and determining its “valid” signal ranges.

These plots are often used in classes to teach students how to utilize an oscilloscope’s XY mode and to familiarize them with visualizing relationships beyond just “signal vs. time.”

Source: I am also a professor at the same college as @Joao

Just because the plot isn’t clear to you right now doesn’t mean it’s senseless. Let me briefly explain why this plot is interesting. It highlights the region where the amplifier’s output behaves linearly in relation to its input, as well as the boundaries of this linear region, where saturation occurs. This information helps evaluate how close the amplifier operates to its limits.

Yeah :confused:

That makes sense. I did not imply that the plot is useless, but the Falstad thing gives zero information on the plot. It’s just an angled line and anyone’s guess. Add to that that the input as well as the output is labelled “out” doesn’t make things easier.

In this post, line 2, I am talking about small signal AC simulation. In this context your statement is misleading, if not wrong.

When I do an AC simulation, the instance parameter AC=1 may be given to any voltage or current source, thus setting it as the input. All outputs then have to be referenced to this input. So selecting 1 is reasonable, as vout/vin = vout in this case. The refernce phase is assumes to be 0, if not given otherwise. The value 1 does not represent any voltage, just the reference.

Indeed the interface KiCad-ngspice is somewhat limited.

You may use additional ngspice capabilities by scripting, e.g. plotting with gnuplot.


gnuplot.7z (4.5 KB)

2 Likes

This is cool, thank you for taking the time to answer.

Are there any future plans from the KiCad team to implement this functionality in the GUI?

Also, this may be useful information for you or other readers, so let me share my experience getting this to work on Ubuntu 24.04LTS:

I tried your file and obviously D:/ does not exist. I tried substituting “D:/temp/gtemp” by “./temp”, but the simulation was still trowing some error about “D:/temp/gtemp” not existing, so I had to delete the simulation config and recreate it (i.e. I closed the simulation tab, pressed “New Analysis Tab” button, and configured all settings as you originally had). This was a bit unexpected and is possibly some kind of oversight / bug - it seems that the .control section was cached from when you ran the simulation in your computer, and did not update despite me changing the text field.

Do you have suggestions on how to do this in a more clean, platform agnostic way? The simulation worked on my computer after deleting the old one and installing gnuplot, but it placed the files on my home folder instead of the project folder (I’m guessing gnuplot is being called from a clean shell environment so “./” refers to my home folder?). @Joao tried that in windows and it apparently needs admin rights to write to “./”, whatever that folder means in windows.

1 Like

You should acquaint yourself with the meanings of “/” or “~/” or “./” in the Linux bash window.

Googling for a temporary directory in Linux yields “/tmp”. I have used this in the project below (without testing it). Please check if o.k…


gnuplot2.7z (5.4 KB)

/tmp is a bit special, as it is emptied when rebooting. If that’s OK, go ahead and use it.

Hi @Holger, I think there has been a misunderstanding :sweat_smile:

I know that you can use /tmp to store temporary files on Linux, but that is beyond the point as I was asking about a platform agnostic way to store the plot files.

I think what caused the confusion is the fact that I mentioned “./temp” when I should have really written “./gtemp” to follow the convention you were using. Or even better yet, something like “{ProjectDir}/gtemp” - the behavior I was expecting when using “./” was that “./” meant the current working directory (i.e. the project directory, where the .kicad_pro file is located).

By storing the plot files on the project directory, the simulation should work regardless of the underlying OS and whether certain drives like “D:” even exist.

It appears that there has been a mistake with the file you have attached - it is the same as the first simulation file you provided. I copied the control section text as shown in your image and can confirm it works fine (but the quotes had to be changed from ’ to ").

Still, if possible, I’d prefer to specify the project dir instead of dealing with per-OS idiosyncrasies. I saw that you used $oscompiled, and after looking at the NGSpice documentation, I see that this is one of many internal variables made available by NGSpice. I saw that $inputdir is also a variable, but on my system this points to “/usr/share/ngspice-kicad/ngspice/scripts”, which is obviously not what is intended.

So, do you know if this is possible to specify the current project directory? Is there any other variable I can write in the control section that achieves this?

1 Like

On MS Windows the project directory is not the current directory, but the directory where Eeschema.exe is located is the current directory. The user typically has not writing access to this directory.

You will get trhe current working directory by putting a

.control
pre_getcwd
.endc

onto the Eeschema canvas.

Eeschema is sending the project directory to ngspice, but it is not available as a variable. I will change this in the next ngspice release.

1 Like