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.

CLA code profile question on CCS5.5+XDS100+TMS320F28035

we use ePWM to profiling our CLA code。

the CLA code list as follow:

                 EPwm3Regs.AQCSFRC.bit.CSFA=2; 

                 CNTL_2P2Z_CLA_C(coeffs, vars);

                 EPwm3Regs.AQCSFRC.bit.CSFA=1; 

we can see epwm3 waves from the scope and get how many time does this function make。

the function CNTL_2P2Z_CLA_C is defined as follow:

#define CNTL_2P2Z_CLA_C(v, k)                 \
  /* Calculate error */                 \
  k.Errn = k.Ref - k.Fdbk;                \
  k.OutPresat = (v.Coeff_A2 * k.Out2) + (v.Coeff_A1 * k.Out1) + (v.Coeff_B2 * k.Errn2) \
      + (v.Coeff_B1 * k.Errn1) + (v.Coeff_B0 * k.Errn);      \
                        \
  /* Update error values */                \
  k.Errn2 = k.Errn1;                  \
  k.Errn1 = k.Errn;                  \
                        \
  /* Determine new output */                \
  k.Out = k.OutPresat;                 \
  k.Out = (k.Out < v.Max) ? k.Out : v.Max;            \
  k.Out = (k.Out > v.IMin) ? k.Out : v.IMin;            \
                        \
  /* Store outputs */                  \
  k.Out2 = k.Out1;                  \
  k.Out1 = k.Out;                   \
  /* Saturated output */                 \
  k.Out = ((k.Out > v.Min) ? k.Out : v.Min)

use the function defined,we get test time:470ms

but just remove the last code of the function,the function is as follow:

#define CNTL_2P2Z_CLA_C(v, k)                 \
  /* Calculate error */                 \
  k.Errn = k.Ref - k.Fdbk;                \
  k.OutPresat = (v.Coeff_A2 * k.Out2) + (v.Coeff_A1 * k.Out1) + (v.Coeff_B2 * k.Errn2) \
      + (v.Coeff_B1 * k.Errn1) + (v.Coeff_B0 * k.Errn);      \
                        \
  /* Update error values */                \
  k.Errn2 = k.Errn1;                  \
  k.Errn1 = k.Errn;                  \
                        \
  /* Determine new output */                \
  k.Out = k.OutPresat;                 \
  k.Out = (k.Out < v.Max) ? k.Out : v.Max;            \
  k.Out = (k.Out > v.IMin) ? k.Out : v.IMin;            \
                        \
  /* Store outputs */                  \
  k.Out2 = k.Out1;                  \
  k.Out1 = k.Out;                   \
  /* Saturated output */                 \
  /*k.Out = ((k.Out > v.Min) ? k.Out : v.Min)*/

we get 10us when we use (the remove last code) function。

Q:why just remove last code we get diff result。

  • the CLA code:

    __interrupt void Cla1Task1 ( void )

    {                。。。。。。。。。。。。。。。。。。。。。。。。。

                     EPwm3Regs.AQCSFRC.bit.CSFA=2; 

                     CNTL_2P2Z_CLA_C(coeffs, vars);

                     EPwm3Regs.AQCSFRC.bit.CSFA=1; 

                     。。。。。。。。。。。。。。。。。。。。。。。。。

    }

  • Hi,

    hai sun said:
    Q:why just remove last code we get diff result。

    Are you sure? As this line should consume more cycles than the one commented:

     k.OutPresat = (v.Coeff_A2 * k.Out2) + (v.Coeff_A1 * k.Out1) + (v.Coeff_B2 * k.Errn2) \
          + (v.Coeff_B1 * k.Errn1) + (v.Coeff_B0 * k.Errn); 

    Regards,

    Gautam

  • sure。

    k.OutPresat = (v.Coeff_A2 * k.Out2) + (v.Coeff_A1 * k.Out1) + (v.Coeff_B2 * k.Errn2) \
          + (v.Coeff_B1 * k.Errn1) + (v.Coeff_B0 * k.Errn);

    this line tests more cycles,but just last code take more time。

    you can see  :without last line code,the whole function just take 10us.

  • hai sun said:
    this line tests more cycles,but just last code take more time。

    How is this possible! They are directly proportional...

    Anyways, the k.Out value in the final line... is it been sent to main CPU for further processing? If so passing the value might be consuming cycles.

    Regards,

    Gautam

  • Hi,Gautam Iyer。From the code we give,we just test the function.

    we set EPWM3 high at the begin of the function CNTL_2P2Z_CLA_C and set EPWM3 low at the end of the function.Then,we see the high time of EPWM3 to get the time of this function.

    we just remove the last line( /*k.Out = ((k.Out > v.Min) ? k.Out : v.Min)*/) in the function and get the time of 10us.

    But if we add the last line in the function,we find the function will run with time :470ms

    it is impossible as the last line  (/*k.Out = ((k.Out > v.Min) ? k.Out : v.Min)*/) can cost too many time.

  • hai sun said:
    it is impossible as the last line  (/*k.Out = ((k.Out > v.Min) ? k.Out : v.Min)*/) can cost too many time.

    Theoretically, this should not happen if its just a function/computation and not passing by a parameter!

    Regards,

    Gautam

  • hi Gautam,we find the mistake。

    epwm3 does not run as we think。

    we set EPwm3Regs.TBCTL.bit.PHSEN = 0 before and now we change as:EPwm3Regs.TBCTL.bit.PHSEN = 1.

    Then we get the result :10us。

    thank you for your reply。we still want to know how this register affect the result。

     
  • hai sun said:

    hi Gautam,we find the mistake。

    epwm3 does not run as we think。

    we set EPwm3Regs.TBCTL.bit.PHSEN = 0 before and now we change as:EPwm3Regs.TBCTL.bit.PHSEN = 1.

    Then we get the result :10us。

     

    That's Great!
    hai sun said:
    thank you for your reply。we still want to know how this register affect the result。
    That's really very strange behavior. Here's the significance of PHSEN bit:
    Regards,
    Gautam