Monte Carlo simulations using ngspice-28


#1

I’m trying to get Monte Carlo analysis of filters to work. A basic .AC analysis works fine, but I can’t get a script to work to run a sizeable iteration count and collect output.

Here’s the SPICE netlist generated (the blockquote unfortunately seems to not format correct). The .ac directive before .control and the loop is for KiCAD to understand this is an .AC analysis. Otherwise it just issues an error when I try to run it.

.title KiCad schematic
R1 Net-C2-Pad1 Net-C1-Pad1 1000
R2 Net-C2-Pad2 Net-C1-Pad1 90.9
R3 Net-C1-Pad1 VIN 100
C1 Net-C1-Pad1 0 76.9nF
C2 Net-C2-Pad1 Net-C2-Pad2 6.83nF
X1 0 Net-C2-Pad2 VDD VSS Net-C2-Pad1 IDEAL
R4 Net-C4-Pad1 Net-C3-Pad1 1000
R5 Net-C4-Pad2 Net-C3-Pad1 500
R6 Net-C3-Pad1 Net-C2-Pad1 1000
C3 Net-C3-Pad1 0 15.0nF
C4 Net-C4-Pad1 Net-C4-Pad2 5.99nF
X2 0 Net-C4-Pad2 VDD VSS Net-C4-Pad1 IDEAL
R7 Net-C6-Pad1 Net-C5-Pad1 1000
R8 Net-C6-Pad2 Net-C5-Pad1 500
R9 Net-C5-Pad1 Net-C4-Pad1 1000
C5 Net-C5-Pad1 0 17.9nF
C6 Net-C6-Pad1 Net-C6-Pad2 4.42nF
X3 0 Net-C6-Pad2 VDD VSS Net-C6-Pad1 IDEAL
R10 VOUT Net-C7-Pad1 1000
R11 Net-C8-Pad2 Net-C7-Pad1 500
R12 Net-C7-Pad1 Net-C6-Pad1 1000
C7 Net-C7-Pad1 0 27.5nF
C8 VOUT Net-C8-Pad2 2.29nF
X4 0 Net-C8-Pad2 VDD VSS VOUT IDEAL
V1 VDD 0 dc 15
V2 0 VSS dc 15
V3 Net-R100-Pad2 0 dc 0 ac 1 0 sin(0 1 12.5k 0 0)
R100 VIN Net-R100-Pad2 0
R101 VOUT 0 100k

… removed ATr1 through ATr102 since the annoying forumware thinks I’m trying to reference other users rather than simply insert a text block and refuses to accept it …

.save V(0)
.save V(GND)
.save V(Net-C1-Pad1)
.save V(Net-C2-Pad1)
.save V(Net-C2-Pad2)
.save V(Net-C3-Pad1)
.save V(Net-C4-Pad1)
.save V(Net-C4-Pad2)
.save V(Net-C5-Pad1)
.save V(Net-C6-Pad1)
.save V(Net-C6-Pad2)
.save V(Net-C7-Pad1)
.save V(Net-C8-Pad2)
.save V(Net-R100-Pad2)
.save V(VDD)
.save V(VIN)
.save V(VOUT)
.save V(VSS)
.subckt IDEAL 1 2 3 4 5
E1 5 0 1 2 1000000.0
.ends
.ac dec 10 10 1000000.0
.control
let mc_runs = 100
let run = 1

  • set curplot = new
    set scratch = $curplot
    define tolerance(val, pct) (val + val * (pct/100) * sunif(0))
    dowhile run <= mc_runs
    alter C1 = tolerance(76.9n, 5)
    alter C2 = tolerance(6.83n, 5)
    alter C3 = tolerance(15.0n, 5)
    alter C4 = tolerance(5.99n, 5)
    alter C5 = tolerance(17.9n, 5)
    alter C6 = tolerance(4.42n, 5)
    alter C7 = tolerance(27.5n, 5)
    alter C8 = tolerance(2.29n, 5)
    alter R1 = tolerance(1000, 2)
    alter R10 = tolerance(1000, 2)
    alter R100 = tolerance(0, 2)
    alter R101 = tolerance(100k, 2)
    alter R11 = tolerance(500, 2)
    alter R12 = tolerance(1000, 2)
    alter R2 = tolerance(90.9, 2)
    alter R3 = tolerance(100, 2)
    alter R4 = tolerance(1000, 2)
    alter R5 = tolerance(500, 2)
    alter R6 = tolerance(1000, 2)
    alter R7 = tolerance(1000, 2)
    alter R8 = tolerance(500, 2)
    alter R9 = tolerance(1000, 2)
    ac dec 10 10 1000000.0
    set run = “$&run”
    set dt = $curplot
    setplot $scratch
    let vout{$run}={$dt}.v(out)
    setplot $dt
    let run = run + 1
    end
    plot db({$scratch}.all)
    .endc
    .end

The code is almost verbatim from an example bundled with ngspice-28, in examples/Monte_Carlo/MonteCarlo.sp

It does run for a while, about 5 seconds on my MacBook Pro, so it’s clearly doing something apart from spitting out errors.

The console output is:

Circuit: KiCad schematic
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Reference value : 1.00000e+01

No. of Data Rows : 51
Error: no such function as ac304.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac305.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac306.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac307.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac308.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac309.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac310.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac311.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac312.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac313.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac314.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac315.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac316.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac317.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac318.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac319.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac320.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac321.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac322.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac323.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Reference value : 1.00000e+01

No. of Data Rows : 51
Error: no such function as ac324.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac325.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac326.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac327.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac328.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac329.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac330.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac331.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac332.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac333.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac334.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac335.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac336.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac337.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac338.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac339.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac340.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac341.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac342.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Reference value : 1.00000e+01

No. of Data Rows : 51
Error: no such function as ac343.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac344.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac345.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac346.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac347.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac348.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac349.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac350.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac351.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac352.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac353.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac354.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac355.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac356.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac357.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac358.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac359.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac360.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Reference value : 1.00000e+01

No. of Data Rows : 51
Error: no such function as ac361.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac362.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac363.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac364.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac365.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac366.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac367.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac368.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac369.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac370.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac371.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac372.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac373.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac374.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac375.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac376.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac377.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac378.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Reference value : 1.00000e+01

No. of Data Rows : 51
Error: no such function as ac379.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac380.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac381.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac382.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac383.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac384.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac385.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac386.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac387.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac388.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac389.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac390.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac391.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac392.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac393.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac394.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac395.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
Reference value : 1.00000e+01

No. of Data Rows : 51
Error: no such function as ac396.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac397.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac398.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac399.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac400.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac401.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac402.v.
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51
Error: no such function as ac403.v.
Error: no such vector @c1[i]
Background thread stopped with timeout = 0
Doing analysis at TEMP = 27.000000 and TNOM = 27.000000
No. of Data Rows : 51

I can’t really tell what the problem here is… if it’s simply a matter of integrating with KiCAD, if KiCAD doesn’t know how to obtain the plot data. Or if the example is broken. (I built ngspice as a shared object so don’t have the command line to experiment with and I’m afraid building and installing a command line version will nuke the shared object installed.)

Why is it looking for “@c1[i]”?!


#2

Two small changes (running your example with Windows GUI version). Your output node is vout, so you are looking for v(vout). The quotation marks around $&run are not valid characters, so skip them.

ac dec 10 10 1000000.0
set run = $&run
set dt = $curplot
setplot $scratch
let vout{$run}={$dt}.v(vout)
setplot $dt

Then I get a plot output.


#3

Yes, that’s it! I removed the last plot statement as well. I can fill E-series values in the alter statements and have the plot reflect them. (Verified by changing a few of the caps’ MC loop values by factors of 10 and observing ripple.)

Sweet!

Now I just want the ideal component values’ plot in a different color on top so I can tell the deviation. That may actually require adding a separate plot for it (e.g. voutref in addition to vout).


#4

But, hmm, I think I’m only seeing one of the trace generated…


#5

Well, I figured out why this can’t work. The netlist generated contains .save statements, which saves node analysis data to be retrieved over the shared library interface. KiCAD never uses plots or plot vectors at all. So ngspice statistical analysis will simply never, ever work, without completely abandoning this scheme. I can get it to sorta work by adding statements to generate gnuplot output to a PNG file. Better would be to save the data and use a python matploblib/scipy to generate a heat plot. Ultimately, KiCAD should probably stop using saved node data and rely on plot data instead, with more flexible selection of which vectors to use from the last plot generated. (E.g. let me specify mc_vout* so I can generate a large number of statistically distributed vectors.)

Oh well. Although this can’t work I at least got up to speed with ngspice. :slight_smile:

Edit: Actually, looking at the shared library interface (in ch 19 of the manual) it looks like there’s a callback on plot vector creation. I suppose KiCAD gets this callback and saves the data provided in the last one. But a script may modify it (for example by generating two plots and dividing them, storing the result in the second one), e.g. “let dbdiff=db(vout) - db({$refplot}.vout)” to add a vector to the last plot that is the difference between its vout in db and a reference plot’s vout in db. Even if made to replace vout itself in the current plot KiCAD doesn’t get a callback on executing the let statement to add or modify the plot vector. (Which may be a bug in ngspice?) A workaround would be when ngspice is done to refetch the plot vectors to get the last value. But then it wouldn’t need the callback structure either and could just ask for the current plot (active plot at exit) and simply pull all the data from it.


#6

If no .save is given, ngspice will store all node voltages as vectors. Only currents through independant voltage sources will be stored as well. The .save command allows to add further vectors or replace the standard ones. There is no difference concerning storage and accessibility between vectors added by .save and the standard vectors.

Shared ngspice accepts all commands of standard ngspice except for plotting. There is no plotting interface. Plotting has to be done by functions integrated into the caller (eeschema).

Did you consider adding a ‘write’ or ‘wrdata’ command to your script? If this is running anyway, an output to a file should be possible.

How did you check that the ‘let’ command does not work? Not seeing the newly created vector in the eeschema plot window may be just a limit of the eeschema-ngspice interface. I don’t assume that there is a bug in ngspice. This could be checked by running your netlist in standard ngspice.


#7

In fact what is missing is an information to the caller (eeschema) that the user has added a vector. How can the caller be convinced to run again function 19.3.2.9 char** ngSpice_AllVecs(char*). Should the ‘let’ command issue the callback function 19.3.3.5 typedef int (SendInitData)(pvecinfoall, int, void*)? This would require an extra action on the caller side. Should we add another callback function? This would change the interface.

The caller does know, because he is the ‘user’. He sends the ‘let’ command.

I will have to think about that.


#8

I think the most obvious answer is to fetch the vectors when the command(s) is done. Then call ngSpice_AllVecs(). This way any vector added or modified in a plot will be used in its final state.

The word “plot” is a bit of a misnomer, so just so we talk about the same thing: commands such as ac, tran, etc create “plots”. A plot consists of a set of result vectors for the nodes, based on the specific analysis. Each time an analysis command is run, a new plot is created. For example, the ac command creates plots named ac1, ac2, ac3… acN. Plots in this sense is a data structure, not a rendering. “Plot” and similar rendering commands actually render these plots in some way. ngspice-shared of course has the plot data structures, just not the actual rendering. This is a bit different from common usage, where a plot is some kind if graph or visualization, not a data structure.

It would be very nice if by default the last active plot were used.

I wonder if there is a problem here with let vs .save? If the vector created with let hasn’t be save’d, will it actually be retained? Hmm.


#9
It would be very nice if by default the last active plot were used.

i just:
setplot tran1
setplot ac2
setplot sp7

etc… via proper script
Paul


#10

@holger

Regarding latest SW implementation on ngspice28

I have run some more syms including the following GDT model

.model G SW(Ron={Zon} Roff=1T Vt={.5*(Vstrike+Vhold)} Vh={.5*(Vstrike-Vhold)} Vser={Vhold-Ihold*Zon})

Currrently it is not recognizing Ihold as a valid PSPICE parameter.
So a simple GDT tracer fails to converge … ignoring Ihold

.SUBCKT GDT 1 2
.param Vstrike=100 Vhold=50 Zon=2K Ihold=200u Tau=100u
S1 1 2   2   N001  G
S2 2 1  N001   2   G
R1 1 N001   100Meg
C1 N001 2   {Tau/100Meg}
.ENDS GDT

V1  Vin   0 DC   200V
XU1 Vgdt  0 GDT  Vstrike=100 Vhold=50 Zon=2K Ihold=200u Tau=100u
R1  Vin  Vgdt    1meg
C1  Vgdt  0      10n

.tran 2000u 10u 0

Still to figure out someway to implement Ihold above with
latest PSPICE improvements.

Paul


#11

It is Vser that is unknown to ngspice. In my PSPICE manual from 2007 I do not find the SW switch, but only the VSWITCH (that is handled in ngspice). Lser and Vser are LTSPICE switch parameters.

Full LTSPICE compatibility is not (yet) available.

Holger


#12

The LTSPICE manual says:
Vser | Series voltage | V | 0.0

So you may place a proper voltage source in series with either the output ?? or the input ??. (I would guess the output, but I do not know).


#13

I will try your suggestion.

I have downloaded the latest VISHAY, EPCOS and Littlefuse PSPICE
models for their current line of MOVs and soon i will port some
LTSPICE MOV syms to test how far we can translate.

Along with other GDTs.
As soon as I have some valid thing I post back

Paul


#14
 a proper voltage source in series with either the output ?? 
or the input ??

EPCOS and VISHAY are using and recommend Rseries and Lseries
on INPUT of their published MOVs and SIOVs models.

On the other side Littlefuse is using a very complex
INPUT before L_series R_series of their TMOVs and UltraMOVs

Somethig like

.SUBCKT TMOV34S  1 2 PARAMS: T=3D1 C=3D1pF L=3D1nH a1=3D1.00 a2=3D23.63E-3 a3=3D275.397E-6=20
+     a4=3D-1.07E-3 a5=3D2.912E-3 a6=3D2.452E-3 a7=3D100u
E_non_lin	3 1	VALUE {T*(
+	10^(
+	+a1+a2*(log10(limit(v(4),a7,1g))-3)
+	+a3*2^(-log10(limit(v(4),a7,1g))+3)
+	+a4*exp(-log10(limit(v(4),a7,1g))+3)
+	+a5*exp(log10(limit(v(4),a7,1g))-3)
+	+a6*2^(log10(limit(v(4),a7,1g))-3)
+	)
+	-10^(
+	a1+a2*(log10(-limit(v(4),-1g,-a7))-3)
+	+a3*2^(-log10(-limit(v(4),-1g,-a7))+3)
+	+a4*exp(-log10(-limit(v(4),-1g,-a7))+3)
+	+a5*exp(log10(-limit(v(4),-1g,-a7))-3)
+	+a6*2^(log10(-limit(v(4),-1g,-a7))-3)
+	)
+	+limit(v(4)/a7*v(8),-v(8),v(8))
+	)}

Paul


#15

And to complicate a bit further the range of options

I have two PSPICE implementations of LIMIT
and now a 3rd one built on ngspice28 PSPICE compat.

Before that usually i would select one of them

.func limit(x, a, b) {min(max(x, a), b) }
or
.func limit(x, y, z) {min(max(x, min(y, z)), max(z, y))} 

in general with same results in time accuracy and interpretation
Paul


#16

Actually, having thought about it some more it would be nice to be able to produce multiple plots in a single simulation script, for example ac, noise, and disto. So for ‘custom’ it would be really nice to specify a series of: plot name, type of plot (e.g. ‘ac dec’ vs ‘ac lin’, not discoverable), vector name or vector pattern (e.g. ‘vout*’ - just plot all of these on top of one another for fat line, or dare I think intensity mapped trace), and an optional vector type (V, A, Hz, dbv, etc) since that too may not be obvious from a script.

This would do away with trying to discover from the first command what kind of plot it is, permit multiple plots, and also permit future enhanced plots. Just some ideas…

The actual plot rendering could be done in python. Then additional custom renderings could be added, especially if sits on top of pyplot.


#17

Another idea… how about extending the schematic file format to include simulation settings? Then it could be remembered between runs and auto populated either from synthesis or template…


#18

I have dealt with this consideration before.

Having multiple plots always leads of a inevitable problem of
having also multiple scales.

So by using the setplot mentioned before I select
each in time and dump vectors to a file where i can
reroute to gnuplot more easily to handle not only multiple
plots but also multiple scales.

And gnuplot is already more or less integrated in spice
so far it worked quite well for my goals

Paul


#19

I like the idea of a single UI integrated with eeschema though…