Tips on runtime optimization
In large applications with a large amount of axes is may be necessary to call function block instances in time optimized way. I.e. the function block instances only will be executed when theyre needed.
The following Code in StructuredText will show the technique to reduce runtime of a plc application. As an example the function block MC_MoveVelocity is used.
With the variable MC_MoveVelocity_Active the execution of the function block is being controlled. It may be set to the following values:
Value | Meaning |
---|---|
0 | Function block is not executed. |
1 | Function block is executed, input Execute/Enable is TRUE. |
2 | Function block is executed until output acknowledges are set (here: Done, CommandAborted etc.). Execute/Enable is FALSE. |
In the beginning MC_MoveVelocity_Active is set to 1 depending on the input Execute/Enable. With this setting the function block MC_MoveVelocity is executed. This state is kept until the input Execute/Enable is reset to FALSE.
IF(Execute_MoveVelocity = TRUE ) AND ( MC_MoveVelocity_Active = 0 ) THEN
MC_MoveVelocity_Active:= 1;
END_IF
The value of MC_MoveVelocityActive changes to 2 if the input Execute/Enable is set to FALSE. Now, the function block is still executed until one of the output acknowledges (here: Done, CommandAborted, etc.) is set to TRUE. Error cases, which are not considered here, must be handled similar.
IF MC_MoveVelocity_Active > 0 THEN
MC_MoveVelocity(
Axis := AxisReference,
Execute := Execute_MoveVelocity,
Velocity := Velocity_MoveVelocity,
Acceleration := Acceleration_MoveVelocity,
Deceleration := Deceleration_MoveVelocity,
Jerk := Jerk_MoveVelocity,
Direction := Direction_MoveVelocity );
AxisReference := MC_MoveVelocity_0.Axis;
InVelocity_MoveVelocity := MC_MoveVelocity_0.InVelocity;
CommandAborted_MoveVelocity := MC_MoveVelocity_0.CommandAborted;
Error_MoveVelocity := MC_MoveVelocity_0.Error;
ErrorID_MoveVelocity := MC_MoveVelocity_0.ErrorID;
IF MC_Mov eVelocity_Active = 2 AND ( InVelocity_MoveVelocity = TRUE OR CommandAborted_MoveVelocity = TRUE) THEN
MC_MoveVelocity_Active :=0;
ELSIF Execute_MoveVelocity = FALSE THEN
MC_MoveVelocity_Active := 2;
END_IF
END_IF