ST Programming Gude & Example
ST Programming Gude & Example
Under some circumstances, failure to observe the precautions given under " CAUTION" may lead to serious
consequences.
Observe the precautions of both levels because they are important for personal and system safety.
Make sure that the end users read this manual and then keep the manual in a safe place for future reference.
[Design Precautions]
WARNING
● When data change, program change, or status control are performed from a personal computer to a
running programmable controller, create an interlock circuit outside the programmable controller to
ensure that the whole system always operates safely.
[Security Precautions]
WARNING
● To maintain the security (confidentiality, integrity, and availability) of the programmable controller and
the system against unauthorized access, denial-of-service (DoS) attacks, computer viruses, and other
cyberattacks from external devices via the network, take appropriate measures such as firewalls,
virtual private networks (VPNs), and antivirus solutions.
1
CONDITIONS OF USE FOR THE PRODUCT
(1) MELSEC programmable controller ("the PRODUCT") shall be used in conditions;
i) where any problem, fault or failure occurring in the PRODUCT, if any, shall not lead to any major or serious accident;
and
ii) where the backup and fail-safe function are systematically or automatically provided outside of the PRODUCT for the
case of any problem, fault or failure occurring in the PRODUCT.
(2) The PRODUCT has been designed and manufactured for the purpose of being used in general industries.
MITSUBISHI ELECTRIC SHALL HAVE NO RESPONSIBILITY OR LIABILITY (INCLUDING, BUT NOT LIMITED TO
ANY AND ALL RESPONSIBILITY OR LIABILITY BASED ON CONTRACT, WARRANTY, TORT, PRODUCT
LIABILITY) FOR ANY INJURY OR DEATH TO PERSONS OR LOSS OR DAMAGE TO PROPERTY CAUSED BY the
PRODUCT THAT ARE OPERATED OR USED IN APPLICATION NOT INTENDED OR EXCLUDED BY
INSTRUCTIONS, PRECAUTIONS, OR WARNING CONTAINED IN MITSUBISHI ELECTRIC USER'S, INSTRUCTION
AND/OR SAFETY MANUALS, TECHNICAL BULLETINS AND GUIDELINES FOR the PRODUCT.
("Prohibited Application")
Prohibited Applications include, but not limited to, the use of the PRODUCT in;
• Nuclear Power Plants and any other power plants operated by Power companies, and/or any other cases in which the
public could be affected if any problem or fault occurs in the PRODUCT.
• Railway companies or Public service purposes, and/or any other cases in which establishment of a special quality
assurance system is required by the Purchaser or End User.
• Aircraft or Aerospace, Medical applications, Train equipment, transport equipment such as Elevator and Escalator,
Incineration and Fuel devices, Vehicles, Manned transportation, Equipment for Recreation and Amusement, and
Safety devices, handling of Nuclear or Hazardous Materials or Chemicals, Mining and Drilling, and/or other
applications where there is a significant risk of injury to the public or property.
Notwithstanding the above restrictions, Mitsubishi Electric may in its sole discretion, authorize use of the PRODUCT in
one or more of the Prohibited Applications, provided that the usage of the PRODUCT is limited only for the specific
applications agreed to by Mitsubishi Electric and provided further that no special quality assurance or fail-safe,
redundant or other safety features which exceed the general specifications of the PRODUCTs are required. For details,
please contact the Mitsubishi Electric representative in your region.
(3) Mitsubishi Electric shall have no responsibility or liability for any problems involving programmable controller trouble and
system trouble caused by DoS attacks, unauthorized access, computer viruses, and other cyberattacks.
2
INTRODUCTION
Thank you for purchasing the Mitsubishi Electric MELSEC iQ-R series and MELSEC iQ-F series programmable controllers.
This manual describes the programming using Structured Text (ST) in GX Works3.
Before using this product, please read this manual and the relevant manuals carefully and develop familiarity with the
functions and performance of the MELSEC iQ-R series and MELSEC iQ-F series programmable controllers to handle the
product correctly.
When applying the program and circuit examples provided in this manual to an actual system, ensure the applicability and
confirm that it will not cause system control problems.
Description in this manual is based on the use of MELSEC iQ-R series.
For the considerations when using MELSEC iQ-F series, refer to the following:
Page 104 Considerations for Using the MELSEC iQ-F Series
3
CONTENTS
SAFETY PRECAUTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .1
CONDITIONS OF USE FOR THE PRODUCT . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .2
INTRODUCTION . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .3
RELEVANT MANUALS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .7
TERMS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
GENERIC TERMS AND ABBREVIATIONS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .8
PART 1 ST PROGRAMMING
4
Clock data (date and time) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
4.5 Array and Structure. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
Data type combined with structure and array . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
CONTENTS
Closed contact (NOT) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 38
Series connection, parallel connection (AND, OR) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 39
Contact and coil of which execution order are complicated . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 40
5.2 Describing Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Instructions that can be used in ladder program and ST program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 41
Instructions that can be described using assignment statements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Instructions that can be described using operator. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
Instructions that can be described in control statement and FUN/FB . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5.3 Describing Statements of Ladder and Notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
5
8.4 Fraction Processing (FUN): FractionProcessing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 67
8.5 Calculator Program: Calculator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 69
8.6 Post-Tax Price Calculation: IncludingTax . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 71
APPENDIX 92
Appendix 1 Specifications of Structured Text language . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Statement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92
Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Comment . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 93
Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94
Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 96
Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 97
Function and function block. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 99
Appendix 2 Instructions That Cannot be Used in ST Programs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Instructions that can be described in assignment statement. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Instructions that can be described with operator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 101
Instructions that can be described with control statement or function . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Unnecessary instructions for ST program . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 103
Appendix 3 Considerations for Using the MELSEC iQ-F Series . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
Differences between the MELSEC iQ-F series and MELSEC iQ-R series . . . . . . . . . . . . . . . . . . . . . . . . . . . . 104
INDEX 105
REVISIONS. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .107
TRADEMARKS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .108
6
RELEVANT MANUALS
Manual name [manual number] Description Available form
MELSEC iQ-R/MELSEC iQ-F Structured Text (ST) Programming using Structured Text (ST) in GX Works3. Fundamental Print book
Programming Guide Book operations and functions are explained using sample programs
e-Manual
[SH-081483ENG](this manual)
PDF
GX Works2 Beginner's Manual (Structured Project) Programming using Structured Text (ST) in GX Works2 Print book
[SH-080788ENG]
PDF
Structured Text (ST) Programming Guide Book Programming using Structured Text (ST) in GX Developer Print book
[SH-080368E] PDF
Detailed specifications of Structured Text language are not described in this manual.
For details, refer to the following:
MELSEC iQ-R Programming Manual (Program Design)
MELSEC iQ-F FX5 Programming Manual (Program Design)
e-Manual refers to the Mitsubishi Electric FA electronic book manuals that can be browsed using a dedicated
tool.
e-Manual has the following features:
• Required information can be cross-searched in multiple manuals.
• Other manuals can be accessed from the links in the manual.
• The hardware specifications of each part can be found from the product figures.
• Pages that users often browse can be bookmarked.
7
TERMS
Unless otherwise specified, this manual uses the following terms.
Term Description
Device A variable of which name, type, and usage are defined by system.
Engineering tool A tool for setting, programming, debugging, and maintaining programmable controllers.
Execution program A program which has been converted.
This program can be executed in a CPU module.
Function A function that can be used as a POU.
This function always outputs same result for the same input.
Function block A function that can be used as a POU.
This function retains values in the internal variables. It can be used by creating an instance.
Instance An entity of a function block of which devices are assigned to the defined internal variables to be processed and
executed.
One or more instances can be created for one function block.
Label A variable that is defined by user.
POU A unit that configures a program.
Units are categorized and provided in accordance with functions. Use of POUs enables dividing the lower-layer
processing in a hierarchical program into some units in accordance with processing or functions, and creating programs
for each unit.
8
PART 1
PART 1 ST PROGRAMMING
This part explains the ST programming with the MELSEC-iQ-R series and MELSEC iQ-F series.
9
1 WHAT IS STRUCTURED TEXT?
Program example
Assign the average from the wValue0 to the wValue2 in the wAverage3.
wAverage3 = (wValue0 + wValue1 + wValue2) 3
ST
wAverage3 := ( wValue0 + wValue1 + wValue2) / 3;
LD
AlwaysON
MOV 0 wTotal
+ wValue0 wTotal
+ wValue1 wTotal
+ wValue2 wTotal
/ wTotal 3 wArray0
For details of the description method using Structured Text language, refer to the following:
Page 18 Operational Expressions
For details of the description method using Structured Text language, refer to the following:
Page 29 Integer and Real Number
Program example
Set 0 to 3 to the wValue1 depending on the value of the wValue0.
• 100 or 200: 0
• 1 to 99: 1
• 150: 2
• Other than above: 3
ST
CASE wValue0 OF
100, 200: wValue1 := 0;
1..99: wValue1 := 1;
150: wValue1 := 2;
ELSE wValue1 := 3;
END_CASE;
LD
AlwaysON
= wValue0 100 MOV 0 wValue1
MOV 1 wValue1
K0
MOV 3 wValue1
For details of the description method using Structured Text language, refer to the following:
Page 22 Selection, Page 25 Iteration
To take full advantage of the features of each language, create a program by combining each language in accordance with the
process.
In GX Works3, the combination of the Structured Text and other languages can be used in the following functions.
Function Language Description
Inline Structured LD Describe the part of a relay sequence processing using Structured Text.
Text
FUN/FB LD Define a sub program (subroutine) described in Structured Text as a POU, and call it from other
FBD programs such as LD.
By describing a simple relay sequence process and perspicuous process using the Ladder Diagram, and describing a part of
complex process using the Structured Text of which process can be segmented, an easy-to-see program can be created.
LD with inline structured text
LD with FUN/FB
FbPou_1 ( FbPou )
AlwaysON
B:EN ENO:B
2.1 Characters 2
The Structured Text is a programming language that can be described in text format. This section explains the characters and
symbols that can be used in the Structured Text language.
Character code
GX Works3 supports the characters in the Unicode Basic Multilingual Plane (UTF-16).
Basic characters and symbols in multiple languages such as Japanese, English, and Chinese can be used for not only
comments but also label names and data names.
For the characters (reserved words) that cannot be used for a label name and data name, refer to the
following:
GX Works3 Operating Manual
Control statement
Function
Line feed
Function block
(instance) Delimiter
TAB Space
The instructions which are not necessary for Structure Text language (such as contact) are not supported.
Page 101 Instructions That Cannot be Used in ST Programs
■Function
Function is a POU that outputs same result for the same input. Function is suitable for segmenting a simple and independent
processing. 2
Describe the function name and arguments in an ST program as follows:
■Function block
Function block is a POU of which internal values can be used for operations. The different result is output for the same input
depending on the value retained in each instance (entity). Function block is suitable for segmenting much more complex
processing than a function, or for processing which is required to be executed repeatedly using the retained value.
To use a function block in an ST program, describe an instance and arguments as follows;
For details of the description method using Structured Text language, refer to the following:
Page 99 Function and function block
For details of the functions and function blocks, refer to the following:
MELSEC iQ-R Programming Manual (Program Design)
MELSEC iQ-F FX5 Programming Manual (Program Design)
Statement
A group of one execution process is referred to as "statement".
A program is described in "statement" units.
Each statement must end with a semicolon ';'.
Structure of statement and type
(Substitution statement) ;
(Selection statement)
(Statement) ;
(Statement) ;
(Iteration statement)
(Statement) ;
Hierarchization of a control statement can be performed. (Other statements such as a select statement or an iteration
statement can be described among the statements.).
(Statement)
(Statement)
;
;
The data type of an expression is recognized at compilation (conversion). The value of an expression is evaluated during the
execution of a program.
An operational expression such as an arithmetic operation and a comparison operation can be described by combining with
constant or variable, and operator in the same manner as a generic expression.
A variable and constant can be used as an expression (primary expression) in the Structured Text language.
The types of expressions are as follows
Type Data type of expression (operation result) Example
Operational Arithmetic expression Integer, real number (depending on the operation target) wValue0 + wValue1
expression
Logical expression Boolean value (TRUE/FALSE) bFlag0 OR bFlag1
Comparison expression Boolean value (TRUE/FALSE) wValue0 > 0
Primary Variable, constant Defined data type X0, wValue0, 123, TRUE
expression
Function call expression Data type of return value FunPou(wValue0, wValue1)
A function which does not have a return value cannot be used as an expression.
Assignment (:=)
The result of an evaluation can be stored to a variable using an assignment statement.
Describe an assignment statement using ':='. This operational expression stores the calculation result of the right side to the
variable in the left side.
<Variable> := <Expression> ;
Use ':=' in the Structured Text language instead of '=' which is used in a general expression.
Program example
The sum from the wValue0 to the wValue2 is assigned to wTotal.
wTotal = wValue0 + wValue1 + wValue2
ST
wTotal := wValue0 + wValue1 + wValue2;
LD
AlwaysON
MOV 0 wTotal
+ wValue0 wTotal
+ wValue1 wTotal
+ wValue2 wTotal
When multiple operational expressions are described in one statement, the operation is processed in order
from high priority operation.
• Priority of basic arithmetic operations (high to low): Multiplication and division (*, /), addition and subtraction
(+, -)
When some operators of which priority is the same are used in one statement, the operators are calculated in
order from the left.
Program example
The average from the wValue0 to the wValue2 is assigned to the wAverage3.
wAverage3 = (wValue0 + wValue1 + wValue2) 3
ST
wAverage3 := ( wValue0 + wValue1 + wValue2) / 3;
LD 3
AlwaysON
MOV 0 wTotal
+ wValue0 wTotal
+ wValue1 wTotal
+ wValue2 wTotal
/ wTotal 3 wArray0
Program example
The length of a hypotenuse is obtained.
C
C = ( A 2+ B 2) B
A
ST
eValueC := SQRT((eValueA ** 2.0) + (eValueB ** 2.0));
LD
AlwaysON
POW eValueA 2.0 eTmp1
E+ eTmp1 eTmp2
Program example
The logical product (AND) of the bFlag0 and the bFlag1 is assigned to the bResult.
ST
bResult := bFlag0 AND bFlag1; 3
LD
Program example
The comparison result of the wValue0 and the wValue1 (equality: TRUE, inequality: FALSE) is assigned to the bResult.
ST
bResult := wValue0 = wValue1;
LD
bResult
= wValue0 wValue1
In the Structured Text language, '=' is regarded as an operator which compares if the left side and right side of
the statements are equal.
Describe an assignment statement using ':='.
END_IF;
frame) are omittable. 3. Judgment of ELSE
When all the conditions of 'IF' and 'ELSIF' are FALSE, the Statement 3
after 'ELSE' is executed.
Program example
The different value is set to the wValue0 depending on the condition of the bFlag0.
• When ON (bFlag0 is TRUE): wValue0 = 100
• When OFF (bFlag0 is FALSE): wValue0 = 0
ST
IF bFlag0 THEN
wValue0 := 100;
ELSE
wValue0 := 0;
END_IF;
LD
bFlag0
MOV 100 wValue0
MOV 0 wValue0
Program example
0, 1, 2, or 3 is set to the wValue1 depending on the value of the bFlag0 and the wValue0.
• When bFlag0 is FALSE: 0
• When the bFlag0 is TRUE and the wValue0 is 100 or 200: 1
• When the bFlag0 is TRUE and the wValue0 is 1 to 99: 2
3
• Other than above: 3
ST
IF NOT bFlag0 THEN
wValue1 := 0;
ELSIF (wValue0 = 100) OR (wValue0 = 200) THEN
wValue1 := 1;
ELSIF (1 <= wValue0) AND (wValue0<= 99) THEN
wValue1 := 2;
ELSE
wValue1 := 3;
END_IF;
LD
bFlag0
MOV 0 wValue1
MOV 3 wValue1
3. Judgment of ELSE
When all the integer values or ranges are equal, the Statement 3 after
'ELSE' is executed.
The following items can be specified in the conditional expression of CASE statement.
• Operational expression of which result is to be an integer (INT or DINT) value
• Variable of integer (INT or DINT) type
• Function call expression of which return value is integer (INT or DINT) type
Multiple selections (<Value>:<Statement>;) determined by an integer value can be set.
Describe the selection using ELSE (ELSE<Statement>) as necessary. (Omittable)
For an integer value to be judged, a label that satisfies the following conditions can be set: the data type is
Word [Signed] or Double Word [Signed], and the class is VAR_CONSTANT.
Program example
0, 1, 2, or 3 is set to the wValue1 depending on the value of the wValue0.
• When 100 or 200: 0
• When 1 to 99: 1
• When 150: 2
• Other than above: 3
ST
CASE wValue0 OF
100, 200: wValue1 := 0;
1..99: wValue1 := 1;
150: wValue1 := 2;
ELSE wValue1 := 3;
END_CASE;
LD
AlwaysON
= wValue0 100 MOV 0 wValue1
MOV 1 wValue1
K0
MOV 3 wValue1
The following items can be specified in the conditional expression of WHILE and REPEAT statement.
• Operational expression of which result is to be a boolean value
• Variable of boolean type
• Function call expression of which return value is boolean type
Program example
When the bFlag0 is TRUE, the wValue0 is incremented.
ST
WHILE bFlag0 DO
wValue0 := wValue0 + 1;
END_WHILE;
LD
P11
bFlag0
CJ P12
AlwaysON
+ 1 wValue0
AlwaysON
CJ P11
P12
Program example
The wValue0 is incremented until the bFlag0 is TRUE or the wValue0 is 10 or more.
ST
REPEAT
wValue0 := wValue0 + 1;
UNTIL bFlag0 OR (wValue0 >= 10)
END_REPEAT;
LD
P21
AlwaysON
+ 1 wValue0
bFlag0
CJ P21
The following items can be specified for the initial value, last value, and increment value of FOR statement.
• Operational expression of which result is to be an integer (INT or DINT) value
• Variable of integer (INT or DINT) type
• Function call expression of which return value is integer (INT or DINT) type
Convert the type in order that the value is to be an integer type.
If the increment value is 1, the addition process of the increment value (BY<Increment (expression)>;) can be
omitted.
After the execution of the FOR statement, the variable set as a condition retains the value at the end of the
FOR statement.
Program example
The element from 10 to 20 of the wArray1 are set to the element from 0 to 10 of the wArray0.
ST
FOR wIndex0 := 0 TO 10 BY 1 DO
wArray0[wIndex0] := wArray1[wIndex0 + 10];
END_FOR;
LD
AlwaysON
RST wIndex0
11
FOR
AlwaysON
wIndex0 K10 wTmp1
+
+ wIndex0 K1 wIndex0
NEXT
When using the value with the different data type as the defined one, use a type conversion function of a
standard function.
Value of range
Depending on the type of variable, the effective digits differ. Specify the variable of the appropriate data type depending on the
operation to be executed.
The following shows the ranges that can be handled in operation depending on the data type of the variable.
Data type Range
Integer Word [Unsigned]/Bit String [16-bit] WORD 0 to 65535
Double Word [Unsigned]/Bit String [32-bit] DWORD 0 to 4294967295
Word [Signed] INT -32768 to 32767
Double Word [Signed] DINT -2147483648 to 2147483647
Real FLOAT [Single Precision] REAL -2128 to -2-126, 0, 2-126 to 2128
number FLOAT [Double Precision] LREAL -21024 to -2-1022, 0, 2-1022 to 21024
Ex.
Assignment between Word [Signed] (INT) and Double Word [Signed] (DINT)
ST Operation result
dValue0 := wValue1; The type conversion from INT to DINT is performed automatically.
wValue1 := dValue0; A conversion error occurs since the data may be lost at conversion from DINT to INT.
wValue1 := DINT_TO_INT(dValue0); Perform a type conversion from DTIN to INT using a type conversion function.
If the range of the value before conversion exceeds the range of INT type, an operation error occurs.
The type conversion is not performed automatically under the following situation. In this case, use a type
conversion function.
• Type conversion for the integer which has same data size and different sign
• Type conversion for the type of which data may be lost
• Type conversion other than integer type and real number type
The data conversion is also performed automatically when passing the input argument to a standard function, standard
function block, and instruction.
The following shows the combinations of data types which are converted automatically when the input argument is defined as
the generic data type.
Data type of variable (before conversion) Data type definition of input argument Data type after conversion
to be specified to argument
Word [Signed] ANY32, ANY32_S Double Word [Signed]
ANY_REAL, ANY_REAL_32 FLOAT [Single Precision]
ANY_REAL_64 FLOAT [Double Precision]
Word [Unsigned]/Bit String [16-bit] ANY32, ANY32_U Double Word [Unsigned]/Bit String [32-bit]
ANY_REAL, ANY_REAL_32 FLOAT [Single Precision]
ANY_REAL_64 FLOAT [Double Precision]
Double Word [Signed] ANY_REAL, ANY_REAL_64 FLOAT [Double Precision]
Double Word [Unsigned]/Bit String [32-bit]
FLOAT [Single Precision] ANY_REAL_64
If the data type of the operator on the right side and left side differ, the data type of the operation result will be
a bigger data type.
• Priority of the data type of an operation result (high to low): FLOAT [Double Precision], FLOAT [Single
Precision], Double Word, Word
[Singed] and [Unsigned] cannot be mixed in binary operation of the integer.
4
Considerations
If the value is outside the range of the data type which can be handled in the operation result, the accurate result (value)
cannot be reflected to the process after the operation.
Convert the data type of the variable for the operation target to the data type within the range of the operation result in
advance.
Ex.
Arithmetic operation of Word [Signed] (INT)
ST Operation result
dValue0 := wValue1 * 10; If the operation result is out of the range of INT type (-32768 to 32767), the operation resulted in
overflow or underflow is assigned.
dValue1 := INT_TO_DINT(wValue1); Overflow or underflow does not occur since the operation is processed with DINT type.
dValue0 := dValue1 * 10;
dValue1 := INT_TO_DINT(wValue1) * 10;
Ex.
Assign the operation result of the expression '(2 10) 10' to D0
Data type ST Operation result
Integer Word [Signed] D0 := (2 / 10) * 10; 0
Real FLOAT [Single Precision] D0:E := (2.0 / 10.0) * 10.0; 2.0
number
For word devices, a data type can be specified by adding ':E' in the Structured Text language.
(Page 94 Type specification of word device)
Ex.
Calculate the lower two-digits of a five-digits integer
Data type ST Operation result
Integer Word [Signed] D0 := (-32368 MOD 100); -68
Program example
The length of a character string is calculated.
ST
wLen0 := LEN(sString0);
Program example
The character string 'ABC' is assigned to the sString0 (character string variable) and the wsString1 (character string [Unicode]
type variable).
ST
sString0 := 'ABC';
wsString1 := "ABC";
Program example
After the comparison of the character strings, the sString1 is assigned to the sString0 if the characters are not equal.
ST
IF sString0 <> sString1 THEN
sString0 := sString1;
END_IF;
For the character string type variable, a comparison operator (<, >, <=, >=) compares the values using the
value of ASCII code or Unicode.
Depending on the first character code number of which inequality is detected, the comparison result of the
character string is determined.
The details of the comparison conditions are the same as the one as the character string comparison
instruction (LD$<, etc.)
The time type variable can be set in the range from T#-24d20h31m23s648ms to T#24d20h31m23s647ms. 4
For details on the description method of the time length, refer to the following:
Page 98 Description method of the time length
Assignment of time
Describe a time type variable using as assignment statement.
Program example
The value that indicates 1 hour 30 minutes is assigned to the tmData0 (time type variable).
ST
tmData0 := T#1h30m;
Comparison of time
Describe a comparison operation (comparison, equality, inequality) of a time type variable using an operator.
Program example
If the time data is one day or more, the processing is ended.
ST
IF tmData0 >= T#1d THEN
RETURN;
END_IF;
Program example
The value in which 10 ms is added and doubled is assigned to the tmData0 (time type variable).
ST
tmData0 := MUL_TIME(tmData0 + T#10ms, 2);
Program example
"year, month, day, hour, minute, second, and day of week" are read from the clock element of the CPU module.
ST
DATERD(TRUE, wArray);
Array
Describe only the label name when indicating whole array type variables.
When indicating each element of the array, describe the element number to be specified enclosing with '[ ]' as an index after
the label name.
Assignment of array
Describe an array type variable using the assignment statement to assign the value to the element specified by the index.
By describing the element without index, the value is assigned (copied) to the whole array elements.
Program example
The following data is assigned to the wArray1 (array type variable) of Word [Signed] data.
• Array 0: 10
• Array 1: Array [0,1] of two-dimensional array, wArray2
ST
wArray1[0] := 10;
wArray1[1] := wArray2[0, 1];
Program example
All the elements of wArray0 are assigned to all the elements of the wArray1 (array type variable of Word [Signed] data).
(This program example can be described when the data type and number of array data on the right side and left side are the
same.)
ST
wArray1 := wArray0;
Program example
The following data is assigned to the wArray1 (array type variable) of the Word [Signed] data.
• Element wIndex0+1: Sum of the element 0 and element 1 in the wArray0
ST
wArray1[wIndex0 +1] := wArray0[0] + wArray0[1];
Structure
Define the structure combining the multiple different data types as one data type.
Structure can be used for data management because the arbitrary name of structure type definition and name of each
member can be set.
When indicating whole structure type variables, describe only the label name.
When indicating each member of the structure, list the member names by adding a dot '.' after the label name.
stData0 . Member2
Member Entity of Member2 Member (Member2)
name
Assignment of structure
Describe a structure type variable using the assignment statement to assign the value to the specified member.
By describing the structure without specifying the member, the value is assigned (copied) to the whole structures.
Program example
The following data is assigned to the member of the stData0 (structure type variable).
• Member1 (FLOAT [Single Precision]): 10.5
• Member2 (Bit): TRUE
ST
stData0.Member1 := 10.5;
stData0.Member2 := TRUE;
Program example
All the elements of stData0 are assigned to all the elements of the stData1 (structure type variable).
(This program example can be described when the data type of the structure (structure type definition) on the right side and
left side are the same.)
ST
stData1 := stData0;
Program example
The wArray1 (array type variable) is assigned to the wArray (array member) of the stData0 (structured type variable). (Both of
them are Word [signed] type and same size.)
ST
stData0.wArray := wArray1;
Program example
The member of the element number 1 and the member of element number 0 in the stArray0 (structured array type variable)
4
are compared.
ST
bResult := stArray0[1].Member1 > stArray0[0].Member1;
Program example
The bResult0 turns ON/OFF according to the ON/OFF statue of the bFlag0.
ST
bResult0 := bFlag0;
LD
bFlag0 bResult0
Describe an assignment statement using ':='. The calculation result of a right side is stored to a variable on the
left side.
Program example
The bResult0 turns OFF when the bFlag0 is ON, and the bResult0 turns ON when the bFlag0 is OFF.
ST
bResult0 := NOT bFlag0;
LD
bFlag0 bResult0
Program example
The bResult0 turns ON when any of the following conditions is met.
• Condition 1: The bFlag0 is ON and the bFlag1 is ON
• Condition 2: The bFlag2 is ON
ST
bResult0 := bFlag0 AND bFlag1 OR bFlag2;
LD
5
bFlag2
When multiple operational expressions are described in one statement, the operation is processed in order
from high priority operation.
• Priority of logical operator (high to low): AND operation(AND, &), XOR operation, OR operation
When some operators of which priority is the same are used in one statement, the operators are operated in
order from the left.
Program example
The bResult0 turns ON when the following condition 1 and condition 2 are met.
The bResult1 turns ON when the following condition 1, condition 2, and condition 3 are met.
• Condition 1: Either the bFlag0 or the bFlag1 is ON
• Condition 2: The bFlag2 is ON
• Condition 3: The bFlag3 is ON
ST
bResult0 := (bFlag0 OR bFlag1) AND bFlag2;
bResult1 := bResult0 AND bFlag3;
LD
When the above program is executed, the ON/OFF timing of each device are as follows;
bFlag0 ON
OFF
bFlag1 ON
OFF
bFlag2 ON
OFF
bFlag3 ON
OFF
ON
bResult0
OFF
ON
bResult1
OFF
Program example
The bResult0 turns ON for one scan when the bFlag0 is turned ON from OFF.
ST
PLS(bFlag0, bResult0); 5
LD
bFlag0
PLS bResult0
For details on the instructions, refer to the programming manual. Press the key with the cursor on the instruction to
display the page of the instruction.
Program example
The eValue0 (FLOAT [Single Precision]) is converted to the wValue1 (16-bit binary data with sign).
ST
wValue1 := REAL_TO_INT( eValue0 );
LD
AlwaysON
FLT2INT eValue0 wValue1
Program example
The sString0 (character string type variable) is transferred (assigned) to the sString1.
ST
sString1 := sString0;
LD
AlwaysON
$MOV sString0 sString1
Program example
Depending on the comparison result of the Word [Signed] (INT) valuable, the two values of Double Word [Signed] (DINT) are
added.
ST
IF (wValue0 < wValue1 ) AND (wValue2 > wValue3 ) OR (wValue4 <> wValue5 ) THEN
dValue1 := dValue0 + dValue1;
END_IF;
LD
END instruction is not required for the Structured Text language. (Page 103 Unnecessary instructions for
ST program)
1. Open an ST editor.
Monitor
ST editor
Program example
Operating procedure
1. Enter 'wValue0 := D10 - 123;'.
By pressing the ++ keys, the assignment symbol (:=) can be entered.
Other than the operation from the [Edit] menu, the following generic key operations can be used.
• +/+: Cut/paste
• +/+: Undo/redo
In GX Works3, the rectangle range can be selected by dragging the range while pressing the key on the
ST editor.
Operating procedure
1. Enter 'IF'.
Entering comment
Enter a comment in the ST program.
Operating procedure
1. Enter a comment in the arbitrary position in the
program. (In the figure on the left, enter a comment after
'bFlag0 := TRUE;'.)
• A space or TAB can be inserted anywhere.
2. Enter the delimiter ('(*' and '*)') before and after the
comment.
The range enclosed with the symbols is regarded as a
comment.
Enter "(* OFF *)" after "FALSE" as well.
In GX Works3, '/**/' and '//', which are the same symbols as C language, can be used for comment.
By adding '//' in front of the statement, the statement is regarded as a comment.
By using the following functions, the comment out/disable comment out function can be performed in the
selected range.
• [Edit] [Comment Out of Selected Range]( + + )
• [Edit] [Disable Comment Out of Selected Range]( + + )
Collapsing comments
Collapse the comment ( ) by clicking the icon ( ) displayed on the left side of the comment.
Registering labels
Register a label from an ST editor.
Operating procedure
Unregistered label name is displayed as an error.
Operating procedure
1. Display the "Local Label Setting" screen.
Set the following items for the local label as the labels to be used in the program example.
Label Name Data Type Class
wValue0 Word [Signed] VAR
wValue1 Word [Signed] VAR
bFlag0 Bit VAR
bResult Bit VAR
Operating procedure
1. Register the bit type label, bResult.
Creating function
Create the new data of a function in the project, and define the function program and its local label.
Operating procedure
1. Select [Project] [Data Operation] [New Data].
The setting items of the created function can be checked on the "Properties" screen.
The "Properties" screen can be displayed with the following operation.
• Select and right-click the data on the Navigation window and select [Property] from the shortcut menu.
Operating procedure
1. Select [Project] [Data Operation] [New Data].
The setting items of the created function block can be checked on the "Properties" screen.
The "Properties" screen can be displayed with the following operation.
• Select and right-click the data on the Navigation window and select [Property] from the shortcut menu.
A function with a return value can be used as an expression. (Function call expression)
A function with no return value must be described as a call statement. (Function call statement)
Instructions can also be entered from the list. (Page 41 Describing Instructions)
By pressing the key on the instruction, the details of the instruction can be checked on the e-Manual
Viewer.
(To check the instructions, the files of the corresponding programming manuals are required to be registered
to e-Manual Viewer.)
Operating procedure
1. By entering "(", the format of the instruction is displayed
in the tooltip.
For the defined function, the arguments can also be inserted using the template.
By pressing the + keys, the template of the selected function name is displayed.
Selecting functions from the Navigation window or the Element Selection window
Insert a function by selecting it from the Navigation window or the Element Selection window.
Insert a function from the Navigation window or the Element Selection window by dragging or dropping it to
the ST editor.
Navigation Element
window Selection
window
Operating procedure
1. Enter the instance name, "FbPou_1" (example).
Operating procedure
1. By entering "(", the format of function block is displayed
in the tooltip.
For the defined function block, the arguments can also be inserted using the template.
By pressing the + keys, the template of the selected instance name is displayed.
Insert a function block from the Navigation window or the Element Selection window by dragging or dropping
it to the ST editor.
Navigation Element
window Selection
window
Converting programs
Convert the created program to the executable code.
Operating procedure
1. Execute [Convert] [Convert] ().
By performing the conversion (), only the added or changed program is converted.
When converting all programs including the converted programs, perform the following function.
• [Convert] [Rebuild All] (++)
6
Checking error/warning
An illegal program is checked at the conversion, and an error/warning message is displayed.
Convert the following program as an example.
Program example
Operating procedure
1. Double-click the error/warning message displayed on
the Output window.
Monitor
Operating procedure
1. Connect a personal computer to the CPU module, and set the connection target in the engineering tool (GX Works3).
Operating procedure
Select [Online] [Monitor] [Start Monitoring]()/[Stop Monitoring](+).
6
Display of current values
The following shows the display of the monitoring value on the ST editor.
■Bit type
The monitoring values of bit types are displayed on the program as follows;
• TRUE:
• FALSE:
Place the cursor on the device/label name to display a monitoring value on the tooltip.
Operating procedure
1. Select the device/label of which current value is to be changed on the ST editor.
2. Click the + keys. (Or double-click while pressing the key)
The devices/labels other than bit type are registered to the Watch window. Change the current value on the Watch window.
Operating procedure
1. Select [Online] [Watch] [Start Watching](+)/[Stop Watching](++).
2. Enter a value to which "Current Value" is to be changed directly while monitoring.
Devices/labels can be registered to the Watch window by any of the following operations.
• Drag and drop the devices/labels from the ST editor to the Watch window.
• [Tool] [Options] "Monitor" "ST Editor" "Setting for Automatic Registration to Watch Window"
Operating procedure
1. Select [Edit] [Inline Structured Text] [Insert Inline Structured Text Box](+).
Enter 'STB' on the ladder entry dialog to insert an inline structured text box.
59
7 OVERVIEW OF PROGRAM EXAMPLE
This chapter explains the list of program examples and their usage.
Considerations
The program examples described in this manual do not guarantee the actual operation.
When applying program examples to the actual system, make sure to match the program example with the system and its
required operation.
Assign the devices for the labels used in the program example according to the equipment to be used as necessary.
Set the parameters in accordance with the equipment or devices to be used as necessary.
1. Set the global labels on the label editor. (Page 48 Registering labels on the label editor)
• When using a structure, create a new structure definition and set the structure.
2. Create a POU.
• Set the local labels. (Page 48 Registering labels on the label editor)
• Apply a program example to the program. (Page 45 Copying/pasting data among editors)
When a POU defined in this manual is used in the sample program, create the function or the function block in the same
project. (Page 49 Creating new data) 7
3. Convert the program. (Page 55 Converting and Debugging Programs)
When reading this manual in PDF or e-Manual format, a sample program can easily be applied by copying
and pasting it.
Overview of function
The following processing are performed.
• When the clear key is input, the current value (previous calculation result) and displayed value are initialized.
• The displayed value is updated according to the input of the ten key. The value after decimal point is rounded depending on
the setting of the slide switches.
• When the post-tax calculation key is input, a post-tax price is displayed.
Device Number Name Description
(1) Decimal part 0 to 5 Specifies the number of digits after a decimal point to be
specification displayed.
switch The values after the specified digits are processed with
1234567 the setting of the Rounding processing switch.
012345F 5/4
(1) (2) Floating point (F) Displays values without rounding.
(2) Rounding Round up () Adds 1 to the specified digit if the digit right after the
(3) TAX C (4)
processing specified digit is other than 0.
switch
(5) 7 8 9 Round off (5/4) Rounds off the value right after the specified digit.
Round down () Rounds down the value under the specified digits.
4 5 6
(3) Post-tax calculation key Calculates post-tax price.
1 2 3
(4) Clear key Initializes current value (previous calculation result) and
0 displayed value.
(5) Ten key 0 to 9, decimal Enters a numerical value.
point (.)
+, -, *, / Specifies the type of basic arithmetic operation.
= Executes the specified basic arithmetic operation.
■Global label
Label Name Data Type Class Assign/Initial Value/ Comment
Constant
G_eDisplayValue FLOAT [Single Precision] VAR_GLOBAL Display value
G_eLastValue FLOAT [Single Precision] VAR_GLOBAL Current value (Previous calculation result)
G_wSwitch1 Word [Signed] VAR_GLOBAL Setting value of switch (0 to 5: Number of decimal part, 6:
Floating point)
■Structure
Do not use.
Program example
(* Initialize the variables when a clear instruction is issued. *)
IF G_bClear THEN
G_eDisplayValue := 0.0;
G_eLastValue := 0.0;
G_wOperation := 0;
G_eDecimal := 0.0;
G_bClear := FALSE;
END_IF;
The values of each variable at first execution depend on the label settings or the setting of the assigned
devices.
Global labels can be used in all programs in the project.
Statements in an IF statement are executed when its conditional expression is TRUE. It is not executed when
the conditional expression is FALSE.
Variable
Define the labels by setting the following items in GX Works3.
■Global label
Label Name Data Type Class Assign/Initial Value/ Comment
Constant
G_bClear Bit VAR_GLOBAL Clear-key input
G_eDisplayValue FLOAT [Single Precision] VAR_GLOBAL Display value
G_eLastValue FLOAT [Single Precision] VAR_GLOBAL Current value (Previous calculation result)
G_wOperation Word [Signed] VAR_GLOBAL Operation type
G_eDecimal FLOAT [Single Precision] VAR_GLOBAL Initial Value: 0 Operation for decimal part
■Local label
Do not use.
POU
Do not use.
Program example
(* Add, subtract, multiply, or divide value 2 to/from value 1. *)
CASE i_wOperation OF
1: (* Operation type is addition: Operation result = Value 1 + Value 2 *)
Calculation := i_eValue1 + i_eValue2;
2: (* For subtraction *)
Calculation := i_eValue1 - i_eValue2;
3: (* For multiplication *)
Calculation := i_eValue1 * i_eValue2;
4: (* For division *)
IF i_eValue2 = 0.0 THEN (* If the value 2 is 0, do not operate. *)
Calculation := i_eValue1;
ELSE
Calculation := i_eValue1 / i_eValue2;
END_IF;
END_CASE;
8
CASE statement selects an execution statement depending on the condition of the integer value. The
statement which does not match the condition is not executed.
Selection statement (IF statement, CASE statement) can be hierarchized.
Variable
Define the labels by setting the following items in GX Works3. Result type can be set in the property of the function.
■Local label
Label Name Data Type Class Initial Value/Constant Comment
i_eValue1 FLOAT [Single Precision] VAR_INPUT Value 1
i_wOperation Word [Signed] VAR_INPUT Operation type
i_eValue2 FLOAT [Single Precision] VAR_INPUT Value 2
■Result type
Identifier Data Type Description
Calculation FLOAT [Single Precision] Operation result
POU
Do not use.
Program example
(* Round the first digit with the specified rounding method. *)
CASE i_wType OF
0: (* Round down *)
Rounding := i_dValue / 10 * 10; (* Round down the first decimal place *)
1: (* Round up *)
Rounding := (i_dValue + 9) / 10 * 10; (* Round up the first decimal place *)
2: (* Round off *)
Rounding := (i_dValue + 5) / 10 * 10; (* Round off the first decimal place *)
ELSE (* Input value is returned when the value is other than specified value. *)
Rounding := i_dValue;
END_CASE;
For the division for an integer, the values after decimal point are rounded down.
Variable
Define the labels by setting the following items in GX Works3. Result type can be set in the property of the function.
■Local label
Label Name Data Type Class Initial Value/Constant Comment
i_wType Word [Signed] VAR_INPUT Rounding method (0: Round down, 1: Round up, 2:
Round off)
i_dValue Double Word [Signed] VAR_INPUT Input value
■Result type
Identifier Data Type Description
Rounding Double Word [Signed] Operation result
POU
Do not use.
Program example
(* Round a value right after the specified decimal place. *)
(* If the specified digit is out of the range, return the input value. *)
IF (i_wDigits <= 0) OR (i_wDigits > c_wMAX) THEN
FractionProcessing := i_eValue;
RETURN; (* End processing *)
END_IF;
(* Move the decimal point in order that the specified value becomes the first place. *)
wDigits := i_wDigits + 1;
eValue := i_eValue * (10.0 ** wDigits) - 0.5;
(* Perform the specified rounding processing for the first digit of an integer value. *)
dValue := Rounding(i_wType, REAL_TO_DINT(eValue));
(* Change the value to the real number, and move the decimal point back to its original position. *)
FractionProcessing := DINT_TO_REAL(dValue) / (10.0 ** wDigits);
When converting a real number type to an integer type, use the type conversion function such as 8
REAL_TO_DINT.
The call expression of the type conversion function can be described for the terms and arguments of an
operational expression.
Variable
Define the labels by setting the following items in GX Works3. Result type can be set in the property of the function.
■Local label
Label Name Data Type Class Initial Value/Constant Comment
i_eValue FLOAT [Single Precision] VAR_INPUT Input value
i_wDigits Word [Signed] VAR_INPUT Number of decimal part to be displayed (Decimal part: 0 to 5
digits)
i_wType Word [Signed] VAR_INPUT Rounding method (0: Round down, 1: Round up, 2: Round off)
c_wMAX Word [Signed] VAR_CONSTANT Constant: 5 Maximum value of decimal place specification
wDigits Word [Signed] VAR Digits of decimal part for processing (Decimal part: 1 to 6 digits)
eValue FLOAT [Single Precision] VAR Real number value (for internal calculation)
dValue Double Word [Signed] VAR Integer value (for internal calculation)
■Result type
Identifier Data Type Description
FractionProcessing FLOAT [Single Precision] Operation result
POU
For details on the POUs used, refer to the following table.
Data name Data type Description Reference
Rounding Function Rounds down/rounds up/rounds off a variable. Page 66 Rounding Processing (FUN): Rounding
Program example
(* The processing is performed depending on the ten-key input. *)
IF G_wTenKey <> c_wNONE THEN
CASE G_wTenKey OF
0..9 : (* For number-key input (0 to 9) *)
(* Add the input numeric value to the end of the display value. *)
IF G_eDecimal = 0.0 THEN
(* For integer part *)
G_eDisplayValue := (G_eDisplayValue * 10) + G_wTenKey;
ELSE
(* For after decimal point *)
G_eDisplayValue := G_eDisplayValue + (G_eDecimal * G_wTenKey);
G_eDecimal := G_eDecimal * 0.1;
END_IF;
10: (* For input of decimal point key *)
8
G_eDecimal := 0.1;
11..14: (* For input of addition, subtraction, multiplication, or division key (11 to 14) *)
(* Retain the operation type *)
G_wOperation := G_wTenKey - 10;
(* Move the display value to the previous operation value and then reset the displayed value *)
G_eLastValue := G_eDisplayValue;
G_eDisplayValue := 0.0;
G_eDecimal := 0.0;
15: (* For equal-key input *)
(* Add, subtract, multiply, or divide the displayed value to/from the current value. *)
G_eLastValue := Calculation(G_eLastValue, G_wOperation, G_eDisplayValue);
(* Assign the rounding result to the display value. *)
G_eDisplayValue := FractionProcessing(G_eLastValue, G_wSwitch1, G_wSwitch2);
G_wOperation := 0; (* Clear the operation type *)
G_eDecimal := 0.0;
END_CASE;
(* Clear the key input *)
G_wTenKey := c_wNONE;
END_IF;
If the data type of the operators on the right side and left side differ, the data type of the operation result will be
a bigger data type. (The operation result between INT type (Word [Signed]) and REAL type (FLOAT [Single
Precision]) will be the REAL type (FLOAT [Single Precision]).)
■Global label
Label Name Data Type Class Assign/Initial Value/ Comment
Constant
G_wTenKey Word [Signed] VAR_GLOBAL Ten-key input (0 to 9: Numerical value, 10: Decimal point, 11
to 14: Basic arithmetic operation, 15: =)
G_eDecimal FLOAT [Single Precision] VAR_GLOBAL Initial Value: 0 Operation for decimal part
G_wOperation Word [Signed] VAR_GLOBAL Operation type
G_eDisplayValue FLOAT [Single Precision] VAR_GLOBAL Display value
G_eLastValue FLOAT [Single Precision] VAR_GLOBAL Current value (Previous calculation result)
G_wSwitch1 Word [Signed] VAR_GLOBAL Setting value of switch (0 to 5: Number of decimal part, 6:
Floating point)
G_wSwitch2 Word [Signed] VAR_GLOBAL Setting value of switch (0: Round down, 1: Round up, 2:
Round off)
■Local label
Label Name Data Type Class Initial Value/Constant Comment
c_wNONE Word [Signed] VAR_CONSTANT Constant: -1 No ten-key input
POU
For details on the POUs used, refer to the following table.
Data name Data type Description Reference
Calculation Function Adds, subtracts, multiplies, or divides a current value to Page 65 Basic Arithmetic Operation (FUN):
an input value. Calculation
FractionProcessing Function Calculates a value by selecting round down/round up/ Page 67 Fraction Processing (FUN):
round off at the specified decimal place. FractionProcessing
Program example
(* When a post-tax calculation instruction is issued, display the post-tax price. *)
IF G_bTax THEN
(* Calculate the amount of tax. (Calculate the values after decimal point as well.) *)
eTaxAmount := G_eDisplayValue * c_eTaxRate / 100.0;
(* Calculate the post-tax price. (Calculate the values after decimal point as well.) *)
G_eLastValue := G_eDisplayValue + eTaxAmount;
(* Set the post-tax price as a display value. (Values after decimal point are rounded off) *)
dPrice := REAL_TO_DINT(G_eLastValue);
G_eDisplayValue := DINT_TO_REAL(dPrice);
(* Clear the key input *)
G_bTax := FALSE;
END_IF;
When converting a real number type to an integer type, use the type conversion function such as 8
REAL_TO_DINT.
The data after type conversion using REAL_TO_DINT will be the value of which first decimal place is rounded
off of REAL type data.
Variable
Define the labels by setting the following items in GX Works3.
■Global label
Label Name Data Type Class Assign/Initial Value/ Comment
Constant
G_eDisplayValue FLOAT [Single Precision] VAR_GLOBAL Display value
G_eLastValue FLOAT [Single Precision] VAR_GLOBAL Current value (Previous calculation result)
G_bTax Bit VAR_GLOBAL Post-tax calculation key input
■Local label
Label Name Data Type Class Initial Value/Constant Comment
c_eTaxRate FLOAT [Single Precision] VAR_CONSTANT Constant: 8.0 Rate of tax (%)
eTaxAmount FLOAT [Single Precision] VAR Amount of tax
dPrice Double Word [Signed] VAR Post-tax price
POU
For details on the POUs used, refer to the following table.
Data name Data type Description Reference
REAL_TO_DINT Standard Converting REAL to DINT MELSEC iQ-R Programming Manual (CPU Module
function Converts a value from REAL type data to DINT type data. Instructions, Standard Functions/Function Blocks)
MELSEC iQ-F FX5 Programming Manual (Instructions,
DINT_TO_REAL Standard Converting DINT to REAL
Standard Functions/Function Blocks)
function Converts a value from DINT type data to REAL type data.
Overview of function
This function calculates the rotation angle of the arm and number of command pulses of the motor for adjusting the length of
the arm in order to move the head of the arm to the target X, Y-coordinate with the following procedure.
Y
1. Rotate the arm towards the target specified in X, Y-coordinate.
y
Target (x, y) 2. Extend the head of the arm towards the target using a stepping motor.
X
0 500.0 x
■Global label
Label Name Data Type Class Assign/Initial Value/ Comment
Constant
G_stTarget stPosition VAR_GLOBAL Target (X, Y-coordinate)
G_stArm stPosition VAR_GLOBAL Head of the arm (X, Y-coordinate)
G_eAngle FLOAT [Single Precision] VAR_GLOBAL Rotation angle (Degree)
G_ePulses FLOAT [Single Precision] VAR_GLOBAL Number of command pulses of the
motor
G_bOneScanOnly Bit VAR_GLOBAL Assign (Device/Label): Turn ON for only 1 scan after RUN
SM402
■Structure
Structure name Label Name Data Type Initial Value Comment
stPosition eXcoordinate FLOAT [Single Precision] 0.0 X-coordinate
eYcoordinate FLOAT [Single Precision] 0.0 Y-coordinate
Program example
(* Calculate radian from X, Y-coordinate, and convert the radian to degree. *)
(* If X-coordinate is 0, 90 degree (End processing without calculation.) *)
IF i_eXcoordinate = 0.0 THEN
GetAngle := 90.0;
ENO := TRUE;
RETURN; (* End processing. *)
END_IF;
(* Calculate radian from X-coordinate and Y-coordinate. *)
eAngleRad := ATAN(i_eYcoordinate / i_eXcoordinate); (* Angle (radian) rad = ATAN (Y-coordinate/X-coordinate) *)
(* Error end if the data which cannot be handled with ATAN instruction is included *)
IF SD0 = H3402 THEN (* Error code : 3402H (Operation error) *)
ENO := FALSE;
RETURN; (* End processing *)
ELSE
ENO := TRUE;
END_IF;
(* Convert radian to degree. *)
GetAngle := eAngleRad * 180.0 / c_ePi; (* Angle (degree) = Angle (radian) rad * 180/pi *)
(* If X-coordinate is negative, add 180 degree. *)
IF i_eXcoordinate < 0.0 THEN
GetAngle := GetAngle + 180.0;
END_IF;
DEG instruction can be used for the conversion from single-precision real number radian to angle.
SD0 is a device for error check. The latest error code will be stored to it.
Variable
Define the labels by setting the following items in GX Works3. Result type can be set in the property of the function.
■Local label
Label Name Data Type Class Initial Value/Constant Comment
i_eXcoordinate FLOAT [Single Precision] VAR_INPUT X-coordinate
i_eYcoordinate FLOAT [Single Precision] VAR_INPUT Y-coordinate
eAngleRad FLOAT [Single Precision] VAR Angle (radian)
c_ePi FLOAT [Single Precision] VAR_CONSTANT Constant: 3.14159 Circular constant
POU
For details on the POU used, refer to the following table.
Data name Data type Description Reference
ATAN Standard function TAN-1 operation MELSEC iQ-R Programming Manual (CPU Module Instructions, Standard Functions/Function
Outputs the arc Blocks)
tangent value (TAN-1) MELSEC iQ-F FX5 Programming Manual (Instructions, Standard Functions/Function Blocks)
of an input value.
Program example
(* Calculate distance between two points from X, Y-coordinate. *)
GetDistance := SQRT((i_stPosition0.eXcoordinate - i_stPosition1.eXcoordinate) ** 2.0
+ (i_stPosition0.eYcoordinate - i_stPosition1.eYcoordinate) ** 2.0);
Variable
Define the labels by setting the following items in GX Works3. Result type can be set in the property of the function.
■Local label
Label Name Data Type Class Initial Value/Constant Comment
i_stPosition0 stPosition VAR_INPUT Position 0 (X, Y-coordinate)
i_stPosition1 stPosition VAR_INPUT Position 1 (X, Y-coordinate)
■Result type
Identifier Data Type Description
GetDistance FLOAT [Single Precision] Distance between two points
■Structure
Structure name Label Name Data Type Initial Value Comment
stPosition eXcoordinate FLOAT [Single Precision] 0.0 X-coordinate
eYcoordinate FLOAT [Single Precision] 0.0 Y-coordinate
POU
For details on the POUs used, refer to the following table.
Data name Data type Description Reference
SQRT Standard function Square root MELSEC iQ-R Programming Manual (CPU Module Instructions, Standard Functions/Function
Outputs the square Blocks)
root of an input value. MELSEC iQ-F FX5 Programming Manual (Instructions, Standard Functions/Function Blocks)
θ
X
x
Create a POU by setting the following items in GX Works3.
Data Type Data Name Program Language Result Type EN/ENO Title
Function GetXY ST stPosition No X, Y-coordinate calculation
Program example
(* Convert the unit from degree to radian. *)
eAngleRad := i_eAngle * c_ePi / 180.0; (* Angle (radian) rad = Angle (degree) * pi/180 *)
(* Calculate X, Y-coordinate. *)
GetXY.eXcoordinate := i_eRadius * COS(eAngleRad); (* X-coordinate = Radius * COS(rad) *)
GetXY.eYcoordinate := i_eRadius * SIN(eAngleRad); (* Y-coordinate = Radius * SIN (rad) *)
Variable
Define the labels by setting the following items in GX Works3. Result type can be set in the property of the function.
■Local label
Label Name Data Type Class Initial Value/Constant Comment
i_eRadius FLOAT [Single Precision] VAR_INPUT Radius (mm)
i_eAngle FLOAT [Single Precision] VAR_INPUT Angle (degree): 0 to 180
eAngleRad FLOAT [Single Precision] VAR Angle (radian)
c_ePi FLOAT [Single Precision] VAR_CONSTANT Constant: 3.14159 Circular constant
■Result type
Identifier Data Type Description
GetXY stPosition X, Y-coordinate
■Structure
Structure name Label Name Data Type Initial Value Comment
stPosition eXcoordinate FLOAT [Single Precision] 0.0 X-coordinate
eYcoordinate FLOAT [Single Precision] 0.0 Y-coordinate
POU
For details on the POUs used, refer to the following table.
Data name Data type Description Reference
COS Standard function COS operation MELSEC iQ-R Programming Manual (CPU Module
Outputs COS (cosine) of an input value. Instructions, Standard Functions/Function Blocks)
MELSEC iQ-F FX5 Programming Manual (Instructions,
SIN Standard function SIN operation
Standard Functions/Function Blocks)
Outputs SIN (sine) of an input value.
Program example
(* Calculate the number of command pulses. *)
IF e1round <> 0.0 THEN
(* Number of command pulses = Motor resolution*(Target movement amount/Movement amount for one motor rotation) *)
o_ePulses := eResolution * ( i_eDistance / e1round );
END_IF;
Variable
Define the labels by setting the following items in GX Works3.
■Local label
Label Name Data Type Class Initial Value/Constant Comment
i_eDistance FLOAT [Single Precision] VAR_INPUT Target movement amount (mm)
o_ePulses FLOAT [Single Precision] VAR_OUTPUT Number of command pulses of motor (pulse)
e1round FLOAT [Single Precision] VAR Movement amount for one motor rotation (mm/rev)
eResolution FLOAT [Single Precision] VAR Motor resolution (Pulse/rev)
Set the initial values to the e1round and the eResolution in the local label setting in the used-side program.
Page 78 Local label
The setting for initial values of labels does not exist for the MELSEC iQ-F series; therefore, set the initial
values by using a program or a watch window of an engineering tool.
POU
Do not use.
Program example
(* Calculate the rotation angle and number of command pulses of the motor for adjusting the length of the arm in order to
move the head of the arm to the target X, Y-coordinate. *)
(* Set the initial value to the coordinate of the arm only at the first time after RUN. *)
IF G_bOneScanOnly THEN
G_stArm.eXcoordinate := 500.0;
G_stArm.eYcoordinate := 0.0;
END_IF;
(* The position of the target will be set to the global variable, G_stTarget in other program. [The program is omitted in this
program example.] *)
(* Calculate the moving angle of the arm for the target X, Y-Coordinate. *)
eTargetAngle := GetAngle( TRUE, bResult1, G_stTarget.eXcoordinate, G_stTarget.eYcoordinate );
eArmAngle := GetAngle( bResult1, bResult2, G_stArm.eXcoordinate, G_stArm.eYcoordinate );
IF bResult2 THEN
G_eAngle := eTargetAngle - eArmAngle;
ELSE
RETURN; (* Error end *)
END_IF;
(* Calculate the current length of the arm (distance from origin) from the X, Y-coordinate of the head of the arm. *)
eDistance := GetDistance( G_stArm, stOrigin ); (* Input variable is a function call of structure *)
(* Calculate the X, Y-coordinate of the head of the arm after the rotation. *)
G_stArm := GetXY( eDistance, G_eAngle); (* Return value is a function call of structure *)
(* Calculate the distance between two points from the X, Y-coordinate of the target and head of the arm. *)
eDistance := GetDistance( G_stTarget, G_stArm );
(* Calculate the number of command pulses to the motor for adjusting the length of the arm from the movement amount. *)
PulseNumberCalculation_1(i_eDistance := eDistance, o_ePulses => G_ePulses ); (* Function block call *)
(* Rotate the arm by specifying the angle. [The program is omitted in this program example.] *)
(* Stretch the head of the arm by specifying the number of command pulses of the motor. [The program is omitted in this
program example.] *)
(* Update the coordinate of the arm. *)
G_stArm := G_stTarget;
When creating a function and function block, whether or not to use an EN and ENO can be selected.
If FALSE is specified to EN, the processing is not executed. ENO becomes FALSE.
Specify the output valuable using '=>' for a function block instance.
■Global label
Label Name Data Type Class Assign/Initial Value/ Comment
Constant
G_bOneScanOnly Bit VAR_GLOBAL Assign (Device/Label): Turn ON for only 1 scan after RUN
SM402
G_stTarget stPosition VAR_GLOBAL Target (X, Y-coordinate)
G_stArm stPosition VAR_GLOBAL Head of arm (X, Y-coordinate)
G_eAngle FLOAT [Single Precision] VAR_GLOBAL Rotation angle (degree)
G_ePulses FLOAT [Single Precision] VAR_GLOBAL Number of command pulses of motor
(pulse)
■Local label
Label Name Data Type Class Initial Value/Constant Comment
eTargetAngle FLOAT [Single Precision] VAR Angle to the target (degree): 0 to 180
eArmAngle FLOAT [Single Precision] VAR Angle of arm (degree): 0 to 180
bResult1 Bit VAR Operation result 1
bResult2 Bit VAR Operation result 2
stOrigin stPosition VAR Origin (X, Y-coordinate = 0. 0)
eDistance FLOAT [Single Precision] VAR Distance
PulseNumberCalculation_1 PulseNumberCalculation VAR Initial Value Calculation of number of command pulses
• e1round: 0.2
• eResolution: 3000.0
The setting for initial values of labels does not exist for the MELSEC iQ-F series; therefore, set the initial
values by using a program or a watch window of an engineering tool.
■Structure
Structure name Label Name Data Type Initial Value Comment
stPosition eXcoordinate FLOAT [Single Precision] 0.0 X-coordinate
eYcoordinate FLOAT [Single Precision] 0.0 Y-coordinate
In GX Works3, initial values can be set for each internal variable of function block instances.
To initialize structure type variables, set the initial values to the structure definition or create an initialization
program. For a global label, initial values can be set to the devices to be assigned.
POU
For details on the POU used, refer to the following table.
Data name Data type Description Reference
GetAngle Function Calculates angle for the target X, Y-coordinate. Page 73 Rotation Angle Calculation (FUN):
GetAngle
GetXY Function Calculates X, Y-coordinate from radius and angle. Page 75 X, Y-Coordinate Calculation (FUN):
GetXY
GetDistance Function Calculates distance between two points from X, Y- Page 74 Distance Calculation (FUN):
coordinate. GetDistance
PulseNumberCalculation Function block Calculates number of command pulses to a motor Page 76 Command Pulse Calculation (FB):
from the movement amount. PulseNumberCalculation
Overview of function
This function sorts product data into non-defectives and defectives by checking the data of the multiple products of which
sizes and weights are measured.
1. Measure the product.
Measurement
Product: 0 1 2 Measured value 0
This program example processes the data of two measured
Measured value 1 values for eight products. Store the arbitrary value for the
measured value for the G_eValueArray (Measured values of
all products).
2. Check the measured values for each product.
Check the measured values of each product
• Non-defective product: A product of which all measured
Measured values of all Acceptable range
products 1.0±0.5 100.0±1.0 values are within the allowable range.
Measured Measured
value 0 value 1 [0] [1] • Defective product: A product of which measured value is
Product [0,0] [0,1] 1.0 100.0 OK
number: 0 1.0 100.0 out of the allowable range.
Product [1,0] [1,1]
number: 1 0.5 98.7 0.5 98.7 NG
Product [2,0] [2,1]
number: 2 1.2 100.5 1.2 100.5 OK
[3,0] [3,1]
0.9 99.8
[0] [1]
3. Sort the product data into non-defectives and
defectives.
Product 0 2
Product data
(non-defective
number
[0] [1] [0] [1] 4. After checking all the products, acquire the data of non-
product) Measured 1.0 100.0 1.2 100.5 defective products and defective products.
value
[0] [1]
Product 1
Product data number
(defective [0] [1] [0] [1]
product) Measured 0.5 98.7
value
■Global label
Label Name Data Type Class Assign/Initial Value/ Comment
Constant
G_eValueArray FLOAT [Single VAR_GLOBAL Measured values for all products
Precision](0..7,0..1) (Values are stored in order of product
number.)
■Structure
Structure name Label Name Data Type Initial Value Comment
stProduct wProductNumber Word [Signed] Product number
eValueArray FLOAT [Single Measured value
Precision](0..1)
Program example
(* Check if the values of each element in the array are within the allowable range. *)
FOR wIndex := 0 TO (i_wValueNumber - 1) BY 1 DO
(* Calculate the upper and lower limit from the standard value and tolerance. *)
eMaxValue := i_eAcceptableArray[wIndex, c_wBasicSize] + i_eAcceptableArray[wIndex, c_wTolerance];
eMinValue := i_eAcceptableArray[wIndex, c_wBasicSize] - i_eAcceptableArray[wIndex, c_wTolerance];
(* Check the upper and lower limit. *)
IF (eMaxValue >= i_eValueArray[wIndex]) AND (eMinValue <= i_eValueArray[wIndex]) THEN
o_bResult := TRUE;
ELSE
o_bResult := FALSE;
EXIT; (* End processing when the value out of the range exists. *)
END_IF;
END_FOR;
The same data processing can be performed for the multiple elements of array by combining array type data
and iteration statement.
Specify the elements of each array using an operational expression as a variable of the defined data type.
Selection statement (IF statement, CASE statement) and iteration statement (FOR statement, WHILE
statement, REPEAT statement) can be hierarchized.
Variable
Define the labels by setting the following items in GX Works3.
■Local label
Label Name Data Type Class Initial Value/Constant Comment
i_eValueArray FLOAT [Single VAR_INPUT Judgment value
Precision](0..1)
i_eAcceptableArray FLOAT [Single VAR_INPUT Allowable range
Precision](0..1,0..1)
i_wValueNumber Word [Signed] VAR_INPUT Number of measured values for one product
o_bResult Bit VAR_OUTPUT Check result
POU
Do not use.
Program example
(* Sort the product data into non-defectives and defectives depending on the check result. *)
IF i_bCheck THEN
(* Non-defective product *)
(* Store the measured value to the Product data (non-defective product). *)
o_stProductArray[wTotal] := i_stProduct;
(* Increment the number of non-defective products *)
wTotal := wTotal + 1;
ELSE
(* Defective product *)
(* Store the measured value to the Product data (defective product). *)
o_stDefectiveArray[wDefectiveTotal] := i_stProduct;
(* Increment the number of defective products *)
wDefectiveTotal := wDefectiveTotal + 1;
END_IF;
(* Update yield rate *)
o_eYieldRatio := INT_TO_REAL(wTotal) / INT_TO_REAL(wTotal + wDefectiveTotal);
The structure which includes array in a member and array of structure type can be used in ST programs.
Variable
Define the labels by setting the following items in GX Works3.
■Local label
Label Name Data Type Class Initial Value/Constant Comment
i_bCheck Bit VAR_INPUT Check result
i_stProduct stProduct VAR_INPUT Checked product data
o_stProductArray stProduct(0..7) VAR_OUTPUT Product data (non-defective product)
o_stDefectiveArray stProduct(0..7) VAR_OUTPUT Product data (defective product)
o_eYieldRatio FLOAT [Single Precision] VAR_OUTPUT Yield rate
wTotal Word [Signed] VAR Number of non-defective products
wDefectiveTotal Word [Signed] VAR Number of defective products
■Structure
Structure name Label Name Data Type Initial Value Comment
stProduct wProductNumber Word [Signed] Product number
eValueArray FLOAT [Single Precision](0..1) Measured value
POU
For details on the POU used, refer to the following table.
Data name Data type Description Reference
INT_TO_REAL Standard Convert of INT type REAL MELSEC iQ-R Programming Manual (CPU Module Instructions, Standard Functions/
function Converts a value from INT Function Blocks)
type data to REAL type data. MELSEC iQ-F FX5 Programming Manual (Instructions, Standard Functions/Function Blocks)
Different initial values cannot be set for each element of an array. Set the different values by a program.
For a function block, arguments can be specified before and after the call statement.
Selection statement (IF statement, CASE statement) and iteration statement (FOR statement, WHILE
statement, REPEAT statement) can be hierarchized.
■Global label
Label Name Data Type Class Assign/Initial Value/ Comment
Constant
G_eValueArray FLOAT [Single VAR_GLOBAL Measured values for all products
Precision](0..7,0..1) (Values are stored in order of product
number.)
GC_wValueNumber Word [Signed] VAR_GLOBAL_CONSTANT Constant: 2 Number of measured values for one
product
GC_wTotalProduct Word [Signed] VAR_GLOBAL_CONSTANT Constant: 8 Total number of products
G_stProductArray stProduct(0..7) VAR_GLOBAL Product data (non-defective product)
G_stDefectiveArray stProduct(0..7) VAR_GLOBAL Product data (defective product)
■Local label
Label Name Data Type Class Initial Value/Constant Comment
wProductNumber Word [Signed] VAR Product number (for internal iterative
processing)
wDataEnd Word [Signed] VAR Data termination (for internal iterative
processing)
wIndex Word [Signed] VAR Element number (for internal iterative
processing)
eValueArray FLOAT [Single VAR Measured value
Precision](0..1)
bResult Bit VAR Checking result (for internal iterative
processing)
stProductData stProduct VAR Checked product data
c_eLimit FLOAT [Single Precision] VAR_CONSTANT Constant: 0.8 Allowable yield rate
Check_1 ProductCheck VAR Product check processing
Assortment_1 Assortment VAR Sorting processing for product data
■Structure
Structure name Label Name Data Type Initial Value Comment
stProduct wProductNumber Word [Signed] Product number
eValueArray FLOAT [Single Measured value
Precision](0..1)
POU
For details on the POUs used, refer to the following table.
Data name Data type Description Reference
ProductCheck Function block Judges the products as non-defective or defective Page 80 Product Check (FB): ProductCheck
from the product data.
Assortment Function block Sorts product data into non-defectives and Page 82 Sorting Product Data (FB): Assortment
defectives.
Overview of function
The following processing are performed.
2. The lamp is turned ON/OFF by judging the status of device from the operation status and operating time.
■Global label
Label Name Data Type Class Assign/Initial Value/ Description
Constant
G_bOperatingStatus Bit VAR_GLOBAL Operation status (TRUE: Operating,
FALSE: Stopped)
G_tmTime Time VAR_GLOBAL Total operating time (Up to
T#24d20h31m23s647ms)
G_bOperationLamp Bit VAR_GLOBAL Operation lamp (TRUE: ON, FALSE: OFF)
G_bWarningLamp Bit VAR_GLOBAL Warning lamp (TRUE: ON, FALSE: OFF)
G_dSeconds Double Word [Signed] VAR_GLOBAL Operating time (0 to 86399 seconds)
G_wTimeArray Word [Signed](0..2) VAR_GLOBAL Operating time ([0]: Hour, [1]: Minute, [2]:
Second)
G_sDisplayedCharacters String(32) VAR_GLOBAL Characters to be displayed on the
operating time display screen
G_bOneScanOnly Bit VAR_GLOBAL Assign (Device/Label): SM402 Turn ON for only 1 scan after RUN
■Structure
Do not use.
Program example
(* Count the operating time for each one second. *)
bResult := OUT_T(G_bOperatingStatus, td1sTimer, 10); (* Timer setting value: 1000 ms *)
IF td1sTimer.S THEN (* After one second *)
(* Operating time (Timer type) count up *)
G_tmTime := G_tmTime + T#1000ms;
IF G_tmTime < T#0ms THEN (* If an overflow occurred *)
G_tmTime := T#0ms; (* Clear to 0 *)
END_IF;
(* Operating time (second unit) count up *)
G_dSeconds := G_dSeconds +1;
IF G_dSeconds >= 86400 THEN
G_dSeconds := 0; (* Clear to 0 if the time is reached at 24 hours *)
END_IF;
(* Reset the timer (Current value: 0, Contact: OFF) *)
RST(TRUE, td1sTimer.N);
RST(TRUE, td1sTimer.S);
END_IF;
Variable
Define the labels by setting the following items in GX Works3.
■Global label
Label Name Data Type Class Assign/Initial Value/ Description
Constant
G_bOperatingStatus Bit VAR_GLOBAL Operation status (TRUE: Operating,
FALSE: Stopped)
G_tmTime Time VAR_GLOBAL Total operating time (Up to
T#24d20h31m23s647ms)
G_dSeconds Double Word [Signed] VAR_GLOBAL Operating time (0 to 86399 seconds)
■Local label
Label Name Data Type Class Initial Value/Constant Description
bResult Bit VAR ENO for executing timer
td1sTimer Timer VAR Timer for measuring one second
POU
For details on the POU used, refer to the following table.
Data name Data type Description Reference
OUT_T Instruction Low-speed timer instruction MELSEC iQ-R Programming Manual (CPU Module
Starts time measurement when the operation result Instructions, Standard Functions/Function Blocks)
up to the OUT instruction is ON and the coil is turned MELSEC iQ-F FX5 Programming Manual (Instructions,
ON. Standard Functions/Function Blocks)
Program example
11
(* Flash the Output signal 0 and 1 alternately. (Flip-flop circuit) *)
(* Calculate the setting value for the low-speed timer. *)
wInterval := TIME_TO_INT(i_tmInterval) / 100;
(* If the Timer 1 is OFF, turn the Timer 0 ON after the set time (ms). *)
bResult := OUT_T(NOT tdTimer1.S, tdTimer0, wInterval);
(* If the Timer 0 is turned ON from OFF, turn the Timer 1 ON after the set time (ms). *)
bResult := OUT_T(tdTimer0.S, tdTimer1, wInterval);
(* If the Timer 0 is ON, turn ON the Output signal 0. *)
o_bOutputSignal0 := tdTimer0.S;
(* If the Timer 0 is OFF, turn ON the Output signal 1. *)
o_bOutputSignal1 := NOT tdTimer0.S;
The setting value for a timer needs to be equal to or more than the total value of scan time and timer limit
setting. The timer limit is set as follows:
• MELSEC iQ-R: Set it in the parameter of an engineering tool. (Default: 100 ms)
• MELSEC iQ-F: The OUT_T instruction operates as a timer of 100 ms, the OUTH instruction as a timer of 10
ms, and the OUTHS instruction as a timer of 1 ms.
Variable
Define the labels by setting the following items in GX Works3.
■Local label
Label Name Data Type Class Initial Value/Constant Description
i_tmInterval Time VAR_INPUT Switching interval
o_bOutputSignal0 Bit VAR_OUTPUT Initial Value: TRUE Output signal 0
o_bOutputSignal1 Bit VAR_OUTPUT Initial Value: TRUE Output signal 1
bResult Bit VAR ENO for executing timer
wInterval Word [Signed] VAR Low-speed timer setting value
tdTimer0 Timer VAR Timer 0
tdTimer1 Timer VAR Timer 1
POU
For details on the POUs used, refer to the following table.
Data name Data type Description Reference
OUT_T Instruction Low-speed timer instruction MELSEC iQ-R Programming Manual (CPU Module
Starts time measurement when the operation result Instructions, Standard Functions/Function Blocks)
up to the OUT instruction is ON and the coil is turned MELSEC iQ-F FX5 Programming Manual (Instructions,
ON. Standard Functions/Function Blocks)
TIME_TO_INT Standard function Conversion of TIME type INT type
Converts a value from TIME type data to INT type
data.
Program example
(* Turn the operation lamp ON/OFF according to the operation state. *)
G_bOperationLamp := G_bOperatingStatus;
(* Turn the warning lamp ON if the total operating time is one week (seven days) or more. *)
G_bWarningLamp := G_tmTime >= T#7d;
(* If the operating time is three weeks (21 days) or more *)
(* Turn the operation lamp and warning lamp alternately. *)
FlickerTimer_1(EN := G_tmTime >= T#21d, i_tmInterval := T#1000ms);
IF FlickerTimer_1.ENO THEN
G_bOperationLamp := FlickerTimer_1.o_bOutputSignal0;
G_bWarningLamp := FlickerTimer_1.o_bOutputSignal1;
END_IF;
Variable
Define the labels by setting the following items in GX Works3.
■Global label
Label Name Data Type Class Assign/Initial Value/ Description
Constant
G_bOperatingStatus Bit VAR_GLOBAL Operation status (TRUE: Operating,
FALSE: Stopped)
G_bOperationLamp Bit VAR_GLOBAL Operation lamp (TRUE: ON, FALSE:
OFF)
G_bWarningLamp Bit VAR_GLOBAL Warning lamp (TRUE: ON, FALSE: OFF)
G_tmTime Time VAR_GLOBAL Total operating time (up to
T#24d20h31m23s647ms)
■Local label
Label Name Data Type Class Initial Value/ Description
Constant
FlickerTimer_1 FlickerTimer VAR Flicker timer
POU
For details on the POU used, refer to the following table.
Data name Data type Description Reference
FlickerTimer Function block Flashes the output signals alternately. Page 87 Flicker Timer (FB): FlickerTimer
Data range
Time (second unit) [0] Hour (0 to 23)
11
Data range
(0 to 86399) [1] Minute (0 to 59)
[2] Second (0 to 59)
Program example
(* Calculate hour, minute, second from the time in second unit. *)
G_wTimeArray[0] := GET_INT_ADDR( G_dSeconds / 3600); (* Hour *)
G_wTimeArray[1] := GET_INT_ADDR((G_dSeconds MOD 3600) / 60); (* Minute *)
G_wTimeArray[2] := GET_INT_ADDR((G_dSeconds MOD 3600) MOD 60); (* Second *)
Variable
Define the labels by setting the following items in GX Works3.
■Global label
Label Name Data Type Class Assign/Initial Value/ Description
Constant
G_dSeconds Double Word [Signed] VAR_GLOBAL Operating time (0 to 86399 seconds)
G_wTimeArray Word [Signed](0..2) VAR_GLOBAL Operating time ([0]: Hour, [1]: Minute,
[2]: Second)
■Local label
Do not use.
POU
For details on the POU used, refer to the following table.
Data name Data type Description Reference
GET_INT_ADDR Standard function Eliminate the need for type conversion MELSEC iQ-R Programming Manual (CPU Module Instructions,
Outputs the input variable as INT type. Standard Functions/Function Blocks)
MELSEC iQ-F FX5 Programming Manual (Instructions, Standard
Functions/Function Blocks)
Program example
(* Convert the operating time to character string for display. *)
(* Initialize the internal variable. *)
IF G_bOneScanOnly THEN (* Execute only once after RUN *)
(* Initialize time unit (day, hour, minute, second in milliseconds). *)
dUnitArray[0] := TIME_TO_DINT(T#1d); (* Day *)
dUnitArray[1] := TIME_TO_DINT(T#1h); (* Hour *)
dUnitArray[2] := TIME_TO_DINT(T#1m); (* Minute *)
dUnitArray[3] := TIME_TO_DINT(T#1s); (* Second *)
(* Specify the digit of numeric value to be converted to a character string. *)
wDigitArray[0] := 3; (* Convert to 2-digit numeric value. (Specify the total number of digits including a sign to 3.) *)
wDigitArray[1] := 0; (* No decimal point *)
END_IF;
sTimeString := ''; (* Initialize character string. *)
(* Convert the time type data to milliseconds. *)
dTime := TIME_TO_DINT(G_tmTime);
(* Processing the day, hour, minute, second in this order. *)
FOR wIndex := 0 TO 3 BY 1 DO
(* Convert the time (in milliseconds) to day/hour/minute/second. *)
wTime := DINT_TO_INT(dTime /dUnitArray[wIndex]);
dTime := dTime MOD dUnitArray[wIndex];
(* Convert the value of day/hour/minute/second to character string with 2-digit numeric value. *)
STR(TRUE, wDigitArray, wTime, sItemString); (* Convert to 3 characters including a sign. *)
sItemString := DELETE(sItemString, 1, 1); (* Delete a sign in the first character. *)
(* Set the character string to be added. *)
CASE wIndex OF
0 : sAdd := '$"Day ';
1 : sAdd := ' Time ';
2,3:sAdd := ':';
END_CASE;
(* Add a character string. *)
sTimeString := CONCAT(sTimeString, sAdd, sItemString);
END_FOR;
(* Add a character string at the end. *)
sTimeString := CONCAT(sTimeString, '$"');
(* Set the created character string to the display character string. *)
G_sDisplayedCharacters := sTimeString;
Variable
Define the labels by setting the following items in GX Works3.
■Global label 11
Label Name Data Type Class Assign/Initial Value/ Description
Constant
G_tmTime Time VAR_GLOBAL Total operating time (Up to
T#24d20h31m23s647ms)
G_bOneScanOnly Bit VAR_GLOBAL Assign (Device/Label): Turn ON for only 1 scan after RUN
SM402
G_sDisplayedCharacters String(32) VAR_GLOBAL Characters to be displayed on the
operating time display screen
■Local label
Label Name Data Type Class Initial Value/ Description
Constant
dUnitArray Double Word [Signed](0..3) VAR Unit (day, hour, minute, second in
milliseconds)
wDigitArray Word [Signed](0..1) VAR Digit specification ([0]: Number of all digits,
[1]: Number of decimal place)
sTimeString String(32) VAR Character string to be created (Day, hour,
minute, second)
dTime Double Word [Signed] VAR Time (in milliseconds)
wIndex Word [Signed] VAR Element number
wTime Word [Signed] VAR Time (Day/hour/minute/second)
sItemString String(32) VAR Character string of 2-digit numeric value for
day/time/minute/second
sAdd String(32) VAR Character string to be added
POU
For details on the POUs used, refer to the following table.
Data name Data type Description Reference
TIME_TO_DINT Standard function Conversion of TIME type DINT type MELSEC iQ-R Programming Manual (CPU
Converts a value from TIME type data to DINT type data. Module Instructions, Standard Functions/
Function Blocks)
DINT_TO_INT Standard function Conversion of DINT type INT type
MELSEC iQ-F FX5 Programming Manual
Converts a value from DINT type data to INT type data.
(Instructions, Standard Functions/Function
STR Instruction Converts 16-bit binary data to character string by adding a Blocks)
decimal point to the specified place of the data.
CONCAT Standard function Concatenation of string data
Concatenates character strings and outputs the result.
Statement
The following shows the types of statement and their description method.
Type Description method Description
Assignment statement An evaluation result of the right side is assigned to the
<Variable> := <Expression> ; variable of the left side.
Subprogram Call statement <Identifier>(argument 1, argument 2, ...) A function or function block is called.
control
RETURN RETURN; A program is ended.
statement
statement
Control Selection IF An execution statement is selected depending on the
statement statement IF <Condition 1> THEN condition of the boolean value.
<Statement 1>; If the Condition 1 is TRUE, the Statement 1 is executed.
Miltiple ELSIFs If the Condition 1 is FALSE, the condition of ELSIF is
ELSIF <Condition 2> THEN (in the line frame)
<Statement 2>; judged. If the Condition 2 is TRUE, the Statement 2 is
are allowable.
executed.
ELSE ELSIF, ELSE If the conditions both IF and ELSIF are FALSE, the
<Statement 3>; (in the dashed-line Statement 3 after ELSE is executed.
frame) are omittable.
END_IF;
END_FOR;
APPX
92 Appendix 1 Specifications of Structured Text language
Hierarchization of functions and function blocks can be performed up to 32 times in total.
Hierarchization of IF statement, CASE statement, WHILE statement, and REPEAT statement can be
performed up to 128 times in total.
Operator
The following shows the types of operators and their description method.
Type Operator Priority Example
(High to low) Generic mathematical ST
expression
Inversion of sign - 1 B=-A eValueB := - eValueA;
Logical operation NOT operation NOT B=A bFlagB := NOT bFlagA;
Exponentiation ** 2 B = CA eValueB := eValueC ** eValueA;
Basic arithmetic Multiplication * 3 AB=C eValueC := eValueA * eValueB;
expression
Division / A B = C ... D eValueC := eValueA / eValueB;
Modulus operation MOD eValueC := eValueA MOD eValueB;
Addition + 4 A+B=C eValueC := eValueA + eValueB;
Subtraction - A-B=C eValueC := eValueA - eValueB;
Comparison Greater that, less than >, < 5 A>B bFlag := eValueA > eValueB;
operation
Greater than or equal to, >=, <= AB bFlag := eValueA <= eValueB;
less than or equal to
Equality = 6 A=B bFlag := eValueA = eValueB;
Inequality <> AB bFlag := eValueA <> eValueB;
Logical operation AND operation AND, & 7 AB bFlag := eValueA AND eValueB;
XOR operation XOR 8 A B bFlag := eValueA XOR eValueB;
OR operation OR 9 A B bFlag := eValueA OR eValueB;
A
Up to 1024 operators can be described in one expression.
Priority
When multiple operational expressions are described in one statement, the operations are processed in order from a high
priority operator.
When some operators of which priority is the same are used in one statement, the operators are operated in order from the
left.
The operational expression in the brackets '()' is operated first.
Comment
The following shows the types of comments and their description method.
Type Symbol Description Example
Multiple line comment (* *) The range from start symbol to end (* Comment *)
/* */ symbol is regarded as a comment. /* Comment */
Single line comment // The range from start symbol to end of // Comment
the line is regarded as a comment.
A comment symbol for the Structured Text language defined in IEC 61131-3 is (**) only, however, in GX
Works3, the same symbols as C language (/**/, //) can be described.
In GX Works2, the comment used (**) can only be used.
APPX
Appendix 1 Specifications of Structured Text language 93
Device
Devices can be specified in the same manner as a ladder program. Add # when specifying local devices.
Device specification (digit specification, bit specification, and indirect specification) and index modification can be used.
A device type specifier cannot be added to digit-specified devices or indirectly specified devices.
Ex.
32-bit binary data transfer instruction (DMOV) (Instruction of which input argument and output argument are both ANY32
type)
• D0 = 16#ABCD
• D1 = 16#1234
APPX
94 Appendix 1 Specifications of Structured Text language
• Word [Signed] type label, G_wLabel to which D0 is assigned
ST Description Value to be
transferred
bResult := DMOV(TRUE, D0, D10); The 32-bit data stored to D0 and D1 are transferred to D10 and D11. 16#1234ABCD
bResult := DMOV(TRUE, D0:UD, D10:UD);
bResult := DMOV(TRUE, D0:U, D10); The integer value of Word [Unsigned]/Bit String [16-bit] type stored to D0 is converted 16#0000ABCD
to Double Word [Signed] type automatically, and the zero-extended value is transferred
to D10 and D11.
bResult := DMOV(TRUE, G_wLebel, D10); The integer value of Word [Signed] type stored to D0 is converted to Double Word 16#FFFFABCD
[Signed] type automatically, and the sing-extended value is transferred to D10 and D11.
bResult := DMOV(TRUE, D0:U, D10:U); A conversion error occurs in D10:U since the output variable cannot be converted
automatically.
When using a word device with no type specification in an operational expression, the data type is converted from Word
[Signed] automatically.
Page 30 Data type that can be converted automatically
APPX
Appendix 1 Specifications of Structured Text language 95
Label
Specify labels in the same manner as a ladder program.
Bit specification (example: Lbl.3) and digit specification (example: K4Lbl) of labels can be used.
APPX
96 Appendix 1 Specifications of Structured Text language
Constant
The following shows the description method of constant.
Type Notation Example Example with '_'
added *1
Boolean value Describe a boolean value with TRUE or FALSE. TRUE, FALSE
Specify the value with 1 or 0. Each notation for integer can be applied. 2#0, 8#1, 0, H1
Integer Binary Add '2#' in front of a binary number. 2#0010, 2#01101010 2#111_1111_1111_1111
Octal Add '8#' in front of an octal number. 8#2, 8#152, 8#377 8#7_7777
Decimal Enter a decimal number directly. 2, 106, -1 32_767
Add 'K' in front of a decimal number. K2, K106, K-1 *2
Hexadecimal Add '16#' in front of a hexadecimal number. 16#2, 16#6A, 16#FF 16#7F_FF
Add 'H' in front of a hexadecimal number. H2, H6A, HFF *2
Real Decimal Enter a real number directly. 1200.0, 0.012, -0.1 3.14_159
number notation
Add 'E' in front of a real number. E1200, E0.012, E-0.1 *2
Exponential Add 'E' between the mantissa part and the exponent. 1.2E3, 1.2E-2, -1.0E-1 2.99_792_458E8
notation 'mEn' indicates that multiplying mantissa part 'm' by the nth power of 10.
Add 'E' in front of the mantissa part, and add '+' or '-' between the E1.2+3, E1.2-2, E-1.0- *2
mantissa part and the exponent. 1
'Em+n' indicates that multiplying mantissa part 'm' by the nth power of
10.*3
Character ASCII Enclose a character string in single quotes ('). 'ABC'
string Shift-JIS
Unicode Enclose a character string in double quotes ("). "ABC"
Time Add 'T#' or 'TIME#' in front of a value. T#1h, T#1d2h3m4s5ms, TIME#1h
*1 In the notation of integer and real numbers, the numbers can be delimited using an underscore '_' to make programs easy to see. And,
the delimiters of values (underscore '_') are ignored in the program processing.
*2 For the notation with K, H, or E added in front, underscores (_) cannot be used.
*3 By adding '+' or '-' right after the value for the real number with 'E' added, it is regarded as an index.
When describing it as an arithmetic operation, insert a space or tabulator between the value and operator. A
(Example: 'E1.2+3' indicates 1200.0, and 'E1.2 +3' indicates 4.2.)
*1 'WORD#' and 'DWORD#' cannot be used for the operands of basic arithmetic operations (target values of operations), the call
statements of functions and function blocks, and the ANY_NUM type arguments in function call expressions, . Use 'UINT#' or 'UDINT#'
instead.
APPX
Appendix 1 Specifications of Structured Text language 97
Using '$' in a character string type constant
When specifying linefeed using a character string type constant, add '$'.
Type Notation
Dollar sign ($) $$, $24
Single quote (') $', $27
Double quote (") $", $22
Line feed $L, $l, $0A
Newline $N, $n, $0D $0A
Form feed (page) $P, $p, $0C
Carriage Return $R, $r, $0D
Tabulator $T, $t, $09
Character corresponding to ASCII code $[ASCII code (2-digits of hexadecimal value)]
■Setting range
When using a sign (-) or omitting time units that are placed before ones to be described, the range of values that can be
described is as follows:
Time unit d (day) h (hour) m (minute) s (second) ms (millisecond)
No omission -24 to 24 0 to 23 0 to 59 0 to 59 0 to 999
'd' omitted -596 to 596 0 to 59 0 to 59 0 to 999
'd' and 'h' omitted -35791 to 35791 0 to 59 0 to 999
'd', 'h', and 'm' omitted -2147483 to 2147483 0 to 999
'd', 'h', 'm', and 's' -2147483648 to 2147483647
omitted
The time length can be set to the time type variable (Page 33 Time type variable) in the following range.
• T#-24d20h31m23s648ms to T#24d20h31m23s647ms
• T#-596h31m23s648ms to T#596h31m23s647ms
• T#-35791m23s648ms to T#35791m23s647ms
• T#-2147483s648ms to T#2147483s647ms
• T#-2147483648ms to T#2147483647ms
APPX
98 Appendix 1 Specifications of Structured Text language
Function and function block
Function and function block are the POUs in which a subroutine to be called from a program is defined.
The defined function can be used in a program block, function block, and other functions.
The defined function block can be used in the program block and other function blocks by creating an instance.
Argument
The following shows the description method of arguments in a call statement.
Actual argument of execution result Actual argument of execution result Actual argument of input Actual argument of output
(expression of input value) (variable to which the result is to be substituted) (expression of input value) (variable to which the result is to be substituted)
The order of the arguments will be the order defined in the local label setting of function definition or function block definition.
When function or function block is created with the setting to use EN/ENO, specify EN for the first argument and ENO for the
second one.
Formal Actual argument Formal Actual argument Formal argument Actual argument Formal argument Actual argument
argument (expression of argument (variable to which the (expression of input value) (variable to which the
input value) result is to be substituted) result is to be substituted)
Execution statement Execution result Input argument Output argument
A
The names of formal arguments will be the variable names specified in the local label setting of function definition or function
block definition.
Specify 'EN' and 'ENO' as formal arguments for EN and ENO.
When assigning the actual argument to the formal argument, use the following format.
• Input argument, input/output argument and EN: '<Formal argument name>:=<Expression>'
• Output argument and ENO: '<Formal argument name>=><Variable>'
When assigning the actual argument to the formal argument, the order of the arguments can be changed arbitrary.
When specifying the argument by assigning the actual argument to the formal argument, the description of the
argument can be omitted.
APPX
Appendix 1 Specifications of Structured Text language 99
Return value
A function which has a return value returns the value to the call source after the completion of the execution.
Program example
The sum from i_wValue0 to i_wValue2 (input argument) are returned as a return value of FunAdd (function).
ST (Program of function, FunAdd)
FunAdd := wValue0 + wValue1 + wValue2;
Program example
The average from wValue0 to wValue2 are assigned to Average3.
FunAdd (function) returns the sum of wValue0 to wValue2 (input argument) as a return value.
ST (Call source program)
Average3 := FunAdd( wValue0 , wValue1, wValue2) / 3;
EN and ENO
When creating a function and function block, whether or not to use an EN and ENO can be selected.
By using an EN (enable input) and ENO (enable output), the execution processing can be controlled.
• EN: Set the execution condition.
• ENO: Execution result is output.
EN/ENO is boolean type.
A function or function block with an EN is executed only when the execution condition of the EN is TRUE.
The following shows the values of output variable and return value depending on the state of EN and ENO.
EN ENO Output variable, returned value Remarks
TRUE TRUE Operation output value Normal completion
FALSE Undefined value Undefined value is returned when FALSE is assigned to the ENO during
processing.
The output value depends on the actual system.
FALSE FALSE • Function: Value at call The processing is ended without execution.
• Function block: Previous result Assignment of value to the input variable and output variable are not executed.
Program example
If an operation error occurs in the BCD instruction, the processing of function/function block is terminated and resulted in error
end.
ST (Program of function/function block)
ENO := BCD(EN, wValue0, D0);
IF ENO = FALSE THEN
RETURN;
END_IF;
APPX
100 Appendix 1 Specifications of Structured Text language
Appendix 2 Instructions That Cannot be Used in ST
Programs
The following instructions, which are used in ladder programs, are described by using an operator or a control statement in ST
programs.
*1 Only assignment statement can be used for transferring character string data, or for a data type that can be converted automatically
(Page 30 Type conversion which is performed automatically).
APPX
Appendix 2 Instructions That Cannot be Used in ST Programs 101
Type Instruction symbol
Dividing 16-bit binary data /(P)(_U)
Multiplying 32-bit binary data D*(P)(_U)
Dividing 32-bit binary data D/(P)(_U)
Adding BCD 4-digit data B+(P) [Using two operands]
Subtracting BCD 4-digit data B-(P) [Using two operands]
Adding BCD 8-digit data DB+(P) [Using two operands]
Subtracting BCD 8-digit data DB-(P) [Using two operands]
Multiplying BCD 4-digit data B*(P)
Dividing BCD 4-digit data B/(P)
Multiplying BCD 8-digit data DB*(P)
Dividing BCD 8-digit data DB/(P)
Adding 16-bit binary block data BK+(P)(_U)
Subtracting 16-bit binary block data BK-(P)(_U)
Adding 32-bit binary block data DBK+(P)(_U)
Subtracting 32-bit binary block data DBK-(P)(_U)
Concatenating string data $+(P) [Using two operands]
Adding single-precision real numbers E+(P) [Using two operands]
Subtracting single-precision real numbers E-(P) [Using two operands]
Adding double-precision real numbers ED+(P) [Using two operands]
Subtracting double-precision real numbers ED-(P) [Using two operands]
Multiplying single-precision real numbers E*(P)
Dividing single-precision real numbers E/(P)
Multiplying double-precision real numbers ED*(P)
Dividing double-precision real numbers ED/(P)
Adding clock data DATE+(P)
Subtracting clock data DATE-(P)
Adding expansion clock data S(P).DATE+
Subtracting expansion clock data S(P).DATE-
Instructions that can be described with logical operator and comparison operator
Type Instruction symbol
Operation start, series connection, parallel connection LD, LDI, AND, ANI, OR, ORI
Ladder block series/parallel connection ANB, ORB
Comparing 16-bit binary data LD(_U), AND(_U), OR(_U)
Comparing 32-bit binary data LDD(_U), ANDD(_U), ORD(_U)
Comparing 16-bit binary block data BKCMP(P)(_U)
Comparing 32-bit binary block data DBKCMP(P)(_U)
Performing an AND operation on 16-bit data WAND(P) [Using two operands]
Performing an AND operation on 32-bit data DAND(P) [Using two operands]
Performing an OR operation on 16-bit data WOR(P) [Using two operands]
Performing an OR operation on 32-bit data DOR(P) [Using two operands]
Performing an XOR operation on 16-bit data WXOR(P) [Using two operands]
Performing an XOR operation on 32-bit data DXOR(P) [Using two operands]
Performing an XNOR operation on 16-bit data WXNR(P) [Using two operands]
Performing an XNOR operation on 32-bit data DXNR(P) [Using two operands]
Comparing string data LD$, AND$, OR$
Comparing single-precision real numbers LDE, ANDE, ORE
Comparing double-precision real numbers LDED, ANDED, ORED
Comparing date data LDDT, ANDDT, ORDT
Comparing time data LDTM, ANDTM, ORTM
APPX
102 Appendix 2 Instructions That Cannot be Used in ST Programs
Instructions that can be described with control statement or
function
Type Instruction symbol
Performing the FOR to NEXT instruction loop FOR, NEXT
Pointer branch CJ, SCJ, JMP
Jumping to END GOEND
Returning from the interrupt program IRET
Forcibly terminating the FOR to NEXT instruction loop BREAK(P)
Calling a subroutine program CALL(P)
Returning from the subroutine program called RET
Calling a subroutine program and turning the output OFF FCALL(P)
Calling a subroutine program in the specified program file ECALL(P)
Calling a subroutine program in the specified program file and turning the EFCALL(P)
output OFF
Calling a subroutine program XCALL
APPX
Appendix 2 Instructions That Cannot be Used in ST Programs 103
Appendix 3 Considerations for Using the MELSEC
iQ-F Series
Description in this manual is based on the use of MELSEC iQ-R series.
This section shows the considerations for creating an ST program for the MELSEC iQ-F series by referring to this manual.
Restrictions on Structured Text language are the same between the MELSEC iQ-R series and MELSEC iQ-F series.
However, besides above, there may be differences in some other specifications such as for instructions, etc. between the
series.
Check the specifications of modules to be used when creating an ST program.
APPX
104 Appendix 3 Considerations for Using the MELSEC iQ-F Series
INDEX
A RETURN . . . . . . . . . . . . . . . . . . . . . . . . . . . 16,92
Return value . . . . . . . . . . . . . . . . . . . . . . . . . .100
Argument . . . . . . . . . . . . . . . . . . . . . . . . 49,50,99
Assignment statement . . . . . . . . . . . . . . . 16,18,92
S
B Selection statement . . . . . . . . . . . . . . . . .16,22,92
ST editor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .44
Boolean . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 29 Statement . . . . . . . . . . . . . . . . . . . . . . . . . . 16,92
Break character . . . . . . . . . . . . . . . . . . . . . . . . 13 Subprogram control statement . . . . . . . . . . . . 16,92
C T
Call statement . . . . . . . . . . . . . . . . . . . . . . . 16,92 Token . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
CASE . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24,92 Type conversion . . . . . . . . . . . . . . . . . . . . . . . . .30
Comment . . . . . . . . . . . . . . . . . . . . . . . . 13,46,93
Constant . . . . . . . . . . . . . . . . . . . . . . . . . . . 13,97
Control statement . . . . . . . . . . . . . . . . . . 16,45,92 V
Conversion . . . . . . . . . . . . . . . . . . . . . . . . . . . . 55 Variable . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .13
D W
Device . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 94 WHILE . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25,92
E
Empty statement . . . . . . . . . . . . . . . . . . . . . . . . 16
EN/ENO . . . . . . . . . . . . . . . . . . . . . . . . 49,50,100
Expression . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17
F
FOR . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 27,92
Function . . . . . . . . . . . . . . . . . . . . . . . 15,49,51,99
Function block . . . . . . . . . . . . . . . . . . 15,50,53,99 I
H
Hierarchization . . . . . . . . . . . . . . . . . . . . . . . 16,93
I
IF . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22,92
Inline structured text . . . . . . . . . . . . . . . . . . . . . 58
Iteration statement . . . . . . . . . . . . . . . . . 16,25,92
L
Label . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 47,96
M
Monitor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
O
Operator . . . . . . . . . . . . . . . . . . . . . . . . . . . 13,93
R
REPEAT . . . . . . . . . . . . . . . . . . . . . . . . . . . 25,92
Result type . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
105
MEMO
106
REVISIONS
*The manual number is given on the bottom left of the back cover.
Revision date *Manual number Description
February 2015 SH(NA)-081483ENG-A First edition
April 2015 SH(NA)-081483ENG-B ■Added or modified parts
TERMS, Section 6.3, Appendix 1
May 2016 SH(NA)-081483ENG-C ■Added or modified parts
Section 1.2, Section 10.1, Section 10.3
December 2017 SH(NA)-081483ENG-D ■Added or modified parts
Section 4.4, Appendix 1
November 2020 SH(NA)-081483ENG-E ■Added or modified parts
SAFETY PRECAUTIONS, CONDITIONS OF USE FOR THE PRODUCT, INTRODUCTION, Section
2.2, Section 3.2, Section 3.3, Section 8.4, Section 8.6, Section 9.2, Section 9.3, Section 10.2,
Section 11.1, Section 11.2, Section 11.4, Section 11.5, Appendix 1, Appendix 3
May 2022 SH(NA)-081483ENG-F ■Added or modified part
Section 11.5
107
TRADEMARKS
Unicode is either a registered trademark or a trademark of Unicode, Inc. in the United States and other countries.
The company names, system names and product names mentioned in this manual are either registered trademarks or
trademarks of their respective companies.
In some cases, trademark symbols such as '' or '' are not specified in this manual.
108
SH(NA)-081483ENG-F(2205)KWIX
MODEL: R-ST-GUIDE-E
MODEL CODE: 13JX28
HEAD OFFICE : TOKYO BUILDING, 2-7-3 MARUNOUCHI, CHIYODA-KU, TOKYO 100-8310, JAPAN
NAGOYA WORKS : 1-14 , YADA-MINAMI 5-CHOME , HIGASHI-KU, NAGOYA , JAPAN
When exported from Japan, this manual does not require application to the
Ministry of Economy, Trade and Industry for service transaction permission.