function TPID.PIDLoop(Errin:Real):Real;
begin
IntT:=IntT+(Errin*TControl);
case Mode of
0: if Errin>0 then PwmOut:=0 else PwmOut:=PwmMax;
1: PwmOut:=-KP*Errin-KI*IntT-KD*(Errin-ErrL)/TControl;
2: begin PwmOut:=PwmOut-KP*(Errin-ErrL)/TControl-KI*Errin-KD*(Errin+ErrLL-2*ErrL)/(TControl*TControl); end;
3: begin PwmOut:=PwmOut-FdK*(Errin+PreK*((Errin-ErrL)/TControl)); end;
4: begin PwmOut:=PwmOut-FdK*(Errin+PreK*((Errin-ErrL)/TControl+PreKv*(Errin+ErrLL-2*ErrL)/(TControl*TControl))); end;
else begin PwmOut:=PwmOut+FdK*(Errin+PreK*((Errin-ErrL)/TControl)); end;
end;
if PwmOut>=PwmMax then PwmOut:=PwmMax
else if PwmOut<=0 then PwmOut:=0;
result:=PwmOut;
ErrLL:= ErrL;
ErrL:=Errin;
end;
其中,case Mode of 2: 的PwmOut 就是增量式PID的输出,经过限幅到区间[0,PwmMax]后的值就是PWM的输出值,该值与PwmMax的比值就是当前输出功率P与最大加热功率Pmax的比值。