This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

CCS/LAUNCHXL-F28379D: 2D Lookup Table

Part Number: LAUNCHXL-F28379D

Tool/software: Code Composer Studio

Hello,

I need to create a 2D lookup table where I can determine the value of Y depending on the value of X.

For example, suppose I have a lookup table

X         Y

1.5     10

2        12

2.5      13

3        13.5

In Simulink for example, they have a built-in method for 2D lookup and it is very easy to do.  For programming in C, is there any built-in library I can use for this?  Or would I need to create my own method for handling lookup tables?

Thanks,

Kevin

  • Kevin,

    There is no general purpose lookup table and you will need to create one for your project.

  • Santosh,

    Is there any example you would recommend looking at for the best way to implement a 2D lookup table?

    One simple way I can see doing it is using a ton of "if" statements

    if (X > 2)

    {

    Y = ...

    }

    else if (X>1.5)

    {

    Y = ....

    }

    else if (X > 1)

    {

    Y = ...

    }

    Is there a better way to do it than stringing together a bunch of "if" statements?

    Thanks,

    Kevin

  • Kevin,

    Perhaps you can create 2 1D arrays X[N] and Y[N] that map to each other as you mention i.e. X[m] maps to Y[m]? I presume you have some external input or variable, k, that you will map to X, and depending on where it lands, you will pick the corresponding value in Y.

    In other words, something like:

    while(k < X[i]){

    i++;}

    value = Y[i];

    We have dealt with conditional sized loops like this before in a similar context - LUT search loops through sorted arrays. In order to keep cycles down, you should pay close attention to the type of the loop search index i. Typically it should be declared as a signed, so as to allow the compiler to generate the efficient indexed addressing mode instructions. For unsigned, the C standard needs to support overflow, so typically the compiler will not generate those.

    Thanks,

    Sira