Anda di halaman 1dari 292

FXCPU Structured Programming Manual Application Functions

FXCPU Structured Programming Manual [Application Functions]

FXCPU Structured Programming Manual


[Application Functions]

Manual number Manual revision Date

JY997D34801 G 5/2012

Foreword
This manual contains text, diagrams and explanations which will guide the reader through the safe and correct installation, use, and operation of the FX Series programmable controller function for structured programs. It should be read and understood before attempting to install or use the unit. Store this manual in a safe place so that you can take it out and read it whenever necessary. Always forward it to the end user.
This manual confers no industrial property rights or any rights of any other kind, nor does it confer any patent licenses. Mitsubishi Electric Corporation cannot be held responsible for any problems involving industrial property rights which may occur as a result of using the contents noted in this manual.

2009 MITSUBISHI ELECTRIC CORPORATION

FXCPU Structured Programming Manual [Application Functions] Outline Precautions


This manual provides information for the use of the FX Series Programmable Controllers. The manual has been written to be used by trained and competent personnel. The definition of such a person or persons is as follows; a) Any engineer who is responsible for the planning, design and construction of automatic equipment using the product associated with this manual should be of a competent nature, trained and qualified to the local and national standards required to fulfill that role. These engineers should be fully aware of all aspects of safety with regards to automated equipment. b) Any commissioning or service engineer must be of a competent nature, trained and qualified to the local and national standards required to fulfill that job. These engineers should also be trained in the use and maintenance of the completed product. This includes being completely familiar with all associated documentation for the said product. All maintenance should be carried out in accordance with established safety practices. c) All operators of the completed equipment should be trained to use that product in a safe and coordinated manner in compliance to established safety practices. The operators should also be familiar with documentation which is connected with the actual operation of the completed equipment. Note: the term 'completed equipment' refers to a third party constructed device which contains or uses the product associated with this manual This product has been manufactured as a general-purpose part for general industries, and has not been designed or manufactured to be incorporated in a device or system used in purposes related to human life. Before using the product for special purposes such as nuclear power, electric power, aerospace, medicine or passenger movement vehicles, consult with Mitsubishi Electric. This product has been manufactured under strict quality control. However when installing the product where major accidents or losses could occur if the product fails, install appropriate backup or failsafe functions in the system. When combining this product with other products, please confirm the standard and the code, or regulations with which the user should follow. Moreover, please confirm the compatibility of this product to the system, machine, and apparatus with which a user is using. If in doubt at any stage during the installation of the product, always consult a professional electrical engineer who is qualified and trained to the local and national standards. If in doubt about the operation or use, please consult the nearest Mitsubishi Electric representative. Since the examples indicated by this manual, technical bulletin, catalog, etc. are used as a reference, please use it after confirming the function and safety of the equipment and system. Mitsubishi Electric will accept no responsibility for actual use of the product based on these illustrative examples. This manual content, specification etc. may be changed without a notice for improvement. The information in this manual has been carefully checked and is believed to be accurate; however, you have noticed a doubtful point, a doubtful error, etc., please contact the nearest Mitsubishi Electric representative.

Registration
Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or other countries. CompactFlash is a trademark of SanDisk Corporation in the United States and other countries. The company name and the product name to be described in this manual are the registered trademarks or trademarks of each company.

FXCPU Structured Programming Manual [Application Functions]

Table of Contents

Table of Contents
Positioning of This Manual....................................................................................................... 8 Related Manuals ...................................................................................................................... 11 Generic Names and Abbreviations Used in Manuals .......................................................... 13

1. Outline

14

1.1 Outline of Structured Programs and Programming Languages............................................. 14


1.1.1 Outline of structured programs ...................................................................................................... 14 1.1.2 Programming languages ............................................................................................................... 15

1.2 PLC Series and Programming Software Version ..................................................................... 16 1.3 Cautions on Creation of Fundamental Programs .................................................................... 16
1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 I/O processing and response delay ............................................................................................... 16 Double output (double coil) operation and countermeasures........................................................ 17 Circuits not available in structured ladder programs and countermeasures.................................. 18 Handling of general flags............................................................................................................... 18 Handling of operation error flag ..................................................................................................... 21

2. Function/Operator List

22

2.1 Type Conversion Functions....................................................................................................... 22 2.2 Standard Functions Of One Numeric Variable ......................................................................... 24 2.3 Standard Arithmetic Functions.................................................................................................. 24 2.4 Standard Bit Shift Functions...................................................................................................... 24 2.5 Standard Bitwise Boolean Functions........................................................................................ 24 2.6 Standard Selection Functions ................................................................................................... 25 2.7 Standard Comparison Functions .............................................................................................. 25 2.8 Standard Character String Functions ....................................................................................... 25 2.9 Functions Of Time Data Types .................................................................................................. 26 2.10 Standard Function Blocks........................................................................................................ 26 2.11 Operator ..................................................................................................................................... 27
2.11.1 Arithmetic operations................................................................................................................... 27 2.11.2 Logical operations ....................................................................................................................... 27 2.11.3 Comparison operations ............................................................................................................... 27

3. Function Construction
3.1 3.2 3.3 3.4

28

Applied Function Expression and Execution Type ................................................................. 28 Labels........................................................................................................................................... 29 Device and Address.................................................................................................................... 32 EN and ENO ................................................................................................................................. 33

4. How to Read Explanation of Functions

34

FXCPU Structured Programming Manual [Application Functions]

Table of Contents

5. Applied Functions (Type Conversion Functions)


5.1 5.2 5.3 5.4

36

BOOL_TO_INT(_E) / Bit data word [signed] data conversion ............................................ 38 BOOL_TO_DINT(_E) / Bit data double word [signed] data conversion............................. 40 BOOL_TO_STR(_E) / Bit data string data conversion ........................................................ 42 BOOL_TO_WORD(_E) / Bit data word [unsigned]/ bit string [16-bit] data conversion............................................................................................. 44 5.5 BOOL_TO_DWORD(_E) / Bit data double word [unsigned]/ bit string [32-bit] data conversion............................................................................................. 46 5.6 BOOL_TO_TIME(_E) / Bit data time data conversion.......................................................... 48 5.7 INT_TO_DINT(_E) / Word [signed] data double word [signed] data conversion .............. 50 5.8 DINT_TO_INT(_E) / Double word [signed] data word [signed] data conversion .............. 52 5.9 INT_TO_BOOL(_E) / Word [signed] data bit data conversion ............................................ 54 5.10 DINT_TO_BOOL(_E) / Double word [signed] data bit data conversion........................... 56 5.11 INT_TO_REAL(_E) / Word [signed] data float (single precision) data conversion......... 58 5.12 DINT_TO_REAL(_E) / Double word [signed] data float (single precision) data conversion................................................................................. 60 5.13 INT_TO_STR(_E) / Word [signed] data string data conversion........................................ 62 5.14 DINT_TO_STR(_E) / Double word [signed] data string data conversion ........................ 64 5.15 INT_TO_WORD(_E) / Word [signed] data word [unsigned]/ bit string [16-bit] data conversion........................................................................................... 66 5.16 DINT_TO_WORD(_E) / Double word [signed] data word [unsigned]/ bit string [16-bit] data conversion........................................................................................... 68 5.17 INT_TO_DWORD(_E) / word [signed] data double word [unsigned]/ bit string [32-bit] data conversion........................................................................................... 70 5.18 DINT_TO_DWORD(_E) / Double word [signed] data double word [unsigned]/ bit string [32-bit] data conversion........................................................................................... 72 5.19 INT_TO_BCD(_E) / Word [signed] data BCD data conversion ......................................... 74 5.20 DINT_TO_BCD(_E) / Double word [signed] data BCD data conversion .......................... 76 5.21 INT_TO_TIME(_E) / Word [signed] data time data conversion......................................... 78 5.22 DINT_TO_TIME(_E) / Double word [signed] data time data conversion.......................... 80 5.23 REAL_TO_INT(_E) / Float (single precision) data word [signed] data conversion ........ 82 5.24 REAL_TO_DINT(_E) / Float (single precision) data double word [signed] data conversion................................................................................... 84 5.25 REAL_TO_STR(_E) / Float (single precision) data string data conversion .................... 86 5.26 WORD_TO_BOOL(_E) / Word [unsigned] / bit string [16-bit] data bit data conversion................................................................................................................... 89 5.27 DWORD_TO_BOOL(_E) / Double word [unsigned]/bit string [32-bit] data bit data conversion................................................................................................................... 91 5.28 WORD_TO_INT(_E) / Word [unsigned]/bit string [16-bit] data word [signed] data conversion ............................................................................................... 93 5.29 WORD_TO_DINT(_E) / Word [unsigned]/bit string [16-bit] data double word [signed] (signed) data conversion.................................................................... 95 5.30 DWORD_TO_INT(_E) / Double word [unsigned]/bit string [32-bit] data Word [signed] data conversion................................................................................................ 97 5.31 DWORD_TO_DINT(_E) / Double word [unsigned]/bit string [32-bit] data double word [signed] data conversion.................................................................................... 99 5.32 WORD_TO_DWORD(_E) / Word [unsigned]/bit string [16-bit] data double word [unsigned]/bit string [32-bit data conversion]................................................ 101 5.33 DWORD_TO_WORD(_E) / Double word [unsigned]/bit string[32-bit] data word [unsigned]/bit string [16-bit] data conversion............................................................ 103 5.34 WORD_TO_TIME(_E) / Word [unsigned]/bit string [16-bit] data time data conversion.............................................................................................................. 105 5.35 DWORD_TO_TIME(_E) / Double word [unsigned]/bit string [32-bit] data time data conversion .......................................................................................................... 107

FXCPU Structured Programming Manual [Application Functions]


5.36 5.37 5.38 5.39 5.40 5.41 5.42 5.43 5.44 5.45 5.46 5.47 5.48 5.49 5.50 5.51 5.52 5.53 5.54 5.55 5.56 5.57 5.58 5.59

Table of Contents

STR_TO_BOOL(_E) / String data bit data conversion .................................................... 109 STR_TO_INT(_E) / String data word [signed] data conversion...................................... 111 STR_TO_DINT(_E) / String data double word [signed] data conversion ...................... 113 STR_TO_REAL(_E) / String data float (single precision) data conversion ................... 115 STR_TO_TIME(_E) / String data time data conversion ................................................... 118 BCD_TO_INT(_E) / BCD data word [signed] data conversion........................................ 120 BCD_TO_DINT(_E) / BCD data double word [signed] data conversion ........................ 122 TIME_TO_BOOL(_E) / Time data bit data conversion ..................................................... 124 TIME_TO_INT(_E) / Time data word [signed] data conversion ...................................... 126 TIME_TO_DINT(_E) / Time data double word [signed] data conversion ....................... 128 TIME_TO_STR(_E) / Time data string data conversion .................................................. 130 TIME_TO_WORD(_E) / Time data word [unsigned]/ bit string [16-bit] data conversion......................................................................................... 132 TIME_TO_DWORD(_E) / Time data double word [unsigned]/ bit string [32-bit] data conversion......................................................................................... 134 BITARR_TO_INT(_E) / Bit array Word [signed] type, word [unsigned]/bit String [16-bit] data conversion ........................................................... 136 BITARR_TO_DINT(_E) / Bit array Double word [signed] type, double word [unsigned]/bit string [32-bit] data conversion............................................... 138 INT_TO_BITARR(_E) / Word [signed] data, word [unsigned]/ bit string [16-bit] data bit array conversion ..................................................................... 140 DINT_TO_BITARR(_E) / Double word [signed] data, double word [unsigned]/bit string [32-bit] data bit array conversion ........................... 142 CPY_BITARR(_E) / Bit array copy ......................................................................................... 144 GET_BIT_OF_INT(_E) / Specified bit read of word [signed] data ....................................... 146 SET_BIT_OF_INT(_E) / Specified bit write of word [signed] data....................................... 148 CPY_BIT_OF_INT(_E) / Specified bit copy of word [signed] data ...................................... 150 GET_BOOL_ADDR / Acquisition of start data...................................................................... 152 GET_INT_ADDR / Acquisition of start data .......................................................................... 153 GET_WORD_ADDR / Acquisition of start data..................................................................... 154

6. Applied Functions (Standard Functions Of One Numeric Variable)

155

6.1 ABS(_E) / Absolute value ......................................................................................................... 156

7. Applied Functions (Standard Arithmetic Functions)


7.1 7.2 7.3 7.4 7.5 7.6 7.7

158

ADD_E / Addition ...................................................................................................................... 159 SUB_E / Subtraction ................................................................................................................. 161 MUL_E / Multiplication.............................................................................................................. 163 DIV_E / Division......................................................................................................................... 165 MOD(_E) / Modulus operation.................................................................................................. 167 EXPT(_E) / Exponentiation ....................................................................................................... 169 MOVE(_E) / Move operation ..................................................................................................... 171

8. Applied Functions (Standard Bit Shift Functions)

173

8.1 SHL(_E) / Left shift .................................................................................................................... 174 8.2 SHR(_E) / Right shift ................................................................................................................. 176

FXCPU Structured Programming Manual [Application Functions]

Table of Contents

9. Applied Functions (Standard Bitwise Boolean Functions)


9.1 9.2 9.3 9.4

178

AND_E / Logical product .......................................................................................................... 179 OR_E / Logical sum .................................................................................................................. 181 XOR_E / exclusive logical sum ................................................................................................ 183 NOT(_E) / logical negation ....................................................................................................... 185

10. Applied Functions (Standard Selection Functions)


10.1 10.2 10.3 10.4 10.5

187

SEL(_E) / Selection ................................................................................................................. 188 MAXIMUM(_E) / Maximum selection...................................................................................... 190 MINIMUM(_E) / Minimum selection........................................................................................ 192 LIMITATION(_E) / Upper/Lower limit control ........................................................................ 194 MUX(_E) / Multiplexer ............................................................................................................. 196

11. Applied Functions (Standard Comparison Functions)


11.1 11.2 11.3 11.4 11.5 11.6

198

GT_E / Comparison................................................................................................................. 199 GE_E / Comparison................................................................................................................. 201 EQ_E / Comparison................................................................................................................. 203 LE_E / Comparison ................................................................................................................. 205 LT_E / Comparison ................................................................................................................. 207 NE_E / Comparison................................................................................................................. 209

12. Applied Functions (Standard Character String Functions)


12.1 12.2 12.3 12.4 12.5 12.6

211

MID(_E) / Extract mid string ................................................................................................... 212 CONCAT(_E) / String concatenation ..................................................................................... 215 INSERT(_E) / String insertion................................................................................................. 217 DELETE(_E) / String deletion ................................................................................................. 220 REPLACE(_E) / String replacement....................................................................................... 222 FIND(_E) / Searches a character string................................................................................. 225

13. Applied Functions (Functions Of Time Data Types)


13.1 13.2 13.3 13.4

228

ADD_TIME(_E) / Addition ....................................................................................................... 229 SUB_TIME(_E) / Subtraction .................................................................................................. 231 MUL_TIME(_E) / Multiplication............................................................................................... 233 DIV_TIME(_E) / Division.......................................................................................................... 235

14. Standard Function Blocks


14.1 14.2 14.3 14.4 14.5 14.6 14.7 14.8

237

R_TRIG(_E) / Rising edge detector........................................................................................ 238 F_TRIG(_E) / Falling edge detector ....................................................................................... 240 CTU(_E) / Up counter .............................................................................................................. 242 CTD(_E) / Down counter ......................................................................................................... 244 CTUD(_E) / Up/Down counter................................................................................................. 246 TP(_E) / Pulse timer ................................................................................................................ 248 TON(_E) / On delay timer........................................................................................................ 250 TOF(_E) / Off delay timer ........................................................................................................ 252

FXCPU Structured Programming Manual [Application Functions]

Table of Contents

14.9 COUNTER_FB_M / Counter function blocks ........................................................................ 254 14.10 TIMER_10_FB_M / Timer function blocks........................................................................... 256 14.11 TIMER_CONT_FB_M / Timer function blocks..................................................................... 257 14.12 TIMER_100_FB_M / Timer function blocks......................................................................... 259

15. Operator

260

15.1 ADD / Addition......................................................................................................................... 261 15.2 SUB / Subtraction.................................................................................................................... 262 15.3 MUL / Multiplication ................................................................................................................ 263 15.4 DIV / Division ........................................................................................................................... 264 15.5 MOD / Modulus operation....................................................................................................... 265 15.6 ** / Exponentiation .................................................................................................................. 266 15.7 AND / Logical product ............................................................................................................ 267 15.8 OR / Logical sum..................................................................................................................... 268 15.9 XOR / Exclusive logical sum .................................................................................................. 269 15.10 NOT / Logical negation ......................................................................................................... 271 15.11 GT / Comparison ................................................................................................................... 272 15.12 GE / Comparison ................................................................................................................... 273 15.13 EQ / Comparison ................................................................................................................... 274 15.14 LE / Comparison.................................................................................................................... 275 15.15 LT / Comparison.................................................................................................................... 276 15.16 NE / Comparison ................................................................................................................... 277

Appendix A: Correspondence between Devices and Addresses

278

Appendix B: Function/Operator List [by Type/in Alphabetic Order]

280

Appendix B-1 [By type] ............................................................................................................. 280 Appendix B-2 [In alphabetic order] ........................................................................................... 283

Warranty................................................................................................................................. 287 Revision History .................................................................................................................... 288

FXCPU Structured Programming Manual [Application Functions]

Positioning of This Manual


This manual explains application functions for structured programs provided by GX Works2. Refer to other manuals for devices, parameters and sequence instructions. Refer to each corresponding manual for analog, communication, positioning control and special units and blocks.

1. When using FX3G/FX3GC/FX3U/FX3UC PLCs


MELSEC-Q/L/F Structured Programming Manual (Fundamentals) (Additional Manual)
Q/L/F Structured This manual explains programming methods, specifications, functions, etc. required to create structured programs.

FXCPU Structured Programming Manual [Device & Common] (Additional Manual)


FX Structured This manual explains devices and parameters for structured programs provided by GX Works2.

FXCPU Structured Programming Manual [Basic & Applied Instruction]


FX Structured

(Additional Manual)
This manual explains sequence instructions for structured programs provided by GX Works2.

(This manual)
FX Structured

FXCPU Structured Programming Manual [Application Functions] (Additional Manual)


This manual explains application functions for structured programs provided by GX Works2.

FX3G/FX3U/FX3GC/FX3UC User's Manual- Analog Control Edition (Additional Manual)


FX3G FX3GC FX3U FX3UC This manual explains details of analog special function blocks and analog special adapters for FX3G/FX3U/FX3GC/FX3UC PLCs and PID instruction. Explanation of instructions and instructions used in program examples are expressed for GX Developer.

FX Series User's Manual -Data Communication Edition (Additional Manual)


FX This manual explains details of simple N:N link, parallel link, computer link, no-protocol communication (RS and RS2 instructions), programming communication and inverter communication for FX PLCs. Explanation of instructions and instructions used in program examples are expressed for GX Developer.

FX3G/FX3U/FX3GC/FX3UC Series User's Manual -Positioning Edition (Additional Manual)


FX3G FX3GC FX3U FX3UC This manual explains details of wiring, instructions and operations of the positioning function built in FX3G/FX3U/FX3GC/FX3UC PLC main units. Explanation of instructions and instructions used in program examples are expressed for GX Developer.

Special unit/block

Individual manuals (Manual supplied with product or additional Manual*1)


This manual explains details of each special unit/block. Explanation of instructions and instructions used in program examples are expressed for GX Developer. *1. Detailed explanation may be provided by a separate manual in some products.

FXCPU Structured Programming Manual [Application Functions]


2. When using FX1S/FX1N/FX1NC/FX2N/FX2NC PLCs
MELSEC-Q/L/F Structured Programming Manual (Fundamentals) (Additional Manual)
Q/L/F This manual explains programming methods, specifications, functions, etc. required to create structured programs.

Structured

FXCPU Structured Programming Manual [Device & Common] (Additional Manual)


FX This manual explains devices and parameters for structured programs provided by GX Works2.

Structured

FX

FXCPU Structured Programming Manual [Basic & Applied Instruction] (Additional Manual)
This manual explains sequence instructions for structured programs provided by GX Works2.

Structured

(This manual)
FX

FXCPU Structured Programming Manual [Application Functions] (Additional Manual)


This manual explains application functions for structured programs provided by GX Works2.

Structured

FX Series User's Manual -Data Communication Edition (Additional Manual)


FX This manual explains details of simple N:N link, parallel link, computer link, no-protocol communication (RS instruction), programming communication and inverter communication for FX PLCs. Explanation of instructions and instructions used in program examples are expressed for GX Developer and FX-PCS/WIN.

Individual manuals (Manual supplied with product or additional Manual *1 )


Special unit/block This manual explains details of each special unit/block. Explanation of instructions and instructions used in program examples are expressed for GX Developer and FX-PCS/WIN. *1. Detailed explanation may be provided by a separate manual in some products.

FXCPU Structured Programming Manual [Application Functions]


3. When using FX0S/FX0/FX0N/FXU/FX2C PLCs
MELSEC-Q/L/F Structured Programming Manual (Fundamentals) (Additional Manual)
Q/L/F This manual explains programming methods, specifications, functions, etc. required to create structured programs.

Structured

FXCPU Structured Programming Manual [Device & Common] (Additional Manual)


FX This manual explains devices and parameters for structured programs provided by GX Works2.

Structured

FX

FXCPU Structured Programming Manual [Basic & Applied Instruction] (Additional Manual)
This manual explains sequence instructions for structured programs provided by GX Works2.

Structured

(This manual)
FX

FXCPU Structured Programming Manual [Application Functions] (Additional Manual)


This manual explains application functions for structured programs provided by GX Works2.

Structured

FX Series User's Manual -Data Communication Edition (Additional Manual)


FX This manual explains details of parallel link, computer link, no-protocol communication (RS instruction) and programming communication for FX PLCs. Explanation of instructions and instructions used in program examples are expressed for GX Developer and FX-PCS/WIN.

Individual manuals (Manual supplied with product or additional Manual *1)


Special unit/block This manual explains details of each special unit/block. Explanation of instructions and instructions used in program examples are expressed for GX Developer and FX-PCS/WIN. *1. Detailed explanation may be provided by a separate manual in some products.

10

FXCPU Structured Programming Manual [Application Functions]

Related Manuals
This manual explains devices and parameters for structured programs provided by GX Works2. Refer to other manuals for sequence instructions and applied functions. This chapter introduces only reference manuals for this manual and manuals which describe the hardware information of PLC main units. Manuals not introduced here may be required in some applications. Refer to the manual of the used PLC main unit and manuals supplied together with used products. Contact the representative for acquiring required manuals.

Common among FX PLCs [structured]


Manual name MELSEC-Q/L/F Structured Programming Manual (Fundamentals) FXCPU Structured Programming Manual [Device & Common] FXCPU Structured Programming Manual [Basic & Applied Instruction] FXCPU Structured Programming Manual [Application Functions] Manual number SH-080782 JY997D26001 JY997D34701 JY997D34801 Supplied with product or Additional Manual Additional Manual Additional Manual Additional Manual Additional Manual Contents Programming methods, specifications, functions, etc. required to create structured programs Devices, parameters, etc. provided in structured projects of GX Works2 Sequence instructions provided in structured projects of GX Works2 Application functions provided in structured projects of GX Works2 Model name code 13JW06 09R925 09R926 09R927

FX3G/FX3GC/FX3U/FX3UC PLCs
Manual name PLC main unit I/O specifications, wiring and installation of the PLC main unit FX3U extracted from the FX3U Series Users Manual - Hardware Edition. For detailed explanation, refer to the FX3U Series Users Manual - Hardware Edition. Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX3U PLC main unit. I/O specifications, wiring and installation of the PLC main unit FX3UC (D, DS, DSS) extracted from the FX3UC Series Users Manual - Hardware Edition. For detailed explanation, refer to the FX3UC Series Users Manual - Hardware Edition. I/O specifications, wiring and installation of the PLC main unit FX3UC-32MT-LT-2 extracted from the FX3UC Series Users Manual - Hardware Edition. For detailed explanation, refer to the FX3UC Series Users Manual - Hardware Edition. Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX3UC PLC main unit. I/O specifications, wiring and installation of the PLC main unit FX3G extracted from the FX3G Series Users Manual - Hardware Edition. For detailed explanation, refer to the FX3G Series Users Manual - Hardware Edition. Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX3G PLC main unit. I/O specifications, wiring and installation of the PLC main unit FX3GC extracted from the FX3GC Series User's Manual - Hardware Edition. For detailed explanation, refer to the FX3GC Series User's Manual - Hardware Edition. Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX3GC PLC main unit. Manual number Supplied with product or Additional Manual Contents Model name code

FX3U Series Hardware Manual

JY997D18801

Supplied with product

FX3U Series User's Manual- Hardware Edition

JY997D16501

Additional Manual

09R516

FX3UC (D, DS, DSS) Series Hardware Manual

JY997D28601

Supplied with product

FX3UC-32MT-LT-2 Hardware Manual

JY997D31601

Supplied with product

FX3UC Series User's Manual Hardware Edition

JY997D28701

Additional Manual

09R519

FX3G Series Hardware Manual

JY997D33401

Supplied with product

FX3G Series User's Manual- Hardware Edition

JY997D31301

Additional Manual

09R521

FX3GC Series Hardware Manual

JY997D45201

Supplied with product

FX3GC Series User's ManualHardware Edition

JY997D45401

Additional Manual

09R533

11

FXCPU Structured Programming Manual [Application Functions]


Supplied with product or Additional Manual Model name code

Manual name Programming FX3G/FX3U/FX3GC/FX3UC User's Manual- Analog Control Edition FX Series User's Manual -Data Communication Edition FX3G/FX3U/FX3GC/FX3UC Series User's Manual -Positioning Edition FX3U-CF-ADP User's Manual

Manual number

Contents

JY997D16701

Additional Manual

Detaileds about the analog special function block (FX3U-4AD, FX3U-4DA, FX3UC-4AD) and analog special adapter (FX3U-****-ADP). Details about simple N : N link, parallel link, computer link and no-protocol communication (RS instruction and FX2N-232IF). Details about the positioning function built in the FX3G/FX3U/FX3GC/FX3UC Series. Describes details of the FX3U-CF-ADP CF card special adapter.

09R619

JY997D16901 JY997D16801 JY997D35401

Additional Manual Additional Manual Additional Manual

09R715 09R620 09R720

FX1S/FX1N/FX1NC/FX2N/FX2NC PLCs
Manual name PLC main unit FX1S HARDWARE MANUAL JY992D83901 Additional Manual Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX1S PLC main unit. Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX1N PLC main unit. Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX2N PLC main unit. Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX1NC PLC main unit. (Japanese only) Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX2NC PLC main unit. Details about simple N : N link, parallel link, computer link and no-protocol communication (RS instruction and FX2N-232IF). Manual number Supplied with product or Additional Manual Contents Model name code

FX1N HARDWARE MANUAL

JY992D89301

Additional Manual

FX2N HARDWARE MANUAL

JY992D66301

Additional Manual

09R508

FX1NC HARDWARE MANUAL

JY992D92101

Additional Manual

09R505

FX2NC HARDWARE MANUAL Programming FX Series User's Manual -Data Communication Edition

JY992D76401

Additional Manual

09R509

JY997D16901

Additional Manual

09R715

FX0S/FX0/FX0N/FXU/FX2C PLCs [whose production is finished]


Manual name PLC main unit FX0/FX0N HARDWARE MANUAL JY992D47501 Supplied with product Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX0/FX0N PLC main unit. Details about the hardware including I/O specifications, wiring, installation and maintenance of the FX0S PLC main unit. Details about the hardware including I/O specifications, wiring, installation and maintenance of the FXU/FX2C PLC main unit. Details about simple N : N link, parallel link, computer link and no-protocol communication (RS instruction and FX2N-232IF). Manual number Supplied with product or Additional Manual Contents Model name code

FX0S HARDWARE MANUAL

JY992D55301

Supplied with product

FX/FX2C HARDWARE MANUAL Programming FX Series User's Manual -Data Communication Edition

JY992D47401

Supplied with product

JY997D16901

Additional Manual

09R715

Manuals of models whose production is finished Production is finished for FX0S/FX0/FX0N/FXU/FX2C PLCs.

12

FXCPU Structured Programming Manual [Application Functions]

Generic Names and Abbreviations Used in Manuals


Abbreviation/generic name PLCs FX3U Series or FX3U PLC FX3UC Series or FX3UC PLC FX3G Series or FX3G PLC FX3GC Series or FX3GC PLC FX2N Series or FX2N PLC FX2NC Series or FX2NC PLC FX1N Series or FX1N PLC FX1NC Series or FX1NC PLC FX1S Series or FX1S PLC FXU Series or FXU PLC FX2C Series or FX2C PLC FX0N Series or FX0N PLC FX0S Series or FX0S PLC FX0 Series or FX0 PLC Special adapters CF card special adapter CF-ADP Programming language ST Structured ladder FBD Manuals Q/L/F Structured Programming Manual (Fundamentals) FX Structured Programming Manual [Device & Common] FX Structured Programming Manual [Basic & Applied Instruction] FX Structured Programming Manual [Application Functions] COMMUNICATION CONTROL EDITION ANALOG CONTROL EDITION POSITIONING CONTROL EDITION Abbreviation of MELSEC-Q/L/F Structured Programming Manual [Fundamentals] Abbreviation of FXCPU Structured Programming Manual [Device & Common] Abbreviation of FXCPU Structured Programming Manual [Basic & Applied Instruction] Abbreviation of FXCPU Structured Programming Manual [Application Functions] Abbreviation of FX Series User's Manual-DATA COMMUNICATION CONTROL EDITION Abbreviation of FX3G/FX3U/FX3GC/FX3UC Series User's Manual-ANALOG CONTROL EDITION Abbreviation of FX3G/FX3U/FX3GC/FX3UC Series User's Manual-POSITIONING CONTROL EDITION Abbreviation of structured text language Abbreviation of ladder diagram language Abbreviation of function block diagram language Generic name of CF card special adapters FX3U-CF-ADP Generic name of FX3U Series PLCs Generic name of FX3UC Series PLCs Generic name of FX3G Series PLCs Generic name of FX3GC Series PLCs Generic name of FX2N Series PLCs Generic name of FX2NC Series PLCs Generic name of FX1N Series PLCs Generic name of FX1NC Series PLCs These products can only used in Japan. Generic name of FX1S Series PLCs Generic name of FXU(FX, FX2) Series PLCs Generic name of FX2C Series PLCs Generic name of FX0N Series PLCs Generic name of FX0S Series PLCs Generic name of FX0 Series PLCs Name

13

FXCPU Structured Programming Manual [Application Functions]

1 Outline
1.1 Outline of Structured Programs and Programming Languages

1.

Outline
This manual explains applied functions for structured programs provided by GX Works2. Refer to a different manual for devices, parameters and sequence instructions. Refer to the following manual for labels, data types and programming languages for structured programs: Q/L/F Structured Programming Manual (Fundamentals)

1.1
1.1.1

Outline of Structured Programs and Programming Languages


Outline of structured programs
You can construct two or more programs (program blocks) into one program. Because you can divide the entire machine processing into small sub processes and create a program for each sub process, you can efficiently create a program for a large system.

1. Structured program
Program structuring is a technique to divide the contents of control executed by the PLC CPU into hierarchical small units (blocks) of processing, and then construct a program. By using this technique, you can design a program while recognizing structuring of a sequence program. Advantages of hierarchical program You can examine the outline of a program at first, and then design its details gradually. Program blocks located at the lowest level in the hierarchy are extremely simple and highly independent. Advantages of program consisting of program blocks Because the processing of each block is clear, the entire program is easy to understand. The entire program can be divided into several blocks that are created by several people. The program reusability is improved, and the development efficiency is improved accordingly.

2. Improved reusability of programs


You can save program blocks in a library. Program resources in the library can be shared, and often used again.

14

FXCPU Structured Programming Manual [Application Functions] 1.1.2 Programming languages

1 Outline
1.1 Outline of Structured Programs and Programming Languages

1
Outline

The following programming languages can be used in each program block.

Graphic languages
1. Structured ladder language
This graphic language is created based on the relay circuit design technology. A circuit always starts from the bus line located on the left side. The structured ladder language consists of contacts, coils, functions and function blocks. These components are connected with vertical lines and horizontal lines.
1 X000 Y000 2 X001 Y000

2
Function/ Operator List

3
Output Y000
Function Construction

X001 D0 EN s

MOV ENO d

D2

4
How to Read Explanation of Functions

When X001 is ON, the contents of D0 are transferred to D2.

2. FBD [Function Block Diagram language]


FBD is a graphic language easy to understand visually. You can easily create programs by connecting parts (functions and function blocks) for special processing, variables and constants along the flow of data and signals to improve the programming efficiency.
1 D0 D2 EQ X000 When the contents X001 of D0 are equivalent X002 AND K4X010 INT_TO_WORD_E EN ENO _INT

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

to the contents of D2, EQ turns ON.

XOR D30 D20

Text language
1. ST (Structured text) language
The ST language can describe control achieved by syntax using selective branches with conditional statements and repetition by repetitive statements in the same way as high-level languages such as C language. By using the ST language, you can create simple programs easy to understand.
Y000:=(X000 OR Y000) AND NOT X001; IF X001 THEN D2:=D0; (*When X001 is ON, the contents of D0 are transferred to D2.*) END_IF; IF X002 THEN D4:=D4+1; (*When X002 is ON, the contents of D4 are added by "1".*) ELSE D6:=D6+1; (*When X002 is OFF, the contents of D6 are added by "1".*) END_IF;

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

15

FXCPU Structured Programming Manual [Application Functions]

1 Outline
1.2 PLC Series and Programming Software Version

1.2

PLC Series and Programming Software Version


PLC Series FX3UFX3UC FX3G FX2NFX2NC FX1NFX1NC FX1S FXU/FX2C FX0N FX0FX0S FX3GC Ver.1.77F or later GX Works2 (SW1DNC-GXW2-E) Ver. 1.08J or later Software package name (model name) GX Works2 version

1.3

Cautions on Creation of Fundamental Programs


This section explains cautions on programming. Refer to the following manual for cautions on structured programs and programming languages: Q/L/F Structured Programming Manual (Fundamentals) Refer to the following programming manual for detailed operations of and cautions on devices and parameters: FX Structured Programming Manual [Device & Common]

1.3.1

I/O processing and response delay


1. Operation timing of I/O relays and response delay
FX PLCs execute the I/O processing by repeating the processing (1) to processing (3). Accordingly, the control executed by PLCs contains not only the drive time of input filters and output devices but also the response delay caused by the operation cycle. Acquiring the latest I/O information For acquiring the latest input information or immediately outputting the operation result in the middle of the operation cycle shown above, the I/O refresh instruction (REF) is available.
(1)
[Input processing] terminals is received at one time. Input image memory is read. Input image is read, and

The ON/OFF status of input

Scan time (operation cycle)

(2) [Program processing]


Image memory of each device is updated.

operation is executed according to program.

[Output processing] Output Result is transferred to devices Batch I/O method output latch memory. are driven.

(3)

(Refresh method)

2. Short pulses cannot be received.


The ON duration and OFF duration of inputs in PLCs require longer time than "PLC cycle time + Input filter response delay". When the response delay "10 ms" of the input filter is considered and the cycle time is supposed as "10 ms", the ON duration and OFF duration should be at least 20 ms respectively. Accordingly, PLCs cannot handle input pulses at 25 Hz (= 1000 /(20 + 20)) or more. However, the situation can be improved by PLC special functions and applied instructions. Convenient functions for improvement By using the following functions, PLCs can receive pulses shorter than the operation cycle: High speed counter function Input interrupt function Pulse catch function Input filter value adjustment function

OFF

This "input ON" can be received. "Input ON" cannot This "input OFF" cannot be received. be received. ON ON OFF Program processing Program processing Program processing Program processing Operation cycle

Input processing Output processing

Time)

16

FXCPU Structured Programming Manual [Application Functions] 1.3.2

1 Outline
1.3 Cautions on Creation of Fundamental Programs

Double output (double coil) operation and countermeasures


This subsection explains the double output (double coil) operation and countermeasures.

1
Outline

1. Operation of double outputs


When a coil (output variable) is used twice (double coils) in another program block to be executed or in the same program block, the PLC gives priority to the latter coil. Suppose that the same coil Y003 is used in two positions as shown in the right figure. For example, suppose that X001 is ON and X002 is OFF. In the first coil Y003, the image memory is set to ON and the output Y004 is also set to ON because the input X001 is ON. In the second coil Y003, however, the image memory is set to OFF because the input X002 is OFF. As a result, the actual output to the outside is "Y003: OFF, Y004: ON".
X002 X001

2
Function/ Operator List

Input processing X001=ON X002=OFF First Y003

3
Function Construction

Y003

Y004

Second

4
How to Read Explanation of Functions

Y003

Output processing Y003=OFF Y004=ON

5
Applied Functions (Type Conversion Functions)

2. Countermeasures against double outputs


Double outputs (double coils) do not cause an illegal input error (program error), but the operation is complicated as described above. Change the program as shown in the example below.
A B Y000 A C Ignored C D E Y000 D B E Y000

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

A Or C D M100 M101

M100

M101

8
Applied Functions (Standard Bit Shift Functions)

Y000

9
Applied Functions (Standard Bitwise Boolean Functions)

The SET and RST instructions or jump instruction can be used instead, or a same output coil can be programmed at each state using step ladder instructions STL and RET. When you use the step ladder instructions STL and RET, note that the PLC regards it as double coils if you program, inside the state, an output coil located outside the RET instruction from another program block or the STL instruction.

10
Applied Functions (Standard Selection Functions)

17

FXCPU Structured Programming Manual [Application Functions] 1.3.3

1 Outline
1.3 Cautions on Creation of Fundamental Programs

Circuits not available in structured ladder programs and countermeasures


1. Bridge circuit
A circuit in which the current flows in both directions should be changed as shown in the right figure (so that a circuit without D and a circuit without B are connected in parallel).
A B F C A A C D C E D E B F

2. Coil connection position


You can program a contact on the right side of a coil. In this case, make sure to program a coil (including a function or function block) at the end of the circuit.
A B C E D A B D E C

Or

1.3.4

Handling of general flags


The following flags are valid in general sequence instructions: (Examples) M8020:Zero flag M8021:Borrow flag M8022:Carry flag M8029:Instruction execution complete flag M8090:Block comparison signal*1 *1 M8328:Instruction non-execution flag M8329:Instruction execution abnormal complete flag*2 M8304:Zero flag*1 M8306:Carry flag*1 *1. *2. Supported only in FX3U/FX3UC PLCs. Supported only in FX3U/FX3UC/FX3G/FX3GC PLCs.

Each of these flags turns ON or OFF every time the PLC executes a corresponding instruction. These flags do not turn ON or OFF when the PLC does not execute a corresponding instruction or when an error occurs. Because these flags are related to many sequence instructions, their ON/OFF status changes every time the PLC executes each corresponding instruction. Refer to examples in the next page, and program a flag contact just under the target sequence instruction.

18

FXCPU Structured Programming Manual [Application Functions]

1 Outline
1.3 Cautions on Creation of Fundamental Programs

1. Program containing many flags (Example of instruction execution complete flag M8029)
If you program the instruction execution complete flag M8029 twice or more together for two or more sequence instructions which actuate the flag M8029, you cannot judge easily by which sequence instruction the flag M8029 is controlled. In addition, the flag M8029 does not turn ON or OFF correctly for each corresponding sequence instruction. Refer to the next page when you would like to use the flag M8029 in any position other than the position just under the corresponding sequence instruction.

1
Outline

2
Function/ Operator List

Good example
M8000 X010 1 M8029 Execution is completed. D0 10 EN s1 s2 EN s1 s2 DSW ENO d1 d2 MUL ENO d

Y010 D0

3
Function Construction

M8029 works as a flag to indicate that execution of DSW is completed.

Number of output pulses

4
How to Read Explanation of Functions

X000

M0 S DPLSY EN ENO s1 d s2 M0 R

M0
M8029 works as a flag to indicate that execution of DPLSY is completed.

5
Applied Functions (Type Conversion Functions)

1000 Number of output pulses M8029 Execution is completed.

Y000

6
Applied Functions (Standard Functions Of One Numeric Variable)

Bad example

M8029 works as a flag to indicate that execution of DPLSY (on the lower side) is completed.

M8029 Execution is completed. M8000 X010 1 X000

M0 R

Program for DPLSY (on the upper side)

M8029 works as a flag to indicate that execution of DSW is completed.

EN s1 s2

DSW ENO d1 d2

7
Applied Functions (Standard Arithmetic Functions)

Y010 D0

M0 S DPLSY EN ENO s1 d s2 MUL ENO d DPLSY(on the upper side) Y000

8
Applied Functions (Standard Bit Shift Functions)

M0 1000 Number of M8029 works as a output pulses flag to indicate that execution of DPLSY (on the upper side) M8029 is completed. Execution is D0 completed. 10 M1 1000 Number of output pulses2

Program for DSW Number of output pulses

EN s1 s2

9
Applied Functions (Standard Bitwise Boolean Functions)

DPLSY EN ENO s1 d s2

DPLSY(on the lower side) Y001

10
Applied Functions (Standard Selection Functions)

19

FXCPU Structured Programming Manual [Application Functions]

1 Outline
1.3 Cautions on Creation of Fundamental Programs

2. Introduction of a method to use flags in any positions other than positions just under sequence instructions
If two or more sequence instructions are programmed, general flags turn ON or OFF when each corresponding instruction is executed. Accordingly, when using a general flag in any position other than a position just under a sequence instruction, set to ON or OFF another device (variable) just under the sequence instruction, and then use the contact of such device (variable) as the command contact.

M8000 X010 1 M8029 Execution is completed. M0 1000 Number of output pulses M8029 Execution is completed. EN s1 s2

DSW execution complete flag M8029 is changed to M100.

DSW ENO d1 d2

Y010 D0

M100

DPLSY execution complete flag M8029 is changed to M200.

DPLSY EN ENO s1 d s2 M0 R M200

Y000

It works as the DSW execution complete flag. M100 D0 10 EN s1 s2 MUL ENO d

Number of output pulses

It works as the DPLSY execution complete flag. M200

Y030

20

FXCPU Structured Programming Manual [Application Functions] 1.3.5 Handling of operation error flag

1 Outline
1.3 Cautions on Creation of Fundamental Programs

1
Outline

When there is an error in the instruction construction, target device or target device number range and an error occurs while operation is executed, the following flag turns ON and the error information is stored.

1. Operation error
Error flag M8067 Device which stores error code D8067 Device which stores error occurrence step FX0S/FX0/FX0N/FX1S/FX1N/FX1NC/ FXU/FX2C/FX2N/FX2NC/FX3G/FX3GC D8069*1 FX3U/FX3UC D8315, D8314

2
Function/ Operator List

*1.

When an error occurs in a step up to the step No. 32767 in the FX3U/FX3UC PLC, you can check the error occurrence step also in D8069 (16 bits).

3
Function Construction

When an operation error has occurred, M8067 turns ON, D8067 stores the operation error code, and the specified device (shown in the table above) stores the error occurrence step. When another error occurs in another step, the stored data is updated in turn to the error code and step number of the new error. (These devices are set to OFF when errors are cleared.) When the PLC mode changes from STOP to RUN, these devices are cleared instantaneously, and then turn ON again if errors have not been cleared.

4
How to Read Explanation of Functions

2. Operation error latch


Error flag M8068 Device which stores error code Device which stores error occurrence step FX0S/FX0/FX0N/FX1S/FX1N/FX1NC/ FXU/FX2C/FX2N/FX2NC/FX3G/FX3GC D8068*2 FX3U/FX3UC D8313, D8312

5
Applied Functions (Type Conversion Functions)

*2.

When an error occurs in a step up to the step No. 32767 in the FX3U/FX3UC PLC, you can check the error occurrence step also in D8068 (16 bits).

6
Applied Functions (Standard Functions Of One Numeric Variable)

When an operation error has occurred, M8068 turns ON, and the device shown in the table above stores the error occurrence step. Even if another error occurs in another step, the stored data is not updated and remains held until these devices are forcibly set to OFF or until the power is turned OFF.

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

21

FXCPU Structured Programming Manual [Application Functions]

2 Function/Operator List
2.1 Type Conversion Functions

2.

Function/Operator List
This chapter introduces a list of functions and operators available in programming.

2.1

Type Conversion Functions


Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C)

Function name

Function

Reference

FX0(S)

FX0N

FX1S

BOOL_TO_INT(_E) BOOL_TO_DINT(_E) BOOL_TO_STR(_E)

Converts bit data into word [signed] data. Converts bit data into double word [signed] data. Converts bit data into string data.

3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

3 3

3 3

3 3

3 3

3 3

3 3

3 3

Section 5.1 Section 5.2 Section 5.3

Converts bit data into word [unsigned]/bit string BOOL_TO_WORD(_E) [16-bit] data. BOOL_TO_DWORD (_E) BOOL_TO_TIME(_E) INT_TO_DINT(_E) DINT_TO_INT(_E) INT_TO_BOOL(_E) DINT_TO_BOOL(_E) INT_TO_REAL(_E) DINT_TO_REAL(_E) INT_TO_STR(_E) DINT_TO_STR(_E) INT_TO_WORD(_E) DINT_TO_WORD(_E) INT_TO_DWORD(_E) DINT_TO_DWORD (_E) INT_TO_BCD(_E) DINT_TO_BCD(_E) INT_TO_TIME(_E) DINT_TO_TIME(_E) REAL_TO_INT(_E) REAL_TO_DINT(_E) REAL_TO_STR(_E) WORD_TO_BOOL(_E) Converts bit data into double word [unsigned]/bit string [32-bit] data. Converts bit data into time data. Converts word [signed] data into double word [signed] data Converts double word [signed] data into word [signed] data. Converts word [signed] data into bit data. Converts double word [signed] data into bit data. Converts word [signed] data into float (single precision) data. Converts double word [signed] data into float (single precision) data. Converts word [signed] data into string data. Converts double word [signed] data into string data. Converts word [signed] data into word [unsigned]/bit string [16-bit] data. Converts double word [signed] data into word [unsigned]/bit string [16-bit] data. Converts word [signed] data into double word [unsigned]/bit string [32-bit] data. Converts double word [signed] data into double word [unsigned]/bit string[32-bit] data. Converts word [signed] data into BCD data. Converts double word [signed] data into BCD data. Converts word [signed] data into time data. Converts double word [signed] data into time data. Converts float (single precision) data into word [signed] data. Converts float (single precision) data into double word [signed] data. Converts float (single precision) data into string data. Converts word [unsigned]/bit string [16-bit] data into bit data.

3 3 3 3 3 3 3 *1 *1

3 3 3 3 3 3 3 3 3

3 3 3 3 3 3 3

3 3 3 3 3 3 3

3 3 3 3 3 3 3

3 3 3 3 3 3 3

3 3 3 3 3 3 3

Section 5.4 Section 5.5 Section 5.6 Section 5.7 Section 5.8 Section 5.9 Section 5.10 Section 5.11 Section 5.12 Section 5.13 Section 5.14

3 3 3 3 3 3 3 3 *1 *1

3 3 3 3 3 3 3 3 3 3

3 3 3 3 3 3 3 3

3 3 3 3 3 3 3 3

3 3 3 3 3 3 3 3

3 3 3 3 3 3 3 3

3 3 3 3 3 3 3 3

Section 5.15 Section 5.16 Section 5.17 Section 5.18 Section 5.19 Section 5.20 Section 5.21 Section 5.22 Section 5.23 Section 5.24 Section 5.25

Section 5.26

*1.

The function is provided in the FX3G Series Ver.1.10 or later.

22

FXCPU Structured Programming Manual [Application Functions]


Applicable PLC

2 Function/Operator List
2.1 Type Conversion Functions

1
Outline
FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C) Function name Function Reference FX0(S) FX0N FX1S

DWORD_TO_BOOL (_E) WORD_TO_INT(_E) WORD_TO_DINT(_E) DWORD_TO_INT(_E) DWORD_TO_DINT (_E) WORD_TO_DWORD (_E) DWORD_TO_WORD (_E) WORD_TO_TIME(_E) DWORD_TO_TIME (_E) STR_TO_BOOL(_E) STR_TO_INT(_E) STR_TO_DINT(_E) STR_TO_REAL(_E) STR_TO_TIME(_E) BCD_TO_INT(_E) BCD_TO_DINT(_E) TIME_TO_BOOL(_E) TIME_TO_INT(_E) TIME_TO_DINT(_E) TIME_TO_STR(_E) TIME_TO_WORD(_E) TIME_TO_DWORD (_E) BITARR_TO_INT(_E)

Converts double word [unsigned]/bit string [32bit] data into bit data. Converts word [unsigned]/bit string [16-bit] data into word [signed] data. Converts word [unsigned]/bit string [16-bit] data into double word [signed] data. Converts double word [unsigned]/bit string [32bit] data into word [signed] data. Converts double word [unsigned]/bit string [32bit] data into double word [signed] data. Converts word [unsigned]/bit string [16-bit] data into double word [unsigned]/bit string [32-bit] data. Converts double word [unsigned]/bit string [32bit] data into word [unsigned]/bit string [16-bit] data. Converts word [unsigned]/bit string [16-bit] data into time data. Converts double word [unsigned]/bit string [32bit] data into time data. Converts string data into bit data. Converts string data into word [signed] data. Converts string data into double word [signed] data. Converts string data into float (single precision) data. Converts string data into time data. Converts BCD data into word [signed] data. Converts BCD data into double word [signed] data. Converts time data into bit data. Converts time data into word [signed] data. Converts time data into double word [signed] data. Converts time data into string data. Converts time data into word [unsigned]/bit string [16-bit] data. Converts time data into double word [unsigned]/ bit string [32-bit] data. Converts specified number of bits of a bit array into word [signed] data or word [unsigned]/bit string [16-bit] data.

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

Section 5.27 Section 5.28 Section 5.29 Section 5.30 Section 5.31

2
Function/ Operator List

3
Function Construction

Section 5.32

Section 5.33

4
How to Read Explanation of Functions

3 3 3 3 3 3 3 3 3 3 3 3 3 3 3

3 3

3 3

3 3

3 3

3 3

3 3

3 3

Section 5.34 Section 5.35 Section 5.36 Section 5.37 Section 5.38 Section 5.39 Section 5.40

5
Applied Functions (Type Conversion Functions)

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

Section 5.41 Section 5.42 Section 5.43 Section 5.44 Section 5.45 Section 5.46

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

3 3

3 3

3 3

3 3

3 3

3 3

3 3

Section 5.47 Section 5.48

Section 5.49

8
Applied Functions (Standard Bit Shift Functions)

Converts specified number of bits of a bit array BITARR_TO_DINT(_E) into double word [signed] data or double word [unsigned]/bit string [32-bit] data. INT_TO_BITARR(_E) Outputs low-order "n" bits of word [signed] data or word [unsigned]/bit string [16-bit] data to a bit array.

Section 5.50

Section 5.51

9
Applied Functions (Standard Bitwise Boolean Functions)

Outputs low-order "n" bits of double word DINT_TO_BITARR(_E) [signed] data or double word [unsigned]/bit string [32-bit] data to a bit array. CPY_BITARR(_E) Copies specified number of bits of a bit array. Reads a value of a specified bit of word [signed] GET_BIT_OF_INT(_E) data. SET_BIT_OF_INT(_E) CPY_BIT_OF_INT(_E) Writes a value to a specified bit of word [signed] data. Copies a specified bit of word [signed] data to a specified bit of another word [signed] data.

3 3 3 3 3

3 3

3 3

3 3

3 3

3 3

3 3

3 3

Section 5.52 Section 5.53 Section 5.54 Section 5.55 Section 5.56

10
Applied Functions (Standard Selection Functions)

23

FXCPU Structured Programming Manual [Application Functions]

2 Function/Operator List
2.2 Standard Functions Of One Numeric Variable

Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C) Function name Function Reference FX0(S) FX0N FX1S

GET_BOOL_ADDR GET_INT_ADDR GET_WORD_ADDR

Outputs start data as bit data. Outputs start data as word [signed] data. Outputs start data as word [unsigned]/bit string [16-bit] data.

3 3 3

3 3 3

3 3 3

3 3 3

3 3 3

3 3 3

3 3 3

3 3 3

Section 5.57 Section 5.58 Section 5.59

2.2

Standard Functions Of One Numeric Variable


Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C)

Function name

Function

Reference

FX0(S)

FX0N

FX1S

ABS(_E)

Obtains the absolute value.

Section 6.1

2.3

Standard Arithmetic Functions


Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C)

Function name

Function

Reference

FX0(S)

FX0N

FX1S

ADD_E SUB_E MUL_E DIV_E MOD(_E) EXPT(_E) MOVE(_E)

Adds data. (Number of pins variable) Subtracts data. Multiplies data. (Number of pins variable) Divides data (and outputs the quotient). Divides data (and outputs the remainder). Obtains the raised result. Transfers data.

3 3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

Section 7.1 Section 7.2 Section 7.3 Section 7.4 Section 7.5 Section 7.6 Section 7.7

2.4

Standard Bit Shift Functions


Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C)

Function name

Function

Reference

FX0(S)

FX0N

FX1S

SHL(_E) SHR(_E)

Shifts bits leftward. Shifts bits rightward.

3 3

3 3

3 3

3 3

3 3

3 3

3 3

3 3

Section 8.1 Section 8.2

2.5

Standard Bitwise Boolean Functions


Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C)

Function name

Function

Reference

FX0(S)

FX0N

FX1S

AND_E OR_E XOR_E NOT_E

Obtains the logical product. (Number of pins variable) Obtains the logical sum. (Number of pins variable) Obtains the exclusive logical sum. (Number of pins variable) Obtains the logical not.

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

Section 9.1 Section 9.2 Section 9.3 Section 9.3

24

FXCPU Structured Programming Manual [Application Functions]

2 Function/Operator List
2.6 Standard Selection Functions

2.6

Standard Selection Functions


Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C)

1
Outline

Function name

Function

Reference

2
Function/ Operator List

FX0(S)

FX0N

FX1S

SEL(_E) MAXIMUM(_E) MINIMUM(_E)

Selects data in accordance with the input condition. Searches the maximum value. (Number of pins variable) Searches the minimum value. (Number of pins variable) Judges whether data is located within the range between the upper limit value and the lower limit value. Selects data, and outputs it. (Number of pins variable)

3 3 3

3 3 3

3 3 3

3 3 3

3 3 3

3 3 3

3 3 3

3 3 3

Section 10.1 Section 10.2 Section 10.3

3
Function Construction

LIMITATION(_E)

Section 10.4

MUX(_E)

Section 10.5

4
How to Read Explanation of Functions
Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C)

2.7

Standard Comparison Functions

Function name

Function

Reference

5
Applied Functions (Type Conversion Functions)

FX0(S)

FX0N

FX1S

GT_E GE_E EQ_E LE_E LT_E NE_E

Compares data with regard to "> (larger)". (Number of pins variable) Compares data with regard to " (larger or equal)". (Number of pins variable) Compares data with regard to "= (equal)". (Number of pins variable) Compares data with regard to " (smaller or equal)". (Number of pins variable) Compares data with regard to "< (smaller)". (Number of pins variable) Compares data with regard to " (unequal)".

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

Section 11.1 Section 11.2 Section 11.3 Section 11.4 Section 11.5 Section 11.6

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

2.8

Standard Character String Functions


Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C)

Function name

Function

Reference

8
Applied Functions (Standard Bit Shift Functions)

FX0(S)

FX0N

FX1S

MID(_E) CONCAT(_E) INSERT(_E) DELETE(_E) REPLACE(_E) FIND(_E)

Obtains a character string from a specified position. Connects character strings. (Number of pins variable) Inserts a character string. Deletes a character string. Replaces a character string. Searches a character string.

3 3 3 3 3 3

Section 12.1 Section 12.2 Section 12.3 Section 12.4 Section 12.5 Section 12.6

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

25

FXCPU Structured Programming Manual [Application Functions]

2 Function/Operator List
2.9 Functions Of Time Data Types

2.9

Functions Of Time Data Types


Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C)

Function name

Function

Reference

FX0(S)

FX0N

FX1S

ADD_TIME(_E) SUB_TIME(_E) MUL_TIME(_E) DIV_TIME(_E)

Adds time data. Subtracts time data. Multiplies time data. Divides time data.

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

Section 13.1 Section 13.2 Section 13.3 Section 13.4

2.10

Standard Function Blocks


Applicable PLC FXU/FX2C FX3G(C) FX3U(C) FX2N(C) FX1N(C)

Function name

Function

Reference

FX0(S)

FX0N

FX1S

R_TRIG(_E) F_TRIG(_E) CTU(_E) CTD(_E) CTUD(_E) TP(_E) TON(_E) TOF(_E) COUNTER_FB_M TIMER_10_FB_M TIMER_CONT_FB_M TIMER_100_FB_M

Detects the rising edge of a signal, and outputs pulse signal. Detects the falling edge of a signal, and outputs pulse signal. Counts up the number of times of rising of a signal. Counts down the number of times of rising of a signal. Counts up/down the number of times of rising of a signal. Keeps ON a signal during specified time duration. Keeps OFF a signal during specified time duration. Turns OFF the output signal at specified time after the input signal turned OFF. Counter drive 10ms timer drive Retentive timer drive 100ms timer drive

3 3 3 3 3 3 3 3 3 3 3 3

3 3 3 3 3 3 3 3 3 3 3 3

3 3 3 3 3 3 3 3 3 3 3 3

3 3 3 3 3 3 3 3 3 3 3 3

3 3 3 3 3 3 3 3 3 3

3 3 3 3 3 3 3 3 3 3 3

3 3

3 3

Section 14.1 Section 14.2 Section 14.3 Section 14.4 Section 14.5 Section 14.6 Section 14.7 Section 14.8

3 3

3 3

Section 14.9 Section 14.10 Section 14.11

Section 14.12

26

FXCPU Structured Programming Manual [Application Functions]

2 Function/Operator List
2.11 Operator

2.11

Operator

1
Outline

2.11.1 Arithmetic operations


Operator name FX3G(C) FX3U(C) FX2N(C) Structured ladder /FBD Function Applicable PLC FXU/FX2C FX1N(C) Reference FX0(S) FX0N FX1S

2
Function/ Operator List

ST

ADD SUB MUL DIV -

+ * / **

Adds data. (Number of pins variable) Subtracts data. Multiplies data. (Number of pins variable) Divides data (, and outputs the quotient). Obtains the raised result.

3 3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

3 3 3 3 3

Section 15.1 Section 15.2 Section 15.3 Section 15.4 Section 15.5 Section 15.6

3
Function Construction

MOD Divides data (, and outputs the remainder).

4
How to Read Explanation of Functions

2.11.2 Logical operations


Operator name FX3G(C) FX3U(C) FX2N(C) Structured ladder /FBD Function Applicable PLC FXU/FX2C FX1N(C) Reference FX0(S) FX0N FX1S

ST

5
Applied Functions (Type Conversion Functions)

AND OR XOR -

& AND OR XOR NOT

Obtains the logical product. (Number of pins variable) Obtains the logical sum. (Number of pins variable) Obtains the exclusive logical sum. (Number of pins variable) Obtains the logical not.

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

3 3 3 3

Section 15.7 Section 15.8 Section 15.9 Section 15.10

6
Applied Functions (Standard Functions Of One Numeric Variable)

2.11.3 Comparison operations


Operator name FX3G(C) FX3U(C) FX2N(C) Structured ladder /FBD Function Applicable PLC FXU/FX2C FX1N(C) Reference FX0(S) FX0N FX1S

7
Applied Functions (Standard Arithmetic Functions)

ST

GT GE EQ LE LT NE

> >= = <= < <>

Compares data with regard to "> (larger)". (Number of pins variable) Compares data with regard to " (larger or equal)". (Number of pins variable) Compares data with regard to "= (equal)". (Number of pins variable) Compares data with regard to " (smaller or equal)". (Number of pins variable) Compares data with regard to "< (smaller)". (Number of pins variable) Compares data with regard to " (unequal)".

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

3 3 3 3 3 3

Section 15.11 Section 15.12 Section 15.13 Section 15.14 Section 15.15 Section 15.16

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

27

FXCPU Structured Programming Manual [Application Functions]

3 Function Construction
3.1 Applied Function Expression and Execution Type

3.

Function Construction
This chapter explains the construction of applied functions.

3.1

Applied Function Expression and Execution Type

Applied function and argument


The name expressing the contents is given to each function. For example, the function name "SHL (bit shift left)" is given. Each function consists of arguments which indicate I/O data used in the function.
SHL_E EN ENO _IN *1 _N

D0 K1

D10

_IN ( s ) : An argument whose contents do not change even if the function is executed is called "source", and expressed in this symbol. d *1 ( ) : An argument whose contents change when the function is executed is called "destination", and expressed in this symbol. K1 ( n ) : Arguments not regarded as source or destination are expressed in "m", "n", etc.

Argument target devices


The input variable (label or device) specifies the target. Bit device themselves such as X, Y, M and S may be handled. Bit devices may be combined in a way "KnX", "KnY", "KnM" and "KnS" to express numeric data. FX Structured Programming Manual [Device & Common] Current value registers of data registers (D), timers (T) and counters (C) may be handled. When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they have 32-bit length. Use global labels when specifying devices. When 32-bit data is handled, two consecutive 16-bit data registers D are combined. For example, when data register D0 is defined as an argument of a 32-bit instruction by a label, 32-bit data stored in D1 and D0 is handled. (D1 offers high-order 16 bits, and D0 offers low-order 16-bits.) When the current value register of a timer or counter is used as a general data register, it is handled in the same way.

Changing the number of arguments (pins)


With certain functions, the number of sources can be changed in the range from 2 to 28. The functions which can be changed is indicated by "(Number of pins variable)" in the function list table. Refer to Section 2. Function List Changing the number of pins
Increment Pins

Decrement Pins

28

FXCPU Structured Programming Manual [Application Functions]

3 Function Construction
3.2 Labels

3.2

Labels

1
Outline

Label types
Labels are classified into two types, global and local. Global labels can be used in program components and function blocks. Local labels can be used only in declared program blocks.

2
Function/ Operator List

Label class
The label class indicates how each label can be used from which program component. The table below shows label classes.
Applicable program component Class VAR_GLOBAL Description Common label available in all program components Label available within declared program components, and not available in any other program component Constant available within declared program components, and not available in any other program component Label which receives a value, and cannot be changed in program components Label output from a function block Local label which receives a value, outputs it from a program component, and can be changed in program components Program block 3 3 3 3 3 3 3 Function Function block 3 3 3 3 3 3 3

3
Function Construction

VAR_GLOBAL_CONSTANT Common constant available in all program components VAR VAR_CONSTANT VAR_INPUT VAR_OUTPUT VAR_IN_OUT

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

Label definition
It is necessary to define a label to use the label. An error will occur when a program in which labels are not defined is converted (compiled). When defining a global label, set the label name, class and data type, and assigns a device. When defining a local label, set the label name, class and data type. You do not have to specify devices for local labels. Assignment of devices is automatically executed during compiling. In the example below, the label "Var_String1" is set for the function "BOOL_TO_STR_E".
X000 M0 BOOL_TO_STR_E EN ENO _BOOL

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

Var_String1

When using "Var_String1" as a global label Set the class, label name, data type and device (or address).

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

When using "Var_String1" as a local label Set the class, label name and data type.

10
Applied Functions (Standard Selection Functions)

29

FXCPU Structured Programming Manual [Application Functions] Constant description method


The table below the description method required to set a constant to a label.
Constant type Bit Binary number Octal number Decimal number Hexadecimal number Real number Character string Description method Input "TRUE" or "FALSE". Or input "0" or "1". Add "2#" before a binary number. Add "8#" before an octal number.

3 Function Construction
3.2 Labels

Example TRUE, FALSE 2#0010, 2#01101010 8#0, 8#337

Input a decimal number directly. Or add "K" before a decimal 123, K123 number. Add "16#" or "H" before a hexadecimal number. Input a real number directly. Or add "E" before a real number. 16#FF, HFF 2.34, E2.34

Surround a character string with single quotations (') or double 'ABC', "ABC" quotations (").

Data type
The label data type is basic or universal. The table below shows a list of basic data types.
Data type Bit Word [signed] Double Word [signed] Integer Double precision integer Description Boolean data Value range 0(FALSE), 1(TRUE) -32768 to 32767 -2147483648 to 2147483647 0 to 65535 0 to 4294967295 E 1.175495-38 to FLOAT (Single Precision) String Time Real number Character string Time value E 3.402823+38 (Number of significant figures: 6) (50 characters maximum) T#-24d-0h31m23s648.00ms to T#24d20h31m23s647.00ms 32 bits Variable 32 bits 1 bit 16 bits 32 bits 16 bits 32 bits Bit length

Word [unsigned]/Bit String 16-bit data [16-bit] Double Word [unsigned]/Bit 32-bit data String [32-bit]

30

FXCPU Structured Programming Manual [Application Functions]

3 Function Construction
3.2 Labels

The universal data type indicates data type of a label which combines several basic data types. The data type name begins with "ANY".
ANY

1
Outline

2
Function/ Operator List

ANY_SIMPLE

Array

*1

Structure

*1

ANY_NUM

ANY_BIT Bit Word [unsigned]/ Bit String [16-bit] Double Word [unsigned]/ Bit String [32-bit]

Time

String

3
Function Construction

ANY_REAL FLOAT (Single Precision) FLOAT (Double Precision)

ANY_INT Word [signed] Double word [signed]

The "ANY" type on a higher layer contains types on the lower layer. The "ANY" type on the top layer contains all types.

4
How to Read Explanation of Functions

5
ANY16 ANY32
Applied Functions (Type Conversion Functions)

Word [unsigned]/ Bit String [16-bit]

Word [signed]

Double Word [unsigned]/ Bit String [32-bit]

Double word [signed]

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

*1 Refer to the following manual for details. Q/L/F Structured Programming Manual (Fundamentals)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

31

FXCPU Structured Programming Manual [Application Functions]

3 Function Construction
3.3 Device and Address

3.3

Device and Address


Devices can be described in two methods, device method and address method.

Device method
In this method, a device is described using the device name and device number.
X0 D 100

Device name

Device number

Address method
This method is defined in IEC61131-3, and used as shown in the table below.
Head 1st character: Position I Q % M Input Output Internal X W D L 2nd character: Size (Omitted) Bit Bit Word (16 bits) Double word (32 bits) Long Word (64 bits) 3rd and later characters: Classification Number

This number is provided for This decimal number detailed classification. corresponds to the device Period (.) is used to delimit number. the subsequent "Number". The characters for classification may be omitted.

%I

%M X 1 . 863

Memory area position

Size

Classification

Number

Memory area position The memory area position in which data is assigned is classified into "input", "output" or "internal". X(X Device method) : I(Input) Y(Y Device method) : Q(Output) Any other device : M(Internal) Size The principle of the description method corresponding to the device method (MELSEC description method) is as follows: Bit device : X(Bit) Word device : W(Word (16 bits)), D(Double word (32 bits)) Classification The 3rd and later characters indicate the device type which cannot be specified only by the position and size explained above. The classification is not required for devices "X" and "Y". Refer to the following for the device description method: 7.3 Appendix A

32

FXCPU Structured Programming Manual [Application Functions]

3 Function Construction
3.4 EN and ENO

3.4

EN and ENO
Execution of an instruction can be controlled when the instruction contains "EN" in its name. "EN" inputs the instruction execution condition. "ENO" outputs the instruction execution status. The table below shows the "ENO" status corresponding to the "EN" status and the operation result.

1
Outline

2
Function/ Operator List

EN TRUE(Executes operation.) FALSE(Stops operation.)

ENO FALSE(Operation error occurred.) FALSE

Operation result Indefinite value Indefinite value

TRUE(Operation error did not occur.) Operation output value

3
Function Construction

X000

BOOL_TO_STR_E EN ENO _BOOL

M1 VAR_D10

4
How to Read Explanation of Functions

In the above example, the function "BOOL_TO_STR_E" is executed only when X000 is "TRUE". When the function is executed normally, "TRUE" is output to M1.

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

33

FXCPU Structured Programming Manual [Application Functions]

4 How to Read Explanation of Functions

4.

How to Read Explanation of Functions


Function explanation pages have the following configuration.

1) 2)

3)

4)

5)

6)

7)

* The above page is prepared for explanation, and is different from the actual page.

34

FXCPU Structured Programming Manual [Application Functions]

4 How to Read Explanation of Functions

1) Indicates the chapter/section/subsection number and instruction name. 2) Indicates PLCs which support the function.
Item Description The PLC Series supports the function from its first product. The supporting status varies on the version. Applicable versions are explained in "Cautions". The PLC Series does not support the function.

1
Outline

2
Function/ Operator List

3) Indicates the expression of each function.


Item Structured ladder /FBD ST Description Indicates the instruction expression in the structured ladder language adopted as the representative. Indicates the instruction expression in the ST language.

3
Function Construction

4) Indicates the input variable name and output variable name of the function as well as the contents and data type of each variable. Refer to the following for detailed data types: Q/L/F Structured Programming Manual (Fundamentals) 5) Explanation of function and operation The function executed by this function is explained. In explanation, the structured ladder language is used as the representative. 6) Cautions Cautions on using the function are described. 7) Program example Program examples are explained in each language. In program examples of the structured ladder/FBD language, the structured ladder language is adopted as the representative.

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

35

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.

Applied Functions (Type Conversion Functions)


Function name BOOL_TO_INT(_E) BOOL_TO_DINT(_E) BOOL_TO_STR(_E) BOOL_TO_WORD(_E) BOOL_TO_DWORD(_E) BOOL_TO_TIME(_E) INT_TO_DINT(_E) DINT_TO_INT(_E) INT_TO_BOOL(_E) DINT_TO_BOOL(_E) INT_TO_REAL(_E) DINT_TO_REAL(_E) INT_TO_STR(_E) DINT_TO_STR(_E) INT_TO_WORD(_E) DINT_TO_WORD(_E) INT_TO_DWORD(_E) DINT_TO_DWORD(_E) INT_TO_BCD(_E) DINT_TO_BCD(_E) INT_TO_TIME(_E) DINT_TO_TIME(_E) REAL_TO_INT(_E) REAL_TO_DINT(_E) REAL_TO_STR(_E) WORD_TO_BOOL(_E) DWORD_TO_BOOL(_E) WORD_TO_INT(_E) WORD_TO_DINT(_E) DWORD_TO_INT(_E) DWORD_TO_DINT(_E) WORD_TO_DWORD(_E) DWORD_TO_WORD(_E) WORD_TO_TIME(_E) DWORD_TO_TIME(_E) STR_TO_BOOL(_E) STR_TO_INT(_E) STR_TO_DINT(_E) STR_TO_REAL(_E) STR_TO_TIME(_E) BCD_TO_INT(_E) BCD_TO_DINT(_E) TIME_TO_BOOL(_E) TIME_TO_INT(_E) TIME_TO_DINT(_E) Function Bit data word [signed] data conversion Bit data double word [signed] data conversion Bit data string data conversion Bit data word [unsigned]/bit string [16-bit] data conversion Bit data double word [unsigned]/bit string [32-bit] data conversion Bit data time data conversion Word [signed] data double word [signed] data conversion Double word [signed] data word [signed] data conversion Word [signed] data bit data conversion Double word [signed] data bit data conversion Word [signed] data float (single precision) data conversion Double word [signed] data float (single precision) data conversion Word [signed] data string data conversion Double word [signed] data string data conversion Word [signed] data word [unsigned]/bit string [16-bit] data conversion Double word [signed] data word [unsigned]/bit string [16-bit] data conversion Word [signed] data double word [unsigned]/bit string [32-bit] data conversion Double word [signed] data double word [unsigned]/bit string [32-bit] data conversion Word [signed] data BCD data conversion Double word [signed] data BCD data conversion Word [signed] data time data conversion Double word [signed] data time data conversion Float (single precision) data word [signed] data conversion Float (single precision) data double word [signed] data conversion Float (single precision) data string data conversion Word [unsigned]/bit string [16-bit] data bit data conversion Double word [unsigned]/bit string [32-bit] data bit data conversion Word [unsigned]/bit string [16-bit] data word [signed] data conversion Word [unsigned]/bit string [16-bit] data double word [signed] (signed) data conversion Double word [unsigned]/bit string [32-bit] data Word [signed] data conversion Double word [unsigned]/bit string [32-bit] data double word [signed] data conversion Word [unsigned]/bit string [16-bit] data double word [unsigned]/bit string [32-bit data conversion] Double word [unsigned]/bit string [32-bit] data word [unsigned]/bit string [16-bit] data conversion Word [unsigned]/bit string [16-bit] data time data conversion Double word [unsigned]/bit string [32-bit] data time data conversion String data bit data conversion String data word [signed] data conversion String data double word [signed] data conversion String data float (single precision) data conversion String data time data conversion BCD data word [signed] data conversion BCD data double word [signed] data conversion Time data bit data conversion Time data word [signed] data conversion Time data double word [signed] data conversion Reference Section 5.1 Section 5.2 Section 5.3 Section 5.4 Section 5.5 Section 5.6 Section 5.7 Section 5.8 Section 5.9 Section 5.10 Section 5.11 Section 5.12 Section 5.13 Section 5.14 Section 5.15 Section 5.16 Section 5.17 Section 5.18 Section 5.19 Section 5.20 Section 5.21 Section 5.22 Section 5.23 Section 5.24 Section 5.25 Section 5.26 Section 5.27 Section 5.28 Section 5.29 Section 5.30 Section 5.31 Section 5.32 Section 5.33 Section 5.34 Section 5.35 Section 5.36 Section 5.37 Section 5.38 Section 5.39 Section 5.40 Section 5.41 Section 5.42 Section 5.43 Section 5.44 Section 5.45

36

FXCPU Structured Programming Manual [Application Functions]


Function name TIME_TO_STR(_E) TIME_TO_WORD(_E) TIME_TO_DWORD(_E) BITARR_TO_INT(_E) BITARR_TO_DINT(_E) INT_TO_BITARR(_E) DINT_TO_BITARR(_E) CPY_BITARR(_E) GET_BIT_OF_INT(_E) SET_BIT_OF_INT(_E) CPY_BIT_OF_INT(_E) GET_BOOL_ADDR GET_INT_ADDR GET_WORD_ADDR Time data string data conversion Function

5 Applied Functions (Type Conversion Functions)

1
Reference Section 5.46 Section 5.47 Section 5.48 Section 5.49 Section 5.50 Section 5.51 Section 5.52 Section 5.53 Section 5.54 Section 5.55 Section 5.56 Section 5.57 Section 5.58 Section 5.59

Outline

Time data word [unsigned]/bit string [16-bit] data conversion Time data double word [unsigned]/bit string [32-bit] data conversion Bit array Word [signed] type, word [unsigned]/bit String [16-bit] data conversion Bit array Double word [signed] type, double word [unsigned]/bit string [32-bit] data conversion Word [signed] data, word [unsigned]/bit string [16-bit] data bit array conversion Double word [signed] data, double word [unsigned]/bit string [32-bit] data bit array conversion Bit array copy Specified bit read of word [signed] data Specified bit write of word [signed] data Specified bit copy of word [signed] data Acquisition of start data Acquisition of start data Acquisition of start data

2
Function/ Operator List

3
Function Construction

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

37

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.1

BOOL_TO_INT(_E) / Bit data word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts bit data into word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST BOOL_TO_INT(_BOOL); Example: D0:= BOOL_TO_INT(M0); BOOL_TO_INT_E(EN,_BOOL, Output label Example: BOOL_TO_INT_E(X000,M0, D0);

BOOL_TO_INT

M0

BOOL_TO_INT _BOOL *1

D0

X000
BOOL_TO_INT_E

M0

BOOL_TO_INT_E EN ENO _BOOL *1

D0

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _BOOL ( s ) ENO *1 ( d ) Execution condition Conversion source bit data Execution status Word [signed] data after conversion Description Bit Bit Bit Word [signed] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts bit data stored in a device specified in s into word [signed] data, and outputs the data obtained by conversion to a device specified in d . When the input value is "FALSE", this function outputs "0" as the word [signed] data value. When the input value is "TRUE", this function outputs "1" as the word [signed] data value.
FALSE TRUE Bit data 0 1 Word [signed] data

Cautions
Use the function having "_E" in its name to connect a bus.

38

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, bit data stored in a device specified in s is converted into word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(BOOL_TO_INT)
[Structured ladder/FBD] [ST]

2
Function/ Operator List

g_bool1

BOOL_TO_INT _BOOL

g_int1 := BOOL_TO_INT(g_bool1);
g_int1

2) Function with EN/ENO(BOOL_TO_INT_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_bool2

BOOL_TO_INT_E EN ENO _BOOL

g_bool3 := BOOL_TO_INT_E(g_bool1, g_bool2, g_int1);


g_bool3 g_int1

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

39

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.2

BOOL_TO_DINT(_E) / Bit data double word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts bit data into double word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST BOOL_TO_DINT(_BOOL); Example: Label:= BOOL_TO_DINT(M0); BOOL_TO_DINT_E(EN, _BOOL, Output label); Example: BOOL_TO_DINT_E(X000,M0, Label);

BOOL_TO_DINT

M0

BOOL_TO_DINT _BOOL *1

Label

BOOL_TO_DINT_ E

X000 M0

BOOL_TO_DINT_E EN ENO _BOOL *1

Label

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _BOOL ( s ) ENO *1 ( d ) Execution condition Conversion source bit data Execution status Double word [signed] data after conversion Description Bit Bit Bit Double Word [signed] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts bit data stored in a device specified in s the data obtained by conversion to a device specified in d .
FALSE TRUE Bit data 0 1 Double word [signed] data

into double word [signed] data, and outputs

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

40

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, bit data stored in a device specified in s is converted into double word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(BOOL_TO_DINT)
[Structured ladder/FBD] [ST]

2
Function/ Operator List

g_bool1

BOOL_TO_DINT _BOOL

g_dint1 := BOOL_TO_DINT(g_bool1);
g_dint1

2) Function with EN/ENO(BOOL_TO_DINT_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_bool2

BOOL_TO_DINT_E EN ENO _BOOL

g_bool3 := BOOL_TO_DINT_E(g_bool1, g_bool2, g_dint1);


g_bool3 g_dint1

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

41

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.3

BOOL_TO_STR(_E) / Bit data string data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts bit data into string data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST BOOL_TO_STR(_BOOL); Example: Label:= BOOL_TO_STR(M0); BOOL_TO_STR_E(EN, _BOOL, Output label); Example: BOOL_TO_STR_E(X000,M0, Label);

BOOL_TO_STR

M0

BOOL_TO_STR _BOOL *1

Label

BOOL_TO_STR_ E

X000 M0

BOOL_TO_STR_E EN ENO _BOOL *1

Label

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _BOOL ( s ) ENO *1 ( d ) Execution condition Conversion source bit data Execution status String data after conversion Description Bit Bit Bit String Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts bit data input to a deice specified in by conversion to a device specified in d .
FALSE TRUE Bit data "0" "1" String data
s

into string data, and outputs the data obtained

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling string data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling string data. Use global labels when specifying labels.

42

FXCPU Structured Programming Manual [Application Functions] Program example


In this program, bit data stored in a deice specified in by conversion is output to a device specified in d . 1) Function without EN/ENO(BOOL_TO_STR)
[Structured ladder/FBD] [ST]

5 Applied Functions (Type Conversion Functions)

1
Outline

is converted into string data, and the data obtained

2
Function/ Operator List

g_bool1

BOOL_TO_STR _BOOL

g_string1 := BOOL_TO_STR(g_bool1);
g_string1

2) Function with EN/ENO(BOOL_TO_STR_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_bool2

BOOL_TO_STR_E EN ENO _BOOL

g_bool3 := BOOL_TO_STR_E(g_bool1, g_bool2, g_string1);


g_bool3 g_string1

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

43

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.4

BOOL_TO_WORD(_E) / Bit data word [unsigned]/ bit string [16-bit] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts bit data into word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST BOOL_TO_WORD(_BOOL); Example: D0:= BOOL_TO_WORD(M0); BOOL_TO_WORD_E(EN, _BOOL, Output label); Example: BOOL_TO_WORD_E(X000, M0,D0);

BOOL_TO_WOR D

M0

BOOL_TO_WORD _BOOL *1

D0

BOOL_TO_WOR D_E

X000 M0

BOOL_TO_WORD_E EN ENO _BOOL *1

D0

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _BOOL ( s ) ENO *1 ( d ) Execution condition Conversion source bit data Execution status Word [unsigned]/bit string [16-bit] data after conversion Description Bit Bit Bit Word [unsigned]/ Bit String [16-bit] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts bit data stored in a device specified in s into word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion to a device specified in d . When the input value is "FALSE", this function outputs "0H" as the word [unsigned]/bit string [16-bit] data value. When the input value is "TRUE", this function outputs "1H" as the word [unsigned]/bit string [16-bit] data value.
FALSE TRUE Bit data 0H 1H Word [unsigned]/ bit string [16-bit] data

Cautions
Use the function having "_E" in its name to connect a bus.

44

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, bit data stored in a device specified in s is converted into word [unsigned]/bit string [16-bit] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(BOOL_TO_WORD)
[Structured ladder/FBD] [ST]

2
Function/ Operator List

g_bool1

BOOL_TO_WORD _BOOL

g_word1 := BOOL_TO_WORD(g_bool1);
g_word1

2) Function with EN/ENO(BOOL_TO_WORD_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_bool2

BOOL_TO_WORD_E EN ENO _BOOL

g_bool3 := BOOL_TO_WORD_E(g_bool1, g_bool2, g_word1);


g_bool3 g_word1

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

45

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.5

BOOL_TO_DWORD(_E) / Bit data double word [unsigned]/ bit string [32-bit] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts bit data into double word [unsigned]/bit string [32-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST BOOL_TO_DWORD(_BOOL); Example: Label:= BOOL_TO_DWORD(M0);

BOOL_TO_DWO RD

M0

BOOL_TO_DWORD _BOOL *1

Label

BOOL_TO_DWO RD_E

X000 M0

BOOL_TO_DWORD_E EN ENO _BOOL *1

BOOL_TO_DWORD_E(EN, _BOOL, Output label); Example: Label BOOL_TO_DWORD_E(X000, M0, Label);

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _BOOL ( s ) ENO *1 ( d ) Execution condition Conversion source bit data Execution status Double word [unsigned]/bit string [32-bit] data after conversion Description Bit Bit Bit Double Word [unsigned]/ Bit string [32-bit] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts bit data stored in a device specified in s into double word [unsigned]/bit string [32bit] data, and outputs the data obtained by conversion to a device specified in d . When the input value is "FALSE", this function outputs "0H" as the double word [unsigned]/bit string [32bit]data value. When the input value is "TRUE", this function outputs "1H" as the double word [unsigned]/bit string [32-bit] data value.
FALSE TRUE Bit data 0H 1H Double Word [unsigned]/ Bit string [32-bit] data

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

46

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, bit data stored in a device specified in s is converted into double word [unsigned]/bit string [32-bit] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(BOOL_TO_DWORD)
[Structured ladder/FBD]

2
Function/ Operator List

g_bool1

BOOL_TO_DWORD _BOOL

g_dword1

[ST]

g_dword1 := BOOL_TO_DWORD(g_bool1);

3
Function Construction

2) Function with EN/ENO(BOOL_TO_DWORD_E)


[Structured ladder/FBD]

g_bool1 g_bool2
[ST]

BOOL_TO_DWORD_E EN ENO _BOOL

g_bool3 g_dword1

4
How to Read Explanation of Functions

g_bool3 := BOOL_TO_DWORD_E(g_bool1, g_bool2, g_dword1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

47

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.6

BOOL_TO_TIME(_E) / Bit data time data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts bit data into time data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST BOOL_TO_TIME(_BOOL); Example: Label:= BOOL_TO_TIME(M0); BOOL_TO_TIME_E(EN,_BOOL, Output label); Example: BOOL_TO_TIME_E(X000,M0, Label);

BOOL_TO_TIME

M0

BOOL_TO_TIME _BOOL *1

Label

BOOL_TO_TIME_ E

X000 M0

BOOL_TO_TIME_E EN ENO _BOOL *1

Label

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _BOOL ( s ) ENO *1 ( d ) Execution condition Conversion source bit data Execution status Time data after conversion Description Bit Bit Bit Time Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts bit data stored in a device specified in obtained by conversion to a device specified in d .
FALSE TRUE Bit data 0 1ms Time data
s

into time data, and outputs the data

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

48

FXCPU Structured Programming Manual [Application Functions] Program example


In this program, bit data stored in a device specified in by conversion is output to a device specified in d . 1) Function without EN/ENO(BOOL_TO_TIME)
[Structured ladder/FBD] [ST]

5 Applied Functions (Type Conversion Functions)

1
Outline

is converted into time data, and the data obtained

2
Function/ Operator List

g_bool1

BOOL_TO_TIME _BOOL

g_time1 := BOOL_TO_TIME(g_bool1);
g_time1

2) Function with EN/ENO(BOOL_TO_TIME_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_bool2

BOOL_TO_TIME_E EN ENO _BOOL

g_bool3 := BOOL_TO_TIME_E(g_bool1, g_bool2, g_time1);


g_bool3 g_time1

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

49

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.7

INT_TO_DINT(_E) / Word [signed] data double word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts word [signed] data into double word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST INT_TO_DINT(_INT); Example: Label:= INT_TO_DINT(D0); INT_TO_DINT_E(EN,_INT, Output label); Example: INT_TO_DINT_E(X000,D0, Label);

INT_TO_DINT

D0

INT_TO_DINT _INT *1

Label

X000
INT_TO_DINT_E

D0

INT_TO_DINT_E EN ENO _INT *1

Label

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _INT ( s ) ENO *1 ( d ) Execution condition Conversion source word [signed] data Execution status Double word [signed] data after conversion Description Bit Word [signed] Bit Double Word [signed] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [signed] data stored in a device specified in s and outputs the data obtained by conversion to a device specified in d .
1234 Word [signed] data 1234 Double word [signed] data

into double word [signed] data,

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

50

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, word [signed] data stored in a device specified in s is converted into double word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(INT_TO_DINT)
[Structured ladder/FBD] [ST]

2
Function/ Operator List

g_int1=5923

INT_TO_DINT _INT

g_dint1 := INT_TO_DINT(g_int1);
g_dint1=5923

2) Function with EN/ENO(INT_TO_DINT_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_int1

INT_TO_DINT_E EN ENO _INT

g_bool3 := INT_TO_DINT_E(g_bool1, g_int1, g_dint1);


g_bool3 g_dint1

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

51

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.8

DINT_TO_INT(_E) / Double word [signed] data word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts double word [signed] data into word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DINT_TO_INT(_DINT); Example: D10:= DINT_TO_INT(Label); DINT_TO_INT_E(EN,_DINT, Output label); Example: DINT_TO_INT_E(X000, Label, D10);

DINT_TO_INT

Label

DINT_TO_INT _DINT *1

D10

X000
DINT_TO_INT_E

Label

DINT_TO_INT_E EN ENO _DINT *1

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DINT ( s ) ENO *1 ( d ) Execution condition Conversion source double word [signed] data Execution status Word [signed] data after conversion Description Bit Double Word [signed] Bit Word [signed] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [signed] data stored in a device specified in and outputs the data obtained by conversion to a device specified in d .
1234 Double word [signed] data 1234 Word [signed] data
s

into word [signed] data,

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

52

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, double word [signed] data stored in a device specified in s is converted into word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DINT_TO_INT)
[Structured ladder/FBD] [ST]

2
Function/ Operator List

g_dint1=5923

DINT_TO_INT _DINT

g_int1 := DINT_TO_INT(g_dint1);
g_int1=5923

2) Function with EN/ENO(DINT_TO_INT_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_dint1

DINT_TO_INT_E EN ENO _DINT

g_bool3 := DINT_TO_INT_E(g_bool1, g_dint1, g_int1);


g_bool3 g_int1

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

53

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.9

INT_TO_BOOL(_E) / Word [signed] data bit data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts word [signed] data into bit data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST INT_TO_BOOL(_INT); Example: M0:= INT_TO_BOOL(D0); INT_TO_BOOL_E(EN,_INT, Output label); Example: INT_TO_BOOL_E(X000,D0,M0);

INT_TO_BOOL

D0 X000

INT_TO_BOOL _INT *1 INT_TO_BOOL_E EN ENO _INT *1

M0

INT_TO_BOOL_E

D0

M0

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _INT ( s ) ENO *1 ( d ) Execution condition Conversion source word [signed] data Execution status Bit data after conversion Description Bit Word [signed] Bit Bit Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [signed] data stored in a device specified in s into bit data, and outputs the data obtained by conversion to a device specified in d . When the input value is "0", this function outputs "FALSE". When the input value is any value other than "0", this function outputs "TRUE".
0 1567 Word [signed] data FALSE TRUE Bit data

Cautions
Use the function having "_E" in its name to connect a bus.

54

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, word [signed] data stored in a device specified in obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(INT_TO_BOOL)
[Structured ladder/FBD] [ST]

is converted into bit data, and the data

2
Function/ Operator List

g_int1=5923

INT_TO_BOOL _INT

g_bool1 := INT_TO_BOOL(g_int1);
g_bool1

2) Function with EN/ENO(INT_TO_BOOL_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_int1

INT_TO_BOOL_E EN ENO _INT

g_bool3 := INT_TO_BOOL_E(g_bool1, g_int1, g_bool2);


g_bool3 g_bool2

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

55

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.10

DINT_TO_BOOL(_E) / Double word [signed] data bit data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts double word [signed] data into bit data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DINT_TO_BOOL(_DINT); Example: M0:= DINT_TO_BOOL(Label); DINT_TO_BOOL_E(EN,_DINT, Output label); Example: DINT_TO_BOOL_E(X000, Label, M0);

DINT_TO_BOOL

Label

DINT_TO_BOOL _DINT *1

M0

DINT_TO_BOOL_ E

X000 Label

DINT_TO_BOOL_E EN ENO _DINT *1

M0

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DINT ( s ) ENO *1 ( d ) Execution condition Conversion source double word [signed] data Execution status Bit data after conversion Description Bit Double Word [signed] Bit Bit Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [signed] data stored in a device specified in s the data obtained by conversion to a device specified in d . When the input value is "0", this function outputs "FALSE". When the input value is any value other than "0", this function outputs "TRUE".
0 12345678 Double word [signed] data FALSE TRUE Bit data

into bit data, and outputs

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

56

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, double word [signed] data stored in a device specified in the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DINT_TO_BOOL)
[Structured ladder/FBD]

is converted into bit data, and

2
Function/ Operator List

g_dint1=0
[ST]

DINT_TO_BOOL _DINT

g_bool1

g_bool1 := DINT_TO_BOOL(g_dint1);

3
Function Construction

2) Function with EN/ENO(DINT_TO_BOOL_E)


[Structured ladder/FBD]

g_bool1 g_dint1
[ST]

DINT_TO_BOOL_E EN ENO _DINT

g_bool3 g_bool2

4
How to Read Explanation of Functions

g_bool3 := DINT_TO_BOOL_E(g_bool1, g_dint1, g_bool2);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

57

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.11

INT_TO_REAL(_E) / Word [signed] data float (single precision) data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts word [signed] data into float (single precision) data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST INT_TO_REAL(a_Int); Example: Label:= INT_TO_REAL(D0); INT_TO_REAL_E(EN,a_Int, Output label); Example: INT_TO_REAL_E(X000,D0,Label);

INT_TO_REAL

D0 X000

INT_TO_REAL a_Int *1 INT_TO_REAL_E EN ENO a_Int *1

Label

INT_TO_REAL_E

D0

Label

*1.

Output variable

2. Set data
Variable Input variable Output variable EN a_Int ( s ) ENO *1 ( d ) Execution condition Conversion source word [signed] data Execution status Float (single precision) data after conversion Description Bit Word [signed] Bit FLOAT (Single Precision) Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [signed] data stored in a device specified in s and outputs the data obtained by conversion to a device specified in d .
1234 Word [signed] data 1234.0 Float (single precision) data

into float (single precision) data,

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) The function is provided in the FX3G Series Ver.1.10 or later. 4) The number of significant figures of FLOAT (Single Precision) data is approximately 7 since the data is processed in 32-bit single precision. Accordingly, the converted data includes an error (rounding error) if an integer value is outside the range of -16777216 to 16777215.

58

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, word [signed] data stored in a device specified in s is converted into float (single precision) data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(INT_TO_REAL)
[Structured ladder/FBD] [ST]

2
Function/ Operator List

g_int1=5923

INT_TO_REAL a_Int

g_real1 := INT_TO_REAL(g_int1);
g_real1=5923.0

2) Function with EN/ENO(INT_TO_REAL_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_int1

INT_TO_REAL_E EN ENO a_Int

g_bool3 := INT_TO_REAL_E(g_bool1, g_int1, g_real1);


g_bool3 g_real1

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

59

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.12

DINT_TO_REAL(_E) / Double word [signed] data float (single precision) data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts double word [signed] data into float (single precision) data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DINT_TO_REAL(a_Dint); Example: Label 2 Label 2:= DINT_TO_REAL(Label 1); DINT_TO_REAL_E(EN,a_Dint, Output label); Example: DINT_TO_REAL_E(X000, Label 1, Label 2);

DINT_TO_REAL

Label 1

DINT_TO_REAL a_Dint *1

DINT_TO_REAL_ E

X000 Label 1

DINT_TO_REAL_E EN ENO a_Dint *1

Label 2

*1.

Output variable

2. Set data
Variable Input variable Output variable EN a_Dint ( s ) ENO *1 ( d ) Execution condition Conversion source double word [signed] data Execution status Float (single precision) data after conversion Description Bit Double Word [signed] Bit FLOAT (Single Precision) Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [signed] data stored in a device specified in s into float (single precision) data, and outputs the data obtained by conversion to a device specified in d .
16543521 Double word [signed] data 16543521.0 Float (single precision) data

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) The function is provided in the FX3G Series Ver.1.10 or later.

60

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, double word [signed] data stored in a device specified in s is converted into float (single precision) data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DINT_TO_REAL)
[Structured ladder/FBD]

2
Function/ Operator List

g_dint1=65000
[ST]

DINT_TO_REAL a_Dint

g_real1=65000.0

g_real1 := DINT_TO_REAL(g_dint1);

3
Function Construction

2) Function with EN/ENO(DINT_TO_REAL_E)


[Structured ladder/FBD]

g_bool1 g_dint1
[ST]

DINT_TO_REAL_E EN ENO a_Dint

g_bool3 g_real1

4
How to Read Explanation of Functions

g_bool3 := DINT_TO_REAL_E(g_bool1, g_dint1, g_real1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

61

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.13

INT_TO_STR(_E) / Word [signed] data string data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts word [signed] data into string data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST INT_TO_STR(_INT); Example: Label:= INT_TO_STR(D0); INT_TO_STR_E(EN,_INT, Output label); Example: INT_TO_STR_E(X000, D0, Label);

INT_TO_STR

D0 X000

INT_TO_STR _INT *1 INT_TO_STR_E EN ENO *1 _INT

Label

INT_TO_STR_E

D0

Label

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _INT ( s ) ENO *1 ( d ) Execution condition Conversion source word [signed] data Execution status String data after conversion Description Bit Word [signed] Bit String Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function converts word [signed] data stored in a device specified in the data obtained by conversion to a device specified in d .
s

into string data, and outputs

Word [signed] data

High-order byte Low-order byte ASCII code for ten-thousands place Sign data String ASCII code for hundreds place ASCII code for thousands place ASCII code for ones place ASCII code for tens place 0000H Automatically stored at the end of the character string

1st word 2nd word 3rd word 4th word

2) In "Sign data", "20H (space)" is stored when the input value is positive, and "2DH (-)" is stored when the input value is negative. 3) "20H (space)" is stored in high-order digits when the number of significant figures is small. Example: When "-123" is input
High-order byte 20H (space) 31H (1) 33H (3) 0000H Low-order byte 2DH (-) 20H (space) 32H (2) String 1st word 2nd word 3rd word 4th word

-123 Word [signed] data

4) "00H" is automatically stored at the end (4th word) of the character string.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling string data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling string data. Use global labels when specifying labels.

62

FXCPU Structured Programming Manual [Application Functions] Error

5 Applied Functions (Type Conversion Functions)

1
Outline

An operation error occurs in the following case. The error flag M8067 turns ON, and D8067 stores the error code. 1) When the number of points occupied by the string data storage destination (device specified in exceeds the range of the corresponding device (Error code: K6706)
d

2
Function/ Operator List

Program example
In this program, word [signed] data stored in a device specified in s data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(INT_TO_STR)
[Structured ladder/FBD] [ST]

is converted into string data, and the

3
Function Construction

g_int1=-12345

INT_TO_STR _INT

g_string1 := INT_TO_STR(g_int1);
g_string='-12345'

2) Function with EN/ENO(INT_TO_STR_E)


[Structured ladder/FBD] [ST]

4
How to Read Explanation of Functions

g_bool1 g_int1

INT_TO_STR_E EN ENO _INT

g_bool3 := INT_TO_STR_E(g_bool1, g_int1, g_string1);


g_bool3 g_string1

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

63

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.14

DINT_TO_STR(_E) / Double word [signed] data string data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts double word [signed] data into string data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DINT_TO_STR(_DINT); Example: Label 2 Label 2:= DINT_TO_STR(Label 1); DINT_TO_STR_E(EN,_DINT, Output label); Example: Label 2 DINT_TO_STR_E(X000, Label 1, Label 2);

DINT_TO_STR

Label 1

DINT_TO_STR _DINT *1

X000
DINT_TO_STR_E

Label 1

DINT_TO_STR_E EN ENO _DINT *1

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DINT ( s ) ENO *1 ( d ) Execution condition Conversion source double word [signed] data Execution status String data after conversion Description Bit Double Word [signed] Bit String Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function converts double word [signed] data stored in a device specified in outputs the data obtained by conversion to a device specified in d .
s

into string data, and

Double word [signed] data

High-order byte Low-order byte ASCII code for billions place Sign data String ASCII code for ten-millions place ASCII code for hundred-millions place ASCII code for hundred-thousands place ASCII code for millions place ASCII code for thousands place ASCII code for ten-thousands place ASCII code for tens place ASCII code for hundreds place 00H ASCII code for ones place Automatically stored at the end of the character string

1st word 2nd word 3rd word 4th word 5th word 6th word

2) In "Sign data", "20H (space)" is stored when the input value is positive, and "2DH (-)" is stored when the input value is negative. 3) "20H (space)" is stored in high-order digits when the number of significant figures is small. Example: When "-123456" is input
High-order byte 20H (space) 20H (space) 31H (1) 33H (3) 35H (5) 00H Low-order byte 2DH (-) 20H (space) 20H (space) 32H (2) 34H (4) 36H (6)

String

-123456
Double word [signed] data

1st word 2nd word 3rd word 4th word 5th word 6th word

4) "00H" is automatically stored at the end (high-order byte of the 6th word) of the character string.

64

FXCPU Structured Programming Manual [Application Functions] Cautions

5 Applied Functions (Type Conversion Functions)

1
Outline

1) Use the function having "_E" in its name to connect a bus. 2) When handling string data and 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling string data and 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

2
Function/ Operator List

Error
An operation error occurs in the following case. The error flag M8067 turns ON, and D8067 stores the error code. 1) When the number of points occupied by the string data storage destination (device specified in exceeds the range of the corresponding device (Error code: K6706)
d

3
Function Construction

Program example
In this program, double word [signed] data stored in a device specified in s and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DINT_TO_STR)
[Structured ladder/FBD]

is converted into string data,

4
How to Read Explanation of Functions

g_dint1=-12345678
[ST]

DINT_TO_STR _DINT

g_string1='-12345678'

g_string1 := DINT_TO_STR(g_dint1);

5
Applied Functions (Type Conversion Functions)

2) Function with EN/ENO(DINT_TO_STR_E)


[Structured ladder/FBD]

g_bool1 g_dint1
[ST]

DINT_TO_STR_E EN ENO _DINT

g_bool3 g_string1

6
Applied Functions (Standard Functions Of One Numeric Variable)

g_bool3 := DINT_TO_STR_E(g_bool1, g_dint1, g_string1);

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

65

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.15

INT_TO_WORD(_E) / Word [signed] data word [unsigned]/ bit string [16-bit] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts word [signed] data into word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST INT_TO_WORD(_INT); Example: D10:= INT_TO_WORD(D0); INT_TO_WORD_E(EN,_INT, Output label); Example: INT_TO_WORD_E(X000,D0,D10);

INT_TO_WORD

D0 X000 D0

INT_TO_WORD *1 _INT INT_TO_WORD_E EN ENO _INT *1

D10

INT_TO_WORD_ E

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _INT ( s ) ENO *1 ( d ) Execution condition Conversion source word [signed] data Execution status Word [unsigned]/Bit String [16-bit] data after conversion Description Bit Word [signed] Bit Word [unsigned]/ Bit String [16-bit] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [signed] data stored in a device specified in s into word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion to a device specified in d .
22136 Word [signed] data 5678H Word [unsigned]/ bit string [16-bit] data

Cautions
Use the function having "_E" in its name to connect a bus.

66

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, word [signed] data stored in a device specified in s is converted into word [unsigned]/bit string [16-bit] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(INT_TO_WORD)
[Structured ladder/FBD]

2
Function/ Operator List

g_int1=5923
[ST]

INT_TO_WORD _INT

g_word1=16#1723

g_word1 := INT_TO_WORD(g_int1);

3
Function Construction

2) Function with EN/ENO(INT_TO_WORD_E)


[Structured ladder/FBD]

g_bool1 g_int1
[ST]

INT_TO_WORD_E EN ENO _INT

g_bool3 g_word1

4
How to Read Explanation of Functions

g_bool3 := INT_TO_WORD_E(g_bool1, g_int1, g_word1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

67

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.16

DINT_TO_WORD(_E) / Double word [signed] data word [unsigned]/ bit string [16-bit] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts double word [signed] data into word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DINT_TO_WORD(_DINT); Example: D10:= DINT_TO_WORD(Label); DINT_TO_WORD_E(EN,_DINT, Output label); Example: DINT_TO_WORD_E(X000, Label, D10);

DINT_TO_WORD

Label

DINT_TO_WORD _DINT *1

D10

DINT_TO_WORD _E

X000 Label

DINT_TO_WORD_E EN ENO _DINT *1

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DINT ( s ) ENO *1 ( d ) Execution condition Conversion source double word [signed] data Execution status Word [unsigned]/bit string [16-bit] data after conversion Description Bit Double Word [signed] Bit Word [unsigned]/ Bit String [16-bit] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [signed] data stored in a device specified in s into word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion to a device specified in d .
12345678 Double word [signed] data 614EH Word [unsigned]/ bit string [16-bit] data

12345678 0 0 0 0 0 0 0 0 1 0 1 1 1 1 0 0 0 1 1 0 0 0 0 1 0 1 0 0 1 1 1 0 614E 0 11 0 0 0 01 01 0 0 1 11 0

The information stored in high-order 16 bits is discarded.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

68

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, double word [signed] data stored in a device specified in s is converted into word [unsigned]/bit string [16-bit] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DINT_TO_WORD)
[Structured ladder/FBD]

2
Function/ Operator List

g_dint1=12345678
[ST]

DINT_TO_WORD _DINT

g_word1=16#614E

g_word1 := DINT_TO_WORD(g_dint1);

3
Function Construction

2) Function with EN/ENO(DINT_TO_WORD_E)


[Structured ladder/FBD]

g_bool1 g_dint1
[ST]

DINT_TO_WORD_E EN ENO _DINT

g_bool3 g_word1

4
How to Read Explanation of Functions

g_bool3 := DINT_TO_WORD_E(g_bool1, g_dint1, g_word1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

69

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.17

INT_TO_DWORD(_E) / word [signed] data double word [unsigned]/ bit string [32-bit] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts word [signed] data into double word [unsigned]/bit string [32-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST INT_TO_DWORD(_INT); Example: Label:= INT_TO_DWORD(D0); INT_TO_DWORD_E(EN,_INT, Output label); Example: INT_TO_DWORD_E(X000,D0, Label);

INT_TO_DWORD

D0

INT_TO_DWORD _INT *1

Label

INT_TO_DWORD _E

X000 D0

INT_TO_DWORD_E EN ENO _INT *1

Label

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _INT ( s ) ENO *1 ( d ) Execution condition Conversion source word [signed] data Execution status Double word [unsigned]/bit string [32-bit] data after conversion Description Bit Word [signed] Bit Double Word [unsigned]/ Bit string [32-bit] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [signed] data stored in a device specified in s into double word [unsigned]/bit string [32-bit] data, and outputs the data obtained by conversion to a device specified in d .
-325 Word [signed] data -325 0000FEBBH Double word [unsigned]/ bit string [32-bit] data 111 1 1 1 1 0 1 0 1 1 10 1 1 Data conversion 0000FEBBH 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 0 1 0 1 1 1 0 1 1 Each of high-order 16 bits becomes "0" after data conversion.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices.

70

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, word [signed] data stored in a device specified in s is converted into double word [unsigned]/bit string [32-bit] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(INT_TO_DWORD)
[Structured ladder/FBD]

2
Function/ Operator List

g_int1=10
[ST]

INT_TO_DWORD _INT

g_dword1=16#0000000A

g_dword1 := INT_TO_DWORD(g_int1);

3
Function Construction

2) Function with EN/ENO(INT_TO_DWORD_E)


[Structured ladder/FBD]

g_bool1 g_int1
[ST]

INT_TO_DWORD_E EN ENO _INT

g_bool3 g_dword1

4
How to Read Explanation of Functions

g_bool3 := INT_TO_DWORD_E(g_bool1, g_int1, g_dword1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

71

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.18

DINT_TO_DWORD(_E) / Double word [signed] data double word [unsigned]/bit string [32-bit] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts double word [signed] data into double word [unsigned]/bit string [32-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DINT_TO_DWORD(_DINT); Example: Label 2 Label 2:= DINT_TO_DWORD(Label 1); DINT_TO_DWORD_E(EN,_DINT, Output label); Example: Label 2 DINT_TO_DWORD_E(X000, Label 1, Label 2);

DINT_TO_DWOR D

Label 1

DINT_TO_DWORD _DINT *1

DINT_TO_DWOR D_E

X000 Label 1

DINT_TO_DWORD_E EN ENO _DINT *1

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DINT ( s ) ENO *1 ( d ) Execution condition Conversion source double word [signed] data Execution status Double word [unsigned]/bit string [32-bit] data after conversion Description Bit Double Word [signed] Bit Double Word [unsigned]/ Bit string [32-bit] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [signed] data stored in a device specified in s into double word [unsigned]/bit string [32-bit] data, and outputs the data obtained by conversion to a device specified in d .
12345678 Double word [signed] data BC614EH Double word [unsigned]/ bit string [32-bit] data

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

72

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, double word [signed] data stored in a device specified in s is converted into double word [unsigned]/bit string [32-bit] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DINT_TO_DWORD)
[Structured ladder/FBD]

2
Function/ Operator List

g_dint1=74565
[ST]

DINT_TO_DWORD _DINT

g_dword1=16#00012345

g_dword1 := DINT_TO_DWORD(g_dint1);

3
Function Construction

2) Function with EN/ENO(DINT_TO_DWORD_E)


[Structured ladder/FBD]

g_bool1 g_dint1
[ST]

DINT_TO_DWORD_E EN ENO _DINT

g_bool3 g_dword1

4
How to Read Explanation of Functions

g_bool3 := DINT_TO_DWORD_E(g_bool1, g_dint1, g_dword1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

73

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.19

INT_TO_BCD(_E) / Word [signed] data BCD data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts word [signed] data into BCD data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST INT_TO_BCD(_INT); Example: D10:= INT_TO_BCD(D0); INT_TO_BCD_E(EN,_INT, Output label); Example: INT_TO_BCD_E(X000,D0,D10);

INT_TO_BCD

D0 X000

INT_TO_BCD _INT *1 INT_TO_BCD_E EN ENO _INT *1

D10

INT_TO_BCD_E

D0

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _INT ( s ) ENO *1 ( d ) Execution condition Conversion source word [signed] data Execution status BCD data after conversion Description Bit Word [signed] Bit Word [unsigned]/ Bit String [16-bit] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [signed] data stored in a device specified in data obtained by conversion to a device specified in d .
9999 Word [signed] data
32768 16384 8192 4096 2048 1024 512 256

into BCD data, and outputs the

9999H Word [unsigned]/ bit string [16-bit] data


128 64 32 16 8 4 2 1

9999

Make sure to set them to "0".


8000 4000 2000 1000 800 400 200 100 80

Conversion into BCD data


40 20 10 8 4 2 1

9999H

Thousands place

Hundreds place

Tens place

Ones place

Cautions
Use the function having "_E" in its name to connect a bus.

Error
An operation error occurs when the value stored in a device specified in "9,999".
s

is outside the range from "0" to

74

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, word [signed] data stored in a device specified in s data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(INT_TO_BCD)
[Structured ladder/FBD]

is converted into BCD data, and the

2
Function/ Operator List

g_int1=5923
[ST]

INT_TO_BCD _INT

g_word=16#5923

g_word1 := INT_TO_BCD(g_int1);

3
Function Construction

2) Function with EN/ENO(INT_TO_BCD_E)


[Structured ladder/FBD]

g_bool1 g_int1
[ST]

INT_TO_BCD_E EN ENO _INT

g_bool3 g_word1

4
How to Read Explanation of Functions

g_bool3 := INT_TO_BCD_E(g_bool1, g_int1, g_word1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

75

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.20

DINT_TO_BCD(_E) / Double word [signed] data BCD data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts double word [signed] data into BCD data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DINT_TO_BCD(_DINT); Example: Label 2 Label 2:= DINT_TO_BCD(Label 1); DINT_TO_BCD_E(EN,_DINT, Output label); Example: DINT_TO_BCD_E(X000, Label 1, Label 2);

DINT_TO_BCD

Label 1

DINT_TO_BCD _DINT *1

X000
DINT_TO_BCD_E

Label 1

DINT_TO_BCD_E EN ENO _DINT *1

Label 2

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DINT ( s ) ENO *1 ( d ) Execution condition Conversion source double word [signed] data Execution status BCD data after conversion Description Bit Double Word [signed] Bit ANY_BIT Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [signed] data stored in a device specified in outputs the data obtained by conversion to a device specified in d .
99999999 Double word [signed] data 99999999 99999999H ANY_BIT data
s

into BCD data, and

Make sure to set them to "0".


107 106 105

104

103

102

99999999H

Ten-millions Millions HundredTen- Thousands Hundreds place place thousands thousands place place place place

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

76

8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1

1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 Tens place Ones place

101

231 230 229 228 227 226 225 224 223 222 221 220 219 218 217 216 215 214 213 212 211 210 29 28 27 26 25 24 23 22 21 20

0 0 0 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 Conversion into BCD data

FXCPU Structured Programming Manual [Application Functions] Error

5 Applied Functions (Type Conversion Functions)

1
Outline

An operation error occurs when the value stored in a device specified in "99,999,999".

is outside the range from "0" to

Program example
In this program, double word [signed] data stored in a device specified in s and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DINT_TO_BCD)
[Structured ladder/FBD]

is converted into BCD data,

2
Function/ Operator List

g_dint1=20000
[ST]

DINT_TO_BCD _DINT

3
g_dword1=16#00020000
Function Construction

g_dword1 := DINT_TO_BCD(g_dint1);

2) Function with EN/ENO(DINT_TO_BCD_E)


[Structured ladder/FBD]

4
How to Read Explanation of Functions

g_bool1 g_dint1
[ST]

DINT_TO_BCD_E EN ENO _DINT

g_bool3 g_dword1

5
Applied Functions (Type Conversion Functions)

g_bool3 := DINT_TO_BCD_E(g_bool1, g_dint1, g_dword1);

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

77

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.21

INT_TO_TIME(_E) / Word [signed] data time data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts word [signed] data into time data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST INT_TO_TIME(_INT); Example: Label:= INT_TO_TIME(D0); INT_TO_TIME_E(EN,_INT, Output label); Example: INT_TO_TIME_E(X000,D0,Label);

INT_TO_TIME

D0 X000

INT_TO_TIME _INT *1 INT_TO_TIME_E EN ENO _INT *1

Label

INT_TO_TIME_E

D0

Label

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _INT ( s ) ENO *1 ( d ) Execution condition Conversion source word [signed] data Execution status Time data after conversion Description Bit Word [signed] Bit Time Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [signed] data stored in a device specified in data obtained by conversion to a device specified in d .
FFFFh Word [signed] data 1m5s535ms Time data
s

into time data, and outputs the

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

78

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, word [signed] data stored in a device specified in data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(INT_TO_TIME)
[Structured ladder/FBD] [ST]

is converted into time data, and the

2
Function/ Operator List

g_int1

INT_TO_TIME _INT

g_time1 := INT_TO_TIME(g_int1);
g_time1

2) Function with EN/ENO(INT_TO_TIME_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_int1

INT_TO_TIME_E EN ENO _INT

g_bool3 := INT_TO_TIME_E(g_bool1, g_int1, g_time1);


g_bool3 g_time1

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

79

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.22

DINT_TO_TIME(_E) / Double word [signed] data time data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts double word [signed] data into time data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DINT_TO_TIME(_DINT); Example: Label 2 Label 2:= DINT_TO_TIME(Label 1); DINT_TO_TIME_E(EN,_DINT, Output label); Example: DINT_TO_TIME_E(X000, Label 1, Label 2);

DINT_TO_TIME

Label 1

DINT_TO_TIME _DINT *1

DINT_TO_TIME_ E

X000 Label 1

DINT_TO_TIME_E EN ENO _DINT *1

Label 2

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DINT ( s ) ENO *1 ( d ) Execution condition Conversion source double word [signed] data Execution status Time data after conversion Description Bit Double Word [signed] Bit Time Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [signed] data stored in a device specified in outputs the data obtained by conversion to a device specified in d .
7FFFFFFFh Double word [signed] data 24d20h31m23s647ms Time data
s

into time data, and

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

80

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, double word [signed] data stored in a device specified in the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DINT_TO_TIME)
[Structured ladder/FBD] [ST]

is converted into time data, and

2
Function/ Operator List

g_dint1

DINT_TO_TIME _DINT

g_time1 := DINT_TO_TIME(g_dint1);
g_time1

2) Function with EN/ENO(DINT_TO_TIME_E)


[Structured ladder/FBD] [ST]

3
Function Construction

g_bool1 g_dint1

DINT_TO_TIME_E EN ENO _DINT

g_bool3 := DINT_TO_TIME_E(g_bool1, g_dint1, g_time1);


g_bool3 g_time1

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

81

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.23

REAL_TO_INT(_E) / Float (single precision) data word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts float (single precision) data into word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST REAL_TO_INT(a_real); Example: D10:= REAL_TO_INT(Label); REAL_TO_INT_E(EN,a_real, Output label); Example: REAL_TO_INT_E(X000, Label, D10);

REAL_TO_INT

Label

REAL_TO_INT a_real *1

D10

X000
REAL_TO_INT_E

Label

REAL_TO_INT_E EN ENO a_real *1

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN a_real ENO *1 ( d ) ( s ) Execution condition Conversion source float (single precision) data Execution status Word [signed] data after conversion Description Bit FLOAT (Single Precision) Bit Word [signed] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts float (single precision) data stored in a device specified in and outputs the data obtained by conversion to a device specified in d .
1234.0 Float (single precision) data 1234 Word [signed] data The portion after the decimal point is rounded off.
s

into word [signed] data,

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) The function is provided in the FX3G Series Ver.1.10 or later. 4) In the data obtained by conversion, the portion after the decimal point of the float (single precision) data (source data) is rounded off. 5) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

82

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, float (single precision) data stored in a device specified in s is converted into word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(REAL_TO_INT)
[Structured ladder/FBD]

2
Function/ Operator List

g_real1=5923.5
[ST]

REAL_TO_INT a_real

g_int1=5923

g_int1 := REAL_TO_INT(g_real1);

3
Function Construction

2) Function with EN/ENO(REAL_TO_INT_E)


[Structured ladder/FBD]

g_bool1 g_real1
[ST]

REAL_TO_INT_E EN ENO a_real

g_bool3 g_int1

4
How to Read Explanation of Functions

g_bool3 := REAL_TO_INT_E(g_bool1, g_real1, g_int1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

83

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.24

REAL_TO_DINT(_E) / Float (single precision) data double word [signed] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts float (single precision) data into double word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST REAL_TO_DINT(a_real); Example: Label 2:= REAL_TO_DINT(Label 1); REAL_TO_DINT_E(EN,a_real, Output label); Example: REAL_TO_DINT_E(X000, Label 1, Label 2);

REAL_TO_DINT

Label 1

REAL_TO_DINT a_real *1

Label 2

REAL_TO_DINT_ E

X000 Label 1

REAL_TO_DINT_E EN ENO a_real *1

Label 2

*1.

Output variable

2. Set data
Variable Input variable Output variable EN a_real ENO *1 ( d ) ( s ) Execution condition Conversion source float (single precision) data Execution status Double word [signed] data after conversion Description Bit FLOAT (Single Precision) Bit Double Word [signed] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts float (single precision) data stored in a device specified in s [signed] data, and outputs the data obtained by conversion to a device specified in d .
16543521.0 FLOAT (single precision) data 16543521 Double word [signed] data The portion after the decimal point is rounded off.

into double word

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) The function is provided in the FX3G Series Ver.1.10 or later. 4) In the data obtained by conversion, the portion after the decimal point of the float (single precision) data (source data) is rounded off. 5) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

84

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, float (single precision) data stored in a device specified in s is converted into double word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(REAL_TO_DINT)
[Structured ladder/FBD]

2
Function/ Operator List

g_real1=65000.5
[ST]

REAL_TO_DINT a_real

g_dint1=65000

g_dint1 := REAL_TO_DINT(g_real1);

3
Function Construction

2) Function with EN/ENO(DINT_TO_TIME_E)


[Structured ladder/FBD]

g_bool1 g_real1
[ST]

REAL_TO_DINT_E EN ENO a_real

g_bool3 g_dint1

4
How to Read Explanation of Functions

g_bool3 := REAL_TO_DINT_E(g_bool1, g_real1, g_dint1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

85

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.25

REAL_TO_STR(_E) / Float (single precision) data string data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts float (single precision) data into string data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST REAL_TO_STR(_REAL); Example: Label 2:= REAL_TO_STR(Label 1); REAL_TO_STR_E(EN,_REAL, Output label); Example: REAL_TO_STR_E(X000, Label 1, Label 2);

REAL_TO_STR

Label 1

REAL_TO_STR _REAL *1

Label 2

X000
REAL_TO_STR_E

Label 1

REAL_TO_STR_E EN ENO _REAL *1

Label 2

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _REAL ( s ) ENO *1 ( d ) Execution condition Conversion source float (single precision) data Execution status String data after conversion Description Bit FLOAT (Single Precision) Bit String Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function converts float (single precision) data stored in a device specified in s (exponent) data, and outputs the data obtained by conversion to a device specified in d .
Float (single precision) data High-order byte 20H (space) ASCII code (2EH) for decimal point (.) ASCII code for 2nd decimal place ASCII code for 4th decimal place 45H(E) ASCII code for tens place of exponent part 00H Low-order byte Sign data (integer part) String ASCII code for integer part ASCII code for 1st decimal place ASCII code for 3rd decimal place ASCII code for 5th decimal place Sign data (exponent part) ASCII code for ones place of exponent part 1st word 2nd word 3rd word 4th word 5th word 6th word 7th word

into string

. Sign (integer part)

E Sign (exponent part) Added automatically

Automatically stored at the end of the character string

86

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

1
2) The string data obtained by conversion is output to a device specified in d as follows: a) The number of digits is fixed respectively for the integer part, decimal part and exponent part as follows: Integer part: 1, decimal part: 5, exponent part: 2 "2EH (.)" is automatically stored in the 3rd byte, and "45H (E)" is automatically stored in the 9th byte.
Total number of digits (12 digits) Integer part (1 digit) -12.3456 Float (single precision) data Decimal part (5 digits) Exponent part (2 digits)
Outline

2
Function/ Operator List

1 . 2 3 4 5 6 E + 0 1 "45H (E)" is stored. "2EH (.)" is stored.

3
Function Construction

b) In "Sign data (integer part)", "20H (space)" is stored when the input value is positive, and "2DH (-)" is stored when the input value is negative. c) The 6th and later digits of the decimal part are rounded.
Total number of digits (12 digits) 7 -12.345678 Float (single precision) data - 1 . 2 3 4 5 6 7 8 E + 0 1 Number of digits of decimal part (5) These digits are rounded.

4
How to Read Explanation of Functions

d) "30H (0)" is stored in the decimal part when the number of significant figures is small.
Total number of digits (12 digits) -12.34 Float (single precision) data - 1 . 2 3 4 0 0 E + 0 1 "30H (0)" is stored. Number of digits of decimal part (5)

5
Applied Functions (Type Conversion Functions)

e) In "Sign data (exponent part)", "2BH (+)" is stored when the input value is positive, and "2DH (-)" is stored when the input value is negative. f) "30H (0)" is stored in the tens place of the exponent part when the exponent part consists of 1 digit.
Total number of digits (12 digits) Number of digits of exponent part (2) -12.3456 Float (single precision) data - 1 . 2 3 4 5 6 E + 0 1 "30H (0)" is stored.

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

3) "00H" is automatically stored at the end (7th word) of the character string.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling character string data and 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling string data and 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

87

FXCPU Structured Programming Manual [Application Functions] Error

5 Applied Functions (Type Conversion Functions)

An operation error occurs in the following cases. The error flag M8067 turns ON, and D8067 stores the error code. 1) When the value stored in a device specified in s is outside the following range: 0, 2-126 (Value of device specified in s ) 2128 (Error code: K6706) 2) When the range of a device which will store the character string obtained by conversion (device specified in d ) exceeds the range of the corresponding device (Error code: K6706) 3) When the conversion result exceeds the specified total number of digits (Error code: K6706)

Program example
In this program, float (single precision) data stored in a device specified in s and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(REAL_TO_STR)
[Structured ladder/FBD]

is converted into string data,

g_real1=-12.34567
[ST]

REAL_TO_STR _REAL

g_string1="-1.23457E+01"

g_string1 := REAL_TO_STR(g_real1);

2) Function with EN/ENO(REAL_TO_STR_E)


[Structured ladder/FBD]

g_bool1 g_real1
[ST]

REAL_TO_STR_E EN ENO _REAL

g_bool3 g_string1

g_bool3 := REAL_TO_STR_E(g_bool1, g_real1, g_string1);

88

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.26

WORD_TO_BOOL(_E) / Word [unsigned] / bit string [16-bit] data bit data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts word [unsigned]/bit string [16-bit] data into bit data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST WORD_TO_BOOL(_WORD); Example: M0:= WORD_TO_BOOL(D0); WORD_TO_BOOL_E(EN, _WORD, Output label); Example: WORD_TO_BOOL_E(X000,D0, M0);

3
Function Construction

WORD_TO_BOO L

D0

WORD_TO_BOOL _WORD *1

M0

4
How to Read Explanation of Functions

WORD_TO_BOO L_E

X000 D0

WORD_TO_BOOL_E EN ENO *1 _WORD

M0

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _WORD ( s ) ENO *1 ( d ) Execution condition Conversion source word [unsigned]/bit String [16-bit] data Execution status Bit data after conversion Description Bit Word [unsigned]/ Bit String [16-bit] Bit Bit Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [unsigned]/bit string [16-bit] data stored in a device specified in and outputs the data obtained by conversion to a device specified in d .
0H 1567H Word [unsigned]/ bit string [16-bit] data FALSE TRUE Bit data
s

into bit data,

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

Cautions
Use the function having "_E" in its name to connect a bus.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

89

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

In this program, word [unsigned]/bit string [16-bit] data stored in a device specified in data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(WORD_TO_BOOL)
[Structured ladder/FBD]

is converted into bit

g_word1=16#0001
[ST]

WORD_TO_BOOL _WORD

g_bool1

g_bool1 := WORD_TO_BOOL(g_word1);

2) Function with EN/ENO(WORD_TO_BOOL_E)


[Structured ladder/FBD]

g_bool1 g_word1
[ST]

WORD_TO_BOOL_E EN ENO _WORD

g_bool3 g_bool2

g_bool3 := WORD_TO_BOOL_E(g_bool1, g_word1, g_bool2);

90

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.27

DWORD_TO_BOOL(_E) / Double word [unsigned]/bit string [32-bit] data bit data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts double word [unsigned]/bit string [32-bit] data into bit data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DWORD_TO_BOOL(_DWORD); Example: M0:= DWORD_TO_BOOL(Label); DWORD_TO_BOOL_E(EN, _DWORD, Output label); Example: DWORD_TO_BOOL_E(X000, Label, M0);

3
Function Construction

DWORD_TO_BO OL

Label

DWORD_TO_BOOL _DWORD *1

M0

4
How to Read Explanation of Functions

DWORD_TO_BO OL_E

X000 Label

DWORD_TO_BOOL_E EN ENO _DWORD *1

M0

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DWORD ( s ) ENO *1 ( d ) Execution condition Conversion source double word [unsigned]/bit string [32-bit] data Execution status Bit data after conversion Description Bit Double Word [unsigned]/ Bit string [32-bit] Bit Bit Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [unsigned]/bit string [32-bit] data stored in a device specified in bit data, and outputs the data obtained by conversion to a device specified in d .
0H 12345678H Double word [unsigned]/ bit string [32-bit] data FALSE TRUE Bit data
s

into

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

91

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

In this program, double word [unsigned]/bit string [32-bit] data stored in a device specified in into bit data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DWORD_TO_BOOL)
[Structured ladder/FBD]

is converted

g_dword1=16#00000001
[ST]

DWORD_TO_BOOL _DWORD

g_bool1

g_bool1 := DWORD_TO_BOOL(g_dword1);

2) Function with EN/ENO(DWORD_TO_BOOL_E)


[Structured ladder/FBD]

g_bool1 g_dword1
[ST]

DWORD_TO_BOOL_E EN ENO _DWORD

g_bool3 g_bool2

g_bool3 := DWORD_TO_BOOL_E(g_bool1, g_dword1, g_bool2);

92

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.28

WORD_TO_INT(_E) / Word [unsigned]/bit string [16-bit] data word [signed] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts word [unsigned]/bit string [16-bit] data into word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST WORD_TO_INT(_WORD); Example: D10:= WORD_TO_INT(D0); WORD_TO_INT_E(EN,_WORD, Output label); Example: WORD_TO_INT_E(X000,D0, D10);

3
Function Construction

WORD_TO_INT

D0

WORD_TO_INT _WORD *1

D10

4
How to Read Explanation of Functions

WORD_TO_INT_ E

X000 D0

WORD_TO_INT_E EN ENO _WORD *1

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _WORD ( s ) ENO *1 ( d ) Execution condition Conversion source word [unsigned]/bit string [16-bit] data Execution status Word [signed] data after conversion Description Bit Word [unsigned]/ Bit String [16-bit] Bit Word [signed] Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [unsigned]/bit string [16-bit] data stored in a device specified in [signed] data, and outputs the data obtained by conversion to a device specified in d .
5678H Word [unsigned]/ bit string [16-bit] data 22136 Word [signed] data
s

into word

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

Cautions
Use the function having "_E" in its name to connect a bus.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

93

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

In this program, word [unsigned]/bit string [16-bit] data stored in a device specified in s is converted into word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(WORD_TO_INT)
[Structured ladder/FBD]

g_word1=16#000A
[ST]

WORD_TO_INT _WORD

g_int1=10

g_int1 := WORD_TO_INT(g_word1);

2) Function with EN/ENO(WORD_TO_INT_E)


[Structured ladder/FBD]

g_bool1 g_word1
[ST]

WORD_TO_INT_E EN ENO _WORD

g_bool3 g_int1

g_bool3 := WORD_TO_INT_E(g_bool1, g_word1, g_int1);

94

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.29

WORD_TO_DINT(_E) / Word [unsigned]/bit string [16-bit] data double word [signed] (signed) data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts word [unsigned]/bit string [16-bit] data into double word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST WORD_TO_DINT(_WORD); Example: Label:= WORD_TO_DINT(D0); WORD_TO_DINT_E(EN,_WORD, Output label); Example: WORD_TO_DINT_E(X000,D0, Label);

3
Function Construction

WORD_TO_DINT

D0

WORD_TO_DINT _WORD *1

Label

4
How to Read Explanation of Functions

WORD_TO_DINT _E

X000 D0

WORD_TO_DINT_E EN ENO _WORD *1

Label

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _WORD ( s ) ENO *1 ( d ) Execution condition Conversion source word [unsigned]/bit string [16-bit] data Execution status Double word [signed] data after conversion Description Bit Word [unsigned]/ Bit String [16-bit] Bit Double Word [signed] Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [unsigned]/bit string [16-bit] data storeds in a device specified in s word [signed] data, and outputs the data obtained by conversion to a device specified in d .
5678H Word [unsigned]/ bit string [16-bit] data 5678H 22136 22136 Double word [signed] data

into double

7
Applied Functions (Standard Arithmetic Functions)

0 1 0 1 01 1 0 0 1 1 1 1 0 00 Data conversion 0 0 0 0 0 0 0 0 00 00 0 0 00 01 01 0 1 1 0 01 1 1 1 0 0 0 Each of high-order 16 bits becomes "0" after data conversion.

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

10
Applied Functions (Standard Selection Functions)

95

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

In this program, word [unsigned]/bit string [16-bit] data stored in a device specified in s is converted into double word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(WORD_TO_DINT)
[Structured ladder/FBD]

g_word1=16#1234
[ST]

WORD_TO_DINT _WORD

g_dint1=4660

g_dint1 := WORD_TO_DINT(g_word1);

2) Function with EN/ENO(WORD_TO_DINT_E)


[Structured ladder/FBD]

g_bool1 g_word1
[ST]

WORD_TO_DINT_E EN ENO _WORD

g_bool3 g_dint1

g_bool3 := WORD_TO_DINT_E(g_bool1, g_word1, g_dint1);

96

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.30

DWORD_TO_INT(_E) / Double word [unsigned]/bit string [32-bit] data Word [signed] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts double word [unsigned]/bit string [32-bit] data into word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DWORD_TO_INT(_DWORD); Example: D10:= DWORD_TO_INT(Label); DWORD_TO_INT_E(EN, _DWORD, Output label); Example: DWORD_TO_INT_E(X000,Label, D10);

3
Function Construction

DWORD_TO_INT

Label

DWORD_TO_INT _DWORD *1

D10

4
How to Read Explanation of Functions

DWORD_TO_INT _E

X000 Label

DWORD_TO_INT_E EN ENO _DWORD *1

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DWORD ( s ) ENO *1 ( d ) Execution condition Conversion source double word [unsigned]/bit string [32-bit] data Execution status Word [signed] data after conversion Description Bit Double Word [unsigned]/ Bit string [32-bit] Bit Word [signed] Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [unsigned]/bit string [32-bit] data stored in a device specified in word [signed] data, and outputs the data obtained by conversion to a device specified in d .
BC614EH Double word [unsigned]/ bit string [32-bit] data BC614EH 24910 The information stored in high-order 16 bits is discarded. 24910 Word [signed] data
s

into

7
Applied Functions (Standard Arithmetic Functions)

0 0 00 0 0 0 01 0 11 11 0 0 0 11 0 0 0 0 1 0 1 0 0 11 1 0 01 1 00 0 0 10 1 0 0 1 1 1 0

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

10
Applied Functions (Standard Selection Functions)

97

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

In this program, double word [unsigned]/bit string [32-bit] data stored in a device specified in s is converted into word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DWORD_TO_INT)
[Structured ladder/FBD]

g_dword1=16#00012345
[ST]

DWORD_TO_INT _DWORD

g_int1=9029

g_int1 := DWORD_TO_INT(g_dword1);

2) Function with EN/ENO(DWORD_TO_INT_E)


[Structured ladder/FBD]

g_bool1 g_dword1
[ST]

DWORD_TO_INT_E EN ENO _DWORD

g_bool3 g_int1

g_bool3 := DWORD_TO_INT_E(g_bool1, g_dword1, g_int1);

98

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.31

DWORD_TO_DINT(_E) / Double word [unsigned]/bit string [32-bit] data double word [signed] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts double word [unsigned]/bit string [32-bit] data into double word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DWORD_TO_DINT(_DWORD); Example: Label 2 Label 2:= DWORD_TO_DINT(Label 1); DWORD_TO_DINT_E(EN, _DWORD, Output label); Example: Label 2 DWORD_TO_DINT_E(X000, Label 1, Label 2);

3
Function Construction

DWORD_TO_DIN T

Label 1

DWORD_TO_DINT _DWORD *1

4
How to Read Explanation of Functions

DWORD_TO_DIN T_E

X000 Label 1

DWORD_TO_DINT_E EN ENO _DWORD *1

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DWORD ( s ) ENO *1 ( d ) Execution condition Conversion source double word [unsigned]/bit string [32-bit] data Execution status Double word [signed] data after conversion Description Bit Double Word [unsigned]/ Bit string [32-bit] Bit Double Word [signed] Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [unsigned]/bit string [32-bit] data stored in a device specified in s double word [signed] data, and outputs the data obtained by conversion to a device specified in d .
BC614EH Double word [unsigned]/ bit string [32-bit] data 12345678 Double word [signed] data

into

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

99

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

In this program, double word [unsigned]/bit string [32-bit] data stored in a device specified in s is converted into double word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DWORD_TO_DINT)
[Structured ladder/FBD]

g_dword1=16#00012345
[ST]

DWORD_TO_DINT _DWORD

g_dint1=74565

g_dint1 := DWORD_TO_DINT(g_dword1);

2) Function with EN/ENO(DWORD_TO_DINT_E)


[Structured ladder/FBD]

g_bool1 g_dword1
[ST]

DWORD_TO_DINT_E EN ENO _DWORD

g_bool3 g_dint1

g_bool3 := DWORD_TO_DINT_E(g_bool1, g_dword1, g_dint1);

100

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.32

WORD_TO_DWORD(_E) / Word [unsigned]/bit string [16-bit] data double word [unsigned]/bit string [32-bit data conversion]
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts word [unsigned]/bit string [16-bit] data into double word [unsigned]/bit string [32-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST WORD_TO_DWORD(_WORD); Example: Label:= WORD_TO_DWORD(D0);

3
Function Construction

WORD_TO_DWO RD

D0

WORD_TO_DWORD _WORD *1

Label

WORD_TO_DWO RD_E

X000 D0

WORD_TO_DWORD_E EN ENO _WORD *1

WORD_TO_DWORD_E(EN, _WORD, Output label); Example: Label WORD_TO_DWORD_E(X000,D0, Label);

4
How to Read Explanation of Functions

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _WORD ( s ) ENO *1 ( d ) Execution condition Conversion source word [unsigned]/bit string [16-bit] data Execution status Double word[unsigned]/bit string[32-bit] data after conversion Description Bit Word [unsigned]/ Bit String [16-bit] Bit Double Word [unsigned]/ Bit string [32-bit] Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [unsigned]/bit string [16-bit] data stored in a device specified in s into double word [unsigned]/bit [32-bit] data, and outputs the data obtained by conversion to a device specified in d . Each of high-order 16 bits becomes "0" after data conversion.
5678H Word [unsigned]/ bit string [16-bit] data 00005678H Double word [unsigned]/ bit string [32-bit] data

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

101

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

In this program, word [unsigned]/bit string [16-bit] data stored in a device specified in s is converted into double word [unsigned]/bit string [32-bit] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(WORD_TO_DWORD)
[Structured ladder/FBD]

g_word1=16#1234
[ST]

WORD_TO_DWORD _WORD

g_dword1=16#00001234

g_dword1 := WORD_TO_DWORD(g_word1);

2) Function with EN/ENO(WORD_TO_DWORD_E)


[Structured ladder/FBD]

g_bool1 g_word1
[ST]

WORD_TO_DWORD_E EN ENO _WORD

g_bool3 g_dword1

g_bool3 := WORD_TO_DWORD_E(g_bool1, g_word1, g_dword1);

102

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.33

DWORD_TO_WORD(_E) / Double word [unsigned]/bit string[32-bit] data word [unsigned]/bit string [16-bit] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts double word [unsigned]/bit string[32-bit] data into word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DWORD_TO_WORD(_DWORD); Example: D10:= DWORD_TO_WORD(Label); DWORD_TO_WORD_E(EN, _DWORD, Output label); Example: DWORD_TO_WORD_E(X000, Label, D10);

3
Function Construction

DWORD_TO_WO RD

Label

DWORD_TO_WORD _DWORD *1

D10

4
How to Read Explanation of Functions

DWORD_TO_WO RD_E

X000 Label

DWORD_TO_WORD_E EN ENO _DWORD *1

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DWORD ( s ) ENO *1 ( d ) Execution condition Conversion source double word [unsigned]/bit string [32-bit] data Execution status Word [unsigned]/bit string [16-bit] data after conversion Description Bit Double Word [unsigned] /Bit string [32-bit] Bit Word [unsigned]/ Bit String [16-bit] Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [unsigned]/bit string [32-bit] data stored in a device specified in s into word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion to a device specified in d .
12345678H Double word [unsigned]/ bit string [32-bit] data 1 2 3 4 5678H Word [unsigned]/ bit string [16-bit] data 5 6 7 8

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

12345678H 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 5678H 0 1 01 0 1 1 0 0 1 1 1 1 0 00

9
Applied Functions (Standard Bitwise Boolean Functions)

The information stored in high-order 16 bits is discarded.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

10
Applied Functions (Standard Selection Functions)

103

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

In this program, double word [unsigned]/bit string [32-bit] data stored in a device specified in s is converted into word [unsigned]/bit string [16-bit] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(WORD_TO_DWORD)
[Structured ladder/FBD]

g_dword1=16#12345678
[ST]

DWORD_TO_WORD _DWORD

g_word1=16#5678

g_word1 := DWORD_TO_WORD(g_dword1);

2) Function with EN/ENO(WORD_TO_DWORD_E)


[Structured ladder/FBD]

g_bool1 g_dword1
[ST]

DWORD_TO_WORD_E EN ENO _DWORD

g_bool3 g_word1

g_bool3 := DWORD_TO_WORD_E(g_bool1, g_dword1, g_word1);

104

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.34

WORD_TO_TIME(_E) / Word [unsigned]/bit string [16-bit] data time data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts word [unsigned]/bit string [16-bit] data into time data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST WORD_TO_TIME(_WORD); Example: Label:= WORD_TO_TIME(D0); WORD_TO_TIME_E(EN,_WORD, Output label); Example: WORD_TO_TIME_E(X000,D0, Label);

3
Function Construction

WORD_TO_TIME

D0

WORD_TO_TIME _WORD *1

Label

4
How to Read Explanation of Functions

WORD_TO_TIME _E

X000 D0

WORD_TO_TIME_E EN ENO _WORD *1

Label

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _WORD ( s ) ENO *1 ( d ) Execution condition Conversion source word [unsigned]/bit string [16-bit] data Execution status Time data after conversion Description Bit Word [unsigned]/ Bit String[ 16-bit] Bit Time Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts word [unsigned]/bit string [16-bit] data stored in a device specified in data, and outputs the data obtained by conversion to a device specified in d .
0 1234 Word [unsigned]/ bit string [16-bit] data 0ms 1s234ms Time data
s

into time

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

105

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

In this program, word [unsigned]/bit string [16-bit] data stored in a device specified in time data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(WORD_TO_TIME)
[Structured ladder/FBD]

is converted into

g_word1
[ST]

WORD_TO_TIME _WORD

g_time1

g_time1 := WORD_TO_TIME(g_word1);

2) Function with EN/ENO(WORD_TO_TIME_E)


[Structured ladder/FBD]

g_bool1 g_word1
[ST]

WORD_TO_TIME_E EN ENO _WORD

g_bool3 g_time1

g_bool3 := WORD_TO_TIME_E(g_bool1, g_word1, g_time1);

106

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.35

DWORD_TO_TIME(_E) / Double word [unsigned]/bit string [32-bit] data time data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts double word [unsigned]/bit string [32-bit] data into time data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST DWORD_TO_TIME(_DWORD); Example: Label 2 Label 2:= DWORD_TO_TIME(Label 1); DWORD_TO_TIME_E(EN,_ DWORD, Output label); Example: Label 2 DWORD_TO_TIME_E(X000, Label 1, Label 2);

3
Function Construction

DWORD_TO_TIM E

Label 1

DWORD_TO_TIME _DWORD *1

4
How to Read Explanation of Functions

DWORD_TO_TIM E_E

X000 Label 1

DWORD_TO_TIME_E EN ENO _DWORD *1

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _DWORD ( s ) ENO *1 ( d ) Execution condition Conversion source double word [unsigned]/bit string [32-bit] data Execution status Time data after conversion Description Bit Double Word [unsigned]/ Bit string [32-bit] Bit Time Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts double word [unsigned]/bit string [32-bit] data stored in a device specified in time data, and outputs the data obtained by conversion to a device specified in d .
0 1234567 Double word [unsigned]/ bit string [32-bit] data 0ms 20m34s567ms Time data
s

into

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

107

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

In this program, double word [unsigned]/bit string [32-bit] data stored in a device specified in into time data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(DWORD_TO_TIME)
[Structured ladder/FBD]

is converted

g_dword1
[ST]

DWORD_TO_TIME _DWORD

g_time1

g_time1 := DWORD_TO_TIME(g_dword1);

2) Function with EN/ENO(DWORD_TO_TIME_E)


[Structured ladder/FBD]

g_bool1 g_dword1
[ST]

DWORD_TO_TIME_E EN ENO _DWORD

g_bool3 g_time1

g_bool3 := DWORD_TO_TIME_E(g_bool1, g_dword1, g_time1);

108

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.36

STR_TO_BOOL(_E) / String data bit data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function converts string data into bit data, and outputs the data obtained by conversion.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST STR_TO_BOOL(_STRING); Example: M0:= STR_TO_BOOL(Label); STR_TO_BOOL_E(EN,_STRING, Output label); Example: STR_TO_BOOL_E(X000, Label, M0);

3
Function Construction

STR_TO_BOOL

Label

STR_TO_BOOL _STRING *1

M0

STR_TO_BOOL_ E

X000 Label

STR_TO_BOOL_E EN ENO *1 _STRING

M0

4
How to Read Explanation of Functions

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _STRING ( s ) ENO *1 ( d ) Execution condition Conversion source string data Execution status Bit data after conversion Description Bit String Bit Bit Data type

5
Applied Functions (Type Conversion Functions)

In explanation of functions, I/O variables inside ( ) are described.

6
Applied Functions (Standard Functions Of One Numeric Variable)

Explanation of function and operation


This function converts string data stored in a device specified in obtained by conversion to a device specified in d .
'0' '12' String data FALSE TRUE Bit data
s

into bit data, and outputs the data

7
Applied Functions (Standard Arithmetic Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling character string data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling string data. Use global labels when specifying labels.

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

109

FXCPU Structured Programming Manual [Application Functions] Program example


In this program, string data stored in a device specified in obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(STR_TO_BOOL)
[Structured ladder/FBD]

5 Applied Functions (Type Conversion Functions)

is converted into bit data, and the data

g_string1
[ST]

STR_TO_BOOL _STRING

g_bool1

g_bool1 := STR_TO_BOOL(g_string1);

2) Function with EN/ENO(STR_TO_BOOL_E)


[Structured ladder/FBD]

g_bool1 g_string1
[ST]

STR_TO_BOOL_E EN ENO _STRING

g_bool3 g_bool2

g_bool3 := STR_TO_BOOL_E(g_bool1, g_string1, g_bool2);

110

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.37

STR_TO_INT(_E) / String data word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function converts string data into word [signed] data, and outputs the data obtained by conversion.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST STR_TO_INT(_STRING); Example: D10:= STR_TO_INT(Label); STR_TO_INT_E(EN,_STRING, Output label); Example: STR_TO_INT_E(X000, Label, D10);

3
Function Construction

STR_TO_INT

Label

STR_TO_INT _STRING *1

D10

X000
STR_TO_INT_E

Label

STR_TO_INT_E EN ENO _STRING *1

D10

4
How to Read Explanation of Functions

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _STRING ( s ) ENO *1 ( d ) Execution condition Conversion source string data Execution status Word [signed] data after conversion Description Bit String Bit Word [signed] Data type

5
Applied Functions (Type Conversion Functions)

In explanation of functions, I/O variables inside ( ) are described.

6
Applied Functions (Standard Functions Of One Numeric Variable)

Explanation of function and operation


This function converts string data (3 words) stored in a device specified in outputs the data obtained by conversion to a device specified in d .
String 1st word 2nd word 3rd word High-order byte Low-order byte Sign data ASCII code for ten-thousands place ASCII code for hundreds place ASCII code for thousands place ASCII code for ones place ASCII code for tens place Word [signed] data
s

into word [signed] data, and

7
Applied Functions (Standard Arithmetic Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling string data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling string data. Use global labels when specifying labels.

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

111

FXCPU Structured Programming Manual [Application Functions] Error

5 Applied Functions (Type Conversion Functions)

1) When the sign data (low-order byte) of the 1st word stored in a device specified in "20H (space)" or "2DH (-)" (Error code: K6706) 2) When the ASCII code for each place (digit) stored in "20H (space)" or "00H (NULL)" (Error code: K6706) 3) When the value stored in -32768 to +32767 (Error code: K6706) 4) When any of devices (Error code: K6706)
s s s

is any other than

to

+2 is any other than "30H" to "39H",

to

+2 is outside the following range:

to

+2 exceeds the device range

Program example
In this program, string data stored in a device specified in s is converted into word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(STR_TO_INT)
[Structured ladder/FBD]

g_string1="-12345"
[ST]

STR_TO_INT _STRING

g_int1=-12345

g_int1 := STR_TO_INT(g_string1);

2) Function with EN/ENO(STR_TO_INT_E)


[Structured ladder/FBD]

g_bool1 g_string1
[ST]

STR_TO_INT_E EN ENO _STRING

g_bool3 g_int1

g_bool3 := STR_TO_INT_E(g_bool1, g_string1, g_int1);

112

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.38

STR_TO_DINT(_E) / String data double word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts string data into double word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST STR_TO_DINT(_STRING); Example: Label 2 Label 2:= STR_TO_DINT(Label 1); STR_TO_DINT_E(EN,_STRING, Output label); Example: Label 2 STR_TO_DINT_E(X000, Label 1, Label 2);

3
Function Construction

STR_TO_DINT

Label 1

STR_TO_DINT _STRING *1

4
How to Read Explanation of Functions

X000
STR_TO_DINT_E

Label 1

STR_TO_DINT_E EN ENO _STRING *1

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _STRING ( s ) ENO *1 ( d ) Execution condition Conversion source string data Execution status Double word [signed] data after conversion Description Bit String Bit Double Word [signed] Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts string data (6 words) stored in a device specified in s data, and outputs the data obtained by conversion to a device specified in d .
String 1st word 2nd word 3rd word 4th word 5th word 6th word High-order byte Low-order byte ASCII code for billions place Sign data ASCII code for ten-millions place ASCII code for hundred-millions place ASCII code for hundred-thousands place ASCII code for millions place ASCII code for thousands place ASCII code for ten-thousands place ASCII code for tens place ASCII code for hundreds place ASCII code for ones place (Ignore)

into double word [signed]

7
Applied Functions (Standard Arithmetic Functions)

Double word [signed] data

8
Applied Functions (Standard Bit Shift Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling string data and 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling string data and 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

113

FXCPU Structured Programming Manual [Application Functions] Error

5 Applied Functions (Type Conversion Functions)

1) When the sign data (low-order byte) of the 1st word stored in a device specified in "20H (space)" or "2DH (-)" (Error code: K6706) 2) When the ASCII code for each place (digit) stored in "20H (space)" or "00H (NULL)" (Error code: K6706)
s

is any other than

to

+5 is any other than "30H" to "39H",

3) When the value stored in s to s +5 is outside the following range: -2,147,483,648 to +2,147,483,647 (Error code: K6706) 4) When any of devices (Error code: K6706)
s

to

+5 exceeds the device range

Program example
In this program, string data stored in a device specified in s is converted into double word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(STR_TO_DINT)
[Structured ladder/FBD]

g_string1="_ _65000"
[ST]

STR_TO_DINT _STRING

g_dint1=65000

g_dint1 := STR_TO_DINT(g_string1);

2) Function with EN/ENO(STR_TO_DINT_E)


[Structured ladder/FBD]

g_bool1 g_string1
[ST]

STR_TO_DINT_E EN ENO _STRING

g_bool3 g_dint1

g_bool3 := STR_TO_DINT_E(g_bool1, g_string1, g_dint1);

114

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.39

STR_TO_REAL(_E) / String data float (single precision) data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

2
Function/ Operator List

Outline
This function converts string data into float (single precision) data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST STR_TO_REAL(_STRING); Example: Label 2 Label 2:= STR_TO_REAL(Label 1); STR_TO_REAL_E(EN,_STRING, Output label); Example: Label 2 STR_TO_REAL_E(X000, Label 1, Label 2);

3
Function Construction

STR_TO_REAL

Label 1

STR_TO_REAL _STRING *1

4
How to Read Explanation of Functions

X000
STR_TO_REAL_E

Label 1

STR_TO_REAL_E EN ENO *1 _STRING

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _STRING ( s ) ENO *1 ( d ) Execution condition Conversion source string data Execution status Float (single precision) data after conversion Description Bit String Bit FLOAT (Single Precision) Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function converts string data (in the decimal format or exponent format) stored in a device specified in s into float (single precision) data, and outputs the data obtained by conversion to a device specified in d .
String 1st word 2nd word 3rd word 4th word 5th word 6th word 7th word Low-order byte High-order byte ASCII code for 1st character Sign data ASCII code for 3rd character ASCII code for 2nd character ASCII code for 5th character ASCII code for 4th character ASCII code for 7th character ASCII code for 6th character ASCII code for 9th character ASCII code for 8th character ASCII code for 11th character ASCII code for 10th character 0000H (Indicates the end of the character string.)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

Float (single precision) data

2) The conversion source string data can be in the decimal format or exponent format. a) In the case of decimal format
String 1st word 2nd word 3rd word 4th word 5th word High-order byte 31H (1) 33H (3) 30H (0) 34H (4) 0000H - 1 . 3 5 0 3 4 Float (single precision) data Low-order byte 2DH (-) 2EH (.) 35H (5) 33H (3)

9
Applied Functions (Standard Bitwise Boolean Functions)

-1.35034

10
Applied Functions (Standard Selection Functions)

115

FXCPU Structured Programming Manual [Application Functions]


b) In the case of exponent format
String 1st word 2nd word 3rd word 4th word 5th word 6th word 7th word High-order byte 31H (1) 33H (3) 30H (0) 34H (4) 2DH (-) 30H (0) 0000H

5 Applied Functions (Type Conversion Functions)

Low-order byte 2DH (-) 2EH (3) 35H (5) 33H (3) 45H (E) 31H (1)

-1.35034E-10 Float (single precision) data

- 1 . 3 5 0 3 4 E - 1 0

3) With regard to string data, six digits excluding the sign, decimal point and exponent part are valid, and the 7th and later digits are discarded during conversion. a) In the case of decimal format
- 1 . 3 5 0 3 4 1 2 0 2 3 Discarded -1.35034 Float (single precision) data

b) In the case of exponent format


- 1 . 3 5 0 3 4 1 2 E - 1 0 Discarded -1.35034E-10 Float (single precision) data

4) String data in the decimal format is handled as positive value during conversion when the sign is set to "2BH (+)" or when the sign is omitted. It is handled as negative value during conversion when the sign is set to "2DH (-)". 5) String data in the exponent format is handled as positive value during conversion when the sign of the exponent part is set to "2BH (+)" or when the sign is omitted. It is handled as negative value during conversion when the sign is set to "2DH (-)". 6) When "20H (space)" or "30H (0)" exists between the sign and the first number except "0" in string data, "20H (space)" or "30H (0)" is ignored during conversion. a) In the case of decimal format
0 1 . 3 5 0 3 4 Ignored -1.35034 Float (single precision) data

b) In the case of exponent format


0 1 . 3 5 0 3 4 E - 1 0 Ignored -1.35034E-10 Float (single precision) data

7)

When "30H (0)" exists between "E" and a number in character string data (in the exponent format), "30H (0)" is ignored during conversion.
- 1 . 3 5 0 3 4 E - 0 2 Ignored -1.35034E-2 Float (single precision) data

8) When "20H (space)" is contained in character string, "20H (space)" is ignored during conversion. 9) Up to 24 characters can be input as string data. Each of "20H (space)" and "30H (0)" contained in string is counted as 1 character respectively.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling string data and 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling string data and 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

116

FXCPU Structured Programming Manual [Application Functions] Error

5 Applied Functions (Type Conversion Functions)

1
Outline

An operation error occurs in the following cases. The error flag M8067 turns ON, and D8067 stores the error code. 1) When any character other than "30H (0)" to "39H (9)" exists in the integer or decimal part (Error code: K6706) 2) When "2EH (.)" exists in two or more positions inside the character string specified in (Error code: K6706)
s

2
Function/ Operator List

3) When any character other than "45H (E)", "2BH (+)" or "2DH (-)" exists in the exponent part, or when two or more exponent parts exist (Error code: K6706) 4) When the number of characters after (Error code: K6706)
s

is "0" or any value larger than "24"

3
Function Construction

Program example
In this program, string data stored in a device specified in s is converted into float (single precision) data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(STR_TO_REAL)
[Structured ladder/FBD]

4
How to Read Explanation of Functions

g_string1
[ST]

STR_TO_REAL _STRING

g_real1

5
Applied Functions (Type Conversion Functions)

g_real1 := STR_TO_REAL(g_string1);

2) Function with EN/ENO(STR_TO_REAL_E)


[Structured ladder/FBD]

g_bool1 g_string1
[ST]

STR_TO_REAL_E EN ENO _STRING

6
Applied Functions (Standard Functions Of One Numeric Variable)

g_bool3 g_real1

g_bool3 := STR_TO_REAL_E(g_bool1, g_string1, g_real1);

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

117

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.40

STR_TO_TIME(_E) / String data time data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts string data into time data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST STR_TO_TIME(_STRING); Example: Label 2:= STR_TO_TIME(Label 1); STR_TO_TIME_E(EN,_STRING, Output label); Example: STR_TO_TIME_E(X000, Label 1, Label 2);

STR_TO_TIME

Label 1

STR_TO_TIME _STRING *1

Label 2

X000
STR_TO_TIME_E

Label 1

STR_TO_TIME_E EN ENO _STRING *1

Label 2

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _STRING ( s ) ENO *1 ( d ) Execution condition Conversion source string data Execution status Time data after conversion Description Bit String Bit Time Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts string data stored in a device specified in obtained by conversion to a device specified in d .
'0' '1234567' String data 0ms 20m34s567ms Time data
s

into time data, and outputs the data

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling string data and 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling string data and 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

118

FXCPU Structured Programming Manual [Application Functions] Error

5 Applied Functions (Type Conversion Functions)

1
Outline

An operation error occurs in the following cases. The error flag M8067 turns ON, and D8067 stores the error code. 1) When the sign data of numeric data specified in (Error code: K6706)
s

is any other than "20H (space)" or "2DH (-)"


s

2) When the ASCII code for each digit of character string data specified in "39H (9)", "20H (space)" or "00H (NULL)" (Error code: K6706) 3) When the numeric value specified in -2,147,483,648 to +2,147,483,647 (Error code: K6706)
s

is any other than "30H (0)" to

2
Function/ Operator List

is outside the following range:

3
Function Construction

Program example
In this program, string data stored in a device specified in s obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(STR_TO_TIME)
[Structured ladder/FBD]

is converted into time data, and the data

4
How to Read Explanation of Functions

g_string1
[ST]

STR_TO_TIME _STRING

g_time1

g_time1 := STR_TO_TIME(g_string1);

5
Applied Functions (Type Conversion Functions)

2) Function with EN/ENO(STR_TO_TIME_E)


[Structured ladder/FBD]

g_bool1 g_string1
[ST]

STR_TO_TIME_E EN ENO _STRING

g_bool3 g_time1

6
Applied Functions (Standard Functions Of One Numeric Variable)

g_bool3 := STR_TO_TIME_E(g_bool1, g_string1, g_time1);

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

119

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.41

BCD_TO_INT(_E) / BCD data word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts BCD data into word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST BCD_TO_INT(_BCD); Example: D10:= BCD_TO_INT(D0); BCD_TO_INT_E(EN,_BCD, Output label); Example: BCD_TO_INT_E(X000,D0,D10);

BCD_TO_INT

D0 X000

BCD_TO_INT _BCD *1 BCD_TO_INT_E EN ENO _BCD *1

D10

BCD_TO_INT_E

D0

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _BCD ( s ) ENO *1 ( d ) Execution condition Conversion source BCD data Execution status Word [signed] data after conversion Description Bit Word [unsigned]/ Bit String [16-bit] Bit Word [signed] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts BCD data stored in a device specified in data obtained by conversion to a device specified in d .
9999H Word [unsigned]/ bit string [16-bit] data
8000 4000 2000 1000 800 400 200 100

into word [signed] data, and outputs the

9999 Word [signed] data


80 40 20 10 8 4 2 1

9999H

Thousands place Hundreds place

Tens place Ones place Conversion into word [signed] data


64 32 16 8 4 2 1

3276516354 8192 4095 2048 1024 512 256 128

9999

Always becomes "0".

Cautions
Use the function having "_E" in its name to connect a bus.

Error
When the source data is not BCD (decimal number), M8067 (operation error) turns ON.

120

FXCPU Structured Programming Manual [Application Functions] Program example


In this example, BCD data stored in a device specified in s data obtained by conversion is output to a device specified in 1) Function without EN/ENO(BCD_TO_INT)
[Structured ladder/FBD]

5 Applied Functions (Type Conversion Functions)

1
Outline

is converted into word [signed] data, and the .

2
Function/ Operator List

g_word1=16#1234
[ST]

BCD_TO_INT _BCD

g_int1=1234

g_int1 := BCD_TO_INT(g_word1);

3
Function Construction

2) Function with EN/ENO(BCD_TO_INT_E)


[Structured ladder/FBD]

g_bool1 g_word1
[ST]

BCD_TO_INT_E EN ENO _BCD

g_bool3 g_int1

4
How to Read Explanation of Functions

g_bool3 := BCD_TO_INT_E(g_bool1, g_word1, g_int1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

121

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.42

BCD_TO_DINT(_E) / BCD data double word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts BCD data into double word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST BCD_TO_DINT(_BCD); Example: Label 2:= BCD_TO_DINT(Label 1); BCD_TO_DINT_E(EN,_BCD, Output label); Example: BCD_TO_DINT_E(X000, Label 1, Label 2);

BCD_TO_DINT

Label 1

BCD_TO_DINT _BCD *1

Label 2

X000
BCD_TO_DINT_E

Label 1

BCD_TO_DINT_E EN ENO _BCD *1

Label 2

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _BCD ( s ) ENO *1 ( d ) Execution condition Conversion source BCD data Execution status Double word [signed] data after conversion Description Bit ANY_BIT Bit Double Word [signed] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts BCD data stored in a device specified in s outputs the data obtained by conversion to a device specified in d .
99999999H ANY_BIT data
107 106 105

into double word [signed] data, and

99999999 Double word [signed] data


104 103 102 101 100

99999999H 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 Tenmillions place Millions HundredTen- Thousands Hundreds Tens place thousands thousands place place place place place Conversion into DINT data Ones place

99999999 0 0 0 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1 Always becomes "0".

Cautions
Use the function having "_E" in its name to connect a bus.

Error
When the source data is not BCD (decimal number), M8067 (operation error) turns ON.

122

231 230 229 228 227 226 225 224 223 222 221 220 219 218 217 216 215 214 213 212 211 210 29 28 27 26 25 24 23 22 21 20

8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this example, BCD data stored in a device specified in s is converted into double word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(BCD_TO_DINT)
[Structured ladder/FBD]

2
Function/ Operator List

g_word1=16#0000
[ST]

BCD_TO_DINT _BCD

g_dint1=0

g_dint1 := BCD_TO_DINT(g_word1);

3
Function Construction

2) Function with EN/ENO(BCD_TO_DINT_E)


[Structured ladder/FBD]

g_bool1 g_word1
[ST]

BCD_TO_DINT_E EN ENO _BCD

g_bool3 g_dint1

4
How to Read Explanation of Functions

g_bool3 := BCD_TO_DINT_E(g_bool1, g_word1, g_dint1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

123

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.43

TIME_TO_BOOL(_E) / Time data bit data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts time data into bit data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST TIME_TO_BOOL(_TIME); Example: M0:= TIME_TO_BOOL(Label); TIME_TO_BOOL_E(EN,_TIME, Output label); Example: TIME_TO_BOOL_E(X000, Label, M0);

TIME_TO_BOOL

Label

TIME_TO_BOOL _TIME *1

M0

TIME_TO_BOOL_ E

X000 Label

TIME_TO_BOOL_E EN ENO _TIME *1

M0

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _TIME ( s ) ENO *1 ( d ) Execution condition Conversion source time data Execution status Bit data after conversion Description Bit Time Bit Bit Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts time data stored in a device specified in obtained by conversion to a device specified in d .
0ms 20m34s567ms Time data FALSE TRUE Bit data
s

into bit data, and outputs the data

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

124

FXCPU Structured Programming Manual [Application Functions] Program example


In this program, time data stored in a device specified in by conversion is output to a device specified in d . 1) Function without EN/ENO(TIME_TO_BOOL)
[Structured ladder/FBD]

5 Applied Functions (Type Conversion Functions)

1
Outline

is converted into bit data, and the data obtained

2
Function/ Operator List

g_time1
[ST]

TIME_TO_BOOL _TIME

g_bool1

g_bool1 := TIME_TO_BOOL(g_time1);

3
Function Construction

2) Function with EN/ENO(TIME_TO_BOOL_E)


[Structured ladder/FBD]

g_bool1 g_time1
[ST]

TIME_TO_BOOL_E EN ENO _TIME

g_bool3 g_bool2

4
How to Read Explanation of Functions

g_bool3 := TIME_TO_BOOL_E(g_bool1, g_time1, g_bool2);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

125

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.44

TIME_TO_INT(_E) / Time data word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts time data into word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST TIME_TO_INT(_TIME); Example: D10:= TIME_TO_INT(Label); TIME_TO_INT_E(EN,_TIME, Output label); Example: TIME_TO_INT_E(X000, Label, D10);

TIME_TO_INT

Label

TIME_TO_INT _TIME *1

D10

X000
TIME_TO_INT_E

Label

TIME_TO_INT_E EN ENO _TIME *1

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _TIME ( s ) ENO *1 ( d ) Execution condition Conversion source time data Execution status Word [signed] data after conversion Description Bit Time Bit Word [signed] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts time data stored in a device specified in data obtained by conversion to a device specified in d .
1s234ms Time data 1234 Word [signed] data
s

into word [signed] data, and outputs the

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

126

FXCPU Structured Programming Manual [Application Functions] Program example


In this program, time data stored in a device specified in s data obtained by conversion is output to a device specified in 1) Function without EN/ENO(TIME_TO_INT)
[Structured ladder/FBD]

5 Applied Functions (Type Conversion Functions)

1
Outline

is converted into word [signed] data, and the d .

2
Function/ Operator List

g_time1
[ST]

TIME_TO_INT _TIME

g_int1

g_int1 := TIME_TO_INT(g_time1);

3
Function Construction

2) Function with EN/ENO(TIME_TO_INT_E)


[Structured ladder/FBD]

g_bool1 g_time1
[ST]

TIME_TO_INT_E EN ENO _TIME

g_bool3 g_int1

4
How to Read Explanation of Functions

g_bool3 := TIME_TO_INT_E(g_bool1, g_time1, g_int1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

127

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.45

TIME_TO_DINT(_E) / Time data double word [signed] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts time data into double word [signed] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST TIME_TO_DINT(_TIME); Example: Label 2:= TIME_TO_DINT(Label 1); TIME_TO_DINT_E(EN,_TIME, Output label); Example: TIME_TO_DINT_E(X000,Label 1, Label 2);

TIME_TO_DINT

Label 1

TIME_TO_DINT _TIME *1

Label 2

TIME_TO_DINT_ E

X000 Label 1

TIME_TO_DINT_E EN ENO _TIME *1

Label 2

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _TIME ( s ) ENO *1 ( d ) Execution condition Conversion source time data Execution status Double word [signed] data after conversion Description Bit Time Bit Double Word [signed] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts time data stored in a device specified in s outputs the data obtained by conversion to a device specified in d .
20m34s567ms Time data 1234567 Double word [signed] data

into double word [signed] data, and

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

128

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, time data stored in a device specified in s is converted into double word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(TIME_TO_DINT)
[Structured ladder/FBD]

2
Function/ Operator List

g_time1
[ST]

TIME_TO_DINT _TIME

g_dint1

g_dint1 := TIME_TO_DINT(g_time1);

3
Function Construction

2) Function with EN/ENO(TIME_TO_DINT_E)


[Structured ladder/FBD]

g_bool1 g_time1
[ST]

TIME_TO_DINT_E EN ENO _TIME

g_bool3 g_dint1

4
How to Read Explanation of Functions

g_bool3 := TIME_TO_DINT_E(g_bool1, g_time1, g_dint1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

129

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.46

TIME_TO_STR(_E) / Time data string data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts time data into string data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST TIME_TO_STR(_TIME); Example: Label 2 Label 2:= TIME_TO_STR(Label 1); TIME_TO_STR_E(EN,_TIME, Output label); Example: TIME_TO_STR_E(X000, Label 1, Label 2);

TIME_TO_STR

Label 1

TIME_TO_STR _TIME *1

X000
TIME_TO_STR_E

Label 1

TIME_TO_STR_E EN ENO _TIME *1

Label 2

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _TIME ( s ) ENO *1 ( d ) Execution condition Conversion source time data Execution status String data after conversion Description Bit Time Bit String Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts time data stored in a device specified in obtained by conversion to a device specified in d .
20m34s567ms Time data "1234567" String data
s

into string data, and outputs the data

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

Error
An operation error occurs in the following case. The error flag M8067 turns ON, and D8067 stores the error code. 1) When the number of points occupied by the device specified in corresponding device.
d

exceeds the range of the

130

FXCPU Structured Programming Manual [Application Functions] Program example


In this program, time data stored in a device specified in s obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(TIME_TO_STR)
[Structured ladder/FBD]

5 Applied Functions (Type Conversion Functions)

1
Outline

is converted into string data, and the data

2
Function/ Operator List

g_time1
[ST]

TIME_TO_STR _TIME

g_string1

g_string1 := TIME_TO_STR(g_time1);

3
Function Construction

2) Function with EN/ENO(TIME_TO_STR_E)


[Structured ladder/FBD]

g_bool1 g_time1
[ST]

TIME_TO_STR_E EN ENO _TIME

g_bool3 g_string1

4
How to Read Explanation of Functions

g_bool3 := TIME_TO_STR_E(g_bool1, g_time1, g_string1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

131

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.47

TIME_TO_WORD(_E) / Time data word [unsigned]/bit string [16-bit] data conversion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts time data into word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST TIME_TO_WORD(_TIME); Example: D10:= TIME_TO_WORD(Label); TIME_TO_WORD_E(EN,_TIME, Output label); Example: TIME_TO_WORD_E(X000, Label, D10);

TIME_TO_WORD

Label

TIME_TO_WORD _TIME *1

D10

TIME_TO_WORD _E

X000 Label

TIME_TO_WORD_E EN ENO _TIME *1

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _TIME ( s ) ENO *1 ( d ) Execution condition Conversion source time data Execution status Word [unsigned]/bit string [16-bit] data after conversion Description Bit Time Bit Word [unsigned]/ Bit String [16-bit] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts time data stored in a device specified in s into word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion to a device specified in d .
1s234ms Time data 1234 Word [unsigned]/ bit string [16-bit] data

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

132

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, time data stored in a device specified in s is converted into word [unsigned]/bit string [16bit] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(TIME_TO_WORD)
[Structured ladder/FBD]

2
Function/ Operator List

g_time1
[ST]

TIME_TO_WORD _TIME

g_word1

g_word1 := TIME_TO_WORD(g_time1);

3
Function Construction

2) Function with EN/ENO(TIME_TO_WORD_E)


[Structured ladder/FBD]

g_bool1 g_time1
[ST]

TIME_TO_WORD_E EN ENO _TIME

g_bool3 g_word1

4
How to Read Explanation of Functions

g_bool3 := TIME_TO_WORD_E(g_bool1, g_time1, g_word1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

133

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.48

TIME_TO_DWORD(_E) / Time data double word [unsigned]/ bit string [32-bit] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts time data into double word [unsigned]/bit string [32-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST TIME_TO_DWORD(_TIME); Example: Label 2 Label 2:= TIME_TO_DWORD(Label 1); TIME_TO_DWORD_E(EN,_TIME, Output label); Example: Label 2 TIME_TO_DWORD_E(X000, Label 1, Label 2);

TIME_TO_DWOR D

Label 1

TIME_TO_DWORD _TIME *1

TIME_TO_DWOR D_E

X000 Label 1

TIME_TO_DWORD_E EN ENO _TIME *1

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _TIME ( s ) ENO *1 ( d ) Execution condition Conversion source time data Execution status Double word [unsigned]/bit string [32-bit] data after conversion Description Bit Time Bit Double Word [unsigned]/ Bit string [32-bit] Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts time data stored in a device specified in s into double word [unsigned]/bit string [32bit] data, and outputs the data obtained by conversion to a device specified in d .
12m34s567ms Time data 1234567 Double word [unsigned]/ bit string [32-bit] data

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

134

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, time data stored in a device specified in s is converted into double word [unsigned]/bit string [32-bit] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(TIME_TO_DWORD)
[Structured ladder/FBD]

2
Function/ Operator List

g_time1
[ST]

TIME_TO_DWORD _TIME

g_dword1

g_dword1 := TIME_TO_DWORD(g_time1);

3
Function Construction

2) Function with EN/ENO(TIME_TO_DWORD_E)


[Structured ladder/FBD]

g_bool1 g_time1
[ST]

TIME_TO_DWORD_E EN ENO _TIME

g_bool3 g_dword1

4
How to Read Explanation of Functions

g_dword1 := TIME_TO_DWORD(g_time1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

135

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.49

BITARR_TO_INT(_E) / Bit array Word [signed] type, word [unsigned]/ bit String [16-bit] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts specified number of bits of a bit array into word [signed] data or word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST BITARR_TO_INT(BitArr, n); Example: D10:= BITARR_TO_INT Label 1[*2], K4); BITARR_TO_INT_E(EN, BitArr, n, Output label); Example: BITARR_TO_INT_E(X000, Label 1[*2], K4, D10);

BITARR_TO_INT
BITARR_TO_INT

Label 1[*2] K4 X000

BitArr n BITARR_TO_INT_E EN

*1

D10

BITARR_TO_INT_E

ENO *1 D10

Label 1[*2] K4

BitArr n

*1. *2.

Output variable Specify an array element.

2. Set data
Variable EN Input variable BitArr ( s )
n

Description Execution condition Start bit of conversion source bit array elements Number of specified bits Execution status ( d ) Bit Bit

Data type

Word [signed] Bit

Output variable

ENO *1

Word [signed] data or word [unsigned]/bit [16-bit] data after ANY16 conversion

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts number of bits specified in n starting from a bit array element stored in a device specified in s into word [signed] data or word [unsigned]/bit string [16-bit] data, and outputs the data obtained by conversion to a device specified in d . Only a constant 4, 8, 12 or 16 can be specified in n . "0" is set to output bits beyond the specified number of bits.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data and array data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data and array data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

136

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, 8 bits starting from the 0th element of a bit array stored in a device specified in s are converted into word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(BITARR_TO_INT)
[Structured ladder/FBD]

2
Function/ Operator List

BITARR_TO_INT
g_bool4[0]

K8
[ST]

BitArr n

g_int1

g_int1 := BITARR_TO_INT(g_bool4[0], K8);

3
Function Construction

2) Function with EN/ENO(BITARR_TO_INT_E)


[Structured ladder/FBD]

g_bool1 g_bool4[0]

BITARR_TO_INT_E
EN BitArr ENO g_bool2 g_int1

4
How to Read Explanation of Functions

K8
[ST]

g_bool2 := BITARR_TO_INT_E(g_bool1, g_bool4[0], K8, g_int1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

137

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.50

BITARR_TO_DINT(_E) / Bit array Double word [signed] type, double word [unsigned]/bit string [32-bit] data conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function converts specified number of bits of a bit array into double word [signed] data or double word [unsigned]/bit string [32-bit] data, and outputs the data obtained by conversion.

1. Format
Function name Expression in each language Structured ladder/FBD ST BITARR_TO_DINT(BitArr, n); Example: Label 2:=BITARR_TO_DINT Label 1[*2], K4); BITARR_TO_DINT_E(EN, BitArr, n, Output label); Example: BITARR_TO_DINT_E(X000, Label 1[*2], K4, Label 2);

BITARR_TO_DINT
BITARR_TO_DINT

Label 1[*2] K4 X000

BitArr n

*1

Label 2

BITARR_TO_DINT_E EN ENO *1 Label 2 BitArr n

BITARR_TO_DINT_E

Label 1[*2] K4

*1. *2.

Output variable Specify an array element.

2. Set data
Variable EN Input variable BitArr ( s )
n

Description Execution condition Start bit of conversion source bit array elements Number of specified bits Execution status ( d ) Bit Bit

Data type

Word [signed] Bit

Output variable

ENO *1

Double word [signed] data or double word [unsigned]/bit string [32ANY32 bit] data after conversion

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function converts number of bits specified in n starting from a bit array element stored in a device specified in s into double word [signed] data or double word [unsigned]/bit string [32-bit] data, and outputs the data obtained by conversion to a device specified in d . Only a constant 4, 8, 12, 16, 20, 24, 28 or 32 can be specified in n . "0" is set to output bits beyond the specified number of bits.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data and array data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data and array data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

138

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, 8 bits starting from the 0th element of a bit array stored in a device specified in s are converted into double word [signed] data, and the data obtained by conversion is output to a device specified in d . 1) Function without EN/ENO(BITARR_TO_DINT)
[Structured ladder/FBD]

2
Function/ Operator List

BITARR_TO_DINT
g_bool4[0]

K8
[ST]

BitArr n

g_dint1

3
Function Construction

g_dint1 := BITARR_TO_DINT(g_bool4[0], K8);

2) Function with EN/ENO(BITARR_TO_DINT_E)


[Structured ladder/FBD]

4
How to Read Explanation of Functions

g_bool1 g_bool4[0]

BITARR_TO_DINT_E
EN BitArr ENO g_bool2 g_dint1

K8
[ST]

g_bool2 := BITARR_TO_DINT_E(g_bool1, g_bool4[0], K8, g_dint1);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

139

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.51

INT_TO_BITARR(_E) / Word [signed] data, word [unsigned]/ bit string [16-bit] data bit array conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function outputs low-order "n" bits of word [signed] data or word [unsigned]/bit string [16-bit] data to a bit array.

1. Format
Function name Expression in each language Structured ladder/FBD ST INT_TO_BITARR(s, n); Example: Label 2[*1]:= INT_TO_BITARR(D10, K4); INT_TO_BITARR_E (EN, s, n, BitArr); Example: INT_TO_BITARR_E(X000, D10, K4, Label 2[*1]);

INT_TO_BITARR
INT_TO_BITARR

D10 K4 X000

s n

BitArr

Label 2[*1]

INT_TO_BITARR_E EN ENO BitArr Label 2[*1] s n

INT_TO_BITARR_E

D10 K4

*1.

Specify an array element.

2. Set data
Variable EN Input variable
s n

Description Execution condition Bit Conversion source word [signed] data or word [unsigned]/bit string ANY16 [16-bit] data Number of specified bits Execution status Start bit of bit array elements after conversion

Data type

Word [signed] Bit Bit

Output variable

ENO BitArr ( d )

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function outputs low-order "n" bits of word [signed] data or word [unsigned]/bit string [16-bit] data stored in a device specified in s to a device specified in d . Only a constant 4, 8, 12 or 16 can be specified in n . Output bits beyond the specified number of bits are not changed.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data and array data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data and array data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

140

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, low-order 4 bits of word [signed] data stored in a device specified in device specified in d . 1) Function without EN/ENO(INT_TO_BITARR)
[Structured ladder/FBD]

are output to a

2
Function/ Operator List

INT_TO_BITARR
g_int1

K4
[ST]

s n

BitArr

g_bool4[0]

g_bool4[0] := INT_TO_BITARR(g_int1, K4);

3
Function Construction

2) Function with EN/ENO(INT_TO_BITARR_E)


[Structured ladder/FBD]

g_bool1 g_int1

INT_TO_BITARR_E
EN s ENO BitArr g_bool2 g_bool4[0]

4
How to Read Explanation of Functions

K4
[ST]

g_bool2 := INT_TO_BITARR_E (g_bool1, g_int1, K4, g_bool4[0]);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

141

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.52

DINT_TO_BITARR(_E) / Double word [signed] data, double word [unsigned]/bit string [32-bit] data bit array conversion
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function outputs low-order "n" bits of double word [signed] data or double word [unsigned]/bit string [32bit] data to a bit array.

1. Format
Function name Expression in each language Structured ladder/FBD ST DINT_TO_BITARR(s, n); Example: Label 2[*1]:= DINT_TO_BITARR (Label 1, K4) DINT_TO_BITARR_E(EN, s, n, BitArr); Example: DINT_TO_BITARR_E(X000, Label 1, K4, Label 2[*1]);

DINT_TO_BITARR
DINT_TO_BITARR

Label 1 K4 X000

s n

BitArr

Label 2[*1]

DINT_TO_BITARR_E EN ENO BitArr Label 2[*1] s n

DINT_TO_BITARR_E

Label 1 K4

*1.

Specify an array element.

2. Set data
Variable EN Input variable
s n

Description Execution condition Bit Conversion source double word [signed] data or double word ANY32 [unsigned]/bit string [32-bit] data Number of specified bits Execution status Start bit of bit array elements after conversion

Data type

Word [signed] Bit Bit

Output variable

ENO BitArr ( d )

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function outputs low-order "n" bits of double word [signed] data or double word [unsigned]/bit string [32bit] data stored in a device specified in s to a device specified in d . Only a constant 4, 8, 12, 16, 20, 24, 28 or 32 can be specified in n . Output bits beyond the specified number of bits are not changed.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data and array data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data and array data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

142

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, low-order 4 bits of double word [signed] data stored in a device specified in a device specified in d . 1) Function without EN/ENO(DINT_TO_BITARR)
[Structured ladder/FBD]

are output to

2
Function/ Operator List

DINT_TO_BITARR
g_dint1

K4
[ST]

s n

BitArr

g_bool4[0]

g_bool4[0] := DINT_TO_BITARR(g_dint1, K4);

3
Function Construction

2) Function with EN/ENO(INT_TO_BITARR_E)


[Structured ladder/FBD]

g_bool1 g_dint1

DINT_TO_BITARR_E
EN s ENO BitArr g_bool2 g_bool4[0]

4
How to Read Explanation of Functions

K4
[ST]

g_bool2 := DINT_TO_BITARR_E (g_bool1, g_dint1, K4, g_bool4[0]);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

143

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.53

CPY_BITARR(_E) / Bit array copy


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function copies specified number of bits of a bit array.

1. Format
Function name Expression in each language Structured ladder/FBD ST CPY_BITARR(BitArrIn, n); Example: Label 2[*1] Label 2[*1]:= CPY_BITARR (Label 1[*1], K4); CPY_BITARR_E(EN, BitArrIn, n, BitArrOut); Example: Label 2[*1] CPY_BITARR_E(X000, Label 1[*1], K4, Label 2[*1]);

CPY_BITARR
CPY_BITARR

Label 1[*1] K4 X000

BitArrIn n

BitArrOut

CPY_BITARR_E EN ENO BitArrOut BitArrIn n

CPY_BITARR_E

Label 1[*1] K4

*1.

Specify an array element.

2. Set data
Variable EN Input variable Output variable BitArrIn
n

Description Execution condition ( s ) Start bit of copy source bit array elements Number of specified bits Execution status Start bit of copy destination bit array elements Bit Bit

Data type

Word [signed] Bit Bit

ENO BitArrOut ( d )

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function outputs "n" bits of a bit array stored in a device specified in Only a constant 4, 8, 12, 16, 20, 24, 28 or 32 can be specified in n .
s

to a device specified in

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data and array data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data and array data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

144

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, 12 bits starting from the "num1"th element of a bit array stored in a device specified in are output to the "num2"th element and later of a bit array stored in a device specified in d . 1) Function without EN/ENO(CPY_BITARR)
[Structured ladder/FBD]

2
Function/ Operator List

CPY_BITARR
g_bool4[num1]

K12
[ST]

BitArrIn n

BitArrOut

g_bool5[num2]

g_bool5[num2] := CPY_BITARR(g_bool4[num1], K12);

3
Function Construction

2) Function with EN/ENO(CPY_BITARR_E)


[Structured ladder/FBD]

g_bool1 g_bool4[num1]

CPY_BITARR_E
EN BitArrIn ENO BitArrOut g_bool2 g_bool5[num2]

4
How to Read Explanation of Functions

K12
[ST]

g_bool2 := CPY_BITARR_E(g_bool1, g_bool4[num1], K12, g_bool5[num2]);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

145

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.54

GET_BIT_OF_INT(_E) / Specified bit read of word [signed] data


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function reads a value of a specified bit of word [signed] data.

1. Format
Function name Expression in each language Structured ladder/FBD ST GET_BIT_OF_INT(s, n); Example: M10:= GET_BIT_OF_INT (D10, K2); GET_BIT_OF_INT_E(EN, s, n, *1); Example: GET_BIT_OF_INT_E(X000, D10, K2, M10);

GET_BIT_OF_INT
GET_BIT_OF_INT

D10 K2 X000

s n

*1

M10

GET_BIT_OF_INT_E EN ENO *1 M10 s n

GET_BIT_OF_INT_E

D10 K2

*1.

Output variable

2. Set data
Variable EN Input variable Output variable
s n

Description Execution condition Read source word [signed] data Specified bit position Execution status ( d ) Read destination bit Bit

Data type Word [signed] Word [signed] Bit Bit

ENO *1

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function reads the value of the "n"th bit of a device specified in device specified in d .
s

, and outputs the read value to a

Cautions
1) Use the function having "_E" in its name to connect a bus.

146

FXCPU Structured Programming Manual [Application Functions] Program example


In this program, the value of the 5th bit of a device specified in device specified in d . 1) Function without EN/ENO(GET_BIT_OF_INT)
[Structured ladder/FBD]

5 Applied Functions (Type Conversion Functions)

1
Outline

is read, and the read value is output to a

2
Function/ Operator List

GET_BIT_OF_INT
g_int1

K5
[ST]

s n

g_bool3

g_bool3 := GET_BIT_OF_INT(g_int1, K5);

3
Function Construction

2) Function with EN/ENO(GET_BIT_OF_INT_E)


[Structured ladder/FBD]

g_bool1 g_int1

GET_BIT_OF_INT_E
EN s ENO g_bool2 g_bool3

4
How to Read Explanation of Functions

K5
[ST]

g_bool2 := GET_BIT_OF_INT_E (g_bool1, g_int1, K5, g_bool3);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

147

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.55

SET_BIT_OF_INT(_E) / Specified bit write of word [signed] data


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function writes a value to a specified bit of word [signed] data.

1. Format
Function name Expression in each language Structured ladder/FBD ST SET_BIT_OF_INT(s, n); Example: D10:= SET_BIT_OF_INT (M0, K4); SET_BIT_OF_INT_E(EN, s, n, *1); Example: SET_BIT_OF_INT_E(X000, M0, K4, D10);

SET_BIT_OF_INT
SET_BIT_OF_INT

M0 K4 X000

s n

*1

D10

SET_BIT_OF_INT_E EN M0 K4 s n ENO *1 D10

SET_BIT_OF_INT_E

*1.

Output variable

2. Set data
Variable EN Input variable Output variable
s n

Description Execution condition Write source bit data Specified bit position Execution status ( d ) Write destination word [signed] data Bit Bit

Data type

Word [signed] Bit Word [signed]

ENO *1

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function reads the value of a device specified in device specified in d .
s

, and writes the read value to the "n"th bit of a

Cautions
1) Use the function having "_E" in its name to connect a bus.

148

FXCPU Structured Programming Manual [Application Functions] Program example


In this program, the value of a device specified in 1) Function without EN/ENO(SET_BIT_OF_INT)
[Structured ladder/FBD]

5 Applied Functions (Type Conversion Functions)

1
Outline

is written to the 3rd bit of a device specified in

SET_BIT_OF_INT
g_bool1

2
Function/ Operator List

K3
[ST]

s n

g_int3

g_int3 := SET_BIT_OF_INT(g_bool1, K3);

3
Function Construction

2) Function with EN/ENO(SET_BIT_OF_INT_E)


[Structured ladder/FBD]

g_bool2 g_bool1

SET_BIT_OF_INT_E
EN s ENO g_bool3 g_int3

4
How to Read Explanation of Functions

K3
[ST]

g_bool3 := SET_BIT_OF_INT_E(g_bool2, g_bool1, K3, g_int3);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

149

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.56

CPY_BIT_OF_INT(_E) / Specified bit copy of word [signed] data


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function copies a specified bit of word [signed] data to a specified bit of another word [signed] data.

1. Format
Function name Expression in each language Structured ladder/FBD ST CPY_BIT_OF_INT(s, n1, n2); Example: D10:= CPY_BIT_OF_INT (D0, K1, K4);

CPY_BIT_OF_INT
CPY_BIT_OF_INT

D0 K1 K4 X000

s n1 n2

*1

D10

CPY_BIT_OF_INT_E D0 K1 K4 EN s n1 n2 ENO *1 D10

CPY_BIT_OF_INT_E

CPY_BIT_OF_INT_E(EN, s, n1, n2, *1); Example: CPY_BIT_OF_INT_E(X000, D0, K1, K4, D10);

*1.

Output variable

2. Set data
Variable EN Input variable
s n1 n2

Description Execution condition Copy source word [signed] data Specified bit position (copy source) Specified bit position (copy destination) Execution status ( d ) Copy destination word [signed] data Bit

Data type Word [signed] Word [signed] Word [signed] Bit Word [signed]

Output variable

ENO *1

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function copies the value of the "n1"th bit of a device specified in specified in d .
s

to the "n2"th bit of a device

Cautions
1) Use the function having "_E" in its name to connect a bus.

150

FXCPU Structured Programming Manual [Application Functions] Program example

5 Applied Functions (Type Conversion Functions)

1
Outline

In this program, the value of the 5th bit of a device specified in specified in d . 1) Function without EN/ENO(CPY_BIT_OF_INT)
[Structured ladder/FBD]

is written to the 3rd bit of a device

2
Function/ Operator List

CPY_BIT_OF_INT
g_int1

K5 K3
[ST]

s n1 n2

g_int3

3
Function Construction

g_int3 := CPY_BIT_OF_INT(g_int1, K5, K3);

2) Function with EN/ENO(CPY_BIT_OF_INT_E)


[Structured ladder/FBD]

4
How to Read Explanation of Functions

g_bool2 g_int1

CPY_BIT_OF_INT_E
EN s ENO g_bool3 g_int3

K5 K3
[ST]

n1 n2

5
Applied Functions (Type Conversion Functions)

g_bool3 := CPY_BIT_OF_INT_E(g_bool2, g_int1, K5, K3, g_int3);

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

151

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.57

GET_BOOL_ADDR / Acquisition of start data


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function outputs the start data as bit data.

1. Format
Function name Expression in each language Structured ladder/FBD ST GET_BOOL_ADDR(s); Example: M10:= GET_BOOL_ADDR (Label);

GET_BOOL_ADDR

GET_BOOL_ADDR Label s *1 M10

*1.

Output variable

2. Set data
Variable Input variable Output variable *1
s

Description Input data ( d ) Output data ANY Bit

Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function outputs the start data of data specified in
Input data type Bit, Bit string Bit Output data type

as bit data to a device specified in

Cautions
When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

Program example
In this program, MOV instruction is executed using the start bit of bit array data stored in a device specified in s .
[Structured ladder/FBD]

GET_BOOL_ADDR g_array s g_int1


[ST]

MOV EN s ENO d g_int2

MOV(GET_BOOL_ADDR(g_array), g_int1, g_int2);

152

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.58

GET_INT_ADDR / Acquisition of start data


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function outputs the start data as word [signed] data.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST GET_INT_ADDR(s); Example: D10:= GET_INT_ADDR (Label);

3
Function Construction

GET_INT_ADDR

GET_INT_ADDR Label s *1 D10

*1.

Output variable

2. Set data
Variable Input variable Output variable *1
s

4
How to Read Explanation of Functions
Description Input data ANY Word [signed] Data type

( d )

Output data

In explanation of functions, I/O variables inside ( ) are described.

5
Applied Functions (Type Conversion Functions)

Explanation of function and operation


This function outputs the start data of data specified in d .
Input data type

as word [signed] data to a device specified in


Output data type

6
Applied Functions (Standard Functions Of One Numeric Variable)

Word [signed], Double Word [signed], Word [unsigned]/Bit String [16-bit], FLOAT (Single Precision), String, Time, Array of Word [signed], Array of double word [signed], Array of word [unsigned]/bit string [16-bit], Word [signed] Array of double word [unsigned]/bit string [32-bit], Array of real number, Array of time type

Cautions
1) When handling 32-bit data and array data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data and array data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

Program example
In this program, low-order 16-bit data of double word [signed] data specified in data to buffer memories.
[Structured ladder/FBD]

is written as word [signed]

9
Applied Functions (Standard Bitwise Boolean Functions)

GET_INT_ADDR g_dint1 s

g_bool1 k0 k27 k1

EN s n1 n2 n3

TO ENO

10
Applied Functions (Standard Selection Functions)

[ST]

TO(g_bool1, GET_INT_ADDR(g_dint1), K0, K27, K1);

153

FXCPU Structured Programming Manual [Application Functions]

5 Applied Functions (Type Conversion Functions)

5.59

GET_WORD_ADDR / Acquisition of start data


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function outputs the start data as word [unsigned]/bit string [16-bit] data.

1. Format
Function name Expression in each language Structured ladder/FBD ST GET_WORD_ADDR(s); Example: D10:= GET_WORD_ADDR (Label);

GET_WORD_ADDR

GET_WORD_ADDR Label s *1 D10

*1.

Output variable

2. Set data
Variable Input variable Output variable *1
s

Description Input data ( d ) Output data ANY

Data type

Word [unsigned]/ Bit String [16-bit]

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function outputs the start data of data specified in device specified in
d s

as word [unsigned]/bit string [16-bit] data to a


Output data type

.
Input data type

Word [signed], Double Word [signed], Word [unsigned]/Bit String [16-bit], FLOAT (Single Precision), String, Time, Array of Word [signed], Word [unsigned]/ Array of double word [signed], Array of word [unsigned]/bit string [16-bit], Bit String [16-bit] Array of double word [unsigned]/bit string [32-bit], Array of real number, Array of time type

Cautions
1) When handling 32-bit data and array data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data and array data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

Program example
In this program, low-order 16-bit data of double word [signed] data specified in [unsigned]/bit string [16-bit] data to buffer memories.
[Structured ladder/FBD]

is written as word

GET_WORD_ADDR g_dint1 s

g_bool1 k0 k27 k1

EN s n1 n2 n3

TO ENO

[ST]

TO(g_bool1, GET_WORD_ADDR(g_dint1), K0, K27, K1);

154

6 Applied Functions (Standard Functions Of One Numeric Variable)

Applied Functions (Standard Functions Of One Numeric Variable)

10

Outline

Function/ Operator List

Function Construction

How to Read Explanation of Functions

Applied Functions (Type Conversion Functions)

Applied Functions (Standard Functions Of One Numeric Variable)

Applied Functions (Standard Arithmetic Functions)

Applied Functions (Standard Bit Shift Functions)

Applied Functions (Standard Bitwise Boolean Functions)

Applied Functions (Standard Selection Functions)

FXCPU Structured Programming Manual [Application Functions]

Function

Function name

6.

ABS(_E)

Absolute value

Section 6.1

Reference

155

FXCPU Structured Programming Manual [Application Functions]

6 Applied Functions (Standard Functions Of One Numeric Variable)


6.1 ABS(_E) / Absolute value

6.1

ABS(_E) / Absolute value


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function obtains the absolute value, and outputs it.

1. Format
Function name Expression in each language Structured ladder/FBD ST ABS(_IN); Example: D10:= ABS(D0); ABS_E(EN,_IN,Output label); Example: ABS_E(X000,D0,D10);

ABS

ABS D0 X000 _IN *1 D10

ABS_E

D0

ABS_E EN ENO _IN *1

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _IN ( s ) ENO *1 ( d ) Execution condition Description Bit Data type

Data whose absolute value is to be obtained, or word device which ANY_NUM stores such data Execution status Word device which will store the operation result Bit ANY_NUM

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function obtains the absolute value of word [signed]/double word [signed]/float (single precision) data stored in a device specified in s , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in a device specified in s . This function is expressed as follows when the input value is "A" and the output operation result is "B".

B= A
2) When the data type stored in a device specified in s is word [signed] and the stored data is "-32768", this function outputs "-32768" to a device specified in d . (The maximum absolute value handled by this function is "32,767".) When the data type stored in a device specified in s is double word [signed] and the stored data is "2147483648", this function outputs "-2147483648" to a device specified in d . (The maximum absolute value handled by this function is "2147483647".)

156

FXCPU Structured Programming Manual [Application Functions] Cautions

6 Applied Functions (Standard Functions Of One Numeric Variable)


6.1 ABS(_E) / Absolute value

1
Outline

1) Use the function having "_E" in its name to connect a bus. 2) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

2
Function/ Operator List

Program example
In this program, the absolute value is obtained for word [signed] data stored in a device specified in s , and the operation result is output to a device specified in d using the data type same as the data stored in a device specified in s . 1) Function without EN/ENO(ABS)
[Structured ladder/FBD]

3
Function Construction

ABS g_int1=-5923
[ST]

_IN

g_int2=5923

4
How to Read Explanation of Functions

g_int2 := ABS(g_int1);

2) Function with EN/ENO(ABS_E)


[Structured ladder/FBD]

5
Applied Functions (Type Conversion Functions)

g_bool1 g_int1
[ST]

ABS_E EN _IN ENO g_bool3 g_int2

g_bool3 := ABS_E(g_bool1, g_int1, g_int2);

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

157

FXCPU Structured Programming Manual [Application Functions]

7 Applied Functions (Standard Arithmetic Functions)

7.

Applied Functions (Standard Arithmetic Functions)


Function name ADD_E SUB_E MUL_E DIV_E MOD(_E) EXPT(_E) MOVE(_E) Addition Subtraction Multiplication Division Modulus operation Exponentiation Move operation Function Reference Section 7.1 Section 7.2 Section 7.3 Section 7.4 Section 7.5 Section 7.6 Section 7.7

158

FXCPU Structured Programming Manual [Application Functions]

7 Applied Functions (Standard Arithmetic Functions)


7.1 ADD_E / Addition

7.1

ADD_E / Addition
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function performs addition using two values (A + B = C), and outputs the operation result.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST ADD_E(EN,_IN,_IN,Output label); Example: ADD_E(X000,D0,D10,D20);

3
Function Construction

X000
ADD_E

D0 D10

ADD_E EN ENO _IN *1 _IN

D20

*1.

Output variable

4
How to Read Explanation of Functions
Description Execution condition Data for addition or word device which stores such data Execution status Bit ANY_NUM Bit ANY_NUM Data type

2. Set data
Variable Input variable Output variable EN _IN ( s1 to s28 ) ENO *1 ( d )

5
Applied Functions (Type Conversion Functions)

Word device which will store the operation result

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function performs addition ( s1 + s2 + s28 ) using word [signed]/double word [signed]/float (single precision) data stored in devices specified in s1 to s28 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [signed]
1234
s1 (Word

6
Applied Functions (Standard Functions Of One Numeric Variable)

5678
s2 (Word d

6912 (Word [signed] data)

7
Applied Functions (Standard Arithmetic Functions)

[signed] data)

[signed] data)
s

2) The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

159

FXCPU Structured Programming Manual [Application Functions] Cautions

7 Applied Functions (Standard Arithmetic Functions)


7.1 ADD_E / Addition

1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) Even if underflow or overflow occurs in the operation result, it is not regarded as an operation error. "TRUE" is output from ENO. However, note that the obtained operation result is not accurate in this case. Either of the flags shown in the table below turns ON or OFF in accordance with the operation result.
Device M8020 Name Zero Description ON : When the operation result is "0" OFF: When the operation result is any other than "0" ON : When the operation result is less than "-32,768" (16-bit operation) or less than "2,147,483,648" (32-bit operation) OFF: When the operation result is "-32,768" (16-bit operation) or more or "-2,147,483,648" (32bit operation) or more ON : When the operation result exceeds "32,767" (16-bit operation) or "2,147,483,647" (32-bit operation) OFF: When the operation result is "32,767" (16-bit operation) or less or "2,147,483,647" (32-bit operation) or less

M8021

Borrow

M8022

Carry

Zero flag -2 , -1 , 0 , -32,768 The most significant bit of data is "1".

Zero flag -1 , 0 , 1 The most significant bit of data is "0".

Zero flag 32,767 , 0, 1, 2

Borrow flag Zero flag -2 , -1 , 0 ,

Carry flag Zero flag

-2,147,483,648

-1 , 0 , 1 Zero flag

2,147,483,647 ,

0, 1, 2

Borrow flag

Carry flag

3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

Program example
In this program, addition is performed using double word [signed] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_bool1 g_dint1 g_dint2


[ST]

ADD_E EN _IN _IN ENO g_bool3 g_dint3

g_bool3:=ADD_E(g_bool1,g_dint1,g_dint2,g_dint3);

160

FXCPU Structured Programming Manual [Application Functions]

7 Applied Functions (Standard Arithmetic Functions)


7.2 SUB_E / Subtraction

7.2

SUB_E / Subtraction
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function performs subtraction using two values (A - B = C), and outputs the operation result.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST SUB_E(EN,_IN1,_IN2,Output label); Example: SUB_E(X000,D0,D10,D20);

3
Function Construction

X000
SUB_E

D0 D10

SUB_E EN ENO _IN1 *1 _IN2

D20

*1.

Output variable

4
How to Read Explanation of Functions
Description Execution condition Data to be subtracted or word device which stores such data Data for subtraction or word device which stores such data Execution status Bit ANY_NUM ANY_NUM Bit ANY_NUM Data type

2. Set data
Variable EN Input variable Output variable _IN1 ( s1 ) _IN2 ( s2 ) ENO *1 ( d )

5
Applied Functions (Type Conversion Functions)

Word device which will store the operation result

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function performs subtraction ( s1 - s2 ) using word [signed]/double word [signed]/float (single precision) data stored in devices specified in s1 and s2 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 and s2 . Example: When the data type is word [signed]
12345
s1 (Word [signed] data)

6
Applied Functions (Standard Functions Of One Numeric Variable)

6789
s2 (Word [signed] data)

5556
d (Word [signed] data)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

161

FXCPU Structured Programming Manual [Application Functions] Cautions

7 Applied Functions (Standard Arithmetic Functions)


7.2 SUB_E / Subtraction

1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) Even if underflow or overflow occurs in the operation result, it is not regarded as an operation error. "TRUE" is output from ENO. However, note that the obtained operation result is not accurate in this case. Either of the flags shown in the table below turns ON or OFF in accordance with the operation result.
Device M8020 Name Zero Description ON : When the operation result is "0" OFF: When the operation result is any other than "0" ON : When the operation result is less than "-32,768" (16-bit operation) or less than "2,147,483,648" (32-bit operation) OFF: When the operation result is "-32,768" (16-bit operation) or more or "-2,147,483,648" (32bit operation) or more ON : When the operation result exceeds "32,767" (16-bit operation) or "2,147,483,647" (32-bit operation) OFF: When the operation result is "32,767" (16-bit operation) or less or "2,147,483,647" (32-bit operation) or less

M8021

Borrow

M8022

Carry

Zero flag -2 , -1 , 0 , -32,768 The most significant bit of data is "1".

Zero flag -1 , 0 , 1 The most significant bit of data is "0".

Zero flag 32,767 , 0, 1, 2

Borrow flag Zero flag -2 , -1 , 0 ,

Carry flag Zero flag

-2,147,483,648

-1 , 0 , 1 Zero flag

2,147,483,647 ,

0, 1, 2

Borrow flag

Carry flag

3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

Program example
In this program, subtraction is performed using word [signed] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_bool1 g_int1 g_int2


[ST]

SUB_E EN _IN1 _IN2 ENO g_bool3 g_int3

g_bool3:=SUB_E(g_bool1,g_int1,g_int2,g_int3);

162

FXCPU Structured Programming Manual [Application Functions]

7 Applied Functions (Standard Arithmetic Functions)


7.3 MUL_E / Multiplication

7.3

MUL_E / Multiplication
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function performs multiplication using two or more values (A B = C), and outputs the operation result.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST MUL_E(EN,_IN,_IN,Output label); Example: MUL_E(X000,D0,D10,D20);

3
Function Construction

X000
MUL_E

D0 D10

MUL_E EN ENO _IN *1 _IN

D20

*1.

Output variable

4
How to Read Explanation of Functions
Description Execution condition Data for multiplication or word device which stores such data Execution status Bit ANY_NUM Bit ANY_NUM Data type

2. Set data
Variable Input variable Output variable EN _IN ( s1 to s28 ) ENO *1 ( d )

5
Applied Functions (Type Conversion Functions)

Word device which will store the operation result

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function performs multiplication ( s1 s2 s28 ) using word [signed]/double word [signed]/float (single precision) data stored in devices specified in s1 to s28 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [signed]
100 (Word [signed] data)
s1 s2

6
Applied Functions (Standard Functions Of One Numeric Variable)

15 (Word [signed] data)


s d

1500 (Word [signed] data)

7
Applied Functions (Standard Arithmetic Functions)

2) The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) Even if underflow or overflow occurs in the operation result, it is not regarded as an operation error. "TRUE" is output from ENO. However, note that the obtained operation result is not accurate in this case. 3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

163

FXCPU Structured Programming Manual [Application Functions] Program example

7 Applied Functions (Standard Arithmetic Functions)


7.3 MUL_E / Multiplication

In this program, multiplication is performed using double word [signed] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_bool1 g_dint1 g_dint2


[ST]

MUL_E EN _IN _IN ENO g_bool3 g_dint3

g_bool3:=MUL_E(g_bool1,g_dint1,g_dint2,g_dint3);

164

FXCPU Structured Programming Manual [Application Functions]

7 Applied Functions (Standard Arithmetic Functions)


7.4 DIV_E / Division

7.4

DIV_E / Division
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function performs division using two values (A / B = C remainder), and outputs the quotient.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST DIV_E(EN,_IN1,_IN2,Output label); Example: DIV_E(X000,D0,D10,D20);

3
Function Construction

X000
DIV_E

D0 D10

DIV_E EN ENO _IN1 *1 _IN2

D20

*1.

Output variable

4
How to Read Explanation of Functions
Description Execution condition Data to be divided, or word device which stores such data Data for division (divisor), or word device which stores such data Execution status Bit ANY_NUM ANY_NUM Bit ANY_NUM Data type

2. Set data
Variable EN Input variable Output variable _IN1 ( s1 ) _IN2 ( s2 ) ENO *1 ( d )

5
Applied Functions (Type Conversion Functions)

Word device which will store the operation result

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function performs division ( s1 / s2 ) using word [signed]/double word [signed]/float (single precision) data stored in devices specified in s1 and s2 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 and s2 . Example: When the data type is word [signed]
5
s1 (Word [signed] data)

6
Applied Functions (Standard Functions Of One Numeric Variable)

2
s2 (Word [signed] data)

(Quotient) 2
d (Word [signed] data)

7
Applied Functions (Standard Arithmetic Functions)

Cautions
1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

Error
1) An operation error occurs when the divisor stored in a device specified in s2 is "0", and the function is not executed. 2) An operation error occurs when the operation result exceeds "32,767" (16-bit operation) or "2,147,483,647" (32-bit operation).

10
Applied Functions (Standard Selection Functions)

165

FXCPU Structured Programming Manual [Application Functions] Program example

7 Applied Functions (Standard Arithmetic Functions)


7.4 DIV_E / Division

In this program, division is performed using double word [signed] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 .
[Structured ladder/FBD]

g_bool1 g_dint1 g_dint2


[ST]

DIV_E EN _IN1 _IN2 ENO g_bool3 g_dint3

g_bool3:=DIV_E(g_bool1,g_dint1,g_dint2,g_dint3);

166

FXCPU Structured Programming Manual [Application Functions]

7 Applied Functions (Standard Arithmetic Functions)


7.5 MOD(_E) / Modulus operation

7.5

MOD(_E) / Modulus operation


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function performs division using two values (A / B = C remainder), and outputs the remainder.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST _IN1 MOD _IN2; *2 Example: Label 3:= Label 1 MOD Label 2; MOD_E(EN,_IN1,_IN2,Output label; *2 Example: MOD_E(X000,Label 1, Label 2,Label 3);

3
Function Construction

MOD

Label 1 Label 2 X000

MOD _IN1 *1 _IN2 MOD_E EN ENO _IN1 *1 _IN2

Label 3

MOD_E

4
How to Read Explanation of Functions

Label 1 Label 2

Label 3

*1. *2.

Output variable Refer to "Cautions".

2. Set data
Variable EN Input variable Output variable _IN1 ( s1 ) _IN2 ( s2 ) ENO *1 ( d ) Execution condition Data to be divided, or word device which stores such data Data for division (divisor), or word device which stores such data Execution status Word device which will store the operation result Description Bit ANY_INT ANY_INT Bit ANY_INT Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function performs division ( s1 / s2 ) using word [signed]/double word [signed] data stored in devices specified in s1 and s2 , and outputs the remainder to a device specified in d using the data type of data stored in devices specified in s1 and s2 . Example: When the data type is word [signed]
5
s1 (Word [signed] data)

7
Applied Functions (Standard Arithmetic Functions)

2
s2 (Word [signed] data)

(Quotient) 2 Not output

(Remainder) 1
d (Word [signed] data)

8
Applied Functions (Standard Bit Shift Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) Note that the "MOD" description method is different from other function description methods in the ST language.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

167

FXCPU Structured Programming Manual [Application Functions] Error

7 Applied Functions (Standard Arithmetic Functions)


7.5 MOD(_E) / Modulus operation

1) An operation error occurs when the divisor stored in a device specified in s2 is "0", and the function is not executed. 2) An operation error occurs when the operation result exceeds "32,767" (16-bit operation) or "2,147,483,647" (32-bit operation).

Program example
In this program, division is performed using double word [signed] data stored in devices specified in s1 and s2 , and the remainder is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 . 1) Function without EN/ENO(MOD)
[Structured ladder/FBD]

MOD g_dint1=5678 g_dint2=1234


[ST]

_IN1 _IN2

g_dint3=742

g_dint3:=g_dint1 MOD g_dint2;

2) Function with EN/ENO(MOD_E)


[Structured ladder/FBD]

g_bool1 g_dint1 g_dint2


[ST]

MOD_E EN _IN1 _IN2 ENO g_bool3 g_dint3

g_bool3 := MOD_E(g_bool1, g_dint1, g_dint2, g_dint3);

168

FXCPU Structured Programming Manual [Application Functions]

7 Applied Functions (Standard Arithmetic Functions)


7.6 EXPT(_E) / Exponentiation

7.6

EXPT(_E) / Exponentiation
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function obtains raised result, and outputs it.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST EXPT(In1,In2); Example: Label 2:= EXPT(Label 1,D10); EXPT_E(EN,In1,In2,Output label); Example: EXPT_E(X000,Label 1,D10, Label 2);

3
Function Construction

EXPT
EXPT

Label 1 D10 X000

In1 In2

*1

Label 2

EXPT_E

Label 1 D10

EXPT_E EN ENO In1 *1 In2

4
How to Read Explanation of Functions

Label 2

*1.

Output variable

2. Set data
Variable EN Input variable Output variable In1 In2 ENO *1 ( d ) ( s1 ) ( s2 ) Execution condition Data to be raised, or word device which stores such data Power data, or word device which stores such data Execution status Word device which will store the operation result Description Bit FLOAT (Single Precision) ANY_NUM Bit FLOAT (Single Precision) Data type

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function raises float (single precision) data stored in a device specified in s1 (to the power of the value stored in a device specified in s2 ), and outputs the operation result to a device specified in d .
2 4.0
s1 Float (single precision) data

7
Applied Functions (Standard Arithmetic Functions)

Word [signed] data


s2

16.0
d Float (single precision) data

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

169

FXCPU Structured Programming Manual [Application Functions] Error

7 Applied Functions (Standard Arithmetic Functions)


7.6 EXPT(_E) / Exponentiation

An operation error occurs in the following cases. The error flag M8067 turns ON, and D8067 stores the error code. 1) When the value stored in a device specified in s1 is negative (Error code: K6706) 2) When the value stored in a device specified in s1 is "0" (Error code: K6706) 3) When the operation result is outside the following range: (Error code: K6706) 2-126Operation result<2128

Program example
In this program, the value stored in a device specified in s1 is raised to the power of the value stored in a device specified in s2 , and the operation result is output to a device specified in d using the data type of data stored in a device specified in s1 . 1) Function without EN/ENO(EXPT)
[Structured ladder/FBD]

EXPT g_real1 g_int1


[ST]

In1 In2

g_real2

g_real2:=EXPT(g_real1,g_int1);

2) Function with EN/ENO(EXPT_E)


[Structured ladder/FBD]

g_bool1 g_real1 g_int1


[ST]

EN In1 In2

EXPT_E ENO

g_bool3 g_real2

g_bool3:=EXPT_E(g_bool1,g_real1,g_int1,g_real2);

170

FXCPU Structured Programming Manual [Application Functions]

7 Applied Functions (Standard Arithmetic Functions)


7.7 MOVE(_E) / Move operation

7.7

MOVE(_E) / Move operation


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function transfers data stored in a device to another device.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST MOVE(_IN); Example: D10:= MOVE(D0); MOVE_E(EN,_IN,Output label); Example: MOVE_E(X000,D0,D10);

3
Function Construction

MOVE

D0

MOVE _IN *1

D10

X000
MOVE_E

D0

MOVE_E EN ENO _IN *1

4
How to Read Explanation of Functions

D10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _IN ( s ) ENO *1 ( d ) Execution condition Transfer source data, or word device which stores such data Execution status Transfer destination word device Description Bit ANY Bit ANY Data type

5
Applied Functions (Type Conversion Functions)

In explanation of functions, I/O variables inside ( ) are described.

6
Applied Functions (Standard Functions Of One Numeric Variable)

Explanation of function and operation


This function transfers data stored in a device specified in
12
s s

to a device specified in

12
d

Word [signed] data

Word [signed] data

7
Applied Functions (Standard Arithmetic Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

171

FXCPU Structured Programming Manual [Application Functions] Program example

7 Applied Functions (Standard Arithmetic Functions)


7.7 MOVE(_E) / Move operation

In this program, word [signed] data stored in a device specified in d . 1) Function without EN/ENO(MOVE)
[Structured ladder/FBD]

is transferred to a device specified in

MOVE g_int1
[ST]

_IN

g_int2

g_int2:=MOVE(g_int1);

2) Function with EN/ENO(MOVE_E)


[Structured ladder/FBD]

g_bool1 g_int1
[ST]

EN _IN

MOVE_E ENO

g_bool3 g_int2

g_bool3:=MOVE_E(g_bool1,g_int1,g_int2);

172

8 Applied Functions (Standard Bit Shift Functions)

10

Outline

Function/ Operator List

Function Construction

How to Read Explanation of Functions

Applied Functions (Type Conversion Functions)

Applied Functions (Standard Functions Of One Numeric Variable)

Applied Functions (Standard Arithmetic Functions)

Applied Functions (Standard Bit Shift Functions)

Applied Functions (Standard Bitwise Boolean Functions)

Applied Functions (Standard Selection Functions)

Section 8.1

Applied Functions (Standard Bit Shift Functions)

FXCPU Structured Programming Manual [Application Functions]

Function

Function name

Left shift

8.

SHR(_E)

SHL(_E)

Right shift

Section 8.2

Reference

173

FXCPU Structured Programming Manual [Application Functions]

8 Applied Functions (Standard Bit Shift Functions)


8.1 SHL(_E) / Left shift

8.1

SHL(_E) / Left shift


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function shifts data of specified bit length leftward by the specified number of bits.

1. Format
Function name Expression in each language Structured ladder/FBD ST SHL(_IN,_N); Example: D10:= SHL(D0,K1); SHL_E(EN,_IN,_N,Output label); Example: SHL_E(X000,D0,K1,D10);

SHL
SHL

D0 K1 X000

_IN _N

*1

D10

SHL_E

D0 K1

SHL_E EN ENO _IN *1 _N

D10

*1.

Output variable

2. Set data
Variable EN Input variable Output variable _IN ( s ) _N ( n ) ENO *1 ( d ) Execution condition Word device which stores data to be shifted leftward Number of shifted bits Execution status Word device which will store data obtained by shift Description Bit ANY_BIT ANY_BIT Bit ANY_BIT Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function shifts word [unsigned]/bit string [16-bit]/double word [unsigned]/bit string [32-bit] data stored in a device specified in s leftward by "n" bits, and outputs the obtained data to a device specified in d using the data type of data stored in a device specified in s . Data is shifted leftward by "n" bits specified in n . Example: When word [unsigned]/bit string [16-bit] data is stored in a device specified in s , and "8" is specified in n
270FH
s (Word [unsigned]/ bit string [16-bit] data)

F00H
d (Word [unsigned]/ bit string [16-bit] data)

270FH

F00H

These bits become "0".

2) "n" bits from the least significant bit become "0".

174

FXCPU Structured Programming Manual [Application Functions] Cautions


1) Use the function having "_E" in its name to connect a bus.

8 Applied Functions (Standard Bit Shift Functions)


8.1 SHL(_E) / Left shift

1
Outline

2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

2
Function/ Operator List

Program example
In this program, word [unsigned]/bit string [16-bit] data stored in a device specified in s is shifted leftward by "n" bits, and the obtained data is output to a device specified in d using the data type of data stored in a device specified in s . 1) Function without EN/ENO(SHL)
[Structured ladder/FBD]

3
Function Construction

SHL g_word1=16#F30F g_const_word1=16#0008


[ST]

_IN _N

g_word2=16#0F00

4
How to Read Explanation of Functions

g_word2:=SHL(g_word1,g_const_word1);

2) Function with EN/ENO(SHL_E)


[Structured ladder/FBD]

5
Applied Functions (Type Conversion Functions)

g_bool1 g_word1 g_const_word1


[ST]

SHL_E EN _IN _N ENO g_bool3 g_word2

6
Applied Functions (Standard Functions Of One Numeric Variable)

g_bool3:=SHL_E(g_bool1,g_word1,g_const_word1,g_word2);

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

175

FXCPU Structured Programming Manual [Application Functions]

8 Applied Functions (Standard Bit Shift Functions)


8.2 SHR(_E) / Right shift

8.2

SHR(_E) / Right shift


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function shifts data of specified bit length rightward by the specified number of bits.

1. Format
Function name Expression in each language Structured ladder/FBD ST SHR(_IN,_K); Example: D10:= SHR(D0,K1); SHR_E(EN,_IN,_N,Output label); Example: SHR_E(X000,D0,K1,D10);

SHR
SHR

D0 K1 X000

_IN _K

*1

D10

SHR_E

D0 K1

SHR_E EN ENO _IN *1 _N

D10

*1.

Output variable

2. Set data
Variable EN Input variable Output variable _IN ( s ) Execution condition Word device which stores data to be shifted rightward Number of shifted bits Execution status ( d ) Word device which will store data obtained by shift Description Bit ANY_BIT ANY_BIT Bit ANY_BIT Data type

_K,_N ( n ) ENO *1

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function shifts word [unsigned]/bit string [16-bit]/double word [unsigned]/bit string [32-bit] data stored in a device specified in s rightward by "n" bits, and outputs the obtained data to a device specified in d using the data type of data stored in a device specified in s . Data is shifted rightward by "n" bits specified in n . Example: When word [unsigned]/bit string [16-bit] data is stored in a device specified in s , and "8" is specified in n
270FH
s (Word [unsigned]/ bit string [16-bit] data)

27H
d (Word [unsigned]/ bit string [16-bit] data)

270FH

27H

These bits become "0".

2) "n" bits from the most significant bit become "0".

176

FXCPU Structured Programming Manual [Application Functions] Cautions


1) Use the function having "_E" in its name to connect a bus.

8 Applied Functions (Standard Bit Shift Functions)


8.2 SHR(_E) / Right shift

1
Outline

2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

2
Function/ Operator List

Program example
In this program, word [unsigned]/bit string [16-bit] data stored in a device specified in s is shifted rightward by "n" bits, and the obtained data is output to a device specified in d using the data type of data stored in a device specified in s . 1) Function without EN/ENO(SHR)
[Structured ladder/FBD]

3
Function Construction

SHR g_word1=16#EEEE g_const_word1=16#0006


[ST]

_IN _K

g_word2=16#03BB

4
How to Read Explanation of Functions

g_word2:=SHR(g_word1,g_const_word1);

2) Function with EN/ENO(SHR_E)


[Structured ladder/FBD]

5
Applied Functions (Type Conversion Functions)

g_bool1 g_word1 g_const_word1


[ST]

SHR_E EN _IN _N ENO g_bool3 g_word2

6
Applied Functions (Standard Functions Of One Numeric Variable)

g_bool3:=SHR_E(g_bool1,g_word1,g_const_word1,g_word2);

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

177

FXCPU Structured Programming Manual [Application Functions]

9 Applied Functions (Standard Bitwise Boolean Functions)

9.

Applied Functions (Standard Bitwise Boolean Functions)


Function name AND_E OR_E XOR_E NOT(_E) Logical product Logical sum Exclusive logical sum Logical negation Function Reference Section 9.1 Section 9.2 Section 9.3 Section 9.4

178

FXCPU Structured Programming Manual [Application Functions]

9 Applied Functions (Standard Bitwise Boolean Functions)


9.1 AND_E / Logical product

9.1

AND_E / Logical product


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function obtains the logical product of two or more bits, and outputs it.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST AND_E(EN,_IN,_IN,Output label); Example: AND_E(X000,M0,M10,M20);

3
Function Construction

X000
AND_E

M0 M10

AND_E EN ENO *1 _IN _IN

M20

*1.

Output variable

4
How to Read Explanation of Functions
Description Execution condition Bit ANY_BIT Bit ANY_BIT Data type

2. Variable
Variable Input variable Output variable EN

_IN ( s1 to s28 ) Device used to obtain the logical product ENO *1 ( d ) Execution status Device which will store the operation result

5
Applied Functions (Type Conversion Functions)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function obtains the logical product using each bit of bit/word [unsigned]/bit string [16-bit]/double word [unsigned]/bit string [32-bit] data stored in devices specified in s1 to s28 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [unsigned]/bit string [16-bit]
s1

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

Logical product
s2

0
s

8
Applied Functions (Standard Bit Shift Functions)

2)

The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

179

FXCPU Structured Programming Manual [Application Functions] Program example

9 Applied Functions (Standard Bitwise Boolean Functions)


9.1 AND_E / Logical product

In this program, the logical product is obtained using each bit of word [unsigned]/bit string [16-bit] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 .
[Structured ladder/FBD]

g_bool1 g_word1 g_word2


[ST]

AND_E EN _IN _IN ENO g_bool3 g_word3

g_bool3:=AND_E(g_bool1,g_word1,g_word2,g_word3);

180

FXCPU Structured Programming Manual [Application Functions]

9 Applied Functions (Standard Bitwise Boolean Functions)


9.2 OR_E / Logical sum

9.2

OR_E / Logical sum


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function obtains the logical sum of two or more bits, and outputs it.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST OR_E(EN,_IN,_IN,Output label); Example: OR_E(X000,M0,M10,M20);

3
Function Construction

X000
OR_E

M0 M10

OR_E EN ENO _IN *1 _IN

M20

*1.

Output variable

4
How to Read Explanation of Functions
Description Execution condition Bit ANY_BIT Bit ANY_BIT Data type

2. Set data
Variable Input variable Output variable EN

_IN ( s1 to s28 ) Device used to obtain the logical sum ENO *1 ( d ) Execution status Device which will store the operation result

5
Applied Functions (Type Conversion Functions)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function obtains the logical sum using each bit of bit/word [unsigned]/bit string [16-bit]/double word [unsigned]/bit string [32-bit] data stored in devices specified in s1 to s28 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [unsigned]/bit string [16-bit]]
s1

6
Applied Functions (Standard Functions Of One Numeric Variable)

Logical sum
s2

7
Applied Functions (Standard Arithmetic Functions)

1
s

2) The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

8
Applied Functions (Standard Bit Shift Functions)

Cautions
1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

181

FXCPU Structured Programming Manual [Application Functions] Program example

9 Applied Functions (Standard Bitwise Boolean Functions)


9.2 OR_E / Logical sum

In this program, the logical sum is obtained using each bit of word [unsigned]/bit string [16-bit] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 .
[Structured ladder/FBD]

g_bool1 g_word1 g_word2


[ST]

OR_E EN _IN _IN ENO g_bool3 g_word3

g_bool3:=OR_E(g_bool1,g_word1,g_word2,g_word3);

182

FXCPU Structured Programming Manual [Application Functions]

9 Applied Functions (Standard Bitwise Boolean Functions)


9.3 XOR_E / exclusive logical sum

9.3

XOR_E / exclusive logical sum


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function obtains the exclusive logical sum of two or more bits, and outputs it.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST XOR_E(EN,_IN,_IN,Output label); Example: XOR_E(X000,M0,M10,M20);

3
Function Construction

X000
XOR_E

M0 M10

XOR_E EN ENO _IN *1 _IN

M20

*1.

Output variable

4
How to Read Explanation of Functions
Description Execution condition Bit ANY_BIT Bit ANY_BIT Data type

2. .Set data
Variable Input variable Output variable EN _IN ( s1 ENO *1 ( d )

to s28 ) Device used to obtain the exclusive logical sum Execution status Device which will store the operation result

5
Applied Functions (Type Conversion Functions)

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function obtains the exclusive logical sum using each bit of bit/word [unsigned]/bit string [16-bit]/ double word [unsigned]/bit string [32-bit] data stored in devices specified in s1 to s28 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [unsigned]/bit string [16-bit]
s1

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

Exclusive logical sum


s2

0
s

8
Applied Functions (Standard Bit Shift Functions)

2)

The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

183

FXCPU Structured Programming Manual [Application Functions]

9 Applied Functions (Standard Bitwise Boolean Functions)


9.3 XOR_E / exclusive logical sum

3) If there are 3 or more s , the exclusive logical sum is obtained using the "exclusive logical sum of s1 and s2 " and s3 . If there is s4 , the exclusive logical sum is obtained using the "exclusive logical sum of "exclusive logical sum of s1 and s2 " and " s3 "" and s4 . In this way, the exclusive logical sum is obtained the s6 required number of times for all input labels s5 Example: When the data type is bit
When the number of "_IN" is 3
s1

When the number of "_IN" is 4 FALSE XOR


s4

When the number of "_IN" is 5 TRUE XOR


s5

FALSE XOR

TRUE XOR
s3

s2

TRUE

TRUE

TRUE

TRUE

Result TRUE

Result FALSE

Result TRUE

After that, the exclusive logical sum is obtained the required number of Result FALSE times.

Cautions
1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

Program example
In this program, the exclusive logical sum is obtained using each bit of word [unsigned]/bit string [16-bit] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 .
[Structured ladder/FBD]

g_bool1 g_word1 g_word2


[ST]

XOR_E EN _IN _IN ENO g_bool3 g_word3

g_bool3:=XOR_E(g_bool1,g_word1,g_word2,g_word3);

184

FXCPU Structured Programming Manual [Application Functions]

9 Applied Functions (Standard Bitwise Boolean Functions)


9.4 NOT(_E) / logical negation

9.4

NOT(_E) / logical negation


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

1
Outline

Outline
This function obtains the logical negation of bits, and outputs it.

2
Function/ Operator List

1. Format
Function name Expression in each language Structured ladder/FBD ST NOT(_IN); Example: M10:= NOT(M0); NOT_E(EN,_IN,Output label); Example: NOT_E(X000,M0,M10);

3
Function Construction

NOT

NOT M0 _IN *1 M10

X000
NOT_E

M0

NOT_E EN ENO _IN *1

4
How to Read Explanation of Functions

M10

*1.

Output variable

2. Set data
Variable Input variable Output variable EN _IN ( s ) ENO *1 ( d ) Execution condition Device used to obtain the logical negation Execution status Device which will store the operation result Description Bit ANY_BIT Bit ANY_BIT Data type

5
Applied Functions (Type Conversion Functions)

In explanation of functions, I/O variables inside ( ) are described.

6
Applied Functions (Standard Functions Of One Numeric Variable)

Explanation of function and operation


This function obtains the logical negation using each bit of bit/word [unsigned]/bit string [16-bit]/double word [unsigned]/bit string [32-bit] data stored in a device specified in s , and outputs the operation result to a device specified in d using the data type of data stored in a device specified in s . Example: When the data type is word [unsigned]/bit string [16-bit]
s

7
Applied Functions (Standard Arithmetic Functions)

Logical negation
d

8
Applied Functions (Standard Bit Shift Functions)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels.

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

185

FXCPU Structured Programming Manual [Application Functions] Program example

9 Applied Functions (Standard Bitwise Boolean Functions)


9.4 NOT(_E) / logical negation

In this program, the logical negation is obtained using each bit of word [unsigned]/bit string [16-bit] data stored in a device specified in s , and the operation result is output to a device specified in d using the data type of data stored in a device specified in s . 1) Function without EN/ENO(NOT)
[Structured ladder/FBD]

NOT g_word1
[ST]

_IN

g_word2

g_word2:= NOT(g_word1);

2) Function with EN/ENO(NOT_E)


[Structured ladder/FBD]

g_bool1 g_word1
[ST]

NOT_E EN _IN ENO g_bool3 g_word2

g_bool3:=NOT_E(g_bool1,g_word1,g_word2);

186

FXCPU Structured Programming Manual [Application Functions]

10 Applied Functions (Standard Selection Functions)

1
Outline

10. Applied Functions (Standard Selection Functions)


Function name SEL(_E) MAXIMUM(_E) MINIMUM(_E) LIMITATION(_E) MUX(_E) Selection Maximum selection Minimum selection Upper/Lower limit control Multiplexer Function Reference Section 10.1 Section 10.2 Section 10.3 Section 10.4 Section 10.5

2
Function/ Operator List

3
Function Construction

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

187

FXCPU Structured Programming Manual [Application Functions]

10 Applied Functions (Standard Selection Functions)


10.1 SEL(_E) / Selection

10.1

SEL(_E) / Selection
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function selects either one between two data in accordance with the input condition, and outputs the selection result.

1. Format
Function name Expression in each language Structured ladder/FBD ST SEL(_G,_IN0,_IN1); Example: D20:= SEL(M0,D0,D10);

SEL

M0 D0 D10 X000

SEL _G *1 _IN0 _IN1 SEL_E EN ENO _G *1 _IN0 _IN1

D20

SEL_E

M0 D0 D10

D20

SEL_E(EN,_G,_IN0,_IN1,Output label); Example: SEL_E(X000,M0,D0,D10,D20);

*1.

Output variable

2. Set data
Variable EN Input variable _G ( s1 ) Execution condition Bit data used as the selection condition Selectable data, or word device which stores such data Selectable data, or word device which stores such data Execution status ( d ) Word device which will store the selection result Description Bit Bit ANY ANY Bit ANY Data type

_IN0 ( s2 ) _IN1 ( s3 )

Output variable

ENO *1

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function outputs either one between the values stored in devices specified in s2 and s3 in accordance with the value stored in a device specified in s1 to a device specified in d using the data type of data stored in a device specified in s2 and s3 . When the value stored in a device specified in s1 is "FALSE", this function outputs the value stored in a device specified in s2 to a device specified in d . When the value stored in a device specified in s1 is "TRUE", this function outputs the value stored in a device specified in s3 to a device specified in d . Example: When the data type of input variables s2 and s3 is word [signed]
FALSE Bit data 1234 Word [signed] data 5678 Word [signed] data SEL G _IN0 _IN1 1234 Word [signed] data

188

FXCPU Structured Programming Manual [Application Functions] Cautions

10 Applied Functions (Standard Selection Functions)


10.1 SEL(_E) / Selection

1
Outline

1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

2
Function/ Operator List

Program example
In this program, either one between the values stored in devices specified in s2 and s3 is output in accordance with the value stored in a device specified in s1 to a device specified in d using the data type of data stored in devices specified in s2 and s3 . 1) Function without EN/ENO(SEL)
[Structured ladder/FBD]

3
Function Construction

4
How to Read Explanation of Functions

SEL g_bool1 g_word1 g_word2


[ST]

_G _IN0 _IN1

g_word3

5
Applied Functions (Type Conversion Functions)

g_word3:=SEL(g_bool1,g_word1,g_word2);

2) Function with EN/ENO(SEL_E)


[Structured ladder/FBD]

6
Applied Functions (Standard Functions Of One Numeric Variable)

g_bool1 g_bool2 g_word1 g_word2


[ST]

SEL_E EN _G _IN0 _IN1 ENO g_bool3 g_word3

7
Applied Functions (Standard Arithmetic Functions)

g_bool3:=SEL_E(g_bool1,g_bool2,g_word1,g_word2,g_word3);

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

189

FXCPU Structured Programming Manual [Application Functions]

10 Applied Functions (Standard Selection Functions)


10.2 MAXIMUM(_E) / Maximum selection

10.2

MAXIMUM(_E) / Maximum selection


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function searches the maximum value among data, and outputs the maximum value.

1. Format
Function name Expression in each language Structured ladder/FBD ST MAXIMUM(_IN,_IN); Example: D20:= MAXIMUM(D0,D10);

MAXIMUM

D0 D10

MAXIMUM _IN *1 _IN

D20

X000
MAXIMUM_E

D0 D10

MAXIMUM_E EN ENO _IN *1 _IN

D20

MAXIMUM_E(EN,_IN,_IN,Output label); Example: MAXIMUM_E(X000,D0,D10,D20);

*1.

Output variable

2. Set data
Variable Input variable Output variable EN Execution condition Description Bit ANY_SIMPLE Bit ANY_SIMPLE Data type

_IN ( s1 to s28 ) Compared data, or word device which stores such data ENO *1 ( d ) Execution status Word device which will store the maximum value

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function outputs the maximum value among ANY_SIMPLE type data stored in devices specified in s1 to s28 to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [signed]
1234 Word [signed] data 5678 Word [signed] data MAXIMUM _IN _IN 5678 Word [signed] data

2) The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

190

FXCPU Structured Programming Manual [Application Functions] Program example

10 Applied Functions (Standard Selection Functions)


10.2 MAXIMUM(_E) / Maximum selection

1
Outline

In this program, the maximum value among word [signed] data stored in devices specified in s1 and s2 is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 . 1) Function without EN/ENO(MAXIMUM)
[Structured ladder/FBD]

2
Function/ Operator List

MAXIMUM g_int1=5678 g_int2=1234


[ST]

_IN _IN

g_int3=5678

g_int3:=MAXIMUM(g_int1,g_int2);

3
Function Construction

2) Function with EN/ENO(MAXIMUM_E)


[Structured ladder/FBD]

g_bool1 g_int1 g_int2


[ST]

MAXIMUM_E EN ENO _IN _IN

g_bool3 g_int3

4
How to Read Explanation of Functions

g_bool3:=MAXIMUM_E(g_bool1,g_int1,g_int2,g_int3);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

191

FXCPU Structured Programming Manual [Application Functions]

10 Applied Functions (Standard Selection Functions)


10.3 MINIMUM(_E) / Minimum selection

10.3

MINIMUM(_E) / Minimum selection


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function searches the minimum value among data, and outputs the minimum value.

1. Format
Function name Expression in each language Structured ladder/FBD ST MINIMUM(_IN,_IN); Example: D20:= MINIMUM(D0,D10);

MINIMUM

D0 D10

MINIMUM _IN *1 _IN

D20

X000
MINIMUM_E

D0 D10

MINIMUM_E EN ENO _IN *1 _IN

D20

MINIMUM_E(EN,_IN,_IN,Output label); Example: MINIMUM_E(X000,D0,D10,D20);

*1.

Output variable

2. Set data
Variable Input variable Output variable EN Execution condition Description Bit ANY_SIMPLE Bit ANY_SIMPLE Data type

_IN ( s1 to s28 ) Compared data, or word device which stores such data ENO *1 ( d ) Execution status Word device which will store the minimum value

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function outputs the minimum value among ANY_SIMPLE type data stored in devices specified in s1 to s28 to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [signed]
1234 Word [signed] data 5678 Word [signed] data MINIMUM _IN _IN 1234 Word [signed] data

2) The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

192

FXCPU Structured Programming Manual [Application Functions] Program example

10 Applied Functions (Standard Selection Functions)


10.3 MINIMUM(_E) / Minimum selection

1
Outline

In this program, the minimum value among word [signed] data stored in devices specified in s1 and s2 is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 . 1) Function without EN/ENO(MINIMUM)
[Structured ladder/FBD]

2
Function/ Operator List

MINIMUM g_int1=5678 g_int2=1234


[ST]

_IN _IN

g_int3=1234

g_int3:=MINIMUM(g_int1,g_int2);

3
Function Construction

2) Function with EN/ENO(MINIMUM_E)


[Structured ladder/FBD]

g_bool1 g_int1 g_int2


[ST]

MINIMUM_E EN ENO _IN _IN

g_bool3 g_int3

4
How to Read Explanation of Functions

g_bool3:=MINIMUM_E(g_bool1,g_int1,g_int2,g_int3);

5
Applied Functions (Type Conversion Functions)

6
Applied Functions (Standard Functions Of One Numeric Variable)

7
Applied Functions (Standard Arithmetic Functions)

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

193

FXCPU Structured Programming Manual [Application Functions]

10 Applied Functions (Standard Selection Functions)


10.4 LIMITATION(_E) / Upper/Lower limit control

10.4

LIMITATION(_E) / Upper/Lower limit control


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function judges whether data is located within the range between the upper limit value and the lower limit value.

1. Format
Function name Expression in each language Structured ladder/FBD ST LIMITATION(_MN,_IN,_MX); Example: D30:= LIMITATION(D0,D10,D20); LIMITATION_E(EN,_MN,_IN,_MX, Output label); Example: LIMITATION_E(X000,D0,D10,D20, D30);

LIMITATION

D0 D10 D20 X000

LIMITATION _MN *1 _IN _MX LIMITATION_E EN ENO *1 _MN _IN _MX

D30

LIMITATION_E

D0 D10 D20

D30

*1.

Output variable

2. Set data
Variable EN Input variable _MN ( s1 ) _IN ( s2 ) _MX ( s3 ) Output variable ENO *1 ( d ) Execution condition Lower limit data, or word device which stores such data Input data, or word device which stores such data Upper limit data, or word device which stores such data Execution status Word device which will store the output data Description Bit ANY_SIMPLE ANY_SIMPLE ANY_SIMPLE Bit ANY_SIMPLE Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function outputs data whose type is same as the data stored in devices specified in s1 , s2 and s3 to a device specified in d in accordance with ANY_SIMPLE type data stored in devices specified in s1 , s2 and s3 . 1) In the case of "Contents of a device specified in s2 > Contents of a device specified in function outputs the contents of a device specified in s3 to a device specified in d . 2) In the case of "Contents of a device specified in s2 < Contents of a device specified in function outputs the contents of a device specified in s1 to a device specified in d .
s3

", this ", this

s1

3) In the case of "Contents of a device specified in s1 Contents of a device specified in s2 Contents of a device specified in s3 ", this function outputs the contents of a device specified in s2 to a device specified in d . Example: When the data type is word [signed]
Output value -100 Word [signed] data 120 Word [signed] data 100 Word [signed] data LIMITATION _MN _IN _MX Minimum input value 100 Word [signed] data

Input value Maximum input value

194

FXCPU Structured Programming Manual [Application Functions] Cautions

10 Applied Functions (Standard Selection Functions)


10.4 LIMITATION(_E) / Upper/Lower limit control

1
Outline

1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

2
Function/ Operator List

Error
An operation error occurs when this function is executed in the following setting status. The error flag M8067 turns ON, and D8067 stores the error code K6706. Contents of a device specified in s1 > Contents of a device specified in s3 (Lower limit data) (Upper limit data)

3
Function Construction

Program example
In this program, data whose type is same as the data stored in devices specified in s1 , s2 and s3 is output to a device specified in d in accordance with ANY_SIMPLE type data stored in devices specified in s1 , s2 and s3 . 1) Function without EN/ENO(LIMITATION)
[Structured ladder/FBD]

4
How to Read Explanation of Functions

5
Applied Functions (Type Conversion Functions)

g_int1=500 g_int2=1300 g_int3=5000


[ST]

LIMITATION _MN _IN _MX

g_int4=1300

6
Applied Functions (Standard Functions Of One Numeric Variable)

g_int4:=LIMITATION(g_int1,g_int2,g_int3);

2) Function with EN/ENO(LIMITATION_E)


[Structured ladder/FBD]

7
Applied Functions (Standard Arithmetic Functions)

g_bool1 g_int1 g_int2 g_int3


[ST]

LIMITATION_E EN ENO _MN _IN _MX

g_bool3 g_int4

8
Applied Functions (Standard Bit Shift Functions)

g_bool3:=LIMITATION_E(g_bool1,g_int1,g_int2,g_int3,g_int4);

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

195

FXCPU Structured Programming Manual [Application Functions]

10 Applied Functions (Standard Selection Functions)


10.5 MUX(_E) / Multiplexer

10.5

MUX(_E) / Multiplexer
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function selects data, and outputs the selected data.

1. Format
Function name Expression in each language Structured ladder/FBD ST MUX(_K,_IN,_IN); Example: D30:= MUX(D0,D10,D20);

MUX
MUX

D0 D10 D20 X000

_K _IN _IN

*1

D30

MUX_E

D0 D10 D20

MUX_E EN ENO *1 _K _IN _IN

D30

MUX_E(EN,_K,_IN,_IN,Output label); Example: MUX_E(X000,D0,D10,D20,D30);

*1.

Output variable

2. Set data
Variable EN Input variable Output variable _K ( n ) Execution condition Selection data, or word device which stores such data Description Bit Word [signed] ANY Bit ANY Data type

_IN ( s1 to s28 ) Selectable data, or word device which stores such data ENO *1 Execution status Word device which will store the selected data

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function outputs either one among values stored in devices specified in s1 to s28 to a device specified in d in accordance with the value specified in n using the data type of data stored in devices specified in s1 to s28 a) When the value specified in n is "1", this function outputs the value stored in a device specified in s1 to a device specified in d . b) When the value specified in n is "n", this function outputs the value stored in a device specified in sn to a device specified in d . Example: When the data type is word [signed]
1 Word [signed] data 1234 Word [signed] data 5678 Word [signed] data MUX _K _IN _IN 1234 Word [signed] data

2) When a value input to n is outside the pin number range for s1 to s28 , this function outputs an indefinite value to a device specified in d . (An operation error does not occur. "MUX_E" outputs "FALSE" from ENO.) 3) The number of pins for
s

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

196

FXCPU Structured Programming Manual [Application Functions] Cautions

10 Applied Functions (Standard Selection Functions)


10.5 MUX(_E) / Multiplexer

1
Outline

1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

2
Function/ Operator List

Program example
In this example, either one among values stored in devices specified in s1 and s2 is output to a device specified in d in accordance with the value specified in n using the data type of data stored in devices specified in s1 and s2 . 1) Function without EN/ENO(MUL)
[Structured ladder/FBD]

3
Function Construction

4
How to Read Explanation of Functions

MUX g_int1=2 g_int2=1234 g_int3=5678


[ST]

_K _IN _IN

g_int4=5678

5
Applied Functions (Type Conversion Functions)

g_int4:=MUX(g_int1,g_int2,g_int3);

2) Function with EN/ENO(MUL_E)


[Structured ladder/FBD]

6
Applied Functions (Standard Functions Of One Numeric Variable)

g_bool1 g_int1 g_int2 g_int3


[ST]

MUX_E EN _K _IN _IN ENO g_bool3 g_int4

7
Applied Functions (Standard Arithmetic Functions)

g_bool3:=MUX_E(g_bool1,g_int1,g_int2,g_int3,g_int4);

8
Applied Functions (Standard Bit Shift Functions)

9
Applied Functions (Standard Bitwise Boolean Functions)

10
Applied Functions (Standard Selection Functions)

197

FXCPU Structured Programming Manual [Application Functions]

11 Applied Functions (Standard Comparison Functions)

11. Applied Functions (Standard Comparison Functions)


Function name GT_E GE_E EQ_E LE_E LT_E NE_E Comparison Comparison Comparison Comparison Comparison Comparison Function Reference Section 11.1 Section 11.2 Section 11.3 Section 11.4 Section 11.5 Section 11.6

198

FXCPU Structured Programming Manual [Application Functions]

11 Applied Functions (Standard Comparison Functions)


11.1 GT_E / Comparison

11.1

GT_E / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function compares data with regard to "> (larger)".

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST GT_E(EN,_IN,_IN,Output label); Example: GT_E(X000,D0,D10,M0);

13
Applied Functions (Functions Of Time Data Types)

X000
GT_E

D0 D10

EN _IN _IN

GT_E ENO *1

M0

*1.

Output variable

14
Standard Function Blocks
Description Execution condition Bit ANY_SIMPLE Bit Bit Data type

2. Set data
Variable Input variable Output variable EN

_IN ( s1 to s28 ) Compared data, or word device which stores such data ENO *1 ( d ) Execution status Device which will store the comparison result

15
Operator

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function compares the contents of devices specified in s1 to s28 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 > s2 ] & [ s2 > s3 ] & & [ s n-1 > sn ]. a) This function outputs "TRUE" when all comparison results are " s n-1 > sn ". b) This function outputs "FALSE" when any comparison result is " s n-1 sn ". 2) The number of pins for
s

A
Correspondence between Devices and Addresses

B
Function/ Operator List

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

199

FXCPU Structured Programming Manual [Application Functions] Program example

11 Applied Functions (Standard Comparison Functions)


11.1 GT_E / Comparison

In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_bool1 g_int1 g_int2 EN _IN _IN

GT_E ENO g_bool3 g_bool2

[ST]

g_bool3:=GT_E(g_bool1,g_int1,g_int2,g_bool2);

200

FXCPU Structured Programming Manual [Application Functions]

11 Applied Functions (Standard Comparison Functions)


11.2 GE_E / Comparison

11.2

GE_E / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function compares data with regard to " (larger or equal)".

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST GE_E(EN,_IN,_IN,Output label); Example: GE_E(X000,D0,D10,M0);

13
Applied Functions (Functions Of Time Data Types)

X000
GE_E

D0 D10

EN _IN _IN

GE_E ENO *1

M0

*1.

Output variable

14
Standard Function Blocks
Description Execution condition Execution status Bit ANY_SIMPLE Bit Bit Data type

2. Set data
Variable Input variable Output variable EN ENO *1 ( d )

_IN ( s1 to s28 ) Compared data, or word device which stores such data Device which will store the comparison result

15
Operator

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function compares the contents of devices specified in s1 to s28 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 s2 ] & [ s2 s3 ] & & [ s n-1 sn ]. a) This function outputs "TRUE" when all comparison results are " s n-1 sn ". b) This function outputs "FALSE" when any comparison result is " s n-1 < sn ". 2) The number of pins for
s

A
Correspondence between Devices and Addresses

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

B
Function/ Operator List

Cautions
1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

201

FXCPU Structured Programming Manual [Application Functions] Program example

11 Applied Functions (Standard Comparison Functions)


11.2 GE_E / Comparison

In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_bool1 g_int1 g_int2 EN _IN _IN

GE_E ENO g_bool3 g_bool2

[ST]

g_bool3:=GE_E(g_bool1,g_int1,g_int2,g_bool2);

202

FXCPU Structured Programming Manual [Application Functions]

11 Applied Functions (Standard Comparison Functions)


11.3 EQ_E / Comparison

11.3

EQ_E / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function compares data with regard to "= (equal)".

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST EQ_E(EN,_IN,_IN,Output label); Example: EQ_E(X000,D0,D10,M0);

13
Applied Functions (Functions Of Time Data Types)

X000
EQ_E

D0 D10

EN _IN _IN

EQ_E ENO *1

M0

*1.

Output variable

14
Standard Function Blocks
Description Execution condition Execution status Bit ANY_SIMPLE Bit Bit Data type

2. Set data
Variable Input variable Output variable EN ENO *1 ( d )

_IN ( s1 to s28 ) Compared data, or word device which stores such data Device which will store the comparison result

15
Operator

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function compares the contents of devices specified in s1 to s28 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 = s2 ] & [ s2 = s3 ] & & [ s n-1 = sn ]. a) This function outputs "TRUE" when all comparison results are " s n-1 = sn ". b) This function outputs "FALSE" when any comparison result is " s n-1 sn ". 2) The number of pins for
s

A
Correspondence between Devices and Addresses

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

B
Function/ Operator List

Cautions
1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

203

FXCPU Structured Programming Manual [Application Functions] Program example

11 Applied Functions (Standard Comparison Functions)


11.3 EQ_E / Comparison

In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_bool1 g_int1 g_int2 EN _IN _IN

EQ_E ENO g_bool3 g_bool2

[ST]

g_bool3:=EQ_E(g_bool1,g_int1,g_int2,g_bool2);

204

FXCPU Structured Programming Manual [Application Functions]

11 Applied Functions (Standard Comparison Functions)


11.4 LE_E / Comparison

11.4

LE_E / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function compares data with regard to " (smaller or equal)".

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST LE_E(EN,_IN,_IN,Output label); Example: LE_E(X000,D0,D10,M0);

13
Applied Functions (Functions Of Time Data Types)

X000
LE_E

D0 D10

EN _IN _IN

LE_E ENO *1

M0

*1.

Output variable

14
Standard Function Blocks
Description Execution condition Execution status Bit ANY_SIMPLE Bit Bit Data type

2. Set data
Variable Input variable Output variable EN ENO *1 ( d )

_IN ( s1 to s28 ) Compared data, or word device which stores such data Device which will store the comparison result

15
Operator

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function compares the contents of devices specified in s1 to s28 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 s2 ] & [ s2 s3 ] & & [ s n-1 sn ]. a) This function outputs "TRUE" when all comparison results are " s n-1 sn ". b) This function outputs "FALSE" when any comparison result is " s n-1 > sn ". 2) The number of pins for
s

A
Correspondence between Devices and Addresses

B
Function/ Operator List

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

205

FXCPU Structured Programming Manual [Application Functions] Program example

11 Applied Functions (Standard Comparison Functions)


11.4 LE_E / Comparison

In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_bool1 g_int1 g_int2 EN _IN _IN

LE_E ENO g_bool3 g_bool2

[ST]

g_bool3:=LE_E(g_bool1,g_int1,g_int2,g_bool2);

206

FXCPU Structured Programming Manual [Application Functions]

11 Applied Functions (Standard Comparison Functions)


11.5 LT_E / Comparison

11.5

LT_E / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function compares data with regard to "< (smaller)".

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST LT_E(EN,_IN,_IN,Output label); Example: LT_E(X000,D0,D10,M0);

13
Applied Functions (Functions Of Time Data Types)

X000
LT_E

D0 D10

EN _IN _IN

LT_E ENO *1

M0

*1.

Output variable

14
Standard Function Blocks
Description Execution condition Execution status Bit ANY_SIMPLE Bit Bit Data type

2. Set data
Variable Input variable Output variable EN ENO *1 ( d )

_IN ( s1 to s28 ) Compared data, or word device which stores such data Device which will store the comparison result

15
Operator

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function compares the contents of devices specified in s1 to s28 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 < s2 ] & [ s2 < s3 ] & & [ s n-1 < sn ]. a) This function outputs "TRUE" when all comparison results are " s n-1 < sn ". b) This function outputs "FALSE" when any comparison result is " s n-1 sn ". 2) The number of pins for
s

A
Correspondence between Devices and Addresses

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

B
Function/ Operator List

Cautions
1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

207

FXCPU Structured Programming Manual [Application Functions] Program example

11 Applied Functions (Standard Comparison Functions)


11.5 LT_E / Comparison

In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_bool1 g_int1 g_int2 EN _IN _IN

LT_E ENO g_bool3 g_bool2

[ST]

g_bool3:=LT_E(g_bool1,g_int1,g_int2,g_bool2);

208

FXCPU Structured Programming Manual [Application Functions]

11 Applied Functions (Standard Comparison Functions)


11.6 NE_E / Comparison

11.6

NE_E / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function compares data with regard to " (unequal)".

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST NE_E(EN,_IN1,_IN2,Output label); Example: NE_E(X000,D0,D10,M0);

13
Applied Functions (Functions Of Time Data Types)

X000
NE_E

D0 D10

NE_E EN ENO _IN1 *1 _IN2

M0

*1.

Output variable

14
Standard Function Blocks
Description Execution condition Compared data, or word device which stores such data Compared data, or word device which stores such data Execution status Bit ANY_SIMPLE ANY_SIMPLE Bit Bit Data type

2. Set data
Variable EN Input variable Output variable _IN1 ( s1 ) _IN2 ( s2 ) ENO *1 ( d )

15
Operator

Device which will store the comparison result

In explanation of functions, I/O variables inside ( ) are described.

A
Correspondence between Devices and Addresses

Explanation of function and operation


This function compares the contents of devices specified in s1 and s2 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 s2 ]. a) This function outputs "TRUE" when in the case of " s1 s2 " b) This function outputs "FALSE" when in the case of " s1 = s2 "

B
Function/ Operator List

Cautions
1) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 2) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

209

FXCPU Structured Programming Manual [Application Functions] Program example

11 Applied Functions (Standard Comparison Functions)


11.6 NE_E / Comparison

In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_bool1 g_int1 g_int2 EN _IN1 _IN2

NE_E ENO g_bool3 g_bool2

[ST]

g_bool3:=NE_E(g_bool1,g_int1,g_int2,g_bool2);

210

FXCPU Structured Programming Manual [Application Functions]

12 Applied Functions (Standard Character String Functions)

11
Applied Functions (Standard Comparison Functions)

12. Applied Functions (Standard Character String Functions)


Function name MID(_E) CONCAT(_E) INSERT(_E) DELETE(_E) REPLACE(_E) FIND(_E) Extract mid string String concatenation String insertion String deletion String replacement Searches a character string Function Reference Section 12.1 Section 12.2 Section 12.3 Section 12.4 Section 12.5 Section 12.6

12
Applied Functions (Standard Character String Functions)

13
Applied Functions (Functions Of Time Data Types)

14
Standard Function Blocks

15
Operator

A
Correspondence between Devices and Addresses

B
Function/ Operator List

211

FXCPU Structured Programming Manual [Application Functions]

12 Applied Functions (Standard Character String Functions)


12.1 MID(_E) / Extract mid string

12.1

MID(_E) / Extract mid string


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function obtains a character string from a specified position.

1. Format
Function name Expression in each language Structured ladder/FBD ST MID(_IN,_L ,_P); Example: Label 2:= MID(Label 1,D10,D20);

MID
MID

Label 1 D10 D20 X000

_IN _L _P

*1

Label 2

MID_E

Label 1 D10 D20

MID_E EN ENO *1 _IN _L _P

Label 2

MID_E(EN,_IN,_L ,_P,Output label); Example: MID_E(X000,Label 1,D10,D20, Label 2);

*1.

Output variable

2. Set data
Variable EN Input variable _IN ( s ) _L _P Output variable ENO *1 ( d ) ( n1 ) ( n2 ) Execution condition Head word device which stores a character string Word device which stores the number of characters to be obtained Description Bit String Word [signed] Data type

Word device which stores the head character position of a character Word [signed] string to be obtained Execution status Head word device which will store the obtained character string Bit String

In explanation of functions, I/O variables inside ( ) are described.

212

FXCPU Structured Programming Manual [Application Functions] Explanation of function and operation

12 Applied Functions (Standard Character String Functions)


12.1 MID(_E) / Extract mid string

11
Applied Functions (Standard Comparison Functions)

1) This function extracts specified number of characters from an arbitrary position of a character string stored in devices specified in s , and outputs the obtained data to devices specified in d . The value specified in n1 specifies the number of characters to be extracted. The value specified in n2 specifies the head character position of characters to be extracted. Example: When "5" is specified in n1 and n2
"ABCDEF12345" High-order byte Low-order byte 1st word 2nd word 3rd word 4th word 5th word 6th word 42H(B) 44H(D) 46H(F) 32H(2) 34H(4) 00H 41H(A) 43H(C) 45H(E) 31H(1) 33H(3) 35H(5) Number of characters to be extracted n1 = 5 Head character position of a character string to be extracted n2 = 5th character "EF123" High-order byte Low-order byte 46H(F) 32H(2) 00H 45H(E) 31H(1) 33H(3) 1st word 2nd word 3rd word

12
Applied Functions (Standard Character String Functions)

13
Applied Functions (Functions Of Time Data Types)

14
Standard Function Blocks

2) A character string (data) stored in devices specified in s indicates the data until "00H" is detected first in units of byte in the range starting from the specified device. 3) When the number of characters to be extracted specified in n1 is "0", this function does not execute processing. 4) When the number of characters to be extracted specified in n1 is "-1", this function outputs the final character of a character string specified in s to devices specified in d .

15
Operator

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling character string data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling character string data. Use global labels when specifying labels.

A
Correspondence between Devices and Addresses

Error
An operation error occurs in the following cases. The error flag M8067 turns ON, and D8067 stores the error code. 1) When "00H" is not set in the corresponding device range after the device specified in (Error code: K6706)
s

B
Function/ Operator List

2) When the head character position specified in n2 exceeds the number of characters of a character string stored in devices specified in s (Error code: K6706) 3) When the number of characters specified in n1 exceeds the range of devices specified in (Error code: K6706)
d

4) When the number of devices after the device number specified in d is smaller than the number of devices required for storing an extracted character string (In this case, "00H" cannot be stored after all character strings and the final character.) (Error code: K6706) 5) When the value specified in n2 is negative (Error code: K6706) 6) When the value specified in n1 is "-2" or less (Error code: K6706) 7) When the value specified in n1 devices specified in s (Error code: K6706) exceeds the number of characters of a character string stored in

213

FXCPU Structured Programming Manual [Application Functions] Program example

12 Applied Functions (Standard Character String Functions)


12.1 MID(_E) / Extract mid string

In this program, specified number of characters are extracted from an arbitrary position of a character string stored in devices specified in s , and the obtained data is output to devices specified in d . 1) Function without EN/ENO(MID)
[Structured ladder/FBD]

MID g_string1="ABCDEF12345" g_int1=5 g_int2=5


[ST]

_IN _L _P

g_string2="EF123"

g_string2:=MID(g_string1,g_int1,g_int2);

2) Function with EN/ENO(MID_E)


[Structured ladder/FBD]

g_bool1 g_string1 g_int1 g_int2


[ST]

MID_E EN _IN _L _P ENO g_bool3 g_string2

g_bool3:=MID_E(g_bool1,g_string1,g_int1,g_int2,g_string2);

214

FXCPU Structured Programming Manual [Application Functions]

12 Applied Functions (Standard Character String Functions)


12.2 CONCAT(_E) / String concatenation

12.2

CONCAT(_E) / String concatenation


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function connects character strings.

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST CONCAT(_IN,_IN); Example: Label 3:= CONCAT(Label 1,Label 2);

13
Applied Functions (Functions Of Time Data Types)

CONCAT
CONCAT

Label 1 Label 2

_IN _IN

*1

Label 3

X000
CONCAT_E

Label 1 Label 2

CONCAT_E EN ENO _IN *1 _IN

Label 3

CONCAT_E(EN,_IN,_IN,Output label); Example: CONCAT_E(X000,Label 1,Label 2, Label 3);

14
Standard Function Blocks

*1.

Output variable

15
Operator
Description Execution condition Bit Head word device which stores the data (character string) to be String connected, or directly specified character string Execution status Bit Head word device which will store the connected data (character String string) Data type

2. Set data
Variable Input variable Output variable EN _IN ( s1 to s28 ) ENO *1 ( d )

A
Correspondence between Devices and Addresses

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function connects a character string stored in devices specified in s n+1 after a character string stored in devices specified in sn , and outputs the character string obtained by connection to devices specified in d . When connecting a character string stored in devices specified in s n+1 , this function ignores "00H" which indicates the end of a character string stored in devices specified in sn . After two character strings are connected, "00H" is automatically added at the end.
"ABCDE" High-order byte Low-order byte 1st word 2nd word 3rd word 42H(B) 44H(D) 00H 41H(A) 43H(C) 45H(E) 1st word 2nd word 3rd word 4th word "123456" High-order byte Low-order byte 32H(2) 34H(4) 36H(6) 31H(1) 33H(3) 35H(5) 1st word 2nd word 3rd word 4th word 5th word 6th word "ABCDE123456" High-order byte Low-order byte 42H(B) 44H(D) 31H(1) 33H(3) 35H(5) 00H 41H(A) 43H(C) 45H(E) 32H(2) 34H(4) 36H(6)

B
Function/ Operator List

0000H

2) A character string (data) stored in devices specified in s indicates the data until "00H" is detected first in units of byte in the range starting from the specified device. 3) For direct specification, up to 32 characters can be specified (input). When word devices are specified in s , this restriction (up to 32 characters) is not applicable.

215

FXCPU Structured Programming Manual [Application Functions]

12 Applied Functions (Standard Character String Functions)


12.2 CONCAT(_E) / String concatenation

4) When both a character string stored in devices specified in this function stores "0000H" in devices specified in d . 5) The number of pins for
s

begin with "00H" (when character = 0),

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling character string data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling character string data. Use global labels when specifying labels.

Error
An operation error occurs in the following cases. The error flag M8067 turns ON, and D8067 stores the error code. 1) When the number of devices after the device number specified in d is smaller than the number of devices required for storing the character string obtained by connection (In this case, "00H" cannot be stored after all character strings and final character.) (Error code: K6706) 2) When devices which store character strings specified in s which will store the character string obtained by connection (Error code: K6706) overlap device numbers specified in
d

3) When "00H" does not exist in the corresponding device range after devices specified in (Error code: K6706)

Program example
In this program, a character string stored in devices specified in s2 is connected after a character string stored in devices specified in s1 , and the character string obtained by connection is output to devices specified in d . 1) Function without EN/ENO(CONCAT)
[Structured ladder/FBD]

CONCAT g_string1="ABCDEF" g_string2="12345"


[ST]

_IN _IN

g_string3="ABCDEF12345"

g_string3:=CONCAT(g_string1,g_string2);

2) Function with EN/ENO(CONCAT_E)


[Structured ladder/FBD]

g_bool1 g_string1 g_string2


[ST]

CONCAT_E EN ENO _IN _IN

g_bool3 g_string3

g_bool3:=CONCAT_E(g_bool1,g_string1,g_string2,g_string3);

216

FXCPU Structured Programming Manual [Application Functions]

12 Applied Functions (Standard Character String Functions)


12.3 INSERT(_E) / String insertion

12.3

INSERT(_E) / String insertion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function inserts a character string.

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST INSERT(_IN1,_IN2,_P); Example: Label 3:= INSERT(Label 1,Label 2,D20);

13
Applied Functions (Functions Of Time Data Types)

INSERT
INSERT

Label 1 Label 2 D20 X000

_IN1 _IN2 _P

*1

Label 3

INSERT_E

Label 1 Label 2 D20

INSERT_E EN ENO *1 _IN1 _IN2 _P

Label 3

INSERT_E(EN,_IN1,_IN2,_P, Output label); Example: INSERT_E(X000,Label 1,Label 2, D20,Label 3);

14
Standard Function Blocks

*1.

Output variable

15
Operator
Description Execution condition Head word device which stores a character string to get insertion Head word device which stores a character string to be inserted Word device which stores a character position to get insertion Execution status Bit String String Word [signed] Bit Data type

2. Set data
Variable EN Input variable _IN1 ( s1 ) _IN2 ( s2 ) _P Output variable ENO *1 ( d ) ( n )

A
Correspondence between Devices and Addresses

Head word device which will store a character string obtained by String insertion

In explanation of functions, I/O variables inside ( ) are described.

B
Function/ Operator List

217

FXCPU Structured Programming Manual [Application Functions] Explanation of function and operation

12 Applied Functions (Standard Character String Functions)


12.3 INSERT(_E) / String insertion

1) This function inserts a character string stored in devices specified in s2 into an arbitrary position (counted from the head) of a character string stored in devices specified in s1 , and outputs the character string obtained by insertion to devices specified in d . The value specified in n specifies the position from which the character string stored in devices specified in s2 is inserted. After inserting a character string stored in devices specified in s2 into a character string stored in devices specified in s1 , this function ignores "00H" which indicates the end of a character string stored in devices specified in s2 . Example: When "4" is specified in n
Input value to s1 "ABCDE" High-order byte Low-order byte 1st word 2nd word 3rd word 42H(B) 44H(D) 00H 41H(A) 43H(C) 45H(E) Insertion start position n = 4th character Output value "ABC123456DE" High-order byte Low-order byte 42H(B) 31H(1) 33H(3) 35H(5) Input value to s2 "123456" High-order byte Low-order byte 1st word 2nd word 3rd word 4th word 32H(2) 34H(4) 36H(6) 0000H 31H(1) 33H(3) 35H(5) 44H(D) 00H 41H(A) 43H(C) 32H(2) 34H(4) 36H(6) 45H(E) 1st word 2nd word 3rd word 4th word 5th word 6th word

2) A character string (data) stored in devices specified in s indicates the data until "00H" is detected first in units of byte in the range starting from the specified device.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling character string data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling character string data. Use global labels when specifying labels.

Error
An operation error occurs in the following cases. The error flag M8067 turns ON, and D8067 stores the error code. 1) When the number of devices after the device number specified in devices required for storing the output data obtained by insertion (Error code: K6706)
d

is smaller than the number of

2) When devices which store character strings specified in s1 and s2 overlap device numbers specified in d which will store the character string obtained by connection (Error code: K6706) 3) When "00H" does not exist in the corresponding device range after devices specified in s1 and s2 (Error code: K6706) 4) When the number of characters of a character string stored in devices specified in s2 is 32768 or more (Error code: K6706) 5) When the value specified in (Error code: K6706)
n

is negative

218

FXCPU Structured Programming Manual [Application Functions] Program example

12 Applied Functions (Standard Character String Functions)


12.3 INSERT(_E) / String insertion

11
Applied Functions (Standard Comparison Functions)

In this program, a character string stored in devices specified in s2 is inserted into an arbitrary position (counted from the head) of a character string stored in devices specified in s1 , and the character string obtained by insertion is output to devices specified in d . 1) Function without EN/ENO(INSERT)
[Structured ladder/FBD]

12
Applied Functions (Standard Character String Functions)

INSERT g_string1="ABCDEF" g_string2="12345" g_int1=3


[ST]

_IN1 _IN2 _P

g_string3="AB12345CDEF"

13
Applied Functions (Functions Of Time Data Types)

g_string3:=INSERT(g_string1,g_string2,g_int1);

2) Function with EN/ENO(INSERT_E)


[Structured ladder/FBD]

14
Standard Function Blocks

g_bool1 g_string1 g_string2 g_int1


[ST]

INSERT_E EN ENO _IN1 _IN2 _P

g_bool3 g_string3

15
Operator

g_bool3:=INSERT_E(g_bool1,g_string1,g_string2,g_int1,g_string3);

A
Correspondence between Devices and Addresses

B
Function/ Operator List

219

FXCPU Structured Programming Manual [Application Functions]

12 Applied Functions (Standard Character String Functions)


12.4 DELETE(_E) / String deletion

12.4

DELETE(_E) / String deletion


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function deletes a character string.

1. Format
Function name Expression in each language Structured ladder/FBD ST DELETE(_IN,_L ,_P); Example: Label 2:= DELETE(Label 1,D10,D20); DELETE_E(EN,_IN,_L ,_P, Output label); Example: DELETE_E(X000, Label 1, D10, D20, Label 2);

DELETE
DELETE

Label 1 D10 D20 X000

_IN _L _P

*1

Label 2

DELETE_E

Label 1 D10 D20

DELETE_E EN ENO _IN *1 _L _P

Label 2

*1.

Output variable

2. Set data
Variable EN Input variable _IN ( s ) _L _P Output variable ENO *1 ( d ) ( n1 ) ( n2 ) Execution condition Head word device which stores a character string to get deletion Number of characters to be deleted Head position to get deletion Execution status Description Bit String Word [signed] Word [signed] Bit Data type

Head word device which will store a character string remaining after String deletion

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function deletes specified number of characters from an arbitrary position of a character string stored in devices specified in s , and outputs the character string remaining after deletion to devices specified in d . The value specified in n1 specifies the number of characters to be deleted. The value specified in n2 specifies the position from which specified number of characters are deleted. Example: When "5" is specified in n1 and n2
"ABCDEF12345" High-order byte Low-order byte 1st word 2nd word 3rd word 4th word 5th word 6th word 42H(B) 44H(D) 46H(F) 32H(2) 34H(4) 00H 41H(A) 43H(C) 45H(E) 31H(1) 33H(3) 35H(5) Number of characters to be deleted n1 = 5 Deletion start position n2 = 5th character "ABCD45" High-order byte Low-order byte 42H(B) 44H(D) 35H(5) 41H(A) 43H(C) 34H(4) 1st word 2nd word 3rd word 4th word

0000H

2) A character string (data) stored in devices specified in s indicates the data until "00H" is detected first in units of byte in the range starting from the specified device.

220

FXCPU Structured Programming Manual [Application Functions] Cautions

12 Applied Functions (Standard Character String Functions)


12.4 DELETE(_E) / String deletion

11
Applied Functions (Standard Comparison Functions)

1) Use the function having "_E" in its name to connect a bus. 2) When handling character string data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling character string data. Use global labels when specifying labels.

12
Applied Functions (Standard Character String Functions)

Error
An operation error occurs in the following cases. The error flag M8067 turns ON, and D8067 stores the error code. 1) When "00H" does not exist in the corresponding device range after the device specified in (Error code: K6706) 2) When the number of characters of a character string stored in devices specified in (Error code: K6706)
s s

13
Applied Functions (Functions Of Time Data Types)

is 32768 or more

3) When the number of devices after the device number specified in d is smaller than the number of devices required for storing the character string remaining after deletion of specified number of characters (Error code: K6706) 4) When the value specified in n2 is negative (Error code: K6706)

14
Standard Function Blocks

Program example
In this program, specified number of characters are deleted from an arbitrary position of a character string stored in devices specified in s , and the character string remaining after deletion is output to devices specified in d . 1) Function without EN/ENO(DELETE)
[Structured ladder/FBD]

15
Operator

DELETE g_string1="ABCDEF12345" g_int1="4" g_int2="3"


[ST]

A
Correspondence between Devices and Addresses

_IN _L _P

g_string2="AB12345"

g_string2:=DELETE(g_string1,g_int1,g_int2);

B
Function/ Operator List

2) Function with EN/ENO(DELETE_E)


[Structured ladder/FBD]

g_bool1 g_string1 g_int1 g_int2


[ST]

DELETE_E EN ENO _IN _L _P

g_bool3 g_string2

g_bool3:=DELETE_E(g_bool1,g_string1,g_int1,g_int2,g_string2);

221

FXCPU Structured Programming Manual [Application Functions]

12 Applied Functions (Standard Character String Functions)


12.5 REPLACE(_E) / String replacement

12.5

REPLACE(_E) / String replacement


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function replaces a character string.

1. Format
Function name Expression in each language Structured ladder/FBD ST REPLACE(_IN1,_IN2,_L ,_P); Example: Label 3:= REPLACE(Label 1,Label 2, D20,D30);

REPLACE

Label 1 Label 2 D20 D30 X000

REPLACE _IN1 *1 _IN2 _L _P REPLACE_E EN ENO _IN1 *1 _IN2 _L _P

Label 3

REPLACE_E

Label 1 Label 2 D20 D30

Label 3

REPLACE_E(EN,_IN1,_IN2, _L ,_P,Output label); Example: REPLACE_E(X000,Label 1, Label 2,D20,D30,Label 3);

*1.

Output variable

2. Set data
Variable EN _IN1 ( s1 ) Input variable _IN2 ( s2 ) _L _P Output variable ENO *1 ( d ) ( n1 ) ( n2 ) Execution condition Head word device which stores a character string to be replaced Head word device which stores a replacement character string Word device which stores the number of characters to be replaced Description Bit String String Word [signed] Data type

Word device which stores the head character position to be Word [signed] replaced in a character string to be replaced Execution status Bit Head word device which will store a character string obtained by String replacement

In explanation of functions, I/O variables inside ( ) are described.

222

FXCPU Structured Programming Manual [Application Functions] Explanation of function and operation

12 Applied Functions (Standard Character String Functions)


12.5 REPLACE(_E) / String replacement

11
Applied Functions (Standard Comparison Functions)

1) This function replaces specified number of characters from an arbitrary position of a character string stored in devices specified in s1 with a character string stored in devices specified in s2 , and outputs the character string obtained by replacement to devices specified in d . The value specified in n1 specifies the number of characters to be replaced. The value specified in n2 specifies the position from which specified number of characters are replaced. Example: When "5" is specified in n1 and n2
Input value to s1 "ABCDEFGH123" High-order byte Low-order byte 1st word 2nd word 3rd word 4th word 5th word 6th word 42H(B) 44H(D) 46H(F) 48H(H) 32H(2) 00H 41H(A) 43H(C) 45H(E) 47H(G) 31H(1) 33H(3) Number of characters to be replaced n1 = 5 Replacement start position n2 = 5th character Output value "ABCD1234523" High-order byte Low-order byte 42H(B) 44H(D) 32H(2) 34H(4) 32H(2) 00H 41H(A) 43H(C) 31H(1) 33H(3) 35H(5) 33H(3) 1st word 2nd word 3rd word 4th word 5th word 6th word

12
Applied Functions (Standard Character String Functions)

13
Applied Functions (Functions Of Time Data Types)

14
Standard Function Blocks

Input value to s2 "123456" High-order byte Low-order byte 1st word 2nd word 3rd word 4th word 32H(2) 34H(4) 36H(6) 0000H 31H(1) 33H(3) 35H(5)

15
Operator

2) A character string (data) stored in devices specified in s indicates the data until "00H" is detected first in units of byte in the range starting from the specified device. 3) When "n1+n2" exceeds the number of characters of a character string stored in devices specified in s1 , excessive characters are not output to devices specified in d . 4) When "-1" is specified in n1 , the number of characters of a character string stored in devices specified in s2 is regarded as the value specified in n1 .

A
Correspondence between Devices and Addresses

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling character string data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling character string data. Use global labels when specifying labels.

B
Function/ Operator List

223

FXCPU Structured Programming Manual [Application Functions] Error

12 Applied Functions (Standard Character String Functions)


12.5 REPLACE(_E) / String replacement

An operation error occurs in the following cases. The error flag M8067 turns ON, and D8067 stores the error code. 1) When "00H" does not exist in the corresponding device range after the devices specified in s1
s2

and

(Error code: K6706) 2) When the value specified in n1 devices specified in s2 (Error code: K6706) exceeds the number of characters of a character string stored in

3) When the value specified in n2 is negative (Error code: K6706) 4) When the value specified in n1 is "-2" or less (Error code: K6706) 5) When the value specified in n2 devices specified in s1 (Error code: K6706) exceeds the number of characters of a character string stored in

Program example
In this program, specified number of characters starting from an arbitrary position of a character string stored in devices specified in s1 are replaced with a character string stored in devices specified in s2 , and the character string obtained by replacement is output to devices specified in d . 1) Function without EN/ENO(REPLACE)
[Structured ladder/FBD]

REPLACE g_string1="ABCDEFGH" g_string2="012345678" g_int1=6 g_int2=3


[ST]

_IN1 _IN2 _L _P

g_string3="AB012345"

g_string3:=REPLACE(g_string1,g_string2,g_int1,g_int2);

2) Function with EN/ENO(REPLACE_E)


[Structured ladder/FBD]

g_bool1 g_string1 g_string2 g_int1 g_int2


[ST]

REPLACE_E EN ENO _IN1 _IN2 _L _P

g_bool3 g_string3

g_bool3:=REPLACE_E(g_bool1,g_string1,g_string2,g_int1,g_int2,g_string3);

224

FXCPU Structured Programming Manual [Application Functions]

12 Applied Functions (Standard Character String Functions)


12.6 FIND(_E) / Searches a character string

12.6

FIND(_E) / Searches a character string


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function searches a character string.

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST FIND(_IN1,_IN2); Example: D20:= FIND(Label 1,Label 2); FIND_E(EN,_IN1,_IN2,Output label); Example: FIND_E(X000,Label 1,Label 2, D20);

13
Applied Functions (Functions Of Time Data Types)

FIND

Label 1 Label 2

FIND _IN1 *1 _IN2

D20

X000
FIND_E

Label 1 Label 2

FIND_E EN ENO _IN1 *1 _IN2

14
Standard Function Blocks

D20

*1.

Output variable

2. Set data
Variable EN Input variable Output variable _IN1 ( s1 ) _IN2 ( s2 ) ENO *1 ( d ) Execution condition Head word device which stores a character string to get search Head word device which stores a character string to be searched Execution status Head word device which will store the search result Description Bit String String Bit Word [signed] Data type

15
Operator

A
Correspondence between Devices and Addresses

In explanation of functions, I/O variables inside ( ) are described.

B
Function/ Operator List

225

FXCPU Structured Programming Manual [Application Functions] Explanation of function and operation

12 Applied Functions (Standard Character String Functions)


12.6 FIND(_E) / Searches a character string

1) This function searches a character string stored in devices specified in s2 from the beginning of a character string stored in devices specified in s1 , and outputs the search result to devices specified in d . This function outputs the head character position of the searched character string detected first as the search result. 2) A character string (data) stored in devices specified in s indicates the data until "00H" is detected first in units of byte in the range starting from the specified device. 3) If a character string stored in devices specified in s2 cannot be detected in a character string stored in devices specified in s1 , this function outputs "0".
Input value to s1 "ABCD1234567" High-order byte Low-order byte 1st word 2nd word 3rd word 4th word 5th word 6th word 42H(B) 44H(D) 32H(2) 34H(4) 36H(6) 00H 41H(A) 43H(C) 31H(1) 33H(3) 35H(5) 37H(7) Search of character string Output value 5 Word [signed]

Input value to s2 "1234" High-order byte Low-order byte 1st word 2nd word 3rd word 32H(2) 34H(4) 0000H 31H(1) 33H(3)

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling character string data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling character string data. Use global labels when specifying labels.

Error
An operation error occurs in the following cases. The error flag M8067 turns ON, and D8067 stores the error code. 1) When "00H (NULL)" does not exist in the corresponding device range specified in s1 (Error code: K6706) 2) When "00H (NULL)" does not exist in the corresponding device range specified in s2 (Error code: K6706)

226

FXCPU Structured Programming Manual [Application Functions] Program example

12 Applied Functions (Standard Character String Functions)


12.6 FIND(_E) / Searches a character string

11
Applied Functions (Standard Comparison Functions)

In this program, a character string stored in devices specified in s2 is searched from the beginning of a character string stored in devices specified in s1 , and the search result is output to devices specified in d . 1) Function without EN/ENO(FIND)
[Structured ladder/FBD]

12
Applied Functions (Standard Character String Functions)

FIND g_string1="ABCDEFGHIJK" g_string2="EFGHIJK"


[ST]

_IN1 _IN2

g_int1=5

13
Applied Functions (Functions Of Time Data Types)

g_int1:=FIND(g_string1,g_string2);

2) Function with EN/ENO(FIND_E)


[Structured ladder/FBD]

14
FIND_E EN _IN1 _IN2 ENO g_bool3 g_int1
Standard Function Blocks

g_bool1 g_string1 g_string2


[ST]

g_bool3:=FIND_E(g_bool1,g_string1,g_string2,g_int1);

15
Operator

A
Correspondence between Devices and Addresses

B
Function/ Operator List

227

FXCPU Structured Programming Manual [Application Functions]

13 Applied Functions (Functions Of Time Data Types)

13. Applied Functions (Functions Of Time Data Types)


Function name ADD_TIME(_E) SUB_TIME(_E) MUL_TIME(_E) DIV_TIME(_E) Addition Subtraction Multiplication Division Function Reference Section 13.1 Section 13.2 Section 13.3 Section 13.4

228

FXCPU Structured Programming Manual [Application Functions]

13 Applied Functions (Functions Of Time Data Types)


13.1 ADD_TIME(_E) / Addition

13.1

ADD_TIME(_E) / Addition
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function adds time data.

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST ADD_TIME(_IN1,_IN2); Example: Label 3:= ADD_TIME(Label 1,Label 2); ADD_TIME_E(EN,_IN1,_IN2, Output label); Example: ADD_TIME_E(X000,Label 1, Label 2,Label 3);

13
Applied Functions (Functions Of Time Data Types)

ADD_TIME

Label 1 Label 2

ADD_TIME _IN1 *1 _IN2

Label 3

X000
ADD_TIME_E

Label 1 Label 2

ADD_TIME_E EN ENO _IN1 *1 _IN2

14
Standard Function Blocks

Label 3

*1.

Output variable

2. Set data
Variable EN Input variable Output variable _IN1 ( s1 ) _IN2 ( s2 ) ENO *1 ( d ) Execution condition Head word device which stores time data to get addition Head word device which stores addition time data Execution status Head word device which will store the operation result Description Bit Time Time Bit Time Data type

15
Operator

A
Correspondence between Devices and Addresses

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function performs addition ( s1 + s2 ) of time data stored in devices specified in s1 and s2 , and outputs the operation result expressed as time data to devices specified in d .

B
Function/ Operator List

229

FXCPU Structured Programming Manual [Application Functions] Cautions

13 Applied Functions (Functions Of Time Data Types)


13.1 ADD_TIME(_E) / Addition

1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) Even if underflow or overflow occurs in the operation result, it is not regarded as an operation error. However, note that the accurate operation result cannot be obtained in this case. ("ADD_TIME_E" outputs "TRUE" from ENO.) Either of the flags shown in the table below turns ON or OFF in accordance with the operation result.
Device M8020 Name Zero Description ON : When the operation result is "0" OFF: When the operation result is any other than "0" ON : When the operation result is less than "-32,768" (16-bit operation) or less than "2,147,483,648" (32-bit operation) OFF: When the operation result is "-32,768" (16-bit operation) or more or "-2,147,483,648" (32bit operation) or more ON : When the operation result exceeds "32,767" (16-bit operation) or "2,147,483,647" (32-bit operation) OFF: When the operation result is "32,767" (16-bit operation) or less or "2,147,483,647" (32-bit operation) or less

M8021

Borrow

M8022

Carry

Zero flag -2 , -1 , 0 , -32,768 The most significant bit of data is "1".

Zero flag -1 , 0 , 1 The most significant bit of data is "0".

Zero flag 32,767 , 0, 1, 2

Borrow flag Zero flag -2 , -1 , 0 ,

Carry flag Zero flag

-2,147,483,648

-1 , 0 , 1 Zero flag

2,147,483,647 ,

0, 1, 2

Borrow flag

Carry flag

Program example
In this program, addition ( s1 + s2 ) is performed using time data stored in devices specified in s1 and s2 , and the operation result expressed as time data is output to devices specified in d . 1) Function without EN/ENO(ADD_TIME)
[Structured ladder/FBD]

g_time1 g_time2
[ST]

ADD_TIME _IN1 _IN2

g_time3

g_time3:=ADD_TIME(g_time1,g_time2);

2) Function with EN/ENO(ADD_TIME_E)


[Structured ladder/FBD]

g_bool1 g_time1 g_time2


[ST]

ADD_TIME_E EN ENO _IN1 _IN2

g_bool3 g_time3

g_bool3:=ADD_TIME_E(g_bool1,g_time1,g_time2,g_time3);

230

FXCPU Structured Programming Manual [Application Functions]

13 Applied Functions (Functions Of Time Data Types)


13.2 SUB_TIME(_E) / Subtraction

13.2

SUB_TIME(_E) / Subtraction
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function performs subtraction of time data.

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST SUB_TIME(_IN1,_IN2); Example: Label 3:= SUB_TIME(Label 1,Label 2); SUB_TIME_E(EN,_IN1,_IN2, Output label); Example: SUB_TIME_E(X000,Label 1, Label 2,Label 3);

13
Applied Functions (Functions Of Time Data Types)

SUB_TIME

Label 1 Label 2

SUB_TIME _IN1 *1 _IN2

Label 3

X000
SUB_TIME_E

Label 1 Label 2

SUB_TIME_E EN ENO _IN1 *1 _IN2

14
Standard Function Blocks

Label 3

*1.

Output variable

2. Set data
Variable EN Input variable Output variable _IN1 ( s1 ) _IN2 ( s2 ) ENO *1 ( d ) Execution condition Head word device which stores time data to get subtraction Head word device which stores subtraction data Execution status Head word device which will store the operation result Description Bit Time Time Bit Time Data type

15
Operator

A
Correspondence between Devices and Addresses

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function performs subtraction ( s1 - s2 ) of time data stored in devices specified in s1 and s2 , and outputs the operation result expressed as time data to devices specified in d .

B
Function/ Operator List

231

FXCPU Structured Programming Manual [Application Functions] Cautions

13 Applied Functions (Functions Of Time Data Types)


13.2 SUB_TIME(_E) / Subtraction

1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) Even if underflow or overflow occurs in the operation result, it is not regarded as an operation error. However, note that the accurate operation result cannot be obtained in this case. ("SUB_TIME_E" outputs "TRUE" from ENO.) Either of the flags shown in the table below turns ON or OFF in accordance with the operation result.
Device M8020 Name Zero Description ON : When the operation result is "0" OFF: When the operation result is any other than "0" ON : When the operation result is less than "-32,768" (16-bit operation) or less than "2,147,483,648" (32-bit operation) OFF: When the operation result is "-32,768" (16-bit operation) or more or "-2,147,483,648" (32bit operation) or more ON : When the operation result exceeds "32,767" (16-bit operation) or "2,147,483,647" (32-bit operation) OFF: When the operation result is "32,767" (16-bit operation) or less or "2,147,483,647" (32-bit operation) or less

M8021

Borrow

M8022

Carry

Zero flag -2 , -1 , 0 , -32,768 Borrow flag Zero flag -2 , -1 , 0 , -2,147,483,648 The most significant bit of data is "1".

Zero flag -1 , 0 , 1 The most significant bit of data is "0".

Zero flag 32,767 , 0, 1, 2

Carry flag Zero flag

-1 , 0 , 1 Zero flag

2,147,483,647 ,

0, 1, 2

Borrow flag

Carry flag

Program example
In this program, subtraction ( s1 - s2 ) is performed using time data stored in devices specified in s1 and s2 , and the operation result expressed as time data is output to devices specified in d . 1) Function without EN/ENO(SUB_TIME)
[Structured ladder/FBD]

g_time1 g_time2
[ST]

SUB_TIME _IN1 _IN2

g_time3

g_time3:=SUB_TIME(g_time1,g_time2);

2) Function with EN/ENO(SUB_TIME_E)


[Structured ladder/FBD]

g_bool1 g_time1 g_time2


[ST]

SUB_TIME_E EN ENO _IN1 _IN2

g_bool3 g_time3

g_bool3:=SUB_TIME_E(g_bool1,g_time1,g_time2,g_time3);

232

FXCPU Structured Programming Manual [Application Functions]

13 Applied Functions (Functions Of Time Data Types)


13.3 MUL_TIME(_E) / Multiplication

13.3

MUL_TIME(_E) / Multiplication
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function performs multiplication of time data.

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST MUL_TIME(_IN1,_IN2); Example: Label 3:= MUL_TIME(Label 1,Label 2); MUL_TIME_E(EN,_IN1,_IN2, Output label); Example: MUL_TIME_E(X000,Label 1, Label 2,Label 3);

13
Applied Functions (Functions Of Time Data Types)

MUL_TIME

Label 1 Label 2

MUL_TIME _IN1 *1 _IN2

Label 3

X000
MUL_TIME_E

Label 1 Label 2

MUL_TIME_E EN ENO _IN1 *1 _IN2

14
Standard Function Blocks

Label 3

*1.

Output variable

2. Set data
Variable EN Input variable Output variable _IN1 ( s1 ) _IN2 ( s2 ) ENO *1 ( d ) Execution condition Head word device which stores time data to get multiplication Multiplication data, or head word device which stores such data Execution status Head word device which will store the operation result Description Bit Time ANY_NUM Bit Time Data type

15
Operator

A
Correspondence between Devices and Addresses

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function performs multiplication( s1 s2 ) using time data stored in devices specified in s1 and s2 , and outputs the operation result expressed as time data to devices specified in d .

B
Function/ Operator List

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) Even if underflow or overflow occurs in the operation result, it is not regarded as an operation error. However, note that the accurate operation result cannot be obtained in this case. ("MUL_TIME_E" outputs "TRUE" from ENO.) 4) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

233

FXCPU Structured Programming Manual [Application Functions] Program example

13 Applied Functions (Functions Of Time Data Types)


13.3 MUL_TIME(_E) / Multiplication

In this program, multiplication ( s1 s2 ) is performed using time data stored in devices specified in s1 and s2 , and the operation result expressed as time data is output to devices specified in d . 1) Function without EN/ENO(MUL_TIME)
[Structured ladder/FBD]

g_time1 g_int1
[ST]

MUL_TIME _IN1 _IN2

g_time2

g_time2:=MUL_TIME(g_time1,g_int1);

2) Function with EN/ENO(MUL_TIME_E)


[Structured ladder/FBD]

g_bool1 g_time1 g_int1


[ST]

MUL_TIME_E EN ENO _IN1 _IN2

g_bool3 g_time2

g_bool3:=MUL_TIME_E(g_bool1,g_time1,g_int1,g_time2);

234

FXCPU Structured Programming Manual [Application Functions]

13 Applied Functions (Functions Of Time Data Types)


13.4 DIV_TIME(_E) / Division

13.4

DIV_TIME(_E) / Division
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function performs division using time data.

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST DIV_TIME(_IN1,_IN2); Example: Label 3:= DIV_TIME(Label 1,Label 2); DIV_TIME_E(EN,_IN1,_IN2, Output label); Example: DIV_TIME_E(X000,Label 1, Label 2,Label 3);

13
Applied Functions (Functions Of Time Data Types)

DIV_TIME

Label 1 Label 2

DIV_TIME _IN1 *1 _IN2

Label 3

X000
DIV_TIME_E

Label 1 Label 2

DIV_TIME_E EN ENO _IN1 *1 _IN2

14
Standard Function Blocks

Label 3

*1.

Output variable

2. Set data
Variable EN Input variable Output variable _IN1 ( s1 ) _IN2 ( s2 ) ENO *1 ( d ) Execution condition Head word device which stores time data to get division Division data, or head word device which stores such data Execution status Head word device which will store the operation result Description Bit Time ANY_NUM Bit Time Data type

15
Operator

A
Correspondence between Devices and Addresses

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


1) This function performs division ( s1 / s2 ) using time data stored in devices specified in s1 and s2 , and outputs the operation result expressed as time data to devices specified in d . 2) The contents of devices specified in s2 are ANY_NUM type data except "0".

B
Function/ Operator List

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) When the FLOAT (Single Precision) data to s is set from the programming tool, a rounding error may be generated. Refer to the MELSEC-Q/L/F Structured Programming Manual (Fundamentals) for cautions on setting the input value from the programming tool.

Error
1) An operation error occurs when the divisor stored in devices specified in s2 is "0", and the function is not executed. 2) An operation error occurs when the operation result exceeds "2,147,483,647".

235

FXCPU Structured Programming Manual [Application Functions] Program example

13 Applied Functions (Functions Of Time Data Types)


13.4 DIV_TIME(_E) / Division

In this program, division ( s1 / s2 ) is performed using time data stored in devices specified in s1 and s2 , and the operation result expressed as time data is output to devices specified in d . 1) Function without EN/ENO(DIV_TIME)
[Structured ladder/FBD]

g_time1 g_int1
[ST]

DIV_TIME _IN1 _IN2

g_time2

g_time2:=DIV_TIME(g_time1,g_int1);

2) Function with EN/ENO(DIV_TIME_E)


[Structured ladder/FBD]

g_bool1 g_time1 g_int1


[ST]

DIV_TIME_E EN ENO _IN1 _IN2

g_bool3 g_time2

g_bool3:=DIV_TIME_E(g_bool1,g_time1,g_int1,g_time2);

236

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks

11
Applied Functions (Standard Comparison Functions)

14. Standard Function Blocks


Function name R_TRIG(_E) F_TRIG(_E) CTU(_E) CTD(_E) CTUD(_E) TP(_E) TON(_E) TOF(_E) COUNTER_FB_M TIMER_10_FB_M TIMER_CONT_FB_M TIMER_100_FB_M Rising edge detector Falling edge detector Up counter Down counter Up/Down counter Pulse timer On delay timer Off delay timer Counter function blocks Timer function blocks Timer function blocks Timer function blocks Function Reference Section 14.1 Section 14.2 Section 14.3 Section 14.4 Section 14.5 Section 14.6 Section 14.7 Section 14.8 Section 14.9 Section 14.10 Section 14.11 Section 14.12

12
Applied Functions (Standard Character String Functions)

13
Applied Functions (Functions Of Time Data Types)

14
Standard Function Blocks

15
Operator

A
Correspondence between Devices and Addresses

B
Function/ Operator List

237

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.1 R_TRIG(_E) / Rising edge detector

14.1

R_TRIG(_E) / Rising edge detector


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function block detects the rising edge of a signal, and outputs pulse signal.

1. Format
Function name Expression in each language Structured ladder/FBD ST R_TRIG(_CLK,Q); Example: Instance name(_CLK:=M0, Q:=M10); R_TRIG_E(EN,_CLK,Q,ENO); Example: Instance name(EN:=X000, _CLK:=M0,Q:=M10);

Instance name
R_TRIG

M0

R_TRIG Q _CLK

M10

Instance name
R_TRIG_E

X000 M0

R_TRIG_E EN ENO _CLK Q

M10

2. Set data
Variable Input variable Output variable EN _CLK ENO Q ( d ) ( s ) Execution condition Input signal whose rising edge is to be detected Execution status Output signal Description Bit Bit Bit Bit Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function block sets to ON a device specified in d when a device specified in keeps ON the device specified in d only for 1 operation cycle.
s

turns ON, and

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) Expression of function blocks in each language Set the instance when using a function block. Describe the instance name when programming a function block.

Error
1) When an output number is specified in d and the specified output number does not exist due to indexing, M8316 (I/O inexistence error) turns ON. (Applicable to the FX3U and FX3UC PLCs only) 2) When a device (M, T or C) other than I/O number is specified in d and the specified device number does not exist due to indexing, an operation error (Error code: 6706) occurs.

238

FXCPU Structured Programming Manual [Application Functions] Program example

14 Standard Function Blocks


14.1 R_TRIG(_E) / Rising edge detector

11
Applied Functions (Standard Comparison Functions)

In this program, a device specified in d turns ON when the bit data stored in a device specified in turns ON from OFF, and the device specified in d remains ON only for 1 operation cycle. 1) Function without EN/ENO(R_TRIG)
[Structured ladder/FBD]

12
Applied Functions (Standard Character String Functions)

R_TRIG_Instance g_bool1
[ST]

R_TRIG _CLK

g_bool2

R_TRIG_Instance(_CLK:=g_bool1,Q:=g_bool2);

13
Applied Functions (Functions Of Time Data Types)

2) Function with EN/ENO(R_TRIG_E)


[Structured ladder/FBD]

X000 g_bool1
[ST]

R_TRIG_E_Instance R_TRIG_E EN ENO _CLK Q

Y010 g_bool2

14
Standard Function Blocks

R_TRIG_E_Instance(EN:=X000,_CLK:=g_bool1,Q:=g_bool2,ENO:=Y010);

15
Operator

A
Correspondence between Devices and Addresses

B
Function/ Operator List

239

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.2 F_TRIG(_E) / Falling edge detector

14.2

F_TRIG(_E) / Falling edge detector


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function block detects the falling edge of a signal, and outputs pulse signal.

1. Format
Function name Expression in each language Structured ladder/FBD ST F_TRIG(_CLK,Q); Example: Instance name(_CLK:=M0, Q:=M10); F_TRIG_E(EN,_CLK,Q,ENO); Example: Instance name(EN:=X000, _CLK:=M0,Q:=M10);

Instance name
F_TRIG

M0

F_TRIG _CLK Q

M10

Instance name
F_TRIG_E

X000 M0

F_TRIG_E EN ENO _CLK Q

M10

2. Set data
Variable Input variable Output variable EN _CLK ENO Q ( d ) ( s ) Execution condition Input signal whose falling edge is to be detected Execution status Output signal Description Bit Bit Bit Bit Data type

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function block sets to ON a device specified in d when a device specified in keeps ON the device specified in d only for 1 operation cycle.
s

turns OFF, and

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) Expression of function blocks in each language Set the instance when using a function block. Describe the instance name when programming a function block.

Error
1) When an output number is specified in d and the specified output number does not exist due to indexing, M8316 (I/O inexistence error) turns ON. (Applicable to the FX3U and FX3UC PLCs only) 2) When a device (M, T or C) other than I/O number is specified in d and the specified device number does not exist due to indexing, an operation error (Error code: 6706) occurs.

240

FXCPU Structured Programming Manual [Application Functions] Program example

14 Standard Function Blocks


14.2 F_TRIG(_E) / Falling edge detector

11
Applied Functions (Standard Comparison Functions)

In this program, a device specified in d turns ON when the bit data stored in a device specified in turns OFF from ON, and the device specified in d remains ON only for 1 operation cycle. 1) Function without EN/ENO(F_TRIG)
[Structured ladder/FBD]

12
Applied Functions (Standard Character String Functions)

F_TRIG_Instance g_bool1
[ST]

F_TRIG _CLK

g_bool2

F_TRIG_Instance(_CLK:=g_bool1,Q:=g_bool2);

13
Applied Functions (Functions Of Time Data Types)

2) Function with EN/ENO(F_TRIG_E)


[Structured ladder/FBD]

X000 g_bool1
[ST]

F_TRIG_E_Instance F_TRIG_E EN ENO _CLK Q

Y010 g_bool2

14
Standard Function Blocks

F_TRIG_E_Instance(EN:=X000,_CLK:=g_bool1,Q:=g_bool2,ENO:=Y010);

15
Operator

A
Correspondence between Devices and Addresses

B
Function/ Operator List

241

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.3 CTU(_E) / Up counter

14.3

CTU(_E) / Up counter
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function block counts up the number of times of rising of a signal.

1. Format
Function name Expression in each language Structured ladder/FBD ST CTU(CU,RESET,PV,Q,CV); Example: Instance name(CU:=M0, RESET:=M10,PV:=D0,Q:=M20, CV:=D10);

Instance name
CTU
CTU

M0 M10 D0

CU RESET PV

Q CV

M20 D10

Instance name
X000
CTU_E

M0 M10 D0

CTU_E EN ENO CU Q RESET CV PV

M20 D10

CTU_E(EN,CU,RESET,PV,Q,CV, ENO); Example: Instance name(EN:=X000, CU:=M0,RESET:=M10,PV:=D0, Q:=M20,CV:=D10);

2. Set data
Variable EN Input variable CU ( s1 ) Execution condition Count source signal Reset input signal Counter set value Execution status ( d1 ) ( d2 ) Count-up output signal Number of times of rising Description Bit Bit Bit Word [signed] Bit Bit Word [signed] Data type

RESET ( s2 ) PV ENO ( n )

Output variable

Q CV

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function block counts up (adds "1" to) the value stored in a device specified in d2 when a device specified in s1 turns ON. When the count value reaches a value specified in n , a device specified in d1 turns ON. When a device specified in s2 turns ON, this function block turns OFF a device specified in d1 , and resets the count value of a device specified in d2 .

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) Expression of function blocks in each language Set the instance when using a function block. Describe the instance name when programming a function block.

242

FXCPU Structured Programming Manual [Application Functions] Program example

14 Standard Function Blocks


14.3 CTU(_E) / Up counter

11
Applied Functions (Standard Comparison Functions)

In this program, the number of times the bit data stored in a device specified in s1 turns ON from OFF is counted, and the count value is output to a device specified in d2 . 1) Function without EN/ENO(CTU)
[Structured ladder/FBD]

12
Applied Functions (Standard Character String Functions)

CTU_Instance CTU g_bool1 g_bool2 g_int1


[ST]

CU RESET PV

Q CV

g_bool3 g_int2

13
Applied Functions (Functions Of Time Data Types)

CTU_Instance(CU:=g_bool1,RESET:=g_bool2,PV:=g_int1,Q:=g_bool3,CV:=g_int2);

2) Function with EN/ENO(CTU_E)


[Structured ladder/FBD]

14
Standard Function Blocks

CTU_E_Instance M10 g_bool1 g_bool2 g_int1


[ST]

CTU_E EN CU RESET PV ENO Q CV M11 g_bool3 g_int2

15
Operator

CTU_E_Instance(EN:=M10,CU:=g_bool1,RESET:=g_bool2,PV:=g_int1,Q:=g_bool3,CV:=g_int2,ENO:=M11);

A
Correspondence between Devices and Addresses

B
Function/ Operator List

243

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.4 CTD(_E) / Down counter

14.4

CTD(_E) / Down counter


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function block counts down the number of times of rising of a signal.

1. Format
Function name Expression in each language Structured ladder/FBD ST CTD(CD,LOAD,PV,Q,CV); Example: Instance name(CD:=M0, LOAD:=M10,PV:=D0,Q:=M20, CV:=D10);

Instance name
CTD
CTD

M0 M10 D0

CD LOAD PV

Q CV

M20 D10

Instance name
X000
CTD_E

M0 M10 D0

CTD_E EN ENO CD Q LOAD CV PV

M20 D10

CTD_E(EN,CD,LOAD,PV,Q,CV, ENO); Example: Instance name(EN:=X000, CD:=M0,LOAD:=M10,PV:=D0, Q:=M20,CV:=D10);

2. Set data
Variable EN Input variable CD LOAD PV ENO Output variable Q CV ( d1 ) ( d2 ) ( s1 ) ( s2 ) ( n ) Execution condition Count source signal Reset input signal Counter set value Execution status Description Bit Bit Bit Word [signed] Bit Data type

Output signal (which turns ON when the current counter value Bit becomes "0" or less) Number of times of rising Word [signed]

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function block counts down (subtracts "1" from) the value stored in a device specified in d2 when a device specified in s1 turns ON. The value n specifies the initial value for subtraction. This function block turns ON a device specified in d1 when the count value becomes "0". When a device specified in s2 turns ON, this function block turns OFF a device specified in d1 , and sets the initial value for subtraction specified in n to the count value of a device specified in d2 .

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) Expression of function blocks in each language Set the instance when using a function block. Describe the instance name when programming a function block.

244

FXCPU Structured Programming Manual [Application Functions] Program example

14 Standard Function Blocks


14.4 CTD(_E) / Down counter

11
Applied Functions (Standard Comparison Functions)

In this program, the number of times the bit data stored in a device specified in s1 turns ON from OFF is counted, and a device specified in d1 turns ON when the value stored in a device specified in d2 becomes "0". 1) Function without EN/ENO(CTD)
[Structured ladder/FBD]

12
Applied Functions (Standard Character String Functions)

CTD_Instance CTD g_bool1 g_bool2 g_int1


[ST]

CD LOAD PV

Q CV

g_bool3 g_int2

13
Applied Functions (Functions Of Time Data Types)

CTD_Instance(CD:=g_bool1,LOAD:=g_bool2,PV:=g_int1,Q:=g_bool3,CV:=g_int2);

2) Function with EN/ENO(CTD_E)


[Structured ladder/FBD]

14
Standard Function Blocks

CTD_E_Instance M10 g_bool1 g_bool2 g_int1


[ST]

CTD_E EN CD LOAD PV ENO Q CV M11 g_bool3 g_int2

15
Operator

CTD_E_Instance(EN:=M10,CD:=g_bool1,LOAD:=g_bool2,PV:=g_int1,Q:=g_bool3,CV:=g_int2,ENO:=M11);

A
Correspondence between Devices and Addresses

B
Function/ Operator List

245

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.5 CTUD(_E) / Up/Down counter

14.5

CTUD(_E) / Up/Down counter


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function block counts up/down the number of times of rising of a signal.

1. Format
Function name Expression in each language Structured ladder/FBD ST CTUD(CU,CD,RESET,LOAD,PV, QU,QD,CV); Example: Instance name(CU:=M0, CD:=M10,RESET:=M20, LOAD:=M30,PV:=D0,QU:=M40, QD:=M50,CV:=D10);

Instance name
CTUD
CTUD

M0 M10 M20 M30 D0

CU QU CD QD RESET CV LOAD PV

M40 M50 D10

Instance name
X000
CTUD_E

M0 M10 M20 M30 D0

CTUD_E EN ENO QU CU CD QD RESET CV LOAD PV

M40 M50 D10

CTUD_E(EN,CU,CD,RESET, LOAD,PV,QU,QD,CV,ENO); Example: Instance name(EN:=X000, CU:=M0,CD:=M10,RESET:=M20, LOAD:=M30,PV:=D0,QU:=M40, QD:=M50,CV:=D10);

2. Set data
Variable EN CU Input variable CD ( s1 ) ( s2 ) Execution condition Count up signal Count down signal Reset input signal Resetting signal Counter set value Execution status ( d1 ) ( d2 ) ( d3 ) Count-up output signal Description Bit Bit Bit Bit Bit Word [signed] Bit Bit Data type

RESET ( s3 ) LOAD PV ENO QU QD CV ( s4 ) ( n )

Output variable

Output signal (which turns ON when the current counter value Bit becomes "0" or less) Count value data Word [signed]

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


This function block counts up (adds "1" to) the value stored in a device specified in d3 when a device specified in s1 turns ON. This function block counts down (subtracts "1" from) the value stored in a device specified in d3 when a device specified in s2 turns ON. n specifies the maximum value of the counter. When the value stored in a device specified in d3 reaches the maximum value n of the counter, a device specified in d1 turns ON. When the value stored in a device specified in d3 becomes "0", a device specified in d2 turns ON. This function block resets the count value of a device specified in d3 when a device specified in s3 turns ON. This function block sets the value stored in n to a device specified in d3 when a device specified in s4 turns ON.

246

FXCPU Structured Programming Manual [Application Functions] Cautions


1) Use the function having "_E" in its name to connect a bus. 2) Expression of function blocks in each language Set the instance when using a function block. Describe the instance name when programming a function block.

14 Standard Function Blocks


14.5 CTUD(_E) / Up/Down counter

11
Applied Functions (Standard Comparison Functions)

12
Applied Functions (Standard Character String Functions)

Program example
In this program, the number of times the bit data stored in a device specified in s1 turns ON from OFF is counted up (added by "1"). When the value stored in a device specified in d3 reaches the value specified in n , a device specified in d1 turns ON. At the same time, the number of times the bit data stored in a device specified in s2 turns ON from OFF is counted down (subtracted by "1"). When the value stored in a device specified in d3 becomes "0", a device specified in d2 turns ON. 1) Function without EN/ENO(CTUD)
[Structured ladder/FBD]

13
Applied Functions (Functions Of Time Data Types)

14
Standard Function Blocks

CTUD_Instance CTUD g_bool1 g_bool2 g_bool3 g_bool4 g_int1


[ST]

CU CD RESET LOAD PV

QU QD CV

g_bool5 g_bool6 g_int2

15
Operator

CTUD_Instance(CU:=g_bool1,CD:=g_bool2,RESET:=g_bool3,LOAD:=g_bool4,PV:=g_int1,QU:=g_bool5, QD:=g_bool6,CV:=g_int2);

2) Function with EN/ENO(CTUD_E)


[Structured ladder/FBD]

A
Correspondence between Devices and Addresses

CTUD_E_Instance M0 g_bool1 g_bool2 g_bool3 g_bool4 g_int1


[ST]

CTUD_E EN CU CD RESET LOAD PV ENO QU QD CV M10 g_bool5 g_bool6 g_int2

B
Function/ Operator List

CTUD_E_Instance(EN:=M0,CU:=g_bool1,CD:=g_bool2,RESET:=g_bool3,LOAD:=g_bool4,PV:=g_int1, QU:=g_bool5,QD:=g_bool6,CV:=g_int2,ENO:=M10);

247

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.6 TP(_E) / Pulse timer

14.6

TP(_E) / Pulse timer


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function block keeps ON a signal for specified duration.

1. Format
Function name Expression in each language Structured ladder/FBD ST TP(IN,PT,Q,ET); Example: Instance name(IN:=M0, PT:=Label 1,Q:=M10, ET:=Label 2); TP_E(EN,IN,PT,Q,ET,ENO); Example: Instance name(EN:=X000, IN:=M0,PT:=Label 1,Q:=M10, ET:=Label 2);

Instance name
TP

TP M0 Label 1 IN PT Q ET M10 Label 2

Instance name
X000
TP_E

M0 Label 1

TP_E EN ENO Q IN PT ET

M10 Label 2

2. Set data
Variable EN Input variable IN ENO Output variable Q ( d1 ) ( s ) Execution condition ON start input signal ON duration data Execution status Output signal ON duration current value Description Bit Bit Time Bit Bit Time Data type

PT ( n )

ET ( d2 )

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


When a device specified in s turns ON, this function block turns ON a device specified in d1 , and keeps it ON for duration specified in n . The elapsed time while a device specified in d1 remains ON is set to a device specified in d2 . A device specified in d1 turns OFF when the elapsed time reaches the set value. Even if a device specified in d1 turns OFF, this function block does not reset the elapsed time. When a device specified in s turns ON from OFF next time, this function block resets the elapsed time and turns ON again a device specified in d1 .

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) Expression of function blocks in each language Set the instance when using a function block. Describe the instance name when programming a function block.

248

FXCPU Structured Programming Manual [Application Functions] Program example


In this program, when bit data stored in a device specified in specified in d1 turns ON and remains ON for 10 seconds. 1) Function without EN/ENO(TP)
[Structured ladder/FBD]

14 Standard Function Blocks


14.6 TP(_E) / Pulse timer

11
Applied Functions (Standard Comparison Functions)

turns ON, bit data stored in a device

12
Applied Functions (Standard Character String Functions)

TP_Instance TP g_bool1 T#10s


[ST]

IN PT

Q ET

g_bool2 g_time1

13
Applied Functions (Functions Of Time Data Types)

TP_Instance(IN:=g_bool1,PT:=T#10s,Q:=g_bool2,ET:=g_time1);

2) Function with EN/ENO(TP_E)


[Structured ladder/FBD]

M0 g_bool1 T#10s
[ST]

TP_E_Instance TP_E EN ENO IN Q PT ET

14
Standard Function Blocks

M10 g_bool2 g_time1

TP_E_Instance(EN:=M0,IN:=g_bool1,PT:=T#10s,Q:=g_bool2,ET:=g_time1,ENO:=M10);

15
Operator

A
Correspondence between Devices and Addresses

B
Function/ Operator List

249

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.7 TON(_E) / On delay timer

14.7

TON(_E) / On delay timer


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function block turns ON after specified time.

1. Format
Function name Expression in each language Structured ladder/FBD ST TON(IN,PT,Q,ET); Example: Instance name(IN:=M0, PT:=Label 1,Q:=M10, ET:=Label 2); TON_E(EN,IN,PT,Q,ET,ENO); Example: Instance name(EN:=X000, IN:=M0,PT:=Label 1,Q:=M10, ET:=Label 2);

Instance name
TON

TON M0 Label 1 IN PT Q ET M10 Label 2

Instance name
X000
TON_E

M0 Label 1

TON_E EN ENO Q IN PT ET

M10 Label 2

2. Set data
Variable EN Input variable IN ENO Output variable Q ( d1 ) ( s ) Execution condition Input signal ON start time data Execution status Output signal ON start time current value Description Bit Bit Time Bit Bit Time Data type

PT ( n )

ET ( d2 )

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


When a device specified in s turns ON, this function block turns ON a device specified in d1 after the time specified in n . The delay elapsed time until a device specified in d1 turns ON is set to a device specified in d2 . When a device specified in s turns OFF, this function block turns OFF a device specified in d1 and resets the delay elapsed time.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) Expression of function blocks in each language Set the instance when using a function block. Describe the instance name when programming a function block.

250

FXCPU Structured Programming Manual [Application Functions] Program example


In this program, when bit data stored in a device specified in specified in d1 turns ON 10 seconds later. 1) Function without EN/ENO(TON)
[Structured ladder/FBD]

14 Standard Function Blocks


14.7 TON(_E) / On delay timer

11
Applied Functions (Standard Comparison Functions)

turns ON, bit data stored in a device

12
Applied Functions (Standard Character String Functions)

TON_Instance TON g_bool1 T#10s


[ST]

IN PT

Q ET

g_bool2 g_time1

13
Applied Functions (Functions Of Time Data Types)

TON_Instance(IN:=g_bool1,PT:=T#10s,Q:=g_bool2,ET:=g_time1);

2) Function with EN/ENO(TON_E)


[Structured ladder/FBD]

M0 g_bool1 T#10s
[ST]

TON_E_Instance TON_E EN ENO IN Q PT ET

14
Standard Function Blocks

M10 g_bool2 g_time1

TON_E_Instance(EN:=M0,IN:=g_bool1,PT:=T#10s,Q:=g_bool2,ET:=g_time1,ENO:=M10);

15
Operator

A
Correspondence between Devices and Addresses

B
Function/ Operator List

251

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.8 TOF(_E) / Off delay timer

14.8

TOF(_E) / Off delay timer


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
When the input signal turns OFF, this function block turns OFF the output signal after the specified time.

1. Format
Function name Expression in each language Structured ladder/FBD ST TOF(IN,PT,Q,ET); Example: Instance name(IN:=M0, PT:=Label 1,Q:=M10, ET:=Label 2); TOF_E(EN,IN,PT,Q,ET,ENO); Example: Instance name(EN:=X000, IN:=M0,PT:=Label 1,Q:=M10, ET:=Label 2);

Instance name
TOF

TOF M0 Label 1 IN PT Q ET M10 Label 2

Instance name
X000
TOF_E

M0 Label 1

TOF_E EN ENO Q IN PT ET

M10 Label 2

2. Set data
Variable EN Input variable IN ENO Output variable Q ( d1 ) ( s ) Execution condition Input signal OFF duration data Execution status Output signal OFF duration current value Description Bit Bit Time Bit Bit Time Data type

PT ( n )

ET ( d2 )

In explanation of functions, I/O variables inside ( ) are described.

Explanation of function and operation


When a device specified in s turns ON, this function block turns ON a device specified in d1 . When a device specified in s turns OFF from ON, this function block turns OFF a device specified in d1 after the time specified in n . The elapsed time until a device specified in d1 turns OFF is set to a device specified in d2 . When a device specified in s turns ON again, this function block turns ON a device specified in d1 and resets the elapsed time.

Cautions
1) Use the function having "_E" in its name to connect a bus. 2) When handling 32-bit data in structured programs, you cannot specify 16-bit devices directly, different from simple projects. Use labels when handling 32-bit data. You can specify 32-bit counters directly, however, because they are 32-bit devices. Use global labels when specifying labels. 3) Expression of function blocks in each language Set the instance when using a function block. Describe the instance name when programming a function block.

252

FXCPU Structured Programming Manual [Application Functions] Program example

14 Standard Function Blocks


14.8 TOF(_E) / Off delay timer

11
Applied Functions (Standard Comparison Functions)

In this program, when bit data stored in a device specified in s turns ON, bit data stored in a device specified in d1 turns ON. When bit data stored in a device specified in s turns OFF, bit data stored in a device specified in d1 turns OFF 10 seconds later. 1) Function without EN/ENO(TOF)
[Structured ladder/FBD]

12
Applied Functions (Standard Character String Functions)

TOF_Instance TOF g_bool1 T#10s


[ST]

IN PT

Q ET

g_bool2 g_time1

13
Applied Functions (Functions Of Time Data Types)

TOF_Instance(IN:=g_bool1,PT:=T#10s,Q:=g_bool2,ET:=g_time1);

2) Function with EN/ENO(TOF_E)


[Structured ladder/FBD]

14
Standard Function Blocks

M0 g_bool1 T#10s
[ST]

TOF_E_Instance TOF_E EN ENO IN Q PT ET

M10 g_bool2 g_time1

15
Operator

TOF_E_Instance(EN:=M0,IN:=g_bool1,PT:=T#10s,Q:=g_bool2,ET:=g_time1,ENO:=M10);

A
Correspondence between Devices and Addresses

B
Function/ Operator List

253

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.9 COUNTER_FB_M / Counter function blocks

14.9

COUNTER_FB_M / Counter function blocks


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This counter starts counting when the condition turns ON from OFF and generates an output when counting up to the set value. A counter initial value can be set.

1. Format
Function name Expression in each language Structured ladder/FBD ST

COUNTER_FB_M

Instance name COUNTER_FB_M Coil ValueOut Preset Status ValueIn

COUNTER_FB_M(Coil,Preset,Val ueIn,ValueOut,Status);

2. Set data
Variable Input variable Output variable Coil Preset ValueIn ValueOut Status Execution condition Counter set value Counter initial value Counter current value Counter output contact Description Bit Word [signed] Word [signed] ANY16 Bit Data type

Function and operation explanation


1) The counter starts counting when detecting the rising edge (from OFF to ON) of the input argument Coil. It does not start counting if the Coil remains ON. The counter starts counting from the value of input argument ValueIn. When the input argument Preset value is reached, the output argument Status turns ON. The current count value is stored in the output argument ValueOut.
[Structured ladder/FBD] COUNTER_FB_M_Instance Var_M0 10 1 COUNTER_FB_M Coil ValueOut Preset Status ValueIn Var_D10 *1 Var_M10 *2

timing chart Var_M0 1 ON ON ON

Value of Var_D10

10

[ ST ] COUNTER_FB_M_Instance(Coil:= Var_M0,Preset:=10, ValueIn:=1,ValueOut:=Var_D10,Status:=Var_M10);

Var_M10

ON

*1. Var_D10 is a global label and is defined as D10. *2. Var_M10 is a global label and is defined as M10.

254

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.9 COUNTER_FB_M / Counter function blocks

2) When resetting the current value of the counter, reset input variable coil.

11
Applied Functions (Standard Comparison Functions)

[Structured ladder/FBD]
COUNTER_FB_M_Instance COUNTER_FB_M Var_D10 Coil ValueOut Var_M0 10 1 M15 EN Preset ValueIn RST ENO d COUNTER_FB_M_Instance.Coil Status Var_M10

12
Applied Functions (Standard Character String Functions)

13
Applied Functions (Functions Of Time Data Types)

[ST]
COUNTER_FB_M_Instance(Coil:= Var_M0,Preset:=10,ValueIn:=1, ValueOut:=Var_D10,Status:=Var_M10); RST(M15,COUNTER_FB_M_Instance.Coil);

Cautions
1) Expression in each language of function block Set the instance when using the function block. Describe the instance name when programming the function block. 2) For the function block, the automatic allocation device needs to be set as the counter numbers are allocated automatically.

14
Standard Function Blocks

15
Operator

A
Correspondence between Devices and Addresses

B
Function/ Operator List

255

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.10 TIMER_10_FB_M / Timer function blocks

14.10 TIMER_10_FB_M / Timer function blocks


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This function block generates an output when the condition continues for the specified time. The initial value and setting value of the timer is multiplied by 10 ms.

1. Format
Function name Expression in each language Structured ladder/FBD ST

TIMER_10_FB_M

Instance name TIMER_10_FB_M Coil ValueOut Preset Status ValueIn

TIMER_10_FB_M(Coil,Preset, ValueIn,ValueOut,Status);

2. Set data
Variable Input variable Output variable Coil Preset ValueIn ValueOut Status Execution condition Timer set value Initial timer value Current timer value Timer output contact Description Bit Word [signed] Word [signed] ANY16 Bit Data type

Function and operation explanation


1) When the execution condition of the input argument Coil turns ON, counting the current value starts. The timer starts counting from "ValueIn 10 ms". When it counts up to "Preset 10 ms", the output argument Status turns ON. The current measurement value is outputted into ValueOut. 2) When the execution condition of the input argument Coil turns OFF, the current value takes on the value of ValueIn and the output argument Status also turns OFF.
[Structured ladder/FBD] TIMER_10_FB_M_Instance TIMER_10_FB_M ValueOut Var_D10 *1 Var_M0 Coil Status 10 Preset Var_M10 *2 1 ValueIn [ ST ] TIMER_10_FB_M_Instance(Coil:= Var_M0,Preset:= 10, ValueIn:= 1,ValueOut:= Var_D10,Status:=Var_M10);

timing chart Var_M0 ON 10 Value of Var_D10 1 90ms ON

Var_M10

*1. *2.

Var_D10 is a global label and is defined as D10. Var_M10 is a global label and is defined as M10.

Cautions
1) Expression in each language of function block Set the instance when using the function block. Describe the instance name when programming the function block. 2) For the function block, the automatic allocation device needs to be set as the timer numbers are allocated automatically.

256

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.11 TIMER_CONT_FB_M / Timer function blocks

14.11 TIMER_CONT_FB_M / Timer function blocks


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function block counts the period of time while the condition is satisfied, and generates an output when the timer counts up the specified time.

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST

13
Applied Functions (Functions Of Time Data Types)

TIMER_ CONT_FB_M

Instance name TIMER_CONT_FB_M Coil ValueOut Preset Status ValueIn

TIMER_CONT_FB_M(Coil, Preset,ValueIn,ValueOut,Status);

14
Standard Function Blocks
Description Data type Bit Word [signed] Word [signed] ANY16 Bit

2. Set data
Variable Input variable Output variable Coil Preset ValueIn ValueOut Status Execution condition Timer set value Initial timer value Current timer value Timer output contact

15
Operator

Function and operation explanation


1) This is a retentive timer that counts the time when the variable is ON. It starts counting the current value when the execution condition of the input argument Coil turns ON. The timer starts counting from "ValueIn 1 to 1000 ms". When it counts up to "Preset 1 to 1000 ms", the output argument Status turns ON. The current measurement value is outputted into ValueOut. 2) The condition of measurement ValueOut and output argument ON/OFF status is maintained even if the execution condition of the input argument Coil turns OFF. When the execution condition of the input argument Coil turns ON, the timer resume counting from the measurement it holds.
[Structured ladder/FBD] TIMER_CONT_FB_M_Instance Var_M0 200 0 TIMER_CONT_FB_M Coil ValueOut Preset Status ValueIn Var_D10 *1 Var_M10 *2

A
Correspondence between Devices and Addresses

B
Function/ Operator List

timing chart Var_M0 0 1 ON 15 sec Value of Var_D10 150 ON 5 sec 151-200

[ ST ] TIMER_CONT_FB_M_Instance(Coil:= Var_M0,Preset:= 200, ValueIn:= 0,ValueOut:= Var_D10,Status:=Var_M10);

Var_M10

ON

*1. *2.

Var_D10 is a global label and is defined as D10. Var_M10 is a global label and is defined as M10.

257

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.11 TIMER_CONT_FB_M / Timer function blocks

3) When resetting the current value of the retentive timer, reset input variable coil.

[Structured ladder/FBD]
TIMER_CONT_FB_M_Instance TIMER_CONT_FB_M Var_D10 Coil ValueOut Var_M0 10 1 M15 EN Preset ValueIn RST ENO d TIMER_CONT_FB_M_Instance.Coil Status Var_M10

[ST]
TIMER_CONT_FB_M_Instance(Coil:= Var_M0,Preset:=10,ValueIn:=1, ValueOut:=Var_D10,Status:=Var_M10); RST(M15,TIMER_CONT_FB_M_Instance.Coil);

Cautions
1) Expression in each language of function block Set the instance when using the function block. Describe the instance name when programming the function block. 2) For the function block, the automatic allocation device needs to be set as the timer numbers are allocated automatically.

258

FXCPU Structured Programming Manual [Application Functions]

14 Standard Function Blocks


14.12 TIMER_100_FB_M / Timer function blocks

14.12 TIMER_100_FB_M / Timer function blocks


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This function block generates an output when the condition continues for the specified time. The initial value and setting value of the timer is multiplied by 100 ms.

12
Applied Functions (Standard Character String Functions)

1. Format
Function name Expression in each language Structured ladder/FBD ST

13
Applied Functions (Functions Of Time Data Types)

TIMER_100_FB_M

Instance name TIMER_100_FB_M Coil ValueOut Preset Status ValueIn

TIMER_100_FB_M(Coil,Preset, ValueIn,ValueOut,Status);

14
Standard Function Blocks
Description Data type Bit Word [signed] Word [signed] ANY16 Bit

2. Set data
Variable Input variable Output variable Coil Preset ValueIn ValueOut Status Execution condition Timer set value Initial timer value Current timer value Timer output contact

15
Operator

Function and operation explanation


1) When the execution condition of the input argument Coil turns ON, counting the current value starts. The timer starts counting from "ValueIn 100 ms". When it counts up to "Preset 100 ms", the output argument Status turns ON. The current measurement value is outputted into ValueOut. 2) When the execution condition of the input argument Coil turns OFF, the current value takes on the value of ValueIn and the output argument Status also turns OFF.
[Structured ladder/FBD] TIMER_100_FB_M_Instance Var_M0 10 1 [ ST ] TIMER_100_FB_M Coil ValueOut Status Preset ValueIn Var_D10 *1 Var_M10 *2

A
Correspondence between Devices and Addresses

timing chart Var_M0 ON 10 Value of Var_D10 1 900ms ON

B
Function/ Operator List

TIMER_100_FB_M_Instance(Coil:= Var_M0,Preset:= 10, ValueIn:= 1,ValueOut:= Var_D10,Status:=Var_M10);

Var_M10

*1. *2.

Var_D10 is a global label and is defined as D10. Var_M10 is a global label and is defined as M10.

Cautions
1) Expression in each language of function block Set the instance when using the function block. Describe the instance name when programming the function block. 2) For the function block, the automatic allocation device needs to be set as the timer numbers are allocated automatically.

259

FXCPU Structured Programming Manual [Application Functions]

15 Operator

15. Operator
Function name ADD SUB MUL DIV MOD ** AND OR XOR NOT GT GE EQ LE LT NE Addition Subtraction Multiplication Division Modulus operation Exponentiation Logical product Logical sum Exclusive logical sum Logical negation Comparison Comparison Comparison Comparison Comparison Comparison Function Reference Section 15.1 Section 15.2 Section 15.3 Section 15.4 Section 15.5 Section 15.6 Section 15.7 Section 15.8 Section 15.9 Section 15.10 Section 15.11 Section 15.12 Section 15.13 Section 15.14 Section 15.15 Section 15.16

260

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.1 ADD / Addition

15.1

ADD / Addition
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This operator performs addition using two values (A + B = C), and outputs the operation result.

12
Applied Functions (Standard Character String Functions)

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1+s2; Example: D20:=D0+D10;

13
Applied Functions (Functions Of Time Data Types)

ADD

ADD

D0 D10

s1 s2

D20

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

14
Standard Function Blocks

Description Data for addition or word device which stores such data Word device which will store the operation result

Data type ANY_NUM ANY_NUM

to s28

15
Operator

Explanation of function and operation


1) This function performs addition ( s1 + s2 + s28 ) using word [signed]/double word [signed]/float (single precision) data stored in devices specified in s1 to s28 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [signed]
1234
s1 (Word [signed] data)

A
Correspondence between Devices and Addresses

5678
s2 (Word [signed] data) s

6912
d (Word [signed] data)

2) The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

B
Function/ Operator List

Cautions
Refer to Section 7.1.

Program example
In this program, addition is performed using double word [signed] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_dint1 g_dint2
[ST]

ADD

g_dint3

g_dint3:=(g_dint1)+(g_dint2);

261

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.2 SUB / Subtraction

15.2

SUB / Subtraction
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This operator performs subtraction using two values (A - B = C), and outputs the operation result.

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1-s2; Example: D20:=D0-D10;

SUB

SUB

D0 D10

s1 s2

D20

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 s2 d

Description Data to be subtracted or word device which stores such data Data for subtraction or word device which stores such data Word device which will store the operation result

Data type ANY_NUM ANY_NUM ANY_NUM

Explanation of function and operation


This function performs subtraction ( s1 - s2 ) using word [signed]/double word [signed]/float (single precision) data stored in devices specified in s1 and s2 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 and s2 . Example: When the data type is word [signed]
12345
s1 (Word [signed] data)

6789
s2 (Word [signed] data)

5556
d (Word [signed] data)

Cautions
Refer to Section 7.2.

Program example
In this program, subtraction is performed using word [signed] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_int1 g_int2
[ST]

SUB

g_int3

g_int3:=(g_int1)-(g_int2);

262

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.3 MUL / Multiplication

15.3

MUL / Multiplication
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This operator performs multiplication using two or more values (A B = C), and outputs the operation result.

12
Applied Functions (Standard Character String Functions)

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1*s2; Example: D20:=D0*D10;

13
Applied Functions (Functions Of Time Data Types)

MUL
MUL

D0 D10

s1 s2

D20

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

14
Standard Function Blocks

Description Data for multiplication or word device which stores such data Word device which will store the operation result

Data type ANY_NUM ANY_NUM

to s28

15
Operator

Explanation of function and operation


1) This function performs multiplication ( s1 s2 s28 ) using word [signed]/double word [signed]/float (single precision) data stored in devices specified in s1 to s28 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [signed]
100
s1 (Word [signed] data)

A
Correspondence between Devices and Addresses

15
s2 (Word [signed] data) s

1500
d (Word [signed] data)

2) The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

B
Function/ Operator List

Cautions
Refer to Section 7.3.

Program example
In this program, multiplication is performed using double word [signed] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_dint1 g_dint2
[ST]

MUL

g_dint3

g_dint3:=(g_dint1) * (g_dint2);

263

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.4 DIV / Division

15.4

DIV / Division
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This operator performs division using two values (A / B = C remainder), and outputs the quotient.

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1/s2; Example: D20:=D0/D10;

DIV
DIV

D0 D10

s1 s2

D20

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 s2 d

Description Data to be divided, or word device which stores such data Data for division (divisor), or word device which stores such data Word device which will store the operation result

Data type ANY_NUM ANY_NUM ANY_NUM

Explanation of function and operation


This function performs division ( s1 / s2 ) using word [signed]/double word [signed]/float (single precision) data stored in devices specified in s1 and s2 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 and s2 . Example: When the data type is word [signed]
5
s1 (Word [signed] data)

2
s2 (Word [signed] data)

(Quotient) 2
d (Word [signed] data)

Cautions
Refer to Section 7.4.

Error
Refer to Section 7.4.

Program example
In this program, division is performed using double word [signed] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 .
[Structured ladder/FBD]

g_dint1 g_dint2
[ST]

DIV

g_dint3

g_dint3:=(g_dint1) /(g_dint2);

264

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.5 MOD / Modulus operation

15.5

MOD / Modulus operation


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This operator performs division using two values (A / B = C remainder), and outputs the remainder.

12
Applied Functions (Standard Character String Functions)

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1 MOD s2 ; The MOD operator is not available in Structured ladder/ Example: FBD language. d:=s1 MOD s2 ;

13
Applied Functions (Functions Of Time Data Types)

MOD

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 s2 d

Description Data to be divided, or word device which stores such data Data for division (divisor), or word device which stores such data Word device which will store the operation result ANY_INT ANY_INT ANY_INT

Data type

14
Standard Function Blocks

Explanation of function and operation


This function performs division ( s1 / s2 ) using word [signed]/double word [signed] data stored in devices specified in s1 and s2 , and outputs the remainder to a device specified in d using the data type of data stored in devices specified in s1 and s2 . Example: When the data type is word [signed]
5
s1 (Word [signed] data)

15
Operator

2
s2 (Word [signed] data)

(Quotient) 2 Not output

(Remainder) 1
d (Word [signed] data)

A
Correspondence between Devices and Addresses

Cautions
Refer to Section 7.5.

B
Function/ Operator List

Error
Refer to Section 7.5.

Program examples
In this program, division is performed using double word [signed] data stored in devices specified in s1 and s2 , and the remainder is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 .
[ST]

g_dint3:=g_dint1 MOD g_dint2;

265

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.6 ** / Exponentiation

15.6

** / Exponentiation
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This operator obtains raised result, and outputs it.

1. Format
Operator name Expression in each language Structured ladder/FBD s1 **s2; The "**" operator is not available in Structured ladder/ Example: FBD language. d:=s1 **s2; ST

**

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 s2 d

Description Data to be raised, or word device which stores such data Power data, or word device which stores such data Word device which will store the operation result

Data type FLOAT (Single Precision) ANY_NUM FLOAT (Single Precision)

Explanation of function and operation


This function raises float (single precision) data stored in a device specified in s1 (to the power of the value stored in a device specified in s2 ), and outputs the operation result to a device specified in d .
2 4.0
s1 Float (single precision) data

Word [signed] data


s2

16.0
d Float (single precision) data

Cautions Cautions
Refer to Section 7.6.

Error
Refer to Section 7.6.

Program examples
In this program, the value stored in a device specified in s1 is raised to the power of the value stored in a device specified in s2 , and the operation result is output to a device specified in d using the data type of data stored in a device specified in s1 .
[ST]

g_real2:=EXPT(g_real1,g_int1);

266

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.7 AND / Logical product

15.7

AND / Logical product


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This operator obtains the logical product of two or more bits, and outputs it.

12
Applied Functions (Standard Character String Functions)

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1 AND s2; Example: M20:=M0 AND M10;

13
Applied Functions (Functions Of Time Data Types)

AND

AND

M0 M10

s1 s2

M20

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

14
Standard Function Blocks
Description Device used to obtain the logical product Device which will store the operation result ANY_BIT ANY_BIT Data type to s28

Explanation of function and operation


1) This function obtains the logical product using each bit of bit/word [unsigned]/bit string [16-bit]/double word [unsigned]/bit string [32-bit] data stored in devices specified in s1 to s28 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [unsigned]/bit string [16-bit]
s1

15
Operator

A
Correspondence between Devices and Addresses

Logical product
s2

B
Function/ Operator List

0
s

2)

The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
Refer to Section 9.1.

Program examples
In this program, the logical product is obtained using each bit of word [unsigned]/bit string [16-bit] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 .
[Structured ladder/FBD]

g_word1 g_word2
[ST]

AND

g_word3

g_word3:=(g_word1) AND (g_word2); or g_word3:=(g_word1) & (g_word2);

267

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.8 OR / Logical sum

15.8

OR / Logical sum
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This operator obtains the logical sum of two or more bits, and outputs it.

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1 OR s2; Example: M20:=M0 OR M10;

OR
OR

M0 M10

s1 s2

M20

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

Description Device used to obtain the logical sum Device which will store the operation result ANY_BIT ANY_BIT

Data type

to s28

Explanation of function and operation


1) This function obtains the logical sum using each bit of bit/word [unsigned]/bit string [16-bit]/double word [unsigned]/bit string [32-bit] data stored in devices specified in s1 to s28 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [unsigned]/bit string [16-bit]]
s1

Logical sum
s2

1
s

2) The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
Refer to Section 9.2.

Program examples
In this program, the logical sum is obtained using each bit of word [unsigned]/bit string [16-bit] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 .
[Structured ladder/FBD]

g_word1 g_word2
[ST]

OR

g_word3

g_word3:=(g_word1) OR (g_word2);

268

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.9 XOR / Exclusive logical sum

15.9

XOR / Exclusive logical sum


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This operator obtains the logical sum of two or more bits, and outputs it.

12
Applied Functions (Standard Character String Functions)

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1 XOR s2; Example: M20:=M0 XOR M10;

13
Applied Functions (Functions Of Time Data Types)

XOR

XOR

M0 M10

s1 s2

M20

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

14
Standard Function Blocks

Description Device used to obtain the exclusive logical sum Device which will store the operation result ANY_BIT ANY_BIT

Data type

to s28

15
Operator

Explanation of function and operation


1) This function obtains the exclusive logical sum using each bit of bit/word [unsigned]/bit string [16-bit]/ double word [unsigned]/bit string [32-bit] data stored in devices specified in s1 to s28 , and outputs the operation result to a device specified in d using the data type of data stored in devices specified in s1 to s28 . Example: When the data type is word [unsigned]/bit string [16-bit]
s1

A
Correspondence between Devices and Addresses

Exclusive logical sum


s2

B
Function/ Operator List

0
s

2)

The number of pins for

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

3) If there are 3 or more s , the exclusive logical sum is obtained using the "exclusive logical sum of s1 and s2 " and s3 . If there is s4 , the exclusive logical sum is obtained using the "exclusive logical sum of "exclusive logical sum of s1 and s2 " and " s3 "" and s4 . In this way, the exclusive logical sum is obtained the s6 required number of times for all input labels s5 Example: When the data type is bit
When the number of "_IN" is 3
s1

When the number of "_IN" is 4 FALSE XOR


s4

When the number of "_IN" is 5 TRUE XOR


s5

FALSE XOR

TRUE XOR
s3

s2

TRUE

TRUE

TRUE

TRUE

Result TRUE

Result FALSE

Result TRUE

After that, the exclusive logical sum is obtained the required number of Result FALSE times.

269

FXCPU Structured Programming Manual [Application Functions] Cautions


Refer to Section 9.3.

15 Operator
15.9 XOR / Exclusive logical sum

Program examples
In this program, the exclusive logical sum is obtained using each bit of word [unsigned]/bit string [16-bit] data stored in devices specified in s1 and s2 , and the operation result is output to a device specified in d using the data type of data stored in devices specified in s1 and s2 .
[Structured ladder/FBD]

g_word1 g_word2
[ST]

XOR

g_word3

g_word3:=(g_word1) XOR (g_word2);

270

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.10 NOT / Logical negation

15.10 NOT / Logical negation


FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This operator obtains the logical negation of bits, and outputs it.

12
Applied Functions (Standard Character String Functions)

1. Format
Operator name Expression in each language Structured ladder/FBD NOT s1; The NOT operator is not available in Structured ladder/ Example: FBD language. d:=NOT(s); ST

13
Applied Functions (Functions Of Time Data Types)

NOT

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s d

Description Device used to obtain the logical negation Device which will store the operation result ANY_BIT ANY_BIT

Data type

14
Standard Function Blocks

Explanation of function and operation


This function obtains the logical negation using each bit of bit/word [unsigned]/bit string [16-bit]/double word [unsigned]/bit string [32-bit] data stored in a device specified in s , and outputs the operation result to a device specified in d using the data type of data stored in a device specified in s . Example: When the data type is word [unsigned]/bit string [16-bit]
s

15
Operator

A
Correspondence between Devices and Addresses

Logical negation
d

Cautions
Refer to Section 9.4.

B
Function/ Operator List

Program examples
In this program, the logical negation is obtained using each bit of word [unsigned]/bit string [16-bit] data stored in a device specified in s , and the operation result is output to a device specified in d using the data type of data stored in a device specified in s .
[ST]

g_word2:= NOT(g_word1);

271

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.11 GT / Comparison

15.11 GT / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This operator compares data with regard to "> (larger)".

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1>s2; Example: M0:=D0>D10;

GT
GT

D0 D10

s1 s2

M0

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

Description Compared data, or word device which stores such data Device which will store the comparison result ANY_BIT Bit

Data type

to s28

Explanation of function and operation


1) This function compares the contents of devices specified in s1 to s28 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 > s2 ] & [ s2 > s3 ] & & [ s n-1 > sn ]. a) This function outputs "TRUE" when all comparison results are " s n-1 > sn ". b) This function outputs "FALSE" when any comparison result is " s n-1 sn ". 2) The number of pins for
s

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
Refer to Section 11.1.

Program examples
In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_int1 g_int2
[ST]

GT

g_bool2

g_bool2:=(g_int1)>(g_int2);

272

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.12 GE / Comparison

15.12 GE / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This operator compares data with regard to " (larger or equal)".

12
Applied Functions (Standard Character String Functions)

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1>=s2; Example: M0:=D0>=D10;

13
Applied Functions (Functions Of Time Data Types)

GE
GE

D0 D10

s1 s2

M0

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

14
Standard Function Blocks

Description Compared data, or word device which stores such data Device which will store the comparison result

Data type ANY_SIMPLE Bit

to s28

15
Operator

Explanation of function and operation


1) This function compares the contents of devices specified in s1 to s28 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 s2 ] & [ s2 s3 ] & & [ s n-1 sn ]. a) This function outputs "TRUE" when all comparison results are " s n-1 sn ". b) This function outputs "FALSE" when any comparison result is " s n-1 < sn ". 2) The number of pins for
s

A
Correspondence between Devices and Addresses

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
Refer to Section 11.2.

B
Function/ Operator List

Program examples
In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_int1 g_int2
[ST]

GE

g_bool2

g_bool2:=(g_int1)>=(g_int2);

273

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.13 EQ / Comparison

15.13 EQ / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This operator compares data with regard to "= (equal)".

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1=s2; Example: M0:=D0=D10;

EQ

EQ

D0 D10

s1 s2

M0

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

Description Compared data, or word device which stores such data Device which will store the comparison result

Data type ANY_SIMPLE Bit

to s28

Explanation of function and operation


1) This function compares the contents of devices specified in s1 to s28 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 = s2 ] & [ s2 = s3 ] & & [ s n-1 = sn ]. a) This function outputs "TRUE" when all comparison results are " s n-1 = sn ". b) This function outputs "FALSE" when any comparison result is " s n-1 sn ". 2) The number of pins for
s

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
Refer to Section 11.3.

Program examples
In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_int1 g_int2
[ST]

EQ

g_bool2

g_bool2:=(g_int1)=(g_int2);

274

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.14 LE / Comparison

15.14 LE / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This operator compares data with regard to " (smaller or equal)".

12
Applied Functions (Standard Character String Functions)

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1<=s2; Example: M0:=D0<=D10;

13
Applied Functions (Functions Of Time Data Types)

LE

LE

D0 D10

s1 s2

M0

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

14
Standard Function Blocks

Description Compared data, or word device which stores such data Device which will store the comparison result

Data type ANY_SIMPLE Bit

to s28

15
Operator

Explanation of function and operation


1) This function compares the contents of devices specified in s1 to s28 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 s2 ] & [ s2 s3 ] & & [ s n-1 sn ]. a) This function outputs "TRUE" when all comparison results are " s n-1 sn ". b) This function outputs "FALSE" when any comparison result is " s n-1 > sn ". 2) The number of pins for
s

A
Correspondence between Devices and Addresses

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
Refer to Section 11.4.

B
Function/ Operator List

Program examples
In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_int1 g_int2
[ST]

LE

g_bool2

g_bool2:=(g_int1)<=(g_int2);

275

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.15 LT / Comparison

15.15 LT / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

Outline
This operator compares data with regard to "< (smaller)".

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1<s2; Example: M0:=D0<D10;

LT
LT

D0 D10

s1 s2

M0

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

Description Compared data, or word device which stores such data Device which will store the comparison result

Data type ANY_SIMPLE Bit

to s28

Explanation of function and operation


1) This function compares the contents of devices specified in s1 to s28 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 < s2 ] & [ s2 < s3 ] & & [ s n-1 < sn ]. a) This function outputs "TRUE" when all comparison results are " s n-1 < sn ". b) This function outputs "FALSE" when any comparison result is " s n-1 sn ". 2) The number of pins for
s

can be changed in the range of 2 to 28. Refer to Section 3. Function Construction

Cautions
Refer to Section 11.5.

Program examples
In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

g_int1 g_int2
[ST]

LT

g_bool2

g_bool2:=(g_int1)<(g_int2);

276

FXCPU Structured Programming Manual [Application Functions]

15 Operator
15.16 NE / Comparison

15.16 NE / Comparison
FX3U(C) FX3G(C) FX2N(C) FX1N(C) FX1S FXU/FX2C FX0N FX0(S)

11
Applied Functions (Standard Comparison Functions)

Outline
This operator compares data with regard to " (unequal)".

12
Applied Functions (Standard Character String Functions)

1. Format
Operator name Expression in each language Structured ladder/FBD ST s1<>s2; Example: M0:=D0<>D10;

13
Applied Functions (Functions Of Time Data Types)

NE
NE

D0 D10

s1 s2

M0

In explanation of operators, the input variable is described as "s " and the output variable is descried as "d".

2. Set data
Variable Input variable Output variable
s1 d

14
Standard Function Blocks

Description
s2

Data type ANY_SIMPLE Bit

to

Compared data, or word device which stores such data Device which will store the comparison result

15
Operator

Explanation of function and operation


This function compares the contents of devices specified in s1 and s2 , and outputs the operation result expressed as the bit type data to a device specified in d . This function executes comparison [ s1 s2 ]. a) This function outputs "TRUE" when in the case of " s1 s2 " b) This function outputs "FALSE" when in the case of " s1 = s2 "

A
Correspondence between Devices and Addresses

Cautions
Refer to Section 11.6.

Program examples
In this program, the contents of devices specified in s1 and s2 are compared, and the operation result is output to a device specified in d .
[Structured ladder/FBD]

B
Function/ Operator List

g_int1 g_int2
[ST]

NE

g_bool2

g_bool2:=(g_int1)<>(g_int2);

277

FXCPU Structured Programming Manual [Application Functions]

Appendix A: Correspondence between Devices and Addresses

Appendix A: Correspondence between Devices and Addresses


The table below shows the correspondence between devices and addresses.
Device Device Input relay Output relay Auxiliary relay Contact Timer Coil Current value Contact Counter Coil Current value X Y M TS TC TN CS CC CN D G R ER P I N Z V State S Xn Yn Mn Tn Tn Tn Cn Cn Cn Dn Ux\Gn Rn ERn Pn In Nn Zn Vn Sn %IXn %QXn %MX0.n %MX3.n %MX5.n %MW3.n %MD3.n %MX4.n %MX6.n %MW4.n %MD4.n %MW0.n %MD0.n %MW14.x.n %MD14.x.n %MW2.n %MD2.n No correspondence " "(NULL character) No correspondence No correspondence %MW7.n %MD7.n %MW6.n %MX2.n Z6 Z6 V7 S4095 P4095 %MW7.7 %MD7.6 %MW6.7 %MX2.4095 Notation Address X367 Y367 M499 TS191 TC191 TN190 T190 CS99 CC99 CN98 C98 D198* D198 U0\G09 U0\G09 R32766 R32766 Example of correspondence between device and address Device Address %IX247 %QX247 %MX0.499 %MX3.191 %MX5.191 %MW3.191 %MD3.190 %MX4.99 %MX6.99 %MW4.99 %MD4.98 %MW0.199 %MD0.198 %MW14.0.10 %MD14.0.9 %MW2.32767 %MD2.32766 No correspondence -

Data register Intelligent function unit device Extension register Extension file register Pointer Interrupt pointer Nesting Index register

278

Applied Functions (Standard Comparison Functions)

Applied Functions (Standard Character String Functions)

Applied Functions (Functions Of Time Data Types)

Standard Function Blocks

12

13

14

15

11

Appendix A: Correspondence between Devices and Addresses

Operator

Correspondence between Devices and Addresses

Function/ Operator List

FXCPU Structured Programming Manual [Application Functions]

MEMO

279

FXCPU Structured Programming Manual [Application Functions]

Appendix B: Application Function List


Appendix B-1 [By type]

Appendix B: Function/Operator List [by Type/in Alphabetic Order]


Appendix B-1 [By type]
1. Type Conversion Functions
Function name Function Ref. Page 38 40 42 44 46 48 50 52 54 56 58 60 62 64 66 68 70 72 74 76 78 80 82 84 Function name REAL_TO_ STR(_E) Function Converts float (single precision) data into string data. Ref. Page 86 89 91 93 95 97 99

BOOL_TO_ Converts bit data into word [signed] data. INT(_E) BOOL_TO_ Converts bit data into double word [signed] DINT(_E) data. BOOL_TO_ Converts bit data into string data. STR(_E) BOOL_TO_ Converts bit data into word [unsigned]/bit WORD(_E) string [16-bit] data. BOOL_TO_ Converts bit data into double word DWORD(_E) [unsigned]/bit string [32-bit] data. BOOL_TO_ Converts bit data into time data. TIME(_E) INT_TO_ DINT(_E) DINT_TO_ INT(_E) INT_TO_ BOOL(_E) DINT_TO_ BOOL(_E) INT_TO_ REAL(_E) DINT_TO_ REAL(_E) INT_TO_ STR(_E) DINT_TO_ STR(_E) INT_TO_ WORD(_E) DINT_TO_ WORD(_E) Converts word [signed] data into double word [signed] data Converts double word [signed] data into word [signed] data. Converts word [signed] data into bit data. Converts double word [signed] data into bit data. Converts word [signed] data into float (single precision) data. Converts double word [signed] data into float (single precision) data. Converts word [signed] data into string data. Converts double word [signed] data into string data. Converts word [signed] data into word [unsigned]/bit string [16-bit] data. Converts double word [signed] data into word [unsigned]/bit string [16-bit] data.

WORD_TO Converts word [unsigned]/bit string [16-bit] _BOOL(_E) data into bit data. DWORD_TO Converts double word [unsigned]/bit string _BOOL(_E) [32-bit] data into bit data. WORD_TO _INT(_E) WORD_TO _DINT(_E) Converts word [unsigned]/bit string [16-bit] data into word [signed] data. Converts word [unsigned]/bit string [16-bit] data into double word [signed] data.

DWORD_ Converts double word [unsigned]/bit string TO_INT(_E) [32-bit] data into word [signed] data. Converts double word [unsigned]/bit string DWORD_ [32-bit] data into double word [signed] TO_DINT(_E) data. Converts word [unsigned]/bit string [16-bit] WORD_TO_ data into double word [unsigned]/bit string DWORD(_E) [32-bit]. DWORD_ TO_WORD (_E) WORD_TO _TIME(_E) DWORD_ TO_TIME(_ E) STR_TO_ BOOL(_E) STR_TO_ INT(_E) STR_TO_ DINT(_E) STR_TO_ REAL(_E) STR_TO_ TIME(_E) BCD_TO_ INT(_E) BCD_TO_ DINT(_E) TIME_TO_ BOOL(_E) Converts double word [unsigned]/bit string [32-bit] data into word [unsigned]/bit string [16-bit] data. Converts word [unsigned]/bit string [16-bit] data into time data. Converts double word [unsigned]/bit string [32-bit] data into time data. Converts string data into bit data. Converts string data into word [signed] data. Converts string data into double word [signed] data. Converts string data into float (single precision) data. Converts string data into time data. Converts BCD data into word [signed] data. Converts BCD data into double word [signed] data. Converts time data into bit data.

101

103 105 107 109 111 113 115 118 120 122 124 126 128 130 132

INT_TO_ Converts word [signed] data into double DWORD(_E) word [unsigned]/bit string [32-bit] data. Converts double word [signed] data into DINT_TO_ double word [unsigned]/bit string [32-bit] DWORD(_E) data. INT_TO_B CD(_E) DINT_TO_ BCD(_E) INT_TO_ TIME(_E) DINT_TO_ TIME(_E) REAL_TO_ INT(_E) REAL_TO_ DINT(_E) Converts word [signed] data into BCD data. Converts double word [signed] data into BCD data. Converts word [signed] data into time data. Converts double word [signed] data into time data. Converts float (single precision) data into word [signed] data. Converts float (single precision) data into double word [signed] data.

TIME_TO_I Converts time data into word [signed] data. NT(_E) TIME_TO_ DINT(_E) TIME_TO_ STR(_E) TIME_TO_ WORD(_E) Converts time data into double word [signed] data. Converts time data into string data. Converts time data into word [unsigned]/bit string [16-bit] data.

280

FXCPU Structured Programming Manual [Application Functions]


Function name Ref. Page 134 136 OR_E 138 XOR_E NOT(_E) 140

Appendix B: Application Function List


Appendix B-1 [By type]

Function

5. Standard Bitwise Boolean Functions


Function name AND_E Function Obtains the logical product. (Number of pins variable) Obtains the logical sum. (Number of pins variable) Obtains the exclusive logical sum. (Number of pins variable) Obtains the logical not. Ref. Page 179 181 183 185

11
Applied Functions (Standard Comparison Functions)

TIME_TO_ Converts time data into double word DWORD(_E) [unsigned]/bit string [32-bit] data. Converts specified number of bits of a bit BITARR_ array into word [signed] data or word TO_INT(_E) [unsigned]/bit string [16-bit] data. Converts specified number of bits of a bit BITARR_TO array into double word [signed] data or _DINT(_E) double word [unsigned]/bit string [32-bit] data. INT_TO_ BITARR(_E) DINT_TO_ BITARR(_E) Outputs low-order "n" bits of word [signed] data or word [unsigned]/bit string [16-bit] data to a bit array. Outputs low-order "n" bits of double word [signed] data or double word [unsigned]/bit string [32-bit] data to a bit array.

12
Applied Functions (Standard Character String Functions)

6. Standard Selection Functions


Function name SEL(_E) Function Selects data in accordance with the input condition. Searches the maximum value. (Number of pins variable) Searches the minimum value. (Number of pins variable) Ref. Page 188 190 192 194 196

13
Applied Functions (Functions Of Time Data Types)

142 144 146 148 150 152

CPY_BITARR Copies specified number of bits of a bit (_E) array. GET_BIT_ OF_INT(_E) SET_BIT_ OF_INT(_E) CPY_BIT_ OF_INT(_E) Reads the value of a specified bit of word [signed] data. Writes a value to a specified bit of word [signed] data. Copies a specified bit of word [signed] data to a specified bit of another word [signed] data.

MAXIMUM (_E) MINIMUM (_E)

14
Standard Function Blocks

Judges whether data is located within the LIMITATION range between the upper limit value and (_E) the lower limit value. MUX(_E) Selects data, and outputs it. (Number of pins variable)

GET_BOOL Outputs start data as bit data. _ADDR GET_INT_ ADDR Outputs start data as word [signed] data.

7. Standard Comparison Functions


153 154 Function name GT_E GE_E Ref. Page 156 EQ_E LE_E LT_E Ref. Page 159 161 163 165 167 169 171 NE_E Function Compares data with regard to "> (larger)". (Number of pins variable) Compares data with regard to " (larger or equal)". (Number of pins variable) Compares data with regard to "= (equal)". (Number of pins variable) Compares data with regard to " (smaller or equal)". (Number of pins variable) Compares data with regard to (smaller)". (Number of pins variable) Compares data (unequal)". with regard to "< " Ref. Page 199 201 203 205 207 209

15
Operator

GET_WORD Outputs start data as word [unsigned]/bit _ADDR string [16-bit] data.

2. Standard Functions Of One Numeric Variable


Function name ABS(_E) Function Obtains the absolute value.

A
Correspondence between Devices and Addresses

3. Standard Arithmetic Functions


Function name ADD_E SUB_E MUL_E DIV_E MOD(_E) EXPT(_E) MOVE(_E) Function Adds data. (Number of pins variable) Subtracts data. Multiplies data. (Number of pins variable) Divides data (, and outputs the quotient). Divides data (, and outputs the remainder). Obtains the raised result. Transfers data.

B
Function/ Operator List

8. Standard Character String Functions


Function name MID(_E) CONCAT (_E) INSERT (_E) DELETE (_E) REPLACE (_E) FIND(_E) Function Obtains a character string from a specified position. Connects character strings. (Number of pins variable) Inserts a character string. Deletes a character string. Replaces a character string. Searches a character string. Ref. Page 212 215 217 220 222 225

4. Standard Bit Shift Functions


Function name SHL(_E) SHR(_E) Function Shifts bits leftward. Shifts bits rightward. Ref. Page 174 176

281

FXCPU Structured Programming Manual [Application Functions]


9. Functions Of Time Data Types
Function name ADD_TIME (_E) SUB_TIME (_E) MUL_TIME (_E) DIV_TIME (_E) Adds time data. Subtracts time data. Multiplies time data. Divides time data. Function Ref. Page 229 231 OR 233 235 XOR Ref. Page 238 240 242 244 246 248 250 252 254 256 257 259 LE GE

Appendix B: Application Function List


Appendix B-1 [By type]

12.Operator (Logical operations)


Operator name Structured ladder /FBD AND ST Function Ref. Page 267 268 269 271

& Obtains the logical product. AND (Number of pins variable) OR Obtains the logical sum. (Number of pins variable)

Obtains the exclusive logical XOR sum. (Number of pins variable) NOT Obtains the logical not.

10.Standard Function Blocks


Function name R_TRIG (_E) F_TRIG (_E) CTU(_E) CTD(_E) CTUD(_E) TP(_E) TON(_E) TOF(_E) COUNTER _ FB_M Function Detects the rising edge of a signal, and outputs pulse signal. Detects the falling edge of a signal, and outputs pulse signal. Counts up the number of times of rising of a signal. Counts down the number of times of rising of a signal. Counts up/down the number of times of rising of a signal. Keeps ON a signal during specified time duration. Keeps OFF a signal during specified time duration. Turns OFF the output signal at specified time after the input signal turned OFF. Counter drive

13.Operator (Comparison operations)


Operator name Structured ladder /FBD GT ST > Function Compares data with regard to "> (larger)". (Number of pins variable) Compares data with regard to " (larger or equal)". (Number of pins variable) Compares data with regard to "= (equal)". (Number of pins variable) Compares data with regard to " (smaller or equal)". (Number of pins variable) Compares data with regard to "< (smaller)". (Number of pins variable) Compares data with regard to " (unequal)". Ref. Page

272

>=

273

EQ

274

<=

275

LT NE

< <>

276 277

TIMER_10_ 10ms timer drive FB_M TIMER_CO NT Retentive timer drive _FB_M TIMER_100_ 100ms timer drive FB_M

11.Operator (Arithmetic operations)


Operator name Structured ladder /FBD ADD SUB MUL DIV ST + * / MOD ** Function Adds data. (Number of pins variable) Subtracts data. Multiplies data. (Number of pins variable) Divides data (, and outputs the quotient). Divides data (, and outputs the remainder). Obtains the raised result Ref. Page 261 262 263 264 265 266

282

FXCPU Structured Programming Manual [Application Functions]

Appendix B: Application Function List


Appendix B-2 [In alphabetic order]

Appendix B-2 [In alphabetic order]


Functions
Function name A ABS(_E) ADD_TIME (_E) ADD_E AND_E B BCD_TO_ DINT(_E) BCD_TO_I NT(_E) Converts BCD data into double word [signed] data. Converts BCD data into word [signed] data. 122 120 Obtains the absolute value. Adds time data. Adds data. (Number of pins variable) Obtains the logical product. (Number of pins variable) 156 229 159 179 Function Ref. Page Function name D DINT_TO_I NT(_E) DINT_TO_ REAL(_E) DINT_TO_ STR(_E) Converts double word [signed] data into word [signed] data. Converts double word [signed] data into float (single precision) data. Converts double word [signed] data into string data. 52 60 64 80 68 235 165 91 Function Ref. Page

11
Applied Functions (Standard Comparison Functions)

12
Applied Functions (Standard Character String Functions)

DINT_TO_T Converts double word [signed] data into IME(_E) time data. DINT_TO_ WORD(_E) DIV_TIME (_E) DIV_E DWORD_T O_BOOL (_E) Converts double word [signed] data into word [unsigned]/bit string [16-bit] data. Divides time data. Divides data (, and outputs the quotient). Converts double word [unsigned]/bit string [32-bit] data into bit data.

13
Applied Functions (Functions Of Time Data Types)

Converts specified number of bits of a bit BITARR_T array into double word [signed] data or O_DINT(_E) double word [unsigned]/bit string [32-bit] data. BITARR_T O_INT(_E) Converts specified number of bits of a bit array into word [signed] data or word [unsigned]/bit string [16-bit] data.

138

14
Standard Function Blocks

136 40 46 38 42 48 44

Converts double word [unsigned]/bit string DWORD_T [32-bit] data into double word [signed] O_DINT(_E) data. DWORD_T O_INT(_E) Converts double word [unsigned]/bit string [32-bit] data into word [signed] data.

99 97 107 103

BOOL_TO_ Converts bit data into double word [signed] DINT(_E) data. BOOL_TO_ Converts bit data into double DWORD(_E) [unsigned]/bit string [32-bit] data. word

DWORD_T Converts double word [unsigned]/bit string O_TIME(_E) [32-bit] data into time data. DWORD_T O_WORD (_E) E EQ_E EXPT(_E) F FIND(_E) Searches a character string. Compares data with regard to "= (equal)". (Number of pins variable) Obtains the raised result. Converts double word [unsigned]/bit string [32-bit] data into word [unsigned]/bit string [16-bit] data.

15
Operator

BOOL_TO_ Converts bit data into word [signed] data. INT(_E) BOOL_TO_ Converts bit data into string data. STR(_E) BOOL_TO_ Converts bit data into time data. TIME(_E) BOOL_TO_ Converts bit data into word [unsigned]/bit WORD(_E) string [16-bit] data. C CONCAT(_ E) COUNTER _FB_M CPY_BITA RR(_E) Connects character strings. (Number of pins variable) Counter drive Copies specified number of bits of a bit array.

203 169 225 240

A
Correspondence between Devices and Addresses

215 254 144 150 244 246 242

Detects the falling edge of a signal, and F_TRIG(_E) outputs pulse signal. G GE_E Compares data with regard to " (larger or equal)". (Number of pins variable)

B
Function/ Operator List

201 146 152 153 154 199

Copies a specified bit of word [signed] data CPY_BIT_ to a specified bit of another word [signed] OF_INT(_E) data. CTD(_E) CTUD(_E) CTU(_E) D DELETE(_E) Deletes a character string. DINT_TO_ BCD(_E) Converts double word [signed] data into BCD data. Counts down the number of times of rising of a signal. Counts up/down the number of times of rising of a signal. Counts up the number of times of rising of a signal.

GET_BIT_ Reads the value of a specified bit of word OF_INT(_E) [signed] data. GET_BOOL Outputs start data as bit data. _ADDR GET_INT_A Outputs start data as word [signed] data. DDR GET_WOR D_ADDR GT_E I Outputs start data as word [unsigned]/bit string [16-bit] data. Compares data with regard to "> (larger)". (Number of pins variable)

220 76 142 56 72

INSERT(_E) Inserts a character string. INT_TO_B CD(_E) INT_TO_BI TARR(_E) INT_TO_B OOL(_E) INT_TO_DI NT(_E) Converts word [signed] data into BCD data. Outputs low-order "n" bits of word [signed] data or word [unsigned]/bit string [16-bit] data to a bit array. Converts word [signed] data into bit data. Converts word [signed] data into double word [signed] data.

217 76 140 54 50

Outputs low-order "n" bits of double word DINT_TO_B [signed] data or double word [unsigned]/bit ITARR(_E) string [32-bit] data to a bit array. DINT_TO_ BOOL(_E) Converts double word [signed] data into bit data.

Converts double word [signed] data into DINT_TO_D double word [unsigned]/bit string [32-bit] WORD(_E) data.

283

FXCPU Structured Programming Manual [Application Functions]


Function name I INT_TO_D WORD(_E) INT_TO_R EAL(_E) Converts word [signed] data into double word [unsigned]/bit string [32-bit] data. Converts word [signed] data into float (single precision) data. 70 58 62 78 66 Ref. Page Function name S

Appendix B: Application Function List


Appendix B-2 [In alphabetic order]

Function

Function

Ref. Page

STR_TO_D Converts string data into double word INT(_E) [signed] data. STR_TO_I NT(_E) Converts string data into word [signed] data.

113 111 115 118 231 161

INT_TO_ST Converts word [signed] data into string R(_E) data. INT_TO_TI ME(_E) INT_TO_W ORD(_E) L LE_E LIMITATIO N(_E) LT_E M MAXIMUM (_E) MID(_E) MINIMUM (_E) MOD(_E) MOVE(_E) MUL_TIME (_E) MUL_E MUX(_E) N NE_E NOT(_E) O OR_E R REAL_TO_ DINT(_E) Converts float (single precision) data into double word [signed] data. Obtains the logical sum. (Number of pins variable) Compares data with regard to " (unequal)". Obtains the logical not. Searches the maximum value. (Number of pins variable) Obtains a character string from a specified position. Searches the minimum value. (Number of pins variable) Divides data (, and outputs the remainder). Transfers data. Multiplies time data. Multiplies data. (Number of pins variable) Selects data, and outputs it. (Number of pins variable) Compares data with regard to " (smaller or equal)". (Number of pins variable) Judges whether data is located within the range between the upper limit value and the lower limit value. Compares data with regard to "< (smaller)". (Number of pins variable) Converts word [signed] data into time data. Converts word [signed] data into word [unsigned]/bit string [16-bit] data.

STR_TO_R Converts string data into float (single EAL(_E) precision) data. STR_TO_TI Converts string data into time data. ME(_E) SUB_TIME (_E) SUB_E T TIME_TO_ BOOL(_E) TIME_TO_ DINT(_E) Converts time data into bit data. Converts time data into double word [signed] data. Subtracts time data. Subtracts data.

205 194 207

124 128 134 126 130 132 257 256 259 252 250 248

TIME_TO_D Converts time data into double word WORD(_E) [unsigned]/bit string [32-bit] data. TIME_TO_I Converts time data into word [signed] data. NT(_E) TIME_TO_ STR(_E) TIME_TO_ WORD(_E) Converts time data into string data. Converts time data into word [unsigned]/bit string [16-bit] data.

190 212 192 167 171 233 163 196

TIMER_CO Retentive timer drive NT_FB_M TIMER_10_ 10ms timer drive FB_M TIMER_100 100ms timer drive _FB_M TOF(_E) TON(_E) Turns OFF the output signal at specified time after the input signal turned OFF. Keeps OFF a signal during specified time duration. Keeps ON a signal during specified time duration.

209 185

TP(_E) W

181

WORD_TO Converts word [unsigned]/bit string [16-bit] _BOOL(_E) data into bit data. WORD_TO _DINT(_E) Converts word [unsigned]/bit string [16-bit] data into double word [signed] data. Converts word [unsigned]/bit string [16-bit] data into double word [unsigned]/bit string [32-bit]. Converts word [unsigned]/bit string [16-bit] data into word [signed] data. Converts word [unsigned]/bit string [16-bit] data into time data. Obtains the exclusive logical sum. (Number of pins variable)

89 95 101 93 105

84 82 86 222 238

REAL_TO_I Converts float (single precision) data into NT(_E) word [signed] data. REAL_TO_ STR(_E) REPLACE (_E) R_TRIG(_E) S SEL(_E) Selects data in accordance with the input condition. Converts float (single precision) data into string data. Replaces a character string. Detects the rising edge of a signal, and outputs pulse signal.

WORD_TO _DWORD (_E) WORD_TO _INT(_E) WORD_TO _TIME(_E) X XOR_E

183

188 148 174 176 109

SET_BIT_O Writes a value to a specified bit of word F_INT(_E) [signed] data. SHL(_E) SHR(_E) Shifts bits leftward. Shifts bits rightward.

STR_TO_B Converts string data into bit data. OOL(_E)

284

FXCPU Structured Programming Manual [Application Functions]


Operator
Operator name Symbol + * / ** & > >= = <= < <> A ADD AND D DIV E EQ G GE GT L LE LT M MOD MUL N NE NOT O OR S SUB X XOR Obtains the exclusive (Number of pins variable) logical sum. 269 Subtracts data. 262 Obtains the logical sum. (Number of pins variable) 268 Compares data (unequal)". with regard to " 277 271 Divides data (, and outputs the remainder). Multiplies data. (Number of pins variable) 265 263 Compares data with regard to " (smaller or equal)". (Number of pins variable) Compares data with regard to (smaller)". (Number of pins variable) "< 275 276 Compares data with regard to " (larger or equal)". (Number of pins variable) Compares data with regard to "> (larger)". (Number of pins variable) 273 272 Compares data with regard to "= (equal)". (Number of pins variable) 274 Divides data (, and outputs the quotient). 264 Adds data. (Number of pins variable) Obtains the logical product. (Number of pins variable) 261 267 Adds data. (Number of pins variable) Subtracts data. Multiplies data. (Number of pins variable) Divides data (, and outputs the quotient). Obtains the raised result. Obtains the logical product. (Number of pins variable) Compares data with regard to "> (larger)". (Number of pins variable) Compares data with regard to " (larger or equal)". (Number of pins variable) Compares data with regard to "= (equal)". (Number of pins variable) Compares data with regard to " (smaller or equal)". (Number of pins variable) Compares data with regard to (smaller)". (Number of pins variable) Compares data (unequal)". with regard to "< " 261 262 263 264 266 267 272 273 274 275 276 277 Function Ref. Page

Appendix B: Application Function List


Appendix B-2 [In alphabetic order]

11
Applied Functions (Standard Comparison Functions)

12
Applied Functions (Standard Character String Functions)

13
Applied Functions (Functions Of Time Data Types)

14
Standard Function Blocks

15
Operator

A
Correspondence between Devices and Addresses

B
Function/ Operator List

Obtains the logical not.

285

FXCPU Structured Programming Manual [Application Functions]

Appendix B: Application Function List


Appendix B-2 [In alphabetic order]

MEMO

286

FXCPU Structured Programming Manual [Application Functions]

Warranty

Warranty
Please confirm the following product warranty details before using this product.

1. Gratis Warranty Term and Gratis Warranty Range


If any faults or defects (hereinafter "Failure") found to be the responsibility of Mitsubishi occurs during use of the product within the gratis warranty term, the product shall be repaired at no cost via the sales representative or Mitsubishi Service Company. However, if repairs are required onsite at domestic or overseas location, expenses to send an engineer will be solely at the customer's discretion. Mitsubishi shall not be held responsible for any re-commissioning, maintenance, or testing on-site that involves replacement of the failed module.

[Gratis Warranty Term]


The gratis warranty term of the product shall be for one year after the date of purchase or delivery to a designated place. Note that after manufacture and shipment from Mitsubishi, the maximum distribution period shall be six (6) months, and the longest gratis warranty term after manufacturing shall be eighteen (18) months. The gratis warranty term of repair parts shall not exceed the gratis warranty term before repairs.

[Gratis Warranty Range]


1) 2) The range shall be limited to normal use within the usage state, usage methods and usage environment, etc., which follow the conditions and precautions, etc., given in the instruction manual, user's manual and caution labels on the product. Even within the gratis warranty term, repairs shall be charged for in the following cases. a) Failure occurring from inappropriate storage or handling, carelessness or negligence by the user. Failure caused by the user's hardware or software design. b) Failure caused by unapproved modifications, etc., to the product by the user. c) When the Mitsubishi product is assembled into a user's device, Failure that could have been avoided if functions or structures, judged as necessary in the legal safety measures the user's device is subject to or as necessary by industry standards, had been provided. d) Failure that could have been avoided if consumable parts (battery, backlight, fuse, etc.) designated in the instruction manual had been correctly serviced or replaced. e) Relay failure or output contact failure caused by usage beyond the specified Life of contact (cycles). f) Failure caused by external irresistible forces such as fires or abnormal voltages, and failure caused by force majeure such as earthquakes, lightning, wind and water damage. g) Failure caused by reasons unpredictable by scientific technology standards at time of shipment from Mitsubishi. h) Any other failure found not to be the responsibility of Mitsubishi or that admitted not to be so by the user. Mitsubishi shall accept onerous product repairs for seven (7) years after production of the product is discontinued. Discontinuation of production shall be notified with Mitsubishi Technical Bulletins, etc. Product supply (including repair parts) is not available after production is discontinued.

2. Onerous repair term after discontinuation of production


1) 2)

3. Overseas service
Overseas, repairs shall be accepted by Mitsubishi's local overseas FA Center. Note that the repair conditions at each FA Center may differ.

4. Exclusion of loss in opportunity and secondary loss from warranty liability


Regardless of the gratis warranty term, Mitsubishi shall not be liable for compensation of damages caused by any cause found not to be the responsibility of Mitsubishi, loss in opportunity, lost profits incurred to the user or third person by Failures of Mitsubishi products, special damages and secondary damages whether foreseeable or not , compensation for accidents, and compensation for damages to products other than Mitsubishi products, replacement by the user, maintenance of on-site equipment, start-up test run and other tasks.

5. Changes in product specifications


The specifications given in the catalogs, manuals or technical documents are subject to change without prior notice.

6. Product application
1) In using the Mitsubishi MELSEC programmable logic controller, the usage conditions shall be that the application will not lead to a major accident even if any problem or fault should occur in the programmable logic controller device, and that backup and failsafe functions are systematically provided outside of the device for any problem or fault. The Mitsubishi programmable logic controller has been designed and manufactured for applications in general industries, etc. Thus, applications in which the public could be affected such as in nuclear power plants and other power plants operated by respective power companies, and applications in which a special quality assurance system is required, such as for Railway companies or Public service purposes shall be excluded from the programmable logic controller applications. In addition, applications in which human life or property that could be greatly affected, such as in aircraft, medical applications, incineration and fuel devices, manned transportation, equipment for recreation and amusement, and safety devices, shall also be excluded from the programmable logic controller range of applications. However, in certain cases, some applications may be possible, providing the user consults their local Mitsubishi representative outlining the special requirements of the project, and providing that all parties concerned agree to the special circumstances, solely at the users discretion.

2)

287

FXCPU Structured Programming Manual [Application Functions]

Revision History

Revision History
Date of preparation 1/2009 7/2009 Revision A B First Edition. Equivalent circuits are deleted. Following instructions are not supported in FX0,FX0S and FX0N PLCs. CTD(_E), CTU(_E), CTUD(_E), TOF(_E), TON(_E), TP(_E) Function blocks (SR(_E), RS(_E)) are deleted. Manual name of a related manual was changed. Operators are added. Following functions are added. BITARR_TO_INT(_E), BITARR_TO_DINT(_E), INT_TO_BITARR(_E), DINT_TO_BITARR(_E), CPY_BITARR(_E), GET_BIT_OF_INT(_E), SET_BIT_OF_INT(_E), CPY_BIT_OF_INT(_E), GET_BOOL_ADDR, GET_INT_ADDR and GET_WORD_ADDR Appendix B is added. FBD language is added. FX3GC is added. The reset method of the counter value and timer value of a function block (COUNTER_FB_M, TIMER_CONT_FB_M) is added. Description

2/2010 9/2010

C D

7/2011 2/2012 5/2012

E F G

288

FXCPU Structured Programming Manual Application Functions

HEAD OFFICE: TOKYO BUILDING, 2-7-3 MARUNOUCHI, CHIYODA-KU, TOKYO 100-8310, JAPAN HIMEJI WORKS: 840, CHIYODA CHO, HIMEJI, JAPAN

MODEL MODEL CODE

FX-KP-OK-E

09R927

JY997D34801G (MEE)

Effective May 2012 Specifications are subject to change without notice.

Anda mungkin juga menyukai