8/21/2019 CFC Tutorial
1/156
SIMATIC CFC Elementary Blocks
________________________________________________________
____________________________
________________________________________________________
______________________________________________________________________
________________________________________________________
Block parameters EN, ENO,
SAMPLE_T
1
Startup on S7-300 CPUs
2
CFC blocks
3
Logic blocks of the data type
BOOL
4
Logic blocks of the data type
WORD and DWORD
5
Blocks for comparing two
input values of the same
type
6
Blocks for converting data
types
7
Arithmetic blocks of the data
type REAL
8
Arithmetic blocks of the data
type INT and DINT
9
Flip-flop blocks
10
Shift blocks
11
Multiplexer blocks
12
Counter blocks
13
Blocks for generating or
processing pulses
14
Blocks for acquiring or
processing time intervals and
timebases
15
Control blocks
16
System function blocks
(SFBs)
17
AS-wide blocks
18
Appendix
19
SIMATIC
Process Control System PCS 7
CFC Elementary Blocks
Programming and Operating Manual
03/2009
A5E02109607-01
8/21/2019 CFC Tutorial
2/156
Legal information
egal information
Warning notice system
This manual contains notices you have to observe in order to ensure your personal safety, as well as to preventdamage to property. The notices referring to your personal safety are highlighted in the manual by a safety alertsymbol, notices referring only to property damage have no safety alert symbol. These notices shown below aregraded according to the degree of danger.
DANGER
indicates that death or severe personal injurywill
result if proper precautions are not taken.
WARNING
indicates that death or severe personal injury mayresult if proper precautions are not taken.
CAUTION
with a safety alert symbol, indicates that minor personal injury can result if proper precautions are not taken.
CAUTION
without a safety alert symbol, indicates that property damage can result if proper precautions are not taken.
NOTICE
indicates that an unintended result or situation can occur if the corresponding information is not taken intoaccount.
If more than one degree of danger is present, the warning notice representing the highest degree of danger willbe used. A notice warning of injury to persons with a safety alert symbol may also include a warning relating toproperty damage.
Qualified Personnel
The device/system may only be set up and used in conjunction with this documentation. Commissioning andoperation of a device/system may only be performed by qualified personnel. Within the context of the safety notesin this documentation qualified persons are defined as persons who are authorized to commission, ground andlabel devices, systems and circuits in accordance with established safety practices and standards.
Proper use of Siemens products
Note the following:
WARNING
Siemens products may only be used for the applications described in the catalog and in the relevant technicaldocumentation. If products and components from other manufacturers are used, these must be recommendedor approved by Siemens. Proper transport, storage, installation, assembly, commissioning, operation andmaintenance are required to ensure that the products operate safely and without any problems. The permissibleambient conditions must be adhered to. The information in the relevant documentation must be observed.
Trademarks
All names identified by are registered trademarks of the Siemens AG. The remaining trademarks in thispublication may be trademarks whose use by third parties for their own purposes could violate the rights of theowner.
Disclaimer of Liability
We have reviewed the contents of this publication to ensure consistency with the hardware and softwaredescribed. Since variance cannot be precluded entirely, we cannot guarantee full consistency. However, theinformation in this publication is reviewed regularly and any necessary corrections are included in subsequenteditions.
Siemens AGIndustry SectorPostfach 48 4890026 NRNBERGGERMANY
A5E02109607-01 01/2009
Copyright Siemens AG 2009.Technical data subject to change
8/21/2019 CFC Tutorial
3/156
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 3
Table of contents
1 Block parameters EN, ENO, SAMPLE_T........................... ......................................................................
11
2 Startup on S7-300 CPUs ...................................................................................................... ................... 13
3 CFC blocks.............................................................................................................................................. 15
4 Logic blocks of the data type BOOL........................... .............................................................................. 17
4.1 BIT_LGC ......................................................................................................................................17
4.2 AND: AND operation....................................................................................................................18
4.3 OR: OR operation ........................................................................................................................19
4.4 XOR: Exclusive-OR operation .....................................................................................................20
4.5 NAND: NAND operation...............................................................................................................21
4.6 NOR: NOR operation ...................................................................................................................22
4.7 NOT: NOT operation....................................................................................................................23
5 Logic blocks of the data type WORD and DWORD ................................................................................. 25
5.1 WRD_LGC ...................................................................................................................................25
5.2 WAND_W: Word AND operation..................................................................................................26
5.3 WOR_W: Word OR operation......................................................................................................27
5.4 WXOR_W: Word exclusive-OR operation ...................................................................................285.5 WNAND_W: Double word AND operation ...................................................................................29
5.6 WNOR_W: Word NOR operation.................................................................................................30
5.7 WNOT_W.....................................................................................................................................31
5.8 WAND_DW ..................................................................................................................................32
5.9 WOR_DW.....................................................................................................................................32
5.10 WXOR_DW ..................................................................................................................................33
5.11 WNAND_DW................................................................................................................................33
5.12 WNOR_DW..................................................................................................................................34
5.13 WNOT_DW: Double word NOT operation ...................................................................................34
6 Blocks for comparing two input values of the same type.......................................................................... 35
6.1 COMPARE...................................................................................................................................35
6.2 CMP_I: Comparator for INT values..............................................................................................35
6.3 CMP_DI: Comparator for DINT values ........................................................................................36
6.4 CMP_R: Comparator for REAL values ........................................................................................37
6.5 CMP_T: Comparator for TIME values..........................................................................................38
8/21/2019 CFC Tutorial
4/156
Table of contents
CFC Elementary Blocks
4 Programming and Operating Manual, 03/2009, A5E02109607-01
7 Blocks for converting data types ............................................................................................ .................. 39
7.1 CONVERT................................................................................................................................... 39
7.2 BY_DW........................................................................................................................................ 417.3 BY_W .......................................................................................................................................... 41
7.4 DI_DW......................................................................................................................................... 42
7.5 DI_I.............................................................................................................................................. 42
7.6 DI_R ............................................................................................................................................ 43
7.7 DW_DI......................................................................................................................................... 43
7.8 DW_R.......................................................................................................................................... 44
7.9 DW_W ......................................................................................................................................... 44
7.10 I_DI.............................................................................................................................................. 45
7.11 I_DW............................................................................................................................................ 45
7.12 I_R............................................................................................................................................... 46
7.13 I_W .............................................................................................................................................. 46
7.14 R_DI ............................................................................................................................................ 47
7.15 R_DW.......................................................................................................................................... 47
7.16 R_I............................................................................................................................................... 48
7.17 W_BY .......................................................................................................................................... 48
7.18 W_DW ......................................................................................................................................... 49
7.19 W_I .............................................................................................................................................. 497.20 BO_BY......................................................................................................................................... 50
7.21 BO_W.......................................................................................................................................... 50
7.22 BO_DW ....................................................................................................................................... 51
7.23 BY_BO......................................................................................................................................... 51
7.24 W_BO.......................................................................................................................................... 52
7.25 DW_BO ....................................................................................................................................... 52
8/21/2019 CFC Tutorial
5/156
Table of contents
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 5
8 Arithmetic blocks of the data type REAL.................................................................................................. 53
8.1 MATH_FP.....................................................................................................................................53
8.2 ADD_R: Addition of REAL values ................................................................................................548.3 SUB_R: Subtraction of REAL values ...........................................................................................54
8.4 MUL_R: Multiplication of REAL values ........................................................................................55
8.5 DIV_R: Division of REAL values ..................................................................................................55
8.6 MAXn_R: Maximum of REAL values ...........................................................................................56
8.7 MINn_R: Minimum of REAL values .............................................................................................57
8.8 ABS_R: Absolute value of REAL values......................................................................................58
8.9 SQRT: Square root ......................................................................................................................58
8.10 EXP: Exponential function ...........................................................................................................59
8.11 POW10: Power-of-10 function .....................................................................................................59
8.12 LN: Natural logarithm...................................................................................................................60
8.13 LOG10: Base-10 logarithm ..........................................................................................................60
8.14 SIN: Sin function ..........................................................................................................................61
8.15 COS: Cos function .......................................................................................................................61
8.16 TAN: Tan function ........................................................................................................................62
8.17 ASIN: Arc sin function ..................................................................................................................62
8.18 ACOS: Arc cos function ...............................................................................................................63
8.19 ATAN: Arc tan function ................................................................................................................638.20 NEG_R.........................................................................................................................................64
8.21 LIM_R: Limiter of REAL values ....................................................................................................64
8.22 EPS_R..........................................................................................................................................65
8.23 CADD_R.......................................................................................................................................66
8.24 POWXY: General power function ................................................................................................67
8.25 SAMP_AVE: Floating average value ...........................................................................................68
8/21/2019 CFC Tutorial
6/156
Table of contents
CFC Elementary Blocks
6 Programming and Operating Manual, 03/2009, A5E02109607-01
9 Arithmetic blocks of the data type INT and DINT ............................................................................. ........ 69
9.1 MATH_INT................................................................................................................................... 69
9.2 ADD_I: Addition of INT values .................................................................................................... 709.3 SUB_I: Subtraction of INT values ............................................................................................... 70
9.4 MUL_I: Multiplication of INT values............................................................................................. 71
9.5 DIV_I: Division of INT values....................................................................................................... 71
9.6 MOD_I: Modulo function of INT values ....................................................................................... 72
9.7 MAXn_I: Maximum of INT values................................................................................................ 72
9.8 MINn_I: Minimum of INT values.................................................................................................. 73
9.9 ABS_I Absolute value of INT values ........................................................................................... 73
9.10 NEG_I: Inverter for INT values.................................................................................................... 74
9.11 LIM_I: Limiter for INT values ....................................................................................................... 74
9.12 EPS_I: Accuracy approximation of INT values ........................................................................... 75
9.13 CADD_I: Controllable adder of INT values ................................................................................. 76
9.14 ADD_DI: Addition of DINT values ............................................................................................... 77
9.15 SUB_DI: Subtraction of DINT values .......................................................................................... 77
9.16 MUL_DI: Multiplication of DINT................................................................................................... 78
9.17 DIV_DI: Division of DINT values ................................................................................................. 78
9.18 MOD_DI: Modulo function of DINT values .................................................................................. 79
9.19 MAXn_DI: Maximum of DINT values .......................................................................................... 799.20 MINn_DI: Minimum of DINT values............................................................................................. 80
9.21 ABS_DI: Absolute value of DINT values ..................................................................................... 80
9.22 NEG_DI: Inverter for DINT values............................................................................................... 81
9.23 LIM_DI: Limiter for DINT values.................................................................................................. 81
9.24 EPS_DI: Accuracy approximation of DINT values ...................................................................... 82
9.25 CADD_DI: Controllable adder of DINT values ............................................................................ 83
10 Flip-flop blocks......................................................................................................................................... 85
10.1 FLIPFLOP ................................................................................................................................... 85
10.2 JK_FF.......................................................................................................................................... 85
10.3 RS_FF: RS flip-flop, reset dominant ........................................................................................... 86
10.4 SR_FF: SR flip-flop, set dominant............................................................................................... 86
8/21/2019 CFC Tutorial
7/156
Table of contents
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 7
11 Shift blocks .............................................................................................................................................. 87
11.1 SHIFT...........................................................................................................................................87
11.2 SHL_W: WORD shift left ..............................................................................................................8711.3 SHL_DW: DWORD shift left.........................................................................................................88
11.4 SHR_W: WORD shift right ...........................................................................................................88
11.5 SHR_DW: DWORD shift right ......................................................................................................89
11.6 ROL_W: WORD rotate left ...........................................................................................................89
11.7 ROL_DW: DWORD rotate left......................................................................................................90
11.8 ROR_W: WORD rotate right ........................................................................................................90
11.9 ROR_DW: DWORD rotate right ...................................................................................................91
12 Multiplexer blocks .......................................... .......................................................................................... 93
12.1 MULTIPLX....................................................................................................................................93
12.2 MUXn_I: Multiplexer 1 of n for INT values ...................................................................................94
12.3 MUXn_DI: Multiplexer 1 of n for DINT values ..............................................................................95
12.4 MUXn_R: Multiplexer 1 of n for REAL values ..............................................................................96
12.5 MUXn_BO: Multiplexer 1 of n for BOOL values...........................................................................97
12.6 SEL_BO: Multiplexer 1 of 2 for BOOL values ..............................................................................98
12.7 SEL_R: Multiplexer 1 of 2 for REAL values .................................................................................98
13 Counter blocks......................................................................................................................................... 99
13.1 COUNTER ...................................................................................................................................9913.2 CTU: Up counter ........................................................................................................................100
13.3 CTD: Down counter ...................................................................................................................101
13.4 CTUD: Up/down counter............................................................................................................102
14 Blocks for generating or processing pulses ........................................................................................... 103
14.1 PULSE .......................................................................................................................................103
14.2 TIMER_P: Pulse generator ........................................................................................................104
14.3 R_TRIG: Detection of the rising edge ........................................................................................107
14.4 F_TRIG: Detection of the falling edge........................................................................................108
14.5 AFP: Clock .................................................................................................................................109
15 Blocks for acquiring or processing time intervals and timebases........................................................... 111
15.1 TIME...........................................................................................................................................111
15.2 TIME: Measures the execution time ..........................................................................................111
15.3 TIME_BEG: Outputs the current time of day .............................................................................112
15.4 TIME_END: Compares the input time with the actual time........................................................112
8/21/2019 CFC Tutorial
8/156
Table of contents
CFC Elementary Blocks
8 Programming and Operating Manual, 03/2009, A5E02109607-01
16 Control blocks............................................................................................................. ........................... 113
16.1 CONTROL................................................................................................................................. 113
16.2 CONT_C.................................................................................................................................... 11416.2.1 CONT_C: Continuous-action controller..................................................................................... 11416.2.2 CONT_C: Block diagram........................................................................................................... 119
16.3 CONT_S.................................................................................................................................... 12016.3.1 CONT_S: Step controller........................................................................................................... 12016.3.2 CONT_S: Block diagram........................................................................................................... 124
16.4 PULSEGEN............................................................................................................................... 12516.4.1 PULSEGEN: Pulse duration modulation for PID controller....................................................... 12516.4.2 PULSEGEN: Block diagram...................................................................................................... 13016.4.3 PULSEGEN: Three-step control ............................................................................................... 13016.4.4 PULSEGEN: Three-step control, asymmetrical ........................................................................ 13216.4.5 PULSEGEN: Two-step control .................................................................................................. 133
16.4.6 PULSEGEN: Manual operation in two-step or three-step control............................................. 13417 System function blocks (SFBs) .............................................................................................................. 135
17.1 EVENT: Start of the priority class ............................................................................................. 135
17.2 DELAY....................................................................................................................................... 136
17.3 DELAY: Delaying the start event .............................................................................................. 136
17.4 EDELAY: Enable signal for delayed start events...................................................................... 137
17.5 DISCARD: All arising start events are discarded...................................................................... 137
17.6 EDISCARD: Enable signal for all new start events................................................................... 138
17.7 LASTERR: Determining the error code in DELAY, EDELAY, DISCARD,
EDISCARD,P_REASON ........................................................................................................... 13817.8 SYSTIME: Determines the system time.................................................................................... 139
17.9 P_REASON: Determining the cause of the process interrupt................................................... 139
17.10 FRC_CFC: Internal Block.......................................................................................................... 140
18 AS-wide blocks ............................................................................................................. ......................... 141
18.1 IK_STATE.................................................................................................................................. 141
18.2 IK_MANAG................................................................................................................................ 143
18.3 IK_SEND ................................................................................................................................... 143
18.4 IK_RCV...................................................................................................................................... 144
18.5 IK_CP_OU................................................................................................................................. 144
18.6 IK_CP_IN................................................................................................................................... 145
18.7 IK_ALARM................................................................................................................................. 145
8/21/2019 CFC Tutorial
9/156
Table of contents
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 9
19 Appendix................................................................................................................................................ 147
19.1 Manual value processing ...........................................................................................................147
19.2 Pulse duration modulation .........................................................................................................14719.3 Process variable branch ............................................................................................................148
19.4 Characteristic with bipolar range of manipulated values ...........................................................148
19.5 Characteristic with unipolar range of manipulated values .........................................................149
19.6 PI step algorithm ........................................................................................................................149
19.7 PID algorithm .............................................................................................................................150
19.8 Error signal.................................................................................................................................150
19.9 Setpoint branch..........................................................................................................................150
19.10 Manipulated value processing ...................................................................................................150
19.11 Disturbance variable input .........................................................................................................151
19.12 Symmetrical characteristic for three-step controller...................................................................151
19.13 Asymmetrical characteristic for three-step controller.................................................................152
Index...................................................................................................................................................... 153
8/21/2019 CFC Tutorial
10/156
Table of contents
CFC Elementary Blocks
10 Programming and Operating Manual, 03/2009, A5E02109607-01
8/21/2019 CFC Tutorial
11/156
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 11
Block parameters EN, ENO, SAMPLE_T
1
EN
EN (enable): Enable input.
The input exists only in the graphical interface of CFC however it is switched to hidden. Youcan use the enable input to enable/disable block processing. It ensures that the block is onlycalled in the task code at AS level if it has been enabled via EN = 1.
ENO
ENO: ENO is the same as BR (Binary Result - refer to the STEP 7 documentation).ENO = 1 shows a valid result as appropriate to the function. When the operating systemand/or the error-handling routine detects an error in the block program, ENO will be set to 0to indicate an invalid result. You can use this information in order to switch to other values(e.g., safety values) and to output messages to the OS as required.
If EN = FALSE, then ENO = FALSE.
SAMPLE_T
All blocks with the input parameter SAMPLE_T must be processed in temporally equidistanttasks, e.g. OB 35: Watchdog interrupt 100 ms. If they are implemented in acyclic tasks, e.g.,
process alarms, these blocks will return incorrect results
8/21/2019 CFC Tutorial
12/156
Block parameters EN, ENO, SAMPLE_T
CFC Elementary Blocks
12 Programming and Operating Manual, 03/2009, A5E02109607-01
8/21/2019 CFC Tutorial
13/156
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 13
Startup on S7-300 CPUs
2
Startup
As it is not possible for S7-300 CPU restarts to be detected automatically, memory word 0(MW0) is used as a startup bit memory word in startup blocks (blocks included inELEM_300). This memory word must not, therefore, be modified in the user program.
In order to ensure a proper restart, you must insert the RESTART (FC 70) function into aCFC chart once for each S7-300 CPU.
Procedure:
1. Open the process editor with the menu commandEdit > Process Sequence
or via theicon in the toolbar.
2. Position the RESTART block at the beginning of OB 100.
3. Delete the RESTART block in the cyclic task (default: OB 35)the block will only still be called in OB 100.
8/21/2019 CFC Tutorial
14/156
Startup on S7-300 CPUs
CFC Elementary Blocks
14 Programming and Operating Manual, 03/2009, A5E02109607-01
8/21/2019 CFC Tutorial
15/156
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 15
CFC blocks
3
The following CFC block families are available:
Family Purpose
BIT_LGC(Page 17) Logic blocks of the data type BOOL.
WRD_LGC(Page 25)
Logic blocks of the data type WORD and DWORD
COMPARE(Page 35)
Blocks for comparing two input values of the same type
CONVERT(Page 39)
Blocks for converting data types
MATH_FP(Page 53) Arithmetic blocks of the data type REAL
MATH_INT(Page 69)
Arithmetic blocks of the data type INT and DINT
FLIPFLOP(Page 85) Flip-flop blocks
SHIFT(Page 87) Shift blocks
MULTIPLX(Page 93)
Multiplexer blocks
COUNTER(Page 99)
Count blocks
PULSE(Page 103) Blocks for generating or processing pulsesTIME(Page 111) Blocks for acquiring or processing time intervals and timebases
CONTROL(Page 113)
Closed-loop-control blocks
SYSTEM(Page 135) System function blocks (SFBs)
IC(Page 141) AS-wide blocks
8/21/2019 CFC Tutorial
16/156
CFC blocks
CFC Elementary Blocks
16 Programming and Operating Manual, 03/2009, A5E02109607-01
8/21/2019 CFC Tutorial
17/156
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 17
Logic blocks of the data type BOOL
4
4.1 BIT_LGC
CFC blocks of the BIT_LGC family
In this family we have implemented the following blocks with which logic combinations canbe implemented:
AND(Page 18) AND operation
OR(Page 19) OR operationXOR(Page 20) Exclusive-OR operation
NAND(Page 21) NAND operation
NOR(Page 22) NOR operation
NOT(Page 23) NOT operation
8/21/2019 CFC Tutorial
18/156
Logic blocks of the data type BOOL
4.2 AND: AND operation
CFC Elementary Blocks
18 Programming and Operating Manual, 03/2009, A5E02109607-01
4.2
AND: AND operation
Function
This block generates logic AND operations at inputs. The output is 1 if all inputs are 1.Otherwise, the output is 0. The number of "IN" inputs at the block can be modified.
Truth table (example of n = 2)
IN1 IN2 OUT
0 0 0
0 1 0
1 0 01 1 1
I/Os
Name Data type Default setting
IN1 BOOL 1
IN2 BOOL 1
... ...
Inputs
INn BOOL 1
Output OUT BOOL 1
8/21/2019 CFC Tutorial
19/156
Logic blocks of the data type BOOL
4.3 OR: OR operation
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 19
4.3
OR: OR operation
Function
This block generates logic OR operations at inputs. The output is 1 if at least one input is 1.If all inputs are 0, the output is 0. The number of "IN" inputs at the block can be modified.
Truth table (example of n = 2)
IN1 IN2 OUT
0 0 0
0 1 1
1 0 11 1 1
I/Os
Name Data type Default setting
IN1 BOOL 0
IN2 BOOL 0
... ...
Inputs
INn BOOL 0
Output OUT BOOL 0
8/21/2019 CFC Tutorial
20/156
Logic blocks of the data type BOOL
4.4 XOR: Exclusive-OR operation
CFC Elementary Blocks
20 Programming and Operating Manual, 03/2009, A5E02109607-01
4.4
XOR: Exclusive-OR operation
Function
This block generates logic exclusive-OR operations at inputs. The output is 0 if all inputshave the same value. Otherwise, the output is 1. The number of "IN" inputs at the block canbe modified.
Truth table (example of n = 2)
IN1 IN2 OUT
0 0 0
0 1 1
1 0 1
1 1 0
I/Os
Name Data type Default setting
IN1 BOOL 0
IN2 BOOL 0
... ...
Inputs
INn BOOL 0
Output OUT BOOL 0
8/21/2019 CFC Tutorial
21/156
Logic blocks of the data type BOOL
4.5 NAND: NAND operation
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 21
4.5
NAND: NAND operation
Function
This block generates and inverts logic AND operations at inputs. The output is 0 if all inputsare 1. The number of "IN" inputs at the block can be modified.
Truth table (example of n = 2)
IN1 IN2 OUT
0 0 1
0 1 1
1 0 11 1 0
I/Os
Name Data type Default setting
IN1 BOOL 1
IN2 BOOL 1
... ...
Inputs
INn BOOL 1
Output OUT BOOL 0
8/21/2019 CFC Tutorial
22/156
Logic blocks of the data type BOOL
4.6 NOR: NOR operation
CFC Elementary Blocks
22 Programming and Operating Manual, 03/2009, A5E02109607-01
4.6
NOR: NOR operation
Function
This block generates and inverts OR logic operations at inputs. The output is 1 if all inputsare 0. The number of "IN" inputs at the block can be modified.
Truth table (example of n = 2)
IN1 IN2 OUT
0 0 1
0 1 0
1 0 01 1 0
I/Os
Name Data type Default setting
IN1 BOOL 0
IN2 BOOL 0
... ...
Inputs
INn BOOL 0
Output OUT BOOL 1
8/21/2019 CFC Tutorial
23/156
Logic blocks of the data type BOOL
4.7 NOT: NOT operation
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 23
4.7
NOT: NOT operation
Function
This block inverts the input.
Truth table
IN OUT
0 1
1 0
I/Os
Name Data type Default setting
Input IN BOOL 0
Output OUT BOOL 1
8/21/2019 CFC Tutorial
24/156
Logic blocks of the data type BOOL
4.7 NOT: NOT operation
CFC Elementary Blocks
24 Programming and Operating Manual, 03/2009, A5E02109607-01
8/21/2019 CFC Tutorial
25/156
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 25
Logic blocks of the data type WORD and DWORD
5
5.1 WRD_LGC
CFC blocks of the WRD_LGC family
This family contains the following word logic blocks for the data types WORD and DWORD:
WAND_W(Page 26) Word AND operation
WAND_DW(Page 32) Double word AND operation
WOR_W(Page 27) Word OR operation
WOR_DW (Page 32) Double word OR operation
WXOR_W(Page 28) Word exclusive-OR operation
WXOR_DW(Page 33) Double word exclusive-OR operation
WNAND_W (Page 29) Word NAND operation
WNAND_DW (Page 33) Double word NAND operation
WNOR_W(Page 30) Word NOR operation
WNOR_DW(Page 34) Double word NOR operation
WNOT_W(Page 31) Word NOT operation
WNOT_DW(Page 34) Double word NOT operation
8/21/2019 CFC Tutorial
26/156
Logic blocks of the data type WORD and DWORD
5.2 WAND_W: Word AND operation
CFC Elementary Blocks
26 Programming and Operating Manual, 03/2009, A5E02109607-01
5.2
WAND_W: Word AND operation
Function
This block generates word logic AND operations at inputs. All input bits of the samesignificance are logically linked by AND; the result is written to the corresponding output bit.The number of "IN" inputs at the block can be modified.
Example (two inputs)
IN1 2# 1 1 1 1_0 0 0 0_1 1 1 1_0 0 0 0_1 1 0 1
IN2 2# 1 1 1 1_0 0 0 0_0 0 1 1_0 0 0 0_0 0 1 1
OUT 2# 1 1 1 1_0 0 0 0_0 0 1 1_0 0 0 0_0 0 0 1
I/Os
Name Data type Default setting
IN1 WORD 0
IN2 WORD 0
Inputs
...
Output OUT WORD 0
8/21/2019 CFC Tutorial
27/156
Logic blocks of the data type WORD and DWORD
5.3 WOR_W: Word OR operation
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 27
5.3
WOR_W: Word OR operation
Function
This block generates word logic OR operations at inputs. All input bits of the samesignificance are logically linked by OR and the result is written to the corresponding outputbit. The number of "IN" inputs at the block can be modified.
Example (two inputs)
IN1 2# 1 1 1 1_0 0 0 0_1 1 1 1_0 0 0 0_1 1 0 1
IN2 2# 1 1 1 1_0 0 0 0_0 0 1 1_0 0 0 0_0 0 1 1
OUT 2# 1 1 1 1_0 0 0 0_1 1 1 1_0 0 0 0_1 1 1 1
I/Os
Name Data type Default setting
IN1 WORD 0
IN2 WORD 0
Inputs
...
Output OUT WORD 0
8/21/2019 CFC Tutorial
28/156
Logic blocks of the data type WORD and DWORD
5.4 WXOR_W: Word exclusive-OR operation
CFC Elementary Blocks
28 Programming and Operating Manual, 03/2009, A5E02109607-01
5.4
WXOR_W: Word exclusive-OR operation
Function
This block generates word logic exclusive-OR operations at inputs. All input bits of the samesignificance are logically linked by exclusive-OR and the result is written to thecorresponding output bit. The bit is 0 if all input bits of the same significance have the samevalue. Otherwise the bit is 1. The number of "IN" inputs at the block can be modified.
Example (two inputs)
IN1 2# 1 1 1 1_0 0 0 0_1 1 1 1_0 0 0 0_1 1 0 1
IN2 2# 1 1 1 1_0 0 0 0_0 0 1 1_0 0 0 0_0 0 1 1
OUT 2# 0 0 0 0_0 0 0 0_1 1 0 0_0 0 0 0_1 1 1 0
I/Os
Name Data type Default setting
IN1 WORD 0
IN2 WORD 0
Inputs
...
Output OUT WORD 0
8/21/2019 CFC Tutorial
29/156
Logic blocks of the data type WORD and DWORD
5.5 WNAND_W: Double word AND operation
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 29
5.5
WNAND_W: Double word AND operation
Function
This block generates word logic NOT AND operations at inputs. All input bits of the samesignificance are logically linked by AND, inverted and the result is written to thecorresponding output bit. The number of "IN" inputs at the block can be modified.
Example (two inputs)
IN1 2# 1 1 1 1_0 0 0 0_1 1 1 1_0 0 0 0_1 1 0 1
IN2 2# 1 1 1 1_0 0 0 0_0 0 1 1_0 0 0 0_0 0 1 1
OUT 2# 0 0 0 0_1 1 1 1_1 1 0 0_1 1 1 1_1 1 1 0
I/Os
Name Data type Default setting
IN1 WORD 0
IN2 WORD 0
Inputs
...
Output OUT WORD 0
8/21/2019 CFC Tutorial
30/156
Logic blocks of the data type WORD and DWORD
5.6 WNOR_W: Word NOR operation
CFC Elementary Blocks
30 Programming and Operating Manual, 03/2009, A5E02109607-01
5.6
WNOR_W: Word NOR operation
Function
This block generates word logic NOT OR operations at inputs. All input bits of the samesignificance are logically linked by OR. The result is then inverted and written to thecorresponding output bit. The number of "IN" inputs at the block can be modified.
Example (two inputs)
IN1 2# 1 1 1 1_0 0 0 0_1 1 1 1_0 0 0 0_1 1 0 1
IN2 2# 1 1 1 1_0 0 0 0_0 0 1 1_0 0 0 0_0 0 1 1
OUT 2# 0 0 0 0_1 1 1 1_0 0 0 0_1 1 1 1_0 0 0 0
I/Os
Name Data type Default setting
IN1 WORD 0Inputs
IN2 WORD 0
Output OUT WORD 0
8/21/2019 CFC Tutorial
31/156
Logic blocks of the data type WORD and DWORD
5.7 WNOT_W
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 31
5.7
WNOT_W
Function
This block inverts the input word. Each bit of the input is inverted and written to the output bitof the corresponding significance.
Example
IN 2# 1 1 1 1_0 0 0 0_1 1 1 1_0 0 0 0_1 1 0 1
OUT 2# 0 0 0 0_1 1 1 1_0 0 0 0_1 1 1 1_0 0 1 0
I/Os
Name Data type Default setting
Input IN WORD 0
Output OUT WORD 1
8/21/2019 CFC Tutorial
32/156
Logic blocks of the data type WORD and DWORD
5.8 WAND_DW
CFC Elementary Blocks
32 Programming and Operating Manual, 03/2009, A5E02109607-01
5.8
WAND_DW
Function
This block generates DWORD logic AND operations at inputs. All input bits of the samesignificance are logically linked by AND; the result is written to the corresponding output bit.The number of "IN" inputs at the block can be modified.
Example (same as WAND_W, extended to 32 bits)
I/Os
Name Data type Default setting
IN1 DWORD 0Inputs
IN2 DWORD 0
Output OUT DWORD 0
5.9 WOR_DW
Function
This block generates DWORD logic OR operations at inputs. All input bits of the samesignificance are logically linked by OR and the result is written to the corresponding outputbit. The number of "IN" inputs at the block can be modified.
Example (same as WOR_W, extended to 32 bits)
I/Os
Name Data type Default setting
IN1 DWORD 0Inputs
IN2 DWORD 0
Output OUT DWORD 0
8/21/2019 CFC Tutorial
33/156
Logic blocks of the data type WORD and DWORD
5.10 WXOR_DW
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 33
5.10
WXOR_DW
Function
This block generates DWORD logic exclusive-OR operations at inputs. All input bits of thesame significance are logically linked by exclusive-OR and the result is written to thecorresponding output bit. The bit is 0 if all input bits of the same significance have the samevalue. Otherwise the bit is 1. The number of "IN" inputs at the block can be modified.
Example (same as WXOR_W, extended to 32 bits)
I/Os
Name Data type Default setting
IN1 DWORD 16#0Inputs
IN2 DWORD 16#0
Output OUT DWORD 16#00000000
5.11
WNAND_DW
Function
This block generates DWORD logic NOT AND operations at inputs. All input bits of the samesignificance are logically linked by AND, inverted and the result is written to thecorresponding output bit. The number of "IN" inputs at the block can be modified.
Example (same as WNAND_W, extended to 32 bits)
I/Os
Name Data type Default setting
IN1 DWORD 0InputsIN2 DWORD 0
Output OUT DWORD 0
8/21/2019 CFC Tutorial
34/156
Logic blocks of the data type WORD and DWORD
5.12 WNOR_DW
CFC Elementary Blocks
34 Programming and Operating Manual, 03/2009, A5E02109607-01
5.12
WNOR_DW
Function
This block generates DWORD logic NOT OR operations at inputs. All input bits of the samesignificance are logically linked by OR. The result is then inverted and written to thecorresponding output bit. The number of "IN" inputs at the block can be modified.
Example (same as WNOR_W, extended to 32 bits)
I/Os
Name Data type Default setting
IN1 DWORD 0Inputs
IN2 DWORD 0
Output OUT DWORD 0
5.13 WNOT_DW: Double word NOT operation
Function
This block inverts the input word. Each bit of the input is inverted and written to the output bitof the corresponding significance.
Example (same as WNOT_W, extended to 32 bits)
I/Os
Name Data type Default setting
Input IN DWORD 0
Output OUT DWORD 0
8/21/2019 CFC Tutorial
35/156
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 35
Blocks for comparing two input values of the same
type
6
6.1
COMPARE
CFC blocks of the COMPARE family
This family contains blocks for comparing two input variables.
CMP_I(Page 35) Comparator for INT values
CMP_DI(Page 36) Comparator for DINT values
CMP_R(Page 37) Comparator for REAL values
CMP_T(Page 38) Comparator for TIME values
6.2
CMP_I: Comparator for INT values
Function
This block compares two input variables and sets the outputs as follows:
GT = 1 if IN1 > IN2
GE = 1 if IN1 IN2,
EQ = 1 if IN1=
IN2
LT = 1 if IN1 < IN2
LE = 1 if IN1 IN2
The other four outputs are set to 0 in each case.
I/Os
Name Data type Description Default setting
IN1 INT Input variable 1 0Inputs
IN2 INT Input variable 2 0
GT BOOL 1, IN1 > IN2 0
GE BOOL 1, IN1 IN2 0
EQ BOOL 1, IN1 = IN2 0
LT BOOL 1, IN1 < IN2 0
Outputs
LE BOOL 1, IN1 IN2 0
8/21/2019 CFC Tutorial
36/156
Blocks for comparing two input values of the same type
6.3 CMP_DI: Comparator for DINT values
CFC Elementary Blocks
36 Programming and Operating Manual, 03/2009, A5E02109607-01
6.3
CMP_DI: Comparator for DINT values
Function
This block compares two input variables and sets the outputs as follows:
GT = 1 if IN1 > IN2
GE = 1 if IN1 IN2,
EQ = 1 if IN1 = IN2
LT = 1 if IN1 < IN2
LE = 1 if IN1 IN2
The other four outputs are set to 0 in each case.
I/Os
Name Data type Description Default setting
IN1 DINT Input variable 1 0Inputs
IN2 DINT Input variable 2 0
GT BOOL 1, IN1 > IN2 0
GE BOOL 1, IN1 IN2 0
EQ BOOL 1, IN1 = IN2 0
LT BOOL 1, IN1 < IN2 0
Outputs
LE BOOL 1, IN1 IN2 0
8/21/2019 CFC Tutorial
37/156
Blocks for comparing two input values of the same type
6.4 CMP_R: Comparator for REAL values
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 37
6.4
CMP_R: Comparator for REAL values
Function
This block compares two input variables and sets the outputs as follows:
GT = 1 if IN1 > IN2
GE = 1 if IN1 IN2,
EQ = 1 if IN1 = IN2
LT = 1 if IN1 < IN2
LE = 1 if IN1 IN2
The other four outputs are set to 0 in each case.
I/Os
Name Data type Description Default setting
IN1 REAL Input variable 1 0Inputs
IN2 REAL Input variable 2 0
GT BOOL 1, IN1 > IN2 0
GE BOOL 1, IN1 IN2 0
EQ BOOL 1, IN1 = IN2 0
LT BOOL 1, IN1 < IN2 0
Outputs
LE BOOL 1, IN1 IN2 0
8/21/2019 CFC Tutorial
38/156
Blocks for comparing two input values of the same type
6.5 CMP_T: Comparator for TIME values
CFC Elementary Blocks
38 Programming and Operating Manual, 03/2009, A5E02109607-01
6.5
CMP_T: Comparator for TIME values
Function
This block compares two input variables and sets the outputs as follows:
GT = 1 if IN1 > IN2
GE = 1 if IN1 IN2,
EQ = 1 if IN1 = IN2
LT = 1 if IN1 < IN2
LE = 1 if IN1 IN2
The other four outputs are set to 0 in each case.
I/Os
Name Data type Description Default setting
IN1 TIME Input variable 1 0Inputs
IN2 TIME Input variable 2 0
GT BOOL 1, IN1 > IN2 0
GE BOOL 1, IN1 IN2 0
EQ BOOL 1, IN1 = IN2 0
LT BOOL 1, IN1 < IN2 0
Outputs
LE BOOL 1, IN1 IN2 0
8/21/2019 CFC Tutorial
39/156
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 39
Blocks for converting data types
7
7.1 CONVERT
Introduction
CFC only allows the interconnection of block outputs (source type) to block inputs (targettype) if both data types are identical (e.g., REAL output REAL input). Conversion blocksmust be used to allow the interconnection of different data types. The input and output dataof the block are of a different type, and it thus converts the input data type according to thedata type set at the output.
Conversion rules
The abbreviated name of the source and target data type, connected by means of anunderscore "_", form the type name.
The table below shows a brief description of conversion rules for specific blocks. If the INinput value is not within the allowed range, the OUT output value becomes invalid and thetest output ENO = 0 is displayed.
You can evaluate ENO, for example, to provide a substitute/safety value for furtherprocessing.
The CONVERT library contains blocks you can use to convert n values of a data type to mvalues of another data type (the values of m and n may be equal).
8/21/2019 CFC Tutorial
40/156
Blocks for converting data types
7.1 CONVERT
CFC Elementary Blocks
40 Programming and Operating Manual, 03/2009, A5E02109607-01
The following blocks convert onevalue of a data type into onevalue of another data type:
BY_DW(Page 41) Converts BYTE to DWORDBY_W(Page 41) Converts BYTE to WORD
DI_DW(Page 42) Converts DINT to DWORD
DI_I(Page 42) Converts DINT to INT
DI_R(Page 43) Converts DINT to REAL
DW_DI(Page 43) Converts DWORD to DINT
DW_R(Page 44) Converts DWORD to REAL
DW_W(Page 44) Converts DWORD to WORD
I_DI(Page 45) Converts INT to DINT
I_DW(Page 45) Converts INT to DWORD
I_R(Page 46) Converts INT to REAL
I_W(Page 46) Converts INT to WORD
R_DI(Page 47) Converts REAL to DINT
R_DW(Page 47) Converts REAL to DWORD
R_I(Page 48) Converts REAL to INT
W_BY(Page 48) Converts WORD to BYTE
W_DW(Page 49) Converts WORD to DWORD
W_I(Page 49) Converts WORD to INT
The following blocks convert severalBOOL type values into oneBYTE, WORD or DWORDtype value:
BO_BY(Page 50) Converts BOOL to BYTE, 8 inputs
BO_W(Page 50) Converts BOOL to WORD, 16 inputs
BO_DW(Page 51) Converts BOOL to DWORD, 32 inputs
The following blocks convertone
BYTE, WORD or DWORD type values intoseveral
BOOLtype values:
BY_BO(Page 51) Converts BYTE to BOOL, 8 outputs
W_BO(Page 52) Converts WORD to BOOL, 16 outputs
DW_BO(Page 52) Converts DWORD to BOOL, 32 outputs
8/21/2019 CFC Tutorial
41/156
Blocks for converting data types
7.2 BY_DW
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 41
7.2
BY_DW
Function
Copies the byte of IN to the low-byte of OUT and sets the high-bytes to 0.
Troubleshooting
n.a.
I/Os
Name Data type Default setting
Input IN BYTE 0
Output OUT DWORD 0
7.3 BY_W
Function
Copies the byte of IN to the low-byte of OUT and sets the high-byte to 0.
Troubleshooting
n.a.
I/Os
Name Data type Default setting
Input IN BYTE 0
Output OUT WORD 0
8/21/2019 CFC Tutorial
42/156
Blocks for converting data types
7.4 DI_DW
CFC Elementary Blocks
42 Programming and Operating Manual, 03/2009, A5E02109607-01
7.4
DI_DW
Function
Copies the bit string of IN to OUT.
Troubleshooting
n.a.
I/Os
Name Data type Description Default setting
Input IN DINT Input value 0
Output OUT DWORD Output value 0
7.5 DI_I
Function
Converts the IN bit string to INT and copies the result to OUT.
Troubleshooting
If the values of IN lie outside the range of -32 768 to 32 767, ENO = 0 and OUT is an invalidvalue.
I/Os
Name Data type Description Default setting
Input IN DINT Input value 0
Output OUT INT Output value 0
8/21/2019 CFC Tutorial
43/156
Blocks for converting data types
7.6 DI_R
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 43
7.6
DI_R
Function
Converts the value of IN to a REAL number and copies the result to OUT.
Troubleshooting
n.a.
I/Os
Name Data type Default setting
Input IN DINT 0
Output OUT REAL 0
7.7 DW_DI
Function
Copies the bit string of IN to OUT.
Troubleshooting
n.a.
I/Os
Name Data type Description Default setting
Input IN DWORD Input value 0
Output OUT DINT Output value 0
8/21/2019 CFC Tutorial
44/156
Blocks for converting data types
7.8 DW_R
CFC Elementary Blocks
44 Programming and Operating Manual, 03/2009, A5E02109607-01
7.8
DW_R
Method of operation
The block only forwards the bit string and does not change any values. To cause a valuechange to REAL, the DW_DI block and then the DI_R block must be used.
Function
Copies the bit string of IN to OUT.
Troubleshooting
Not applicable
I/Os
Name Data type Description Default setting
Input IN DWORD Input value 0
Output OUT REAL Output value 0
7.9
DW_W
Function
Copies the low-word of IN to the word of OUT.
Troubleshooting
ENO = 0 if the IN high-word > 0
I/Os
Name Data type Description Default setting
Input IN DWORD Input value 0
Output OUT WORD Output value 0
8/21/2019 CFC Tutorial
45/156
Blocks for converting data types
7.10 I_DI
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 45
7.10
I_DI
Function
Copies the value of IN to OUT.
Troubleshooting
n.a.
I/Os
Name Data type Default setting
Input IN INT 0
Output OUT DINT 0
7.11 I_DW
Function
Copies the bit string of IN to the low-word of OUT and sets the high-word to 0.
Troubleshooting
n.a.
I/Os
Name Data type Description Default setting
Input IN INT Input value 0
Output OUT DWORD Output value 0
8/21/2019 CFC Tutorial
46/156
Blocks for converting data types
7.12 I_R
CFC Elementary Blocks
46 Programming and Operating Manual, 03/2009, A5E02109607-01
7.12
I_R
Function
Copies the integer of IN to OUT.
Troubleshooting
n.a.
I/Os
Name Data type Default setting
Input IN INT 0
Output OUT REAL 0
7.13 I_W
Function
Copies the bit string of IN to OUT.
Troubleshooting
n.a.
I/Os
Name Data type Description Default setting
Input IN INT Input value 0
Output OUT WORD Output value 0
8/21/2019 CFC Tutorial
47/156
Blocks for converting data types
7.14 R_DI
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 47
7.14
R_DI
Function
Converts the REAL value of IN to OUT.
Troubleshooting
If the value of IN is outsidce the range -2.147483648e+09 und 2.147483647e+09, then ENO= 0 and OUT is invalid.
I/Os
Name Data type Default setting
Input IN REAL 0
Output OUT DINT 0
7.15
R_DW
Method of operation
The block only forwards the bit string and does not change any values. In order to convert
REAL to DWORD, you must use the R_TO_DW block (PCS 7 Library).
Function
Copies the bit string of IN to OUT.
Troubleshooting
Not applicable
I/Os
Name Data type Default setting
Input IN REAL 0
Output OUT DWORD 0
8/21/2019 CFC Tutorial
48/156
Blocks for converting data types
7.16 R_I
CFC Elementary Blocks
48 Programming and Operating Manual, 03/2009, A5E02109607-01
7.16
R_I
Function
Converts the REAL value of IN to OUT.
Troubleshooting
If the value at IN is not in the range 32768 to 32767, then ENO = 0 and OUT is invalid.
I/Os
Name Data type Default setting
Input IN REAL 0
Output: OUT INT 0
7.17 W_BY
Function
Copies the low-byte of IN to OUT.
Troubleshooting
If the high-byte > 0, then ENO = 0.
I/Os
Name Data type Description Default setting
Input IN WORD Input value 0
Output OUT BYTE Output value 0
8/21/2019 CFC Tutorial
49/156
Blocks for converting data types
7.18 W_DW
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 49
7.18
W_DW
Function
Copies the word of IN to the low-word of OUT.
Troubleshooting
n.a.
I/Os
Name Data type Default setting
Input IN WORD 0
Output OUT DWORD 0
7.19 W_I
Function
Copies the bit string of IN to OUT.
Troubleshooting
n.a.
I/Os
Name Data type Description Default setting
Input IN WORD Input value 0
Output OUT INT Output value 0
8/21/2019 CFC Tutorial
50/156
Blocks for converting data types
7.20 BO_BY
CFC Elementary Blocks
50 Programming and Operating Manual, 03/2009, A5E02109607-01
7.20
BO_BY
Function
This block converts the eight Boolean type input values to a BYTE type value and outputsthe result. 8 BOOL -> 1 BYTE conversions are performed as follows:The i-th bit of the BYTE value is set to 0 (or 1) when the i-th input value is 0 (or 1).(i = 0 to 7).
Troubleshooting
Not applicable
I/Os
Name Data type Default setting
IN0 BOOL 0
... ...
Inputs
IN7 BOOL 0
Output OUT BYTE 0
7.21
BO_W
Function
This block converts the 16 Boolean type input values to a WORD type value and outputs theresult. 16 BOOL -> 1 WORD conversions are performed as follows:The i-th bit of the WORD value is set to 0 (or 1) when the i-th input value is 0 (or 1)(i = 0 to 15).
Troubleshooting
Not applicable
I/Os
Name Data type Default setting
Inputs IN0 BOOL 0
... ...
IN15 BOOL 0
Output OUT WORD 0
8/21/2019 CFC Tutorial
51/156
Blocks for converting data types
7.22 BO_DW
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 51
7.22
BO_DW
Function
This block converts the 32 Boolean type input values to a DWORD type value and outputsthe result. 32 BOOL -> 1 DWORD conversions are performed as follows:The i-th bit of the DWORD value is set to 0 (or 1) when the i-th input value is 0 (or 1)(i = 0 to 31).
Troubleshooting
Not applicable
I/Os
Name Data type Default setting
IN0 BOOL 0
... ...
Inputs
IN31 BOOL 0
Output OUT DWORD 0
7.23
BY_BO
Function
This block converts the input value of data type BYTE to 8 values of data type BOOL andoutputs the result in 8 variables. IN bit0 is mapped to OUT0, IN bit1 to OUT1, etc.
Troubleshooting
n.a.
I/Os
Name Data type Default setting
Input IN BYTE 0
OUT0 BOOL 0
... ...
Outputs
OUT7 BOOL 0
8/21/2019 CFC Tutorial
52/156
Blocks for converting data types
7.24 W_BO
CFC Elementary Blocks
52 Programming and Operating Manual, 03/2009, A5E02109607-01
7.24
W_BO
Function
This block converts the input value of the WORD data type in 16 values of the BOOL datatype, which are created at the 16 outputs. IN-Bit0 is then converted to OUT0, IN-Bit1 toOUT1 etc.
Troubleshooting
Not applicable
I/Os
Name Data type Default setting
Input IN WORD 0
OUT0 BOOL 0
... ...
Outputs
OUT15 BOOL 0
7.25
DW_BO
Function
This block converts the input value of the DWORD data type in 32 values of the BOOL datatype, which are created at the 32 outputs. IN-Bit0 is then converted to OUT0, IN-Bit1 toOUT1 etc.
Troubleshooting
Not applicable
I/Os
Name Data type Default setting
Input IN DWORD 0
OUT0 BOOL 0
... ...
Outputs
OUT31 BOOL 0
8/21/2019 CFC Tutorial
53/156
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 53
Arithmetic blocks of the data type REAL
8
8.1 MATH_FP
CFC blocks of the MATH_FP family
This family contains the following floating-point arithmetic blocks for data of the type REAL.
ADD_R(Page 54) Addition of REAL values
SUB_R(Page 54) Subtraction of REAL values
MUL_R(Page 55) Multiplication of REAL values
DIV_R(Page 55) Division of REAL values
ABS_R(Page 58) Absolute value of REAL values
EPS_R(Page 65) Precision; approximation
NEG_R(Page 64) Negation of REAL values
MAXn_R(Page 56) Maximum of REAL values
MINn_R(Page 57) Minimum of REAL values
LIM_R(Page 64) Limiter of REAL values
CADD_R(Page 66) Controllable adder of REAL values
SQRT(Page 58) Square root
EXP(Page 59) Exponential functionPOW10(Page 59) Power of ten
LN(Page 60) Natural logarithm
LOG10(Page 60) Logarithm to base 10
SIN(Page 61) Sine function
COS(Page 61) Cosine function
TAN(Page 62) Tangent function
ASIN(Page 62) Arc sine function
ACOS(Page 63) Arc cosine function
ATAN(Page 63) Arc tangent function
POWXY(Page 67) General power functionSAMP_AVE(Page 68) Variable average
Note
The value range of real numbers is:-3.40282e^+38 ... -1.755e^-38 ... 0 ... 1.755e^-38 ... 3.40282e^+38
8/21/2019 CFC Tutorial
54/156
Arithmetic blocks of the data type REAL
8.2 ADD_R: Addition of REAL values
CFC Elementary Blocks
54 Programming and Operating Manual, 03/2009, A5E02109607-01
8.2
ADD_R: Addition of REAL values
Function
This block adds the values of inputs and outputs the sum.
OUT = IN1 + IN2
Troubleshooting
ENO = 0 on overflow or underflow.
I/Os
Name Data type Description Default setting
IN1 REAL Addend 1 0.0Inputs
IN2 REAL Addend 2 0.0
Output OUT REAL Sum 0.0
8.3
SUB_R: Subtraction of REAL values
Function
This block subtracts the value at input IN2 from input IN1 and outputs the difference.
OUT = IN1 - IN2
Troubleshooting
ENO = 0 on overflow and underflow.
I/Os
Name Data type Description Default setting
IN1 REAL Minuend 0.0Inputs
IN2 REAL Subtrahend 0.0
Output OUT REAL Difference 0.0
8/21/2019 CFC Tutorial
55/156
Arithmetic blocks of the data type REAL
8.4 MUL_R: Multiplication of REAL values
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 55
8.4
MUL_R: Multiplication of REAL values
Function
This block multiplies the inputs and outputs the product.
OUT = IN1 * IN2
Troubleshooting
ENO = 0 on overflow and underflow.
I/Os
Name Data type Description Default setting
IN1 REAL Multiplicand 0.0Inputs
IN2 REAL Multiplier 0.0
Output OUT REAL Product 0.0
8.5
DIV_R: Division of REAL values
Function
This block divides the value at input IN1 by the value at input IN2 and outputs the quotient.
OUT = IN1 / IN2
Troubleshooting
ENO is set to 0 on divisions by 0, overflow and underflow.
I/Os
Name Data type Description Default setting
IN1 REAL Dividend 0.0Inputs
IN2 REAL Divisor 0.0
Output OUT REAL Quotient 0.0
8/21/2019 CFC Tutorial
56/156
Arithmetic blocks of the data type REAL
8.6 MAXn_R: Maximum of REAL values
CFC Elementary Blocks
56 Programming and Operating Manual, 03/2009, A5E02109607-01
8.6
MAXn_R: Maximum of REAL values
Function
This block compares the inputs and outputs their maximum value.
OUT = MAX {IN1, ... , INn}
Blocks
Name Description
MAX2_R 2 inputs of type REAL
MAX4_R 4 inputs of type REAL
MAX8_R 8 inputs of type REAL
I/Os
Name Data type Description Default setting
IN1 REAL Input variable 1 0.0
...
Inputs
INn REAL Input variable n 0.0
Output OUT REAL Maximum value 0.0
8/21/2019 CFC Tutorial
57/156
Arithmetic blocks of the data type REAL
8.7 MINn_R: Minimum of REAL values
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 57
8.7
MINn_R: Minimum of REAL values
Function
This block compares the inputs and outputs their minimum value.
OUT = MIN {IN1, ... , INn}
Blocks
Name Description
MIN2_R 2 inputs of type REAL
MIN4_R 4 inputs of type REAL
MIN8_R 8 inputs of type REAL
I/Os
Name Data type Description Default setting
IN1 REAL Input variable 1 0.0
...
Inputs
INn REAL Input variable n 0.0
Output OUT REAL Maximum value 0.0
8/21/2019 CFC Tutorial
58/156
Arithmetic blocks of the data type REAL
8.8 ABS_R: Absolute value of REAL values
CFC Elementary Blocks
58 Programming and Operating Manual, 03/2009, A5E02109607-01
8.8
ABS_R: Absolute value of REAL values
Function
This block outputs the absolute value of the input.
OUT = | IN |
I/Os
Name Data type Description Default setting
Inputs IN REAL Input value 0.0
Output OUT REAL Absolute value 0.0
8.9
SQRT: Square root
Function
This block calculates and outputs the square root of the input.
OUT = SQRT(IN)
Troubleshooting
ENO = 0 and OUT = 0 if IN < 0.
I/Os
Name Data type Description Default setting
Input IN REAL Radicand 0.0
Output OUT REAL Square root 0.0
8/21/2019 CFC Tutorial
59/156
Arithmetic blocks of the data type REAL
8.10 EXP: Exponential function
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 59
8.10
EXP: Exponential function
Function
This block calculates and outputs the exponential function of the input. In this equation, "e" isEulers constant 2.71, the base of the natural logarithm.
OUT = e^IN
Troubleshooting
ENO = 0 on overflow and underflow.
ENO = 0 and OUT = 0 if IN < 0.
I/Os
Name Data type Description Default setting
Input IN REAL Exponent 0.0
Output OUT REAL Exponential function 0.0
8.11
POW10: Power-of-10 function
Function
This block calculates the power of 10INof the input and send the result to the output.
OUT = 10^IN
Troubleshooting
ENO = 0 with IN1 < -37.9 and IN1 > 38.5
I/Os
Name Data type Description Default setting
Input IN REAL Exponent 0.0
Output OUT REAL Power of ten 0.0
8/21/2019 CFC Tutorial
60/156
Arithmetic blocks of the data type REAL
8.12 LN: Natural logarithm
CFC Elementary Blocks
60 Programming and Operating Manual, 03/2009, A5E02109607-01
8.12
LN: Natural logarithm
Function
This block calculates and outputs the natural logarithm of the input.
OUT = LN (IN)
The variable at input IN must be positive.
Troubleshooting
ENO = 0 on overflow and underflow.
ENO = 0 and OUT = 0 if IN < 0.
I/Os
Name Data type Description Default setting
Input IN REAL Argument 0.0
Output OUT REAL nat. Logarithm 0.0
8.13
LOG10: Base-10 logarithm
Function
This block calculates and outputs the base-10 logarithm value of the input.
OUT = LOG10(IN)
The variable at input IN must be positive.
Troubleshooting
ENO = 0 on overflow and underflow.
ENO = 0 and OUT = 0 if IN < 0.
I/Os
Name Data type Description Default setting
Input IN REAL Argument 0.0
Output OUT REAL Logarithm 0.0
8/21/2019 CFC Tutorial
61/156
Arithmetic blocks of the data type REAL
8.14 SIN: Sin function
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 61
8.14
SIN: Sin function
Function
This block calculates and outputs the sine of the input. The variable at IN must be a radianvalue.
OUT = SIN(IN)
I/Os
Name Data type Description Default setting
Input IN REAL Argument 0.0
Output OUT REAL Sine 0.0
8.15
COS: Cos function
Function
This block calculates and outputs the cosine of the input. The variable at IN must be a radianvalue.
OUT = COS(IN)
I/Os
Name Data type Description Default setting
Input IN REAL Argument 0.0
Output OUT REAL Cosine 0.0
8/21/2019 CFC Tutorial
62/156
Arithmetic blocks of the data type REAL
8.16 TAN: Tan function
CFC Elementary Blocks
62 Programming and Operating Manual, 03/2009, A5E02109607-01
8.16
TAN: Tan function
Function
This block calculates and outputs the tangent of the input. The variable at IN must be aradian value.
OUT = TAN(IN)
I/Os
Name Data type Description Default setting
Input IN REAL Argument 0.0
Output OUT REAL Tangent 0.0
8.17
ASIN: Arc sin function
Function
This block calculates and outputs the arc sine of the input. The result is output as a radianvalue between - /2 and + /2. The range of the function argument must be between 1 and+1.
OUT = ASIN(IN)
I/Os
Name Data type Description Default setting
Input IN REAL Argument 0.0
Output OUT REAL Arc sine 0.0
8/21/2019 CFC Tutorial
63/156
Arithmetic blocks of the data type REAL
8.18 ACOS: Arc cos function
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 63
8.18
ACOS: Arc cos function
Function
This block calculates and outputs the arc cosine of the input. The result is output as a radianvalue between 0 and . The range of the function argument must be between 1 and +1.
OUT = ACOS(IN)
Troubleshooting
ENO = 0 at IN < -1 --> OUT = 3.14.
ENO = 0 at IN > 1 --> OUT = 0
I/Os
Name Data type Description Default setting
Input IN REAL Argument 0.0
Output OUT REAL Arc cosine 0.0
8.19
ATAN: Arc tan function
Function
This block calculates and outputs the arc tangent of the input. The result is output as aradian value between - /2 and + /2. The range of the function argument is the entire REALnumber range.
OUT = ATAN(IN)
I/Os
Name Data type Description Default setting
Input IN REAL Argument 0.0Output OUT REAL Arc tangent 0.0
8/21/2019 CFC Tutorial
64/156
Arithmetic blocks of the data type REAL
8.20 NEG_R
CFC Elementary Blocks
64 Programming and Operating Manual, 03/2009, A5E02109607-01
8.20
NEG_R
Function
This block outputs the input variable with inverted sign.
I/Os
Name Data type Description Default setting
Input IN REAL Input variable 0.0
Output OUT REAL Output variable 0.0
8.21
LIM_R: Limiter of REAL values
Function
This block compares the input variables IN, MAX and MIN. It checks if IN is within or outsidethe intervals limited by MIN and MAX. If the low limit MIN of the interval is greater than orequal to the high limit MAX, the output OUT = MAX and the outputs OUTU and OUTL are setto 1. IN > MAX represents a violation of the high limit, OUT = MAX, OUTU = 1 and OUTL =0. IN < MIN represents a violation of the low limit, OUT = MIN, OUTU = 0, OUTL = 1. If IN isbetween MIN and MAX, OUT = IN, OUTU = 0, OUTL = 0 are set.
I/Os
Name Data type Description Default setting
IN REAL Input variable 0.0
MIN REAL Low limit -100.0
Inputs
MAX REAL High limit 100.0
OUT REAL Output variable 0
OUTU BOOL Out of high limits 0
Outputs
OUTL BOOL Out of low limits 0
8/21/2019 CFC Tutorial
65/156
Arithmetic blocks of the data type REAL
8.22 EPS_R
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 65
8.22
EPS_R
Function
This block compares the absolute values of the inputs. If the absolute value of input IN MAX represents a violation of the high limit, OUT = MAX, OUTU = 1 and OUTL = 0. IN< MIN represents a violation of the low limit, OUT = MIN, OUTU = 0, OUTL = 1. If IN isbetween MIN and MAX, OUT = IN, OUTU = 0, OUTL = 0 are set.
Troubleshooting
ENO = 0 with MIN > MAX --> OUT = MAX; OUTU = OUTL = 1
I/Os
Name Data type Description Default setting
MAX INT High limit 0
IN INT Input variable 0
Inputs
MIN INT Low limit 0
OUTU BOOL Out of high limits 0
OUTL BOOL Out of low limits 0
Outputs
OUT INT Output variable 0
8/21/2019 CFC Tutorial
75/156
Arithmetic blocks of the data type INT and DINT
9.12 EPS_I: Accuracy approximation of INT values
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 75
9.12
EPS_I: Accuracy approximation of INT values
Function
This block compares the absolute value of the input IN with the value of the INTERVALinput. If the absolute amount of input IN < than the INTERVAL limit, output QA will be set to1 and output QN to 0. In this case the input variable IN is contained in the interval. Otherwiseoutput QA is set to 0 and output QN is set to 1. The input variable IN is then outside theinterval.
INTERVAL must have a positive value.If INTERVAL 0, then QA = 0.
Troubleshooting
ENO = 0 with IN = -32 768
I/Os
Name Data type Description Default setting
IN INT Input variable 0Inputs
INTERVAL INT Interval limit 0
QA BOOL Validation bit memory 0Outputs
QN BOOL Inverted validation bit memory 0
8/21/2019 CFC Tutorial
76/156
Arithmetic blocks of the data type INT and DINT
9.13 CADD_I: Controllable adder of INT values
CFC Elementary Blocks
76 Programming and Operating Manual, 03/2009, A5E02109607-01
9.13
CADD_I: Controllable adder of INT values
Function
This block adds the input variable IN to the output variable OUT when the CI input is set to 1and the RI and SI inputs are set to 0. If RI = 1, the OUT output is set to 0. If SI = 1 and RI =0, then OUT = IN.
Troubleshooting
ENO = 0 on overflow and underflow.
Truth table
RI SI CI OUT ENO
1 X X 0 1
0 1 X IN 1
0 0 1 OUT* + IN 1
0 0 0 OUT* 1
X is any value
OUT* is the old value from the last cycle
I/Os
Name Data type Description Default setting
IN INT Addend 0
RI BOOL Reset 0
SI BOOL Set 0
Inputs
CI BOOL Count 0
Output OUT INT Sum 0
8/21/2019 CFC Tutorial
77/156
Arithmetic blocks of the data type INT and DINT
9.14 ADD_DI: Addition of DINT values
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 77
9.14
ADD_DI: Addition of DINT values
Function
This block adds the values of inputs and outputs the sum.
OUT = IN1 + IN2
Troubleshooting
ENO = 0 on overflow and underflow.
I/Os
Name Data type Description Default setting
IN1 DINT Addend 1 0Inputs
IN2 DINT Addend 2 0
Output OUT DINT Sum 0
9.15
SUB_DI: Subtraction of DINT values
Function
This block subtracts the value at input IN2 from input IN1 and outputs the difference.
OUT = IN1 - IN2
Troubleshooting
ENO = 0 on overflow and underflow.
I/Os
Name Data type Description Default setting
IN1 DINT Minuend 0Inputs
IN2 DINT Subtrahend 0
Output OUT DINT Difference 0
8/21/2019 CFC Tutorial
78/156
Arithmetic blocks of the data type INT and DINT
9.16 MUL_DI: Multiplication of DINT
CFC Elementary Blocks
78 Programming and Operating Manual, 03/2009, A5E02109607-01
9.16
MUL_DI: Multiplication of DINT
Function
This block multiplies the inputs and outputs the product.
OUT = IN1 * IN2
Troubleshooting
ENO = 0 on overflow and underflow.
I/Os
Name Data type Description Default setting
IN1 DINT Multiplicand 0Inputs
IN2 DINT Multiplier 0
Output OUT DINT Product 0
9.17
DIV_DI: Division of DINT values
Function
This block divides the value at input IN1 by the value at input IN2 and outputs the quotient.
OUT = IN1 / IN2
Troubleshooting
ENO = 0 in the case of division by 0 and 2147483648 in the case of division by 1.
I/Os
Name Data type Description Default setting
IN1 DINT Dividend 0Inputs
IN2 DINT Divisor 0
Output OUT DINT Quotient 0
8/21/2019 CFC Tutorial
79/156
Arithmetic blocks of the data type INT and DINT
9.18 MOD_DI: Modulo function of DINT values
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 79
9.18
MOD_DI: Modulo function of DINT values
Function
This block outputs the modulo of an integer division DIV_DI(Page 78) of input IN1 by inputIN2.
Troubleshooting
ENO = 0 in the case of division by 0.
I/Os
Name Data type Description Default setting
IN1 DINT Dividend 0Inputs
IN2 DINT Divisor 0
Output OUT DINT Remainder 0
9.19
MAXn_DI: Maximum of DINT values
Function
This block compares the inputs and outputs their maximum value.
OUT = MAX {IN1, ... , INn}
Blocks
Name Description
MAX2_DI 2 inputs of the type DINT
MAX4_DI 4 inputs of the type DINT
MAX8_DI 8 inputs of the type DINT
I/Os
Name Data type Description Default setting
IN1 DINT Input variable 1 0
...
Inputs
INn DINT Input variable n 0
Output OUT DINT Maximum value 0
8/21/2019 CFC Tutorial
80/156
Arithmetic blocks of the data type INT and DINT
9.20 MINn_DI: Minimum of DINT values
CFC Elementary Blocks
80 Programming and Operating Manual, 03/2009, A5E02109607-01
9.20
MINn_DI: Minimum of DINT values
Function
This block compares the inputs and outputs their minimum value.
OUT = MIN {IN1, ... , INn}
Blocks
Name Description
MIN2_DI 2 inputs of the type DINT
MIN4_DI 4 inputs of the type DINT
MIN8_DI 8 inputs of the type DINT
I/Os
Name Data type Description Default setting
IN1 DINT Input variable 1 0
...
Inputs
INn DINT Input variable n 0
Output OUT DINT Maximum value 0
9.21
ABS_DI: Absolute value of DINT values
Function
This block outputs the absolute value of the input.
OUT = | IN |
Troubleshooting
ENO = 0 if IN = -2 147 483 648 (smallest negative number)
I/Os
Name Data type Description Default setting
Input IN DINT Input value 0
Output OUT DINT Absolute value 0
8/21/2019 CFC Tutorial
81/156
Arithmetic blocks of the data type INT and DINT
9.22 NEG_DI: Inverter for DINT values
CFC Elementary Blocks
Programming and Operating Manual, 03/2009, A5E02109607-01 81
9.22
NEG_DI: Inverter for DINT values
Function
This block outputs the input variable with inverted sign.
Troubleshooting
ENO = 0 if IN = -2 147 483 648
I/Os
Name Data type Description Default setting
Input IN DINT Input variable 0
Output OUT DINT Output variable 0
9.23 LIM_DI: Limiter for DINT values
Function
This block compares the input variables IN, MAX and MIN. It checks if IN is within or outsidethe intervals limited by MIN and MAX.
If the low limit MIN of the interval is greater than the high limit MAX, the output OUT = MAXand the outputs OUTU and OUTL are set to 1.
IN > MAX represents a violation of the high limit, OUT = MAX, OUTU = 1 and OUTL = 0. IN< MIN represents a violation of the low limit, OUT = M