5
\$\begingroup\$

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?

\$\endgroup\$

1 Answer 1

6
\$\begingroup\$

.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.

\$\endgroup\$
8
  • \$\begingroup\$ Can I ask what the keys are? \$\endgroup\$
    – user207787
    Commented Sep 29, 2019 at 20:55
  • \$\begingroup\$ 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}\$ \$\endgroup\$
    – jDAQ
    Commented Sep 29, 2019 at 20:59
  • \$\begingroup\$ So, that means if n == 0, a1 = 0, if n == 1, a1 = 1, if n == 2, a1 = ,etc? \$\endgroup\$
    – user207787
    Commented Sep 29, 2019 at 21:03
  • \$\begingroup\$ 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. \$\endgroup\$
    – jDAQ
    Commented Sep 29, 2019 at 21:08
  • \$\begingroup\$ Ohh, the definition given in the library makes sense now. Thank you so much. \$\endgroup\$
    – user207787
    Commented Sep 29, 2019 at 21:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.