A few months back @Joao was asking how to plot two variables as X/Y as you’d see on an oscilloscope’s XY Mode. Simulation Plot XY I’m also working on circuits like this. It’s basically a lot of analog multipliers, dividers, bias, and op-amps. They’re really difficult to get right using the existing simulation tools. I’ve built hardware and it doesn’t even get close to what I wanted. So… what is method folks are using to inject an two variables to a circuit and output something in CSV or whatever so we can plot it?
Your question is too general. Let’s make it more specific: Vary X_IN and Y_IN (voltage sources .V5 and V6) and monitor X_OUT
Spice Simulator Window → New simulation tab → DC - DC sweep analysis → sweep type V → . Source 1: V5, Source 2 V6, start, final, increment for both sources, uncheck currents, power, digital
Signal window → select V(/X_OUT)
Run the simulation (after having attached spice models for the amplifiers and the multiplier)
Watch the outcome.
Saving data to file requires using ngspice commands. Put in a text box onto the Eeschema canvas:
.control
set controlswait
wrdata mypath/myfile V(/X_OUT)
.endc
Thanks that’s great. But it outputs only one variable. I want X and Y together. There are two axis on an XY mode graph. For example. https://www.youtube.com/watch?v=p3qvsSAwmu4&t=87s
Rather than just outputting two separate sweeps, you want them combined into a 2D graph. XY Mode.
But it outputs only one variable. I want X and Y together. There are two axis on an XY mode graph.
You can add as many vectors to “wrdata” as you need. Check out the ngspice manual. So, just add whatever you want on the Y axis as an additional parameter.
wrdata xydata.csv V(/X_OUT) V(/Y_WHATEVER)
The output certainly isn’t a standard csv. Using wr_singlescale, wr_vecnames and wr_onespace gets it closer, too bad those don’t default to on.
So just to be sure – there’s no way of asking KiCad Simulator GUI to do an XY Scatter plot? It sure would be nice to have it auto redraw with adjustments to the tunables.
There are a couple of irritating bugs in the KiCad GUI.
- Whenever you click the edit DC Sweep Analysis tab, it switches both Sources back to the first one in the list. Dunno why you’d ever want two identical sources.
- It should remember all the settings so you don’t have to keep unchecking things.
- It’s near impossible to figure out how to force spice to reload the configuration and netlist from the schematic. I think it’s some combination of deleting the analysis, closing the simulator, saving the eeschema text block and then restarting everything?
How it XY looks in the GUI.
How it looks in an XY Plot.
Indeed there is no way.
There might be another option: Install GnuPlot. Then add to the .control section:
.control
set controlswait
wrdata mypath/myfile V(/X_OUT) V(/Y_OUT) ; not required for gnuplot
gnuplot gplfile V(/Y_OUT) vs V(/X_OUT)
.endc