Mitsubishi Electric MELSEC QL Structured v2 Programming Manual
MELSEC-Q/L Structured Programming Manual (Application Functions)
SAFETY PRECAUTIONS (Read these precautions before using this product.)
Before using MELSEC-Q or -L series programmable controllers, please read the manuals included with each product and the
relevant manuals introduced in those manuals carefully, and pay full attention to safety to handle the product correctly.
Make sure that the end users read the manuals included with each product, and keep the manuals in a safe place for future
reference.
CONDITIONS OF USE FOR THE PRODUCT (1) Mitsubishi programmable controller ("the PRODUCT") shall be used in conditions;
i) where any problem, fault or failure occurring in the PRODUCT, if any, shall not lead to any major or serious accident; and ii) where the backup and fail-safe function are systematically or automatically provided outside of the PRODUCT for the case of any problem, fault or failure occurring in the PRODUCT.
(2) The PRODUCT has been designed and manufactured for the purpose of being used in general industries. MITSUBISHI SHALL HAVE NO RESPONSIBILITY OR LIABILITY (INCLUDING, BUT NOT LIMITED TO ANY AND ALL RESPONSIBILITY OR LIABILITY BASED ON CONTRACT, WARRANTY, TORT, PRODUCT LIABILITY) FOR ANY INJURY OR DEATH TO PERSONS OR LOSS OR DAMAGE TO PROPERTY CAUSED BY the PRODUCT THAT ARE OPERATED OR USED IN APPLICATION NOT INTENDED OR EXCLUDED BY INSTRUCTIONS, PRECAUTIONS, OR WARNING CONTAINED IN MITSUBISHI'S USER, INSTRUCTION AND/OR SAFETY MANUALS, TECHNICAL BULLETINS AND GUIDELINES FOR the PRODUCT. ("Prohibited Application") Prohibited Applications include, but not limited to, the use of the PRODUCT in; Nuclear Power Plants and any other power plants operated by Power companies, and/or any other cases in which the
public could be affected if any problem or fault occurs in the PRODUCT. Railway companies or Public service purposes, and/or any other cases in which establishment of a special quality
assurance system is required by the Purchaser or End User. Aircraft or Aerospace, Medical applications, Train equipment, transport equipment such as Elevator and Escalator,
Incineration and Fuel devices, Vehicles, Manned transportation, Equipment for Recreation and Amusement, and Safety devices, handling of Nuclear or Hazardous Materials or Chemicals, Mining and Drilling, and/or other applications where there is a significant risk of injury to the public or property.
Notwithstanding the above restrictions, Mitsubishi may in its sole discretion, authorize use of the PRODUCT in one or more of the Prohibited Applications, provided that the usage of the PRODUCT is limited only for the specific applications agreed to by Mitsubishi and provided further that no special quality assurance or fail-safe, redundant or other safety features which exceed the general specifications of the PRODUCTs are required. For details, please contact the Mitsubishi representative in your region.
1
2
INTRODUCTION Thank you for purchasing the Mitsubishi Electric MELSEC-Q or -L series programmable controllers.
Before using this product, please read this manual and the relevant manuals carefully and develop familiarity with the
programming specifications to handle the product correctly.
When applying the program examples introduced in this manual to an actual system, ensure the applicability and confirm that
it will not cause system control problems.
MEMO
3
4
CONTENTS SAFETY PRECAUTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
CONDITIONS OF USE FOR THE PRODUCT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
INTRODUCTION. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
MANUALS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
TERMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
GENERIC TERMS AND ABBREVIATIONS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
CHAPTER 1 OVERVIEW 10
1.1 Purpose of This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
CHAPTER 2 FUNCTION TABLES 12
2.1 How to Read Function Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
2.2 Function Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Type conversion functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13
Standard functions of one numeric variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Standard arithmetic functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Standard bitwise Boolean functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Standard selection functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
Standard comparison functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Standard character string functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Functions of time data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Standard bistable function blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Standard edge detection function blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Standard counter function blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
Standard timer function blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18
2.3 Operator Tables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Arithmetic operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Logical operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
Comparison operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19
CHAPTER 3 CONFIGURATION OF FUNCTIONS 20
3.1 Configuration of Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20
3.2 Input Pins Variable Function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21
CHAPTER 4 HOW TO READ FUNCTIONS 22
CHAPTER 5 APPLICATION FUNCTIONS 24
5.1 Type Conversion Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Converting bit type to word (signed), double word (signed) type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24
Converting bit type to string type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26
Converting bit type to word (unsigned)/16-bit string, double word (unsigned)/32-bit string type. . . . . . . . . . . . . 28
Converting bit type to time type. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Converting word (signed) type to double word (signed) type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Converting double word (signed) type to word (signed) type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Converting word (signed), double word (signed) type to bit type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Converting word (signed), double word (signed) type to single-precision real type . . . . . . . . . . . . . . . . . . . . . . 38
Converting word (signed), double word (signed) type to double-precision real type. . . . . . . . . . . . . . . . . . . . . . 40
Converting word (signed), double word (signed) type to string type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
C O
N T
E N
T S
Converting word (signed), double word (signed) type to word (unsigned)/16-bit string type. . . . . . . . . . . . . . . . 45
Converting word (signed), double word (signed) type to double word (unsigned)/32-bit string type. . . . . . . . . . 47
Converting word (signed), double word (signed) type to BCD type. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Converting word (signed), double word (signed) type to time type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Converting single-precision real type to word (signed), double word (signed) type . . . . . . . . . . . . . . . . . . . . . . 54
Converting double-precision real type to word (signed), double word (signed) type. . . . . . . . . . . . . . . . . . . . . . 56
Converting single-precision real type to double-precision real type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Converting double-precision real type to single-precision real type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
Converting single-precision real type to string type. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
Converting word (unsigned)/16-bit string, double word (unsigned)/32-bit string type to bit type. . . . . . . . . . . . . 65
Converting word (unsigned)/16-bit string type to word (signed), double word (signed) type. . . . . . . . . . . . . . . . 67
Converting double word (unsigned)/32-bit string type to word (signed), double word (signed) type. . . . . . . . . . 69
Converting word (unsigned)/16-bit string type to double word (unsigned)/32-bit string type. . . . . . . . . . . . . . . . 71
Converting double word (unsigned)/32-bit string type to word (unsigned)/16-bit string type. . . . . . . . . . . . . . . . 73
Converting word (unsigned)/16-bit string, double word (unsigned)/32-bit string type to string type . . . . . . . . . . 75
Converting word (unsigned)/16-bit string, double word (unsigned)/32-bit string type to time type . . . . . . . . . . . 77
Converting string type to bit type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 79
Converting string type to word (signed), double word (signed) type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Converting string type to single-precision real type. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 84
Converting string type to word (unsigned)/16-bit string, double word (unsigned)/32-bit string type . . . . . . . . . . 88
Converting string type to time type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Converting string type to BCD type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Converting BCD type to word (signed), double word (signed) type. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Converting BCD type to string type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Converting time type to bit type. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Converting time type to word (signed), double word (signed) type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Converting time type to string type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 105
Converting time type to word (unsigned)/16-bit string, double word (unsigned)/32-bit string type . . . . . . . . . . 107
Converting bit array to word (signed) type, word (unsigned)/16-bit string type, double word (signed) type, double
word (unsigned)/32-bit string type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 109
Converting word (signed) type, word (unsigned)/16-bit string type, double word (signed) type, double word
(unsigned)/32-bit string type to bit array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
Bit array copy. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 113
Specified bit read of word (signed) type data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 115
Specified bit write of word (signed) type data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 117
Specified bit copy of word (signed) type data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 119
Nonessential type conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 121
5.2 Standard Functions of One Numeric Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
Absolute value. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 123
5.3 Standard Arithmetic Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 126
Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 128
Subtraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 130
Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 132
Remainder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 134
Exponentiation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 136
Move operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 138
5.4 Standard Bitwise Boolean Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
Boolean AND, boolean OR, boolean exclusive OR, and boolean NOT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 140
5.5 Standard Selection Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
Selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 144
5
6
Maximum/Minimum selection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 146
Upper/Lower limit control. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 149
Multiplexer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 151
5.6 Standard Comparison Functions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 153
5.7 Standard Character String Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
Extract mid string. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 155
String concatenation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 157
String insertion. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 159
String deletion . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 161
String replacement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
5.8 Functions of Time Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 166
Subtraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 168
Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 170
Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 172
5.9 Standard Bistable Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Standard bistable function blocks (Set-dominant) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 174
Standard bistable function blocks (Reset-dominant) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 176
5.10 Standard Edge Detection Function Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Rising edge detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 178
Falling edge detector . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 180
5.11 Standard Counter Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Up counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 182
Down counter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 184
Up/Down counter. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 186
Counter function blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 190
5.12 Standard Timer Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
Pulse timer. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 192
On delay timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 195
Off delay timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 198
Timer function blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 201
CHAPTER 6 OPERATOR 205
6.1 Arithmetic Operations. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Addition . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 205
Multiplication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 207
Subtraction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 208
Division . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 209
Remainder . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 211
Exponentiation. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 212
6.2 Logical Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
Boolean AND, boolean OR, boolean exclusive OR, and boolean NOT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 213
6.3 Comparison Operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
Comparison . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 215
INDEX 216
C O
N T
E N
T S
INSTRUCTION INDEX 218
REVISIONS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .220
WARRANTY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .221
TRADEMARKS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .222
7
8
MANUALS
RELEVANT MANUALS The manuals related to this product are listed below. Order each manual as needed, referring to the following lists.
Structured programming
Operation of GX Works2
Manual name
Description
MELSEC-Q/L/F Structured Programming Manual
(Fundamentals)
Methods and languages for structured programming
MELSEC-Q/L Structured Programming Manual (Common
Instructions)
Specifications and functions of common instructions, such as sequence instructions, basic
instructions, and application instructions, that can be used in structured programs
MELSEC-Q/L Structured Programming Manual (Special
Instructions)
Specifications and functions of special instructions, such as module dedicated instructions,
PID control instructions, and built-in I/O function instructions, that can be used in structured
programs
Manual name
Description
GX Works2 Version 1 Operating Manual (Common)
System configuration, parameter settings, and online operations of GX Works2, which are
common to Simple projects and Structured projects
GX Works2 Version 1 Operating Manual (Structured Project)
Operations, such as programming and monitoring in Structured projects, of GX Works2
GX Works2 Beginner's Manual (Structured Project)
Basic operations, such as programming, editing, and monitoring in Structured projects, of GX
Works2. This manual is intended for first-time users of GX Works2.
TERMS Unless otherwise specified, this manual uses the following terms.
GENERIC TERMS AND ABBREVIATIONS Unless otherwise specified, this manual uses the following generic terms and abbreviations.
Term Description
Application function A term for the functions, such as functions and function blocks, defined in IEC 61131-3.
It is executed by combinations of multiple common instructions in a programmable controller.
GX Works2 A programming tool used for setting up programmable controllers, programming, debugging, and maintenance
Generic term/abbreviation Description
Basic model QCPU Q00JCPU, Q00CPU, Q01CPU
Common instruction A sequence instruction, a basic instruction, an application instruction, a data link instruction, a multiple CPU
dedicated instruction, a multiple CPU high-speed transmission dedicated instruction, and a redundant system
instruction
High Performance model QCPU Q02CPU, Q02HCPU, Q06HCPU, Q12HCPU, Q25HCPU
IEC 61131-3 The IEC 61131-3 international standard
LCPU L02SCPU, L02SCPU-P, L02CPU, L02CPU-P, L06CPU, L06CPU-P, L26CPU, L26CPU-P, L26CPU-BT,
L26CPU-PBT
Personal computer A personal computer where Windows operates
Process CPU Q02PHCPU, Q06PHCPU, Q12PHCPU, Q25PHCPU
QCPU (Q mode) A Basic model QCPU, a High Performance model QCPU, a Process CPU, a Redundant CPU, and a Universal
model QCPU
Redundant CPU Q12PRHCPU, Q25PRHCPU
Special instruction A module dedicated instruction, a PID control instruction, a socket communication function instruction, a built-in
I/O function instruction, and a data logging function instruction
Universal model QCPU Q00UJCPU, Q00UCPU, Q01UCPU, Q02UCPU, Q03UDCPU, Q03UDVCPU, Q03UDECPU, Q04UDHCPU,
Q04UDVCPU, Q04UDPVCPU, Q04UDEHCPU, Q06UDHCPU, Q06UDVCPU, Q06UDPVCPU, Q06UDEHCPU,
Q10UDHCPU, Q10UDEHCPU, Q13UDHCPU, Q13UDVCPU, Q13UDPVCPU, Q13UDEHCPU, Q20UDHCPU,
Q20UDEHCPU, Q26UDHCPU, Q26UDVCPU, Q26UDPVCPU, Q26UDEHCPU, Q50UDEHCPU,
Q100UDEHCPU
9
10
1 OVERVIEW
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 following.
Page 8 RELEVANT MANUALS
Operation of GX Works2
Operations in each programming language For details of instructions used in each programming language, refer to the following.
Page 11 Details of instructions in each programming language
*1 MELSAP3 and FX series SFC only
Purpose Overview Detail
Installation Learning the operating environment
and installation method
GX Works2 Installation Instructions
Learning a USB driver installation
method
GX Works2 Version 1 Operating Manual
(Common)
Operation of GX
Works2
Learning all functions of GX Works2 GX Works2 Version 1 Operating Manual
(Common)
Learning the project types and
available languages in GX Works2
Learning the basic operations and
operating procedures when creating a
simple project for the first time
GX Works2 Beginner's Manual (Simple
Project)
Learning the basic operations and
operating procedures when creating a
structured project for the first time
GX Works2 Beginner's Manual
(Structured Project)
Learning the operations of available
functions regardless of project type.
GX Works2 Version 1 Operating Manual
(Common)
Learning the functions and operation
methods for programming
GX Works2 Version 1 Operating Manual
(Common)
GX Works2 Version 1 Operating Manual
(Simple Project)
GX Works2 Version 1 Operating Manual
(Structured Project)
Learning data setting methods for
intelligent function module
GX Works2 Version 1 Operating Manual
(Intelligent Function Module)
Purpose OVERVIEW Detail
Simple Project Ladder GX Works2 Beginner's Manual (Simple
Project)
GX Works2 Version 1 Operating Manual
(Simple Project)
SFC GX Works2 Beginner's Manual (Simple
Project)*1
ST GX Works2 Beginner's Manual
(Structured Project)
GX Works2 Version 1 Operating Manual
(Structured Project)
Structured Project/
FBD
Ladder GX Works2 Beginner's Manual (Simple
Project)
GX Works2 Version 1 Operating Manual
(Simple Project)
SFC GX Works2 Beginner's Manual (Simple
Project)*1
Structured ladder/FBD GX Works2 Beginner's Manual
(Structured Project)
GX Works2 Version 1 Operating Manual
(Structured Project)ST
1 OVERVIEW 1.1 Purpose of This Manual
1
Purpose Overview Detail
All languages Learning details of programmable
controller CPU error codes, special
relays, and special registers
Use's Manual (Hardware Design,
Maintenance and Inspection) for the CPU
module used
Using ladder
language
Learning the types and details of
common instructions
MELSEC-Q/L Programming Manual
(Common Instruction)
Learning the types and details of
instructions for intelligent function
modules
Manual for the intelligent function module
used
Learning the types and details of
instructions for network modules
Manual for the network module used
Learning the types and details of
instructions for the PID control function
MELSEC-Q/L/QnA Programming
Manual (PID Control Instructions)
Learning the types and details of the
process control instructions
MELSEC-Q Programming/Structured
Programming Manual (Process Control
Instructions)
Using SFC
language
Learning details of specifications,
functions, and instructions of SFC
(MELSAP3)
MELSEC-Q/L/QnA Programming Manual
(SFC)
Using structured
ladder/FBD/ST
language
Learning the fundamentals for creating
a structured program
MELSEC-Q/L/F Structured Programming
Manual (Fundamentals)
Learning the types and details of
common instructions
MELSEC-Q/L Structured Programming
Manual (Common Instructions)
Learning the types and details of
instructions for intelligent function
modules
MELSEC-Q/L Structured Programming
Manual (Special Instructions)
Manual for the intelligent function module
used
Learning the types and details of
instructions for network modules
Manual for the network module used
Learning the types and details of
instructions for the PID control function
MELSEC-Q/L/QnA Programming
Manual (PID Control Instructions)
Learning the types and details of
application functions
MELSEC-Q/L Structured Programming
Manual (Application Functions)
Learning the types and details of the
process control instructions
MELSEC-Q Programming/Structured
Programming Manual (Process Control
Instructions)
1 OVERVIEW 1.1 Purpose of This Manual 11
12
2 FUNCTION TABLES
2.1 How to Read Function Tables Function tables in Page 13 Function Tables are shown in the following format.
Description
Indicates the functions used in a program. 'Function name(_E)' is used as a function with EN/ENO. Without "_E", it is
used as a a function without EN/ENO.
Indicates the arguments of the function.
Indicates the processing details of each function.
Indicates the references on which the functions are explained.
Symbol Name Description
(s) Source Stores data before operation.
(d) Destination Indicates the destination of data after operation.
(Number of pins variable) Allows the number of (s) (source) to be changed in the range from 2 to 28.
Changing the number of pins
Adding a pin
Deleting a pin
2 FUNCTION TABLES 2.1 How to Read Function Tables
2
2.2 Function Tables
Type conversion functions
Function name Argument Processing details Reference
BOOL_TO_INT(_E) (s), (d) Converts bit type data into word (signed) or double word (signed) type
data.
Page 24 Converting bit type to
word (signed), double word
(signed) type BOOL_TO_DINT(_E) (s), (d)
BOOL_TO_STR(_E) (s), (d) Converts bit type data into string type data. Page 26 Converting bit type to
string type
BOOL_TO_WORD(_E) (s), (d) Converts bit type data into word (unsigned)/16-bit string or double word
(unsigned)/32-bit string type date.
Page 28 Converting bit type to
word (unsigned)/16-bit string,
double word (unsigned)/32-bit
string type
BOOL_TO_DWORD(_E) (s), (d)
BOOL_TO_TIME(_E) (s), (d) Converts bit type data into time type data. Page 30 Converting bit type to
time type
INT_TO_DINT(_E) (s), (d) Converts word (signed) type data into double word (signed) type data. Page 32 Converting word
(signed) type to double word
(signed) type
DINT_TO_INT(_E) (s), (d) Converts double word (signed) type data into word (signed) type data. Page 34 Converting double
word (signed) type to word
(signed) type
INT_TO_BOOL(_E) (s), (d) Converts word (signed) or double word (signed) type data into bit type
data.
Page 36 Converting word
(signed), double word (signed)
type to bit type DINT_TO_BOOL(_E) (s), (d)
INT_TO_REAL(_E) (s), (d) Converts word (signed) or double word (signed) type data into single-
precision real type data.
Page 38 Converting word
(signed), double word (signed)
type to single-precision real
type
DINT_TO_REAL(_E) (s), (d)
INT_TO_LREAL(_E) (s), (d) Converts word (signed) or double word (signed) type data into double-
precision real type data.
Page 40 Converting word
(signed), double word (signed)
type to double-precision real
type
DINT_TO_LREAL(_E) (s), (d)
INT_TO_STR(_E) (s), (d) Converts word (signed) or double word (signed) type data into string
type data.
Page 42 Converting word
(signed), double word (signed)
type to string type DINT_TO_STR(_E) (s), (d)
INT_TO_WORD(_E) (s), (d) Converts word (signed) or double word (signed) type data into word
(unsigned)/16-bit string type data.
Page 45 Converting word
(signed), double word (signed)
type to word (unsigned)/16-bit
string type
DINT_TO_WORD(_E) (s), (d)
INT_TO_DWORD(_E) (s), (d) Converts word (signed) or double word (signed) type data into double
word (unsigned)/32-bit string type data.
Page 47 Converting word
(signed), double word (signed)
type to double word (unsigned)/
32-bit string type
DINT_TO_DWORD(_E) (s), (d)
INT_TO_BCD(_E) (s), (d) Converts word (signed) or double word (signed) type data into BCD
type data.
Page 49 Converting word
(signed), double word (signed)
type to BCD type DINT_TO_BCD(_E) (s), (d)
INT_TO_TIME(_E) (s), (d) Converts word (signed) or double word (signed) type data into time type
data.
Page 52 Converting word
(signed), double word (signed)
type to time type DINT_TO_TIME(_E) (s), (d)
REAL_TO_INT(_E) (s), (d) Converts single-precision real type data into word (signed) or double
word (signed) type data.
Page 54 Converting single-
precision real type to word
(signed), double word (signed)
type
REAL_TO_DINT(_E) (s), (d)
LREAL_TO_INT(_E) (s), (d) Converts double-precision real type data into word (signed) or double
word (signed) type data.
Page 56 Converting double-
precision real type to word
(signed), double word (signed)
type
LREAL_TO_DINT(_E) (s), (d)
REAL_TO_LREAL(_E) (s), (d) Converts single-precision real type data into double-precision real type
data.
Page 58 Converting single-
precision real type to double-
precision real type
2 FUNCTION TABLES 2.2 Function Tables 13
14
LREAL_TO_REAL(_E) (s), (d) Converts double-precision real type data into single-precision real type
data.
Page 60 Converting double-
precision real type to single-
precision real type
REAL_TO_STR(_E) (s), (d) Converts single-precision real type data into string type (exponential
form) data.
Page 62 Converting single-
precision real type to string type
WORD_TO_BOOL(_E) (s), (d) Converts word (unsigned)/16-bit string or double word (unsigned)/32-bit
string type data into bit type data.
Page 65 Converting word
(unsigned)/16-bit string, double
word (unsigned)/32-bit string
type to bit type
DWORD_TO_BOOL(_E) (s), (d)
WORD_TO_INT(_E) (s), (d) Converts word (unsigned)/16-bit string type data into word (signed) or
double word (signed) type data.
Page 67 Converting word
(unsigned)/16-bit string type to
word (signed), double word
(signed) type
WORD_TO_DINT(_E) (s), (d)
DWORD_TO_INT(_E) (s), (d) Converts double word (unsigned)/32-bit string type data into word
(signed) or double word (signed) type data.
Page 69 Converting double
word (unsigned)/32-bit string
type to word (signed), double
word (signed) type
DWORD_TO_DINT(_E) (s), (d)
WORD_TO_DWORD(_E) (s), (d) Converts word (unsigned)/16-bit string type data into double word
(unsigned)/32-bit string type data.
Page 71 Converting word
(unsigned)/16-bit string type to
double word (unsigned)/32-bit
string type
DWORD_TO_WORD(_E) (s), (d) Converts double word (unsigned)/32-bit string type data into word
(unsigned)/16-bit string type data.
Page 73 Converting double
word (unsigned)/32-bit string
type to word (unsigned)/16-bit
string type
WORD_TO_STR(_E) (s), (d) Converts word (unsigned)/16-bit string or double word (unsigned)/32-bit
string type data into string type data.
Page 75 Converting word
(unsigned)/16-bit string, double
word (unsigned)/32-bit string
type to string type
DWORD_TO_STR(_E) (s), (d)
WORD_TO_TIME(_E) (s), (d) Converts word (unsigned)/16-bit string or double word (unsigned)/32-bit
string type data into time type data.
Page 77 Converting word
(unsigned)/16-bit string, double
word (unsigned)/32-bit string
type to time type
DWORD_TO_TIME(_E) (s), (d)
STR_TO_BOOL(_E) (s), (d) Converts string type data into bit type data. Page 79 Converting string type
to bit type
STR_TO_INT(_E) (s), (d) Converts string type data into word (signed) or double word (signed)
type data.
Page 81 Converting string type
to word (signed), double word
(signed) type STR_TO_DINT(_E) (s), (d)
STR_TO_REAL(_E) (s), (d) Converts string type data into single-precision real type data. Page 84 Converting string type
to single-precision real type
STR_TO_WORD(_E) (s), (d) Converts string type data into word (unsigned)/16-bit string or double
word (unsigned)/32-bit string type data.
Page 88 Converting string type
to word (unsigned)/16-bit string,
double word (unsigned)/32-bit
string type
STR_TO_DWORD(_E) (s), (d)
STR_TO_TIME(_E) (s), (d) Converts string type data into time type data. Page 91 Converting string type
to time type
STR_TO_BCD(_E) (s), (d) Converts string type data into BCD type data. Page 93 Converting string type
to BCD type