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
Loading...
+ 238 hidden pages