//西门子PLC
//说明:同向作用时的PID控制块
FUNCTION_BLOCK FB100
KNOW_HOW_PROTECT
VAR_INPUT
MEAS:REAL; //当前测量值
UP:REAL; //比例系数
UI:REAL; //积分系数
UD:REAL; //微分系数
DEST:REAL; //目标值
MAXOUT:REAL;//输出最大值
MINOUT:REAL;//输出最小值
END_VAR
VAR_OUTPUT
AOout:WORD; //输出AO地址
END_VAR
VAR_IN_OUT
LASTMEAS:REAL; //上次测量值
LLASTMEAS:REAL;//上上次测量值
LASTOUT:REAL; //上次输出值
END_VAR
LASTOUT:= LASTOUT -(MEAS-LASTMEAS)*UP - (MEAS-DEST)*UI - (MEAS+LLASTMEAS-2*LASTMEAS)*UD; //PID计算
IF LASTOUT>MAXOUT THEN LASTOUT:=MAXOUT; END_IF; //检查上限
IF LASTOUT<MINOUT THEN LASTOUT:=MINOUT; END_IF; //检查下限
AOout:=INT_TO_WORD(REAL_TO_INT(LASTOUT/MAXOUT*27648.0)); //输出转换
LLASTMEAS:=LASTMEAS; LASTMEAS:=MEAS; //更新数据
END_FUNCTION_BLOCK