对于PLC工程师来说,常用的功能块(FB)确实能够显著提升编程效率。功能块是一种预定义的、可重用的代码模块,它封装了特定的控制逻辑或算法。它们不仅提高了编程效率,还使得PLC程序更加可靠、易于理解和维护。因此,对于PLC工程师来说,熟练掌握功能块的使用和编程技巧是非常重要的。
以下是一个气缸控制功能块的ST书写方式
Cylinder_FB(
DoingInExecute:= ,
DoingOutExecute:= ,
DetectingInSensor:= ,
DetectingOutSensor:= ,
ResetButton:= ,
DoingIn=> ,
DoingOut=> ,
DoingInDown=> ,
DoingOutDown=> ,
AlarmOut=> ,
AlarmIn=> );
这个是梯形图书写方式
以下是气缸功能块的程序,可以直接COPY使用
FUNCTION_BLOCK Cylinder_FB
VAR_INPUT
DoingInExecute:BOOL;
DoingOutExecute:BOOL;
DetectingInSensor:BOOL;
DetectingOutSensor:BOOL;
ResetButton:BOOL;
END_VAR
VAR_OUTPUT
DoingIn:BOOL;
DoingOut:BOOL;
DoingInDown:BOOL;
DoingOutDown:BOOL;
AlarmOut:BOOL;
AlarmIn:BOOL;
END_VAR
VAR
DetectingInSensorTon:TON;
DetectingOutSensorTon:TON;
END_VAR
(*************************气缸缩回****************************)
IF(DoingInExecuteAND NOT DoingOutExecute AND NOT DoingOut ) THEN
DoingIn:=TRUE;
DoingOut:=FALSE;
END_IF;
DetectingInSensorTon(IN:=NOT DetectingInSensorANDDoingInANDNOT ResetButton ,PT :=T#6S);
IF DetectingInSensorTon.Q THEN
AlarmIn:=TRUE;
ELSE
DoingIn:=FALSE;
AlarmIn:=FALSE;
END_IF;
IF DoingIn AND DetectingInSensor THEN
DoingInDown:=TRUE;
ELSE
DoingInDown:=FALSE;
END_IF;
(*************************气缸伸出***************************)
IF(DoingOutExecuteAND NOT DoingInExecute AND NOT DoingIn ) THEN
DoingIn:=FALSE;
DoingOut:=TRUE;
END_IF;
DetectingOutSensorTon(IN:=NOT DetectingOutSensorAND DoingOutAND NOT ResetButton ,PT :=T#6S);
IF DetectingOutSensorTon.Q THEN
AlarmOut:=TRUE;
ELSE
DoingOut:=FALSE;
AlarmOut:=FALSE;
END_IF;
IF DoingOut AND DetectingOutSensor THEN
DoingOutDown:=TRUE;
ELSE
DoingOutDown:=FALSE;
END_IF;