18

I need to do three transient simulations with different values of certain resistors (conveniently called R1 and R2) in each. What I mean to do exactly is this:

  • Sim. 1: R1 = 1 k\$\Omega\$, R2 = 10 k\$\Omega\$
  • Sim. 2: R1 = 1 M\$\Omega\$, R2 = 10 M\$\Omega\$
  • Sim. 3: R1 = 1 k\$\Omega\$, R2 = 1 M\$\Omega\$

If there were just one resistor whose resistance to vary, then I would just set its resistance to "{r1}" (I use lower case letters to make it a different variable/parameter than R1) and use a command such as:

.step param r1 list 1k 1meg 1k

However, since I have to change two parameters (together) two times each, I have read here that (at least on LTSpiceIV) that a workaround to my problem could be using something like this:

.step param X list 1 2 3

.param r1 = table(X, 1k, 1meg, 1k)

.param r2 = table(X, 10k, 1meg, 10meg)

Upon doing the simulation, I get the following warnings:

WARNING: Can´t resolve .param r2 = table(X, 10k, 1meg, 10meg)
Select OK to continue the simulation with the default model or Cancel to quit now.

The same applies for r1.

For some reason, the simulation doesn´t "break" if I add one extra element to the table. In that case, the simulation takes too long, advancing more slowly every time, as it would never end. I have tried setting X to 0 1 2 instead of 1 2 3, but that does not work either.

Here are some pictures:

Circuit + commands

Error message

Your help would be much appreciated.

sebascarra
  • 181
  • 1
  • 1
  • 5
  • I'm confused, do you want to simulate 3 situations or more? If you just want to simulate the 3 scenarios I wouldn't bother doing it with spice. – ACD Aug 26 '14 at 20:32
  • And what do you want the X axis to be? – ACD Aug 26 '14 at 21:02
  • I would like to simulate those three situations and plot them together. I know I could just export a CSV file and plot them with Octave or Excel, but it would be so much more useful to do it directly on LTSpice. In this post (http://electronics.stackexchange.com/questions/20811/ltspice-automation) someone said how to do it but it doesn't work for me. In this example I put three scenarios but I might need to put more. – sebascarra Aug 28 '14 at 13:28
  • As regards your second question, X would be the different indexes that let me access the table's values. Since (apparently) LT will only allow me to sweep through one variable at a time, I sweep through X and then I try to access the table's values according to the value that X has taken in that step. I hope I'm being clear. Thank you. – sebascarra Aug 28 '14 at 13:31
  • Well for one the table command wants an index, which is X, then a set of xy pairs. Each param should have 3 pairs in it, not three values. – ACD Aug 28 '14 at 13:53
  • I don't really understand very well. Why would the table command need x, then x and y as inputs? Could you please write a short example on how to use the param and table functions together? Thank you. – sebascarra Sep 01 '14 at 13:46
  • Please add .asc file to make life easier. I would like to try. – AKR Sep 12 '14 at 07:10

4 Answers4

27

In LTSpice the table command really creates a kind of dictionary where you have to specify key value pairs. The proper directive for your case would then be:

.step param Rx list 1 2 3
.param R1 table(Rx,1,1k,2,1Meg,3,1k)
.param R2 table(Rx,1,10k,2,1Meg,3,10Meg)

and set the value of the resistors to {R1} and {R2} respectively.

If you want to have the values of a resistor near to it, you can also enter (instead of value, when right clicking onto it)

R=table(Rx,1,10k,2,1Meg,3,10Meg)

into the resistor value field. This works the same way for all kinds of components and with an external script to create .asc files it can be used as a crutch for LTspices missing monte carlo functonality.

PlasmaHH
  • 6,498
  • 5
  • 38
  • 49
3

One parameter sweep/step can control multiple component values through expressions.

Your control variable you are stepping could be a phase angle or time delay or similar that you input in one or more formulas/expressions to obtain resulting component values or parameters to be applied in the design as {parameter}

This is useful if you want to maintain a relation or control some indirect physical property of the design like a current or filter property.

In the "op" command editor you can enter something like this:

.STEP param Imax 0.1 0.3 0.1 
.PARAM Uin= 5
.PARAM R = (Uin-0.84954605)/Imax

It steps Imax from 0.1 to 0.3 in steps of 0.1 and computes a resistor value R using parameter Imax, Uin, some assumed voltage drop 0.85.. of a diode.

The PARAM R can be referenced in a component value usng {R} notation. Notice Uin could be used as {Uin} in a voltage source or similar and so on.

For multiple lines in the "op" editor window use CTRL+M to keep all params in same textbox.

tofo
  • 139
  • 1
2

This is working for my circuit

.step param n list 2 3 4

.param Rf=table(n,1,1.3k,2,1.1k,3,1.2k,4,1k)

.param Cf=table(n,1,54p,1,64p,2,64pF,4,64pF)

So Rf gets the value of the current index ( defined in the .step directive) So the table of the values start with the index identifier (here n) then follows the pairs index, value . If I don't use the index in the tables I get the same error as indicated in the first post

The working solution was found after reading LTspice table function

W Beaumont
  • 21
  • 1
-3

After much thrashing around, I found there are two aspects to this problem that need to be explored. Firstly, The parameter you wish to vary needs to be designated.

If you've got a resistor R5 on your LTSpice schematic, for example, then Control-Right click over the component to pull up the Component Attributes dialogue box. You've likely already given it a value, eg 1k0. You need to replace this with your parameter designator; put that inside {} brackets, e.g. {R5} then Save.

To be clear I've used {R5} for my convenience and understanding. It could be {Pickle1} and it would still work.

Now LT spice knows what you're talking about when you start writing your scripts.

Now you can start using the Spice Directive dialogue box (.op Icon top right) and enter your script. E.G:

.step param Rx 1 5000 100
.param R5=Rx
.param R6=Rx
.op

In this example, I want to modify two resistors (R5 and R6) so I can see the output of my regulators, assuming that I change the values from 1 ohm to 5000 ohms over 100 steps. I've called the parameter Rx: The 1st line defines the steps I want to take as detailed above.

.step param Rx 1 5000 100

Now I want to take that parameter and apply it to my components. I've done the trick with the Component Attributes dialogue on both components already. Remember that R5 relates to the parameter designator. If I'd used {Pickle} then the line would read:

.param Pickle=Rx

The next two lines in the script above tell LTSpice that the parameters for R5 and R6 should follow the steps designated as Rx.

.param R5=Rx
.param R6=Rx

Lastly the .op command drives the operation.

End result is that my circuit, which other than those two values is in a fixed state, is now complete and, in the example I was trying to get to, I can see the effect on the regulated output.

The list examples detailed above is a different way of achieving the end result required, but it looks like some of the comments are because, as was the case with me, it was not understood that you can't use the component designators without doing the {} thing. LTSpice doesn't know what your talking about until you do that bit.

Hope that explanation helps someone else so they're not spending three hours trying to figure out why the code lifted from the examples here may not be working.

  • 2
    This is not what OP is asking about. Your answer is a simple tutorial on a basic LTspice concept. – pipe Oct 06 '20 at 16:41