Omron SYSMAC WS02-CXPC1-E-V50, CS1-H Series, SYSMAC CJ1-H, SYSMAC CJ1-M, CX-PROGRAMMER 5.0-FUNCTION BLOCK OPERATION, CX-Programmer 5.0 Operating instructions

Omron SYSMAC WS02-CXPC1-E-V50, CS1-H Series, SYSMAC CJ1-H, SYSMAC CJ1-M, CX-PROGRAMMER 5.0-FUNCTION BLOCK OPERATION, CX-Programmer 5.0 Operating instructions
Cat.No. W438-E1-01
SYSMAC
WS02-CXPC1-E-V50
CS1-H, CJ1-H, CJ1M CPU Units
CX-Programmer Ver.5.0
OPERATION MANUAL
Function Blocks
CX-Programmer
Ver. 5.0
WS02-CXPC1-E-V50
CS1-H, CJ1-H, CJ1M CPU Units
Operation Manual
Function Blocks
Produced July 2004
iv
Notice:
OMRON products are manufactured for use according to proper procedures by a qualified operator
and only for the purposes described in this manual.
The following conventions are used to indicate and classify precautions in this manual. Always heed
the information provided with them. Failure to heed precautions can result in injury to people or damage to property.
!DANGER
Indicates an imminently hazardous situation which, if not avoided, will result in death or
serious injury.
!WARNING
Indicates a potentially hazardous situation which, if not avoided, could result in death or
serious injury.
!Caution
Indicates a potentially hazardous situation which, if not avoided, may result in minor or
moderate injury, or property damage.
OMRON Product References
All OMRON products are capitalized in this manual. The word “Unit” is also capitalized when it refers to
an OMRON product, regardless of whether or not it appears in the proper name of the product.
The abbreviation “Ch,” which appears in some displays and on some OMRON products, often means
“word” and is abbreviated “Wd” in documentation in this sense.
The abbreviation “PLC” means Programmable Controller. “PC” is used, however, in some Programming Device displays to mean Programmable Controller.
Visual Aids
The following headings appear in the left column of the manual to help you locate different types of
information.
Note Indicates information of particular interest for efficient and convenient operation of the product.
1,2,3...
1. Indicates lists of one sort or another, such as procedures, checklists, etc.
 OMRON, 2004
All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or
by any means, mechanical, electronic, photocopying, recording, or otherwise, without the prior written permission of
OMRON.
No patent liability is assumed with respect to the use of the information contained herein. Moreover, because OMRON is constantly striving to improve its high-quality products, the information contained in this manual is subject to change without
notice. Every precaution has been taken in the preparation of this manual. Nevertheless, OMRON assumes no responsibility
for errors or omissions. Neither is any liability assumed for damages resulting from the use of the information contained in
this publication.
v
vi
TABLE OF CONTENTS
PRECAUTIONS . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xi
1
Intended Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xii
2
General Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xii
3
Safety Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xii
4
Application Precautions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xiii
SECTION 1
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1
1-1
Introducing the Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1-2
Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
1-3
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
1-4
Converting Function Block Definitions to Library Files . . . . . . . . . . . . . . . . . . . . . . . . . . . .
16
1-5
Usage Procedures. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17
SECTION 2
Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
19
2-1
Function Block Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
2-2
Instance Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
30
2-3
Restrictions on Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
37
2-4
Function Block Applications Guidelines. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
2-5
Precautions for Instructions with Operands Specifying the First or Last of Multiple Words
49
2-6
Instruction Support and Operand Restrictions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
52
2-7
CPU Unit Function Block Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
104
2-8
Number of Function Block Program Steps and Instance Execution Time . . . . . . . . . . . . . .
108
SECTION 3
Creating Function Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . 111
3-1
Procedural Flow. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
112
3-2
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
114
Appendices
A
Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
137
B
Structured Text (ST Language) Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
139
C
External Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
161
Index. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 163
Revision History . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 165
vii
TABLE OF CONTENTS
viii
About this Manual:
This manual describes the function blocks and related functionality of the CX-Programmer Ver. 5.0
used together with CS1-H, CJ1-H, and CJ1M CPU Units with unit version 3.0 or later, and includes the
sections described on the next page. The CX-Programmer Ver. 5.0 is software that enables the personal computer to be used as a function block programming device, and can be used only for SYSMAC CS-series and CJ-series CPU Units that support function blocks.
The CX-Programmer Ver. 5.0 function block functions have been enhanced. This manual describes
only CX-Programmer Ver. 5.0 operations that are related to functions blocks. For operations not related
to function blocks, refer to the CX-Programmer Operation Manual (enclosed, Cat. No. W437). This
manual also provides only information related to function blocks for the CS1-H, CJ1-H, and CJ1M CPU
Units. For other information, refer to the CS/CJ-series manuals.
Please read this manual and related manuals carefully and be sure you understand the information
provided before attempting to install or operate the CX-Programmer Ver. 5.0 or the CS1-H, CJ1-H, or
CJ1M CPU Units. Be sure to read the precautions provided in the following section.
Manuals Related to the CX-Programmer Ver. 5.0
Name
SYSMAC WS02-CXPC1-E-V50
CX-Programmer Ver. 5.0 Operation Manual
Function Blocks
([email protected]@H, [email protected]@H,
[email protected]@H, [email protected]@H,
[email protected]@ CPU Units)
SYSMAC WS02-CXPC1-E-V50
CX-Programmer Operation Manual
Cat. No.
Contents
W438
Describes the functionality unique to the CX-Programmer Ver.
5.0 and CS/CJ-series CPU Units with unit version 3.0 or later
based on function blocks. Functionality that is the same as
that of the CX-Programmer is described in W437 (enclosed).
W437
Provides information on how to use the CX-Programmer for
all functionality except for function blocks.
Manuals Related to the CS1-H, CJ1-H, CJ1M CPU Units
Name
SYSMAC CS Series
CS1G/[email protected]@-EV1, CS1G/[email protected]@H
Programmable Controllers
Operation Manual
Cat. No.
Contents
W339
Provides an outline of and describes the design, installation,
maintenance, and other basic operations for the CS-series
PLCs.
The following information is included:
An overview and features
The system configuration
Installation and wiring
I/O memory allocation
Troubleshooting
Use this manual together with the W394.
SYSMAC CJ Series
[email protected]@, CJ1G/[email protected]@H, [email protected]@P, [email protected]@
Programmable Controllers
Operation Manual
W393
Provides an outline of and describes the design, installation,
maintenance, and other basic operations for the CJ-series
PLCs.
The following information is included:
An overview and features
The system configuration
Installation and wiring
I/O memory allocation
Troubleshooting
Use this manual together with the W394.
ix
Name
SYSMAC CS/CJ Series
CS1G/[email protected]@-EV1, CS1G/[email protected]@H,
[email protected]@, CJ1G/[email protected]@H, [email protected]@P, [email protected]@
Programmable Controllers
Programming Manual
Cat. No.
Contents
W394
Describes programming and other methods to use the functions of the CS/CJ-series PLCs.
SYSMAC CS/CJ Series
CS1G/[email protected]@-EV1, CS1G/[email protected]@H,
[email protected]@, CJ1G/[email protected]@H, [email protected]@P, [email protected]@
Programmable Controllers
Instructions Reference Manual
SYSMAC CS/CJ Series
CS1G/[email protected]@-EV1, CS1G/[email protected]@H,
CS1W-SCB21-V1/41-V1, CS1W-SCU21/41,
[email protected]@, CJ1G/[email protected]@H, [email protected]@P, [email protected]@, CJ1W-SCU21-V1/
41-V1
Communications Commands
Reference Manual
W340
The following information is included:
Programming
Tasks
File memory
Other functions
Use this manual together with the W339 or W393.
Describes the ladder diagram programming instructions supported by CS/CJ-series PLCs.
When programming, use this manual together with the Operation Manual (CS1: W339 or CJ1: W393) and Programming
Manual (W394).
W342
Describes the communications commands that can be
addressed to CS/CJ-series CPU Units.
The following information is included:
C-series (Host Link) commands
FINS commands
Note: This manual describes commands that can be sent to
the CPU Unit without regard for the communications path,
which can be through a serial communications port on the
CPU Unit, a communications port on a Serial Communications Unit/Board, or a port on any other Communications
Unit.
Overview of Contents
Precautions provides general precautions for using the CX-Programmer Ver. 5.0.
Section 1 introduces the function block functionality of the CX-Programmer and explains the features
that are not contained in the non-function block version of CX-Programmer.
Section 2 provides specifications for reference when using function blocks, including specifications on
function blocks, instances, and compatible PLCs, as well as usage precautions and guidelines.
Section 3 describes the procedures for creating function blocks on the CX-Programmer.
The Appendices provide information on data types, structure text specifications, and external variables.
!WARNING Failure to read and understand the information provided in this manual may result in personal injury or death, damage to the product, or product failure. Please read each section
in its entirety and be sure you understand the information provided in the section and
related sections before attempting any of the procedures or operations given.
x
PRECAUTIONS
This section provides general precautions for using the CX-Programmer Ver. 5.0 and the Programmable Logic Controller.
The information contained in this section is important for the safe and reliable application of the CX-Programmer
Ver. 5.0 and Programmable Controller. You must read this section and understand the information contained before
attempting to set up or operate the CX-Programmer Ver. 5.0 and Programmable Controller.
1
2
3
4
Intended Audience . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
General Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Safety Precautions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
Application Precautions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
xii
xii
xii
xiii
xi
1
Intended Audience
1
Intended Audience
This manual is intended for the following personnel, who must also have
knowledge of electrical systems (an electrical engineer or the equivalent).
• Personnel in charge of installing FA systems.
• Personnel in charge of designing FA systems.
• Personnel in charge of managing FA systems and facilities.
2
General Precautions
The user must operate the product according to the performance specifications described in the operation manuals.
Before using the product under conditions which are not described in the
manual or applying the product to nuclear control systems, railroad systems,
aviation systems, vehicles, combustion systems, medical equipment, amusement machines, safety equipment, and other systems, machines, and equipment that may have a serious influence on lives and property if used
improperly, consult your OMRON representative.
Make sure that the ratings and performance characteristics of the product are
sufficient for the systems, machines, and equipment, and be sure to provide
the systems, machines, and equipment with double safety mechanisms.
This manual provides information for programming and operating the product.
Be sure to read this manual before attempting to use the product and keep
this manual close at hand for reference during operation.
!WARNING It is extremely important that a PLC and all PLC Units be used for the specified purpose and under the specified conditions, especially in applications that
can directly or indirectly affect human life. You must consult with your
OMRON representative before applying a PLC System to the above-mentioned applications.
3
Safety Precautions
!WARNING Confirm safety sufficiently before transferring I/O memory area status from the
CX-Programmer Ver. 5.0 to the actual CPU Unit. The devices connected to
Output Units may malfunction, regardless of the operating mode of the CPU
Unit. Caution is required in respect to the following functions.
• Transferring from the CX-Programmer to real I/O (CIO Area) in the CPU
Unit using the PLC Memory Window.
• Transferring from file memory to real I/O (CIO Area) in the CPU Unit using
the Memory Card Window.
!Caution Variables must be specified either with AT settings (or external variables), or
the variables must be the same size as the data size to be processed by the
instruction when specifying the first or last address of multiple words in the
instruction operand.
1. If a non-array variable with a different data size and without an AT setting
is specified, the CX-Programmer will output an error when compiling.
2. Array Variable Specifications
xii
4
Application Precautions
• When the size to be processed by the instruction operand is fixed:
The number of array elements must be the same as the number of elements to be processed by the instruction. Otherwise, the CX-Programmer
will output an error when compiling.
• When the size to be processed by the instruction operand is not fixed:
The number of array elements must be greater than or the same as the
size specified in the other operands.
• If the other operand specifying a size is a constant, the CX-Programmer Ver. 5.0 will output an error when compiling.
• If the other operand specifying a size is a variable, the CX-Programmer
Ver. 5.0 will not output an error when compiling, even if the size of the
array variable is not the same as that specified by the other operand
(variable). A warning message, however, will be displayed. In particular, if the number of array elements is less than the size specified by
the other operand (e.g., the size of the instruction operand is 16, and
the number of elements registered in the actual variable table is 10),
the instruction will execute read/write processing for the area that exceeds the number of elements. For example, read/write processing will
be executed for the 6 words following those for the number of elements
registered in the actual variable table. If these words are used for other
instructions (including internal variable allocations), unexpected operation will occur, which may result in serious accidents.
Check that the system will not be adversely affected if the size of the
variable specified in the operand is less than the size in the operand
definition before starting PLC operations.
!Caution Confirm safety at the destination node before transferring a program to
another node or changing contents of the I/O memory area. Doing either of
these without confirming safety may result in injury.
!Caution Execute online editing only after confirming that no adverse effects will be
caused by extending the cycle time. Otherwise, the input signals may not be
readable.
!Caution Confirm safety sufficiently before monitoring power flow and present value
status in the Ladder Section Window or when monitoring present values in the
Watch Window. If force-set/reset or set/reset operations are inadvertently performed by pressing short-cut keys, the devices connected to Output Units
may malfunction, regardless of the operating mode of the CPU Unit.
4
Application Precautions
Observe the following precautions when using the CX-Programmer.
• User programs cannot be uploaded to the CX-Programmer.
• Observe the following precautions before starting the CX-Programmer.
• Exit all applications not directly related to the CX-Programmer. Particularly exit any software such as screen savers, virus checkers, E-mail
or other communications software, and schedulers or other applications that start up periodically or automatically.
• Disable sharing hard disks, printers, or other devices with other computers on any network.
xiii
4
Application Precautions
• With some notebook computers, the RS-232C port is allocated to a
modem or an infrared line by default. Following the instructions in documentation for your computer and enable using the RS-232C port as
a normal serial port.
• With some notebook computers, the default settings for saving energy
do not supply the rated power to the RS-232C port. There may be both
Windows settings for saving energy, as well as setting for specific computer utilities and the BIOS. Following the instructions in documentation for your computer, disable all energy saving settings.
• Do not turn OFF the power supply to the PLC or disconnect the connecting cable while the CX-Programmer is online with the PLC. The computer
may malfunction.
• Confirm that no adverse effects will occur in the system before attempting
any of the following. Not doing so may result in an unexpected operation.
• Changing the operating mode of the PLC.
• Force-setting/force-resetting any bit in memory.
• Changing the present value of any word or any set value in memory.
• Check the user program for proper execution before actually running it on
the Unit. Not checking the program may result in an unexpected operation.
• When online editing is performed, the user program and parameter area
data in CS1-H, CJ1-H, and CJ1M CPU Units is backed up in the built-in
flash memory. The BKUP indicator will light on the front of the CPU Unit
when the backup operation is in progress. Do not turn OFF the power
supply to the CPU Unit when the BKUP indicator is lit. The data will not be
backed up if power is turned OFF. To display the status of writing to flash
memory on the CX-Programmer, select Display dialog to show PLC Memory Backup Status in the PLC properties and then select Windows - PLC
Memory Backup Status from the View Menu.
• Programs including function blocks (ladder programming language or
structured text (ST) language) can be downloaded or uploaded in the
same way as standard programs that do not contain function blocks.
Tasks including function blocks, however, cannot be downloaded in task
units (uploading is possible).
• If a user program containing function blocks created on the CX-Programmer Ver. 5.0 or later is downloaded to a CPU Unit that does not support
function blocks (CS/CJ-series CPU Units with unit version 2.0 or earlier),
all instances will be treated as illegal commands and it will not be possible
to edit or execute the user program.
• If the input variable data is not in boolean format, and numerical values
only (e.g., 20) are input in the parameters, the actual value in the CIO
Area address (e.g., 0020) will be passed. Therefore, be sure to include an
&, #, or +, - prefix before inputting the numerical value.
• Addresses can be set in input parameters, but the address itself cannot
be passed as an input variable. (Even if an address is set as an input
parameter, the value passed to the function block will be that for the size
of data in the input variable.) Therefore, an input variable cannot be used
as the operand of the instruction in the function block when the operand
specifies the first or last of multiple words. Use an internal variable with an
AT setting. Alternatively, specify the first or last element in an internal
array variable.
xiv
4
Application Precautions
• Values are passed in a batch from the input parameters to the input variables before algorithm execution (not at the same time as the instructions
in the algorithm are executed). Therefore, to pass the value from a
parameter to an input variable when an instruction in the function block
algorithm is executed, use an internal variable or external variable instead
of an input variable. The same applies to the timing for writing values to
the parameters from output variables.
• Always use internal variables with AT settings in the following cases.
• The addresses allocated to Basic I/O Units, Special I/O Units, and
CPU Bus Units cannot be registered to global symbols, and these variables cannot be specified as external variables (e.g., the data set for
global variables may not be stable).
• Use internal variables when Auxiliary Area bits other than those preregistered to external variables are registered to global symbols and
these variables are not specified as external variables.
• Use internal variables when specifying PLC addresses for another
node on the network: For example, the first destination word at the remote node for SEND(090) and the first source word at the remote
node for RECV(098).
• Use internal variables when the first or last of multiple words is specified by an instruction operand and the operand cannot be specified as
an internal array variable (e.g., the number of array elements cannot
be specified).
xv
Application Precautions
xvi
4
SECTION 1
Introduction
This section introduces the function block functionality of the CX-Programmer and explains the features that are not
contained in the non-function block version of CX-Programmer.
1-1
1-2
1-3
1-4
1-5
Introducing the Function Blocks. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1-1-1
Overview and Features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
2
1-1-2
Function Block Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
3
1-1-3
Files Created with CX-Programmer Ver. 5.0 . . . . . . . . . . . . . . . . . .
4
1-1-4
CX-Programmer Ver. 5.0 Function Block Menus . . . . . . . . . . . . . .
5
Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
1-2-1
Outline . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
1-2-2
Advantages of Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . .
7
1-2-3
Function Block Structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
8
Variables . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
1-3-1
Introduction. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
1-3-2
Variable Usage and Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
13
1-3-3
Variable Properties . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
14
1-3-4
Variable Properties and Variable Usage . . . . . . . . . . . . . . . . . . . . . .
15
1-3-5
Internal Allocation of Variable Addresses . . . . . . . . . . . . . . . . . . . .
15
Converting Function Block Definitions to Library Files . . . . . . . . . . . . . . . .
16
Usage Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
17
1-5-1
Creating Function Blocks and Executing Instances . . . . . . . . . . . . .
17
1-5-2
Reusing Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
18
1
Section 1-1
Introducing the Function Blocks
1-1
1-1-1
Introducing the Function Blocks
Overview and Features
The CX-Programmer Ver. 5.0 is a Programming Device that can use standard
IEC 61131-3 function blocks. The CX-Programmer Ver. 5.0 function block
function is supported for CS/CJ-series CPU Units with unit version 3.0 or later
and has the following features.
• User-defined processes can be converted to block format by using function blocks.
• Function block algorithms can be written in the ladder programming language or in the structured text (ST) language. (See note.)
• When ladder programming is used, ladder programs created with nonCX-Programmer Ver. 4.0 or earlier can be reused by copying and pasting.
• When ST language is used, it is easy to program mathematical processes that would be difficult to enter with ladder programming.
Note
The ST language is an advanced language for industrial control
(primarily Programmable Logic Controllers) that is described in IEC
61131-3. The ST language supported by CX-Programmer conforms to the IEC 61131-3 standard.
• Function blocks can be created easily because variables do not have to
be declared in text. They are registered in variable tables.
A variable can be registered automatically when it is entered in a ladder or
ST program. Registered variables can also be entered in ladder programs
after they have been registered in the variable table.
• A single function block can be converted to a library function as a single
file, making it easy to reuse function blocks for standard processing.
• A program check can be performed on a single function block to easily
confirm the function block’s reliability as a library function.
• Programs containing function blocks (ladder programming language or
structured text (ST) language) can be downloaded or uploaded in the
same way as standard programs that do not contain function blocks.
Tasks containing function blocks, however, cannot be downloaded in task
units (uploading is possible).
• One-dimensional array variables are supported, so data handling is easier for many applications.
Note
2
The IEC 61131 standard was defined by the International Electrotechnical
Commission (IEC) as an international programmable logic controller (PLC)
standard. The standard is divided into 7 parts. Specifications related to PLC
programming are defined in Part 3 Textual Languages (IEC 61131-3).
Section 1-1
Introducing the Function Blocks
1-1-2
Function Block Specifications
For specifications that are not listed in the following table, refer to the CX-Programmer Ver. 5.0 Operation Manual (W437).
Item
Specifications
Model number
WS02-CXPC1-E-V50
Setup disk
Compatible CPU Units
CD-ROM
CS/CJ-series CS1-H, CJ1-H, and CJ1M CPU Units with unit version 3.0 or
later are compatible.
Device Type
CPU Type
• CS1G-H
CS1G-CPU42H/43H/44H/45H
• CS1H-H
CS1H-CPU63H/64H/65H/66H/67H
• CJ1G-H
CJ1G-CPU42H/43H/44H/45H
• CJ1H-H
CJ1H-CPU65H/66H/67H
• CJ1M
CJ1M-CPU11/12/13/21/22/23
Note If a user program containing function blocks created on the CX-Programmer Ver. 5.0 or later is downloaded to a CPU Unit that does not
support function blocks (CS/CJ-series CPU Units with unit version 2.0
or earlier), all instances will be treated as illegal commands and it will
not be possible to edit or execute the user program.
Compatible
computers
Computer
CS/CJ Series Function Restrictions
• Instructions Not Supported in Function Block Definitions
Block Program Instructions (BPRG and BEND), Subroutine Instructions
(SBS, GSBS, RET, MCRO, and SBN), Jump Instructions (JMP, CJP, and
CJPN), Step Ladder Instructions (STEP and SNXT), Immediate Refresh
Instructions (!), I/O REFRESH (IORF), ONE-MS TIMER (TMHH)
For details, refer to 2-3 Restrictions on Function Blocks.
IBM PC/AT or compatible
CPU
133 MHz Pentium or faster with Windows 98, SE, or NT 4.0 (with service pack
6 or higher)
OS
Microsoft Windows 95, 98, SE, Me, 2000, XP, or NT 4.0 (with service pack 6
or higher)
64 Mbytes min. with Windows 98, SE, or NT 4.0 (with service pack 6 or
higher)
Refer to Computer System Requirements below for details.
Memory
Hard disk space
Monitor
SVGA (800 × 600 pixels) min.
100 Mbytes min. available disk space
CD-ROM drive
COM port
One CD-ROM drive min.
One RS-232C port min.
Note Use “small font” for the font size.
3
Section 1-1
Introducing the Function Blocks
Functions not
supported by
CX-Programmer Ver. 4.0
or earlier.
Item
Specifications
Defining
Number of
CS1-H/CJ1-H CPU Units:
and creat- function block • Suffix -CPU44H/45H/64H/65H/66H/67H: 1,024 max. per CPU Unit
ing funcdefinitions
• Suffix -CPU42H/43H/63H: 128 max. per CPU Unit
tion blocks
CJ1M CPU Units:
• CJ1M-CPU11/12/13/21/22/23: 128 max. per CPU Unit
Function
block names
Variables
Language
Creating
instances
Number of
instances
Storing
function
blocks as
files
Variable names
30,000 characters max.
Variable types
Number of I/O variables in
function block definitions
Allocation of addresses
used by variables
Actual address specification
Inputs, Outputs, Internals, and Externals
64 max. (not including EN and ENO)
Automatic allocation (The allocation range can
be set by the user.)
Supported
Array specifications
Supported (one-dimensional arrays only)
Function blocks can be created in ladder programming language or structured
text (ST, see note).
CS1-H/CJ1-H CPU Units:
• Suffix -CPU44H/45H/64H/65H/66H/67H: 2,048 max. per CPU Unit
• Suffix -CPU42H/43H/63H: 256 max. per CPU Unit
CJ1M CPU Units:
CJ1M-CPU11/12/13/21/22/23: 256 max. per CPU Unit
Instance
names
30,000 characters max.
Project files
Program files
The project file (.cxp/cxt) Includes function block definitions and instances.
The file memory program file (*.obj) includes function block definitions and
instances.
Each function block definition can be stored as a single file (.cxf) for reuse in
other projects.
Function
block library
files
Note
1-1-3
64 characters max.
The structured text (ST language) conforms to the IEC 61131-3 standard, but
CX-Programmer Ver. 5.0 supports only assignment statements, selection
statements (CASE and IF statements), iteration statements (FOR, WHILE,
REPEAT, and EXIT statements), RETURN statements, arithmetic operators,
logical operators, comparison functions, numeric functions, and comments.
For details, refer to Appendix B Structured Text (ST Language) Specifications.
Files Created with CX-Programmer Ver. 5.0
Project Files (*.cxp) and
File Memory Program
Files (*.obj)
Projects created using CX-Programmer that contain function block definitions
and projects with instances are saved in the same standard project files
(*.cxp) and file memory program files (*.obj).
The following diagram shows the contents of a project. The function block definitions are created at the same directory level as the program within the relevant PLC directory.
4
Section 1-1
Introducing the Function Blocks
Project file (.cxp)
PLC1
Global symbol table
I/O table
PLC Setup
PLC memory table
Program (with rung comments)
Local symbol table
Section 1 (with instances)
Section 2 (with instances)
END section (with instances)
Function block definitions
FunctionBlock1
FunctionBlock2
PLC2
Instances created
in program
sections.
Each function block can be
stored in a separate
definition file (.cxf).
Function Block Library
Files (*.cxf)
A function block definition created in a project with CX-Programmer Ver. 5.0
can be saved as a file (1 definition = 1 file), enabling definitions to be loaded
into other programs and reused.
Project Text Files
Containing Function
Blocks (*.cxt)
Data equivalent to that in project files created with CX-Programmer Ver. 5.0
(*.cxp) can be saved as CXT text files (*.cxt).
1-1-4
CX-Programmer Ver. 5.0 Function Block Menus
The following tables list CX-Programmer Ver. 5.0 menus related to function
blocks. For details on all menus, refer to the CX-Programmer Ver. 5.0 Operation Manual (W437).
Main Menu
Main menu
File
Submenu
Shortcut
Function
---
Reads the saved function block library files (*.cxf).
---
Edit
Func- Load Function
tion
Block from File
Block Save Function
Block to File
Update Function Block
Saves the created function block definitions to a file ([function block
library file]*.cxf).
When a function block definition’s I/O variables have been changed
after the instance was created, an error will be indicated by displaying the instance’s left bus bar in red. This command updates the
instance with the new information and clears the error.
Insert
Function Block Invocation
F
Creates an instance in the program (section) at the present cursor
location.
Function Block Parameter
P
When the cursor is located to the left of an input variable or the right
of an output variable, sets the variable’s input or output parameter.
Function
Block
Memory
---
Sets the range of addresses (function block instance areas) internally allocated to the selected instance’s variables.
Checks the status of the addresses internally allocated to the
selected instance’s variables.
Checks the addresses internally allocated to each variable in the
selected instance.
Optimizes the allocation of addresses internally allocated to variables.
PLC
Function Block
Memory Allocation
Function Block
Memory Statistics
Function Block
Instance Address
Optimize Function
Memory
---
-------
5
Section 1-1
Introducing the Function Blocks
Main Popup Menus
Popup Menu for Function Block Definitions
Popup menu
Insert Function Block
Function
Ladder
Creates a function block definition with a ladder programming language algorithm.
Structured Text
From file
Creates a function block definition with an ST language algorithm.
Reads a function block definition from a function block library file (*.cxf).
Popup Menu for Inserted Function Blocks
Open
Popup menu
Function
Displays the contents of the selected function block definition on the right side of the window.
Save Function Block File
Compile
Saves the selected function block definition in a file.
Compiles the selected function block definition.
Popup Menu for Function Block Variable Tables
Popup menu
Function
Edit
Edits the variable.
Insert Variable
Insert Variable
Adds a variable to the last line.
Inserts the variable above the current cursor position.
Above
Cut
Below
Inserts the variable below the current cursor position.
Cuts the variable.
Copy
Paste
Copies the variable.
Pastes the variable.
Find
Searches for the variable. Variable names, variable comments, or all (text strings) can
be searched.
Replace
Delete
Replaces the variable.
Deletes the variable.
Rename
Changes only the name of the variable.
Popup Menu for Instances
Popup menu
Function
Edit
Changes the instance name.
Update Invocation
When a function block definition’s I/O variables have been changed after the instance
was created, an error will be indicated by displaying the instance’s left bus bar in red.
This command updates the instance with the new information and clears the error.
Go To Function Block Definition Displays the selected instance’s function block definition on the right side of the window.
Shortcut Keys
F Key: Pasting Function
Block Definitions in
Program
Move the cursor to the position at which to create the copied function block
instance in the Ladder Section Window, and click the F Key. This operation is
the same as selecting Insert - Function Block Invocation.
P Key: Inputting
Parameters
Position the cursor at the left of the input variable, or at the right of the output
variable and click the P Key. This operation is the same as selecting Insert Function Block Parameter.
6
Section 1-2
Function Blocks
1-2
1-2-1
Function Blocks
Outline
A function block is a basic program element containing a standard processing
function that has been defined in advance. Once the function block has been
defined, the user just has to insert the function block in the program and set
the I/O in order to use the function.
As a standard processing function, a function block does not contain actual
addresses, but variables. The user sets addresses or constants in those variables. These address or constants are called parameters. The addresses
used by the variables themselves are allocated automatically by the CX-Programmer for each program.
With the CX-Programmer, a single function block can be saved as a single file
and reused in other PLC programs, so standard processing functions can be
made into libraries.
Program 2
Copy of function block A
Function block A
Program 1
Variable
Copy of function block A
Standard
program section
written with
variables
Input
Variable Variable
Output
Output
Define in advance.
Insert in
program.
Set
Set
Copy of function block A
Save function
block as a file.
Convert to
library function.
Function
block A
Input
Variable Variable
Output
To another PLC program
Reuse.
1-2-2
Advantages of Function Blocks
Function blocks allow complex programming units to be reused easily. Once
standard programming is created in a function block and saved in a file, it can
be reused just by placing the function block in a program and setting the
parameters for the function block’s I/O. The ability to reuse existing function
blocks will save significant time when creating/debugging programs, reduce
coding errors, and make the program easier to understand.
Structured
Programming
Structured programs created with function blocks have better design quality
and require less development time.
Easy-to-read “Black Box”
Design
The I/O operands are displayed as variable names in the program, so the program is like a “black box” when entering or reading the program and no extra
time is wasted trying to understand the internal algorithm.
Use One Function Block
for Multiple Processes
Many different processes can be created easily from a single function block by
using the parameters in the standard process as input variables (such as
timer SVs, control constants, speed settings, and travel distances).
7
Section 1-2
Function Blocks
Reduce Coding Errors
Coding mistakes can be reduced because blocks that have already been
debugged can be reused.
Data Protection
The variables in the function block cannot be accessed directly from the outside, so the data can be protected. (Data cannot be changed unintentionally.)
Improved Reusability with
Variable Programming
The function block’s I/O is entered as variables, so it isn’t necessary to change
data addresses in a block when reusing it.
Creating Libraries
Processes that are independent and reusable (such as processes for individual steps, machinery, equipment, or control systems) can be saved as function block definitions and converted to library functions.
The function blocks are created with variable names that are not tied to actual
addresses, so new programs can be developed easily just by reading the definitions from the file and placing them in a new program.
Compatible with
Multiple Languages
1-2-3
Mathematical expressions can be entered in structured text (ST) language.
Function Block Structure
Function blocks consist of function block definitions that are created in
advance and function block instances that are inserted in the program.
Function Block
Definitions
Function block definitions are the programs contained in function blocks. Each
function block definition contains the algorithm and variable definitions, as
shown in the following diagram.
Function Block Definition
Example: CLOCK PULSE
Example: CLOCK PULSE
1. Algorithm
tim_b
TIMX tim_a OFF_TIME
Algorithm
tim_a
TIMX tim_b ON_TIME
Variable definitions
ENO
2. Variable Definitions
Usage
Name
Internal
Internal
Input
Input
tim_a
tim_b
ON_TIME
OFF_TIME
Type
TIMER
TIMER
INT
INT
1. Algorithm
Standardized programming is written with variable names rather than real I/O
memory addresses. In the CX-Programmer, algorithms can be written in
either ladder programming or structured text.
8
Section 1-2
Function Blocks
2. Variable Definitions
The variable table lists each variable’s usage (input, output, or internal) and
properties (data type, etc.). For details, refer to 1-3 Variables.
Number of Function Block
Definitions
The maximum number of function block definitions that can be created for one
CPU Unit is either 128 or 1,024 depending on the CPU Unit model.
Instances
To use an actual function block definition in a program, create a copy of the
function block diagram and insert it in the program. Each function block definition that is inserted in the program is called an “instance” or “function block
instance.” Each instance is assigned an identifier called an “instance name.”
By generating instances, a single function block definition can be used to process different I/O data with the same function.
Not yet in program
and memory not yet
allocated
(abstract).
Function Block Definition FB1
Block instance in program with memory
allocated. (object)
Standard
program unit
with variable
names a, b, c,
etc.
Instance
Program
Insert in
program.
Automatic
allocation
Input
data
a
b
c
Output data
Output data
2. Parameters
Table defining usage
and properties of
variables a, b, c, etc.
Memory
used
Instance FB1_1 of function block definition FB1
1. Algorithm
Automatic
allocation
Memory
for FB1_2
Insert in
program.
Instance FB1_2 of function block definition FB1
Input
data
a
b
c
Note
Memory
for FB1_1
Different I/O data
can be processed
with the same
function.
Output data
Output data
Instances are managed by names. More than one instance with the same
name can also be inserted in the program. If two or more instances have the
same name, they will use the same internal variables. Instances with different
names will have different internal variables.
For example, consider multiple function blocks that use a timer as an internal
variable. In this case all instances will have to be given different names. If
more than one instance uses the same name, the same timer would be used
in multiple locations, resulting in duplicated use of the timer.
If, however, internal variables are not used or they are used only temporarily
and initialized the next time an instance is executed, the same instance name
can be used to save memory.
9
Section 1-2
Function Blocks
instance_A
TIMER_FB
Function Block Definition
TIMER_FB
Variable Definitions
Internal variable: WORK_NUM
Use same internal variables.
instance_A
TIMER_FB
Use different internal variables.
instance_B
TIMER_FB
Number of Instances
Multiple instances can be created from a single function block definition. Up to
either 256 or 2,048 instances can be created for a single CPU Unit depending
on the CPU Unit model. The allowed number of instances is not related to the
number of function block definitions and the number of tasks in which the
instances are inserted.
Parameters
Each time an instance is created, set the real I/O memory addresses or constants for I/O variables used to pass input data values to instances and obtain
output data values from instances. These addresses and constants are called
parameters.
Instance of Function Block Definition A
Input 0.00
a
Input 3.00
c
Set the constants or
input source addresses
from which to pass data.
b
Output 2.00
Set the constant or
output destination
address to which to pass
data.
Here, it is not the input source address itself, but the contents at the input
address in the form and size specified by the variable data type that is passed
to the function block. In a similar fashion, it is not the output destination
address itself, but the contents for the output address in the form and size
specified by the variable data type that is passed from the function block.
10
Section 1-2
Function Blocks
Even if an input source address (i.e., an input parameter) or an output destination address (i.e., an output parameter) is a word address, the data that is
passed will be the data in the form and size specified by the variable data type
starting from the specified word address.
Program
Instance of Function Block Definition A
Input D100
m
Input D200
n
k
Output D300
Examples:
If m is type WORD, one word of data from D100 will be passed to the
variable.
If n is type DWORD, two words of data from D200 and D201 will be
passed to the variable.
If k is type LWORD, four words of data from the variable will be passed
to the D300 to D303.
Note
(1) Only addresses in the following areas can be used as parameters: CIO
Area, Auxiliary Area, DM Area, EM Area (banks 0 to C), Holding Area,
and Work Area.
The following cannot be used: Index and Data Registers (both direct and
indirect specifications) and indirect addresses to the DM Area and EM
Area (both in binary and BCD mode).
(2) Local and global symbols in the user program can also be specified as
parameters. To do so, however, the data size of the local or global symbol
must be the same as the data size of the function block variable.
(3) When an instance is executed, input values are passed from parameters
to input variables before the algorithm is processed. Output values are
passed from output variables to parameters just after processing the algorithm. If it is necessary to read or write a value within the execution cycle of the algorithm, do not pass the value to or from a parameter. Assign
the value to an internal variable and use an AT setting (specified addresses).
!Caution If an address is specified in an input parameter, the values in the address are
passed to the input variable. The actual address data itself cannot be passed.
!Caution Parameters cannot be used to read or write values within the execution cycle
of the algorithm. Use an internal variable with an AT setting (specified
addresses). Alternatively, reference a global symbol as an external variable.
■ Reference Information
A variety of processes can be created easily from a single function block by
using parameter-like elements (such as fixed values) as input variables and
changing the values passed to the input variables for each instance.
Example: Creating 3 Instances from 1 Function Block Definition
11
Section 1-2
Function Blocks
Instance
CASCADE_01
Algorithm
Cyclic task 0
CASCADE_01
P_On
EN
&20
Internal and I/O
variables
&10
CONTROL
ENO
1.0
ON_TIME
OFF_TIME
Function Block Definition
Instance
CASCADE_02
Algorithm
Example: CONTROL
Algorithm
CASCADE_02
P_On
EN
&15
Internal and I/O
variables
Variables
Example:
There are 3 FB
instances and each
has its own I/O and
internal variables.
Instance
CASCADE_03
Algorithm
&10
CONTROL
ENO
1.1
ON_TIME
OFF_TIME
Cyclic task 1
CASCADE_03
P_On
EN
&7
Internal and I/O
variables
&8
CONTROL
ENO
1.2
ON_TIME
OFF_TIME
If internal variables are not used, if processing will not be affected, or if the
internal variables are used in other locations, the same instance name can be
used at multiple locations in the program.
Cyclic taskCASCADE
0
P_On
&100
The same instance can be
used at multiple locations.
&130
CONTROL
EN
ENO
1.0
PARA_1
PARA_2
Function block definition
Instance
CASCADE
Algorithm
Example: CONTROL
Algorithm
Internal and I/O
variables
Variables
P_On
&50
&150
CASCADE
CONTROL
EN
ENO
1.1
PARA_1
PARA_2
Cyclic taskCASCADE
1
P_On
&100
&200
CONTROL
EN
ENO
1.2
PARA_1
PARA_2
Some precautions are required when using the same memory area. For
example, if the same instance containing a timer instruction is used in more
than one program location, the same timer number will be used causing coil
duplication, and the timer will not function properly if both instructions are executed.
Registration of Instances
Each instance name is registered in the global symbol table as a file name.
Program
Instance (sample) of function block definition A
a
b
c
The instance is registered in the
global symbol table with the instance
name as the symbol name.
Name
Data type
sample FB [FunctionBlock1]
Instance name
12
Address/
value
N/A[Auto]
The function block definition
name is registered after FB in
square parentheses [ ].
Section 1-3
Variables
1-3
1-3-1
Variables
Introduction
In a function block, the addresses (see note) are not entered as real I/O memory addresses, they are all entered as variable names. Each time an instance
is created, the actual addresses used by the variable are allocated automatically in the specified I/O memory areas by the CX-Programmer. Consequently, it isn’t necessary for the user to know the real I/O memory addresses
used in the function block, just as it isn’t necessary to know the actual memory allocations in a computer. A function block differs from a subroutine in this
respect, i.e., the function block uses variables and the addresses are like
“black boxes.”
Example:
Program
Function block definition A
Instance of function block definition A
Standard program section with
variable names a, b, c, etc.
b
a
c
MOV
Table indicating usage and
prpperties of variables a, b, c, etc.
Usage: Inputs
a
c
AT
Initial Value Retained
BOOL
BOOL
Usage: Outputs
Prpperties:
Name Type
BOOL
b
Note
AT
Input 0.00
a
Input 3.00
c
b
Output 2.00
Specify inputs and outputs
at the same time.
Status of 0.00 (1 or 0) is
passed to a.
0.00 1
a
1
Status of b (1 or 0) is
passed to 2.00.
b
1
2.00
1
Status of 3.00 (1 or 0) is
passed to c.
Prpperties:
Name Type
Insert in
program.
Initial Value Retained
3.00 0
c
0
The system automatically allocates the
addresses used by variables a, b, and c. For
example, when W100 to W120 is set as the
system’s non-retained memory area, bit
addresses such as a = W10000, b = W10001,
and c = W10002 will be allocated.
Constants are not registered as variables. Enter constants directly in instruction operands.
• Ladder programming language: Enter hexadecimal numerical values
after the # and decimal values after the &.
• Structured text (ST language): Enter hexadecimal numerical values after 16# and enter decimal numerical values as is.
Exception: Enter directly or indirectly specified addresses for Index Registers
IR0 to IR15 and Data Registers DR0 to DR15 directly into the instruction
operand.
1-3-2
Variable Usage and Properties
Variable Usage
The following variable types (usages) are supported.
Internals:
Internal variables are used only within an instance. They cannot
be used pass data directly to or from I/O parameters.
Inputs:
Input variables can input data from input parameters outside of
the instance. The default input variable is an EN (Enable) variable, which passes input condition data.
13
Section 1-3
Variables
Outputs:
Output variables can output data to output parameters outside of
the instance. The default output variable is an ENO (Enable Out)
variable, which passes the instance’s execution status.
Externals: External variables are either system-defined variables registered
in advance with the CX-Programmer, such as the Condition Flags
and some Auxiliary Area bits, or user-defined global symbols for
use within instances.
For details on variable usage, refer to the section on Variable Type (Usage)
under Variable Definitions in 2-1-2 Function Block Elements.
The following table shows the number of variables that can be used and the
kind of variable that is created by default for each of the variable usages.
1-3-3
Variable Properties
Variables have the following properties.
Variable Name
The variable name is used to identify the variable in the function block. It
doesn’t matter if the same name is used in other function blocks.
Note
Data Type
The variable name can be up to 30,000 characters long, but must not begin
with a number. Also, the name cannot contain two underscore characters in a
row. The character string cannot be the same as that of a an index register
such as in IR0 to IR15. For details on other restrictions, refer to Variable Definitions in 2-1-2 Function Block Elements.
Select one of the following data types for the variable:
BOOL, INT, UINT, DINT, UDINT, LINT, ULINT, WORD, DWORD, LWORD,
REAL, LREAL, TIMER, COUNTER
For details on variable data types, refer to Variable Definitions in 2-1-2 Function Block Elements.
AT Settings (Allocation to
an Actual Addresses)
It is possible to set a variable to a particular I/O memory address rather than
having it allocated automatically by the system. To specify a particular
address, the user can input the desired I/O memory address in this property.
This property can be set for internal variables only. Even if a specific address
is set, the variable name must still be used in the algorithm.
Refer to Variable Definitions in 2-1-2 Function Block Elements for details on
AT settings and 2-4-3 AT Settings for Internal Variables for details on using AT
settings.
Array Settings
A variable can be treated as a single array of data with the same properties.
To convert a variable to an array, specify that it is an array and specify the
maximum number of elements.
This property can be set for internal variables only. Only one-dimensional
arrays are supported by the CX-Programmer Ver. 5.0.
• Setting Procedure
Click the Advanced Button, select the Array Variable option, and input the
maximum number of elements.
• When entering an array variable name in the algorithm in a function block
definition, enter the array index number in square brackets after the variable number.
For details on array settings, refer to Variable Definitions in 2-1-2 Function Block
Elements.
Initial Value
14
This is the initial value set in a variable before the instance is executed for the
first time. Afterwards, the value may be changed as the instance is executed.
Section 1-3
Variables
For example, set a boolean (BOOL) variable (bit) to either 1 (TRUE) or 0
(FALSE). Set a WORD variable to a value between 0 and 65,535 (between
0000 and FFFF hex).
If an initial value is not set, the variable will be set to 0. For example, a boolean variable would be 0 (FALSE) and a WORD variable would be 0000 hex.
Retain
Select the Retain Option if you want a variable’s data to be retained when the
PLC is turned ON again and when the PLC starts operating.
• Setting Procedure
Select the Retain Option.
1-3-4
Variable Properties and Variable Usage
The following table shows which properties must be set, can be set, and cannot be set, based on the variable usage.
Property
Note
1-3-5
Variable usage
Name
Internals
Must be set.
Inputs
Must be set.
Outputs
Must be set.
Data Type
AT (specified address)
Must be set.
Can be set.
Must be set.
Cannot be set.
Must be set.
Cannot be set.
Initial Value
Can be set.
Can be set.
Retained
Can be set.
Can be set.
(See note.)
Can be set.
(See note.)
Can be set.
Inputs can be set as initial values, but the value of the actual input parameter
will be given priority.
Internal Allocation of Variable Addresses
When an instance is created from a function block definition, the CX-Programmer internally allocates addresses to the variables. Addresses are allocated
to all of the variables registered in the function block definition except for variables that have been assigned actual addresses with the AT Settings property.
FB instance areas
Program
Instance of function block definition A
Non-retained area
Starting address 15
Input 0.00
a
b Output 2.00
t
Output 5.00
Note: Variable c is an internal
variable, so it is not displayed.
Usage: Inputs
Properties:
Name Type AT
a
BOOL
Initial Value Retained
0
CIO, H, W,
D, or E Area
Retained area
Starting address 15
Name Type
b
t
AT
Initial Value Retained
BOOL
TIMER
Name Type
c
Setting Internal Allocation
Areas for Variables
AT
BOOL 2000.00
InitialValue Retained
Size (words)
Timer area
T Area
Size (Completion
Flags)
C Area
Size (Completion
Flags)
Counter area
YES
Usage: Internals
Properties:
0
H, D, or E
Area
Starting address
Usage: Outputs
Properties:
Size (words)
Automatic allocation of
addresses by system
Starting
address
Example
2000.00
Manual allocation of address to
variable in FB by AT Settings option.
The user sets the function block instance areas in which addresses are allocated internally by the system. The variables are allocated automatically by
the system to the appropriate instance area set by the user.
15
Section 1-4
Converting Function Block Definitions to Library Files
Setting Procedure
Select Function Block Memory - Function Block Memory Allocation from
the PLC Menu. Set the areas in the Function Block Memory Allocation Dialog
Box.
Function Block Instance Areas
FB Instance
Area
Function Block Holding
Area Words (H512 to
H1535)
1-4
Default value
Start Address End Address
Size
Applicable memory
areas
Non Retain
Retain
H512
H1408
H1407
H1535
896
128
CIO, WR, HR, DM, EM
HR, DM, EM
Timers
Counters
T3072
C3072
T4095
C4095
1024
1024
TIM
CNT
The Function Block Holding Area words are allocated from H512 to H1535.
These words are different to the standard Holding Area used for programs
(H000 to H511) and are used only for the function block instance area (internally allocated variable area). These words cannot be specified as instruction
operands. They are displayed in red if input when a function block is not being
created. Although the words can be input when creating a function block, an
error will occur when the program is checked. If this area is specified not to be
retained in the Function Block Memory Allocation Dialog Box, turn the power
ON/OFF or clear the area without retaining the values when starting operation.
Converting Function Block Definitions to Library Files
A function block definition created using the CX-Programmer can be stored as
a single file known as a function block definition file with filename extension
*.cxf. These files can be reused in other projects (PLCs).
Project
Project
Function block definition
Example: CLOCK_PULSE
Function block definition
Example: CLOCK_PULSE
1. Algorithm
1. Algorithm
Save
tim_b
Read
TIMX tim_a OFF_TIME
tim_b
TIMX tim_a OFF_TIME
tim_a
tim_a
TIMX tim_b ON_TIME
TIMX tim_b ON_TIME
ENO
ENO
2. Variable Definitions
Usage
Name
Internal
Internal
Input
Input
16
tim_a
tim_b
ON_TIME
OFF_TIME
2. Variable Definitions
Usage
Name
Type
Internal
Internal
Input
Input
TIMER
TIMER
INT
INT
Function block
definition file (.cxf)
tim_a
tim_b
ON_TIME
OFF_TIME
Type
TIMER
TIMER
INT
INT
Section 1-5
Usage Procedures
1-5
Usage Procedures
Once a function block definition has been created and an instance of the algorithm has been created, the instance is used by calling it when it is time to
execute it. Also, the function block definition that was created can be saved in
a file so that it can be reused in other projects (PLCs).
1-5-1
Creating Function Blocks and Executing Instances
The following procedure outlines the steps required to create and execute a
function block.
1,2,3...
1. First, create the function block definition including the algorithm and variable definitions in ladder program or ST language. Alternatively, insert a
function block library file that has been prepared in advance.
Note (a) Create the algorithm entirely with variable names.
(b) When entering the algorithm in ladder programming language,
project files created with versions of CX-Programmer earlier than
Ver. 5.0 can be reused by reading the project file into the CX-Programmer Ver. 5.0 and copying and pasting useful parts.
2. When creating the program, insert copies of the completed function block
definition. This step creates instances of the function block.
3. Enter an instance name for each instance.
4. Set the variables’ input source addresses and/or constants and output
destination addresses and/or constants as the parameters to pass data for
each instance.
5. Select the created instance, select Function Block Memory - Function
Block Memory Allocation from the PLC Menu, and set the internal data
area for each type of variable.
6. Transfer the program to the CPU Unit.
7. Start program execution in the CPU Unit and the instance will be called and
executed if their input conditions are ON.
Function block definition A
Program
Input
condition
1. Algorithm
Standard
program section
with variable
names a, b, c,
etc.
Insert in
program.
Input 0.00
The instance is
executed if the input
condition is established.
3. Input instance name
Instance of function block definition A
5. The system automatically allocates
the addresses used by these
variables. Set the data area area in
which these addresses are allocated.
Output 2.00
a
b
c
Output 3.00
2. Variables
Table defining usage
and properties of
variables a, b, c, etc.
4. Specify the input source and
output destination addresses.
17
Section 1-5
Usage Procedures
1-5-2
Reusing Function Blocks
Use the following procedure to save a function block definition as a file and
use it in a program for another PLCs.
1,2,3...
1. Select the function block that you want to save and save it as a function
block definition file (*.cxf).
2. Open the other PLC’s project and open/read the function block definition
file (*.cxf) that was saved.
3. Insert the function block definition in the program when creating the new
program.
Function block definition A
Program
1. Algorithm
Input
condition
Standard
program section
with variable
names a, b, c,
etc.
Input 1.00
2. Variables
Table defining usage
and properties of
variables a, b, c, etc.
Instance of function block definition A
a
b
Output 5.00
c
Output 6.00
Read and
insert.
Save
Function
block
definition
A
Function block
definition file (*.cxf)
Note
18
In the CX-Programmer Ver. 5.0, each function block definition can be compiled and checked as a program. We recommend compiling to perform a program check on each function block definition file before saving or reusing the
file.
SECTION 2
Specifications
This section provides specifications for reference when using function blocks, including specifications on function blocks,
instances, and compatible PLCs, as well as usage precautions and guidelines.
2-1
2-2
2-3
2-4
2-5
2-6
Function Block Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
2-1-1
Function Block Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
2-1-2
Function Block Elements . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
21
Instance Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
30
2-2-1
Composition of an Instance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
30
2-2-2
Parameter Specifications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
34
2-2-3
Operating Specifications. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
35
Restrictions on Function Blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
37
Function Block Applications Guidelines . . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
2-4-1
Deciding on Variable Data Types . . . . . . . . . . . . . . . . . . . . . . . . . . .
42
2-4-2
Determining Variable Types (Inputs, Outputs, Externals, and Internals)
42
2-4-3
AT Settings for Internal Variables. . . . . . . . . . . . . . . . . . . . . . . . . . .
43
2-4-4
Array Settings for Internal Variables . . . . . . . . . . . . . . . . . . . . . . . .
44
2-4-5
Specifying Addresses Allocated to Special I/O Units . . . . . . . . . . .
45
2-4-6
Using Index Registers. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
46
Precautions for Instructions with Operands Specifying the First or Last
of Multiple Words . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
49
Instruction Support and Operand Restrictions . . . . . . . . . . . . . . . . . . . . . . . .
52
2-6-1
Sequence Input Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
53
2-6-2
Sequence Output Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
55
2-6-3
Sequence Control Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
56
2-6-4
Timer and Counter Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . .
57
2-6-5
Comparison Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
60
2-6-6
Data Movement Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
62
2-6-7
Data Shift Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
64
2-6-8
Increment/Decrement Instructions . . . . . . . . . . . . . . . . . . . . . . . . . .
67
2-6-9
Symbol Math Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
67
2-6-10 Conversion Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
72
2-6-11 Logic Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
74
2-6-12 Special Math Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
76
2-6-13 Floating-point Math Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . .
76
2-6-14 Double-precision Floating-point Instructions. . . . . . . . . . . . . . . . . .
80
2-6-15 Table Data Processing Instructions. . . . . . . . . . . . . . . . . . . . . . . . . .
82
2-6-16 Data Control Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
85
2-6-17 Subroutine Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
86
2-6-18 Interrupt Control Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
87
2-6-19 High-speed Counter and Pulse Output Instructions
(CJ1M-CPU21/22/23 Only) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
88
19
2-7
2-8
2-6-20 Step Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
89
2-6-21 Basic I/O Unit Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
89
2-6-22 Serial Communications Instructions . . . . . . . . . . . . . . . . . . . . . . . . .
91
2-6-23 Network Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
93
2-6-24 File Memory Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
95
2-6-25 Display Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
95
2-6-26 Clock Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
96
2-6-27 Debugging Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
97
2-6-28 Failure Diagnosis Instructions. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
98
2-6-29 Other Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
98
2-6-30 Block Programming Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . .
99
2-6-31 Text String Processing Instructions . . . . . . . . . . . . . . . . . . . . . . . . . .
101
2-6-32 Task Control Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
103
2-6-33 Model Conversion Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
103
2-6-34 Special Instructions for Function Blocks . . . . . . . . . . . . . . . . . . . . .
104
CPU Unit Function Block Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . .
104
2-7-1
Specifications . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
104
2-7-2
Operation of Timer Instructions . . . . . . . . . . . . . . . . . . . . . . . . . . . .
107
Number of Function Block Program Steps and Instance Execution Time . . .
108
2-8-1
Number of Function Block Program Steps
(CPU Units with Unit Version 3.0 or Later) . . . . . . . . . . . . . . . . . . .
2-8-2
Function Block Instance Execution Time
(CPU Units with Unit Version 3.0 or Later) . . . . . . . . . . . . . . . . . . .
20
108
109
Section 2-1
Function Block Specifications
2-1
2-1-1
Function Block Specifications
Function Block Specifications
Item
Description
Number of function block definitions CS1-H/CJ1-H CPU Units:
• Suffix -CPU44H/45H/64H/65H/66H/67H:
1,024 max. per CPU Unit
• Suffix -CPU42H/43H/63H: 128 max. per CPU
Unit
CJ1M CPU Units:
• CJ1M-CPU11/12/13/21/22/23: 128 max. per
CPU Unit
Number of instances
2-1-2
Number of instance nesting levels
CS1-H/CJ1-H CPU Units:
• Suffix -CPU44H/45H/64H/65H/66H/67H:
2,048 max. per CPU Unit
• Suffix -CPU42H/43H/63H: 256 max. per CPU
Unit
CJ1M CPU Units:
CJ1M-CPU11/12/13/21/22/23: 256 max. per
CPU Unit
Nesting is not supported.
Number of I/O variables
64 variables max. per function block definition
Function Block Elements
The following table shows the items that must be entered by the user when
defining function blocks.
Function Block
Definition Name
Item
Function block
definition name
Description
The name of the function block definition
Language
The programming language used in the function block definition. Select ladder programming or structured text
Variable definitions
Variable settings, such as operands and return values,
required when the function block is executed
• Type (usage) of the variable
• Name of the variable
• Data type of the variable
• Initial value of the variable
Algorithm
Enter the programming logic in ladder or structured text.
• Enter the programming logic using variables.
• Input constants directly without registering in variables.
Comment
Function blocks can have comments.
Each function block definition has a name. The names can be up to 64 characters long and there are no prohibited characters. The default function block
name is [email protected], where @ is a serial number.
Function block definition name
CLOCK PULSE
EN
ENO
(BOOL) (BOOL)
ON_TIME
(INT)
OFF_TIME
(INT)
21
Section 2-1
Function Block Specifications
Language
Select either ladder programming language or structured text (ST language).
For details refer to Appendix B Structured Text (ST Language) Specifications.
Variable Definitions
Variable Names
Define the operands and variables used in the function block definition.
• Variable names can be up to 30,000 characters long.
• Variables name cannot contain spaces or any of the following characters:
! “ # $ % & ‘ ( ) = - ~ ^ \ | ‘ @ { [ + ; * : } ] < , > . ? /
• Variable names cannot start with a number (0 to 9).
• Variable names cannot contain two underscore characters in a row.
• The following characters cannot be used to indicate addresses in I/O
memory.
A, W, H (or HR), D (or DM), E (or EM), T (or TIM), C (or CNT) followed
by the numeric value (word address)
Variable Notation
CLOCK PULSE
EN
ENO
(BOOL) (BOOL)
ON_TIME
(INT)
OFF_TIME
(INT)
Variable table
Usage
Internal
Internal
Input
Input
Name
tim_a
tim_b
ON_TIME
OFF_TIME
Type
TIMER
TIMER
INT
INT
Output variables
Input variables
tim_b
TIMX tim_a OFF_TIME
tim_a
TIMX tim_b OFF_TIME
ENO
Internal
variables
Variable Type (Usage)
Item
Definition
Variable type
Inputs
Operands to the
instance
Outputs
Internals
Return values from the Variables used only
instance
within instance
Externals
Global symbols registered as variables
beforehand with the
CX-Programmer or
user-defined global
symbols.
Status of value at next The value is not
execution
passed on to the next
execution.
The value is passed on The value is passed on The value is not
to the next execution. to the next execution. passed on to the next
execution.
Display
Displayed on the left
side of the instance.
Displayed on the right
side of the instance.
Number allowed
AT setting
64 max. per function
block (excluding EN)
No
64 max. per function
Unlimited
block (excluding ENO)
No
Supported
No
Array setting
No
No
No
22
Not displayed.
Supported
Not displayed.
Unlimited
Section 2-1
Function Block Specifications
Item
Retain setting
Variables created by
default
Variable type
Inputs
Outputs
No
EN (Enable):
Receives an input condition.
Supported
ENO (Enable Output):
Outputs the function
block’s execution status.
Note
Internals
Externals
Supported
None
No
Pre-defined symbols
registered in advance
as variables in the CXProgrammer, such as
Condition Flags and
some Auxiliary Area
bits.
For details on Externals, refer to Appendix C External Variables.
■ Input Variables
Input variables pass external operands to the instance. The input variables
are displayed on the left side of the instance.
The value of the input source (data contained in the specified parameter just
before the instance was called) will be passed to the input variable.
P_On
1.0
FB
EN
ENO
D0
D100
PV
CV
The value of the parameter specified as the input (value of D0)
is passed to the instance’s input variable (PV).
Example
0.0
ADD_INT_DINT
EN
ENO
D100
IN16
OUT32
10.0
Algorithm (Body)
P_On
SIGN IN16
+L IN32
D200
tmp OUT32
IN32
IN16 is an INT variable, so the content of D100 is used.
IN32 is a DINT variable, so the content of D200 and
D201 is used.
Note
tmp
D1000
Variable table
Usage
Name
Internal tmp
EN
Input
IN16
Input
IN32
Input
Output ENO
Output OUT32
Type
DINT
BOOL
INT
DINT
BOOL
DINT
1. The same name cannot be assigned to an input variable and output variable. If it is necessary to have the same variable as an input variable and
output variable, register the variables with different names and transfer the
value of the input variable to the output variable in the function block with
an instruction such as MOV.
2. When the instance is executed, input values are passed from parameters
to input variables before the algorithm is processed. Consequently, values
cannot be read from parameters to input variables within the algorithm. If
it is necessary to read a value within the execution cycle of the algorithm,
do not pass the value from a parameter. Assign the value to an internal
variable and use an AT setting (specified addresses). Alternatively, reference the global symbol as external variables.
23
Section 2-1
Function Block Specifications
Initial Value
Initial values can be set for input variables, but the value of the input parameter will be enabled (the input parameter value will be set when the parameter
for input variable EN goes ON and the instance is executed).
Note
The input parameter setting cannot be omitted when using the CXProgrammer.
EN (Enable) Variable
When an input variable is created, the default input variable is the EN variable.
The instance will be executed when the parameter for input variable EN is ON.
■ Output Variables
Output variables pass return values from the instance to external applications.
The output variables are displayed on the right side of the instance.
After the instance is executed, the value of the output variable is passed to the
specified parameter.
P_On
EN
D0
1.0
FB
ENO
PV
CV
D100
The value of the output variable (CV) is passed to the parameter
specified as the output destination, which is D100 in this case.
Example
0.0
ADD_INT_DINT
EN
ENO
D100
IN16
D200
OUT32
10.0
Algorithm (Body)
EN
SIGN IN16 tmp
D1000
+L IN32
IN32
OUT32 is a DINT variable, so
the variable's value is passed
to D1000 and D1001.
Variable table
Usage
Name
Internal tmp
EN
Input
IN16
Input
IN32
Input
Output ENO
Output OUT32
tmp OUT32
Data type
DINT
BOOL
INT
DINT
BOOL
DINT
Like internal variables, the values of output variables are retained until the
next time the instance is executed (i.e., when EN turns OFF, the value of the
output variable is retained).
Example:
In the following example, the value of output variable CV will be retained until
the next time the instance is executed.
Product A counter
CTD
CD
Q
LD
PV
Note
24
CV
D150
1. The same name cannot be assigned to an input variable and output variable. If it is necessary to have the same variable as an input variable and
output variable, register the variables with different names and transfer the
value of the input variable to the output variable in the function block with
an instruction such as MOV.
Section 2-1
Function Block Specifications
2. When the instance is executed, output variables are passed to the corresponding parameters after the algorithm is processed. Consequently, values cannot be written from output variables to parameters within the
algorithm. If it is necessary to write a value within the execution cycle of the
algorithm, do not write the value to a parameter. Assign the value to an internal variable and use an AT setting (specified addresses).
Initial Value
An initial value can be set for an output variable that is not being retained, i.e.,
when the Retain Option is not selected. An initial value cannot be set for an
output variable if the Retain Option is selected.
The initial value will not be written to the output variable if the IOM Hold Bit
(A50012) is ON.
Auxiliary Area control bit
IOM Hold Bit (A50012)
ON
Initial value
The initial value will not be set.
ENO (Enable Output) Variable
The ENO variable is created as the default output variable. The ENO output
variable will be turned ON when the instance is called. The user can change
this value. The ENO output variable can be used as a flag to check whether or
not instance execution has been completed normally.
■ Internal Variables
Internal variables are used within an instance. These variables are internal to
each instance. They cannot be referenced from outside of the instance and
are not displayed in the instance.
The values of internal variables are retained until the next time the instance is
executed (i.e., when EN turns OFF, the value of the internal variable is
retained). Consequently, even if instances of the same function block definition are executed with the same I/O parameters, the result will not necessarily
be the same.
Example:
The internal variable tim_a in instance Pulse_2sON_1sOFF is different from
internal variable tim_a in instance Pulse_4sON_1sOFF, so the instances cannot reference and will not affect each other’s tim_a value.
Pulse_2sON_1sOFF
P_On
CLOCK PULSE
EN
ENO
1.0
&20
ON_TIME
&10
Variable table
Name
Usage
Internal tim_a
Internal tim_b
ON_TIME
Input
OFF_TIME
Input
Data type
TIMER
TIMER
INT
INT
OFF_TIME
Pulse_4sON_1sOFF
P_On
CLOCK PULSE
EN
ENO
1.1
&40
ON_TIME
&10
OFF_TIME
25
Section 2-1
Function Block Specifications
0.0
ADD_INT_DINT
EN
ENO
D100
IN16
D200
OUT32
Algorithm (Body)
10.0
EN
SIGN IN16 tmp
D1000
+L IN32
IN32
tmp OUT32
Variable table
Name
Internal tmp
EN
Input
IN16
Input
IN32
Input
Output ENO
Output OUT32
Internal variable tmp
is not displayed.
Type
DINT
BOOL
INT
DINT
BOOL
DINT
Retain Data through Power Interruptions and Start of Operation
Internal variables retain the value from the last time that the instance was
called. In addition, the Retain Option can be selected so that an internal variable will also retains its value when the power is interrupted or operation
starts (the mode is switched from PROGRAM to RUN or MONITOR mode).
When the Retain Option is selected, the value of the variable is retained when
the power is interrupted or operation starts unless the CPU Unit does not
have a backup battery. If the CPU Unit does not have a good battery, the value
will be unstable.
Variables
Variables set to Retain
Condition
Start of operation
Status
Retained
Power ON
Retained
When the Retain Option is not selected, the value of the variable will not be
held when the power is interrupted or operation starts. Even variables not set
to be retained, however, can be held at the start of operation by turning ON
the IOM Hold Bit (A50012) and can be held during power interruptions by setting the PLC Setup, as shown in the following table.
Variables
Condition
IOM Hold Bit (A50012) setting
OFF
Variables not
set to Retain
ON
Start of operation Not retained
IOM Hold Bit Status at Startup
(PLC Setup) selected
Retained
IOM Hold Bit Status at Startup
(PLC Setup) not selected
Retained
Power ON
Retained
Not retained
Note
Not retained
The IOM Hold Bit (A50012) is supported for compatibility with previous models. To hold the values of variables in function blocks, however, use the Retain
Option and not the IOM Hold Bit.
Initial Value
An initial value can be set for an internal variable that is not being retained
(i.e., when the Retain Option not selected). An initial value cannot be set for
an internal variable if the Retain Option is selected.
Internal variables that are not being retained will be initialized to 0.
The initial value will not be written to the internal variable if the IOM Hold Bit
(A50012) is ON.
Auxiliary Area control bit
IOM Hold Bit (A50012)
ON
OFF
Initial value
The initial value will not be set.
The initial value will be set.
■ External Variables
External variables are either system-defined variables that have been registered in CX-Programmer before hand, or variables that externally reference
user-defined variables in the global symbol table.
26
Section 2-1
Function Block Specifications
• For details on system-defined variables, refer to Appendix C External
Variables.
• To reference user-defined variables in the global symbol table, the variables must be registered in the global symbol table using the same variable name and data type as the external variable.
Variable Properties
Variable Name
The variable name is used to identify the variable in the function block. The
name can be up to 30,000 characters long. The same name can be used in
other function blocks.
Note
A variable name must be input for variables, even ones with AT settings (specified address).
Data Type
Any of the following types may be used.
Data type
BOOL
Bit data
Content
1 bit
OK
Outputs
OK
Internals
OK
INT
UNIT
Integer
Unsigned integer
16 bits
16 bits
OK
OK
OK
OK
OK
OK
DINT
UDINT
Double integer
Unsigned double integer
32 bits
32 bits
OK
OK
OK
OK
OK
OK
LINT
ULINT
Long (4-word) integer
Unsigned long (4-word) integer
64 bits
64 bits
OK
OK
OK
OK
OK
OK
WORD
DWORD
16-bit data
32-bit data
16 bits
32 bits
OK
OK
OK
OK
OK
OK
LWORD
REAL
64-bit data
Real number
64 bits
32 bits
OK
OK
OK
OK
OK
OK
LREAL
TIMER
Long real number
Timer (See note 1.)
OK
OK
OK
Not supported Not supported OK
COUNTER
Counter (See note 2.)
64 bits
Flag: 1 bit
PV: 16 bits
Flag: 1 bit
PV: 16 bits
Note
Size
Inputs
Not supported Not supported OK
(1) The TIMER data type is used to enter variables for timer numbers (0 to
4095) in the operands for TIMER instructions (TIM, TIMH, etc.). When
this variable is used in another instruction, the Timer Completion Flag (1
bit) or the timer present value (16 bits) is specified (depending on the instruction operand). The TIMER data type cannot be used in structured
text function blocks.
(2) The COUNTER data type is used to enter variables for counter numbers
(0 to 4095) in the operands for COUNTER instructions (CNT, CNTR,
etc.). When this variable is used in another instruction, the Counter Completion Flag (1 bit) or the counter present value (16 bits) is specified (depending on the instruction operand). The COUNTER data type cannot be
used in structured text function blocks.
AT Settings (Allocation to Actual Addresses)
With internal variables, it is possible to set the variable to a particular I/O
memory address rather than having it allocated automatically by the system.
To specify a particular address, the user can input the desired I/O memory
address in this property. It is still necessary to use variable name in programming even if a particular address is specified.
Note
(1) The AT property can be set for internal variables only.
27
Section 2-1
Function Block Specifications
(2) AT settings can be used only with the CIO (Core I/O Area), A (Auxiliary
Area), D (Data Memory Area), E (Extended Memory Area, H (Holding
Relay Area), W (Internal Relay Area).
The AT property cannot be set in the following memory areas:
• Index Register and Data Register Areas (directly/indirectly specified)
• Indirectly specified DM/EM (: binary mode, *:BCD mode)
(3) AT settings can be used for the following allocations.
• Addresses for Basic I/O Units, CPU Bus Units, or Special I/O Units
• Auxiliary Area bits not registered as external variables in advance
• PLC addresses for other nodes in the network
• Instruction operands specifying the beginning word (or end word) of
multiple words.
Example:
If the READ DATA FILE instruction (FREAD) is being used in the function
block definition and it is necessary to check the File Memory Operation Flag
(A34313), use an internal variable and specify the flag’s address in the AT setting.
Register an internal variable, select the AT setting option, and specify A34313
as the address. The status of the File Memory Operation Flag can be checked
through this internal variable.
Address A34313 is allocated to a
boolean internal variable named
NOW_CARD_ACCESS.
When the AT setting is used, the function block loses its flexibility. This function should thus be used only when necessary.
Array Setting
With internal variables, a variable can be defined as an array.
Note
Only one-dimensional arrays are supported by the CX-Programmer.
With the array setting, a large number of variables with the same properties
can be used by registering just one variable.
• An array can have from 1 to 32,000 array elements.
• The array setting can be set for internal variables only.
• Any data type can be specified for an array variable, as long as it is an
internal variable.
• When entering an array variable name in the algorithm of a function block
definition, enter the array index number in square brackets after the variable name. The following three methods can be used to specify the index.
(In this case the array variable is a[].)
• Directly with numbers (for ladder or ST language programming)
Example: a[2]
• With a variable (for ladder or ST language programming)
Example: a[n], where n is a variable
28
Section 2-1
Function Block Specifications
Note
INT, DINT, LINT, UINT, UDINT, or ULINT can be used as the variable data type.
• With an equation (for ST language programming only)
Example: a[b+c], where b and c are variables
Note
Equations can contain only arithmetic operators (+, −, *, and /).
An array is a collection of data elements that are the same type of data. Each
array element is specified with the same variable name and a unique index.
(The index indicates the location of the element in the array.)
A one-dimensional array is an array with just one index number.
Example: When an internal variable named SCL is set as an array variable
with 10 elements, the following 10 variables can be used:
SCL[0], SCL[1], SCL[2], SCL[3], SCL[4], SCL[5], SCL[6], SCL[7], SCL[8], and
SCL[9]
SCL
0
1
2
3
4
5
6
7
8
9
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
WORD variable
Specify SCL[3] to access this data element.
Settings for variable SCL as an array
variable with element numbers 0 to 9.
Note
Use an internal array variable when specifying the first or last of multiple
words in an instruction operand to enable reusing the function block if an internal variable with a AT property cannot be set for the operand and an external
variable cannot be set. Prepare an internal array variable with the number of
elements for the required size, and after setting the data in each array element, specify the first or last element in the array variable for the operand.
Example:
Function block definition
Instance
SCL
Variable
SCL
EN
WORD[10]
S
ENO
D
100
Algorithm
SCL- BODY
SCL
LD P_On
MOV #0000 SCL[0]
SC
MOV &0SCL[1]
SC
MOV #0300 SCL[2]
SC
MOV &4000 SCL[3]
SC
SCL S SC
SCL[0]
D
0
1
2
3
#0000
&0
#0300
&4000
Specifying this array element
in the SCL instruction is the
same as specifying the first
address.
Write the operand data to
the array variables.
Specify the beginning of the
array in the SCL instruction.
29
Section 2-2
Instance Specifications
Note
For details, refer to 2-5 Precautions for Instructions with Operands Specifying
the First or Last of Multiple Words.
Initial Values
When an instance is executed the first time, initial values can be set for input
variables, internal variables, and output variables. For details, refer to Initial
Value under the preceding descriptions of input variables, internal variables,
and output variables.
Retaining Data through Power Interruptions and Start of Operation
The values of internal variables can be retained through power interruptions
and the start of operation. When the Retain Option is selected, the variable
will be allocated to a region of memory that is retained when the power is
interrupted and PLC operation starts.
Algorithm
Enter the logic programming using the registered variables.
Operand Input
Restrictions
Addresses cannot be directly input into instruction operands within function
blocks. Addresses that are directly input will be treated as variable names.
Note
Exception: Input directly or indirectly specified addresses for Index Registers
IR0 to IR15 and Data Registers DR0 to DR15 directly into the instruction
operand. Do not input variables.
Input constants directly into instruction operands.
• Ladder programming language: Enter hexadecimal numerical values
after the # and decimal values after the &.
• Structured text (ST language): Enter hexadecimal numerical values after 16# and enter decimal numerical values as is.
Comment
2-2
2-2-1
A comment of up to 30,000 characters long can be entered.
Instance Specifications
Composition of an Instance
The following table lists the items that the user must set when registering an
instance.
Item
Instance name
Description
Name of the instance
Language
The programming and variables are the same as in
Variable definitions
the function block definition.
Function block instance areas The ranges of addresses used by the variables
Comments
30
A comment can be entered for each instance.
Section 2-2
Instance Specifications
Instance Name
This is the name of the instance.
• Instance names can be up to 30,000 characters long.
• Instance names cannot contain spaces or any of the following characters:
! “ # $ % & ‘ ( ) = - ~ ^ \ | ‘ @ { [ + ; * : } ] < , > . ? /
• Instance names cannot start with a number (0 to 9).
There are no other restrictions.
The instance name is displayed above the instance in the diagram.
Instance name
Pulse_2sON_2sOFF
CLOCK PULSE
EN
ENO
&20
ON_TIME
&10
Function Block
Instance Areas
OFF_TIME
To use a function block, the system requires memory to store the instance’s
internal variables and I/O variables. These areas are known as the function
block instance areas and the user must specify the first addresses and sizes
of these areas. The first addresses and area sizes can be specified in 1-word
units.
When the CX-Programmer compiles the function, it will output an error if there
are any instructions in the user program that access words in these areas.
FB Instance
Area
Function Block Instance
Area Types
Default value
Start Address End Address
Non Retain
Retain
H512
H1408
H1407
H1535
896
128
CIO, WR, HR, DM, EM
HR, DM, EM
Timers
Counters
T3072
C3072
T4095
C4095
1024
1024
TIM
CNT
The following settings are made in the function block instance area:
Non-retained Areas
Item
Contents
Allocated variables
Variables for which the retain property for power OFF and
operation start is set as non-retained (See note 1.)
Applicable areas
H (Function block Special Holding Area), I/O (CIO Area), H
(Holding Area), W (Internal Relay Area), D (Data Memory
Area) (see note 2), E (Extended Data Memory Area) (See
notes 2 and 3.)
Set in words
Setting unit
Allocated words
(default)
Note
Size
Applicable memory
areas
H512 to H140
(1) Except when the data type is set to TIMER or COUNTER.
31
Section 2-2
Instance Specifications
(2) Bit data can be accessed even if the DM or EM Area is specified for the
non-retained area or retained area.
(3) The same bank number cannot be specified as the current bank in the
user program if the EM Area is specified for the non-retained area or retained area.
Retained Area
Item
Note
Contents
Allocated variables
Variables for which the retain property for power OFF and
operation start is set as retained (See note 1.)
Applicable areas
H (Function block Special Holding Area), H (Holding Area), D
(Data Memory Area) (see note 1), E (Extended Data Memory
Area) (See notes 2 and 3.)
Setting unit
Allocated words
(default)
Set in words
H1408 to H1535
(1) Except when the data type is set to TIMER or COUNTER.
(2) Bit data can be accessed even if the DM or EM Area is specified for the
non-retained area or retained area.
(3) The same bank number cannot be specified as the current bank in the
user program if the EM Area is specified for the non-retained area or retained area.
Timer Area
Item
Contents
Allocated variables
Applicable areas
Variables with TIMER set as the data type.
T (Timer Area) Timer Flag (1 bit) or timer PVs (16 bits)
Allocated words
(default)
T3072 to T4095 Timer Flag (1 bit) or timer PVs (16 bits)
Counter Area
Item
Function Block Holding
Area (H512 to H1535)
Contents
Allocated variables
Applicable areas
Variables with COUNTER set as the data type.
C (Counter Area) Counter Flag (1 bit) or counter PVs (16 bits)
Allocated words
(default)
C3072 to C4095 Counter Flag (1 bit) or counter PVs (16 bits)
The default allocation of Function Block Holding Area words set as retained
and non-retained words is H512 to H1535. These words are different to the
standard Holding Area used for programs (H000 to H511), and are used only
for the function block instance area (internally allocated variable area).
• These words cannot be specified in AT settings for internal variables.
• These words cannot be specified as instruction operands.
• These words are displayed in red if they are input when a function
block is not being created.
• Although the words can be input when creating a function block, an
error will occur when the program is checked.
• If this area is specified as non-retained, turn the power ON/OFF or clear
the area without retaining the values when starting operation.
Note
32
To prevent overlapping of instance area addresses with addresses used in the
program, set H512 to H1535 (Function Block Holding Area words) for the nonretained area and retained area.
Section 2-2
Instance Specifications
Accessing Function Block
Instance Area from the
User Program
If the user program contains an instruction to access the function block
instance area, an error will be displayed in the Compile Tab of the Output Window of CX-Programmer if the following operations are attempted.
• Attempting to write during online editing (writing not possible)
• Executing program check (Selecting Compile from the Program Menu or
Compile All PLC Programs from the PLC Menu)
Example: If W0 to W511 is specified as the non-retained area of the function
block instance area and W0.00 is used in the ladder program, an error will
occur when compiling and be displayed as “ERROR: [omitted]...- Address W0.00 is reserved for Function Block use].
Program
P_Off
EN
W0.00
FB
ENO
1.0
Instance data area Start
address
3.0
Non Retain
Retain
Timers
Counters
W0
Size
512
Compile error
Note
Comments
The allocations in the function block instance area for variables are automatically reallocated when a variable is added or deleted. A single instance
requires addresses in sequence, however, so if addresses in sequence cannot be obtained, all variables will be allocated different addresses. As a result,
unused areas will be created. If this occurs, execute the optimization operation to effectively use the allocated areas and remove the unused areas.
A comment of up to 30,000 characters long can be entered.
Creating Multiple
Instances
Calling the Same Instance
A single instance can be called from multiple locations. In this case, the internal variables will be shared.
Making Multiple Instances
Multiple instances can be created from a single function block definition. In
this case, the values of internal variables will be different in each instance.
Example: Counting Product A and Product B
Prepare a function block definition called Down Counter (CTD) and set up
counters for product A and product B. There are two types of programs, one
for automatic operation and another for manual operation. The user can
switch to the appropriate mode of operation.
In this case, multiple instances will be created from a single function block.
The same instance must be called from multiple locations.
33
Section 2-2
Instance Specifications
Program 2 (manual operation)
Program 1 (automatic operation)
Product B counter
Product A counter
CTD
CD
CTD
Q
CD
LD
Q
LD
PV
D100
CV
PV
Product B counter
CV
D150
Reading the same product’s counter
value at different locations
CTD
CD
Q
Reading different products’ counter values
(Algorithm calculating counter value is the same.)
LD
PV
D200
CV
Program 1
Instance A
Instance A
I/O variables,
Internal
variables
FB
FB definition
Body
Instance B
Variable
definitions
FB
Instance B
Body
I/O variables,
Internal
variables
Program 2
Instance A
Body
FB
Use the same internal variables
Use different internal variables
2-2-2
Parameter Specifications
The data that can be set by the user in the input parameters and output
parameters is as follows:
Item
Input parameters
Applicable data
Values (See note 1.), addresses, and program symbols (global symbols and local symbols) (See note 2.)
Note The data that is passed to the input variable from the
parameter is the actual value of the size of the input
variable data. (An address itself will not be passed even
if an address is set in the parameter.)
Output parameters
Note
Input
variable
data type
Contents
(1) The following table shows the methods for inputting values in parameters.
Size
BOOL
INT
Bit data
Integer
1 bit
16 bits
DINT
LINT
Double integer
Long (8-byte) integer
32 bits
64 bits
34
Note Input parameters must be set. If even one input parameter has not been set, a fatal error will occur and the
input parameters will not be transferred to the actual
PLC.
Addresses, program symbols (global symbols, local symbols)
(See note 2.)
Parameter value input
method
Setting range
P_Off, P_On
0 (FALSE), 1 (TRUE)
Positive value: & or + followed −32,768 to 32,767
by integer
−2,147,483,648 to 2,147,483,647
Negative value: − followed by −9,223,372,036,854,775,808 to
integer
9,223,372,036,854,775,807
Section 2-2
Instance Specifications
Input
variable
data type
Contents
Size
UINT
UDINT
Unsigned integer
Unsigned double integer
16 bits
32 bits
ULINT
Unsigned long (8-byte)
integer
64 bits
REAL
Real number
32 bits
LREAL
Long real number
64 bits
WORD
16-bit data
16 bits
DWORD
32-bit data
32 bits
LWORD
64-bit data
64 bits
Parameter value input
method
Setting range
Positive value: & or + followed &0 to 65,535
by integer
&0 to 4,294,967,295
&0 to 18,446,744,073,709,551,615
Positive value: & or + followed −3.402823 × 1038 to −1.175494 ×
by real number (with decimal
10−38, 0, 1.175494 × 10−38 to
point)
3.402823 × 1038
Negative value: − followed by
−1.79769313486232 × 10308 to
real number (with decimal
−2.22507385850720 × 10−308, 0,
point)
2.22507385850720 × 10−308,
1.79769313486232 × 10308
# followed by hexadecimal
#0000 to FFFF or &0 to 65,535
number (4 digits max.)
& or + followed by decimal
number
# followed by hexadecimal
number (8 digits max.)
& or + followed by decimal
number
# followed by hexadecimal
number (16 digits max.)
& or + followed by decimal
number
#00000000 to FFFFFFFF or &0 to
4,294,967,295
#0000000000000000 to
FFFFFFFFFFFFFFFF or &0 to
18,446,744,073,709,551,615
(2) The size of function block input variables and output variables must
match the size of program symbols (global and local), as shown in the following table.
Size
Function block variable data
type
1 bit
16 bits
BOOL
INT, UINT, WORD
BOOL
INT, UINT, UINT BCD, WORD
32 bits
DINT, UDINT, REAL, DWORD
DINT, UDINT, UDINT BCD, REAL,
DWORD
64 bits
LINT, ULINT, LREAL, LWORD
LINT, ULINT, ULINT BCD, LREAL,
LWORD
CHANNEL, NUMBER (see note)
More than 1 Non-boolean
bit
Note
2-2-3
Program symbol (global, local)
data type
The program symbol NUMBER can be set only in the input parameters. The value that is input must be within the size range for the
function block variable data type.
Operating Specifications
Calling Instances
The user can call an instance from any location. The instance will be executed
when the input to EN is ON.
Instance
1.0
0.0
EN
ENO
A
B
D0
In this case, the input to EN is bit 0.0 at the left of the diagram.
D10
• When the input to EN is ON, the instance is executed and
the execution results are reflected in bit 1.0 and word D10.
• When the input to EN is OFF, the instance is not executed,
bit 1.0 is turned OFF, and the content of D10 is not changed.
35
Section 2-2
Instance Specifications
Operation when the
Instance Is Executed
The system calls a function block when the input to the function block’s EN
input variable is ON. When the function block is called, the system generates
the instance’s variables and copies the algorithm registered in the function
block. The instance is then executed.
Pulse_2sON_1sOFF
P_On
CLOCK PULSE
EN
ENO
&20
tim_b
TIMX tim_a OFF_TIME
1. The FB is called.
ON_TIME
&10
Algorithm (Body)
1.0
tim_a
TIMX tim_b ON_TIME
OFF_TIME
ENO
2. The system generates the instance
variables and copies the algorithm.
FB instance (Pulse_2sON_1sOFF)
Usage
Internal
Internal
Input
Input
Name
200-100ms_PULSE_tim_a
200-100ms_PULSE_tim_b
200-100ms_PULSE_ON_TIME
200-100ms_PULSE_OFF_TIME
Value
----&20
&10
3. The contents of the
instance are executed.
Algorithm (Image)
Pulse_2sON_1sOFF tim_b
Pulse_2sON_1sOFF tim_a
Pulse_2sON_1sOFF OFF_TIME
Pulse_2sON_1sOFF tim_a
Pulse_2sON_1sOFF tim_b
Pulse_2sON_1sOFF ON_TIME
Pulse_2sON_1sOFF ENO
The order of execution is as follows:
1. Read data from parameters to input variables.
2. Execute the algorithm.
3. Write data from output variables to parameters.
Input to EN is ON.
Parameters
1. Read values from parameters
to input variables.
2. Execute the algorithm.
3. Write values from output
variables to parameters.
Parameters
Data cannot be exchanged with parameters in the algorithm itself.
In addition, if an output variable is not changed by the execution of the algorithm, the output parameter will retain its previous value.
36
Section 2-3
Restrictions on Function Blocks
Operation when the
Instance Is Not Executed
When the input to the function block’s EN input variable is OFF, the function
block is not called, so the internal variables of the instance do not change (values are retained). In the same way the output variables do not change when
EN is OFF (values are retained).
Program
FB definition
Body
P_Off
1.0
FB
EN
P_On
ENO
ENO
Internal
variable a
Execution results:
Output variable 1.0 is turned OFF, but
internal variable a retains its previous value.
Program
P_Off
P_On
1.0
If the programming were entered
directly into the program instead of in a
function block definition, both bit 1.0
and variable a would be turned OFF.
Internal
variable a
!Caution An instance will not be executed while its EN input variable is OFF, so Differentiation and Timer instructions will not be initialized while EN is OFF. If Differentiation or Timer instructions are being used, use the Always ON Flag
(P_On) for the EN input condition and include the instruction’s input condition
within the function block definition.
Nesting
A function block cannot be called from another function block, i.e., nesting is
not supported.
Program
Instance A: FB1
Instance X: FB2
Instance A
FB1
2-3
FB2
Restrictions on Function Blocks
Ladder Programming
Restrictions
There are some restrictions on instructions used in ladder programs.
Instructions Prohibited in
Function Block Definitions
The following instructions cannot be used in function block definitions. A compile error will occur if any of these instructions is used.
• Block Programming Instructions (All instructions, including BPRG and
BEND)
• Subroutine Instructions (SBS, GSBS, RET, MCRO, SBN, GSBN, and
GRET)
• Jump Instructions (JMP, CJP, CJPN, and JME)
• Step Instructions (STEP and SNXT)
• Immediate Refresh Instructions (!)
• I/O REFRESH Instruction (IORF)
• TMHH and TMHHX Instructions
• CV Address Conversion Instructions (FRMCV and TOCV)
37
Section 2-3
Restrictions on Function Blocks
• Instructions manipulating record positions (PUSH, FIFO, LIFO, SETR,
and GETR)
• FAILURE POINT DETECTION Instruction (FPD)
• Move Timer/Counter PV to Register Instruction (MOVRW)
AT Setting Restrictions
(Unsupported Data Areas)
Addresses in the following areas cannot be used for AT settings.
• Index Registers (neither indirect nor direct addressing is supported) and
Data Registers
Note
Input the address directly, not the AT setting.
• Indirect addressing of DM or EM Area addresses (Neither binary-mode
nor BCD-mode indirect addressing is supported.)
Direct Addressing of I/O
Memory in Instruction
Operands
• Addresses, not variables, can be directly input in Index Registers (both
indirect and direct addressing) and Data Registers.
The following values can be input in instruction operands:
Direct addressing: IR0 to IR15; Indirect addressing: ,IR0 to ,IR15; Constant offset (example): +5,IR0; DR offset: DR0,IR0; Auto-increment:
,IR0++; Auto-decrement: --,IR0
• Direct addressing in instruction operands is not supported for any other
areas in I/O memory.
I/O Variable Restrictions
(Unsupported Data Areas)
Addresses in the following data areas cannot be used as parameters for input
and output variables.
• Index Registers (neither indirect nor direct addressing is supported) and
Data Registers
• Indirect addressing of DM or EM Area addresses (Neither binary-mode
nor BCD-mode indirect addressing is supported.)
Interlock Restrictions
When a function block is called from an interlocked program section, the contents of the function block definition will not be executed. The interlocked function block will behave just like an interlocked subroutine.
P_Off
IL
FB_BODY
FB
ILC
Interlocked
Differentiation
Instructions in Function
Block Definitions
Interlock will not
affect instructions in
the function block
definition.
An instance will not be executed while its EN input variable is OFF, so the following precautions are essential when using a Differentiation Instruction in a
function block definition. (Differentiation Instructions include DIFU, DIFD, and
any instruction with an @ or % prefix.)
• As long as the instance’s EN input variable is OFF, the execution condition
will retain its previous status (the last status when the EN input variable
was ON) and the Differentiation Instruction will not operate.
• When the instance’s EN input variable goes ON, the present execution
condition status will not be compared to the last cycle’s status. The
present execution condition will be compared to the last condition when
the EN input variable was ON, so the Differentiation Instruction will not
operate properly. (If the EN input variable remains ON, the Differentiation
Instruction will operate properly when the next rising edge or falling edge
occurs.)
38
Section 2-3
Restrictions on Function Blocks
Example:
Body
0.0
FB1
EN
ENO
IN1
OUT1
LD EN
OR IN1
SET OUT1
These Differentiation Instructions do not
operate when input condition 0.00 goes
from OFF to ON the first time.
The instructions do not operate while
input condition 0.00 is OFF.
If Differentiation Instructions are being used, always use the Always ON Flag
(P_On) for the EN input condition and include the instruction’s input condition
within the function block definition.
Body
P _On
FB1
0.00
EN
ENO
a
O UT1
LD a
OR I N1
SET OUT1
IN 1
The EN input condition is always ON, so
these Differentiation Instructions operate
normally.
• Input a decimal numerical value after “#” when specifying the first operand
of the following instructions.
MILH(517), MILR(518), MILC(519), DIM(631), MSKS(690), MSKR(692),
CLI(691), FAL(006), FALS(007), TKON(820), TKOF(821)
Note
“&” is not supported.
• CNR(545), CNRX(547) (RESET TIMER/COUNTER) instructions cannot
be used to reset multiple timers and counters within a function block at the
same time.
Always specify the same variable for the first operand (timer/counter number 1) and second operand (timer/counter number 2). Different variables
cannot be specified for the first and second operand.
Timer Instructions in
Function Block Definitions
An instance will not be executed while its EN input variable is OFF, so the following precautions are essential when using a Timer Instruction in a function
block definition.
The Timer Instruction will not be initialized even though the instance’s EN
input variable goes OFF. Consequently, the timer’s Completion Flag will not be
turned OFF if the EN input variable goes OFF after the timer started operating.
Body
0.00
FB1
EN
ENO
LD EN
TI M t i m U P
UP
The timer’s Completion Flag (UP)
will not be turned OFF even though
input condition 0.00 goes OFF.
If Timer Instructions are being used, always use the Always ON Flag (P_On)
for the EN input condition and include the instruction’s input condition within
the function block definition.
39
Section 2-3
Restrictions on Function Blocks
Body
P _On
FB1
EN
0.00
a
ENO
LD a
TI M t i m U P
UP
The timer’s completion flag (UP) is turned
OFF when input condition a (0.00) goes OFF.
• If the same instance containing a timer is used in multiple locations at the
same time, the timer will be duplicated.
ST Programming
Restrictions
• Only the following statements and operators are supported.
• Assignment statements
• Selection statements (CASE and IF statements)
• Iteration statements (FOR, WHILE, REPEAT, and EXIT statements)
• RETURN statements
• Arithmetic operators
• Logical operators
• Comparison operators
• Numerical Functions
• Arithmetic Functions
• Comments
• The TIMER and COUNTER data types cannot be used.
For further details, refer to Appendix B Structured Text (ST Language) Specifications.
Program Structure Precautions
No Branches to the Left of
the Instance
Branches are not allowed on the left side of the instance. Branches are
allowed on the right side.
Incorrect
Correct
FB
FB
Instruction
Instruction
Only One Instance per
Rung
A program rung cannot have more than one instance.
Incorrect
Incorrect
FB
FB
40
FB
Section 2-3
Restrictions on Function Blocks
No Function Block
Connections
A function block’s input cannot be connected to another function block’s output. In this case, a variable must be registered to transfer the execution status
from the first function block’s output to the second function blocks input.
0.0
0.0
FB1
FB1
EN
XOUT
FB2
XIN1
EN
XOUT
D3000
0.0
D100
XIN2
FB2
Temporary variables
transfer the value from
FB1 to FB2.
EN
D3000
XIN1
D100
XIN2
Downloading in Task Units
Tasks including function blocks cannot be downloaded in task units, but
uploading is possible.
Programming
Console Displays
When a user program created with the CX-Programmer is downloaded to the
CPU Unit and read by a Programming Console, the instances will all be displayed as question marks. (The instance names will not be displayed.)
Online Editing
Restrictions
The following online editing operations cannot be performed on the user program in the CPU Unit.
• Changing or deleting function block definitions (variable table or algorithm)
• Inserting instances or changing instance names
Note
Error-related
Restrictions
The instance’s I/O parameters can be changed, instances can be
deleted, and instructions outside of an instance can be changed.
If a fatal error occurs in the CPU Unit while a function block definition is being
executed, ladder program execution will stop at the point where the error
occurred.
Program
FB definition
Instance name
0.0
D100
10.0
FB
EN
ENO
AAA
BBB
D200
Body
LD P_On
++ AAA
Fatal error occurs here.
MOV AAA BBB
In this case, the MOV AAA BBB instruction will not be executed and output
variable D200 will retain the same value that it had before the function block
was executed.
Prohibiting Access to
FB Instance Areas
To use a function block, the system requires memory areas to store the
instance’s internal variables and I/O variables.
Function block instance Initial value of
area
start address
Non-retained
H512
Initial value
Allowed data areas
of size
896
CIO, WR, HR, DM, EM
Retained
Timer
H1408
T3072
128
1,024
HR, DM, EM
TIM
Counter
C3072
1,024
CNT
If there is an instruction in the user program that accesses an address in an
FB instance area, the CX-Programmer will output an error in the following
cases.
41
Section 2-4
Function Block Applications Guidelines
• When a program check is performed by the user by selecting Program Compile from the Program Menu or Compile All Programs from the
PLC Menu.
• When attempting to write the program through online editing (writing is
not possible).
2-4
Function Block Applications Guidelines
This section provides guidelines for using function blocks with the CX-Programmer.
2-4-1
Deciding on Variable Data Types
Integer Data Types
(1, 2, or 4-word Data)
Use the following data types when handling single numbers in 1, 2, or 4-word
units.
• INT and UINT
• DINT and DINT
• LINT and ULINT
Note
Word Data Types
(1, 2, or 4-word Data)
Use signed integers if the numbers being used will fit in the range.
Use the following data types when handling groups of data (non-numeric
data) in 1, 2, or 4-word units.
• WORD
• DWORD
• LWORD
2-4-2
Determining Variable Types (Inputs, Outputs, Externals, and
Internals)
Using Input Variable to
Change Passed Values
To paste a function block into the program and then change the value (not the
address itself) to be passed to the function block for each instance, use an
input variable.
Program
Instance for function block definition A
The value itself is
passed
&3
Unit No.
&50
PARA
Changing the pass value to an input variable.
The following two restrictions apply.
• An address can be set in an input parameter, but an address itself cannot
be passed to an input variable (even if an address is set in the input
parameter, the value for the size of the input variable data type is passed
to the function block). Therefore, when the first or last of multiple words is
specified in the instruction operand within the function block, an input variable cannot be used for the operand. Specify either to use internal variables with AT settings, specify the first or last element in an internal array
variable, or use an external variable (as described in 2-4-4 Array Settings
for Internal Variables).
42
Section 2-4
Function Block Applications Guidelines
Program
Instance for function block definition A
The actual value is
passed
If the size of the data type in
DATA_1 is 1 word, the value
for the word D00100 is
D00100
DATA_1
passed.
W500
An input variable cannot be used to specify
the address of an operand that specifies
the the first (or last) address of multiple
words.
For example, the XFER (BLOCK
TRANSFER) instruction cannot be used to
transfer 10 words from the address
beginning with DATA_1 to the address
beginning with DATA_2.
DATA_2
If the size of the data type in
DATA_2 is 2 words, the value
for the 2 words W500 and
W501 is passed.
XFER
&10
DATA_1
DATA_2
The address can be specified, but the address itself is not passed.
• Values are passed in a batch from the input parameters to the input variables before algorithm execution (not at the same time as the instruction
in the algorithm is executed). Therefore, to pass the value from a parameter to an input variable when the instruction in the function block algorithm
is executed, use an internal variable or external variable instead of an
input variable.
Passing Values from or
Monitoring Output
Variables
To paste into the program and then pass values outside (the program) from
the function block for each instance, or monitor values, use output variables.
Program
Instance for function block definition A.
The actual value is
passed.
OK_Flag
W0.00
NG_ Flag
W0.01
Variable for passing a value outside or monitoring:
Use an output variable.
The following restrictions apply.
• Values are passed from output variables to output parameters all at once
after algorithm execution.
External Variables:
Condition Flags, Clock
Pulses, Auxiliary Area
Bits, Global Symbols in
Program
Condition Flags (e.g., Always ON Flag, Equals Flag), Clock Pulses (e.g., 1.0
second clock pulse bit), pre-registered Auxiliary Area Bits (e.g., First Cycle
Flag), and global symbols used in the program are all external variables
defined by the system.
Internal Variables:
Internally Allocated
Variables and Variables
Requiring AT Settings
Variables that are not specified as Inputs, Outputs, or Externals are Internals.
Internal variables include variables with internally allocated addresses, variables requiring addresses with AT settings (e.g., I/O allocation addresses,
addresses specially allocated for Special I/O Units), or variables requiring
array settings. For details on conditions requiring AT settings or array settings,
refer to 2-4-3 AT Settings for Internal Variables, and 2-4-4 Array Settings for
Internal Variables.
2-4-3
AT Settings for Internal Variables
Always specify AT settings for internal variables under the following conditions.
• When addresses allocated to Basic I/O Units, Special I/O Units, or CPU
Bus Units are used and these addresses are registered to global symbols
that cannot be specified as external variables (e.g., data set for global
symbols is unstable).
43
Function Block Applications Guidelines
Note
Section 2-4
The method for specifying Index Registers for Special I/O Unit allocation addresses requires AT settings to be specified for the first
address of the allocation area. (For details, refer to 2-4-5 Specifying
Addresses Allocated to Special I/O Units.)
• When Auxiliary Area bits that are not pre-registered to external variables
are used, and these bits are registered to global symbols that are not
specified as external variables.
• When setting the first destination word at the remote node for SEND(090)
and the first source word at the local node for RECV(098).
• When the instruction operand specifies the first or last of multiple words,
and internal array variable cannot be specified for the operand (e.g., the
number of array elements cannot be specified).
2-4-4
Array Settings for Internal Variables
Using Array Variables
to Specify First or Last
Word in Multiword
Operands
Note
When specifying the first or last of a range of words in an instruction operand
(see note), the instruction operates according to the address after AT specification or internal allocation. (Therefore, the variable data type and number of
elements for the variable are unrelated to the operation of the instruction.) Always specify a variable with an AT setting or an array variable with a number
of elements that matches the data size to be processed by the instruction.
Some examples are the first source word or first destination word of the
XFER(070) (BLOCK TRANSFER) instruction, the first source word for
SEND(090), or control data for applicable instructions.
For details, refer to 2-5 Precautions for Instructions with Operands Specifying
the First or Last of Multiple Words. Use the following method to specify an array
variable.
1,2,3...
1. Prepare an internal array variable with the required number of elements.
Note
Make sure that the data size to be processed by the instruction is
the same as the number of elements. For details on the data sizes
processed by each instruction, refer to 2-6 Instruction Support and
Operand Restrictions.
2. Set the data in each of the array elements using the MOV instruction in the
function block definition.
3. Specify the first (or last) element of the array variable for the operand. This
enables specification of the first (or last) address in a range of words.
Examples are provided below.
Handling a Single String of Data in Multiple Words
In this example, an array contains the directory and filename (operand S2) for
an FREAD instruction.
• Variable table
Internal variable, data type = WORD, array setting with 10 elements, variable names = filename[0] to filename[9]
• Ladder programming
MOV #5C31 file_name[0]
Set data in each array element.
MOV #3233 file_name[1]
MOV #0000 file_name[2])
Specify the first element
FREAD (omitted) (omitted) file_name[0] (omitted)
of the array in the instruction
operand.
44
Section 2-4
Function Block Applications Guidelines
Handling Control Data in Multiple Words
In this example, an array contains the number of words and first source word
(operand S1) for an FREAD instruction.
• Variable table
Internal variable, data type = DINT, array setting with 3 elements, variable
names = read_num[0] to read_num[9]
• Ladder programming
MOVL &100 read_num[0] (No._of_words)
MOVL &0 read_num[1] (1st_source_word)
Set data in each array element.
FREAD (omitted) read_num[0] (omitted) (omitted)
Specify the first element of the array
in the instruction operand.
Handling a Block of Read Data in Multiple Words
The allowed amount of read data must be determined in advance and an
array must be prepared that can handle the maximum amount of data. In this
example, an array receives the FREAD instruction’s read data (operand D).
• Variable table
Internal variable, data type = WORD, array setting with 100 elements,
variable names = read_data[0] to read_data[99]
• Ladder programming
FREAD (omitted) (omitted) (omitted) read_data[0]
Division Using Integer
Array Variables (Ladder
Programming Only)
Note
2-4-5
A two-element array can be used to store the result from a ladder program’s
SIGNED BINARY DIVIDE (/) instruction. The result from the instruction is D
(quotient) and D+1 (remainder). This method can be used to obtain the remainder from a division operation in ladder programming.
When ST language is used, it isn’t necessary to use an array to receive the
result of a division operation. Also, the remainder can’t be calculated directly
in ST language. The remainder must be calculated as follows:
Remainder = Dividend − (Divisor × Quotient)
Specifying Addresses Allocated to Special I/O Units
Use Index Registers IR0 to IR15 (indirectly specified constant offset) to specify addresses allocated to Special I/O Units based on the value passed for the
unit number as an input parameter within the function block definition as
shown in the following examples.
Note
For details on using Index Registers in function blocks, refer to 2-4-6 Using
Index Registers.
Examples
Example 1: Specifying the CIO Area within a Function Block (Same for DM
Area)
Special I/O Units
Variables: Use the unit number as an input variable, and specifying the first
allocation address as an internal variable with the AT set to CIO 2000.
Programs: Use the following procedure.
1,2,3...
1. Multiply the unit number (input variable) by &10, and create the unit number offset (internal variable, DINT data type).
2. Use the MOVR(560) (MOVE TO REGISTER) instruction to store the real I/
O memory address for the first allocation address (internal variable, AT =
CIO 2000) in the Index Register (e.g., IR0).
45
Section 2-4
Function Block Applications Guidelines
3. Add the unit number offset to the real I/O memory address within the Index
Register (e.g., IR0).
Example 2: Specifying the Designated Bit in the CIO Area (e.g., CIO Word
n+a, Bit b)
Programs: Use either of the following methods.
• Word addresses: Specify the constant offset of the Index Register using
an indirect specification (e.g., +a,IR0).
• Bit addresses: Specify an instruction that can specify a bit address within
a word (e.g., &b in second operand of SETB instruction when writing and
TST instruction when reading).
Example: Special I/O Units
Instance for function block definition A.
&3
Unit No.
1) Specify the first CIO Area word n (n = CIO 2000 + unit number × 10)
Used constants:
Unit number (input variable, INT data type)
Offset (internal variable, DINT data type)
Relay (internal variable, WORD data type, 400 array elements, AT
setting = 2000)
&10
Unit No.
Offset
Multiplies unit number by
&10 and stores in offset.
MOVR
Relay
IR0
Stores the real I/O memory
address for the relay in IR0.
+L
Adds offset to IR0.
IR0
Offset
IR0
2) Specify the designated bit in the CIO
Area (e.g., CIO word n+1, bit 02)
SETB
+1,IR0
&2
2-4-6
Turns ON CIO word n+1,
bit 02.
Using Index Registers
Index Registers IR0 to IR15 function as pointers for specifying I/O memory
addresses. These Index Registers can be used within function blocks to
directly specify addresses using IR0 to IR15 and not the variable names
(Index Register direct specification: IR0 to IR15; Index Register indirect specification: ,IR0 to ,IR15)
Note
46
After storing the real I/O memory addresses in the Index Registers using the
MOVR(560) instruction, Index Registers can be indirectly specified using general instructions. This enables all I/O memory areas to be specified dynamically.
Section 2-4
Function Block Applications Guidelines
Pointer
All I/O memory
areas
MOVR(560)
[email protected]
Index Register
Example: Specifying +5,IR0 using
Specify address
constant offset specification, not
in IR0
variable name
Function block
Indirect +5 offset
specifiInstruction
cation
Specify ad+5,IR0
dress at +5
a
IR0
offset from
IR0.
Note
I/O memory
(1) When Index Registers IR0 to IR15 are used within function blocks, using
the same Index Register within other function blocks or in the program
outside of function blocks will create competition between the two instances and the program will not execute properly. Therefore, when using
Index Registers (IR0 to IR15), always save the value of the Index Register
at the point when the function block starts (or before the Index Register
is used), and when the function block is completed (or after the Index
Register has been used), incorporate processing in the program to return
the Index Register to the saved value.
Example: Starting function block (or before using Index Register):
1. Save the value of IR (e.g., A).
Value A
Value A
IR0
Within function block:
2.Use IR.
Value B
IR0
At start of function block (or before Index Register is used):
3. Return IR to saved valuev(e.g., A)
Value A
Value A
IR0
(2) Always set the value before using Index Registers. Operation will not be
stable if Index Registers are used without the values being set.
47
Function Block Applications Guidelines
Application Examples
The following examples are for using Index Registers IR0 to IR15 within function blocks.
Example
Saving the Index Register Value before Using Index Register
Store IR0 temporarily in backup buffer
Using Index Registers
1) Setting the value in the Index Register. (Stores the real I/O memory
address for first CIO Area word n)
Calculate offset address from unit number
Section 2-4
Details
When Index Registers are used within this
function block, processing to save the Index
Register value is performed when the function starts (or before the Index Register is
used) to enable the value to be returned to
the original Index Register value after the
function block is completed (or after the
Index Register is used).
Example: Save the contents of Index Register IR0 by storing it in SaveIR[0] (internal
variable, data type DINT, 1 array element).
Example: The real I/O memory address for
the first word of CIO 1500 + unit number ×
25 allocated in the CPU Bus Unit allocation
area based on the CPU Bus Unit’s unit
number (&0 to &15) passed from the function block is stored in IR0.
Procedure:
Assumes that unit numbers &0 to &15 have
already been input (from outside the function block) in UnitNo (input variables, INT
data type).
1. Multiple UnitNo by &25, and store in Offset (internal variable, DINT data type)
2. Store the real I/O memory address for
SCPU_Relay (internal variable, WORD
data type, (if required, specify the array as
400 elements (see note), AT setting =
1500)) in Index Register IR0.
Note Specifying an array for SCPU_relay,
such as SCPU_relay [2], for example,
enables the address CIO 1500 +
(UnitNo × &25) + 2 to be specified.
This also applies in example 2 below.
3. Increment the real I/O memory address
in Index Register IR0 by the value for the
variable Offset (variable UnitNo × &25).
48
Precautions for Instructions with Operands Specifying the First or Last of Multiple Section 2-5
Example
2) Specifying constant offset of Index Register (Specifying a bit between
CIO n+0 to n+24)
Details
The real I/O memory address for CIO 1500
+ (UnitNo × &25) is stored in Index Register
IR0 by the processing in step 1 above.
Therefore the word address is specified
using the constant offset from IR0.
For example, specifying +2,IR0 will specify
CIO 1500 + (UnitNo × &25) + 2.
Note CIO 1500 + (UnitNo × &25) + 2 can
also by specified by specifying
SCPU_relay [2] using the array setting with SCPU_relay.
Specify bit addresses using instructions that
can specify bit addresses within words
(e.g., second operand of TST(350/351)/
SETB(532) instructions).
Example: Variable NodeSelf_OK turns ON
when NetCheck_OK (internal variable,
BOOL data type) is ON and bit 15 of the
word at the +6 offset from IR0 (CIO 1500 +
UnitNo × &25 +6) is ON.
Check local node data link participation
Returning the Index Register to the Prior Value
Restore data to IR0 from temporary backup buffer
2-5
The Index Register returns to the original
value after this function block is completed
(or after the Index Register has been used).
Example: The value for variable SaveIR[0]
that was saved is stored in Index Register
IR0, and the value is returned to the contents from when this function started (or
prior to using the Index Register).
Precautions for Instructions with Operands Specifying the
First or Last of Multiple Words
When using ladder programming to create function blocks with instruction
operands specifying the first or last of a range of words, the following precautions apply when specifying variables for the operand.
When the operand specifies the first or last word of multiple words, the
instruction operates according to the internally allocated address for AT setting (or external variable setting). Therefore, the variable data type and number of array elements are unrelated to the operation of the instruction. Either
specify a variable with an AT setting, or an array variable with a size that
matches the data size to be processed by the instruction.
For details on whether an AT setting (or external variable setting) or an array
setting for a number of elements is required to specify the first address of a
range of words in the instruction operand, refer to 2-6 Instruction Support and
Operand Restrictions.
Note
To specify the first or last of multiple words in an instruction operand, always
specify a variable with AT setting (or an external variable), or a variable with
the same size as the data size to be processed in the instruction. The following precautions apply.
1,2,3...
1. If a non-array variable is specified without AT setting and without a matching data size, the CX-Programmer will output an error when compiling.
2. The following precautions apply to when an array variable is specified.
49
Precautions for Instructions with Operands Specifying the First or Last of Multiple Section 2-5
Size to Be Processed in the Instruction Operand Is Fixed
Make sure that the number of elements in the array is the same as size to be
processed by the instruction. Otherwise, the CX-Programmer will output an
error when compiling.
Size to Be Processed in the Instruction Operand Is Not Fixed
Make sure that the number of elements in the array is the same or greater
than the size specified by another operand.
Other Operand Specifying Size: Constant
The CX-Programmer outputs an error when compiling.
Other Operand Specifying Size: Variable
The CX-Programmer will not output an error when compiling (a warning message will be displayed) even if the number of elements in the array does not
match the size specified in another operand (variable).
In particular, when the number of elements in the array is less than the size
specified by another operand, (for example, when instruction processing size
is 16 and the number of elements actually registered in the variable table is
10), the instruction will execute read/write processing in the areas exceeding
the number of elements. (In this example, read/write processing will be executed for the next 6 words after the number of elements registered in the
actual variable table.) If the same area is being used by another instruction
(including internal variable allocations), unexpected operation may occur,
which may result in a serious accident.
Do not use variables with a size that does not match the data size to be processed by the instruction in the operand specifying the first address (or last
address) for a range of words. Always use either non-array variables data type
with a size that is the same as the data size required by the instruction or
array variable with the number of elements that is the same as the data size
required by the instruction. Otherwise, the following errors will occur.
Non-array Variables
without Matching Data
Size and without AT
Setting
If the operand specifying the first address (or last address) of multiple words
uses a non-array variable data type with a size that does not match the data
size required by the instruction and an AT setting is also not used, the CX-Programmer will output a compile error.
Example: BLOCK TRANSFER(070) instruction: XFER W S D
(W: Number of words, S: First source word; D: First destination word)
When &10 is specified in W, variable a with data type WORD is specified in S,
and variable b with data type WORD is specified in D: XFER &10 a
b
The XFER(070) instruction will transfer the data in the 10 words beginning from
the automatically allocated address in variable a to the 10 words beginning
with the automatically allocated address in variable b. Therefore, the CX-Programmer will output a compile error.
Example: XFER &10
a
b
(variables a and b are WORD data types)
Internally allocated address
Example: H700
Variable a (1 word)
Internally allocated address
Example: [email protected]@
10 words are
transferred regardless of the size of
variable a.
50
Variable b (1 word)
This area will be overwritten,
so the CX-Programmer will
output a compile error.
Precautions for Instructions with Operands Specifying the First or Last of Multiple Section 2-5
Array Variables
The result depends on the following conditions.
Size to Be Processed by Instruction Is Fixed
If the size to be processed by the instruction is a fixed operand, and this size
does not match the number of array elements, the CX-Programmer will output
a compile error.
Example: LINE TO COLUMN(064) instruction; COLM
S
D N
(S: Bit number, D: First destination word, N: Source word)
E.g., COLM
a
b[0]
c
If an array for a WORD data type with 10 array elements is specified in D
when it should be for 16 array elements, the CX-Programmer will output an
error when compiling.
Size to Be Processed by Instruction Is Not Fixed
When the operand size to be processed by the instruction is not fixed (when
the size is specified by another operand in the instruction), make sure that the
number of array elements is the same or greater than the size specified in the
other operand (i.e., size to be processed by the instruction).
Other Operand Specifying Size: Constant
The CX-Programmer will output an error when compiling.
Example: BLOCK TRANSFER: XFER
W
S D
(W: Number of words, S: First source word; D: First destination word)
When &20 is specified in W, array variable a with data type WORD and 10
elements is specified in S, and array variable b with data type WORD and 10
elements is specified in D:
XFER &20
a[0]
b[0]
Even though the array variables a[0] and b[0] are both 10 words, the
XFER(070) instruction will execute transfer processing for the 20 words specified in W. As a result, the XFER(070) instruction will perform read/write processing for the I/O memory area following the number of array elements that
was allocated, as shown in the following diagram.
Therefore, if a[10 elements] is internally allocated words (e.g., H700 to H709),
and b[10 elements] is internally allocated words (e.g., H800 to H809),
XFER(070) will transfer data in words H700 to H719 to words H800 to H819.
In this operation, if another internally allocated variable (e.g., c), is allocated
words in H810 to H819, the words will be overwritten, causing unexpected
operation to occur. To transfer 20 words, make sure that the number of elements is specified as 20 elements for both array variable a and b.
51
Section 2-6
Instruction Support and Operand Restrictions
XFER
&20 a[0] b[0]
Using a WORD data type with 10 elements for both variables a and b:
To transfer 20 words, be sure to specify 20 elements for both array variables a and b.
Internally allocated address
Internally allocated address
Example: H700
10 words
Array variable
a (10 words)
Example: H710
Example: H719
20 words
Array variable
a (10 words)
10 words
Example: H810
20 words will be
transferred regardless of the size of array variables a and b.
Example: H819
The variables allocated in this area
(H810 to H819 in this example) are
overwritten. The data is variablelength data, so the CX-Programmer
will not output a compile error.
Other Operand Specifying Size: Variable
Even if the number of array elements does not match the size (i.e., size to be
processed by the instruction) specified in another operand (variable), the CXProgrammer will not output an error when compiling. The instruction will be
executed according to the size specified by the operand, regardless of the
number of elements in the array variable.
Particularly if the number of elements in the array is less than the size (i.e.,
size to be processed by the instruction) specified by another operand (variable), other variables will be affected and unexpected operation may occur.
2-6
Instruction Support and Operand Restrictions
The tables in this appendix indicate which instructions can be used in function
blocks created with ladder programming language, the restrictions that apply
to them and to the operands, including the variables (whether array variables
and AT settings or external variable specifications are required, and which
data types can be used).
Instruction Support
Restrictions on Operands
Instructions that are not supported for use in function block definitions by the
CX-Programmer and CS/CJ-series CPU Units with unit version 3.0 are given
as Not supported in function blocks in the Symbol column.
• Operands that specify the first or last of multiple words, thereby requiring
AT setting or specification of array variables, are indicated as follows in
the AT setting or array required column.
Yes: An AT setting (or external specification) or array variable must be
specified for the operand to specify the first or last of multiple words.
• The value within parentheses is the fixed size used by the instruction
for reading, writing, or other processing. This size indicates either the
data type size or the size required for the array variable specified in
word units. For array variables, this size must be the same as the number of elements. Otherwise, the CX-Programmer will output an error
when compiling.
52
Section 2-6
Instruction Support and Operand Restrictions
• If “not fixed” is indicated in parentheses, the size used by the instruction for reading, writing, or other processing can be changed. Make
sure that the maximum size required for the number of array elements
is provided.
Even if the number of array elements in an operand with unfixed size
does not match the size specified in another operand, the CX-Programmer will not output an error when compiling. The instruction will
operate according to the size specified in the other operand, regardless of the number of array variable elements.
---: Operands that do not require an AT setting or specification of array variables.
Note
When specifying the first or last word of multiple words in an instruction operand, input parameters cannot be used to pass data
to or from variables. Either an AT setting or an array variable with
the required number of elements must be prepared, and after the
array data is set in the function block definition, the first or last element in the array variable must be specified for the operand.
• Any operands for which an AT setting must be specified for an I/O memory address on a remote node in the network are indicated as Specify
address at remote node with AT setting in the AT setting or array required
column.
2-6-1
Sequence Input Instructions
Instruction
LOAD
LOAD NOT
AND
Mnemonic
LD
@LD
%LD
!LD
[email protected]
!%LD
LD NOT
!LD NOT
@LD NOT
%LD NOT
[email protected] NOT
!%LD NOT
AND
@AND
%AND
!AND
[email protected]
!%AND
Function
code
Symbol
Bus bar
Operands
Supported
variable
data types
B: Bit
BOOL
AT setting or
array variable
required
(Required word
data size
shown in
parentheses.)
---
B: Bit
BOOL
---
B: Bit
BOOL
---
Starting point of block
Bus bar
Starting point of block
53
Section 2-6
Instruction Support and Operand Restrictions
Instruction
AND NOT
OR
Mnemonic
Function
code
Symbol
AND NOT
!AND NOT
@AND NOT
%AND NOT
[email protected] NOT
!%AND NOT
OR
@OR
%OR
!OR
[email protected]
!%OR
OR NOT
OR NOT
!OR NOT
@OR NOT
%OR NOT
[email protected] NOT
!%OR NOT
AND LOAD
AND LD
OR LOAD
OR LD
Operands
Supported
variable
data types
---
BOOL
AT setting or
array variable
required
(Required word
data size
shown in
parentheses.)
---
Bus bar
---
BOOL
---
Bus bar
---
BOOL
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
---
S: Source word
N: Bit number
WORD
UINT
-----
S: Source word
WORD
---
N: Bit number
UINT
---
Logic block
Logic block
Logic block
Logic block
NOT
NOT
520
CONDITION
ON
UP
521
CONDITION
OFF
DOWN
522
BIT TEST
LD TST
350
NOT
UP
DOWN
TST
S
N
BIT TEST
LD TSTN
351
TSTN
S
N
54
Section 2-6
Instruction Support and Operand Restrictions
Instruction
BIT TEST
Mnemonic
AND TST
Function
code
Symbol
Operands
350
AND TST
Supported
variable
data types
S: Source word
WORD
AT setting or
array variable
required
(Required word
data size
shown in
parentheses.)
---
N: Bit number
UINT
---
S: Source word
WORD
---
N: Bit number
UINT
---
S: Source word
WORD
---
N: Bit number
UINT
---
S: Source word
WORD
---
N: Bit number
UINT
---
S
N
BIT TEST
AND TSTN
351
AND TSTN
S
N
BIT TEST
OR TST
350
TST
S
N
BIT TEST
OR TSTN
351
TSTN
S
N
2-6-2
Sequence Output Instructions
Instruction
Mnemonic
Function
code
Symbol
Operands
Supported
variable
data types
AT setting or
array variable
required
(Required
word data size
shown in
parentheses.)
OUTPUT
OUT
!OUT
---
BOOL
---
OUTPUT NOT
OUT NOT
!OUT NOT
---
BOOL
---
KEEP
KEEP
!KEEP
---
BOOL
---
---
BOOL
---
---
BOOL
---
DIFFERENTIATE UP
DIFU
!DIFU
011
S (Set)
KEEP
R (Reset)
013
B
DIFU
B
DIFFERENTIATE DOWN
DIFD
!DIFD
014
DIFD
B
55
Section 2-6
Instruction Support and Operand Restrictions
Instruction
SET
RESET
MULTIPLE BIT
SET
Mnemonic
SET
@SET
%SET
!SET
[email protected]
!%SET
RSET
@RSET
%RSET
!RSET
[email protected]
!%RSET
SETA
@SETA
Function
code
Symbol
SET
Operands
Supported
variable
data types
B: Bit
BOOL
AT setting or
array variable
required
(Required
word data size
shown in
parentheses.)
---
B: Bit
BOOL
---
D: Beginning word
UINT
Yes (not fixed)
N1: Beginning bit
N2: Number of bits
UINT
UINT
-----
D: Beginning word
N1: Beginning bit
UINT
UINT
Yes (not fixed)
---
N2: Number of bits
UINT
---
D: Word address
N: Bit number
UINT
UINT
-----
D: Word address
UINT
---
N: Bit number
UINT
---
D: Word address
N: Bit number
UINT
UINT
-----
B
RSET
B
530
SETA
D
N1
N2
MULTIPLE BIT
RESET
RSTA
@RSTA
531
RSTA
D
N1
N2
SINGLE BIT
SET
SETB
@SETB
!SETB
532
SETB
D
N
SINGLE BIT
RESET
RSTB
@RSTB
!RSTB
533
RSTB
D
N
SINGLE BIT
OUTPUT
OUTB
@OUTB
!OUTB
534
OUTB
D
N
56
Section 2-6
Instruction Support and Operand Restrictions
2-6-3
Sequence Control Instructions
Instruction
END
Mnemonic
Function
code
END
001
NO OPERATION NOP
000
INTERLOCK
IL
002
INTERLOCK
CLEAR
ILC
003
MULTI-INTERLOCK DIFFERENTIATION
HOLD
MILH
517
MULTI-INTERLOCK DIFFERENTIATION
RELEASE
MILR
MULTI-INTERLOCK CLEAR
MILC
Symbol
END
--IL
ILC
MILH
N
D
518
MILR
N
D
519
MILC
Operands
Supported
variable
data types
AT setting or
array variable
required
(Required
word data
size shown in
parentheses.)
---
---
---
---
---
---
---
---
---
---
---
---
N: Interlock number # + decimal
only
---
D: Interlock Status
Bit
---
BOOL
N: Interlock number # + decimal
only
D: Interlock Status BOOL
Bit
---
N: Interlock number # + decimal
only
---
---
N
JUMP
JMP
004
Not supported in function N: Jump number
blocks
---
---
JUMP END
JME
005
Not supported in function N: Jump number
blocks
---
---
CONDITIONAL
JUMP
CJP
510
Not supported in function N: Jump number
blocks
---
---
CONDITIONAL
JUMP
MULTIPLE
JUMP
CJPN
511
---
---
JMP0
515
Not supported in function N: Jump number
blocks
---
---
---
MULTIPLE
JUMP END
JME0
516
---
---
FOR-NEXT
LOOPS
FOR
512
JMP0
JME0
FOR
---
N: Number of loops UINT
---
---
---
---
---
---
---
N
BREAK LOOP
BREAK
514
FOR-NEXT
LOOPS
NEXT
513
BREAK
NEXT
57
Section 2-6
Instruction Support and Operand Restrictions
2-6-4
Timer and Counter Instructions
Instruction
TIMER
Mnemonic
Function
code
Symbol
TIM
(BCD)
Operands
TIM
N
Supported
variable
data types
AT setting or
array variable
required
(Required
word data
size shown in
parentheses.)
N: Timer number
S: Set value
TIMER
WORD
-----
N: Timer number
S: Set value
TIMER
UINT
-----
N: Timer number
TIMER
---
S: Set value
WORD
---
N: Timer number
TIMER
---
S: Set value
UINT
---
S
TIMX
(BIN)
550
TIMX
N
S
HIGH-SPEED
TIMER
TIMH
(BCD)
015
TIMH
N
S
TIMHX
(BIN)
551
TIMHX
N
S
ONE-MS TIMER TMHH
(BCD)
ACCUMULATIVE TIMER
540
Not supported in function N: Timer number
blocks.
S: Set value
TIMER
---
WORD
---
TMHHX
(BIN)
552
Not supported in function N: Timer number
blocks.
S: Set value
TIMER
UINT
-----
TTIM
(BCD)
087
N: Timer number
S: Set value
TIMER
WORD
-----
N: Timer number
S: Set value
TIMER
UINT
-----
WORD
---
D1
D1: Completion
Flag
D2: PV word
DWORD
---
D2
S: SV word
DWORD
---
UINT
---
D1
D1: Completion
Flags
D2: PV word
UDINT
---
D2
S: SV word
UDINT
---
TTIM
N
S
TTIMX
(BIN)
555
Timer input
TTIMX
N
Reset input
LONG TIMER
TIML
(BCD)
542
S
TIML
S
TIMLX
(BIN)
553
TIMLX
S
58
Section 2-6
Instruction Support and Operand Restrictions
Instruction
Mnemonic
MULTI-OUTPUT MTIM
TIMER
(BCD)
Function
code
Symbol
543
Operands
Supported
variable
data types
D1: Completion
Flags
UINT
AT setting or
array variable
required
(Required
word data
size shown in
parentheses.)
---
D2: PV word
S: 1st SV word
WORD
WORD
--Yes (8)
UINT
---
D1
D1: Completion
Flags
D2: PV word
UINT
---
D2
S: 1st SV word
WORD
Yes (8)
MTIM
D1
D2
S
MTIMX
(BIN)
554
MTIMX
S
COUNTER
CNT
(BCD)
Count input
CNT
N: Counter number COUNTER
---
S: Set value
---
WORD
N
Reset input
CNTX
(BIN)
546
Count input
S
CNTX
N: Counter number COUNTER
S: Set value
UINT
-----
N: Counter number COUNTER
---
S: Set value
---
N
Reset input
REVERSIBLE
COUNTER
CNTR
(BCD)
012
Increment input
Decrement input
Reset input
CNTRX
(BIN)
548
Increment input
Decrement input
Reset input
RESET TIMER/
COUNTER
CNR
@CNR
(BCD)
545
S
CNTR
S
CNTRX
---
S: Set value
UINT
---
N1: 1st number in
range
TIMER or
COUNTER
(See note.)
---
N2: Last number in
range
TIMER or
COUNTER
(See note.)
---
N1: 1st number in
range
TIMER or
COUNTER
(See note.)
TIMER or
COUNTER
(See note.)
---
S
CNR
N1
547
CNRX
N1
N2
Note
N: Counter number COUNTER
N
N2
CNRX
@CNRX
(BIN)
WORD
N
N2: Last number in
range
---
Enabled when the same variable is specified for N1 and N2.
59
Section 2-6
Instruction Support and Operand Restrictions
2-6-5
Comparison Instructions
Instruction
Symbol Comparison (Unsigned)
Mnemonic
Function
code
LD,AND, OR 300 (=)
+
305 (<>)
=, <>, <, <=, 310 (<)
>, >=
315 (<=)
320 (>)
325 (>=)
Symbol
Operands
Using LD:
Symbol, option
S1
Supported
variable
data types
S1: Comparison
data 1
UINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
S2: Comparison
data 2
UINT
---
S1: Comparison
data 1
UDINT
---
S2: Comparison
data 2
UDINT
---
S1: Comparison
data 1
S2: Comparison
data 2
INT
---
INT
---
S1: Comparison
data 1
S2: Comparison
data 2
DINT
---
DINT
---
S1: Comparison
data 1
S2: Comparison
data 2
UINT
---
UINT
---
S2
Using AND:
Symbol, option
S1
S2
Using OR:
Symbol, option
S1
S2
Symbol Comparison (Double-word,
unsigned)
Symbol Comparison (Signed)
Symbol Comparison (Double-word,
signed)
UNSIGNED COMPARE
LD,AND, OR
+
=, <>, <, <=,
>, >=
+
L
301 (=)
306 (<>)
311 (<)
316 (<=)
321 (>)
326 (>=)
LD,AND, OR 302 (=)
+
307 (<>)
=, <>, <, <=,
312 (<)
>, >=
317 (<=)
+
S
322 (>)
327 (>=)
LD,AND, OR 303 (=)
+
308 (<>)
=, <>, <, <=,
313 (<)
>, >=
318 (<=)
+
SL
323 (>)
328 (>=)
CMP
!CMP
020
---
---
---
CMP
S1
S2
60
Section 2-6
Instruction Support and Operand Restrictions
Instruction
DOUBLE
UNSIGNED COMPARE
Mnemonic
CMPL
Function
code
060
Symbol
Operands
CMPL
S1
S2
SIGNED BINARY
COMPARE
CPS
!CPS
114
CPS
S1
S2
DOUBLE SIGNED CPSL
BINARY COMPARE
115
CPSL
S1
S2
TABLE
COMPARE
TCMP
@TCMP
085
Supported
variable
data types
S1: Comparison
data 1
S2: Comparison
data 2
UDINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
UDINT
---
S1: Comparison
data 1
S2: Comparison
data 2
INT
---
INT
---
S1: Comparison
data 1
DINT
---
S2: Comparison
data 2
DINT
---
S: Source data
WORD
T: 1st word of table WORD
--Yes (16)
R: Result word
UINT
---
WORD
Yes (16)
WORD
Yes (16)
S2
S1: 1st word of set
1
S2: 1st word of set
2
R
R: Result word
UINT
S: Source data
WORD
---
T: 1st word of table
R: Result word
WORD
UINT
Yes (32)
---
S: Source data
WORD
T: 1st word of block WORD
--Yes (not
fixed)
R: Result word
WORD
---
CD: Compare data
(1 word)
UINT
---
LL: Lower limit of
range
UL: Upper limit of
range
UINT
---
UINT
---
TCMP
S
T
R
MULTIPLE
COMPARE
MCMP
@MCMP
019
MCMP
S1
UNSIGNED
BLOCK
COMPARE
BCMP
@BCMP
068
BCMP
S
T
R
EXPANDED
BCMP2
BLOCK COMPARE @BCMP2
502
BCMP2
S
T
R
AREA RANGE
COMPARE
ZCP
088
ZCP
CD
LL
UL
61
Section 2-6
Instruction Support and Operand Restrictions
Instruction
Mnemonic
DOUBLE AREA
ZCPL
RANGE COMPARE
Function
code
Symbol
116
Operands
ZCPL
CD
LL
UL
Time Comparison
LD, AND, OR
+
=DT, <>
DT, <DT,
<=DT, >DT,
>=DT
341 (=DT) LD (LOAD):
342
Symbol
(<>DT)
C
343 (<DT)
S1
344
(<=DT)
S2
345 (>DT)
AND:
346
(>=DT)
Supported
variable
data types
CD: Compare data
(2 words)
LL: Lower limit of
range
UL: Upper limit of
range
UDINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
UDINT
---
UDINT
---
C: Control word
S1: 1st word of
present time
S2: 1st word of
comparison time
WORD
WORD
--Yes (3)
WORD
Yes (3)
Symbol
C
S1
S2
OR:
Symbol
C
S1
S2
2-6-6
Data Movement Instructions
Instruction
MOVE
DOUBLE MOVE
Mnemonic Function
code
MOV
@MOV
!MOV
[email protected]
021
MOVL
@MOVL
498
Symbol
Operands
MOV
S
AT setting or
array variable
required
(Required
word data size
shown in
parentheses.)
S: Source
D: Destination
WORD
WORD
-----
S: 1st source
word
DWORD
---
D: 1st destination word
DWORD
---
D
MOVL
S
D
62
Supported
variable
data types
Section 2-6
Instruction Support and Operand Restrictions
Instruction
MOVE NOT
Mnemonic Function
code
MVN
@MVN
022
Symbol
Operands
MVN
S
Supported
variable
data types
S: Source
WORD
AT setting or
array variable
required
(Required
word data size
shown in
parentheses.)
---
D: Destination
WORD
---
S: 1st source
word
D: 1st destination word
DWORD
---
DWORD
---
S: Source word
or data
C: Control word
WORD
---
UINT
---
D: Destination
word
WORD
---
S: Source word
or data
C: Control word
WORD
---
UINT
---
D: Destination
word
UINT
---
C: Control word
S: 1st source
word
D: 1st destination word
UINT
WORD
--Yes
(not fixed)
Yes
(not fixed)
N: Number of
words
UINT
---
S: 1st source
word
WORD
Yes
(not fixed)
D: 1st destination word
WORD
Yes
(not fixed)
S: Source word WORD
St: Starting word WORD
--Yes
(not fixed)
E: End word
WORD
Yes
(not fixed)
E1: 1st
exchange word
WORD
---
E2: Second
exchange word
WORD
---
E1: 1st
exchange word
DWORD
---
E2: Second
exchange word
DWORD
---
D
DOUBLE MOVE
NOT
MVNL
@MVNL
499
MVNL
S
D
MOVE BIT
MOVB
@MOVB
082
MOVB
S
C
D
MOVE DIGIT
MOVD
@MOVD
083
MOVD
S
C
D
MULTIPLE BIT
TRANSFERÅ@
XFRB
@XFRB
062
XFRB
C
S
D
BLOCK
TRANSFER
XFER
@XFER
070
XFER
N
S
D
BLOCK SET
BSET
@BSET
071
BSET
S
St
WORD
E
DATA EXCHANGE
XCHG
@XCHG
073
XCHG
E1
E2
DOUBLE DATA
EXCHANGE
XCGL
@XCGL
562
XCGL
E1
E2
63
Section 2-6
Instruction Support and Operand Restrictions
Instruction
SINGLE WORD
DISTRIBUTE
Mnemonic Function
code
DIST
@DIST
Symbol
080
Operands
DIST
S
Bs
Supported
variable
data types
S: Source word
WORD
Bs: Destination
base address
Of: Offset
WORD
UINT
AT setting or
array variable
required
(Required
word data size
shown in
parentheses.)
--Yes
(not fixed)
---
Of
DATA COLLECT
COLL
@COLL
081
COLL
Bs
Of
D
MOVE TO
REGISTER
MOVR
@MOVR
560
MOVR
S
D
MOVE TIMER/
COUNTER PV TO
REGISTER
MOVRW
561
@MOVRW
Not supported in function blocks
Bs: Source base WORD
address
Of: Offset
WORD
Yes
(not fixed)
---
D: Destination
word
WORD
---
S: Source
(desired word
orbit)
BOOL
---
D: Destination
WORD
(Index Register)
S: Source
--(desired TC
number)
D: Destination
--(Index Register)
2-6-7
---
---
Data Shift Instructions
Instruction
SHIFT REGISTER
Mnemonic Function
code
SFT
010
Symbol
Data input
Shift input
Reset input
REVERSIBLE
SHIFT REGISTER
SFTR
@SFTR
084
Operands
SFT
St
Supported
variable
data types
St: Starting word
UINT
E: End word
UINT
C: Control word
UINT
St: Starting word
E: End word
UINT
UINT
E
SFTR
C
St
E
64
---
AT setting or
array variable
required
(Required
word data size
shown in
parentheses.)
Yes (not fixed)
Yes (not fixed)
D1 and D2
must be the
same array variable when array
variables are
required.
--Yes (not fixed)
Yes (not fixed)
D1 and D2
must be the
same array variable when array
variables are
required.
Section 2-6
Instruction Support and Operand Restrictions
Instruction
ASYNCHRONOUS SHIFT
REGISTER
Mnemonic Function
code
ASFT
@ASFT
017
Symbol
Operands
ASFT
C
Supported
variable
data types
C: Control word
UINT
St: Starting word
E: End word
UINT
UINT
S: Source word
St: Starting word
WORD
UINT
E: End word
UINT
Wd: Word
UINT
Yes (not fixed)
D1 and D2
must be the
same array variable when array
variables are
required.
---
Wd: Word
UDINT
---
Wd: Word
UINT
---
Wd: Word
UDINT
---
Wd: Word
UINT
---
Wd: Word
UDINT
---
Wd: Word
UINT
---
Wd: Word
UDINT
---
Wd: Word
UINT
---
St
E
WORD SHIFT
WSFT
@WSFT
016
WSFT
S
St
E
ARITHMETIC
SHIFT LEFT
ASL
@ASL
025
ASL
AT setting or
array variable
required
(Required
word data size
shown in
parentheses.)
--Yes (not fixed)
Yes (not fixed)
D1 and D2
must be the
same array variable when array
variables are
required.
Yes (not fixed)
Wd
DOUBLE SHIFT
LEFT
ASLL
@ASLL
570
ASLL
Wd
ARITHMETIC
SHIFT RIGHT
ASR
@ASR
026
ASR
Wd
DOUBLE SHIFT
RIGHT
ASRL
@ASRL
571
ASRL
Wd
ROTATE LEFT
ROL
@ROL
027
ROL
Wd
DOUBLE
ROTATE LEFT
ROLL
@ROLL
572
ROLL
Wd
ROTATE LEFT
WITHOUT
CARRY
RLNC
@RLNC
DOUBLE
ROTATE LEFT
WITHOUT
CARRY
ROTATE RIGHT
RLNL
@RLNL
574
RLNC
Wd
576
RLNL
Wd
ROR
@ROR
028
ROR
Wd
65
Section 2-6
Instruction Support and Operand Restrictions
Instruction
DOUBLE
ROTATE RIGHT
Mnemonic Function
code
RORL
@RORL
573
Symbol
Operands
RORL
Supported
variable
data types
Wd: Word
UDINT
AT setting or
array variable
required
(Required
word data size
shown in
parentheses.)
---
Wd: Word
UINT
---
Wd: Word
UDINT
---
St: Starting word
E: End word
UINT
UINT
Yes (not fixed)
Yes (not fixed)
St: Starting word
E: End word
UINT
UINT
Yes (not fixed)
Yes (not fixed)
D: Beginning
word for shift
UINT
Yes (not fixed)
C: Beginning bit
N: Shift data
length
UINT
UINT
-----
D: Beginning
word for shift
C: Beginning bit
UINT
Yes (not fixed)
UINT
---
N: Shift data
length
UINT
---
D: Shift word
UINT
---
C: Control word
UINT
---
D: Shift word
C: Control word
UDINT
UINT
-----
D: Shift word
C: Control word
UINT
UINT
-----
D: Shift word
C: Control word
UDINT
UINT
-----
Wd
ROTATE RIGHT
WITHOUT
CARRY
RRNC
@RRNC
DOUBLE
ROTATE RIGHT
WITHOUT
CARRY
RRNL
@RRNL
ONE DIGIT
SHIFT LEFT
SLD
@SLD
575
RRNC
Wd
577
RRNL
Wd
074
SLD
St
E
ONE DIGIT
SHIFT RIGHT
SRD
@SRD
075
SRD
St
E
SHIFT N-BIT
DATA LEFT
NSFL
@NSFL
578
NSFL
D
C
N
SHIFT N-BIT
DATA RIGHT
NSFR
@NSFR
579
NSFR
D
C
N
SHIFT N-BITS
LEFT
NASL
@NASL
580
NASL
D
C
DOUBLE SHIFT
N-BITS LEFT
NSLL
@NSLL
582
NSLL
D
C
SHIFT N-BITS
RIGHT
NASR
@NASR
581
NASR
D
C
DOUBLE SHIFT
N-BITS RIGHT
NSRL
@NSRL
583
NSRL
D
C
66
Section 2-6
Instruction Support and Operand Restrictions
2-6-8
Increment/Decrement Instructions
Instruction
INCREMENT
BINARY
Mnemonic
++
@++
Function
code
Symbol
590
Operands
++
Supported
variable
data types
AT setting
or array
variable
required
(Required
word data
size
shown in
parentheses.)
Wd: Word
UINT
---
Wd: Word
UDINT
---
Wd: Word
UINT
---
Wd: 1st word
UDINT
---
Wd: Word
WORD
---
Wd: 1st word
DWORD
---
Wd: Word
DWORD
---
Wd: 1st word
WORD
---
Wd
DOUBLE INCREMENT BINARY
++L
@++L
591
++L
Wd
DECREMENT
BINARY
[email protected]
592
-Wd
DOUBLE DECREMENT BINARY
--L
@--L
593
--L
Wd
INCREMENT BCD
++B
@++B
594
++B
Wd
DOUBLE INCREMENT BCD
++BL
@++BL
595
++BL
Wd
DECREMENT BCD
--B
@--B
596
--B
Wd
DOUBLE DECREMENT BCD
--BL
@--BL
597
--BL
Wd
2-6-9
Symbol Math Instructions
Instruction
SIGNED BINARY
ADD WITHOUT
CARRY
Mnemonic
+
@+
Function
code
400
Symbol
Operands
+
Au
Supported
variable
data types
Au: Augend word
INT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
Ad: Addend word
R: Result word
INT
INT
-----
Ad
R
67
Section 2-6
Instruction Support and Operand Restrictions
Instruction
DOUBLE SIGNED
BINARY ADD
WITHOUT CARRY
Mnemonic
+L
@+L
Function
code
401
Symbol
Operands
Au: 1st augend
word
Ad: 1st addend
word
R: 1st result word
DINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
DINT
---
DINT
---
Au: Augend word
Ad: Addend word
INT
INT
-----
R: Result word
INT
---
Au: 1st augend
word
DINT
---
Ad: 1st addend
word
R: 1st result word
DINT
---
DINT
---
Au: Augend word
WORD
---
Ad: Addend word
R: Result word
WORD
WORD
-----
DWORD
---
DWORD
---
Ad
Au: 1st augend
word
Ad: 1st addend
word
R
R: 1st result word
DWORD
---
Au: Augend word
WORD
---
Ad: Addend word
R: Result word
WORD
WORD
-----
Au: 1st augend
word
Ad: 1st addend
word
R: 1st result word
DWORD
---
DWORD
---
DWORD
---
INT
INT
-----
INT
---
+L
Au
Ad
R
SIGNED BINARY
ADD WITH CARRY
+C
@+C
402
Supported
variable
data types
+C
Au
Ad
R
DOUBLE SIGNED +CL
BINARY ADD WITH @+CL
CARRY
403
+CL
Au
Ad
R
BCD ADD
WITHOUT CARRY
+B
@+B
404
+B
Au
Ad
R
DOUBLE BCD ADD +BL
WITHOUT CARRY @+BL
405
+BL
Au
BCD ADD WITH
CARRY
+BC
@+BC
406
+BC
Au
Ad
R
DOUBLE BCD ADD +BCL
WITH CARRY
@+BCL
407
+BCL
Au
Ad
R
SIGNED BINARY
SUBTRACT WITHOUT CARRY
@-
410
Mi
Su
R
68
Mi: Minuend word
Su: Subtrahend
word
R: Result word
Section 2-6
Instruction Support and Operand Restrictions
Instruction
DOUBLE SIGNED
BINARY SUBTRACT WITHOUT
CARRY
Mnemonic
-L
@-L
Function
code
411
Symbol
Operands
Supported
variable
data types
Mi: Minuend word
DINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
Mi
Su: Subtrahend
word
DINT
---
Su
R: Result word
DINT
---
Mi
Mi: Minuend word
Su: Subtrahend
word
INT
INT
-----
Su
R: Result word
INT
---
Mi: Minuend word
Su: Subtrahend
word
R: Result word
DINT
DINT
-----
DINT
---
-L
R
SIGNED BINARY
SUBTRACT WITH
CARRY
-C
@-C
412
-C
R
DOUBLE SIGNED
BINARY WITH
CARRY
-CL
@-CL
413
-CL
Mi
Su
R
BCD SUBTRACT
WITHOUT CARRY
-B
@-B
414
Mi: Minuend word
WORD
---
Su: Subtrahend
word
R: Result word
WORD
---
WORD
---
DWORD
---
DWORD
---
Su
Mi: 1st minuend
word
Su: 1st subtrahend
word
R
R: 1st result word
DWORD
---
-B
Mi
Su
R
DOUBLE BCD
SUBTRACT WITHOUT CARRY
BCD SUBTRACT
WITH CARRY
-BL
@-BL
415
-BL
Mi
-BC
@-BC
416
Mi: Minuend word
WORD
---
Mi
Su: Subtrahend
word
WORD
---
Su
R: Result word
WORD
---
DWORD
---
DWORD
---
R
Mi: 1st minuend
word
Su: 1st subtrahend
word
R: 1st result word
DWORD
---
*
Md: Multiplicand
word
INT
---
Mr: Multiplier word
R: Result word
INT
DINT
-----
-BC
R
DOUBLE BCD
SUBTRACT WITH
CARRY
-BCL
@-BCL
417
-BCL
Mi
Su
SIGNED BINARY
MULTIPLY
*
@*
420
Md
Mr
R
69
Section 2-6
Instruction Support and Operand Restrictions
Instruction
DOUBLE SIGNED
BINARY MULTIPLY
Mnemonic
*L
@*L
Function
code
421
Symbol
Operands
*L
Md
Mr
R
UNSIGNED
BINARY MULTIPLY
*U
@*U
422
Supported
variable
data types
Md: 1st multiplicand DINT
word
Mr: 1st multiplier
DINT
word
R: 1st result word
LINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
-------
UINT
---
Md
Md: Multiplicand
word
Mr: Multiplier word
UINT
---
Mr
R: Result word
UINT
---
*U
R
DOUBLE
UNSIGNED
BINARY
MULTIPLY
BCD MULTIPLY
*UL
@*UL
423
Md: 1st multiplicand UDINT
word
---
UDINT
---
R
Mr: 1st multiplier
word
R: 1st result word
ULINT
---
*B
Md: Multiplicand
word
WORD
---
Mr: Multiplier word
R: Result word
WORD
DWORD
-----
---
Mr
Md: 1st multiplicand DWORD
word
DWORD
Mr: 1st multiplier
word
R
R: 1st result word
LWORD
---
Dd: Dividend word
INT
---
Dr: Divisor word
R: Result word
INT
DWORD
--Yes (2)
INT must
be used
when
array variables are
required.
*UL
Md
Mr
*B
@*B
424
Md
Mr
R
DOUBLE BCD
MULTIPLY
*BL
@*BL
425
*BL
Md
SIGNED BINARY
DIVIDE
/
@/
430
/
Dd
Dr
R
70
---
Section 2-6
Instruction Support and Operand Restrictions
Instruction
DOUBLE SIGNED
BINARY DIVIDE
Mnemonic
/L
@/L
Function
code
431
Symbol
Operands
Supported
variable
data types
Dd
Dd: 1st dividend
DINT
word
Dr: 1st divisor word DINT
Dr
R: 1st result word
LWORD
Dd: Dividend word
UINT
Dr: Divisor word
R: Result word
UINT
DWORD
--Yes (2)
UINT must
be used
when
array variables are
required.
Dd: 1st dividend
word
UDINT
---
/L
R
UNSIGNED
BINARY DIVIDE
/U
@/U
432
/U
Dd
Dr
R
DOUBLE
UNSIGNED
BINARY DIVIDE
/UL
@/UL
433
/UL
Dd
Dr
Dr: 1st divisor word UDINT
R: 1st result word
LWORD
R
BCD DIVIDE
/B
@/B
434
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
/B
Dd
Dr
R
Dd: Dividend word
WORD
Dr: Divisor word
R: Result word
WORD
DWORD
--Yes (2)
DINT must
be used
when
array variables are
required.
---
--Yes (2)
UDINT
must be
used
when
array variables are
required.
----Yes (2)
WORD
must be
used
when
array variables are
required.
71
Section 2-6
Instruction Support and Operand Restrictions
Instruction
DOUBLE BCD
DIVIDE
Mnemonic
/BL
@/BL
Function
code
Symbol
435
Operands
Supported
variable
data types
Dd
Dd: 1st dividend
DWORD
word
Dr: 1st divisor word DWORD
Dr
R: 1st result word
/BL
LWORD
R
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
----Yes (2)
DWORD
must be
used
when
array variables are
required.
2-6-10 Conversion Instructions
Instruction
BCD-TO-BINARY
Mnemonic
BIN
@BIN
Function
code
023
Symbol
BIN
S
Operands
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
S: Source word
R: Result word
WORD
UINT
-----
S: 1st source word
R: 1st result word
DWORD
UDINT
-----
S: Source word
R: Result word
UINT
WORD
-----
S: 1st source word
UDINT
---
R: 1st result word
DWORD
---
S: Source word
WORD
---
R: Result word
UINT
---
R
DOUBLE BCD-TODOUBLE BINARY
BINL
@BINL
058
BINL
S
R
BINARY-TO-BCD
BCD
@BCD
024
BCD
S
R
DOUBLE BINARYTO-DOUBLE BCD
BCDL
@BCDL
059
BCDL
S
R
2’S COMPLEMENT
NEG
@NEG
160
NEG
S
R
72
Section 2-6
Instruction Support and Operand Restrictions
Instruction
DOUBLE 2’S COMPLEMENT
Mnemonic
NEGL
@NEGL
Function
code
161
Symbol
Operands
NEGL
S
Supported
variable
data types
S: 1st source word
DWORD
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
R: 1st result word
UDINT
---
S: Source word
R: 1st result word
WORD
DINT
-----
S: Source word
C: Control word
UINT
UINT
-----
R: 1st result word
UINT
Yes (not
fixed)
S: 1st source word
UINT
Yes (not
fixed)
R: Result word
C: Control word
UINT
UINT
-----
R
16-BIT TO 32-BIT
SIGNED BINARY
SIGN
@SIGN
600
SIGN
S
R
DATA DECODER
MLPX
@MLPX
076
MLPX
S
C
R
DATA ENCODER
DMPX
@DMPX
077
DMPX
S
R
C
ASCII CONVERT
ASC
@ASC
086
ASC
S
Di
S: Source word
UINT
---
Di: Digit designator
D: 1st destination
word
UINT
UINT
--Yes (3)
S: 1st source word
UINT
Yes (2)
D
ASCII TO HEX
HEX
@HEX
162
HEX
S
Di: Digit designator UINT
D: Destination word UINT
--Yes (not
fixed)
S: 1st source word
N: Bit number
Yes (16)
---
Di
D
COLUMN TO LINE
LINE
@LINE
063
LINE
S
WORD
UINT
D: Destination word UINT
---
S: Source word
D: 1st destination
word
N: Bit number
WORD
WORD
--Yes (16)
UINT
---
N
D
LINE TO COLUMN
COLM
@COLM
064
COLM
S
D
N
73
Section 2-6
Instruction Support and Operand Restrictions
Instruction
SIGNED BCD-TOBINARY
Mnemonic
BINS
@BINS
Function
code
470
Symbol
Operands
BINS
C
C: Control word
Supported
variable
data types
UINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
S: Source word
WORD
D: Destination word INT
-----
C: Control word
S: 1st source word
UINT
DWORD
-----
D: 1st destination
word
DINT
---
C: Control word
S: Source word
UINT
INT
-----
S
D
DOUBLE SIGNED
BCD-TO-BINARY
BISL
@BISL
472
BISL
C
S
D
SIGNED BINARYTO-BCD
BCDS
@BCDS
471
BCDS
C
D: Destination word WORD
---
C: Control word
UINT
---
S: 1st source word
D: 1st destination
word
DINT
DWORD
-----
S
D
DOUBLE SIGNED
BINARY-TO-BCD
BDSL
@BDSL
473
BDSL
C
S
D
2-6-11 Logic Instructions
Instruction
LOGICAL AND
Mnemonic
ANDW
@ANDW
Function
code
034
Symbol
Operand
ANDW
l1
Supported
variable
data types
I1: Input 1
WORD
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
I2: Input 2
R: Result word
WORD
WORD
-----
l2
R
DOUBLE LOGICAL
AND
ANDL
@ANDL
610
ANDL
l1
l2
R
74
I1: Input 1
DWORD
---
I2: Input 2
R: Result word
DWORD
DWORD
-----
Section 2-6
Instruction Support and Operand Restrictions
Instruction
LOGICAL OR
Mnemonic
ORW
@ORW
Function
code
035
Symbol
Operand
ORW
l1
Supported
variable
data types
I1: Input 1
WORD
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
I2: Input 2
R: Result word
WORD
WORD
-----
I1: Input 1
I2: Input 2
DWORD
DWORD
-----
R: Result word
DWORD
---
I1: Input 1
I2: Input 2
WORD
WORD
-----
R: Result word
WORD
---
l2
R
DOUBLE LOGICAL
OR
ORWL
@ORWL
611
ORWL
l1
l2
R
EXCLUSIVE OR
XORW
@XORW
036
XORW
l1
l2
R
DOUBLE EXCLUSIVE OR
XORL
@XORL
612
XORL
l1
I1: Input 1
DWORD
---
I2: Input 2
R: Result word
DWORD
DWORD
-----
I1: Input 1
WORD
---
I2: Input 2
R: Result word
WORD
WORD
-----
l2
R
EXCLUSIVE NOR
XNRW
@XNRW
037
XNRW
l1
l2
R
DOUBLE EXCLUSIVE NOR
XNRL
@XNRL
613
XNRL
l1
I1: Input 1
DWORD
---
I2: Input 2
R: Result word
DWORD
DWORD
-----
Wd: Word
WORD
---
Wd: Word
DWORD
---
l2
R
COMPLEMENT
COM
@COM
029
COM
Wd
DOUBLE COMPLEMENT
COML
@COML
614
COML
Wd
75
Section 2-6
Instruction Support and Operand Restrictions
2-6-12 Special Math Instructions
Instruction
BINARY ROOT
Mnemonic
ROTB
@ROTB
Function
code
Symbol
620
Operands
S: 1st source word
UDINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
R: Result word
UINT
---
S: 1st source word
DWORD
---
R: Result word
WORD
---
C: Control word
UINT
C
S: Source data
WORD
Yes (not
fixed)
---
S
R: Result word
WORD
---
Dd: 1st dividend
word
UDINT
---
Dr: 1st divisor word UDINT
R: 1st result word
UDINT
-----
ROTB
S
Supported
variable
data types
R
BCD SQUARE
ROOT
ROOT
@ROOT
072
ROOT
S
R
ARITHMETIC PROCESS
APR
@APR
069
APR
R
FLOATING POINT
DIVIDE
FDIV
@FDIV
079
FDIV
Dd
Dr
R
BIT COUNTER
BCNT
@BCNT
067
BCNT
N
N: Number of
words
UINT
---
S: 1st source word
UINT
Yes (not
fixed)
R: Result word
UINT
---
S
R
2-6-13 Floating-point Math Instructions
Instruction
FLOATING TO 16BIT
Mnemonic
FIX
@FIX
Function
code
450
Symbol
FIX
S
R
76
Operands
S: 1st source word
R: Result word
Supported
variable
data types
REAL
INT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
-----
Section 2-6
Instruction Support and Operand Restrictions
Instruction
FLOATING TO 32BIT
Mnemonic
FIXL
@FIXL
Function
code
451
Symbol
Operands
Supported
variable
data types
S: 1st source word
REAL
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
R: Result word
DINT
---
S: Source word
R: 1st result word
INT
REAL
-----
S: 1st source word
R: Result word
DINT
REAL
-----
Au: 1st augend
word
REAL
---
Ad: 1st addend
word
REAL
---
Ad
R
R: 1st result word
REAL
-----
Su
Mi: 1st Minuend
REAL
word
Su: 1st Subtrahend REAL
word
R
R: 1st result word
REAL
---
Md: 1st Multiplicand REAL
word
Mr: 1st Multiplier
REAL
word
R: 1st result word
REAL
---
FIXL
S
R
16-BIT TO FLOATING
FLT
@FLT
452
FLT
S
R
32-BIT TO FLOATING
FLTL
@FLTL
453
FLTL
S
R
FLOATING-POINT
ADD
+F
@+F
454
+F
Au
FLOATING-POINT
SUBTRACT
-F
@-F
455
-F
Mi
FLOATING- POINT
MULTIPLY
*F
@*F
456
*F
Md
Mr
R
FLOATING- POINT
DIVIDE
/F
@/F
457
---
-----
Dd
Dd: 1st Dividend
REAL
word
Dr: 1st Divisor word REAL
---
Dr
R: 1st result word
REAL
---
S: 1st source word
R: 1st result word
REAL
REAL
-----
S: 1st source word
R: 1st result word
REAL
REAL
-----
/F
---
R
DEGREES TO RADI- RAD
ANS
@RAD
458
RAD
S
R
RADIANS TO
DEGREES
DEG
@DEG
459
DEG
S
R
77
Section 2-6
Instruction Support and Operand Restrictions
Instruction
SINE
Mnemonic
SIN
@SIN
Function
code
460
Symbol
SIN
S
Operands
Supported
variable
data types
S: 1st source word
REAL
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
R: 1st result word
REAL
---
S: 1st source word
R: 1st result word
REAL
REAL
-----
S: 1st source word
R: 1st result word
REAL
REAL
-----
S: 1st source word
R: 1st result word
REAL
REAL
-----
S: 1st source word
REAL
---
R: 1st result word
REAL
---
R
COSINE
COS
@COS
461
COS
S
R
TANGENT
TAN
@TAN
462
TAN
S
R
ARC SINE
ASIN
@ASIN
463
ASIN
S
R
ARC COSINE
ACOS
@ACOS
464
ACOS
S
R
ARC TANGENT
ATAN
@ATAN
465
ATAN
S
S: 1st source word
REAL
---
R: 1st result word
REAL
---
S: 1st source word
R: 1st result word
REAL
REAL
-----
S: 1st source word
R: 1st result word
REAL
REAL
-----
S: 1st source word
R: 1st result word
REAL
REAL
-----
B: 1st base word
REAL
---
E: 1st exponent
word
R: 1st result word
REAL
---
REAL
---
R
SQUARE ROOT
SQRT
@SQRT
466
SQRT
S
R
EXPONENT
EXP
@EXP
467
EXP
S
R
LOGARITHM
LOG
@LOG
468
LOG
S
R
EXPONENTIAL
POWER
PWR
@PWR
840
PWR
B
E
R
78
Section 2-6
Instruction Support and Operand Restrictions
Instruction
Mnemonic
Floating Symbol
Comparison
LD, AND,
OR
+
=F, <>F, <F,
<=F, >F, >=F
Function
code
Symbol
329 (=F) Using LD:
330 (<>F)
Symbol, option
331 (<F)
S1
332 (<=F)
333 (>F)
S2
334 (>=F)
Operands
Supported
variable
data types
S1:Comparoson
data 1
S2:Comparison
data 2
REAL
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
REAL
---
S: 1st source word
REAL
Using AND:
Symbol, option
S1
S2
Using OR:
Symbol, option
S1
S2
FLOATING- POINT
TO ASCII
FSTR
@FSTR
448
FSTR
S
---
C: Control word
UINT
D: Destination word UINT
Yes (3)
Yes (not
fixed)
S: Source word
UINT
D: 1st destination
word
REAL
Yes (not
fixed)
---
C
D
ASCII TO FLOATING- FVAL
POINT
@FVAL
449
FVAL
S
D
79
Section 2-6
Instruction Support and Operand Restrictions
2-6-14 Double-precision Floating-point Instructions
Instruction
DOUBLE FLOATING
TO 16-BIT BINARY
Mnemonic
FIXD
@FIXD
Function
code
841
Symbol
FIXD
S
Operands
Supported
variable
data types
S: 1st source word LREAL
D: Destination
word
INT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
-----
D
DOUBLE FLOATING
TO 32-BIT BINARY
FIXLD
@FIXLD
842
FIXLD
S
S: 1st source word LREAL
---
D: 1st destination
word
DINT
---
S: Source word
INT
---
D: 1st destination
word
LREAL
---
D
16-BIT BINARY TO
DOUBLE FLOATING
DBL
@DBL
843
DBL
S
D
32-BIT BINARY TO
DOUBLE FLOATING
DBLL
@DBLL
844
S: 1st source word DINT
D: 1st destination
DINT
word
-----
Au: 1st augend
word
LREAL
---
Ad: 1st addend
word
LREAL
---
Ad
R
R: 1st result word
LREAL
---
-D
Mi: 1st minuend
word
LREAL
---
Su: 1st subtrahend word
LREAL
---
Su
R
R: 1st result word
LREAL
---
LREAL
---
LREAL
---
Mr
Md: 1st multiplicand word
Mr: 1st multiplier
word
R
R: 1st result word
LREAL
-----
Dd
Dd: 1st Dividend
LREAL
word
Dr: 1st divisor word LREAL
---
Dr
R: 1st result word
---
DBLL
S
D
DOUBLE FLOATING- +D
POINT ADD
@+D
845
+D
Au
DOUBLE FLOATING- -D
POINT SUBTRACT
@-D
846
Mi
DOUBLE FLOATING- *D
POINT MULTIPLY
@*D
847
*D
Md
DOUBLE FLOATING- /D
POINT DIVIDE
@/D
848
/D
R
80
LREAL
Section 2-6
Instruction Support and Operand Restrictions
Instruction
DOUBLE DEGREES
TO RADIANS
Mnemonic
RADD
@RADD
Function
code
849
Symbol
RADD
S
Operands
Supported
variable
data types
S: 1st source word LREAL
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
R: 1st result word
LREAL
---
S: 1st source word LREAL
R: 1st result word LREAL
-----
S: 1st source word LREAL
R: 1st result word LREAL
-----
S: 1st source word LREAL
R: 1st result word LREAL
-----
S: 1st source word LREAL
---
R: 1st result word
LREAL
---
S: 1st source word LREAL
---
R: 1st result word
LREAL
---
S: 1st source word LREAL
R: 1st result word LREAL
-----
S: 1st source word LREAL
R: 1st result word LREAL
-----
S: 1st source word LREAL
R: 1st result word LREAL
-----
S: 1st source word LREAL
---
R: 1st result word
---
R
DOUBLE RADIANS
TO DEGREES
DEGD
@DEGD
850
DEGD
S
R
DOUBLE SINE
SIND
@SIND
851
SIND
S
R
DOUBLE COSINE
COSD
@COSD
852
COSD
S
R
DOUBLE TANGENT
TAND
@TAND
853
TAND
S
R
DOUBLE ARC SINE
ASIND
@ASIND
854
ASIND
S
R
DOUBLE ARC
COSINE
ACOSD
@ACOSD
855
ACOSD
S
R
DOUBLE ARC TANGENT
ATAND
@ATAND
856
ATAND
S
R
DOUBLE SQUARE
ROOT
SQRTD
@SQRTD
857
SQRTD
S
R
DOUBLE EXPONENT
EXPD
@EXPD
858
EXPD
S
LREAL
R
81
Section 2-6
Instruction Support and Operand Restrictions
Instruction
DOUBLE LOGARITHM
Mnemonic
LOGD
@LOGD
Function
code
Symbol
859
Operands
Supported
variable
data types
S: 1st source word LREAL
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
R: 1st result word
LREAL
---
B
B: 1st base word
E: 1st exponent
word
LREAL
LREAL
-----
E
R: 1st result word
LREAL
---
S1:Comparoson
data 1
LREAL
---
S2:Comparison
data 2
LREAL
---
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
LOGD
S
R
DOUBLE EXPONEN- PWRD
TIAL POWER
@PWRD
860
PWRD
R
DOUBLE SYMBOL
COMPARISON
LD, AND,
OR
+
=D, <>D, <D,
<=D, >D,
>=D
335 (=D)
336 (<>D)
337 (<D)
338 (<=D)
339 (>D)
340 (>=D)
Using LD:
Symbol, option
S1
S2
Using AND:
Symbol, option
S1
S2
Using OR:
Symbol, option
S1
S2
2-6-15 Table Data Processing Instructions
Instruction
SET STACK
Mnemonic
SSET
@SSET
Function
code
630
Symbol
Operands
SSET
TB
N
82
TB: 1st stack
address
N: Number of
words
UINT
UINT
Yes (not
fixed)
---
Section 2-6
Instruction Support and Operand Restrictions
Instruction
Mnemonic
Function
code
Symbol
Operands
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
PUSH ONTO
STACK
PUSH
@PUSH
632
Not supported in function blocks
TB: 1st stack
address
S: Source word
-----
---
FIRST IN FIRST
OUT
FIFO
@FIFO
633
Not supported in function blocks
TB: 1st stack
address
---
---
LAST IN FIRST
OUT
LIFO
@LIFO
634
Not supported in function blocks
D: Destination word --TB: 1st stack
--address
-----
D: Destination word --N: Table number
# + decimal
only
LR: Length of each UINT
record
NR: Number of
UINT
records
-----
TB: 1st table word
UINT
Yes (not
fixed)
N: Table number
R: Record number
-----
-----
D: Destination
Index Register
---
---
N: Table number
IR: Index Register
-----
-----
DIMENSION
RECORD TABLE
DIM
@DIM
631
DIM
N
LR
NR
TB
SET RECORD
LOCATION
GET RECORD
NUMBER
DATA SEARCH
SETR
@SETR
GETR
@GETR
SRCH
@SRCH
635
636
181
Not supported in function blocks
Not supported in function blocks
-----
R1: 1st word in
range
UINT
Yes (not
fixed)
Cd: Comparison
data
WORD
---
N: Number of
words
R1: 1st word in
range
UINT
---
UINT
Yes (not
fixed)
C
C: 1st control word
R1: 1st word in
range
UDINT
UINT
--Yes (not
fixed)
R1
D: Destination word UINT
SRCH
R1
Cd
SWAP
@SWAP
637
SWAP
N
R1
FIND MAXIMUM
MAX
@MAX
182
---
D: Destination word --C: 1st control word UDINT
C
SWAP BYTES
---
MAX
---
D
83
Section 2-6
Instruction Support and Operand Restrictions
Instruction
FIND MINIMUM
Mnemonic
MIN
@MIN
Function
code
Symbol
183
Operands
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
C: 1st control word
UDINT
C
R1: 1st word in
range
UINT
R1
D: Destination word UINT
---
C: 1st control word
R1: 1st word in
range
UDINT
UINT
--Yes (not
fixed)
D: 1st destination
word
UDINT
---
C: 1st control word
R1: 1st word in
range
D: 1st destination
word
UDINT
UINT
--Yes (not
fixed)
---
TB: First stack
address
UINT
MIN
Yes (not
fixed)
D
SUM
SUM
@SUM
184
SUM
C
R1
D
FRAME CHECK
SUM
FCS
@FCS
180
FCS
C
R1
D
STACK SIZE READ
SNUM
@SNUM
638
SNUM
TB
UINT
Yes (not
fixed)
D: Destination word UINT
---
TB
TB: First stack
address
C: Offset value
Yes (not
fixed)
---
C
D: Destination word UINT
---
TB
TB: First stack
address
C: Offset value
UINT
Yes (not
fixed)
---
C
S: Source data
UINT
---
UINT
TB
TB: First stack
address
C: Offset value
UINT
Yes (not
fixed)
---
C
S: Source data
UINT
---
TB: First stack
address
UINT
Yes (not
fixed)
D
STACK DATA READ SREAD
@SREAD
639
SREAD
UINT
UINT
D
STACK DATA
OVERWRITE
SWRIT
@SWRIT
640
SWRIT
UINT
S
STACK DATA
INSERT
SINS
@SINS
641
SINS
S
STACK DATA
DELETE
SDEL
@SDEL
642
SDEL
TB
C
D
84
C: Offset value
UINT
D: Destination word UINT
-----
Section 2-6
Instruction Support and Operand Restrictions
2-6-16 Data Control Instructions
Instruction
PID CONTROL
Mnemonic
PID
Function
code
190
Symbol
S: Input word
UINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
C: 1st parameter
word
D: Output word
WORD
Yes (39)
UINT
---
S: Input word
UINT
---
S
C: 1st parameter
word
WORD
Yes (40)
C
D: Output word
UINT
---
S: Input word
INT
---
C: 1st limit word
D: Output word
DINT
INT
Yes (2)
---
S: Input word
C: 1st limit word
INT
UINT
--Yes (2)
D: Output word
UINT
---
S: Input word
C: 1st limit word
INT
UDINT
--Yes (2)
D: Output word
UINT
---
S: Input word
UINT
PID
S
C
Operands
Supported
variable
data types
D
PID CONTROL
WITH AUTO TUNING
PIDAT
191
PIDAT
D
LIMIT CONTROL
LMT
@LMT
680
LMT
S
C
D
DEAD BAND CONTROL
BAND
@BAND
681
BAND
S
C
D
DEAD ZONE CONTROL
ZONE
@ZONE
682
ZONE
S
C
D
TIME-PROPORTIONAL OUTPUT
TPO
685
TPO
S
C
WORD
C: 1st parameter
word
R: Pulse Output Bit BOOL
--Yes (7)
---
R
SCALING
SCL
@SCL
194
S: Input word
UINT
---
S
P1: 1st parameter
word
LWORD
Yes (2)
P1
R: Result word
WORD
---
SCL
R
85
Section 2-6
Instruction Support and Operand Restrictions
Instruction
SCALING 2
Mnemonic
SCL2
@SCL2
Function
code
Symbol
486
Operands
Supported
variable
data types
S: Source word
INT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
S
P1: 1st parameter
word
WORD
Yes (3)
P1
R: Result word
WORD
---
S
S: Source word
P1: 1st parameter
word
WORD
WORD
--Yes (3)
P1
R: Result word
INT
---
S: Source word
N: Number of
cycles
R: Result word
UINT
UINT
-----
UINT
Yes (not
fixed)
SCL2
R
SCALING 3
SCL3
@SCL3
487
SCL3
R
AVERAGE
AVG
195
AVG
S
N
R
2-6-17 Subroutine Instructions
Instruction
Mnemonic
Function
code
Symbol
Operands
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
SUBROUTINE CALL
SBS
@SBS
091
Not supported in function blocks
N: Subroutine num- --ber
---
SUBROUTINE
ENTRY
SBN
092
Not supported in function blocks
N: Subroutine num- --ber
---
SUBROUTINE
RETURN
MACRO
RET
093
---
---
MCRO
@MCRO
099
Not supported in function blocks
Not supported in function blocks
N: Subroutine num- --ber
S: 1st input param- --eter word
D: 1st output
--parameter word
---
N: Subroutine num- --ber
---
GLOBAL SUBROUTINE CALL
86
GSBS
@GSBS
750
Not supported in function blocks
-----
Section 2-6
Instruction Support and Operand Restrictions
Instruction
GLOBAL SUBROUTINE ENTRY
GLOBAL SUBROUTINE RETURN
Mnemonic
Function
code
GSBN
751
GRET
752
Symbol
Operands
Not supported in function blocks
Not supported in function blocks
Supported
variable
data types
N: Subroutine num- --ber
---
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
-----
2-6-18 Interrupt Control Instructions
Instruction
SET INTERRUPT
MASK
Mnemonic
MSKS
@MSKS
Function
code
690
Symbol
Operands
MSKS
N
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
N: Interrupt identifier
# + decimal
only
---
S: Interrupt data
UINT
---
S
READ INTERRUPT
MASK
MSKR
@MSKR
692
MSKR
N
N: Interrupt identi- # + decimal
fier
only
D: Destination word UINT
---
N: Interrupt identifier
S: Interrupt data
# + decimal
only
UINT
-----
---
---
---
---
---
---
---
D
CLEAR INTERRUPT
CLI
@CLI
691
CLI
N
S
DISABLE INTERRUPTS
ENABLE INTERRUPTS
DI
@DI
EI
693
694
DI
EI
87
Section 2-6
Instruction Support and Operand Restrictions
2-6-19 High-speed Counter and Pulse Output Instructions (CJ1M-CPU21/
22/23 Only)
Instruction
MODE CONTROL
Mnemonic
INI
@INI
Function
code
880
Symbol/Operands
INI
P
C
Function
Supported
variable
data types
P: Port specifier
WORD
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
C: Control data
NV: 1st word with
new PCV
UINT
DWORD
-----
P: Port specifier
WORD
---
C: Control data
D: 1st destination
word
UINT
WORD
--Yes (1 or
2)
C1: Control data
C2: Pulses/revolution
WORD
UINT
-----
D: 1st destination
word
UDINT
---
P: Port specifier
C: Control data
UINT
UINT
-----
TB: 1st comparison table word
LWORD
Yes (not
fixed)
P: Port specifier
M: Output mode
UINT
WORD
-----
F: 1st pulse frequency word
UDINT
---
P: Port specifier
UINT
---
T: Pulse type
N: Number of
pulses
UINT
DINT
-----
P: Port specifier
UINT
---
NV
HIGH-SPEED
COUNTER PV
READ
PRV
@PRV
881
PRV
P
C
D
COUNTER FREPRV2
QUENCY CONVERT
(CJ1M CPU Unit
Ver. 2.0 or later only)
COMPARISON
TABLE LOAD
CTBL
@CTBL
883
PRV2
C1
C2
D
882
CTBL
P
C
TB
SPEED OUTPUT
SPED
@SPED
885
SPED
P
M
F
SET PULSES
PULS
@PULS
886
PULS
P
T
N
PULSE OUTPUT
PLS2
@PLS2
887
PLS2
P
M
S
F
88
M: Output mode
WORD
S: 1st word of set- WORD
tings table
F: 1st word of start- UDINT
ing frequency
--Yes (6)
---
Section 2-6
Instruction Support and Operand Restrictions
Instruction
ACCELERATION
CONTROL
Mnemonic
ACC
@ACC
Function
code
Symbol/Operands
888
ACC
P
M
Function
Supported
variable
data types
P: Port specifier
UINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
M: Output mode
S: 1st word of settings table
UINT
WORD
--Yes (3)
P: Port specifier
C: Control data
UINT
WORD
-----
P: Port specifier
F: Frequency
UINT
UINT
-----
D: Duty factor
UINT
---
S
ORIGIN SEARCH
ORG
@ORG
889
ORG
P
C
PULSE WITH VARI- PWM
ABLE DUTY [email protected]
TOR
891
PWM
P
F
D
2-6-20 Step Instructions
Instruction
Mnemonic
Function
code
Symbol
Operands
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
STEP DEFINE
STEP
008
Not supported in function blocks
B: Bit
---
---
STEP START
SNXT
009
Not supported in function blocks
B: Bit
---
---
2-6-21 Basic I/O Unit Instructions
Instruction
I/O REFRESH
Mnemonic
IORF
@IORF
Function
code
097
Symbol
Not supported in function blocks
Operands
St: Starting word
E: End word
Supported
variable
data types
-----
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
-----
89
Section 2-6
Instruction Support and Operand Restrictions
Instruction
7-SEGMENT
DECODER
Mnemonic
SDEC
@SDEC
Function
code
078
Symbol
Operands
SDEC
S
Di
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
S: Source word
UINT
Di: Digit designator
D: 1st destination
word
UINT
UINT
--Yes (not
fixed)
I: Data input word
(D0 to D3)
O: Output word
UINT
---
UINT
---
D: 1st result word
C1: Number of digits
C2: System word
WORD
UINT
-----
WORD
---
D
DIGITAL SWITCH
INPUT
DSW
210
DSW
I
O
D
C1
C2
TEN KEY INPUT
TKY
211
TKY
I
D1
I: Data input word
UINT
---
D1: 1st register
word
UDINT
---
D2: Key input word
UINT
---
I: Data input word
O: Output word
UINT
UINT
-----
D2
HEXADECIMAL
KEY INPUT
HKY
212
HKY
I
D: 1st register word WORD
C: System word
WORD
Yes (3)
---
I: Data input word
O: Output word
UINT
UINT
-----
D: 1st destination
word
ULINT
Yes (3)
O
D
C: System word
WORD
---
S: 1st source word
WORD
Yes (2)
O: Output word
C: Control data
UINT
UINT
-----
D: System word
WORD
---
O
D
C
MATRIX INPUT
MTR
213
MTR
I
C
7-SEGMENT DISPLAY OUTPUT
7SEG
214
7SEG
S
O
C
D
90
Section 2-6
Instruction Support and Operand Restrictions
Instruction
INTELLIGENT I/O
READ
Mnemonic
IORD
@IORD
Function
code
Symbol
222
Operands
IORD
C
S
Supported
variable
data types
C: Control data
UINT
S: Transfer source
and number of
words
UDINT
D
D: Transfer destina- UINT
tion and number of
words
INTELLIGENT I/O
WRITE
IOWR
@IOWR
223
IOWR
C
S
D
CPU BUS UNIT I/O DLNK
REFRESH
@DLNK
226
DLNK
N
C: Control data
UINT
S: Transfer source WORD
and number of
words
D: Transfer destina- UINT
tion and number of
words
N: Unit number
UINT
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
--Yes (2)
UINT must
be used
when
array variables are
required.
Yes (not
fixed)
--Yes (not
fixed)
Yes (2)
UINT must
be used
when
array variables are
required.
---
2-6-22 Serial Communications Instructions
Instruction
Mnemonic
PROTOCOL MACRO PMCR
@PMCR
Function
code
260
Symbol
PMCR
C1
Operands
Supported
variable
data types
C1:Control word 1
UINT
C2: Control word 2
S: 1st send word
UINT
UINT
--Yes (not
fixed)
R: 1st receive word UINT
Yes (not
fixed)
C2
S
R
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
91
Section 2-6
Instruction Support and Operand Restrictions
Instruction
TRANSMIT
Mnemonic
TXD
@TXD
Function
code
236
Symbol
RXD
@RXD
235
S
C: Control word
UINT
C
N: Number of bytes UINT
0000 to 0100 hex(0
to 256 decimal)
---
D: 1st destination
word
Yes (not
fixed)
RXD
C
N
TXDU
@TXDU
256
TXDU
S
C
N
RECEIVE VIA
SERIAL COMMUNICATIONS UNIT
RXDU
@RXDU
255
RXDU
D
C
N
CHANGE SERIAL
PORT SETUP
STUP
@STUP
237
STUP
C
S
92
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
Yes (not
fixed)
---
UINT
D
TRANSMIT VIA
SERIAL COMMUNICATIONS UNIT
Supported
variable
data types
S: 1st source word
TXD
N
RECEIVE
Operands
UINT
C: Control word
UINT
N: Number of bytes UINT
to store 0000 to
0100 hex(0 to 256
decimal)
-----
S: 1st source word
UINT
Yes (not
fixed)
C: 1st control word
N: Number of send
bytes (4 digits
BCD)
D: 1st destination
word
C: 1st control word
UDINT
UINT
-----
UINT
UDINT
Yes (not
fixed)
---
N: Number of storage bytes
UINT
---
C: Control word
(port)
S: 1st source word
UINT
---
UINT
Yes (not
fixed)
Section 2-6
Instruction Support and Operand Restrictions
2-6-23 Network Instructions
Instruction
NETWORK SEND
Mnemonic
SEND
@SEND
Function
code
090
Symbol
SEND
S
D
Operands
Supported
variable
data types
S: 1st source word
UINT
D: 1st destination
word
UINT
Specify
address at
remote
node with
AT setting.
C: 1st control word
S: 1st source word
WORD
UINT
D: 1st destination
word
UINT
Yes (5)
Specify
address at
remote
node with
AT setting.
Yes (not
fixed)
C: 1st control word
S: 1st command
word
D: 1st response
word
C: 1st control word
WORD
UINT
C
NETWORK RECEIVE RECV
@RECV
098
RECV
S
D
C
DELIVER COMMAND CMND
@CMND
490
CMND
S
D
C
EXPLICIT MESSAGE EXPLT
SEND
720
EXPLT
S
D
C
EXPLICIT GET
ATTRIBUTE
EGATR
721
EGATR
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
Yes (not
fixed)
WORD
Yes (5)
Yes (not
fixed)
Yes (not
fixed)
Yes (6)
S: 1st word of send WORD
message
Yes (not
fixed)
D: 1st word of
received message
C: 1st control word
UINT
WORD
LWORD
S: 1st word of send ULINT
message
S
D
C
D: 1st word of
received message
WORD
C: 1st control word
message
LWORD
Yes (not
fixed)
Yes (4)
WORD
must be
used
when
array variables are
required.
Yes (4)
WORD
must be
used
when
array variables are
required.
Yes (not
fixed)
Yes (4)
93
Section 2-6
Instruction Support and Operand Restrictions
Instruction
EXPLICIT SET
ATTRIBUTE
Mnemonic
ESATR
Function
code
722
Symbol
ESATR
S
Operands
Supported
variable
data types
S: 1st word of send WORD
message
C: 1st control word WORD
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
Yes (not
fixed)
Yes (3)
C
EXPLICIT WORD
READ
ECHRD
723
ECHRD
S: 1st source word UINT
in remote CPU Unit
UINT
Specify
the destination
address
when
using AT
settings.
Yes (2)
WORD
Yes (5)
S: 1st source word
in local CPU Unit
UINT
Yes (not
fixed)
D: 1st destination
word in remote
CPU Unit
UINT
C: 1st control word
WORD
Specify
the destination
address
when
using AT
settings.
Yes (5)
S
D
C
D: 1st destination
word in local CPU
Unit
C: 1st control word
EXPLICIT WORD
WRITE
ECHWR
724
ECHWR
S
D
C
94
Section 2-6
Instruction Support and Operand Restrictions
2-6-24 File Memory Instructions
Instruction
READ DATA FILE
Mnemonic
FREAD
@FREAD
Function
code
700
Symbol
FREAD
Operand
C: Control word
Supported
variable
data types
UINT
S1: 1st source word LWORD
C
S1
S2
D
WRITE DATA FILE
FWRIT
@FWRIT
701
FWRIT
C
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
--Yes (2)
DWORD
must be
used
when
array variables are
required.
Yes (39)
S2: Filename
UINT
D: 1st destination
word
UINT
Yes (not
fixed)
C: Control word
D1: 1st destination
word
UINT
LWORD
D2: Filename
UINT
--Yes (2)
DWORD
must be
used
when
array variables are
required.
Yes (39)
S: 1st source word
UINT
D1
D2
S
Yes (not
fixed)
2-6-25 Display Instructions
Instruction
DISPLAY MESSAGE
Mnemonic
MSG
@MSG
Function
code
046
Symbol
MSG
N
M
Operands
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
N: Message number
UINT
---
M: 1st message
word
UINT
Yes (16)
95
Section 2-6
Instruction Support and Operand Restrictions
2-6-26 Clock Instructions
Instruction
CALENDAR ADD
Mnemonic
CADD
@CADD
Function
code
730
Symbol
Operands
Supported
variable
data types
CADD
C: 1st calendar
word
WORD
C
T: 1st time word
DWORD
Yes (2)
WORD
must be
used
when
array variables are
required.
R: 1st result word
C: 1st calendar
word
T: 1st time word
WORD
WORD
Yes (3)
Yes (3)
DWORD
R: 1st result word
WORD
Yes (2)
WORD
must be
used
when
array variables are
required.
Yes (3)
S: 1st source word
DWORD
D: 1st destination
word
DWORD
T
R
CALENDAR SUBTRACT
CSUB
@CSUB
731
CSUB
C
T
R
HOURS TO SECONDS
SEC
@SEC
065
SEC
S
D
96
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
Yes (3)
Yes (2)
WORD
must be
used
when
array variables are
required.
Yes (2)
WORD
must be
used
when
array variables are
required.
Section 2-6
Instruction Support and Operand Restrictions
Instruction
SECONDS TO
HOURS
Mnemonic
HMS
@HMS
Function
code
066
Symbol
HMS
Operands
Supported
variable
data types
S: 1st source word
DWORD
D: 1st destination
word
DWORD
S: 1st source word
LWORD
S
D
CLOCK ADJUSTMENT
DATE
@DATE
735
DATE
S
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
Yes (2)
WORD
must be
used
when
array variables are
required.
Yes (2)
WORD
must be
used
when
array variables are
required.
Yes (4)
WORD
must be
used
when
array variables are
required.
2-6-27 Debugging Instructions
Instruction
TRACE MEMORY
SAMPLING
Mnemonic
TRSM
Function
code
045
Symbol
TRSM
Operands
---
Supported
variable
data types
---
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
97
Section 2-6
Instruction Support and Operand Restrictions
2-6-28 Failure Diagnosis Instructions
Instruction
FAILURE ALARM
Mnemonic
FAL
@FAL
Function
code
006
Symbol
FAL
N
M
SEVERE FAILURE
ALARM
FALS
007
FALS
N
FPD
269
Supported
variable
data types
N: FAL number
# + decimal
only
M: 1st message
word or error code
to generate(#0000
to #FFFF)
N: FALS number
WORD
---
# + decimal
only
WORD
---
-----
-----
R: 1st register word ---
---
M: 1st message
word or error code
to generate(#0000
to #FFFF)
M
FAILURE POINT
DETECTION
Operands
Not supported in function blocks
C: Control word
T: Monitoring time
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
---
2-6-29 Other Instructions
Instruction
Mnemonic
SET CARRY
STC
@STC
CLEAR CARRY
CLC
@CLC
SELECT EM BANK EMBC
@EMBC
Function
code
040
041
281
Symbol
Operands
STC
CLC
EMBC
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
---
---
---
---
---
N: EM bank number.
UINT
---
T: Timer setting
Constants
only
---
---
---
---
---
---
---
N
EXTEND MAXIWDT
MUM CYCLE TIME @WDT
094
WDT
T
SAVE Condition
FlagS
LOAD Condition
FlagS
98
CCS
@CCS
CCL
@CCL
282
283
CCS
CCL
Section 2-6
Instruction Support and Operand Restrictions
Instruction
CONVERT
ADDRESS FROM
CV
CONVERT
ADDRESS TO CV
Mnemonic
FRMCV
@FRMCV
TOCV
@TOCV
DISABLE PERIPH- IOSP
ERAL SERVICING @IOSP
ENABLE PERIPH- IORS
ERAL SERVICING
Function
code
284
285
287
288
Symbol
Not supported in function blocks
Not supported in function blocks
IOSP
IORS
Operands
Supported
variable
data types
S: Word containing
CV-series memory
address
---
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
D: Destination
Index Register
S: Index Register
containing CS
Series memory
address
---
---
---
---
D: Destination word -------
-----
---
---
---
2-6-30 Block Programming Instructions
Instruction
Mnemonic
Function
code
Symbol
Operands
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
BLOCK PROGRAM
BEGIN
BPRG
096
Not supported in function blocks
N: Block program
number
---
---
BLOCK PROGRAM
END
BLOCK PROGRAM
PAUSE
BLOCK PROGRAM
RESTART
CONDITIONAL
BLOCK EXIT
BEND
801
---
---
---
BPPS
811
---
812
---
---
CONDITION EXIT
806
N: Block program
number
N: Block program
number
---
---
BPRS
Not supported in function blocks
Not supported in function blocks
Not supported in function blocks
Not supported in function blocks
---
---
CONDITIONAL
BLOCK EXIT
EXIT Bit
operand
806
Not supported in function blocks
B: Bit operand
---
---
CONDITIONAL
BLOCK EXIT (NOT)
EXIT NOT
Bit operand
806
Not supported in function blocks
B: Bit operand
---
---
CONDITIONAL
BLOCK BRANCHING
CONDITIONAL
BLOCK BRANCHING
CONDITIONAL
BLOCK BRANCHING (NOT)
CONDITION IF
IF Bit operand
IF NOT Bit
operand
802
Not supported in function blocks
Not supported in function blocks
Not supported in function blocks
---
---
---
B: Bit operand
---
---
B: Bit operand
---
---
802
802
99
Section 2-6
Instruction Support and Operand Restrictions
Instruction
Mnemonic
Function
code
Symbol
Operands
Supported
variable
data types
CONDITIONAL
BLOCK BRANCHING (ELSE)
ELSE
803
Not supported in function blocks
---
---
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
CONDITIONAL
BLOCK BRANCHING END
IEND
804
Not supported in function blocks
---
---
---
ONE CYCLE AND
WAIT
CONDITION WAIT
805
Not supported in function blocks
---
---
---
ONE CYCLE AND
WAIT
ONE CYCLE AND
WAIT (NOT)
TIMER WAIT
WAIT Bit
operand
WAIT NOT
Bit operand
TIMW
(BCD)
805
Not supported in function blocks
Not supported in function blocks
Not supported in function blocks
B: Bit operand
---
---
B: Bit operand
---
---
N: Timer number
---
---
TIMWX
(BIN)
816
SV: Set value
N: Timer number
-----
-----
CNTW
(BCD)
814
SV: Set value
--N: Counter number ---
-----
SV: Set value
I: Count input
-----
-----
CNTWX
(BIN)
817
Not supported in function blocks
N: Counter number --SV: Set value
---
-----
815
Not supported in function blocks
I: Count input
N: Timer number
-----
-----
SV: Set value
N: Timer number
-----
-----
SV: Set value
---
-----
-----
---
---
---
B: Bit operand
---
---
B: Bit operand
---
---
COUNTER WAIT
HIGH-SPEED TIMER TMHW
WAIT
(BCD)
805
813
Not supported in function blocks
Not supported in function blocks
TMHWX
(BIN)
818
Not supported in function blocks
LOOP
LOOP
809
LEND
LEND
810
LEND
LEND Bit
operand
810
Not supported in function blocks
Not supported in function blocks
Not supported in function blocks
LEND NOT
LEND NOT
Bit operand
810
100
Not supported in function blocks
Section 2-6
Instruction Support and Operand Restrictions
2-6-31 Text String Processing Instructions
Instruction
MOV STRING
Mnemonic
MOV$
@MOV$
Function
code
664
Symbol
+$
@+$
D: 1st destination
word
UINT
Yes (not
fixed)
S1: Text string 1
INT
S2: Text string 2
INT
Yes (not
fixed)
Yes (not
fixed)
D
D: First destination
word
INT
Yes (not
fixed)
LEFT$
S1: Text string first
word
UINT
Yes (not
fixed)
S2: Number of
characters
D: First destination
word
S1: Text string first
word
S2: Number of
characters
D: First destination
word
UINT
---
UINT
Yes (not
fixed)
Yes (not
fixed)
---
UINT
Yes (not
fixed)
S1: Text string first
word
UINT
Yes (not
fixed)
S2: Number of
characters
UINT
---
S3: Beginning position
D: First destination
word
S1: Source text
string first word
S2: Found text
string first word
UINT
---
UINT
Yes (not
fixed)
Yes (not
fixed)
Yes (not
fixed)
D: First destination
word
UINT
---
S: Text string first
word
UINT
Yes (not
fixed)
D: 1st destination
word
UINT
---
+$
S1
S2
GET STRING LEFT
LEFT$
@LEFT$
652
S1
S2
D
GET STRING
RIGHT
RGHT$
@RGHT$
653
RGHT$
S1
S2
D
GET STRING MIDDLE
MID$
@MID$
654
MID$
S1
S2
S3
D
FIND IN STRING
FIND$
@FIND$
660
FIND$
S1
S2
D
STRING LENGTH
LEN$
@LEN$
650
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
Yes (not
fixed)
UINT
S
656
Supported
variable
data types
S: 1st source word
MOV$
D
CONCATENATE
STRING
Operands
LEN$
S
D
UINT
UINT
UINT
UINT
101
Section 2-6
Instruction Support and Operand Restrictions
Instruction
REPLACE IN
STRING
Mnemonic
RPLC$
@RPLC$
Function
code
661
Symbol
RPLC$
S1
S2
S3
S4
D
DELETE STRING
DEL$
@DEL$
658
DEL$
S1
S2
S3
D
EXCHANGE
STRING
XCHG$
@XCHG$
665
XCHG$
Ex1
Ex2
CLEAR STRING
CLR$
@CLR$
666
CLR$
Operands
Supported
variable
data types
S1: Text string first UINT
word
S2: Replacement
UINT
text string first word
S3: Number of
UINT
characters
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
Yes (not
fixed)
Yes (not
fixed)
---
S4: Beginning posi- UINT
tion
---
D: First destination
word
UINT
Yes (not
fixed)
S1: Text string first
word
S2: Number of
characters
S3: Beginning position
D: First destination
word
UINT
UINT
Yes (not
fixed)
---
UINT
---
UINT
Yes (not
fixed)
Ex1: 1st exchange
word 1
UINT
Yes (not
fixed)
Ex2: 1st exchange
word 2
UINT
Yes (not
fixed)
S: Text string first
word
UINT
Yes (not
fixed)
S1: Base text string UINT
first word
Yes (not
fixed)
UINT
Yes (not
fixed)
---
S
INSERT INTO
STRING
INS$
@INS$
657
INS$
S1
S2
S3
D
String Comparison
102
LD,AND, OR 670 (=$)
+
671 (<>$)
=$,<>$,<$,< 672 (<$)
=$,>$,>=$
673 (<=$)
674 (>$)
675 (>=$)
Symbol
S1
S2
S2: Inserted text
string first word
S3: Beginning position
D: First destination
word
S1: Text string 1
UINT
S2: Text string 2
UINT
UINT
UINT
Yes (not
fixed)
Yes (not
fixed)
Yes (not
fixed)
Section 2-6
Instruction Support and Operand Restrictions
2-6-32 Task Control Instructions
Instruction
TASK ON
Mnemonic
TKON
@TKON
Function
code
820
Symbol
TKON
Operands
Supported
variable
data types
N: Task number
# + decimal
only
N: Task number
# + decimal
only
Operands
Supported
variable
data types
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
N
TASK OFF
TKOF
@TKOF
821
TKOF
---
N
2-6-33 Model Conversion Instructions
Instruction
BLOCK TRANSFER
Mnemonic
XFERC
@XFERC
Function
code
565
Symbol
XFERC
W
W: Number of
words (in BCD)
S: 1st source word
WORD
D: 1st destination
word
WORD
WORD
S
D
SINGLE WORD DIS- DISTC
TRIBUTE
@DISTC
566
DISTC
S1
D
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
--Yes (not
fixed)
Yes (not
fixed)
S1: Source word
WORD
D: Destination base WORD
address
S2: Offset (in BCD) WORD
--Yes (not
fixed)
---
S1: Source base
address
Yes (not
fixed)
S2
DATA COLLECT
COLLC
@COLLC
567
COLLC
S1
WORD
S2: Offset (in BCD) WORD
D: Destination word WORD
-----
WORD
---
WORD
---
C
S: Source word or
data
C: Control word (in
BCD)
D
D: Destination word WORD
---
S2
D
MOVE BIT
MOVBC
@MOVBC
568
MOVBC
S
103
Section 2-7
CPU Unit Function Block Specifications
Instruction
BIT COUNTER
Mnemonic
BCNTC
@BCNTC
Function
code
621
Symbol
Operands
BCNTC
W
Supported
variable
data types
W: Number of
words (in BCD)
S: 1st source word
WORD
D: Result word
WORD
UINT
S
D
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
--Yes (not
fixed)
---
2-6-34 Special Instructions for Function Blocks
Instruction
GET VARIABLE ID
Mnemonic
GETID
@GETIC
Function
code
286
Symbol
Operands
GETID
S
D1
D2
2-7
Supported
variable
data types
S: Source variable
or address
D1: Variable type
(I/O memory area)
code
WORD
AT
setting or
array
variable
required
(Required
word data
size
shown in
parentheses.)
---
WORD
---
D2: Word address
WORD
---
CPU Unit Function Block Specifications
The specifications of the functions blocks used in CS/CJ-series CS1-H, CJ1H, and CJ1M CPU Units with version 3.0 or later are as follows. Refer to the
other Operation Manuals for the CS/CJ Series for other specifications.
2-7-1
Specifications
CS1-H CPU Unit
Item
Model
I/O bits
Program capacity
(steps)
Data memory
104
Specification
CS1HCS1HCS1HCS1HCS1HCS1GCS1GCS1GCS1GCPU67H CPU66H CPU65H CPU64H CPU63H CPU45H CPU44H CPU43H CPU42H
5,120
250K
32K words
120K
60K
30K
20K
60K
1,280
30K
960
20K
10K
Section 2-7
CPU Unit Function Block Specifications
Item
Extended Data
Memory
32K
32K
words × words ×
13 banks 7 banks
32K
words ×
3 banks
Specification
32K words × 1 bank 32K
words ×
E0_00000 to
3 banks
E0_32767
E0_00000 E0_00000 E0_00000
to
to
to
EC_32767 E6_32767 E2_32767
32K words × 1 bank
E0_00000 to E0_32767
E0_00000
to
E2_32767
Function Maxi1,024
blocks
mum
number of
definitions
Maxi2,048
mum
number of
instances
1,024
1,024
1,024
128
1,024
1,024
128
128
2,048
2,048
2,048
256
2,048
2,048
256
256
Flash
memory
Function 1,664
block program
memory
(Kbytes)
Com128
ment files
(Kbytes)
1,664
1,024
512
512
1,024
512
512
512
128
64
64
64
64
64
64
64
Program 128
index files
(Kbytes)
128
64
64
64
64
64
64
64
Variable
tables
(Kbytes)
128
128
64
64
128
64
64
64
128
CJ1-H CPU Unit
Item
Specification
Model
CJ1HCPU67H
CJ1HCPU66H
CJ1HCPU65H
CJ1GCPU45H
CJ1GCPU44H
CJ1GCPU43H
CJ1GCPU42H
I/O bits
Program capacity
(steps)
Data memory
2,560
250K
120K
60K
1,280
60K
30K
960
20K
10K
32K words
Extended Data
Memory
32K words
× 13 banks
× 7 banks
× 3 banks
× 3 banks
32K words
32K words × 1 bank
E0_00000 to E0_32767
E0_00000
to
EC_32767
1,024
E0_00000
to
E6_32767
1,024
E0_00000
to
E2_32767
1,024
E0_00000
to
E2_32767
1,024
1,024
128
128
2,048
2,048
2,048
2,048
256
256
Function Maxiblocks
mum
number of
definitions
Maxi2,048
mum
number of
instances
32K words
32K words
105
Section 2-7
CPU Unit Function Block Specifications
Flash
memory
Item
Function 1,664
block program
memory
(Kbytes)
Com128
ment files
(Kbytes)
Program 128
index files
(Kbytes)
Variable
128
tables
(Kbytes)
1,664
1,024
Specification
1,024
512
512
512
128
64
64
64
64
64
128
64
64
64
64
64
128
128
128
64
64
64
CJ1M CPU Unit
Item
Units with internal I/O functions
Specification
Units without internal I/O functions
Model
I/O bits
CJ1M-CPU23
640
CJ1M-CPU22
320
CJ1M-CPU21
160
CJ1M-CPU13
640
CJ1M-CPU12
320
CJ1M-CPU11
160
Program capacity
(steps)
20K
10K
5K
20K
10K
5K
Number of Expansion Racks
Data memory
1 max.
Expansion not supported
1 max.
Expansion not supported
32K words
Extended Data
Memory
None
Pulse start times
46 µs (without acceleration/
deceleration)
70 µs (with acceleration/deceleration)
Number of scheduled interrupts
PWM outputs
Maximum value of
subroutine number
Maximum value of
jump number in JMP
instruction
Internal inputs
Internal outputs
106
2
63 µs (without
acceleration/
deceleration)
100 µs (with
acceleration/
deceleration)
1
2
1
2
1,024
1
256
None
1,024
256
1,024
256
1,024
256
---
10 points
--• 4 interrupt inputs (pulse catch)
• 2 high-speed counter inputs (50-kHz phase difference or 100-kHz single-phase)
6 points
• 2 pulse outputs (100 kHz)
• 2 PWM outputs
6 points
• 2 pulse outputs
(100 kHz)
• 1 PWM output
---
Section 2-7
CPU Unit Function Block Specifications
Item
Units with internal I/O functions
Specification
Units without internal I/O functions
Function Maxi128
blocks
mum
number of
definitions
Maxi256
mum
number of
instances
Flash
memory
Function 256
block program
memory
(Kbytes)
Com64
ment files
(Kbytes)
Program 64
index files
(Kbytes)
Variable
tables
(Kbytes)
2-7-2
64
Operation of Timer Instructions
There is an option called Apply the same spec as TO-2047 to T2048-4095 in
the PLC properties of CPU Units. This setting affects the operation of timers
as described in this section.
Selecting the Option
(Default)
If this option is selected, all timers will operate the same regardless of timer
number, as shown in the following table.
Timer Operation for Timer Numbers T0000 to T4095
Refresh
When instruction is
executed
Description
The PV is refreshed each time the instruction is executed.
If the PV is 0, the Completion Flag is turned ON. If it is not 0,
the Completion Flag is turned OFF.
When execution of all All PV are refreshed once each cycle.
tasks is completed
Every 80 ms
Not Selecting the
Option
If the cycle time exceeds 80 ms, all PV are refreshed once
every 80 ms.
If this option is not selected, the refreshing of timer instructions with timer
numbers T0000 to T2047 will be different from those with timer numbers
T2048 to T4095, as given below. This behavior is the same for CPU Units that
do not support function blocks. (Refer to the descriptions of individual instruction in the CS/CJ Series Instruction Reference for details.)
107
Number of Function Block Program Steps and Instance Execution Time
Section 2-8
Timer Operation for Timer Numbers T0000 to T2047
Refresh
When instruction is
executed
Description
The PV is refreshed each time the instruction is executed.
If the PV is 0, the Completion Flag is turned ON. If it is not 0,
the Completion Flag is turned OFF.
When execution of all All PV are refreshed once each cycle.
tasks is completed
Every 80 ms
If the cycle time exceeds 80 ms, all PV are refreshed once
every 80 ms.
Timer Operation for Timer Numbers T2048 to T4095
Refresh
When instruction is
executed
Description
The PV is refreshed each time the instruction is executed.
If the PV is 0, the Completion Flag is turned ON. If it is not 0,
the Completion Flag is turned OFF
When execution of all PV are not updated.
tasks is completed
Every 80 ms
PV are not updated even if the cycle time exceeds 80 ms.
Select the Apply the same spec as TO-2047 to T2048-4095 Option to ensure
consistent operation when using the timer numbers allocated by default to
function block variables (T3072 to T4095).
2-8
2-8-1
Number of Function Block Program Steps and Instance
Execution Time
Number of Function Block Program Steps (CPU Units with Unit
Version 3.0 or Later)
Use the following equation to calculate the number of program steps when
function block definitions have been created and the instances copied into the
user program using CS/CJ-series CPU Units with unit version 3.0 or later.
Number of steps
= Number of instances × (Call part size m + I/O parameter transfer part size n × Number of parameters) + Number of instruction steps in the function block definition p
(See note.)
Note
108
The number of instruction steps in the function block definition (p) will not be
diminished in subsequence instances when the same function block definition
is copied to multiple locations (i.e., for multiple instances). Therefore, in the
above equation, the number of instances is not multiplied by the number of
instruction steps in the function block definition (p).
Section 2-8
Number of Function Block Program Steps and Instance Execution Time
Contents
m
Call part
n
I/O parameter
transfer part
The data type is
shown in parentheses.
p
CS/CJ-series CPU Units
with unit version 3.0 or later
57 steps
1-bit I/O variable (BOOL)
1-word I/O variable (INT,
UINT, WORD)
2-word I/O variable (DINT,
UDINT, DWORD, REAL)
4-word I/O variable (LINT,
ULINT, LWORD, LREAL)
6 steps
6 steps
6 steps
12 steps
Number of instruc- The total number of instruction steps (same as standard
tion steps in func- user program) + 27 steps.
tion block definition
Example:
Input variables with a 1-word data type (INT): 5
Output variables with a 1-word data type (INT): 5
Function block definition section: 100 steps
Number of steps for 1 instance = 57 + (5 + 5) × 6 steps + 100 steps + 27 steps
= 244 steps
2-8-2
Function Block Instance Execution Time (CPU Units with Unit
Version 3.0 or Later)
Use the following equation to calculate the effect of instance execution on the
cycle time when function block definitions have been created and the
instances copied into the user program using CS/CJ-series CPU Units with
unit version 3.0 or later.
Effect of Instance Execution on Cycle Time
= Startup time (A)
+ I/O parameter transfer processing time (B)
+ Execution time of instructions in function block definition (C)
The following table shows the length of time for A, B, and C.
Operation
A
Startup time
B
I/O parameter transfer processing time
The data type is
indicated in parentheses.
C
[email protected]
[email protected]
Startup time not including 6.8 µs
I/O parameter transfer
CPU Unit model
[email protected]
[email protected]
8.8 µs
1-bit I/O variable (BOOL) 0.4 µs
0.7 µs
1-word I/O variable (INT, 0.3 µs
0.6 µs
UINT, WORD)
2-word I/O variable
0.5 µs
0.8 µs
(DINT, UDINT, DWORD,
REAL)
4-word I/O variable (LINT, 1.0 µs
1.6 µs
ULINT, LWORD, LREAL)
Function block defi- Total instruction processing time (same as standard user program)
nition instruction
execution time
[email protected]@
15.0 µs
1.0 µs
0.8 µs
1.1 µs
2.2 µs
Example: CS1H-CPU63H
Input variables with a 1-word data type (INT): 3
Output variables with a 1-word data type (INT): 2
Total instruction processing time in function block definition section: 10 µs
Execution time for 1 instance = 6.8 µs + (3 + 2) × 0.3 µs + 10 µs = 18.3 µs
109
Number of Function Block Program Steps and Instance Execution Time
Note
110
Section 2-8
The execution time is increased according to the number of multiple instances
when the same function block definition has been copied to multiple locations.
SECTION 3
Creating Function Blocks
This section describes the procedures for creating function blocks on the CX-Programmer.
3-1
Procedural Flow . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
112
3-2
Procedures . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
114
3-2-1
Creating a Project . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
114
3-2-2
Creating a New Function Block Definition . . . . . . . . . . . . . . . . . . .
114
3-2-3
Defining Function Blocks Created by User . . . . . . . . . . . . . . . . . . .
117
3-2-4
Creating Instances from Function Block Definitions . . . . . . . . . . . .
124
3-2-5
Setting Function Block Parameters Using the P Key . . . . . . . . . . . .
125
3-2-6
Setting the FB Instance Areas. . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
128
3-2-7
Checking Internal Address Allocations for Variables . . . . . . . . . . .
129
3-2-8
Copying and Editing Function Block Definitions . . . . . . . . . . . . . .
131
3-2-9
Checking the Source Function Block Definition from an Instance .
131
3-2-10 Checking the Size of the Function Block Definition . . . . . . . . . . . .
131
3-2-11 Compiling Function Block Definitions (Checking Program). . . . . .
131
3-2-12 Printing Function Block Definition . . . . . . . . . . . . . . . . . . . . . . . . .
132
3-2-13 Saving and Reusing Function Block Definition Files . . . . . . . . . . .
133
3-2-14 Downloading/Uploading Programs to the Actual CPU Unit . . . . . .
134
3-2-15 Monitoring and Debugging Function Blocks . . . . . . . . . . . . . . . . . .
134
111
Section 3-1
Procedural Flow
3-1
Procedural Flow
The following procedures are used to create function blocks, save them in
files, transfer them to the CPU Unit, monitor them, and debug them.
Creating Function Blocks
Create a Project
Refer to 3-2-1 Creating a Project for details.
■
1,2,3...
Creating a New Project
1. Start the CX-Programmer and select New from the File Menu.
2. Select a Device type: CS1G-H, CS1H-H, CJ1G-H, CJ1H-H, or CJ1M.
■
1,2,3...
Reusing an Existing CX-Programmer Project
1. Start the CX-Programmer, and read the existing project file (.cxp) created
using CX-Programmer Ver. 4.0 or earlier by selecting the file from the File
Menu.
2. Select a Device type: CS1H-H, CS1G-H, CJ1G-H, CJ1H-H, or CJ1M.
Create a Function Block
Definition
Refer to 3-2-2 Creating a New Function Block Definition for details.
1,2,3...
1. Select Function Blocks in the project workspace and right-click.
2. Select Insert Function Block - Ladder or Insert Function Blocks Structured Text from the popup menu.
Define the Function Block
Refer to 3-2-3 Defining Function Blocks Created by User for details.
■
1,2,3...
Registering Variables before Inputting the Ladder Program or ST Program
1. Register variables in the variable table.
2. Create the ladder program or ST program.
■
1,2,3...
Registering Variables as Necessary while Inputting the Ladder Program
or ST Program
1. Create the ladder program or ST program.
2. Register a variable in the variable table whenever required.
Refer to 3-2-4 Creating Instances from Function Block Definitions for details.
Create an Instance from
the Function Block
Definition
■
1,2,3...
Inserting Instances in the Ladder Section Window and then Inputting the
Instance Name
1. Place the cursor at the location at which to create an instance (i.e., a copy)
of the function block and press the F Key.
2. Input the name of the instance.
3. Select the function block definition to be copied.
■
1,2,3...
Registering Instance Names in the Global Symbol Table and then
Selecting the Instance Name when Inserting
1. Select Function Block as the data type for the variable in the global symbol
table.
2. Press the F Key in the Ladder Section Window.
3. Select the name of the instance that was registered from the pull-down
menu on the FB Instance Field.
112
Section 3-1
Procedural Flow
Allocate External I/O to
the Function Block
1,2,3...
Refer to 3-2-5 Setting Function Block Parameters Using the P Key for details.
1. Place the cursor at the position of the input variable or output variable and
press the P Key.
2. Input the source address for the input variable or the destination address
for the output variable.
Set the Function Block
Memory Allocations
(Instance Areas)
1,2,3...
Refer to 3-2-6 Setting the FB Instance Areas for details.
1. Select the instance and select Function Block Memory - Function Block
Memory Allocation from the PLC Menu.
2. Set the function block memory allocations.
Printing, Saving, and Reusing Function Block Files
Compile the Function
Block Definition and Save
It as a Library File
1,2,3...
Refer to 3-2-11 Compiling Function Block Definitions (Checking Program) and
3-2-13 Saving and Reusing Function Block Definition Files for details.
1. Compile the function block that has been saved.
2. Print the function block.
3. Save the function block as a function block definition file (.cxf).
4. Read the file into another PLC project.
Transferring the Program to the PLC
Refer to 3-2-14 Downloading/Uploading Programs to the Actual CPU Unit.
Monitoring and Debugging the Function Block
Refer to 3-2-15 Monitoring and Debugging Function Blocks.
113
Section 3-2
Procedures
3-2
3-2-1
Procedures
Creating a Project
Creating New Projects
with CX-Programmer
1,2,3...
1. Start the CX-Programmer and select New from the File Menu.
2. In the Change PLC Window, select a Device Type that supports function
blocks. These are listed in the following table.
Device
CPU
CS1G-H
CS1H-H
CPU42H/43H/44H/45H
CPU63H/64H/65H/66H/67H
CJ1G-H
CJ1H-H
CPU42H/43H/44H/45H
CPU65H/66H/67H
CJ1M
CPU11/12/13/21/22/23
Press the Settings Button and select the CPU Type. For details on other
settings, refer to the CX-Programmer Ver. 5.0 Operation Manual (W414).
3-2-2
Creating a New Function Block Definition
1,2,3...
1. When a project is created, a Function Blocks icon will appear in the project
workspace as shown below.
Function Blocks will appear under the PLC.
2. Function block definitions are created by inserting function block definitions after the Function Blocks icon.
Creating Function Block
Definitions
Function blocks can be defined by the user using either ladder programming
or structured text.
Creating (Inserting) Function Block Definitions with Ladders
1. Select Function Blocks in the project workspace, right-click, and select
Insert Function Blocks - Ladder from the popup menu. (Or select Function Block - Ladder from the Insert Menu.)
Creating (Inserting) Function Block Definitions with Structured Text
1. Select Function Blocks in the project workspace, right-click, and select
Insert Function Blocks - Structured Text from the popup menu. (Or select Function Block - Structured Text from the Insert Menu.)
114
Section 3-2
Procedures
FunctionBlock1 is displayed as the
Icon
under the Function Blocks Icon (
).
2. A function block called FunctionBlock1 will be automatically inserted either
after the
for ladder programming language (default) or the
for ST
language. This icon contains the definitions for the newly created (inserted) function block.
3. Whenever a function block definition is created, the name [email protected]
will be assigned automatically, where @ is a serial number. These names
can be changed. All names must contain no more than 64 characters.
Using OMRON FB Library Files
Use the following procedure to insert OMRON FB Library files (.cxf).
1. Select Function Blocks in the project workspace, right-click, and select
Insert Function Blocks - Library File from the popup menu. (Or select
Function Block - Library File from the Insert Menu.)
2. The following Select Function Block Library File Dialog Box will be displayed.
Note
To specify the default folder (file location) in the Function Block Library File Dialog Box, select Tools - Options, select the General
Tab and the select the default file in the OMRON FB library storage
location field.
3. Specify the folder in which the OMRON FB Library file is located, select the
library file, and click the Open Button. The library file will be inserted as a
function block definition after the
.
115
Section 3-2
Procedures
Function Block Definitions
Creating Function Block
Definitions
One of the following windows will be displayed when the newly created Function Block 1 icon is double-clicked (or if it is right-clicked and Open is selected
from the popup menu). A variable table for the variables used in the function
block is displayed on top and an input area for the ladder program or structured text is displayed on the bottom.
Ladder Program
Variable table
Ladder input area
Structured Text
Variable table
ST input area
As shown, a function block definition consists of a variable table that serves
as an interface and a ladder program or structured text that serves as an algorithm.
Variable Table as an Interface
At this point, the variable table is empty because there are no variables allocated for I/O memory addresses in the PLC.
Ladder Program or Structure Text as an Algorithm
• With some exceptions, the ladder program for the function block can contain any of the instructions used in the normal program. Refer to 2-3
Restrictions on Function Blocks for restrictions on the instructions that
can be used.
• Structured text can be input according to the ST language defined in
IEC61131-3.
Using OMRON FB Library
Files
116
Double-click the inserted function block library (or right-click and select Open
from the pop-up menu) to display the variable table that has finished being
created at the top right window, and the ladder program that has finished
being created in the bottom right window. Both windows are displayed in gray
and cannot be edited.
Section 3-2
Procedures
Variable table
Ladder program
Note
3-2-3
Function block definitions are not displayed in the default settings for OMRON
FB Library files (.cxf). To display definitions, select the Display the inside of
FB option in the function block properties. (Select the OMRON FB Library file
in the project workspace, right-click, select Properties, and select the Display the inside of FB option in the General Tab.)
Defining Function Blocks Created by User
A function block is defined by registering variables and creating an algorithm.
There are two ways to do this.
• Register the variables first and then input the ladder program or structure
text.
• Register variables as they are required while inputting input the ladder
program or structure text.
Registering Variables First
Registering Variables in
the Variable Table
The variables are divided by type into four sheets in the variable table: Internals, Inputs, Outputs, and Externals.
These sheets must be switched while registering or displaying the variables.
1,2,3...
1. Make the sheet for the type of variable to be registered active in the variable table. (See note.) Place the cursor in the sheet, right-click, and perform either of the following operations:
• To add a variable to the last line, select Insert Variable from the popup
menu.
• To add the variable to the line above or below a line within the list, select Insert Variable - Above or Below from the popup menu.
Note
The sheet where a variable is registered can also be switched
when inserting a variable by setting the usage (N: Internals, I: Inputs, O: Outputs, E: Externals).
The New Variable Dialog Box shown below will be displayed.
• Name: Input the name of the variable.
• Data Type: Select the data type.
• Usage: Select the variable type.
• Initial Value: Select the initial value of the variable at the start of operation.
• Retain: Select if the value of the variable is to be maintained when the
power is turned ON or when the operating mode is changed from
PROGRAM or MONITOR mode to RUN mode. The value will be
cleared at these times if Retain is not selected.
117
Section 3-2
Procedures
Input the name of the
function block variable
The default data type is BOOL.
Change as required.
Type of variable to register
(i.e., the sheet)
Initial value
Select to maintain value for
power interruptions.
Note (a) For user-defined external variables, the global symbol table can
be browsed by registering the same variable name in the global
symbol table.
(b) External variables defined by the system are registered in the external variable table in advance.
2. For example, input “aaa” as the variable name and click the OK Button.
As shown below, a BOOL variable called aaa will be created on the Inputs
Sheet of the Variable Table.
BOOL variable called aaa
created on Inputs Sheet.
Note
(1) After a variable is added, it can be selected to display in reverse video,
then moved to another line by dragging and dropping. To select a variable
for dragging and dropping, select the variable in any of the columns except the Name field.
(2) After inputting a variable, to move to the registered sheet, double-click,
and switch the setting in the Usage field (N: Internals, I: Inputs, O: Outputs, E: Externals). The variable can also be copied or moved between
the sheets for internal, external, input, and output variables. Select the
variable, right-click, and select Copy or Cut from the pop-up menu, and
then select Paste.
(3) Variable names must also be input for variables specified with AT (allocating actual address) settings.
(4) The following text is used to indicate I/O memory addresses in the PLC
and thus cannot be input as variable names in the function block variable
table.
• A, W, H, HR, D, DM, E, EM, T, TIM, C, or CNT followed by a numeric
value
118
Section 3-2
Procedures
Creating the Algorithm
1,2,3...
Using a Ladder Program
1. Press the C Key and select aaa registered earlier from the pull-down menu
in the New Contact Dialog Box.
Press the C Key and select aaa registered earlier
from the pull-down menu in the New Contact Dialog Box.
2. Click the OK Button. A contact will be entered with the function block internal variable aaa as the operand (variable type: internal).
Contact entered with function block
internal variable aaa as operand.
The rest of the ladder program is input in exactly the same way as for standard programs with CX-Programmer.
Note
Addresses cannot be directly input for instruction operands within function
blocks. Only Index Registers (IR) and Data Registers (DR) can be input
directly as follows (not as variables): Addresses DR0 to DR5, direct specifications IR0 to IR15, and indirect specifications ,IR0 to ,IR15.
Using Structured Text
An ST language program (see note) can either be input directly into the ST
input area or a program input into a general-purpose text editor can be copied
and then pasted into the ST input area using the Paste Command on the Edit
Menu.
Note
The ST language conforms to IEC61131-3. Refer to Appendix B Structured
Text (ST Language) Specifications for details.
119
Section 3-2
Procedures
ST program input directly or pasted from one
created in a text editor.
Note
(1) Tabs or spaces can be input to create indents. They will not affect the algorithm.
(2) The display size can be changed by holding down the Ctrl Key and turning the scrolling wheel on a wheel mouse.
(3) When an ST language program is input or pasted into the ST input area,
syntax keywords reserved words will be automatically displayed in blue,
comments in green, errors in red, and everything else in black.
(4) To change the font size or colors, select Options from the Tools Menu
and then click the ST Font Button on the Appearance Tab Page. The font
names, font size (default is 8 point) and color can be changed.
(5) For details on structured text specifications, refer to Appendix B Structured Text (ST Language) Specifications.
Registering Variables as Required
The ladder program or structured text program can be input first and variable
registered as they are required.
Using a Ladder Program
When using a ladder diagram, a dialog box will be displayed to register the
variable whenever a variable name that has not been registered is input. The
variable is registered at that time.
Use the following procedure.
1,2,3...
1. Press the C Key and input a variable name that has not been registered,
such as aaa, in the New Contact Dialog Box.
Note
Addresses cannot be directly input for instruction operands within
function blocks. Only Index Registers (IR) and Data Registers (DR)
can be input directly as follows (not as variables): Addresses DR0
to DR5, direct specifications IR0 to IR15, and indirect specifications
,IR0 to ,IR15.
2. Click the OK Button. The New Variable Dialog Box will be displayed. With
special instructions, a New Variable Dialog Box will be display for each operand in the instruction.
Set the data type and other
properties other than the name.
120
Section 3-2
Procedures
The properties for all input variables will initially be displayed as follows:
• Usage: Internal
• Data Type: BOOL for contacts and WORD for channel (word)
• Initial Value: The default for the data type.
• Retain: Not selected.
3. Make any required changes and click the OK Button.
4. As shown below, the variable that was registered will be displayed in the
variable table above the program.
Instruction input. Function block internal variable registered.
5. If the type or properties of a variable that was input are not correct, doubleclick the variable in the variable table and make the required corrections.
■ Reference Information
AT Settings (Specified Address)
AT settings can be made in the variable properties to specify allocation
addresses for Basic I/O Units, Special I/O Units, or CPU Bus Units, or Auxiliary Area addresses not registered using the CX-Programmer. A variable
name is required to achieve this. Use the following procedure to specify an
address.
1,2,3...
1. After inputting the variable name in the New Variable Dialog Box, click the
Advanced Button. The Advanced Settings Dialog Box will be displayed.
2. Select AT (Specified Address) under AT Settings and input the desired address.
Select AT.
Input address.
The variable name is used to enter variables into the algorithm in the function block definition even when they have an address specified for the AT
settings (the same as for variables without a specified address).
For example, if a variable named Restart has an address of A50100 specified for the AT settings, Restart is specified for the instruction operand.
Array Settings
An array can be specified to use the same data properties for more than one
variable and manage the variables as a group.
Use the following procedure to set an array.
121
Section 3-2
Procedures
1,2,3...
1. After inputting the variable name in the New Variable Dialog Box, click the
Advanced Button. The Advanced Settings Dialog Box will be displayed.
2. Select Array Variable in the Array Settings and input the maximum number
of elements in the array.
Select Array Variable.
Input the number of elements.
When the name of an array variable is entered in the algorithm in the function block definition, square brackets surrounding the index will appear after the array name.
For example, if you create a variable named PV with a maximum of 3 elements, PV[0], PV[1], and PV[2] could be specified as instruction operands.
There are three ways to specify indices.
• Directly with numbers, e.g., PV[1] in the above example (for ladder programming or ST language programming)
• With a variable, e.g., PV[a] in the above example, where “a” is the
name of a variable with a data type of INT (for ladder programming or
ST language programming)
• With an equation, e.g., PV[a+b] or PV[a+1} in the above example,
where “a” and “b” are the names of variables with a data type of INT
(for ST language programming only)
Using Structured Text
When using structured text, a dialog box will not be displayed to register the
variable whenever a variable name that has not been registered is input. Be
sure to always register variables used in standard text programming in the
variable table, either as you need them or after completing the program.
(Place the cursor in the tab page on which to register the variable, right-click,
and select Insert Variable from the popup menu.
Note
For details on structured text specifications, refer to Appendix B Structured
Text (ST Language) Specifications.
Copying User Program Circuits and Pasting in Ladder Programming of Function
Block Definitions
A single circuit or multiple circuits in the user program can be copied and
pasted in the ladder programming of function block definitions. This operation,
however, is subject to the following restrictions.
Source Instruction
Operand: Address Only
Note
122
Addresses are not registered in the function block definition variable tables.
After pasting, the addresses will be displayed in the operand in red. Doubleclick on the instruction and input the variable name into the operand.
Index Registers (IR) and Data Registers (DR), however, do not require modification after pasting and function in the operand as is.
Section 3-2
Procedures
Source Instruction
Operand: Address and I/O
Comment
Automatically generate symbol name Option Selected in Symbols Tab
under Options in Tools Menu
The user program symbol names (in the global symbol table only) will be generated automatically as AutoGen_ + Address (if the option is deselected, the
symbol names will be removed).
Example 1: For address 100.01, the symbol name will be displayed as
AutoGen_100_01.
Example 2: For address D0, the symbol name will be displayed as
AutoGen_D0.
If circuits in the user program are copied and pasted into the function block
definition program as is, the symbols will be registered automatically in the
function block definition symbol table (at the same time as copying the circuits) as the symbol name AutoGen_Address and I/O comments as Comment. This function enables programmed circuits to be easily reused in
function blocks as addresses and I/O comments.
Note
The prefix AutoGen_ is not added to Index Registers (IR) and Global Data
Registers (DR), and they cannot be registered in the original global symbol
table.
Automatically generate symbol name Option Not Selected in Symbols
Tab under Options in Tools Menu
Addresses and I/O comments are not registered in the function block definition variable tables. Addresses are displayed in the operand in red. I/O comments will be lost. Double-click on the instruction and input the symbol name
into the operand.
Index Registers (IR) and Data Registers (DR), however, do not require modification after pasting and function in the operand as is.
Source Instruction
Operand: Symbol
The user program symbol is automatically registered in the internal variables
of the function block definition variable table. This operation, however, is subject to the following restrictions.
Addresses
Symbol addresses are not registered. Use AT settings to specify the same
address.
Symbol Data Types
The symbol data types are converted when pasted from the user program into
the function block definition, as shown in the following table.
Symbol data type in user program
→
Variable data type after pasting in
function block program
WORD
CHANNEL
→
NUMBER
→
UINT BCD
→
The variable will not be registered,
and the value (number) will be pasted
directly into the operand as a constant.
WORD
UDINT BCD
ULINT BCD
→
→
DWORD
LWORD
Symbol data types CHANNEL, NUMBER, UINT BCD, UDINT BCD, or ULINT
BCD, however, cannot be copied from the symbol table (not the program) and
then pasted into the variable table in the function block definition.
123
Section 3-2
Procedures
Note
3-2-4
Symbols with automatically generated symbol names (AutoGen_ + Address)
cannot be copied from a global symbol table and pasted into the function
block definition symbol table.
Creating Instances from Function Block Definitions
If a function block definition is registered in the global symbol table, either of
the following methods can be used to create instances.
Method 1:Select the function block definition, insert it into the program, and
input a new instance name. The instance will automatically be registered in
the global symbol table.
Method 2: Set the data type in the global symbol table to “FUNCTION
BLOCK,” specify the function block definition to use, and input the instance
name to register it.
■ Method 1: Using the F Key in the Ladder Section Window and Inputting
the Instance Name
1,2,3...
1. In the Ladder Section Window, place the cursor in the program where the
instance is to be inserted and press the F Key. (Alternately, select Function Block Invocation from the Insert Menu.) The New Function Block Invocation Dialog Box will be displayed.
2. Input the instance name, select the function block from which to create an
instance, and click the OK Button.
Press F Key with cursor here.
Following dialog Input the instance name.
box is displayed.
Select the function block from
which to create an instance.
3. As an example, set the instance name in the FB Instance Field to sample,
set the function block in the FB Definition Field to FunctionBlock1, and
click the OK Button. As shown below, a copy of the function block definition
called FunctionBlock1 will be created with an instance name of sample.
Instance name
Function block definition
An instance called sample
is created from the function
block definition called
FunctionBlock1.
The instance will be automatically registered in the global symbol table
with an instance name of sample and a data type of FUNCTION BLOCK.
124
Section 3-2
Procedures
■ Method 2: Registering the Instance Name in the Global Symbol Table in
Advance and Then Selecting the Instance Name
If the instance name is registered in the global symbol table in advance, the
instance name can be selected from the global symbol table to create other
instances.
1,2,3...
1. Select a data type of Function block in the global symbol table, input the
instance name, and registered the instance.
2. Press the F Key in the Ladder Section Window. The Function Block Invocation Dialog Box will be displayed.
3. Select the instance name that was previously registered from the pulldown
menu on the FB Instance Field. The instance will be created.
Restrictions
Observe the following restrictions when creating instances. Refer to 2-3
Restrictions on Function Blocks for details.
• No more than one function block can be created in each program circuit.
• The rung cannot be branched to the left of an instance.
• Instances cannot be connected directly to the left bus bar, i.e., an EN
must always be inserted.
Note
3-2-5
If changes are made in the I/O variables in a variable table for a function block
definition, the bus bar to the left of all instances that have been created from
that function block definition will be displayed in red to indicate an error. When
this happens, select the function block, right-click, and select Update Invocation. The instance will be updated for any changes that have been made in
the function block definition and the red bus bar display indicating an error will
be cleared.
Setting Function Block Parameters Using the P Key
After an instance of a function block has been created, input parameters must
be set for input variables and output parameters must be set for output variables to enable external I/O.
• Values, addresses, and program symbols (global symbols and local symbols) can be set in input parameters. (See note a.)
• Addresses and program symbols (global symbols and local symbols) can
be set in output parameters. (See note b.)
Note (a) The function block’s input variable data size and the program’s
symbol data size must match.
(b) The function block’s output variable data size and the program’s
symbol data size must match.
1,2,3...
1. Inputs are located on the left of the instance and outputs on the right. Place
the cursor where the parameter is to be set and press the P Key. (Alternately, select Function Block Parameter from the Insert Menu.) The New
Parameter Dialog Box will be displayed as shown below.
125
Section 3-2
Procedures
Instance name
Function block definition
Press the P Key with the cursor on the left
of the instance. The New Parameter
Dialog Box will be displayed.
Input the address from which to pass data
to the input variable.
2. Set the source address from which to pass the address data to the input
variable. Also set the destination address to which the address data will be
passed from the output variable.
The value of 001 is passed to input
variable aaa.
Note
Set the data in all the input parameters. If even a single input parameter
remains blank, the left bus bar for the instance will be displayed in red to indicate an error. If this happens, the program cannot be transferred to the CPU
Unit.
Inputting Values in Parameters
The following table lists the methods for inputting values in parameters.
Input variable data
type
Content
Size
BOOL
INT
Bit data
Integer
1 bit
16 bits
DINT
Double integer
32 bits
LINT
Long (4-word) inte- 64 bits
ger
Input method
Setting range
UINT
Unsigned integer
16 bits
UDINT
Unsigned double
integer
32 bits
P_Off, P_On
0 (FALSE), 1 (TRUE)
Positive value: & or + followed −32768 to +32767
by integer
−2147483648 to +2147483647
Negative value: − followed by
−9223372036854775808 to
integer
+9223372036854775807
Positive value: & or + followed &0 to 65535
by integer
&0 to 4294967295
ULINT
Unsigned long (4word) integer
64 bits
&0 to 18446744073709551615
126
Section 3-2
Procedures
Input variable data
Content
type
REAL
Real number
32 bits
LREAL
Long real number
64 bits
WORD
16-bit data
16 bits
# followed by hexadecimal
number (4 digits max.)
& or + followed by decimal
number
#0000 to FFFF or &0 to 65535
DWORD
32-bit data
32 bits
#00000000 to FFFFFFFF or &0
to 4294967295
LWORD
64-bit data
64 bits
# followed by hexadecimal
number (8 digits max.)
& or + followed by decimal
number
# followed by hexadecimal
number (16 digits max.)
& or + followed by decimal
number
Note
Size
Input method
Setting range
Positive value: & or + followed
by real number (with decimal
point)
−3.402823 × 1038 to −1.175494
× 10−38, 0, +1.175494 × 10−38
to +3.402823 × 1038
−1.79769313486232 × 10308 to
−2.22507385850720 × 10−308,
−
0, +2.22507385850720 × 10 308
to +1.79769313486232 × 10308
Negative value: − followed by
real number (with decimal
point)
#0000000000000000 to
FFFFFFFFFFFFFFFF or &0 to
18446744073709551615
If a non-boolean data type is used for the input variable and only a numerical
value (e.g., 20) is input, the value for the CIO Area address (e.g, CIO 0020)
will be passed, and not the numerical value. To set a numerical value, always
insert an &, #, + or − prefix before inputting the numerical value.
Example Programs:
Instance for function block definition A
10
( INT )
DATA_1
If the data format for DATA_1 is INT, and "10" is input,
the value for CIO 0010 will be passed.
Instance for function block definition A
&10
( INT )
DATA_1
If the data format for DATA_1 is INT, and the prefix &
is added so that "&10" is input, the numerical value
will be passed.
If the input variable data type is boolean and a numerical value only (e.g.,
0 or 1) is input in the parameter, the value for CIO 000000 (0.00) or
CIO 000001 (0.01) will be passed. Always input P_Off for 0 (OFF) and
P_On for 1 (ON).
127
Section 3-2
Procedures
3-2-6
Setting the FB Instance Areas
The areas where addresses for variables used in function blocks are allocated
can be set. These areas are called the function block instance areas.
1,2,3...
1. Select the instance in the Ladder Section Window or in the global symbol
table, and then select Function Block Memory - Function Block Memory Allocation from the PLC Menu.
The Function Block Memory Allocation Dialog shown below will appear.
2. Set the FB instance areas.
Non-retained area
Retained area
Timer area
Counter area
First
address
Last
address
Size
The non-retained and retained areas are set in words. The timer and
counter areas are set by time and counter numbers.
The default values are as follows:
FB Instance
Area
Applicable memory
areas
Start Address End Address
H512 (See
H1407 (See
note 2.)
note 2.)
Size
896
CIO, WR, HR, DM, EM
Retain (See
note 1.)
Timers
H1408 (See
note 2.)
T3072
H1535 (See
note 2.)
T4095
128
HR, DM, EM
1024
TIM
Counters
C3072
C4095
1024
CNT
Non Retain
(See notes 1
and 3.)
Note
Default value
(1) Bit data can be accessed even if the DM or EM Area is specified for the
non-retained area or retained area.
(2) The Function Block Holding Area words are allocated in H512 to H1535.
These words cannot be specified in instruction operands in the user program. These words can also not be specified in the internal variable’s AT
settings.
(3) Words H512 to H1535 are contained in the Holding Area, but the addresses set as non-retained will be cleared when the power is turned
OFF and ON again or when operation is started.
(4) To prevent overlapping of instance area addresses and addresses used
in the program, set H512 to H1535 (Function Block Holding Area words)
for the non-retained area and retained area. If another area is set, the addresses may overlap with addresses that are used in the user program.
If the addresses in the function block instance areas overlap with any of
the addresses used in the user program, an error will occur when compiling. This error will also occur when a program is downloaded, edited online, or checked by the user.
128
Section 3-2
Procedures
Work Area Addresses
used in the user
program overlap with
the instance areas.
If addresses are duplicated and an error occurs, either change the function
block instance areas or the addresses used in the user program.
3-2-7
Checking Internal Address Allocations for Variables
The following procedure can be used to check the I/O memory addresses
internally allocated to variables.
1,2,3...
1. Select View - Symbols - Global.
2. Select the instance in the global symbol table, right-click, and select Function Block Memory Address from the popup menu. (Alternately, select
Function Block Memory - Function Block Memory Address from the
PLC Menu.)
Example: Instance name displayed in global variable table (automatically registered)
Right-click on the instance name and select Function Block Instance Address.
3. The FB Interface Memory Dialog Box will be displayed. Check the I/O
memory addresses internally allocated to variables here.
Example: Addresses used internally
for the input variables.
129
Section 3-2
Procedures
Method Used for Checking Addresses Internally Allocated to Variables
Program
Instance of function block definition A,
instance name: sample
a
b
c
Instance registered in global
symbol table under instance name.
Name Type
sample FB [FunctionBlock1]
Right-click and select Function
Block Memory Address.
FM Instance Memory Dialog Box
Address/
Value
N/A [Auto]
Instance name
Inputs
Name Type
a
BOOL
Address
W400.00
Outputs
Name Type
b
BOOL
c
BOOL
Address
W401.00
W401.02
Addresses used for function
block internal variables
Checking the Status of
Addresses Internally
Allocated to Variables
1,2,3...
The following procedure can be used to check the number of addresses allocated to variables and the number still available for allocation in the function
block instance areas.
1. Select the instance in the Ladder Section Window, right-click, and select
Function Block Memory - Function Block Memory Statistics from the
PLC Menu.
2. The Function Block Memory Statistics Dialog Box will be displayed as
shown below. Check address usage here.
The total number
The number of
of words in each The number words still available.
interface area. of words
already used.
Optimizing Function
Memory
1,2,3...
When a variable is added or deleted, addresses are automatically re-allocated
in the variables’ instance area. Consecutive addresses are required for each
instance, so all of the variables will be allocated to a different block of
addresses if the original block of addresses cannot accommodate the change
in variables. This will result in an unused block of addresses. The following
procedure can be used to eliminate the unused areas in memory so that
memory is used more efficiently.
1. Select the instance in the Ladder Section Window, right-click, and select
Function Block Memory - Optimize Function Memory from the PLC
Menu.
The following dialog box will be displayed.
2. Click the OK Button. Allocations to the function block instance areas will
be optimized.
130
Section 3-2
Procedures
3-2-8
Copying and Editing Function Block Definitions
Use the following operation to copy and edit the function block definition that
has been created.
1. Select the function block to copy, right-click, and select Copy from the popup menu.
2. Position the cursor over the function block item under the PLC in the
project directory, right-click and select Paste from the pop-up menu.
3. The function block definition will be copied (“copy” is indicated before the
name of the function block definition at the copy source).
4. To change the function block name, left-click or right-click and select Rename from the pop-up menu.
5. Double-click the function block definition to edit it.
3-2-9
Checking the Source Function Block Definition from an Instance
Use the following procedure to check the function block definition from which
an instance was created.
1,2,3...
Right-click the instance and select Go To - Function Block Definition from
the popup menu. The function block definition will be displayed.
3-2-10 Checking the Size of the Function Block Definition
CX-Programmer can be used to check the size of the function block definition
being created using a similar method to checking the program capacity. The
procedure is as follows:
1. Select Memory View from the View Menu.
2. The function block definition size and number of function block definitions
will be displayed in the Memory View Dialog Box as shown below.
• The Used FB, Free FB, and Total fields under Function Block refer to the
size of the function block definitions. The values are displayed in step
units. 1 step = 4 bytes, so the function block source memory capacity (K
bytes) in the CPU Unit’s internal flash memory is the value multiplied by
1,024 and divided by 4.
• The Used #, Free #, and Max # fields under Function Block refer to the
number of function block definitions.
3-2-11 Compiling Function Block Definitions (Checking Program)
A function block definition can be compiled to perform a program check on it.
Use the following procedure.
1,2,3...
Select the function block definition, right-click, and select Compile from the
popup menu. (Alternately, press the Ctrl + F7 Keys.)
The function block will be compiled and the results of the program check will
be automatically displayed on the Compile Table Page of the Output Window.
131
Section 3-2
Procedures
Results of program check displayed.
3-2-12 Printing Function Block Definition
Use the following procedure to print function block definitions.
1,2,3...
1. Double-click the function block definition to be printed, and with the variable table and algorithm displayed, select Print from the File Menu. The
following Target Print Rung Dialog Box will be displayed.
2. Select the All Rung or Select Rung option. When the Select Rung option
is selected, specify the start rung and end rung numbers. When a page
number has been specified in the header and footer fields in File - Page
Setup, the first page number can be specified.
3. Select either of the following options for the function block printing range.
• Symbol table and program (default)
• Symbol table
• Program
4. Click the OK Button, and display the Print Dialog Box. After setting the
printer, number of items to print and the paper setting, click the OK button.
5. The following variable table followed by the algorithm (e.g, ladder programming language) will be printed.
132
Section 3-2
Procedures
Note
For details on print settings, refer to the section on printing in the CX-Programmer Ver. 5.0 Operation Manual (W437).
3-2-13 Saving and Reusing Function Block Definition Files
The function block definition that has been created can be saved independently as a function block library file (*.cxf) to enable reusing it in other
projects.
Note
Saving a Function Block
Library File
1,2,3...
Before saving to file, or reusing in another project, compile the function block
definition and perform a program check.
Use the following procedure to save a function block definition to a function
block library file.
1. Select the function block definition, right-click, and select Save Function
Block to File from the popup menu. (Alternately, select Function Block Save Function Block to File from the File Menu.)
2. The following dialog box will be displayed. Input the file name. Function
Block Library Files (*.cxf) should be selected as the file type.
Reading Function Block
Library Files into Other
Projects
1,2,3...
Use the following procedure to read a function block library file (*.cxf) into a
project.
1. Select the function block definition item under the PLC directory in the
Project Workspace, right-click, and select Insert Function Block - From
File from the popup menu (or select File - Function Block - Load Function Block from File).
2. The following dialog box will be displayed. Select a function block library
file (*.cxf) and click the Open Button.
133
Section 3-2
Procedures
3. A function block called FunctionBlock1 will be automatically inserted after
the Function Blocks icon. This icon contains the definition of the function
block.
4. Double-click the FunctionBlock1 Icon. The variable table and algorithm
will be display.
3-2-14 Downloading/Uploading Programs to the Actual CPU Unit
After a program containing function blocks has been created, it can be downloaded from the CX-Programmer to an actual CPU Unit that it is connected to
online. Programs can also be uploaded from the actual CPU Unit. It is also
possible to check if the programs on the CX-Programmer Ver. 5.0 (personal
computer) and in the actual CPU Unit are the same. When the program contains function blocks, however, downloading in task units is not possible
(uploading is possible).
3-2-15 Monitoring and Debugging Function Blocks
The following procedures can be used to monitor programs containing function blocks.
Monitoring Programs in
Function Block Definitions
Use the following procedure to check the program in the function block definition for an instance during monitoring.
1,2,3...
Right-click the instance and select Go To - Function Block Definition from
the popup menu. The function block definition will be displayed.
Monitoring Instance
Variables in the Watch
Window
1,2,3...
Use the following procedure to monitor instance variables.
1. Select View - Window - Watch.
A Watch Window will be displayed.
2. Double-click the watch window.
The Edit Dialog Box will be displayed as shown below.
Click the Browse Button.
Note
134
The instance variable is displayed as the instance name and variable name.
Section 3-2
Procedures
3. Click the Browse Button, select the variable to be monitored, and click the
OK Button.
Select the variable to monitor.
Note
Instance
variables
variable_name.
are
displayed
as
instance_name,
4. Click the OK Button. Variable values will be display in the Watch Window
as shown below.
Address being used
Variable name
Monitoring Instance I/O
Variables
The present values of parameters for I/O variables are displayed below the
parameters.
PV of parameter for I/O variable.
Editing Function Block
Definition Programs
Online
Programs using function blocks can be edited online. Changes can also be
made around instances.
• Instance parameters can be changed, instances can be deleted, and
instructions other than those in instances can be changed.
• Instances cannot be added, instance names cannot be changed, and
algorithms and variable tables in function block definitions cannot be
changed.
135
Procedures
136
Section 3-2
Appendix A
Data Types
Basic Data Types
Data type
BOOL
Bit data
Content
1
Size
0 (FALSE), 1 (TRUE)
INT
DINT
Integer
Double integer
16
32
−32,768 to +32,767
−2,147,483,648 to +2,147,483,647
LINT
UINT
Long (8-byte) integer
Unsigned integer
64
16
−9,223,372,036,854,775,808 to +9,223,372,036,854,775,807
&0 to 65,535
UDINT
ULINT
Unsigned double integer 32
Unsigned long (8-byte)
64
integer
&0 to 4,294,967,295
&0 to 18,446,744,073,709,551,615
REAL
Real number
32
−3.402823 × 1038 to −1.175494 × 10−38, 0,
+1.175494 × 10−38 to +3.402823 × 1038
LREAL
Long real number
64
−1.79769313486232 × 10308 to −2.22507385850720 × 10−308, 0,
2.22507385850720 × 10−308 to 1.79769313486232 × 10308
WORD
DWORD
16-bit data
32-bit data
16
32
#0000 to FFFF or &0 to 65,535
#00000000 to FFFFFFFF or &0 to 4,294,967,295
LWORD
64-bit data
64
#0000000000000000 to FFFFFFFFFFFFFFFF or
&0 to 18,446,744,073,709,551,615
Timer number: 0 to 4095
Completion Flag: 0 or 1
Timer PV: 0 to 9999 (BCD), 0 to 65535 (binary)
TIMER
Timer (See note.)
(See note.)
Flag: 1 bit
PV: 16 bits
COUNTER Counter (See note.)
(See note.)
Flag: 1 bit
PV: 16 bits
Range of values
Counter number: 0 to 4095
Completion Flag: 0 or 1
Counter PV: 0 to 9999 (BCD), 0 to 65535 (binary)
Note The TIMER and COUNTER data types cannot be used in structured text function blocks.
Derivative Data Types
Array
1-dimensional array; 32,000 elements max.
137
Data Types
138
Appendix A
Appendix B
Structured Text (ST Language)
Specifications
Structured Text
Structured text (also referred to as ST language) is a high-level programming language similar to PASCAL that
uses language structures such as selection and iteration statements. Programs written using structured text
are configured using statements. Statements are configured from variables and equations.
• Equations are sequences containing operators and operands (variables or constants). Operators include
arithmetic operators, comparison operators, and logical operators.
• Statements are either assignment or control statements. Assignment statements store calculation results
from the equation in the variable. Control statements include selection statements and iteration statements.
Example of Structured Text
Statement (e.g., CASE):
Configured using variables,
equations, etc.
CASE COLOR OF
1: NofRed := NofRed +1;
2: NofBlue := NofBlue+1;
Equation: Configured using
operators and operands.
(*Variable COLOR value is...*)
(*1: Increment variable NofRed by 1*)
(*2: Increment variable NofBlue by 1*)
(*Neither 1 or 2: Increment variable NofOther by 1*)
ELSE NofOther := NofOther+1;
END CASE;
IF NofRed > 100 OR NofBlue >100 THEN
STOP:=TRUE
(* When NofRed or NofBlue exceeds 100*)
(*Assign TRUE for variable STOP*)
END IF;
Comment: Configured using (* before the
comment and *) after the comment.
Statement (e.g., IF):
Configured using variables,
equations, etc.
Restrictions
Statement Delimiters
• Statements (assignment and control statements) must always end in a semicolon (;). The statement cannot be completed by simply using a carriage return.
• Do not use a semicolon (;) as a delimiter within a statement such as following reserved words, values, or
equations. Inserting a semicolon within a statement, except at the end of a statement, will result in a syntax
error.
Comments
• Comments are enclosed in parentheses and asterisks, i.e., (*comment*). Any characters except parentheses and asterisks can be used within a comment. Nesting within comments is not supported.
Notation
Example
(*comment*)
(*this is the comment*)
139
Appendix B
Structured Text (ST Language) Specifications
Note: Nesting in comments is not possible, i.e., (*(*this type of nesting is not supported*)*)
Spaces, Carriage Returns, Tabs
• Any number of spaces, carriage returns, and tabs, or combinations of these can be used anywhere within
statements. Therefore, use spaces, carriage returns, and tabs between reserved words and equations to
make them easier to read.
• Spaces, carriage returns, and tabs cannot be used between the following tokens (the smallest meaningful
unit for compiling), in which case they are referred to as token separators.
Tokens: Reserved words, variable names, special characters, constants (numerical values)
Reserved words (upper or lower case):AND, CASE, DO, ELSE, FOR, IT, NOT, OF, OR, REPEAT,
THEN, TO, UNTIL, WHILE, XOR, TRUE, FALSE, ELSIF, BY,
EXIT, RETURN
Variable names:
Any text that is not a reserved word will be recognized as a variable
name.
Special characters:
<=, >=, <>, :=, .., &, (*, *)
Constants (numerical values):
Numerical value only for decimal numbers
16# followed by numerical value for hexadecimal numbers
2# followed by numerical value for binary numbers
8# followed by numerical value for octal numbers
If a space, carriage return, or tab is used between any of the above tokens, the parts of the token on either
side will be treated as separate tokens. Therefore, make sure that spaces, carriage returns, or tabs are not
used within a single token.
• Always use a space, carriage return, tab, or other token separator between reserved words and variable
names. Using token separators between other token combinations is optional.
In the following example, the box (@) indicates where a space, carriage return, tab, or other token separator is required.
[email protected]>[email protected]=10;
[email protected]
X:=0;
END_IF;
Upper and Lower Case
• Reserved words and variable names do not distinguish between upper and lower case (either can be
used).
Prohibited Characters for Variable Names
• The following characters enclosed in square brackets cannot be used in variable names.
[!], [“], [#], [$], [%], [&], [‘], [(],, [)], [-], [=], [^], [~], [\], [|], [@], [‘], [[], [{], [;], [+], [:], [*], []], [}], [,], [<], [.], [>], [/], [?]
• The numbers 0 to 9 cannot be used as the first character of variable names.
• An underscore cannot be followed immediately by another underscore in variable names.
• Spaces cannot be used in variable names.
An error message will occur if any of these characters are used in this way.
Inputting Constants (Numerical Values)
• Numerical values can be expressed in decimal, hexadecimal, octal, or binary, as shown in the following
examples.
140
Notation method
Example (for the decimal value 12)
Decimal:
Numerical value only
12
Hexadecimal:
16# followed by numerical value
16#C
Octal:
8# followed by numerical value
8#14
Binary:
2# followed by numerical value
2#1100
Appendix B
Structured Text (ST Language) Specifications
Operator Priority
• Consider the operator priority in the structured text syntax, or enclose operations requiring priority in
parentheses.
Example: AND takes priority over OR. Therefore, in the example X OR Y AND Z, priority will be given to Y
AND Z.
CX-Programmer’s ST Input Screen Display
Text Display Color
The CX-Programmer automatically displays text in the following colors when it is input or pasted in the ST Input
Screen.
• Text keywords (reserved words): Blue
• Comments: Green
• Errors: Red
• Other: Black
Changing Fonts
To change font sizes or display colors, select Tools - Options - Display, and then click the ST Font Button.
The font name, font size (default is 8 point), and color can be changed.
Statements
Statement
End of statement
Function
Ends the statement
Comment
All text between (* and *) is treated as a (*comment*)
comment.
Assignment
Substitutes the results of the expression, variable, or value on the right for
the variable on the left.
IF, THEN, ELSIF, ELSE, END_IF
Evaluates an expression when the con- IF (condition_1) THEN
dition for it is true.
(expression 1);
ELSIF (condition_2) THEN
(expression 2);
ELSE
(expression 3);
END_IF;
Evaluates an express based on the
CASE (variable) OF
value of a variable.
1: (expression 1);
2: (expression 2);
3: (expression 3);
ELSE
(expression 4);
END_CASE;
CASE, ELSE, END_CASE
FOR, TO, BY, DO, END_FOR
WHILE, DO, END_WHILE
REPEAT, UNTIL, END_REPEAT
Example
;
A:=B;
Repeatedly evaluates an expression
according to the initial value, final
value, and increment.
FOR (identifier) := (initial_value) TO
(final_value) BY (increment) DO
(expression);
END_FOR;
Repeatedly evaluates an expression as WHILE (condition) DO
long as a condition is true.
(expression);
END_WHILE;
Repeatedly evaluates an expression
until a condition is true.
REPEAT
(expression);
UNTIL (condition)
END_REPEAT;
141
Appendix B
Structured Text (ST Language) Specifications
Statement
Function
Stops repeated processing.
EXIT
RETURN
Example
EXIT;
Returns to the point in the program
RETURN;
from which a function block was called.
Operators
Operation
Symbol
Parentheses and
brackets
Function evaluation
(expression),
array[index]
identifier
Exponential
Data types supported by operator
Priority
1: Lowest
11: Highest
1
**
Depends on the function (refer to 2-6 Instruction
Support and Operand Restrictions)
REAL, LREAL
2
3
Complement
Multiplication
NOT
*
BOOL, WORD, DWORD, LWORD
INT, DINT, UINT, UDINT, ULINT, REAL, LREAL
4
5
Division
Addition
/
+
INT, DINT, LINT, UINT, UDINT, ULINT, REAL, LREAL 5
INT, DINT, LINT, UINT, UDINT, ULINT, REAL, LREAL 6
Subtraction
Comparisons
−
<, >, <=, >=
Equality
=
INT, DINT, LINT, UINT, UDINT, ULINT, REAL, LREAL 6
BOOL, INT, DINT, LINT, UINT, UDINT, ULINT,
7
WORD, DWORD, LWORD, REAL, LREAL
BOOL, INT, DINT, LINT, UINT, UDINT, ULINT,
8
WORD, DWORD, LWORD, REAL, LREAL
Non-equality
<>
BOOL, INT, DINT, LINT, UINT, UDINT, ULINT,
WORD, DWORD, LWORD, REAL, LREAL
8
Boolean AND
Boolean AND
&
AND
BOOL, WORD, DWORD, LWORD
BOOL, WORD, DWORD, LWORD
9
9
Boolean exclusive
OR
XOR
BOOL, WORD, DWORD, LWORD
10
Boolean OR
OR
BOOL, WORD, DWORD, LWORD
11
Note Operations are performed according to the data type.
Therefore, the addition result for INT data, for example, must be a variable using the INT data type. Particularly care is required when a carry or borrow occurs in an operation for integer type variables. For
example, using integer type variables A=3 and B= 2, if the operation (A/B)*2 is performed, the result of
A/B is 1 (1.5 with the value below the decimal discarded), so (A/B)*2 = 2.
Functions
Function
Numerical Functions
Syntax
Absolute values, trigonometric functions, etc.
Arithmetic Functions
Data type conversion Functions
Exponential (EXPT)
Source data type_TO_New data type (Variable name)
142
Appendix B
Structured Text (ST Language) Specifications
Numerical Functions
The following numerical functions can be used in structured text.
Numerical
functions
ABS (argument)
Argument data type
Return value
data type
INT, DINT, LINT,
INT, DINT, LINT,
UINT, UDINT, ULINT, UINT, UDINT,
REAL, LREAL
ULINT, REAL,
LREAL
SQRT (argument)
REAL, LREAL
REAL, LREAL
LN (argument)
REAL, LREAL
LOG (argument)
EXP (argument)
Contents
Example
Absolute value [argument] a: = ABS (b)
(*absolute value of variable b
stored in variable a*)
Square root:
a: = SQRT (b)
(*square root of variable b
stored in variable a*)
REAL, LREAL
Natural logarithm: LOGe
argument
a: = LN (b)
(*natural logarithm of variable b stored in variable a*)
REAL, LREAL
REAL, LREAL
Common logarithm:
LOG10 argument
REAL, LREAL
REAL, LREAL
Natural exponential: eargu-
a: = LOG (b)
(*common logarithm of variable b stored in variable a*)
a: = EXP (b)
(*natural exponential of variable b stored in variable a*)
a: = SIN (b)
(*sine of variable b stored in
variable a*)
a: = COS (b)
(*cosine of variable b stored
in variable a*)
√ argument
ment
SIN (argument)
REAL, LREAL
REAL, LREAL
Sine: SIN argument
COS (argument)
REAL, LREAL
REAL, LREAL
Cosine: COS argument
TAN (argument)
REAL, LREAL
REAL, LREAL
Tangent: TAN argument
ASIN (argument)
REAL, LREAL
REAL, LREAL
ACOS (argument)
REAL, LREAL
REAL, LREAL
ATAN (argument)
REAL, LREAL
REAL, LREAL
−1
Arc sine: SIN
argument
−1 argu-
Arc cosine: COS
ment
Arc tangent: TAN
ment
−1
argu-
a: = TAN (b)
(*tangent of variable b stored
in variable a*)
a: = ASIN (b)
(*arc sine of variable b
stored in variable a*)
a: = ACOS (b)
(*arc cosine of variable b
stored in variable a*)
a: = ATAN (b)
(*arc tangent of variable b
stored in variable a*)
Note The data type returned for numerical functions is the same as that used in the argument. Therefore, variables substituted for function return values must be the same data type as the argument.
Arithmetic Functions
The following general exponential function can be used in structured text.
Exponential
function
EXPT (base, exponent)
Argument data type
Return value
data type
Base: REAL, LREAL REAL, LREAL
Exponent: INT, DINT,
LINT, UINT, UDINT,
ULINT
Contents
Example
Exponential: Baseexponent a: = EXPT (b, c)
(*Exponential with variable b
as the base and variable c as
the exponent is stored in
variable a*)
Note The data type returned for the general exponential function is the same as that used in the argument.
Therefore, variables substituted for function return values must be the same data type as the argument.
143
Appendix B
Structured Text (ST Language) Specifications
Data Type Conversion Functions
The following data type conversion functions can be used in structured text.
Syntax
Source data type_TO_New data type (Variable name)
Example: REAL_TO_INT (C)
In this example, the data type for variable C will be changed from REAL to INT.
Data Type Combinations
The combinations of data types that can be converted are given in the following table.
(YES = Conversion possible, No = Conversion not possible)
FROM
TO
BOOL
INT
DINT
LINT
UINT
UDINT
ULINT
WORD
DWORD LWORD
REAL
LREAL
No
No
No
No
No
YES
No
YES
No
YES
No
YES
No
YES
No
YES
No
YES
No
YES
No
YES
No
YES
No
No
YES
YES
No
YES
YES
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
No
No
YES
YES
YES
YES
YES
YES
No
YES
YES
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
No
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
No
YES
YES
No
YES
YES
YES
YES
YES
No
YES
No
DWORD No
BOOL
INT
DINT
LINT
UINT
UDINT
ULINT
WORD
LWORD
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
No
YES
YES
No
No
No
No
No
REAL
No
No
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
YES
No
No
No
No
No
No
No
YES
YES
No
LREAL
Statement Details
Assignment
Summary
The left side of the statement (variable) is substituted with the right side of the statement (equation, variable, or
constant).
Reserved Words
:=
Combination of colon (:) and equals sign (=).
Statement Syntax
Variable: = Equation, variable, or constant;
Usage
Use assignment statements for inputting values in variables. This is a basic statement for use before or within
control statements. This statement can be used for setting initial values, storing calculation results, and incrementing or decrementing variables.
Description
Substitutes (stores) an equation, variable, or constant for the variable.
Examples
Example 1: Substitute variable A with the result of the equation X+1.
A:=X+1;
Example 2: Substitute variable A with the value of variable B.
A:=B;
144
Structured Text (ST Language) Specifications
Appendix B
Example 3: Substitute variable A with the constant 10.
A:=10;
Precautions
The data type of the equation, variable, or constant to be assigned must be the same as the data type of the
variable to be substituted. Otherwise, a syntax error will occur.
Control Statements
IF Statement (Single Condition)
Summary
This statement is used to execute an expression when a specified condition is met. If the condition is not met,
a different expression is executed.
Reserved Words
IF, THEN, (ELSE), END_IF
Note ELSE can be omitted.
Statement Syntax
IF <condition> THEN
<expression_1>;
ELSE
<expression_2>;
END_IF;
Process Flow Diagram
Condition
False
True
Expression 1
Expression 2
Usage
Use the IF statement to perform a different operation depending on whether a single condition (condition equation) is met.
Description
Condition = If true, execute expression_1
Condition = If false, execute expression_2
Precautions
• IF must be used together with END_IF.
• The condition must include a true or false equation for the evaluation result.
Example: IF(A>10)
The condition can also be specified as a boolean variable only rather than an equation. As a result, the
variable value is 1 (ON) = True result, 0 (OFF) = False result.
• Statements that can be used in expression_1 and expression_2 are assignment statements, IF, CASE,
FOR, WHILE, or REPEAT.
145
Structured Text (ST Language) Specifications
Appendix B
Example:
IF <condition_1> THEN
IF <condition_2> THEN
<expression_1>;
ELSE
<expression_2>:
END_IF;
END_IF;
The processing flow diagram is as follows:
Condition 1 False
True
Condition 2
False
True
Expression 1
Expression 1
ELSE corresponds to THEN immediately before it, as shown in the above diagram.
• Multiple statements can be executed within expression_1 and expression_2. Be sure to use a semicolon (;)
delimiter between multiple statements in an expression.
• The ELSE statement can be omitted. When ELSE is omitted, no operation is executed if the result of the
condition equation is false.
Processing Flow Diagram
Condition
False
True
Expression
Examples
Example 1: If variable A>0 is true, variable X will be substituted with numerical value 10. If A>0 is false, variable
X will be substituted with numerical value 0.
IF A>0 THEN
X:=10;
ELSE
X:=0;
END_IF;
Example 2: If variable A>0 and variable B>1 are both true, variable X will be substituted with numerical value
10, and variable Y will be substituted with numerical value 20. If variable A>0 and variable B>1 are both false,
variable X and variable Y will both be substituted with numerical value 0.
146
Structured Text (ST Language) Specifications
Appendix B
IF A>0 AND B>1 THEN
X:=10; Y:=20;
ELSE
X:=0; Y:=0;
END_IF;
Example 3: If the boolean (BOOL data type) variable A=1(ON), variable X will be substituted with numerical
value 10. If variable A=0(OFF), variable X will be substituted with numerical value 0.
IF A THEN X:=10;
ELSE X:=0;
END_IF;
IF Statement (Multiple Conditions)
Summary
This statement is used to execute an expression when a specified condition is met. If the first condition is not
met, but another condition is met, a corresponding expression is executed. If none of the conditions is met, a
different expression is executed.
Reserved Words
IF, THEN, ELSIF, (ELSE)
Note ELSE can be omitted.
Statement Syntax
IF <condition_1> THEN <expression_1>;
ELSIF <condition_2> THEN <expression_2>;
ELSIF <condition_3> THEN <expression_3>;
...
ELSIF <condition_n> THEN <expression_n>;
ELSE <expression_m>;
END_IF;
Processing Flow Chart
Condition 1
True
Expression 1
False
Condition 2
True
Expression 2
False
Condition 3
False
True
Expression 3
Expression m
Usage
Use the IF statement to perform different operations depending which of multiple conditions (condition equation) is met.
147
Structured Text (ST Language) Specifications
Appendix B
Description
Condition 1 = If true, execute expression 1
Condition 1 = If false,
Condition 2 = If true, execute expression 2
Condition 2 = If false,
Condition 3 = If true, execute expression 3
etc.
Condition n = If true, execute expression n
If none of these conditions are met, condition m is executed.
Precautions
• IF must be used together with END_IF.
• [email protected] contains the true or false result of the equation (e.g., IF(A>10)).
A boolean (BOOL data type) variable only can also be specified as the condition rather than an equation.
For boolean conditions, the result is true when the variable value is 1 (ON) and false when it is 0 (OFF).
• Statements that can be used in [email protected] are assignment statements, IF, CASE, FOR, WHILE, or
REPEAT.
• Multiple statements can be executed in [email protected] Be sure to use a semicolon (;) delimiter between
multiple statements in an expression.
• The ELSE statement can be omitted. When ELSE is omitted, no operation is executed if the result of any
condition equation is false.
Examples
Example 1: If variable A>0 is true, variable X will be substituted with numerical value 10.
If A>0 is false, but variable B=1, variable X will be substituted with numerical value 1.
If A>0 is false, but variable B=2, variable X will be substituted with numerical value 2.
If either of these conditions is met, variable X will be substituted with numerical value 0.
IF A>0 THEN X:=10;
ELSIF B=1 THEN X:=1;
ELSIF B=2 THEN X:=2;
ELSE X:=0;
END_IF;
CASE Statement
Summary
This statement executes an expression containing a selected integer that matches the value from an integer
equation. If the selected integer value is not the same, either no expression or a specified expression is executed.
Reserved Word
CASE
Statement Syntax
CASE <integer_equation> OF
<integer_equation_value_1 >:<expression_1>;
<integer_equation_value_2>:<expression_2>;
...
<integer_equation_value_n>:<expression_n>;
ELSE <expression_m>;
END_CASE;
148
Appendix B
Structured Text (ST Language) Specifications
Processing Flow Chart
Same as
selected
value 1?
Yes
No
Same as
selected
value 2?
Yes
No
Same as
selected
value n?
Yes
No
Expression m
Expression n
Expression 2
Expression 1
Usage
Use the CASE statement to execute different operations depending on specified integer values.
Description
If the integer_equation matches integer_equation_value_n, expression_n is executed.
if the integer_equation does not match any of integer_equation_value_n, expression_m is executed.
Precautions
• CASE must be used together with END_CASE.
• The result of the integer_equation must be in integer format (INT, DINT, LINT, UINT, UDINT, or ULINT).
• Statements that can be used in [email protected] are assignment statements, IF, CASE, FOR, WHILE, or
REPEAT.
• Multiple statements can be executed in [email protected] Be sure to use a semicolon (;) delimiter between
multiple statements in an expression.
• Variables in integer format (INT, DINT, LINT, UINT, UDINT, or ULINT), or equations that return integer values can be specified in the integer_equation.
• When OR logic is used for multiple integers in the integer_equation_value_n, separate the numerical value
using a comma delimiter. To specify a sequence of integers, use two periods (..) as delimiters between the
first and last integers.
Examples
Example 1: If variable A is 1, variable X is substituted with numerical value 1. If variable A is 2, variable X is
substituted with numerical value 2. If variable A is 3, variable X is substituted with numerical value 3. If neither
of these cases matches, variable Y will be substituted with 0.
CASE A OF
1:X:=1;
2:X:=2;
3:X:=3;
ELSE Y:=0;
END_CASE;
149
Structured Text (ST Language) Specifications
Appendix B
Example 2: If variable A is 1, variable X is substituted with numerical value 1. If variable A is 2 or 5, variable X
is substituted with numerical value 2. If variable A is a value between 6 and 10, variable X is substituted with
numerical value 3. If variable A is 11, 12, or a value between 15 and 20, variable X is substituted with numerical
value 4. If neither of these cases matches, variable Y will be substituted with 0.
CASE A OF
1:X:=1;
2,5:X:=2;
6..10:X:=3;
11,12,15..20:X:=4;
ELSE Y:=0;
END_CASE;
FOR Statement
Summary
This statement is used to execute a specified expression repeatedly until a variable (referred to here as an iteration variable) reaches a specified value.
Reserved Words
FOR, TO, (BY), DO, END_FOR
Note BY can be omitted.
Statement Syntax
FOR <iteration_variable>:= <initial_value> TO <final_value_equation> BY
<increment_value_equation>
DO
<expression>;
END_FOR;
Processing Flow Chart
Iteration variable = Initial
True
Iteration
variable ≥
Final value?
Iteration
False
Expression
Iteration variable + Increment value
End
Usage
Use the FOR statement when the number of iterations has been determined beforehand. FOR is particularly
useful when switching the number of elements in an array variable according to the value of a specified iteration variable.
150
Structured Text (ST Language) Specifications
Appendix B
Description
When the iteration_variable is the initial_value, the expression is executed. After execution, the value obtained
from the increment_equation is added to the iteration_variable, and if the iteration_variable <
final_value_equation (see note 1), the expression is executed. After execution, the value obtained from the
increment_equation is added to the iteration_variable, and if the iteration_variable < final_value_equation value
(see note 1), the expression is executed. This process is repeated. If the iteration_variable ≥
final_value_equation (see note 2), the processing ends.
Note
(1) If the value from the increment_equation is negative, the condition is iteration_variable >
final_value_equation value.
(2) If the value from the increment_equation is negative, the condition is iteration_variable
final_value_equation.
≤
Precautions
• A negative value can be specified in the increment_equation
• FOR must be used in combination with END_FOR.
• The initial_value, final_value_equation, and final_value_equation must be an integer data type (INT, DINT,
LINT, UINT, UDINT, or ULINT).
• Do not reference an iteration variable that is outside the FOR statement, where possible. The value of the
iteration variable after completing execution of the FOR statement depends on the actual model specifications, and may prevent use of the program for general-purpose applications.
Example: In the following structured text, whether the value of a is TRUE or FALSE depends on the actual
model being used.
FOR i:=0 TO 100 DO
array[i]:=0;
END_FOR;
IF i=101 THEN
a:=TRUE;
ELSE
a:=FALSE;
END_IF;
• Do not use a FOR statement in which an iteration variable is changed directly. Doing so may result in unexpected operations.
Example:
FOR i:=0 TO 100 BY 1 DO
array[i]:=0;
i:=i+5;
END_FOR;
• Statements that can be used in the expression are assignment statements, IF, CASE, FOR, WHILE, or
REPEAT.
• Multiple statements can be executed in the expression. Be sure to use a semicolon (;) delimiter between
multiple statements in an expression.
• BY increment_equation can be omitted. When omitted, BY is taken as 1.
• Variables with integer data types (INT, DINT, LINT, UINT, UDINT, or ULINT), or equations that return integer values can be specified in the initial_value, final_value_equation, and increment_equation.
Example 1: The iteration is performed when the iteration variable n = 0 to 50 in increments of 5, and the
array variable SP[n] is substituted with 100.
FOR n:=0
TO 50
SP[n]:=100;
END_FOR;
BY 5 DO
151
Structured Text (ST Language) Specifications
Appendix B
Example 2: The total value of elements DATA[1] to DATA[50] of array variable DATA[n] is calculated, and
substituted for the variable SUM.
FOR n:=0
TO 50 BY 1 DO
SUM:=SUM+DATA[n];
END_FOR;
Example 3: The maximum and minimum values from elements DATA[1] to DATA[50] of array variable
DATA[n] are detected. The maximum value is substituted for variable MAX and the minimum value is substituted for variable MIN. The value for DATA[n] is between 0 and 1000.
MAX:=0;
MIN:=1000;
FOR n:=1
TO 50 BY 1 DO
IF DATA[n]>MAX THEN
MAX:=DATA[n];
END IF;
IF DATA[n]<MIN THEN
MIN:=DATA[n];
END IF;
END_FOR;
WHILE Statement
Summary
This statement is used to execute a specified expression repeatedly for as long as a specified condition is true.
Reserved Words
WHILE, DO, END_WHILE
Statement Syntax
WHILE <condition> DO
<expression>;
END_WHILE;
Processing Flow Chart
Iteration
Condition
False
True
Expression
End
Usage
Use the WHILE statement when the number of iterations has not been determined beforehand (depends on
the condition being met) to repeat specified processing for the duration that the condition is met. This statement can be used to execute processing while the condition equation is true only (pretest loop).
Description
Before the expression is executed, the condition is evaluated.
If the condition is true, the expression is executed. Afterwards, the condition is evaluated again. This process is
repeated. If the condition is false, the expression is not executed and the condition evaluation ends.
152
Structured Text (ST Language) Specifications
Appendix B
Precautions
• WHILE must be used in combination with END_WHILE.
• Before executing the expression, if the condition equation is false, the process will end without executing
the expression.
• Statements that can be used in the expression are assignment statements, IF, CASE, FOR, WHILE, or
REPEAT.
• Multiple statements can be executed in the expression. Be sure to use a semicolon (;) delimiter between
multiple statements in an expression.
• The condition can also be specified as a boolean variable (BOOL data type) only rather than an equation.
Examples
Example 1: The value exceeding 1000 in increments of 7 is calculated and substituted for variable A.
A:=0;
WHILE A>=1000 DO
A:=A+7;
END_WHILE;
Example 2: While X<3000, the value of X is doubled, and the value is substituted for the array variable DATA[1].
The value of X is then multiplied by 2 again, and the value is substituted for the array variable DATA[2]. This
process is repeated.
n:=1’
WHILE X<3000 DO
X:=X*2;
DATA[n]:=X;
n:=n+1;
END_WHIE;
REPEAT Statement
Summary
This statement is used to repeatedly execute an expression until a specified condition is true.
Reserved Words
REPEAT, UNTIL, END_REPEAT
Statement Syntax
REPEAT
<expression>;
UNTIL <condition>
END_REPEAT
Processing Flow Chart
Expression
Condition
Iteration
False
True
End
153
Structured Text (ST Language) Specifications
Appendix B
Usage
Use the REPEAT statement to repeat processing for as long as a condition is met after specified processing,
when the number of iterations is undetermined beforehand (depends on whether the condition is met). This
statement can be used to determine whether to repeat processing according to the results of specified processing execution (post-test loop).
Description
The expression will execute the first time without a condition. Thereafter, the condition equation will be evaluated. If the condition is false, the expression will be executed again. If the condition is true, processing will end
without executing the expression.
Precautions
• REPEAT must be used together with END_REPEAT.
• Even if the condition equation is true before the expression has been executed, the expression will be executed.
• Statements that can be used in the expression are assignment statements, IF, CASE, FOR, WHILE, or
REPEAT.
• Multiple statements can be executed in the expression. Be sure to use a semicolon (;) delimiter between
multiple statements in an expression.
• The condition can also be specified as a boolean variable (BOOL data type) only rather than an equation.
Examples
Example 1: Numeric values from 1 through 10 are incremented and the total is substituted for the variable
TOTAL.
A:=1;
TOTAL:=0;
REPEAT
TOTAL:=TOTAL+A;
A:=A+1;
UNTIL A>10
END_REPEAT;
EXIT Statement
Summary
This statement is used within iteration statements (FOR, WHILE, REPEAT) only to force an iteration statement
to end. This statement can also be used within an IF statement to force an iteration statement to end when a
specified condition is met.
Reserved Words
EXIT
Statement Syntax (Example: Using within IF Statement)
FOR (WHILE, REPEAT) expression
...
IF <condition> THEN EXIT;
END_IF;
...
END_FOR (WHILE, REPEAT);
Usage
Use the EXIT statement to force iteration processing to end before the end condition is met.
Description (Example: Using within IF Statement)
When the condition equation is true, the iteration statement (FOR, WHILE, REPEAT) is forced to end, and any
statements after EXIT will not be executed.
154
Structured Text (ST Language) Specifications
Note
Appendix B
(1) The condition can also be specified as a boolean variable (BOOL data type) only rather than an
equation.
(2) Even if the condition equation is true before the expression has been executed, the expression will
be executed.
Example
Processing is repeated from when variable n = 1 until 50 in increments of 1 and n is added to array variable
DATA[n]. If DATA[n] exceeds 100, however, processing will end.
FOR n:=1; TO 50 BY 1 DO
DATA[n]:=DATA[n]+n;
IF DATA[n]>100 THEN EXIT;
END_IF;
END_FOR;
RETURN Statement
Summary
This statement is used to execute the next instruction following the location that called the function block in the
program when the function block in the structured text must be forced to end before it has been completed.
Reserved Words
RETURN
Statement Syntax
RETURN;
Usage
Use the RETURN statement when a function block has been forced to end.
Examples of Structured Text Programming
Example 1: Conversion of BCD Data (#0000-#9999) to BIN Data
(*Check the input parameter "Input_BCD" (BCD data) *)
IF (Input_BCD>=0 & Input_BCD<=16#9999) THEN
ENO:=true;
ELSE
ENO:=false;
RETURN;
END_IF;
(*BCD data is divided by 16 four times to get each digit of the BIN data converted from the BCD data*)
DIV_1:=Input_BCD/16;
DIV_2:=DIV_1/16;
DIV_3:=DIV_2/16;
DIV_4:=DIV_3/16;
(*Calculate each digit of the BIN data converted from the BCD data*)
BIN_1:=Input_BCD-16*DIV_1; (*a number of 160 digit*)
BIN_2:=DIV_1-16*DIV_2; (*a number of 161 digit*)
BIN_3:=DIV_2-16*DIV_3; (*a number of 162 digit*)
BIN_4:=DIV_3-16*DIV_4; (*a number of 163 digit*)
(*Calculate the BIN data "Output_BIN" (output parameter) *)
Output_BIN:=BIN_1+BIN_2*10+BIN_3*10*10+BIN_4*10*10*10;
Input_BCD
Output_BIN
155
Structured Text (ST Language) Specifications
Appendix B
Example 2: Conversion of BIN Data (#0000-#FFFF) to BCD Data
(*check the input parameter "Input_BIN" (BIN data) *)
IF (Input_BIN>=0 & Input_BIN<=16#FFFF) THEN
ENO:=true;
ELSE
ENO:=false;
RETURN;
END_IF;
(*BIN data is divided by 10 four times to get each digit of the BCD data converted from the BIN data*)
DIV_1:=Input_BIN/10;
DIV_2:=DIV_1/10;
DIV_3:=DIV_2/10;
DIV_4:=DIV_3/10;
(*Calculate each digit of the BCD data converted from the BIN data*)
BCD_1:=Input_BIN-10*DIV_1; (*a number of 100 digit*)
BCD_2:=DIV_1-10*DIV_2; (*a number of 101 digit*)
BCD_3:=DIV_2-10*DIV_3; (*a number of 102 digit*)
BCD_4:=DIV_3-10*DIV_4; (*a number of 103 digit*)
(*Calculate the BCD data "Output_BCD" (output parameter) *)
Output_BCD:=BCD_1+BCD_2*16+BCD_3*16*16+BCD_4*16*16*16;
Input_BIN
Output_BCD
Restrictions
Nesting
There is no restriction on the number of nests that can be used in IF, CASE, FOR, WHILE, or REPEAT statements.
Data Type Restrictions
• Integers can only be allocated to variables with data types WORD, DWORD, INT, DINT, UINT, UDINT, or
ULINT. For example, if A is an INT data type, A:=1; it possible. If the value is not an integer data type, a
syntax error will occur. For example, if A is an INT data type, a syntax error will occur for A:=2.5;.
• If a real number (floating point decimal data) can only be allocated to variables with data types REAL and
UREAL. For example, if A is a REAL data type, A:=1.5; is possible. If the value is not an real data type, a
syntax error will occur. For example, if A is a REAL data type, a syntax error will occur for A:=2;. Use
A:=2.0;.
• Bits (TRUE, FALSE) can only be allocated to variables with the BOOL data type. For example, if A is a
BOOL data type, A:=FALSE; is possible. If a BOOL data type is not used, a syntax error will occur. For
example, if A is an INT data type, a syntax error will occur for A:=FALSE;.
• Data types must all be consistent within the structured text. For example, if A, B, and C are INT data types,
A:=B+C; is possible. If, however, A and B are INT data types, but C is a REAL data type or LINT data type,
a syntax error will occur for A:=B+C;.
156
Appendix B
Structured Text (ST Language) Specifications
Structured Text Errors
Error Messages
Error Message
%s' Input variables cannot be
assigned a value
%s' operator not supported by
%s data type
Cause of error
Example
A value was substituted for an
input variable.
A numerical value or variable A:=B+1; (*A and B are WORD type variables*))
for a data type that is not supported by the operator was
used.
%s' variable had a read only
A value was substituted for a
memory AT Address and can- variable allocated to a readnot be assigned a value
only memory address (readonly Auxiliary Area address or
Condition Flag).
Array index out of range
Conversion cannot convert
from %s to %s
Division by Zero
An array index larger than the
array size was specified.
A numeric equation in which
the data type of the operation
result does not match the variable at the substitution destination and a variable that is
different from the data type
was substituted.
The numeric expression contains division by 0.
Array[100]:=10; (*Array is an array variable with an array
size of 100*)
Y:=ABS(X); (*X is an INT type variable, Y is a UINT type
variable*)
End of comment not found
The comment does not have a (*comment
closing parenthesis and asterisk “*)” corresponding to the
opening parenthesis and
asterisk “(*” of the comment.
Invalid Literal Format '%s'
The numeric format is illegal.
X:=123_; (*There is no numeral after underscore*)
X:=1__23; (*The underscore is followed immediately by
another underscore*)
X:=2#301; Y:=8#90; (*A numeral that cannot be used with
binary or octal values has been used*)
Note The underscore can be inserted between numerals
to make them easier to read. Placing 2#, 8#, and
16# at the beginning of the numeral expresses the
numerals as binary, octal, and hexadecimal values,
respectively.
Invalid Literal Value
The numeric value is illegal.
Invalid array index
A numeric equation with a
non-integer type operation
result or a non-integer variable has been specified in the
array index.
Invalid constant
A numeric equation with a
non-integer type operation
result, or a non-integer variable or numeric value has
been specified in the integer
equation of a CASE statement.
X:=1e2; (*an index was used for a numeric value that was
not a REAL data type*)
Note “e” indicates an exponent of 10.
Array[Index]:=10; (*Index is a WORD type variable*)
CASE A OF (*A is a REAL type variable*)
1: X:=1;
2: X:=2;
END_CASE;
157
Appendix B
Structured Text (ST Language) Specifications
Error Message
Invalid expression
Cause of error
The numeric equation is illegal. For example, the integer
equation or condition equation
is illegal or has not been specified in the syntax (IF, WHILE,
REPEAT, FOR, CASE).
Invalid parameter in FOR loop A variable with data type other
declaration
than INT, DINT, LINT, UINT,
UDINT, or ULINT has been
used for variables in a FOR
statement.
Invalid statement
The statement is illegal. E.g.,
The statement (IF, WHILE,
REPEAT, FOR, CASE,
REPEAT) does not contain an
IF, WHILE, REPEAT, FOR,
CASE, or REPEAT in the syntax, respectively.
Example
WHILE DO (*The WHILE statement does not contain a
condition equation*)
X:=X+1;
END_WHILE;
FOR I:=1 TO 100 DO (*I is a WORD type variable*)
X:=X+1;
END_FOR;
X:=X+1; (*There is no REPEAT in the syntax*)
UNTIL X>10
END_REPEAT;
Invalid variable for Function
output
The specified variable for the Y:=SIN(X1, ENO=>1);
function output is illegal (A
non-boolean (BOOL) variable
or numeral has been specified
as the ENO transfer destination.)
Missing (
The call for a data format con- Y:=INT_TO_DINT X);
version instruction or function
does not contain a “(“ (opening parenthesis).
The operator parentheses or Y:=(X1+X2/2
the call for a data format conversion instruction or function
does not contain a “)“ (closing
parenthesis) corresponding to
“(“ (opening parenthesis).
Missing )
Missing :
The integer equation in the
CASE statement is not followed by a “:” (colon).
Missing :=
“:=” is not included in the
assignment equation.
Missing ;
The statement is not concluded by a “;” (semicolon).
“DO” is not provided in the
FOR or WHILE statement.
“END_CASE” is not provided
at the end of the CASE statement.
“END_FOR” is not provided at
the end of the FOR statement.
“END_IF” is not provided at
the end of the IF statement.
“END_REPEAT” is not provided at the end of the
REPEAT statement.
“END_WHILE” is not provided at the end of the WHILE
statement.
The function argument is not Y:=EXPT(X);
specified or is insufficient.
Missing DO
Missing END_CASE
Missing END_FOR
Missing END_IF
Missing END_REPEAT
Missing END_WHILE
Missing Input Parameter. All
input variables must be set.
158
CASE A OF
1 X:=1;
END_CASE;
Appendix B
Structured Text (ST Language) Specifications
Error Message
Missing OF
Cause of error
“OF” is not included in CASE
statement.
Missing THEN
“THEN” is not included in IF
statement.
Missing TO
“TO” is not included in FOR
statement.
Missing UNTIL
“UNTIL” is not included in
REPEAT statement.
The array index for the array
variable has not been specified.
Missing [
Example
X:=Array; (*Array is an array variable*)
Missing ]
The array index for the array
variable has not been specified.
X:=Array[2; (*Array is an array variable*)
Missing constant
A constant is not provided in
the integer equation of the
CASE statement.
NOT operation not supported
on a literal number
Negation not supported by %s
data type
The NOT operator was used
for a numeric value.
A minus symbol was used
before a variable with a data
type that does not support
negative values (UINT,
UDINT, ULINT).
CASE A OF
2..: X:=1;
2,: X:=2;
END_CASE;
Result:=NOT 1;
There must be one line of
valid code (excluding comments)
Too many variables specified
for Function
Undefined identifier '%s'
There is no line of valid code
(excluding comments).
Unexpected syntax '%s'
Usage mismatch in Function
variable
Value out of range
Y:=-X; (*X is an UINT type variable, Y is an INT type variable*)
Too many parameter settings Y:=SIN(X1,X2);
are specified for the function.
A variable that is not defined
in the variable table has been
used.
A keyword (reserved word) or FOR I:=1 TO 100 DO BY -1 (*The DO position is illegal*)
variable has been used illeX:=X+1;
gally.
END_FOR;
The function parameter has
Y:=SIN(X1,EN=>BOOL1); (*The input parameter EN has
been used illegally.
been used as an output parameter*)
A value outside the range for X:=32768; (*X is an INT type variable*)
the variable data type has
been substituted in the variable.
Variable '%s' is not a Function A variable that cannot be
Y:=SIN(Z:=X); (*X and Y are REAL type variables, and Z
parameter
specified in the function
is not a SIN function parameter *)
parameter has been specified
in the parameter.
159
Appendix B
Structured Text (ST Language) Specifications
Warning Messages
Warning message
Keyword '%s' is redundant
Cause of warning
The keyword has been used
in an invalid location. For
example, use of the EXIT
statement outside a loop syntax.
Example
Conversion from '%s' to '%s',
possible loss of data
Data may be lost due to conversion of a data type with a
large data size to a data type
with a small data size.
Y:=DINT_TO_INT(X); (*X is a DINT type variable, Y is an
INT type variable*)
Commonly Asked Questions
Q: How is a hexadecimal value expressed?
A: Add “16#” before the value, e.g., 16#123F.
The prefixes 8# and 2# can also be added to express octal numbers and binary numbers, respectively. Numbers without these prefixes will be interpreted as decimal numbers.
Q: How many times can FOR be used?
A: In the following example, the contents of the FOR statement is executed 101 times. The loop processing
ends when the value of “i” is equal to 101.
FOR i:=0 TO 100 BY 1 DO
a:=a+1;
END_FOR;
Q: What occurs when the array subscript is exceeded?
A: For the array variable INT[10] with 10 elements, an error will not be detected for the following type of statement. Operation will be unstable when this statement is executed.
i:=15;
INT[i]:=10;
Q: Are the variables in the structured text editor automatically registered in the variable tables?
A: No. Register the variables in the variable table before using them.
Q: Can ladder programming instructions be called directly?
A: No.
160
Appendix C
External Variables
Classification
Conditions Flags
Clock Pulses
Name
Greater Than or Equals (GE) Flag
External variable in
Data type
CX-Programmer
P_GE
BOOL
CF00
Not Equals (NE) Flag
Less Than or Equals (LE) Flag
P_NE
P_LE
BOOL
BOOL
CF001
CF002
Instruction Execution Error (ER) Flag
Carry (CY) Flag
P_ER
P_CY
BOOL
BOOL
CF003
CF004
Greater Than (GT) Flag
Equals (EQ) Flag
P_GT
P_EQ
BOOL
BOOL
CF005
CF006
Less Than (LT) Flag
Negative (N) Flag
P_LT
P_N
BOOL
BOOL
CF007
CF008
Overflow (OF) Flag
Underflow (UF) Flag
P_OF
P_UF
BOOL
BOOL
CF009
CF010
Access Error Flag
Always OFF Flag
P_AER
P_Off
BOOL
BOOL
CF011
CF114
Always ON Flag
0.02 second clock pulse bit
P_On
P_0_02s
BOOL
BOOL
CF113
CF103
0.1 second clock pulse bit
0.2 second clock pulse bit
P_0_1s
P_0_2s
BOOL
BOOL
CF100
CF101
1 minute clock pulse bit
P_1mim
BOOL
CF104
P_1s
P_First_Cycle
BOOL
BOOL
CF102
A200.11
First Task Execution Flag
P_Step
P_First_Cycle_Task
BOOL
BOOL
A200.12
A200.15
Maximum Cycle Time
Present Scan Time
P_Max_Cycle_Time UDINT
P_Cycle_Time_Value UDINT
A262
A264
Cycle Time Error Flag
Low Battery Flag
P_Cycle_Time_Error
P_Low_Battery
BOOL
BOOL
A401.08
A402.04
I/O VerIFication Error Flag
Output OFF Bit
P_IO_Verify_Error
P_Output_Off_Bit
BOOL
BOOL
A402.09
A500.15
CIO Area specification
HR Area specification
P_CIO
P_HR
WORD
WORD
A450
A452
WR Area specification
DM Area specification
P_WR
P_DM
WORD
WORD
A451
A460
EM0 to C Area specification
P_EM0 to P_EMC
WORD
A461 to
A473
1.0 second clock pulse bit
Auxiliary Area Flags/ First Cycle Flag
Bits
Step Flag
OMRON FB Library
words (see note)
Address
Note These words are external variables for the OMRON FB Library. Do not use these words for creating
function blocks.
161
External Variables
162
Appendix C
Index
A
addresses
allocation areas, 31
checking internal allocations, 129
setting allocation areas, 128
algorithm
creating, 119
applications
precautions, xiii
array settings, 14, 28, 44, 121
AT settings, 14, 27, 121
restrictions, 38
C
compiling, 131
computer system requirements, 3
D
data types, 14, 27, 137
determining, 42
debugging function blocks, 134
differentiation
restrictions, 38
function blocks
advantages, 7
application guidelines, 42
creating, 17, 111
debugging, 134
defining, 117
elements, 21
errors, 41
monitoring, 134
operating specifications, 35
outline, 7
restrictions, 37
reusing, 18
setting parameters, 125
specifications, 4, 21
structure, 8
functions, 2
function blocks, 4
restrictions, 3
G
global symbol table, 12
I
IEC 61131-3, 2, 4
input variables, 23
E
errors
function blocks, 41
external variables, 26
list, 161
externals, 14
F
features, 2
files
function block definitions, 133
library, 5
project text files, 5
function block definitions, 8
checking for an instance, 131
compiling, 131
creating, 114
saving to files, 133
inputs, 13
instance areas, 15, 31
setting, 16, 128
instances
creating, 17, 124
multiple, 33
number of, 10
outline, 9
registering in global symbol table, 12
specifications, 30
internal variables, 25
internals, 13
L
ladder programming
function block definition, 116
restrictions, 40
restrictions in function blocks, 37
163
Index
M
menus, 5
main, 5
popup, 6
monitoring function blocks, 134
O
online editing
restrictions, 41
output variables, 24
outputs, 14
P
parameters
outline, 10
precautions, xi
applications, xiii
general, xii
safety, xii
Programming Consoles, 41
projects
creating, 114
S
safety precautions, xii
specifications, 19
CX-Programmer Ver. 5.0, 3
function block operation, 35
instances, 30
structured text
function block definition, 116
restrictions, 40
symbol name
automatically generating, 123
T
timer instructions
operation, 107
restrictions, 39
V
variable names, 14
164
variables
address allocations, 15
checking address allocations, 129
creating as needed, 120
definitions, 22
introduction, 13
properties, 13, 14, 27
registering in advance, 117
restrictions, 38
setting allocation areas, 15
usage, 13, 22
Revision History
A manual revision code appears as a suffix to the catalog number on the front cover of the manual.
Cat. No. W438-E1-01
Revision code
The following table outlines the changes made to the manual during each revision. Page numbers refer to the
previous version.
Revision code
01
Date
July 2004
Revised content
Original production
165
Revision History
166
OMRON CORPORATION
FA Systems Division H.Q.
66 Matsumoto
Mishima-city, Shizuoka 411-8511
Japan
Tel: (81)55-977-9181/Fax: (81)55-977-9045
Regional Headquarters
OMRON EUROPE B.V.
Wegalaan 67-69, NL-2132 JD Hoofddorp
The Netherlands
Tel: (31)2356-81-300/Fax: (31)2356-81-388
OMRON ELECTRONICS LLC
1 East Commerce Drive, Schaumburg, IL 60173
U.S.A.
Tel: (1)847-843-7900/Fax: (1)847-843-8568
OMRON ASIA PACIFIC PTE. LTD.
83 Clemenceau Avenue,
#11-01, UE Square,
Singapore 239920
Tel: (65)6835-3011/Fax: (65)6835-2711
Authorized Distributor:
Cat. No. W438-E1-01
Note: Specifications subject to change without notice
This manual is printed on 100% recycled paper.
Printed in Japan
Was this manual useful for you? yes no
Thank you for your participation!

* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project

Download PDF

advertisement