20
3 PROGRAM ORGANIZATION UNITS
3.3 Function Blocks (FB)
Input variables, output variables, and input/output variables
Input variables, output variables, and input/output variables need to be defined in function blocks.
A function block can output multiple operation results. It can also be set not to output operation results.
Input variables are set in the VAR_INPUT class, output variables are set in the VAR_OUTPUT class and
VAR_OUTPUT_RETAIN class, and input/output variables are set in the VAR_IN_OUT class.
Internal variables
Function blocks use internal variables. For each instance of a function block, labels are assigned to the different areas. Even
though the same label names are used, different states are held for each instance.
The above function block starts counting when the input variables turn on and turns on the output variable when the current
value held in the internal variable reaches the set value. Even though the same function block is used, the output timings differ
because the instances A and B hold different states.
Internal variables are set in the VAR, VAR_CONSTANT and VAR_RETAIN class.
External variables and public variables
Function blocks can use external variables (global label) and public variables.
Public variables are set in the VAR_PUBLIC and VAR_PUBLIC_RETAIN class.
(1) The operation result(s) is output.
(2) No operation result is output.
_S1 Q1
RESET
IN_Bool
iTim
lCnt
CD Q
CVLOAD
PV
InstanceInstance
Instance
SR SAMPLE_FB1
CTD
(1) (2)
bLabel3 bLabel6
bLabel1
uLabel2
bLabel10
uLabel12
bLabel13
cdLabel11
uLabel12
cdLabel11
bLabel4
uLabel5
bLabel10
bLabel13
Instance A
Function block
Instance B
Function block
Count contact
Count set value
Count contact
Count set value
Current value Current value
Counting-up Counting-up