Mitsubishi Melsec-Q, Q-KP-OK-E, 13JW08 Programming Manual

QCPU
Structured Programming Manual
(Application Functions)
Mitsubishi Programmable Controller
(Always read these instructions before using this product.)
Before using the MELSEC-Q series programmable controller, thoroughly read the manuals attached to the products and the relevant manuals introduced in the attached manuals. Also pay careful attention to safety and handle the products properly.
Please keep this manual in a place where it is accessible when required and always forward it to the end user.
A-1

REVISIONS

The manual number is written at the bottom left of the back cover.
Print date Manual number Revision
Jul., 2008 SH(NA)-080784ENG-A First edition
Japanese manual version SH-080737-B
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.
© 2008 MITSUBISHI ELECTRIC CORPORATION
A-2

INTRODUCTION

Thank you for purchasing the Mitsubishi MELSEC-Q series programmable controller. Before using the product, thoroughly read this manual to develop full familiarity with the programming specifications to ensure correct use. Please forward this manual to the end user.

CONTENTS

SAFETY PRECAUTIONS ................................................................................................................................A - 1
REVISIONS....................................................................................................................................................... A - 2
INTRODUCTION............................................................................................................................................... A - 3
CONTENTS ...................................................................................................................................................... A - 3
MANUALS......................................................................................................................................................... A - 6
1. OVERVIEW 1 - 1 to 1 - 4
1.1 Purpose of This Manual 1 - 2
1.2 Generic Terms and Abbreviations in This Manual 1 - 4
2. FUNCTION TABLES 2 - 1 to 2 - 6
2.1 How to Read Function Tables 2 - 2
2.1.1 Type conversion functions ............................................................................................................. 2 - 3
2.1.2 Standard functions of one numeric variable .................................................................................. 2 - 4
2.1.3 Standard arithmetic functions ........................................................................................................ 2 - 4
2.1.4 Standard bitwise Boolean functions............................................................................................... 2 - 4
2.1.5 Standard selection functions.......................................................................................................... 2 - 5
2.1.6 Standard comparison functions ..................................................................................................... 2 - 5
2.1.7 Standard character string functions ............................................................................................... 2 - 5
2.1.8 Functions of time data types .......................................................................................................... 2 - 5
2.1.9 Standard bistable function blocks .................................................................................................. 2 - 5
2.1.10 Standard edge detection function blocks ....................................................................................... 2 - 6
2.1.11 Standard counter function blocks .................................................................................................. 2 - 6
2.1.12 Standard timer function blocks ...................................................................................................... 2 - 6
3. FUNCTIONS 3 - 1 to 3 - 12
3.1 Input Pins Variable Function 3 - 2
3.2 Functions with EN 3 - 3
3.3 Labels 3 - 4
3.3.1 Global labels .................................................................................................................................. 3 - 4
3.3.2 Local labels.................................................................................................................................... 3 - 4
3.3.3 Label classes ................................................................................................................................. 3 - 4
3.3.4 Setting labels ................................................................................................................................. 3 - 5
3.4 Data Types 3 - 6
3.5 Device and Address 3 - 8
3.5.1 Device ........................................................................................................................................... 3 - 8
3.5.2 Address.......................................................................................................................................... 3 - 8
3.6 Expressing Methods of Constants 3 - 10
3.7 Precautions on Programming 3 - 10
A-3
3.7.1 Precautions on assigning a name................................................................................................ 3 - 10
4. HOW TO READ FUNCTIONS 4 - 1 to 4 - 4
5. APPLICATION FUNCTIONS 5 - 1 to 5 - 218
5.1 Type Conversion Functions 5 - 2
5.1.1 Bit type word (signed), double word (signed) type conversion.................................................. 5 - 2
5.1.2 Bit type string type conversion .................................................................................................. 5 - 5
5.1.3
5.1.4 Bit type time type conversion .................................................................................................. 5 - 10
5.1.5 Word (signed) type double word (signed) type conversion ..................................................... 5 - 13
5.1.6 Double word (signed) type → word (signed) type conversion ..................................................... 5 - 16
5.1.7 Word (signed), double word (signed) type bit type conversion ............................................... 5 - 19
5.1.8 Word (signed), double word (signed) type single-precision real type conversion ................... 5 - 23
5.1.9 Word (signed), double word (signed) type double-precision real type conversion.................. 5 - 26
5.1.10 Word (signed), double word (signed) type string type conversion .......................................... 5 - 29
5.1.11
5.1.12
5.1.13 Word (signed), double word (signed) type BCD type conversion............................................ 5 - 39
5.1.14 Word (signed), double word (signed) type time type conversion ............................................ 5 - 42
5.1.15 Single-precision real type word (signed), double word (signed) type conversion ................... 5 - 45
5.1.16 Double-precision real type word (signed), double word (signed) type conversion .................. 5 - 48
5.1.17 Single-precision real type double-precision real type conversion ........................................... 5 - 51
5.1.18 Double-precision real type single-precision real type conversion ........................................... 5 - 54
5.1.19 Single-precision real type string type conversion .................................................................... 5 - 57
5.1.20
5.1.21
5.1.22
5.1.23
5.1.24
5.1.25
5.1.26
5.1.27 String type bit type conversion ................................................................................................ 5 - 82
5.1.28 String type word (signed), double word (signed) type conversion........................................... 5 - 85
5.1.29 String type single-precision real type conversion .................................................................... 5 - 88
5.1.30
5.1.31 String type time type conversion ............................................................................................. 5 - 95
5.1.32 String type BCD type conversion ............................................................................................ 5 - 98
5.1.33
5.1.34 BCD type string type conversion........................................................................................... 5 - 104
5.1.35 Time type bit type conversion ............................................................................................... 5 - 107
5.1.36 Time type word (signed), double word (signed) type conversion .......................................... 5 - 110
5.1.37 Time type string type conversion .......................................................................................... 5 - 113
5.1.38
Bit type → word (unsigned)/16-bit string, double word (unsigned)/32-bit string type conversion
Word (signed), double word (signed) type → word (unsigned)/16-bit string type conversion Word (signed), double word (signed) type
Word (unsigned)/16-bit string, double word (unsigned)/32-bit string type → bit type conversion Word (unsigned)/16-bit string type → word (signed), double word (signed) type conversion Double word (unsigned)/32-bit string type → word (signed), double word (signed) type conversion Word (unsigned)/16-bit string type → double word (unsigned)/32-bit string type conversion Double word (unsigned)/32-bit string type → word (unsigned)/16-bit string type conversion Word (unsigned)/16-bit string, double word (unsigned)/32-bit string type → string type conversion Word (unsigned)/16-bit string, double word (unsigned)/32-bit string type → time type conversion
String type → word (unsigned)/16-bit string, double word (unsigned)/32-bit string type conversion
BCD type → word (signed), double word (signed) type conversion
Time type → word (unsigned)/16-bit string, double word (unsigned)/32-bit string type conversion
double word (unsigned)/32-bit string type conversion
.................................................... 5 - 101
........................ 5 - 7
........................ 5 - 36
...................... 5 - 61
........................ 5 - 67
......................... 5 - 76
........................... 5 - 79
......................... 5 - 92
........................ 5 - 116
.................... 5 - 33
.................... 5 - 64
.................... 5 - 70
.................... 5 - 73
5.2 Standard Functions of One Numeric Variable 5 - 119
5.2.1 Absolute value ........................................................................................................................... 5 - 119
5.3 Standard Arithmetic Functions 5 - 122
5.3.1 Addition ...................................................................................................................................... 5 - 122
5.3.2 Multiplication .............................................................................................................................. 5 - 125
5.3.3 Subtraction................................................................................................................................. 5 - 128
5.3.4 Division ...................................................................................................................................... 5 - 131
A-4
5.3.5 Modulus operation ..................................................................................................................... 5 - 134
5.3.6 Exponentiation ........................................................................................................................... 5 - 137
5.3.7 Move operation .......................................................................................................................... 5 - 140
5.4 Standard Bitwise Boolean Functions 5 - 143
5.4.1 Boolean AND, boolean OR, boolean exclusive OR, and boolean NOT .................................... 5 - 143
5.5 Standard Selection Functions 5 - 148
5.5.1 Selection .................................................................................................................................... 5 - 148
5.5.2 Multiplexer ................................................................................................................................. 5 - 151
5.6 Standard Comparison Functions 5 - 154
5.6.1 Comparison ............................................................................................................................... 5 - 154
5.7 Standard Character String Functions 5 - 157
5.7.1 Extract mid string ....................................................................................................................... 5 - 157
5.7.2 String concatenation .................................................................................................................. 5 - 160
5.7.3 String insertion........................................................................................................................... 5 - 163
5.7.4 String deletion............................................................................................................................ 5 - 166
5.7.5 String replacement .................................................................................................................... 5 - 169
5.8 Functions of Time Data Type 5 - 172
5.8.1 Addition...................................................................................................................................... 5 - 172
5.8.2 Subtraction................................................................................................................................. 5 - 175
5.8.3 Multiplication .............................................................................................................................. 5 - 178
5.8.4 Division ...................................................................................................................................... 5 - 181
5.9 Standard Bistable Function Blocks 5 - 184
5.9.1 Standard bistable function blocks (Set-dominant) ..................................................................... 5 - 184
5.9.2 Standard bistable function blocks (Reset-dominant) ................................................................. 5 - 187
5.10 Standard Edge Detection Function Blocks 5 - 190
5.10.1 Rising edge detector.................................................................................................................. 5 - 190
5.10.2 Falling edge detector ................................................................................................................. 5 - 192
5.11 Standard Counter Function Blocks 5 - 194
5.11.1 Up counter ................................................................................................................................. 5 - 194
5.11.2 Down counter............................................................................................................................. 5 - 197
5.11.3 Up/Down counter ....................................................................................................................... 5 - 200
5.11.4 Counter function blocks ............................................................................................................. 5 - 203
5.12 Standard Timer Function Blocks 5 - 205
5.12.1 Pulse timer................................................................................................................................. 5 - 205
5.12.2 On delay timer ........................................................................................................................... 5 - 208
5.12.3 Off delay timer ........................................................................................................................... 5 - 211
5.12.4 Timer function blocks................................................................................................................. 5 - 214
APPENDIX App - 1 to App - 8
Appendix 1 Correspondence between Generic Data Types and Devices App - 2
Appendix 2 Correspondence between Devices and Addresses App - 6
INDEX Index - 1 to Index - 4
A-5

MANUALS

Related manuals
The manuals related to this product are shown below.
Refer to the following tables when ordering required manuals.
(1) Structured programming
Manual name
QCPU Structured Programming Manual (Fundamentals)
Explains the programming method, types of programming languages, and other information required to create structured
programs.
(Sold separately)
QCPU Structured Programming Manual (Common Instructions)
Explains the specifications and functions of sequence instructions, basic instructions, and application instructions that can be
used in structured programs.
(Sold separately)
QCPU Structured Programming Manual (Special Instructions)
Explains the specifications and functions of instructions for network modules, intelligent function modules, and PID control
functions that can be used in structured programs.
(Sold separately)
(2) Operation of GX Works2
Manual name
GX Works2 Version1 Operating Manual (Common)
Explains the system configuration of GX Works2 and the functions common to a Simple project and Structured project such as
parameter setting, operation method for the online function.
(Sold separately)
GX Works2 Version1 Operating Manual (Structured Project)
Explains operation methods such as creating and monitoring programs in Structured project of GX Works2.
(Sold separately)
GX Works2 Beginner's Manual (Structured Project)
Explains fundamental operation methods such as creating, editing, and monitoring programs in Structured project for users
inexperienced with GX Works2.
(Sold separately)
Manual number
(Model code)
SH-080782ENG
(13JW06)
SH-080783ENG
(13JW07)
SH-080785ENG
(13JW09)
Manual number
(Model code)
SH-080779ENG
(13JU63)
SH-080781ENG
(13JU65)
SH-080788ENG
(13JZ23)
A-6
The Operating Manual is included in the CD-ROM with the software package. Manuals in printed form are sold separately. Order a manual by quoting the manual number (model code) listed in the table above.
1

OVERVIEW

1
OVERVIEW
2
FUNCTION TABLES
3
1.1 Purpose of This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-2
1.2 Generic Terms and Abbreviations in This Manual . . . . . . . . . . . . . . . . . . . . . . 1-4
FUNCTIONS
4
HOW TO READ
FUNCTIONS
5
APPLICATION
FUNCTIONS
A
APPENDIX
I
1-1
INDEX
1.1 Purpose of This Manual
This manual explains the application functions used for creating structured programs.
Manuals for reference are listed in the following table according to their purpose.
For information such as the contents and number of each manual, refer to the list of 'Related manuals'.
(1) Operation of GX Works2
Purpose
Installation
Operation of Simple project
Learning the operating environment and installation method
Learning the basic operations and operating procedures
Learning the functions and operation methods for programming
Learning all functions and operation methods except for programming
Learning the basic operations and operating procedures
GX Works2 Installation
Instructions
Details
GX Works2
Beginner's Manual
Simple Project
Details
Structured
Project
Details
GX Works2 Version1
Operating Manual
Common
Outline Outline
Outline
Details
Outline Outline
Simple
Project
Details
Structured
Project
Operation of Structured project
1-2
Learning the functions and operation methods for programming
Learning all functions and operation methods except for programming

1.1 Purpose of This Manual

Outline
Details Details
Details
Purpose
(2) Programming
QCPU Structured Programming Manual
QCPU(Q mode)/QnACPU
Programming Manual
User's Manual for
intelligent function
module/
Reference Manual
for network module
1
OVERVIEW
Programming in Simple project
Learning the types and details of common instructions, descriptions of error codes, special relays, and special registers
Learning the types and details of instructions for intelligent function modules
Learning the types and details of instructions for network modules
Learning the types and details of instructions for the PID control function
Learning the fundamentals for creating a structured program for the first time
Learning the types and details of common instructions
Fundamentals
Details
Common
Instructions
Details
Special
Instructions
Application
Functions
Common
Instructions
Details
PID Control
Instructions
Details
Details
Details
Programming in Structured project
Learning the types and details of instructions for intelligent function modules
Learning the types and details of instructions for network modules
Learning the types and details of instructions for the PID control function
Learning the descriptions of error codes, special relays, and special registers
Learning the types and details of application functions
Details Details
Details Details
Details Details
Details
Details
1.1 Purpose of This Manual
1-3
1.2 Generic Terms and Abbreviations in This Manual
This manual uses the generic terms and abbreviations listed in the following table to discuss the software packages and programmable controller CPUs. Corresponding module models are also listed if needed.
Generic term and
abbreviation
GX Works2 Generic product name for the SWnDNC-GXW2-E (n: version)
CPU module Generic term for the High Performance model QCPU and Universal model QCPU
High Performance model
QCPU
Universal model QCPU
Personal computer
IEC61131-3 Abbreviation for the IEC 61131-3 international standard
Common instruction Generic term for the sequence instructions, basic instructions, and application instructions
Special instruction Generic term for the PID control instructions and module dedicated instructions
Generic term for the Q02, Q02H, Q06H, Q12H, and Q25H
Generic term for the Q02U, Q03UD, Q03UDE, Q04UDH, Q04UDEH, Q06UDH, Q06UDEH, Q13UDH,
Q13UDEH, Q26UDH, and Q26UDEH
Generic term for personal computer on which Windows® operates
Description
1-4

1.2 Generic Terms and Abbreviations in This Manual

2

FUNCTION TABLES

1
OVERVIEW
2
FUNCTION TABLES
3
2.1 How to Read Function Tables. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-2
FUNCTIONS
4
HOW TO READ
FUNCTIONS
5
APPLICATION
FUNCTIONS
A
APPENDIX
I
2-1
INDEX
2.1 How to Read Function Tables
Function name Argument Processing details Page
s1 s2 s8 d
ADD(_E)
MUL(_E)
SUB(_E)
DIV(_E)
Description
..........Indicates the functions used in a program. 'Function name(_E)' is used as a function
with EN.
..........Indicates the arguments of the function.
, ,... ,
(Number of pins
variable)
s1 s2 s8 d
, ,... ,
(Number of pins
variable)
s1 s2 d s1 s2
, , Outputs the difference ( ) between input values.
s1 s2 d s1 s2
, , Outputs the quotient ( ) of input values.
Outputs the sum ( + +···+ ) of input values.
Outputs the product ( ··· ) of input values.
s1 s2 s8
s1 s2 s8
÷
5-139
5-142
5-145
5-148
s
: Source ......................................Stores data before operation.
d
: Destination................................ Indicates the destination of data after operation.
(Number of pins variable) ...............Allows the number of (source) to be changed in
s
the range from 2 to 8.
Changing the number of pins
Adding a pin
Deleting a pin
..........Indicates the processing details of each function.
..........Indicates the pages on which the functions are explained.
2-2

2.1 How to Read Function Tables

2.1.1 Type conversion functions
Function name Argument Processing details Page
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_LREAL(_E)
DINT_TO_LREAL(_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)
LREAL_TO_INT(_E)
LREAL_TO_DINT(_E)
REAL_TO_LREAL(_E)
LREAL_TO_REAL(_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_STR(_E)
DWORD_TO_STR(_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)
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
Converts bit type data into word (signed) or double word (signed) type
data.
Converts bit type data into string type data.
Converts bit type data into word (unsigned)/16-bit string or double
word (unsigned)/32-bit string type date.
Converts bit type data into time type data.
Converts word (signed) type data into double word (signed) type data.
Converts double word (signed) type data into word (signed) type data.
Converts word (signed) or double word (signed) type data into bit type
data.
Converts word (signed) or double word (signed) type data into single-
precision real type data.
Converts word (signed) or double word (signed) type data into double-
precision real type data.
Converts word (signed) or double word (signed) type data into string
type data.
Converts word (signed) or double word (signed) type data into word
(unsigned)/16-bit string type data.
Converts word (signed) or double word (signed) type data into double
word (unsigned)/32-bit string type data.
Converts word (signed) or double word (signed) type data into BCD
type data.
Converts word (signed) type data into time type data.
Converts single-precision real type data into word (signed) or double
word (signed) type data.
Converts double-precision real type data into word (signed) or double
word (signed) type data.
Converts single-precision real type data into double-precision real
type data.
Converts double-precision real type data into single-precision real
type data.
Converts single-precision real type data into string type (exponent
form) data.
Converts word (unsigned)/16-bit string or double word (unsigned)/32-
bit string type data into bit type data.
Converts word (unsigned)/16-bit string type data into word (signed) or
double word (signed) type data.
Converts double word (unsigned)/32-bit string type data into word
(signed) or double word (signed) type data.
Converts word (unsigned)/16-bit string type data into double word
(unsigned)/32-bit string type data.
Converts double word (unsigned)/32-bit string type data into word
(unsigned)/16-bit string type data.
Converts word (unsigned)/16-bit string or double word (unsigned)/32-
bit string type data into string type data.
Converts word (unsigned)/16-bit string or double word (unsigned)/32-
bit string type data into time type data.
Converts string type data into bit type data.
Converts string type data into word (signed) or double word (signed)
type data.
Converts string type data into single-precision real type data.
5-2
5-2
5-5
5-7
5-7
5-10
5-13
5-16
5-19
5-19
5-23
5-23
5-26
5-26
5-29
5-29
5-33
5-33
5-36
5-36
5-39
5-39
5-42
5-42
5-45
5-45
5-48
5-48
5-51
5-54
5-57
5-61
5-61
5-64
5-64
5-67
5-67
5-70
5-73
5-76
5-76
5-79
5-79
5-82
5-85
5-85
5-88
2
FUNCTION TABLES
2.1 How to Read Function Tables

2.1.1 Type conversion functions

2-3
Function name Argument Processing details Page
STR_TO_WORD(_E)
STR_TO_DWORD(_E)
STR_TO_TIME(_E)
STR_TO_BCD(_E)
BCD_TO_INT(_E)
BCD_TO_DINT(_E)
BCD_TO_STR(_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)
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
s d
,
Converts string type data into word (unsigned)/16-bit string or double
word (unsigned)/32-bit string type data.
Converts string type data into time type data.
Converts string type data into BCD type data.
Converts BCD type data into word (signed) or double word (signed)
type data.
Converts BCD type data into string type data.
Converts time type data into bit type data.
Converts time type data into word (signed) or double word (signed)
type data.
Converts time type data into string type data.
Converts time type data into word (unsigned)/16-bit string or double
word (unsigned)/32-bit string type data.
2.1.2 Standard functions of one numeric variable
Function name Argument Processing details Page
ABS(_E)
s d
,
Outputs the absolute value of an input value.

2.1.3 Standard arithmetic functions

5-92
5-92
5-95
5-98
5-101
5-101
5-104
5-107
5-110
5-110
5-113
5-116
5-116
5-119
Function name Argument Processing details Page
s1 s2 s8 d
, ,... ,
ADD(_E)
(Number of pins
Outputs the sum ( + +···+ ) of input values.
s1 s2 s8
variable)
s1 s2 s8 d
, ,... ,
MUL(_E)
(Number of pins
Outputs the product ( ··· ) of input values.
s1 s2 s8
variable)
SUB(_E)
DIV(_E)
MOD(_E)
EXPT(_E)
MOVE(_E)
s1 s2 d s1 s2
, , Outputs the difference ( ) between input values.
s1 s2 d s1 s2
, , Outputs the quotient ( ÷ ) of input values.
s1 s2 d s1 s2
, , Outputs the remainder after division of input values ( ÷ ).
s1 s2 d
, ,
s1 s2 s8 d
, ,... ,
(Number of pins
Outputs the exponentiation of an input value.
Outputs the substitution of an input value.
variable)

2.1.4 Standard bitwise Boolean functions

Function name Argument Processing details Page
s1 s2 s8 d
, ,... ,
AND(_E)
OR(_E)
XOR(_E)
NOT(_E)
(Number of pins
variable)
s1 s2 s8 d
, ,... ,
(Number of pins
variable)
s1 s2 s8 d
, ,... ,
(Number of pins
variable)
s d
,
Outputs the Boolean AND of input values.
Outputs the Boolean OR of input values.
Outputs the Boolean exclusive OR of input values.
Outputs the Boolean NOT of input values.
5-122
5-125
5-128
5-131
5-134
5-137
5-140
5-143
5-143
5-143
5-143
2-4
2.1 How to Read Function Tables

2.1.2 Standard functions of one numeric variable

2.1.5 Standard selection functions
Function name Argument Processing details Page
SEL(_E)
MUX(_E)
s1 s2 s3 d
, , ,
s1 s2 s8 d
,,...,
(Number of pins
variable)
Outputs the value selected from the input values.
Outputs one of the multiple input values.

2.1.6 Standard comparison functions

Function name Argument Processing details Page
s1 s2 s8 d
,,...,
GT( _E)
GE(_E)
EQ(_E)
LE(_E)
LT( _E)
NE(_E)
(Number of pins
variable)
s1 s2 s8 d
,,...,
(Number of pins
variable)
s1 s2 s8 d
,,...,
(Number of pins
variable)
s1 s2 s8 d
,,...,
(Number of pins
variable)
s1 s2 s8 d
,,...,
(Number of pins
variable)
s1 s2 d
, ,
Outputs the comparison value of an input value.
5-148
5-151
2
FUNCTION TABLES
5-154
5-154
5-154
5-154
5-154
5-154

2.1.7 Standard character string functions

Function name Argument Processing details Page
MID(_E)
CONCAT(_E)
INSERT(_E)
DELETE(_E)
REPLACE(_E)
s1 s2 s3 d
, , ,
s1 s2 d
, ,
s1 s2 s3 d
, , ,
s1 s2 s3 d
, , ,
s1 s2 s3 s4 d
, , , ,
Outputs the specified number of characters, extracted from the
specified start position in the input character string.
Concatenates two character strings and outputs the operation result.
Inserts a character string between other character strings and outputs
the operation result.
Deletes the specified range in a character string and outputs the
operation result.
Replaces the specified range in a character string with the specified
character string and outputs the operation result.

2.1.8 Functions of time data types

Function name Argument Processing details Page
ADD_TIME(_E)
SUB_TIME(_E)
s1 s2 d s1 s2
, , Outputs the sum ( + ) of the input values (time type).
s1 s2 d s1 s2
, , Outputs the difference ( - ) of input values (time type).

2.1.9 Standard bistable function blocks

Function name Argument Processing details Page
SR(_E)
RS(_E)
s1 s2 d
, ,
s1 s2 d
, ,
Discriminates two input values and outputs 1 (TRUE) or 0 (FALSE).
Discriminates two input values and outputs 1 (TRUE) or 0 (FALSE).
5-157
5-160
5-163
5-166
5-169
5-172
5-175
5-184
5-187
2.1 How to Read Function Tables

2.1.5 Standard selection functions

2-5
2.1.10 Standard edge detection function blocks
Function name Argument Processing details Page
RTRIG(_E)
F_TRIG(_E)
s1 d
,
s1 d
,
Detects the rising edge of a signal and outputs pulse signals.
Detects the falling edge of a signal and outputs pulse signals.

2.1.11 Standard counter function blocks

Function name Argument Processing details Page
CTU(_E)
CTD(_E)
CTUD(_E)
COUNTER_FB_M
s1 s2 s3 d1 d2
, , , ,
s1 s2 s3 d1 d2
, , , ,
s1 s2 s3 s4
, , ,
s5 d1 d2 d3
, , ,
s1 s2 s3 d1 d2 s3 s2
, , , , Counts the number of times that the signal turns ON from to .
Counts the number of times that the signal turns ON.
Counts down the number of times that the signal turns ON.
Counts/counts down the number of times that the signal turns ON.

2.1.12 Standard timer function blocks

Function name Argument Processing details Page
TP(_E)
TP_HIGH(_E)
TON(_E)
TON_HIGH(_E)
TOF(_E)
TOF_HIGH(_E)
TIMER_10_FB_M
TIMER_100_FB_M
TIMER_HIGH_FB_M
TIMER_LOW_FB_M
TIMER_CONT_FB_M TIMER_CONTHFB_M
s1 s2 d1 d2
, , ,
s1 s2 s3 d1 d2
, , , ,
s1 s2 s3 s4
, , ,
s5 d1 d2 d3
, , ,
s1 s2 s3 d1 d2
, , , ,
Holds the signal ON for the specified time.
Turns ON the signal after the specified time.
Turns OFF the signal after the specified time.
Turns ON the signal after the specified time counted from input value
s3 s2
to .
5-190
5-192
5-194
5-197
5-200
5-203
5-205
5-208
5-211
5-214
2-6
2.1 How to Read Function Tables

2.1.10 Standard edge detection function blocks

3

FUNCTIONS

1
OVERVIEW
2
FUNCTION TABLES
3
3.1 Input Pins Variable Function. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-2
3.2 Functions with EN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3
3.3 Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4
3.4 Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-6
3.5 Device and Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-8
3.6 Expressing Methods of Constants . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
3.7 Precautions on Programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-10
FUNCTIONS
4
HOW TO READ
FUNCTIONS
5
APPLICATION
FUNCTIONS
A
APPENDIX
I
3-1
INDEX
3.1 Input Pins Variable Function
Some functions allow the number of input pins to be changed.
To change the number of input pins, select the target function and change the number.
For the number of input pins change operation GX Works2 Version1 Operating Manual (Structured Project)
Adding a pin
Deleting a pin
3-2

3.1 Input Pins Variable Function

3.2 Functions with EN
The function has two types: ordinary functions and functions with EN that have EN/ENO pins.
Functions with EN allow control of function execution.
EN inputs the condition for executing a function.
ENO outputs execution status.
The following table shows the status of EN and ENO and the operation result according to the status of EN.
Table 3.2-1 Status of EN and ENO and the operation result according
to the status of EN
EN ENO Operation result
TRUE (Operation execution)
FALSE (Operation stop) FALSE Undefined value
Functions with EN are expressed as 'Function name_E'.
TRUE (No operation error) Operation output value
FALSE (Operation error) Undefined value
3
FUNCTIONS
Examples of use of EN and ENO
No. Control description
When the EN input is directly connected from the left base line, the EN input is always TRUE and the function is
always executed. If the ADD_E function is used in this manner, the operation result is the same as the ADD function without the EN input.
When Variable_1 is connected to the EN input, the function is executed when Variable_1 is TRUE.
When the result of Boolean operation is connected to the EN input, the function is executed when the result is TRUE.
When the ENO outputs are connected to the EN inputs, three functions are executed when Variable_1 is TRUE.
When the ENO outputs are not connected, the execution status of the function is not output.

3.2 Functions with EN

3-3
3.3 Labels
Labels include global labels and local labels.
3.3.1 Global labels
The global labels are labels that can be used in program blocks and function blocks.
In the setting of a global label, a label name, a class, a data type, and a device are associated with each other.

3.3.2 Local labels

The local labels are labels that can be used only in declared POUs. They are individually defined per POU.
In the setting of a local label, a label name, a class, and a data type are set.
For the local labels, the user does not need to specify devices. Devices are assigned automatically at compilation.

3.3.3 Label classes

The label class indicates from which POU and how a label can be used. Different classes can be selected according to the type of POU.
The following table shows label classes.
Table 3.3.3-1 Label classes
Class Description
VAR_GLOBAL
VAR_GLOBAL_CONSTANT
VAR
VAR_CONSTANT
VAR_RETAIN
VAR _INP UT
VAR_OUTPUT Label that outputs a value from a function block
VAR_IN_OUT
Common label that can be used in program blocks and
function blocks
Common constant that can be used in program blocks
and function blocks
Label that can be used within the range of declared
POUs
This label cannot be used in other POUs.
Constant that can be used within the range of declared
POUs
This constant cannot be used in other POUs.
Latch type label that can be used within the range of
declared POUs
This label cannot be used in other POUs.
Label that receives a value
This label cannot be changed in a POU.
Local label that receives a value and outputs the value
from a POU
This label can be changed in a POU.
Program
block
Applicable POU
Function
Function
block
3-4

3.3 Labels

3.3.1 Global labels

3.3.4 Setting labels
Labels used in a program require setting of either global label or local label.
The following describes setting examples of the arguments g_bool1 and g_int1 of the BOOL_TO_INT_E function.
Using the arguments of the BOOL_TO_INT_E function as global labels Set the Class, Label Name, Data Type, Device, and Address.
Using the arguments of the BOOL_TO_INT_E function as local labels Set the Class, Label Name, and Data Type.
3
FUNCTIONS
3.3 Labels

3.3.4 Setting labels

3-5
3.4 Data Types
Data types of labels include the elementary data types and the generic data types.
Generic data type is the data type of labels covering some elementary data types. The data type name starts with 'ANY'.
The following shows the list of elementary data types and generic data types.
Data type Description Value r ang e Bit length
Bit Bool
Word
(signed)
Double word
(signed)
Word
(unsigned)/
16-bit string
Double word
(unsigned)/
32-bit string
Single-
precision
real
Double-
precision
*1
real
String Character string
*2
Time
Double-precision
16-bit string
32-bit string
Double-precision
Time value
Integer
integer
Real
real
Table 3.4-1 Elementary data types
0(FALSE), 1(TRUE)
-32768 to 32767
-2147483648 to 2147483647
0 to 65535
0 to 4294967295
128
-126
-126
-2
to -2
, 0, 2
1024
-2
Maximum 255 characters
T#-24d-0h31m23s648ms to T#24d20h31m23s647ms
to -2
-1022
, 0, 2
to 2
-1022
128
to 2
1024
1 bit
16 bits
32 bits
16 bits
32 bits
32 bits
64 bits
Variable
32 bits
*1 Can be used for the Universal model QCPU only. *2 The time type is used in time type operation instructions of application function.
3-6

3.4 Data Types

Generic data types
ANY
ANY_NUM
ANY_REAL ANY_INT
Single-precision
real
Double-precision
real
ANY16
Word
(unsigned)/
16-bit string
*3 For details QCPU Structured Programming Manual (Common Instructions)
Word
(signed)
Double word
(signed)
Word
(signed)
ANY_SIMPLE
ANY_BIT
Bit
Word
(unsigned)/
16-bit string Double word
(unsigned)/
32-bit string
ANY32
Double word
(unsigned)/
32-bit string
Time String
The higher 'ANY' data types include sub-level data types. The highest 'ANY' data type includes all data types.
Double word
(signed)
*3 *3
Array Structure
3
FUNCTIONS
For data specification method, refer to the following manual.
QCPU Structured Programming Manual (Common Instructions)
For the format of devices that correspond to generic data types, refer to the following section.
Appendix 1 Correspondence between Generic Data Types and Devices
3.4 Data Types
3-7
3.5 Device and Address
r
r
This section explains the method for expressing programmable controller CPU devices. The following two types of format are available.
• Device: This format consists of a device name and a device number.
• Address: A format defined in IEC61131-3. In this format, a device name starts with %.
3.5.1 Device
Device is a format that uses a device name and a device number.
For details of devices used in the QCPU, refer to the following manual.
QCPU User's Manual (Function Explanation, Program
Fundamentals)

3.5.2 Address

Address is a format defined in IEC61131-3.
The following table shows details of format that conforms to IEC61131-3.
Start
1st character:
position
I Input (Omitted) Bit
Q Output X Bit
%
M Internal
Device name Device numbe
Table 3.5.2-1 Address definition specifications
2nd character: data size
W Word (16 bits)
D Double word (32 bits)
L Long word (64 bits)
3rd character and later:
classification
Numerics used for detailed
classification
Use '.' (period) to delimit the
numbers from the
subsequent numbers.
A period may be omitted.
Example)
X0 W35F
Number
Number
corresponding to
the device
number (decimal
notation)
3-8
Position
Position is a major class indicating the position to which data are allocated in three types: input, output, and internal.
The following shows the format rules corresponding to the device format.
• X, J\X (X device) : I (input)
• Y, J\Y (Y device) : Q (output)
• Other devices : M (internal)

3.5 Device and Address

3.5.1 Device

Example)
X0%I %MX1 . 863
Position Data
size
Classification
Numbe
Data size
Data size is a class indicating the size of data.
The following shows the format rules corresponding to the device format.
• Bit device : X (bit)
• Word device : W (word), D (double word), L (long word)
Classification
Classification is a minor class indicating the type of a device that cannot be identified only by its position and size.
Devices X and Y do not support classification.
For the format corresponding to the device format, refer to the following section.
Appendix 2 Correspondence between Devices and Addresses
3
Long words are used in double-precision real operation instructions of the Universal model QCPU.
FUNCTIONS
3.5 Device and Address
3.5.2 Address
3-9
3.6 Expressing Methods of Constants
The following table shows the expressing method for setting a constant to a label.
Table 3.6-1 Constant expressing method
Constant
type
Bool
Binary Append '2#' in front of a binary number. 2#0010, 2#01101010
Octal
notation
Decimal Directly input a decimal number, or append 'K' in front of a decimal number. 123, K123
Hexadecimal
Real
number
Character
string
Input FALSE or TRUE, or input 0 or 1. TRUE, FALSE
Append '8#' in front of an octal number. 8#0, 8#337
Append '16#' or 'H' in front of a hexadecimal number.
When a lowercase letter 'h' is appended, it is converted to uppercase automatically.
Directly input a real number or append 'E' in front of a real number. 2.34, E2.34
Enclose a character string with single quotations (') or double quotations ("). 'ABC', "ABC"
Expressing method Example

3.7 Precautions on Programming

Reserved words cannot be used for a name that is used in a program (label name, function block instance name, structured data type name, etc.).
3.7.1 Precautions on assigning a name
16#FF, HFF
This section explains the conditions for assigning a name and shows the list of reserved words.
Conditions
(1) Specify a name by a character string of up to 32 characters.
(2) Do not use a reserved word.
For reserved words, refer to Table 3.7-1 Reserved words.
(3) Use alphanumeric and underscore (_).
(4) Do not use an underscore at the end of a name.
Do not use two or more underscores in succession.
(5) Do not use a space.
(6) Do not use a number at the initial character.
(7) A constant cannot be used.
(An identifier that begins with 'H' or 'h' and an expression where a hexadecimal (0 to F) immediately follows 'H' or 'h' (maximum 9 digits including 'H' or 'h' (excluding 0 that immediately follows 'H' or 'h')) are also treated as a constant. (Example: 'hab0'))
3-10

3.6 Expressing Methods of Constants

3.7.1 Precautions on assigning a name

(8) An elementary data type name cannot be used.
(9) Part names of function/FB cannot be used.
Reserved words list
Table 3.7-1 Reserved words (1/2)
Category Character string
VAR, VAR_RETAIN, VAR_ACCESS, VAR_CONSTANT, VAR_CONSTANT_RETAIN, VAR_INPUT, VAR_INPUT_RETAIN,
Class identifier
Data type
Data type hierachy ANY, ANY_NUM, ANY_BIT, ANY_REAL, ANY_INT, ANY_DATE, ANY_SIMPLE, ANY16, ANY32
Device name
Character string recognized as device (Device name + Numeral)
ST operator NOT, MOD
IL operator
Application instruction in GX Works2
SFC instruction
ST code body
Standard function name Function names in application functions such as AND_E, NOT_E
VAR_OUTPUT, VAR_OUTPUT_RETAIN, VAR_IN_OUT, VAR_IN_EXT, VAR_EXTERNAL, VAR_EXTERNAL_CONSTANT, VAR_EXTERNAL_CONSTANT_RETAIN, VAR_EXTERNAL_RETAIN, VAR_GLOBAL, VAR_GLOBAL_CONSTANT, VAR_GLOBAL_CONSTANT_RETAIN, VAR_GLOBAL_RETAIN
BOOL, BYTE, INT, SINT, DINT, LINT, UINT, USINT, UDINT, ULINT, WORD, DWORD, LWORD, ARRAY, REAL, LREAL, TIME, STRING
X, Y, D, M, T, B, C, F, L, P, V, Z, W, I, N, U, J, K, H, E, A, SD, SM, SW, SB, FX, FY, DX, DY, FD, TR, BL, SG, VD, ZR, ZZ
Such as X0
LD, LDN, ST, STN, S, S1, R, R1, AND, ANDN, OR, ORN, XOR, XORN, ADD, SUB, MUL, DIV, GT, GE, EQ, NE, LE, LT, JMP, JMPC, JMPCN, CAL, CALC, CALCN, RET, RETC, RETCN, LDI, LDP, LDF, ANI, ANDP, ANDF, ANB, ORI, ORP, ORF, ORB, MPS, MRD, MPP, INV, MEP, MEF, EGP, EGF, OUT(H), SET, RST, PLS, PLF, FF, DELTA(P), SFT(P), MC, MCR, STOP, PAGE, NOP, NOPLF
Application instructions such as DMOD, PCHK, INC(P)
QCPU (Q Mode)/QnACPU Programming Manual (Common Instructions), QCPU Structured Programming Manual (Common
Instructions)
SFCP, SFCPEND, BLOCK, BEND, TRANL, TRANO, TRANA, TRANC, TRANCA, TRANOA, SEND, TRANOC, TRANOCA, TRANCO, TRANCOC, STEPN, STEPD, STEPSC, STEPSE, STEPST, STEPR, STEPC, STEPG, STEPI, STEPID, STEPISC, STEPISE, STEPIST, STEPIR, TRANJ, TRANOJ, TRANOCJ, TRANCJ, TRANCOJ, TRANCOCJ
RETURN, IF, THEN, ELSE, ELSIF, END_IF, CASE, OF, END_CASE, FOR, TO, BY, DO, END_FOR, WHILE, END_WHILE, REPEAT, UNTIL, END_REPEAT, EXIT, TYPE, END_TYPE, STRUCT, END_STRUCT, RETAIN, VAR_ACCESS, END_VAR, FUNCTION, END_FUNCTION, FUCTION_BLOCK, END_FUCTION_BLOCK, STEP, INITIAL_STEP, END_STEP, TRANSITION, END_TRANSITION, FROM, TO, UNTILWHILE
3
FUNCTIONS
3.7 Precautions on Programming
3.7.1 Precautions on assigning a name
3-11
Table 3.7-2 Reserved words (2/2)
Category Character string
Standard function block name
Symbol ", %, ', ~, ^, ¦, @, [, ] , {, }, ;, :, , , ., ?, \, !, #, $, ', _, *, /, +, <, >, =, &, (, ), -
Date and time literal DATE, DATE_AND_TIME, DT, TIME, TIME_OF_DAY, TOD
Others
String that starts with K1 to K8
Address Such as %IX0
Statement in ladder language
Common instruction Such as MOV
Windows reserved word
Function block names in application functions such as CTD, CTU
ACTION, END_ACTION, CONFIGURATION, END_CONFIGURATION, CONSTANT, F_EDGE, R_EDGE, AT, PROGRAM, WITH, END_PROGRAM, TRUE, FALSE, READ_ONLY, READ_WRITE, RESOURCE, END_RESOURCE, ON, TASK, EN, ENO, BODY_CCE, BODY_FBD, BODY_IL, BODY_LD, BODY_SFC, BODY_ST, END_BODY, END_PARAMETER_SECTION, PARAM_FILE_PATH, PARAMETER_SECTION, SINGLE, TRUE, FALSE, RETAIN, INTERVAL, L, P
Such as K1AAA
;FB BLK START, ;FB START, ;FB END, ;FB BLK END, ;FB IN, ;FB OUT, ;FB_NAME;,INSTANCE_NAME, ;FB, ;INSTANCE
COM1, COM2, COM3, COM4, COM5, COM6, COM7, COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6, LPT7, LPT8, LPT9, AUX, CON, PRN, NUL
3-12
3.7 Precautions on Programming
3.7.1 Precautions on assigning a name
4
1
OVERVIEW

HOW TO READ FUNCTIONS

2
FUNCTION TABLES
3
FUNCTIONS
4
HOW TO READ
FUNCTIONS
5
APPLICATION
FUNCTIONS
A
APPENDIX
I
INDEX
4-1
Chapter 5 provides detailed explanation on each function in the layout as shown below.
4-2
Indicates a section number and an outline of a function.
Indicates a function to be explained.
Indicates the CPU modules that can use the function.
Icon
Universal model
QCPU
High Performance model
QCPU
Description
Universal
UD
Un
iversal
UD
Universal
UD
High
Performance
High
Performance
High
Performance
The normal icon indicates that the CPU module can use the
corresponding functions.
The icon with U symbol indicates that the CPU module can use the
corresponding functions under certain restrictions. (Function version
and software version)
The icon with symbol indicates that the CPU module cannot use
the corresponding functions.
Indicates the function names.
Indicates the function names that can be described.
Indicates the description format of the function in the structured ladder and ST languages.
Indicates the names of input and output arguments, the data type of each argument, and the availability of direct device setting for each function.
Elementary
data type
Typ e Description
Bit Bool
Word (signed) Integer
Double word
(signed)
Double-
precision
integer
Word
(unsigned)/
16-bit string
16-bit string
Double word
(unsigned)/
32-bit string
32-bit string
Single-
precision real
Double-
precision
*1
real
String
*2
Time
Real
Double-
precision real
Character
string
Time value
Uses bit data or bit device.
(Data range: 0 (FALSE), 1 (TRUE))
Uses signed word data.
(Data range: -32768 to 32767)
Uses signed double-word data.
(Data range: -2147483648 to 2147483647)
Uses unsigned word data/16-bit BIN data.
(Data range: 0 to 65535)
Uses unsigned double-word data/32-bit BIN data.
(Data range: 0 to 4294967295)
Uses floating-point data.
128
-126
-126
(Data range: -2
Uses floating-point data.
(Data range: -2
Uses character string data. (Data range: max. 255 characters)
Uses the time type data.
(Data range: T#-24d-0h31m23s648ms to
T#24d20h31m23s647ms)
1024
to -2
to -2
-1022
, 0, 2
, 0, 2
to 2
-1022
128
to 2
)
1024
)
Direct device
setting
4
HOW TO READ
FUNCTIONS
*1 Can be used for the Universal model QCPU only. *2 The time type is used in time type operation instructions of application function.
4-3
Generic data
type
ANY
ANY_NUM
ANY_REAL
ANY_INT
ANY_BIT
ANY16 Can use elementary data type of word (unsigned)/16-bit string and word (signed).
ANY32
Can use all elementary data types.
Can use elementary data type of single-precision real, double-precision real, word (signed), and double
word (signed).
Can use elementary data type of single-precision real and double-precision real.
Can use elementary data type of word (signed) and double word (signed).
Can use elementary data type of bit, word (unsigned)/16-bit string, and double word (unsigned)/32-bit string.
With word (unsigned)/16-bit string, and double word (unsigned)/32-bit string, bit is specified.
Can use elementary data type of double word (unsigned)/32-bit string and double word (signed).
Description
Indicates the processing performed by the function.
Indicates whether to exist the related error. When an error exists, conditions that cause an error are described.
Indicates program examples in the structured ladder and ST languages.
4-4
5
1

APPLICATION FUNCTIONS

2
3
OVERVIEW
FUNCTION TABLES
5.1 Type Conversion Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2
5.2 Standard Functions of One Numeric Variable. . . . . . . . . . . . . . . . . . . . . . . . 5-119
5.3 Standard Arithmetic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-122
5.4 Standard Bitwise Boolean Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-143
5.5 Standard Selection Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-148
5.6 Standard Comparison Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-154
5.7 Standard Character String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-157
5.8 Functions of Time Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-172
5.9 Standard Bistable Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-184
5.10 Standard Edge Detection Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . 5-190
5.11 Standard Counter Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-194
5.12 Standard Timer Function Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-205
FUNCTIONS
4
HOW TO READ
FUNCTIONS
5
APPLICATION
FUNCTIONS
A
APPENDIX
I
5-1
INDEX
BOOL_TO_INT(_E), BOOL_TO_DINT(_E)
5.1 Type Conversion Functions
5.1.1 Bit type word (signed), double word (signed) type
conversion
BOOL_TO_INT(_E), BOOL_TO_DINT(_E)
Universal
UD
High
Performance
BOOL_TO_INT(_E) BOOL_TO_DINT(_E)
Structured ladder
BOOL_TO_INT_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
indicates any of the following
ST
BOOL_TO_INT_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Bit
Output status (TRUE: Normal execution, FALSE: Error or stop) :Bit
Output :Word (signed), double word (signed)
(EN, s, d);ENO:=
functions.
BOOL_TO_INT BOOL_TO_INT_E
BOOL_TO_DINT BOOL_TO_DINT_E
5-2
Operation processing
(1) BOOL_TO_INT, BOOL_TO_INT_E
Converts bit type data input to into word (signed) type data, and outputs the operation
result from .
d
When the input value is FALSE, 0 is output in word (signed) type data. When the input value is TRUE, 1 is output in word (signed) type data.
FALSE
TRUE
Bit type

5.1 Type Conversion Functions

5.1.1 Bit type → word (signed), double word (signed) type conversion

s
0
1
Word (signed) type
(2) BOOL_TO_DINT, BOOL_TO_DINT_E
BOOL_TO_INT(_E), BOOL_TO_DINT(_E)
Converts bit type data input to into double word (signed) type data, and outputs the
operation result from .
d
s
When the input value is FALSE, 0 is output in double word (signed) type data. When the input value is TRUE, 1 is output in double word (signed) type data.
FALSE
TRUE
Bit type
Double word (signed) type
0
1
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
d
Undefined value
d
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
d
5
APPLICATION
FUNCTIONS
BOOL_TO_INT(_E),
BOOL_TO_DINT(_E)
5.1.1 Bit type
5.1 Type Conversion Functions
word (signed), double word (signed) type conversion
5-3
BOOL_TO_INT(_E), BOOL_TO_DINT(_E)
Operation Error
No operation error occurs in the execution of the BOOL_TO_INT(_E) and BOOL_TO_DINT(_E) functions.
Program Example
(1) The program which converts bit type data input to into word (signed) type data, and
outputs the operation result from .
d
s
(a) Function without EN/ENO (BOOL_TO_INT)
[Structured ladder]
[ST]
g_int1 := BOOL_TO_INT(g_bool1);
(b) Function with EN/ENO (BOOL_TO_INT_E)
[Structured ladder]
[ST]
g_bool3 := BOOL_TO_INT_E(g_bool1, g_bool2, g_int1);
5-4
(2) The program which converts bit type data input to into double word (signed) type data,
and outputs the operation result from .
d
s
(a) Function without EN/ENO (BOOL_TO_DINT)
[Structured ladder]
[ST]
g_dint1 := BOOL_TO_DINT(g_bool1);
5.1 Type Conversion Functions
5.1.1 Bit type → word (signed), double word (signed) type conversion

5.1.2 Bit type string type conversion

BOOL_TO_STR(_E)
BOOL_TO_STR(_E)
High
Universal
UD
Performance
BOOL_TO_STR(_E)
Structured ladder
BOOL_TO_STR_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
ST
BOOL_TO_STR_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Bit
Output status (TRUE: Normal execution, FALSE: Error or stop) :Bit
Output :String
(EN, s, d);ENO:=
functions.
BOOL_TO_STR BOOL_TO_STR_E
indicates any of the following
5
APPLICATION
FUNCTIONS
Operation processing
Converts bit type data input to into string type data, and outputs the operation result from
d
. When the input value is FALSE, 0 is output in string type data. When the input value is TRUE, 1 is output in string type data.
FALSE
TRUE
Bit type
s
'0'
'1'
String type
5.1 Type Conversion Functions
5.1.2 Bit type
string type conversion
BOOL_TO_STR(_E)
5-5
BOOL_TO_STR(_E)
Operation result
(1) Function without EN/ENO
(2) Function with EN/ENO
An operation is executed and the operation value is output from .
d
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
Operation Error
No operation error occurs in the execution of the BOOL_TO_STR(_E) function.
Program Example
The program which converts bit type data input to into string type data, and outputs the
operation result from .
(a) Function without EN/ENO (BOOL_TO_STR)
[Structured ladder]
d
*1
FALSE
d
Undefined value
d
d
s
[ST]
g_string1 := BOOL_TO_STR (g_bool1);
5-6
5.1 Type Conversion Functions
5.1.2 Bit type → string type conversion
BOOL_TO_WORD(_E), BOOL_TO_DWORD(_E)
5.1.3 Bit type
word (unsigned)/16-bit string, double word
(unsigned)/32-bit string type conversion
BOOL_TO_WORD(_E) BOOL_TO_DWORD(_E)
Structured ladder
BOOL_TO_DWORD_E
EN ENO
ds
BOOL_TO_WORD(_E), BOOL_TO_DWORD(_E)
High
Performance
ST
BOOL_TO_DWORD_E
Universal
UD
_E: With EN/ENO
indicates any of the following
functions.
BOOL_TO_WORD BOOL_TO_WORD_E
(EN, s, d);ENO:=
BOOL_TO_DWORD
BOOL_TO_DWORD_E
Input argument, EN:
s:
Output argument, ENO:
d:
Function
Operation processing
(1) BOOL_TO_WORD, BOOL_TO_WORD_E
Converts bit type data input to into word (unsigned)/16-bit string type data, and outputs
the operation result from . When the input value is FALSE, 0H is output in word (unsigned)/16-bit string type data. When the input value is TRUE, 1H is output in word (unsigned)/16-bit string type data.
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Bit
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Word (unsigned)/16-bit string, double word
(unsigned)/32-bit string
s
d
FALSE
TRUE
Bit type
Word (unsigned)/16-bit string type
0H
1
H
5
APPLICATION
FUNCTIONS
BOOL_TO_WORD(_E),
BOOL_TO_DWORD(_E)
5.1 Type Conversion Functions

Bit type → word (unsigned)/16-bit string, double word (unsigned)/32-bit string type conversion

5.1.3
5-7
BOOL_TO_WORD(_E), BOOL_TO_DWORD(_E)
(2) BOOL_TO_DWORD, BOOL_TO_DWORD_E
Converts bit type data input to into double word (unsigned)/32-bit string type data, and
outputs the operation result from . When the input value is FALSE, 0
s
d
H is output in double word (unsigned)/32-bit string type
data. When the input value is TRUE, 1
H is output in double word (unsigned)/32-bit string type
data.
FALSE
TRUE
Bit type
Double word (unsigned)/32-bit string type
0H
1
H
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
d
Undefined value
d
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
d
5-8
5.1 Type Conversion Functions
5.1.3
Bit type → word (unsigned)/16-bit string, double word (unsigned)/32-bit string type conversion
Operation Error
No operation error occurs in the execution of the BOOL_TO_WORD(_E) and BOOL_TO_DWORD(_E) functions.
Program Example
BOOL_TO_WORD(_E), BOOL_TO_DWORD(_E)
(1) The program which converts bit type data input to into word (unsigned)/16-bit string type
data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (BOOL_TO_WORD)
[Structured ladder]
[ST]
g_word1 := BOOL_TO_WORD (g_bool1);
(b) Function with EN/ENO (BOOL_TO_WORD_E)
[Structured ladder]
[ST]
g_bool3 := BOOL_TO_WORD_E(g_bool1, g_bool2, g_word1);
5
APPLICATION
FUNCTIONS
(2) The program which converts bit type data input to into double word (unsigned)/32-bit
string type data, and outputs the operation result from .
s
d
(a) Function without EN/ENO (BOOL_TO_DWORD)
[Structured ladder]
[ST]
g_dword1 := BOOL_TO_DWORD (g_bool1);
5.1 Type Conversion Functions
Bit type → word (unsigned)/16-bit string, double word (unsigned)/32-bit string type conversion
5.1.3
5-9
BOOL_TO_WORD(_E),
BOOL_TO_DWORD(_E)
BOOL_TO_TIME(_E)
5.1.4 Bit type → time type conversion
BOOL_TO_TIME(_E)
High
Universal
UD
Performance
BOOL_TO_TIME(_E)
Structured ladder
BOOL_TO_TIME_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
ST
BOOL_TO_TIME_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Bit
Output status (TRUE: Normal execution, FALSE: Error or stop) :Bit
Output :Time
(EN, s, d);ENO:=
functions.
BOOL_TO_TIME BOOL_TO_TIME_E
indicates any of the following
5-10
Operation processing
Converts bit type data input to into time type data, and outputs the operation result from
d
. When the input value is FALSE, 0 is output in time type data. When the input value is TRUE, 1 is output in time type data.
FALSE
TRUE
Bit type
5.1 Type Conversion Functions

5.1.4 Bit type → time type conversion

s
0
1
ms
Time type
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
BOOL_TO_TIME(_E)
d
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
d
d
5
APPLICATION
FUNCTIONS
BOOL_TO_TIME(_E)
5.1 Type Conversion Functions
5.1.4 Bit type
time type conversion
5-11
BOOL_TO_TIME(_E)
Operation Error
No operation error occurs in the execution of the BOOL_TO_TIME(_E) function.
Program Example
The program which converts bit type data input to into time type data, and outputs the
operation result from .
(a) Function without EN/ENO (BOOL_TO_TIME)
[Structured ladder]
[ST]
g_time1 := BOOL_TO_TIME (g_bool1);
(b) Function with EN/ENO (BOOL_TO_TIME_E)
[Structured ladder]
d
s
[ST]
g_bool3 := BOOL_TO_TIME_E (g_bool1, g_bool2, g_time1);
5-12
5.1 Type Conversion Functions
5.1.4 Bit type → time type conversion
INT_TO_DINT(_E)

5.1.5 Word (signed) type double word (signed) type conversion

INT_TO_DINT(_E)
High
Universal
UD
Performance
INT_TO_DINT(_E)
Structured ladder
INT_TO_DINT_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
indicates any of the following
ST
INT_TO_DINT_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Word (signed)
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Double word (signed)
(EN, s, d);ENO:=
functions.
INT_TO_DINT INT_TO_DINT_E
5
APPLICATION
FUNCTIONS
Operation processing
Converts word (signed) type data input to into double word (signed) type data, and
outputs the operation result from .
1234
Word (signed) type
5.1.5 Word (signed) type
d
s
1234
Double word (signed) type
5.1 Type Conversion Functions
double word (signed) type conversion
INT_TO_DINT(_E)
5-13
INT_TO_DINT(_E)
Operation result
(1) Function without EN/ENO
(2) Function with EN/ENO
An operation is executed and the operation value is output from .
d
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
d
d
5-14
5.1 Type Conversion Functions
5.1.5 Word (signed) type → double word (signed) type conversion
Operation Error
No operation error occurs in the execution of the INT_TO_DINT(_E) function.
Program Example
INT_TO_DINT(_E)
The program which converts word (signed) type data input to into double word (signed) type
data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (INT_TO_DINT)
[Structured ladder]
[ST]
g_dint1 := INT_TO_DINT (g_int1);
(b) Function with EN/ENO (INT_TO_DINT_E)
[Structured ladder]
5
[ST]
g_bool3 := INT_TO_DINT_E (g_bool1, g_int1, g_dint1);
APPLICATION
FUNCTIONS
INT_TO_DINT(_E)
5.1.5 Word (signed) type
5.1 Type Conversion Functions
double word (signed) type conversion
5-15
DINT_TO_INT(_E)
5.1.6 Double word (signed) type → word (signed) type conversion
DINT_TO_INT(_E)
Universal
UD
High
Performance
DINT_TO_INT(_E)
Structured ladder
DINT_TO_INT_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
indicates any of the following
ST
DINT_TO_INT_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Double word (signed)
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Word (signed)
(EN, s, d);ENO:=
functions.
DINT_TO_INT DINT_TO_INT_E
5-16
Operation processing
Converts double word (signed) type data input to into word (signed) type data, and
outputs the operation result from .
1234
Double word (signed) type
5.1 Type Conversion Functions

5.1.6 Double word (signed) type → word (signed) type conversion

d
Word (signed) type
s
1234
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
DINT_TO_INT(_E)
d
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
d
d
When the DINT_TO_WORD(_E) function is executed, high-order 16-bit data
of double word (signed) type data input to is discarded.
s
5
APPLICATION
FUNCTIONS
DINT_TO_INT(_E)
5.1.6 Double word (signed) type
5.1 Type Conversion Functions
word (signed) type conversion
5-17
DINT_TO_INT(_E)
Operation Error
No operation error occurs in the execution of the DINT_TO_INT(_E) function.
Program Example
The program which converts double word (signed) type data input to into word (signed) type
data, and outputs the operation result from .
(a) Function without EN/ENO (DINT_TO_INT)
[Structured ladder]
[ST]
g_int1 := DINT_TO_INT(g_dint1);
(b) Function with EN/ENO (DINT_TO_INT_E)
[Structured ladder]
d
s
[ST]
g_bool3 := DINT_TO_INT_E (g_bool1, g_dint1, g_int1);
5-18
5.1 Type Conversion Functions
5.1.6 Double word (signed) type → word (signed) type conversion
INT_TO_BOOL(_E), DINT_TO_BOOL(_E)
5.1.7 Word (signed), double word (signed) type → bit type
conversion
INT_TO_BOOL(_E), DINT_TO_BOOL(_E)
Universal
UD
High
Performance
INT_TO_BOOL(_E) DINT_TO_BOOL(_E)
Structured ladder
INT_TO_BOOL_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
indicates any of the following
ST
INT_TO_BOOL_E
Executing condition (TRUE: Execution, FALSE: Stop) ;Bit
Input :Word (signed), double word (signed)
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Bit
(EN, s, d);ENO:=
functions.
INT_TO_BOOL INT_TO_BOOL_E
DINT_TO_BOOL DINT_TO_BOOL_E
5
APPLICATION
FUNCTIONS
Operation processing
(1) INT_TO_BOOL, INT_TO_BOOL_E
Converts word (signed) type data input to into bit type data, and outputs the operation
result from .
d
When the input value is 0, FALSE is output in bit type data. When the input value is other than 0, TRUE is output in bit type data.
0
1567
Word (signed) type
5.1.7 Word (signed), double word (signed) type
s
FALSE
TRUE
Bit type
5.1 Type Conversion Functions
bit type conversion
5-19
INT_TO_BOOL(_E),
DINT_TO_BOOL(_E)
INT_TO_BOOL(_E), DINT_TO_BOOL(_E)
(2) DINT_TO_BOOL, DINT_TO_BOOL_E
Converts double word (signed) type data input to into bit type data, and outputs the
operation result from .
d
s
When the input value is 0, FALSE is output in bit type data. When the input value is other than 0, TRUE is output in bit type data.
0
12345678
Double word (signed) type
FALSE
TRUE
Bit type
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
d
Undefined value
d
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
d
5-20
5.1 Type Conversion Functions
5.1.7 Word (signed), double word (signed) type → bit type conversion
Operation Error
No operation error occurs in the execution of the INT_TO_BOOL(_E) and DINT_TO_BOOL(_E) functions.
Program Example
INT_TO_BOOL(_E), DINT_TO_BOOL(_E)
(1) The program which converts word (signed) type data input to into bit type data, and
outputs the operation result from .
d
s
(a) Function without EN/ENO (INT_TO_BOOL)
[Structured ladder]
[ST]
g_bool1 := INT_TO_BOOL(g_int1);
(b) Function with EN/ENO (INT_TO_BOOL_E)
[Structured ladder]
5
[ST]
g_bool3 := INT_TO_BOOL_E (g_bool1, g_int1, g_bool2);
APPLICATION
FUNCTIONS
INT_TO_BOOL(_E),
DINT_TO_BOOL(_E)
5.1 Type Conversion Functions
5.1.7 Word (signed), double word (signed) type
bit type conversion
5-21
INT_TO_BOOL(_E), DINT_TO_BOOL(_E)
(2) The program which converts double word (signed) type data input to into bit type data,
and outputs the operation result from .
d
s
(a) Function without EN/ENO (DINT_TO_BOOL)
[Structured ladder]
[ST]
g_bool1 := DINT_TO_BOOL(g_dint1);
5-22
5.1 Type Conversion Functions
5.1.7 Word (signed), double word (signed) type → bit type conversion
INT_TO_REAL(_E), DINT_TO_REAL(_E)
5.1.8 Word (signed), double word (signed) type single-precision
real type conversion
INT_TO_REAL(_E), DINT_TO_REAL(_E)
High
Universal
UD
Performance
INT_TO_REAL(_E) DINT_TO_REAL(_E)
Structured ladder
INT_TO_REAL_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
indicates any of the following
ST
INT_TO_REAL_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Word (signed), double word (signed)
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Single-precision real
(EN, s, d);ENO:=
functions.
INT_TO_REAL INT_TO_REAL_E
DINT_TO_REAL DINT_TO_REAL_E
5
APPLICATION
FUNCTIONS
Operation processing
(1) INT_TO_REAL, INT_TO_REAL_E
Converts word (signed) type data input to into single-precision real type data, and outputs
the operation result from .
1234
Word (signed) type
5.1.8 Word (signed), double word (signed) type
d
s
1234.0
Single-precision real type
5.1 Type Conversion Functions
single-precision real type conversion
5-23
INT_TO_REAL(_E),
DINT_TO_REAL(_E)
INT_TO_REAL(_E), DINT_TO_REAL(_E)
(2) DINT_TO_REAL, DINT_TO_REAL_E
(a) Converts double word (signed) type data input to into single-precision real type data,
and outputs the operation result from .
16543521
Double word (signed) type
d
16543521.0
Single-precision real type
s
(b) The number of significant figures of single-precision real type 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.
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
d
Undefined value
d
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
d
5-24
5.1 Type Conversion Functions
5.1.8 Word (signed), double word (signed) type → single-precision real type conversion
Operation Error
No operation error occurs in the execution of the INT_TO_REAL(_E) and DINT_TO_REAL(_E) functions.
Program Example
INT_TO_REAL(_E), DINT_TO_REAL(_E)
(1) The program which converts word (signed) type data input to into single-precision real
type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (INT_TO_REAL)
[Structured ladder]
[ST]
g_real1 := INT_TO_REAL(g_int1);
(b) Function with EN/ENO (INT_TO_REAL_E)
[Structured ladder]
5
[ST]
g_bool3 := INT_TO_REAL_E(g_bool1, g_int1, g_real1);
(2) The program which converts double word (signed) type data input to into single-precision
real type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (DINT_TO_REAL)
[Structured ladder]
[ST]
g_real1 := DINT_TO_REAL(g_dint1);
APPLICATION
FUNCTIONS
INT_TO_REAL(_E),
DINT_TO_REAL(_E)
5.1.8 Word (signed), double word (signed) type
5.1 Type Conversion Functions
single-precision real type conversion
5-25
INT_TO_LREAL(_E), DINT_TO_LREAL(_E)
5.1.9 Word (signed), double word (signed) type double-precision
real type conversion
INT_TO_LREAL(_E), DINT_TO_LREAL(_E)
Universal
UD
INT_TO_LREAL(_E) DINT_TO_LREAL(_E)
Structured ladder
INT_TO_LREAL_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Word (signed), double word (signed)
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Double-precision real
Function
ST
INT_TO_LREAL_E
_E: With EN/ENO
indicates any of the following
functions.
INT_TO_LREAL INT_TO_LREAL_E
DINT_TO_LREAL DINT_TO_LREAL_E
(EN, s, d);ENO:=
5-26
Operation processing
(1) INT_TO_LREAL, INT_TO_LREAL_E
Converts word (signed) type data input to into double-precision real type data, and
outputs the operation result from .
1234 1234.0
Word (signed) type Double-precision real type
5.1 Type Conversion Functions

5.1.9 Word (signed), double word (signed) type → double-precision real type conversion

d
s
(2) DINT_TO_LREAL, DINT_TO_LREAL_E
INT_TO_LREAL(_E), DINT_TO_LREAL(_E)
Converts double word (signed) type data input to into double-precision real type data,
and outputs the operation result from .
16543521
d
16543521.0
Double-precision real typeDouble word (signed) type
s
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
d
Undefined value
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
d
d
5
APPLICATION
FUNCTIONS
INT_TO_LREAL(_E),
DINT_TO_LREAL(_E)
5.1.9 Word (signed), double word (signed) type
5.1 Type Conversion Functions
double-precision real type conversion
5-27
INT_TO_LREAL(_E), DINT_TO_LREAL(_E)
Operation Error
No operation error occurs in the execution of the INT_TO_LREAL(_E) and DINT_TO_LREAL(_E) functions.
Program Example
(1) The program which converts word (signed) type data input to into double-precision real
type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (INT_TO_LREAL)
[Structured ladder]
[ST]
g_lreal1 := INT_TO_LREAL(g_int1);
(b) Function with EN/ENO (INT_TO_LREAL_E)
[Structured ladder]
[ST]
g_bool3 := INT_TO_LREAL_E(g_bool1, g_int1, g_lreal2);
(2) The program which converts double word (signed) type data input to into double-
precision real type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (DINT_TO_LREAL)
[Structured ladder]
[ST]
g_lreal1 := DINT_TO_LREAL(g_dint1);
5-28
5.1 Type Conversion Functions
5.1.9 Word (signed), double word (signed) type → double-precision real type conversion
INT_TO_STR(_E), DINT_TO_STR(_E)
5.1.10 Word (signed), double word (signed) type → string type
conversion
INT_TO_STR(_E), DINT_TO_STR(_E)
Universal
UD
High
Performance
INT_TO_STR(_E) DINT_TO_STR(_E)
Structured ladder
INT_TO_STR_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
indicates any of the following
ST
INT_TO_STR_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Word (signed), double word (signed)
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :String(6)
(EN, s, d);ENO:=
functions.
INT_TO_STR INT_TO_STR_E
DINT_TO_STR DINT_TO_STR_E
5
APPLICATION
FUNCTIONS
Operation processing
(1) INT_TO_STRING, INT_TO_STRING_E
(a) Converts word (signed) type data input to into string type data, and outputs the
operation result from .
Word (signed) type
(b) '20
H (space)' is stored in 'Sign data' when the input value is positive; '2DH ()' is stored
d
High-order byte Low-order byte
ASCII code of ten-thousand's place
ASCII code of hundreds place
ASCII code of units place ASCII code of tens place
Automatically stored at the end of the character string.
when negative.
5.1.10 Word (signed), double word (signed) type
s
Sign data
ASCII code of thousands place
00
H
5.1 Type Conversion Functions
string type conversion
String 1st word
2nd word
3rd word
4th word
5-29
INT_TO_STR(_E),
DINT_TO_STR(_E)
INT_TO_STR(_E), DINT_TO_STR(_E)
(c) If the number of significant figures is less, '20H (space)' is stored to high-order digits.
(Example) Inputting 123
-123
Word (signed) type
High-order byte Low-order byte
20H (space) 2DH (-)
H (1)
31
33H (3)32H (2)
00
20H (space)
H
String 1st word
2nd word
3rd word
4th word
(d) '00
H' is automatically stored at the end of the character string (4th word).
(2) DINT_TO_STRING, DINT_TO_STRING_E
(a) Converts double word (signed) type data input to into string type data, and outputs
the operation result from .
Double word (signed) type
Automatically stored at the end of the character string.
(b) '20
H (space)' is stored in 'Sign data' when the input value is positive; '2DH (-)' is stored
d
High-order byte Low-order byte
ASCII code of billions place
ASCII code of ten-millions place
ASCII code of hundred-thousands place
ASCII code of thousands place
ASCII code of tens place
00H ASCII code of units place
s
Sign data
ASCII code of hundred-millions place
ASCII code of millions place
ASCII code of ten-thousand's place
ASCII code of hundreds place
String 1st word
2nd word
3rd word
4th word
5th word
6th word
when negative
(c) If the number of significant figures is less, '20
H (space)' is stored to high-order digits.
(Example) Inputting 123456
-123456
Double word (signed) type
(d) '00
H' is automatically stored at the end of the character string (high-order byte in 6th
word).
High-order byte Low-order byte
H (space) 2DH ( - )
20
H (space)
20
31
H (1) 20H (space)
33
H (3) 32H (2)
35
H (5) 34H (4)
00
H 36H (6)
20H (space)
String
1st word
2nd word
3rd word
4th word
5th word
6th word
5-30
5.1 Type Conversion Functions
5.1.10 Word (signed), double word (signed) type → string type conversion
INT_TO_STR(_E), DINT_TO_STR(_E)
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
d
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
d
d
5
APPLICATION
FUNCTIONS
INT_TO_STR(_E),
DINT_TO_STR(_E)
5.1 Type Conversion Functions
5.1.10 Word (signed), double word (signed) type
string type conversion
5-31
INT_TO_STR(_E), DINT_TO_STR(_E)
Operation Error
No operation error occurs in the execution of the INT_TO_STR(_E) and DINT_TO_STR(_E) functions.
Program Example
(1) The program which converts word (signed) type data input to into string type data, and
outputs the operation result from .
d
s
(a) Function without EN/ENO (INT_TO_STR)
[Structured ladder]
[ST]
g_string1 := INT_TO_STR(g_int1);
(b) Function with EN/ENO (INT_TO_STR_E)
[Structured ladder]
[ST]
g_bool3 := INT_TO_STR_E (g_bool1, g_int1, g_string1);
(2) The program which converts double word (signed) type data input to into string type data,
and outputs the operation result from .
d
s
(a) Function without EN/ENO (DINT_TO_STR)
[Structured ladder]
[ST]
g_string1 := DINT_TO_STR (g_dint1);
5-32
5.1 Type Conversion Functions
5.1.10 Word (signed), double word (signed) type → string type conversion
INT_TO_WORD(_E), DINT_TO_WORD(_E)
5.1.11 Word (signed), double word (signed) type
(unsigned)/16-bit string type conversion
INT_TO_WORD(_E), DINT_TO_WORD(_E)
INT_TO_WORD(_E) DINT_TO_WORD(_E)
Structured ladder
INT_TO_WORD_E
EN ENO
ds
ST
INT_TO_WORD_E
(EN, s, d);ENO:=
_E: With EN/ENO
functions.
INT_TO_WORD INT_TO_WORD_E
DINT_TO_WORD DINT_TO_WORD_E
word
Universal
UD
indicates any of the following
High
Performance
Input argument, EN:
s:
Output argument, ENO:
d:
Function
Operation processing
(1) INT_TO_WORD, INT_TO_WORD_E
Converts word (signed) type data input to into word (unsigned)/16-bit string type data,
and outputs the operation result from .
Word (signed) type
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Word (signed), double word (signed)
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Word (unsigned)/16-bit string
s
d
22136
Word (unsigned)/16-bit string type
5678
H
5
APPLICATION
FUNCTIONS
INT_TO_WORD(_E),
DINT_TO_WORD(_E)
5.1 Type Conversion Functions

Word (signed), double word (signed) type → word (unsigned)/16-bit string type conversion

5.1.11
5-33
INT_TO_WORD(_E), DINT_TO_WORD(_E)
(2) DINT_TO_WORD, DINT_TO_WORD_E
Converts double word (signed) type data input to into word (unsigned)/16-bit string type
data, and outputs the operation result from .
12345678
Double word (signed) type
12345678
614E
H
High-order 16-bit data is discarded.
s
d
614EH
Word (unsigned)/16-bit string type
000011110100000000 11110000000011001100001111110
0
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
d
Undefined value
d
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
d
When the DINT_TO_WORD(_E) function is executed, high-order 16-bit data
of double word (signed) type data input to input variable is discarded.
s
5-34
5.1 Type Conversion Functions
5.1.11
Word (signed), double word (signed) type → word (unsigned)/16-bit string type conversion
Operation Error
No operation error occurs in the execution of the INT_TO_WORD(_E) and DINT_TO_WORD(_E) functions.
Program Example
INT_TO_WORD(_E), DINT_TO_WORD(_E)
(1) The program which converts word (signed) type data input to into word (unsigned)/16-bit
string type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (INT_TO_WORD)
[Structured ladder]
[ST]
g_word1 := INT_TO_WORD(g_int1);
(b) Function with EN/ENO (INT_TO_WORD_E)
[Structured ladder]
5
[ST]
g_bool3 := INT_TO_WORD_E (g_bool1, g_int1, g_word1);
(2) The program which converts double word (signed) type data input to into word
(unsigned)/16-bit string type data, and outputs the operation result from .
s
d
(a) Function without EN/ENO (DINT_TO_WORD)
[Structured ladder]
[ST]
g_word1 := DINT_TO_WORD(g_dint1);
APPLICATION
FUNCTIONS
INT_TO_WORD(_E),
DINT_TO_WORD(_E)
5.1 Type Conversion Functions
Word (signed), double word (signed) type → word (unsigned)/16-bit string type conversion
5.1.11
5-35
INT_TO_DWORD(_E), DINT_TO_DWORD(_E)
5.1.12 Word (signed), double word (signed) type double word
(unsigned)/32-bit string type conversion
INT_TO_DWORD(_E), DINT_TO_DWORD(_E)
Universal
UD
High
Performance
INT_TO_DWORD(_E) DINT_TO_DWORD(_E)
Structured ladder
INT_TO_DWORD_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Word (signed), double word (signed)
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Double word (unsigned)/32-bit string
Function
ST
INT_TO_DWORD_E
_E: With EN/ENO
indicates any of the following
functions.
INT_TO_DWORD INT_TO_DWORD_E
DINT_TO_DWORD DINT_TO_DWORD_E
(EN, s, d);ENO:=
5-36
Operation processing
(1) INT_TO_DWORD, INT_TO_DWORD_E
Converts word (signed) type data input to into double word (unsigned)/32-bit string type
data, and outputs the operation result from .
-325
Word (signed) type
-325 11111110 1 0 1110 11
0000FEBB
5.1 Type Conversion Functions
5.1.12

Word (signed), double word (signed) type → double word (unsigned)/32-bit string type conversion

H
Always filled with 0s.
s
d
0000FEBBH
Double word (unsigned)/32-bit string type
Data conversion
10000000000000000 1111110 1 0 1110 11
(2) DINT_TO_DWORD, DINT_TO_DWORD_E
INT_TO_DWORD(_E), DINT_TO_DWORD(_E)
Converts double word (signed) type data input to into double word (unsigned)/32-bit
string type data, and outputs the operation result from .
12345678
Double word (signed) type
Double word (unsigned)/32-bit string type
s
d
BC614EH
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
d
Undefined value
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
d
d
5
APPLICATION
FUNCTIONS
INT_TO_DWORD(_E),
DINT_TO_DWORD(_E)
5.1 Type Conversion Functions
Word (signed), double word (signed) type → double word (unsigned)/32-bit string type conversion
5.1.12
5-37
INT_TO_DWORD(_E), DINT_TO_DWORD(_E)
Operation Error
No operation error occurs in the execution of the INT_TO_DWORD(_E) and DINT_TO_DWORD(_E) functions.
Program Example
(1) The program which converts word (signed) type data input to into double word
(unsigned)/32-bit string type data, and outputs the operation result from .
s
d
(a) Function without EN/ENO (INT_TO_DWORD)
[Structured ladder]
[ST]
g_dword1:= INT_TO_DWORD(g_int1);
(b) Function with EN/ENO (INT_TO_DWORD_E)
[Structured ladder]
[ST]
g_bool3 := INT_TO_DWORD_E(g_bool1, g_int1, g_dword1);
(2) The program which converts double word (signed) type data input to into double word
(unsigned)/32-bit string type data, and outputs the operation result from .
s
d
(a) Function without EN/ENO (DINT_TO_DWORD)
[Structured ladder]
[ST]
g_dword1:= DINT_TO_DWORD(g_dint1);
5-38
5.1 Type Conversion Functions
5.1.12
Word (signed), double word (signed) type → double word (unsigned)/32-bit string type conversion
INT_TO_BCD(_E), DINT_TO_BCD(_E)
5.1.13 Word (signed), double word (signed) type → BCD type
conversion
INT_TO_BCD(_E), DINT_TO_BCD(_E)
Universal
UD
High
Performance
INT_TO_BCD(_E) DINT_TO_BCD(_E)
Structured ladder
INT_TO_BCD_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
_E: With EN/ENO
indicates any of the following
ST
INT_TO_BCD_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Word (signed), double word (signed)
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Word (unsigned)/16-bit string, double word
(EN, s, d);ENO:=
functions.
INT_TO_BCD INT_TO_BCD_E
DINT_TO_BCD DINT_TO_BCD_E
(unsigned)/32-bit string
5
APPLICATION
FUNCTIONS
Function
Operation processing
(1) INT_TO_BCD, INT_TO_BCD_E
(a) Converts word (signed) type data input to into BCD type data, and outputs the
1
0
9999
4096
0
1000
1
d
2048
0
800
1
1024
s
400
512
2568012840642032101688442211
1
1
1
200
100
1
0
0
operation result from .
Word (signed) type
3276816384
9999 0
8000 4000
9999H
Thousand's place Hundred's place Ten's place Unit's place
8192
0
0
Must always be 0.
2000
0
1
(b) The value to be input to is word (signed) type data within the range from 0 to 9999.
5.1.13 Word (signed), double word (signed) type
s
9999H
Word (unsigned)/16-bit string type
0000011110101
BCD conversion
1
5.1 Type Conversion Functions
BCD type conversion
1
5-39
INT_TO_BCD(_E),
DINT_TO_BCD(_E)
INT_TO_BCD(_E), DINT_TO_BCD(_E)
(2) DINT_TO_BCD, DINT_TO_BCD_E
(a) Converts double word (signed) type data input to into BCD type data, and outputs
the operation result from .
99999999
Double word (signed) type
2312302292282272262252242232222212202192182172162152142132122112102928272625242322212
d
Double word (unsigned)/32-bit string type
s
99999999H
0
99999999 11010111110100000 110000011111111
BCD conversionMust always be 0.
7
8421842
99999999
H
Ten million's place
(b) The value to be input to is double word (signed) type data within the range from 0 to
10
6
10
Million's place
5
1
84218421842184218421842
Hundred thousand's place
s
10
4
10
Ten thousand's place
3
11001100110011001
001100110011001
Thousand's place
10
2
10
Hundred's place
1
10
Ten's place
0
10
Unit's place
1
99999999.
Operation result
(1) Function without EN/ENO
The following table shows the operation results.
Operation result
No operation error Operation output value
Operation error Undefined value
d
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution)
FALSE (Operation stop)
TRUE (No operation error) Operation output value
FALSE (Operation error)
*1
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
Undefined value
d
d
5-40
5.1 Type Conversion Functions
5.1.13 Word (signed), double word (signed) type → BCD type conversion
Operation Error
An operation error occurs when the value input exceeds 9999 or 99999999 respectively in the execution of the INT_TO_BCD(_E) or DINT_TO_BCD(_E) function. (Error code: 4100)
Program Example
INT_TO_BCD(_E), DINT_TO_BCD(_E)
(1) The program which converts word (signed) type data input to into BCD type data, and
outputs the operation result from .
d
s
(a) Function without EN/ENO (INT_TO_BCD)
[Structured ladder]
[ST]
g_word1:= INT_TO_BCD(g_int1);
(b) Function with EN/ENO (INT_TO_BCD_E)
[Structured ladder]
5
[ST]
g_bool3 := INT_TO_BCD_E(g_bool1, g_int1, g_word1);
(2) The program which converts double word (signed) type data input to into BCD type data,
and outputs the operation result from .
d
s
(a) Function without EN/ENO (DINT_TO_BCD)
[Structured ladder]
[ST]
s_dword1:= DINT_TO_BCD(g_dint1);
APPLICATION
FUNCTIONS
INT_TO_BCD(_E),
DINT_TO_BCD(_E)
5.1 Type Conversion Functions
5.1.13 Word (signed), double word (signed) type
BCD type conversion
5-41
INT_TO_TIME(_E), DINT_TO_TIME(_E)
5.1.14 Word (signed), double word (signed) type time type
conversion
INT_TO_TIME(_E), DINT_TO_TIME(_E)
Universal
UD
High
Performance
INT_TO_TIME(_E) DINT_TO_TIME(_E)
Structured ladder
INT_TO_TIME_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
indicates any of the following
ST
INT_TO_TIME_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Word (signed), double word (signed)
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Time
(EN, s, d);ENO:=
functions.
INT_TO_TIME INT_TO_TIME_E
DINT_TO_TIME DINT_TO_TIME_E
5-42
Operation processing
Converts word (signed) type data input to into time type data, and outputs the operation
result from .
Word (signed) type
5.1 Type Conversion Functions

5.1.14 Word (signed), double word (signed) type → time type conversion

d
FFFFH
s
1m5s535ms
Time type
INT_TO_TIME(_E), DINT_TO_TIME(_E)
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
d
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
d
d
5
APPLICATION
FUNCTIONS
INT_TO_TIME(_E),
DINT_TO_TIME(_E)
5.1 Type Conversion Functions
5.1.14 Word (signed), double word (signed) type
time type conversion
5-43
INT_TO_TIME(_E), DINT_TO_TIME(_E)
Operation Error
No operation error occurs in the execution of the INT_TO_TIME(_E) and DINT_TO_TIME(_E) functions.
Program Example
(1) The program which converts word (signed) type data input to into time type data, and
outputs the operation result from .
d
s
(a) Function without EN/ENO (INT_TO_TIME)
[Structured ladder]
[ST]
g_time1:= INT_TO_TIME(g_int1);
(b) Function with EN/ENO (INT_TO_TIME_E)
[Structured ladder]
[ST]
g_bool3 := INT_TO_TIME_E(g_bool1, g_int1, g_time1);
(2) The program which converts double word (signed) type data input to into time type data,
and outputs the operation result from .
d
s
(a) Function without EN/ENO (DINT_TO_TIME)
[Structured ladder]
[ST]
g_time1:= DINT_TO_TIME(g_dint1);
5-44
5.1 Type Conversion Functions
5.1.14 Word (signed), double word (signed) type → time type conversion
REAL_TO_INT(_E), REAL_TO_DINT(_E)
5.1.15 Single-precision real type word (signed), double word
(signed) type conversion
REAL_TO_INT(_E), REAL_TO_DINT(_E)
Universal
UD
Performance
High
REAL_TO_INT(_E) REAL_TO_DINT(_E)
Structured ladder
REAL_TO_INT_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
indicates any of the following
ST
REAL_TO_INT_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Single-precision real
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Word (signed), double word (signed)
(EN, s, d);ENO:=
functions.
REAL_TO_INT REAL_TO_INT_E
REAL_TO_DINT REAL_TO_DINT_E
5
APPLICATION
FUNCTIONS
Operation processing
(1) REAL_TO_INT, REAL_TO_INT_E
(a) Converts single-precision real type data input to into word (signed) type data, and
outputs the operation result from .
1234.0
Single-precision real type
(b) The value to be input to is single-precision real type data, within the range from
s
d
Word (signed)
32768 to 32767.
(c) The converted data is the value rounded single-precision real type data to the first digit
after the decimal point.
5.1.15 Single-precision real type
word (signed), double word (signed) type conversion
s
1234
type
5.1 Type Conversion Functions
5-45
REAL_TO_INT(_E),
REAL_TO_DINT(_E)
REAL_TO_INT(_E), REAL_TO_DINT(_E)
(2) REAL_TO_DINT, REAL_TO_DINT_E
(a) Converts single-precision real type data input to into double word (signed) type data,
and outputs the operation result from .
16543521.0
Single-precision real type
(b) The value to be input to is single-precision real type data within the range from
s
d
Double word (signed) type
s
16543521
2147483648 to 2147483647.
(c) The converted data is the value rounded single-precision real type data to the first digit
after the decimal point.
Operation result
(1) Function without EN/ENO
The following table shows the operation results.
Operation result
No operation error Operation output value
Operation error Undefined value
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
d
EN ENO
TRUE (Operation execution)
FALSE (Operation stop)
TRUE (No operation error) Operation output value
FALSE (Operation error)
*1
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
Undefined value
d
d
5-46
5.1 Type Conversion Functions
5.1.15 Single-precision real type → word (signed), double word (signed) type conversion
Operation Error
An operation error occurs in the following cases.
• REAL_TO_INT(_E): The input value is outside the range of 32768 to 32767.
• REAL_TO_DINT(_E): The input value is outside the range of 2147483648 to
2147483647. (Error code: 4100)
Program Example
REAL_TO_INT(_E), REAL_TO_DINT(_E)
(Error code: 4100)
(1) The program which converts single-precision real type data input to into word (signed)
type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (REAL_TO_INT)
[Structured ladder]
[ST]
g_int1:= REAL_TO_INT(g_real1);
(b) Function with EN/ENO (REAL_TO_INT_E)
[Structured ladder]
[ST]
g_bool3 := REAL_TO_INT_E(g_bool1, g_real1, g_int1);
5
APPLICATION
FUNCTIONS
(2) The program which converts single-precision real type data input to into double word
(signed) type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (REAL_TO_DINT)
[Structured ladder]
[ST]
g_dint1:= REAL_TO_DINT(g_real1);
5.1 Type Conversion Functions
5.1.15 Single-precision real type
word (signed), double word (signed) type conversion
5-47
REAL_TO_INT(_E),
REAL_TO_DINT(_E)
LREAL_TO_INT(_E), LREAL_TO_DINT(_E)
5.1.16 Double-precision real type word (signed), double word
(signed) type conversion
LREAL_TO_INT(_E), LREAL_TO_DINT(_E)
Universal
UD
LREAL_TO_INT(_E) LREAL_TO_DINT(_E)
Structured ladder
LREAL_TO_INT_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Double-precision real
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Word (signed), double word (signed)
Function
ST
LREAL_TO_INT_E
_E: With EN/ENO
indicates any of the following
functions.
LREAL_TO_INT LREAL_TO_INT_E
LREAL_TO_DINT LREAL_TO_DINT_E
(EN, s, d);ENO:=
5-48
Operation processing
(1) LREAL_TO_INT, LREAL_TO_INT_E
(a) Converts double-precision real type data input to into word (signed) type data, and
outputs the operation result from .
1234.0
Double-precision real type
(b) The value to be input to is double-precision real type data, within the range from
s
d
Word (signed) type
32768 to 32767.
(c) The converted data is the value rounded double-precision real type data to the first digit
after the decimal point.
5.1 Type Conversion Functions

5.1.16 Double-precision real type → word (signed), double word (signed) type conversion

s
1234
(2) LREAL_TO_DINT, LREAL_TO_DINT_E
LREAL_TO_INT(_E), LREAL_TO_DINT(_E)
(a) Converts double-precision real type data input to into double word (signed) type
data, and outputs the operation result from .
16543521.0
Double-precision real type
(b) The value to be input to is double-precision real type data within the range from
s
Double word (signed) type
s
d
16543521
2147483648 to 2147483647.
(c) The converted data is the value rounded double-precision real type data to the first digit
after the decimal point.
Operation result
(1) Function without EN/ENO
The following table shows the operation results.
Operation result
No operation error Operation output value
Operation error Undefined value
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
d
EN ENO
TRUE (Operation execution)
FALSE (Operation stop)
TRUE (No operation error) Operation output value
FALSE (Operation error)
*1
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
Undefined value
d
d
5
APPLICATION
FUNCTIONS
LREAL_TO_INT(_E),
LREAL_TO_DINT(_E)
5.1.16 Double-precision real type
5.1 Type Conversion Functions
word (signed), double word (signed) type conversion
5-49
LREAL_TO_INT(_E), LREAL_TO_DINT(_E)
Operation Error
An operation error occurs in the following cases.
• The input value is -0 or outside the following range. (Error code: 4140)
0, 2
-1022
s d
| , | 2
• LREAL_TO_INT(_E): The input value is outside the range of -32768 to 32767.
• LREAL_TO_DINT(_E): The input value is outside the range of -2147483648 to
2147483647. (Error code: 4140)
Program Example
1024
(Error code: 4140)
(1) The program which converts double-precision real type data input to into word (signed)
type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (LREAL_TO_INT)
[Structured ladder]
[ST]
g_int1:= LREAL_TO_INT(g_lreal1);
(b) Function with EN/ENO (LREAL_TO_INT_E)
[Structured ladder]
[ST]
g_bool3 := LREAL_TO_INT_E(g_bool1, g_lreal1, g_int1);
5-50
(2) The program which converts double-precision real type data input to into double word
(signed) type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (LREAL_TO_DINT)
[Structured ladder]
[ST]
g_dint1:= LREAL_TO_DINT(g_lreal1);
5.1 Type Conversion Functions
5.1.16 Double-precision real type → word (signed), double word (signed) type conversion
REAL_TO_LREAL(_E)
5.1.17 Single-precision real type double-precision real type
conversion
REAL_TO_LREAL(_E)
Universal
UD
REAL_TO_LREAL(_E)
Structured ladder
REAL_TO_LREAL_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Single-precision real
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Double-precision real
Function
ST
REAL_TO_LREAL_E
_E: With EN/ENO
indicates any of the following
functions.
REAL_TO_LREAL REAL_TO_LREAL_E
(EN, s, d);ENO:=
5
APPLICATION
FUNCTIONS
Operation processing
Converts single-precision real type data input to into double-precision real type data, and
outputs the operation result from .
1234.0
Single-precision real type
5.1.17 Single-precision real type
d
Double-precision real type
double-precision real type conversion
s
1234
5.1 Type Conversion Functions
5-51
REAL_TO_LREAL(_E
)
REAL_TO_LREAL(_E)
Operation result
(1) Function without EN/ENO
The following table shows the operation results.
Operation result
No operation error Operation output value
Operation error Undefined value
d
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution)
FALSE (Operation stop)
TRUE (No operation error) Operation output value
FALSE (Operation error)
*1
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
Undefined value
d
d
5-52
5.1 Type Conversion Functions
5.1.17 Single-precision real type → double-precision real type conversion
Operation Error
An operation error occurs in the following cases.
• The input value is -0 or outside the following range. (Error code: 4140)
-126
0, 2
• The operation result is outside the following range (an overflow occurrence).
1024
2
Program Example
s
| | 2
128
| operation result |
REAL_TO_LREAL(_E)
(Error code: 4141)
The program which converts single-precision real type data input to into double-precision real
type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (REAL_TO_LREAL)
[Structured ladder]
[ST]
g_lreal1:= REAL_TO_LREAL(g_real1);
(b) Function with EN/ENO (REAL_TO_LREAL_E)
[Structured ladder]
5
APPLICATION
FUNCTIONS
[ST]
g_bool3 := REAL_TO_LREAL_E(g_bool1, g_real1, g_lreal1);
5.1 Type Conversion Functions
5.1.17 Single-precision real type
double-precision real type conversion
5-53
REAL_TO_LREAL(_E
)
LREAL_TO_REAL(_E)
5.1.18 Double-precision real type single-precision real type
conversion
LREAL_TO_REAL(_E)
Universal
UD
LREAL_TO_REAL(_E)
Structured ladder
LREAL_TO_REAL_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Double-precision real
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Single-precision real
Function
ST
LREAL_TO_REAL_E
_E: With EN/ENO
indicates any of the following
functions.
LREAL_TO_REAL LREAL_TO_REAL_E
(EN, s, d);ENO:=
5-54
Operation processing
Converts double-precision real type data input to into single-precision real type data, and
outputs the operation result from .
1234.0 1234
Double-precision real type Single-precision real type
5.1 Type Conversion Functions

5.1.18 Double-precision real type → single-precision real type conversion

d
s
Operation result
(1) Function without EN/ENO
The following table shows the operation results.
LREAL_TO_REAL(_E)
Operation result
No operation error Operation output value
Operation error Undefined value
d
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution)
FALSE (Operation stop)
TRUE (No operation error) Operation output value
FALSE (Operation error)
*1
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
Undefined value
d
d
5
APPLICATION
FUNCTIONS
LREAL_TO_REAL(_E
)
5.1.18 Double-precision real type
5.1 Type Conversion Functions
single-precision real type conversion
5-55
LREAL_TO_REAL(_E)
Operation Error
An operation error occurs in the following cases.
• The input value is -0 or outside the following range. (Error code: 4140)
0, 2
• The operation result is outside the following range (an overflow occurrence).
2
Program Example
-1022
| | 2
128
| operation result |
s
1024
(Error code: 4141)
The program which converts double-precision real type data input to into single-precision real
type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (LREAL_TO_REAL)
[Structured ladder]
[ST]
g_real1:= LREAL_TO_REAL(g_lreal1);
(b) Function with EN/ENO (LREAL_TO_REAL_E)
[Structured ladder]
5-56
[ST]
g_bool3 := LREAL_TO_REAL_E(g_bool1, g_lreal1, g_real1);
5.1 Type Conversion Functions
5.1.18 Double-precision real type → single-precision real type conversion
REAL_TO_STR(_E)

5.1.19 Single-precision real type string type conversion

REAL_TO_STR(_E)
Universal
UD
High
Performance
REAL_TO_STR(_E)
Structured ladder
REAL_TO_STR_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Function
_E: With EN/ENO
indicates any of the following
ST
REAL_TO_STR_E
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Single-precision real
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :String(12)
(EN, s, d);ENO:=
functions.
REAL_TO_STR REAL_TO_STR_E
5
APPLICATION
FUNCTIONS
Operation processing
(1) Converts single-precision real type data input to into string type (exponent form) data,
and outputs the operation result from .
Single-precision
real type
.
Sign (integral part)
E
Sign (exponent part)
Automatically added.
5.1.19 Single-precision real type
d
High-order byte Low-order byte
ASCII code of integral part
ASCII code of one decimal place
ASCII code of three decimal place
ASCII code of five decimal place
Sign data (exponential part)
ASCII code of exponent part's units place
Automatically stored at the end of the character string.
s
Sign data (integral part)
ASCII code of (.) decimal place (2E
ASCII code of two decimal place
ASCII code of four decimal place
ASCII code of exponent part's tens place
00
H
H)
H(E)
45
5.1 Type Conversion Functions
string type conversion
String 1st word
2nd word
3rd word
4th word
5th word
6th word
7th word
5-57
REAL_TO_STR(_E)
REAL_TO_STR(_E)
(2) The character string data after conversion is output from output variable in the following
d
manner.
(a) The number of digits is fixed respectively for the integral part, decimal part, and
exponent part. (Integral part: 1 digit, decimal part: 5 digits, exponent part: 2 digits) '2E
H' (.) and '45H' (E) are automatically stored in the 3rd and 9th bytes, respectively.
All together 12 digits
Decimal part (5 digits) Exponent part (2 digits)Integral part (1 digit)
-12.3456
Single-precision real type
5432.1-6E+0 1
2E
H (.)
45
H (E)
(b) '20H' (space) is stored in 'Sign data' (integral part) when the input value is positive;
'2DH' () is stored when negative
(c) Decimal part is rounded to 5 decimal places.
All together 12 digits
-12.345678
Single-precision real type
Decimal part (5 digits)
5432.1- 6677 8E+0 1
Rounded off.
(d) If the number of significant figures is less, '30
All together 12 digits
-12.34
Single-precision real type
(e) '2B
H' (+) is stored in the 'Sign data' (exponent part) if the exponent is positive; '2DH' (−)
Decimal part (5 digits)
is stored when negative.
(f) '30
(3) '00
H' (0) is stored to tens place in the exponent part if exponent part has only one digit.
All together 12 digits
-12.3456
Single-precision real type
H' is automatically stored to the end of the character string (7th word).
H' (0) is stored to decimal part.
0432.1- 0 E+ 0 1
30
H (0)
Exponent part (2 digits)
5432.1-6E+0 1
30H (0)
5-58
5.1 Type Conversion Functions
5.1.19 Single-precision real type → string type conversion
Operation result
(1) Function without EN/ENO
The following table shows the operation results.
REAL_TO_STR(_E)
Operation result
No operation error Operation output value
Operation error Undefined value
d
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution)
FALSE (Operation stop)
TRUE (No operation error) Operation output value
FALSE (Operation error)
*1
FALSE
*1
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
Undefined value
Undefined value
d
d
5
APPLICATION
FUNCTIONS
REAL_TO_STR(_E)
5.1 Type Conversion Functions
5.1.19 Single-precision real type
string type conversion
5-59
REAL_TO_STR(_E)
Operation Error
An operation error occurs in the following case.
• The input value is outside the range of ±1.17549
Program Example
38
to ±3.40282
+38
. (Error code: 4100)
The program which converts single-precision real type data input to into string type (exponent
form) data, and outputs the operation result from .
(a) Function without EN/ENO (REAL_TO_STR)
[Structured ladder]
[ST]
g_string1:= REAL_TO_STR(g_real1);
(b) Function with EN/ENO (REAL_TO_STR_E)
[Structured ladder]
d
s
[ST]
g_bool3 := REAL_TO_STR_E(g_bool1, g_real1, g_string1);
5-60
5.1 Type Conversion Functions
5.1.19 Single-precision real type → string type conversion
WORD_TO_BOOL(_E), DWORD_TO_BOOL(_E)
5.1.20 Word (unsigned)/16-bit string, double word (unsigned)/32-bit
string type bit type conversion
WORD_TO_BOOL(_E), DWORD_TO_BOOL(_E)
High
Universal
UD
Performance
WORD_TO_BOOL(_E) DWORD_TO_BOOL(_E)
Structured ladder
WORD_TO_BOOL_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Word (unsigned)/16-bit string, double word
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Bit
ST
WORD_TO_BOOL_E
_E: With EN/ENO
indicates any of the following
functions.
WORD_TO_BOOL WORD_TO_BOOL_E
(EN, s, d);ENO:=
DWORD_TO_BOOL
DWORD_TO_BOOL_E
5
(unsigned)/32-bit string
APPLICATION
FUNCTIONS
Function
Operation processing
(1) WORD_TO_BOOL, WORD_TO_BOOL_E
5.1.20
Converts word (unsigned)/16-bit string type data input to into bit type data, and outputs
the operation result from . When the input value is 0 When the input value is other than 0
0H
1567H
Word (unsigned)/16-bit string type

Word (unsigned)/16-bit string, double word (unsigned)/32-bit string type → bit type conversion

d
H, FALSE is output.
H, TRUE is output.
FALSE
TRUE
Bit type
5.1 Type Conversion Functions
s
5-61
WORD_TO_BOOL(_E),
DWORD_TO_BOOL(_E)
WORD_TO_BOOL(_E), DWORD_TO_BOOL(_E)
(2) DWORD_TO_BOOL, DWORD_TO_BOOL_E
Converts double word (unsigned)/32-bit string type data input to into bit type data, and
outputs the operation result from . When the input value is 0
H, FALSE is output.
When the input value is other than 0
0H
12345678H
Double word (unsigned)/32-bit string type
d
H, TRUE is output.
FALSE
TRUE
Bit type
s
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
d
Undefined value
d
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
d
5-62
5.1 Type Conversion Functions
5.1.20
Word (unsigned)/16-bit string, double word (unsigned)/32-bit string type → bit type conversion
Operation Error
No operation error occurs in the execution of the WORD_TO_BOOL(_E) and DWORD_TO_BOOL(_E) functions.
Program Example
WORD_TO_BOOL(_E), DWORD_TO_BOOL(_E)
(1) The program which converts word (unsigned)/16-bit string type data input to into bit type
data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (WORD_TO_BOOL)
[Structured ladder]
[ST]
g_bool1:= WORD_TO_BOOL(g_word1);
(b) Function with EN/ENO (WORD_TO_BOOL_E)
[Structured ladder]
5
[ST]
g_bool3 := WORD_TO_BOOL_E(g_bool1, g_word1, g_bool2);
(2) The program which converts double word (unsigned)/32-bit string type data input to into
bit type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (DWORD_TO_BOOL)
[Structured ladder]
[ST]
g_bool1:= DWORD_TO_BOOL(g_dword1);
APPLICATION
FUNCTIONS
WORD_TO_BOOL(_E),
DWORD_TO_BOOL(_E)
5.1 Type Conversion Functions
Word (unsigned)/16-bit string, double word (unsigned)/32-bit string type → bit type conversion
5.1.20
5-63
WORD_TO_INT(_E), WORD_TO_DINT(_E)
5.1.21 Word (unsigned)/16-bit string type word (signed), double
word (signed) type conversion
WORD_TO_INT(_E), WORD_TO_DINT(_E)
Universal
UD
Performance
High
WORD_TO_INT(_E) WORD_TO_DINT(_E)
Structured ladder
WORD_TO_INT_E
EN ENO
ds
Input argument, EN:
s:
Output argument, ENO:
d:
Executing condition (TRUE: Execution, FALSE: Stop) :Bit
Input :Word (unsigned)/16-bit string
Output status (TRUE: Normal, FALSE: Error) :Bit
Output :Word (signed), double word (signed)
Function
ST
WORD_TO_INT_E
_E: With EN/ENO
indicates any of the following
functions.
WORD_TO_INT WORD_TO_INT_E
WORD_TO_DINT WORD_TO_DINT_E
(EN, s, d);ENO:=
5-64
Operation processing
(1) WORD_TO_INT, WORD_TO_INT_E
Converts word (unsigned)/16-bit string type data input to into word (signed) type data,
and outputs the operation result from .
5678H
Word (unsigned)/16-bit string type
5.1 Type Conversion Functions
5.1.21

Word (unsigned)/16-bit string type → word (signed), double word (signed) type conversion

d
22136
Word (signed) type
s
(2) WORD_TO_DINT, WORD_TO_DINT_E
WORD_TO_INT(_E), WORD_TO_DINT(_E)
Converts word (unsigned)/16-bit string type data input to into double word (signed) type
data, and outputs the operation result from .
5678H
Word (unsigned)/16-bit string type
5678H 0 1 0 1 0 11001111000
22136
Always filled with 0s.
00000000000000000 1 0 1 0 11001111000
d
Double word (signed) type
Data conversion
s
22136
Operation result
(1) Function without EN/ENO
An operation is executed and the operation value is output from .
(2) Function with EN/ENO
The following table shows the executing conditions and operation results.
EN ENO
TRUE (Operation execution) TRUE Operation output value
FALSE (Operation stop)
FALSE
*1
d
Undefined value
d
*1 When FALSE is output from ENO, the data output from is undefined.
In this case, create a program so that the data output from is not used.
d
d
5
APPLICATION
FUNCTIONS
WORD_TO_INT(_E),
WORD_TO_DINT(_E)
5.1 Type Conversion Functions
Word (unsigned)/16-bit string type → word (signed), double word (signed) type conversion
5.1.21
5-65
WORD_TO_INT(_E), WORD_TO_DINT(_E)
Operation Error
No operation error occurs in the execution of the WORD_TO_INT(_E) and WORD_TO_DINT(_E) functions.
Program Example
(1) The program which converts word (unsigned)/16-bit string type data input to into word
(signed) type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (WORD_TO_INT)
[Structured ladder]
[ST]
g_int1:= WORD_TO_INT(g_word1);
(b) Function with EN/ENO (WORD_TO_INT_E)
[Structured ladder]
[ST]
g_bool3 := WORD_TO_INT_E(g_bool1, g_word1, g_int1);
(2) The program which converts word (unsigned)/16-bit string type data input to into double
word (signed) type data, and outputs the operation result from .
d
s
(a) Function without EN/ENO (WORD_TO_DINT)
[Structured ladder]
[ST]
g_dint1:= WORD_TO_DINT(g_word1);
5-66
5.1 Type Conversion Functions
5.1.21
Word (unsigned)/16-bit string type → word (signed), double word (signed) type conversion
Loading...