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.

Compiler/TMS320F28379D: Discret PID with interrupt_void

Part Number: TMS320F28379D
Other Parts Discussed in Thread: C2000WARE

Tool/software: TI C/C++ Compiler

Dear all, good day

Here is my code for the discrert PID 

//////////////////////////////////////////////////////////////////////////////////////

v_fonte = AdcaResultRegs.ADCRESULT0; 

v_pk = kp*v_fonte;

v_ik = v_ik1 + ki*v_dt*v_fonte;


v_dk = (kd/v_dt)*(v_fonte - v_fonte_1);

v_pid = v_pk + v_ik + v_dk;

DAC_PTR[DAC_NUM]->DACVALS.all = v_pid ;

v_fonte_1 = v_fonte;
v_ik1 = v_ik;

/////////////////////////////////////////////////

As you can see, in order to compute V_IK ad V_DK, I will need V_FONTE_1 & V_IK1  which are the previous values of V_FONTE & V_IK. I attempted to place V_FONTE_1 = V_FONTE as below the DAC_PTR line. 

However, V_FONTE_1 and V_IK1 keep the same values as the actual V_FONTE and V_IK values, making V_DK equal to 0. 

I would like to know which is the proper writing for kind of operation. 

BR,

Christian

  • Hello Christian,

    Your code implements a basic parallel PID and is logically correct. From the code I do not see what the variable types are or how you are handling numerical range. This could be one reason why there is apparently no difference between v_fonte and v_fonte_1 in consecutive sample periods.

    I also noticed you are not handling integrator windup. This could easily cause the control loop to saturate, again resulting in v_fonte and v_fonte_1 being the same.

    I recommend you download the C2000Ware and look for the Digital Control Library (DCL) in the "C:\ti\c2000\C2000Ware_2_00_00_02\libraries\control\DCL" directory. There you will find many PID examples and you can see the source and documentation to see how it is done.

    I hope this helps.

    Regards,

    Richard