5

How does the table function work in LTspice? In the LTspice library, it says, table(x,a,b,c,d,...): Interpolate a value for x based on a look-up table given as a set of pairs of points.

I don't really understand what it means. Could somebody help me understand what it does?

Example:

.step param n 0 5 1

.param cc=0.01 ; delta
.param a1=table(n,0,0,1,1,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0)
.param R1=2k*(1+cc*a1)
.meas Vout0 FIND V(out) when n=0

How do the above statements work?

pfabri
  • 758
  • 7
  • 18
user207787
  • 425
  • 1
  • 3
  • 12

1 Answers1

5

.step param n 0 5 1

Simulates the circuit for different values of n, starting at 0, stopping at 5, with steps 1. So, n is one of [0,1,2,3,4,5]

.param cc=0.01 ; delta

assign a value cc = 0.01, not sure what the delta is, probably just a comment, not a LTspice command.

.param a1=table(n,0,0,1,1,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0)

a1 gets a value based on the value of n, the table has the following structure, table(index, pairs of key,value ). in your case n is the index, and the bold ones are the keys, followed by non bold values. table(n,0,0,1,1,2,0,3,0,4,0,5,0,6,0,7,0,8,0,9,0,10,0) Notice that, n is in [0,1,2,3,4,5], so many of those keys will never be reached/used

.param R1=2k*(1+cc*a1)

Assign the value of R1 = 2k*(1+cc*a1), equal to, R1 = 2k*(1+0.01*a1), that for n=0 will be, R1 = 2k*(1+0.01*0). For n=2, R1 = 2k*(1+0.01*0), and so on.

.meas Vout0 FIND V(out) when n=0 ; this will not work, see below

As pointed by pfabri in the comments, this measure operation will not work. It is unclear to me why that happens, but it seems that the expression used as a condition for when can only be in terms of literals, currents and voltages, e.g., V(n001)=4+I(n002). Also, if the condition is never met you will also get that the measurement failed.

pfabri
  • 758
  • 7
  • 18
jDAQ
  • 2,517
  • 1
  • 9
  • 19
  • Can I ask what the keys are? – user207787 Sep 29 '19 at 20:55
  • for that table you have, \$ f(\text{key}) = \text{value}\$. An in that code, the index ( "the current key" ) is given by n, so \$ f(n) = \text{value}\$ – jDAQ Sep 29 '19 at 20:59
  • So, that means if n == 0, a1 = 0, if n == 1, a1 = 1, if n == 2, a1 = ,etc? – user207787 Sep 29 '19 at 21:03
  • Yes, when n == 0, a1 = 0. But there is a catch when the value is not present in the table, lets say, table((n == 0, a1 = 0),(n == 1, a1 = 1)) but you want n==0.6. That is where the interpolation comes into hand, it makes a linear interpolation between (n == 0, a1 = 0) and (n == 1, a1 = 1), that is just a line. And uses that to figure out the supposed value. – jDAQ Sep 29 '19 at 21:08
  • Ohh, the definition given in the library makes sense now. Thank you so much. – user207787 Sep 29 '19 at 21:10
  • I get a *Measurement "vout0" FAIL'ed* for a simple voltage divider, where the output is labeled `out`. My measurement expression is: `.meas TRAN Vout0 FIND V(out) WHEN n =1 RISE=last` and my stepped parameter is: `.step param n list 1 2`. Probing the `out` node comes up as `V(out)` in the graph as expected. If I just use `.meas TRAN Vout0 FIND V(out) AT 1u` I get the correct readings listed for both steps of `n`. What am I missing? – pfabri Mar 17 '23 at 14:59
  • From testing a few expressions it seem that the `WHEN` condition can only be in terms of currents and voltages, `I( )` and `V( )`, and won't allow for parameters, such as `n`. If you do just `.meas TRAN Vout0 FIND V(out) AT 1u ` you will get the measurements for each step of `n`, and then you can just read the one associated with `n = 1`, that might be easier than doing something to measure only at `n = 1`. I will add to the answer that, although reasonable, that last line won't work. But since this question is about the table function the rest should be ok. – jDAQ Mar 17 '23 at 18:26
  • @jDAQ Okay, that makes sense. I just wasn't sure if I was overlooking something. – pfabri Mar 24 '23 at 11:13