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.

Lookup Table

Other Parts Discussed in Thread: TMS320F2808

Board: TMS320F2808

How to generate look-up table for sin wave and then compared with TBPRD (time base period) register. 

  • Asim,

    There are many ways to do it.  Some people use Matlab to generate the table, then save it as a CSV file and copy it into Excel or Notepad and edit it there.  Alternatively you can do the entire thing in Excel.

    Lab 4 in the F28377D 1-day workshop uses a 5 quadrant look-up table generated this way, which I attach.  The workshop files are here:

    http://processors.wiki.ti.com/index.php/F2837xD_Workshop

    Hope this helps.

    Regards,

    Richard

    /* sinetab.c */
    
    // table section declaration
    // #pragma DATA_SECTION(QuadratureTable,"QuadratureTableSection")
    
    // quadrature look-up table: contains 5 quadrants of sinusoid data points
    int QuadratureTable[40] = {
    		0x0000,			// [0]  0
    		0x18F8,	        // [1]  11.25
    		0x30FB,	        // [2]  22.50
    		0x471C,	        // [3]  33.75
    		0x5A81,	        // [4]  45.00
    		0x6A6C,	        // [5]  56.25
    		0x7640,	        // [6]  67.50
    		0x7D89,	        // [7]  78.75
    		0x7FFF,	        // [8]  90.00
    		0x7D89,	        // [9]  78.75
    		0x7640,	        // [10] 67.50
    		0x6A6C,	        // [11] 56.25
    		0x5A81,	        // [12] 45.00
    		0x471C,	        // [13] 33.75
    		0x30FB,	        // [14] 22.50
    		0x18F8,	        // [15] 11.25
    		0x0000,	        // [16] 0
    		0xE708,	        // [17] -11.25
    		0xCF05,	        // [18] -22.50
    		0xB8E4,	        // [19] -33.75
    		0xA57F,        	// [20] -45.00
    		0x9594,	        // [21] -56.25
    		0x89C0,	        // [22] -67.50
    		0x8277,	        // [23] -78.75
    		0x8000,        	// [24] -90.00
    		0x8277,	        // [25] -78.75
    		0x89C0,	        // [26] -67.50
    		0x9594,	        // [27] -56.25
    		0xA57F,	        // [28] -45.00
    		0xB8E4,         // [29] -33.75
    		0xCF05,	        // [30] -22.50
    		0xE708,	        // [31] -11.25
    		0x0000,			// [32] 0
    		0x18F8,	        // [33] 11.25
    		0x30FB,	        // [34] 22.50
    		0x471C,	        // [35] 33.75
    		0x5A81,	        // [36] 45.00
    		0x6A6C,	        // [37] 56.25
    		0x7640,	        // [38] 67.50
    		0x7D89 	        // [39] 78.75
    		};
    
    /* end of file */
    

  • Hii Gaston and Richard,

    Board: TMS320F2808

    Case:-1

    In EPWMxA peripheral, is possible to compare a single time constant value at which

    switching event occur using the register (CMPA).

    {

    int a=1000;

    EPwm1Regs.TBPRD = 1900;

    EPwm1Regs.TBPHS.half.TBPHS = 0;

    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;

    EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;

    EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

    EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;

    EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;

    EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;  

    EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;

    EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;

    EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;

    EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

    EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;

    EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

    EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;

    EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;

    EPwm1Regs.CMPA.half.CMPA = a;

    }

     

    Case:-2

    But in case of multiple time constant value i.e. sine lookup table, at EPWMxA peripheral how

    to compare with the register (CMPA).

    {

    int a[22] = {50,65,78,89,97,100,99,93,84,72,57,43,28,16,7,1,0,3,11,22,35,50}

    EPwm1Regs.TBPRD = 1900;

    EPwm1Regs.TBPHS.half.TBPHS = 0;

    EPwm1Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;

    EPwm1Regs.TBCTL.bit.HSPCLKDIV = TB_DIV1;

    EPwm1Regs.TBCTL.bit.CLKDIV = TB_DIV1;

    EPwm1Regs.TBCTL.bit.PHSEN = TB_DISABLE;

    EPwm1Regs.TBCTL.bit.PRDLD = TB_SHADOW;

    EPwm1Regs.TBCTL.bit.SYNCOSEL = TB_SYNC_DISABLE;

    EPwm1Regs.CMPCTL.bit.SHDWAMODE = CC_SHADOW;

    EPwm1Regs.CMPCTL.bit.SHDWBMODE = CC_SHADOW;

    EPwm1Regs.CMPCTL.bit.LOADAMODE = CC_CTR_ZERO;

    EPwm1Regs.CMPCTL.bit.LOADBMODE = CC_CTR_ZERO;

    EPwm1Regs.AQCTLA.bit.ZRO = AQ_SET;

    EPwm1Regs.AQCTLA.bit.CAU = AQ_CLEAR;

    EPwm1Regs.AQCTLB.bit.ZRO = AQ_SET;

    EPwm1Regs.AQCTLB.bit.CBU = AQ_CLEAR;

    EPwm1Regs.CMPA.half.CMPA = a[22];

    }

  • # Any one please suggest me, how to assigning multiple time constant value in a Counter-Compare Register [CMPA / CMPB] and so it is continuously compared with the Time-Base-Counter Register [TBCTR] value and generate an appropriate event.

    # Assigning Single time value and Multiple time value in Counter-Compare Register [CMPA / CMPB] may be different, because i am getting appropriate event in Single time value but not possible in multiple time value.
    I have mentioned on the above comment for Case 1 i.e. single time value and Case 2 i.e. Multiple time value using sine lookup table.

  • Hi Asim,

    I'm not completely sure I've understood your question.  The compare registers (CMBA & CMPB) are continuously compared with the TB counter and generate whichever event is assigned to them when there is a match.  To use the look-up table, you would typically generate an interrupt once per time-base period (say, on a zero match) and update the appropriate CMPx registers using the next value in the look-up table.  In this way the duty cycle is modulated according to sequential values in the look-up table.

    If iths isn't what you meant, could you clarify what you mean by "single time" and "multiple time" please?  Thanks.

    Regards,

    Richard

  • Hii Richard,

    --------------------------------------------------------------what you mean by "single time" and "multiple time" please? -----------------------------------------------------

    Oct 31 Reply

    Case:-1 Single time value Counter-Compare i.e

    int a=1000;

    EPwm1Regs.CMPA.half.CMPA = a;

     

    Case:-2 Multiple time value Counter-Compare i.e.

    int a[22] = {50,65,78,89,97,100,99,93,84,72,57,43,28,16,7,1,0,3,11,22,35,50};

    EPwm1Regs.CMPA.half.CMPA = a[22];

    ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

    I am facing problem in Case:-2 that when i assigning lookup table i.e. a[22] in CMPA register i.e. EPwm1Regs.CMPA.half.CMPA = a[22]; and "debugging" and "Go Main", the Oscilloscope gives no output event. (Why??)

    But in Case:-1 when i assigning,  int a=1000; EPwm1Regs.CMPA.half.CMPA = a;   and "debugging" and "Go Main", the Oscilloscope gives an appropriate event, i.e. Square wave pulse. 

  • Hi Asim,

    In C, all arrays have 0 as the first index number.  When you assign an array with 22 elements, the last element in the array is a[21], not a[22]. 

    There is no bounds checking in C.  It won't warn you if you try to access something which outside the limits of the array.  You're reading whatever happens to be in memory one word beyond "a".

    Regards,

    Richard

  • Thank you very much, Richard