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.

Sine Table in uscib0_i2c_03 example

Hi,

I want to know how this table was made, and if there is information about  it:

const unsigned char Sine_Tab[] =            // 16 Point 16-bit Sine Table

{

  0xFF,                                     // MSB Word 0

  0xFF,                                     // LSB

  0xF6,                                     // MSB Word 1

  0x40,                                     // LSB

  0xDA,                                     // MSB Word 2

  0x81,                                     // LSB

  0xB0,                                     // MSB Word 3

  0xFA,                                     // LSB

  0x7F,                                     // MSB Word 4

  0xFF,                                     // LSB

  0x4F,                                     // MSB Word 5

  0x03,                                     // LSB

  0x25,                                     // MSB Word 6

  0x7C,                                     // LSB

  0x09,                                     // MSB Word 7

  0xBD,                                     // LSB

  0x00,                                     // MSB Word 8

  0x00,                                     // LSB

  0x09,                                     // MSB Word 9

  0xBD,                                     // LSB

  0x25,                                     // MSB Word 10

  0x7C,                                     // LSB

  0x4F,                                     // MSB Word 11

  0x03,                                     // LSB

  0x7F,                                     // MSB Word 12

  0xFE,                                     // LSB

  0xB0,                                     // MSB Word 13

  0xFA,                                     // LSB

  0xDA,                                     // MSB Word 14

  0x81,                                     // LSB

  0xF6,                                     // MSB Word 15

  0x40                                      // LSB

};

 

Thanks

Gastón

  • It looks like some approximation of:

    32767*COS(22.5*i)+32768;

    where i is from 0 to 15

  • thanks for reply , what are the step to make my own sine table?.

    Gastón

  • There are many ways to generate a sine table. For example: Write a program in c, Pascal, Basic, Fortran, or whatever and use a Wintel PC, Mac, Linux, or whatever.

    I used a Calculator with sine function and dec-to-hex capability. I could use paper and pencil to do it by hand, use a slid-rule, or looked it up in my old high school text book (1950 vintage).

    May be it is on YouTube or Twitter too. (I do not know what they are.)

     

  • Hi,

    As OCY mentioned the table given in the example is based on the formula: 32767 * COS(22.5 * i) + 32768, with "i" going from 0 to 15. Please note that the table is a 16 point table. This means 0-360 degrees are represented as 16 points only. This is how the 22.5 is coming in to the picture, since 360 / 16 = 22.5. Therefore you must first decide how many points table do you want. For example, if you want a 60 point table then the formula will change to: 32767 + COS (6 * i) + 32768. Here "i" will run from 0 - 59. So just write a simple C code to calculate this for you, with the loop running from 0 to 59.

    The result has been multiplied by 32767 to convert the floating number less than 1 (from COS calculation) to a number much larger than 1. Finally we have added 32768 to make the result always positive since the lowest value of COS is -1 which means the result will be -32767 + 32768 = 1.

    Regards,

    Praval

  • thanks  for the tip

     

    Gastón

  • I am very new to TMS.  I am using TMS2808 experimental kit. I want to generate C code for space vector modulation. Most of the application notes are based on assembly language. Initially I am trying to use the available look up table values for the sine wave generation which is in asm. But I wonder how can I call this to my main program tat is in C compiler?

**Attention** This is a public forum