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.

IQ-Math variable too slow

Other Parts Discussed in Thread: TMS320F28069

Hello,

i´m programming with an TMS320F28069 mikrocontroller for my masterthesis. The program is for controlling a threephase voltage source converter. The sample time of the discrete control technique is 31.25µs.  I read in the multiday-workshop and the IQ-Math-Guide that using variable from _iq-type is faster than run the program with double or float-variables, so I used the _iq-type.
 Now I have a problem, that my interrupt-service-routine with the AD-sampling and control-functions needs about 192µs, which is too much time refered to the control-loop-/sample-time of 31.25µs. I tested the cycle-time by setting and clearing an IO-pin. I compared the cycle-time of a part of program when reading the ADCresult-regs for 13 channels. With IQ-variables the part of program needs ca. 58µs and with double-variables it needs ca.5.8µs. Here are the two tested parts:

// note: the variables are arrays

    *i_fu_u = _IQmpy(iq_readAdc(0),_IQ(-0.019536)) + _IQ(40);         // convert Analog A0
    *i_fu_v = _IQmpy(iq_readAdc(1),_IQ(-0.019536)) + _IQ(40);         // convert Analog A1
    *i_fu_w = _IQmpy(iq_readAdc(2),_IQ(-0.019536)) + _IQ(40);         // convert Analog A2

    *i_vm_u = _IQmpy(iq_readAdc(3),_IQ(-0.019536)) + _IQ(40);         // convert Analog A3
    *i_vm_v = _IQmpy(iq_readAdc(4),_IQ(-0.019536)) + _IQ(40);         // convert Analog A4
    *i_vm_w = _IQmpy(iq_readAdc(5),_IQ(-0.019536)) + _IQ(40);         // convert Analog A5

    *u_vm_dc = _IQmpy(iq_readAdc(6),_IQ(200));     // convert Analog A6
    *temperatur = _IQmpy(iq_readAdc(7),_IQ(0.08058608));     // convert Analog A7    // u(t)=10mV/C° *T +0°    // T = 3,3V/4095*100*(C°/V)=0.08058608

    *u_fu_pwm_u = _IQmpy(iq_readAdc(8) ,_IQ(-0.27876)) + _IQ(519);     // convert Analog B0        u_adc_b0 = -1/346*u +1,5V;    u = Result*(-0,27876)+519
    *u_fu_pwm_v = _IQmpy(iq_readAdc(9) ,_IQ(-0.27876)) + _IQ(519);     // convert Analog B1        u_adc_b1 = -1/346*u +1,5V
    *u_fu_pwm_w = _IQmpy(iq_readAdc(10),_IQ(-0.27876)) + _IQ(519);    // convert Analog B2        u_adc_b2 = -1/346*u +1,5V

    *poti_buffer_1 = (iq_readAdc(11));             // convert Analog B3
    *poti_buffer_2 = (iq_readAdc(12));             // convert Analog B4

// other programming technique with double-variables:

   test_variable = ((double)(AdcResult.ADCRESULT0)-2046.0)*2.0;
   test_variable = ((double)(AdcResult.ADCRESULT1)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT2)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT3)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT4)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT5)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT6)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT7)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT8)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT9)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT10)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT11)-2046.0)*2.0;
    test_variable = ((double)(AdcResult.ADCRESULT12)-2046.0)*2.0;

I expected programming with the IQ-Math-lib would increase the speed instead of decreasing it.

The µC runs from Flash with 3 waitstates at 90MHz. Currently I´m reading how to boot from flash but runthe program in RAM.

I hope anybody can help me,

yours sincerely,


B.Eng. Andreas Bauer

  • Hi Andreas,

    the 28069 has a hardware floating point unit, so float computations are going to be much faster than IQ math. IQ math is faster than float on devices that dont have a HW FPU, where the floating point computation is emulated in software and is cycle intensive.

  • Thank you for your answer. I adjust my code. However I´m just wondering that IQ-math takes up to tentimes more time to work. To learn to program with this controller, I started with the corresponding multi-day-workshop for the F28069 Experimenter Kit. In this file it is recommended to use IQ, because the accuracy is increased and it should faster because multiplying IQs with 2 or dividing it by 2 is just a bishift operation.
  • IQ math does have better accuracy than float does, and yes, multiply/divide by 2 is cheap...that much is true, but for everything else, including trig calculations the HW FPU is faster. It really depends on the code you are writing - the tradeof is between accuracy and speed. I dont really know much about power converters so i cant really comment on what is needed in this case. You can probably take a look at our power libraries (DPLib) and get an idea of when and where we use IQMath vs Float.
  • Ok, I have to take a look at the power libraries. Thank you for your help.

    Regards,

    Andreas