(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 dateManual numberRevision
Jul., 2008SH(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.
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.
REVISIONS....................................................................................................................................................... A - 2
INTRODUCTION............................................................................................................................................... A - 3
CONTENTS ...................................................................................................................................................... A - 3
MANUALS......................................................................................................................................................... A - 6
1. OVERVIEW1 - 1 to 1 - 4
1.1 Purpose of This Manual1 - 2
1.2 Generic Terms and Abbreviations in This Manual1 - 4
2. FUNCTION TABLES2 - 1 to 2 - 6
2.1 How to Read Function Tables2 - 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. FUNCTIONS3 - 1 to 3 - 12
3.1 Input Pins Variable Function3 - 2
3.2 Functions with EN3 - 3
3.3 Labels3 - 4
3.3.1 Global labels .................................................................................................................................. 3 - 4
3.3.2 Local labels.................................................................................................................................... 3 - 4
3.7.1 Precautions on assigning a name................................................................................................ 3 - 10
4. HOW TO READ FUNCTIONS4 - 1 to 4 - 4
5. APPLICATION FUNCTIONS5 - 1 to 5 - 218
5.1 Type Conversion Functions5 - 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
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.
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
OutlineOutline
Outline
Details
OutlineOutline
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
DetailsDetails
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
DetailsDetails
DetailsDetails
DetailsDetails
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 Works2Generic product name for the SWnDNC-GXW2-E (n: version)
CPU moduleGeneric term for the High Performance model QCPU and Universal model QCPU
High Performance model
QCPU
Universal model QCPU
Personal computer
IEC61131-3Abbreviation for the IEC 61131-3 international standard
Common instructionGeneric term for the sequence instructions, basic instructions, and application instructions
Special instructionGeneric 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
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
IInput(Omitted)Bit
QOutputXBit
%
MInternal
Device nameDevice numbe
Table 3.5.2-1 Address definition specifications
2nd character: data size
WWord (16 bits)
DDouble word (32 bits)
LLong 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)
X0W35F
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
PositionData
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
BinaryAppend '2#' in front of a binary number.2#0010, 2#01101010
Octal
notation
DecimalDirectly 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 methodExample
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)
CategoryCharacter string
VAR, VAR_RETAIN, VAR_ACCESS, VAR_CONSTANT, VAR_CONSTANT_RETAIN, VAR_INPUT, VAR_INPUT_RETAIN,
Class identifier
Data type
Data type hierachyANY, 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 operatorNOT, 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