Int16 PIControl (Int16 targetCur, Int16 Current)
{
Int16 Result = 0; //PI运算结果
Int32 curErr = 0; //测量值和实际值的差
Int32 portion_asP = 0; //本次比例部分的值
float portion_asI = 0; //本次积分部分的值
Int32 max;
curErr = (Int32)targetCur - (Int32)Current;
portion_asP = ((float)curErr) * FL_EPC_PV_DX;
portion_asI = ((float)curErr) * FL_EPC_IV_DX;
max = MAX;
portion_asI += portion_asI_lastZL;
portion_asI_lastZL = portion_asI; //保存这次的积分值
if(portion_asI_lastZL < (-max))
portion_asI_lastZL = -max;
if(portion_asI_lastZL > max)
portion_asI_lastZL = max;
result = portion_asI + portion_asP;
if(result < (-max))
result = -max;
if(result > max)
result = max;
return result;
}