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.

CCS/TMS320F28379D: PI controller

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Tool/software: Code Composer Studio

hi,

In my program I need to set a PI controller. the error signal, difference of reference signal and current signal is finely calculated. As I want to multiply this value with proportional term, e.g. #define P_gain  0x0005, I face difficulties. How is the multiplying rule of two 16 bit values and saving it in a 32 bit variable?

Uint32 eRROR_COPM_SIG_P;// proportional error sig.

eRROR_COPM_SIG_P=eRROR_COPM_SIG*P_gain;

//EPwm1Regs.CMPA.bit.CMPA = eRROR_COPM_SIG_P >> 16; shifting 16 bits,is right?
EPwm1Regs.CMPA.bit.CMPA = (int)(eRROR_COPM_SIG_P );  can I use int, to select only 16 upper value?

I am working with a fixed-point mode. (I did not use DCL, Digital Controller Library)

Do I need to choose floating point mode of working?

Can you help me further please? 

thank you in advanced.

  • If you multiply two 16-bit numbers the result will be 32-bits in length. Typecasting to a 16-bit int will take the lower word, so if you do this...

    int a = 3;
    int b = 5;
    int c = 0;
    long int d = 0;

    d = a* b;
    c = (int) d;

    ...d will be 0x0000000F, and c will be 0x000F.

    If you wanted the upper word you would do:
    c = (int) (d >> 16);

    I recommend you use the IQmath library to manage numerical range and resolution. Please take a look at that in C2000Ware. The library allows you to control the range / resolution trade-off inherent in fixed-point arithmetic directly in C. The documentation will answer a lot of your questions.

    If you convert to floating-point you will burn a lot of cycles, so if your controller is time critical you probably don't want to do that. Very likely you will be able to work in fixed-point, and the default IQ24 format in IQmath will meet your needs. There is a series form fixed point PI controller in the DCL which takes Q24 inputs. You don't have to use it, but it's efficient and has been thoroughly tested.

    Regards,

    Richard
  • hi Richard,

    thank you for your reply.

    I checked the DCL folder, they are from older version of TI Microcontroller and I was not able to modify them the way i want.

    I had a question regarding implementing PI controller . as far as i read from Literatur, PI is : u(k)=kp*e(k)+Ki*T* ∑e(i)( summation is from i=0 to k). theoretically it is a series of scalar multiplications and addition instructions.
    Is it right if I use this equation?
    how should I implement the summation of above equation?

    Regards,

    Parisa
  • Parisa,

    There is nothing device specific in the DCL. The relevant controller is the PI_A1 - a series PI controller implemented as a C callable assembly function. It will run on any C28x device and is your fastest, most efficient way to implement PI control.

    PI(D) control is straightforward in principle, but there are subtleties which can make a lot of difference. Your equation will implement a crude parallel form PI controller, but it will not perform well if the loop saturates, for example. Take a look at the C coded PI controllers in the DCL, such as PI_C3. The code is in "DCLF32.h" and you can use it a starting point for your own code by converting it over to use IQmath.

    I hope this helps.

    Regards,

    Richard