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.

Example Code for Proportional-Resonant (PR) Controllers and Filters

Other Parts Discussed in Thread: CONTROLSUITE, SFRA, TMS320F28069, TMS320F2811

Hi,

I want to implement PR control for three phase and single phase grid connected inverter.

So is there any example code or guide line to implement this??

Thanks and regards,

Himanshu

  • You can use the 2p2z structure itself,

    C:\ti\controlSUITE\libs\app_libs\SFRA\v1_10_00_00\Doc

    Look at the documentation above, instead of the PI or 2p2z controller use the analog form of PR and substitute the values using tustin transform.

    And you will get the coefficients for the 2p2z module which is available in solar library

    PS: We will have a very flexible module available for the same in October'15 , however because of policy I cannot share the code through the forum.

  • Hi,

    Thanks for your response, I am started to implementing PR control using 2p2z controller.

    I am using TMS320F28069 with 90Mhz clock. I am using atan() function for theta calculation as mention below.

    float rAlpha;
    float rBeta;
    float betabyalpha;

    if (rAlpha != 0.0)
    {
    betabyalpha = rBeta / rAlpha;
    betabyalpha = atan(betabyalpha);
    }

    Please tell me the execution time (cycle time) for this.

    Regards,
    Himanshu
  • Hi,

    Waiting for your response regarding the cycle time of atan() function for TMS320F28069.

    Regards,

    Himanshu

  • depends where you get the Atan from

    if you use the regular Run Time surpport library it will be more than 200 cycles
    if you use the fastRTS library , that C2000 has it will be ~102 cycles
    if you use the new device , F2837x it will be 5 pipe-lined cycles as we have atan implemented in the processor itself !!

    also PR controller will be in controlSUITE on Oct 15th.. you can use it as a starting basis..
  • Hi,
    thanks for your response.
    But as I am getting around 8uSec time to execute mention if loop with atan() function.
    Regards,
    Himanshu
  • 1. Which device are you using ?

    2. What is you metric of measuring 8usec ?  i.e. GPIO toggle ? 

    3. Have you made sure you are running the CPU at the right speed? 

  • I am using TMS320F28069 with 90Mhz clock.
    And done measurement with GPIO toggle.

    float rAlpha;
    float rBeta;
    float betabyalpha;

    if (rAlpha != 0.0)
    {
    // set GPIO
    betabyalpha = rBeta / rAlpha;
    betabyalpha = atan(betabyalpha);
    // Reset GPIO
    }

    As I mention above it took 12.3 uSec. and for only atan() it took 9.66uSec.
  • Ok if you are using the floating point device, you need to link in the FPU Fast RTS library to make use of the fast atan routine. Instructions to link in the fast RTS routine are found here.

    C:\ti\controlSUITE\libs\math\FPUfastRTS\V100\doc

    Though i still feed you have something fundamentally wrong in your project

    1. Are you running from flash or ram ?
    2. Try running this example and make sure you are confident the PLL is set right etc.. baiscally if you put two NOPs between the GPIO toggle are you getting 2*1/(90Mhz) delay ? It may be +-2 cycles but should be in the same ball park.. C:\ti\controlSUITE\device_support\f2806x\v150\F2806x_examples_ccsv5\gpio_toggle
  • Hi,

    I check the execution time using GPIO toggle as shown below from Flash.

    GpioDataRegs.AIOSET.bit.AIO10_LED = 1;
    asm(" RPT #250 || NOP");
    GpioDataRegs.AIOCLEAR.bit.AIO10_LED = 1;

    Clock is 90MHz.
    Result is 2.832uS. It is nearly to 2.78us as theoretical calculation.

    We are using compiler version c2000_6.2.5.
    In this Runtime support librery is selected as "automatic".
    It is showing this option.
    automatic, None, rts2800_fpu32.lib and rts2800_ml.lib

    Regards,
    Himanshu
  • Himanshu,

    Select "None" and recompile again , you need to do a rebuild project,

    To confirm the routine is linking to the correct RTS library , open the MAP file which is present in the folder with other compiled objects for the project.

    you should see somethings like this, if the RTS library is being linked in.. in the map file

    rts2800_fpu32_fast_supplement.lib : atan2_f32.obj (.text)

    regards
    Manish Bhardwaj
  • Hi,
    Thanks for your guidance.
    If I selected "automatic", it is using “c2800_fpu32.lib”. Now I changed it to "rts2800_fpu32_fast_supplement.lib".
    Now execution become faster.
    The code, that I mention previously, is now taken only 1.432uSec instead of 12.24uSec.
    Is there any special care has to be taken for this new lib??
    Currently I am using CCS6 with 6.2.5 compiler.

    Regards,
    Himanshu
  • Himanshu,

    For most control application this library is good. 

    One more thing you can do to improve the performance further is link in the library into RAM memory, you can do this by the following directive in the cmd file for the ramfuncs..

    ramfuncs : LOAD = FLASHD,
    RUN = RAMLS0LS1LS2LS3LS4,
    LOAD_START(_RamfuncsLoadStart),
    LOAD_SIZE(_RamfuncsLoadSize),
    LOAD_END(_RamfuncsLoadEnd),
    RUN_START(_RamfuncsRunStart),
    RUN_SIZE(_RamfuncsRunSize),
    RUN_END(_RamfuncsRunEnd),
    PAGE = 0, ALIGN(4)
    {
    --library=SFRA_F_Lib.lib<SFRA_F_INJECT.obj>
    --library=SFRA_F_Lib.lib<SFRA_F_COLLECT.obj>
    --library=Solar_Lib_Float.lib
    --library=rts2800_fpu32_fast_supplement.lib<sqrt_f32.obj>
    --library=rts2800_fpu32_fast_supplement.lib<atan2_f32.obj>
    }

  • hi,
    Thanks for your guideline. Execution became faster after taking into RAM.
    Can you explain the "ALIGN(4)"?
    We are also using the TMS320F2811. Is there any fast library for it??

    Regards,
    Himanshu
  • Himanshu,

    F2811 is a fixed point processor, you need to use IQmath lib for best performance on fixed point processor. 

    C:\ti\controlSUITE\libs\math\IQmath

    ALIGN(4), you may not have to worry about this alignment is needed when running some specific assembly instructions that we use in our DSP Lib. You can ignore the directive for most use cases. It basically forces the instructions to be stored starting at 4 word boundary. Refer to the compiler guide for details

    www.ti.com/.../spru514i.pdf

  • Thanks for your response.
    We are already using the IQmath lib for F2811.

    Regards,
    Himanshu