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.

2P2Z for PID control

PID controller is just a particular case of 2P2Z controller, just A1= -1  and A2 =0. Few examples from Ti  put A1 = 1  to go from PID to 2P2Z  instead of -1 !!!!!!!!!!!!! see  code bellow ( line : CNTL_2P2Z_CoefStruct1.a1 = _IQ26(1.0); // A1 = 1   )

please any idea  why ? 

Thank you

Hamid

/ ADC feedback connections

ADCDRV_1ch_Rlt1 = &Adc_Vout1;

ADCDRV_1ch_Rlt2 = &Adc_Vout2;

//2P2Z connections for the Voltage Loop - Ch1

CNTL_2P2Z_Ref1 = &Vout1SetSlewed; // Slewed Voltage command

CNTL_2P2Z_Out1 = &Duty1A; // Duty command

CNTL_2P2Z_Fdbk1 = &Adc_Vout1; // O/P Voltage feedback

CNTL_2P2Z_Coef1 = &CNTL_2P2Z_CoefStruct1.b2; // point to first coeff.

// Coefficients for the Voltage Loop - PID coefficients & Clamping (Q26)

Dmax1 = _IQ24(0.8);

Pgain1 = _IQ26(0.001953);

Igain1 = _IQ26(0.003);

Dgain1 = _IQ26(0.0);

// Coefficient init - Coeeficient values in Q26

CNTL_2P2Z_CoefStruct1.b2 = Dgain1; // B2

CNTL_2P2Z_CoefStruct1.b1 = (Igain1-Pgain1-Dgain1-Dgain1); // B1

CNTL_2P2Z_CoefStruct1.b0 = (Pgain1 + Igain1 + Dgain1); // B0

CNTL_2P2Z_CoefStruct1.a2 = 0.0; // A2 = 0

CNTL_2P2Z_CoefStruct1.a1 = _IQ26(1.0); // A1 = 1

CNTL_2P2Z_CoefStruct1.max = Dmax1; //Clamp Hi

CNTL_2P2Z_CoefStruct1.min = _IQ24(0.0); //Clamp Min

//2P2Z connections for the Voltage Loop - Ch2

CNTL_2P2Z_Ref2 = &Vout2SetSlewed; // Slewed Voltage command

CNTL_2P2Z_Out2 = &Iref2; // Peak current reference command

CNTL_2P2Z_Fdbk2 = &Adc_Vout2; // O/P Voltage feedback

CNTL_2P2Z_Coef2 = &CNTL_2P2Z_CoefStruct2.b2; // point to first coeff.

// Coefficients for the Voltage Loop - PID coefficients & Clamping (Q26)

Dmax2 = _IQ24(0.8);

Pgain2 = _IQ26(0.001953);

Igain2 = _IQ26(0.003);

Dgain2 = _IQ26(0.0);

// Coefficient init - Coeeficient values in Q26

  • Hamid,

    The reason for the apparent discrepancy is the way the 2P2Z has been implemented in the digital power library.  If you take a look at the 2P2Z description in the library documentation you'll see the author has negated the a1 & a2 coefficients in the transfer function.  These terms end up being added (rather than subtracted) in the assembly code.  Presumably this has been done to make use of the QMPYAL assembly instruction for better efficiency.

    By the way, the coefficients also depend on the transformation method. I think this example used backwards Euler for the derivative term and trapezoidal for the integral term (see attached).  If you use trapezoidal for both you get: a1 = 0, a2 = -1.

    Regards,

    Richard

    Discrete PID controller.pdf

  • Thank you  Richard for your answer but it still not obvious for me.

    in fact :
     the code in the digital library  is implemented for  the  2p2z  control. if I need to use this code for the PID controller  I have to put A1 = -1 and A2 =0    without changing the code in the library!!!!
    I don't  understand   the reason to use A1=1 !!!!
    Best Regards
    Hamid
  • Hamid,

    Look at the 2P2Z difference equation in chapter 5 of the DP library user's guide.  The first two terms on the RHS would normally be subtracted rather than added, but that's not how it's been implemented in the code.  Coefficients A1 & A2 have been negated, so if you want to use this function you must negate your coefficients before using it.

    Regards,

    Richard

  • Thank you Richard

    Hamid