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.

TMS320F28075: Fastest way to devide between 4096.0 within a CLA task

Part Number: TMS320F28075

Hello.

I guess that many applications need to divide between 4096.0, so I am wondering how would be the fastest way to execute a 2^n division by the CLA using FPU.

Thank you in advance.

Regards, 

Paloma

  • Hi Paloma,

    I am checking with the experts. Will get back to you shortly.

    Regards,

    Veena

  • Hi Paloma,

    Is it for integer or float type?

    In case of integer, the faster way would be to use the shift operators ( num >> 12 )

    In case of float, one option is to take out the exponent field, subtract by 12 and put it back

    Regards,

    Veena

  • Hello Veena. Thank you for your response.

    It is a float type. Can you write me an example of:

    to take out the exponent field, subtract by 12 and put it back

    Regards, 

    Paloma

  • Hi,

    In case of float, a better option would be to multiply by 1/4096. If the number 4096 is known at the build time, compiler will automatically compute the inverse and CLA would only be executing the multiply instruction.

    The CLAMath library also provides a CLAdiv function that Implements division using Newton-Raphson Method

    Regards,

    Veena

  • Hello

    I evaluate the time that takes a code execution using a PWM timer like this:

    EPwm12Regs.TBCTL.bit.CTRMODE = TB_FREEZE;

    EPwm12Regs.TBCTR = 0;

    EPwm12Regs.TBCTL.bit.CTRMODE = TB_COUNT_UP;

    /************** code to be evaluated **************/

    clk_cycles = EPwm12Regs.TBCTR; 

    Where clk_cycles holds the number of cycles that takes the execution of    /************** code to be evaluated **************/

    I have evaluated the following codes:

    1.    feedback=(float)(AdcdResultRegs.ADCRESULT0)/4096.0; ->  clk_cycles = 1
    2.    feedback=(float)(AdcdResultRegs.ADCRESULT0)*0.000244140625; ->  clk_cycles = 3           

    ¿Is it normal that the multiplication takes more cycles to be executed? ¿do you know a better way to evalute execution times?

    Thank you.

    Regards,

    Paloma

  • Hi Paloma,

    I would recommend looking at the generated assembly code.

    Have you enabled optimization?

    Regards,

    Veena

  • Hello,

    We use the following optimization: -O2, --opt_for_speed=5, --fp_mode=relaxed.

    We have seen the assembly code that generates “/4096” and “*0.000244140625” operations, and actually it is the same, 1clk cycle. One operation was being executing right after the other and I guess that CLA optimized the first one. So, any of them located in the first place, was executed faster than the second one.

    In this case, what’s make the difference in terms number of ASM intructions, is when local variables are used instead of global ones.

    Thank you for your help.

    Regards,

    Paloma