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.

TMU sin function

Hi all 

I am using the TMX320F28075 device.

It seems to me that calculations are taking much more time than expected.

I tried to calculate sine function. As the device is having internal TMU sin function must be faster. Here is the compiler flag summary.

-v28 -ml -mt --cla_support=cla1 --float_support=fpu32 --tmu_support=tmu0 --fp_mode=relaxed --include_path="C:/ti/ccsv6/tools/compiler/ti-cgt-c2000_16.9.0.LTS/include" --include_path="D:/projects/background study software/sin pwm/hw_files" --advice:performance=all -g --diag_warning=225 --diag_wrap=off --display_error_number

I have implemented TMU support.

I also suspect that the system clock may be slower  but I am not able to measure it I have posted a separate thread for that. (https://e2e.ti.com/support/microcontrollers/c2000/f/171/t/561091).

But not just suspecting system clock (because I have PWM module working correctly), what should be the reason for sine calculations to take that much of time.

 

The code I am evaluating is

       GpioDataRegs.GPASET.bit.GPIO31 =1 ;//to profile code timing

       sin_r = sin(0);

       sin_y = sin(0);

       sin_b = sin(0);

       GpioDataRegs.GPACLEAR.bit.GPIO31 =1 ; //to profile code timing

 

This takes around 4.9uS.

Disassembly of this code             

693         GpioDataRegs.GPASET.bit.GPIO31 =1 ;//to profile code timing

08216b:   761F01FC    MOVW         DP, #0x1fc

08216d:   1A038000    OR           @0x3, #0x8000

 733        sin_r = sin(0);

08216f:   E590        ZERO         R0

082170:   764830F4    LCR          __relaxed_sin

082172:   761F0242    MOVW         DP, #0x242

082174:   E203001E    MOV32        @0x1e, R0H

 734        sin_y = sin(0);

082176:   E590        ZERO         R0

082177:   764830F4    LCR          __relaxed_sin

082179:   761F0242    MOVW         DP, #0x242

08217b:   E203001C    MOV32        @0x1c, R0H

 735        sin_b = sin(0);

08217d:   E590        ZERO         R0

08217e:   764830F4    LCR          __relaxed_sin

082180:   761F0242    MOVW         DP, #0x242

082182:   E2030020    MOV32        @0x20, R0H

 745        GpioDataRegs.GPACLEAR.bit.GPIO31 =1 ; //to profile code timing

 

Can you please help me with this?

  • Hi Keyur Acharya,

    Actually I have something to share with you. I don't know that you know it before or not.

    Have you ever compare the sine function in CCS with the sine by your definition?

    I think if you define by yourself it takes shorter duration of time.

    Usually, I do like this:

    // in header file (*.h)

    //---------------------------------------------------

    /* Inverse Factorial */
    #define  F2    (1./2.)
    #define  F3    (F2/3.)
    #define  F4    (F3/4.)
    #define  F5    (F4/5.)
    #define  F6    (F5/6.)
    #define  F7    (F6/7.)
    #define  F8    (F7/8.)
    #define  F9    (F8/9.)
    #define  F10    (F9/10.)
    #define  F11    (F10/11.)
    #define  F12    (F11/12.)
    #define  F13    (F12/13.)
    #define  F14    (F13/14.)
    #define  F15    (F14/15.)

    /* sin cos */
    #define  SIN(x,x2)  ((x)*(1.-(x2)*(F3-(x2)*(F5-(x2)*(F7-(x2)*(F9-(x2)*(F11-(x2)*(F13-(x2)*F15))))))))
    #define  COS(x2)  (1.-(x2)*(F2-(x2)*(F4-(x2)*(F6-(x2)*(F8-(x2)*(F10-(x2)*(F12-(x2)*F14)))))))

    //---------------------------------------------------

    After that you can use this function by yourself in main program like this: (*.c)

    //---------------------------------------------------

    Theta_sc = Theta*Theta;
    sin_Theta = SIN(Theta,Theta_sc);
    cos_Theta = COS(Theta_sc);

    //---------------------------------------------------

    You can check and compare the result.

    Besides that you should set up clk of PWM and system correctly.

    Regards

    Duc-Dung Le