FX5 Programming Manual (Program Design PDF
FX5 Programming Manual (Program Design PDF
INTRODUCTION
This manual describes the instructions and functions required for programming of the FX5. Please read this manual and the
relevant manuals and understood the functions and performance of the FX5 PLCs before attempting to use the unit.
It should be read and understood before attempting to install or use the unit. Store this manual in a safe place so that you can
take it out and read it whenever necessary. Always forward it to the end user.
When utilizing the program examples introduced in this manual to the actual system, always confirm that it poses no problem
for control of the target system.
Note
• If in doubt at any stage during the installation of the product, always consult a professional electrical engineer who is
qualified and trained to the local and national standards. If in doubt about the operation or use, please consult the nearest
Mitsubishi Electric representative.
• Since the examples indicated by this manual, technical bulletin, catalog, etc. are used as a reference, please use it after
confirming the function and safety of the equipment and system. Mitsubishi Electric will accept no responsibility for actual
use of the product based on these illustrative examples.
• This manual content, specification etc. may be changed without a notice for improvement.
• The information in this manual has been carefully checked and is believed to be accurate; however, if you have noticed a
doubtful point, a doubtful error, etc., please contact the nearest Mitsubishi Electric representative. When doing so, please
provide the manual number given at the end of this manual.
1
CONTENTS
SAFETY PRECAUTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
RELEVANT MANUALS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .4
TERMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .5
CHAPTER 1 OUTLINE 7
CHAPTER 4 LABELS 32
4.1 Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
4.2 Class . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.3 Data Type . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
4.4 Arrays . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
4.5 Structures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
4.6 Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
4.7 Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
CHAPTER 6 ST LANGUAGE 48
6.1 Configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
Delimiter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
Syntax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 51
Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Label and device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
Comment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 60
2
7.2 Program Execution Order. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
The order of executions of program units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
APPENDIX 68
Appendix 1 Operations of when the MC/MCR instructions are used to control EN . . . . . . . . . . . . . . . . . . . . . . . 68
INDEX 74
REVISIONS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .76
WARRANTY . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .77
CONTENTS
TRADEMARKS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .78
3
RELEVANT MANUALS
Manual name <manual number> Description
MELSEC iQ-F FX5 User's Manual (Startup) Performance specifications, procedures before operation, and troubleshooting of the
<JY997D58201> CPU module.
MELSEC iQ-F FX5UJ User's Manual (Hardware) Describes the details of hardware of the FX5UJ CPU module, including input/output
<SH-082206ENG> specifications, wiring, installation, and maintenance.
MELSEC iQ-F FX5U User's Manual (Hardware) Describes the details of hardware of the FX5U CPU module, including input/output
<JY997D55301> specifications, wiring, installation, and maintenance.
MELSEC iQ-F FX5UC User's Manual (Hardware) Describes the details of hardware of the FX5UC CPU module, including input/output
<JY997D61401> specifications, wiring, installation, and maintenance.
MELSEC iQ-F FX5 User's Manual (Application) Describes basic knowledge required for program design, functions of the CPU
<JY997D55401> module, devices/labels, and parameters.
MELSEC iQ-F FX5 Programming Manual (Program Design) Describes specifications of ladders, ST, FBD/LD, and other programs and labels.
<JY997D55701> (This manual)
MELSEC iQ-F FX5 Programming Manual (Instructions, Standard Describes specifications of instructions and functions that can be used in programs.
Functions/Function Blocks)
<JY997D55801>
MELSEC iQ-F FX5 User's Manual (Serial Communication) Describes N:N network, Parallel link, MELSEC Communication protocol, inverter
<JY997D55901> communication, non-protocol communication, and predefined protocol support.
MELSEC iQ-F FX5 User's Manual (MELSEC Communication Protocol) Explains methods for the device that is communicating with the CPU module by MC
<JY997D60801> protocol to read and write the data of the CPU module.
MELSEC iQ-F FX5 User's Manual (MODBUS Communication) Describes MODBUS serial communication and MODBUS/TCP communication.
<JY997D56101>
MELSEC iQ-F FX5 User's Manual (PROFIBUS) Describes the functions of the PROFIBUS-DP master module.
<SH-081910ENG>
MELSEC iQ-F FX5 User's Manual (Ethernet Communication) Describes the Ethernet communication function of the CPU module built-in and the
<JY997D56201> Ethernet module.
MELSEC iQ-F FX5-ENET User's Manual Describes the functions of the Ethernet module.
<SH-082026ENG>
MELSEC iQ-F FX5 User's Manual (SLMP) Explains methods for the device that is communicating with the CPU module by
<JY997D56001> SLMP to read and write the data of the CPU module.
MELSEC iQ-F FX5 User's Manual (CC-Link IE) Describes CC-Link IE field network module.
<JY997D64201>
MELSEC iQ-F FX5 User's Manual (CC-Link) Describes CC-Link system master/intelligent device module.
<SH-081793ENG>
MELSEC iQ-F FX5 User's Manual (AnyWireASLINK) Describes AnyWireASLINK system master module.
<SH-081796ENG>
MELSEC iQ-F FX5 User's Manual (Positioning Control - CPU module Describes the positioning function of the CPU module built-in and the high-speed
built-in, High-speed pulse input/output module) pulse input/output module.
<JY997D56301>
MELSEC iQ-F FX5 User's Manual (Positioning Control - Intelligent Describes the positioning module.
function module)
<SH-081805ENG>
MELSEC iQ-F FX5 Simple Motion Module User's Manual (Startup) Specifications, procedures before operation, system configuration, wiring, and
<IB0300251> operation examples of the Simple Motion module.
MELSEC iQ-F FX5 Simple Motion Module User's Manual (Application) Functions, input/output signals, buffer memories, parameter settings, programming,
<IB0300253> and troubleshooting of the Simple Motion module.
MELSEC iQ-F FX5 Simple Motion Module User's Manual (Advanced Functions and programming for the synchronous control of the Simple Motion
Synchronous Control) module.
<IB0300255>
MELSEC iQ-F FX5 User's Manual (Analog Control - CPU module built- Describes the analog function of the CPU module built-in and the analog adapter.
in, Expansion adapter)
<JY997D60501>
MELSEC iQ-F FX5 User's Manual (Analog Control - Intelligent function Describes the analog input module, analog output module, and multiple input
module) module.
<SH-081802ENG>
MELSEC iQ-F FX5 User's Manual (Temperature Control) Describes the temperature control module.
<SH-081799ENG>
MELSEC iQ-F FX5 User's Manual (Safety Control) Describes the safety extension modules.
<SH082078ENG>
4
Manual name <manual number> Description
GX Works3 Operating Manual System configuration, parameter settings, and online operations of GX Works3.
<SH-081215ENG>
Transition from MELSEC FX3G, FX3U, FX3UC Series to MELSEC iQ- Describes the transition from MELSEC FX3G/FX3U/FX3UC series to MELSEC iQ-F
F Series Handbook series.
<JY997D66201>
TERMS
Unless otherwise specified, this manual uses the following terms.
For details on the FX3 devices that can be connected with the FX5, refer to the User’s Manual (Hardware) of the CPU module
to be used.
Terms Description
■Devices
FX5 Generic term for FX5UJ, FX5U and FX5UC PLCs
FX3 Generic term for FX3S, FX3G, FX3GC, FX3U, and FX3UC PLCs
FX5 CPU module Generic term for FX5UJ CPU module, FX5U CPU module and FX5UC CPU module
FX5UJ CPU module Generic term for FX5UJ-24MR/ES, FX5UJ-24MT/ES, FX5UJ-24MT/ESS, FX5UJ-40MR/ES, FX5UJ-40MT/ES,
FX5UJ-40MT/ESS, FX5UJ-60MR/ES, FX5UJ-60MT/ES, and FX5UJ-60MT/ESS
FX5U CPU module Generic term for FX5U-32MR/ES, FX5U-32MT/ES, FX5U-32MT/ESS, FX5U-64MR/ES, FX5U-64MT/ES,
FX5U-64MT/ESS, FX5U-80MR/ES, FX5U-80MT/ES, FX5U-80MT/ESS, FX5U-32MR/DS, FX5U-32MT/DS,
FX5U-32MT/DSS, FX5U-64MR/DS, FX5U-64MT/DS, FX5U-64MT/DSS, FX5U-80MR/DS, FX5U-80MT/DS, and
FX5U-80MT/DSS
FX5UC CPU module Generic term for FX5UC-32MT/D, FX5UC-32MT/DSS, FX5UC-64MT/D, FX5UC-64MT/DSS, FX5UC-96MT/D,
FX5UC-96MT/DSS, FX5UC-32MT/DS-TS, FX5UC-32MT/DSS-TS, and FX5UC-32MR/DS-TS
Extension module Generic term for FX5 extension modules, FX3 function modules, Extension modules (extension cable type) and
Extension module (extension connector type)
FX5 extension module Generic term for I/O modules, FX5 extension power supply modules, FX5 intelligent function modules, and FX5
safety extension modules
FX3 extension module Generic term for FX3 extension power supply module and FX3 intelligent function module
Extension module (extension cable type) Generic term for Input modules (extension cable type), Output modules (extension cable type), Input/output
modules (extension cable type), Powered input/output module, High-speed pulse input/output module,
Extension power supply module (extension cable type), Connector conversion module (extension cable type),
Intelligent function modules, Safety extension modules, and Bus conversion module (extension cable type)
Extension module (extension connector Generic term for Input modules (extension connector type), Output modules (extension connector type), Input/
type) output modules (extension connector type), Extension power supply module (extension connector type),
Connector conversion module (extension connector type), and Bus conversion module (extension connector
type)
I/O module Generic term for Input modules, Output modules, Input/output modules, Powered input/output modules, and
High-speed pulse input/output modules
Input module Generic term for Input modules (extension cable type) and Input modules (extension connector type)
Input module (extension cable type) Generic term for FX5-8EX/ES and FX5-16EX/ES
Input module (extension connector type) Generic term for FX5-C16EX/D, FX5-C16EX/DS, FX5-C32EX/D, FX5-C32EX/DS, and FX5-C32EX/DS-TS
Output module Generic term for Output modules (extension cable type) and Output modules (extension connector type)
Output module (extension cable type) Generic term for FX5-8EYR/ES, FX5-8EYT/ES, FX5-8EYT/ESS, FX5-16EYR/ES, FX5-16EYT/ES, and FX5-
16EYT/ESS
Output module (extension connector type) Generic term for FX5-C16EYT/D, FX5-C16EYT/DSS, FX5-C16EYR/D-TS, FX5-C32EYT/D, FX5-C32EYT/DSS,
FX5-C32EYT/D-TS, and FX5-C32EYT/DSS-TS
Input/output module Generic term for Input/output modules (extension cable type) and Input/output modules (extension connector
type)
Input/output module (extension cable type) Generic term for FX5-16ER/ES, FX5-16ET/ES, and FX5-16ET/ESS
Input/output module (extension connector Generic term for FX5-C32ET/D, FX5-C32ET/DSS, FX5-C32ET/DS-TS, and FX5-C32ET/DSS-TS
type)
Powered input/output module Generic term for FX5-32ER/ES, FX5-32ET/ES, FX5-32ET/ESS, FX5-32ER/DS, FX5-32ET/DS, and FX5-32ET/
DSS
High-speed pulse input/output module Generic term for FX5-16ET/ES-H and FX5-16ET/ESS-H
Extension power supply module Generic term for FX5 extension power supply module and FX3 extension power supply module
FX5 extension power supply module Generic term for FX5 extension power supply module (extension cable type) and FX5 extension power supply
module (extension connector type)
5
Terms Description
FX5 extension power supply module Different name for FX5-1PSU-5V
(extension cable type)
FX5 extension power supply module Different name for FX5-C1PS-5V
(extension connector type)
FX3 extension power supply module Different name for FX3U-1PSU-5V
Intelligent module The abbreviation for intelligent function modules
Intelligent function module Generic term for FX5 intelligent function modules and FX3 intelligent function modules
FX5 intelligent function module Generic term for FX5-4AD, FX5-4DA, FX5-8AD, FX5-4LC, FX5-20PG-P, FX5-20PG-D, FX5-40SSC-S, FX5-
80SSC-S, FX5-ENET, FX5-CCLIEF, FX5-CCL-MS, FX5-ASL-M, and FX5-DP-M
FX3 intelligent function module Generic term for FX3U-4AD, FX3U-4DA, FX3U-4LC, FX3U-1PG, FX3U-2HC, FX3U-16CCL-M, FX3U-64CCL,
FX3U-128ASL-M, and FX3U-32DP
FX5 safety extension module Generic term for safety main modules and safety expansion modules
Safety main module Different name for FX5-SF-MU4T5
Safety expansion module Generic term for expansion modules installed to a safety main module
Safety input expansion module Different name for FX5-SF-8DI4
Expansion board Generic term for board for FX5UJ CPU module and FX5U CPU module
Communication board Generic term for FX5-232-BD, FX5-485-BD, and FX5-422-BD-GOT
Expansion adapter Generic term for adapter for FX5 CPU module
Communication adapter Generic term for FX5-232ADP and FX5-485ADP
Analog adapter Generic term for FX5-4AD-ADP, FX5-4DA-ADP, FX5-4AD-PT-ADP, and FX5-4AD-TC-ADP
Bus conversion module Generic term for Bus conversion module (extension cable type) and Bus conversion module (extension
connector type)
Bus conversion module (extension cable Different name for FX5-CNV-BUS
type)
Bus conversion module (extension Different name for FX5-CNV-BUSC
connector type)
Connector conversion module Generic term for Connector conversion module (extension cable type) and Connector conversion module
(extension connector type)
Connector conversion module (extension Different name for FX5-CNV-IF
cable type)
Connector conversion module (extension Different name for FX5-CNV-IFC
connector type)
Extended extension cable Generic term for FX5-30EC and FX5-65EC
Connector conversion adapter Different name for FX5-CNV-BC
Battery Different name for FX3U-32BL
Peripheral device Generic term for engineering tools and GOTs
GOT Generic term for Mitsubishi Electric Graphic Operation Terminal GOT1000 and GOT2000 series
■Software packages
Engineering tool The product name of the software package for the MELSEC programmable controllers
GX Works3 The product name of the software package, SWnDND-GXW3, for the MELSEC programmable controllers (The
'n' represents a version.)
■Program
Operand A generic term for items, such as source data (s), destination data (d), number of devices (n), and others, used
to configure instructions and functions.
Signal flow The execution status that the last time an operation of a program or an FB is executed in each step.
Device A device (X, Y, M, D, or others) in a CPU module.
Buffer memory A memory in an intelligent function module, where data (such as setting values and monitoring values) are
stored.
POU Defined unit of a program. Use of POUs enables a program to be divided into units according to process or
function, and each unit to be programmed individually.
6
1 OUTLINE
1
This manual describes program configurations, content, and method for creating programs.
For how to create, edit, or monitor programs using the engineering tool, refer to the following.
GX Works3 Operating Manual
■Ladder diagram
■ST language
■FBD/LD language
1 OUTLINE
7
• Ladder diagram and FBD/LD language are for customers who have knowledge or experience of sequence
control and logic circuits.
• ST language is for customers who have knowledge or experience of the C language programming.
• By using labels in a program, the readability of the program is improved, and activating a program for the
system with a different module configuration is easy.
1 OUTLINE
8
2 PROGRAM CONFIGURATION
Using the engineering tool, multiple programs and program organization units (POUs) can be created.
Programs and POUs can be divided according to processing.
This chapter describes the program configuration. 2
Project
Program file 1 Program file 2 FB file FUN file
POU POU POU POU
Program block Program block Function block Function
Program block
Project
A project is a group of data (such as programs and parameters) to be executed in a CPU module.
Only one project can be written to a single CPU module.
At least one program file needs to be created in a project.
Program file
A program file is a group of programs and POUs.
A program file consists of at least one program block. ( Page 11 Program Blocks)
The following operations are performed in units of program file: changing the program execution type from the fixed scan
execution type to the standby type and writing data to the CPU module.
2 PROGRAM CONFIGURATION
9
3 PROGRAM ORGANIZATION UNITS
There are three types of program organization units (POUs).
• Program block
• Function
• Function block
Processing can be described in the programming language that suits the control performed in each POU. Processing can be
described in the ladder diagram, structured text language, or FBD/LD in a function or a function block.
Functions and function blocks are called and executed by program blocks.
Project
Program file
Used
POU
Program block
POU folder
POU
Function block
POU
Function
Up to 32 worksheets can be created in one POU in the structured text language and FBD/LD.
Set the execution order of multiple worksheets on the "Worksheet Execution Order Setting" window of the
engineering tool. ( GX Works3 Operating Manual)
Program block 2
P0 I0
Main routine program Subroutine program Interrupt program
Execute the program according to the order of the execution of program file setting.
Program file setting
Actual program
Main routine program
ProgPou1
FEND
END (1) Main routine program
FEND
P0 P0
Subroutine program Subroutine program
ProgPou2
RET RET
END (1) I0
Interrupt program
I0 IRET
Interrupt program END
ProgPou3
IRET
END
(1) The END instruction in the middle of the program file is ignored.
• Create a subroutine program and interrupt program after the FEND instruction of the main routine program.
Any program after the FEND instruction is not executed as a main routine program. For example, when the
FEND instruction is used at the end of the second program block, the third program block or later runs as a
subroutine program or interrupt program. (Page 28 When a subroutine program or an interrupt program
is used)
• To create an easy-to-understand program, use a pair of instructions, such as the FOR and NEXT
instructions or the MC and MCR instructions, within a single program block.
• A simple program can be executed in the CPU module simply by writing the main routine in one program
block.
For details on the subroutine program and interrupt program, refer to the following.
MELSEC iQ-F FX5 User's Manual (Application)
Program
Function block
3
FUN
Function block
or Program
function block
FUN FB or FUN
Operation overview
The program of a function is stored in the FUN file and called by the calling source program when executed.
Ex.
When calling FUN1 and FUN2 from the main program, and calling FUN3 by FUN1 (Nested three times)
to indicate the execution flow (order).
(Program file) (FUN file)
Main program FUN1 program (FUN file)
FUN3 program
FUN3
FUN1
(FUN file)
FUN2 program
FUN2
Up to 32 subroutine type function blocks, macro type function blocks, and functions in total can be nested.
Input variables are set in the VAR_INPUT class and output variables are set in the VAR_OUTPUT class.
Variables defined in the function are overwritten every time the function is called.
To hold the data in the variables, create a program by using function blocks or so that the data in the output
variable is saved in another variable.
EN and ENO
EN (enable input) and ENO (enable output) can be appended to a function to control execution processing.
• Set a boolean variable used as an execution condition of a function to EN.
• A function with EN is executed only when the execution condition of EN is TRUE.
• Set a boolean variable used to output a function execution result to ENO.
The following table lists the ENO states and operation results according to the EN states.
EN ENO Operation result
TRUE (executed) TRUE Operation result output value
FALSE (not executed) FALSE Undefined value
• Setting an output label to ENO is not always required for the program written in ladder or FBD/LD.
• When EN/ENO is used in a standard function, the function with EN is represented by "function-name_E".
Program a function name as a label in a function to set a return value of the function. Setting function names
as labels is not necessary. The data type set in "Result Type" in the properties of the function can be used.
Ex.
When calling FUN1 and FUN2 from the main program, and calling FUN3 by FUN1
( to indicate the execution flow (order).)
(Program file) (FUN file)
Main program FUN1 program (FUN file)
FUN3 program
FUN3
FUN1
(FUN file)
FUN2 program
FUN2
The following figure shows the label assignments while the above functions are being executed.
Main program being executed FUN1 being executed FUN3 being executed FUN1 being executed
(before FUN3 is called) (after FUN3 is executed)
Temporary area
Main program being executed FUN2 being executed Main program being executed
The class of labels that can be defined in the function are VAR, VAR_CONSTANT, VAR_INPUT, and VAR_OUTPUT.
The label to be defined by a function must be initialized by a program before the first access because the label
value will be undefined.
■Program
The number of steps required for a function program is the total number of instruction steps plus a minimum of additional 13
steps occupied by the system. For the number of steps required for each instruction, refer to the following.
MELSEC iQ-F FX5 Programming Manual (Instructions, Standard Functions/Function Blocks)
■Calling source
3
When calling a function, the calling source generates the processing that passes the argument and return value before and
after the call processing.
Program block 1 (1) Passing the argument
(displayed) Program file (2) Calling the FUN1 program
(3) Passing the return value
Function Program
block block
FB
Function Program
block block
FB FB
(3) (3)
(4)
(4)
Ex.
When calling FB1_a and FB2_a from the main program, calling FB3_a by FB1_a, and calling FB3_b by FB2_a
Execution
3
(Program file) flow Actual structure of
Main program main program
FB1_a
FB1 FB1 program (1)
FB3 program
(2)
FB2_a
FB2 FB2 program (3)
FB3 program
(4)
(1) The FB1 program is loaded into the main program and executed.
(2) The FB3 program called by FB1 is loaded into the FB1 program.
(3) The FB2 program is loaded into the main program and executed in the same way as the FB1 program.
(4) The FB3 program called by FB2 is loaded into the FB2 program.
Ex.
When calling FB1_a and FB2_a from the main program, calling FB3_a by FB1_a, and calling FB3_b by FB2_a (Nested three
times)
to indicate the execution flow (order).
(Program file) (FB file)
Main program FB1 program (FB file) Program memory
FB3 program
FB3_a
FB1_a
FB3 Main program
FB1
FB1 program
(FB file)
FB2_a
FB2 program
FB2 FB2 program
FB3_b
FB3
FB3 program
Up to 32 subroutine type function blocks, macro type function blocks, and functions in total can be nested.
RESET iTim
lCnt
(1) (2)
Instance
CTD
CD Q
LOAD CV
PV
Input variables are set in the VAR_INPUT class, output variables are set in the VAR_OUTPUT class and
VAR_OUTPUT_RETAIN class, and input/output variables are set in the VAR_IN_OUT class.
Internal variables
Function blocks use internal variables. For each instance of a function block, labels are assigned to the different areas. Even
though the same label names are used, different states are held for each instance.
Ex.
Instance A Instance B
cdLabel11 cdLabel11
Current value Current value
The above function block starts counting when the input variables turn on and turns on the output variable when the current
value held in the internal variable reaches the set value. Even though the same function block is used, the output timings differ
because the instances A and B hold different states.
Internal variables are set in the VAR, VAR_CONSTANT and VAR_RETAIN class.
Ex.
Structure of instance (Example of subroutine type function block)
9 words
Reserved area 8 words
Creating another
instance based on
FB1 definition Another instance of FB1
(same area size)
Local label area
For the local label area and local latch label area, since the label area is secured in units of four words, three-words (padding
size) are secured in the above example.
Each area occupies a reserved area. The reserved area is used to add or change the local label, instructions, or instances of
the function block while keeping the label assignment by conversion or online change. If the area of the target data type to be
added cannot be secured, all programs are required to be converted (reassigned).
FB2 area
bLabel1 Reserved area 16 words FB1 area
16 words
MOVP wLabel0 wLabel1 36 words
The instance of FB2 declared as a local label is secured in the local label area, local latch label area, and signal flow for FB of
FB1 which is the declared source.
When an FB type local label to FB1 is added in the above example, since the capacity of the reserved area is 48 words for
local label area, 16 words for local latch label area, and 8 words for signal flow for FB, all programs are required to be
converted (reassigned) to add a function block with an area exceeding the capacity.
*1 Local labels can be declared as the local labels of a program block or function block. Local labels cannot be declared in a function.
Same function blocks can be instantiated with different names in a single POU. 3
Instance A
Function block
wLabel5
wLabel1 Input variable 1 wLabel8
wLabel6 Output variable wLabel4
wLabel2 Input variable 2
wLabel7 wLabel9
wLabel3 Input variable 3 Local variable
(1) (2)
Instance A Instance B
wLabel5 wLabel5
wLabel1 Input variable 1 wLabel8 wLabel10 Input variable 1 wLabel8
wLabel6 Output variable wLabel4 wLabel6 Output variable wLabel13
wLabel2 Input variable 2 wLabel11 Input variable 1
wLabel7 wLabel9 wLabel7 wLabel9
wLabel3 Input variable 3 Local variable wLabel12 Input variable 1 Local variable
If the reserved area capacity cannot be allocated to the data to be added by online change, the online change
cannot be executed and all programs are required to be converted (reassigned).
Creating programs
The program of a function block can be created by using the engineering tool. 3
[Navigation window] [FB/FUN] Right-click [Add New Data]
Select "Function Block" for "Data Type" in "Basic Setting".
The created program is stored in the FB file.
[CPU Parameter] [Program Setting] [FB/FUN File Setting]
Up to 64 created programs can be stored in one FB file.
For details on program creation, refer to the following.
Item Reference
How to create function blocks GX Works3 Operating Manual
Number of FB/FUN files that can be written to a CPU module MELSEC iQ-F FX5 User's Manual (Startup)
■Types of program
There are two types of function blocks and the program of each function block type is stored in different ways.
• Macro type function block
• Subroutine type function block
For details, refer to the following.
Page 19 Operation overview
The above cannot be selected for module function blocks, standard functions, and standard function blocks.
*1 To select this item, select "Yes" for "Use EN/ENO". However, the item cannot be used depending on the versions of the CPU module
and GX Works3 used when "Subroutine Type" is selected for "FB Type". For the versions of the CPU module and the GX Works3, refer
to the following.
MELSEC iQ-F FX5 User's Manual (Application)
FB1_a
FB1 program
FB1
(FB1_a)
FB1_b
FB1
FB1 program
(FB1_b)
(1)
■Program
The number of steps required for a function block program is the total number of instruction steps, like usual programs.
For the number of steps required for each instruction, refer to the following.
MELSEC iQ-F FX5 Programming Manual (Instructions, Standard Functions/Function Blocks)
FB1 program
• EN/ENO
The following table lists the number of steps required for EN/ENO.
Item Number of steps
EN 4 to 7
(The number of steps differs depending on the details of the program such as the type and number of the device specified as the
input source of EN.)
ENO 6 to 10
(The number of steps differs depending on the details of the program such as the type and number of the device specified as the
output destination of ENO.)
■Program
The number of steps required for a function block program is the total number of instruction steps, like usual programs.
For the number of steps required for each instruction, refer to the following.
MELSEC iQ-F FX5 Programming Manual (Instructions, Standard Functions/Function Blocks)
FEND
I0
Interrupt program
IRET
END
• Only one FEND instruction can be used for a program file. When multiple FEND instructions are used, an error occurs.
Program file
Execution
order
Because there are two
Main routine program
FEND instructions are in
the program file, an error
occurs.
FEND
FEND
I0
Interrupt program
IRET
END
MOV K0 Z2
Program execution
Ex.
Device used for passing the argument
MacroFbPou_1 (EN := M0, ENO => M1);
M2 := M1;
An unintended value may be generated if the argument of the macro type function block is used in other than the program of
the macro type function block.
Ex.
Unintended value
MacroFbPou_1 (EN := M0, ENO => M1);
M2 := MacroFbPou_1.ENO;
Ex.
A conversion error (1) occurs in VAR_OUTPUT in the macro type function block (FbPou)
(1)
If no error was found in (1), check the inputs and outputs (2) of the corresponding function block in the program block that is
the calling source.
(2)
Since the output variables of the function block have been passed to the write-protected label/device, a conversion error has
occurred in the above example.
4.1 Type
This manual describes the following types of label.
• Global labels
• Local labels
Global labels
Global labels are labels that can be shared by programs in a project. Global labels can be used in all the programs in a
project.
Global labels can be used in program blocks and function blocks.
When setting a global label, set the label name, class and data type, and assign a device.
■Device assignment
Devices can be assigned to global labels.
Item Description
Label to which no device is assigned • Programming without concern to devices is possible.
• Defined labels are allocated to the label area or latch label area in the device/label memory.
Label to which a device is assigned • If a device is to be programmed as a label referring to a device that is being used for input or output, the device can
be assigned directly.
• Defined labels are allocated to the device area in the device/label memory.
Local labels
Local labels are labels that can be used in each POU only. Local labels that are not included in POUs cannot be used.
When setting a local label, set the label name, class, and data type.
There are other types of labels available in addition to global labels and local labels.
System labels
System labels can be shared among iQ Works-compatible products and are managed by MELSOFT
Navigator. Global labels registered as system labels can be monitored or accessed using the system labels on
GOT.
For details, refer to the following.
iQ Works Beginner's Manual
Module labels
Module labels are labels defined uniquely by each module. Module labels are automatically generated by the
engineering tool from the module used, and can be used as a global label.
For details, refer to the following.
MELSEC iQ-F FX5 CPU Module Function Block Reference
For registration of module labels, refer to the following.
GX Works3 Operating Manual
4 LABELS
32 4.1 Type
4.2 Class
The label class indicates how each label can be used from which POU.
The selectable class varies depending on the POU.
Global label
Class Description Applicable POU
Program Function Function
block block
VAR_GLOBAL Common label that can be used in program blocks and function blocks
VAR_GLOBAL_CONSTANT Common constant that can be used in program blocks and function blocks
VAR_GLOBAL_RETAIN Latch type label that can be used in program blocks and function blocks
4
Local label
Class Description Applicable POU
Program Function Function
block block
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 label cannot be used in other POUs.
VAR_RETAIN 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 inputs to a function or a function block.
This label receives a value, and cannot be changed in POUs.
VAR_OUTPUT Label that outputs a value from a function or a function block
VAR_OUTPUT_RETAIN Latch type label that outputs a value from a function or a function block
VAR_IN_OUT Local label which receives a value, outputs it from a POU, and can be changed
in POUs
VAR_PUBLIC Label that can be accessed from other POUs
VAR_PUBLIC_RETAIN Latch type label that can be accessed from other POUs
4 LABELS
4.2 Class 33
Data type Description Value range Bit
length
Time*1 TIME Handles values as d (day), h (hour), m T#-24d20h31m23s648 ms to 32-bit
(minute), s (second), or ms (millisecond) T#24d20h31m23s647 ms*2
String(32) STRING Handles a character string (character) Up to 255 letters (half-width Variable
character)
Timer TIMER Structure that corresponds to a timer (T) of Page 34 Data types of timers and counters
a device
Retentive Timer RETENTIVETIMER Structure that corresponds to a retentive
timer (ST) of a device
Counter COUNTER Structure that corresponds to a counter (C)
of a device
Long Counter LCOUNTER Structure that corresponds to a long
counter (LC) of a device
Pointer POINTER Type that corresponds to a pointer (P) of a device (MELSEC iQ-F FX5 User's Manual
(Application))
*1 The time data is used in the time data type function of standard functions. For the standard function, refer to the following.
MELSEC iQ-F FX5 Programming Manual (Instructions, Standard Functions/Function Blocks)
*2 When using a constant for a label of the time data, prefix "T#" to the label.
4 LABELS
34 4.3 Data Type
Generic data type (ANY)
The generic data type indicates data type of a label which combines several basic data types. The data type name begins with
"ANY".
The generic data type is used when multiple data types are available in arguments or return values etc. of a function of a
function block.
Labels defined as generic data types can be used for any sub-level data type.
For the types of generic data types and the primitive data types, refer to the following.
MELSEC iQ-F FX5 Programming Manual (Instructions, Standard Functions/Function Blocks)
4 LABELS
4.3 Data Type 35
4.4 Arrays
An array represents a consecutive accumulation of the same data type labels, under the same name.
Arrays can be defined by the elementary data types or structures.
The maximum number of arrays differs depending on the data types.
One-dimensional array Two-dimensional array
Label name Indexes Label name Indexes
[1,0] [1,1]
…
…
…
[m,0] … …
[m,n]
Definition of arrays
■Array elements
When an array is defined, the number of elements, or the length of array, must be determined. For the range of the number of
elements, refer to the following.
Page 37 Maximum number of array elements
■Definition format
The following table lists definition format examples up to three dimensions.
The range from the array start value to the array end value is the number of elements.
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 33 Elementary data type
(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 Page 38 Structures
value .. 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 LABELS
36 4.4 Arrays
Precautions
When a bit of a device/label (example: D0.0) is assigned to bit array in global label, labels and devices can not be used for
the array index in programming (example: bLabel1[D0] cannot be programmed).
• The data storage location becomes dynamic by specifying a label for the array index. This enables arrays to
be used in a program that executes loop processing. The following is a program example that consecutively
stores "1234" in the "uLabel4" array.
bLabel1
INC wLabel3
bLabel2
MOV K1234 uLabel4[wLabel3] 4
• In the case of the ladder diagram, arrays can be used with element numbers omitted. When the element
number is omitted, it is converted to the starting number of the array element. For example, when the label
name you define is "boolAry" and the data type is "bit (0..2,0..2)", then "boolAry[0,0]" and "boolAry" are
treated in the same way.
• A multidimensional array can be specified as setting data of an instruction, function, or function block using
arrays. In that case, the rightmost element in the multidimensional array is treated as the first dimension.
Precautions
■When an interrupt program is used
When a label or device is specified for the array index, the operation is performed with a combination of multiple instructions.
For this reason, if an interrupt occurs during operation of the label defined as an array, data inconsistency may occur
producing an unintended operation result.
To prevent data inconsistency, create a program using the DI/EI instructions that disables/enables interrupt programs as
shown below.
DI
EI
For the DI/EI instructions, refer to the following.
MELSEC iQ-F FX5 Programming Manual (Instructions, Standard Functions/Function Blocks)
4 LABELS
4.4 Arrays 37
■Array elements
When accessing the element defined in an array, access it within the range of the number of elements.
If a constant out of the range defined for the array index is specified, a compile error will occur.
If the array index is specified with data other than a constant, a compile error will not occur. The processing will be performed
by accessing another label area or latch label area.
4.5 Structures
A structure is a data type that includes different labels. Structures can be used in all POUs.
Each member (label) included in a structure can be defined even when the data types are different.
Creating structures
To create a structure, first create the configuration of the structure, and define members for the created structure.
Structure
Member (Label 1)
Member (Label 2)
Member (Label 3)
Member (Label 4)
Ex.
When using the member of a structure
stLabel1 . bLabel1
Member name
Structure label name
• When labels are registered by defining multiple data types in a structure and used in a program, the order
the data is stored after converted is not the order the data types were defined. When programs are
converted using the engineering tool, labels are classified into type and data type, and then assigned to the
memory (memory assignment by packing blocks).
GX Works3 Operating Manual
• If a member of a structure is specified in an instruction operand that uses control data (series of consecutive
devices from the operand used by the instruction), the control data is assigned to members of the structure
by the order they are stored in memory, not the order the members are defined.
4 LABELS
38 4.5 Structures
Arrays of structures
Structures can also be used as arrays.
Structure label [1] Structure label [2] Structure label [3] Structure label [4]
When a structure is declared as an array, append an index enclosed by "[ ]" after the structure label name.
The array of structure can be specified as arguments of functions and function blocks. 4
Ex.
When using an element of the structured array
stLabel [0] . bLabel1
Member name
Indexes
Structure label name
Structure types
The following data types are defined as a structure beforehand.
Type Reference
Timer type Page 33 Data Type
Retentive Timer type
Counter type
Long Counter type
4 LABELS
4.5 Structures 39
4.6 Constant
Types of constants
The following table shows the expressions for setting a constant to a label.
Applicable data type Type Expression Example
Bit Boolean data Input "TRUE" or "FALSE". TRUE, FALSE
Binary Append "2#" in front of a binary number. 2#0, 2#1
Octal Append "8#" in front of an octal number. 8#0, 8#1
Decimal Directly input a decimal number, or append "K" in front of a 0, 1, K0, K1
decimal number.
Hexadecimal Append "16#" or "H" in front of a hexadecimal number. 16#0, 16#1, H0, H1
• Word [Unsigned]/Bit String [16-bit] Binary*1 Append "2#" in front of a binary number. 2#0010, 2#01101010,
• Double Word [Unsigned]/Bit String [32- 2#1111_1111
bit]
Octal*1 Append "8#" in front of an octal number. 8#0, 8#337, 8#1_1
• Word [Signed]
*1
• Double Word [Signed] Decimal Directly input a decimal number or append "K" in front of a 123, K123, K-123,
decimal number. 12_3
Hexadecimal*1 Append "16#" in front of a hexadecimal number. 16#FF, HFF, 16#1_1
Or append "H" in front of a value.
FLOAT [Single Precision] Real number*1 Directly input a real number, or append "E" in front of a real 2.34, E2.34, E-2.34,
number. 3.14_15
Real number Append "E" in front of an exponent expression or a real number. 1.0E6, E1.001+5
(exponent Append "+" in front of exponent part.
expression)
String(32) Character string Enclose a character string with single quotations ('). 'ABC'
Time Time Append "T#" in front. T#1h,
T#1d2h3m4s5ms
*1 In the binary notation, the octal notation, the decimal notation, the hexadecimal notation, and the real number notation, values can be
delimited by an underscore (_) to make programs easy to read. (In the program processing, underscores are ignored.)
4 LABELS
40 4.6 Constant
4.7 Precautions
3. Use the label defined in step 2 for the functions having no restrictions on the use of labels. Use the device assigned to
the label for the function having restrictions on the use of labels.
2. Create a program using the label. The following is the program example for copying the data. (The data logging function
uses the data in udLabel1.)
SM400
DMOV udLabel1 D0
3. Use the device where the data has been transferred in step 2 for the function having restrictions on the use of labels. (In
the program example in step 2, use D0.)
When copying a value of a label to another device by a transfer instruction, note that the number of program
steps increases. In addition, when adding a transfer instruction on a program, consider execution timing of the
function to be used.
4 LABELS
4.7 Precautions 41
Precautions for creating programs
When specifying a label as an operand used in instructions, match the data type of the label with that of the operand. In
addition, when specifying a label as an operand used in instructions that control continuous data, specify the data range used
in instructions within the data range of the label.
Ex.
SFT(P) instruction
SFT bLabel[0]
To shift the bits correctly, specify the array of a bit type label.
SFTP bLabel[1]
or
SFT wLabel1.0
Specify the bit number of a word type label.
SFTP wLabel1.1
Ex.
SFR(P) instruction
Start device number of search range
wLabel1[0] 10
Data matched
wLabel1[1] 500
20
123
wLabel1[n]
Specify a label which has a larger data range than the search range (n) points.
4 LABELS
42 4.7 Precautions
5 LADDER DIAGRAM
Ladder diagram is a language that describes the sequence control by indicating logical operations consisting of "AND" or
"OR" with combinations of series connections and parallel connections in a ladder consisting of contacts and coils.
5.1 Configuration
With the ladder diagram, the following ladder can be created.
(1)
(2)
(3)
5
(4)
(5)
Ladder symbols
This section shows ladder symbols that can be used for programming in the ladder diagram.
Element Symbol Description
NO contact Turns on when a specified device or label is ON.
Rising edge Turns on at the rising edge (OFF to ON) of a specified device or label.
Falling edge Turns on at the falling edge (ON to OFF) of a specified device or label.
Negated rising edge 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 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.
Conversion of operation result Turns on at the rising edge (OFF to ON) of an operation result. Turns off when the operation result
to leading edge pulse is other than the rising edge.
Conversion of operation result Turns on at the falling edge (ON to OFF) of an operation result. Turns off when the operation result
to trailing edge pulse is other than the falling edge.
Inverting the operation result Inverts the operation just before this instruction.
Turn-back Turns back a circuit by creating a turn source symbol and a turn destination symbol when the
number of contacts exceeds the number of contacts that can be created in one line.
5 LADDER DIAGRAM
5.1 Configuration 43
Element Symbol Description
Function Executes a function.
• How to create functions (GX Works3 Operating Manual)
• Standard function (MELSEC iQ-F FX5 Programming Manual (Instructions, Standard
Functions/Function Blocks))
Function block Executes a function block.
• How to create function blocks (GX Works3 Operating Manual)
• Standard function blocks (MELSEC iQ-F FX5 Programming Manual (Instructions, Standard
Functions/Function Blocks))
• Module function blocks (MELSEC iQ-F FX5 CPU Module Function Block Reference)
X1 1 X3 3 Y1 4
X2 2 X4 5 Y2 6
When executing the program above, Y1 and Y2 turn on corresponding to turning ON or OFF of X1 to X4 as shown below.
ON
X1 OFF
ON
X2 OFF
ON
X3
OFF
ON
X4
OFF
ON
Y1
OFF
ON
Y2
OFF
5 LADDER DIAGRAM
44 5.1 Configuration
Precautions for using a function block in ladder diagram
(1)
To change the on/off states of EN and the input variables (bit type), use a contact or an instruction equivalent to the contact. 5
(2): Contact
(3): Instruction equivalent to a contact
(2)
(3)
5 LADDER DIAGRAM
5.1 Configuration 45
5.2 Inline ST
Inline ST is a function that creates, edits and monitors inline ST box that displays an ST program in a cell of an instruction that
is equivalent to a coil in the ladder editor.
Numerical operations or character string operations can be created easily in a ladder program.
• Program with the inline ST
X0
1 W0:=K0;
2 W0:=(D0+D1+D2+D3+D4+D5+D6+D7+D8+D9+D10+D11)/K12;
+ D0 W0
+ D1 W0
+ D2 W0
+ D3 W0
+ D4 W0
+ D5 W0
+ D6 W0
+ D7 W0
+ D8 W0
+ D9 W0
+ D10 W0
+ D11 W0
/ W0 K12 W0
Specifications
For the specifications of the inline ST, refer to the ST language specifications.
Page 48 ST LANGUAGE
Precautions
• Only one inline ST can be created in one line of a ladder program.
• Creating both a function block and an inline ST box in one line of a ladder program is impossible.
• Creating an inline ST box in a position of an instruction that is equivalent to a contact creates an inline ST box in a position
of an instruction that is equivalent to a coil.
• The maximum number of characters that can be input in an inline ST is 2048. (A newline is counted as two characters.)
• In inline ST, do not use rising execution instructions, falling execution instructions, special timer instructions, or standard
function blocks (edge detection function blocks and counter function blocks) as they may not work property.
• When the RETURN syntax is used in an inline ST, the processing inside the inline ST box ends, and the processing inside
the program block does not end.
5 LADDER DIAGRAM
46 5.2 Inline ST
5.3 Statements and Notes
In a ladder program, statements and notes can be displayed.
Statements
By using statements, users can append comments to circuit blocks. Appending statements makes the processing flow easy to
understand.
Statements include line statements, P statements, and I statements.
A line statement can be displayed on a tree view of the Navigation window.
■Line statement
A comment is appended to a ladder block as a whole.
■P statement
A comment is appended to a pointer number.
5
■I statement
A comment is appended to an interrupt pointer number.
Notes
By using notes, users can append comments to coils and instructions in a program.
Appending notes makes the details of coils and application instructions easy to understand.
5 LADDER DIAGRAM
5.3 Statements and Notes 47
6 ST LANGUAGE
The ST language is one of the languages supported by IEC 61131-3, the international standard that defines the description
methods for logic. ST language is a text programming language with a grammatical structure similar to C language. ST
language is suitable for programming some complicated processing that cannot be easily described using ladder diagram.
ST language supports control syntaxes, operational expressions, function blocks (FBs), and functions (FUNs). Therefore, the
following description can be made.
Ex.
Control syntaxes using selective branches with conditional statements and repetition by iteration statements
(* Control conveyors of Line A to C. *)
CASE Line OF
1: Start_switch := TRUE; (* The conveyor starts. *)
2: Start_switch := FALSE; (* The conveyor stops. *)
3: Start_switch := TRUE; (* The conveyor stops with an alarm. *)
ELSE Alarm_lamp := TRUE;
END_CASE;
IF Start_switch = TRUE THEN (* The conveyor starts and performs processing 100 times. *)
FOR Count := 0
TO 100
BY 1 DO
Count_No := Count_No +1;
END_FOR;
END_IF;
Ex.
Expressions using operators (such as *, /, +, -, <, >, and =)
D0 := D1* D2 + D3 / D4 -D5;
IF D0 > D10 THEN
D0 := D10;
END_IF;
Ex.
Calling a defined function block
//FB data name : LINE1_FB
//Input variable : I_Test
//Output variable : O_Test
//Input/output variable : IO_Test
//FB label name : FB1
FB1(I_Test :=D0,O_Test => D1,IO_Test := D100);
Ex.
Calling a standard function
(* Convert BOOL data type to INT/DINT data type. *)
wLabel2 := BOOL_TO_INT (bLabel1);
6 ST LANGUAGE
48
6.1 Configuration
Operators and syntaxes are used for programing in ST language.
IF M1 THEN
btn01 := TRUE;
ELSE Conditional statement
btn01 := FALSE;
END_IF;
intV1 := 0 ;
End of the statement
intV2 := 2 ; 6
Spaces, tabs, and line feeds can be inserted anywhere between an operator and data.
Space
intV1 := 0 ;
intV2 := Tab
2;
Line feed
intV1 := 0;
(* Substitution *) Comment
intV2 := 2;
6 ST LANGUAGE
6.1 Configuration 49
Delimiter
The following delimiters are provided in ST language for clarifying the program structure.
Symbol Description
() Parenthesized
[] Specification of an array element
. (period) Specification of members of the structure or function block
, (comma) Separation of arguments
: (colon) Device type specifier
; (semicolon) End of a sentence
' (single quotation mark) Description of a character string
.. (two periods) Specification of an integer range
Operator
The following shows the operators used in a ST program and the target data types and operation result data types for each
operator.
Operator Target data type Operation result type
*, /, +, - ANY_NUM ANY_NUM
<, >,<=, >=, =, <> ANY_ELEMENTARY Bit
MOD ANY_INT ANY_INT
AND, &, XOR, OR, NOT ANY_BIT ANY_BIT
** ANY_REAL (Base) ANY_REAL
ANY_NUM (Exponent)
• If an expression includes multiple operators with the same priority, the operation is performed from the leftmost operator.
• Up to 1024 operators can be used in one statement.
6 ST LANGUAGE
50 6.1 Configuration
Syntax
The following table shows the types of statements that can be used in a ST program.
Item Description Reference
Assignment statement Assignment statement Page 51 Assignment statement
Sub-program control statement Function block call statement, function call statement Page 52 Sub-program control statement
RETURN statement
Conditional statement IF statement (IF, IF...ELSE, IF...ELSIF) Page 53 Conditional statement
CASE statement
Iteration statement FOR statement Page 54 Iteration statement
WHILE statement
REPEAT statement
EXIT statement
Assignment statement
Format Description Example
<Left side> := <Right side> ; The assignment statement assigns the result of the right side expression to the label or device of
intV1 := 0;
6
the left side.
intV2 := 2;
The result of the right side expression and the data type of the left side need to be the same data
type.
When an array type label or a structure label is used, check the data types of the left side and right side of the assignment
statement.
When an array type label is used, the data type and the number of elements need to be the same for the left side and right
side. Do not specify elements.
Ex.
intAry1 := intAry2;
When a structure label is used, the data type needs to be the same for the left side and right side.
Ex.
dutVar1 := dutVar2;
Ex.
Example of automatic conversion
dintLabel1 := intLabel1;
// Assignment statement : Automatically convert the INT type variable (intLabel1) to a DINT type variable,
and assign it the DINT type variable (dintLabel1).
6 ST LANGUAGE
6.1 Configuration 51
To avoid the deletion of the data during type conversion, only conversion from smaller type to larger type is performed. Of the
elementary data types, type conversion is performed only for the following data types among basic data types are the targets
of a type conversion.
Data type Description
Word [Signed] In the case of a double word [signed] after conversion, the conversion is automatically made into a value
with a sign extension.
In the case of a single-precision real, an automatic conversion is made into the same value as the integer
before the conversion.*1
Word [Unsigned]/Bit String [16-bit] In the case of a double word [unsigned]/bit string [32 bits] or a double word [signed] after conversion, an
automatic conversion is made into to a value with a zero extension.*2
In the case of a single-precision real, an automatic conversion is made into the same value as the integer
before the conversion.*1
*1 When the data of 16 bits (a word [signed] or a word [unsigned]/bit string [16 bits]) is transferred to an input argument of the data type
ANY_REAL, an automatic conversion is made into a single- precision real.
*2 When the data of a word [unsigned]/bit string [16 bits] is transferred to an input argument of ANY32, an automatic conversion is made
into a double word [unsigned]/bit string [32 bits].
For data types that are not described above, use the type conversion function.
Since type conversion is not performed in the following cases, use the type conversion function.
• Type conversion between integer-data types with different signs
• Type conversion between the data types by which the data is deleted
For the precautions for assigning the result of an arithmetic operation, refer to the following.
Page 55 When an assigned arithmetic operation is used
The following table shows the symbols used for arguments in a function block call statement and available formats.
Type Description Attribute Symbol Available formats
VAR_INPUT Input variable N/A, or RETAIN := All formats
VAR_OUTPUT Output variable N/A, or RETAIN => Variable only
VAR_IN_OUT Input/Output variable N/A := Variable only
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 input variable and one FB name: FBADD
FBADD1(IN1:=Input1);
output variable FB instance name: FBADD1
Input variable1: IN1
Output1:=FBADD1_OUT1;
Output variable1: OUT1
Calling a function block with three input variables and two FB name: FBADD
FBADD1(IN1:=Input1, IN2:=Input2, IN3:=Input3);
output variables FB instance name: FBADD1
Input variable1: IN1
Output1:=FBADD1_OUT1;
Input variable2: IN2 Output2:=FBADD1_OUT2;
Input variable3: IN3
Output variable1: OUT1
Output variable2: OUT2
6 ST LANGUAGE
52 6.1 Configuration
■Function call statement
Format Description
Function name(Variable1, Variable2, ...); Enclose an argument by "()" after the function name.
When using multiple arguments, delimit them by "," (comma).
A user-defined function that does not return a value and a function that includes a VAR_OUTPUT variable in the argument of
a call statement can be executed as a statement by adding a semicolon (;) at the end.
■RETURN statement
Syntax Format Description Example
6
■RETURN RETURN; The RETURN statement is used to end a program, function
IF bool1 THEN
block, or function in the middle of processing.
RETURN;
When the RETURN statement is used in a program, the
END_IF;
processing jumps to the next step after the last line of the
program.
When the RETURN statement is used in a function block, the
processing is returned from the function block.
When the RETURN statement is used in a function, the
processing is returned from the function.
One pointer type label is used by the system for one RETURN
statement.
A user-defined function that does not return a value and a function that includes a VAR_OUTPUT variable in the parameter of
a call statement can be executed as a statement by adding a semicolon (;) at the end.
Conditional statement
Syntax Format Description Example
■IF IF <Boolean expression> THEN The statement is executed when the value of Boolean
IF bool1 THEN
<Statement> ; expression (conditional expression) is TRUE. The statement is
intV1:=intV1+1;
END_IF; not executed if the value of Boolean expression is FALSE.
END_IF;
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.
■IF...ELSE IF <Boolean expression> THEN Statement 1 is executed when the value of Boolean expression
IF bool1 THEN
<Statement 1> ; (conditional expression) is TRUE.
intV3:=intV3+1;
ELSE Statement 2 is executed when the value of Boolean expression
ELSE
<Statement 2> ; is FALSE.
END_IF;
intV4:=intv4+1;
END_IF;
■IF...ELSIF IF <Boolean expression 1> THEN Statement 1 is executed when the value of Boolean expression
IF bool1 THEN
<Statement 1> ; (conditional expression) 1 is TRUE. Statement 2 is executed
intV1:=intV1+1;
ELSIF <Boolean expression 2> THEN when the value of Boolean expression 1 is FALSE and the
ELSIF bool2 THEN
<Statement 2> ; value of Boolean expression 2 is TRUE.
ELSIF <Boolean expression 3> THEN Statement 3 is executed when the value of Boolean expression
intv2:=intV2+2;
<Statement 3> ; 1 and 2 are FALSE and the value of Boolean expression 3 is ELSIF bool3 THEN
END_IF; TRUE. intV3:=intV3+3;
END_IF;
6 ST LANGUAGE
6.1 Configuration 53
Syntax Format Description Example
■CASE CASE <Integer expression> OF When the statement that has the integer selection value that
CASE intV1 OF
<Integer selection 1> : matches with the value of the integer expression (conditional
1:
<Statement 1> ; expression) is executed, and if no integer selection value
bool1:=TRUE;
<Integer selection 2> : matches with the expression value, the statement that follows
<Statement 2> ; the ELSE statement is executed.
2:
The CASE statement is used to execute a conditional statement bool2:=TRUE;
<Integer selection n> : based on a single integer value or an integer value as the result ELSE
<Statement n> ; of a complicated expression. intV1:=intV1+1;
ELSE END_CASE;
<Statement n+1> ;
END_CASE;
Iteration statement
Syntax Format Description Example
■FOR FOR <Repeat variable initialization> The FOR...DO statement first initializes the data used as a
FOR intV1:=0
TO <Last value> repeat variable.
TO 30
BY <Incremental expression> DO An addition or subtraction is made to the initialized repeat
BY 1 DO
<Statement> ; variable according to the incremental expression. One or more
END_FOR; statements from DO to END_FOR are repeatedly executed until
intV3:=intV1+1;
the final value is exceeded. END_FOR;
The repeat variable at the end of the FOR...DO syntax is the
value at end of the execution.
■WHILE WHILE <Boolean expression> DO The WHILE...DO statement executes one or more statements
WHILE intV1=30 DO
<Statement> ; while the value of Boolean expression (conditional expression)
intV1:=intV1+1;
END_WHILE; is TRUE.
END_WHILE;
The Boolean expression is evaluated before the execution of
the statement. If the value of Boolean expression is FALSE, the
statement in the WHILE...DO statement is not executed. Since
a return result of the Boolean expression in the WHILE
statement requires only TRUE or FALSE, any Boolean
expression that can be specified in the IF conditional statement
can be used.
■REPEAT REPEAT The REPEAT...UNTIL statement executes one or more
REPEAT
<Statement> ; statements while the value of Boolean expression (conditional
intV1:=intV1+1;
UNTIL <Boolean expression> expression) is FALSE.
UNTIL intV1=30
END_REPEAT; The Boolean expression is evaluated after the execution of the
statement. If the value of Boolean expression is TRUE, the
END_REPEAT;
statement in the REPEAT...UNTIL statement are not executed.
Since a return result of the Boolean expression in the REPEAT
statement requires only TRUE or FALSE, any Boolean
expression that can be specified in the IF conditional statement
can be used.
■EXIT EXIT; The EXIT statement is used only in an iteration statement to
FOR intV1:=0
end the iteration statement in the middle of processing.
TO 10
When the EXIT statement is reached during execution of the
BY 1 DO
iteration loop, the iteration loop processing after the EXIT
statement is not executed. The processing continues from the
IF intV1>10 THEN
line after the one where the iteration statement is ended. EXIT;
END_IF;
END_FOR;
6 ST LANGUAGE
54 6.1 Configuration
Precautions
■When an assignment statement is used
• The maximum number of character strings that can be assigned is 255. If 256 or more character strings are assigned, a
conversion error occurs.
• Contacts and coils of the timer type or counter type cannot be used for the left side of an assignment statement.
• The instance of a function block cannot be used for the left side of an assignment statement. Use input variables, input/
output variables, and external variables of the instance for the left side of an assignment statement.
Ex.
When an arithmetic operation result of 16-bit data (INT type) is assigned to 32-bit data (DINT type)
varDint1 := varInt1 * 10; // VarInt1 is a INT type variable, and varDint1 is a DINT type variable.
The arithmetic operation result is the same data type as that of the input operand. Thus, in the case of the above program,
when the operation result of varInt1 * 10 exceeds the range of the INT type (-32768 to +32767), an overflow or underflow
result is assigned to varDint1.
6
In this case, convert the operand of the operational expression to the data type of the left side in advance and execute the
operation.
varDint2 := INT_TO_DINT(varInt1); // INT type variable is converted to DINT type variable.
varDint2 := varDint2 * 10; // DINT type multiplication is performed, and the operation result is assigned.
■Using the operator "-" for sign inversion in an arithmetic operation
When the operator "-" is used to invert the sign of the minimum value of a data type, the minimum value evaluates to the same
value.
For example, -(-32768), where the operator "-" is used with the minimum value of INT type, evaluates to -32768. Thus, an
unintended result may be produced if the operator "-" is used to invert the sign of a variable whose data type will be
automatically converted.
Ex.
When the value of varInt1 (INT type) is -32768, and the value of varDint1 (DINT type) is 0.
varDint2 := -varInt1 + varDint1;
In the example above, the value of (-varInt1) evaluates to -32768 and -32768 is assigned to varDint2.
When using the operator "-" to invert the sign of a variable in an arithmetic operation, perform automatic conversion of the
data type of the variable before the arithmetic operation. Alternatively, avoid using the operator "-" for sign inversion in the
program.
Ex.
Performing automatic conversion of the data type before an arithmetic operation
varDint3 := varInt;
varDint2 := -varDint3 + varDint1;
Ex.
Avoiding the use of the operator "-" for sign inversion
varDint2 := varDint1 - varInt1;
6 ST LANGUAGE
6.1 Configuration 55
■When a bit type label is used
Once the Boolean expression (conditional expression) is satisfied in a conditional statement or an iteration statement, the bit
type label that is turned ON in <Statement> is always set to ON.
Ex.
Program whose bit type label is always set to on
ST program Ladder program equivalent to ST program
To avoid the bit device to be always set to ON, add a program to turn OFF the bit type label as shown below.
Ex.
Program to avoid the bit type label to be always set to ON
ST program*1 Ladder program equivalent to ST program
Ex.
When a timer function block is used
Program before change
IF bLabel1 THEN
TIMER_100_FB_M_1(Coil:=bLabel2,Preset:=wLabel3,ValueIn:=wLabel4,ValueOut=>wLabel5,Status=>bLabel6);
END_IF;
(* When bLabel1 = on and bLabel2 = on, counting starts. *)
(* When bLabel1 = on and bLabel2 = off, the counted value is cleared. *)
(* When bLabel1 = off and bLabel2 = on, counting stops. The counted value is not cleared. *)
(* When bLabel1 = off and bLabel2 = off, counting stops. The counted value is not cleared. *)
Program after change
TIMER_100_FB_M_1(Coil:=(bLabel1&bLabel2),Preset:=wLabel3,ValueIn:=wLabel4,ValueOut=>wLabel5,Status=>bLabel6);
When a counter function block is used
Program before change
IF bLabel1 THEN
COUNTER_FB_M_1(Coil:=bLabel2,Preset:=wLabel3,ValueIn:=wLabel4,ValueOut=>wLabel5,Status=>bLabel6);
END_IF;
(* When bLabel1 = on and bLabel2 = on/off, the value is incremented by 1. *)
(* When bLabel1 = off and bLabel2 = on/off, the value is not counted. *)
(* The counting operation does not depend on the on/off status of bLabel1. *)
Program after change
COUNTER_FB_M_1(Coil:=(bLabel1&bLabel2),Preset:=wLabel3,ValueIn:=wLabel4,ValueOut=>wLabel5,Status=>bLabel6);
An error occurs when the program before change is used since the statement related to the timer or counter is not executed
when the selection statement is not satisfied.
6 ST LANGUAGE
56 6.1 Configuration
When the timer or counter is operated according to the AND condition of bLabel1 and bLabel2, do not use any control
statement, just use a function block only.
Using the program after change operates the timer and counter.
*1 This is a fall (ON to OFF), but the instruction is not executed because the condition in the IF statement or the CASE statement is not
satisfied.
Ex.
When the PLS instruction (rising execution instruction) is used in an IF statement
IF bLabel0 THEN
PLS(bLabel1,bLabel10);
END_IF;
(1) If bLabel0 = OFF (the condition expression in the IF statement is
ON
FALSE), the ON/OFF judgment result is OFF. The PLS
bLabel0 OFF instruction is not executed. (bLabel10 = OFF does not change.)
(2) If bLabel0 = ON (the condition expression in the IF statement is
ON ON
TRUE) and bLabel1 = OFF (the condition for executing the
bLabel1 OFF instruction is OFF), the ON/OFF judgment result is OFF. The PLS
instruction is not executed. (bLabel10 = OFF does not change.)
ON
ON/OFF (3) If bLabel0 = ON (the condition expression in the IF statement is
judgment OFF TRUE) and bLabel1 = ON (the condition for executing the
result instruction is ON), the ON/OFF judgment result is OFF to ON (the
(3) condition for a rise is satisfied). The PLS instruction is executed.
(1) (2) ON (bLabel10 turns ON for once scan only.)
bLabel10 OFF
1 scan
6 ST LANGUAGE
6.1 Configuration 57
■When a master control instruction is used
Shown here is the operation when the master control is OFF.
• The statement in a selection statement (an IF statement or a CASE statement) or in a iteration statement (a FOR
statement, a WHILE statement, or a REPEAT statement) is not processed.
• Outside of a selection statement or a iteration statement, assignment statement is not processed and statement other than
assignment statement is not executed.
Ex.
A statement in a selection statement (IF statement)
MC(M0,N1,M1); //Master control OFF
IF M2 THEN
M3:=M4; //No processing is executed when the master control is OFF. So, M3 maintains the value at the time of a previous scan.
END_IF;
M20:=MCR(M0,N1);
Ex.
A statement out of a selection statement or a iteration statement (in the case of a bit assignment statement)
MC(M0,N1,M1); //Master control OFF
M3:=M4; //No processing is executed when the master control is OFF. So, M3 maintains the value at the time of a previous scan.
M20:=MCR(M0,N1);
Ex.
A statement out of a selection statement or a iteration statement (in the case of an OUT instruction)
MC(M0,N1,M1); //Master control OFF
OUT(M2,M3); //No execution is made when the master control is OFF.
M20:=MCR(M0,N1);
Constant
For the expression methods other than the one described the above, refer to the following.
Page 40 Constant
Specification method
Labels and devices can be directly described in the ST program. Labels and devices can be used for the left or right side of an
expression or as an argument or return value of a standard function/function block.
For available labels, refer to the following.
Page 32 LABELS
For available devices, refer to the following.
MELSEC iQ-F FX5 User's Manual (Application)
6 ST LANGUAGE
58 6.1 Configuration
■Device expression with type specification
A word device can be used in ST language as an arbitrary data type by adding a device type specifier to its name.
Device type specifier Data type Example Description
N/A Generic data type ANY16. D0 When no type specifier is added to D0
When only devices are used in arithmetic operations,
the data type is Word [signed].
However, when the data is specified as a device
without the type specification in the argument part of
FUN/FB, the data type is the one of the argument
definition.
:U Word [Unsigned]/Bit String [16-bit] D0:U The value when D0 is Word [unsigned]/Bit string [16-bit]
:D Double Word [Signed] D0:D The value when D0 and D1 are Double word [signed]
:UD Double Word [Unsigned]/Bit String [32-bit] D0:UD The value when D0 and D1 are Double word [unsigned]/Bit
string [32-bit]
:E FLOAT (Single Precision) D0:E The value when D0 and D1 are single-precision real
numbers
The following shows the devices to which device type specifiers can be added.
• Data register (D)
• Link register (W)
• Module access device (U\G) 6
• File register (R)
Precautions
• The pointer type can be used for ST programs.
• When a value is assigned using nibble specification, use the same data type for the left side and right side of an operation.
Ex.
D0 := K5X0;
In the above case, since K5X0 is the double word type and D0 is the word type, an error occurs in the program.
• When a value is assigned using nibble specification and the data size of the right side is larger than that of the left side,
data is transmitted within the range of the target points of the left side.
Ex.
K5X0 := 2#1011_1101_1111_0111_0011_0001;
In the above case, since the target points of K5X0 is 20, 1101_1111_0111_0011_0001 (20 bits) are assigned to K5X0.
• When the current value (such as TNn) of a counter (C), timer (T), or retentive timer (ST) is used with a type other than Word
[unsigned]/Bit string [16-bit], or when the current value (such as LCNn) of a long counter (LC) is used with a type other than
Double word [unsigned]/Bit string [32-bit], use the type conversion function.
Ex.
varInt := WORD_TO_INT(TN0); (*Use the type conversion function*)
6 ST LANGUAGE
6.1 Configuration 59
Comment
The following table shows the comment formats that can be used in a ST program.
Comment format Comment Description Example
symbol
Single line comment // The character strings between the start symbol "//" and the end of the // Comment
line are used as a comment.
Multiple-line comment (* *) The character strings between the start symbol "(*" and the end symbol ■Without newline
"*)" are used as a comment. (* Comment *)
Newlines can be inserted in the comment. ■With newline
(* Comment in the first line
Comment in the second line *)
/* */ The character strings between the start symbol "/*" and the end symbol ■Without newline
"*/" are used as a comment. /* Comment */
Newlines can be inserted in the comment. ■With newline
/* Comment in the first line
Comment in the second line */
When the multiple-line comment format is used, do not use end symbols inside comments.
6 ST LANGUAGE
60 6.1 Configuration
7 FBD/LD LANGUAGE
This is a language that creates a program by wiring blocks for specific processing, variables, and constants along with the
flows of data and signals.
7.1 Configuration
With the FBD/LD language, the following program can be created.
(1) FBD unit
(2) LD unit
(6) (3) Common unit
(4) Connecting wire
(2) (5) (5) Connecting point
(6) Worksheet
(1) (4)
7
(3)
In a program of the FBD/LD language, data flows from the output point of a function block (FB), a function (FUN), a variable
unit (label or device), and constant unit to the input point of another function block, variable unit, and so forth.
7 FBD/LD LANGUAGE
7.1 Configuration 61
Program unit
FBD unit
Units constituting FBD/LD program are shown below.
Unit Symbol Description
Variable A variable is used to store each value (data). The data type of a variable should be a certain type.
Only the value (data) of the data type is stored.
You can specify a label or a device to a variable.
Constant The constant specified is output.
Ex.
When 1 is input as a constant value
The data type can be a BOOL type, a WORD type, a DWORD type, an INT type, a DINT type, or a REAL type. So, the data
type is not determined. When the constant unit and an FBD unit are connected over a connecting wire, the data type becomes
the data type at the input point of the unit at the destination of the connection.
(1) The data type is not determined.
1 (2) INT type
(3) INT type
(1)
INT_TO_REAL
1 IN
(2)
(3)
7 FBD/LD LANGUAGE
62 7.1 Configuration
■The input/output point of a function
• It is necessary that all the input points of a function should be connected to other FBD units over connecting wires.
• The data types of the input variables and output variables of a function should be of certain types. It is necessary that the
FBD units to be connected to the input point or output point should be of the same data types.
• Connect a variable element between an output variable (except for ENO) of a CPU module instruction or module dedicated
instruction and an input variable of another function (or function block).
• In a program that connects a function with EN to another function over a connecting wire, the other function must be a
function with EN and the program must connect ENO and EN over a connecting wire, in order to prevent the function from
using an indefinite value.
AND_E AND_E
(1)
BOOL_EN_DATA EN ENO EN ENO
LD unit 7
Units of ladder diagram that can be used in a program of the FBD/LD language are shown below.
Unit Symbol Description
Left bus This is an unit to represent a bus. This is the starting point to create a ladder circuit.
Rising edge Turns on at the rising edge (OFF to ON) of a specified device or label.
Falling edge Turns on at the falling edge (ON to OFF) of a specified device or label.
Negated rising edge 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 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.
Coil Outputs an operation result to a specified device or a label.
Complementing coil When the operation result turns OFF, the specified device or label turns ON.
Set When the operation result turns ON, the specified device or label turns ON.
The device or the label that turns ON remains ON even if the operation result turns OFF.
Reset When the operation result turns ON, the specified device or label turns OFF.
When the operation result is OFF, the status of the device or the label does not change.
7 FBD/LD LANGUAGE
7.1 Configuration 63
■The AND operation and OR operation of a contact symbol
A contact symbol executes an AND operation or an OR operation depending on the status of the connection of a circuit chart.
This is reflected in the operation result.
• In the case of a series connection (1), an AND operation is executed with the operation results so far. This will be the
operation result.
• In the case of a parallel connection (2), an OR operation is executed with the operation results so far. This will be the
operation result.
(1) Series connection contact
Common unit
This represents a common unit placed on the FBD/LD editor.
Unit Symbol Description
Jump The execution processing is jumped over from a jump unit to a jump label. The portion that is
jumped over is not executed.
Whether a jump is made or not is controlled depending on the ON/OFF information to the jump unit.
ON: The execution processing is jumped over up to a jump label.
OFF: The execution processing is not jumped over but is executed.
Jump label This is the destination of a jump from a jump instruction in the same program. The processing is
executed from a program in the execution order after the jump label.
Connector This is used as a substitute of a connecting wire.
The processing moves on to the corresponding connector unit.
You can use one input connector or multiple input connectors for one output connector.
Return The processing after a return unit in the program is aborted. Use this when you want to prohibit the
execution of the processing of a program, function, or a function block after the return unit.
Whether the return processing is executed or not is controlled depending on the ON/OFF
information to the return unit.
ON: The return processing is executed.
OFF: The return processing is not executed, but the ordinary execution processing is executed.
Comment Use this to describe a comment.
7 FBD/LD LANGUAGE
64 7.1 Configuration
■The operation of a return unit
A return unit operates differently depending on whether a program, function, and/or function block used there.
Program unit to use
Program The execution of the program unit is terminated.
Function The function is terminated, and the step goes back to the one next to the instruction that has called the function.
Function block The function block is terminated, and the step goes back to the one next to the instruction that has called the function
block.
If a return element is used in a macro-type function block, do not place two or more function block elements of the same
instance name.
A local label "_SYSTEM_RETURN" is automatically registered when a program using a return element is converted.
The local label "_SYSTEM_RETURN" has the following operational limitations:
Operation on the label automatically registered Permitted/Prohibited
Changing the label name Prohibited*1
Changing the data type Prohibited
Changing the class Prohibited
Deleting the label Prohibited*1
Changing the line of registration Permitted
*1 If the program is converted again after change or deletion, a new local label is registered.
■Connector unit
Use a connector element to place the program within the display area or print area of the FBD/LD editor.
7
Var1 Var2 Var3 Var4 Var5
CONNECTOR
Connecting wire
This is the wire to connect the connecting points between FBD unit, LD unit, and common unit.
After units are connected, the data is transferred from the left end to the right end. The data types of the connected units need
to be the same.
Connecting point
This is a terminal point to use a connecting wire to connect FBD unit, LD unit, and common unit.
The point on the left side of each unit is the input side, while the point on the right side represents the output side.
Unit Input connecting Output connecting Unit Input connecting Output connecting
point point point point
Contact Coil
Variable Constant
7 FBD/LD LANGUAGE
7.1 Configuration 65
■Inverting input and output points
You can invert an input to an unit or an output from an unit by using a connecting point.
The connecting point having been inverted is circled with a black circle. The data to be input or
output is inverted (FALSE to TRUE or TRUE to FALSE).
You can invert the following data types: BOOL, WORD, DWORD, ANY_BIT, and ANY_BOOL.
Worksheet
A worksheet is a work area for inserting program units and for connecting them with wires.
Constant
For the expression methods other than the one described the above, refer to the following.
Page 40 Constant
Specification method
You can directly describe and use labels and devices in an FBD/LD program. You can use labels and devices for inputs and
output points of units, for arguments of standard functions/function blocks, return values, and so forth.
For available labels, refer to the following.
Page 32 LABELS
For available devices, refer to the following.
MELSEC iQ-F FX5 User's Manual (Application)
Caution
■When using label
• Labels whose name ends with "_" cannot be used as an array index. To use such a device or label as an array index,
assign it to another device or label and specify that device or label as an index.
• Members of labels (structures or function blocks) whose name ends with "_" cannot be specified.
• Indexes cannot be specified to labels (arrays) whose name ends with "_".
7 FBD/LD LANGUAGE
66 7.1 Configuration
7.2 Program Execution Order
The order of executions of program units
The order of executions of the units in the FBD/LD editor is determined depending on the positional relation of the units and
on the status of connecting wires.
Executed from
the left side to
the right side
M0 Y0
1 2
CTD_E_1
CTD_E
SM400
EN ENO
3
Var_CU CD Q Var_Q
4 8
Var_R LD CV Var_CV
5 9 7
Var_PV PV
6
7
SM400
RETURN
Executed from 10 11
the top to the
bottom
The number of the order of the execution is shown on each unit placed on the FBD/LD editor.
ADD
7 FBD/LD LANGUAGE
7.2 Program Execution Order 67
APPENDIX
Appendix 1 Operations of when the MC/MCR
instructions are used to control EN
The following table lists operations of instructions, devices, and labels used in a function block when "Use MC/MCR to Control
EN" is enabled in the inherent property setting of the function block.
Instruction/device/label used in a function Operation of Instruction/device/label used in a function block
block When "Yes" is selected for "Use MC/ When "No" is selected for "Use MC/MCR
MCR to Control EN" to Control EN"
Instructions executed at the rising edge or falling The next time EN is turned on, the instruction is The next time EN is turned on, the instruction may
edge (PLS instruction, instructions for conversion to executed if the condition contact is TRUE. not be executed even though the condition contact is
pulses (P))*1 TRUE.
Timer (low-speed timer/timer/high-speed timer) The count value becomes 0 and the both coil The state of devices remains unchanged.
and contact turn off.
Retentive timer (low-speed timer/timer/high-speed The coil turns off, but the current count value The state of devices remains unchanged.
timer), counter, long counter and the current state of the contact remain
unchanged.
Devices specified as the device part of the OUT The devices are forcibly turned off. The state of devices remains unchanged.
instruction
When "Yes" is selected for "Use MC/MCR to Control EN", do not use the MC/MCR instructions while the
function block is being executed. If the MC/MCR instructions are used, the EN control may not operate
properly.
APPX
68 Appendix 1 Operations of when the MC/MCR instructions are used to control EN
Instructions executed at the rising/falling edge
The following describes operations of instructions executed at the rising/falling edge.
Ex.
A subroutine-type FB using an instruction executed at the rising edge
EN IN ENO
MOVP
IN OUT
END
Sc
EN
IN
(1)
MOVP
Sc: Scan
EN is turned on. (User operation)
IN is turned on. (User operation)
The MOVP instruction is executed. (CPU module operation)
EN is turned off. (User operation)
The MOVP instruction is executed. (CPU module operation)
Sc
EN
IN
(1)
MOVP
Sc: Scan
EN is turned on. (User operation)
IN is turned on. (User operation)
The MOVP instruction is executed. (CPU module operation)
EN is turned off. (User operation)
The MOVP instruction is executed when the condition contact is FALSE immediately before EN is turned off at . (CPU module operation) (The MOVP
instruction is not executed when the condition contact is TRUE immediately before EN is turned off at .)
APPX
Appendix 1 Operations of when the MC/MCR instructions are used to control EN 69
Timer (low-speed timer/timer/high-speed timer)
The following describes operations of the timer (low-speed timer/timer/high-speed timer).
Ex.
A subroutine-type FB using a low-speed timer
EN SM400 ENO
OUT T0 K3
END
Sc
EN
(1)
T0 (Count) 0 1 2 3 0 1 2
T0 (Coil)
(2)
Sc: Scan
T0 (Count): T0 (count value)
T0 (Coil): T0 (coil)
EN is turned off. (User operation)
The coil turns off and the timer value and the count value are cleared. (CPU module operation)
Sc
EN
(1)
T0 (Count) 0 1 2 3 3 3 3
T0 (Coil)
(1)
Sc: Scan
T0 (Count): T0 (count value)
T0 (Coil): T0 (coil)
EN is turned off. (User operation)
The values remain unchanged. (CPU module operation)
APPX
70 Appendix 1 Operations of when the MC/MCR instructions are used to control EN
Retentive timer (low-speed timer/timer/high-speed timer), counter, and long counter
The following describes operations of the retentive timer (low-speed timer/timer/high-speed timer), counter, and long counter.
Ex.
A subroutine-type FB using a low-speed retentive timer
EN SM400 ENO
OUT ST0 K3
END
Sc
EN
(1)
ST0 (Count) 0 1 2 3 3 3 3
ST0 (Coil)
(2)
Sc: Scan
ST0 (Count): T0 (count value)
ST0 (Coil): T0 (coil)
EN is turned off. (User operation)
The coil turns off, but the current count value and the current state of the contact remain unchanged. (CPU module operation)
Sc
EN
(1)
ST0 (Count) 0 1 2 3 3 3 3
ST0 (Coil)
(1)
Sc: Scan
ST0 (Count): T0 (count value)
ST0 (Coil): T0 (coil)
EN is turned off. (User operation)
The values remain unchanged. (CPU module operation)
APPX
Appendix 1 Operations of when the MC/MCR instructions are used to control EN 71
Devices specified as the device part of the OUT instruction
The following describes operations of devices specified as the device part of the OUT instruction.
Ex.
A subroutine-type FB using M0 for the device part of the OUT instruction.
EN SM400 M0 ENO
END
Sc
EN
M0
(1)
Sc: Scan
EN is turned off. (User operation)
The coil turns off. (CPU module operation)
Sc
EN
M0
(1)
Sc: Scan
EN is turned off. (User operation)
The state of coil remains unchanged. (CPU module operation)
APPX
72 Appendix 1 Operations of when the MC/MCR instructions are used to control EN
MEMO
APPX
Appendix 1 Operations of when the MC/MCR instructions are used to control EN 73
INDEX
O
E
OR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .50
EN. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14,25 Output variable . . . . . . . . . . . . . . . . . . . . . . . 14,20
ENO . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14,25
EXIT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
External variable . . . . . . . . . . . . . . . . . . . . . . . . 20 P
POINTER . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
F Pointer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .34
Program . . . . . . . . . . . . . . . . . . . . . . . . . .9,15,25
FB file . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25 Program Block . . . . . . . . . . . . . . . . . . . . . . . . . .11
FBD unit . . . . . . . . . . . . . . . . . . . . . . . . . . . 61,62 Program file . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
FBD/LD language . . . . . . . . . . . . . . . . . . . . . . 7,61 Programming languages . . . . . . . . . . . . . . . . . . . .7
FLOAT [Single Precision] . . . . . . . . . . . . . . . . . . 33 Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .9
FOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
74
R
REAL . . . . . . . . . . . ..................... 33
REPEAT . . . . . . . . ..................... 54
Reserved word . . . . ..................... 49
Retentive Timer . . . ..................... 34
RETENTIVETIMER . ..................... 34
RETURN . . . . . . . . ..................... 53
S
ST language . . . . . . . . . . . . . . . . . . . . . . . . . . 7,48
Statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47
STRING . . . . . . . . . . . . . . . . . . . . . . . . . 34,58,66
String . . . . . . . . . . . . . . . . . . . . . . . . . . . 34,58,66
Structures . . . . . . . . . . . . . . . . . . . . . . . . . . 34,38
Subroutine program . . . . . . . . . . . . . . . . . . . . . 11
Subroutine type function block . . . . . . . . . . . . 19,27
System labels . . . . . . . . . . . . . . . . . . . . . . . . . . 32
T
TIME . . . . . . . . . . ...................... 34
Time . . . . . . . . . . ...................... 34
TIMER . . . . . . . . . ...................... 34
Timer . . . . . . . . . . ...................... 34
Type conversion . . ...................... 51
Type specification . ...................... 59
W
WHILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 54
WORD . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Word [Signed] . . . . . . . . . . . . . . . . . . . . . . . . . . 33
Word [Unsigned]/Bit String [16-bit] . . . . . . . . . . . 33
Worksheet . . . . . . . . . . . . . . . . . . . . . . . . . . 61,66
X I
XOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 50
75
REVISIONS
Revision date Revision Description
October 2014 A First Edition
January 2015 B ■Added functions
FBD/LD language
■Added or modified parts
Chapter 1, Section 3.1, 3.2, 4.1, 4.3, 4.4, 4.5, 5.2, 5.3, Chapter 6, 7
April 2015 C A part of the cover design is changed.
August 2015 D ■Added or modified parts
Section 4.4, Chapter 7
July 2018 E ■Added or modified parts
RELEVANT MANUALS, TERMS, Section 3.2, 4.4, 5.2, 5.3, 6.1, 7.1
December 2018 F ■Added or modified parts
RELEVANT MANUALS, TERMS, Chapter 2, 3, Section 6.1, Appendix 1, TRADEMARKS
October 2019 G ■Added models
FX5UJ CPU module
■Added or modified parts
RELEVANT MANUALS, TERMS, Section 3.4, 5.3, 6.1
This manual confers no industrial property rights or any rights of any other kind, nor does it confer any patent licenses. Mitsubishi Electric Corporation cannot
be held responsible for any problems involving industrial property rights which may occur as a result of using the contents noted in this manual.
76
WARRANTY
Please confirm the following product warranty details before using this product.
1. Gratis Warranty Term and Gratis Warranty 2. Onerous repair term after discontinuation
Range of production
If any faults or defects (hereinafter "Failure") found to (1) Mitsubishi shall accept onerous product repairs for
be the responsibility of Mitsubishi occurs during use of seven (7) years after production of the product is
the product within the gratis warranty term, the discontinued.
product shall be repaired at no cost via the sales Discontinuation of production shall be notified with
representative or Mitsubishi Service Company. Mitsubishi Technical Bulletins, etc.
However, if repairs are required onsite at domestic or (2) Product supply (including repair parts) is not
overseas location, expenses to send an engineer will available after production is discontinued.
be solely at the customer's discretion. Mitsubishi shall
not be held responsible for any re-commissioning,
3. Overseas service
maintenance, or testing on-site that involves Overseas, repairs shall be accepted by Mitsubishi's
replacement of the failed module. local overseas FA Center. Note that the repair
conditions at each FA Center may differ.
[Gratis Warranty Term] 4. Exclusion of loss in opportunity and
The gratis warranty term of the product shall be for secondary loss from warranty liability
one year after the date of purchase or delivery to a Regardless of the gratis warranty term, Mitsubishi
designated place. Note that after manufacture and shall not be liable for compensation to:
shipment from Mitsubishi, the maximum distribution (1) Damages caused by any cause found not to be
period shall be six (6) months, and the longest gratis the responsibility of Mitsubishi.
warranty term after manufacturing shall be eighteen (2) Loss in opportunity, lost profits incurred to the
(18) months. The gratis warranty term of repair parts user by Failures of Mitsubishi products.
shall not exceed the gratis warranty term before (3) Special damages and secondary damages
repairs. whether foreseeable or not, compensation for
accidents, and compensation for damages to
[Gratis Warranty Range] products other than Mitsubishi products.
(4) Replacement by the user, maintenance of on-site
(1) The range shall be limited to normal use within the
equipment, start-up test run and other tasks.
usage state, usage methods and usage
environment, etc., which follow the conditions and 5. Changes in product specifications
precautions, etc., given in the instruction manual, The specifications given in the catalogs, manuals or
user's manual and caution labels on the product. technical documents are subject to change without
(2) Even within the gratis warranty term, repairs shall prior notice.
be charged for in the following cases. 6. Product application
1. Failure occurring from inappropriate storage or (1) In using the Mitsubishi MELSEC programmable
handling, carelessness or negligence by the controller, the usage conditions shall be that the
user. Failure caused by the user's hardware or application will not lead to a major accident even if
software design. any problem or fault should occur in the
2. Failure caused by unapproved modifications,
programmable controller device, and that backup
etc., to the product by the user.
and fail-safe functions are systematically provided
3. When the Mitsubishi product is assembled into
outside of the device for any problem or fault.
a user's device, Failure that could have been
avoided if functions or structures, judged as (2) The Mitsubishi programmable controller has been
necessary in the legal safety measures the designed and manufactured for applications in
user's device is subject to or as necessary by general industries, etc. Thus, applications in which
industry standards, had been provided. the public could be affected such as in nuclear
4. Failure that could have been avoided if power plants and other power plants operated by
consumable parts (battery, backlight, fuse, respective power companies, and applications in
etc.) designated in the instruction manual had which a special quality assurance system is
been correctly serviced or replaced. required, such as for railway companies or public
5. Relay failure or output contact failure caused service purposes shall be excluded from the
by usage beyond the specified life of contact programmable controller applications.
(cycles). In addition, applications in which human life or
6. Failure caused by external irresistible forces property that could be greatly affected, such as in
such as fires or abnormal voltages, and failure aircraft, medical applications, incineration and fuel
caused by force majeure such as earthquakes, devices, manned transportation, equipment for
lightning, wind and water damage. recreation and amusement, and safety devices,
7. Failure caused by reasons unpredictable by shall also be excluded from the programmable
scientific technology standards at time of controller range of applications.
shipment from Mitsubishi. However, in certain cases, some applications may
8. Any other failure found not to be the be possible, providing the user consults their local
responsibility of Mitsubishi or that admitted not Mitsubishi representative outlining the special
to be so by the user. requirements of the project, and providing that all
parties concerned agree to the special
circumstances, solely at the user's discretion.
77
TRADEMARKS
Ethernet is a registered trademark of Fuji Xerox Co., Ltd. in Japan.
PROFIBUS is a trademark of PROFIBUS Nutzerorganisation e.V.
Anywire and AnyWireASLINK are either registered trademarks or trademarks of Anywire Corporation.
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.
78
Manual number: JY997D55701G
Model: FX5-P-PS-E
Model code: 09R538
When exported from Japan, this manual does not require application to the
Ministry of Economy, Trade and Industry for service transaction permission.
HEAD OFFICE: TOKYO BUILDING, 2-7-3 MARUNOUCHI, CHIYODA-KU, TOKYO 100-8310, JAPAN