Omron SYSMAC CS Series Instruction & Reference Manual
Omron SYSMAC CS Series Instruction & Reference Manual

Omron SYSMAC CS Series Instruction & Reference Manual

Hide thumbs Also See for SYSMAC CS Series:
Table of Contents

Quick Links

Cat. No. W474-E1-13
SYSMAC CS Series
CS1@-CPU@@@-@@
SYSMAC CJ Series
CJ2H-CPU6@-EIP
CJ2H-CPU6@
CJ2M-CPU@@
CJ1@-CPU@@@-@
SYSMAC One NSJ Series
NSJ@@-@@@@@-@@@
Programmable Controllers
INSTRUCTIONS
REFERENCE MANUAL
Table of Contents
loading

Summary of Contents for Omron SYSMAC CS Series

  • Page 1 Cat. No. W474-E1-13 SYSMAC CS Series CS1@-CPU@@@-@@ SYSMAC CJ Series CJ2H-CPU6@-EIP CJ2H-CPU6@ CJ2M-CPU@@ CJ1@-CPU@@@-@ SYSMAC One NSJ Series NSJ@@-@@@@@-@@@ Programmable Controllers INSTRUCTIONS REFERENCE MANUAL...
  • Page 2 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. Neverthe- less, OMRON assumes no responsibility for errors or omissions.
  • Page 3 SYSMAC CS Series CS1@-CPU@@@-@@ SYSMAC CJ Series CJ2H-CPU6@-EIP CJ2H-CPU6@ CJ2M-CPU@@ CJ1@-CPU@@@-@ SYSMAC One NSJ Series NSJ@@-@@@@@-@@@ Programmable Controllers Instructions Reference Manual Revised December 2018 CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 4 About this Manual: This manual describes the ladder diagram programming instructions of the CPU Units for CS/CJ- series Programmable Controllers (PLCs) and the NSJ-series Controllers. The CS Series, CJ Series and NSJ Series are subdivided as shown in the following table. Series Name Model numbers...
  • Page 5 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”...
  • Page 6 Omron’s exclusive warranty is that the Products will be free from defects in materials and work- manship for a period of twelve months from the date of sale by Omron (or such other period expressed in writing by Omron). Omron disclaims all other warranties, express or implied.
  • Page 7 Disclaimers Performance Data Data presented in Omron Company websites, catalogs and other materials is provided as a guide for the user in determining suitability and does not constitute a warranty. It may represent the result of Omron’s test conditions, and the user must correlate it to actual application requirements. Actual per- formance is subject to the Omron’s Warranty and Limitations of Liability.
  • Page 8 CJ2H-CPU65-EIP Unit version CPU UNIT Example for Unit version 1.0 Lot No. 080701 CPU Ver.1.0 OMRON Corporation MADE IN JAPAN Confirming Unit Versions CX-Programmer version 4.0 can be used to confirm the unit version using one with Support Software of the following two methods.
  • Page 9 Unit version Use the above display to confirm the unit version of the CPU Unit. Unit Manufacturing Information In the IO Table Window, right-click and select Unit Manufacturing informa- tion - CPU Unit. The following Unit Manufacturing information Dialog Box will be displayed. viii CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 10 Unit version Use the above display to confirm the unit version of the CPU Unit connected online. Using the Unit Version The following unit version labels are provided with the CPU Unit. Labels These labels can be attached to the front of previous CPU Units to differenti- ate between CPU Units of different unit versions.
  • Page 11 Units on which a version is given (Ver. @.@) given Lot No. XXXXXX XXXX Ver. @ @ .@ Lot No. XXXXXX XXXX OMRON Corporation MADE IN JAPAN Meaning CS1H-CPU67H CPU Unit Ver. @.@ Designating individual Pre-Ver. 2.0 CS1-H CPU Units CPU Units (e.g., the...
  • Page 12 Unit Versions CS Series Units Models Unit version CS1-H CPU Units CS1@-CPU@@H Unit version 4.0 Unit version 3.0 Unit version 2.0 Pre-Ver. 2.0 CS1D CPU Units Duplex-CPU Systems Unit version 1.2 CS1D-CPU@@H Unit version 1.1 Pre-Ver. 1.1 Single-CPU Systems Unit version 2.0 CS1D-CPU@@S CS1 CPU Units CS1@-CPU@@...
  • Page 13 Function Support by Unit Version • Functions Supported for Unit Version 4.0 or Later CX-Programmer 7.0 or higher must be used to enable using the functions added for unit version 4.0. CS1-H CPU Units Function CS1@-CPU@@H Unit version 4.0 or Other unit versions later Online editing of function blocks...
  • Page 14 • Functions Supported for Unit Version 3.0 or Later CX-Programmer 5.0 or higher must be used to enable using the functions added for unit version 3.0. CS1-H CPU Units Function CS1@-CPU@@H Unit version 3.0 or Other unit versions later Function blocks Serial Gateway (converting FINS commands to CompoWay/F commands at the built-in serial port) Comment memory (in internal flash memory)
  • Page 15 • Functions Supported for Unit Version 2.0 or Later CX-Programmer 4.0 or higher must be used to enable using the functions added for unit version 2.0. CS1-H CPU Units Function CS1-H CPU Units (CS1@-CPU@@H) Unit version 2.0 or Other unit versions later Downloading and Uploading Individual Tasks Improved Read Protection Using Passwords...
  • Page 16 CS1D CPU Units Function CS1D CPU Units for CS1D CPU Units for Duplex-CPU Single-CPU Systems Systems (CS1D-CPU@@H) (CS1D-CPU@@S) Unit version 2.0 Unit version 1.1 or Pre-Ver. 1.1 later Functions Duplex CPU Units unique to CS1D Online Unit Replacement CPU Units Duplex Power Supply Units Duplex Controller Link...
  • Page 17 CJ1-H/CJ1M CPU Units Function CJ1-H CPU Units CJ1M CPU Units CJ1H-CPU@@H-R CJ1M- CJ1@-CPU@@H CJ1M-CPU12/13/22/23 CPU11/21 CJ1G-CPU@@P Unit version Other unit Unit version Other unit Other unit 2.0 or later versions 2.0 or later versions versions Downloading and Uploading Individual Tasks Improved Read Protection Using Passwords OK Write Protection from FINS Commands Sent to CPU Units via Networks...
  • Page 18 Unit Versions and Programming Devices The following tables show the relationship between unit versions and CX-Pro- grammer versions. Unit Versions and Programming Devices CPU Unit Functions (See note 1.) CX-Programmer Program- ming Con- Ver. 3.3 Ver. Ver. 5.0 Ver. 7.0 sole or lower Ver.
  • Page 19 Device Type Setting The unit version does not affect the setting made for the device type on the CX-Programmer. Select the device type as shown in the following table regardless of the unit version of the CPU Unit. Series CPU Unit group CPU Unit model Device type setting on CX-Programmer Ver.
  • Page 20 Troubleshooting Problems with Unit Versions on the CX-Programmer Problem Cause Solution An attempt was made to down- Check the program or change load a program containing to a CPU Unit with a later unit instructions supported only by version. later unit versions or a CPU Unit to a previous unit version.
  • Page 21 Manual (W339) ,CJ-series Programmable CJ1G-CPU@@, Controller Operation Manual (W393) or CS1D NSJ@-@@@@(B)-G5D, NSJ@-@@@@(B)-M3D CPU Units (W394). Programmable Controllers Programming Manual SYSMAC CS Series W339 Provides an outline of, and describes the design, CS1G/H-CPU@@H installation, maintenance, and other basic opera- Programmable Controllers Operation Manual tions for the CS-series PLCs.
  • Page 22 NSJW-ETN21, NSJW-CLK21-V1, NSJW-IC101 Troubleshooting and maintenance Operation Manual Use this manual in combination with the following manuals: SYSMAC CS Series Operation Manual (W339), SYSMAC CJ Series Operation Manual (W393), SYSMAC CS/CJ Series Programming Manual (W394), and NS-V1/-V2 Series Setup Manual (V083)
  • Page 23 CS1W-SCB -V1, CS1W-SCU -V1, with external devices, including the usage of stan- CJ1W-SCU -V1, CJ1W-SCU dard system protocols for OMRON products. Serial Communications Boards/Units Operation Manual W344 Describes the use of the CX-Protocol to create CXONE-AL D-V4 protocol macros as communications sequences CX-Protocol Operation Manual to communicate with external devices.
  • Page 24 Safety Precautions 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 pre- cautions can result in injury to people or damage to property.
  • Page 25 xxiv CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 26 It is extremely important that a PLC and all PLC Units be used for the speci- fied 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-men- tioned applications. Safety Precautions...
  • Page 27 PRECAUTIONS !Caution Confirm safety before transferring data files stored in the file memory (Mem- ory Card or EM file memory) to the I/O area (CIO) of the CPU Unit using a peripheral tool. Otherwise, the devices connected to the Output Unit may mal- function regardless of the operating mode of the CPU Unit.
  • Page 28 PRECAUTIONS Operating Environment Precautions !Caution Do not operate the control system in the following locations: • Locations subject to direct sunlight. • Locations subject to temperatures or humidity outside the range specified in the specifications. • Locations subject to condensation as the result of severe changes in tem- perature.
  • Page 29 PRECAUTIONS • Observe the following precautions when using a Power Supply Unit that supports the Replacement Notification Function. • Replace the Power Supply Unit within six months if the display on the front of the Power Supply Unit alternates between 0.0 and A02, or if the alarm output automatically turns OFF.
  • Page 30 PRECAUTIONS • Do not apply voltages or connect loads to the Output Units in excess of the maximum switching capacity. Excess voltage or loads may result in burning. • Do not pull on the cables or bend the cables beyond their natural limit. Doing either of these may break the cables.
  • Page 31 PRECAUTIONS erwise subjected to excessive shock. Batteries that have been subjected to shock may leak if they are used. • UL standards require that only an experienced engineer can replace the battery. Make sure that an experienced engineer is in charge of battery replacement.
  • Page 32 PRECAUTIONS • Check the user program and Unit parameter settings for proper execution before actually running them on the Unit. Not checking the program and parameter settings may result in an unexpected operation. • When setting a Special I/O Unit or CPU Bus Unit in the I/O tables, care- fully check the safety of the devices at the connection target before restarting the Unit.
  • Page 33: Table Of Contents

    TABLE OF CONTENTS General Precautions ............!WARNINGSafety Precautions .
  • Page 34 TABLE OF CONTENTS Debugging Instructions ........... . . Failure Diagnosis Instructions .
  • Page 35: Basic Understanding Of Instructions

    SECTION 1 Basic Understanding of Instructions This section describes the basic information that is required to use programming instructions. Basic Understanding of Instructions ....... . Specifying Operands .
  • Page 36: Basic Understanding Of Instructions

    1. Basic Understanding of Instructions Basic Understanding of Instructions Structure of Instructions Programs consist of instructions. The conceptual structure of the inputs to and outputs from an instruction is shown in the following diagram. Power flow (P.F., execution condition) * Power flow (P.F., execution condition) Instruction condition * Instruction condition...
  • Page 37 1. Basic Understanding of Instructions The following instructions are used in pairs to set and cancel certain instruc- tion conditions. These paired instructions must be in the same task. Instruction Description Setting Canceling condition instruction instruction Interlocked An interlock turns OFF part of the IL(002) ILC(003) program.
  • Page 38 1. Basic Understanding of Instructions Example &3 S (source) N (number) D (destination) Operand types Operand Description symbol Source Specifies the address of Source Source operand the data to be read or a Operand other than control constant. data (C) Control Compound data in a data...
  • Page 39 1. Basic Understanding of Instructions Instruction Variations The following variations are available for instructions to differentiate executing conditions and to refresh data when the instruction is executed (immediate refresh). Variation Symbol Description Differentiation Instruction that differentiates when the execution condition turns ON. OFF % Instruction that differentiates when the execution condition turns OFF.
  • Page 40 1. Basic Understanding of Instructions Input-differentiated Instructions Upwardly Differentiated Instructions (Instruction Preceded by @) ■ Output Instructions: The instruction is executed only during the cycle in which the execution condi- tion turned ON (OFF → ON) and are not executed in the following cycles. The instruction is executed only during the cycle in which the execution condi- tion turned ON (OFF →...
  • Page 41 1. Basic Understanding of Instructions Time Chart ■ Bit A Bit B Bit A Bit B Downwardly Differentiated Instructions (Instruction Preceded by %) ■ Output Instructions: The instruction is executed only during the cycle in which the execution condi- tion turned OFF (ON → OFF) and is not executed in the following cycles. 1.02 Example (%) Downwardly...
  • Page 42 1. Basic Understanding of Instructions Input Instructions (Logical Starts and Intermediate Instructions): The instruction reads bit status, makes comparisons, tests bits, or perform other types of processing every cycle and will output an OFF execution condi- tion (power flow stops) when results switch from ON to OFF. Example Downwardly differentiated input instruction 1.03...
  • Page 43 1. Basic Understanding of Instructions I/O Instruction Timing The following timing chart shows different operating timing for individual instructions using a program comprised of only LD and OUT instructions. Input read Input read Input read Input read Input read Input read Input read...
  • Page 44 1. Basic Understanding of Instructions Differentiated Instructions • A differentiated instruction has an internal flag that tells whether the previ- ous value is ON or OFF. At the start of operation, the previous value flags for upwardly differentiated instruction (DIFU and @ instructions) are set to ON and the previous value flags for downwardly differentiated instructions (DIFD and % instructions) are set to OFF.
  • Page 45: Specifying Operands

    1. Basic Understanding of Instructions Specifying Operands Addressing I/O Memory Areas Bit Addresses @@@@.@@ Bit number (00 to 15) Word address Example: The address of bit 03 in word 1 in the CIO Area would be as shown below. 1. 03 Bit number: 03 Word address: 0001 Bit: CIO 0001.03...
  • Page 46 1. Basic Understanding of Instructions Example: EM Area The address for word E200 in the current bank would be as shown below. E200 Word address Example: EM Area Bank 1 The address for word E200 in bank 1 would be as shown below. E01_200 Word address Bank number...
  • Page 47 1. Basic Understanding of Instructions Operand Description Notation Application examples Specifying offsets for In brackets, specify the number of bits to MOV 3 D0[200] D0[2] offset the specified starting bit address. Number of words to word addresses offset address Starting word address @@@@.[@@] Number of words to Offset...
  • Page 48 1. Basic Understanding of Instructions Operand Description Notation Application examples Specifying indirect E0 _0 to E0 _32767 of bank 0 in Extended @D300 Data Memory (EM) are specified if DM/EM addresses in @D(@@@@@) contains 8000 Hex to FFFF &32769 Contents Binary Mode Hex (32768 to 65535).
  • Page 49 1. Basic Understanding of Instructions Operand Description Notation Application examples Specifying a An index register (IR) or a data register (DR) is MOVR 1.02 IR0 register directly specified directly by specifying IR@ (@: 0 to 15) or Stores the PLC memory address for (See note.) DR@ (@: 0 to 15).
  • Page 50 1. Basic Understanding of Instructions Data Operand Data form Symbol Range Application example 16-bit All binary data or a Unsigned binary #0000 to #FFFF MOV #0100 D0 constant limited range of binary Stores #0100 hex (&256 decimal) data in D0. +#0009 #0001 D1 Stores #000A hex (&10 decimal) in D1.
  • Page 51 1. Basic Understanding of Instructions Text string Description Symbol Examples Text string data is stored in ABCDE MOV$ D100 D200 ASCII (one byte except for D100 special characters) in order ‘A’ ‘B’ from the leftmost to the D101 ‘C’ ‘D’ rightmost byte and from the D102 ‘E’...
  • Page 52 1. Basic Understanding of Instructions Precautions for Correct Use Precautions for Correct Use The following instructions are executed even when the input conditions are OFF. Therefore, when indirect memory addresses are specified using auto-incrementing or auto-decrementing (,IR+ or ,IR-) in an operand of any of these instructions, the value in the Index Register (IR) is refreshed each cycle regardless of the input condition (increases or decreases one every cycle).
  • Page 53: Data Formats

    1. Basic Understanding of Instructions Data Formats The following table shows the data formats that the CJ Series can handle. Data type Data format Decimal 4-digit hexadecimal Unsigned &0 to #0000 to binary #FFFF &65535 Binary Decimal 3 2 7 6 8 1 6 3 8 4 8 1 9 2 4 0 9 6 2 0 4 8 1 0 2 4 5 1 2 2 5 6...
  • Page 54 1. Basic Understanding of Instructions Data type Data format Decimal 4-digit hexadecimal Single precision floating point Binary decimal Exponent Sign of Mantissa mantissa × 1.[Mantissa] × 2 Exponent 1: negative or 0: positive Sign (bit 31) Mantissa The 23 bits from bit 00 to bit 22 contain the mantissa, i.e., the portion below the decimal point in 1.@@@@.., in binary.
  • Page 55 1. Basic Understanding of Instructions The two's complement b Hex of a Hex is FFFF Hex − a Hex + 0001 Hex = b Hex. To determine the two's complement b Hex of “a Hex,” use b Hex = 10000 Hex − a Hex. Example: to determine the two's complement of 3039 Hex, use 10000 Hex −...
  • Page 56 1. Basic Understanding of Instructions CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 57: Instructions (Applicable Cpu Units)

    SECTION 2 Instructions (Applicable CPU Units) Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Sequence LOAD Indicates a logical start and cre- Input ates an ON/OFF execution condi- Instructions tion based on the ON/OFF status of the specified operand bit.
  • Page 58 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Sequence LOAD BIT LD TST LD TST(350) is used in the pro- Input TEST gram like LD; the execution condi- Instructions tion is ON when the specified bit in the specified word is ON, and...
  • Page 59 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Sequence SINGLE BIT RSTB RSTB(533) turns OFF the speci- Output RESET fied bit. @RSTB Instructions !RSTB !@RSTB SINGLE BIT OUTB OUTB(534) outputs the status of OUTPUT...
  • Page 60 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Timer and LONG TIMER TIML TIML(542)/TIMLX(553) operates Counter a decrementing timer with units of Instructions TIMLX 0.1s. MULTI-OUT- MTIM MTIM(543)/MTIMX(554) oper- PUT TIMER...
  • Page 61 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Comparison AREA RANGE Compares a 16-bit unsigned Instructions COMPARE binary value (CD) with the range defined by lower limit LL and upper limit UL.
  • Page 62 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Data Shift ARITHMETIC ASR/ Shifts the contents of Wd one bit Instruction SHIFT RIGHT @ASR to the right. DOUBLE SHIFT ASRL/ Shifts the contents of Wd and Wd...
  • Page 63 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Symbol SIGNED Adds 4-digit (single-word) hexa- Math BINARY ADD decimal data and/or constants. Instructions WITHOUT CARRY DOUBLE Adds 8-digit (double-word) hexa- SIGNED decimal data and/or constants.
  • Page 64 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Symbol DOUBLE Divides 8-digit (double-word) Math SIGNED signed hexadecimal data and/or Instructions BINARY constants. DIVIDE UNSIGNED Divides 4-digit (single-word) BINARY unsigned hexadecimal data DIVIDE...
  • Page 65 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Conversion DOUBLE GRAY GRAY_BINL/ Converts the specified two words Instructions CODE TO @GRAY_BINL of gray code to two words of BINARY CON- binary data.
  • Page 66 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Floating- FLOATING TO FIX/ Converts a 32-bit floating-point point Math 16-BIT @FIX value to 16-bit signed binary data Instructions and places the result in the speci- fied result word.
  • Page 67 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Floating- EXPONENTIAL PWR/ Raises a 32-bit floating-point point Math POWER @PWR number to the power of another Instructions 32-bit floating-point number.
  • Page 68 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Double- DOUBLE TAN- TAND/ Calculates the tangent of a dou- precision GENT @TAND ble-precision (64-bit) floating-point Floating- number (in radians) and places point the result in the specified destina- Instructions...
  • Page 69 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Table Data STACK DATA SDEL/ Deletes the data element at the Processing DELETE @SDEL specified location in the stack, out- Instructions puts that data to the specified desti- nation word, and shifts the...
  • Page 70 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Tracking Unsigned Two- RSRCH2 < , An Unsigned Two-word Record Instructions word Record @RSRCH2 < Search Instruction searches the Search Instruc- specified table of records for a RSRCH2 <= ,...
  • Page 71 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Subroutines SUBROUTINE SBS/ Calls the subroutine with the CALL @SBS specified subroutine number and executes that program. MACRO MCRO/ Calls the subroutine with the speci- @MCRO...
  • Page 72 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H High-speed ACCELERA- ACC/ ACC(888) outputs pulses to the Ver. Counter/ TION CON- @ACC specified output port at the speci- 2.0 or Pulse TROL...
  • Page 73 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Basic INTELLIGENT IORD/ Reads the contents of memory I/O Unit I/O READ @IORD area of a Special I/O Unit or CPU Instructions Bus Unit.
  • Page 74 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Network NETWORK SEND/ Sends data to a node in the net- Instructions SEND @SEND work. NETWORK SEND2/ Sends data to a node on a net- SEND 2 @SEND2 work.
  • Page 75 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Other SET CARRY STC/ Sets the Carry Flag (CY). Instructions @STC CLEAR CARRY CLC/ Turns OFF the Carry Flag (CY). @CLC SELECT EM EMBC/...
  • Page 76 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Block HUNDRED-MS TIMW Delays execution of the rest of the Programming TIMER WAIT block program until the specified Instructions TIMWX time has elapsed.
  • Page 77 2. Instructions (Applicable CPU Units) CJ1M CS1D CJ1-H/ CJ1/ Classification Instruction Mnemonic Function CJ2H CJ2M Page code CS1-H -CPU1@ -CPU2@ -SA/S -HA/H Special GET VARI- GETID/ Outputs the FINS command vari- Ver. Ver. Ver. Ver. Ver. 1056 Function ABLE ID @GETID able type (data area) code and 3.0 or...
  • Page 78 2. Instructions (Applicable CPU Units) CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 79: Instructions

    SECTION 3 Instructions This section describes each of the instructions that can be used in programming NSJ/CS/CJ-series PLCs. Instructions are described in order of function, as classified in Section 2 Summary of Instructions. Notation and Layout of Instruction Descriptions ........Sequence Input Instructions .
  • Page 80 BCMP ............. . . BCMP2 .
  • Page 81 LINE ..............COLM.
  • Page 82 SWRIT ............. . SINS .
  • Page 83 PWM..............IFEED .
  • Page 84 Failure Diagnosis Instructions ........... FAL.
  • Page 85: Section 3Notation And Layout Of Instruction Descriptions

    3. Instructions Notation and Layout of Instruction Descriptions Instructions are described in groups by function. Refer to Appendix A List of Instructions by Function Code for a list of instructions by mnemonic that lists the page number in this section for each instruction. The description of each instruction is organized as described in the following table.
  • Page 86 3. Instructions Item Contents Flags The flags table indicates the status of the condition flags immediately after execution of the instruction. Any flags that are not listed are not affected by the instruction. “OFF” indicates that a flag is turned OFF immediately after execution of the instruction regardless of the results of executing the instruction.
  • Page 87 3. Instructions Condition Flags Programming Console labels are used for condition flags in this section. With the CX-Programmer, the condition flags are registered in advance as global symbols with “P_” in front of the symbol name. Flag CX-Programmer label Programming Console label Error Flag P_ER Access Error Flag...
  • Page 88: Sequence Input Instructions

    3. Instructions Sequence Input Instructions Differentiated and Immediate Refreshing Instructions • The LOAD, AND, and OR instructions have differentiated and immediate refreshing variations in addition to their ordinary forms, and there are also two combinations available. • The LOAD NOT, AND NOT, OR NOT, OUT, and OUT NOT instructions have immediate refreshing variations in addition to their ordinary forms.
  • Page 89 3. Instructions  Operation Timing for I/O Instructions The following chart shows the differences in the timing of instruction operations for a program configured from LD and OUT. Input received Input received Input ↑ received Input ↓ received Input received Input received Input...
  • Page 90 3. Instructions LD/LD NOT Function Instruction Mnemonic Variations Function code Indicates a logical start and creates an ON/OFF @LD, %LD, !LD, LOAD execution condition based on the ON/OFF status !@LD, !%LD of the specified operand bit. @LD NOT, %LD Indicates a logical start and creates an ON/OFF NOT, ! LD NOT, LOAD NOT LD NOT...
  • Page 91 3. Instructions Hint • LD/LD NOT is used in the following circumstances as an instruction for indicating a logical start. 1. When directly connecting to the bus bar. 2. When logic blocks are connected by AND LD or OR LD, i.e., at the beginning of a logic block. The AND LOAD and OR LOAD instructions are used to connect in series or in parallel logic blocks beginning with LD or LD NOT.
  • Page 92 3. Instructions AND/AND NOT Function Instruction Mnemonic Variations Function code @AND, %AND, Takes a logical AND of the status of the specified !AND, !@AND, operand bit and the current execution condition. !%AND @AND NOT, %AND NOT, Reverses the status of the specified operand bit AND NOT AND NOT !AND NOT,...
  • Page 93 3. Instructions Precautions • Differentiate up (@) or differentiate down (%) can be specified for AND. If differentiate up (@) is specified, the execution condition is turned ON for one cycle only after the status of the operand bit goes from OFF to ON. If differentiate down (%) is specified, the execution condition is turned ON for one cycle only after the status of the operand bit goes from ON to OFF.
  • Page 94 3. Instructions OR/OR NOT Function Instruction Mnemonic Variations Function code @OR, %OR, Takes a logical OR of the ON/OFF status of the !OR, !@OR, specified operand bit and the current execution !%OR condition. @OR NOT, %OR NOT, !OR NOT, Reverses the status of the specified bit and takes OR NOT OR NOT !@OR NOT,...
  • Page 95 3. Instructions Precautions • Differentiate up (@) or differentiate down (%) can be specified for OR. If differentiate up (@) is specified, the execution condition is turned ON for one cycle only after the status of the operand bit goes from OFF to ON. If differentiate down (%) is specified, the execution condition is turned ON for one cycle only after the status of the operand bit goes from ON to OFF.
  • Page 96 3. Instructions AND LD/OR LD Function Instruction Mnemonic Variations Function code AND LOAD AND LD Takes a logical AND between logic blocks. OR LOAD OR LD Takes a logical OR between logic blocks. AND LD OR LD Logic block Symbol Logic block Logic block Logic block...
  • Page 97 3. Instructions Precautions • When a logic block is connected by AND LOAD or OR LOAD instructions, the total number of AND LOAD/OR LOAD instructions must match the total number of LOAD/LOAD NOT instructions minus 1. If they do not match, a programming error will occur. •...
  • Page 98 3. Instructions Example Programming  AND LD Coding Example (1) Coding Example (2) 5.00 0.00 0.02 0.04 Instruction Operand Instruction Operand 0.00 0.00 0.01 0.03 0.05 OR NOT 0.01 OR NOT 0.01 LD NOT 0.02 LD NOT 0.02 0.03 0.03 AND LD 0.04 0.04...
  • Page 99 3. Instructions Function Instruction Mnemonic Variations Function code Reverses the execution condition. Symbol NOT(520) Applicable Program Areas Function block SFC action or Area Block program areas Step program areas Subroutines Interrupt tasks definitions transition programs Usage Flags There are no flags affected by NOT(520). Function NOT(520) is placed between an execution condition and another instruction to invert the execution condition.
  • Page 100 3. Instructions UP/DOWN Function Instruction Mnemonic Variations Function code UP(521) turns ON the execution condition for the CONDITION ON next instruction for one cycle when the execution condition it receives goes from OFF to ON. DOWN(522) turns ON the execution condition for CONDITION OFF DOWN the next instruction for one cycle when the execu-...
  • Page 101 3. Instructions Note Observe the following precaution when using UP(521) and DOWN(522) in a subroutine. • The operation of UP(521) and DOWN(522) will not be consistent if the same subroutine is executed more than once in the same cycle. • An subroutine will not be executed while the input condition for the subroutine is OFF. Caution is thus required when using UP(521) and DOWN(522) in a function block definition.
  • Page 102 3. Instructions LD TST/LD TSTN Function Instruction Mnemonic Variations Function code LD TST(350) is used in the program like LD; the execution condition is ON when the specified bit in LOAD BIT TEST LD TST the specified word is ON, and OFF when the bit is OFF.
  • Page 103 3. Instructions Function  LD TST LD TST(350) is used in the program like LD; the execution condition is ON when the specified bit in the specified word is ON, and OFF when the bit is OFF.  LD TSTN LD TSTN(351) is used in the program like LD NOT;...
  • Page 104 3. Instructions AND TST/AND TSTN Function Instruction Mnemonic Variations Function code AND TST(350) is used in the program like AND; the execution condition is ON when the specified AND BIT TEST AND TST bit in the specified word is ON, and OFF when the bit is OFF.
  • Page 105 3. Instructions Function  AND TST AND TST(350) is used in the program like AND; the execution condition is ON when the specified bit in the specified word is ON, and OFF when the bit is OFF.  AND TSTN AND TSTN(351) is used in the program like AND NOT;...
  • Page 106 3. Instructions OR TST/OR TSTN Function Instruction Mnemonic Variations Function code OR TST(350) is used in the program like OR; the execution condition is ON when the specified bit in OR BIT TEST OR TST the specified word is ON, and OFF when the bit is OFF.
  • Page 107 3. Instructions Function  OR TST OR TST(350) is used in the program like OR; the execution condition is ON when the specified bit in the specified word is ON, and OFF when the bit is OFF.  OR TSTN OR TSTN(351) is used in the program like OR NOT;...
  • Page 108: Sequence Output Instructions

    3. Instructions Sequence Output Instructions OUT/OUT NOT Function Instruction Mnemonic Variations Function code Outputs the result (execution condition) of the OUTPUT !OUT logical processing to the specified bit. Reverses the result (execution condition) of the OUTPUT NOT OUT NOT !OUT NOT logical processing, and outputs it to the specified bit.
  • Page 109 3. Instructions Hint • Immediate refreshing (!) can be specified for OUT and OUT NOT. An immediate refresh instruction updates the status of the output terminal just after the instruction is executed for the Basic Output Unit (but not for Basic Output Units on Slave Racks or for C200H Group 2 Multi-point Input Units), at the same time as it writes the status of the execution condition (power flow) to the specified output bit in I/O memory.
  • Page 110 3. Instructions Function Instruction Mnemonic Variations Function code TR bits are used to temporarily retain the ON/OFF TR Bits status of execution conditions in a program when programming in mnemonic code. Function TR bits are used to temporarily retain the ON/OFF status of execution conditions in a program when programming in mnemonic code.
  • Page 111 3. Instructions  TR0 to TR15 Considerations TR bits are used only for retaining (OUT TR0 to TR15) and restoring (LD TR0 to TR15) the ON/OFF status of branching points in programs with many output branches. They are thus different from general bits, and cannot be used with AND or OR instructions, or with instructions that include NOT.
  • Page 112 3. Instructions KEEP Function Instruction Mnemonic Variations Function code KEEP KEEP !KEEP Operates like a latching relay. KEEP S(SET) Symbol KEEP(011) R(RESET) Applicable Program Areas Function block SFC action or transition Area Block program areas Step program areas Subroutines Interrupt tasks definitions programs Usage...
  • Page 113 3. Instructions Hint • KEEP(011) has an immediate refreshing variation (!KEEP(011)). When an external output bit has been specified for B in a !KEEP(011) instruction, any changes to B will be refreshed when !KEEP(011) is executed and reflected immediately in the output bit. (The changes will not be reflected immediately if the bit is allocated to a Group-2 High-density I/O Unit, High-density Special I/O Unit, or a Unit mounted in a SYSMAC BUS Remote I/O Slave Rack.) •...
  • Page 114 3. Instructions • If a holding bit is used for B, the bit status will be retained even during a power interruption. KEEP(011) can thus be used to program bits that will maintain status after restarting the PLC following a power interruption. An example of this that can be used to produce a warning display following a system shutdown for an emergency situation is shown below.
  • Page 115 3. Instructions Example Programming When CIO 0.00 goes ON in the left example, CIO 5.00 is 0.00 turned ON. CIO 5.00 remains ON until CIO 0.01 goes 5.00 When CIO 0.02 goes ON and CIO 0.03 goes OFF in the 0.01 left example, CIO 1.00 is turned ON.
  • Page 116 3. Instructions DIFU Function Instruction Mnemonic Variations Function code DIFU(013) turns the designated bit ON for one DIFFERENTIATE UP DIFU !DIFU cycle when the execution condition goes from OFF to ON (rising edge). DIFU Symbol DIFU(013) B: Bit Applicable Program Areas SFC action or transition Function block Area...
  • Page 117 3. Instructions Precautions • The operation of DIFU(013) depends on the execution condition for the instruction itself as well as the execution condition for the program section when it is programmed in an interlocked program section, a jumped program section, or a subroutine. •...
  • Page 118 3. Instructions DIFD Function Instruction Mnemonic Variations Function code DIFD(014) turns the designated bit ON for one DIFFERENTIATE DOWN DIFD !DIFD cycle when the execution condition goes from ON to OFF (falling edge). DIFD Symbol DIFD(014) B: Bit Applicable Program Areas Function block SFC action or transition Area...
  • Page 119 3. Instructions Precautions • The operation of DIFD(014) depends on the execution condition for the instruction itself as well as the execution condition for the program section when it is programmed in an interlocked program section, a jumped program section, or a subroutine. •...
  • Page 120 3. Instructions SET/RSET Function Instruction Mnemonic Variations Function code SET turns the operand bit ON when the execution @SET, %SET, condition is ON. After this, the specified contact !SET, !@SET, will remain ON regardless of ON/OFF of the input !%SET condition.
  • Page 121 3. Instructions Hint • Differences between OUT/OUT NOT and SET/RSET The operation of SET differs from that of OUT because the OUT instruction turns the operand bit OFF when its execution condition is OFF. Likewise, RSET differs from OUT NOT because OUT NOT turns the operand bit ON when its execution condition is OFF.
  • Page 122 3. Instructions SETA/RSTA Function Instruction Mnemonic Variations Function code SETA(530) turns ON the specified number of MULTIPLE BIT SET SETA @SETA consecutive bits. RSTA(531) turns OFF the specified number of MULTIPLE BIT RESET RESTA @RSTA consecutive bits. SETA RSTA SETA(530) RSTA(531) Beginning word Beginning word...
  • Page 123 3. Instructions  RSTA RSTA(531) turns OFF N2 bits, beginning from bit N1 of D, and continuing to the left (more-significant bits). All other bits are N2 bits are left unchanged. (No changes will be reset to 0 (OFF). made if N2 is set to 0.) Bits turned OFF by RSTA(531) can be turned ON by any other instructions, not just SETA(530).
  • Page 124 3. Instructions SETB/RSTB Function Instruction Mnemonic Variations Function code @SETB, !SETB, SINGLE BIT SET SETB SETB(532) turns ON the specified bit. !@SETB @RSTB, !RSTB, SINGLE BIT RESET RSTB RSTB(533) turns OFF the specified bit. !@RSTB SETB RSTB SETB(532) RSTB(533) Symbol D: Word address D: Word address N: Bit number...
  • Page 125 3. Instructions  RSTB RSTB(533) turns OFF bit N of word D when the execution condition is ON. The This bit is turned OFF. status of the bit is not affected when the execution condition OFF. (Use SETB(532) to turn ON the bit.) Execution condition Bit N of word D Hint...
  • Page 126 3. Instructions OUTB Function Instruction Mnemonic Variations Function code OUTB(534) outputs the status of the instruction's SINGLE BIT OUTPUT OUTB !OUTB execution condition to the specified bit. OUTB OUTB(534) Symbol D: Word address N: Bit number Applicable Program Areas Function block SFC action or transition Area Block program areas...
  • Page 127 3. Instructions Hint • Difference between SETB(532)/RSTB(533) and OUTB(534) For OUTB(534), the operand bit is turned ON when the input condition turns ON and is turned OFF when the input condition turns OFF. For SETB(532) and RSTB(533), the operand bit turns ON or OFF, respectively, when the input condition turns ON and the operand bit does not change when the input condition turns OFF.
  • Page 128: Sequence Control Instructions

    3. Instructions Sequence Control Instructions Overview of Interlock Instructions  Interlock Instructions The following instruction combinations can be used to interlock outputs in a program section. • INTERLOCK and INTERLOCK CLEAR (IL(002) and IL(003)) • MULTI-INTERLOCK DIFFERENTIATION HOLD and MULTI-INTERLOCK CLEAR (MILH(517) and MILC(519))* Note MILH(517) holds the status of the Differentiation Flag, so differentiated instructions that were interlocked are executed after the interlock is cleared.
  • Page 129 3. Instructions  Differences between MILH(517) and MILR(518) Differentiated instructions (DIFU, DIFD, or instructions with a @ or % prefix) operate differently in interlocks created with MILH(517) and MILR(518). The operation of differentiated instructions in an interlock created with MILH(517) is identical to the operation in an interlock created with IL(002).
  • Page 130 3. Instructions  Differences between Interlocks and Jumps The following table shows the differences between interlocks (created with IL(002)/ILC(003), MILH(517)/MILC(519), or MILR(518)/MILC(519)) and jumps created with JMP(004)/JME(005). Treatment in IL(002)/ILC(003), Treatment in Item MILH(517)/MILC(519), or JMP(004)/JME(005) MILR(518)/MILC(519)) Instruction execution Except OUT, OUT NOT, OUTB(534), and No instructions are executed.
  • Page 131 3. Instructions Function Instruction Mnemonic Variations Function code Indicates the end of a program. Symbol END(001) Applicable Program Areas Function block SFC action or Area Block program areas Step program areas Subroutines Interrupt tasks definitions transition programs Usage Not allowed Not allowed Not allowed Not allowed...
  • Page 132 3. Instructions Function Instruction Mnemonic Variations Function code NO OPERATION This instruction has no function. Symbol (There is no ladder symbol associated with NOP(000).) Applicable Program Areas Function block SFC action or Area Block program areas Step program areas Subroutines Interrupt tasks definitions transition programs...
  • Page 133 3. Instructions IL/ILC Function Instruction Mnemonic Variations Function code Interlocks all outputs between IL(002) and INTERLOCK ILC(003) when the execution condition for IL(002) is OFF. INTERLOCK CLEAR Indicates the end of the interlock range. Symbol IL(002) ILC(003) Applicable Program Areas Function block SFC action or Area...
  • Page 134 3. Instructions Hint • If there are bits which you want to remain ON in an interlocked program section, set these bits to ON with SET just before IL(002). • It is often more efficient to switch a program section with IL(002) and ILC(003). When several processes are controlled with the same execution condition, it takes fewer program steps to put these processes...
  • Page 135 3. Instructions  Operation of Differentiated Instructions If there is a differentiated instruction (DIFU, DIFD, or instruction prefixed by @ or %) between IL(002) and ILC(003) instructions, that instruction will be executed when the interlock is cleared if the differentiation condition of the instruction is satisfied by means of a change in the input condition between starting and clearing of the interlock.
  • Page 136 3. Instructions Example Programming When CIO 0.00 is OFF in the right example, all outputs between IL(002) and ILC(003) are interlocked. When CIO 0.00 is ON in the right 0.00 0.00 ON 0.00 OFF example, the instructions between IL(002) and ILC(003) are executed normally.
  • Page 137 3. Instructions MILH/MILR/MILC Function Instruction Mnemonic Variations Function code Interlocks all outputs between MILH(517) and MULTI-INTERLOCK MILH MILC(519) when the execution condition for DIFFERENTIATION HOLD MILH(517) is OFF. Interlocks all outputs between MILR(518) and MULTI-INTERLOCK MILR MILC(519) when the execution condition for DIFFERENTIATION RELEASE MILR(518) is OFF.
  • Page 138 3. Instructions Function When the execution condition for MILH(517) (or MILR(518)) with interlock number N is OFF, the outputs for all instructions between that MILH(517)/MILR(518) instruction and the next MILC(519) with interlock number N are interlocked. When the execution condition for MILH(517) (or MILR(518)) with interlock number N is ON, the instructions between that MILH(517)/MILR(518) instruction and the next MILC(519) with interlock number N are executed normally.
  • Page 139 3. Instructions • A1 and A2 are interlocked when the Global interlock Emergency Stop Button is ON. (Emergency stop) When the Emergency Stop is ON (input MILH • A2 is interlocked when Conveyor condition OFF), both A1 and A2 are RUN is OFF.
  • Page 140 3. Instructions  Differences between MILH(517) and MILR(518) Differentiated instructions (DIFU, DIFD, or instructions with a @ or % prefix) operate differently in interlocks created with MILH(517) and MILR(518). When a program section is interlocked with MILR(518), a differentiated instruction will not be executed when the interlock is cleared even if the differentiation condition was activated during the interlock (comparing the status of the execution condition when the interlock started to its status when the interlock was cleared).
  • Page 141 3. Instructions  Operation of Differentiated Instructions in an MILR(518) Interlock If there is a differentiated instruction (DIFU, DIFD, or instruction with a @ or % prefix) between MILR(518) and the corresponding MILC(519), that instruction will not be executed after the interlock is cleared even if the differentiation condition of the instruction was established.
  • Page 142 3. Instructions Hint • The cycle time is not shortened when a section of the program is interlocked by MILH(517) or MILR(518) because the interlocked instructions are executed internally. • When nesting interlocks, assign interlock numbers so that the nested program section does not exceed the outer program section.
  • Page 143 3. Instructions • If there is an ILC(003) instruction between MILR an MILR(518) and MILC(519) pair, the When input condition "a" is OFF, program sections A1 and A2 are interlocked. ILC(003) instruction will be ignored and the full program section between MILR(518) and MILC(519) will be interlocked.
  • Page 144 3. Instructions • Program operation can be switched more efficiently by using interlocks with MILH(517) or MILR(518). Instead of switching processing with compound conditions, insert an MILH(517) or MILR(518) instruction before each process and an MILC(519) instruction after each process. MILH MILH MILC...
  • Page 145 3. Instructions Example Programming When W0.00 and W0.01 are both ON, the instructions between MILH(517) with interlock number 0 and MILC(519) with interlock number 0 are executed normally. When W0.00 is OFF, the instructions between MILH(517) with interlock number 0 and MILC(519) with interlock number 0 are interlocked.
  • Page 146 3. Instructions JMP/JME Function Instruction Mnemonic Variations Function code When the execution condition for JMP(004) is OFF, program execution jumps directly to the first JUMP JME(005) in the program with the same jump number. Indicates the end position of a jump by JMP or JUMP END CJP instruction.
  • Page 147 3. Instructions Function When the execution condition for JMP(004) is ON, no Execution condition jump is made and the program is executed consecu- Instructions tively as written. jumped When the execution condition for JMP(004) is OFF, Instructions in this section are not executed program execution jumps directly to the first Instructions and output status is...
  • Page 148 3. Instructions • In block programs, the instructions between JMP(004) and JME(005) are always skipped regardless of the status of the execution condition for JMP(004). Block program section JMP &1 JME &1 • JMP(004) and JME(005) pairs must be in the same task because jumps between tasks are not allowed.
  • Page 149 3. Instructions CJP/CJPN Function Instruction Mnemonic Variations Function code When the execution condition for CJP(510) is ON, program execution jumps directly to the first CONDITIONAL JUMP JME(005) in the program with the same jump number. When the execution condition for CJP(004) is OFF, program execution jumps directly to the first CONDITIONAL JUMP NOT CJPN...
  • Page 150 3. Instructions Function  CJP Execution Execution condition OFF condition ON When the execution condition for Instructions CJP(510) is OFF, no jump is made jumped and the program is executed con- secutively as written. Instructions in this section are not When the execution condition for executed and output status is Instructions...
  • Page 151 3. Instructions • When JME(005) precedes the CJP(510) or CJPN(511) instruction in the program, the instructions in- between will be executed repeatedly as long as the execution condition remains OFF (CJP(510)) or ON (CJPN(511)). A Cycle Time Too Long error will occur if the jump is not completed by changing the execution condition executing END(001) within the maximum cycle time.
  • Page 152 3. Instructions JMP0/JME0 Function Instruction Mnemonic Variations Function code When the execution condition for JMP0(515) is MULTIPLE JUMP JMP0 OFF, all instructions from JMP0(515) to the next JME0(516) in the program are processed as MULTIPLE JUMP END JME0 NOP(000). JMP0 JME0 Symbol JMP0(515)
  • Page 153 3. Instructions Hint • In the case of a JMP, CJP, or CJPN instruction, the program jumps directly to the JME instruction when the jump condition is satisfied. An instruction is not executed between JMP/CJP/CJPN and JME, and thus instruction execution time is not needed in that interval. Therefore, cycle time is reduced.
  • Page 154 3. Instructions Example Programming When CIO 0.00 is OFF in the following example, the instructions between JMP0(515) and JME0(516) are 0.00 processed as NOP(000) instructions and the outputs CIO 0.00 CIO 0.00 maintain their previous status. When CIO 0.00 is ON in the following example, the instructions between JMP0(515) and JME0(516) are executed normally.
  • Page 155 3. Instructions FOR/NEXT Function Instruction Mnemonic Variations Function code The instructions between FOR(512) and NEXT(513) are repeated a specified number of NEXT times. NEXT FOR(512) NEXT(513) Symbol N: Number of loops Applicable Program Areas Function block SFC action or Area Block program areas Step program areas Subroutines...
  • Page 156 3. Instructions Hint There are two ways to repeat a program section until a given execution condition is input. • FOR-NEXT Loop with BREAK Start a FOR-NEXT loop with a maximum of N repetitions. Program BREAK(514) within the loop with the desired execution condition.
  • Page 157 3. Instructions • A jump instruction such as JMP(004) may be executed within a FOR-NEXT loop, but do not jump beyond the FOR-NEXT loop. • The following instructions cannot be used within FOR-NEXT loops: • Block programming instructions • MULTIPLE JUMP and JUMP END: JMP(515) and JME(516) •...
  • Page 158 3. Instructions BREAK Function Instruction Mnemonic Variations Function code Programmed in a FOR-NEXT loop to cancel the execution of the loop for a given execution condi- BREAK LOOP BREAK tion. The remaining instructions in the loop are processed as NOP(000) instructions. BREAK Symbol BREAK(514)
  • Page 159: Timer And Counter Instructions

    3. Instructions Timer and Counter Instructions Timer Instructions Refresh Methods for Timer/Counter PV  Overview There are two PV refresh methods for instructions related to timer/counters, “BCD” and “BINARY”. Method Description Setting range Set value Sets the timer set value in BCD. 0~9.999 #0000~9999 Binary...
  • Page 160 3. Instructions  Basic Timer Specifications TIM/TIMX TIMH(015)/ TMHH(540)/ TIMU(541)/ TMUH(544)/ TTIM(087)/ TIML(542)/ MTIM(543)/ Item (550) TIMHX(551) TMHHX(552) TIMUX(556) TMUHX(557) TTIMX(555) TIMLX(553) MTIMX(554) (See note 3.) (See note 3.) Decrementin Decrementing Decrementing Decrementing Decrementing Incrementing Decrementing Incrementing Timing method Timing units 100 ms 10 ms 1 ms...
  • Page 161 3. Instructions Example Timer and Counter Applications Example 1: Long-term Timers The following program examples show three ways to create long-term timers with standard TIM and CNT instructions. 1) Two TIM Instructions In this example, two TIM instructions are combined to make a 30-minute timer. 0.00 (900 seconds) Instruction Operands...
  • Page 162 3. Instructions Example 2: Two-stage Counter When an SV higher than 9999 is required, two counters can be combined as shown in the following example. In this case, two CNT instructions are combined to make a BCD counter with an SV of 20,000.
  • Page 163 3. Instructions Example 4: One-shot Bit A TIM timer can be combined with OUT or OUT NOT to control how long a particular bit is ON or OFF. In this example, CIO 2.04 will be ON for 1.5 seconds (the SV of T0001) after CIO 0.00 goes ON. 10.00 0.00 Instruction Operands...
  • Page 164 3. Instructions Indirect Addressing of Timer/Counter Numbers • Timer and counter numbers can be indirectly addressed using Index Registers. When Index Registers will be used for indirect addressing, use MOVRW(561) (MOVE TIMER/COUNTER PV TO REGISTER) to set the PLC memory address of the desired timer or counter's PV to the desired Index Register.
  • Page 165 3. Instructions The subroutine above is equivalent to the 400 instructions below 2000.00 0000 D100 2000.00 T0000 2000.01 0001 D101 2000.01 T0001 2006.02 0099 D199 2006.02 T0099  Timer reset method There are three methods for resetting a timer instruction. 1.
  • Page 166 3. Instructions 2. Turn OFF the execution condition for the timer instruction. The timer will be reset when its execution condition turns OFF. The timer will start timing again when its execution condition turns ON. With this method, a timer cannot be reset and then restarted within the same cycle. 0.01 0010 #100...
  • Page 167 3. Instructions TIM/TIMX Function Instruction Mnemonic Variations Function code TIM or TIMX(550) operates a decrementing timer HUNDRED-MS TIMER TIM/TIMX with units of 0.1-s. TIMX Binary TIMX(550) Symbol N: Timer number N: Timer number S: Set value S: Set value Applicable Program Areas Function block SFC action or transition Area...
  • Page 168 3. Instructions Function • When the timer input is OFF, the timer Timer input specified by N is reset, i.e., the timer's PV is reset to the SV and its Completion Flag is Timer PV turned OFF. • When the timer input goes from OFF to ON, Completion TIM/TIMX(550) starts decrementing the PV.
  • Page 169 3. Instructions Precautions • Timer numbers are shared with other timer instructions. If two timers share the same timer number, but are not used simultaneously, a duplication error will be generated when the program is checked, but the timers will operate normally. Timers which share the same timer number will not operate properly if they are used simultaneously.
  • Page 170 3. Instructions Example Programming When timer input CIO 0.00 goes from OFF to ON in the following example, the timer PV will begin counting down from the SV. Timer Completion Flag T0000 will be turned ON when the PV reaches 0. When CIO 0.00 goes OFF, the timer PV will be reset to the SV and the Completion Flag will be turned OFF.
  • Page 171 3. Instructions TIMH/TIMHX Function Instruction Mnemonic Variations Function code TIMH TIMH(015)/TIMHX(551) operates a decrementing TEN-MS TIMER timer with units of 10-ms. TIMHX TIMH TIMHX Binary TIMHX(551) TIMH(015) Symbol N: Timer number N: Timer number S: Set value S: Set value Applicable Program Areas Function block SFC action or transition...
  • Page 172 3. Instructions Function • When the timer input is OFF, the timer specified Timer input by N is reset, i.e., the timer's PV is reset to the SV and its Completion Flag is turned OFF. Timer PV • When the timer input goes from OFF to ON, TIMH(015)/TIMHX(551) starts decrementing the Completion PV.
  • Page 173 3. Instructions Precautions • Timer numbers are shared with other timer instructions. If two timers share the same timer number, but are not used simultaneously, a duplication error will be generated when the program is checked, but the timers will operate normally. Timers which share the same timer number will not operate properly if they are used simultaneously.
  • Page 174 3. Instructions • The timers will not operate correctly if the cycle time exceeds 100 ms. • If an TIMH(015)/TIMHX(551) instruction is in a task that is stopped or is not executed because it is jumped by a JMP(004), CJMP(510), or CJPN(511) instruction, the timer will not operate correctly. Example Programming When timer input CIO 0.00 goes from OFF to ON in the following example, the timer PV will begin counting down from the SV (#0064 = 100 = 1.00 s).
  • Page 175 3. Instructions TMHH/TMHHX Function Instruction Mnemonic Variations Function code TMHH TMHH(540)/TMHHX(552) operates a decrement- ONE-MS TIMER ing timer with units of 1-ms. TMHHX TMHH TMHHX Binary TMHH(540) TMHHX(552) Symbol N: Timer number N: Timer number S: Set value S: Set value Applicable Program Areas Function block SFC action or transition...
  • Page 176 3. Instructions Function • When the timer input is OFF, the timer specified by N is reset, i.e., the timer's PV is reset to the SV and its Completion Flag is turned OFF. • When the timer input goes from OFF to ON, TMHH(540)/TMHHX(552) starts decrementing the PV. The PV will continue timing down as long as the timer input remains ON and the timer's Completion Flag will be turned ON when the PV reaches 0000.
  • Page 177 3. Instructions *2 If the IOM Hold Bit (A500.12) has been turned ON and the status of the IOM Hold Bit itself is protected in the PLC Setup, the status of timer Completion Flags and PVs will be maintained even when the power is interrupted. However, timing is not continued after power is restored.
  • Page 178 3. Instructions TIMU/TIMUX Function Instruction Mnemonic Variations Function code TIMU TIMU(541)/TIMUX(556) operates a decrementing TENTH-MS TIMER timer with units of 0.1-ms. TIMUX TIMU TIMUX Binary TIMU(541) TIMUX(556) Symbol N: Timer number N: Timer number S: Set value S: Set value Applicable Program Areas Function block SFC action or transition...
  • Page 179 3. Instructions Function • When the timer input is OFF, the timer specified by N is reset, i.e., the timer's Completion Flag is turned OFF. • When the timer input goes from OFF to ON, TIMU(541)/TIMUX(556) starts decrementing the PV. If the set value is reached while the timer input is ON, the timer's Completion Flag will be turned ON (the timer times out).
  • Page 180 3. Instructions • When TIMU(541)/TIMUX(556) is in a program section between IL(002) and ILC(003) and the program section is interlocked, the PV will be reset to the SV and the Completion Flag will be turned OFF. • TIMU(541)/TIMUX(556) timers may not time accurately when used in a program section jumped by the JMP(004), CJMP(510), CJPN(511), and JME(005) instructions.
  • Page 181 3. Instructions TMUH/TMUHX Function Instruction Mnemonic Variations Function code TMUH TMUH(544)/TMUHX(557) operates a decrement- HUNDREDTH-MS TIMER ing timer with units of 0.01-ms. TMUHX TMUH TMUHX Binary TMUH(541) TMUHX(557) Symbol N: Timer number N: Timer number S: Set value S: Set value Applicable Program Areas Function block SFC action or transition...
  • Page 182 3. Instructions Function • When the timer input is OFF, the timer specified by N is reset, i.e., the timer's Completion Flag is turned OFF. • When the timer input goes from OFF to ON, TMUH(544)/TMUHX(557) starts decrementing the PV. If the set value is reached while the timer input is ON, the timer's Completion Flag will be turned ON (the timer times out).
  • Page 183 3. Instructions • When TIMU(541)/TIMUX(556) is in a program section between IL(002) and ILC(003) and the program section is interlocked, the PV will be reset to the SV and the Completion Flag will be turned OFF. • TIMUH(544)/TIMUHX(557) timers may not time accurately when used in a program section jumped by the JMP(004), CJMP(510), CJPN(511), and JME(005) instructions.
  • Page 184 3. Instructions TTIM/TTIMX Function Instruction Mnemonic Variations Function code TTIM TTIM(087)/TTIMX(555) operates an incrementing ACCUMULATIVE TIMER timer with units of 0.1-s. TTIMX TTIM TTIMX Binary Timer input Timer input TTIMX(555) TTIM(087) Symbol N: Timer number N: Timer number Reset input Reset input S: Set value S: Set value...
  • Page 185 3. Instructions Function • When timer input TTIM(087)/TTIMX(555) increments the PV. Timer input When the timer input goes OFF, the timer will stop incrementing the PV, but the PV will Timer PV retain its value. The PV will resume timing Timing resume when the timer input goes ON again.
  • Page 186 3. Instructions • When TTIM(087)/TTIMX(555) is in a program section between IL(002) and ILC(003) and the program section is interlocked, the PV will retain its previous value (it will not be reset). Be sure to take this fact into account when TTIM(087)/TTIMX(555) is programmed between IL(002) and ILC(003). •...
  • Page 187 3. Instructions TIML/TIMLX Function Instruction Mnemonic Variations Function code TIML TIML(542)/TIMLX(553) operates a decrementing LONG TIMER timer with units of 0.1s. TIMLX TIML TIMLX Binary TIML(542) TIMLX(543) Symbol D1: Completion Flag D1: Completion Flag D2: PV word D2: PV word S: SV word S: SV word Applicable Program Areas...
  • Page 188 3. Instructions Function • When the timer input is OFF, the timer is reset, i.e., the timer's PV is reset to the SV Timer input and its Completion Flag is turned OFF. • When the timer input goes from OFF to ON, Timer PV TIML(542)/TIMLX(553) starts decrementing the PV in D2+1 and D2.
  • Page 189 3. Instructions Example Programming When timer input CIO 0.00 is ON in the following example, the timer PV (in D201 and D200) will be set to the SV (in D101 and D100) and the PV will begin counting down. The timer Completion Flag (CIO 200.00) will be turned ON when the PV reaches 0.
  • Page 190 3. Instructions MTIM/MTIMX Function Instruction Mnemonic Variations Function code MTIM MTIM(543)/MTIMX(554) operates a 0.1-s incre- MULTI-OUTPUT TIMER menting timer with eight independent SVs and MTIMX Completion Flags. MTIM MTIMX Binary MTIM(543) MTIMX(554) Symbol D1: Completion Flags D1: Completion Flags D2: PV Word D2: PV Word S: First SV Word S: First SV Word...
  • Page 191 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the PV contained in D2 is not BCD, when MTIM(543) is used. • OFF in all other cases. Function • When execution condition Timer PV MTIM(543)/MTIMX(554) is ON and the reset and timer bits are both OFF, MTIM(543)/MTIMX(554) increments the PV in D2.
  • Page 192 3. Instructions • If in BCD mode and an SV in S through S+7 does not contain BCD data, that SV will be ignored. An error will not occur and the Error Flag will not be turned ON. • Since the Completion Flag for MTIM(543)/MTIMX(554) is in a data area it can be forced set or forced reset like other bits, but the PV will not change.
  • Page 193 3. Instructions 0.00 D100 D1: 100CH D200 Completion Flags Reset bit Pause bit Timer PV (Incrementing) D2: D100 Corresponding completion flag ON when SV ≤ PV. Timer SVs S: D200 S+1: D201 S+2: D202 S+3: D203 S+4: D204 S+5: D205 S+6: D206 S+7: D207 Timer input...
  • Page 194 3. Instructions CNT/CNTX Function Instruction Mnemonic Variations Function code CNT/CNTX(546) operates a decrementing COUNTER CNT/CNTX counter. CNTX Binary Count input Count input CNTX(548) Symbol N: Counter number N: Counter number Reset input Reset input S: Set value S: Set value Applicable Program Areas Function block SFC action or transition...
  • Page 195 3. Instructions Function • The counter PV is decremented by 1 every time that the count input goes from OFF to Count input ON. The Completion Flag is turned ON when the PV reaches 0. Reset input • Once the Completion Flag is turned ON, reset the counter by turning the reset input Counter PV ON or by using the CNR(545)/CNRX(547)
  • Page 196 3. Instructions • When a CNT/CNTX(546) counter is forced set, its Completion Flag will be turned ON and its PV will be reset to 0000. When a CNT/CNTX(546) counter is forced reset, its Completion Flag will be turned OFF and its PV will be set to the SV. •...
  • Page 197 3. Instructions CNTR/CNTRX Function Instruction Mnemonic Variations Function code CNTR REVERSIBLE COUNTER CNTRX CNTR CNTRX Binary Increment input Increment input CNTR(012) CNTRX(548) Symbol Decrement input Decrement input N: Counter number N: Counter number Reset input Reset input S: Set value S: Set value Applicable Program Areas Function block...
  • Page 198 3. Instructions Function The counter PV is incremented by 1 every time that the increment input goes from OFF to ON and it is decremented by 1 every time Increment input that the decrement input goes from OFF to ON. The PV can fluctuate between 0 and the Decrement input When incrementing, the Completion Flag will be turned ON when the PV is incremented...
  • Page 199 3. Instructions 0.00 Increment input CNTR 0001 Decrement 0.01 input #0003 Increment input 0.02 Reset input 0.00 Decrement input 0.01 Reset input 0.00 Increment input CNTRX 0.02 0001 Decrement 0.01 input &3 Counter PV C0001 0.02 Reset input Completion Flag C0001 The add and subtract count inputs increase/decrease the count once when the signal rises (OFF to ON).
  • Page 200 3. Instructions CNR/CNRX Function Instruction Mnemonic Variations Function code @CNR Resets the timers or counters within the specified RESET TIMER/COUNTER range of timer or counter numbers. CNRX @CNRX CNRX Binary CNR(545) CNRX(547) Symbol N1: First number in range N1: First number in range N2: Last number in range N2: Last number in range Applicable Program Areas...
  • Page 201 3. Instructions Precautions The timer/counter that is reset is as follows. • Instructions reset Operation of CNR(545) TIM: HUNDRED-MS TIMER The PV is set to its maximum value (9,999 BCD) and TIMH(015): TEN-MS TIMER the Completion Flag is turned OFF. TMHH(540): ONE-MS TIMER TTIM(087): ACCUMULATIVE TIMER...
  • Page 202 3. Instructions TRSET Function Instruction Mnemonic Variations Function code TIMER RESET TRSET @TRSET Resets the specified timer. TRSET TRSET Symbol N: Timer number Applicable Program Areas Function block SFC action or transition Area Block program areas Step program areas Subroutines Interrupt tasks definitions programs...
  • Page 203: Comparison Instructions

    3. Instructions Comparison Instructions =, <>, <, <=, >, >= Function Instruction Mnemonic Variations Function code Input comparison instructions compare two values =, <>, <, <=, >, (constants and/or the contents of specified words) Input Comparison Instructions 300 to 328 >= and create an ON execution condition when the comparison condition is true.
  • Page 204 3. Instructions Name Label Operation Equal Flag • ON if S with one-word data. • ON if S +1, S +1, S with double-length data. • OFF in all other cases. Not Equal Flag < > • ON if S ≠...
  • Page 205 3. Instructions  Summary of Input Comparison Instructions The following table shows the function codes, mnemonics, names, and functions of the 72 input comparison instructions. (For one-word comparisons C1=S and C2=S ; for double comparisons C1=S +1, S and C2=S +1, S Code Mnemonic...
  • Page 206 3. Instructions Code Mnemonic Name Function LD>= LOAD GREATER THAN OR EQUAL True if C1 ≥ C2 AND>= AND GREATER THAN OR EQUAL OR>= OR GREATER THAN OR EQUAL LD>=L LOAD DOUBLE GREATER THAN OR EQUAL AND>=L AND DOUBLE GREATER THAN OR EQUAL OR>=L OR DOUBLE GREATER THAN OR EQUAL LD>=S...
  • Page 207 3. Instructions =DT, <>DT, DT, >=DT Function Instruction Mnemonic Variations Function code <>DT Time comparison instructions compare two BCD
    DT >=DT =DT, <>DT, DT, >=DT...
  • Page 208 3. Instructions through S +2: Present Time Data through S +2: Comparison Time Data through S +2 contain the present time through S +2 contain the comparison data. S through S +2 must be in the same time data. S through S +2 must be in the data area.
  • Page 209 3. Instructions Function The time comparison instruction compares the unmasked values (corresponding bit of C set to 0) of the present time data in S to S +2 with the comparison time data in S to S +2 and creates an ON execution condition when the comparison condition is true.
  • Page 210 3. Instructions Precautions • Time comparison instructions cannot be used as right-hand instructions, i.e., another instruction must be used between them and the right bus bar. Example Programming When CIO 0.00 is ON and the time is 13:00:00, CIO 50.00 is turned ON. The contents of A351 to A352 (the CPU Unit's internal calendar/clock data) are used as the present time data and the contents of D100 to D102 are used as the comparison time data.
  • Page 211 3. Instructions CMP/CMPL Function Instruction Mnemonic Variations Function code Compares two unsigned binary values (constants and/or the contents of specified words) and out- COMPARE !CMP puts the result to the Arithmetic Flags in the Auxil- iary Area. Compares two double unsigned binary values (constants and/or the contents of specified words) DOUBLE COMPARE CMPL...
  • Page 212 3. Instructions Flags Operation CX-Programmer Name label CMPL Error Flag Unchanged (See note.) Unchanged (See note.) Greater Than Flag > • ON if S > S • ON if S +1, S > S +1, S • OFF in all other cases. •...
  • Page 213 3. Instructions Precautions • Using CMP(020)Results in the Program When CMP(020)/CMPL(060) is executed, the result is reflected in the Arithmetic Flags. Control the desired output or right-hand instruction with a branch from the same input condition that controls CMP(020)/CMPL(060), as shown in the following diagram. In this case, the Equals Flag and output A will be turned ON when S or S + 1, S...
  • Page 214 3. Instructions CPS/CPSL Function Instruction Mnemonic Variations Function code Compares two signed binary values (constants and/or the contents of specified words) and out- SIGNED BINARY COMPARE !CPS puts the result to the Arithmetic Flags in the Auxil- iary Area. Compares two double signed binary values (con- DOUBLE SIGNED BINARY stants and/or the contents of specified words) and CPSL...
  • Page 215 3. Instructions Flags Operation Name Label CPSL Error Flag Unchanged (See note.) OFF or unchanged (See note.) Greater Than Flag > • ON if S > S • ON if S +1, S > S +1, S • OFF in all other cases. •...
  • Page 216 3. Instructions Precautions • When CPS(114)/CPSL(115) is executed, the result is reflected in the Arithmetic Flags. Control the desired output or right-hand instruction with a branch from the same input condition that controls CPS(114)/CPSL(115), as shown in the following diagram. CPS/CPSL Arithmetic Flag (Example: Equal Flag)
  • Page 217 3. Instructions MCMP Function Instruction Mnemonic Variations Function code Compares 16 consecutive words with another 16 consecutive words and turns ON the correspond- MULTIPLE COMPARE MCMP @MCMP ing bit in the result word where the contents of the words are not equal. MCMP MCMP(019) Symbol...
  • Page 218 3. Instructions Flags Name Label Operation Error Flag Equals Flag • ON if the result word is 0000. (The two 16-word sets contain the same data.) • OFF in all other cases. Function MCMP(019) compares the contents of the 16 0: Words are equal.
  • Page 219 3. Instructions TCMP Function Instruction Mnemonic Variations Function code Compares the source data to the contents of 16 consecutive words and turns ON the correspond- TABLE COMPARE TCMP @TCMP ing bit in the result word when the contents of the words are equal.
  • Page 220 3. Instructions Function TCMP(085) compares the source data (S) to each of 1: Data are equal. the 16 words T through T+15 and turns ON the 0: Data aren't equal. corresponding bit in word R when the data are equal. Comparison Bit n of R is turned ON if the content of T+n is equal to S and it is turned OFF if they are not equal.
  • Page 221 3. Instructions BCMP Function Instruction Mnemonic Variations Function code Compares the source data to 16 ranges (defined by 16 lower limits and 16 upper limits) and turns BLOCK COMPARE BCMP @BCMP ON the corresponding bit in the result word when the source data is within a range.
  • Page 222 3. Instructions Function BCMP(068) compares the source data (S) to the 16 ranges defined by pairs of lower and upper limit values in B through B+31. The first word in each pair (B+2n) provides the lower limit and the second word (B+2n+1) provides the upper limit of range n (n = 0 to 15).
  • Page 223 3. Instructions BCMP2 Function Instruction Mnemonic Variations Function code Compares the source data to up to 256 ranges EXPANDED BLOCK (defined by 256 lower limits and 256 upper limits) BCMP2 @BCMP2 COMPARE and turns ON the corresponding bit in the result word when the source data is within a range.
  • Page 224 3. Instructions  Operand Specifications Indirect Word addresses DM/EM Registers Con- Pulse addresses Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER Function BCMP2(502) compares the source data (S) to the ranges defined by pairs of lower and upper limit values in the comparison block.
  • Page 225 3. Instructions • When B+1 ≤ B+2 If B+1 ≤ S ≤ B+2, then bit 0 of R will turn ON, If B+3 ≤ S ≤ B+4, then bit 1 of R will turn ON, If S < B+5 and B+6 < S, then bit 2 of R will turn OFF, and If S <...
  • Page 226 3. Instructions ZCP/ZCPL Function Instruction Mnemonic Variations Function code Compares a 16-bit unsigned binary value (CD) with the range defined by lower limit LL and upper AREA RANGE COMPARE limit UL. The results are output to the Arithmetic Flags. Compares a 32-bit unsigned binary value (CD+1, DOUBLE AREA RANGE CD) with the range defined by lower limit (LL+1, ZCPL...
  • Page 227 3. Instructions Operation Name Label ZCPL Not Equal Flag P_NE • CJ2H (unit version 1.0 to 1.2), CS1-H, CJ1-H, • CJ2H (unit version 1.0 to 1.2), CS1-H, CJ1-H, CJ1M, or CS1D CPU Unit: Held CJ1M, or CS1D CPU Unit: Held •...
  • Page 228 3. Instructions Comparison Result and Flag Operation Greater Than or Less Than or Not Equals Equals Flag* Equals Flag* Flag* (AND of Greater Than Result Equals Flag Less Than Flag (AND of Greater (AND of Less Greater Than Flag Than Flag and Than Flag and Flag and Less Equals Flag)
  • Page 229 3. Instructions Precautions • When ZCP(088)/ZCPL(116) is executed, the result is reflected in the Arithmetic Flags. Control the desired output or right-hand instruction with a branch from the same input condition that controls ZCP(088)/ZCPL(116), as shown in the following diagram. Arithmetic Flag (Example: Equal Flag) In this case, the Equals Flag and output A will...
  • Page 230 3. Instructions ZCPS/ZCPSL Function Instruction Mnemonic Variations Function code Compares the 16-bit signed binary value in CD SIGNED AREA RANGE COM- (word contents or constant) to the range defined ZCPS PARE by LL and UL and outputs the results to the Arith- metic Flags.
  • Page 231 3. Instructions Operation Name Label ZCPL Less Than Flag P_LT • ON if CD < LL. • ON if CD+1, CD < LL+1, LL. • OFF in all other cases. • OFF in all other cases. Less Than or Equal Flag P_LE •...
  • Page 232 3. Instructions Precautions • When ZCPS(117)/ZCPSL(118) is executed, the result is reflected in the Arithmetic Flags. Control the desired output or right-hand instruction with a branch from the same input condition that controls ZCPS(117)/ZCPSL(118), as shown in the following diagram. ZCPS Arithmetic Flag Example: P_EQ...
  • Page 233: Data Movement Instructions

    3. Instructions Data Movement Instructions MOV/MOVL Function Instruction Mnemonic Variations Function code @MOV, !MOV, MOVE Transfers a word of data to the specified word. !@MOV Transfers two words of data to the specified DOUBLE MOVE MOVL @MOVL words. MOVL MOVL(498) MOV(021) Symbol S: Source...
  • Page 234 3. Instructions Function  MOV Transfers S to D. If S is a constant, the value can be used for a data setting.  MOVL MOVL(498) transfers S+1 and S to D+1 and D. If S+1 and S are constants, the value can be used for a data setting.
  • Page 235 3. Instructions When CIO 0.00 is ON in the following example, the content of D101 and D100 are copied to D201 and D200. 0.00 D100 D200 D100 D200 D101 D201 0.01 #1234 (Hexadecimal 1234) 0.02 +1234 (Decimal 1234) 0.03 -1234 (Decimal -1234) CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 236 3. Instructions MVN/MVNL Function Instruction Mnemonic Variations Function code Transfers the complement of a word of data to the MOVE NOT @MVN specified word. Transfers the complement of two words of data to DOUBLE MOVE NOT MVNL @MVNL the specified words. MVNL MVN(022) MVNL(499)
  • Page 237 3. Instructions Function  MVN MVN(022) inverts the bits in S and transfers Bit status the result to D. The content of S is left inverted. unchanged.  MVNL MVNL(499) inverts the bits in S+1 and S and transfers the result to D+1 and D. The Bit status contents of S+1 and S are left unchanged.
  • Page 238 3. Instructions MOVB Function Instruction Mnemonic Variations Function code MOVE BIT MOVB @MOVB Transfers the specified bit. MOVB MOVB(082) Symbol S: Source word or data C: Control word D: Destination word Applicable Program Areas Function block SFC action or transition Area Block program areas Step program areas...
  • Page 239 3. Instructions Function MOVB(082) copies the specified bit (n) from S to the specified bit (m) in D. Hint The same word can be specified for both S and D to copy a bit within a word. Precautions The other bits in the destination word are left unchanged. Example Programming When CIO 0.00 is ON in the following example, the 5 bit of the source word (CIO 200) is copied to the...
  • Page 240 3. Instructions MOVD Function Instruction Mnemonic Variations Function code Transfers the specified digit or digits. MOVE DIGIT MOVD @MOVD (Each digit is made up of 4 bits.) MOVB MOVD(083) S: Source word or data Symbol C: Control word D: Destination word Applicable Program Areas Function block SFC action or...
  • Page 241 3. Instructions Flags Name Label Operation Error Flag • ON if one of the first three digits of C is not within the specified range of 0 to 3. • OFF in all other cases. Function MOVB(082) copies the specified bit (n) from S to the specified bit (m) in D.
  • Page 242 3. Instructions XFRB Function Instruction Mnemonic Variations Function code Transfers the specified number of consecutive MULTIPLE BIT TRANSFER XFRB @XFRB bits. XFRB XFRB(062) Symbol C: Control word S: First source word D: First destination word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 243 3. Instructions Function XFRB(062) transfers up to 255 consecutive bits from the source words (beginning with bit l of S) to the destination words (beginning with bit m of D). The beginning bits and number of bits are specified in C, as shown in the following diagram.
  • Page 244 3. Instructions XFER Function Instruction Mnemonic Variations Function code Transfers the specified number of consecutive BLOCK TRANSFER XFER @XFER words. XFER XFER(070) Symbol N: Number of words S: First source word D: First destination word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 245 3. Instructions Function XFER(070) copies N words beginning with S (S to S+(N-1)) to the N words beginning with D (D to D+(N-1)). N words S+(N−1) (N−1) Hint • It is possible for the source words and D100 destination words to overlap, so XFER(070) D102 &10 can perform word-shift operations.
  • Page 246 3. Instructions BSET Function Instruction Mnemonic Variations Function code Copies the same word to a range of consecutive BLOCK SET BSET @BSET words. BSET BSET(071) Symbol S: Source word St: Starting word E: End word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 247 3. Instructions Function BSET(071) copies the same source word (S) Source word Destination words to all of the destination words in the range St to E. Precautions • Some time will be required to complete BSET(071) when a large number of words is being set. Even if an interrupt occurs, execution of this instruction will not be interrupted and execution of the interrupt task will be started after execution of BSET(071) has been completed.
  • Page 248 3. Instructions XCHG/XCGL Function Instruction Mnemonic Variations Function code Exchanges the contents of the two specified DATA EXCHANGE XCHG @XCHG words. Exchanges the contents of a pair of consecutive DOUBLE DATA EXCHANGE XCGL @XCGL words with another pair of consecutive words. XCHG XCGL XCHG(073)
  • Page 249 3. Instructions Hint exchange more words, XFER(070) to transfer the words to a third set XFER(070) operation of words (a buffer) as shown in this diagram. Buffer XFER(070) operation XFER(070) operation Example Programming When CIO 0.00 is ON in this example, the When CIO 0.00 is ON in this example, the content of D100 is exchanged with the content contents of D100 and D101 are exchanged with...
  • Page 250 3. Instructions DIST Function Instruction Mnemonic Variations Function code Transfers the source word to a destination word SINGLE WORD DISTRIBUTE DIST @DIST calculated by adding an offset value to the base address. DIST DIST(080) Symbol S: Source word Bs: Destination base address Of: Offset Applicable Program Areas Function block...
  • Page 251 3. Instructions Function DIST(080) copies S to the destination word calculated by adding Of to Bs. Bs+n Hint The same DIST(080) instruction can be used to distribute the source word to various words in the data area by changing the value of Of. Precautions Be sure that the offset does not exceed the end of the data area, i.e., Bs and Bs+Of are in the same data area.
  • Page 252 3. Instructions COLL Function Instruction Mnemonic Variations Function code Transfers the source word (calculated by adding DATA COLLECT COLL @COLL an offset value to the base address) to the desti- nation word. COLL COLL(081) Symbol Bs: Source base address Of: Offset D: Destination word Applicable Program Areas Function block...
  • Page 253 3. Instructions Function COLL(081) copies the source word (calculated by adding Of to Bs) to the destination word. Bs+n Hint The same COLL(081) instruction can be used to collect data from various source words in the data area by changing the value of Of. Precautions Be sure that the offset does not exceed the end of the data area, i.e., Bs and Bs+Of are in the same data area.
  • Page 254 3. Instructions MOVR/MOVRW Function Instruction Mnemonic Variations Function code Sets the PLC memory address of the specified MOVE TO REGISTER MOVR @MOVR word, bit, or timer/counter Completion Flag in the specified Index Register. Sets the PLC memory address of the specified MOVE TIMER/COUNTER PV MOVRW @MOVRW...
  • Page 255 3. Instructions Function  MOVR MOVR(560) finds the PLC memory address Internal I/O memory address of S (absolute address) of S and writes that address in D (an Index Register). Index Register  MOVRW MOVRW(561) finds the PLC memory address Internal I/O memory address of S for the PV of the timer or counter specified in S and writes that address in D (an Index...
  • Page 256 3. Instructions Example Programming When CIO 0.00 is ON in the following example, MOVR(560) writes the PLC memory address of CIO 20 to IR0. 0.00 Internal I/O memory address S: 20 Internal I/O memory address of CIO 20 D: IR0 When CIO 0.00 is ON in the following example, MOVRW(561) writes the PLC memory address for the PV of timer T0 to IR1.
  • Page 257: Data Shift Instruction

    3. Instructions Data Shift Instruction Function Instruction Mnemonic Variations Function code SHIFT REGISTER Operates a shift register. Data input SFT(010) Symbol Shift input St: Starting word Reset input E: End word Applicable Program Areas Function block SFC action or transition Area Block program areas Step program areas...
  • Page 258 3. Instructions Precautions • Do not use more than one SFT(010) instructions with overlapping shift words. The results will not be dependable. • St and E must be in the same data area. • The bit data shifted out of the shift register is discarded. •...
  • Page 259 3. Instructions SFTR Function Instruction Mnemonic Variations Function code REVERSIBLE SHIFT REGIS- Creates a shift register that shifts data to either the SFTR @SFTR right or the left. SFTR SFTR(084) C: Control word Symbol St: Starting word E: End word Applicable Program Areas Function block SFC action or transition...
  • Page 260 3. Instructions Function When the execution condition of the shift input bit (bit 14 of C) changes to ON, all the data from St to E is moved in the designated shift direction (designated by bit Data input 12 of C) by 1 bit, and the ON/OFF status of the data input is placed Data input Shift direction...
  • Page 261 3. Instructions ASFT Function Instruction Mnemonic Variations Function code Shifts all non-zero word data within the specified ASYNCHRONOUS SHIFT ASFT @ASFT word range either towards St or toward E, REGISTER replacing 0000Hex word data. ASFT ASFT(017) Symbol C: Control word St: Starting word E: End word Applicable Program Areas...
  • Page 262 3. Instructions Function When the Shift Enable Bit (bit 14 of C) is ON, all of the words with non-zero content within the range of words between St and E will be shifted one word in the direction determined Shift direction by the Shift Direction Bit (bit 13 of C) Shift enabled whenever the word in the shift direction...
  • Page 263 3. Instructions WSFT Function Instruction Mnemonic Variations Function code WORD SHIFT WSFT @WSFT Shifts data between St and E in word units. WSFT WSFT(016) S: Source word Symbol St: Starting word E: End word Applicable Program Areas Function block SFC action or transition Area Block program areas Step program areas...
  • Page 264 3. Instructions Example Programming When CIO 0.00 is ON, data from CIO 100 through CIO 102 will be shifted one word toward E. The contents of CIO 300 will be stored in CIO 100 and the contents of CIO 102 will be lost. 0.00 S: CIO 300 E: CIO 100...
  • Page 265 3. Instructions ASL/ASLL Function Instruction Mnemonic Variations Function code ARITHMETIC SHIFT LEFT @ASL Shifts the contents of Wd one bit to the left. DOUBLE SHIFT LEFT ASLL @ASLL Shifts the contents of Wd and Wd +1 one bit to the left. ASLL ASL(025) ASLL(570)
  • Page 266 3. Instructions Function  ASL ASL(025) shifts the contents of Wd one bit to the left (from rightmost bit to leftmost bit). “0” is placed in the rightmost bit and the data from the leftmost bit is shifted into the Carry Flag (CY).
  • Page 267 3. Instructions ASR/ASRL Function Instruction Mnemonic Variations Function code ARITHMETIC SHIFT RIGHT @ASL Shifts the contents of Wd one bit to the right. DOUBLE SHIFT RIGHT ASRL @ASLL Shifts the contents of Wd and Wd +1 one bit to the right. ASRL Symbol ASR(026)
  • Page 268 3. Instructions Function  ASR ASR(026) shifts the contents of Wd one bit to the right (from leftmost bit to rightmost bit). “0” will be placed in the leftmost bit and the contents of the rightmost bit will be shifted into the Carry Flag (CY).
  • Page 269 3. Instructions ROL/ROLL Function Instruction Mnemonic Variations Function code Shifts all Wd bits one bit to the left ROTATE LEFT @ROL including the Carry Flag (CY). Shifts all Wd and Wd +1 bits one bit to DOUBLE ROTATE LEFT ROLL @ROLL the left including the Carry Flag (CY).
  • Page 270 3. Instructions Function  ROL ROL(027) shifts all bits of Wd including the Carry Flag (CY) to the left (from rightmost bit to leftmost bit).  ROLL ROLL(572) shifts all bits of Wd and Wd +1 including the Carry Flag (CY) to the left (from Wd+1 rightmost bit to leftmost bit).
  • Page 271 3. Instructions RLNC/RLNL Function Instruction Mnemonic Variations Function code ROTATE LEFT WITHOUT Shifts all Wd bits one bit to the left not including the RLNC @RLNC CARRY Carry Flag (CY). DOUBLE ROTATE LEFT Shifts all Wd and Wd +1 bits one bit to the left not RLNL @RLNL WITHOUT CARRY...
  • Page 272 3. Instructions Function  RLNC RLNC(574) shifts all bits of Wd to the left (from rightmost bit to leftmost bit). The contents of the leftmost bit of Wd shifts to the rightmost bit and to the Carry Flag (CY).  RLNL RLNL(576) shifts all bits of Wd and Wd +1 to the left (from rightmost bit to leftmost bit).
  • Page 273 3. Instructions ROR/RORL Function Instruction Mnemonic Variations Function code Shifts all Wd bits one bit to the right ROTATE RIGHT @ROR including the Carry Flag (CY).). Shifts all Wd and Wd +1 bits one bit to DOUBLE ROTATE RIGHT RORL @RORL the right including the Carry Flag (CY).
  • Page 274 3. Instructions Function  ROR ROR(028) shifts all bits of Wd including the Carry Flag (CY) to the right (from leftmost bit to rightmost bit).  RORL RORL(573) shifts all bits of Wd and Wd +1 including the Carry Flag (CY) to the right Wd+1 (from leftmost bit to rightmost bit).
  • Page 275 3. Instructions RRNC/RRNL Function Instruction Mnemonic Variations Function code ROTATE RIGHT WITHOUT Shifts all Wd bits one bit to the right not including the RRNC @RRNC CARRY Carry Flag (CY). DOUBLE ROTATE RIGHT Shifts all Wd and Wd +1 bits one bit to the right not RRNL @RRNL WITHOUT CARRY...
  • Page 276 3. Instructions Function  RRNC RRNC(575) shifts all bits of Wd to the right (from leftmost bit to rightmost bit) not including the Carry Flag (CY). The contents of the rightmost bit of Wd shifts to the leftmost bit and to the Carry Flag (CY). ...
  • Page 277 3. Instructions SLD/SRD Function Instruction Mnemonic Variations Function code ONE DIGIT SHIFT LEFT @SLD Shifts data by one digit (4 bits) to the left. ONE DIGIT SHIFT RIGHT @SRD Shifts data by one digit (4 bits) to the right. SLD(074) SRD(075) Symbol St: Starting Word...
  • Page 278 3. Instructions Precautions • St and E must be in the same data area. SLD • When large amounts of data are shifted, the instruction execution time is quite long. Be sure that the power is not cut while SLD(074) and SRD(075) Lost is being executed, causing the shift operation to stop halfway through.
  • Page 279 3. Instructions NSFL/NSFR Function Instruction Mnemonic Variations Function code SHIFT N-BIT DATA LEFT NSFL @NSFL Shifts the specified number of bits to the left. SHIFT N-BIT DATA RIGHT NSFR @NSFR Shifts the specified number of bits to the right. NSFL NSFR NSFL(578) NSFR(579)
  • Page 280 3. Instructions Function  NSFL NSFL(578) shifts the specified number of bits by the shift data length (N) from the beginning bit (C) in the rightmost word, as designated by D one bit to the left (towards the leftmost word and the leftmost Shifts one bit to the left N−1 bit bit).
  • Page 281 3. Instructions  NSFR When CIO 0.00 is ON, all bits from the beginning bit 2 to end of the shift data length 11 bits (B hex), will be shifted one bit to the right, (from the leftmost bit to the rightmost bit). “0” is shifted into bit 12 of CIO 100.
  • Page 282 3. Instructions NASL/NSLL Function Instruction Mnemonic Variations Function code Shifts the specified 16 bits of word data to the left by the SHIFT N-BITS LEFT NASL @NASL specified number of bits. Shifts the specified 32 bits of word data to the left by the DOUBLE SHIFT N-BITS LEFT NSLL @NSLL...
  • Page 283 3. Instructions Flags Name Label Operation Error Flag • ON when the control word C (the number of bits to shift) is not within range. • OFF in all other cases. Equals Flag • ON when the shift result is 0. •...
  • Page 284 3. Instructions 0.00 No. of bits to shift: 10 bits (0A Hex) Always 0. Data shifted into register 8 Hex: Contents of rightmost bit shifted in Lost Rightmost bit No. of bits to shift: 10 bits (Contents of the rightmost bit is inserted.) When CIO 0.00 is ON, CIO 100 and CIO 101 will be shifted to the left (from the rightmost bit to the leftmost bit) by 10 bits.
  • Page 285 3. Instructions NASR/NSRL Function Instruction Mnemonic Variations Function code Shifts the specified 16 bits of word data to the right by SHIFT N-BITS RIGHT NASR @NASR the specified number of bits. DOUBLE SHIFT N-BITS Shifts the specified 32 bits of word data to the right by NSRL @NSRL RIGHT...
  • Page 286 3. Instructions Name Label Operation Carry Flag • ON when 1 is shifted into the Carry Flag (CY). • OFF in all other cases. Negative Flag • ON when the leftmost bit is 1 as a result of the shift. •...
  • Page 287 3. Instructions 0.00 No. of bits to shift: 10 bits (0A Hex) Always 0. Data shifted into register 8 Hex: Contents of leftmost bit shifted in Leftmost bit Lost No. of bits to shift: 10 bits (Contents of the leftmost bit is inserted.) When CIO 0.00 is ON, CIO 100 and CIO 101 will be shifted 10 bits to the right (from the leftmost bit to the rightmost bit).
  • Page 288: Increment/Decrement Instructions

    3. Instructions Increment/Decrement Instructions ++/++L Function Instruction Mnemonic Variations Function code Increments the 4-digit hexadecimal content of the INCREMENT BINARY specified word by 1. DOUBLE INCREMENT Increments the 8-digit hexadecimal content of the @++L BINARY specified words by 1. + +L ++(590) ++L(591) Symbol...
  • Page 289 3. Instructions Function  ++ The ++(590) instruction adds 1 to the binary content of Wd. The specified word will be incremented by 1 every cycle as long as the execution condition of ++(590) is ON. When the up-differentiated variation of this instruction (@++(590)) is used, the specified word is incremented only when the exe- cution condition has gone from OFF to ON.
  • Page 290 3. Instructions  Operation of @++(590)/@++L(591) The up-differentiated variation is used in the following example, so the content of D100 will be incremented by 1 only when CIO 0.00 has gone from OFF to ON. 0.00 Incremented every cycle while CIO 0.00 is ON. D100 D100 D100...
  • Page 291 3. Instructions --/--L Function Instruction Mnemonic Variations Function code Decrements the 4-digit hexadecimal content of the DECREMENT BINARY specified word by 1. DOUBLE DECREMENT Decrements the 8-digit hexadecimal content of the @--L BINARY specified words by 1. - -(592) - -L(593) Symbol Wd: Word Wd: First word...
  • Page 292 3. Instructions Function  -- The --(592) instruction subtracts 1 from the binary content of Wd. The specified word will be decremented by 1 every cycle as long as the execution condition of --(592) is ON. When the up-differentiated variation of this instruction (@ -- (592)) is used, the specified word is decremented only when the execution condition has gone from OFF to ON.
  • Page 293 3. Instructions  Operation of @--(592)/@--L(593) In the following example, the content of D100 will be decremented by 1 every cycle as long as CIO 0.00 is ON. 0.00 − − Decremented every cycle while CIO 0.00 is ON. D100 D100 D100 0 0 2 0...
  • Page 294 3. Instructions ++B/++BL Function Instruction Mnemonic Variations Function code Increments the 4-digit BCD content of the speci- INCREMENT BCD @++B fied word by 1. Increments the 8-digit BCD content of the speci- DOUBLE INCREMENT BCD ++BL @++BL fied words by 1. + +BL + +B(594) + +BL(595)
  • Page 295 3. Instructions Function  ++B The ++B(594) instruction adds 1 to the BCD content of Wd. The specified word will be incremented by 1 every cycle as long as the execution condition of ++B(594) is ON. When up-differentiated variation this instruction (@++B(594)) is used, the specified word is incremented only when the execution condition has gone from OFF to...
  • Page 296 3. Instructions  Operation of @++B(594)/@++BL(595) The up-differentiated variation is used in the following example, so the content of D100 will be incremented by 1 only when CIO 0.00 has gone from OFF to ON. 0.00 Incremented only for @++B up-differentiation.
  • Page 297 3. Instructions --B/--BL Function Instruction Mnemonic Variations Function code Decrements the 4-digit BCD content of the speci- DECREMENT BCD @--B fied word by 1. Decrements the 8-digit BCD content of the speci- DOUBLE DECREMENT BCD --BL @--BL fied words by 1. --BL - -BL(597) - -B(596)
  • Page 298 3. Instructions Function  --B The --B(596) instruction subtracts 1 from the BCD content of −1 Wd. The specified word will be decremented by 1 every cycle as long as the execution condition of --B(596) is ON. When the up-differentiated variation of this instruction (@-- B(596)) is used, the specified word is decremented only when the execution condition has gone from OFF to ON.
  • Page 299 3. Instructions  Operation of @--B(596)/@--BL(597) The up-differentiated variation is used in the following example, so the BCD content of D100 will be decremented by 1 only when CIO 0.00 has gone from OFF to ON. 0.00 @ − −B Decremented only for up-differentiation.
  • Page 300: Symbol Math Instructions

    3. Instructions Symbol Math Instructions +/+L Function Instruction Mnemonic Variations Function code SIGNED BINARY ADD Adds 4-digit (single-word) hexadecimal data WITHOUT CARRY and/or constants. DOUBLE SIGNED BINARY Adds 8-digit (double-word) hexadecimal data ADD WITHOUT CARRY and/or constants. +L(401) +(400) Au: 1st augend word Au: Augend word Symbol Ad: Addend word...
  • Page 301 3. Instructions Flags Operation Name Label Error Flag Equals Flag • ON when the result is 0. • ON when the result is 0. • OFF in all other cases. • OFF in all other cases. Carry Flag • ON when the addition results in a carry. •...
  • Page 302 3. Instructions +C/+CL Function Instruction Mnemonic Variations Function code SIGNED BINARY ADD WITH Adds 4-digit (single-word) hexadecimal data CARRY and/or constants with the Carry Flag (CY). DOUBLE SIGNED BINARY Adds 8-digit (double-word) hexadecimal data @+CL ADD WITH CARRY and/or constants with the Carry Flag (CY). +C(402) +CL(403) Symbol...
  • Page 303 3. Instructions Flags Operation Name Label Error Flag Equals Flag • ON when the addition result is 0. • ON when the result is 0. • OFF in all other cases. • OFF in all other cases. Carry Flag • ON when the addition results in a carry. •...
  • Page 304 3. Instructions +B/+BL Function Instruction Mnemonic Variations Function code Adds 4-digit (single-word) BCD data and/or con- BCD ADD WITHOUT CARRY stants. DOUBLE BCD ADD WITHOUT Adds 8-digit (double-word) BCD data and/or con- @+BL CARRY stants. +BL(405) +B(404) Symbol Au: Augend word Au: 1st augend word Ad: Addend word Ad: 1st addend word...
  • Page 305 3. Instructions Function  +B +B(404) adds the BCD values in Au and Ad and outputs the result to R. (BCD) (BCD) CY will turn ON (BCD) when there is a carry.  +BL +BL(405) adds the BCD values in Au and Au+1 and Ad and Ad+1 and outputs the result to R, R+1. (BCD) Au+1 (BCD)
  • Page 306 3. Instructions +BC/+BCL Function Instruction Mnemonic Variations Function code Adds 4-digit (single-word) BCD data and/or con- BCD ADD WITH CARRY @+BC stants with the Carry Flag (CY). DOUBLE BCD ADD WITH Adds 8-digit (double-word) BCD data and/or con- +BCL @+BCL CARRY stants with the Carry Flag (CY).
  • Page 307 3. Instructions Flags Operation Name Label +BCL Error Flag • ON when Au is not BCD. • ON when Au, Au +1 is not BCD. • ON when Ad is not BCD. • ON when Ad, Ad +1 is not BCD. •...
  • Page 308 3. Instructions –/–L Function Instruction Mnemonic Variations Function code SIGNED BINARY SUBTRACT Subtracts 4-digit (single-word) hexadecimal data – @– WITHOUT CARRY and/or constants. DOUBLE SIGNED BINARY Subtracts 8-digit (double-word) hexadecimal data SUBTRACT WITHOUT –L @–L and/or constants. CARRY – –L −L(411) −(410) Symbol...
  • Page 309 3. Instructions Flags Operation Name Label – –L Error Flag Equals Flag • ON when the result is 0. • ON when the result is 0. • OFF in all other cases. • OFF in all other cases. Carry Flag •...
  • Page 310 3. Instructions Hint • 2's Complement A 2’s complement is the value obtained by subtracting each binary digit from 1 and adding one to the result. For example, the 2’s complement for 1101 is calculated as follows: 1111 (F hexadecimal) – 1101 (D hexadecimal) + 1 (1 hexadecimal) = 0011 (3 hexadecimal).
  • Page 311 3. Instructions Subtraction at (1) Mi+1: CIO 201 Mi: CIO 200 Su+1: CIO 121 Su: CIO 120 − R+1: D101 R+1: D100 The Carry Flag (CY) is ON, so the result is subtracted from 0000 0000 to obtain the actual number. Subtraction at (2) Su+1: D101 Su: D100...
  • Page 312 3. Instructions –C/–CL Function Instruction Mnemonic Variations Function code SIGNED BINARY SUBTRACT Subtracts 4-digit (single-word) hexadecimal data –C @–C WITH CARRY and/or constants with the Carry Flag (CY). DOUBLE SIGNED BINARY Subtracts 8-digit (double-word) hexadecimal data –CL @–CL SUBTRACT WITH CARRY and/or constants with the Carry Flag (CY).
  • Page 313 3. Instructions Flags Operation Name Label –C –CL Error Flag Equals Flag • ON when the subtraction result is 0. • ON when the result is 0. • OFF in all other cases. • OFF in all other cases. Carry Flag •...
  • Page 314 3. Instructions Example Programming 0.00 When CIO 0.00 is ON in the following example, D110 and CY will be –C subtracted from D100 as 4-digit signed binary values and the result will D100 be output to D120. D110 D120 0.00 When CIO 0.00 is ON in the following example, D111, D110 and CY will be –CL subtracted from D101 and D100 as 8-digit signed binary values, and the...
  • Page 315 3. Instructions –B/–BL Function Instruction Mnemonic Variations Function code BCD SUBTRACT WITHOUT Subtracts 4-digit (single-word) BCD data and/or –B @–B CARRY constants. DOUBLE BCD SUBTRACT Subtracts 8-digit (double-word) BCD data and/or –BL @–BL WITHOUT CARRY constants. –B –BL –B(414) –BL(415) Symbol Mi: Minuend word Mi: 1st minuend word...
  • Page 316 3. Instructions Function  –B –B(414) subtracts the BCD values in Su from Mi and outputs the result to R. If the result of the subtraction is negative, the result is output as a 10's complement. (BCD) − (BCD) CY will turn ON (BCD) when there is a borrow.
  • Page 317 3. Instructions Subtraction at (1) Mi+1: CIO 201 S1: CIO 200 Su+1: CIO 121 S2: CIO 120 – 09583960+(100000000-17072641) R+1: D101 R+1: D100 The Carry Flag (CY) is ON, so the result is subtracted from 0000 0000. Subtraction at (2) Su+1: D101 Su: D100 –...
  • Page 318 3. Instructions –BC/–BCL Function Instruction Mnemonic Variations Function code BCD SUBTRACT WITH Subtracts 4-digit (single-word) BCD data and/or –BC @–BC CARRY constants with the Carry Flag (CY). DOUBLE BCD SUBTRACT Subtracts 8-digit (double-word) BCD data and/or –BCL @–BCL WITH CARRY constants with the Carry Flag (CY).
  • Page 319 3. Instructions Function  –BC –BC(416) subtracts BCD values in Su and CY from Mi and outputs the result to R. If the result is negative, it is output to R as a 10's complement. (BCD) (BCD) – CY will turn ON (BCD) when there is a borrow.
  • Page 320 3. Instructions */*L Function Instruction Mnemonic Variations Function code Multiplies 4-digit signed hexadecimal data and/or SIGNED BINARY MULTIPLY constants. DOUBLE SIGNED BINARY Multiplies 8-digit signed hexadecimal data and/or MULTIPLY constants. *L(421) *(420) Symbol Md: 1st multiplicand word Md: Multiplicand word Mr: 1st multiplier word Mr: Multiplier word R: 1st result word...
  • Page 321 3. Instructions Function  * *(420) multiplies the signed binary values in Md and Mr and outputs the result to R, R+1. (Signed binary) × (Signed binary) R +1 (Signed binary)  *L *L(421) multiplies the signed binary values in Md and Md+1 and Mr and Mr+1 and outputs the result to R, R+1, R+2, and R+3.
  • Page 322 3. Instructions *U/*UL Function Instruction Mnemonic Variations Function code UNSIGNED BINARY MULTI- Multiplies 4-digit unsigned hexadecimal data and/or constants. DOUBLE UNSIGNED BINARY Multiplies 8-digit unsigned hexadecimal data @*UL MULTIPLY and/or constants. *U(422) *UL(423) Symbol Md: Multiplicand word Md: 1st multiplicand word Mr: Multiplier word Mr: 1st multiplier word R: Result word...
  • Page 323 3. Instructions Function  *U *U(420) multiplies the binary values in Md and Mr and outputs the result to R, R+1. (Unsigned binary) × (Unsigned binary) (Unsigned binary)  *UL *UL(423) multiplies the unsigned binary values in Md and Md+1 and Mr and Mr+1 and outputs the result to R, R+1, R+2, and R+3.
  • Page 324 3. Instructions *B/*BL Function Instruction Mnemonic Variations Function code Multiplies 4-digit (single-word) BCD data and/or BCD MULTIPLY constants. Multiplies 8-digit (double-word) BCD data and/or DOUBLE BCD MULTIPLY @*BL constants. *BL(425) *B(424) Symbol Md: Multiplicand word Md: 1st multiplicand word Mr: 1st multiplier word Mr: Multiplier word R: 1st result word R: Result word...
  • Page 325 3. Instructions Function  *B *B(424) multiplies the BCD content of Md and Mr and outputs the result to R, R+1. (BCD) × (BCD) (BCD)  *BL *BL(425) multiplies BCD values in Md and Md+1 and Mr and Mr+1 and outputs the result to R, R+1, R+2, and R+3.
  • Page 326 3. Instructions /, /L Function Instruction Mnemonic Variations Function code Divides 4-digit (single-word) signed hexadecimal SIGNED BINARY DIVIDE data and/or constants. DOUBLE SIGNED BINARY Divides 8-digit (double-word) signed hexadecimal DIVIDE data and/or constants. /L(431) /(430) Symbol Dd: Dividend word Dd: 1st dividend word Dr: 1st divisor word Dr: Divisor word R: Result word...
  • Page 327 3. Instructions Function  / /(430) divides the signed binary (16 bit) values in Dd by those in Dr and outputs the result to R, R+1. The quotient is placed in R and the remainder in R+1. (Signed binary) ÷ (Signed binary) (Signed binary) Remainder...
  • Page 328 3. Instructions /U, /UL Function Instruction Mnemonic Variations Function code Divides 4-digit (single-word) unsigned hexadeci- UNSIGNED BINARY DIVIDE mal data and/or constants. DOUBLE UNSIGNED BINARY Divides 8-digit (double-word) unsigned hexadeci- @/UL DIVIDE mal data and/or constants. /U(432) /UL(433) Symbol Dd: 1st dividend word Dd: Dividend word Dr: 1st divisor word Dr: Divisor word...
  • Page 329 3. Instructions Function  /U /U(432) divides the unsigned binary values in Dd by those in Dr and outputs the quotient to R and the remainder to R+1. (Unsigned binary) ÷ (Unsigned binary) (Unsigned binary) Remainder Quotient  /UL /UL(433) divides the unsigned binary values in Dd and Dd+1 by those in Dr and Dr+1 and outputs the quotient to R, R+1 and the remainder to R+2, and R+3.
  • Page 330 3. Instructions /B, /BL Function Instruction Mnemonic Variations Function code Divides 4-digit (single-word) BCD data and/or con- BCD DIVIDE stants. Divides 8-digit (double-word) BCD data and/or DOUBLE BCD DIVIDE @/BL constants. /BL(435) /B(434) Symbol Dd: 1st dividend word Dd: Dividend word Dr: 1st divisor word Dr: Divisor word R: Result word...
  • Page 331 3. Instructions Function  /B /B(434) divides the BCD content of Dd by those of Dr and outputs the quotient to R and the remainder to R+1. (BCD) ÷ (BCD) (BCD) R +1 Remainder Quotient  /BL /BL(435) divides BCD values in Dd and Dd+1 by those in Dr and Dr+1 and outputs the quotient to R, R+1 and the remainder to R+2, R+3.
  • Page 332: Conversion Instructions

    3. Instructions Conversion Instructions BIN/BINL Function Instruction Mnemonic Variations Function code BCD TO BINARY @BIN Converts BCD data to binary data. DOUBLE BCD TO DOUBLE Converts 8-digit BCD data to 8-digit hexadecimal BINL @BINL BINARY (32-bit binary) data. BINL BIN(023) BINL(058) Symbol S: Source word...
  • Page 333 3. Instructions Function  BIN BIN(023) converts the BCD data in S to binary data and (BCD) (BIN) writes the result to R. The following diagram shows an example BCD-to-binary conversion. ×10 ×10 ×10 ×10 ×16 ×16 ×16 ×16  BINL BINL(058) converts the 8-digit BCD data in S and S+1 to 8- digit hexadecimal (32-bit binary) data and writes the result to (BCD)
  • Page 334 3. Instructions BCD/BCDL Function Instruction Mnemonic Variations Function code Converts a word of binary data to a word of BCD BINARY TO BCD @BCD data. DOUBLE BINARY TO Converts 8-digit hexadecimal (32-bit binary) data BCDL @BCDL DOUBLE BCD to 8-digit BCD data. BCDL BCD(024) BCDL(059)
  • Page 335 3. Instructions Function  BCD BCD(024) converts the binary data in S to BCD data and (BIN) (BCD) writes the result to R. The following diagram shows an example BCD-to-binary conversion. × × × × × × × ×  BCDL BCDL(059) converts the 8-digit hexadecimal (32-bit binary) data in S and S+1 to 8-digit BCD data and writes the result (BCD)
  • Page 336 3. Instructions  In this example, N words of binary data is converted to BCD data. If N = 3, the three words of binary starting from D10 will be converted to binary data one word at a time when CIO 0.00 turns ON. The resulting BCD data will be stored starting from D100. 0.00 MOVR (Hexadecimal #0064)
  • Page 337 3. Instructions NEG/NEGL Function Instruction Mnemonic Variations Function code Calculates the 2's complement of a word of hexa- 2'S COMPLEMENT @NEG decimal data. Calculates the 2's complement of two words of DOUBLE 2'S COMPLEMENT NEGL @NEGL hexadecimal data. NEGL NEG(160) NEGL(161) Symbol S: Source word...
  • Page 338 3. Instructions Function  NEG NEG(160) calculates the 2's complement of S and writes the result to R. The 2's complement 2's complement calculation basically reverses the status of the bits in S and (Complement + 1) adds 1. Note The result for 8000 hex will be 8000 hex. ...
  • Page 339 3. Instructions SIGN Function Instruction Mnemonic Variations Function code 16-BIT TO 32-BIT SIGNED Expands a 16-bit signed binary value to its 32-bit SIGN @SIGN BINARY equivalent. SIGN SIGN(600) Symbol S: Source word R: First result word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 340 3. Instructions Function SIGN(600) converts the 16-bit signed binary number in S to its 32-bit signed binary equivalent and writes the result in R+1 and R. The conversion is accomplished by copying the content of S to R and writing FFFF to R+1 if bit 15 of S is 1 or writing 0000 to R+1 if bit 15 of S is 0.
  • Page 341 3. Instructions MLPX Function Instruction Mnemonic Variations Function code Reads the numerical value in the specified digit (or byte) in the source word with 4-to 16 conver- DATA DECODER MLPX @MLPX sion (or 8-to-256 conversion), turns ON the corre- sponding bit in the result word, and turns OFF all other bits in the result word.
  • Page 342 3. Instructions  8-to-256 bit conversion S: Source Word R: First Result Word D+15 to D: Decoding result of 1st digit of decoded digits Digit 1 Digit 0 D+31 to D+16: Digits from the starting digit going left are Decoding result of 2nd digit of decoded digits decoded (Returns to digit 0 after digit 1) Note The result words must be in the same data area.
  • Page 343 3. Instructions  8-to-256 bit Conversion l=1 (Convert 2 bytes.) When the leftmost digit of C is 1, MLPX(076) takes the value of the specified byte in S (00 to FF) and turns ON the corresponding bit in the n=1 (Start with second byte.) range of 16 result words.
  • Page 344 3. Instructions Example Programming  4-to-16 bit Conversion When CIO 0.00 is ON in the following example, MLPX(076) will convert 3 digits in S beginning with digit 1 (the second digit), as indicated by C (#0021). The corresponding bits in D100, D101, and D102 will be turned ON.
  • Page 345 3. Instructions  Example of multi-digit decoding • Example of 4-to-16 bit decoding C: #0010 C: #0030 C: #0031 Digit 3 Digit 2 Digit 1 Digit 0 Digit 3 Digit 2 Digit 1 Digit 0 Digit 3 Digit 2 Digit 1 Digit 0 •...
  • Page 346 3. Instructions DMPX Function Instruction Mnemonic Variations Function code Finds the location of the first or last ON bit within the source word with 16-to-4 conversion (or 256- DATA ENCODER DMPX @DMPX to-8 conversion), and writes that value to the specified digit (or byte) in the result word.
  • Page 347 3. Instructions  256-to-8 bit conversion S: First Source Word R: Result Word S+15 to S: 1st digit of digits to be encoded Digit 1 Digit 0 S+31 to S+16: 2nd digit of digits to be encoded The results of encoding of S to S+15, S+16 to S+31 are stored from the starting digit going left (returns to digit 0 after digit 1).
  • Page 348 3. Instructions  256-to-8 bit Conversion When the fourth (leftmost) digit of C is 1, DMPX(077) finds the locations of the leftmost (highest bit address) or rightmost (lowest bit address) ON bits in one or two 16-word ranges of source words. The locations of these bits are written to R beginning with the specified byte.
  • Page 349 3. Instructions Example Programming  16-to-4 bit Conversion When CIO 0.00 is ON in the following example, DMPX(077) will find the leftmost ON bits in CIO 100, CIO 101, and CIO 102 and write those locations to 3 digits in R beginning with digit 1 (the second digit), as indicated by C (#0021).
  • Page 350 3. Instructions  256-to-8 bit Conversion C: #1010 C: #1011 Digit 1 Digit 0 Digit 1 Digit 0 If the conversion data contains 0000 hex, but other data is to be encoded, separate the conversion by using more than one DMPX(077) instructions. DMPX(077) D0 D100 #0300 ...
  • Page 351 3. Instructions Function Instruction Mnemonic Variations Function code Converts 4-bit hexadecimal digits in the source ASCII CONVERT @ASC word into their 8-bit ASCII equivalents. ASC(086) Symbol S: Source word DI: Digit designator D: First destination word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 352 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag • ON if the content of Di is not within the specified ranges. •...
  • Page 353 3. Instructions Example Programming When CIO 0.00 is ON in the following example, ASC(086) converts three hexadecimal digits in D100 (beginning with digit 1) into their ASCII equivalents and writes this data to D200 and D201 beginning with the leftmost byte in D200. In this case, a digit designator of #0121 specifies no parity, the starting byte (when writing) = leftmost byte, the number of digits to read = 3, and the starting digit (when reading) = digit 1.
  • Page 354 3. Instructions  Parity It is possible to specify the parity of the ASCII data for use in error control during data transmissions. The leftmost bit of each ASCII character will be automatically adjusted for even, odd, or no parity. •...
  • Page 355 3. Instructions Function Instruction Mnemonic Variations Function code Converts up to 4 bytes of ASCII data in the source ASCII TO HEX @HEX word to their hexadecimal equivalents and writes these digits in the specified destination word. HEX(162) Symbol S: First source word DI: Digit designator D: Destination word Applicable Program Areas...
  • Page 356 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag • ON if there is a parity error in the ASCII data. • ON if the ASCII data in the source words is not equivalent to hexadecimal digits •...
  • Page 357 3. Instructions Example Programming When CIO 0.00 is ON in the following example, HEX(162) converts the ASCII data in D100 and D101 according to the settings of the digit designator. (Di=#0121 specifies no parity, the starting byte (when reading) = leftmost byte, the number of bytes to read = 3, and the starting digit (when writing) = digit 1.) HEX(162) converts three bytes of ASCII data (3 characters) beginning with the leftmost byte of D100 into their hexadecimal equivalents and writes this data to D200 beginning with digit 1.
  • Page 358 3. Instructions  Output example Conversion data Output result (hex data) ASCII (MSB) bit content (LSB) Value Bit content code * Parity bit - changes according to the parity specification. When CIO 0.00 is ON in the following example, HEX(162) converts the ASCII data in D10 beginning with the rightmost byte and writes the hexadecimal equivalents in D300 beginning with digit 1.
  • Page 359 3. Instructions  Example of converting multiple bytes of ASCII code to hex Di: #0112 Di: #0030 Di: #0131 Leftmost Leftmost Rightmost Leftmost Rightmost Leftmost Rightmost Leftmost Rightmost Rightmost Digit 3 Digit 2 Digit 1 Digit 0 Digit 3 Digit 2 Digit 1 Digit 0 Digit 3 Digit 2 Digit 1 Digit 0 CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 360 3. Instructions LINE Function Instruction Mnemonic Variations Function code Converts a column of bits from a 16-word range COLUMN TO LINE LINE @LINE (the same bit number in 16 consecutive words) to the 16 bits of the destination word. LINE LINE(063) Symbol S: First source word...
  • Page 361 3. Instructions Function LINE(063) copies the 16 bits with bit number N from the 16-word range S to S+15 to the destination word D. Bit N of S+m is copied to bit m of D, i.e., bit N of S is copied to bit 00 of D and bit N of S+15 is copied to bit 15 of D.
  • Page 362 3. Instructions COLM Function Instruction Mnemonic Variations Function code Converts the 16 bits of the source word to a col- umn of bits in a 16-word range of destination LINE TO COLUMN COLM @COLM words (the same bit number in 16 consecutive words).
  • Page 363 3. Instructions Flags Name Label Operation Error Flag • ON if N is not within the specified range of 0000 to 000F. • OFF in all other cases. Equal Flag • ON if bit N is 0 in all 16 words D to D+15 after execution. •...
  • Page 364 3. Instructions BINS/BISL Function Instruction Mnemonic Variations Function code Converts one word of signed BCD data to one SIGNED BCD TO BINARY BINS @BINS word of signed binary data. DOUBLE SIGNED BCD TO Converts double signed BCD data to double BISL @BISL BINARY...
  • Page 365 3. Instructions • C = 2 (Input Data Range: -999 to 9999 BCD) 3 digits BCD, 12 bits 0 to 9: Fourth digit BCD F: Negative (–) A to E: Error • C = 3 (Input Data Range: -1999 to 9999 BCD) 3 digits BCD, 12 bits 0 to 9: Fourth digit BCD A: Negative (–1)
  • Page 366 3. Instructions  Operand Specifications BINS Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR BISL Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation...
  • Page 367 3. Instructions Function  BINS BINS(470) converts the signed BCD data in S to signed binary data and writes the result in Signed BCD format according to the format setting in the control specified in C word (C). Signed BCD Signed binary Setting Signed BCD values...
  • Page 368 3. Instructions Example Programming  BINS BCD Format 0 (C=#0000) When CIO 0.00 is ON in the following example, the signed BCD data format and range in D100 are checked against the format specified in the control word (0000). The source data is correct, so the signed BCD data in D100 is converted to signed binary and output to D200.
  • Page 369 3. Instructions BCDS/BDSL Function Instruction Mnemonic Variations Function code Converts one word of signed binary data to one SIGNED BINARY TO BCD BCDS @BCDS word of signed BCD data. DOUBLE SIGNED BINARY TO Converts double signed binary data to double BDSL @BDSL signed BCD data.
  • Page 370 3. Instructions • C = 1 (Output Data Range: -7999 to 7999 BCD) 3 digits BCD, 12 bits 3 bits of digit 4 (Bit 12 to 14) Sign bit (0: Positive; 1: Negative) • C = 2 (Output Data Range: -999 to 9999 BCD) 3 digits BCD, 12 bits 0 to 9: Fourth digit BCD F: Negative (–)
  • Page 371 3. Instructions  Operand Specifications BCDS Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR BDSL Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation...
  • Page 372 3. Instructions  BDSL BDSL(473) converts the double singled binary data in S+1 and S to signed BCD data and writes the result in D+1 and D according to the Signed BCD format specified in C format setting in the control word (C). Signed binary Signed BCD Signed BCD...
  • Page 373 3. Instructions Function Instruction Mnemonic Variations Function code Converts the gray binary code in a specified word GRAY CODE CONVERT @GRY to standard binary data, BCD data, or an angle at the specified resolution. GRY(474) C: First control word Symbol S: Source word D: First destination word Applicable Program Areas...
  • Page 374 3. Instructions S: Source Word Contains the gray binary code to be converted. The range must be within the number of bits determined by the resolution specified in bits 00 to 03 of C. All bits outside of the number of bits for the specified resolution will be ignored.
  • Page 375 3. Instructions Function GRY(474) converts the gray binary code in the word specified in S at the resolution specified in C using one of the following conversion modes (binary, BCD, or 360 ), also specified in C, and places the °...
  • Page 376 Angle data stored. D+1: D201 0000 Example 3: Converting to BCD Data with for an OMRON E6C2-AG5C Absolute Encoder (Resolution: 360/rota- tion, Encoder Remainder Compensation: 76) and Zero Point Offset of 0000 Hex C: D0 Resolution: User-specified Conversion mode: BCD Mode...
  • Page 377 3. Instructions Example 4: Converting to BCD Data with for an OMRON E6C2-AG5C Absolute Encoder (Resolution: 360/rota- tion, Encoder Remainder Compensation: 76) and Zero Point Offset of 000A Hex C: D0 Resolution: User-specified Conversion mode: BCD Mode Operating mode: Gray binary code conversion...
  • Page 378 3. Instructions GRAY_BIN/GRAY_BINL Function Instruction Mnemonic Variations Function code GRAY CODE TO BINARY Converts the specified word of gray code to one GRAY_BIN @GRAY_BIN CONVERT word of binary data. DOUBLE GRAY CODE TO Converts the specified two words of gray code to GRAY_BINL @GRAY_BINL BINARY CONVERT...
  • Page 379 3. Instructions Function  GRAY_BIN(478) GRAY_BIN(478) converts one word of gray code to one word of binary data. S specifies the source word containing the gray code and the binary data is output to D.  GRAY_BINL(479) GRAY_BINL(479) converts two words of gray code to two words of binary data. S specifies the first of the two words containing the gray code and the binary data is output to D and D+1.
  • Page 380 3. Instructions BIN_GRAY/BIN_GRAYL Function Instruction Mnemonic Variations Function code BINARY TO GRAY CODE Converts the specified word of binary data to one BIN_GRAY @BIN_GRAY CONVERT word of gray code. DOUBLE BINARY TO GRAY Converts the specified two words of binary data to BIN_GRAYL @BIN_GRAYL CODE CONVERT...
  • Page 381 3. Instructions Function  BIN_GRAY(480) BIN_GRAY(480) converts one word of binary data to one word of gray code. S specifies the source word containing the binary data and the gray code is output to D.  BIN_GRAYL(481) BIN_GRAYL(481) converts two words of binary data to two words of gray code. S specifies the first of the two words containing the binary data and the gray code is output to D and D+1.
  • Page 382 3. Instructions STR4/STR8/STR16 Function Instruction Mnemonic Variations Function code FOUR-DIGIT NUMBER TO Converts a 4-digit hexadecimal number (#0000 to STR4 @STR4 ASCII #FFFF) to ASCII data (4 characters). Converts an 8-digit hexadecimal number (#0000 EIGHT-DIGIT NUMBER TO STR8 @STR8 0000 to #FFFF FFFF) to ASCII data (8 charac- ASCII ters).
  • Page 383 3. Instructions Function  STR4 STR4(601) converts the numerical data in S (4-digit hexadecimal, #0000 to #FFFF) to ASCII data (4 characters) and writes the result Hexadecimal: #1234 to D and D+1. ASCII  STR8 STR8(602) converts the numerical data in S and S+1 (8-digit hexadecimal, #0000 0000 to #FFFF FFFF) to ASCII data (8 characters) and writes the result to D, D+1, D+2, and D+3.
  • Page 384 3. Instructions Example Programming  Converting 3 Words of Numerical Data to ASCII Data When CIO 0.00 is ON in the following example, the 3 words of numerical data starting at D10 are converted, one word at a time, to ASCII data. The converted ASCII data is stored in the DM Area starting at D100.
  • Page 385 3. Instructions NUM4/NUM8/NUM16 Function Instruction Mnemonic Variations Function code ASCII TO FOUR-DIGIT Converts 4 characters of ASCII data to NUM4 @NUM4 NUMBER a 4-digit hexadecimal number. ASCII TO EIGHT-DIGIT Converts 8 characters of ASCII data to NUM8 @NUM8 NUMBER an 8-digit hexadecimal number. ASCII TO SIXTEEN-DIGIT Converts 16 characters of ASCII data to NUM16...
  • Page 386 3. Instructions Function  NUM4 • NUM4(604) converts the 4 characters of ASCII data in S and S+1 to numerical data (4-digit hexadecimal) and writes the result to ASCII • The Error Flag will be turned ON if the ASCII data in S and S+1 contains any characters Hexadecimal that are not hexadecimal digits.
  • Page 387 3. Instructions Example Programming  Converting 3 Sets of 4 ASCII Characters to the Equivalent Hexadecimal Digits When CIO 0.00 is ON in the following example, the 6 words of ASCII data starting at D10 are converted, two words at a time, to numerical data. The converted numerical data is stored in the DM Area starting at D100.
  • Page 388: Logic Instructions

    3. Instructions Logic Instructions ANDW/ANDL Function Instruction Mnemonic Variations Function code Takes the logical AND of corresponding bits in LOGICAL AND ANDW @ANDW single words of word data and/or constants. Takes the logical AND of corresponding bits in DOUBLE LOGICAL AND ANDL @ANDL double words of word data and/or constants.
  • Page 389 3. Instructions Function  ANDW → R ANDW(034) takes the logical AND of data specified in and I and outputs the result to R.  ANDL +1) → (R, R+1) • ANDL(610) takes the logical AND of data specified in R, R+1 +1 and I +1 and outputs the result to R, R+1.
  • Page 390 3. Instructions ORW/ORWL Function Instruction Mnemonic Variations Function code Takes the logical OR of corresponding bits in sin- LOGICAL OR @ORW gle words of word data and/or constants. Takes the logical OR of corresponding bits in dou- DOUBLE LOGICAL OR ORWL @ORWL ble words of word data and/or constants.
  • Page 391 3. Instructions Function  ORW → R ORW(035) takes the logical OR of data specified in I and I and outputs the result to R.  ORWL +1) → (R, R+1) +1) + (I ORWL(611) takes the logical OR of data specified in R, R+1 and I as double-word data and outputs the result...
  • Page 392 3. Instructions XORW/XORL Function Instruction Mnemonic Variations Function code Takes the logical exclusive OR of corresponding EXCLUSIVE OR XORW @XORW bits in single words of word data and/or constants. Takes the logical exclusive OR of corresponding DOUBLE EXCLUSIVE OR XORL @XORL bits in double words of word data and/or con- stants.
  • Page 393 3. Instructions Function  XORW → R • • XORW(036) takes the logical exclusive OR of data specified in I and I and outputs the result to R.  XORL +1) → (R, R+1) +1) + (I • • XORL(612) takes the logical exclusive OR of data specified in I and I as double-word data and outputs...
  • Page 394 3. Instructions XNRW/XNRL Function Instruction Mnemonic Variations Function code Takes the logical exclusive NOR of corresponding EXCLUSIVE NOR XNRW @XNRW single words of word data and/or constants. Takes the logical exclusive NOR of corresponding DOUBLE EXCLUSIVE NOR XNRL @XNRL bits in double words of word data and/or con- stants.
  • Page 395 3. Instructions Function  XNRW → R • • XNRW(037) takes the logical exclusive NOR of data specified in I and I and outputs the result to R.  XNRL +1) → (R, R+1) +1) + (I • • XNRL(613) takes the logical exclusive NOR of data specified in I and I and outputs the result to R, R+1.
  • Page 396 3. Instructions COM/COML Function Instruction Mnemonic Variations Function code Turns OFF all ON bits and turns ON all OFF bits in COMPLEMENT @COM Turns OFF all ON bits and turns ON all OFF bits in DOUBLE COMPLEMENT COML @COML Wd and Wd+1. COML COM(029) COML(614)
  • Page 397 3. Instructions Example Programming When CIO 0.00 is ON in the following example, the status of each bit D100 will be reversed. 0.00 D100 D100 D100 When CIO 0.00 is ON in the following example, the status of each bit in D100 and D101 will be reversed.
  • Page 398: Special Math Instructions

    3. Instructions Special Math Instructions ROTB Function Instruction Mnemonic Variations Function code Computes the square root of the 32-bit signed binary contents (positive value) of the specified BINARY ROOT ROTB @ROTB words and outputs the integer portion of the result to the specified result word.
  • Page 399 3. Instructions Function ROTB(620) computes the square root of the 32-bit binary number in S+1 and S and outputs the integer portion of the result to R. Binary data (32 bits) Binary data (16 bits) Note 1 The non-integer remainder is eliminated. 2 The range of data that can be specified for words S+1 and S is 0000 0000 to 3FFF FFFF.
  • Page 400 3. Instructions ROOT Function Instruction Mnemonic Variations Function code Computes the square root of an 8-digit BCD num- BCD SQUARE ROOT ROOT @ROOT ber and outputs the integer portion of the result to the specified result word. ROOT ROOT(072) Symbol S: First source word R: Result word Applicable Program Areas...
  • Page 401 3. Instructions Example Programming When CIO 0.00 is ON in the following example, ROOT(072) calculates the square root of the data in D1 and D0, and writes the integer portion of the result in D100. 0.00 D100 S+1: D1 S: D0 D: D100 Truncated CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 402 3. Instructions Application example The following example shows how to take the square root of a 4-digit number and round off the result. This program example calculates the square root of the 4-digit number in CIO 10, rounds off the result, and writes it to CIO 11.
  • Page 403 3. Instructions Function Instruction Mnemonic Variations Function code Calculates the sine, cosine, or a linear extrapola- ARITHMETIC PROCESS @APR tion of the source data. APR(069) C: Control word Symbol S: Source word R: Result word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 404 3. Instructions  Linear Extrapolation Function • Linear Extrapolation (C = Data area address) Operand Value Data range APR(069) linear extrapolation is specified when C is a word Data area address address. 16-bit unsigned BCD data 0000 to 9999 The content of word C specifies the number of coordinates in 16-bit unsigned binary a data table starting at C+2, the form of the source data, and 0 to 65,535...
  • Page 405 3. Instructions · Signed Integer Data (Binary) 14 13 12 11 Number of coordinates minus one (m-1), 00 to FF hex (1 < m < 256) Floating-point specification for S and D 0: Integer data Data length specification for S and D (note 1) 0: 16-bit signed binary data 1: 32-bit signed binary data Signed data specification for S and D...
  • Page 406 3. Instructions Flags Name Label Operation Error Flag • ON if C is a constant greater than 0001. ≤ ≤ ≤ • ON if C is a word address but the X coordinates are not in ascending order (X • ON if C is a word address and bits 9, 11, and 15 of C indicate BCD input, but S is not BCD. •...
  • Page 407 3. Instructions  16-bit Unsigned BCD Data Setting name Bit in C Setting The input data and/or the output data can be 16-bit Input data (S) format 0: Binary unsigned BCD data. Also, the linear extrapolation 1: BCD function can be set to operate on the value speci- Output data (D) format 0: Binary fied in S directly or on X...
  • Page 408 3. Instructions  Floating-point Data (CJ2, CS1-H, CJ1-H, CJ1M, and CS1D Only) Setting name Bit in C Setting Input data (S) format Output data (D) format Source data form Signed data specification for S and D Data length specification for S and D Floating-point specification 1: Floating-point data...
  • Page 409 3. Instructions • Y = f(X ), Y = f(X Word Coordinate • Be sure that X < X in all cases. Xm (max. X value) • Input all values of (X ) as binary data. ↓ ↓ C+(2m+1) (max. X value) C+(2m+2) This example shows how to construct a linear extrapolation with 12 coordinates.
  • Page 410 3. Instructions • Using 32-bit Signed Binary Data (CJ2, CS1-H, CJ1-H, CJ1M, and CS1D ×Only) In this example, APR(069) is used to convert the fluid height in a tank to fluid volume based on the shape of the holding tank. Fluid height to volume conversion table (32-bit signed binary data) X0 (rightmost 16 bits)
  • Page 411 3. Instructions • Using Floating-point Data (CJ2, CS1-H, CJ1-H, CJ1M, and CS1D Only) In this example, APR(069) is used to convert the fluid height in a tank to fluid volume based on the shape of the holding tank. X0 (rightmost 16 bits) Fluid height to volume X0 (leftmost 16 bits) conversion table...
  • Page 412 3. Instructions FDIV Function Instruction Mnemonic Variations Function code Divides one 7-digit floating-point number by FLOATING POINT DIVIDE another. The floating-point numbers are FDIV @FDIV (BCD) expressed in scientific notation (7-digit mantissa and 1-digit exponent). FDIV FDIV(079) Dd: First dividend word Symbol Dr: First divisor word R: First result word...
  • Page 413 3. Instructions Note The result is expressed as a floating-point value, so it has 7 significant digits. The eighth and higher digits are eliminated. To represent the floating-point values, the rightmost seven digits are used for the mantissa and the leftmost digit is used for the exponent, as shown in the diagram below.
  • Page 414 3. Instructions Application example In this example, the 4-digit BCD number in D0 is divided by the 4-digit BCD number in D1 and the floating-point result is written to D3 and D2. (Example) 0.3452 0.0079 104=0.436962 × ÷ × × 0.00 To perform the floating point division, the BCD value @MOV...
  • Page 415 3. Instructions BCNT Function Instruction Mnemonic Variations Function code Counts the total number of ON bits in the specified BIT COUNTER BCNT @BCNT word(s). BCNT BCNT(067) N: Number of words Symbol S: First source word R: Result word Applicable Program Areas Function block SFC action or Area...
  • Page 416 3. Instructions Precautions • Some time will be required to complete BCNT(067) if a large number of words is specified. Even if an interrupt occurs, execution of this instruction will not be interrupted and execution of the interrupt task will be started after execution of BCNT(067) has been completed. One BCNT(067) instruction can be replaced with two BCNT(067) instructions to help avoid this problem.
  • Page 417: Floating-Point Math Instructions

    3. Instructions Floating-point Math Instructions Floating-point Math Instructions The Floating-point Math Instructions convert data and perform floating-point arithmetic operations.  Data Format Floating-point data expresses real numbers using a sign, exponent, and mantissa. When data is expressed in floating-point format, the following formula applies. e–127 Real number = (–1) (1.f)
  • Page 418 3. Instructions  Writing Floating-point Constants When writing floating-point constants, include the plus (+) or minus (−) sign. For example, enter the following: +123, +123.45, or −123.45. If you enter “&”, such as in “&123,” the value will be taken as a decimal value, and the floating-point instruction will not function correctly.
  • Page 419 3. Instructions (2) Non-normalized Numbers Non-normalized numbers express real numbers with very small absolute values. The sign bit will be 0 for a positive number and 1 for a negative number. The exponent (e) will be 0, and the real exponent will be –126. The mantissa (f) will be expressed from 1 to 2 –...
  • Page 420 3. Instructions  Floating-point Arithmetic Results (1) Rounding Results The following methods will be used to round results when the number of digits in the accurate result of floating-point arithmetic exceeds the significant digits of internal processing expressions. If the result is close to one of two internal floating-point expressions, the closer expression will be used. If the result is midway between two internal floating-point expressions, the result will be rounded so that the last digit of the mantissa is 0.
  • Page 421 3. Instructions Example Programming 0.00 Calculations D200 Distance r =   −1 Angle θ = tan -- - D201   Example: Given the coordinates (100, 100), D200 the distance r and the angle θ can D202 be calculated from the above D201 equation.
  • Page 422 3. Instructions FIX/FIXL Function Instruction Mnemonic Variations Function code Converts a 32-bit floating-point value to 16-bit FLOATING TO 16-BIT @FIX signed binary data and places the result in the specified result word. Converts a 32-bit floating-point value to 32-bit FLOATING TO 32-BIT FIXL @FIXL signed binary data and places the result in the...
  • Page 423 3. Instructions Function  FIX FIX(450) converts the integer portion of the 32-bit floating-point number in S+1 and S (IEEE754-format) to 16-bit signed binary data and places the result in R. Floating-point data (32 bits) Signed binary data (16 bits) Only the integer portion of the floating-point data is converted, and the fraction portion is truncated.
  • Page 424 3. Instructions FLT/FLTL Function Instruction Mnemonic Variations Function code Converts a 16-bit signed binary value to 32-bit 16-BIT TO FLOATING @FLT floating-point data and places the result in the specified result words. Converts a 32-bit signed binary value to 32-bit 32-BIT TO FLOATING FLTL @FLTL...
  • Page 425 3. Instructions Function  FLT FLT(452) converts the 16-bit signed binary value in S to 32-bit floating-point data (IEEE754-format) and places the result in R+1 and R. A single 0 is added after the decimal point in the floating-point result. Signed binary data (16 bits) Floating-point data (32 bits) Only values within the range of −32,768 to 32,767 can be specified for S.
  • Page 426 3. Instructions +F, –F, *F, /F Function Instruction Mnemonic Variations Function code Adds two 32-bit floating-point numbers and places FLOATING-POINT ADD the result in the specified result words. Subtracts one 32-bit floating-point number from FLOATING-POINT SUBTRACT –F @–F another and places the result in the specified result words.
  • Page 427 3. Instructions Flags Name Label Operation Error Flag ON if Au, AD, Mi, Su, Md, Dd is not recognized as floating-point data. • ON if the augend or addend data is not a number (NaN). • ON if +∞ and –∞ are added. •...
  • Page 428 3. Instructions  /F Dd+1 Dividend (floating-point data, 32 bits) ÷ Dr+1 Divisor (floating-point data, 32 bits) Result (floating-point data, 32 bits) • If the absolute value of the result is greater than the maximum value that can be expressed as floating-point data, the Overflow Flag will turn ON and the result will be output as ±∞.
  • Page 429 3. Instructions  FLOATING-POINT MULTIPLY (*F) Multiplicand Multiplier Numeral +∞ –∞ +/–∞ +/–∞ Numeral See note 1. (See note 2.) (See note 2.) +/–∞ +∞ +∞ –∞ (See note 2.) +/–∞ –∞ +∞ –∞ (See note 2.) Note 1 The results could be zero (including underflows), a numeral, +∞, or –∞. 2 With CJ1H-CPU@@H-R CPU Units, an undetermined value will be output.
  • Page 430 3. Instructions Function Instruction Mnemonic Variations Function code Converts a 32-bit floating-point number from DEGREES TO RADIANS @RAD degrees to radians and places the result in the specified result words. RAD(458) Symbol S: First source word R: First result word Applicable Program Areas Function block SFC action or...
  • Page 431 3. Instructions Function RAD(458) converts the 32-bit floating-point number in S+1 and S from degrees to radians and places the result in R and R+1. (The floating point source data must be in IEEE754 format.) Source (degrees, 32-bit floating-point data) Result (radians, 32-bit floating-point data) Degrees are converted to radians by means of the following formula: Degrees ×...
  • Page 432 3. Instructions Function Instruction Mnemonic Variations Function code Converts a 32-bit floating-point number from radi- RADIANS TO DEGREES @DEG ans to degrees and places the result in the speci- fied result words. DEG(459) Symbol S: First source word R: First result word Applicable Program Areas Function block SFC action or...
  • Page 433 3. Instructions Function DEG(459) converts the 32-bit floating-point number in S+1 and S from radians to degrees and places the result in R+1 and R. (The floating point source data must be in IEEE754 format.) Source (radians, 32-bit floating-point data) Result (degrees, 32-bit floating-point data) Radians are converted to degrees by means of the following formula: Radians ×...
  • Page 434 3. Instructions SIN/COS/TAN Function Instruction Mnemonic Variations Function code Calculates the sine of a 32-bit floating-point num- SINE @SIN ber (in radians) and places the result in the speci- fied result words. Calculates the cosine of a 32-bit floating-point COSINE @COS number (in radians) and places the result in the specified result words.
  • Page 435 3. Instructions Function  SIN SIN(460) calculates the sine of the angle (in radians) expressed as a 32-bit floating-point value in S+1 and S and places the result in R+1 and R. (The floating point source data must be in IEEE754 format.) Source (32-bit floating-point data) Result (32-bit floating-point data) Specify the desired angle (–65,535 to 65,535) in radians in S+1 and S.
  • Page 436 3. Instructions  TAN TAN(462) calculates the tangent of the angle (in radians) expressed as a 32-bit floating-point value in S+1 and S and places the result in R+1 and R. (The floating point source data must be in IEEE754 format.) T AN Source (32-bit floating-point data) Result (32-bit floating-point data)
  • Page 437 3. Instructions SINQ/COSQ/TANQ Function Instruction Mnemonic Variations Function code Calculates the sine of a 32-bit floating-point num- HIGH-SPEED SINE SINQ @SINQ ber (in radians) and places the result in the speci- fied result words. Calculates the cosine of a 32-bit floating-point HIGH-SPEED COSINE COSQ @COSQ...
  • Page 438 3. Instructions Function  SINQ SINQ(475) calculates the sine of the angle (in radians) expressed as a 32-bit floating-point value in S+1 and S and places the result in R+1 and R. (The floating point source data must be in IEEE754 format.) Source (32-bit floating-point data) Result (32-bit floating-point data) •...
  • Page 439 3. Instructions  TANQ TANQ(477) calculates the tangent of the angle (in radians) expressed as a 32-bit floating-point value in S+1 and S and places the result in R+1 and R. (The floating point source data must be in IEEE754 format. T AN Source (32-bit floating-point data) Result (32-bit floating-point data)
  • Page 440 3. Instructions Precautions  SINQ, COSQ SINQ(475)/COSQ(476) differs from SIN(460)/COS(461) in the following respects: • The instruction has improved performance. • The instruction length is 8 steps. • The Condition Flags are not refreshed. • An unpredictable value will be output if the angle data is out-of-range. •...
  • Page 441 3. Instructions ASIN/ACOS/ATAN Function Instruction Mnemonic Variations Function code Calculates the arc sine of a 32-bit floating-point ARC SINE ASIN @ASIN number and places the result in the specified result words. Calculates the arc cosine of a 32-bit floating-point ARC COSINE ACOS @ACOS number and places the result in the specified...
  • Page 442 3. Instructions Flags Name Label Operation Error Flag ON if the source data is not recognized as floating-point data. • ASIN ON if the source data is not a number (NaN). ON if the absolute value of the source data exceeds 1.0. •...
  • Page 443 3. Instructions  ACOS ACOS(464) computes the angle (in radians) for a cosine value expressed as a 32-bit floating-point number in S+1 and S and places the result in R+1 and R. (The floating point source data must be in IEEE754 format.) –1 Source (32-bit floating-point data) Result (32-bit floating-point data)
  • Page 444 3. Instructions SQRT Function Instruction Mnemonic Variations Function code Calculates the square root of a 32-bit floating- SQUARE ROOT SQRT @SQRT point number and places the result in the specified result words. SQRT SQRT(466) Symbol S: First source word R: First result word Applicable Program Areas Function block SFC action or...
  • Page 445 3. Instructions Function SQRT(466) calculates the square root of the 32-bit floating-point number in S+1 and S and places the result in R+1 and R. (The floating point source data must be in IEEE754 format.) Source (32-bit floating-point data) Result (32-bit floating-point data) The following diagram shows the relationship between the input data and result.
  • Page 446 3. Instructions Function Instruction Mnemonic Variations Function code Calculates the natural (base e) exponential of a EXPONENT @EXP 32-bit floating-point number and places the result in the specified result words. EXP(467) Symbol S: First source word R: First result word Applicable Program Areas Function block SFC action or...
  • Page 447 3. Instructions Function EXP(467) calculates the natural (base e) exponential of the 32-bit floating-point number in S+1 and S and places the result in R+1 and R. In other words, EXP(467) calculates e (x = source) and places the result in R+1 and R. Source (32-bit floating-point data) Result (32-bit floating-point data) The constant e is 2.718282.
  • Page 448 3. Instructions Function Instruction Mnemonic Variations Function code Calculates the natural (base e) logarithm of a 32- LOGARITHM @LOG bit floating-point number and places the result in the specified result words. LOG(468) Symbol S: First source word R: First result word Applicable Program Areas Function block SFC action or...
  • Page 449 3. Instructions Function LOG(468) calculates the natural (base e) logarithm of the 32-bit floating-point number in S+1 and S and places the result in R+1 and R. Source (32-bit floating-point data) Result (32-bit floating-point data) The constant e is 2.718282. The following diagram shows the relationship between the input data and result.
  • Page 450 3. Instructions Function Instruction Mnemonic Variations Function code Raises a 32-bit floating-point number to the power EXPONENTIAL POWER @PWR of another 32-bit floating-point number. PWR(840) Symbol B: First base word E: First exponent word R: First result word Applicable Program Areas Function block SFC action or Area...
  • Page 451 3. Instructions Function PWR(840) raises the 32-bit floating-point number in B+1 and B to the power of the 32-bit floating-point number in E+1 and E. In other words, PWR(840) calculates XY (X = B+1 and B; Y = E+1 and E). Exponent data Base data For example, when the base words (B+1 and B) contain 3.1 and the exponent words (E+1 and E)
  • Page 452 3. Instructions =F, <>F, F, >=F Function Instruction Mnemonic Variations Function code These input comparison instructions compare two <> single-precision floating point values (32-bit < Single-precision Floating-point IEEE754 constants and/or the contents of speci- <= Comparison fied words) and create an ON execution condition >...
  • Page 453 3. Instructions Function input comparison instruction LD connection ON execution condition when compares the data specified in S1 and S2 comparison result is true. as single-precision floating point values
  • Page 454 3. Instructions Code Mnemonic Name Function LD>=F LOAD FLOATING GREATER THAN OR EQUAL True if C1 ≥ C2 AND>=F AND FLOATING GREATER THAN OR EQUAL OR>=F OR FLOATING GREATER THAN OR EQUAL Precautions • Input comparison instructions cannot be used as right-hand instructions, i.e., another instruction must be used between them and the right bus bar.
  • Page 455 3. Instructions FSTR Function Instruction Mnemonic Variations Function code Expresses a 32-bit floating-point value (IEEE754- FLOATING-POINT TO ASCII FSTR @FSTR format) in standard decimal notation or scientific notation and converts that value to ASCII text. FSTR FSTR(448) Symbol S: First source word C: First control word D: First destination word Applicable Program Areas...
  • Page 456 3. Instructions Function FSTR(448) expresses the 32-bit floating-point number in S+1 and S (IEEE754-format) in decimal notation or scientific notation according to the control data in words C to C+2, converts the number to ASCII text, and outputs the result to the destination words starting at D. •...
  • Page 457 3. Instructions  Storage of ASCII Text After the floating-point number is converted to ASCII text, the ASCII characters are stored in the destination words beginning with D, as shown in the following diagrams. Different storage methods are used for decimal notation and scientific notation. Decimal notation (C=0 hex) Total number of characters Integer part...
  • Page 458 3. Instructions • Limits on the Number of Digits in the Integer Part 1) Decimal Notation (C = 0 hex) • When there is no fractional part (C+2 = 0 hex): 1 ≤ Number of Integer Digits ≤ 24 • When there is a fractional part (C+2 = 1 to 7 hex): 1 ≤...
  • Page 459 3. Instructions  Converting to ASCII Text in Scientific Notation When CIO 0.00 is ON in the following example, FSTR(448) converts the floating-point data in D1 and D0 to scientific-notation ASCII text and writes the ASCII text to the destination words beginning with D100.
  • Page 460 3. Instructions FVAL Function Instruction Mnemonic Variations Function code Converts a number expressed in ASCII text (deci- mal or scientific notation) to a 32-bit floating-point ASCII TO FLOATING-POINT FVAL @FVAL value (IEEE754-format) and outputs the floating- point value to the specified words. FVAL FVAL(449) Symbol...
  • Page 461 3. Instructions • Scientific Notation Real numbers expressed as an integer part, fractional part, and exponent part. Example: 1.2456E-2 (1.2456×10 The data format (decimal or scientific notation) is detected automatically. The ASCII text must be stored in S and subsequent words in the following order: leftmost byte of S, rightmost byte of S, leftmost byte of S+1, rightmost byte of S+1, etc.
  • Page 462 3. Instructions  Storage of ASCII Text The following diagrams show how the ASCII text number is converted to floating-point data. Different conversion methods are used for numbers stored with decimal notation and scientific notation. ASCII Character Storage FVAL(449) converts the ASCII characters starting with the leftmost byte of S and continuing until a byte containing 00 hex is reached.
  • Page 463 3. Instructions Example Programming  Converting ASCII Text in Decimal Notation to Floating-point Data When CIO 0.00 is ON in the following example, FVAL(449) converts the specified decimal-notation ASCII text number in the source words starting at D0 to floating-point data and writes the result to destination words D100 and D101.
  • Page 464 3. Instructions MOVF Function Instruction Mnemonic Variations Function code MOVE FLOATING-POINT Transfers the specified 32-bit floating-point num- MOVF @MOVF (SINGLE) ber to the destination words. MOVF MOVF(469) Symbol S: First source word D: First destination word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 465: Double-Precision Floating-Point Instructions

    3. Instructions Double-precision Floating-point Instructions Double-precision Floating-point Instructions  Data Format Floating-point data expresses real numbers using a sign, exponent, and mantissa. When data is expressed in floating-point format, the following formula applies. e-1,023 Real number = (-1) (1.f) s: Sign e: Exponent f: Mantissa The floating-point data format conforms to the IEEE754 standards.
  • Page 466 3. Instructions • Special Numbers The formats for NaN, ±∞, and 0 are as follows: • NaN*:e = 2,047 and f ≠ 0 • +∞:e = 2,047, f = 0, and s= 0 • -∞: e = 2,047, f = 0, and s= 1 •...
  • Page 467 3. Instructions Sign: - Exponent:1,024 - 1,023 = 1 Mantissa: 1 + (2 ) × 2 = 1 + (2 ) = 1 + (0.75) = 1.75 Value: -1.75 × 2 = -3.5 (2) Non-normalized numbers Non-normalized numbers express real numbers with very small absolute values. The sign bit will be 0 for a positive number and 1 for a negative number.
  • Page 468 3. Instructions (2) Overflows, Underflows, and Illegal Calculations • Overflows will be output as either positive or negative infinity, depending on the sign of the result. Underflows will be output as either positive or negative zero, depending on the sign of the result.
  • Page 469 3. Instructions  Ladder Program for the Single-precision Calculation 1. This program section converts the BCD data to single- 0.00 precision floating-point data (32 bits, IEEE754-for- mat). D100 • The BIN(023) instructions convert the BCD data to D1000 binary and the FLT(452) instructions convert the D1000 binary data to single-precision floating-point data.
  • Page 470 3. Instructions  Ladder Program for the Double-precision Calculation 1. This program section converts the BCD data to dou- 0.00 ble-precision floating-point data (64 bits, IEEE754-for- mat). D100 • The BIN(023) instructions convert the BCD data to D1000 binary and the DBL(843) instructions convert the D1000 binary data to double-precision floating-point data.
  • Page 471 3. Instructions FIXD/FIXLD Function Instruction Mnemonic Variations Function code Converts a double-precision (64-bit) floating-point DOUBLE FLOATING TO 16-BIT FIXD @FIXD value to 16-bit signed binary data and places the result in the specified result word. Converts a double-precision (64-bit) floating-point DOUBLE FLOATING TO 32-BIT FIXLD @FIXLD...
  • Page 472 3. Instructions Flags Operation Name Label FIXD FIXLD Error Flag P_ER • ON if the source data is not recognized as • ON if the source data is not recognized as floating-point data. floating-point data. • ON if the source data (S) is not a number (NaN). •...
  • Page 473 3. Instructions DBL/DBLL Function Instruction Mnemonic Variations Function code Converts a 16-bit signed binary value to double- 16-BIT TO DOUBLE FLOAT- @DBL precision (64-bit) floating-point data and places the result in the specified destination words. Converts a double-precision (64-bit) floating-point 32-BIT TO DOUBLE FLOAT- DBLL @DBLL...
  • Page 474 3. Instructions Function  DBL DBL(843) converts the 16-bit signed binary value in S to double-precision (64-bit) floating-point data (IEEE754-format) and places the result in words D to D+3. A single 0 is added after the decimal point in the floating-point result. Signed binary data (16 bits) D+3CH D+2CH...
  • Page 475 3. Instructions +D, -D, ∗D, /D Function Instruction Mnemonic Variations Function code Adds two double-precision (64-bit) floating-point DOUBLE FLOATING-POINT numbers and places the result in the specified destination words. Subtracts one double-precision (64-bit) floating- DOUBLE FLOATING-POINT − point number from another and places the result in SUBTRACT the specified destination words.
  • Page 476 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Au, Mi, Md, Dd, Ad, Su, Mr, Dr Flags Name Label Operation Error Flag P_ER • ON when S1 or S2 is not treated as floating-point data. •...
  • Page 477 3. Instructions  Operation rules The result of an operation is output as shown below depending on the combination of floating-point data.  DOUBLE FLOATING-POINT ADD (+D) Augend Addend Numeral +∞ –∞ Numeral +∞ –∞ Numeral Numeral +∞ –∞ +∞ +∞...
  • Page 478 3. Instructions RADD Function Instruction Mnemonic Variations Function code Converts a double-precision (64-bit) floating-point DOUBLE DEGREES TO RADD @RADD number from degrees to radians and places the RADIANS result in the specified result words. RADD RADD(849) Symbol S: First source word D: First destination word Applicable Program Areas Function block...
  • Page 479 3. Instructions Function RADD(849) converts the double-precision (64-bit) floating-point number in words S to S+3 from degrees to radians and places the result in words D to D+3. (The floating point source data must be in IEEE754 format.) S+3CH S+2CH S+1CH Source (degrees, 64-bit floating-point data) D+3CH...
  • Page 480 3. Instructions DEGD Function Instruction Mnemonic Variations Function code Converts a double-precision (64-bit) floating-point DOUBLE RADIANS TO DEGD @DEGD number from radians to degrees and places the DEGREES result in the specified result words. DEGD DEGD(850) Symbol S: First source word D: First destination word Applicable Program Areas Function block...
  • Page 481 3. Instructions Function DEGD(850) converts the double-precision (64-bit) floating-point number in words S to S+3 from radians to degrees and places the result in words D to D+3. (The floating point source data must be in IEEE754 format.) S+3CH S+2CH S+1CH Source (degrees, 64-bit floating-point data) D+3CH...
  • Page 482 3. Instructions SIND/COSD/TAND Function Instruction Mnemonic Variations Function code Calculates the sine of a double-precision (64-bit) DOUBLE SINE SIND @SIND floating-point number (in radians) and places the result in the specified destination words. Calculates the cosine of a double-precision (64- DOUBLE COSINE COSD @COSD...
  • Page 483 3. Instructions Function  SIND SIND(851) calculates the sine of the angle (in radians) expressed as a double-precision (64-bit) floating-point value in words S to S+3 and places the result in words D to D+3. (The floating point source data must be in IEEE754 format.) ) →...
  • Page 484 3. Instructions • Specify the desired angle (-65,535 to 65,535) in radians in words S to S+3. For information on converting between degrees and radians, see 3-16-9 DOUBLE DEGREES TO RADIANS: RADD(849) or 3-16-10 DOUBLE RADIANS TO DEGREES: DEGD(850). • If the angle is outside of the range -65,535 to 65,535, an error will occur and the instruction will not be executed.
  • Page 485 3. Instructions ASIND/ACOSD/ATAND Function Instruction Mnemonic Variations Function code Calculates the arc sine of a double-precision (64- DOUBLE ARC SINE ASIND @ASIND bit) floating-point number and places the result in the specified destination words. Calculates the arc cosine of a double-precision DOUBLE ARC COSINE ACOSD @ACOSD...
  • Page 486 3. Instructions Function  ASIND ASIND(854) computes the angle (in radians) for a sine value expressed as a double-precision (64-bit) floating-point number in words S to S+3 and places the result in words D to D+3. (The floating point source data must be in IEEE754 format.) ) →...
  • Page 487 3. Instructions  ACOSD ACOSD(855) computes the angle (in radians) for a cosine value expressed as a double-precision (64- bit) floating-point number in words S to S+3 and places the result in words D to D+3. (The floating point source data must be in IEEE754 format.) ) →...
  • Page 488 3. Instructions SQRTD Function Instruction Mnemonic Variations Function code Calculates the square root of a double-precision DOUBLE SQUARE ROOT SQRTD @SQRTD (64-bit) floating-point number and places the result in the specified result words. SQRTD SQRTD(857) Symbol S: First source word D: First destination word Applicable Program Areas Function block...
  • Page 489 3. Instructions Function SQRTD(857) calculates the square root of the double-precision (64-bit) floating-point number in words S to S+3 and places the result in words D to D+3. (The floating point source data must be in IEEE754 format.) →  The following diagram shows the relationship between the input data and result. S: Input data R: Result CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 490 3. Instructions EXPD Function Instruction Mnemonic Variations Function code Calculates the natural (base e) exponential of a DOUBLE EXPONENT EXPD @EXPD double-precision (64-bit) floating-point number and places the result in the specified result words. EXPD EXPD(858) Symbol S: First source word D: First destination word Applicable Program Areas Function block...
  • Page 491 3. Instructions Function EXPD(858) calculates the natural (base e) exponential of the double-precision (64-bit) floating-point number in words S to S+3 and places the result in words D to D+3. In other words, EXP(467) calculates ex (x = source) and places the result in words D to D+3. →...
  • Page 492 3. Instructions LOGD Function Instruction Mnemonic Variations Function code Calculates the natural (base e) logarithm of a dou- ble-precision (64-bit) floating-point number and DOUBLE LOGARITHM LOGD @LOGD places the result in the specified destination words. LOGD LOGD(859) Symbol S: First source word D: First destination word Applicable Program Areas Function block...
  • Page 493 3. Instructions Function LOGD(859) calculates the natural (base e) logarithm of the double-precision (64-bit) floating-point number in words S to S+3 and places the result in words D to D+3. → • The constant e is 2.718282.  The following diagram shows the relationship between the input data and result. S: Input data R: Result CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 494 3. Instructions PWRD Function Instruction Mnemonic Variations Function code Raises a double-precision (64-bit) floating-point DOUBLE EXPONENTIAL PWRD @PWRD number to the power of another double-precision POWER (64-bit) floating-point number. PWRD PWRD(860) Symbol B: First base word E: First exponent word D: First destination word Applicable Program Areas Function block...
  • Page 495 3. Instructions Function PWRD(860) raises the double-precision (64-bit) floating-point number in words B to B+3 to the power of the double-precision (64-bit) floating-point number in words E to E+3. In other words, PWR(840) calculates XY (X = content of B to B+3; Y = content of E to E+3). Exponent data S2+3 S2+2...
  • Page 496 3. Instructions =D, <>D, D, >=D Function Instruction Mnemonic Variations Function code <>D These input comparison instructions compare two Double-precision Floating-point D dition when the comparison condition is true.
  • Page 497 3. Instructions Function input comparison instruction LD connection ON execution condition when compares the data specified in S1 and S2 comparison result is true. as double-precision floating point values
  • Page 498 3. Instructions Code Mnemonic Name Function LD>=D LOAD DOUBLE FLOATING GREATER THAN OR EQUAL True if C1 ≥ C2 AND>=D AND DOUBLE FLOATING GREATER THAN OR EQUAL OR>=D OR DOUBLE FLOATING GREATER THAN OR EQUAL Precautions Input comparison instructions cannot be used as right-hand instructions, i.e., another instruction must be used between them and the right bus bar.
  • Page 499: Table Data Processing Instructions

    3. Instructions Table Data Processing Instructions Table Data Processing Instructions All of these instructions define or operate on a group of words. The group of words in a stack are defined by SSET(630), the group of words in a record-table are defined by DIM(631), and the group of words used in a range instruction are defined independently in each instruction.
  • Page 500 3. Instructions  FIFO(633) Reads first (oldest) word of data that was stored in the stack, shifts the remaining data down one word, and decrements the pointer by one. Stack Stack Pointer to last word in stack Pointer Data region Data region Pointer Pointer...
  • Page 501 3. Instructions  SREAD(639) Reads the data from the specified data element in the stack. The offset value indicates the location of the desired word (the number of words before the current pointer position). Stack Stack Pointer to last word in stack Pointer (n=3) Data region...
  • Page 502 3. Instructions  SINS(641) Inserts the source data at the specified location in the stack and shifts the rest of the data in the stack downward. The offset value indicates the location of the desired word (the number of words before the current pointer position).
  • Page 503 3. Instructions  SNUM(638) Counts the amount of stack data (number of words of data) from the stack pointer to the beginning of the data region. Stack Stack Pointer to last Pointer to last word in stack word in stack Pointer Pointer Data...
  • Page 504 3. Instructions SSET Function Instruction Mnemonic Variations Function code Defines a stack of the specified length beginning SET STACK SSET @SSET at the specified word. SSET SSET(630) Symbol TB: First stack address N: Number of words Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 505 3. Instructions Flags Name Label Operation Error Flag • ON if N is not within the specified range of 0005 to FFFF. • OFF in all other cases. Note The minimum value for the number of words in the stack (N) is 5 because N includes the four words that contain the pointer to the last word in the stack and the stack pointer.
  • Page 506 3. Instructions Example Programming When CIO 0.00 is ON in the following example, SSET(630) secures a 10-word stack from D0 to D9. D0 and D1 contain the PLC memory address of the last word in the stack. D2 and D3 contain the stack pointer.
  • Page 507 3. Instructions PUSH Function Instruction Mnemonic Variations Function code PUSH ONTO STACK PUSH @PUSH Writes one word of data to the specified stack. PUSH PUSH(632) Symbol TB: First stack address S: Source word Applicable Program Areas Function block SFC action or Area Block program areas Step program areas...
  • Page 508 3. Instructions Flags Name Label Operation Error Flag • ON if the address specified by the stack pointer (TB+3 and TB+2) exceeds the last word in the stack. (This is a stack overflow error.) • OFF in all other cases. Function PUSH(632) writes the content of S to the address indicated by the stack pointer (TB+3 and TB+2) and increments the stack pointer by one.
  • Page 509 3. Instructions LIFO/FIFO Function Instruction Mnemonic Variations Function code Reads the last word of data written to the specified LAST IN FIRST OUT LIFO @LIFO stack (the newest data in the stack). Reads the first word of data written to the speci- FIRST IN FIRST OUT FIFO @FIFO...
  • Page 510 3. Instructions Flags Name Label Operation Error Flag • ON if the contents of the stack pointer (TB+3 and TB+2) is less than or equal to the PLC memory address of first word in the data region of the stack (TB+4). (This is a stack underflow error.) •...
  • Page 511 3. Instructions Example Programming  LIFO When CIO 0.00 is ON in the following example, LIFO(634) reads the content of the word indicated by the stack pointer (D6) and writes that data to D300. 0.00 D300 PC memory address of last word in stack Stack pointer Stack pointer...
  • Page 512 3. Instructions  FIFO When CIO 0.00 is ON in the following example, FIFO(633) reads the content of D4 (TB+4 for the stack beginning at D0) and writes that data to D300. 0.00 D300 PC memory address of last word in stack Stack pointer Stack Last word...
  • Page 513 3. Instructions SNUM Function Instruction Mnemonic Variations Function code Counts the amount of stack data (number of STACK SIZE READ SNUM @SNUM words) in the specified stack. SNUM SNUM(638) Symbol TB: First stack address D: Destination word Applicable Program Areas Function block SFC action or Area...
  • Page 514 3. Instructions Flags Name Label Operation Error Flag P_ER Equal Flag P_EQ • ON if the number of words of data in the stack (the value output to D) is 0. • OFF in all other cases. Function SNUM(638) counts the number of data words in the specified stack from the beginning of the data region at TB+4 to the address before the one indicated by the stack pointer (TB+3 and TB+2).
  • Page 515 3. Instructions SREAD Function Instruction Mnemonic Variations Function code Reads the data from the specified data element in the stack. The offset value indicates the location STACK DATA READ SREAD @SREAD of the desired data element (how many data ele- ments before the current pointer position).
  • Page 516 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON if the specified read location is not within the stack area. •...
  • Page 517 3. Instructions Example Programming When CIO 0.00 is ON in the following example, SREAD(639) reads the data in the specified word in the stack starting at D0 and outputs the data to D100. In this case, the stack pointer indicates D7 and the offset value is 3, so the data is read from D4.
  • Page 518 3. Instructions SWRIT Function Instruction Mnemonic Variations Function code Writes the source data to the specified data ele- ment in the stack (overwriting the existing data). STACK DATA OVERWRITE SWRIT @SWRIT The offset value indicates the location of the desired data element (how many data elements before the current pointer position).
  • Page 519 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON if the specified write location is not within the stack area. •...
  • Page 520 3. Instructions Example Programming When CIO 0.00 is ON in the following example, SWRIT(640) writes the data in D100 to the specified word in the stack starting at D0. In this case, the stack pointer indicates D7 and the offset value is 3, so the data in D4 is overwritten.
  • Page 521 3. Instructions SINS Function Instruction Mnemonic Variations Function code Inserts the source data at the specified location in the stack and shifts the rest of the data in the STACK DATA INSERT SINS @SINS stack downward. The offset value indicates the location of the desired data element (how many data elements before the current pointer position).
  • Page 522 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON if the address indicated by the stack pointer (TB+3 and TB+2) is greater than the PLC memory address of last word in the data region of the stack.
  • Page 523 3. Instructions Example Programming When CIO 0.00 is ON in the following example, SINS(641) inserts the source data in D100 at the specified address in the stack starting at D0. In this case, the stack pointer indicates D7 and the offset value is 3, so the source data is inserted in D4.
  • Page 524 3. Instructions SDEL Function Instruction Mnemonic Variations Function code Deletes the data element at the specified location in the stack, outputs that data to the specified des- tination word, and shifts the remaining the data in STACK DATA DELETE SDEL @SDEL the stack upward.
  • Page 525 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON if the content of the stack pointer (TB+3 and TB+2) is less than or equal to the PLC memory address of first word in the data region of the stack (TB+4).
  • Page 526 3. Instructions Example Programming In this case, the stack pointer indicates D7 and the offset value is 3, so the data is deleted from D4. The remaining data is shifted up one word and the stack pointer is decremented from D7 to D6. 0.00 SDEL &3...
  • Page 527 3. Instructions Function Instruction Mnemonic Variations Function code Defines the specified I/O memory area as a record table by declaring the length of each record and DIMENSION RECORD TABLE @DIM the number of records. Up to 16 record tables can be defined.
  • Page 528 3. Instructions Function DIM(631) registers the words from TB to TB+LR×NR-1 as table number N. Table number N has NR records and each record is LR words long. The data within this region cannot be changed once the region has been declared as records. Records in a registered table are identified by their record numbers, which range from 0 to NR-1.
  • Page 529 3. Instructions SETR Function Instruction Mnemonic Variations Function code Writes the location of the specified record (the SET RECORD LOCATION SETR @SETR PLC memory address of the beginning of the record) in the specified Index Register. SETR SETR(635) N: Table number Symbol R: Record number D: Destination Index Register...
  • Page 530 3. Instructions Function SETR(635) stores the PLC memory address of the first word of the specified record in the specified Index Register. Table number (N) PC memory address SETR(635) writes the PC memory address (m) of the first word of record R to Index Register D. Record number (R) Note...
  • Page 531 3. Instructions GETR Function Instruction Mnemonic Variations Function code Returns the record number of the record at the GET RECORD NUMBER GETR @GETR PLC memory address contained in the specified Index Register. GETR GETR(636) N: Table number Symbol IR: Index Register D: Destination word Applicable Program Areas Function block...
  • Page 532 3. Instructions Function GETR(636) finds which record includes the PLC memory address contained in the specified Index Register and writes that record number in D. The PLC memory address contained in the Index Register does not have to be the first word in the record; it can be any word in the record. PC memory Table number (N) address...
  • Page 533 3. Instructions SRCH Function Instruction Mnemonic Variations Function code Searches for a word of data within a range of DATA SEARCH SRCH @SRCH words. SRCH SRCH(181) C: First control word Symbol R1: First word in range Cd: Comparison data Applicable Program Areas Function block SFC action or Area...
  • Page 534 3. Instructions Flags Name Label Operation Error Flag • ON if the content of C is not within the specified range of 0001 through FFFF. • ON if the Communications Port Enabled Flag for the communications port number specified as the Com Port number for Background Execution is OFF when background processing is specified.
  • Page 535 3. Instructions Example Programming When CIO 0.00 is ON in the following example, SRCH(181) searches the 10-word range beginning at D100 for words that have the same content as D200. The PLC memory address of the first word containing a match is written to IR0 and the total number of matches is written to DR0. 0.00 PC memory address...
  • Page 536 3. Instructions SWAP Function Instruction Mnemonic Variations Function code Switches the leftmost and rightmost bytes in all of SWAP BYTES SWAP @SWAP the words in the range. SWAP SWAP(637) Symbol N: Number of words R1: First word in range Applicable Program Areas Function block SFC action or Area...
  • Page 537 3. Instructions Function SWAP(637) switches the position of the two Byte position is swapped. bytes in all of the words in the range of memory from R1 to R1+N-1. Hint • This instruction can be used to reverse the order of ASCII-code characters in each word. •...
  • Page 538 3. Instructions MAX/MIN Function Instruction Mnemonic Variations Function code FIND MAXIMUM @MAX Finds the maximum value in the range. FIND MINIMUM @MIN Finds the minimum value in the range. MAX(182) MIN(183) C: First control word Symbol C: First control word R1: First word in range R1: First word in range D: Destination word...
  • Page 539 3. Instructions Flags Operation Name Label Error Flag • ON if the content of C is not within the specified range of 0001 through FFFF. • ON if the Communications Port Enabled Flag for the communications port number specified as the Com Port number for Background Execution is OFF when background processing is specified.
  • Page 540 3. Instructions Hint • When bit 15 of C+1 has been set to 1, the data within the range is treated as signed binary data and hexadecimal values 8000 to FFFF are considered negative. Thus, the results of the search will differ depending on the data-type setting.
  • Page 541 3. Instructions  MIN When CIO 0.00 turns ON in the following example, MIN(183) searches the 10-word range beginning at D200 for the minimum value. The minimum value is written to D300 and the PLC memory address of the word containing the minimum value is written to IR0. 0.00 D100 D200...
  • Page 542 3. Instructions MAXL Function Instruction Mnemonic Variations Function code Treats the specified number of data items as dou- DOUBLE FIND MAXIMUM MAXL @MAXL ble word table data and outputs the maximum value in the table. MAXL MAXL C: First control word Symbol R1: First word in range D: First destination word...
  • Page 543 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the length of the table specified in C (bits 00 to 15) is not between 0001 and FFFF hex. • OFF in all other cases. Equals Flag P_EQ •...
  • Page 544 3. Instructions  Background Processing The execution time of MAXL will increase proportionately to the size of the table data. Background processing can be used for MAXL to suppress variations in the cycle time of the CPU Unit when the table data is too large.
  • Page 545 3. Instructions MAXF Function Instruction Mnemonic Variations Function code Treats the specified number of data items as a FIND MAXIMUM FLOATING MAXF @MAXF table of single-precision floating-point data and outputs the maximum value in the table. MAXF MAXF C: First control word Symbol R1: First word in range D: First destination word...
  • Page 546 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the length of the table specified in C (bits 00 to 15) is not between 0001 and FFFF hex. • ON if the table data is nonnumeric. • OFF in all other cases. Equals Flag P_EQ •...
  • Page 547 3. Instructions MAXD Function Instruction Mnemonic Variations Function code Treats the specified number of data items as a FIND DOUBLE MAXIMUM MAXD @MAXD table of double-precision floating-point data and FLOATING outputs the maximum value in the table. MAXD MAXD C: First control word Symbol R1: First word in range D: First destination word...
  • Page 548 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the length of the table specified in C (bits 00 to 15) is not between 0001 and FFFF hex. • ON if the table data is nonnumeric. • OFF in all other cases. Equals Flag P_EQ •...
  • Page 549 3. Instructions MINL Function Instruction Mnemonic Variations Function code Treats the specified number of data items as dou- DOUBLE FIND MINIMUM MINL @MINL ble word table data and outputs the minimum value in the table. MINL MINL C: First control word Symbol R1: First word in range D: First destination word...
  • Page 550 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the length of the table specified in C (bits 00 to 15) is not between 0001 and FFFF hex. • OFF in all other cases. Equals Flag P_EQ •...
  • Page 551 3. Instructions MINF Function Instruction Mnemonic Variations Function code Treats the specified number of data items as a FIND MINIMUM FLOATING MINF @MINF table of single-precision floating-point data and outputs the minimum value in the table. MINF MINF C: First control word Symbol R1: First word in range D: First destination word...
  • Page 552 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the length of the table specified in C (bits 00 to 15) is not between 0001 and FFFF hex. • ON if the table data is nonnumeric. • OFF in all other cases. Equals Flag P_EQ •...
  • Page 553 3. Instructions MIND Function Instruction Mnemonic Variations Function code Treats the specified number of data items as a FIND DOUBLE MINIMUM MIND @MIND table of double-precision floating-point data and FLOATING outputs the minimum value in the table. MIND MIND C: First control word Symbol R1: First word in range D: First destination word...
  • Page 554 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the length of the table specified in C (bits 00 to 15) is not between 0001 and FFFF hex. • ON if the table data is nonnumeric. • OFF in all other cases. Equals Flag P_EQ •...
  • Page 555 3. Instructions Function Instruction Mnemonic Variations Function code Adds the bytes or words in the range and outputs @SUM the result to two words. SUM(184) C: First control word Symbol R1: First word in range D: First destination word Applicable Program Areas Function block SFC action or Area...
  • Page 556 3. Instructions Flags Name Label Operation Error Flag • ON if the content of C is not within the specified range of 0001 through FFFF. • ON if the BCD data has been specified, but the range contains binary data. •...
  • Page 557 3. Instructions Example Programming When CIO 0.00 is ON in the following example, SUM(184) adds 10 bytes of unsigned binary data beginning with the rightmost byte of D100 and writes the result to D201 and D200. 0.00 Number of words/bytes D300 D100 C+1: D301...
  • Page 558 3. Instructions Function Instruction Mnemonic Variations Function code Calculates the FCS value for the specified range FRAME CHECKSUM @FCS and outputs the result in ASCII. FCS(180) C: First control word Symbol R1: First word in range D: First destination word Applicable Program Areas Function block SFC action or...
  • Page 559 3. Instructions Flags Name Label Operation Error Flag • ON if the content of C is not within the specified range of 0001 through FFFF. • ON if the Communications Port Enabled Flag for the communications port number specified as the Com Port number for Background Execution is OFF when background processing is specified.
  • Page 560 3. Instructions Example Programming When CIO 0.00 is ON in the following example, FCS(180) calculates the FCS value for the 10 bytes of data beginning with the rightmost byte of D100 and writes the result to D200. 0.00 D300 D100 C+1: D301 D200 Always 0.
  • Page 561: Tracking Instructions

    3. Instructions Tracking Instructions Tracking Instructions Manufacturing information on workpieces placed into a production line is generally called tracking data. Tracking data includes many pieces of information, such as the product type, model, quantity, manufacturing date, product grade, and manufacturing factory. Each group of information is called a record.
  • Page 562 3. Instructions  Finding Tracking Data That Matches Certain Conditions The table of tracking data is searched for shelf number 0006 hex and the data is stored in another location. First word of first record D1000 Record length Number of records First word of search results D100 Search key...
  • Page 563 3. Instructions 0 0 0 8 Number of records = 8 C: D0 Record length = 5 words 0 0 0 5 C+1: D1 Search data offset = 2 words 0 0 0 2 C+2: D2 Index register output designation: Output 8 0 0 1 C+3: D3 Search method = Linear, Setting to end search = Effective end data...
  • Page 564 3. Instructions  Sorting and Then Searching Tracking Data The tracking data table is sorted according to the delivery code and then the data is searched for delivery code A200 0038 hex. First word of first record D1000 Record length Number of records First word of sorting results D200...
  • Page 565 3. Instructions RSORT2 C: D300 0 0 0 8 Number of records = 8 C+1: D301 0 0 0 5 Record length = 5 words C+2: D302 0 0 0 3 Sorting data offset = 3 words C+3: D303 0 0 0 0 Split sort setting = Disabled, Ascending C+4: D304 8 0 0 1...
  • Page 566 3. Instructions Sorting Tracking Data That Contains Many Records Using a Split Sort Tracking data that contains 2,048 records is sorted according to the delivery code. To shorten the cycle time, the sort is executed over multiple cycles. First word of first record D1000 Record length Number of records...
  • Page 567 3. Instructions Number of records = 2,048 C: D300 2 0 4 8 Record length = 5 words C+1: D301 0 0 0 5 Sorting data offset = 3 words C+2: D302 0 0 0 3 Split sort setting = Enabled, Ascending C+3: D303 8 0 0 0 Index register output designation = Disabled, Setting to end sort = Disabled...
  • Page 568 3. Instructions RSRCH<, RSRCH<=, RSRCH=, RSRCH>, RSRCH>= Function Instruction Mnemonic Variations Function code RSRCH< @RSRCH< An Unsigned One-word Record Search Instruction RSRCH<= @RSRCH<= searches the specified table of records for a record Unsigned One-word Record RSRCH= @RSRCH= with the specific data (1 word) in the specified location. Search Instructions RSRCH>...
  • Page 569 3. Instructions C: First control word Number of records: 1 to 32768 decimal (maximum: 32,768) Record length (in words): 1 to 1024 decimal (maximum: 1,024) Search data offset (in words): 0 to 1023 decimal 15 14 0 0 0 0 0 0 0 Setting to end search Always 0.
  • Page 570 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON when the record length in C+1 is not between 1 and 1,024, inclusive. •...
  • Page 571 3. Instructions  Searching with the Setting to End the Search Disabled The search is performed for the number of records specified in C. Search data (S2) First word of first record (S1) Record 0 Search data Search data offset (C+2) Searched data Record length (C+1) Record 1...
  • Page 572 3. Instructions  Searching with End Data Enabled to End the Search If the setting to end the search is enabled in C+3 for end data, records will be searched until the record just before the record in which the end data specified in C+4 is found. If the end data is not found, the number of records specified in C will be searched.
  • Page 573 3. Instructions  Searching with End PLC Memory Address Enabled to End the Search If the setting to end the search is enabled in C+3 for a PLC memory address, records will be searched until the PLC memory address specified in C+4 and C+5. No records past the end PLC memory address will be searched.
  • Page 574 3. Instructions RSRCH2<, RSRCH2<=, RSRCH2=, RSRCH2>, RSRCH2>= Function Instruction Mnemonic Variations Function code RSRCH2< @RSRCH2< An Unsigned Two-word Record Search Instruction RSRCH2<= @RSRCH2<= searches the specified table of records for a record with Unsigned Two-word Record RSRCH2= @RSRCH2= the specific data (2 words) in the specified location. Search Instructions RSRCH2>...
  • Page 575 3. Instructions C: First control word Number of records: 1 to 16384 decimal (maximum: 16,384) Record length (in words): 2 to 1024 decimal (maximum: 1,024) Search data offset (in words): 0 to 1022 decimal 15 14 0 0 0 0 0 0 0 Setting to end search Always 0.
  • Page 576 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON when the record length in C+1 is not between 2 and 1,024, inclusive. •...
  • Page 577 3. Instructions RSRCH4<, RSRCH4<=, RSRCH4=, RSRCH4>, RSRCH4>= Function Instruction Mnemonic Variations Function code RSRCH4< @RSRCH4< An Unsigned Four-word Record Search Instruction RSRCH4<= @RSRCH4<= searches the specified table of records for a record with Unsigned Four-word RSRCH4= @RSRCH4= the specific data (4 words) in the specified location. Record Search Instructions RSRCH4>...
  • Page 578 3. Instructions C: First control word Number of records: 1 to 8192 decimal (maximum: 8,192) Setting to End Search Disabled C+4: Always 0. C+5: Always 0. Record length (in words): C+6: Always 0. 4 to 1024 decimal (maximum: 1,024) C+7: Always 0. End Data Enabled C+4 to C+7: End data (0000 0000 0000 0000 to FFFF FFFF FFFF FFFF hex)
  • Page 579 3. Instructions Flags Name Label Operation Error Flag P_ER • ON when the record length in C+1 is not between 4 and 1,024, inclusive. • ON when the number of records specified in C times the record length in C+1 is greater than 32,768.
  • Page 580 3. Instructions RSORT Function Instruction Mnemonic Variations Function code Sorts the records in the specified table according UNSIGNED ONE-WORD RSORT @RSORT to the data (1 word) at the specified position in the RECORD SORT records. RSORT RSORT(203) C: First control word Symbol S: First word of first record to sort D1: First word of sorting results...
  • Page 581 3. Instructions 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 C+7 to C+86 System word area Searching with the Setting to End the Sort Disabled Always clear C+7 to 0 before C+5: Always 0. starting to sort records.
  • Page 582 3. Instructions  Sorting with the Setting to End Sorting Disabled The sort operation is performed for the number of records specified in C. First word in table (S1) Example for 4 records sorted in Control data (C+3) ascending order using a split sort Sort data offset (C+2) Record 0 Item used...
  • Page 583 3. Instructions  Searching with End PLC Memory Address Enabled to End the Search If the setting to end the search is enabled in C+3 for a PLC memory address, records will be searched until the PLC memory address specified in C+4 and C+5. No records past the end PLC memory address will be searched.
  • Page 584 3. Instructions RSORT2 Function Instruction Mnemonic Variations Function code Sorts the records in the specified table according UNSIGNED TWO-WORD RSORT2 @RSORT2 to the data (2 words) at the specified position in RECORD SORT the records. RSORT2 RSORT2(204) C: First control word Symbol S: First word of first record to sort D1: First word of sorting results...
  • Page 585 3. Instructions C: First control word Number of records: 1 to 16384 decimal (maximum: 16,384) Record length (in words): 2 to 1024 decimal (maximum: 1,024) Sort data offset (in words): 0 to 1022 decimal 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Always 0.
  • Page 586 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON when the record length in C+1 is not between 2 and 1,024, inclusive. •...
  • Page 587 3. Instructions RSORT4 Function Instruction Mnemonic Variations Function code Sorts the records in the specified table according UNSIGNED FOUR-WORD RSORT4 @RSORT4 to the data (4 words) at the specified position in RECORD SORT the records. RSORT4 RSORT4(205) C: First control word Symbol S: First word of first record to sort D1: First word of sorting results...
  • Page 588 3. Instructions C: First control word Number of records: 1 to 8192 decimal (maximum: 8,192) Record length (in words): 4 to 1024 decimal (maximum: 1,024) Sort data offset (in words): 0 to 1020 decimal 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Always 0.
  • Page 589 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON when the record length in C+1 is not between 4 and 1,024, inclusive. •...
  • Page 590: Data Control Instructions

    3. Instructions Data Control Instructions Function Instruction Mnemonic Variations Function code Executes PID control according to the specified PID CONTROL parameters. PID(190) S: Input word Symbol C: First parameter word D: Output word Applicable Program Areas Function block SFC action or Area Block program areas Step program areas...
  • Page 591 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag • ON if the C data is out of range. • ON if the actual sampling period is more than twice the designated sampling period. •...
  • Page 592 3. Instructions • For proportional operation only, the manipulated variable output when the PV equals the SV can be designated as follows: 0: Output 0% 1: Output 50%. • The direction of proportional operation can be designated as either forward or reverse. •...
  • Page 593 3. Instructions Block Diagram for Target Value PID with Two Degrees of Freedom When overshooting is prevented with simple PID control, stabilization of disturbances is slowed (1). If stabilization of disturbances is speeded up, on the other hand, overshooting occurs and response toward the target value is slowed (2).
  • Page 594 3. Instructions PID Parameter Settings Change with ON Control data Item Contents Setting range input condition Set value (SV) The target value of the process being Binary data (of the same number of bits as Allowed controlled. specified for the input range) Proportional band The parameter for P action expressing the 0001 to 270F hex (1 to 9999);...
  • Page 595 3. Instructions Note 1 When the unit is designated as 1, the range is from 1 to 8,191 times the period. When the unit is designated as 9, the range is from 0.1 to 819.1 s. When 9 is designated, set the integral and derivative times to within a range of 1 to 8,191 times the sampling period.
  • Page 596 3. Instructions PID control  Proportional Action (P) Proportional action is an operation in which a proportional band is established with respect to the set value (SV), and within that band the manipulated variable (MV) is made proportional to the deviation. An example for reverse operation is shown in the following illustration.
  • Page 597 3. Instructions  Derivative Action (D) Proportional action and integral action both make corrections with respect to the control results, so there is inevitably a response delay. Derivative action compensates for that drawback. In response to a sudden disturbance it delivers a large manipulated variable and rapidly restores the original status. A correction is executed with the manipulated variable made proportional to the incline (derivative coefficient) caused by the deviation.
  • Page 598 3. Instructions Direction of Action When using PID control, select either of the following two control directions. In either direction, the MV increases as the difference between the SV and the PV increases. • Forward action: MV is increased when the PV is larger than the SV. •...
  • Page 599 3. Instructions Hint • The setting in bit 1 of C+5 is supported only by CJ2, CJ1, CS1-H, CJ1-H CPU Units and CS1 CPU Units with lot numbers of 001201@@@@ or later (manufactured December 1, 2000 or later). • The number of valid input data bits for the measured value is designated by the input range setting in C+6, bits 08 to 11, and the number of valid output data bits for the manipulated variable output is designated by the output range setting in C+6, bits 0 to 3.
  • Page 600 3. Instructions Precautions • If PID(190) is used between IL(002) and ILC(003), between JMP(004) and JME(005), or in a subroutine, operation will not be consistent depending on the input condition. • Within the PID parameters (C to C+38), the only value that can be changed while the input condition is ON is the set value for C.
  • Page 601 3. Instructions PIDAT Function Instruction Mnemonic Variations Function code PID CONTROL WITH Executes PID control according to the specified PIDAT AUTOTUNING parameters. The PID constants can be autotuned. PIDAT(191) PID(190) S: Input word S: Input word Symbol C: First parameter word C: First parameter word D: Output word D: Output word...
  • Page 602 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON if the C data is out of range. • ON if the actual sampling period is more than twice the designated sampling period. •...
  • Page 603 3. Instructions • If the AT Command Bit is turned ON during PIDAT(191) execution, PIDAT(191) interrupts the PID control being performed with the user-set PID constants, performs autotuning, and then resumes PID control with the calculated PID constants. The following flowchart shows the autotuning procedure: The AT Command Bit (bit 15 of C+9) is ON at the start of PIDAT(191) execution or it is turned ON during execution.
  • Page 604 3. Instructions • Integral constant (Tik) = &9999 (no integral operation) if the integral constant (Tik) is less than 1 as a result of AT execution with integral and derivative unit = "1: Sampling period multiple". Likewise, differential constant (Tdk) = 0 (no derivative operation) if the derivative constant (Tdk) is less than 1 as a result of AT execution with integral and derivative unit = "1: Sampling period multiple".
  • Page 605 3. Instructions Control Change with ON Item Contents Setting range data input condition Sampling period (τ) Sets the period for executing the PID action. 0001 to 270F hex (1 to 9999); Not allowed (0.01 to 99.99 s, in units of 10 ms) Bits 04 to 15 2-PID parameter (α) The input filter coefficient.
  • Page 606 3. Instructions Note 1 When the unit is designated as 1, the range is from 1 to 8,191 times the period. When the unit is designated as 9, the range is from 0.1 to 819.1 s. When 9 is designated, set the integral and derivative times to within a range of 1 to 8,191 times the sampling period.
  • Page 607 3. Instructions Calculated PID PID control starts. constants are set. CIO 0.00 PID control AT executing PID control W0.00 Bit 15 of D209 Time Time CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 608 3. Instructions  Starting PIDAT(191) with Autotuning At the rising edge of CIO 0.00 (OFF to ON), autotuning will be performed first if bit 0.00 15 of D209 (C+9) is ON. When autotuning is completed, the calculated P, I, and D constants are written to C+1, C+2, and C+3.
  • Page 609 3. Instructions Function Instruction Mnemonic Variations Function code Controls output data according to whether or not LIMIT CONTROL @LMT input data is within upper and lower limits. LMT(680) S: Input word Symbol C: First limit word D: Output word Applicable Program Areas Function block SFC action or Area...
  • Page 610 3. Instructions Function When the execution condition is ON, LMT(680) controls output data according to whether or not the specified input data (signed 16-bit binary) is within the upper and lower limits. If the input data (S) is less than the lower limit (C), the lower limit data will be output to D and the Less Than Flag will turn ON.
  • Page 611 3. Instructions BAND Function Instruction Mnemonic Variations Function code Controls output data according to whether or not DEAD BAND CONTROL BAND @BAND input data is within the lower and upper limits of the range (dead band range.) BAND BAND(681) S: Input word Symbol C: First limit word D: Output word...
  • Page 612 3. Instructions Flags Name Label Operation Error Flag • ON if the upper limit is less than the lower limit. • OFF in all other cases. Greater Than Flag > • ON if the input data (S) is greater than the upper limit. •...
  • Page 613 3. Instructions Example Programming If D100 is 00B4 hex (180), then 180–200=FFEC hex (–20) will be output to D300 because 180 is less than the lower limit of 200. If D100 is 00E6 hex (230), then 0 will be output to D300 because 230 is within the upper and lower limits.
  • Page 614 3. Instructions ZONE Function Instruction Mnemonic Variations Function code Adds the specified bias to input data and outputs DEAD ZONE CONTROL ZONE @ZONE the result. ZONE ZONE(682) S: Input word Symbol C: First limit word D: Output word Applicable Program Areas Function block SFC action or Area...
  • Page 615 3. Instructions Function When the execution condition is ON, ZONE(682) adds the specified bias to the specified input data (signed 16-bit binary) and places the result in a specified word. If the input data (S) is less than zero, the input data plus the negative bias will be output to D and the Less Than Flag will turn ON.
  • Page 616 3. Instructions Function Instruction Mnemonic Variations Function code Inputs the duty ratio or manipulated variable from the specified word, converts the duty ratio to a TIME-PROPORTIONAL time-proportional output based on the specified OUTPUT parameters, and outputs the result from the speci- fied output.
  • Page 617 3. Instructions R: Pulse Output Bit Specifies the destination output bit for the pulse output. Normally, specify an output bit allocated to a Transistor Output Unit and connect a solid state relay to the Transistor Output Unit.  Operand Specifications Indirect DM/EM Word addresses Registers...
  • Page 618 3. Instructions In this case, set the same value for the PID Control instruction’s output range and the TPO(685) instruction’s manipulated variable range. For example, when the PID Control instruction’s output range and the TPO(685) instruction’s manipulated variable range are both set to 12 bits (0000 to 0FFF hex), the duty ratio is calculated by dividing the manipulated variable from the PID Control instruction by 0FFF hex and TPO(685) converts that duty ratio to a time-proportional output.
  • Page 619 3. Instructions • The output (R) is turned ON/OFF when the instruction is executed and the accuracy of the output’s ON/OFF timing is 10 ms max. • Execution of the instruction stops when the input condition goes OFF. At that time, the elapsed time value will be reset and the control period will be initialized.
  • Page 620 3. Instructions • Input time setting = 2 (Use higher value.) Control period (a) Control period (a) 100% 70% target is kept. Duty ratio (MV/MV range) 70% target raised to 80%. a × a × 0.45 s a × 0.55 s a ×...
  • Page 621 3. Instructions Precautions When using TPO(685) in combination with PID(190) in a cyclic task and also using an interrupt task, temporarily disable interrupts by executing DI(693) (DISABLE INTERRUPTS) ahead PID(190) and TPO(685). If interrupts are not disabled and an interrupt occurs between the PID(190) and TPO(685), the control period may be shifted.
  • Page 622 3. Instructions  Using TPO(685) Alone When CIO 0.00 is ON, TPO(685) takes the duty ratio in D10, converts the duty ratio to a time- proportional output, and outputs the pulses to CIO 100. In this case, the control period is 1 s and the output limit function is enabled with a lower limit 20.00% and an upper limit of 80.00%.
  • Page 623 3. Instructions Function Instruction Mnemonic Variations Function code Converts unsigned binary data into unsigned BCD SCALING @SCL data according to the specified linear function. SCL(194) S: Source word Symbol P1: First parameter word R: Result word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 624 3. Instructions Flags Name Label Operation Error Flag • ON if the contents of C (Ar) or C+1 (Br) is not BCD. • ON if the contents of C+1 (As) and C+3 (Bs) are equal. • OFF in all other cases. Equals Flag •...
  • Page 625 3. Instructions Example Programming In the following example, it is assume that an analog signal from 1 to 5 V is converted and input to D0 as 0000 to 0FA0 hexadecimal. SCL(194) is used to convert (scale) the value in CIO 200 to a value between 0 and 300 BCD.
  • Page 626 3. Instructions In this example, values from 0000 to 00C8 hexadecimal will be converted to negative values. SCL(194), however, can output only unsigned BCD values from 0000 to 9999, so 0000 BCD will be output whenever the contents of D0.00 is between 0000 and 00C8 hexadecimal. Reverse Scaling Reverse scaling can also be used by setting As <...
  • Page 627 3. Instructions SCL2 Function Instruction Mnemonic Variations Function code Converts signed binary data into signed BCD data SCALING 2 SCL2 @SCL2 according to the specified linear function. An offset can be input in defining the linear function. SCL2 SCL2(486) S: Source word Symbol P1: First parameter word R: Result word...
  • Page 628 3. Instructions Flags Name Label Operation Error Flag • ON if the contents of C+1 (ΔX) is 0000. • ON if the contents of C+2 (ΔY) is not BCD. • OFF in all other cases. Equals Flag • ON if the result is 0. •...
  • Page 629 3. Instructions Hint • SCL2(486) can be used to scale the results of analog signal conversion values from Analog Input Units according to user-defined scale parameters. For example, if a 1 to 5-V input to an Analog Input Unit is input to memory as 0000 to 0FA0 hexadecimal, the value in memory can be scaled to –100 to 200°C using SCL2(486).
  • Page 630 3. Instructions  Scaling 1 to 5-V Analog Input to –200 to 200 In the following example, it is assume that an analog signal from 1 to 5 V is converted and input to CIO 2005 as 0000 to 0FA0 hexadecimal. SCL2(486) is used to convert (scale) the value in CIO 2005 to a value between –0200 and 0200 BCD.
  • Page 631 3. Instructions SCL3 Function Instruction Mnemonic Variations Function code Converts signed BCD data into signed binary data SCALING 3 SCL3 @SCL3 according to the specified linear function. An offset can be input in defining the linear function. SCL3 SCL3(487) S: Source word Symbol P1: First parameter word R: Result word...
  • Page 632 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag • ON if the contents of S is not BCD. • ON if the contents of C+1 (ΔX) is not between 0001 and 9999 BCD. •...
  • Page 633 3. Instructions Positive Offset Negative Offset R (signed binary) R (signed binary) Max conversion Max conversion ΔY ΔY ΔX ΔX S (signed BCD) Offset Offset Min. conversion S (signed BCD) Min. conversion Offset of 0000 R (signed binary) Max conversion ΔY ΔX S (signed BCD)
  • Page 634 3. Instructions Function Instruction Mnemonic Variations Function code Calculates the average value of an input word for AVERAGE the specified number of cycles. AVG(195) S: Source word Symbol N: Number of cycles R: Result first word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 635 3. Instructions Function For the first N–1 cycles when the execution S: Source word condition is ON, AVG(195) writes the values of S in order to words starting with R+2. The Previous Value Pointer (bits 00 to 07 of R+1) is incremented each time a value is written.
  • Page 636 3. Instructions S: D100 0.00 D100 D200 N: D200 (10 times) R: CIO 300 R+1: CIO 301 Pointer Average Valid Flag Average R+2: CIO 302 R+3: CIO 303 R+11: CIO 311 • In the following example, the content of CIO 40 is set to #0000 and then incremented by 1 each cycle.
  • Page 637: Subroutines

    3. Instructions Subroutines Subroutine instruction In the CS/CJ Series, function blocks and subroutines can be used as a means of structuring programs. The advantages and disadvantages of each are as follows:  Differences between function blocks and subroutines Function blocks Subroutines Unit versions of CPU CS1-H, CJ1-H, CJ1M CPU Units: Unit version 3.0 or later...
  • Page 638 3. Instructions Function Instruction Mnemonic Variations Function code Calls the subroutine with the specified subroutine SUBROUTINE CALL @SBS number and executes that program. Symbol SBS(091) N: Subroutine number Applicable Program Areas Function block SFC action or transition Area Block program areas Step program areas Subroutines Interrupt tasks...
  • Page 639 3. Instructions Function SBS(091) calls the subroutine with the Execution condition ON specified subroutine number. subroutine program section between SBN(092) and RET(093). When the subroutine is completed, program Main program execution continues with next instruction after SBS(091). A subroutine can be called more than once in a program.
  • Page 640 3. Instructions Precautions • The subroutine number must be unique for each subroutine. You cannot use the same number for more than one 0.00 subroutine. • Each subroutine must have a unique 0.01 subroutine number. Do not use the same subroutine number for more than one subroutine.
  • Page 641 3. Instructions Example Programming  Sequential (Non-nested) Subroutines CIO 0.00 ON 0.00 Main program CIO 0.01 ON 0.01 0.00 0.01 Order of execution A→S1→ B→S2→C A→S1→ B→C A→B→ S2→C A→B→ Subroutines Program end When CIO 0.00 is ON in the following example, subroutine 1 is executed and program execution returns to the next instruction after SBS(091) 1.
  • Page 642 3. Instructions  Nested Subroutines CIO 0.00 ON 0.00 0.00 0.01 0.01 Order of execution 0.00 Order of execution A→S1-1→S2→S1-2→B Subroutine 1 A→S1-1→S1-2→B CIO 0.01 ON A→B 0.01 A→B Subroutine 2 When CIO 0.00 is ON in the following example, subroutine 1 is executed. If CIO 0.01 is ON, subroutine 2 is executed from within subroutine 1 and program execution returns to the next instruction after SBS(091) 2 when subroutine 2 is completed.
  • Page 643 3. Instructions When CIO 0.00 is ON in the following example, subroutine 1 is executed and program execution returns to the next instruction after SBS(091). CIO 0.00 ON 0.00 remainder main program Main program (through the instruction just before SBN(092) 1) is then executed. 0.00 0.00 Order of execution...
  • Page 644 3. Instructions MCRO Function Instruction Mnemonic Variations Function code Calls the subroutine with the specified subroutine number and executes that program using the input MACRO MCRO @MCRO parameters in S to S+3 and the output parameters in D to D+3. MCRO MCRO(099) Symbol...
  • Page 645 3. Instructions Related Auxiliary Area Words and Bits Name Address Operation Macro area input words A600 to A603 When MCRO(099) is executed the four words from S to S+3 are copied to A600 to A603. These input words are passed to the subroutine. Macro area output words A604 to A607 After the subroutine specified in MCRO(099) has been executed, the output data in these output words...
  • Page 646 3. Instructions Example Programming When CIO 0.00 is ON in the following example, two MCRO(099) instructions pass different input and output data to subroutine 1. 1. The first MCRO(099) instruction passes the input data in CIO 100 to CIO 103 and executes the subroutine. When the subroutine is completed, the output data is stored in CIO 300 to CIO 303.
  • Page 647 3. Instructions SBN/RET Function Instruction Mnemonic Variations Function code Indicates the beginning of the subroutine program with SUBROUTINE ENTRY the specified subroutine number. SUBROUTINE RETURN Indicates the end of a subroutine program. Symbol SBN(092) RET(093) N: Subroutine number Applicable Program Areas ...
  • Page 648 3. Instructions Flags  SBN/RET There are no flags affected by this instruction. Function  SBN SBN(092) indicates the beginning of the subroutine with the specified subroutine number. The end of the subroutine is MCRO indicated by RET(093). The region of the program beginning at the first SBN(092) instruction is the subroutine region.
  • Page 649 3. Instructions • The step instructions, STEP(008) and SNXT(009) cannot be used in subroutines. Not allowed • Place the subroutines after the main program and just before the END(001) instruction in the program for each task. If part of the main program is placed after the subroutine region, that program section will be ignored.
  • Page 650 3. Instructions GSBS Function Instruction Mnemonic Variations Function code Calls the global subroutine with the specified GLOBAL SUBROUTINE CALL GSBS @GSBS subroutine number and executes that program. GSBS Symbol GSBS(750) N: Global subroutine number Applicable Program Areas Function block SFC action or transition Area Block program areas Step program areas...
  • Page 651 3. Instructions Function GSBS(750) calls the global subroutine with the specified global subroutine number. The global subroutine is the program section between GSBN(751) and GRET(752). When the global subroutine is completed, program execution continues with the next instruction after GSBS(750). The same global subroutine region (GSBN(751) to GRET(752)) can be called more than once.
  • Page 652 3. Instructions Cyclic or interrupt task Execution condition ON Multiple global subroutine regions (GSBN(751) to 0.00 GSBS GRET(752)) can be defined in interrupt task 0. Execution 0.01 condition ON GSBS Interrupt task 0 GSBN GRET Subroutine functions GSBN divided by task. GRET An SBS(091) or GSBS(750) instruction can be Interrupt task 0...
  • Page 653 3. Instructions Precautions The regular SUBROUTINE CALL instruction, SBS(091), cannot call a global subroutine region (GSBN(751) to GRET(752)). GSBS(750) will not be executed when it is within a program section interlocked by IL(002) and ILC(003), so interlocks are not allowed within global subroutine regions. •...
  • Page 654 3. Instructions • In contrast, the output of a differentiated instruction (DIFU(013) or DIFD(014)) would remain ON if the instruction was executed and the output was turned ON but the same global subroutine was not called a second time. In the following example, global subroutine 1 is executed if CIO 0.00 is ON. Output CIO 1.00 is turned ON by DIFU(013) when CIO 0.01 has gone from OFF to ON.
  • Page 655 3. Instructions Two or more global subroutine programs can be programmed in interrupt task 0. In this case, interrupt task 0 can be divided and used as the subroutine function's task. Cyclic or interrupt task When CIO 0.00 is ON, global subroutine program 1 is executed.
  • Page 656 3. Instructions GSBN/GRET Function Instruction Mnemonic Variations Function code GLOBAL SUBROUTINE Indicates the beginning of the global subroutine program GSBN ENTRY with the specified subroutine number. GLOBAL SUBROUTINE GRET Indicates the end of a subroutine program. RETURN GSBN GRET Symbol GSBN(751) GRET(752) N: Global subroutine number...
  • Page 657 3. Instructions Function  GSBN Cyclic or interrupt task GSBN(751) indicates the beginning of the global subroutine with specified GSBS subroutine number. The region of the program beginning at the first GSBN(751) instruction is the subroutine region. A subroutine is executed only when it has been called by GSBS(750).
  • Page 658 3. Instructions • The step instructions, STEP(008) and SNXT(009) cannot be used in global GSBN subroutines. SNXT Not allowed STEP GRET • Place the global subroutine region (GSBN(751) to GRET(752)) in interrupt task 0 just before the END(001) instruction. When two or more global subroutines are being used, group them together in interrupt task 0 after the end of the main program.
  • Page 659: Interrupt Control Instructions

    3. Instructions Interrupt Control Instructions Interrupt Control Instructions The CS/CJ-series CPU Units support the following interrupts. Type Execution condition Setting procedure I/O Interrupts Interrupt input from the Interrupt Input Unit on the Use the MSKS instruction to assign inputs from Interrupt Input Units CPU Rack turns ON/OFF.
  • Page 660 3. Instructions Precautions in Using Interrupt Tasks  Precautions for All Interrupts • When IORF(097), FIORF(225), IORD(222), or IOWR(223) is being executed within an interrupt task to refresh I/O in a Special I/O Unit, cyclic refreshing with that Special I/O Unit must be disabled in the PLC Setup.
  • Page 661 3. Instructions Related Memory Area Words Name Address Operation Maximum Interrupt A440 The maximum processing time for an interrupt task is stored in binary data in 0.1-ms units and is cleared Task Processing Time at the start of operation. Interrupt Task with A441 The interrupt task number with maximum processing time is stored in binary data.
  • Page 662 3. Instructions MSKS Function Instruction Mnemonic Variations Function code SET INTERRUPT MASK MSKS @MSKS Controls interrupts. MSKS MSKS(690) Symbol N: Interrupt identifier C: Control data Applicable Program Areas Function block SFC action or Area Block program areas Step program areas Subroutines Interrupt tasks definitions...
  • Page 663 3. Instructions (2) Specifying Up/Down Differentiation of Interrupt Inputs for I/O Interrupts and Input Interrupts (Except when Using a C200HS-INT01 Interrupt Input Unit) Operand Contents Interrupt input Interrupt identifier Inputs to a CS1W-INT01/CJ1W-INT01 2: Unit number 0 Interrupt Input Unit (16 inputs/Unit) I/O interrupts 0 to 15 (interrupt tasks 100 to 115) 3: Unit number 1 I/O interrupts 16 to 31 (interrupt tasks 116 to 131)
  • Page 664 3. Instructions (4) Resetting and Starting Scheduled Interrupts (CJ1M and CJ2M CPU Units Only) Operand Contents Scheduled Interrupt No. 14: Scheduled interrupt 0 (interrupt task 2) 15: Scheduled interrupt 1 (interrupt task 3) Note Only scheduled interrupt 0 can be used with the CJ1M-CPU11/21. Scheduled interrupt time units Scheduled interrupt set time (Set in the PLC Setup.)
  • Page 665 3. Instructions Note If high-speed interrupt function is enabled for a CJ2 CPU Unit with unit version 1.1 or later, an error will not occur and the Error Flag will remain OFF even if the time unit is set to 0.1 ms for scheduled interrupt 0 (N = 4). Related PLC Setup Settings Name Description...
  • Page 666 3. Instructions • When MSKS(690) is used to restart the internal timer, the time from the execution of MSKS(690) to the start of the first scheduled interrupt task is uncertain, because the existing internal timer PV is used. When you want to specify the interrupt start time, use CLI(691) together with MSKS(690). (4) Resetting Internal Timers for Scheduled Interrupts (N = 14 or 15) •...
  • Page 667 3. Instructions  Example for Scheduled Interrupts 1. When W0.00 goes from OFF to ON in the following example, MSKS(690) sets a 15 ms time interval for scheduled interrupt 0, and starts the internal timer. (In this case, the scheduled time interval units are set to 1 ms.) 2.
  • Page 668 3. Instructions MSKR Function Instruction Mnemonic Variations Function code Reads the current interrupt control settings that READ INTERRUPT MASK MSKR @MSKR were set with MSKS(690). MSKR MSKR(692) Symbol N: Interrupt identifier D: Destination word Applicable Program Areas Function block SFC action or Area Block program areas Step program areas...
  • Page 669 3. Instructions Operand Contents Interrupt input Read interrupt mask status Inputs to a CS1W-INT01 or CJ1W-INT01 Range: 0000 to FFFF hex Interrupt Input Unit (16 inputs/Unit) Bits 0 to 15 correspond to each interrupt task. The meaning of the individual flags is as follows: 1: Disable (mask) the interrupt.
  • Page 670 3. Instructions (4) Reading the Present Value of a Scheduled Interrupts Internal Timer (CJ1M and CJ2M CPU Units Only) Operand Contents Interrupt identifier 14: Scheduled interrupt 0 (interrupt task 2) 15: Scheduled interrupt 1 (interrupt task 3) Note Only scheduled interrupt 0 can be used with the CJ1M-CPU11/21. Scheduled interrupt time units Read internal timer PV (Set in the PLC Setup.)
  • Page 671 3. Instructions Note 1 The CJ1M-CPU11/21 supports only one scheduled interrupt task, interrupt task 2 for scheduled interrupt 2 The time unit for the scheduled interrupt set time and PV is set as the Schedule Interrupt Interval in the PLC Setup (default:10 ms). 3 MSKR(692) can be executed in the main program or in interrupt tasks.
  • Page 672 3. Instructions  Example for Scheduled Interrupts When W0.00 goes from OFF to ON while the internal timer is operating for scheduled interrupt 1, MSKR(692) reads the interrupt time interval setting and outputs the setting to D100. W0.00 @MSKR D100 Scheduled interrupt 1 (interrupt task 3) 24 ms 24 ms...
  • Page 673 3. Instructions Function Instruction Mnemonic Variations Function code Clears/retains recorded interrupt inputs, sets the CLEAR INTERRUPT @CLI time to the first scheduled interrupt for scheduled interrupt tasks. CLI(691) Symbol N: Interrupt identifier C: Control data Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 674 3. Instructions Operand Contents Interrupt input Control data (cause processing data) Inputs to a CS1W-INT01 or CJ1W-INT01 Set to 0000 to FFFF hex. Interrupt Input Unit (16 inputs/Unit) Bits 0 to 15 correspond to each interrupt task. Individual bit settings are as follows: 0: Retain the recorded interrupt.
  • Page 675 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if N is not within the specified range (0, 1, or 4 to 11 for CJ1M CPU Unit; 0, 1, 4 to 13, or 100 to 107 for CJ2M CPU Unit; or 0 to 5 for other CPU Units). •...
  • Page 676 3. Instructions (3) Clearing or Holding High-speed Counter Interrupt Causes (N = 10 or 13) When N is 10 or 13, CLI(691) clears or retains the recorded high-speed counter interrupt cause (either target-value or range comparison) for the built-in high-speed counter interrupt specified by N.
  • Page 677 3. Instructions Function Instruction Mnemonic Variations Function code Disables execution of all interrupt tasks except the DISABLE INTERRUPTS power OFF interrupt task for part of a program. Symbol DI(693) Applicable Program Areas Function block SFC action or Area Block program areas Step program areas Subroutines Interrupt tasks...
  • Page 678 3. Instructions Example Programming When CIO 0.00 is ON in the following example, DI(693) 0.00 disables all interrupt tasks other than the power OFF interrupt task. Note With CS1D CPU Units for Single-CPU Systems or CJ2, Disables execution of CS1-H, CJ1-H, or CJ1M CPU Units: all interrupt tasks Power OFF interrupt processing can be disabled at the (except the power...
  • Page 679 3. Instructions Function Instruction Mnemonic Variations Function code Enables execution of all interrupt tasks that were ENABLE INTERRUPTS disabled with DI(693). Symbol EI(694) Applicable Program Areas Function block SFC action or Area Block program areas Step program areas Subroutines Interrupt tasks definitions transition programs Usage...
  • Page 680 3. Instructions Example Programming Disables execution of all interrupt tasks (except the power OFF interrupt). 0.00 Enables execution of all disabled interrupt tasks. Note When the power OFF interrupt task is disabled for a CJ2, CS1-H, CJ1-H, CJ1M CPU Unit, or CS1D CPU Unit for Single-CPU System, power OFF processing will also be enabled at the same time.
  • Page 681: High-Speed Counter/Pulse Output Instructions

    3. Instructions High-speed Counter/Pulse Output Instructions Mne- Varia- Function Instruction Function monic tions code INI(880) is used to start and stop comparison for a comparison table, to change the present value (PV) of a high-speed counter, to change the PV of an input interrupt in counter mode, to change the maximum value MODE CONTROL @INI of the ring counter (CJ2M only), to change the PV of a pulse output...
  • Page 682 3. Instructions P: Port Specifier Port 0000 hex Pulse output 0 0001 hex Pulse output 1 0002 hex Pulse output 2 (CJ2M only) 0003 hex Pulse output 3 (CJ2M only) 0010 hex High-speed counter 0 0011 hex High-speed counter 1 0012 hex High-speed counter 2 (CJ2M only) 0013 hex...
  • Page 683 3. Instructions NV: First Word with New PV This operand is used only for changing the PV, changing the New data maximum ring value, and Interrupt Input in Counter Mode: changing origin search/return 0000 to FFFF hex settings. • Changing the PV (C = 0002 hex) or Changing Lower word of new PV the Maximum Ring Value...
  • Page 684 3. Instructions Function INI(880) performs the operation specified in C for the port specified in P. The possible combinations of operations and ports are shown in the following table. C: Control data Changing the Changing the origin maximum ring P: Port specifier 0000 hex: Start 0001 hex: Stop 0002 hex:...
  • Page 685 3. Instructions All of these parameters can be changed at the same time. All parameters must be specified even when changing only one of them. If invalid parameters are specified, an instruction error will occur and the parameters will not be changed.
  • Page 686 3. Instructions Example: Changing Origin Search/Return Settings (C = 0005 Hex) (CJ2M Only) When CIO 0.00 turns ON in the following example, INI(880) changes the origin search/return set- tings. Then an origin return is executed with ORG(889). #0064 0.00 Origin Search/Return Initial Speed: 100 pps #0000 @INI NV+1:...
  • Page 687 3. Instructions Function Instruction Mnemonic Variations Function code HIGH-SPEED PRV(881) reads the High-speed counter PV and pulse output PV @PRV COUNTER PV READ and interrupt input PV in counter mode. PRV(881) Symbol P: Port specifier C: Control data D: First destination word Applicable Program Areas Function block SFC action or transition...
  • Page 688 3. Instructions C: Control Data PRV(881) function 0000 hex Reads the PV. 0001 hex Reads status. 0002 hex Reads range comparison results. P = 0000 to 0003: Reads the output frequency of pulse output 0 to 3. C = 0003 hex: Standard operation P = 0010: Reads the frequency of high-speed counter input 0 (high-speed counter 0 only).
  • Page 689 3. Instructions Function PRV(881) reads the data specified in C for the port specified in P. The possible combinations of data and ports are shown in the following table. C: Control data 0002 hex: Read P: Port specifier 0001 hex: Read sta- 00@3 hex: Read fre- 0000 hex: Read PV range...
  • Page 690 3. Instructions  Reading Status (C = 0001 hex) Port and mode Operation Results of reading Pulse output The pulse output status is stored in D. D 0 0 0 0 0 0 Pulse Output Status Flag OFF: Constant speed ON: Accelerating/decelerating PV Overflow/Underflow Flag OFF: Normal...
  • Page 691 3. Instructions  Reading the Results of Range Comparison (C = 0002 hex) If C is 0002 hex, PRV(881) reads the results of range comparison and stores it in D as shown in the following diagram. Results for Eight Ranges D 0 0 0 0 0 0 0 0 Comparison Result 1 OFF: Not in range ON: In range...
  • Page 692 3. Instructions • High-frequency Calculation Method: In this case, the counting method is switched at high and low frequencies. At high frequencies (above 1 kHz), the function counts the number of pulses within a fixed interval (the sampling time) and calculates the frequency from that count. One of the following three sam- pling times can be selected by setting the rightmost two digits of C.
  • Page 693 3. Instructions PRV2 Function Instruction Mnemonic Variations Function code Reads the pulse frequency input from a high-speed counter and either converts the frequency to a rotational speed (number of revo- COUNTER lutions) or converts the counter PV to the total number of revolu- FREQUENCY CON- PRV2 @PRV2...
  • Page 694 3. Instructions D: First Destination Word Conversion result (Rightmost 4 digits) Conversion result (Leftmost 4 digits)  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER •...
  • Page 695 3. Instructions When the CPU Unit is a CJ1M CPU Unit with unit version 3.0 or later or a CJ2M CPU Unit, there are two ways to calculate the frequency of pulses input to high-speed counter 0. • Standard Calculation Method (C1 = 0 00) The count is calculated by counting each pulse regardless of the frequency.
  • Page 696 3. Instructions CTBL Function Instruction Mnemonic Variations Function code REGISTER CTBL(882) is used to register a comparison table and perform CTBL @CTBL COMPARISON TABLE comparisons for a high-speed counter PV. CTBL CTBL(882) Symbol P: Port specifier C: Control data TB: First comparison table word Applicable Program Areas Function block SFC action or transition...
  • Page 697 3. Instructions TB: First comparison table word  Specifying a Target Value Comparison Table (C = 0000 or 0002 Hex) For target value comparison, the length of the comparison table is determined by the number of tar- get values specified in TB. The table can be between 4 and 145 words long, as shown below. 0001 to 30 hex (1 to 48 target values) Number of target values Lower word of target value 1...
  • Page 698 3. Instructions Number of ranges 0001 to 0020 hex (1 to 32 decimal) Lower word of range 1 lower limit TB+1 0000 0000 to FFFF FFFF hex Upper word of range 1 lower limit TB+2 Lower word of range 1 upper limit TB+3 0000 0000 to FFFF FFFF hex Upper word of range 1 upper limit...
  • Page 699 3. Instructions Function CTBL(882) registers a comparison table and starts target-value or range comparison for the high- speed counter specified in P and the method specified in C.  Registering a Comparison Table (C = 0002, 0003, 0005 Hex) If C is set to 0002 or 0003 hex, a comparison table will be registered, but comparison will not be started. Comparison is started with INI(880).
  • Page 700 3. Instructions • For range comparisons, the interrupt task for any one range will be executed only once each time the comparison value enters or leaves the range. It will not be executed again until the condition for execution is no longer met and then met again. The Range Comparison Condition Met Flag, however, will be ON whenever the comparison value is within the range regardless of the out of range/in range specification.
  • Page 701 3. Instructions 0.00 @CTBL High-speed counter input 0 #0000 Register target comparison table #0000 and start comparison D100 High-speed counter PV D100 0002 Number of target values: 2 D101 01F4 Target value 1 D102 01F4 hex (500 decimal) 0000 Target value 2: 1,000 decimal Target value 1 interrupt task No.: D103 0001...
  • Page 702 3. Instructions  Example for Range Comparison for 1 to 32 Ranges (CJ2M Only) When CIO 0.00 turns ON in the following programming example, CTBL(882) registers a range comparison table using upper and lower limits for high-speed counter 0 and starts comparison. When the PV of the high-speed counter leaves the upper/lower limits for range 1, interrupt task 0 is executed.
  • Page 703 3. Instructions SPED Function Instruction Mnemonic Variations Function code SPED(885) is used to set the output pulse frequency for a specific SPEED OUTPUT SPED @SPED port and start pulse output without acceleration or deceleration. SPED SPED(855) Symbol P: Port specifier M: Output mode F: First pulse frequency word Applicable Program Areas...
  • Page 704 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the specified range for P, M, or F is exceeded. • ON if ACC(888), PLS2(887), ORG(889) or IFEED(892) is already being executed to control pulse output for the specified port.
  • Page 705 3. Instructions Procedure/ Operation Purpose Application Frequency changes Description instruction Stopping Stop pulse Immediate stop Stops the pulse output SPED(885) Pulse frequency pulse output output immediately. (Continuous) ↓ Present frequency INI(880) Time Execution of INI(880) Stop pulse Immediate stop Stops the pulse output SPED(885) Pulse frequency output...
  • Page 706 3. Instructions Procedure/ Operation Purpose Application Frequency changes Description instruction Stopping To stop pulse Immediate stop Stops the pulse output PULS(886) Pulse frequency pulse output output immediately and clears ↓ (Number of the number of output SPED(885) Present pulses setting pulses setting.
  • Page 707 3. Instructions PULS Function Instruction Mnemonic Variations Function code PULS(886) is used to set the pulse output amount (number of out- SET PULSES PULS @PULS put pulses). PULS PULS(886) Symbol P: Port specifier T: Pulse type N: Number of pulses Applicable Program Areas Function block SFC action or transition...
  • Page 708 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR P, T Flags Name Label Operation Error Flag P_ER • ON if the specified range for P, T, or N is exceeded. •...
  • Page 709 3. Instructions PLS2 Function Instruction Mnemonic Variations Function code PLS2(887) outputs a specified number of pulses to the specified port. Pulse output starts at a spec- ified startup frequency, accelerates to the target PULSE OUTPUT PLS2 @PLS2 frequency at a specified acceleration rate, decel- erates at the specified deceleration rate, and stops at approximately the same frequency as the startup frequency.
  • Page 710 3. Instructions M: Output Mode Relative/absolute specifier 0 hex: Relative pulses 1 hex: Absolute pulses Direction 0 hex: CW 1 hex: CCW Pulse output method (See note 1.) 0 hex: CW/CCW 1 hex: Pulse + direction Stopping operation for reversal specification (See note 2.)/operation compensation for parameters changes (See note 3.) 0 hex: Deceleration stop when reversing and no operation compensation 4 hex: Deceleration stop when reversing and operation compensation...
  • Page 711 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR P, M Flags Name Label Operation Error Flag P_ER • ON if the specified range for P, M, S, or F is exceeded. •...
  • Page 712 3. Instructions  Independent Mode Positioning Note Pulse output will stop immediately if the CPU Unit is changed to PROGRAM mode. Opera- Procedure/ Purpose Application Frequency changes Description tion instruction Starting Complex Positioning with Accelerates and PLS2(887) Pulse frequency Specified number pulse trapezoidal trapezoidal...
  • Page 713 3. Instructions Opera- Procedure/ Purpose Application Frequency changes Description tion instruction Changing To change Changing the PLS2(887) can be PLS2(887) Specified number of settings speed target speed executed during ↓ Pulse pulses (Specified with frequency smoothly (frequency) during positioning to change the PLS2(887) PULS(886).) Changed target...
  • Page 714 3. Instructions Opera- Procedure/ Purpose Application Frequency changes Description tion instruction Changing To change Changing the PLS2(887) can be PULS(886) Number of pulses target posi- settings, acceleration and executed during ↓ Pulse specified by tion and continued deceleration rates positioning (acceleration ACC(888) frequency Acceleration rate n...
  • Page 715 3. Instructions  Switching from Continuous Mode Speed Control to Independent Mode Positioning Procedure/ Example application Frequency changes Description instruction Change from speed control to fixed PLS2(887) can be executed during a ACC(888) Outputs the number of distance positioning during operation speed control operation started with (Continuous) pulses specified in...
  • Page 716 3. Instructions  Operation Compensation When Parameters Are Changed If a constant speed cannot be achieved or the target position is exceeded after parameters are changed, operation can be compensated and continued. Note On the CJ1M-CPU2@, operation compensation cannot be used. •...
  • Page 717 3. Instructions Example Programming When CIO 0.00 turns ON in the following programming example, PLS2(887) starts pulse output from pulse output 0 with an absolute pulse specification of 100,000 pulses. Pulse output is accelerated at a rate of 500 pps every 4 ms starting at 200 pps until the target speed of 50 kpps is reached. From the deceleration point, the pulse output is decelerated at a rate of 250 pps every 4 ms starting until the starting speed of at 200 pps is reached, at which point pulse output is stopped.
  • Page 718 3. Instructions Function Instruction Mnemonic Variations Function code ACC(888) outputs pulses to the specified output ACCELERATION CONTROL @ACC port at the specified frequency using the specified acceleration and deceleration rate. ACC(888) P: Port specifier Symbol M: Output mode S: First word of settings table Applicable Program Areas Function block SFC action or transition...
  • Page 719 3. Instructions S: First Word of Settings Table CJ1M CPU Units, no unit version 1 to 2000 pps (#0001 to 07D0) Acceleration/deceleration rate CJ1M CPU Unit with unit version 2.0 or later or CJ2M CPU Unit 1 to 65535 pps (#0001 to FFFF) Specify the increase or decrease in the frequency per pulse control period (4 ms).
  • Page 720 3. Instructions ACC(888) can also be used to change settings during pulse output. ACC(888) in independent mode can also be executed during pulse output for PLS2(887) during acceleration, constant speed, or deceleration. With the CJ1M and CJ2M CPU Units, PLS2(887) can be executed during pulse output for ACC(888) in either independent or continuous mode, and during acceleration, constant speed, or deceleration.
  • Page 721 3. Instructions  Continuous Mode Speed Control Pulse output will continue until it is stopped from the program. Note Pulse output will stop immediately if the CPU Unit is changed to PROGRAM mode. Opera- Procedure/ Purpose Application Frequency changes Description tion instruction Starting...
  • Page 722 3. Instructions  Independent Mode Positioning When independent mode operation is started, pulse output will be continued until the specified number of pulses has been output. The deceleration point is calculated from the number of output pulses and deceleration rate set in S and when that point is reached, the frequency is decreased every pulse control period at the deceleration rate specified in S until the specified number of points has been output, at which point pulse output is stopped.
  • Page 723 3. Instructions Opera- Procedure/ Purpose Application Frequency changes Description tion instruction Stopping To stop Decelerating to a Decelerates the pulse PULS(886) Pulse frequency pulse pulse output stop output to a stop. ↓ output, smoothly. ACC(888) Note If ACC(888) started Present continued (Number of Deceleration rate...
  • Page 724 3. Instructions  Operation Compensation When Parameters Are Changed If a constant speed cannot be achieved or the target position is exceeded after parameters are changed in independent mode, operation can be compensated and continued. Note On the CJ1M-CPU2@, operation compensation cannot be used. •...
  • Page 725 3. Instructions 0.00 @ACC D100 #0014 Acceleration/deceleration rate: 20 pps #0000 D101 #01F4 Pulse output: 0 Target frequency: 500 pps #0000 D102 #0000 Pulse output method: CW/CCW D100 Direction: CW in continuous mode D105 #000A Acceleration/deceleration rate: 10 pps 0.01 D106 #03E8 @ACC...
  • Page 726 3. Instructions Function Instruction Mnemonic Variations Function code ORG(889) performs an origin search or origin ORIGIN SEARCH @ORG return operation. ORG(889) Symbol P: Port specifier C: Control data Applicable Program Areas Function block SFC action or transition Block program areas Step program areas Subroutines Interrupt tasks...
  • Page 727 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the specified range for P or C is exceeded. • ON if ORG(889) is specified for a port during pulse output for SPED(885), ACC(888), PLS2(887) or IFEED(892). • ON if ORG(889) is executed in an interrupt task when an instruction controlling pulse output is being executed in a cyclic task.
  • Page 728 3. Instructions  Origin Return (Bits 12 to 15 of C = 1 hex) ORG(889) starts outputting pulses using the Pulse frequency Origin return specified method at the Origin Return Initial target speed Speed (1 in diagram). Origin return Origin return deceleration rate Pulse output is accelerated to the Origin Return acceleration...
  • Page 729 3. Instructions Instruction Mnemonic Variations Fun No. Function PWM(891) is used to output pulses with a variable PWM outputs @PWM duty factor. Symbol P: Port specifier/numeric units F: Frequency D: Duty factor Applicable Program Areas Function block SFC action or transition Area Block program areas Step program areas...
  • Page 730 3. Instructions D: Duty factor Setting support CJ1M-CPU2@ with unit Numeric unit Setting range CJ1M-CPU2@ version 2.0 or later or (pre-version 2.0) CJ2M + MD21@ 0% to 100% 0 to 100 (0000 to 0064 hex) 0.1% 0.0% to 100.0% Not allowed. 0 to 1,000 (0000 to 03E8 hex) ...
  • Page 731 3. Instructions Example Programming When CIO 0.00 turns ON in the following programming example, PWM(891) starts pulse output from PWM output 0 at 200 Hz with a duty factor of 50%. When CIO 0.01 turns ON, the duty factor is changed to 25% from the next output pulse. 0.00 @PWM PWM output...
  • Page 732 3. Instructions IFEED Function Instruction Mnemonic Variations Function code IFEED(892) uses an input interrupt as a trigger to switch from speed control to position control and INTERRUPT FEEDING IFEED @IFEED move the specified number of pulses. IFEED(892) is supported only by the CJ2M. IFEED Symbol P: Port Specifier...
  • Page 733 3. Instructions S: First word of settings table Acceleration Rate 1 to 65,535 pps/4 ms (0001 to FFFF hex) Deceleration Rate 1 to 65,535 pps/4 ms (0001 to FFFF hex) Lower word of target frequency 0 to 100 kpps (0000 0000 to 0001 86A0 hex) Upper word of target frequency Lower word with number of pulses Number of output pulses: 0 to 2,147,483,647...
  • Page 734 3. Instructions Pulse frequency Input interrupt occurs Target Number of output pulses frequency Deceleration rate Acceleration rate Speed control Position control Time Execution of IFEED(892) Precautions for Correct Use An instruction error will occur if a constant speed cannot be achieved for the number of pulses specified by S.
  • Page 735: Step Instructions

    3. Instructions Step Instructions Step Instructions In CS/CJ-series PLCs, STEP(008)/SNXT(009) can be used together to create step programs. Instruction Operation Diagram SNXT(009): STEP Controls progression to the next step of the Step Ladder section start instruction START program. Equivalent to STEP(008): STEP Indicates the start of a step.
  • Page 736 3. Instructions SNXT/STEP Function Instruction Mnemonic Variations Function code SNXT(009) is used to control progression of step STEP START SNXT execution in the step program area. STEP(008) is used to define the beginning and STEP DEFINE STEP the end of the step program area. SNXT STEP When defining the beginning of a step, a control bit is specified as...
  • Page 737 3. Instructions Proceeding to the Next Step When SNXT(009) occurs in the middle of the step program area, it is used to proceed to the next step. It turns OFF the previous control bit and turns ON the next control bit B, for the next step, thereby starting step B (all instructions after STEP(008) B).
  • Page 738 3. Instructions Hint A200.12 (Step Flag) is turned ON for one cycle 0.00 when STEP(008) is executed. This flag can be Start used to conduct initialization once the step W0.00 execution has started. W0.00 A200.12 W0.00 1 cycle 0.01 A200.12 Related Bits Name Address...
  • Page 739 3. Instructions • STEP(008) and SNXT(009) cannot be used inside of subroutines, interrupt programs, or block programs. • The instructions that cannot be used within step programs are listed in the following table. Function Mnemonic Name Sequence END(001) Control IL(002) INTERLOCK Instructions ILC(003)
  • Page 740 3. Instructions (1) Sequential Control 0.01 0.01 (Step (A) starting condition) W0.00 Step (A) W0.00 W0.00 0.02 (Step (A) → Step (B) transition condition) Step W0.00 (A) Step (A) ladder program Step (B) W0.01 0.02 0.03 (Step (B) → Step (C) transition condition) W0.01 Step (C) W0.02...
  • Page 741 3. Instructions (2) Branching Control 0.01 0.02 0.02 (Step (B) starting condition) 0.01 (Step (A) W0.00 starting condition) 0.02 0.01 Step (A) W0.00 Step (B) W0.01 W0.01 0.03 (Step (A) → Step (C) transition 0.04 (Step (B) → Step (C) condition) transition condition) W0.00...
  • Page 742 3. Instructions (3) Parallel Control 0.01 0.01 (Step (A), (C) simultaneous starting condition) W0.00 Step (A) W0.00 Step (C) W0.02 W0.02 0.02 (Step (A) → 0.03 (Step (C) → Step (D) Step (B) transition transition condition) condition) W0.00 Step (B) W0.01 Step (D) W0.02...
  • Page 743 3. Instructions Application Examples (1) Sequential Execution Robot hand Solenoid 1 Solenoid 2 Photomicro- SW 1 sensor SW 4 SW 2 SW 3 Conveyor belt 1 Conveyor belt 2 Conveyor belt 3 Process A: Loading Process B: Part installation Process C: Inspection/Unloading 0.01(SW1) 0.01 (SW1) Process A...
  • Page 744 3. Instructions (2) Branching Execution Printer SW C1 SW D SW A1 Guide SW A2 SW C2 Process A Conveyer A Process B Conveyer B SW B2 SW B1 Weight scale Process C 0.01 0.02 0.02(SW B1) 0.01(SW A1) W0.00 0.01 0.02 Process A...
  • Page 745 3. Instructions (3) Parallel Execution Conveyer B Process A Conveyer A Process B Process E Conveyer E Process D Process C Conveyer D Conveyer C 0.01(SW1, SW2) 0.01(SW 1 and SW2 both ON) Process A started. Process C W0.00 started. Process A Process C W0.02...
  • Page 746: Basic I/O Unit Instructions

    3. Instructions Basic I/O Unit Instructions IORF Function Instruction Mnemonic Variations Function code I/O REFRESH IORF @IORF Refreshes the specified I/O words. IORF IORF(097) Symbol St: Starting word E: End word Applicable Program Areas Function block SFC action or Area Block program areas Step program areas Subroutines...
  • Page 747 3. Instructions Units Refreshed by IORF(097) Unit position On the CPU rack or an expansion rack (excluding SYSMAC BUS Slave Racks) Refreshable by FIORF(255) Unit Type Basic I/O Units CS series Basic I/O Units C200H Basic I/O Units (CS Series only) C200H Group-2 High-density Basic I/O Units (CS Series only) CJ-Series Basic I/O Units Special I/O units (CIO words of all special I/O units, including high-density I/O units)
  • Page 748 3. Instructions Precaution • IORF(097) can be used in an interrupt task, which allows high-speed processing of specific I/O data with an interrupt. If IORF(097) is used in an interrupt task, always disable cyclic refreshing of the specified Special I/O Unit by turning ON the corresponding Special I/O Unit Cyclic Refreshing Disable Bit in the PLC Setup.
  • Page 749 3. Instructions FIORF Function Instruction Mnemonic Variations Function code Performs I/O refreshing immediately for the speci- SPECIAL I/O UNIT I/O FIORF @FIORF fied Special I/O Unit's allocated CIO Area and DM REFRESH Area words with the specified unit number. FIORF Symbol FIORF(225) N: Unit number...
  • Page 750 3. Instructions Function FIORF(225) performs immediate I/O refreshing of CPU Unit Special I/O Unit the CIO Area words and DM Area words with unit number N Words allocated to Special I/O Unit allocated to the Special I/O Unit with the unit with unit number N number specified by N.
  • Page 751 3. Instructions Example Programming When CIO 0.00 is ON, FIORF(225) immediately refreshes the CIO Area and DM Area words allocated to the Special I/O Unit set as unit number 0. 0.00 FIORF &0 CPU Unit Special I/O Unit Words allocated to Special I/O Unit with unit number 0 with unit number 0 Allocated CIO Area words...
  • Page 752 3. Instructions DLNK Function Instruction Mnemonic Variations Function code Performs I/O refreshing immediately for the CPU CPU BUS UNIT I/O REFRESH DLNK @DLNK Bus Unit with the specified unit number. DLNK Symbol DLNK(226) N: Unit number Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 753 3. Instructions Function DLNK(226) performs immediate I/O refreshing for the CPU Bus Unit with the specified unit number. The data listed below is refreshed. Refer to the Hint below for details on the execution conditions to use for immediate refreshing. 1.
  • Page 754 3. Instructions Precaution • DLNK(226) refreshes data between the CPU Unit and specified CPU Bus Unit. Some time is required for the data exchange with the CPU Bus Unit (for example, a data link with a Controller Link Unit). • If the specified CPU Bus Unit is exchanging data, DLNK(226) will not be executed and the Equals Flag will be turned OFF.
  • Page 755 3. Instructions The actual timing for data link area refreshing in this example is as follows: • When transmitting: Data is transmitted over the network the next time that the token right is acquired. (The transmitted data is delayed up to 1 communications cycle time max.) •...
  • Page 756 3. Instructions SDEC Function Instruction Mnemonic Variations Function code Converts the hexadecimal contents of the desig- nated digit(s) into 8-bit, 7-segment display code 7-SEGMENT DECODER SDEC @SDEC and places it into the upper or lower 8-bits of the specified destination words. SDEC SDEC(078) Symbol...
  • Page 757 3. Instructions Function SDEC(078) regards the data specified by S as 4-digit hexadecimal data, converts the digits specified in S by Di (first digit and number of Number of digits digits) to 7-segment data and outputs the results to D in the bits specified in Di. First digit to convert Rightmost 8 bits (0) 7-segment...
  • Page 758 3. Instructions  7-segment Data The following table shows the data conversions from a hexadecimal digit (4 bits) to 7-segment code (8 bits). Original data Converted code (segments) Display Original data Digit Bits – CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 759 3. Instructions Function Instruction Mnemonic Variations Function code Reads the value set on a external digital switch (or thumbwheel switch) connected to an I/O Unit and DIGITAL SWITCH INPUT stores the 4-digit or 8-digit value in the specified words. DSW(210) I: Input word Symbol O: Output word...
  • Page 760 3. Instructions D: First Result Word Specifies the leading word address where the external digital switch's set values will be stored. 12 11 Digit 4 Digit 3 Digit 2 Digit 1 12 11 (See note.) Digit 8 Digit 6 Digit 7 Digit 5 Note: Only when C1 = 0001 hex to read 8 digits.
  • Page 761 3. Instructions ID212 Input Unit Thumbwheel Switch OD212 Switch no. 8 Output Unit Note The data read signal is not connected in this example. The inputs and outputs can be connected to the following kinds of Basic I/O Units and High-density I/O Units as long as they are not mounted in a SYSMAC BUS Remote I/O Rack.
  • Page 762 3. Instructions Precaution • Do not read or write the system word (C2) from any other instruction. DSW(210) will not operate correctly if the system word is accessed by another instruction. The system word is not initialized by DSW(210) in the first cycle when program execution starts. If DSW(210) is being used from the first cycle, clear the system word from the program.
  • Page 763 3. Instructions Function Instruction Mnemonic Variations Function code Reads numeric data from a ten-key keypad con- TEN KEY INPUT @TKY nected to an Input Unit and stores up to 8 digits of BCD data in the specified words. TKY(211) I: Input word Symbol D1: First register word D2: Key input word...
  • Page 764 3. Instructions D2: Key Input Word Bits 00 to 10 of D2 indicate key inputs. When one of the keys on the keypad (0 to 9) has been pressed, the corresponding bit of D2 (0 to 9) is turned ON. Bit 10 of D2 will be ON while any key is being pressed.
  • Page 765 3. Instructions The Input Unit must be a DC Input Unit or High-density Input Unit with at least 16 inputs and the Input Unit cannot be mounted in a SYSMAC BUS Remote I/O Rack.  Timing Chart Before 0 0 0 0 0 0 0 0 execution Input from 10-key 0 0 0 0 0 0 0 1...
  • Page 766 3. Instructions Function Instruction Mnemonic Variations Function code Reads numeric data from a hexadecimal keypad connected to an Input Unit and Output Unit and HEXADECIMAL KEY INPUT stores up to 8 digits of hexadecimal data in the specified words. HKY(212) I: Input word Symbol O: Output word...
  • Page 767 3. Instructions D: First Register Word Specifies the leading word address where the hexadecimal keypad's numeric input (up to 8 digits) will be stored. 12 11 Digit 4 Digit 3 Digit 2 Digit 1 12 11 Digit 8 Digit 6 Digit 7 Digit 5 ON when the corresponding key...
  • Page 768 3. Instructions  External Connections Connect the hexadecimal keypad to Input Unit contacts 0 to 3 and Output Unit contacts 0 to 3, as shown in the following diagram. OD212 ID212 Output Unit Input Unit The inputs and outputs can be connected to the following kinds of Basic I/O Units and High-density I/O Units as long as they are not mounted in a SYSMAC BUS Remote I/O Rack.
  • Page 769 3. Instructions Precaution • Do not read or write the system word (C) from any other instruction. HKY(212) will not operate correctly if the system word is accessed by another instruction. The system word is not initialized by HKY(212) in the first cycle when program execution starts. If HKY(212) is being used from the first cycle, clear the system word from the program.
  • Page 770 3. Instructions Function Instruction Mnemonic Variations Function code Inputs up to 64 signals from an 8 × 8 matrix con- nected to an Input Unit and an Output Unit (using MATRIX INPUT 8 input points and 8 output points) and stores that 64-bit data in the 4 destination words.
  • Page 771 3. Instructions D: First Register Word Specifies the leading word address of the 4 words that contain the data from the 8 × 8 matrix. Bits 00 to 15 correspond to matrix elements 0 to 15. Bits 00 to 15 correspond to matrix elements 16 to 31.
  • Page 772 3. Instructions Flags Name Label Operation Error Flag P_ER Function MTR(213) outputs the selection signals to bits 00 to 07 of O, reads the data in order from bits 00 to 07 of I, and stores the 64 bits of data in the 4 words D through D+3. MTR(213) reads the status of the 64- bit matrix every 24 CPU Unit cycles.
  • Page 773 3. Instructions Precaution • Do not read or write the system word (C) from any other instruction. MTR(213) will not operate correctly if the system word is accessed by another instruction. The system word is not initialized by MTR(213) in the first cycle when program execution starts. If MTR(213) is being used from the first cycle, clear the system word from the program.
  • Page 774 3. Instructions 7SEG Function Instruction Mnemonic Variations Function code Converts the source data (either 4-digit or 8-digit 7-SEGMENT DISPLAY 7SEG BCD) to 7-segment display data, and outputs that OUTPUT data to the specified output word. 7SEG 7SEG(214) S: Source word Symbol O: Output word C: Control data...
  • Page 775 3. Instructions • Converting 8 digits − − − One Round Flag Latch outputs Leftmost 4-digit data output Rightmost 4-digit data output C: Control Data The value of C (0000 to 0007 hex) indicates the number of digits of source data and the logic for the Input and Output Units, as shown in the following table.
  • Page 776 3. Instructions The One Round Flag (bit 08 of O when converting 4 digits, bit 12 of O when converting 8 digits) is turned ON for one cycle in every 12 cycles after 7SEG(214) has turned ON each of the latch output signals.
  • Page 777 3. Instructions Precaution • Do not read or write the system word (D) from any other instruction. 7SEG(214) will not operate correctly if the system word is accessed by another instruction. The system word is not initialized by 7SEG(214) in the first cycle when program execution starts. If 7SEG(214) is being used from the first cycle, clear the system word from the program.
  • Page 778 3. Instructions AIDC Function Instruction Mnemonic Variations Function code Reads the input conversion value of the specified ANALOG INPUT DIRECT AIDC @AIDC analog input number from the CJ1W-AD042 Ana- CONVERSION log Input Unit in Direct Conversion Mode. AIDC AIDC Symbol N: Unit number A: Analog input number Applicable Program Areas...
  • Page 779 3. Instructions Flags Name Label Operation Error Flag • ON if the unit number in N is not between &0 and &95 decimal (#0000 and #005F hex). • ON if the specified unit is not a CJ1W-AD042 Analog Input Unit. •...
  • Page 780 3. Instructions • If an attempt is made to execute this instruction while the CJ1W-AD042 Analog Input Unit is being initialized, it will not be executed and the Error Flag will turn ON. To ensure that the Unit is not being initialized when this instruction is executed, use the High-speed I/O Unit Initialization Flag in a normally closed condition for the instruction.
  • Page 781 3. Instructions AODC Function Instruction Mnemonic Variations Function code Outputs the output set value for the specified ana- ANALOG OUTPUT DIRECT AODC @AODC log output number to the CJ1W-DA042V Analog CONVERSION Output Unit in Direct Conversion Mode. AODC AODC Symbol N: Unit number A: Analog output number Applicable Program Areas...
  • Page 782 3. Instructions Flags Name Label Operation Error Flag • ON if the unit number in N is not between &0 and &95 decimal (#0000 and #005F hex). • ON if the specified unit is not a CJ1W-DA042V Analog Output Unit. •...
  • Page 783 3. Instructions • If an attempt is made to execute this instruction while the CJ1W-DA042V Analog Output Unit is being initialized, it will not be executed and the Error Flag will turn ON. To ensure that the Unit is not being initialized when this instruction is executed, use the High-speed I/O Unit Initialization Flag in a normally closed condition for the instruction.
  • Page 784 3. Instructions NCDMV Function Instruction Mnemonic Variations Function code NCDMV(218) starts absolute or relative high- PCU HIGH-SPEED speed point-to-point positioning for the specified NCDMV @NCDMV POSITIONING axis of a CJ1W-NC@@4, CJ1W-NC@81, or CJ1W-NC@82 Position Control Unit. NCDMV NCDMV Symbol C: Control word A: First word of Direct Operation Command Area Applicable Program Areas Function block...
  • Page 785 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if a Unit with the number C+1 is not in range. • ON if the Unit specified in C+1 is not a CJ1W-NC214, CJ1W-NC234, CJ1W-NC414, CJ1W-NC434, CJ1W-NC281, CJ1W-NC481, CJ1W-NC881, CJ1W-NCF81, CJ1W-NC482, or CJ1W-NC882 Posi- tion Control Unit.
  • Page 786 3. Instructions Refer to the CJ-series Position Control Unit Operation Manual (Cat. No. W426) for details on using direct operation. Precautions for Correct Use • The Position Control Unit can execute only one command for one NCDMV(218) instruction each control cycle. If high-speed PTP movements are started continuously, the Position Control Unit may not be able to accept all of them.
  • Page 787 3. Instructions Example Programming When CIO 0.00 turns ON in the following example, an relative movement is executed using direct operation for axis 2 of the CJ1W-NC2@4 Position Control Unit (a Special I/O Unit) with unit number 3. If the first word of the Direct Operation Command Area is D0, the direct operation command settings in D12 to D23 are used to start high-speed PTP positioning.
  • Page 788 3. Instructions NCDTR Function Instruction Mnemonic Variations Function code NCDTR(219) is used to start a sequence for Mem- ory Operation of a CJ1W-NC@81/NC@82 Position PCU POSITIONING TRIGGER NCDTR @NCDTR Control Unit when the start condition for the sequence is waiting for a command from NCDTR(219).
  • Page 789 3. Instructions Related Auxiliary Area Words and Bits Name Addresses Operation CPU Bus Unit Initializing Flags A302.00 to Turns ON when the CPU Bus Unit is being initialized. A302.15 OFF: Not initializing. ON: Initializing. Function NCDTR(219) starts a sequence that is waiting for a command input from NCDTR(219) for the task specified in C for Memory Operation in the Position Control Unit specified in C+1.
  • Page 790 3. Instructions • NCDTR(219) can be used in interrupt tasks. However, do not execute NCDTR(219) in a cyclic task for the same Unit if NCDTR(219) is executed in an interrupt task. (The same thing applies to IORD(222) and IOWR(223).) If an attempt is made to execute NCDTR(219) in an interrupt task when it is already being executed for the same Unit in a cyclic task, it will cause a duplicate refresh error (non-fatal) and A402.13 will turn ON.
  • Page 791 3. Instructions IORD Function Instruction Mnemonic Variations Function code Reads the contents of memory area of a Special INTELLIGENT I/O READ IORD @IORD I/O Unit or CPU Bus Unit. IORD IORD(222) Symbol C: Control data S: Transfer source and number of words D: Transfer destination Applicable Program Areas Function block...
  • Page 792 3. Instructions Function IORD(222) reads the number of words designated in S+1 from the memory area of the Special I/O Unit or CPU Bus Unit whose unit number is designated by S and outputs the data to D. Only Special I/O Units or CPU Bus Units mounted on CPU Racks or Expansion I/O Racks can be designated.
  • Page 793 3. Instructions Example Programming In this example, IORD(222) is used to read data. When CIO 0.00 is turned ON, 10 words are read from the Special I/O 0.00 10.00 Unit with unit number 3, and are stored in D100 to D109. #A0003 D100 20.00...
  • Page 794 3. Instructions IOWR Function Instruction Mnemonic Variations Function code Outputs the contents of the CPU Unit's I/O mem- INTELLIGENT I/O WRITE IOWR @IOWR ory area to a Special I/O Unit or CPU Bus Unit. IOWR IOWR(223) Symbol C: Control data S: Transfer source and number of words D: Transfer destination and number of words Applicable Program Areas...
  • Page 795 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the number of words to transfer (D) is outside the range of 0001 to 0080 hex. • ON if the unit number (D) is outside the range of 0000 to 005F hex or 8000 to 800F hex. •...
  • Page 796 3. Instructions • When the input condition is met, self maintenance is performed by output A and IOWR(223) is executed with each cycle until the Equals Flag turns ON. When the writing is completed and the Equals Flag turns ON, output B turns ON and the self maintenance is cleared. •...
  • Page 797: Serial Communications Instructions

    3. Instructions Serial Communications Instructions Serial Communications Instructions There are two types of serial communications instruction. The TXD(236), RXD(235), TXDU(256), RXDU(255), DTXDU(262), and DRXDU(261) instructions send and receive data in no-protocol (custom) communications with an external device. PMCR(260)/PMCR2(264) sends and receives data using user-defined protocols with an external device.
  • Page 798 3. Instructions Instructions Mode Communications ports TXDU(256) No-protocol Serial Port of Serial Communications Unit with Unit Version 1.2 or Later (custom) Serial RXDU(255) Communications CPU Unit Unit TXDU(256)/ RXDU(255) RXDU(255) TXDU(256) DTXDU(262) No-protocol Serial Port of CJ1W-SCU22/SCU32/SCU42 Serial Communications Unit (custom) CJ2H CPU Unit Serial...
  • Page 799 3. Instructions  Auxiliary Area Words and Bits The Network Communications Instructions use the communications information in operand I in place of the Communications Port Enabled Flags in A202 used by previous instructions. Network Communications Instructions Auxiliary Area CJ2 Network Communications Instructions for CJ1/CS1/CJ2 A202.00 to A202.07 Communications Port Enabled Flag...
  • Page 800 3. Instructions PMCR Function Instruction Mnemonic Variations Function code Starts a communications sequence (protocol data) that is registered in a Serial Communications PROTOCOL MACRO PMCR @PMCR Board (CS Series only) or Serial Communications Unit. PMCR PMCR(260) C1: Control word 1 Symbol C2: Control word 2 S: First send word...
  • Page 801 3. Instructions Send area specification S: First Send Word and Send Area The first word of the words required to send data is specified. S contains the number of words to be sent +1 (i.e., including the S word) and send data starts in S+1. Between 0000 and 00FA hex (0 and 250 decimal) words can be sent.
  • Page 802 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers addresses Con- Pulse Area stants bits bits Indirect using IR C1, C2 *1 H512 to H1535 cannot be used. *2 In the EM Area, bank D and higher cannot be used. Flags Name Label...
  • Page 803 3. Instructions CPU Bus Unit Area n = 1500 + 25 x unit number Name Address Contents Port 1 Protocol Macro Execution Flag ON when PMCR(260) is executed. The flag will remain OFF if execution fails. Bit 15 of CIO n+9 The flag will turn OFF when the communications sequence has been completed Port 2 Protocol Macro Execution Flag Bit 15 of CIO n+19...
  • Page 804 3. Instructions Receive Area Not Held Communications sequence Recv Receive buffer Cleared Error Cleared data Receive area (starting at (all zeros) R+1) stored. Receive Area Held Communications sequence Receive buffer Cleared and Recv previous data stored Error Receive area (starting at R+1) Set data stored if no new data has been received...
  • Page 805 3. Instructions • The corresponding Protocol Macro Execution Flag will turn ON at the start of PMCR(260) execution. It will turn OFF after the communications sequence has been completed and data has been written to the specified receive area. A N.C. input for the corresponding Protocol Macro Execution Flag should be used as part of the execution condition whenever executing PMCR(260) to be sure that only one communications sequence is being executed at the same time for the same physical port.
  • Page 806 3. Instructions Example Programming When CIO 0.00 is ON in the following example, 0.00 1919.15 A202.07 communications sequence No. 101 (0065 hex) will be executed as long as the Communications Protocol Communica- Port Enabled Flag for port 7 (A20207) is ON and Macro tions Port Execution...
  • Page 807 3. Instructions Function Instruction Mnemonic Variations Function code Outputs the specified number of bytes of data from the CPU Unit's built-in RS-232C port or one TRANSMIT @TXD of the Serial Communications Board's serial ports. (The Serial Communications Board must be Ver. 1.2 or later).
  • Page 808 3. Instructions Flags Name Label Operation Error Flag • ON if the CPU Unit's RS-232C port is specified as the send port, but no-protocol mode is not set in the PLC Setup. • ON if one of the Serial Communication Board's serial ports is specified as the send port, but no-proto- col mode is not set in the port's allocated DM Setup Area.
  • Page 809 3. Instructions  PLC Setup Settings Programming Console address Name Settings Word No-protocol Mode Send Delay 0000 to 210F hex, 0 to 15 0 to 99,990 ms decimal (in 10-ms units) 8 to 15 No-protocol Mode Start Code 00 to FF hex 0 to 7 No-protocol Mode End Code 00 to FF hex...
  • Page 810 3. Instructions  Start code / end code settings and send data · Byte order 0: Upper to lower Upper byte Lower byte N bytes of data is sent in the following order when sending the most significant bytes first is specified: 1, 2, 3, 4, 5, 6 No Start or End Code ·...
  • Page 811 3. Instructions Example Programming  Sending Data to a Code Reader This example shows how to send data to the V530-R150V3 2D Code Reader as an example of communicating with an external device. Hardware Configuration Sync Sensor Monitor F150-M05L Power Supply Console (24 VDC) F150-KP...
  • Page 812 3. Instructions Programming Example If CIO 0.01 turns ON while the RS-232C Port Send Ready Flag (A392.05) is ON, three bytes of data starting from the upper byte of D10 are sent without conversion to the Code Reader connected to the CPU Unit's built-in RS-232C port.
  • Page 813 3. Instructions Function Instruction Mnemonic Variations Function code Reads the specified number of bytes of data from the CPU Unit's built-in RS-232C port or one of the RECEIVE @RXD Serial Communications Board's serial ports. (The Serial Communications Board must be Ver. 1.2 or later).
  • Page 814 3. Instructions Flags Name Label Operation Error Flag • ON if the CPU Unit's RS-232C port is specified as the send port, but no-protocol mode is not set in the PLC Setup. • ON if one of the Serial Communication Board's serial ports is specified as the send port, but no-proto- col mode is not set in the port's allocated DM Setup Area.
  • Page 815 3. Instructions  Auxiliary Area Flags for Serial Communication Board's Ports Port Name Address Contents Port 1 Reception Completed Flag A356.06 ON when no-protocol reception is completed. Number of Receive Bytes Specified: The flag will turn ON when the specified number of bytes has been received. End Code Specified: The flag will turn ON when the end code is received or when 256 bytes have been received.
  • Page 816 3. Instructions  PLC Setup Settings for CPU Unit's RS-232C Port Programming Console address Name Settings Word No-protocol Mode Send Delay 0000 to 210F hex, 0 to 15 0 to 99,990 ms decimal (in 10-ms units) 8 to 15 No-protocol Mode Start Code 00 to FF hex 0 to 7 No-protocol Mode End Code...
  • Page 817 3. Instructions • When more data is input to the Serial Communications Board's serial port than is specified in N, that data will be discarded when RXD(235) is executed. In contrast, extra data input to the CPU Unit's RS-232C port will not be discarded when RXD(235) is executed. •...
  • Page 818 3. Instructions  Start Code/End Code Settings and Receive Data No Start or End Code 1 2 3 4 5 6 0... Receive bytes: Specified in the PC Setup Only Start Code 1 2 3 4 5 6 0... Receive bytes after ST: Specified in the PC Setup Only End Code 1 2 3 4 5 6 0...
  • Page 819 3. Instructions Hint • When the RXD(235) instruction is used to read data in the CPU Unit's RS-232C port, the data after the stored number of bytes in the reception buffer is not cleared after the command is executed, so multiple RXD(235) instructions can be executed to receive a block of data in parts.
  • Page 820 3. Instructions Precautions • Do not enter a TXD instruction or RXD instruction for a serial port (port 1 or 2) of the serial communication board in both a cyclic task and an interrupt task. If an interrupt task is started during the execution of a TXD instruction or RXD instruction for a serial port (port 1 or 2) of the serial communication board in a cyclic task, the TXD instruction or RXD instruction for a serial port (port 1 or 2) of the serial communication board cannot be executed in the interrupt task.
  • Page 821 3. Instructions Example Programming  Receiving data This example shows how to receive data from the V530-R150V3 2D Code Reader as an example of communicating with an external device. Hardware Configuration Sync Sensor Monitor F150-M05L Power Supply Console (24 VDC) F150-KP Console Cable RS-232C Cable...
  • Page 822 3. Instructions Programming Example If CIO 0.02 turns ON while the RS-232C Port Send Ready Flag (A392.05) is ON, the number of bytes of reading results specified in the RS-232C Port Reception Counter (A393) are read from the Code Reader connected to the CPU Unit's built-in RS-232C port and stored starting from the upper byte of D100.
  • Page 823 3. Instructions TXDU Function Instruction Mnemonic Variations Function code Outputs the specified number of bytes of data TRANSMIT VIA SERIAL from one of the Serial Communications Unit's TXDU @TXDU COMMUNICATIONS UNIT serial ports. (The Serial Communications Unit must be Ver. 1.2 or later). TXDU TXDU(256) S: First source word...
  • Page 824 3. Instructions Flags Name Label Operation Error Flag • ON if all of the logical ports are being used or the Communications Port Enabled Flag for the speci- fied logical port is OFF when the instruction is executed. • ON if the value of C is not within range. •...
  • Page 825 3. Instructions Related Flags in the CPU Bus Unit Area  (n = CIO 1500 + 25 × unit number) Word Name Status Port 1 Port 2 TXDU Instruction Executing Flag 0: TXDU(256) is not being executed. n+19 1: TXDU(256) is being executed. Function •...
  • Page 826 3. Instructions  Start code / end code settings and send data · Byte order 0: Upper to lower Upper byte Lower byte N bytes of data is sent in the following order when sending the most significant bytes first is specified: 1, 2, 3, 4, 5, 6 No Start or End Code ·...
  • Page 827 3. Instructions Hint • Depending on the external device, it might be necessary to set a send delay when sending data with TXDU(256). If a send delay is required, set or adjust the delay time in the allocated DM Setup Area. Precautions •...
  • Page 828 3. Instructions Example Programming When CIO 0.00 is ON, A202.03 (the Communications Port Enabled Flag) is ON, and CIO 1559.05 (the TXDU Instruction Executing Flag for port 1) is OFF in the following example, TXDU(256) outputs data through serial port 1 of the Serial Communications Unit with unit number 2. The 5 bytes of output data are read from the DM Area beginning at the rightmost byte of D100 and output through logical port 3 to a general-purpose device such as a printer.
  • Page 829 3. Instructions  Performing RS and ER signal control 0.01 When 0.01 is ON, bit 15 of D300 is applied to TXDU the RS signal, and bit 14 will be used as the ER signal. D300 D400 &0 15 14 13 12 S:D300 1 0 0 0 Switches the ER signal to 0...
  • Page 830 3. Instructions RXDU Function Instruction Mnemonic Variations Function code Reads the specified number of bytes of data from RECEIVE VIA SERIAL one of the Serial Communications Unit's serial RXDU @RXDU COMMUNICATIONS UNIT ports. (The Serial Communications Unit must be Ver. 1.2 or later). RXDU RXDU(255) D: First destination word...
  • Page 831 3. Instructions Flags Name Label Operation Error Flag • ON if all of the logical ports are being used or the Communications Port Enabled Flag (A202.00 to A202.07) for the specified logical port is OFF when the instruction is executed. •...
  • Page 832 3. Instructions Related Flags in the CPU Bus Unit Area  (n = CIO 1500 + 25 × unit number) Word Function Port 1 Port 2 Overrun Error Flag 1: The reception buffer contained more than 259 bytes of data before RXDU(255) was executed. n+18 Note: Once this error flag goes ON, it can be turned OFF only by turning the power OFF and then ON again or restarting the Board.
  • Page 833 3. Instructions 3) If CS and DR signal monitoring is specified in C, the status of the CS signal will be stored in bit 15 of D and the status of the DR signal will be stored in bit 14 of D. •...
  • Page 834 3. Instructions  Start Code/End Code Settings and Send Data No Start or End Code 1, 2, 3, 4, 5, 6... Number of bytes (Specified in allocated Only Start Code DM Setup Area) 1, 2, 3, 4, 5, 6... Number of bytes Only End Code (Specified in allocated DM Setup Area)
  • Page 835 3. Instructions  Flag Operation End code or specified number of bytes received. Reception Port reception processing processing Serial Communications Unit Reception Completed Flag (n+9/n+19 bit 06, n = CIO 1500 + 25 x unit number) Instruction RXDU instruction executed. CPU Unit Communications Enabled Flag (logical ports 0 to 7: A202 bits 00 to 07)
  • Page 836 3. Instructions Example Programming When CIO 0.00 is ON, A202.03 (the Communications Port Enabled Flag) is ON, and CIO 1559.06 (the Reception Completed Flag for port 1) is ON in the following example, RXDU(255) reads the data received through serial port 1 of the Serial Communications Unit with unit number 2. (Logical communications port number 3 is used to receive the data from a general-purpose device such as a bar-code reader.) The 10 bytes of received data are written to the DM Area beginning at the rightmost byte of D100.
  • Page 837 3. Instructions DTXDU Function Instruction Mnemonic Variations Function code Outputs the specified number of bytes of data from the serial port of a CJ1W- SCU22/SCU32/SCU42 Serial Communications Unit. The data is output in no-protocol mode from DIRECT TRANSMIT VIA the specified first word with the start code and end SERIAL COMMUNICATIONS DTXDU @DTXDU...
  • Page 838 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the value of C is not within range. • ON if the value for N is not between 0000 and 0100 hex. • ON if execution of DRXDU(261)/DTXDU(262) in a cyclic task is interrupted by an interrupt task and DTXDU(262) is also executed in the interrupt task.
  • Page 839 3. Instructions Related Flags in the CPU Bus Unit Area  (n = CIO 1500 + 25 × unit number) Word Name Status Port 1 Port 2 n+19 DTXDU Send Ready Flag ON: Ready to send, OFF: Sending not possible Function •...
  • Page 840 3. Instructions  Start code / end code settings and send data · Byte order 0: Upper to lower Upper byte Lower byte N bytes of data is sent in the following order when sending the most significant bytes first is specified: 1, 2, 3, 4, 5, 6 No Start or End Code ·...
  • Page 841 3. Instructions • DTXDU(262) will not be executed while the DTXDU(262) Send Ready Flag (n+9/n+19 bit 04) is OFF (n = CIO 1500 + 25 × unit number). Use the DTXDU(262) Send Ready Flag in an NO input condition for DTXDU(262). Example Programming In the following sample, if CIO 0.00 is turned ON while the DTXDU(262) Send Ready Flag (CIO 1559.04) is ON, 5 bytes of data starting from the lower byte of D100 will be sent to the external device...
  • Page 842 3. Instructions  Performing RS and ER signal control 1519.04 0.01 DTXDU When 0.01 is ON, bit 15 of D300 is applied to the RS signal, DTXDU instruction D300 and bit 14 is applied to the ER signal. send ready flag D400 (Unit No.
  • Page 843 3. Instructions DRXDU Function Instruction Mnemonic Variations Function code Reads the specified number of bytes of data from the serial port of a CJ1W-SCU22/SCU32/SCU42 Serial Communications Unit to CPU Unit memory starting at the specified first word. The data is read DIRECT RECEIVE VIA in no-protocol mode with the start code and end SERIAL COMMUNICATIONS...
  • Page 844 3. Instructions Flags Name Label Operation Error Flag P_ER • ON if the value of C is not within range. • ON if the value for N is not between 0000 and 0100 hex. • ON if execution of DTXDU(262)/DRXDU(261) in a cyclic task is interrupted by an interrupt task and DRXDU(261) is also executed in the interrupt task.
  • Page 845 3. Instructions Related Flags in the CPU Bus Unit Area  (n = CIO 1500 + 25 × unit number) Word Function Port 1 Port 2 Overrun Error Flag 1: The reception buffer contained more than 259 bytes of data before RXD(235), RXDU(255), or n+18 DRXDU(261) was executed.
  • Page 846 3. Instructions • Specification of monitor in bits 4 to 7 of C for the CS and DR signals takes effect as follows: 1) If CS signal monitoring is specified in C, the status of the CS signal will be stored in bit 15 of D. 2) If DR signal monitoring is specified in C, the status of the DR signal will be stored in bit 15 of D.
  • Page 847 3. Instructions  Start Code/End Code Settings and Send Data No Start or End Code 1, 2, 3, 4, 5, 6... Number of bytes (Specified in allocated Only Start Code DM Setup Area) 1, 2, 3, 4, 5, 6... Number of bytes Only End Code (Specified in allocated DM Setup Area)
  • Page 848 3. Instructions Hint • Execute RXDU(255) to read the received data from the buffer when the Reception Completed Flag (in the allocated DM Setup Area) is ON. Precautions • DRXDU(261) can be executed only for serial ports on a CJ1W-SCU22/SCU32/SCU42 Serial Communications Unit.
  • Page 849 3. Instructions Example Programming Using DRXDU(261) in Cyclic Tasks When CIO 0.00 is ON and CIO 1559.06 (the Reception Completed Flag for port 1) is ON in the following example, DRXDU(255) reads the data received from the general-purpose device connected to serial port 1 of the Serial Communications Unit with unit number 2.
  • Page 850 3. Instructions Using DRXDU(261) in Interrupt Tasks This example shows how to start interrupt task 5 in the CPU Unit when 10 bytes of data is received from an external device (e.g., a barcode reader) connected to the Serial Communications Unit with unit number 2 and store the data in memory starting from the lower byte of D00100.
  • Page 851 3. Instructions STUP Function Instruction Mnemonic Variations Function code Changes the communications parameters of a CHANGE SERIAL PORT serial port on the CPU Unit, Serial Communica- STUP @STUP SETUP tions Board (CS Series only), or Serial Communi- cations Unit (CPU Bus Unit). STUP STUP(237) Symbol...
  • Page 852 3. Instructions Related Auxiliary Area Words and Bits Name Address Contents Peripheral Port Parameters Changing Flag A619.01 ON when the communications parameters are being changed for the peripheral port. RS-232C Port Parameters Changing Flag A619.02 ON when the communications parameters are being changed for the RS- 232C port.
  • Page 853 3. Instructions Communication Mode Word Settings Periph- Serial Serial PLC Serial PLC Host Link NT Link No-protocol eral Bus gateway Link (master) Link (slave) +160 Any setting 0: Standard 1: Any setting 8 to 11 Communication 0 hex: Host Link Mode 2 hex: NT Link 3 hex: No-protocol...
  • Page 854 3. Instructions Hint • Use STUP(237) to change communications parameter for a port during operation based on specified conditions. For example, STUP(237) can be used to change to Host Link communications for monitoring and programming from a host computer when specified conditions are meet while execution a communications sequence for a modem connection.
  • Page 855 3. Instructions PMCR2 Function Instruction Mnemonic Variations Function code Starts a communications sequence (protocol data) PROTOCOL MACRO 2 PMCR2 @PMCR2 that is registered in a Serial Communications Unit. PMCR2 PMCR2(264) C1: Control word 1 Symbol C2: Control word 2 S: First send word R: First receive word I: First communications information word Applicable Program Areas...
  • Page 856 3. Instructions  Receive Area Specification R: First receive word • Executing a Protocol Macro • Setting before Executing PMCR2 The number of words of data that was Set the data specified by m (beginning with R) as received is automatically stored here. 0 to 250 decimal (0000 to 00FA hex) the initial data for the receive buffer (backup data for receive failure).
  • Page 857 3. Instructions Communications Responses Code Contents No corresponding program number 1106 (hex) • Specified Send/Receive Sequence No. that has not been registered. • Modify the Send/Receive Sequence No. or add the number using the CX-Programmer. Not operable due to protocol execution 2201 (hex) Since one protocol macro has already been executed, no further execution is accepted.
  • Page 858 3. Instructions Example: The following programming example shows the instructions used to constantly or periodically execute PMCR2(264) to read data through a single receive operation. Communications Always ON Protocol Macro Port Enabled Flag Flag Execution Flag PMCR2 Receive buffer Data that was set will be transfer if new data is not successfully received.
  • Page 859 3. Instructions Serial Communications Units Serial Communications Board (CS Series only) Serial Port 1, 2 E1 hex (CS Series only) Unit address Unit No. + 10 hex • The corresponding Protocol Macro Execution Flag will turn ON at the start of PMCR2(264) execution. It will turn OFF after the communications sequence has been completed and data has been written to the specified receive area.
  • Page 860 3. Instructions Note PMCR2(264) is used to start a communications sequence. Use the Sequence End Completion Flag in the CIO Area words that are allocated to the Serial Communications Unit to determine when execution of the communications sequence has ended normally. Protocol Macro Execution Flag 0.00...
  • Page 861: Network Instructions

    3. Instructions Network Instructions Network Instructions Overview of Network Communications Instructions The network instructions can be divided into two types, SEND(090)/SEND2(491)/RECV(098)/RECV2(492) and CMND(490)/CMND2(493). These instructions are transmitted between Units (CPU Units, CPU Bus Units, and computers) in a network to transfer data and control operation, such as changing the operating mode.
  • Page 862 3. Instructions CPU Unit CPU Bus Unit Inner Board Computer Unit address 00 hex Unit number +10 hex E1 hex 01 hex Node number Node number Node number Destination device Node number  Unit Addresses It is also possible to directly specify a serial port (port 1 to 4) within the destination device. Serial Communications Unit CPU Unit Inner Board...
  • Page 863 3. Instructions Network Communications Patterns Communications with Another Device on the Network The following example shows communications from a PLC to devices in another PLC (the CPU Unit, CPU Bus Unit, or Inner Board). For more details, refer to the operation manual for the network (Controller Link or Ethernet) being used.
  • Page 864 3. Instructions In order to communicate through the network, it is necessary to register a routing table in each PLC's CPU Unit which indicates the route by which data will be transferred to the desired node. Each routing table is made up of a local network table and a relay network table. •...
  • Page 865 3. Instructions Serial Gateway Communications with a Component or Host Link Slave It is possible to send FINS commands (or send/receive data) to a component or Host Link Slave connected to the PLC through its serial port with the serial gateway function. •...
  • Page 866 3. Instructions Network Communications Instructions With CS/CJ-series PLCs, up to eight Network Communications Instructions can be executed simultaneously. With CJ2-series PLCs, up to 64 Network Communications Instructions can be executed simultaneously for some instructions. These instructions are called CJ2 Network Communications Instructions.
  • Page 867 3. Instructions Communications Flags The operation of the communications flags is outlined below. • The Communications Port Enabled Flag is turned OFF when communications are in progress and turned ON when communications are completed (normally or not). • The status of the Communications Port Error Flag is maintained until the next time that data is transmitted or received.
  • Page 868 3. Instructions Execution Timing of Network Communications Instructions When the execution condition for a Network Communications Instruction is ON, processing communications is started, but actual communications are processed in the background using peripheral servicing. Background processing of communications Specifies only Execution Communications Port Cycle...
  • Page 869 3. Instructions Network Communications Instructions for CJ1/CS1/CJ2 Communications Ports There are 8 logical communications ports provided, so 8 communications instructions can be executed simultaneously. Only one instruction can be executed at a time for each communications port. Exclusive control must be used when more than 8 instructions are executed. These 8 communications ports are shared by the network instructions (SEND(090), SEND2(491), RECV(098), RECV2(492), CMND(490), CMND2(493), etc.), the serial communications instructions (TXDU(256) and RXDU(255)), and the PROTOCOL MACRO instruction (PMCR(260) and...
  • Page 870 3. Instructions Example When Not Using Automatic Port Allocation Exclusive control was required by the user when the same communications port was used more than once. Confirmation of the availability of a communications port was required using the corresponding Communications Port Enabled Flag, here for port 0. Execution condition (Executing)
  • Page 871 3. Instructions Ladder Programming Examples  Specifying Communications Ports Execution condition a (Executing) is turned ON and held ON when the A202.00 execution condition and Communications Port KEEP Enabled Flag (A202.00) turn ON. (Executing) a (Executing) is turned OFF when d (Execution d (Execution completed) completed) turns ON The network communications instruction is executed when a (Executing)
  • Page 872 3. Instructions User Specification of Communications Ports The communications port can be specified in the control data of the Network Communications Instruction. The same communications port cannot be used in any other instruction until processing this instruction has been completed. Exclusive control of the communications port is necessary. ...
  • Page 873 3. Instructions Application Methods 1. Set the communications port in the instruction operand to 0 to 7 hex. 2. Use the Communications Port Enabled Flag (A202.00 to A202.07) to perform exclusive control of the communications port. Bit A remains ON while the communications KEEP A instruction is being executed.
  • Page 874 3. Instructions Automatic Allocation of Communications Ports  Overview Each of the following instructions use one of the communications ports (0 to 7) to perform network communications or serial communications. • Network Communications Instructions (SEND, RECV, and CMND) • Serial Communications Instructions (PMCR, TXDU, and RXDU) The above instructions are collectively referred to as communications instructions.
  • Page 875 3. Instructions Applications Methods 1. Set the communications port in the instruction operand to F hex. 2. Program the ladder diagram as shown below.  Completing and Processing Errors after Executing Communications Instructions Execution condition KEEP (Executing) d (Execution completed) a (Executing) When a (Executing) turns ON, a communications instruction Communications...
  • Page 876 3. Instructions  Accessing the Completion Code after Executing Communications Instructions The completion codes are generally used to troubleshoot errors when they occur. A completion code of 0000 hex can, however, also be used to confirm that communications have been completed normally. Execution condition KEEP (Executing)
  • Page 877 3. Instructions Note 1 If you use communications instructions inside interrupt tasks (regardless of whether you specify communications ports or use automatic port allocation), use the DI and EI instructions to prohibit executing interrupt tasks when exe- cuting communications instructions with automatic port allocation in cyclic tasks, as shown below. Cyclic Task a (Executing) @Communications...
  • Page 878 3. Instructions 3 It is acceptable to specify the communications port for some communications instructions and use automatic port allocation for others. It is possible, however, that a port specified by the user for one communications instructions may have already been automatically allocated. You must therefore be careful when adding communications instruc- tions that use automatic port allocation to existing ladder diagrams, as shown below.
  • Page 879 3. Instructions  Auxiliary Area Words and Bits The CJ2 Network Communications Instructions use the communications information in operand I in place of the Communications Port Enabled Flags in A202 used by previous instructions. Network Communications Instructions Auxiliary Area CJ2 Network Communications Instructions for CJ1/CS1/CJ2 A202.00 to A202.07 Communications Port Enabled Flag...
  • Page 880 3. Instructions  Explicit Message Instructions The following instructions, which are used specially for explicit messages, are called Explicit Message Instructions. Mnemonic Instruction Name Outline EXPLT (720) EXPLICIT MESSAGE SEND Sends an explicit message with any service code. Note Functionally, this instruction is the same as sending CMND(490) or CMND2(493) with a FINS command code of 2801 hex.
  • Page 881 3. Instructions  Normal End An explicit message is sent and a normal response is returned. The corresponding Explicit Communications Error Flag (A213.00 to A213.07: Communications ports 0 to 7) will be OFF and the Communications Port Completion Code (A203 to A210: Communications ports 0 to 7) will contain the explicit message normal completion code of 0000 hex.
  • Page 882 3. Instructions Communications Flags Communications Port Enabled Flag Instruction Instruction Explicit Message being executed being executed Instruction Explicit Communications Error Flag Communications Port Error Flag Communications Port Previous 0000 hex FINS end code 0000 hex Completion Code b) When the Explicit Message Was Sent But an Explicit Error Response Was Returned In this case, the explicit message was sent but an error existed in the explicit message command frame (code not supported, illegal size, etc.).
  • Page 883 3. Instructions Ladder Programming Examples  User Specification of Communications Ports Communications Port Execution Enabled Flag a (Executing) is turned ON and held ON when the A202.00 condition execution condition and Communications Port KEEP Enabled Flag (A202.00) turn ON. a (Executing) is turned OFF when d (Execution a (Executing) d (Execution completed) completed) turns ON.
  • Page 884 3. Instructions  Automatically Allocating Communications Ports (i.e., Internal Logical Ports) Execution condition KEEP a (Executing) d (Execution completed) The explicit message instruction is executed when a (Executing) a (Executing) turns ON. The port number F is specified. Explicit message instruction Port: F The automatically allocated port number stored in A218 (Used...
  • Page 885 3. Instructions SEND Function Instruction Mnemonic Variations Function code NETWORK SEND SEND @SEND Sends data to a node in the network. SEND SEND(090) S: First source word (local node) Symbol D: First destination word (remote node) C: First control word Applicable Program Areas Function block SFC action or...
  • Page 886 3. Instructions Resend times #0 to F (0 to 15) #0: Fixed Logical port number #0 to 7 (#F: automatic allocation) Response needed / not needed (See note 5.) #0: Response needed #9: Response not needed Response monitor time &1 to 65535 (#0001 to FFFF hex) 0.1 to 6553.5 sec #0000:2s (default value) Note 1 The following two methods can be used to send data to the host computer through a serial port with the host link...
  • Page 887 3. Instructions 5 The unit address indicates the Unit, as shown in the following table. Unit Unit address setting CPU Unit 00 hex CPU Bus Unit 10 hex + unit number Special I/O Unit (except C200H-series Special I/O Units) 20 hex + unit number Inner Board (CS Series only) E1 hex Computer...
  • Page 888 3. Instructions Function SEND(090) transfers the data beginning at word S to addresses beginning at D in the designated device through the PLC’s CPU Bus or over a network. The number of words to be transmitted is specified in C. Local node Destination node Number...
  • Page 889 3. Instructions  Sending Data to a Host Link Slave PLC Connected by Serial Gateway The serial gateway function can be used to send data to a PLC connected as a host link Slave to a Serial SEND Communications Board or Unit. In this case, the destination node address must be set to the host link unit number + 1.
  • Page 890 3. Instructions Precaution • Only one network instruction may be executed for a communications port at one time. To ensure that SEND(090) is not executed while a port is busy, program the port’s Communications Port Enabled Flag (A202.00 to A202.07) as a normally open condition. •...
  • Page 891 3. Instructions SEND2 Function Instruction Mnemonic Variations Function code NETWORK SEND 2 SEND2 @SEND2 Sends data to a node on a network. SEND2 SEND2 S: First source word Symbol D: First destination word C: First control word I: First communications information word Applicable Program Areas Function block SFC action or...
  • Page 892 3. Instructions C: First Control Word I: First communications information word Clear D and I words before executing the instruction. Number of send words 0001 to maximum data length (hex) System work Execution Completed Flag (Depends on network, for example area 0: Not completed.
  • Page 893 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON if the serial port number specified in C+1 is not between 0 and 4 hex. •...
  • Page 894 3. Instructions Example Programming If CIO 0.00 (start bit) and A202.08 (CJ2 Instructions Enabled Flag) are ON, W10.00 (executing) will turn When W10.00 (Executing) turns ON, the ten words of data starting from D100 (D100 to D109) are sent to the CPU Unit with node number 3 in the local network where they are written to ten words starting from D200 (D200 to D209).
  • Page 895 3. Instructions RECV Function Instruction Mnemonic Variations Function code Requests data to be transmitted from a node in NETWORK RECEIVE RECV @RECV the network and receives the data. RECV RECV(098) S: First source word (remote node) Symbol D: First destination word (local node) C: First control word Applicable Program Areas Function block...
  • Page 896 3. Instructions C+ 3 Resend times #0 to F (0 to 15) #0: Fixed Logical port number #0 to 7 (#F: automatic allocation) Response needed / not needed #0: Fixed at response needed (Response is fixed to "required.") C+ 4 Response monitor time &1 to 65535 (#0001 to FFFF hex) 0.1 to 6553.5 sec...
  • Page 897 3. Instructions 5 Unit address • CPU Unit: 00 hex • CPU Bus Unit: 10 hex + unit number • Special I/O Unit (except C200H-series Special I/O Units): 20 hex + unit number • Inner Board (CS Series only): E1 hex •...
  • Page 898 3. Instructions Function RECV(098) requests the number of words specified in C beginning at word S to be transferred from the designated device to the local PLC. The data is received through the PLC's CPU Bus or over the network and written to the PLC's data area beginning at D. Local node Source node (remote node) Number of words...
  • Page 899 3. Instructions  Receiving Data from a Host Link Slave PLC Connected by Serial Gateway The serial gateway function can be used to receive data from a PLC connected as a host link Slave to a RECV Serial Communications Board or Unit. In this case, the source node address must be set to the host link unit number + 1.
  • Page 900 3. Instructions RECV2 Function Instruction Mnemonic Variations Function code Requests data to be transmitted from a node in NETWORK RECEIVE 2 RECV2 @RECV2 the network and receives the data. RECV2 RECV2 S: First source word Symbol D: First destination word C: First control word I: First communications information word Applicable Program Areas...
  • Page 901 3. Instructions C: First Control Word I: First communications information word Clear D and I words before executing the instruction. Number of words to receive 0001 to maximum data length (hex) System work Execution Completed Flag (Depends on network, for example area 0: Not completed.
  • Page 902 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON if the serial port number specified in C+1 is not between 0 and 4 hex. •...
  • Page 903 3. Instructions Example Programming If CIO 0.00 (start bit) and A202.08 (CJ2 Instructions Enabled Flag) are ON, W10.00 (executing) will turn When W10.00 (Executing) turns ON, the ten words of data starting from D100 (D100 to D109) are received from the CPU Unit with node number 3 in the same network and written to ten words starting from D200 (D200 to D209) at the local node.
  • Page 904 3. Instructions CMND Function Instruction Mnemonic Variations Function code Sends an FINS command and receives the DELIVER COMMAND CMND @CMND response. CMND CMND(490) S: First command word Symbol D: First response word C: First control word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 905 3. Instructions Destination unit address (See note 6) #00 to FE hex Destination node address (See note 5) 00 to maximum node address (hex) (Depends on the network. Example: In the case of Controller Link, #00 to 20 hex (0 to 32)) #FF: Broadcast Resend times #0 to F (0 to 15)
  • Page 906 3. Instructions • CPU Unit Ports Port Port’s unit address Peripheral FD hex (253 decimal) RS-232C FC hex (252 decimal) 3 When specifying the serial port without a routing table for the serial gateway function (conversion to host link FINS), set the serial port's unit address in the source network address byte.
  • Page 907 3. Instructions Related Auxiliary Area Words and Bits Name Address Operation Communications Port Enabled A202.00 to These flags are turned ON to indicate that network instructions, including PMCR(260) may be executed Flag A202.07 for the corresponding ports (00 to 07). A flag is turned OFF when a network instruction is being executed for the corresponding port and turned ON again when the instruction is completed.
  • Page 908 3. Instructions • Destination node address (bits 08 to 15 of C+3): 00 hex (local node) • Number of retries (bits 00 to 03 of C+4): 0 hex (this setting is invalid; set it to 0) • Response monitoring time: (bits 00 to 15 of C+5): 0000 to FFFF hex (but 0000 will specify 6553.5 s, and not 2 s as normal) •...
  • Page 909 3. Instructions • Sending to a PLC operating as a Host Link Slave SEND The serial gateway function can be used to send any FINS command to a PLC that is connected as a host link slave and through a Serial Communi- cations Board or Unit’s serial port.
  • Page 910 3. Instructions Precaution • To ensure that CMND(490) is not executed while a port is busy, program the port's Communications Port Enabled Flag (A202.00 to A202.07) as a normally open condition. Note Refer to Automatically Allocating Communications Ports (i.e., Internal Logical Ports) in SECTION 3 Instruc- tions - Network Instructions for details on using automatic allocation of the communications port number (logical port).
  • Page 911 DIRECTORY) to the local CPU Unit. The response is stored in D100 to D101. Here, the FINS command will create a directory called CS/CJ under the OMRON directory. The command code (2 bytes) and the end code (2 bytes) will be returned and stored as the response.
  • Page 912 3. Instructions CMND2 Function Instruction Mnemonic Variations Function code Sends an FINS command and receives the DELIVER COMMAND 2 CMND2 @CMND2 response. CMND2 CMND2 S: First command word Symbol D: First response word C: First control word I: First communications information word Applicable Program Areas Function block SFC action or...
  • Page 913 3. Instructions C: First Control Word I: First communications information word Clear D and I words before executing the instruction. Bytes of command data (See note 1.) 0002 to maximum data length (hex) System work Execution Completed Flag The maximum data length for command area 0: Not completed.
  • Page 914 3. Instructions The serial port unit address are as follows: • Serial Communications Units: × Port 1: 80 hex + 04 hex unit number × Port 2: 81 hex + 04 hex unit number • Serial Communications Boards: Port 1: E4 hex (228 decimal) Port 2: E5 hex (229 decimal) •...
  • Page 915 (CREATE/DELETE SUBDIRECTORY) is set to the local CPU Unit and the response is stored in D100 and D101. The FINS command creates a director called “CS1” in the “OMRON” directory in the Memory Card in the CPU Unit. The command code 2215 hex (2 bytes) and the 2-byte end code are returned as the response.
  • Page 916 3. Instructions EXPLT Function Instruction Mnemonic Variations Function code EXPLICIT MESSAGE SEND EXPLT @EXPLT Sends an explicit message with any service code. EXPLT EXPLT(720) S: First word of send message Symbol D: First word of received message C: First control word Applicable Program Areas Function block SFC action or...
  • Page 917 3. Instructions S: First word of send message D: First word of received message Contains the number of bytes of data from words D+1 on. Set the number of bytes of source data from words S+1 on. For Does not include the 2 bytes in word D itself. example, set S to 000A hex if there are 5 words of data (S+1 to This value does include the leftmost bytes of D+1 and D+2, which contain 00.
  • Page 918 3. Instructions C: First control word Set the total number of words of response data beginning at D. The allowed setting range is 0 to 010E hex (270 words). Note If the number of words of received data exceeds the value set here, a FINS error will occur (response too long, code 11 0B) and no data at all will be stored (in the area starting at D+3).
  • Page 919 3. Instructions Related Auxiliary Area Words and Bits The corresponding Explicit Communications Error Flag will be OFF if the instruction ended normally or ON if an error occurred. If an error occurred (corresponding flag in A213 ON), the corresponding Communications Port Error Flag can be used to determine whether the explicit message itself was not sent (corresponding flag in A219 ON) or that the message was sent but there was an error in the message (corresponding flag in A219 OFF).
  • Page 920 3. Instructions • Storing Data from the Rightmost Byte Set bits 12 to 15 of C+1 to 8 hex. Frame (order of data in line) Stored from rightmost byte. Data area 08 07 Note: A, B, C, and D represent bytes of data. Precaution Be sure that the order of bytes in the source data Command format...
  • Page 921 3. Instructions Example Programming In this example, EXPLT(720) is used to read the total ON time or number of contact operations from a DRT2 Slave (I/O Terminal). When CIO 0.00 and A202.06 (the Communications Port Communications Port Enabled Flag for port 06) are ON, EXPLT(720) reads the Enabled Flag (Port 6) A202.06 0.00...
  • Page 922 3. Instructions EGATR Function Instruction Mnemonic Variations Function code Sends an information/status read command in an EXPLICIT GET ATTRIBUTE EGATR @EGATR explicit message (Get Attribute Single, Service Code: 0E hex). EGATR EXPLT(720) EGATR(721) S: First word of send message S: First word of send message Symbol D: First word of received message D: First word of received message...
  • Page 923 3. Instructions C: First control word Set the maximum number of words of data in the received data beginning at D. The allowed setting range is 0 to 010C hex (268 words). If the number of words of received data exceeds the value set here, a FINS error will occur (response too long, code 11 0B) and no data at all will be stored (in the area starting at D+3).
  • Page 924 3. Instructions Related Auxiliary Area Words and Bits The corresponding Explicit Communications Error Flag will be OFF if the instruction ended normally or ON if an error occurred. If an error occurred (corresponding flag in A213 ON), the corresponding Communications Port Error Flag can be used to determine whether the explicit message itself was not sent (corresponding flag in A219 ON) or that the message was sent but there was an error in the message (corresponding flag in A219 OFF).
  • Page 925 3. Instructions • Storing Data from the Rightmost Byte Set bits 12 to 15 of C+1 to 8 hex. Frame (order of data in line) Stored from rightmost byte. Data area 08 07 Note: A, B, C, and D represent bytes of data. Precaution Be sure that the order of bytes in the source data Command format...
  • Page 926 3. Instructions Example Programming In this example, EGATR(721) is used to read the general status of a DRT2 Slave (I/O Terminal). When CIO 0.00 and A202.06 (the Communications Port Communications Port Enabled Flag for port 06) are ON, EGATR(721) reads the Enabled Flag (Port 6) A202.06 0.00...
  • Page 927 3. Instructions ESATR Function Instruction Mnemonic Variations Function code Sends an information write command in an explicit EXPLICIT SET ATTRIBUTE ESATR @ESATR message (Set Attribute Single, Service Code: 10 hex). ESATR ESATR(722) Symbol S: First word of send message C: First control word Applicable Program Areas Function block SFC action or...
  • Page 928 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag P_ER • ON if the Communications Port Enabled Flag is OFF for the communications port number specified in •...
  • Page 929 3. Instructions • Storing Data from the Leftmost Byte Set bits 12 to 15 of C+1 to 0 hex. Frame (order of data in line) Data Stored from leftmost byte. area 08 07 Note: A, B, C, and D represent bytes of data. •...
  • Page 930 3. Instructions • Storing Data from the Rightmost Byte (Bits The data in the frame is in the order 78 → 56 → 34 → 12. 12 to 15 of C = 8 hex) Example: Storing the value 12345678 hex Frame in S+5 and S+6 In this case, 12345678 hex is...
  • Page 931 3. Instructions ECHRD Function Instruction Mnemonic Variations Function code Reads data to the local CPU Unit from another EXPLICIT WORD READ ECHRD @ECHRD CPU Unit in the network. (The remote CPU Unit must support explicit messages.) ECHRD ECHRD(723) S: First source word in remote CPU Unit Symbol D: First destination word in local CPU Unit C: First control word...
  • Page 932 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR * The D bank and higher of the EM Area can be specified only for CJ2 CPU Units. The D bank and higher cannot be specified in the program in a CS/CJ-series CPU Unit even if the source is a CJ2 CPU Unit.
  • Page 933 3. Instructions Hint • ECHRD(723) sends an explicit message with the Service Code 1C hex (Byte Data Read). Example Programming In this example, ECHRD(723) is used to read the I/O memory of the CJ-series CPU Unit on the DeviceNet network, and store the data in the I/O memory of the local CPU Unit. When CIO 0.00 and A202.06 (the Communications Port Communications Enabled Flag for port 06) are ON, ECHRD(723) reads...
  • Page 934 3. Instructions ECHWR Function Instruction Mnemonic Variations Function code Writes data from the local CPU Unit to another EXPLICIT WORD WRITE ECHWR @ECHWR CPU Unit in the network. (The remote CPU Unit must support explicit messages.) ECHWR ECHWR(724) S: First source word in local CPU Unit Symbol D: First destination word in remote CPU Unit C: First control word...
  • Page 935 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR * The D bank of the EM Area can be specified only for CJ2 CPU Units. The D bank and higher cannot be specified in the pro- gram in a CS/CJ-series CPU Unit even if the destination is a CJ2 CPU Unit.
  • Page 936 3. Instructions Hint • ECHWR(724) sends an explicit message with the Service Code 1E hex (Byte Data Write). Example Programming In this example, ECHWR(724) is used to write data from the I/O memory of the local CPU Unit to the I/O memory of a CJ-series CPU Unit on the DeviceNet network.
  • Page 937: File Memory Instructions

    3. Instructions File Memory Instructions File Memory Instructions User Instructions for File Memory Operations  Overview • The FWRIT(701) (WRITE DATA FILE)/TWRIT(704) (WRITE TEXT FILE) instruction can be used to create a data file containing the specified I/O memory data in a Memory Card or EM file memory. It can also add to or overwrite from any point in existing files.
  • Page 938 3. Instructions FREAD(700) and FWRIT(701) Operands Bits in C Settings Programming Device limitations 12 to 15 Data type 0 and 6 hex 0: Binary (.IOM) 1: Non-delimited words (.TXT) 2: Non-delimited double-words (.TXT) 3: Comma-delimited words (.CSV) 4: Comma-delimited double-words (.CSV) 5: Tab-delimited words (.TXT) 6: Tab-delimited double-words (.TXT) 08 to 11...
  • Page 939 3. Instructions  CMND(490): DELIVER COMMAND Instruction Name Mnemonic Operation DELIVER COMMAND CMND CMND(490) can be used to issue a FINS command to the local CPU Unit itself to perform file (490) memory operations such as formatting or deleting files. Note Make the following settings in CMND(490)'s control words: Destination network address: 00 hex (local network), Serial port: 0 hex (not used), Destination unit address: 00 hex (CPU Unit), Destination node address: 00 hex (local node), Retries: 0 hex (Set to 0 because retrying...
  • Page 940 (for port 7) D100 In this case, the FINS command creates a subdirectory named "CS1" within the OMRON directory in the CPU Unit's Memory Card. The response is composed of the 2-byte command code (2215) and the 2-byte response code.
  • Page 941 3. Instructions Reading/Writing a Data File in EM File Memory or Performing Another File Memory Operation Convert all banks from the specified bank of the EM Area to file memory using the settings in the PLC Setup. Initialize EM file memory from the CX-Programmer. Using the FWRIT(701) instruction, name a file in the specified I/O memory area and save the data in the EM file memory.
  • Page 942 3. Instructions Never remove the Memory Card from the CPU Unit when the BUSY indicator is lit. Press the Memory Card power OFF button and wait for the BUSY indicator to go out before removing the Memory Card. The Memory Card may become unusable if this is not done. Insert the Memory Card with the label facing to the right.
  • Page 943 3. Instructions For word CSV format (.CSV), the data will be as follows when 1234 hex, 5678 hex, 9ABC hex, and DEF0 hex are stored in the file ABC.CSV (the basic structure would be the same for text data (.TXT): 4 bytes I/O memory 1234...
  • Page 944 3. Instructions  Instruction-related Words and Bits Name Address Operation File Write Error Flag A343.08 ON when an error occurred when writing to the file. ON when the file being written is write-protected. File Write Impossible Flag A343.09 ON when the data could not be written because there was insufficient free memory. File Read Error Flag A343.10 ON when a file could not be read because its data was corrupted or if it contains the wrong...
  • Page 945 3. Instructions FREAD Function Instruction Mnemonic Variations Function code Reads the specified data or amount of data from the READ DATA FILE FREAD @FREAD specified data file in file memory to the specified data area in the CPU Unit. FREAD FREAD(700) C: Control word Symbol...
  • Page 946 3. Instructions S1: Number of read words, starting read position • S1 and S1+1: Number of Read Items S1+1 S1+1 contains the leftmost 4 digits and S1 contains the rightmost 4 digits. S1+1 is the leftmost 4 digits, S1 is the rightmost 4 digits Data type Bits 12 to 15 of C Contents of S1 and S1+1...
  • Page 947 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR S1, S2 Flags Name Label Operation Error Flag • ON if the file memory specified in C does not exist. •...
  • Page 948 3. Instructions  Reading Number of Words of Data (Third Digit of C=1) FREAD(700) finds the number of words in the file specified in S2 (with filename extension .IOM) and writes that 8-digit hexadecimal value to D and D+1. File specified CPU Unit in S2 Number of words...
  • Page 949 3. Instructions • A few seconds is required for the CPU Unit to detect a Memory Card after it has been inserted. If a Memory Card is going to be accessed soon after power is turned ON or after a Memory Card is inserted, use the Memory Card Detected Flag (A343.15) in a NO input condition as shown below to be sure that the Memory Card has been detected.
  • Page 950 3. Instructions FWRIT Function Instruction Mnemonic Variations Function code Overwrites or appends data in the specified data file WRITE DATA FILE FWRIT @FWRIT in file memory with the specified data from the data area in the CPU Unit. FWRIT FWRIT(701) C: Control word Symbol D1: First destination word...
  • Page 951 3. Instructions D1: Number of write words, starting write position • D1 and D1+1: Number of Write Items D1+1 D1+1 contains the leftmost 4 digits and D1 contains the rightmost 4 digits. Data type Bits 12 to 15 of C Contents of D1 and D1+1 Binary 0 hex (binary)
  • Page 952 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR D1, D2 Flags Name Label Operation Error Flag • ON if the file memory type specified in C does not exist. •...
  • Page 953 3. Instructions Function • Overwriting Data in an Existing File (Third Digit of C=1) FWRIT(701) uses data area data starting at the word specified in S to overwrite file memory data in the specified data type. It overwrites the number of words or fields specified in D1 and D1+1 in the file specified in D2 (with filename extension .IOM, .TXT, or .CVS) starting at the address specified in D1+2 and D1+3.
  • Page 954 3. Instructions Example: Write the pathname and filename in ASCII beginning with the leftmost byte of D2, as shown in the following example for \ABC\XYZ.IOM. (The extension is added automatically.) '\ ' → D2+1 D2+1 '\ ' D2+2 D2+2 D2+3 D2+3 →...
  • Page 955 3. Instructions Hint • When another file memory related operation (file memory format, file copy, file delete, etc.) is executed from the ladder program, send the file memory related FINS command to the local CPU Unit with a CMND(490) instruction. Precaution •...
  • Page 956 3. Instructions TWRIT Function Instruction Mnemonic Variations Function code Reads ASCII data from I/O memory and stores that WRITE TEXT FILE TWRIT @TWRIT data in the Memory Card as a text file (writing a new file or appending a file). TWRIT TWRIT(704) C: Control word...
  • Page 957 3. Instructions S3: First write data word Specifies the first word (I/O memory data area address) containing the data to be written. Note It is not necessary for all of the source words (starting at S3) to be in the same data area. The data will be read in PLC memory address order and written as a file.
  • Page 958 3. Instructions Function TWRIT(704) writes the number of bytes of Write data data specified in S1, starting from the word specified in S3, to a text file (filename.TXT) in Characters: 12 #3132 the Memory Card with the filename specified S3+1 Characters: 34 #3334 in S2.
  • Page 959 3. Instructions • Store the directory name and filename in ASCII and in order from leftmost byte → rightmost byte and lower word address → higher word address, starting from the leftmost byte of S2. • If the specified directory does not exist, the No File Flag (A343.11) will be turned ON and the file will not be overwritten.
  • Page 960 3. Instructions Example Programming This example records the daily production total (number of units produced) in D100 and D101 in 8-digit hexadecimal. Every day at 23:00, the program converts the daily production total to BCD format and appends the file LOG.TXT in the Memory Card's root directory. Always ON Flag ANDW A352...
  • Page 961: Display Instructions

    3. Instructions Display Instructions Function Instruction Mnemonic Variations Function code Reads the specified sixteen words of extended Display Instructions @MSG ASCII and displays the message on a Peripheral Device such as a Programming Console. MSG(046) Symbol N: Message number M: First message word Applicable Program Areas Function block SFC action or transition...
  • Page 962 3. Instructions Function When the execution condition is ON, MSG(046) registers the 16 words of ASCII data (up to 32 characters including the null character) from M to M+15 for the message number specified by N. Once a message has been registered, a Programming Console can be connected and the message will be displayed after any error messages that have been generated.
  • Page 963 3. Instructions  ASCII Four leftmost bits CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 964: Clock Instructions

    3. Instructions Clock Instructions CADD/CSUB Function Instruction Mnemonic Variations Function code Adds time to the calendar data in the specified CALENDAR ADD CADD @CADD words. Subtracts time from the calendar data in the spec- CALENDAR SUBTRACT CSUB @CSUB ified words. CADD CSUB CADD(730)
  • Page 965 3. Instructions  CADD C through C+2: Calendar Data T and T+1: Time Data Seconds: 00 to 59 (BCD) Seconds: 00 to 59 (BCD) Minutes: 00 to 59 (BCD) Minutes: 00 to 59 (BCD) Hours: 0000 to 9999 (BCD) Hour: 00 to 23 (BCD) Day: 01 to 31 (BCD) Month: 01 to 12 (BCD) Year: 00 to 99 (BCD)
  • Page 966 3. Instructions  CSUB C through C+2: Calendar Data T and T+1: Time Data Seconds: 00 to 59 (BCD) Seconds: 00 to 59 (BCD) Minutes: 00 to 59 (BCD) Minutes: 00 to 59 (BCD) Hour: 00 to 23 (BCD) Hours: 0000 to 9999 (BCD) Day: 01 to 31 (BCD) Month: 01 to 12 (BCD) Year: 00 to 99 (BCD)
  • Page 967 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag • ON if the calendar data in C through C+2 is not within the specified ranges. •...
  • Page 968 3. Instructions Example Programming  CADD When CIO 0.00 turns ON in the following example, the calendar data in D100 through D102 (year, month, day, hour, minutes, seconds) is added to the time data in D200 and D201 (hours, minutes, seconds) and the result is output to D300 through D302.
  • Page 969 3. Instructions Function Instruction Mnemonic Variations Function code Converts time data in hours/minutes/seconds for- HOURS TO SECONDS @SEC mat to an equivalent time in seconds only. SEC(065) Symbol S: First source word D: First destination word Applicable Program Areas Function block SFC action or Area Block program areas...
  • Page 970 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag • ON when S+1 (time data) is not BCD data • ON if the minutes data in S (bits 08 to 15) is not BCD and in the range 00 to 59. •...
  • Page 971 3. Instructions Function Instruction Mnemonic Variations Function code Converts seconds data to an equivalent time in SECONDS TO HOURS @HMS hours/minutes/seconds format. HMS(066) Symbol S: First source word D: First destination word Applicable Program Areas Function block SFC action or Area Block program areas Step program areas...
  • Page 972 3. Instructions  Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag • ON if the seconds data in S and S+1 is not BCD and in the range 0 to 35,999,999. •...
  • Page 973 3. Instructions DATE Function Instruction Mnemonic Variations Function code Changes the internal clock setting to the setting in CLOCK ADJUSTMENT DATE @DATE the specified source words. DATE DATE(735) Symbol S: First source word Applicable Program Areas Function block SFC action or Area Block program areas Step program areas...
  • Page 974 3. Instructions Related Auxiliary Area Words and Bits Name Address Operation Clock data A351 to A354 A351.00 to A351.07: Seconds (00 to 59) (BCD) A351.08 to A351.15: Minutes (00 to 59) (BCD) A352.00 to A352.07: Hours (00 to 23) (BCD) A352.08 to A352.15: Day of the month (01 to 31) (BCD) A353.00 to A353.07: Month (01 to 12) (BCD) A353.08 to A353.15: Year (00 to 99) (BCD)
  • Page 975: Debugging Instructions

    3. Instructions Debugging Instructions TRSM Function Instruction Mnemonic Variations Function code When TRSM(045) is executed, the status of a pre- Trace Memory Sampling TRSM selected bit or word is sampled and stored in Trace Memory. TRSM Symbol TRSM(045) Applicable Program Areas Function block SFC action or transition Area...
  • Page 976 3. Instructions It is possible to incorporate two or more TRSM(045) instructions in a program. In this case, the value of the same specified bit or word will be stored in Trace Memory each time that one of the TRSM(045) instructions is executed.
  • Page 977 3. Instructions  Timing Chart Operated from Peripheral Device (Sampling Start Bit: A508.15) Trace Start Bit: A508.14 Trace Busy Flag: A508.13 Trace Completed Flag: A508.12 Trace Trigger Monitor Flag: A508.11 Delay Valid Trace ends when setting samples Trace Memory is full. Sampling : Execution of TRSM(045) Example: word data...
  • Page 978: Failure Diagnosis Instructions

    3. Instructions Failure Diagnosis Instructions Function Instruction Mnemonic Variations Function code Generates or clears user-defined non-fatal errors. FAILURE ALARM @FAL Non-fatal errors do not stop PLC operation. Generating or Clearing User-defined Non-fatal Errors Generating Non-fatal System Errors FAL(006) FAL(006) Symbol N: FAL number N: FAL number (value in A529) S: First message word or...
  • Page 979 3. Instructions Flags Name Label Operation Error Flag • ON if N is not within the specified range of 0 to 511 decimal. • ON if a non-fatal system error is being generated, but the specified error code or error details code is incorrect.
  • Page 980 3. Instructions Function  Generating Non-fatal User-defined Errors The following table shows the error codes and FAL Error Flags for FAL(006). FAL number 1 to 511 decimal FAL error codes 4101 to 42FF Executed FAL Number Flags A360.01 to A391.15 When FAL(006) is executed with N set to an FAL number (&1 to &511) that is not equal to the content of A529 (the system-generated FAL/FALS number), a non-fatal error will be generated with that FAL number and the following processing will be performed:...
  • Page 981 3. Instructions 1. The specified error code will be written to A400. 2. The error code and the time that the error occurred will be written to the Error Log Area (A100 through A199). 3. The appropriate Auxiliary Area Flags are set based on the error code and error details. 4.
  • Page 982 3. Instructions  Disabling Error Log Entries of User-defined Errors Normally when FAL(006) generates a user-defined error, the error code and the time that the error occurred are written to the Error Log Area (A100 through A199). It is possible to set the PLC Setup so that user-defined errors generated by FAL(006) are not recorded in the Error Log.
  • Page 983 3. Instructions Example Programming  Generating a Non-fatal Error When CIO 0.00 is ON in the following example, FAL(006) will generate a non-fatal error with FAL number 31 and execute the following processes. 1. The FAL Error Flag (A402.15) will be turned ON. 2.
  • Page 984 3. Instructions  Clearing the Most Serious Non-fatal Error When CIO 0.03 is ON in the following example, FAL(006) will clear the most serious non-fatal error that has occurred and reset the error code in A400. If the cleared error was originally generated by FAL(006), the corresponding Executed FAL Number Flag and the FAL Error Flag (A402.15) will be turned OFF.
  • Page 985 3. Instructions FALS Function Instruction Mnemonic Variations Function code Generates user-defined fatal errors. Fatal errors SEVERE FAILURE ALARM FALS stop PLC operation. FALS Generating or Clearing User-defined Fatal Errors Generating Fatal Errors from the System FALS(007) FALS(007) Symbol N: FAL number N: FAL number (value in A529) S: First message word or S: First word containing the...
  • Page 986 3. Instructions Related Auxiliary Area Words and Bits  Auxiliary Area Words/Flags for User-defined Errors Only Name Address Operation FALS Error Flag A401.06 ON when an error is generated with FALS(007).  Auxiliary Area Words/Flags for System Errors Only Name Address Operation System-generated FAL/FALS...
  • Page 987 3. Instructions 4 When a user-defined fatal error is registered, the I/O memory and output status from output units will be as indicated below. I/O memory Output status from output units Hold IOM Hold Bit (A500.12). Hold  Generating Non-fatal System Errors Error code written to A400 Execution of FALS(007) Error code and time written to Error Log Area...
  • Page 988 3. Instructions The following table shows how to specify error codes and error details in S and S+1. Error name Error code Error details Memory Error 80F1 hex Bits 00 to 09: Memory Error Location Bit 00: User program Bit 04: PLC Setup Bit 05: Registered I/O table Bit 07: Routing table Bit 08: CPU Bus Unit Setup...
  • Page 989 3. Instructions  Displaying Messages with Fatal User-defined Errors • If S is a word address, the ASCII message beginning at S will be displayed at the Programming Device when FALS(007) is executed. (If a message is not required, set S to a constant.) •...
  • Page 990 3. Instructions Example Programming  Generating a User-defined Error When CIO 0.00 is ON in the following example, FALS(007) will generate a fatal error with FAL number 31 and execute the following processes. 1. The FALS Error Flag (A401.06) will be turned ON. 2.
  • Page 991 3. Instructions Function Instruction Mnemonic Variations Function code Diagnoses a failure in an instruction block by mon- itoring the time between execution of FPD(269) FAILURE POINT DETECTION and execution of a diagnostic output and finding which input is preventing an output from being turned ON.
  • Page 992 3. Instructions Flags Name Label Operation Error Flag • ON if C is not within the specified range of 0000 to 01FF or 8000 to 81FF. • ON if T is not within the specified range of 0000 to 270F. •...
  • Page 993 3. Instructions  Time Monitoring Function FPD(269) starts timing when it is executed (when execution condition A goes ON); it will generate a non-fatal error and turn ON the Carry Flag if the diagnostic output is not turned ON within the specified monitoring time.
  • Page 994 3. Instructions Note • The logic diagnosis function is executed every cycle as long as the execution condition for FPD(269) is ON. The operation of the logic diagnosis function is independent of the time monitoring function. • The input circuit to be logically diagnosed should consist of multiple N.C. or N.O. conditions. •...
  • Page 995 3. Instructions Bit Address and Message Output (C=8@@@) When the leftmost digit of C is set to 8, the ASCII address of the input bit is output to R+2 to R+4. R contains two flags which indicate whether an input bit has been found and whether it is used in a normally open or normally closed input condition.
  • Page 996 3. Instructions Hint  Disabling Error Log Entries of Non-fatal FPD(269) Errors Normally when the FPD(269) Time Monitoring Function generates a non-fatal error, the error code and the time that the error occurred are written to the Error Log Area (A100 through A199). It is possible to set the PLC Setup so that the non-fatal errors generated by FAL(006) are not recorded in the Error Log.
  • Page 997 3. Instructions Example Programming The following program example is used to demonstrate the operation of the time monitoring function and logic diagnosis function. In this example, the diagnostic output (CIO 200.00) does not go ON because CIO 100.00 and CIO 100.03 remain OFF in the logic diagnosis execution condition. Execution condition 300.00...
  • Page 998 3. Instructions FAL number = 10 Diagnostic output mode = 8 (bit address and message output) Bit Address Found Flag Input type 1: Bit address found 0: Normally open R: D300 Not used. R+1: D301 R+2: D302 Contains bit address in ASCII. R+3: D303 (100.00 is converted to ASCII.) R+4: D304...
  • Page 999: Other Instructions

    3. Instructions Other Instructions STC/CLC Function Instruction Mnemonic Variations Function code SET CARRY @STC Sets the Carry Flag (CY). CLEAR CARRY @CLC Turns OFF the Carry Flag (CY). Symbol STC(040) CLC(041) Applicable Program Areas Function block SFC action or transition Area Block program areas Step program areas...
  • Page 1000 3. Instructions EMBC Function Instruction Mnemonic Variations Function code SELECT EM BANK EMBC @EMBC Changes the current EM bank. EMBC Symbol EMBC(281) N: EM bank number Applicable Program Areas Function block SFC action or transition Area Block program areas Step program areas Subroutines Interrupt tasks definitions...

Table of Contents