4

Running a worst case simulation, as guided here: LTspice: Worst-Case Circuit Analysis with Minimal Simulations Runs
How does one find out what circuit values were used during a run? In my sim I have 12 resistors, so 4096 runs. On run 265 there was a decent shift in output, so I would like to find which resistor values were used during a specific run.

Aaron
  • 7,274
  • 16
  • 30

3 Answers3

7

Looking at the way they define the wc and binary function in the article, the index of the parameterized value is the "bit" in the run number (starting from the LSB), which is the last parameter of the wc function they created.

So in figure 3 of the article, R4 is bit 0, R1 is bit 1, R2 is bit 2, and R3 is bit 3:

figure 3

Then to decode what value each resistor has you just need to encode the run number in binary, and if the specific bit is 0 you are on the min value, and if 1 you are on the max value. A special case is when the run index equals \$2^N\$. In this case all resistors are set to the nominal value.

As an example, take run 5 from the example they give in the article. In 4-bit binary this is 0101, so the value of the 4 resistors are given by: $$ R_4 = 22.5\cdot (1+0.05) k\Omega\\ R_1 = 22.5\cdot (1-0.01) k\Omega\\ R_2 = 22.5\cdot (1+0.01) k\Omega\\ R_3 = 22.5\cdot (1-0.05) k\Omega $$

If you have a different definition for wc or binary, then the order might be different.

In your case, run 265 is 000100001001, so whatever is index 0, 3, and 8 are the max value and all the others are the min value.

helloworld922
  • 16,600
  • 10
  • 54
  • 87
  • There are multiple good answers here. This one was the one that my brain groked the easiest. – Aaron Sep 09 '21 at 18:24
  • Using the above method, I was then able to identify and reduce the worst case down to 4 resistors, then re-run the sims to verify. – Aaron Sep 09 '21 at 18:26
7

I don't recall seeing that page you linked before and I've not needed to do worst-case testing of lots of parts in LTspice. So you faced me with a novel (to me) question. But the answer wasn't hard to find.

Let's take a simple case (to save me from typing more) of a resistor divider:

enter image description here

I think I've accurately represented a case from the link you provided, above. When I run this and click on \$V_{_\text{DIV}}\$, and add a couple more traces, I get the following chart:

enter image description here

The x-axis is the run number, the red trace is the unloaded divider output voltage, the green trace is the value of \$R_3\$ and the turquoise trace is the value of \$R_1\$. You can just read them directly off of the plot.

The only issue is that you need to be creative in specifying what to plot.

You can also use the .MEAS card. Like this:

.MEAS R1 FIND V(N001,VDIV)/I(R1) WHEN run=RUNSELECT

That is, if you have identified the run number of interest to you. In this case, it will capture these values for you and store them into the "Spice Error Log", which you can access using View/Spice Error Log from the menu system.

You can sprinkle in as many of these as you feel you need. But in that case you might want to create a PARAM and use that, instead. So, let's say I wanted the values for \$R_1\$ and \$R_2\$ at run=2. I might do the following:

.PARAM RUNSELECT=2
.MEAS R1 FIND V(N001,VDIV)/I(R1) WHEN run=RUNSELECT
.MEAS R3 FIND V(vdiv)/I(R3) WHEN run=RUNSELECT

I'd find this in the log file:

r1: v(n001,vdiv)/i(r1)=4750 at 2
r3: v(vdiv)/i(r3)=5250 at 2

All nicely captured.

jonk
  • 77,059
  • 6
  • 73
  • 185
  • ...and the advantage of the `.MEAS` script is that it can be written as an external file, called externally through the menu *File > Execute .MEAS Script* (with the waveform viewer active), and all this without the need to re-run the simulation. – a concerned citizen Sep 09 '21 at 15:23
4

Create a behavioral voltage source for each device (R), then just paste in labels and schematic function values. Run a DC .op (operating point) to get one value per trial run. Plot each voltage (R). You can paste these values out to a text file to get a table of R values vs. trial run.

You could also program a script in a language like matlab, to generate the values, using the same programming steps as LTspice (I confirmed it works fine).

enter image description here

enter image description here

pat
  • 2,075
  • 12
  • 11