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.

TMS320F28335: how to have faster loops?

Part Number: TMS320F28335


Hello

I am measuring the time between a series of calculations in my code. It takes almost 0.0003 s to run this piece of code:

StartTimer();

 vol1 = voltage*3/4095;
 cur1 = current*3/4095;

      sum1=W[0]*phi1(f1_1(cur1,vol1),f1_2(cur1,vol1),fmod(t1,1)+dt)+W[1]*phi4(f1_1(cur1,vol1),f1_2(cur1,vol1),fmod(t1,1)+dt)+W[2]*phi5(f1_1(cur1,vol1),f1_2(cur1,vol1),fmod(t1,1)+dt)+W[3]*phi6(f1_1(cur1,vol1),f1_2(cur1,vol1),fmod(t1,1)+dt)+W[4]*phi16(f1_1(cur1,vol1),f1_2(cur1,vol1),fmod(t1,1)+dt)+W[5]*phi32(f1_1(cur1,vol1),f1_2(cur1,vol1),fmod(t1,1)+dt)+W[6]*phi33(f1_1(cur1,vol1),f1_2(cur1,vol1),fmod(t1,1)+dt);

      sum2=W[0]*phi1(f2_1(cur1,vol1),f2_2(cur1,vol1),fmod(t1,1)+dt)+W[1]*phi4(f2_1(cur1,vol1),f2_2(cur1,vol1),fmod(t1,1)+dt)+W[2]*phi5(f2_1(cur1,vol1),f2_2(cur1,vol1),fmod(t1,1)+dt)+W[3]*phi6(f2_1(cur1,vol1),f2_2(cur1,vol1),fmod(t1,1)+dt)+W[4]*phi16(f2_1(cur1,vol1),f2_2(cur1,vol1),fmod(t1,1)+dt)+W[5]*phi32(f2_1(cur1,vol1),f2_2(cur1,vol1),fmod(t1,1)+dt)+W[6]*phi33(f2_1(cur1,vol1),f2_2(cur1,vol1),fmod(t1,1)+dt);

      sum3=W[0]*phi1(f3_1(cur1,vol1),f3_2(cur1,vol1),fmod(t1,1)+dt)+W[1]*phi4(f3_1(cur1,vol1),f3_2(cur1,vol1),fmod(t1,1)+dt)+W[2]*phi5(f3_1(cur1,vol1),f3_2(cur1,vol1),fmod(t1,1)+dt)+W[3]*phi6(f3_1(cur1,vol1),f3_2(cur1,vol1),fmod(t1,1)+dt)+W[4]*phi16(f3_1(cur1,vol1),f3_2(cur1,vol1),fmod(t1,1)+dt)+W[5]*phi32(f3_1(cur1,vol1),f3_2(cur1,vol1),fmod(t1,1)+dt)+W[6]*phi33(f3_1(cur1,vol1),f3_2(cur1,vol1),fmod(t1,1)+dt);



      if ((sum1<=sum2) && (sum1<=sum3)) {
          Gpio_setup1();

      }
      else if ((sum2<=sum1) && (sum2<=sum3)) {
          Gpio_setup2();
      }
      else {
          Gpio_setup3();
      }
      StopTimer();

As seen, I am calling 3*21 functions, doing a multiplication and then choosing a minimum. I know this way, I am not using rich strategies of C programming. So my question is how can I call these function and do these calculations faster? 

Best,

Ata

  • Hello Ata,

    In general there are some things you can do in C code to allow the compiler to better exploit the architecture of the C28x.  For example, your (f1_1, f1_2,...) functions might be in-lined or written as macros to avoid the calling overhead.  The compiler optimizer will help you a lot.  For C28x, you really should invoke the optimizer at least at the -o2 setting to get good performance.

    For further information, please take a look at this Wiki page:

    Regards,

    Richard