MELSEC-Q/L/F Structured Programming Manual (Fundamentals)
MELSEC-Q/L/F Structured Programming Manual (Fundamentals)
MELSEC-Q/L/F Structured Programming Manual (Fundamentals)
1
INTRODUCTION
Thank you for purchasing the Mitsubishi Electric MELSEC-Q, -L, or -F 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.
■What is GX Works2?
GX Works2 is a software package used for editing and debugging sequence programs, monitoring programmable controller
CPUs, and other operations. It runs on a personal computer in the Microsoft Windows Operating System environment.
Created sequence programs are managed in units of 'projects' for each programmable controller CPU. Projects are broadly
divided into 'Simple project' and 'Structured project'.
This manual explains the basic programming by referring the Structured project in GX Works2.
2
MEMO
3
CONTENTS
SAFETY PRECAUTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
CONDITIONS OF USE FOR THE PRODUCT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
MANUALS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .6
TERMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
CHAPTER 1 OVERVIEW 8
1.1 Purpose of This Manual . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
1.2 Features of Structured Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4
Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52
Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53
Correspondence between devices and addresses . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
4.6 Index Setting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
4.7 Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 70
User libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
4.8 Precautions on Assigning a Name . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 72
CONTENTS
5.1 ST . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Standard format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 73
Operators in ST language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 74
Syntax in ST language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 75
Calling functions in ST language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Calling function blocks in ST language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 81
Precautions when using conditional syntax and iteration syntax. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 82
Operations when the master control instruction is used . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 85
5.2 Structured Ladder/FBD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Standard format. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86
Ladder symbols in structured ladder/FBD language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 87
Executing order . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 89
Ladder branches and compilation results . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 91
Precautions on creating programs with structured ladder/FBD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
APPENDICES 93
Appendix 1 Correspondence Between Generic Data Types and Devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Internal user device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Internal system device. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 95
Link direct device. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Intelligent function module device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Index register. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
File register . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Nesting . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 98
Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
String constant. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Appendix 2 Character Strings That Cannot Be Used in Label Names and Data Names . . . . . . . . . . . . . . . . . . . 100
Appendix 3 Recreating Ladder Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Procedure for creating a structured program. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Example of creating a structured program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
INDEX 108
REVISIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 110
WARRANTY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
TRADEMARKS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 112
5
MANUALS
Related Manuals
The manuals related to this product are listed below. Please place an order as needed.
■Structured programming
Manual name Description
<Manual number>
MELSEC-Q/L Structured Programming Manual (Common Specifications and functions of common instructions, such as sequence instructions, basic
Instructions) instructions, and application instructions, that can be used in structured programs
<SH-080783ENG>
MELSEC-Q/L Structured Programming Manual (Application Specifications and functions of application functions that can be used in structured programs
Functions)
<SH-080784ENG>
MELSEC-Q/L Structured Programming Manual (Special Specifications and functions of special instructions, such as module dedicated instructions,
Instructions) PID control instructions, and built-in I/O function instructions, that can be used in structured
<SH-080785ENG> programs
FXCPU Structured Programming Manual [Device & Common] Devices and parameters for structured programming provided in GX Works2
<JY997D26001>
FXCPU Structured Programming Manual [Basic & Applied Sequence instructions for structured programming provided in GX Works2
Instruction]
<JY997D34701>
FXCPU Structured Programming Manual [Application Application functions for structured programming provided in GX Works2
Functions]
<JY997D34801>
■Operation of GX Works2
Manual name Description
<Manual number>
GX Works2 Version 1 Operating Manual (Common) System configuration, parameter settings, and online operations of GX Works2, which are
<SH-080779ENG> 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
<SH-080781ENG>
GX Works2 Beginner's Manual (Structured Project) Basic operations, such as programming, editing, and monitoring in Structured projects, of GX
<SH-080788ENG> Works2. This manual is intended for first-time users of GX Works2.
6
TERMS
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.
Term Description
Application function A generic term for the functions, such as functions and function blocks, defined in IEC 61131-3.
(The functions are executed with a set of common instructions in a programmable controller.)
Basic model QCPU A generic term for the Q00JCPU, Q00CPU, and Q01CPU
Common instruction A generic term for the sequence instructions, basic instructions, application instructions, data link instructions,
multiple CPU dedicated instructions, multiple CPU high-speed transmission dedicated instructions, and
redundant system instructions
CPU module A generic term for the QCPU (Q mode), LCPU, and FXCPU
FXCPU A generic term for MELSEC-FX series programmable controllers
(FX0S, FX0, FX0N, FX1, FX1S, FX1N, FX1NC, FX2, FX2C, FX2N, FX2NC, FX3S, FX3G, FX3GC, FX3U, FX3UC)
GX Developer The product name of the software package for the MELSEC programmable controllers
GX Works2
High Performance model QCPU A generic term for the Q02CPU, Q02HCPU, Q06HCPU, Q12HCPU, and Q25HCPU
High-speed Universal model QCPU A generic term for the Q03UDVCPU, Q04UDVCPU, Q06UDVCPU, Q13UDVCPU, and Q26UDVCPU
IEC 61131-3 An abbreviation for the IEC 61131-3 international standard
LCPU A generic term for the L02SCPU, L02SCPU-P, L02CPU, L02CPU-P, L06CPU, L06CPU-P, L26CPU, L26CPU-P,
L26CPU-BT, and L26CPU-PBT
Personal computer The generic term for personal computers where Windows operates
Process CPU A generic term for the Q02PHCPU, Q06PHCPU, Q12PHCPU, and Q25PHCPU
QCPU (Q mode) A generic term for the Basic model QCPU, High Performance model QCPU, Process CPU, Redundant CPU,
and Universal model QCPU
QnU(D)(H)CPU A generic term for the Q02UCPU, Q03UDCPU, Q04UDHCPU, Q06UDHCPU, Q10UDHCPU, Q13UDHCPU,
Q20UDHCPU, and Q26UDHCPU
QnUDE(H)CPU A generic term for the Q03UDECPU, Q04UDEHCPU, Q06UDEHCPU, Q10UDEHCPU, Q13UDEHCPU,
Q20UDEHCPU, Q26UDEHCPU, Q50UDEHCPU, and Q100UDEHCPU
QnUDPVCPU A generic term for the Q04UDPVCPU, Q06UDPVCPU, Q13UDPVCPU, and Q26UDPVCPU
QnUDVCPU A generic term for the Q03UDVCPU, Q04UDVCPU, Q06UDVCPU, Q13UDVCPU, and Q26UDVCPU
Redundant CPU A generic term for the Q12PRHCPU and Q25PRHCPU
Special instruction A generic term for the module dedicated instructions, PID control instructions, socket communication function
instructions, built-in I/O function instructions, and data logging function instructions
Universal model Process CPU A generic term for the Q04UDPVCPU, Q06UDPVCPU, Q13UDPVCPU, and Q26UDPVCPU
Universal model QCPU A generic term for the 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, and Q100UDEHCPU
7
1 OVERVIEW
This manual describes program configurations and content for creating sequence programs using a structured programming
method, and provides basic knowledge for writing programs.
Operation of GX Works2
Purpose Summary Detail
Installation Learning the operating environment GX Works2 Installation Instructions
and installation method
Learning a USB driver installation GX Works2 Version 1 Operating Manual
method (Common)
Operation of GX Learning all functions of GX Works2 GX Works2 Version 1 Operating Manual
Works2 (Common)
Learning the project types and
available languages in GX Works2
Learning the basic operations and GX Works2 Beginner's Manual (Simple
operating procedures when creating a Project)
simple project for the first time
Learning the basic operations and GX Works2 Beginner's Manual
operating procedures when creating a (Structured Project)
structured project for the first time
Learning the operations of available GX Works2 Version 1 Operating Manual
functions regardless of project type. (Common)
Learning the functions and operation GX Works2 Version 1 Operating Manual GX Works2 Version 1 Operating Manual
methods for programming (Common) (Simple Project)
GX Works2 Version 1 Operating Manual
(Structured Project)
Learning data setting methods for GX Works2 Version 1 Operating Manual
intelligent function module (Intelligent Function Module)
1 OVERVIEW
8 1.1 Purpose of This Manual
Details of instructions in each programming language
■QCPU (Q mode)/LCPU 1
Purpose Summary Detail
All languages Learning details of programmable User's Manual (Hardware Design,
controller CPU error codes, special Maintenance and Inspection) for the CPU
relay areas, and special register areas module used
Using ladder Learning the types and details of MELSEC-Q/L Programming Manual
language common instructions (Common Instruction)
Learning the types and details of Manual for the intelligent function module
instructions for intelligent function used
modules
Learning the types and details of Manual for the network module used
instructions for network modules
Learning the types and details of MELSEC-Q/L/QnA Programming Manual
instructions for the PID control function (PID Control Instructions)
Learning the types and details of the MELSEC-Q Programming/Structured
process control instructions Programming Manual (Process Control
Instructions)
Using SFC Learning details of specifications, MELSEC-Q/L/QnA Programming Manual
language functions, and instructions of SFC (SFC)
(MELSAP3)
Using structured Learning the fundamentals for creating MELSEC-Q/L/F Structured Programming
ladder/FBD/ST a structured program Manual (Fundamentals)
language
Learning the types and details of MELSEC-Q/L Structured Programming
common instructions Manual (Common Instructions)
Learning the types and details of MELSEC-Q/L Structured Programming Manual for the intelligent function module
instructions for intelligent function Manual (Special Instructions) used
modules
Learning the types and details of Manual for the network module used
instructions for network modules
Learning the types and details of MELSEC-Q/L/QnA Programming Manual
instructions for the PID control function (PID Control Instructions)
Learning the types and details of MELSEC-Q/L Structured Programming
application functions Manual (Application Functions)
Learning the types and details of the MELSEC-Q Programming/Structured
process control instructions Programming Manual (Process Control
Instructions)
■FXCPU
Purpose Summary Detail
Using ladder Learning the types and details of basic/ Programming manual for the FXCPU
language application instructions, descriptions of used
devices and parameters
Using SFC Learning details of specifications,
language functions, and instructions of SFC
Using structured Learning the fundamentals for creating MELSEC-Q/L/F Structured Programming
ladder/FBD/ST a structured program Manual (Fundamentals)
language
Learning the descriptions of devices, FXCPU Structured Programming Manual
parameters, and error codes [Device & Common]
Learning the types and details of FXCPU Structured Programming Manual
sequence instructions [Basic & Applied Instruction]
Learning the types and details of FXCPU Structured Programming Manual
application functions [Application Functions]
1 OVERVIEW
1.1 Purpose of This Manual 9
1.2 Features of Structured Programs
This section explains the features of structured programs.
Structured design
A structured design is a method to program control content performed by a programmable controller CPU, which are divided
into small processing units (components) to create hierarchical structures. A user can design programs knowing the
component structures of sequence programs by using the structured programming.
The following are the advantages of creating hierarchical programs.
• A user can start programming by planning the outline of a program, then gradually work into detailed designs.
• Programs stated at the lowest level of a hierarchical design are extremely simple and each program has a high degree of
independence.
The following are the advantages of creating structured programs.
• The process of each component is clarified, allowing a good perspective of the program.
• Programs can be divided and created by multiple programmers.
• Program reusability is increased, and it improves the efficiency in development.
1 OVERVIEW
10 1.2 Features of Structured Programs
2 STRUCTURED DESIGN OF SEQUENCE
PROGRAMS
2.1 Hierarchical Sequence Program 2
The hierarchy is to create a sequence program by dividing control functions performed in a programmable controller CPU into
a number of levels.
In higher levels, the processing order and timing in a fixed range is controlled. With each move from a higher level to a lower
level, control content and processes are progressively subdivided within a fixed range, and specific processes are described
in lower levels.
In the Structured project, hierarchical sequence programs are created with the configuration that states the highest level as
the project, followed by program files, tasks, and POUs (abbreviation for Program Organization Units).
Project
Initial process
Initial process
Lamp test
Lamp test
Conveyor drive A
Data process A
Conveyor drive B
Data process A
Program file (Station B)
Data process B
Indicator output
Task (Indicator control)
Indicator output
MUL
MUL
Calls Process A
DIV
MUL Process A
DIV
Structured
program
MUL
Divided Control a
2. Creating POUs
3
• Create POUs.
• Define global labels.
• Define local labels.
• Edit the programs of each POU.
3. Setting the programs
Register the POUs in the tasks.
Task 1 Task 1
Program 1 Function block 1
Program 1
Program 2
Program 2 Function block 2
Sequence
program
Task 2 Task 2
Program 3 Function 1
Program 3
Program 4
Program 4 Function 2
Project
POU
Task Program Task
POU POU
Program Program
POU
Program
4 PROGRAM CONFIGURATION
4.1 Overview of Program Configuration 15
Project
A project is a generic term for data (such as programs and parameters) to be executed in a programmable controller CPU.
One or more program files need to be created in a project.
Program files
One or more tasks need to be created in a program file. (Created tasks are executed under the control of the program file.)
The execution types (such as scan execution and fixed scan execution) for executing program files in a programmable
controller CPU are set in the program setting of the parameter.
For details of the execution types set in the parameter, refer to the user's manual for the CPU module used.
Project
POU
Task Program Task
POU POU
Program Program
POU
Program
4 PROGRAM CONFIGURATION
16 4.1 Overview of Program Configuration
Tasks
A task is an element that contains multiple POUs, and it is registered to a program file. One or more programs of POU need to
be registered in a task. (Functions and function blocks cannot be registered in a task.)
Project
POU
Program
POU
Program
POU
Program 4
POU
Task Program Task
POU POU
Program Program
POU
Program
■Event
Executes tasks when values are set to the corresponding devices or labels.
■Interval
Executes tasks in a specified cycle.
Priority
A priority can be set for each task execution.
When executing conditions of multiple tasks are met simultaneously, the tasks are executed according to the set priority.
• Tasks are executed in the order from the smallest priority level number.
• Tasks set with a same priority level number are executed in the order of task data name.
4 PROGRAM CONFIGURATION
4.1 Overview of Program Configuration 17
4.2 POUs
A POU (abbreviation for Program Organization Unit) is a program component defined by each function.
Types of POU
The following three types can be selected for each POU according to the content to be defined.
• Program
• Function
• Function block
Each POU consists of a program and local labels*1.
A process can be described in a programming language that suits the control function for each POU.
Project
Program file
Task
Registration
POU
Program
POU folder
POU
Program
POU
Function
POU
Function block
*1 Local labels are labels that can be used only in programs of declared POUs. For details of local labels, refer to the following section.
Page 29 Local labels
4 PROGRAM CONFIGURATION
18 4.2 POUs
Program
A program is an element that is stated at the highest level of POU. Functions, function blocks, and operators are used to edit
programs.
Program Function
Function block
Operator
4
Sequence programs executed in a programmable controller CPU are created by programs of POU. For a simplest sequence
program, only one program needs to be created and registered to a task in order to be executed in a programmable controller
CPU.
Programs can be described in the ST or structured ladder/FBD language.
Functions
Functions and operators are used to edit functions. Functions can be used by calling them from programs, functions, or
function blocks.
Function Function
Operator
Functions always output same processing results for same input values. By defining simple and independent algorithms that
are frequently used, functions can be reused efficiently.
Functions can be described in the ST or structured ladder/FBD language.
4 PROGRAM CONFIGURATION
4.2 POUs 19
Function blocks
Functions, function blocks, and operators are used to edit function blocks. Function blocks can be used by calling them from
programs or function blocks. Note that they cannot be called from functions.
Function block
Operator
Function blocks can retain the input status since they can store values in internal and output variables. Since they use
retained values for the next processing, they do not always output the same results even with the same input values.
Function blocks can be described in the ST or structured ladder/FBD language.
Instantiation
Function blocks need to be instantiated to be used in programs. ( Page 24 Functions, function blocks, and operators)
Instances are variables representing devices assigned to labels of function blocks. Devices are automatically
assigned when instances are created with local labels.
■Number of function blocks that can be called from within a function block.
• Macro type function blocks: No limit*1
• Subroutine type function block: No limit*2
*1 There is no limit as long as the memory capacity is not exceeded.
*2 There is no limit as long as the upper limit of pointer in the auto device setting (default: 2048) is not exceeded. Note, depending on the
program, that the upper limit is less than usual because the pointer device is used for other than subroutine type function blocks.
4 PROGRAM CONFIGURATION
20 4.2 POUs
Operators
Operators can be used by calling them from programs, functions, or function blocks. Operators cannot be edited.
Operators always output same processing results for the same input values.
4 PROGRAM CONFIGURATION
4.2 POUs 21
Ladder blocks
In the structured ladder/FBD language, a program is divided into units of ladder blocks.
In the ST language, ladder blocks are not used.
4 PROGRAM CONFIGURATION
22 4.2 POUs
Programming languages for POUs
Two types of programming language are available for programs of POU.
The following explains the features of each programming language.
• FBD
4 PROGRAM CONFIGURATION
4.2 POUs 23
Functions, function blocks, and operators
The following table shows differences among functions, function blocks, and operators.
Item Function Function block Operator
Output variable assignment Cannot be assigned Can be assigned Cannot be assigned
Internal variable Not used Used Not used
Creating instances Not necessary Necessary Not necessary
Ex.
The following table shows the examples.
Function Function block Operator
4 PROGRAM CONFIGURATION
24 4.2 POUs
Internal variables
A function does not use internal variables. It uses devices assigned directly to each input variable and repeats operations.
A program that outputs the total of three input variables
Ex.
When using a function (FUN1)
Function
X0
D109 D109
FUN1 D120 4
D110 D110
D111 D111
A function block uses internal variables. Different devices are assigned to the internal variables for each instance of function
blocks.
Ex.
When using function blocks
Instance A Instance B
Function block Function block
4 PROGRAM CONFIGURATION
4.2 POUs 25
Creating instances
When using function blocks, create instances to reserve internal variables. Variables can be called from programs and other
function blocks by creating instances for function blocks.
To create an instance, declare as a label in a global label or local label of POU that uses function blocks. Same function
blocks can be instantiated with different names in a single POU.
Instance A
Function block
D6200
D10 Input label1 D6203
D6201 Output label D13
D11 Input label2
D6202 D6204
D12 Input label3 Local label
Function blocks perform operations using internal variables assigned to each instance.
If the same function is called in the circuit multiple times, the value of internal variables or output variables is
overwritten everytime the function is called. To hold the value of internal variables or output variables when
the function is called, edit programs to use function blocks or to save the values as different valuables.
4 PROGRAM CONFIGURATION
26 4.2 POUs
EN and ENO
An EN (enable input) and ENO (enable output) can be appended to a function and function block to control their execution.
A Boolean variable used as an executing condition of a function is set to an EN.
A function with an EN is executed only when the executing condition of the EN is TRUE.
A Boolean variable used as an output of function execution result is set to an ENO.
The following table shows the status of ENO and the operation result according to the status of EN.
EN ENO Operation result 4
TRUE (Operation execution) TRUE (No operation error) Operation output value
FALSE (Operation error) Undefined value
FALSE (Operation stop) FALSE Undefined value
Ex.
Usage example of EN and ENO
(1)
(5)
(2)
(5)
(3)
(5)
(4) (4)
(5)
4 PROGRAM CONFIGURATION
4.2 POUs 27
Precautions
The following example shows that the operation results an undefined value.
When Variable_1 is OFF, the MOV or SET instruction is executed though the ADD_E or TEST instruction is not executed.
Even though Variable_1 is OFF, a value may be set in D2 by the MOV instruction or M1 may turn ON by the SET instruction.
Input ENO of the first instruction to EN of the next instruction not to perform the sequential operation when EN is OFF.
4 PROGRAM CONFIGURATION
28 4.2 POUs
4.3 Labels
Labels include global labels and local labels.
Global labels
The global labels are labels that can be used in programs 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.
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. 4
For the local labels, the user does not need to specify devices. Devices are assigned automatically at compilation.
4 PROGRAM CONFIGURATION
4.3 Labels 29
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.
Class Description Applicable POU
Program Function Function
block
VAR_GLOBAL Common label that can be used in programs and function blocks
VAR_GLOBAL_CONSTANT Common constant that can be used in programs and function blocks
VAR Label that can be used within the range of declared POUs. This label
cannot be used in other POUs.
VAR_CONSTANT Constant that can be used within the range of declared POUs. This
constant cannot be used in other POUs.
VAR_RETAIN*1 Latch type label that can be used within the range of declared POUs This
label cannot be used in other POUs.
VAR_INPUT Label that receives a value. This label cannot be changed in a POU.
VAR_OUTPUT Label that outputs a value from a function block
VAR_IN_OUT Local label that receives a value and outputs the value from a POU. This
label can be changed in a POU.
VAR_INPUT VAR_OUTPUT
VAR_IN_OUT
4 PROGRAM CONFIGURATION
30 4.3 Labels
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_int1 and g_int2 of the DMOV instruction.
X0 DMOV
EN ENO
g_int1 s d g_int2
Ex.
Using the arguments of the DMOV instruction as global labels
Set the Class, Label Name, Data Type, Device, and Address.
4
Ex.
Using the arguments of the DMOV instruction as local labels
Set the Class, Label Name, and Data Type.
4 PROGRAM CONFIGURATION
4.3 Labels 31
Data types
Labels are classified into several data types according to the bit length, processing method, or value range.
The following data types are available.
• Elementary data types
• Generic data types
*1 The following data types cannot be used for the structured ladder/FBD/ST language. They can be only used for the ladder language.
Timer data type: Handles programmable controller CPU timer devices (T).
Retentive timer data type: Handles programmable controller CPU retentive timer devices (ST).
Counter data type: Handles programmable controller CPU counter devices (C).
Pointer data type: Handles programmable controller CPU pointer devices (P).
*2 The FX3S, FX3G, FX3GC, FX3U, and FX3UC support this data type.
*3 The Universal model QCPU and the LCPU support this data type.
*4 The FX3U and FX3UC support this data type.
*5 This data type is used in time type operation instructions of application function. For details of the application functions, refer to the
following.
MELSEC-Q/L Structured Programming Manual (Application Functions)
FXCPU Structured Programming Manual [Application Functions]
4 PROGRAM CONFIGURATION
32 4.3 Labels
Generic data types
Generic data type is the data type of labels summarizing some elementary data types. Data type name starts with 'ANY'. ANY
data types are used when multiple data types are allowed for function arguments and return values.
Labels defined in generic data types can be used in any sub-level data type.
For example, if the argument of a function is ANY_NUM data type, desired data type for an argument can be specified from
word (signed) type, double word (signed) type, single-precision real type, and double-precision real type.
Arguments of functions and instructions are described using generic data types, in order to be used for various different data
types.
The following figure shows the types of generic data type and their corresponding elementary data types.
ANY
4
ANY_SIMPLE Array*1 Structure*2
Bit
ANY_REAL ANY_INT
Word
Single- Word (unsigned)/
precision 16-bit string The higher 'ANY' data types include sub-level data types.
(signed) The highest 'ANY' data type includes all data types.
real
Double word
Double- Double (unsigned)/
precision word 32-bit string
real (signed)
ANY16 ANY32
4 PROGRAM CONFIGURATION
4.3 Labels 33
Expressing methods of constants
The following table shows the expressing method for setting a constant to a label.
Constant type Expressing method Example
Bool Input FALSE or TRUE, or input 0 or 1. TRUE, FALSE
Binary Append '2#' in front of a binary number. 2#0010, 2#01101010
Octal Append '8#' in front of an octal number. 8#0, 8#337
Decimal Directly input a decimal number, or append 'K' in front of a decimal number. 123, K123
Hexadecimal Append '16#' or 'H' in front of a hexadecimal number. 16#FF, HFF
When a lowercase letter 'h' is appended, it is converted to uppercase automatically.
Real number Directly input a real number, or append 'E' in front of a real number. 2.34, E2.34
Character string Enclose a character string with single quotations (') or double quotations ("). 'ABC', "ABC"
Time Append "T#" in front. T#1h,
T#1d2h3m4s5ms
4 PROGRAM CONFIGURATION
34 4.3 Labels
4.4 Method for Specifying Data
The following shows the seven types of data that can be used for instructions in CPU modules.
Data that can be handled by CPU module Reference
Bit data Page 36 Bit data
Numeric data Integer data Word (Signed) data Page 37 Word (16 bits) data
Double word (Signed) data Page 39 Double word (32 bits) data
Real number data Single-precision real data Page 42 Single-precision real (single-precision floating-point data)
Double-precision real data Page 43 Double-precision real (double-precision floating-point
data)
Character string data Page 46 String data
Time data Page 47 Time data 4
4 PROGRAM CONFIGURATION
4.4 Method for Specifying Data 35
Bit data
Bit data are data handled in units of 1 bit, such as contacts and coils.
'Bit devices' and 'bit-specified word device' can be used as bit data.
For FXCPU, bit specification of a word device can be used for FX3U and FX3UC.
4 PROGRAM CONFIGURATION
36 4.4 Method for Specifying Data
Word (16 bits) data
Word data are 16-bit numeric value data used in basic instructions and application instructions.
The following shows the two types of word data that can be handled in CPU modules.
• Decimal constants: K-32768 to K32767
• Hexadecimal constants: H0000 to HFFFF
For word data, word devices and digit-specified bit device can be used.
Note that word data cannot be specified using digit specification for direct access inputs (DX) and direct access outputs (DY).
(For direct access inputs and direct access outputs, refer to the User's Manual (Function Explanation, Program
Fundamentals) for the CPU module used.)
XF XC XB X8 X7 X4 X3 X0
·
K1 specification
range
(4 points)
K2 specification
range
(8 points)
K3 specification
range
(12 points)
K4 specification
range
(16 points)
4 PROGRAM CONFIGURATION
4.4 Method for Specifying Data 37
The following table shows the numeric values that can be used as source data when digits are specified at the source (s).
Number of specified digits Value range
K1 (4 points) 0 to 15
K2 (8 points) 0 to 255
K3 (12 points) 0 to 4095
K4 (16 points) -32768 to 32767
When destination (D) data is a word device, the word device for the destination becomes 0 following the bit designated by
digit designation at the source.
Ladder example Processing
• Instruction that processes 16-bit data
K1X0 X3 X2 X1 X0
X10 MOV
EN ENO 0s are stored
K1X0 s d D0
b15 b4 b3 b2 b1 b0
D0 0 0 0 0 0 0 0 0 0 0 0 0 X3 X2 X1 X0
Source s
When digits are specified at the destination (d), the points by the specified digit are the target of destination.
The status of bit devices which follow the digit-specified bit devices is not changed.
Ladder example Processing
• When the source (s) is a numeric value
1 2 3 4
X10 MOV H1234 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0
EN ENO
H1234 s d K2M0
M15 M8 M7 M0
Destination d
K2M0 0 0 1 1 0 1 0 0
Not changed 3 4
• When the source (s) is a word device
b15 b8 b7 b0
D0 1 1 1 0 1 0 1 0 1 0 0 1 1 1 0 1
X10 MOV
EN ENO
D0 s d K2M100
M115 M108 M107 M100
K2M100 1 0 0 1 1 1 0 1
Destination d
Not changed
M0 MOV
EN ENO
100 s d D0
• When performing the process with digit specification, a desired value can be used for the start device
number of bit devices.
• Digits cannot be specified for direct access inputs/outputs (DX, DY).
4 PROGRAM CONFIGURATION
38 4.4 Method for Specifying Data
Double word (32 bits) data
Double word data are 32-bit numeric value data used in basic instructions and application instructions.
The following shows the two types of double word data that can be handled in CPU modules.
• Decimal constants: K-2147483648 to K2147483647
• Hexadecimal constants: H00000000 to HFFFFFFFF
For double word data, word devices and digit specification for bit devices can be used.
Note that double word data cannot be specified using digit specification for direct access inputs (DX) and direct access
outputs (DY).
K1
specification
range
(4 points)
K2 specification range
(8 points)
K3 specification range
(12 points)
K4 specification range
(16 points)
K5 specification range
(20 points)
K6 specification range
(24 points)
K7 specification range
(28 points)
K8 specification range
(32 points)
4 PROGRAM CONFIGURATION
4.4 Method for Specifying Data 39
The following table shows the numeric values that can be used as source data when digits are specified at the source (s).
Number of specified digits Value range Number of specified digits Value range
K1 (4 points) 0 to 15 K5 (20 points) 0 to 1048575
K2 (8 points) 0 to 255 K6 (24 points) 0 to 16777215
K3 (12 points) 0 to 4095 K7 (28 points) 0 to 268435455
K4 (16 points) 0 to 65535 K8 (32 points) -2147483648 to 2147483647
When destination (D) data is a word device, the word device for the destination becomes 0 following the bit designated by
digit designation at the source. (Data_s:K1X0, Data_d:D0)
Ladder example Processing
• Instruction that processes 32-bit data
K1X0 X3 X2 X1 X0
X10 DMOV
EN ENO 0s are stored
Data_s s d Data_d
b15 b4 b3 b2 b1 b0
D0 0 0 0 0 0 0 0 0 0 0 0 0 X3 X2 X1 X0
Source s D1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
b31 b16
0s are stored
4 PROGRAM CONFIGURATION
40 4.4 Method for Specifying Data
When digits are specified at the destination (d), the points by the specified digit are the target of destination. (Data_d1:K5M0,
Data_d2:K5M10, Data_s:D0) Bit devices below the number of points designated as digits do not change.
Ladder example Processing
• When the source (s) is a numeric value
H78123456
X10 DMOV 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0
EN ENO
H78123456 s d Data_d1 3 4 5 6
0 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0
Destination d 7 8 1 2
K5M0
M15 M8 M7 M0
0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0
M31 M20 M19 M16
0 0 1 0 4
Not changed
• When the source (s) is a word device
b15 b8 b7 b0
X10 DMOV D0 1 1 1 0 0 1 0 0 0 1 0 1 1 1 0 1
EN ENO
b15 b8 b7 b0
Data_s s d Data_d2
D1 0 0 1 1 0 1 0 0 1 0 0 1 0 1 1 1
Destination d
M25 M18 M17 M10
1 1 1 0 0 1 0 0 0 1 0 1 1 1 0 1
M41 M30M29 M26
0 1 1 1
Not changed
• When performing the process with digit specification, a desired value can be used for the start device
number of bit devices.
• Digits cannot be specified for direct access inputs/outputs (DX, DY).
4 PROGRAM CONFIGURATION
4.4 Method for Specifying Data 41
Single-precision real/double-precision real data
Single-precision real/double-precision real data are 32-bit floating-point data used in basic instructions and application
instructions.
For FXCPU, double-precision real data is not supported.
Real number data can be stored only in word devices.
• Exponent: b23 to b30 represent n of 2n. The values of n are as follows according to BIN values of b23 to b30.
b23 to b30 FFH FEH FDH 81H 80H 7FH 7EH 02H 01H 00H
• Mantissa: Each of the 23 bits, b0 to b22, represents the "XXXXXX..." portion when the data is represented in binary,
"1.XXXXXX...".
4 PROGRAM CONFIGURATION
42 4.4 Method for Specifying Data
Double-precision real (double-precision floating-point data)
Devices used in lower 16 bits are specified for instructions that use real number data.
Real number data are stored in 64 bits of 'specified device number' and 'specified device number + 3'.
4
b63 b62 to b52 b51 to b16 b15 to b0
• Exponent: The 11 bits, b52 to b62, represent the excess n of 2n. The values of n are as follows according to BIN values of
b52 to b62.
b52 to b62 7FFH 7FEH 7FDH 400H 3FFH 3FEH 3FDH 3FCH 02H 01H 00H
• Mantissa: Each of the 52 bits, b0 to b51, represents the "XXXXXX..." portion when the data is represented in binary,
"1.XXXXXX...".
4 PROGRAM CONFIGURATION
4.4 Method for Specifying Data 43
Precautions
Precautions when an input value of a single/double-precision real number is set using a programming tool are shown below.
■Single-precision real
Single-precision real data are processed as 32-bit single precision in the programming tool, and thus the number of significant
figures becomes approximately 7. If the input value of single-precision real data exceeds 7 digits, the 8th digit is rounded. If
the value after the rounding exceeds a value between -2147483648 and 2147483647, an operation error occurs.
4 PROGRAM CONFIGURATION
44 4.4 Method for Specifying Data
Floating-point data in a CPU module can be monitored by the monitoring function of the programming tool.
To express 0 in floating-point data, set all of the following bits to 0.
• Single-precision floating-point data: b0 to b31
• Double-precision floating-point data: b0 to b63
The setting range of floating decimal point data is as follows.*1
• Single-precision floating-point data: -2128 < Device data -2-126, 0, 2-126 Device data < 2128
• Double-precision floating-point data: -21024 < Device data -2-1022, 0, 2-1022 Device data < 21024
Do not specify -0 (when only the highest bit of the floating-point real number is 1) for floating-point data. (A
floating-point operation with -0 results an operation error.) For the following CPU modules, a floating-point
operation does not result an error since -0 is converted to 0 in a CPU module when -0 is specified.
• High Performance model QCPU in which the internal operation is set to double precision*2 (The default 4
setting of internal floating-point operation is double precision.)
• Universal model QCPU (QnUDVCPU and QnUDPVCPU only)
The following are the CPU modules in which the operation results an error when -0 is specified.
• Basic model QCPU*3
• High Performance model QCPU in which the internal operation is set to single precision*2
• Process CPU
• Redundant CPU
• Universal model QCPU (excluding QnUDVCPU and QnUDPVCPU)
• LCPU
• FXCPU*4
*1 For operations when an overflow or underflow is occurred, or when a special value is input, refer to the following manuals.
QCPU (Q mode)/LCPU
User's Manuals (Function Explanation, Program Fundamentals) for the CPU module used.
FXCPU
User's manuals and Programming Manuals for the FXCPU used
*2 Switching between single precision and double precision of the internal floating-point operation is set in the PLC system of the PLC
parameter. For single precision and double precision of floating point operation, refer to the User's Manual (Function Explanation,
Program Fundamentals) for the CPU module used.
*3 The floating point operation is supported with the Basic model QCPU with a serial number whose first five digits are '04122' or higher.
*4 Only the FX2N, FX2NC, FX3S, FX3G, FX3GC, FX3U, and FX3UC support floating point operations.
4 PROGRAM CONFIGURATION
4.4 Method for Specifying Data 45
String data
String data are character data used in basic instructions and application instructions.
From the specified character to the NULL code (00H) that indicates the end of the character string are the target string data.
D0 42H 41H
D1 44H 43H
D2 NULL
Transfers character string data
Specification of a character string
composed of even numbers
D0 42H 41H
D1 44H 43H
D2 NULL 45H
Transfers character string data
Specification of a character string
composed of odd numbers
4 PROGRAM CONFIGURATION
46 4.4 Method for Specifying Data
Time data
Time data are used in time type operation instructions of application functions.
Specify time data in the T#10d20h30m40s567ms form.
For example. the following adds "1 Day, 2 Hours, 3 Minutes, and 4 Seconds" to "10 Days, 20 Hours, 30 Minutes, 40 Seconds,
and 567 Milliseconds".
T#10d20h30m40s567ms g_time1
ADD_TIME
g_time1
T#1d2h3m4s
_IN1
_IN2
g_time2 4
Each value of time data can be specified within the following range.
Value Range
d (Day) 0 to 24
h (Hour) 0 to 23
m (Minute) 0 to 59
s (Second) 0 to 59
ms (Millisecond) 0 to 999
4 PROGRAM CONFIGURATION
4.4 Method for Specifying Data 47
Arrays
An array represents a consecutive aggregation of same data type labels.
Arrays can be defined by the elementary data types or structures.
( GX Works2 Version 1 Operating Manual (Structured Project))
The maximum number of arrays differs depending on the data types.
• One-dimensional array (Number of elements: 4) • Two-dimensional array (Number of elements: 5 4)
bLabel1 [0] [1] [2] [3] bLabel2 [0,0] [0,1] [0,2] [0,3]
Defining arrays
■Dimension number of multidimensional array
Up to three-dimensional array can be defined.
■Definition format
The following table lists definition format.
Number of array Format Remarks
dimensions
One dimension Array of elementary data type/structure name (array start value .. array end value) For elementary data types
Page 32 Data types
(Definition example) Bit (0..2)
For structured data types
Two dimensions Array of elementary data type/structure name (array start value .. array end value, array start value .. Page 51 Structures
array end value)
(Definition example) Bit (0..2, 0..1)
Three dimensions Array of elementary data type/structure name (array start value .. array end value, array start value ..
array end value, array start value .. array end value)
(Definition example) Bit (0..2, 0..1, 0..3)
4 PROGRAM CONFIGURATION
48 4.4 Method for Specifying Data
Expression of arrays
To identify individual labels of an array, append an index enclosed by '[ ]' after the label name. Values that can be specified for
indexes are within the range from -32768 to 32767.
For an array with two or more dimensions, delimit indexes in '[ ]' by ','.
Example)
[ST]
FOR Index1:=0
TO 4
BY 1 DO
INC(TRUE,Var_D0[Index1]);
END_FOR;
■Precautions
The following explains precautions for the index of an array.
• When a label or a device is specified for an array index, the operation is performed with a combination of multiple sequence
instructions. Therefore, if an interruption occurs during the operation of the array label, an unintended operation result may
be produced. When using interrupt programs, use interrupt disable/enable instructions (DI/EI instructions) as necessary.
• If the index which is outside of the defined range is specified for an array index*1, any of the following operations occur.
• An operation error occurs.
• A current value of other label is referred or written.
*1 For example, a value other than the value within 0 to 2 is used for the index of an array which is declared with the bit array (0..2).
4 PROGRAM CONFIGURATION
4.4 Method for Specifying Data 49
Maximum number of array elements
The maximum number of array elements differs depending on data types as shown below.
Data type Maximum number
Bit, word (signed), word (unsigned)/16-bit string, timer, counter, and retentive timer 32768
Double word (signed), double word (unsigned)/32-bit string, single-precision real, and time 16384
Double-precision real 8192
String 32768 divided by string length
4 PROGRAM CONFIGURATION
50 4.4 Method for Specifying Data
Structures
A structure is an aggregation of different data type labels. Structures can be used in all POUs. To use structures, first create
the configuration of structure, and define a structure label name for the created structure as a new data type
( GX Works2 Version 1 Operating Manual (Structured Project))
To use each element of structure, append an element name after the structure label name with '.' as a delimiter in between.
Structure
label name
Element name
4
Structures can also be used as arrays. When a structure is declared as an array, append an index enclosed by '[ ]' after the
structure label name. When arrays are used and accessed using array indices to specify a label or device, the maximum
value in an array is 32767.
The arranged structured data can be specified as arguments of functions and function blocks. When arrays are used and
accessed using array indices to specify a label or device, a bit-specified word device cannot be specified for a bit type
element.
Example) When using the element
of the arranged structured data
dut_b1 [0] . in00
Creating structures
Expression in a program
dut_a1.bo00 dut_a1.bo01
MOV
EN ENO
dut_a1.in00 s d idata1
4 PROGRAM CONFIGURATION
4.4 Method for Specifying Data 51
4.5 Device and Address
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 IEC 61131-3. In this format, a device name starts with %.
Device
Device is a format that uses a device name and a device number.
Example)
X0 W35F
4 PROGRAM CONFIGURATION
52 4.5 Device and Address
Address
Address is a format defined in IEC 61131-3. The following table shows details of format that conforms to IEC 61131-3.
Start 1st character: 2nd character: data size 3rd character and later: Number
position classification
% I: Input (Omitted) Bit Numeric characters used for detailed Number corresponding to the
Q: Output classification. Use'.' (period) to delimit device number (decimal
X Bit
M: Internal the numbers from the subsequent notation)
W Word (16 bits) numbers. A period may be omitted.
D Double word (32 bits)
L Long word (64 bits)*1
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.
Device Position
X, J\X I (input)
(X device)
Y, J\Y Q (output)
(Y device)
Other devices M (internal)
Data size
Data size is a class indicating the size of data. The following shows the format rules corresponding to the device format.
Device Data size
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.
Page 54 Correspondence between devices and addresses
Long words are used in double-precision real operation instructions of the Universal model QCPU/LCPU.
4 PROGRAM CONFIGURATION
4.5 Device and Address 53
Correspondence between devices and addresses
This section explains the correspondence between devices and addresses.
■QCPU (Q mode)/LCPU
Device Expressing method Example of correspondence between
device and address
Device Address Device Address
Input X Xn %IXn X7FF %IX2047
Output Y Yn %QXn Y7FF %QX2047
Internal relay M Mn %MX0.n M2047 %MX0.2047
Latch relay L Ln %MX8.n L2047 %MX8.2047
Annunciator F Fn %MX7.n F1023 %MX7.1023
Special relay SM SMn %MX10.n SM1023 %MX10.1023
Function input FX FXn None FX10 None
Function output FY FYn None FY10 None
Edge relay V Vn %MX9.n V1023 %MX9.1023
Direct access input DX DXn %IX1.n DX7FF %IX1.2047
Direct access output DY DYn %QX1.n DY7FF %QX1.2047
Timer Contact TS Tn %MX3.n TS511 %MX3.511
Coil TC Tn %MX5.n TC511 %MX5.511
Current value TN Tn %MW3.n TN511 %MW3.511
%MD3.n T511 %MD3.511
Counter Contact CS Cn %MX4.n CS511 %MX4.511
Coil CC Cn %MX6.n CC511 %MX6.511
Current value CN Cn %MW4.n CN511 %MW4.511
%MD4.n C511 %MD4.511
Retentive Contact STS STn %MX13.n STS511 %MX13.511
timer
Coil STC STn %MX15.n STC511 %MX15.511
Current value STN STn %MW13.n STN511 %MW13.511
%MD13.n ST511 %MD13.511
Data register D Dn %MW0.n D11135 %MW0.11135
%MD0.n %MD0.11135
Special register SD SDn %MW10.n SD1023 %MW10.1023
%MD10.n %MD10.1023
Function register FD FDn None FD0 None
Link relay B Bn %MX1.n B7FF %MX1.2047
Link special relay SB SBn %MX11.n SB3FF %MX11.1023
Link register W Wn %MW1.n W7FF %MW1.2047
%MD1.n %MD1.2047
Link special register SW SWn %MW11.n SW3FF %MW11.1023
%MD11.n %MD11.1023
Intelligent function module device G Ux\Gn %MW14.x.n U0\G65535 %MW14.0.65535
%MD14.x.n %MD14.0.65535
File register R Rn %MW2.n R32767 %MW2.32767
%MD2.n %MD2.32767
Pointer P Pn "" (Null character) P299 None
Interrupt pointer I In None
Nesting N Nn None
Index register Z Zn %MW7.n Z9 %MW7.9
%MD7.n %MD7.9
Step relay S Sn %MX2.n S127 %MX2.127
SFC transition device TR TRn %MX18.n TR3 %MX18.3
4 PROGRAM CONFIGURATION
54 4.5 Device and Address
Device Expressing method Example of correspondence between
device and address
Device Address Device Address
SFC block device BL BLn %MX17.n BL3 %MX17.3
Link input J Jx\Xn %IX16.x.n J1\X1FFF %IX16.1.8191
Link output Jx\Yn %QX16.x.n J1\Y1FFF %QX16.1.8191
Link relay Jx\Bn %MX16.x.1.n J2\B3FFF %MX16.2.1.16383
Link register Jx\Wn %MW16.x.1.n J2\W3FFF %MW16.2.1.16383
%MD16.x.1.n %MD16.2.1.16383
Link special relay Jx\SBn %MX16.x.11.n J2\SB1FF %MX16.2.11.511
Link special register Jx\SWn %MW16.x.11.n J2\SW1FF %MW16.2.11.511
%MD16.x.11.n
File register ZR ZRn %MW12.n
%MD12.n
ZR32767 %MW12.32767
%MD12.32767
4
■FXCPU
Device Expressing method Example of correspondence between
device and address
Device Address Device Address
Input X Xn %IXn X367 %IX247
Output Y Yn %QXn Y367 %QX247
Auxiliary relay M Mn %MX0.n M499 %MX0.499
Timer Contact TS Tn %MX3.n TS191 %MX3.191
Coil TC Tn %MX5.n TC191 %MX5.191
Current value TN Tn %MW3.n TN191 %MW3.191
%MD3.n T190 %MD3.190
Counter Contact CS Cn %MX4.n CS99 %MX4.99
Coil CC Cn %MX6.n CC99 %MX6.99
Current value CN Cn %MW4.n CN99 %MW4.99
%MD4.n C98 %MD4.98
Data register D Dn %MW0.n D199 %MW0.199
%MD0.n D198 %MD0.198
Intelligent function module device G Ux\Gn %MW14.x.n U0\G09 %MW14.0.10
%MD14.x.n %MD14.0.9
Extension register R Rn %MW2.n R32767 %MW2.32767
%MD2.n R32766 %MD2.32766
Extension file register ER ERn None
Pointer P Pn "" (Null character) P4095 None
Interrupt pointer I In None
Nesting N Nn None
Index register Z Zn %MW7.n Z7 %MW7.7
%MD7.n Z6 %MD7.6
V Vn %MV6.n V7 %MW6.7
State S Sn %MX2.n S4095 %MX2.4095
4 PROGRAM CONFIGURATION
4.5 Device and Address 55
Digit specification of bit devices
The following table shows the correspondence between devices and addresses when specifying digits of bit devices.
Device Address
K[Number of digits][Device name][Device number](Number of digits: 1 to %[Position of memory area][Data size]19.[Number of
8) digits].[Classification].[Number]
(Number of digits: 1 to 8)
• Correspondence examples
Device Address
K1X0 %IW19.1.0
K4M100 %MW19.4.0.100
K8M100 %MD19.8.0.100
K2Y7E0 %QW19.2.2016
• Correspondence examples
Device Address
D11135.C %MX0.11135.12
SD1023.F %MX10.1023.15
• Index setting, digit specification of bit devices, and bit specification of word device
Index setting, digit specification of bit devices, and bit specification of word device cannot be applied to labels.
4 PROGRAM CONFIGURATION
56 4.5 Device and Address
4.6 Index Setting
X0 MOV
EN ENO Stores -1 at Z0.
-1 s d Z0
Index setting
*1 For the specifications of the index register, refer to the User's Manual (Function Explanation, Program Fundamentals) for the CPU
module used.
■Devices that can be used for the index setting (for QCPU (Q mode), LCPU)
The index setting can be applied to devices used by contacts, coils, basic instructions, and application instructions except for
the restrictions listed in the tables below. The index setting cannot be applied to labels.
• Devices that cannot be used for the index setting
Device Description
E Floating-point data
$ Character string data
. (D0.1 etc.) Bit-specified word device
FX, FY, FD Function devices
P Pointers used as labels
I Interrupt pointers used as labels
Z Index registers
S Step relays*2
TR SFC transition devices*1
BL SFC block devices*1*2
*1 SFC transition devices and SFC block devices are devices for SFC programs.
For details, refer to the following manual.
MELSEC-Q/L/QnA Programming Manual (SFC)
*2 The SFC block devices (BL) and step relays (S) of the High-speed Universal model QCPU and Universal model Process CPU can be
used for the index modification under the following ranges.
SFC block device (BL): BL0 to BL319
Step relay (S): Within the range set in the parameter (device settings)
When the step relays (S) in an SFC block device are selected, S0 to S511 can be used for the index setting.
4 PROGRAM CONFIGURATION
4.6 Index Setting 57
• Devices with restrictions on index registers*3
Device Description Example
T, ST • Only Z0 or Z1 can be used for contacts or coils of the
TS0Z0 OUT_T
timer.
EN ENO
TC1Z1 s1
100 s2
C • Only Z0 or Z1 can be used for contacts or coils of the
CS0Z1 OUT_C
counter.
EN ENO
CC1Z0 s1
100 s2
*3 The High-speed Universal model QCPU and Universal model Process CPU are excluded.
■Devices that can be used for the index setting (for FXCPU)
The following table shows the devices that can be used for the index setting
Device Description
M, S, T, C, D, R, KnM, KnS, P, K Decimal devices, values
X, Y, KnX, KnY Octal devices
H Hexadecimal values
There are no usage restrictions on index register numbers for current values of the timer and counter.
X0 OUT_T
EN ENO
TC0 s1
100 s2
Set value of timer
(Index setting is not applicable)
SM400 BCD
EN ENO
TN0Z4 s d K4Y30
Current value of timer
X1 OUT_C
EN ENO
CC100 s1
10 s2
Set value of counter
(Index setting is not applicable)
SM400 BCD
EN ENO
CN100Z6 s d K2Y40
Current value of counter
4 PROGRAM CONFIGURATION
58 4.6 Index Setting
■The following figure shows the examples of index setting and their actual processing devices.
(With the setting of Z0=20 and Z1=-5)
Ladder example Actual processing device
X1 MOV
X0 MOV EN ENO
EN ENO K2X64 s d K1M33
K20 s d Z0 Description
K2X50Z0 K2X(50 + 14) = K2X64
MOV
EN ENO
K-5 s d Z1 Converts K20 to a hexadecimal number.
K1M38Z1 K1M(38 - 5) = K1M33
X1 MOV
EN ENO
K2X50Z0 s d K1M38Z1 4
X1 MOV
X0 MOV EN ENO
EN ENO D20 s d K3Y12A
K20 s d Z0
Description
MOV D0Z0 D (0 + 20) = D20
EN ENO K3Y12FZ1 K3Y(12F - 5) = K3Y12A
K-5 s d Z1
Hexadecimal number
X1 MOV
EN ENO
D0Z0 s d K3Y12FZ1
4 PROGRAM CONFIGURATION
4.6 Index Setting 59
32-bit index setting
For Universal model QCPU (excluding Q00UJCPU) and LCPU, either of the following two methods can be selected to specify
index registers used for a 32-bit index setting.
• Specify a range of index registers used for a 32-bit index setting.
• Specify a 32-bit index setting using 'ZZ'.
For FXCPU, combine index registers V (from V0) and Z (from Z0) for a 32-bit index setting.
32-bit index settings using 'ZZ' can be used for the following CPU modules only. For the usable programming
tool, refer to the operating manual of the programming tool.
• QnU(D)(H)CPU with a serial number whose first five digits are '10042' or higher (excluding Q00UJCPU)
• Built-in Ethernet port QCPU
• LCPU
X0 DMOV
EN ENO Stores 40000 to Z0
40000 s d Var_Z0
X0 MOV
Stores the data of
EN ENO
s d ZR {10+40000} = ZR40010 to D0
ZR10Z0 D0
Index setting
• Specification method
When setting indexes in 32-bit range, specify the start number of index registers to be used in the device setting of the PLC
parameter.
When changing the start number of index registers to be used in the device setting of the PLC parameter, do
not change nor write only parameters to the programmable controller. Always write parameters along with the
program to the programmable controller.
If data are forcibly written, the operation error "CAN'T EXE. PRG." (error code: 2500) occurs.
4 PROGRAM CONFIGURATION
60 4.6 Index Setting
• Devices that can be used for index settings
Only the following devices can be used for index settings.
Device Description
ZR Serial number access file register
D Extended data register
W Extended link register
• The following figure shows the examples of index setting and their actual processing devices. (With the setting of Z0 (32
bits) = 100000 and Z2 (32 bits) = -20)
Ladder example Actual processing device
X1 MOV
X0 DMOV EN ENO
EN ENO ZR101000 s d D12980
K100000 s d Z0
Description
DMOV
EN ENO ZR1000Z0 ZR(1000+100000) ZR101000
K-20 s d Z2 D13000Z2 D(30-20) D12980
X1 MOV
EN ENO
ZR1000Z0 s d D13000Z2
4 PROGRAM CONFIGURATION
4.6 Index Setting 61
■Specifying a 32-bit index setting using 'ZZ'
A 32-bit index can be specified to the index register by specifying an index using 'ZZ', for instance, 'ZR0ZZ4'.
The following figure shows the 32-bit index setting using 'ZZ'.
M0 DMOVP
EN ENO Set 100000 to Z4 and Z5.
K100000 s d Z4
• Specification method
When specifying a 32-bit index setting using 'ZZ', select "Use ZZ" in the "Indexing Setting for ZR Device" setting in the
"Device" tab of the PLC parameter.
*1 The devices can be used for the High-speed Universal model QCPU and Universal model Process CPU only.
• Usage range of index registers
The following table shows the usage range of index registers when specifying 32-bit index setting using 'ZZ'.
When specifying a 32-bit index setting using 'ZZ', specify a device as a form of ZRmZZn.
The device number of ZRm is indexed with 32 bits (Zn, Zn+1) by specifying ZRmZZn.
'ZZ'*2 Index register 'ZZ'*2 Index register
ZZ0 Z0, Z1 ZZ10 Z10, Z11
ZZ1 Z1, Z2 ZZ11 Z11, Z12
ZZ2 Z2, Z3 ZZ12 Z12, Z13
ZZ3 Z3, Z4 ZZ13 Z13, Z14
ZZ4 Z4, Z5 ZZ14 Z14, Z15
ZZ5 Z5, Z6 ZZ15 Z15, Z16
ZZ6 Z6, Z7 ZZ16 Z16, Z17
ZZ7 Z7, Z8 ZZ17 Z17, Z18
ZZ8 Z8, Z9 ZZ18 Z18, Z19
ZZ9 Z9, Z10 ZZ19 Not applicable
4 PROGRAM CONFIGURATION
62 4.6 Index Setting
• The following figure shows the examples of 32-bit index setting using 'ZZ' and their actual processing devices. (With the
setting of Z0 (32 bits) =100000 and Z2 (32 bits)=-20)
Ladder example Actual processing device
X1 MOV
X0 DMOV EN ENO
EN ENO ZR101000 s d D12980
K100000 s d Z0
Description
DMOV
EN ENO ZR1000Z0 ZR(1000+100000) ZR101000
K-20 s d Z2 D13000Z2 D(30-20) D12980
X1 MOV
EN ENO
ZR1000ZZ0 s d D13000Z2
4
• Functions that can use 'ZZ'
32-bit index settings using 'ZZ' can be used in the following functions.
No. Description
1 Device specification with an instruction in a program
2 Monitoring device registrations
3 Device test
4 Device test with an execution condition
5 Setting monitoring conditions
6 Sampling trace (trace point (device specification), trace target devices)
7 Data logging function (sampling interval (device specification), logging target data)
ZZn cannot be used individually such as 'DMOV K100000 ZZ0'. When setting a value to index registers to
specify a 32-bit index setting using 'ZZ', set a value to Zn (Z0 to Z19).
ZZn cannot be entered individually in the functions.
4 PROGRAM CONFIGURATION
4.6 Index Setting 63
Applying index settings to extended data registers (D) and extended link registers (W)*1
As an index setting can be applied to internal user devices, data registers (D) and link registers (W), the device specification
by the index setting can be used within the range of extended data registers (D) and extended link registers (W).
Z1 = 0
D20000
MOV Extended data
EN ENO
register
1234 s d D20000Z1
D22000
Z1 = 2000
■Index settings that cross internal user devices and extended data registers (D)/extended link
registers (W)
An index setting that crosses internal user devices and extended data registers (D)/extended link registers (W) cannot be
applied. If the device range check is enabled at the index setting, an error occurs. (Error code: 4101)
D20100
Z0=20000 Extended data register
4 PROGRAM CONFIGURATION
64 4.6 Index Setting
■Index settings that cross file registers (ZR), extended data registers (D), and extended link
registers (W)
Even when an index setting that crosses file registers (ZR), extended data registers (D), and extended link registers (W) is
applied, an error does not occur.
However, if the result of the index setting applied to file registers (ZR), extended data registers (D) or extended link registers
(W) exceeds the range of the file register files, an error occurs. (Error code: 4101)
EN
MOV
ENO
Z0=0
ZR100 register
(8K points) 4
1234 s d D100Z0
Z0=10000
D14196 Extended data
register (D)
D20000 (8K points)
MOV Z1=0 From D12288
EN ENO
1234 s d D20000Z1 Extended link
Z1=4000 register (W)
W2DC0
(8K points)
From W2000
Even when the index setting that
crosses extended data register (D)
and extended link register (W) is
applied, an error does not occur.
4 PROGRAM CONFIGURATION
4.6 Index Setting 65
Other applicable data
For bit data, an index setting is applicable to device numbers whose digits are specified.
Note that an index setting is not applicable to the digit-specified bit device.
BIN
EN ENO
K4X0Z2 s d D0
Index setting is applicable
to the device number,
BIN If Z2=3, then (X0+3)=X3
EN ENO
K4Z3X0 s d D0
Index setting is not applicable
to the digit-specified bit device.
For intelligent function module devices*1, an index setting is applicable to both start I/O numbers of the intelligent function
module and buffer memory addresses.
MOV
EN ENO
U10Z1\G0Z2 s d D0
If Z1=2 and Z2=8,
then U(10+2)\G(0+8)=U12\G8
For link direct devices*1, an index setting is applicable to both network numbers and device numbers.
MOV
EN ENO
J1Z1\K4X0Z2 s d D0
If Z1=2 and Z2=8,
then J(1+2)\K4X(0+8)=J3\K4X8
For multiple CPU area devices*2, an index setting is applicable to both start I/O numbers of the CPU module and CPU shared
memory addresses.
MOV
EN ENO
U3E0Z1\G0Z2 s d D0
When applying an index setting to extended data registers (D) or extended link registers (W), it can be applied in 32-bit range
as applying an index setting to file registers (ZR) in the following two methods.*3
• Specify a range of index registers used for a 32-bit index setting.
• Specify a 32-bit index setting using 'ZZ'.
*1 For intelligent function module devices and link direct devices, refer to the User's Manual (Function Explanation, Program
Fundamentals) of the CPU module used.
*2 For multiple CPU area devices, refer to the User's Manual (Function Explanation, Program Fundamentals) of the CPU module used.
*3 For Universal model QCPU (excluding Q00UJCPU), and LCPU
32-bit index settings using 'ZZ' can be used for the following CPU modules only. For the usable programming
tool, refer to the operating manual of the programming tool.
• QnU(D)(H)CPU with a serial number whose first five digits are '10042' or higher (excluding Q00UJCPU)
• Built-in Ethernet port QCPU
• LCPU
4 PROGRAM CONFIGURATION
66 4.6 Index Setting
Precautions
■Using the index setting for arguments of instruction/application function/function/function
block
When "Use ZZ" is checked in "Indexing Setting for ZR Device" setting in the <<Device>> tab of the PLC parameter, and Z
device is used for the argument of instruction/application function/function/function block, the expression is converted to "ZZ"
at the compilation.
This may cause unintended device accesses.
When "Use ZZ" is checked, use ZZ devices for arguments of instruction/application function/function/function block.
■Applying the index setting within the FOR to NEXT instruction loop
The pulses can be output by using edge relays (V) within the FOR to NEXT instruction loop.
Note that the pulses cannot be output by the PLS, PLF, or pulse (P) instruction. 4
When using an edge relay When not using an edge relay
M0Z1 pulse is output normally. M0Z1 pulse is not output normally.
FOR FOR
EN ENO EN ENO
10 n 10 n
NEXT NEXT
EN ENO EN ENO
• The ON/OFF information of X0Z1 is stored to the edge relay V0Z1. For example, the ON/OFF data of X0 is
stored to V0 and the ON/OFF data of X1 is stored to V1.
• Z0 and Z1 cannot be used when labels are used for array indexes within the FOR to NEXT instruction loop.
4 PROGRAM CONFIGURATION
4.6 Index Setting 67
■Applying the index setting in the CALL instruction
The pulse can be output by using edge relays (V) with the CALL instruction.
Note that the pulse cannot be output by the PLS, PLF, or pulse (P) instruction.
When using an edge relay When not using an edge relay
M0Z1 pulse is output normally. M0Z1 pulse is not output normally.
CALL CALL
EN ENO EN ENO
P0 p P0 p
CALL CALL
EN ENO EN ENO
P0 p P0 p
FEND FEND
EN ENO EN ENO
RET RET
EN ENO EN ENO
*1 When the data after index modification exceed the user specified device range, it may cause an error. (Error code: 4101).
*2 For the executions conditions for each instruction, refer to the descriptions page for each instruction.
*3 The PLS instruction and PLF instruction are excluded. (The PLS instruction and PLF instruction always check the device range during
index modification.)
4 PROGRAM CONFIGURATION
68 4.6 Index Setting
• For the QnUDVCPU and QnUDPVCPU:
The device range is checked during index modification.
It is also possible not to allow checking the device range using the parameters.
The timings for checking the device change during index modification are shown below.
Instruction Timings for checking
Contact Instructions Always*4
Association instruction
Comparison operation instruction (LD)
Comparison operation instruction (AND)
Comparison operation instruction (OR)
Instructions other than the above It follows the execution conditions for the instruction.*5*6*7
*4
*5
When the data after index modification exceed the user specified device range, the operation results in OFF without causing an error.
When the data after index modification exceed the user specified device range, it may cause an error. (Error code: 4101).
4
*6 For the executions conditions for each instruction, refer to the descriptions page for each instruction.
*7 The PLS instruction and PLF instruction are excluded. (The PLS instruction and PLF instruction always check the device range during
index modification.)
4 PROGRAM CONFIGURATION
4.6 Index Setting 69
4.7 Libraries
A library is an aggregation of data including POUs, global labels, and structures organized in a single file to be utilized in
multiple projects.
The following are the advantages of using libraries.
• Data in library files can be utilized in multiple projects by installing them to each project.
• Since library data can be created according to the functions of components, data to be reused can be easily confirmed.
• If components registered in a library are modified, the modification is applied to projects that use the modified data.
The following figure shows the data flow when using library components in a project.
Library
Program Program
Install Edit
Function Function
Structure Structure
Utilize
Global label
Installed library can be
registered in the task
Program file of the project.
Task
Function
Function block
Structure
4 PROGRAM CONFIGURATION
70 4.7 Libraries
User libraries
A user library is a library for storing created structures, global labels, POUs, and other data that can be used in other projects.
4 PROGRAM CONFIGURATION
4.7 Libraries 71
4.8 Precautions on Assigning a Name
This section explains the conditions for assigning a name to a label, function block instance, or structure label.
• Specify a name within 32 characters.
• Do not use reserved words. For reserved words, refer to the following section.
Page 100 Character Strings That Cannot Be Used in Label Names and Data Names
• Use alphanumeric and underscores (_).
• Do not use an underscore at the end of the name. Do not use two or more underscores in succession.
• Do not use spaces.
• Do not use a number for the initial character.
• Constants 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'))
• Elementary data type names cannot be used.
• Function/FB names cannot be used.
4 PROGRAM CONFIGURATION
72 4.8 Precautions on Assigning a Name
5 WRITING PROGRAMS
5.1 ST
The ST language is a text language with a similar grammatical structure to the C language. Controls such as conditional
judgment and repetition process written in syntax can be described.
This language is suitable for programming complicated processes that cannot be easily described by a graphic language
(structured ladder/FBD language).
Standard format
Assignment syntax
5
syntaxes
Comment
Spaces, tabs, and line feeds can be inserted anywhere between a keyword and an identifier.
Space
Tab
Line feed
Comments can be inserted in a program. Describe '(*' in front of a comment and '*)' in back of a comment.
Comment
5 WRITING PROGRAMS
5.1 ST 73
Operators in ST language
The following table shows the operators used in the ST program and their priorities.
Operator Description Example Priority
() Parenthesized expression (1+2)*(3+4) 1
Function ( ) Function (Parameter list) ADD_E(bo01, in01, in02, in03) 2
** Exponentiation re01:= 2.0 ** 4.4 3
NOT Logical negation NOT bo01 4
* Multiplication 3*4 5
/ Division 12 / 3
MOD Modulus operation 13 MOD 3
+ Addition in01 + in02 6
- Subtraction in01 - in02
<, >, <=, >= Comparison in01 < in02 7
= Equality in01 = in02 8
<> Inequality in01 <> in02
AND, & Logical AND bo01 & bo02 9
XOR Exclusive OR bo01 XOR bo02 10
OR Logical OR bo01 OR bo02 11
If a syntax includes multiple operators with a same priority, the operation is performed from the leftmost operator.
The following table shows the operators, applicable data types, and operation result data types.
Operator Applicable data type Operation result data type
*, /, +, - ANY_NUM ANY_NUM
<, >, <=, >=, =, <> ANY_SIMPLE Bit
MOD ANY_INT ANY_INT
AND, &, XOR, OR, NOT ANY_BIT ANY_BIT
** ANY_REAL (Base) ANY_REAL
ANY_NUM (Exponent)
5 WRITING PROGRAMS
74 5.1 ST
Syntax in ST language
The following table shows the syntax that can be used in the ST program.
Type of syntax Description Assignment syntax
Assignment syntax Assignment syntax Page 75 Assignment syntax
Conditional syntax IF conditional syntax IF THEN conditional syntax Page 76 IF THEN conditional syntax
IF ELSE conditional syntax Page 76 IF ...ELSE conditional syntax
IF ELSIF conditional syntax Page 77 IF ...ELSIF conditional syntax
CASE conditional syntax Page 77 CASE conditional syntax
Iteration syntax FOR DO syntax Page 78 FOR...DO syntax
WHILE DO syntax Page 78 WHILE...DO syntax
REPEAT UNTIL syntax Page 79 REPEAT...UNTIL syntax
Other control syntax RETURN syntax Page 79 RETURN syntax
EXIT syntax Page 80 EXIT syntax
5
Assignment syntax
■Format
<Left side> := <Right side>;
■Description
The assignment syntax assigns the result of the right side expression to the label or device of the left side. The result of the
right side expression and data type of the left side need to obtain the same data when using the assignment syntax.
■Example
intV1 := 0;
intV2 := 2;
Array type labels and structure labels can be used for the assignment syntax.
Note the data types of left side and right side.
• Array type labels
The data type and the number of elements need to be the same for left side and right side.
When using array type labels, do not specify elements.
< Example >
intAry1 := intAry2;
• Structure labels
The data type (structured data type) needs to be the same for left side and right side.
< Example >
dutVar1 := dutVar2;
5 WRITING PROGRAMS
5.1 ST 75
IF THEN conditional syntax
■Format
IF <Boolean expression> THEN
<Syntax ...>;
END_IF;
■Description
The syntax is executed when the value of Boolean expression (conditional expression) is TRUE. The syntax is not executed if
the value of Boolean expression is FALSE.
Any expression that returns TRUE or FALSE as the result of the Boolean operation with a single bit type variable status, or a
complicated expression that includes many variables can be used for the Boolean expression.
■Example
IF bool1 THEN
intV1 := intV1 + 1;
END_IF;
■Description
Syntax 1 is executed when the value of Boolean expression (conditional expression) is TRUE.
Syntax 2 is executed when the value of Boolean expression is FALSE.
■Example
IF bool1 THEN
intV3 := intV3 + 1;
ELSE
intV4 := intV4 + 1;
END_IF;
5 WRITING PROGRAMS
76 5.1 ST
IF ...ELSIF conditional syntax
■Format
IF <Boolean expression 1> THEN
<Syntax 1 ...>;
ELSIF <Boolean expression 2> THEN
<Syntax 2 ...>;
ELSIF <Boolean expression 3> THEN
<Syntax 3 ...>;
END_IF;
■Description
Syntax 1 is executed when the value of Boolean expression (conditional expression) 1 is TRUE. Syntax 2 is executed when
the value of Boolean expression 1 is FALSE and the value of Boolean expression 2 is TRUE.
Syntax 3 is executed when the value of Boolean expression 1 and 2 are FALSE and the value of Boolean expression 3 is
TRUE.
■Example
IF bool1 THEN
5
intV1 := intV1 + 1;
ELSIF bool2 THEN
intV2 := intV2 + 2;
ELSIF bool3 THEN
intV3 := intV3 + 3;
END_IF;
■Description
The result of the CASE conditional expression is returned as an integer value. The CASE conditional syntax is used to
execute a selection syntax by a single integer value or an integer value as the result of a complicated expression.
When the syntax that has the integer selection value that matches with the value of integer expression is executed, and if no
integer selection value is matched with the expression value, the syntax that follows the ELSE syntax is executed.
■Example
CASE intV1 OF
1:bool1 := TRUE;
2:bool2 := TRUE;
ELSE
intV1 := intV1 + 1;
END_CASE;
5 WRITING PROGRAMS
5.1 ST 77
FOR...DO syntax
■Format
FOR <Repeat variable initialization>
TO <Last value>
BY <Incremental expression> DO
<Syntax ...>;
END_FOR;
■Description
First, initialize the data to be used as an iteration variable.
One or more statements between the DO statement and the END_FOR statement are executed repeatedly, adding or
subtracting the initialized iteration variable according to the increase expression until the final value is exceeded.
The iteration variable after the FOR...DO statement is completed retains the value at the end of the processing.
■Example
FOR intV1 := 0
TO 30
BY 1 DO
intV3 := intV1 + 1;
END_FOR;
WHILE...DO syntax
■Format
WHILE <Boolean expression> DO
<Syntax ...>;
END_WHILE;
■Description
The WHILE...DO syntax executes one or more syntax while the value of Boolean expression (conditional expression) is
TRUE.
The Boolean expression is evaluated before the execution of the syntax. If the value of Boolean expression is FALSE, the
syntax within DO...END_WHILE is not executed. Since a return result of the Boolean expression in the WHILE syntax
requires only TRUE or FALSE, any Boolean expression that can be specified in the IF conditional syntax can be used.
■Example
WHILE intV1 = 30 DO
intV1 := intV1 + 1;
END_WHILE;
5 WRITING PROGRAMS
78 5.1 ST
REPEAT...UNTIL syntax
■Format
REPEAT
<Syntax ...>;
UNTIL <Boolean expression>
END_REPEAT;
■Description
The REPEAT...UNTIL syntax executes one or more syntax while the value of Boolean expression (conditional expression) is
FALSE.
The Boolean expression is evaluated after the execution of the syntax. If the value of Boolean expression is TRUE, the syntax
in the REPEAT...UNTIL syntax are not executed.
Since a return result of the Boolean expression in the REPEAT syntax requires only TRUE or FALSE, any Boolean expression
that can be specified in the IF conditional syntax can be used.
■Example
REPEAT 5
intV1 := intV1 + 1;
UNTIL intV1 = 30
END_REPEAT;
RETURN syntax
■Format
RETURN;
■Description
The RETURN syntax is used to end a program in a middle of the process.
When the RETURN syntax is used in a program, the process jumps from the RETURN syntax execution step to the last line of
the program, ignoring all the remaining steps after the RETURN syntax.
■Example
IF bool1 THEN
RETURN;
END_IF;
5 WRITING PROGRAMS
5.1 ST 79
EXIT syntax
■Format
EXIT;
■Description
The EXIT syntax is used only in iteration syntax to end the iteration syntax in a middle of the process. When the EXIT syntax
is reached during the execution of the iteration loop, the iteration loop process after the EXIT syntax is not executed. The
process continues from the line after the one where the iteration syntax is ended.
■Example
FOR intV1 := 0
TO 10
BY 1 DO
IF intV1 > 10 THEN
EXIT;
END_IF;
END_FOR;
5 WRITING PROGRAMS
80 5.1 ST
Calling functions in ST language
The following description is used to call a function in the ST language.
Description of calling functions
Function name (Variable1, Variable2, ...);
Enclose the arguments by '( )' after the function name. When using multiple variables, delimit them by ','.
The execution result of the function is stored by assigning the result to the variables.
Function Example
Calling a function with one input variable (Example: ABS) Output1 := ABS(Input1);
Calling a function with three input variables (Example: MAX) Output1 := MAX(Input1, Input2, Input3);
Calling a function with EN/ENO (Example: MOV) boolENO := MOV(boolEN, Input1, Output1);*1
*1 For a function with EN/ENO, the result of the function execution is ENO, and the first argument (Variable 1) is EN.
Enclose the assignment syntax that assigns variables to the input variable and output variable by '( )' after the instance name.
When using multiple variables, delimit assignment syntax by ',' (comma).
The execution result of the function block is stored by assigning the output variable that is specified by adding '.' (period) after
the instance name to the variable.
Function block FB definition Example
Calling a function block with one FB Name FBADD FBADD1(IN1:=Input1);
input variable and one output FB instance name FBADD1 Output1 := FBADD1.OUT1;
variable
Input variable1 IN1
Output variable1 OUT1
Calling a function block with three FB Name FBADD FBADD1(IN1:=Input1, IN2:=Input2, IN3:=Input3);
input variables and two output FB instance name FBADD1
Output1 := FBADD1.OUT1;
variables Output2 := FBADD1.OUT2;
Input variable1 IN1
Input variable2 IN2
Input variable3 IN3
Output variable1 OUT1
Output variable2 OUT2
5 WRITING PROGRAMS
5.1 ST 81
Precautions when using conditional syntax and iteration syntax
The following explains the precautions when creating ST programs using conditional syntax and iteration syntax.
Precaution 1
Once the conditions (boolean expression) are met in the conditional syntax or iteration syntax, the bit device which is turned
ON in the <syntax> is always set to ON.
To avoid the bit device to be always set to ON, add a program to turn the bit device OFF as shown below.
5 WRITING PROGRAMS
82 5.1 ST
Precaution 2
When Q00UCPU, Q00UJCPU or, Q01UCPU is used, and the string type is applied to Boolean expression (conditional
expression) with conditional syntax or iteration syntax, a compilation error may occur.
To avoid a compilation error, create the function blocks of the string type comparison with ladder or structured ladder/FBD,
and apply the operation result of function blocks to the conditional expression of conditional syntax or iteration syntax.
The following is an example when creating the function blocks with structured ladder/FBD. 5
■Program creation example which avoids compilation error
1. Create the function blocks of the string type comparison with structured ladder/FBD program
Function block (EQFB_01)
2. Apply the operation result of function blocks (EQFB_01) to the conditional expression in ST program.
Label setting
ST program
5 WRITING PROGRAMS
5.1 ST 83
Precaution 3
The following table lists operations when the STMR instruction or instructions that are executed at the rising or falling edge
are used in the IF or CASE conditional statement.
Condition Operation result
Conditional Instruction On/off On/off Rising edge Falling edge STMR
formula of IF or execution determination determination execution execution instruction
CASE condition (EN) result of the result of the instruction instruction
conditional instruction in instruction
statement the last scan
TRUE or CASE TRUE ON ON Not executed Not executed Previous value held
match
OFF ON Executed Not executed Rising edge
processing
FALSE ON OFF Not executed Executed Falling edge
processing
OFF OFF Not executed Not executed Previous value held
FALSE or CASE TRUE ON ON*1 Not executed Not executed Previous value held
mismatch
OFF OFF Not executed Not executed Previous value held
FALSE ON ON*1 Not executed Not executed Previous value held
OFF OFF Not executed Not executed Previous value held
*1 On the falling edge (on to off), the instruction is not executed because the condition of the IF or CASE statement is not satisfied.
Ex.
When the PLS instruction (execution condition: rising edge) is used in the IF statement
IF M0 THEN
PLS(M1, M10);
END_IF;
ON
M0 OFF
ON ON
M1 OFF
ON
On/off
determination OFF
result (3)
(1) (2) ON
M10 OFF
1 scan
(1) When M0 is off (the conditional formula of the IF conditional statement is FALSE), the on/off determination result will be off. The PLS instruction is not
executed. (The M10 remains off.)
(2) When M0 is on (the conditional formula of the IF conditional statement is TRUE) and M1 is off (the instruction execution condition is off), the on/off
determination result will be off. The PLS instruction is not executed. (The M10 remains off.)
(3) When M0 is on (the conditional formula of the IF conditional statement is TRUE) and M1 is also on (the instruction execution condition is on), the on/off
determination result will be off to on (rising edge). The PLS instruction is executed. (The M10 is on for one scan.)
• To execute the rising or falling edge execution instruction in the iteration statement, use the edge relay (V) or perform index
modification. When the rising or falling edge execution instruction in the iteration statement is used, the instruction may not
be executed normally at rising or falling edge.
Ex.
When the rising execution instructions is used in the FOR statement
• Example that the edge relay (V) is used*2
FOR Z0 := 0 TO 9 BY 1 DO
INC(EGP(M100Z0, V0Z0), D100Z0);
END_FOR;
• Example that the edge relay (V) is not used
FOR Z0 := 0 TO 9 BY 1 DO
INC(M100Z0, D100Z0);
END_FOR;
*2 The edge relay (V) is used 1 bit in the system in addition to the number of bits used in the loop. The edge relay (V) is used up to a total
of 11 points (V0 to V10) in the above example.
5 WRITING PROGRAMS
84 5.1 ST
Operations when the master control instruction is used
Operations between the MC and MCR instructions when the master control is off will be as follows.
• Off is assigned to the assignment statement (bit).
• The assignment statement (word) performs no processing.
• When the statement is other than assignment statement, the execution processing is not performed.
Ex.
For the assignment statement (bit)
MC(M0, N1, M1);
M3 := M2;
M20 := MCR(M0, N1);
Ex.
For the assignment statement (word)
MC(M0, N1, M1);
D3 := D2;
5
M20 := MCR(M0, N1);
D3 retains the previous value because no processing is performed when the master control is off.
Ex.
For the statement (OUT instruction) that is other than assignment statement
MC(M0, N1, M1);
OUT(M2, M3);
M20 := MCR(M0, N1);
M3 is off because the instruction is not executed when the master control is off.
5 WRITING PROGRAMS
5.1 ST 85
5.2 Structured Ladder/FBD
The structured ladder/FBD is a graphic language for writing programs using ladder symbols such as contacts, coils, functions,
and function blocks.
Standard format
Contact Coil
Function
Ladder block label Function block
In the structured ladder/FBD language, units of ladder blocks are used for programming.
For structured ladder, connect the left power rail and ladder symbols with lines.
For FBD, connect the ladder symbols with lines according to the flow of data or signals without connecting with the left power
rail.
5 WRITING PROGRAMS
86 5.2 Structured Ladder/FBD
Ladder symbols in structured ladder/FBD language
The following table shows the ladder symbols that can be used in the structured ladder/FBD language.
For details, refer to the following manual.
MELSEC-Q/L Structured Programming Manual (Common Instructions)
Element Ladder symbol Description
*1*2
Normal Turns ON when a specified device or label is ON
Rising edge*1*2*3 Turns ON at the rising edge (OFF to ON) of a specified device or label.
Falling edge*1*2*3 Turns ON at the falling edge (ON to OFF) of a specified device or label.
5
Negated rising edge*1*2*3 Turns ON when a specified device or label is OFF or ON, or at the falling edge (ON to OFF) of a specified
device or label.
Negated falling edge*1*2*3 Turns ON when a specified device or label is OFF or ON, or at the rising edge (OFF to ON) of a specified
device or label.
Negation*1 A specified device or label turns ON when the operation result turns OFF.
Set*1 A specified device or label turns ON when the operation result turns ON.
Once the device or label turns ON, it remains ON even when the operation result turns OFF.
Reset*1 A specified device or label turns OFF when the operation result turns ON. If the operation result is OFF,
the status of the device or label does not change.
5 WRITING PROGRAMS
5.2 Structured Ladder/FBD 87
Element Ladder symbol Description
Function return value Outputs the return value from a function or function block.
output
Function inverted return Inverts the return value from a function or function block and outputs it
value output
( )
Parallel-connection contact
*3 Supported with GX Works2 Version 1.15R or later.
For the confirmation method of the version of GX Works2, refer to the following manual.
GX Works2 Version 1 Operating Manual (Common)
The performance of return differs depending on the programs, functions, and function blocks being used.
• When used in the programs
End the execution of POUs
• When used in the functions
End the functions. Also, return to the next step of the instruction which called the functions.
• When used in the function blocks
The performance differs depending on whether "Use Macrocode" is checked or not on the Property screen.
When it is checked, end the execution of POUs.
When it is not checked, end the function blocks. Also, return to the next step of the instruction which called the
functions.
5 WRITING PROGRAMS
88 5.2 Structured Ladder/FBD
Executing order
The following figures explain the program executing order.
The operation order in a ladder block is from the left power rail to the right and from the top to the bottom.
(3) (4)
(5)
The program is executed from the left power rail to the right when the ladder is not branched and ENs and ENOs are
connected in series.
5
(1)
(5)
(4)
(3)
(2)
5 WRITING PROGRAMS
5.2 Structured Ladder/FBD 89
The program is executed from the top to the bottom, when the ladder is branched and ENs and ENOs are connected in
parallel.
(2)
(3)
(1)
(4)
(5)
The program is executed in the order as shown below when the MOV instruction (4) in the above figure is moved to the top.
(2)
(3)
(1) (4)
Move to the top
(5)
5 WRITING PROGRAMS
90 5.2 Structured Ladder/FBD
Ladder branches and compilation results
When the ladder is branched, different compilation results are produced for the program after the branch depending on the
program up to the branch. The following explains the precautions on compilation results depending on ladder branches.
■Precautions
When the device in which the value changes during one scan (such as SM412) is used, only a part of the sequence program
after the branch is executed, and the rest of the sequence program may not be executed.
When executing multiple instructions against one contact, connect the instructions in series. Since the sequence program
uses the LD instruction only once in the compilation result, all sequence programs are executed.
5 WRITING PROGRAMS
5.2 Structured Ladder/FBD 91
Multiple contacts are used up to the branch
The temporary variable is appended to the branch in the compilation result.
< Example > < Compilation result >
Connect the instructions in series to avoid using temporary variables in the compilation result.
Page 91 Precautions
For details on temporary variables, refer to the following manual.
GX Works2 Version 1 Operating Manual (Structured Project)
Ex.
Program example which causes compilation error
To avoid a compilation error, use LD$=, LD$<>, LD$<=, LD$<, LD$>=, or LD$> instructions.
Ex.
Program example which avoids compilation error
5 WRITING PROGRAMS
92 5.2 Structured Ladder/FBD
APPENDICES
Appendix 1 Correspondence Between Generic Data
Types and Devices
The following table shows the correspondence between generic data types and devices.
Bit device
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
Input X *2 *2 *2 *2
Output Y *2 *2 *2 *2
Internal relay M *2 *2 *2 *2
Latch relay L *2 *2 *2 *2
Annunciator F *2 *2 *2 *2
Edge relay V
A
Step relay S *2 *2 *2 *2
Link special relay SB *2 *2 *2 *2
Link relay B *2 *2 *2 *2
Timer contact*2 TS *2 *2 *2 *2
Timer coil*2 TC *2 *2 *2 *2
*2 *2 *2 *2
Retentive timer STS
contact*2
Retentive timer STC *2 *2 *2 *2
coil*2
Counter contact*2 CS *2 *2 *2 *2
Counter coil CC *2 *2 *2 *2
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
*2 Can be used for digit specification.
APPX
Appendix 1 Correspondence Between Generic Data Types and Devices 93
Word device
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
Timer current T or TN*2
value
Retentive timer ST or
current value STN*2
Counter current C or CN*2
value
Data register D *3
Link register W *3
*3
Link special SW
register
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
*2 Can be used for digit specification.
*3 Can be used for bit specification
APPX
94 Appendix 1 Correspondence Between Generic Data Types and Devices
Internal system device
Bit device
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
Function input FX
Function output FY
Special relay SM *2 *2 *2 *2
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
*2 Can be used for digit specification.
Word device
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL A
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
Function register FD
Special register SD *2
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
*2 Can be used for bit specification
APPX
Appendix 1 Correspondence Between Generic Data Types and Devices 95
Link direct device
Bit device
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
Link input Jn\X *2 *2 *2 *2
Link output Jn\Y *2 *2 *2 *2
Link relay Jn\B *2 *2 *2 *2
Link special relay Jn\SB *2 *2 *2 *2
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
*2 Can be used for digit specification.
Word device
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
Link register Jn\W *2
Link special Jn\SW *2
register
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
*2 Can be used for bit specification
APPX
96 Appendix 1 Correspondence Between Generic Data Types and Devices
Intelligent function module device
Word device
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
Intelligent function Un\G *2
module device
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
*2 Can be used for bit specification
Index register
Word device
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String A
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
Index register Z
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
APPX
Appendix 1 Correspondence Between Generic Data Types and Devices 97
File register
Word device
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
File register R or ZR *2
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
*2 Can be used for bit specification
Nesting
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
Nesting N
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
Pointer
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
Pointer P
Interrupt pointer I
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
APPX
98 Appendix 1 Correspondence Between Generic Data Types and Devices
Constant
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
K, H
E
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
String constant
Device Generic data type
Device name Device ANY*1
symbol ANY_SIMPLE
ANY_BIT ANY_NUM Time String
ANY_INT ANY_REAL
Bit Word Double Word Double Single- Double-
(unsigned) word (signed) word precision precision
/16-bit (unsigned) (signed) real real
string /32-bit
string
A
'Character
string' or
"Character
string"
*1 Devices available for ANY16 are the same as the ones for word (unsigned)/16-bit string and word (signed).
Devices available for ANY32 are the same as the ones for double word (unsigned)/32-bit string and double word (signed).
No devices are available for arrays and structures.
APPX
Appendix 1 Correspondence Between Generic Data Types and Devices 99
Appendix 2 Character Strings That Cannot Be Used
in Label Names and Data Names
Character strings used for application function names, common instruction names, special instruction names, and instruction
words are called reserved words.
These reserved words cannot be used for label names or data names. If the character string defined as a reserved word is
used for a label name or data name, an error occurs during registration or compilation.
The following tables shows character strings that cannot be used for label names or data names.
The numbers from (1) to (9) in the tables indicate the following label names and data names.
<Label name and data name>
(1) Project file name
(2) Program file name (Simple (without labels))
(3) Program file name (Simple (with labels))
(4) Program file name (structure)
(5) Task name
(6) Global label data name
(7) Structure name
(8) POU name
(9) Label name
APPX
100 Appendix 2 Character Strings That Cannot Be Used in Label Names and Data Names
Category Character string (1) (2) (3) (4) (5) (6) (7) (8) (9)
Application instruction Application instructions such as DMOD, PCHK, INC(P) *1
in GX Works2 For details, refer to the following.
• QCPU (Q mode)/LCPU
MELSEC-Q/L Programming Manual (Common
Instruction)
MELSEC-Q/L Structured Programming Manual
(Common Instructions)
• FXCPU
FXCPU Structured Programming Manual [Basic &
Applied Instruction]
FXCPU Structured Programming Manual [Application
Functions]
SFC instruction SFCP, SFCPEND, BLOCK, BEND, TRANL, TRANO, *1
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
ST code body 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,
FUNCTION_BLOCK, END_FUNCTION_BLOCK, STEP,
INITIAL_STEP, END_STEP, TRANSITION,
END_TRANSITION, FROM, TO, UNTILWHILE
Function name in Function names in application functions such as AND_E,
application function NOT_E
Function block name Function block names in application functions such as CTD,
in application function CTU
Symbol /, \, *, ?, <, >, |, ", :, [, ] , , , =, +, %, ', ~, @, {, }, &, ^, ., ', tab
character
;
!, #, $, `
A
Date and time literal DATE, DATE_AND_TIME, DT, TIME, TIME_OF_DAY, TOD
Others 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,
RETAIN, INTERVAL
String that starts with Such as K1AAA *1
K1 to K8
Address Such as %IX0
Statement in ladder ;FB BLK START, ;FB START, ;FB END, ;FB BLK END, ;FB
language IN, ;FB OUT, ;FB_NAME;,INSTANCE_NAME, ;FB,
;INSTANCE
Common instruction Such as MOV *3
Windows reserved COM1, COM2, COM3, COM4, COM5, COM6, COM7,
word COM8, COM9, LPT1, LPT2, LPT3, LPT4, LPT5, LPT6,
LPT7, LPT8, LPT9, AUX, CON, PRN, NUL
APPX
Appendix 2 Character Strings That Cannot Be Used in Label Names and Data Names 101
Precautions on using labels
• In a function, the same name as the function cannot be used for a label.
• A space cannot be used.
• A numeral cannot be used at the beginning of label name.
• A label name is not case-sensitive. An error may occur at compilation when the same label names with different cases
(example: 'AAA' and 'aaa') are declared.
• An underscore (_) cannot be used at the beginning or end of label name. Consecutive underscores (_) cannot be used for
data name and label name.
• For Simple projects, function names and function block names in common instructions and application functions can be
used.
• In structured ladder/FBD and ST programs, the same label name can be used for a global label and a local label by setting
the following option in GX Works2.
Check the "Use the same label name in global label and local label" item under [Tool] [Options] "Compile" "Basic
Setting".
APPX
102 Appendix 2 Character Strings That Cannot Be Used in Label Names and Data Names
Appendix 3 Recreating Ladder Programs
This section provides an example of creating a structured program same as the program created in the ladder programming
language using GX Works2.
2. Setting labels Global labels and local labels to be used in the program must be defined.
Define all labels to be used in the program.
APPX
Appendix 3 Recreating Ladder Programs 103
Example of creating a structured program
This section shows an example of creating a sequence program same as the program created in GX Developer using GX
Works2.
Ex.
The following examples explain the method for creating a structured program same as the data receive program for a Q-
compatible serial communication module, using the structured ladder/FBD and ST languages.
The following shows the original program.
APPX
104 Appendix 3 Recreating Ladder Programs
Setting labels
Set global labels and local labels.
• Setting examples of global labels
*1 Devices of local labels are automatically assigned within the range specified in the device/label automatic-assign setting in GX Works2.
To assign the same devices as those in the original ladder program, set them as global labels.
APPX
Appendix 3 Recreating Ladder Programs 105
Creating a structured program
The following examples show how a structured program is created based on the original program.
• Original program (Programming language: ladder)
APPX
106 Appendix 3 Recreating Ladder Programs
• Original program (Programming language: ladder)
*1
2
*1
*1
*1 2
3 A
*1 When using multiple contacts for execution conditions, enclose them by '( )' to be programmed in a group.
APPX
Appendix 3 Recreating Ladder Programs 107
INDEX
0 to 9 I
16-bit index setting . . . . . . . . . . . . . . . . . . . . . . 57 IEC 61131-3. . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
32-bit index setting . . . . . . . . . . . . . . . . . . . . . . 60 Index Setting . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
Input variables . . . . . . . . . . . . . . . . . . . . . . . . . .30
Input/output variables . . . . . . . . . . . . . . . . . . . . . 30
A
Instances . . . . . . . . . . . . . . . . . . . . . . . . . . . 20,26
Address . . . . . . . . . . . . . . . . . . . . . . . . . . . . 53,54 Internal variables . . . . . . . . . . . . . . . . . . . . . . . . 25
Application function . . . . . . . . . . . . . . . . . . . . . . . 7
Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48 L
Labels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
B
Ladder block labels . . . . . . . . . . . . . . . . . . . . . . .22
Basic model QCPU . . . . . . . . . . . . . . . . . . . . . . . 7 Ladder blocks. . . . . . . . . . . . . . . . . . . . . . . . . . .22
Bit data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36 Ladder symbols . . . . . . . . . . . . . . . . . . . . . . . . .87
LCPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
Libraries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .70
C Local labels . . . . . . . . . . . . . . . . . . . . . . . . . . . .29
Calling function blocks . . . . . . . . . . . . . . . . . . . . 81
Calling functions . . . . . . . . . . . . . . . . . . . . . . . . 81 M
Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 30
Common instruction . . . . . . . . . . . . . . . . . . . . . . 7 Method for specifying data . . . . . . . . . . . . . . . . . . 35
Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
Correspondence between generic data types and
O
devices . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
CPU module . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7 Operators . . . . . . . . . . . . . . . . . . . . . . . . . . . . .74
Output variables . . . . . . . . . . . . . . . . . . . . . . 24,30
D
P
Data types . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 52,54 Personal computer . . . . . . . . . . . . . . . . . . . . . . . .7
Double word (32 bits) data . . . . . . . . . . . . . . . . . 39 POU . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .18
Double-precision real Precautions on assigning a name . . . . . . . . . . . . .72
(double-precision floating-point data) . . . . . . . . . . 43 Priority . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .17
Process CPU . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
Program blocks . . . . . . . . . . . . . . . . . . . . . . . . .19
E
Program components . . . . . . . . . . . . . . . . . . 10,12
Elementary data types . ................... 32 Program files . . . . . . . . . . . . . . . . . . . . . . . . . . . 16
EN. . . . . . . . . . . . . . . ................... 27 Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11,16
ENO . . . . . . . . . . . . . ................... 27
Executing condition . . . ................... 17 Q
QCPU (Q mode) . . . . . . . . . . . . . . . . . . . . . . . . . .7
F
QnU(D)(H)CPU . . . . . . . . . . . . . . . . . . . . . . . . . .7
FBD. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 86 QnUDE(H)CPU . . . . . . . . . . . . . . . . . . . . . . . . . .7
Function blocks. . . . . . . . . . . . . . . . . . . . . . . . . 20 QnUDPVCPU. . . . . . . . . . . . . . . . . . . . . . . . . . . .7
Functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19 QnUDVCPU . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
FXCPU . . . . . . . . . ...................... 7
R
G
Redundant CPU . . . . . . . . . . . . . . . . . . . . . . . . . .7
Generic data type . . . . . . . . . . . . . . . . . . . . . . . 33
Global labels . . . . . . . . . . . . . . . . . . . . . . . . . . 29 S
GX Developer . . . . . ...................... 7
GX Works2. . . . . . . ...................... 7 Single-precision real . . . . . . . . . . . . . . . . . . . . . .42
Special instruction . . . . . . . . . . . . . . . . . . . . . . . .7
Specify a bit device of word device . . . . . . . . . . . .36
H
Specify digits of bit data. . . . . . . . . . . . . . . . . 37,39
Hierarchy . . . . . . . . . . . . . . . . . . . . . . . . . . . 10,11 ST. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23,73
High Performance model QCPU . . . . . . . . . . . . . . 7 Standard format . . . . . . . . . . . . . . . . . . . . . . 73,86
High-speed Universal model QCPU . . . . . . . . . . . 7 String data . . . . . . . . . . . . . . . . . . . . . . . . . . . . .46
Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .51
108
Structured design . . . . . . . . . . . . . . . . . . . . . . . 10
Structured ladder . . . . . . . . . . . . . . . . . . . . . . . 86
Structured ladder/FBD . . . . . . . . . . . . . . . . . . 23,86
Syntax in ST language. . . . . . . . . . . . . . . . . . . . 75
T
Tasks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
Time data . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
U
Universal model Process CPU . . . . . . . . . . . . . . . 7
Universal model QCPU . . . . . . . . . . . . . . . . . . . . 7
User libraries . . . . . . . . . . . . . . . . . . . . . . . . . . 71
W
Word (16 bits) data . . . . . . . . . . . . . . . . . . . . . . 37
109
REVISIONS
*The manual number is given on the bottom left of the back cover.
Print date *Manual number Revision
July 2008 SH(NA)-080782ENG-A Due to the transition to the e-Manual, the details of revision have been deleted.
July 2013 SH(NA)-080782ENG-M
October 2015 SH(NA)-080782ENG-N Complete revision (layout change)
September 2018 SH(NA)-080782ENG-O ■Added or modified parts
INTRODUCTION, Section 4.4, 4.6
110
WARRANTY
Please confirm the following product warranty details before using this product.
1. Gratis Warranty Term and Gratis Warranty Range
If any faults or defects (hereinafter "Failure") found to be the responsibility of Mitsubishi occurs during use of the product
within the gratis warranty term, the product shall be repaired at no cost via the sales representative or Mitsubishi Service
Company.
However, if repairs are required onsite at domestic or overseas location, expenses to send an engineer will be solely at
the customer's discretion. Mitsubishi shall not be held responsible for any re-commissioning, maintenance, or testing
on-site that involves replacement of the failed module.
[Gratis Warranty Term]
The gratis warranty term of the product shall be for one year after the date of purchase or delivery to a designated place.
Note that after manufacture and shipment from Mitsubishi, the maximum distribution period shall be six (6) months, and
the longest gratis warranty term after manufacturing shall be eighteen (18) months. The gratis warranty term of repair
parts shall not exceed the gratis warranty term before repairs.
[Gratis Warranty Range]
(1) The range shall be limited to normal use within the usage state, usage methods and usage environment, etc., which
follow the conditions and precautions, etc., given in the instruction manual, user's manual and caution labels on the
product.
(2) Even within the gratis warranty term, repairs shall be charged for in the following cases.
1. Failure occurring from inappropriate storage or handling, carelessness or negligence by the user. Failure caused
by the user's hardware or software design.
2. Failure caused by unapproved modifications, etc., to the product by the user.
3. When the Mitsubishi product is assembled into a user's device, Failure that could have been avoided if functions
or structures, judged as necessary in the legal safety measures the user's device is subject to or as necessary by
industry standards, had been provided.
4. Failure that could have been avoided if consumable parts (battery, backlight, fuse, etc.) designated in the
instruction manual had been correctly serviced or replaced.
5. Failure caused by external irresistible forces such as fires or abnormal voltages, and Failure caused by force
majeure such as earthquakes, lightning, wind and water damage.
6. Failure caused by reasons unpredictable by scientific technology standards at time of shipment from Mitsubishi.
7. Any other failure found not to be the responsibility of Mitsubishi or that admitted not to be so by the user.
2. Onerous repair term after discontinuation of production
(1) Mitsubishi shall accept onerous product repairs for seven (7) years after production of the product is discontinued.
Discontinuation of production shall be notified with Mitsubishi Technical Bulletins, etc.
(2) Product supply (including repair parts) is not available after production is discontinued.
3. Overseas service
Overseas, repairs shall be accepted by Mitsubishi's local overseas FA Center. Note that the repair conditions at each FA
Center may differ.
4. Exclusion of loss in opportunity and secondary loss from warranty liability
Regardless of the gratis warranty term, Mitsubishi shall not be liable for compensation to:
(1) Damages caused by any cause found not to be the responsibility of Mitsubishi.
(2) Loss in opportunity, lost profits incurred to the user by Failures of Mitsubishi products.
(3) Special damages and secondary damages whether foreseeable or not, compensation for accidents, and
compensation for damages to products other than Mitsubishi products.
(4) Replacement by the user, maintenance of on-site equipment, start-up test run and other tasks.
5. Changes in product specifications
The specifications given in the catalogs, manuals or technical documents are subject to change without prior notice.
111
TRADEMARKS
Microsoft and Windows are either registered trademarks or trademarks of Microsoft Corporation in the United States and/or
other countries.
The company names, system names and product names mentioned in this manual are either registered trademarks or
trademarks of their respective companies.
In some cases, trademark symbols such as '' or '' are not specified in this manual.
112 SH(NA)-080782ENG-O
SH(NA)-080782ENG-O(1809)KWIX
MODEL: Q/FX-KP-KI-E
MODEL CODE: 13JW06
HEAD OFFICE : TOKYO BUILDING, 2-7-3 MARUNOUCHI, CHIYODA-KU, TOKYO 100-8310, JAPAN
NAGOYA WORKS : 1-14 , YADA-MINAMI 5-CHOME , HIGASHI-KU, NAGOYA , JAPAN
When exported from Japan, this manual does not require application to the
Ministry of Economy, Trade and Industry for service transaction permission.