Convert a function block to a user-defined function to save program steps
The main purpose of these functions is to simplify the replacement of function blocks (FBs) by functions (FUNs). Multiple FB instances in separate subroutines are replaced by one function in one subroutine.
Function block |
Converted function |
Not all Panasonic instructions can be used in one common function. Examples of instruction that cannot be used in one common function:
Some high speed counter instructions like F166_HighSpeedCounter_Set, F165_HighSpeedCounter_Cam
Some positioning instructions like F166_PulseOutput_Set, F171_PulseOutput_Trapezoidal
This must be checked in detail.
Can require much less program code
Can require much less relays (R)
Can be used in loops using arrays of the memory DUTs
It requires additional development and maintenance work
The converted function must be tested very carefully
It requires more effort from the user
Monitoring is more difficult because you have no instance which can be monitored, only the last call is monitored
It can require more data registers (DT)
The PLC performance is decreased, scan time is increased
The behavior of the timer functions may be slightly different compared to the timer FBs
Test very carefully whether the behavior of the new function corresponds to the behavior of the FB, especially when the new function is called several times.
Functions instead of function blocks should only be used if really needed
Functions instead of function blocks should only be used as much as really necessary
Analyze very carefully which function block should be converted to obtain the maximum benefit with minimum work
The main criteria for deciding whether a function block should be converted are: How often is the function block called, how many steps does the function block require?
This is the formula for calculating how many program code steps can be saved.
The current situation is as follows:
A given function block
Is called X times
Uses Y steps => total number of steps: X * Y steps
Uses TON, SR, pulsed flags
The given FB can be replaced by a function which requires the following:
Additional steps for X calls to copy the memory DUT data twice, i.e. X * 2 * 7 steps approximately (e.g. for two FP10_BKMV)
Y * 2 steps for one common function call (some additional steps are assumed)
One common call of:
TON_FUN using xxx steps
SR_FUN using xxx steps
R_TRIG_FUN using xxx steps
This calculation example gives only approximate figures.
A given function block
Is called 30 times
Uses 750 steps => total number of steps: 30 * 750 steps = 22500 steps
Uses TON, SR, pulsed flags
The given FB can be replaced by a function which requires the following:
Additional steps for 30 calls to copy the memory DUT data twice, i.e. 30 * 2 * 7 steps = 420 steps (e.g. for two FP10_BKMV)
750 * 2 steps for one common function call = 1500 steps (some additional steps are assumed)
One common call of:
TON_FUN using 200 steps
SR_FUN using 35 steps
R_TRIG_FUN using 35 steps
Total number of steps: 420 steps + 1500 steps + 200 steps + 35 steps + 35 steps = 2190 steps
Result: Using this function you save approx. 22500 steps - 2190 steps = 20310 steps.
Procedure of conversion from a user function block XXX to a function XXX_FUN
We recommend to keep the name conventions.
Assumption: a function XXX with a VAR_IN_OUTdutXXX of data type XXX_FUN_INSTANCE_DUT is used in all examples
Operation |
Original programming example |
Converted programming example |
---|---|---|
Calls |
||
FB POU header |
FUN POU header |
|
DUT XXX_FUN_INSTANCE_DUT |
||
Set Reset |
||
KEEP |
||
Conditional assignment, calculation |
||
Increasing/decreasing variable values |
||
Pulsed flags |
||
At the end of the function: If needed, assign some memory variables to the corresponding output variables: |
||
SR |
||
RS |
||
TON |
||
TM_100ms |
Assumption: a function XXX with a VAR_IN_OUTdutXXX of data type XXX_FUN_INSTANCE_DUT is used in all examples
Operation |
Original programming example |
Converted programming example |
---|---|---|
Set Reset |
|
|
KEEP |
|
|
Conditional assignment, calculation |
|
|
Increasing/decreasing variable values |
|
|
Pulsed flags |
|
|
At the end of the function: If needed, assign some memory variables to the corresponding output variables: |
|
|
SR |
|
|
RS |
|
|
TON |
|
|
TM_100ms |
|
|