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.

PI controller assembly function in C2000Ware, DCL_PI_A1.asm, how to use it?



Hello. I want to use the assembly function DCL_PI_A1.asm from C2000Ware. It is a function for PI control which can be used for fixed point processors like TMS320F28035. I can't find any example projects where this function is used, and I am not sure of how to use it. Could anyone give some guidelines?

The assembly function code and the DCL32.h header file can be seen in the figure below. Before calling the assembly function, do I need to put *p in XAR4, rk in ACC and yk in [stack-2] by myself? Or is that done somewhere else? What other things do I need to do? I have read the DCL User's Guide PDF but it doesn't give very much information on exactly how to use the functions.

  • Hello Niclas,

    The function is designed to be called from C with 32-bit fixed point arguments. You don't need to write or modify any assembly code.

    Like any fixed point controller, you'll have to scale the inputs and variables to match the avaliable numerical range and resolution. In C, this is a lot simpler if you are using the IQmath library, so I will assume below that you are doing that and using (for example) IQ24 format.

    You would first add the controller source file "DCL_PI_A1.asm" to your project, then declare the controller and variables, something like this:

    #include"DCL32.h"
    #include "IQmathLib.h"

    DCL_PI32 pi32 = DCL_PI32_DEFAULTS;
    _iq24 rk, yk, uk;

    Then, initialise the controller coefficients as desired in your code. For example:
    rk = _IQ24(0.5);
    pi32.Kp = _IQ24(1.2345);
    pi32.Ki = _IQ24(0.6789);
    ...

    To use the function in an ISR for example, you would load the feedback variable "yk" in IQ24 format...
    yk = (_iq24) ((long) AdcResult.ADCRESULT0 << 12);

    ...and call the PI "run" function, like this:
    uk = DCL_runPI_A1(&pi32, rk, yk);

    "uk" will have the controller output in IQ24 format. You'll have to apply any offsets and scaling to "uk", depending on what you want to do with it. The inner workings of the PI_A1 function are described on p.59 of the DCL user's guide (v2.1.1).

    I hope this helps. Please post back if anything's unclear or you run into difficulty.

    Regards,

    Richard

  • Is it correct that Backward Euler approximation is used for integration? In that case, should my continous time Ki be multiplied with the sampling frequency to get the discrete time Ki used in code? Ki_discrete = Ki * Ts

  • Niclas,
    Good question. Yes, the integrator is backward Euler, and yes, you do have to take the sample period into account when selecting Ki. The code doesn't do that in the current version of the library.
    Regards,
    Richard