Omron CJ - INSTRUCTIONS REFERENCE MANUAL 07-2009 Reference Manual
Omron CJ - INSTRUCTIONS REFERENCE MANUAL 07-2009 Reference Manual

Omron CJ - INSTRUCTIONS REFERENCE MANUAL 07-2009 Reference Manual

Programmable controllers
Hide thumbs Also See for CJ - INSTRUCTIONS REFERENCE MANUAL 07-2009:
Table of Contents

Advertisement

Quick Links

Cat. No. W474-E1-04
SYSMAC CS Series
CS1@-CPU@@@-@@
SYSMAC CJ Series
CJ2H-CPU6@-EIP
CJ2H-CPU6@
CJ1@-CPU@@@-@
SYSMAC One NSJ Series
NSJ@@-@@@@@-@@@
Programmable Controllers
INSTRUCTIONS
REFERENCE MANUAL

Advertisement

Table of Contents
loading

Summary of Contents for Omron CJ - INSTRUCTIONS REFERENCE MANUAL 07-2009

  • Page 1 Cat. No. W474-E1-04 SYSMAC CS Series CS1@-CPU@@@-@@ SYSMAC CJ Series CJ2H-CPU6@-EIP CJ2H-CPU6@ CJ1@-CPU@@@-@ SYSMAC One NSJ Series NSJ@@-@@@@@-@@@ Programmable Controllers INSTRUCTIONS REFERENCE MANUAL...
  • Page 2 OMRON, 2008 All rights reserved. No part of this publication may be reproduced, stored in a retrieval system, or transmitted, in any form, or by any means, mechanical, electronic, photocopying, recording, or otherwise, without the prior written permission of OMRON.
  • Page 3 CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 4 SYSMAC CS Series CS1@-CPU@@@-@@ SYSMAC CJ Series CJ2H-CPU6@-EIP CJ2H-CPU6@ CJ1@-CPU@@@-@ SYSMAC One NSJ Series NSJ@@-@@@@@-@@@ Programmable Controllers Instructions Reference Manual Revised July 2009 CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 5 CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 6: About This Manual

    NSJ5-TQ@@(B)-M3D NSJ5-SQ@@(B)-M3D NSJ8-TV@@(B)-M3D Please read this manual and all related manuals listed in the table and be sure you understand infor- mation provided before attempting to program or use CS/CJ-series CPU Units in a PLC System or an NSJ-series Controller.
  • Page 7: Intended Audience

    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 8 WHETHER SUCH CLAIM IS BASED ON CONTRACT, WARRANTY, NEGLIGENCE, OR STRICT LIABILITY. In no event shall the responsibility of OMRON for any act exceed the individual price of the product on which liability is asserted. IN NO EVENT SHALL OMRON BE RESPONSIBLE FOR WARRANTY, REPAIR, OR OTHER CLAIMS...
  • Page 9 The following are some examples of applications for which particular attention must be given. This is not intended to be an exhaustive list of all possible uses of the products, nor is it intended to imply that the uses listed may be suitable for the products: •...
  • Page 10 PERFORMANCE DATA Performance data given in this manual 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 users must correlate it to actual application requirements.
  • Page 11 Some instructions are supported only by specific versions of a CPU Unit. Confirm support before programming. Notation of Unit Versions The unit version is given to the right of the lot number on the nameplate of the on Products products for which unit versions are being managed, as shown below.
  • Page 12 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.
  • Page 13 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 14 Unit Version Notation In this manual, the unit version of a CPU Unit is given as shown in the follow- ing table. Product nameplate CPU Units on which no unit version is Units on which a version is given given (Ver.
  • Page 15 CJ1M CPU Units Unit version 4.0 CJ1M-CPU12/13 Unit version 3.0 CJ1M-CPU22/23 Unit version 2.0 Pre-Ver. 2.0 CJ1M-CPU11/21 Unit version 4.0 Unit version 3.0 Unit version 2.0 NSJ Series Units Unit version Unit version 3.0 NSJ@-TQ@@(B)-G5D NSJ@-TQ@@(B)-M3D CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 16 4.0 or later cannot be used on CS/CJ-series CPU Units with unit ver- sion 3.0 or earlier. An error message will be displayed if an attempt is made to download programs containing unit version 4.0 functions to a CPU Unit with a unit version of 3.0 or earlier, and the download will not be possible.
  • Page 17 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...
  • Page 18 3.0 or later cannot be used on CS/CJ-series CPU Units with unit ver- sion 2.0 or earlier. An error message will be displayed if an attempt is made to download programs containing unit version 3.0 functions to a CPU Unit with a unit version of 2.0 or earlier, and the download will not be possible.
  • Page 19 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...
  • Page 20 Network Levels Connecting Online to PLCs via NS-series Setting First Slot Words OK for up to 64 groups Automatic Transfers at Power ON without a Parameter File Automatic Detection of I/O Allocation Method for Automatic Transfer at Power ON Operation Start/End Times...
  • Page 21 2.0 or later cannot be used on CS/CJ-series Pre-Ver. 2.0 CPU Units. An error message will be displayed if an attempt is made to download pro- grams containing unit version s.0 functions to a Pre-Ver. 2.0 CPU Unit, and the download will not be possible.
  • Page 22 2. CX-Programmer version 7.1 or higher is required to use the new functions of the CJ1-H-R CPU Units. CX-Programmer version 7.22 or higher is re- quired to use unit version 4.1 of the CJ1-H-R CPU Units. You can check the CX-Programmer version using the About menu command to display version information.
  • Page 23 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...
  • Page 24 CPU Unit to a previous unit version. After the above message is displayed, a compiling error will be displayed on the Compile Tab Page in the Output Window. An attempt was to download a Check the settings in the PLC...
  • Page 25: Related Manuals

    CJ2H-CPU6@-EIP, CJ2H-CPU6@ Overview, system design, hardware specifica- tions, hardware settings, installation, wiring, main- tenance, and troubleshooting. Use this manual together with the CJ2 CPU Unit Software User's Manual (W473). CJ Series CJ2 CPU Unit Software User’s Manual W473 Provides the following information on the CJ2...
  • Page 26 CX-One Setup Manual !WARNING Failure to read and understand the information provided in this manual may result in per- sonal injury or death, damage to the product, or product failure. Please read each section in its entirety and be sure you understand the information provided in the section and related sections before attempting any of the procedures or operations given.
  • Page 27: Safety Precautions

    Always heed the information provided with them. Failure to heed pre- cautions can result in injury to people or damage to property. !DANGER Indicates an imminently hazardous situation which, if not avoided, will result in death or serious injury. Additionally, there may be severe property damage. !WARNING Indicates a potentially hazardous situation which, if not avoided, could result in death or serious injury.
  • Page 28 CS/CJ/NSJ Series Instructions Reference Manual (W474) xxix...
  • Page 29: General 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 operation mode of the CPU Unit.
  • Page 30 PLC to which is mounted a non-insulated Unit (CS1W-CLK12/52(-V1) or CS1W-ETN01) connected to an external power supply. A short-circuit will be created if the 24 V side of the external power supply is grounded and the 0 V side of the peripheral device is grounded. When connecting a peripheral device to this type of PLC, either ground the 0 V side of the external power supply or do not ground the external power supply at all.
  • Page 31: Application Precautions

    • Locations subject to possible exposure to radioactivity. • Locations close to power supplies. !Caution The operating environment of the PLC System can have a large effect on the longevity and reliability of the system. Improper operating environments can lead to malfunction, failure, and other unforeseeable problems with the PLC System.
  • Page 32 • When storing the Power Supply Unit for more than three months, store it at 20 to 30 C and 25% to 70% humidity to preserve the Replace- ment Notification Function. • If the Power Supply Unit is not installed properly, heat buildup may cause the replacement notification signal to appear at the wrong time or may cause interior elements to deteriorate or become damaged.
  • Page 33 PRECAUTIONS • Do not apply voltages to the Input Units in excess of the rated input volt- age. Excess voltages may result in burning. • Always connect to a ground of 100 or less when installing the Units. Not connecting to a ground of 100 or less may result in electric shock.
  • Page 34 • A battery is mounted to a CJ-series CPU Unit when the Unit is shipped from the factory. Also, the time is set on the internal clock. It is thus not necessary to clear memory and set the clock before using a CJ-series CPU Unit.
  • Page 35 • If the I/O Hold Bit is turned ON, the outputs from the PLC will not be turned OFF and will maintain their previous status when the PLC is switched from RUN or MONITOR mode to PROGRAM mode.
  • Page 36: Table Of Contents

    Instructions ........
  • Page 37 Index..........1209 Revision History ........1217...
  • Page 38: Basic Understanding Of Instructions

    This section describes the basic information that is required to use programming instructions. Basic Understanding of Instructions ....... .
  • Page 39: Basic Understanding Of Instructions

    An instruction may not be executed or may act differently depending on instruction conditions. Instruction conditions are reset (canceled) at the start of each task, i.e., they are reset when the task changes. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 40 JME0(516) jump. Block program Executes a program block from BPRG(096) BEND(801) execution BPRG(096) to BEND(801). Flags In this context, a flag is a bit that serves as an interface between instructions. Input flags Output flags Flag Description Flag Description Carry (CY)
  • Page 41: Instruction Location And Execution Conditions

    Note Operands are also called the first operand, second operand, and so on, start- ing from the top of the instruction. First operand Second operand Instruction Location and Execution Conditions The following table shows the possible locations for instructions.
  • Page 42 Input Instructions (Logical Starts and Intermediate Instructions): These instructions read bit status, make comparisons, test bits, or perform other types of processing every cycle. If the results are ON, power flow is out- put (i.e., the execution condition is turned ON).
  • Page 43 ■ 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 ON) and are not executed in the following cycles.
  • Page 44 Note The downward differentiation variation (indicated by “%”) cannot be used with as many instructions as the upward differentiation varia- tion. It can be used only with the LD, AND, OR, SET, and RSET in- struction. To use downward differentiation with any other instructions, combine the instruction with the DIFD(014) or DOWN(522) instruc- tion.
  • Page 45 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.
  • Page 46 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...
  • Page 47 • With both upwardly and downwardly differentiated instructions, outputs will turn OFF in the next cycle. Note Do not use the Always P_On Flag or A200.11 (First Cycle Flag) as the input bit for an upwardly differentiated instruction. Do not use the Always P_Off Flag as the input bit for a downwardly differentiated instruction.
  • Page 48: 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 49: Specifying Operands

    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.
  • Page 50 A constant or word address in I/O memory can be used for the offset. If a word address is speci- fied, the contents of the word is used directly as the offset.
  • Page 51 Note When specifying an indirect address in Binary Mode, treat Data Memory (DM) and Extended Data Memory (EM) (banks 0 to 18) as one series of addresses. If the contents of an address with the @ symbol exceeds 32767, the address will be assumed to be an address in the Extended Data Memory (EM) continuing on from 0 in bank No.
  • Page 52 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 DR@ (@: 0 to 15).
  • Page 53 D0. +#0009 #0001 D1 Stores #000A hex (&10 decimal) in D1. Signed decimal 32768 to +32767 MOV .100 D0 Stores .100 decimal (#FF9C hex) in D0. + 9 1 D1 Stores 10 decimal (#FFF6 hex) in D1. Unsigned decimal &...
  • Page 54 ‘D’ an even number of charac- ters. ASCII characters that can be used in a text string includes alphanumeric characters, Katakana and symbols (except for special characters). The characters are shown in the following table. Upper four digits CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 55: Data Formats

    #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 1 2 8 Signed...
  • Page 56 It can be used to set or monitor from the I/O memory Edit and Monitor Screen on the CX-Programmer. As such, users do not need to know this for- mat although they do need to know that the formatting takes up two words.
  • Page 57 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.
  • Page 58: Summary Of Instructions

    2-2-26 Display Instructions ........
  • Page 59: Instruction Set And Cpu Unit Support For Individual Instructions

    The following table lists the CS/CJ-series instructions by function. The instruc- tions also appear by order of their function in SECTION 3 Instructions. Asterisks and numbers are used in the table to indicate which CPU Unit mod- els and unit versions support each instruction as listed below. If no asterisk and number appears, all models and all unit versions of the CS/CJ-series CPU Units support the instruction.
  • Page 60 COMPARE COMPARE CPSL DOUBLE AREA RANGE DOUBLE ZCPL SIGNED COMPARE AREA RANGE BINARY COMPARE COMPARE Table MCMP MULTIPLE TCMP TABLE COM- BCMP UNSIGNED compare COMPARE PARE BLOCK COM- PARE EXPANDED BCMP2 BLOCK COM- PARE CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 61 INCREMENT ++BL DOUBLE – –B DECRE- decrement INCREMENT MENT BCD instructions – –BL DOUBLE DECRE- MENT BCD Binary INCREMENT DOUBLE – – DECRE- BINARY INCREMENT MENT BINARY BINARY – –L DOUBLE DECRE- MENT BINARY CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 62 MULTIPLY DOUBLE UNSIGNED BINARY MULTIPLY BCD multiply DOUBLE BCD MULTIPLY MULTIPLY Binary divide SIGNED DOUBLE UNSIGNED BINARY SIGNED BINARY DIVIDE BINARY DIVIDE DIVIDE DOUBLE UNSIGNED BINARY DIVIDE BCD divide BCD DIVIDE DOUBLE BCD DIVIDE CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 63 DOUBLE LOGICAL OR EXCLUSIVE XNRW EXCLUSIVE XNRL DOUBLE EXCLUSIVE Complement COMPLE- COML DOUBLE MENT COMPLE- MENT Special ROTB BINARY ROOT BCD SQUARE ARITHMETIC math ROOT ROOT PROCESS instructions FDIV FLOATING BCNT POINT COUNTER DIVIDE CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 64 EXPD DOUBLE LOGD DOUBLE math SQUARE EXPONENT LOGARITHM ROOT PWRD DOUBLE EXPONEN- TIAL POWER Symbol compari- LD, AND, OR Symbol com- parison (dou- =, <>, <, <=, >, ble-precision >= + D floating point) CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 65 COMPARI- SPEED OUT- SET PULSES CTBL SPED PULS SON TABLE tions LOAD PULSE OUT- ACCELERA- ORIGIN PLS2 TION Control SEARCH PULSE WITH VARIABLE DUTY FAC- Step STEP STEP DEFINE SNXT STEP START instructions CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 66 BANK EXTEND SAVE CONDI- LOAD CONDI- MAXIMUM TION FLAGS TION FLAGS CYCLE TIME CONVERT CONVERT DISABLE FRMCV TOCV IOSP ADDRESS ADDRESS TO PERIPH- FROM CV ERAL SER- VICING ENABLE IORS PERIPH- ERAL SER- VICING CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 67 SFC pro- SFCON SFC ON SFCOFF SFC OFF SFCPR SFC PAUSE gram WITH RESET instruc- SFCPRN SFC PAUSE STEP ACTI- STEP DEAC- tions WITH NO VATION TIVATION RESET READ SET SET STEP TIMER TIMER CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 68: Instruction Functions

    @LD NOT %LD NOT !LD NOT Starting !@LD NOT point of !%LD NOT block Takes a logical AND of the status of the specified operand bit and the Continues on current execution condition. rung @AND Required %AND !AND !@AND...
  • Page 69 TST(350) gram like LD, AND, and OR; the execution condition is ON when the rung LD TST specified bit in the specified word is ON and OFF when the bit is OFF. Not required S: Source word N: Bit number...
  • Page 70: Sequence Output Instructions

    TST(350) gram like LD, AND, and OR; the execution condition is ON when the rung OR TST specified bit in the specified word is ON and OFF when the bit is OFF. Required S: Source word N: Bit number BIT TEST...
  • Page 71 SETB(532) turns ON the specified bit in the specified word when the exe- Output (CJ2, CS1-H, SETB(532) cution condition is ON. Required CJ1-H, CJ1M, or Unlike the SET instruction, SETB(532) can be used to set a bit in a DM or CS1D only) EM word. SETB @SETB D: Word address !SETB...
  • Page 72 RSTB(533) turns OFF the specified bit in the specified word when the Output RESET (CJ2, RSTB(533) execution condition is ON. Required CS1-H, CJ1-H, Unlike the RSET instruction, RSTB(533) can be used to reset a bit in a CJ1M, or CS1D DM or EM word. only) RSTB @RSTB D: Word address...
  • Page 73: Sequence Control Instructions

    Indicates the end of a program. END(001) Not required END(001) completes the execution of a program for that cycle. No instructions written after END(001) will be executed. Execution proceeds to the program with the next task number. When the program being executed has the highest task number in the program, END(001) marks the end of the overall main program.
  • Page 74 D: Interlock Status Bit @ or% prefix) between MILH(517) and the corresponding MILC(519), Unit Ver. 2.0 or later that instruction will be executed after the interlock is cleared if the dif- and CJ2 CPU Units only ferentiation condition of the instruction was established while it was interlocked.
  • Page 75 JUMP When the execution condition for CJP(004) is OFF, program execution Not required CJPN jumps directly to the first JME(005) in the program with the same jump number. CJPN(511) and JME(005) are used in pairs. N: Jump number Execution Execution...
  • Page 76 Mnemonic Execution condition Code BREAK LOOP Output Programmed in a FOR-NEXT loop to cancel the execution of the loop BREAK(514) for a given execution condition. The remaining instructions in the loop BREAK Required are processed as NOP(000) instructions. Condition a ON...
  • Page 77: Timer And Counter Instructions

    TEN-MS TIMER TIMH(015)/TIMHX(551) operates a decrementing timer with units of Output TIMH(015) 10-ms. The setting range for the set value (SV) is 0 to 99.99 s for BCD TIMH Required and 0 to 655.35 s for binary (decimal or hexadecimal).
  • Page 78 ONE-MS TIMER TMHH(540)/TMHHX(552) operates a decrementing timer with units of Output TMHH(540) 1-ms. The setting range for the set value (SV) is 0 to 9.999 s for BCD TMHH Required and 0 to 65.535 s for binary (decimal or hexadecimal).
  • Page 79 TMUH(554)/TMUHX(557) operates an decrementing timer with units of Output TMUH(554) TIMER (CJ1-H-R 0.01-s. The setting range for the set value (SV) is 0 to 0.0999 s for BCD Required and CJ2 only) and 0 to 0.65535 s for binary (decimal or hexadecimal).
  • Page 80 MTIM(543) TIMER Required independent SVs and Completion Flags. The setting range for the MTIM set value (SV) is 0 to 999.9 s for BCD and 0 to 6,553.5 s for binary (decimal or hexadecimal). (BCD) Timer PV MTIMX D1: Completion...
  • Page 81 Completion Flag RESET TIMER/ CNR(545)/CNRX(547) resets the timers or counters within the speci- Output CNR(545) COUNTER fied range of timer or counter numbers. Sets the set value (SV) to the Required maximum of 9999. @CNR (BCD) : 1st number in...
  • Page 82: Comparison Instructions

    32-bit binary data and create an ON execution condition when AND, OR: : Comparison the comparison condition is true. There are three types of symbol com- Required LD, AND, OR + =, data 2 parison instructions, LD (LOAD), AND, and OR.
  • Page 83 AND, and OR. Time values (year, month, day, hour, minute, and second) DT, <> DT, < DT, Required can be masked/unmasked in the comparison so it is easy to create cal- <= DT, > DT, >= endar timer functions. 341 (= DT) 342 (<>...
  • Page 84 Output Compares the source data to 16 ranges (defined by 16 lower limits BCMP(068) BLOCK COM- and 16 upper limits) and turns ON the corresponding bit in the result Required PARE word when the source data is within the range.
  • Page 85 AREA RANGE Compares the 16-bit unsigned binary value in CD (word contents or Output ZCP(088) COMPARE constant) to the range defined by LL and UL and outputs the results to Required the Arithmetic Flags in the Auxiliary Area. @ZCP (CJ2, CS1-H,...
  • Page 86: Data Movement Instructions

    @MOVL Bit status not S: 1st source changed. word D: 1st destination word MOVE NOT Output Transfers the complement of a word of data to the specified word. MVN(022) Required Source word @MVN S: Source D: Destination Bit status inverted.
  • Page 87 Symbol/Operand Function Location Page Mnemonic Execution condition Code MOVE DIGIT Output Transfers the specified digit or digits. (Each digit is made up of 4 bits.) MOVD(083) MOVD Required @MOVD S: Source word or data C: Control word D: Destination word...
  • Page 88 @DIST S: Source word Bs: Destination base address Of: Offset Bs+n DATA COLLECT Output Transfers the source word (calculated by adding an offset value to the COLL(081) COLL base address) to the destination word. Required @COLL Bs: Source base Bs+n...
  • Page 89: Data Shift Instructions

    Status of data Lost input for each shift St: Starting word input E: End word REVERSIBLE Output Creates a shift register that shifts data to either the right or the left. SHIFT REGISTER SFTR(084) Required SFTR @SFTR Data input Shift...
  • Page 90 Shifts all Wd bits one bit to the left including the Carry Flag (CY). ROL(027) Required @ROL Wd: Word DOUBLE Output Shifts all Wd and Wd + 1 bits one bit to the left including the Carry Flag ROTATE LEFT ROLL(572) Required (CY). ROLL Wd+1...
  • Page 91 Execution condition Code DOUBLE Output Shifts all Wd and Wd +1 bits one bit to the right not including the Carry ROTATE RIGHT RRNL(577) Required Flag (CY). The contents of the rightmost bit of Wd +1 is shifted to the WITHOUT leftmost bit of Wd, and to the Carry Flag (CY).
  • Page 92 Function Location Page Mnemonic Execution condition Code DOUBLE SHIFT Output Shifts the specified 32 bits of word data to the left by the specified NSLL(582) N-BITS LEFT Required number of bits. NSLL @NSLL Shift n-bits D: Shift word C: Control word Contents of "a"...
  • Page 93 Location Page Mnemonic Execution condition Code INCREMENT Output Increments the 4-digit hexadecimal content of the specified word by 1. BINARY ++(590) Required Wd: Word DOUBLE INCRE- Output Increments the 8-digit hexadecimal content of the specified words by 1. MENT BINARY...
  • Page 94: Symbol Math Instructions

    Ad: 1st addend word R: 1st result word SIGNED BINARY Output Adds 4-digit (single-word) hexadecimal data and/or constants with the +C(402) ADD WITH Carry Flag (CY). Required CARRY (Signed binary) (Signed binary) Au: Augend word...
  • Page 95 Ad: 1st addend word R: 1st result word BCD ADD WITH Output Adds 4-digit (single-word) BCD data and/or constants with the Carry +BC(406) CARRY Required Flag (CY). (BCD) @+BC (BCD) Au: Augend word CY will turn ON...
  • Page 96 Mi: 1st minuend (BCD) when there is a word borrow. Su: 1st subtrahend word R: 1st result word BCD SUBTRACT Output Subtracts 4-digit (single-word) BCD data and/or constants with the BC(416) WITH CARRY Required Carry Flag (CY). –BC (BCD) @–BC (BCD) −...
  • Page 97 2. Summary of Instructions Instruction Symbol/Operand Function Location Page Mnemonic Execution condition Code SIGNED BINARY Output Multiplies 4-digit signed hexadecimal data and/or constants. *(420) MULTIPLY Required (Signed binary) × (Signed binary) Md: Multiplicand (Signed binary) R +1 word Mr: Multiplier...
  • Page 98 2. Summary of Instructions Instruction Symbol/Operand Function Location Page Mnemonic Execution condition Code DOUBLE BCD Output Multiplies 8-digit (double-word) BCD data and/or constants. *BL(425) MULTIPLY Required (BCD) Md + 1 @*BL (BCD) × Mr + 1 Md: 1st multiplicand word...
  • Page 99: Conversion Instructions

    BINL @BINL (BCD) (BIN) S: 1st source word R: 1st result word BINARY TO BCD Output Converts a word of binary data to a word of BCD data. BCD(024) Required @BCD (BIN) (BCD) S: Source word R: Result word DOUBLE Output Converts 8-digit hexadecimal (32-bit binary) data to 8-digit BCD data.
  • Page 100 Instruction Symbol/Operand Function Location Page Mnemonic Execution condition Code 2’S COMPLE- Output Calculates the 2's complement of a word of hexadecimal data. NEG(160) MENT Required 2's complement @NEG (Complement + 1) S: Source word R: Result word DOUBLE 2’S Output Calculates the 2's complement of two words of hexadecimal data.
  • Page 101 Mnemonic Execution condition Code DATA DECODER Output Reads the numerical value in the specified digit (or byte) in the source MLPX(076) MLPX Required word, turns ON the corresponding bit in the result word (or 16-word @MLPX range), and turns OFF all other bits in the result word (or 16-word range).
  • Page 102 Execution condition Code DATA ENCODER Output FInds the location of the first or last ON bit within the source word (or DMPX(077) 16-word range), and writes that value to the specified digit (or byte) in DMPX Required the result word.
  • Page 103 16 consecutive words) to the 16 bits of the destination word. LINE @LINE 0 0 0 1 1 1 1 0 0 0 1 0 0 0 0 1 S: 1st source 1 1 0 1 0 0 1 0 0 1 1 1 0 0 0 1...
  • Page 104 Symbol/Operand Function Location Page Mnemonic Execution condition Code SIGNED BCD TO Output Converts one word of signed BCD data to one word of signed binary BINS(470) BINARY Required data. BINS @BINS Signed BCD format specified in C Signed binary C: Control word...
  • Page 105 2. Summary of Instructions Instruction Symbol/Operand Function Location Page Mnemonic Execution condition Code DOUBLE GRAY Converts the specified two words of gray code to two words of binary Output GRAY_BINL(479) CODE TO data. Required BINARY CON- VERT GRAY_BINL S: First source @GRAY_BINL...
  • Page 106 Instruction Symbol/Operand Function Location Page Mnemonic Execution condition Code ASCII TO EIGHT- Converts 8 characters of ASCII data to an 8-digit hexadecimal number. Output NUM8 DIGIT NUMBER Required NUM8 @NUM8 (CS/CJ-series S: ASCII text CPU Units with D: Numeric unit version 4.0 or...
  • Page 107: Logic Instructions

    Function Location Page Mnemonic Execution condition Code LOGICAL AND Output Takes the logical AND of corresponding bits in single words of word ANDW(034) ANDW Required data and/or constants. @ANDW → R : Input 1 : Input 2 R: Result word...
  • Page 108 Required @COM Wd→Wd: 1 → 0 and 0 → 1 Wd: Word DOUBLE COM- Output Turns OFF all ON bits and turns ON all OFF bits in Wd and Wd+1. PLEMENT COML(614) Required COML (Wd+1, Wd) → (Wd+1, Wd) @COML...
  • Page 109: Special Math Instructions

    Page Mnemonic Execution condition Code BINARY ROOT Output Computes the square root of the 32-bit binary content of the specified ROTB(620) words and outputs the integer portion of the result to the specified ROTB Required result word. @ROTB S: 1st source...
  • Page 110 Function Location Page Mnemonic Execution condition Code FLOATING TO Output Converts a 32-bit floating-point value to 16-bit signed binary data and FIX(450) 16-BIT places the result in the specified result word. Required @FIX Floating-point data (32 bits) S: 1st source...
  • Page 111 S: 1st source word R: 1st result word Result (degrees, 32-bit floating-point data) SINE Output Calculates the sine of a 32-bit floating-point number (in radians) and SIN(460) Required places the result in the specified result words. @SIN Source (32-bit floating-point...
  • Page 112 Calculates the arc sine of a 32-bit floating-point number and places ASIN(463) ASIN Required the result in the specified result words. (The arc sine function is the @ASIN inverse of the sine function; it returns the angle that produces a given sine value between 1 and 1.)
  • Page 113 ATAN(465) ATAN Required places the result in the specified result words. (The arc tangent @ATAN function is the inverse of the tangent function; it returns the angle that produces a given tangent value.) Source (32-bit S: 1st source floating-point word...
  • Page 114 FLOATING SYM- Compares the specified single-precision data (32 bits) or constants Using LD: BOL COMPARI- and creates an ON execution condition if the comparison result is true. Not required SON (CJ2, CS1- Symbol, option Three kinds of symbols can be used with the floating-point symbol H, CJ1-H, CJ1M, comparison instructions: LD (Load), AND, and OR.
  • Page 115 Execution condition Code DOUBLE FLOAT- Converts the specified double-precision floating-point data (64 bits) to 16- Output ING TO 16-BIT bit signed binary data and outputs the result to the destination word. FIXD(841) Required BINARY FIXD @FIXD S: 1st source word...
  • Page 116 R: 1st result word DOUBLE Calculates the cosine of the angle (radians) in the specified double-preci- Output COSINE sion floating-point data (64 bits) and outputs the result to the result words. COSD(852) Required COSD @COSD S: 1st source word...
  • Page 117 (64 bits) and outputs the result to the Required result words. (The arc sine function is the inverse of the sine function; it ASIND returns the angle that produces a given sine value between -1 and 1.)
  • Page 118 BOL COMPARI- execution condition if the comparison result is true. required Symbol, option Three kinds of symbols can be used with the floating-point symbol com- LD, AND. or OR parison instructions: LD (Load), AND, and OR. AND or =D (335), <>D (336),...
  • Page 119: Table Data Processing Instructions

    TB+2 TB+2 address PUSH(632) TB+3 TB+3 S: Source word LAST IN FIRST Output Reads the last word of data written to the specified stack (the newest LIFO(634) Required data in the stack). LIFO @LIFO Stack Internal I/O Internal I/O pointer...
  • Page 120 Page Mnemonic Execution condition Code DIMENSION Output Defines a record table by declaring the length of each record and the RECORD TABLE DIM(631) Required number of records. Up to 16 record tables can be defined. @DIM Table number (N) Record 1 N: Table number LR ×...
  • Page 121 R1+(W −1) R1: 1st word in range D: Destination word DOUBLE FIND Treats the specified number of data items as double word table data and Output MAXL(174) MAXIMUM outputs the maximum value in the table. Required MAXL @MAXL...
  • Page 122 C: First control (CJ2 only) word S: First word in range D: First destination word Output Adds the bytes or words in the range and outputs the result to two SUM(184) Required words. @SUM C: 1st control word R1: 1st word in R1+(W−1)
  • Page 123 Symbol/Operand Function Location Page Mnemonic Execution condition Code STACK SIZE Counts the amount of stack data (number of words) in the specified stack. Output READ (CJ2, CS1- required SNUM(638) H, CJ1-H, CJ1M, or CS1D only) SNUM @SNUM TB: First stack...
  • Page 124: Tracking Instructions

    An Unsigned One-word Record Search Instruction searches the specified Output Symbol word Record table of records for a record with the specific data (1 word) in the specified required Search Instruc- location. When a record matching the specified condition is found, its tions record number and data are output.
  • Page 125 Symbol/Operand Function Location Page Mnemonic Execution condition Code UNSIGNED ONE- Sorts the records in the specified table according to the data (1 word) at Output RSORT(203) WORD RECORD the specified position in the records. required SORT RSORT @RSORT (CJ2 only)
  • Page 126: Data Control Instructions

    S: Input word C: 1st parameter word D: Output word LIMIT CONTROL Output Controls output data according to whether or not input data is within LMT(680) Required upper and lower limits. @LMT Upper limit S: Input word C: 1st limit word...
  • Page 127 TIME-PROPOR- Inputs the duty ratio or manipulated variable from the specified word, Output TIONAL OUTPUT converts the duty ratio to a time-proportional output based on the spec- Required TPO (685) ified parameters, and outputs the result from the specified output.
  • Page 128 SCALING 2 Output Converts signed binary data into signed BCD data according to the SCL2(486) SCL2 Required specified linear function. An offset can be input in defining the linear @SCL2 function. Positive Offset Negative Offset R (signed BCD) R (signed BCD)
  • Page 129 SCALING 3 Output Converts signed BCD data into signed binary data according to the SCL3(487) SCL3 Required specified linear function. An offset can be input in defining the linear @SCL3 function. Positive Offset Negative Offset R (signed binary) R (signed binary)
  • Page 130 MACRO Output Calls the subroutine with the specified subroutine number and MCRO(099) MCRO Required executes that program using the input parameters in S to S+3 and the @MCRO output parameters in D to D+3. MCRO(099) N: Subroutine number S: 1st input...
  • Page 131: Interrupt Control Instructions

    Both I/O interrupt tasks and scheduled interrupt tasks (Not supported are masked (disabled) when the PC is first turned on. by CS1D CPU MSKS(690) can be used to unmask or mask I/O interrupts and Units for Duplex- set the time intervals for scheduled interrupts. CPU Systems.)
  • Page 132 CLEAR Output Clears or retains recorded interrupt inputs for I/O interrupts CLI(691) INTERRUPT Required or sets the time to the first scheduled interrupt for scheduled (Not supported interrupts. by CS1D CPU Units for Duplex- N = 0 to 3 CPU Systems.)
  • Page 133 (number of revolutions) or Required VERT converts the counter PV to the total number of revolutions. The result is output to the destination words as 8-digit hexadecimal. Pulses can be PRV2 input from high-speed counter 0 only.
  • Page 134 ORG(889) is used to perform origin searches and returns. Output Required @ORG P: Port specifier C: Control data PULSE WITH PWM(891) is used to output pulses with a variable duty factor. Output VARIABLE DUTY Required FACTOR P: Port specifier F: Frequency...
  • Page 135: Step Instructions

    I/O refreshing SPECIAL I/O Performs I/O refreshing immediately for the specified Special I/O Unit's Output UNIT I/O FIORF(225) allocated CIO Area and DM Area words.t with the specified unit num- Required REFRESH ber. (CJ1-H-R and CJ2 only) N: Unit number...
  • Page 136 HEXADECIMAL Reads numeric data from a hexadecimal keypad connected to an Input Output KEY INPUT HKY (212) Unit and Output Unit and stores up to 8 digits of hexadecimal data in Required the specified words. (CS/CJ-series CPU Unit Ver. 2.0...
  • Page 137 Note: CS/CJ-series CPU Unit Ver. 2.0 or later and CJ2 CPU Units only (including CS1-H, CJ1-H, and CJ1M CPU Units from lot number 030418 or later) can read from CPU Bus Units. INTELLIGENT I/O...
  • Page 138: Serial Communications Instructions

    TRANSMIT Outputs the specified number of bytes of data from the RS-232C port Output TXD(236) built into the CPU Unit or the serial port of a Serial Communications Required Board (version 1.2 or later). @TXD S: 1st source...
  • Page 139 Page Mnemonic Execution condition Code TRANSMIT VIA Outputs the specified number of bytes of data from the serial port of a Output TXDU(256) SERIAL COMMU- Serial Communications Unit (version 1.2 or later). The data is output in Required NICATIONS UNIT no-protocol mode with the start code and end code (if any) specified in the allocated DM Setup Area.
  • Page 140: Network Instructions

    D: First destination word C: First control word I: First communications information word NETWORK Output Requests data to be transmitted from a node in the network and RECV(098) RECEIVE receives the data. Required RECV @RECV Local node Source node S: 1st source...
  • Page 141 D: 1st word of received message C: 1st control word EXPLICIT GET Reads status information with an explicit message (Get Attribute Sin- Output EGATR (721) ATTRIBUTE gle, Service Code: 0E hex). Required EGATR (CS/CJ-series CPU Unit Ver. 2.0...
  • Page 142 CJ2 send message CPU Units only) First control word EXPLICIT WORD Reads data to the local CPU Unit from a remote CPU Unit in the net- Output READ work. (The remote CPU Unit must support explicit messages.) Required ECHRD (723)
  • Page 143: File Memory Instructions

    Mnemonic Execution condition Code READ DATA FILE Output Reads the specified data or amount of data from the specified data file FREAD(700) FREAD Required in file memory to the specified data area in the CPU Unit. @FREAD Starting read ad-...
  • Page 144 Reads ASCII data from I/O memory and stores that data in the Memory Output TWRIT FILE Card as a text file (writing a new file or appending a file). The data is Required stored in the TXT format. TWRIT @TWRIT...
  • Page 145: Display Instructions

    Symbol/Operand Function Location Page Mnemonic Execution condition Code DISPLAY Reads the specified sixteen words of extended ASCII and displays the Output MSG(046) MESSAGE message on a Peripheral Device such as a Programming Console. Required @MSG N: Message number M: 1st message...
  • Page 146: Debugging Instructions

    Location Page Mnemonic Execution condition Code TRACE When TRSM(045) is executed, the status of a preselected bit or word Output TRSM(045) MEMORY is sampled and stored in Trace Memory. TRSM(045) can be used any- Not required SAMPLING where in the program, any number of times.
  • Page 147: Failure Diagnosis Instructions

    FPD(269) Required between execution of FPD(269) and execution of a diagnostic output and finding which input is preventing an output from being turned ON. Time monitoring function: Starts timing when execution condition A goes ON. Generates a non-fatal error if output B isn't turned ON within the monitoring time.
  • Page 148: Other Instructions

    Changes the current EM bank. Output EMBC(281) BANK Required EMBC @EMBC N: EM bank number EXTEND Extends the maximum cycle time, but only for the cycle in which this Output WDT(094) MAXIMUM instruction is executed. Required CYCLE TIME @WDT T: Timer setting SAVE CONDI- Saves the status of the condition flags.
  • Page 149: Block Programming Instructions

    @IOSP ENABLE Enables peripheral servicing that was disabled by IOSP(287) for pro- Output 1007 IORS(288) PERIPHERAL gram execution in one of the Parallel Processing Modes or Peripheral Not required SERVICING Servicing Priority Mode. (CS1D CPU Unit for Single-CPU Systems, CJ2,...
  • Page 150 Block program n. This block program will now be executed as long as bit "a" is ON. CONDITIONAL EXIT(806) Block program 1017 EXIT(806) without an operand bit exits the program if the execution BLOCK EXIT condition is ON. Required EXIT B: Bit operand Execution...
  • Page 151 OFF. (NOT) B: Bit operand IF NOT CONDITIONAL If the ELSE(803) instruction is omitted and the operand bit is ON, the Block program 1019 BLOCK instructions between IF(802) and IEND(804) will be executed...
  • Page 152 "C" executed. executed. Wait ONE CYCLE AND WAIT(805) If the operand bit is OFF (ON for WAIT NOT(805)), the rest of the Block program 1022 WAIT instructions in the block program will be skipped. In the next cycle, Required none of the block program will be executed except for the execution WAIT condition for WAIT(805) or WAIT(805) NOT.
  • Page 153 Code COUNTER WAIT CNTW(814) Block program 1028 Delays execution of the rest of the block program until the specified count CNTW Required has been achieved. Execution will be continued from the next instruction after CNTW(814)/CNTWX(818) when the counter counts out.
  • Page 154 LEND LEND (810) Block program 1033 If the operand bit is OFF for LEND(810) (or ON for LEND(810) NOT), LEND Required execution of the loop is repeated starting with the next instruction after LOOP(809). If the operand bit is ON for LEND(810) (or OFF for...
  • Page 155: Text String Processing Instructions

    S1: Text string first word S2: Number of characters D: First destination word GET STRING Output 1041 Reads a designated number of characters from the right (end) of a RIGHT RGHT$(653) Required text string. RGHT$ @RGHT$ S1: Text string first word...
  • Page 156 Required @LEN$ S: Text string first word D: 1st destination word REPLACE IN Output 1050 Replaces a text string with a designated text string from a designated STRING RPLC$(654) Required position. RPLC$ @RPLC$ S1: Text string first word S2: Replacement...
  • Page 157 String Compari- Sting comparison instructions (=$, <>$, <$, <=$, >$, >=$) compare two 1060 text strings from the beginning, in terms of value of the ASCII codes. If LD: Not Symbol the result of the comparison is true, an ON execution condition is cre-...
  • Page 158: Task Control Instructions

    TKON(820) TKON Required @TKON The specified task's task number The specified task's task number is higher than the local task's is lower than the local task's task N: Task number task number (m<n). number (m>n). Task m Task m comes...
  • Page 159 Output 1073 Transfers the source word to a destination word calculated by adding DISTC(566) DISTRIBUTE Required an offset value to the base address. Can also write to a stack (Stack DISTC Push Operation). @DISTC S: Source word Bs: Destination base address...
  • Page 160: Special Function Block Instructions

    Outputs the FINS command variable type (data area) code and word Output 1083 GETID(286) address for the specified variable or address. This instruction is gener- Required ally used to get the assigned address of a variable in a function block. GETID @GETID S: Variable or address D1: ID code...
  • Page 161: Sfc Instructions

    SE(785) DEACTIVATE actions. Required (CS/CJ Unit Ver. 4.0 or later, CJ2 only) READ SET The present value of the Step Time specified by S is stored starting at Output 1089 TSR(780) TIMER Required @TSR (CS/CJ Unit Ver. 4.0 or later,...
  • Page 162: Instructions

    Notation and Layout of Instruction Descriptions ........
  • Page 163 Increment/Decrement Instructions ........
  • Page 164 Double-precision Floating-point Instructions ........
  • Page 165 High-speed Counter/Pulse Output Instructions........
  • Page 166 Serial Communications Instructions........
  • Page 167 Block Programming Instructions ........
  • Page 168: Notation And Layout Of Instruction Descriptions

    The memory areas addresses that can be used each operand are listed in a table like the following one. The letters used in the column headings on the above are the same as those used in the ladder symbol. “---” is used to indicate when an area cannot be specific for an operand.
  • Page 169 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 170: Condition Flags

    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...
  • Page 171: Sequence Input Instructions

    CPU's internal memory and the I/O Unit. • In addition to the above I/O refreshing, an immediate refresh instruction exchanges data with the I/O Unit for those words that are accessed by the instruction. An immediate refresh instruction refreshes eight bits simultaneously (leftmost or rightmost eight bits) in addition to the specified bit.
  • Page 172 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 173 Function LD is used for the first normally open bit from the bus bar or for the first normally open bit of a logic block. If there is no immediate refreshing specification, the specified bit in I/O memory is read. If there is an immediate refreshing specification, the status of the Basic Input Unit's input terminal is read and used.
  • Page 174 OFF to ON, or from ON to OFF. • With CJ2 CPU Units, LD and LD NOT can be used for bits in the DM or EM Area. For other models of CPU Unit, LD and LD NOT cannot be used for bits in the DM or EM Area. Use LD TST(350) and LD TSTN(351) instead.
  • Page 175 Function AND is used for a normally open bit connected in series. AND cannot be directly connected to the bus bar, and cannot be used at the beginning of a logic block. If there is no immediate refreshing specification, the specified bit in I/O memory is read.
  • Page 176 OFF to ON, or from ON to OFF. With CJ2 CPU Units, AND and AND NOT can be used for bits in the DM or EM Area. For other models of CPU Unit, AND and AND NOT cannot be used for bits in the DM or EM Area. Use AND TST (350) instead.
  • Page 177 Function OR is used for a normally open bit connected in parallel. A normally open bit is configured to form a logical OR with a logic block beginning with a LOAD or LOAD NOT instruction (connected to the bus bar or at the begin- ning of the logic block).
  • Page 178 OFF to ON, or from ON to OFF. • With CJ2 CPU Units, OR and OR NOT can be used for bits in the DM or EM Area. For other models of CPU Unit, OR and OR NOT cannot be used for bits in the DM or EM Area. Use OR TST (350) instead.
  • Page 179 AND LD • Three or more logic blocks can be connected in series using this instruction to first connect two of the logic blocks and then to connect the next and subsequent ones in order. It is also possible to continue placing this instruction after three or more logic blocks and connect them together in series.
  • Page 180 ON execution condition will be produced when either of the execution conditions in the left logic block is ON (i.e., when either CIO 0.00 or CIO 0.01 is ON) and either of the execution conditions in the right logic block is ON (i.e., when either CIO 0.02 is ON or CIO 0.03 is OFF).
  • Page 181 LOAD is not more than eight. • To use nine or more, program using method (1). • If there are nine or more with method (2), then a program error will occur during the program check by the Peripheral Device.
  • Page 182 NOT(520) is placed between an execution condition and another instruction to invert the execution condition. Precautions NOT(520) is an intermediate instruction, i.e., it cannot be used as a right-hand instruction. Be sure to program a right-hand instruction after NOT(520). Sample program 0.03...
  • Page 183 • An instance will not be executed while EN is OFF. Caution is thus required when using UP(521) and DOWN(522) in a function block definition. For details, refer to information on restrictions on using ladder programming instructions in the CX-Programmer Operation Manual: Function Blocks.
  • Page 184 • 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. For details, refer to information on SBS(091).
  • Page 185 N: Bit number The bit number must be between 0000 and 000F hexadecimal or between &0000 and &0015 decimal. Only the rightmost bit (0 to F hexadecimal) of the contents of the word is valid when a word address is specified.
  • Page 186 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; the execution condition is OFF when the specified bit in the specified word is ON, and ON when the bit is OFF.
  • Page 187 N: Bit number The bit number must be between 0000 and 000F hexadecimal or between &0000 and &0015 decimal. Only the rightmost bit (0 to F hexadecimal) of the contents of the word is valid when a word address is specified.
  • Page 188 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; the execution condition is OFF when the specified bit in the specified word is ON, and ON when the bit is OFF.
  • Page 189 N: Bit number The bit number must be between 0000 and 000F hexadecimal or between &0000 and &0015 decimal. Only the rightmost bit (0 to F hexadecimal) of the contents of the word is valid when a word address is specified.
  • Page 190 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; the execution condition is OFF when the specified bit in the specified word is ON, and ON when the bit is OFF.
  • Page 191: Sequence Output Instructions

    If there is no immediate refreshing specification, the status of the execution condition (power flow) is written to the specified bit in I/O memory. If there is an immediate refreshing specification, the status of the execution condition (power flow) is also written to the Basic Output Unit's output terminal in addition to the output bit in I/O memory.
  • Page 192 OFF. Precautions • With CJ2 CPU Units, OUT can be used for bits in the DM or EM Area. For other models of CPU Unit, OUT cannot be used for bits in the DM or EM Area. Use OUTB(534) instead.
  • Page 193 Function TR bits are used to temporarily retain the ON/OFF status of execution conditions in a program when programming in mnemonic code. They are not used when programming directly in ladder program form because the processing is automatically executed by the Peripheral Device. The following diagram shows a simple application using two TR bits.
  • Page 194 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 195 Flags No flags are affected by KEEP(011). Function When S turns ON, the designated bit will go ON and stay ON until reset, regardless of whether S stays ON or goes OFF. When R turns ON, the designated bit will go OFF. The...
  • Page 196 • 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 197 • The status of I/O Area bits can be retained in the event of a power interruption by turning ON the IOM Hold Bit and setting IOM Hold Bit Hold in the PLC Setup. In this case, I/O Area bits used in KEEP(011) will maintain status after restarting the PLC following a power interruption, just like holding bits.
  • Page 198 KEEP (011) 1.00 Note KEEP(011) is input in different orders on in ladder and mnemonic form. In ladder form, input the set input, KEEP(011), and then the reset input. In mnemonic form, input the set input, the reset input, and then KEEP(011).
  • Page 199 Status of B 1 cycle Hint • UP(521) can be used to execute an instruction for just one cycle when the execution condition goes from OFF • DIFU(013) has immediate refreshing variation (!DIFU(013)). When an external output bit has been specified for B in this instruction, any changes to B will be refreshed when the instruction is executed and reflected immediately in the output bit.
  • Page 200 • The operation of DIFU(013) will not be consistent if the same subroutine is executed more than once in the same cycle. Sample program When CIO 0.00 goes from ON to OFF in the following example, CIO 10.00 is turned ON for one cycle. 0.00 DIFU 10.00...
  • Page 201 ON OFF. • 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 202 DIFD(014) in a function block definition. For details, refer to information on SBS(091). Sample program When CIO 0.00 goes from ON to OFF in the following example, CIO 10.00 is turned ON for one cycle. 0.00 10.00 0.00...
  • Page 203 Execution condition condition is ON, and does not affect the status of the of SET operand bit when the execution condition is OFF. Use RSET to turn OFF a bit that has been turned ON with Status of B SET. RSET...
  • Page 204 Precautions • With CJ2 CPU Units, SET can be used for bits in the DM or EM Area. For other models of CPU Unit, SET cannot be used for bits in the DM or EM Area. Use SETB(532) instead. With CJ2 CPU Units, RSET can be used for bits in the DM or EM Area.
  • Page 205 Flags Operand Description Data type Error Flag • ON if N1 is not within the specified range of 0000 to 000F (&0 to &15). • OFF in all other cases. Function SETA SETA(530) turns ON N2 bits, beginning from bit N1 of D, and continuing to the left N2 bits are set to 1 (ON).
  • Page 206 SETA(530). Hint SETA • SETA(530) can be used to turn ON bits in data areas that are normally accessed by words only, such as the DM and EM areas. RSTA • RSTA(531) can be used to turn OFF bits in data areas that are normally accessed by words only, such as the DM and EM areas.
  • Page 207 Flags Operand Description Data type Error Flag • ON if N is not within the specified range of 0000 to 000F (&0 to &15). • OFF in all other cases. Function SETB SETB(532) turns ON bit N of word D when the execution condition is ON.
  • Page 208 • Differences between SET/RSET and SETB(532)/RSTB(533) The instructions operate in the same way when the specified bit is in the CIO, W, H, or A Area. The SETB(532) and RSTB(533) instructions can control bits in the DM and EM Areas, unlike SET and RSET.
  • Page 209 If the immediate refreshing version is not This bit is turned OFF. used, the status of the execution condition (power flow) is written to the specified bit in Execution condition I/O memory. If the immediate refreshing version is used, the status of the execution...
  • Page 210 (This is the same as an OUT instruction in an interlocked program section.) • When a word is specified for the bit number (N), only bits 00 to 03 of N are used. For example, if N contains FFFA hex, OUTB(534) will control bit 10 of word D.
  • Page 211: Sequence Control Instructions

    • MULTI-INTERLOCK DIFFERENTIATION RELEASE and MULTI-INTERLOCK CLEAR (MILR(518) and MILC(519))* Note MILR(518) does not hold the status of the Differentiation Flag, so differentiated instructions that were inter- locked are not executed after the interlock is cleared. • These instructions are supported only by CS/CJ-series CPU Unit Ver. 2.0 or later and CJ2 CPU Units.
  • Page 212 IL(002) and ILC.(003). MILH Note The different interlocks (IL-ILC, MILH-MILC, and MILR-MILC) can be used together as long as the inter- locked program sections do not overlap. For example, all three interlock methods can be used without overlapping, as shown in the following diagram.
  • Page 213 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 214 Program Z End of the main program I/O refreshing Precautions • Always place END(001) at the end of each program. A programming error will occur if there is not an END(001) instruction in the program. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 215 No flags are affected by NOP(000). Function • No processing is performed for NOP(000), but this instruction can be used to set aside lines in the program where instructions will be inserted later. • NOP(000) can only be used with mnemonic displays, not with ladder programs.
  • Page 216 Unchanged *1 In CJ2, CS1-H, CJ1-H, CJ1M, and CS1D (for Single-CPU System) CPU Units, the Equals and Negative Flags are left unchanged. In CS1D CPU Units for Duplex Systems, CS1 CPU Units, and CJ1 CPU Units, these are turned OFF.
  • Page 217 • In general, IL(002) and ILC(003) are used in pairs, although it is possible to use more than one IL(002) with a single ILC(003) as shown in the following diagram. If IL(002) and ILC(003) are not paired, an error message will appear when the program check is performed but the program will be executed properly.
  • Page 218 2. Input condition 0.01 of DIFU goes from OFF to ON while 0.00 is OFF (interlock in effect), 3. When 0.00 goes from OFF to ON (interlock cleared), the DIFU instruction is executed if input condition 0.01 of DIFU is ON.
  • Page 219 3. Instructions Sample program 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 220 BOOL N: Interlock Number The interlock number must be between 0 and 15. Match the interlock number of the MILH(517) (or MILR(518)) instruction with the same number in the corresponding MILC(519) instruction. The interlock numbers can be used in any order.
  • Page 221 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 222 When the Conveyor RUN switch is OFF (input condition OFF), both A2 and A3 are interlocked. When the Conveyor RUN switch is ON (input condition ON), A2 is executed normally and A3 is controlled by the Arm RUN switch as described below.
  • Page 223 2. The DIFU's CIO 0.01 input condition goes from OFF to ON while CIO 0.00 is OFF (DIFU interlocked), start of interlock Differentiation condition established 3. When CIO 0.00 goes from OFF to ON (interlock cleared), DIFU is executed if CIO 0.01 is still ON. 0.01 0.01...
  • Page 224 2. The DIFU's CIO 0.01 input condition goes from OFF to ON while CIO 0.00 is OFF (DIFU interlocked), 3. When CIO 0.00 goes from OFF to ON (interlock cleared), DIFU is not executed even though CIO 0.01 is still ON.
  • Page 225 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 226 Note The MILR(518) interlocks operate in the same way if there is another MILH(517) or MILR(518) instruction with the same interlock number between an MILR(518) and MILC(519) pair. • If there is an MILC(519) instruction with a MILH When input condition "a"...
  • Page 227 ... • If there are bits which you want to remain ON in a program section interlocked by MILH(517) or MILR(518), set these bits to ON with SET just before the MILH(517) or MILR(518) instruction. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 228 3. Instructions Sample program 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 229 • ON if there is a JMP(004) in the program without a JME(005) with the same jump number. • ON if there is a JMP(004) in the task without a JME(005) with the same jump number in the task. • OFF in all other cases.
  • Page 230 • Because all of instructions between JMP(004)/CJP(510)/CJPN(511) and JME(005) are skipped when the execution condition for JMP(004) is OFF, the cycle time is reduced by the total execution time of the skipped instructions. In contrast, processing time equivalent to NOP(000) processing is required for instructions between JMP0(515) and JME0(516), so the cycle time is not reduced as much with those jump instructions.
  • Page 231 JME &1 • JMP(004) and JME(005) pairs must be in the same task because jumps between tasks are not allowed. An error will occur if a JME(005) instruction is not programmed in the same task as its corresponding JMP(004) instruction.
  • Page 232 • ON if there is a CJP(510) or CJPN(511) instruction in a task without a JME(005) with the same jump number. • OFF in all other cases. Note For CJ1M-CPU11 and CJ1M-CPU21 CPU Units, the jump number must be between the range 0 to 255 (0000 to 00FF hex). CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 233 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 234 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 235 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 236 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 237 3. Instructions Sample program When CIO 0.00 is OFF in the following example, the instructions between JMP0(515) and JME0(516) are 0.00 CIO 0.00 CIO 0.00 processed as NOP(000) instructions and the outputs 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 238 Loops can be used to process tables of data with a minimum amount of programming. Note If a loop repeats in one cycle and a differentiated bit is used in the FOR-NEXT loop, that bit will be always ON or always OFF within that loop.
  • Page 239 JMP(004) is OFF. (A Cycle Time Too Long error will occur if the execution condition is not turned ON or END(001) is not executed within the maximum cycle time.) Precautions •...
  • Page 240 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 241 Processed as NOP(000). Precautions • A BREAK(514) instruction cancels only one loop, so several BREAK(514) instructions (the number of levels nested) are required to escape from nested loops. • BREAK(514) can be used only in a FOR-NEXT loop. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 242: Timer And Counter Instructions

    PLC Setup for the entire product. • In the CJ2 CPU Units, BCD and binary PV refreshing can both be used in the same project. The setting of the PV refresh method in the PLC Setup will be ignored.
  • Page 243 80 ms. Com- ple- Value tion after Flags reset Note Timers are refreshed at different times depending on the timer number. Refer to the descriptions of individual timer instructions for details TIM/TIMX TIMH(015)/ TMHH(540)/ TIMU(541)/ TMUH(544)/ TTIM(087)/ TIML(542)/...
  • Page 244 In this example, a TIM instruction and a CNT instruction are combined to make a 500-second timer. TIM 0001 generates a pulse every 5 s and CNT 0002 counts these pulses. The set value for this combination is the timer interval counter SV.
  • Page 245 In this example two TIM timers are combined with KEEP(011) to make an ON delay and an OFF delay. CIO 5.00 will be turned ON 5.0 seconds after CIO 0.00 goes ON and it will be turned OFF 3.0 seconds after CIO 0.00 goes OFF.
  • Page 246 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.
  • Page 247 • 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 248 1. Use the TIMER RESET Instruction. The specified instruction will be reset when the TIMER RESET instruction (TRSET) is executed. TRSET can be used to reset only one timer at a time, but it is faster than the RESET TIMER/COUNTER instruction (CNR/CNRX).
  • Page 249 The specified instruction will be reset when the RESET TIMER/COUNTER instruction (CNR/CNRX) is executed. More than one timer can be reset at the same time for CNR/CNRX, but more time is required than for TRSET. CNR/CNRX is used in the same way as TRSET.
  • Page 250 Operation Error Flag • ON if N is indirectly addressed through an Index Register but the address in the Index Register is not the address of a timer Completion Flag or timer PV. • ON if in BCD mode and S does not contain BCD data.
  • Page 251 4.1 of the CJ1-H-R is -0.1 to 0 s. Hint A TIM/TIMX(550) instruction's PV and Completion Flag can be refreshed in the following ways depending on the timer number that is used. Timers Created with Timer Numbers 0000 to 2047...
  • Page 252 *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 off.
  • Page 253 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 254 Operation Error Flag • ON if N is indirectly addressed through an Index Register but the address in the Index Register is not the address of a timer Completion Flag or timer PV. • ON if in BCD mode and S does not contain BCD data.
  • Page 255 TIMHX(551). The timer accuracy is 0 to 0.01 s. Completion Flag Hint A TIMH(015)/TIMHX(551) instruction's PV and Completion Flag can be refreshed in the following ways depending on the timer number that is used. Timers Created with Timer Timers Created with Timer...
  • Page 256 *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 off.
  • Page 257 SV (#0064 = 100 = 1.00 s). The 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 258 Operation Error Flag • ON if N is indirectly addressed through an Index Register but the address in the Index Register is not the address of a timer Completion Flag or timer PV. • ON if in BCD mode and S does not contain BCD data.
  • Page 259 *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.
  • Page 260 • If the TMHH/TMHHX instruction is in a task that is stopped or is not executed because it is jumped by a JMP, CJMP, or CJPN instruction, there will be an error in the timer of up to minus 10 ms.
  • Page 261 Operation Error Flag • ON if timer number N is indirectly addressed through an Index Register but the address in the Index Register is not the address of a timer's Completion Flag or PV. • ON if in BCD mode and S does not contain BCD data.
  • Page 262 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.
  • Page 263 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 264 Operation Error Flag • ON if timer number N is indirectly addressed through an Index Register but the address in the Index Register is not the address of a timer's Completion Flag or PV. • ON if in BCD mode and S does not contain BCD data.
  • Page 265 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.
  • Page 266 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 267 Operation Error Flag • ON if N is indirectly addressed through an Index Register but the address in the Index Register is not the address of a timer Completion Flag or timer PV. • ON if in BCD mode and S does not contain BCD data.
  • Page 268 *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.
  • Page 269 Timer Completion Flag T0001 will be turned ON when the PV reaches the SV. If the reset input is turned ON, the timer PV will be reset to 0 and the Completion Flag (T0001) will be turned OFF. (Usually the reset input is turned ON to reset the timer and then the timer input is turned ON to start timing.)
  • Page 270 Error Flag • ON if the PV contained in D2 is not BCD. • ON if the SV contained in S is not BCD, when TIML(542) is used. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 271 TIML(542)/TIMLX(553) is programmed between JMP(004) and JME(005). • Be sure that the words specified for the Completion Flag and PV (D1, D2, and D2+1) are not used in other instructions. If these words are affected by other instructions, the timer might not time out properly.
  • Page 272 Sample program 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 273 Completion Flags • In Binary: Reset bit &0 to &65535 (decimal) or Pause bit #0000 to #FFFF (hex) Note S through S+7 must be in the same data area. Corresponding bit (Completion Flag) in D1 Operand Specifications Indirect DM/EM Word addresses...
  • Page 274 • When the PV reaches 9999, the PV will be reset to 0 and all of the Completion Flags will be turned OFF. • 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.
  • Page 275 • The timer's Completion Flag is refreshed only when MTIM(543)/MTIMX(554) is executed, so a delay of up to one cycle may be required for the Completion Flag to be turned ON after the timer times out. • When MTIM(543)/MTIMX(554) 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).
  • Page 276 Timer input must remain ON while the timer is timing. Reset bit 100.08 Pause bit 100.09 Timing resumes. Max. PV = 9999 Timer SVs SV 7 SV 1 PV maintained. SV 0 Completion Flags CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 277 Operation Error Flag • ON if N is indirectly addressed through an Index Register but the address in the Index Register is not the address of a counter Completion Flag or counter PV. • ON if in BCD mode and S does not contain BCD data.
  • Page 278 • A counter's PV is refreshed when the count input goes from OFF to ON and the Completion Flag is refreshed each time that CNT/CNTX(546) is executed. The Completion Flag is turned ON if the PV is 0 and it is turned OFF if the PV is not 0.
  • Page 279 • The reset input will take precedence and the counter will be reset if the reset input and count input are both ON at the same time. (The PV will be reset to the SV and the Completion Flag will be turned OFF.)
  • Page 280 Operation Error Flag • ON if N is indirectly addressed through an Index Register but the address in the Index Register is not the PV address of a counter. • ON if in BCD mode and S does not contain BCD data.
  • Page 281 • The PV will not be changed if the increment and decrement inputs both go from OFF to ON at the same time. When the reset input is ON, the PV will be reset to 0 and both count inputs will be ignored.
  • Page 282 ON, the PV changes to 0 and count input is not accepted. In the following example, the SV for CNTR(012) 0007 is determined by the content of CIO 0001. When the content of CIO 0001 is controlled by an external switch, the set value can be changed manually from the switch.
  • Page 283 N2 must be a timer number between T0000 and T4095 or a counter number between C0000 and C4095 Note N1 and N2 must be in the same data area, i.e., N1 and N2 must be timer numbers or counter numbers. Operand Specifications...
  • Page 284 CNR(545)/CNRX(547) is different from directly resetting the instructions. For example, when a TIM/TIMX(550) instruction is reset directly its PV is set to the SV, but when that timer is reset by CNR(545)/CNRX(547) its PV is set to the maximum value (9999 for BCD and FFFF for binary).
  • Page 285 Label Operation Error Flag • ON if N is indirectly addressed through an Index Register but the address in the Index Register is not the address of a timer Completion Flag or timer PV. • OFF in all other cases.
  • Page 286: Comparison Instructions

    ON execution condition when the comparison condition is true. Note Input comparison instructions are available to compare signed or unsigned data of one-word or double length data. Refer to 3-15-24 Single-precision Floating-point Comparison Instructions for details on single-precision floating-point input comparison instructions and 3-16-21 Double-precision Floating-point Input Comparison Instructions for details on double-precision floating-point input comparison instructions.
  • Page 287 Negative Flag OFF or unchanged (See note.) Note In CS1D CPU Units for Duplex Systems, CS1 CPU Units, and CJ1 CPU Units, these are turned OFF. In CJ2, CS1-H, CJ1-H, CJ1M, and CS1D CPU Units, these Flags are left unchanged.
  • Page 288 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...
  • Page 289 When CIO 0.00 is ON in the following example, the contents of D100 and D200 are compared in as unsigned binary data. If the content of D100 is less than that of D200, CIO 50.00 is turned ON and execution proceeds to the next line. If the content of D100 is not less than that of D200, the remainder of the instruction line is skipped and execution moves to the next instruction line.
  • Page 290 C: Control Word Bits 00 to 05 of C specify whether or not the time data will be masked for the comparison. Bits 00 to 05 mask the seconds, minutes, hours, day, month, and year, respectively. If all 6 values are masked, the instruction will not be executed, the execution condition will be OFF, and the Error Flag will be turned Masks seconds data when ON.
  • Page 291 S1, S2 Flags Name Label Operation Error Flag • ON if all 6 of the mask bits (C bits 00 to 05) are ON. • OFF in all other cases. Greater Than Flag > • ON if S > S •...
  • Page 292 Time values can be masked individually and excluded from the comparison operation. To mask a time value, set the corresponding bit in the control word (C) to 1. Bits 00 to 05 of C mask the seconds, minutes, hours, day, month, and year, respectively.
  • Page 293 Sample program When CIO 0.00 is ON and the time is 13:00:00, CIO 50.00 is turned ON. The contents of A351 to A353 (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 294 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)
  • Page 295 Unchanged (See note.) Unchanged (See note.) Note In CS1D CPU Units for Duplex Systems, CS1 CPU Units, and CJ1 CPU Units, these are turned OFF. The following table shows the status of the Arithmetic Flags after execution of CMP(020). Flag status CMP(020) Result >...
  • Page 296 Slave Racks.) Sample program • When CIO 0.00 is ON in the following example, the eight-digit unsigned binary data in CIO 0011 and CIO 0010 is compared to the eight-digit unsigned binary data in CIO 0009 and CIO 0008 and the result is output to the Arithmetic Flags.
  • Page 297 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...
  • Page 298 Unchanged (See note.) OFF or unchanged (See note.) Note In CS1D CPU Units for Duplex Systems, CS1 CPU Units, and CJ1 CPU Units, these are turned OFF. The following table shows the status of the Arithmetic Flags after execution of CPS(114).
  • Page 299 • If the content of D2 and D1 is greater than that of D6 and D5, the Greater Than Flag will be turned ON, causing CIO 20.00 to be turned ON. • If the content of D2 and D1 is equal to that of D6 and D5, the Equals Flag will be turned ON, causing CIO 20.01 to be turned ON.
  • Page 300 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 S1: First word of set 1...
  • Page 301 +n; bit n of R is turned ON if the contents are not equal. Hint • If the contents of all 16 pairs of words are the same, the Equals Flag will turn ON after the instruction has been executed. Sample program When CIO 0.00 is ON in the following example, MCMP(019) compares words D100 through D115 in...
  • Page 302 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. TCMP TCMP(085) Symbol S: Source data...
  • Page 303 R is turned ON if they are equal or OFF if they are not equal, ..., and S is compared to the content of T+15 and bit 15 of R is turned ON if they are equal or OFF if they are not equal. Sample program When CIO 0.00 is ON in the following example, TCMP(085) compares the content of D100 with the...
  • Page 304 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 305 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). If S is within any of these ranges (inclusive of the upper and lower limits), the corresponding bit in R is turned ON.
  • Page 306 B: First word of block R: First result word N: 00 to FF hex Each bit of each R word contains the result of a comparison between S and (0 to 255) Comparison block one of the ranges defined the comparison block. The maximum number of Word result words is 16, i.e., m equals 0 to 15.
  • Page 307 (R to R+15 max.) are turned ON. The rest of the bits in R will be turned OFF. The number of ranges is determined by the value N set in the lower byte of B. N can be between 0 and 255. The upper byte of B must be 00 hex.
  • Page 308 For example, if the source data in CIO 10 is in the range defined by D201 and D202, then bit 00 of CIO 100 is turned ON and if it in not in the range, then bit 00 of CIO 100 is turned OFF. Likewise,...
  • Page 309 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,...
  • Page 310 ZCPL(116) compares the 32-bit signed binary data in CD+1, CD with the range defined by LL+1, LL and UL+1, UL and outputs the result to the Greater Than, Equals, and Less Than Flags in the Auxiliary Area. (The Less Than or Equal, Greater Than or Equal, and Not Equal Flags are left unchanged.) When S+1,S >...
  • Page 311 Sample program • When CIO 0.00 is ON in the following example, the 16-bit unsigned binary data in D0 is compared to the range 0005 to 001F hex (5 to 31 decimal) and the result is output to the Arithmetic Flags.
  • Page 312: Data Movement Instructions

    • ON if the data being transferred (D) is 0. • OFF in all other cases. Negative Flag • ON if the leftmost bit of the data being transferred (D) is 1. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 313 MOV(021) has an immediate refreshing variation (!MOV(021)). An external input bits can be specified for S and external output bits can be specified for D. Input bits used for S will refreshed just before, and output bits used for D will be refreshed just after execution unless the bits are 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 314 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...
  • Page 315 • ON if the data being transferred (D) is 0. • OFF in all other cases. Negative Flag • ON if the leftmost bit of the data being transferred (D) is 1. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 316 3. Instructions Function 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 inverted.
  • Page 317 IR Flags Name Label Operation Error Flag • ON if the rightmost and leftmost two digits of C are not within the specified range of 00 to 0F. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 318 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.
  • Page 319 Digit 1 Digit 0 The destination digits are written from right to The source digits are read from right to left, left, wrapping back to the rightmost digit (digit wrapping back to the rightmost digit (digit 0) if 0) if necessary.
  • Page 320 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 321 First bit in D (m): 0 to F (0 to 15) Number of bits (n): 00 to FF (0 to 255) Note The source words and the destination words must be in the same data area respectively. S: First Source Word S+16 max. Operand Specifications...
  • Page 322 • Bits in the destination words that are not overwritten by the source bits are left unchanged. Sample program When CIO 0.00 is ON in the following example, the 20 bits beginning with CIO 200.06 are copied to the 20 bits beginning with CIO 300.
  • Page 323 WORD Variable First destination word WORD Variable N: Number of Words Specifies the number of words to be transferred. The possible range for N is 0000 to FFFF (0 to 65,535 decimal). S+(N-1) D+(N-1) Operand Specifications Indirect DM/EM Word addresses...
  • Page 324 D111 Precautions • Be sure that the source words (S to S+N-1) and destination words (D to D+N-1) do not exceed the end of the data area. • Some time will be required to complete XFER(070) when a large number of words is being transferred.
  • Page 325 • ON if St is greater than E. • OFF in all other cases. Note Be sure that the starting word (St) and end word (E) are in the same data area and that St CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 326 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. If power is interrupted during execution of BSET(071), execution may not be completed, i.e., all of the specified words may not be...
  • Page 327 Unchanged (See note.) Equals Flag Unchanged (See note.) Negative Flag Unchanged (See note.) Note In CS1D CPU Units for Duplex Systems, CS1 CPU Units, and CJ1 CPU Units, these are turned OFF. Function XCHG XCGL XCHG(073) exchanges the contents of E1 and XCHG(073) exchanges the contents of E1+1 and E1 with the contents of E2+1 and E2.
  • Page 328 3. Instructions Hint exchange more words, XFER(070) XFER(070) to transfer the words to a third set operation of words (a buffer) as shown in this diagram. Buffer XFER(070) operation XFER(070) operation Sample program When CIO 0.00 is ON in this example, the When CIO 0.00 is ON in this example, the...
  • Page 329 Offset UINT Bs: Destination Base Address Bs+Of Of: Offset The offset can be any value from 0000 to FFFF (0 to 65,535 decimal). Note Bs and Bs+Of must be in the same data area. Operand Specifications Indirect DM/EM Word addresses...
  • Page 330 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. Sample program When CIO 0.00 is ON in this example, the contents of D100 will be copied to D210 (D200 + 10) if the...
  • Page 331 Destination word WORD Bs: Source Base Address Bs+Of Of: Offset The offset can be any value from 0000 to FFFF (0 to 65,535 decimal). Note Bs and Bs+Of must be in the same data area. Operand Specifications Indirect DM/EM Word addresses...
  • Page 332 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. Sample program When CIO 0.00 is ON in the following example, the contents of D110 (D100 + 10) will be copied to...
  • Page 333 Error Flag Unchanged (See note.) Equals Flag Unchanged (See note.) Negative Flag Unchanged (See note.) Note In CS1D CPU Units for Duplex Systems, CS1 CPU Units, and CJ1 CPU Units, these are turned OFF. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 334 PLC memory addresses of timer/counter PVs. • The contents of an index register in an interrupt task is not predictable until it is set. Be sure to set a register using MOVR(560) in an interrupt task before using the register.
  • Page 335 3. Instructions Sample program 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...
  • Page 336: Data Shift Instruction

    Step program areas Subroutines Interrupt tasks definitions programs Usage Not allowed * OK as long as words in the CIO Area, Work Area, or Holding Area are specified in the function block instance allocation areas. Operands Operand Description Data type Size...
  • Page 337 (E) will be reset (i.e., set to 0). The reset input takes priority over other inputs. • St must be less than or equal to E, but even when St is set to greater than E an error will not occur and one word of data in St will be shifted.
  • Page 338 C: Control Word 15 14 13 12 Shift direction 1 (ON): Left 0 (OFF): Right Data input Shift input Reset Note St and E must be in the same data area. Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con-...
  • Page 339 • The above shift operations are applicable when the reset bit (bit 15 of C) is set to OFF. • When reset (bit 15 of C) turns ON all bits in the shift register, from St to E will be reset (i.e., set to 0).
  • Page 340 Error Flag • ON when St is greater than E. • 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. • OFF in all other cases.
  • Page 341 If the Shift Enable Bit, CIO 300.14, goes ON when CIO 0.00 is ON, all words with non-zero data content from CIO 100 through CIO 109 will be shifted in the direction designated by the Shift Direction Bit, CIO 300.13 (e.g., 1: Toward St) if the word to the left of the non-zero data is all zeros. 0.00...
  • Page 342 • St and E must be in the same data area. • When large amounts of data are shifted, the instruction execution time is quite long. Be sure that the power is not cut while WSFT(016) is being executed, causing the shift operation to stop halfway through.
  • Page 343 Sample program 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.
  • Page 344 • 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. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 345 When CIO 0.00 is ON, word CIO 100 and CIO shifted one bit to the left. “0” will be placed in 101 will shift one bit to the left. “0” is placed into CIO 100.00 and the contents of CIO 100.15 CIO 100.00 and the contents of CIO 101.15 will...
  • Page 346 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 ASR(026) ASRL(571) Symbol Wd: Word Wd: Word...
  • Page 347 When CIO 0.00 is ON, word CIO 100 and CIO 101 shift one bit to the right. “0” will be placed in will shift one bit to the right. “0” will be placed into CIO CIO 100.15 and the contents of CIO 100.00 100.15 and the contents of CIO 100.00 will be shifted...
  • Page 348 • 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. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 349 Carry Flag (CY) to the left (from rightmost bit to leftmost bit). Hint It is possible to set the Carry Flag contents to 1 or 0 immediately before executing this instruction, by using the Set Carry (STC(040)) or Clear Carry (CLC(041)) instructions. Sample program When CIO 0.00 is ON, word CIO 100 and the...
  • Page 350 • 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. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 351 Sample program When CIO 0.00 is ON, word CIO 100 will shift When CIO 0.00 is ON, word CIO 100 and CIO 101 one bit to the left (excluding the Carry Flag will shift one bit to the left (excluding the Carry (CY)).
  • Page 352 • 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. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 353 Carry Flag (CY) to the right (from leftmost bit to rightmost bit). Hint It is possible to set the Carry Flag contents to 1 or 0 immediately before executing this instruction, by using the Set Carry (STC(040)) or Clear Carry (CLC(041)) instructions. Sample program When CIO 0.00 is ON, word CIO 100 and the...
  • Page 354 • 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. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 355 Sample program When CIO 0.00 is ON, word CIO 100 will When CIO 0.00 is ON, words CIO 100 and CIO 101 shift one bit to the right (excluding the Carry will shift one bit to the right, (excluding the Carry Flag Flag (CY)).
  • Page 356 Function SLD(074) shifts data between St and E by one digit (4 bits) to the left. “0” is placed in the rightmost digit (bits 3 to 0 of St), and the content of the leftmost digit (bits 15 to 12 of E) is lost.
  • Page 357 When CIO 0.00 is ON, words CIO 100 through CIO 102 will shift by one digit (4 bits) to the left. A zero will be placed in bits 0 to 3 of word CIO 100 and the contents of bits 12 to 15 of CIO 102 will be lost.
  • Page 358 C: Beginning bit 0000 to 000F hex (0 to 15) N: Shift data length 0000 to FFFF hex (0 to 65535) Note All words in the shift register must be in the same area. Operand Specifications Indirect DM/EM Word addresses...
  • Page 359 NSFL When CIO 0.00 is ON, all bits from the beginning bit 3 to the shift data length (B hex) will be shifted one bit to the left (from the rightmost bit to the leftmost bit). “0” will be placed into bit 3 of CIO 100. The contents of the leftmost bit in the shift area (bit 13 of CIO 100) are copied into the Carry Flag (CY).
  • Page 360 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 361 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...
  • Page 362 Sample program When CIO 0.00 is ON, The contents of CIO 100 is shifted 10 bits to the left (from the rightmost bit to the leftmost bit). The number of bits to shift is specified in bits 0 to 7 of word CIO 300 (control data). The contents of bit 0 of CIO 100 is copied into bits from which data was shifted and the contents of the rightmost bit which was shifted out of range is shifted into the Carry Flag (CY).
  • Page 363 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. The number of bits to shift is specified in bits 0 to 7 of word CIO 300 (control data).
  • Page 364 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. • OFF in all other cases.
  • Page 365 Sample program • When CIO 0.00 is ON, CIO 100 will be shifted 10 bits to the right (from the leftmost bit to the rightmost bit). The number of bits to shift is specified in bits 0 to 7 of word CIO 300. The contents of bit 15 of CIO 100 is copied into the bits from which data was shifted and the contents of the leftmost bit of data which was shifted out of range, is shifted into the Carry Flag (CY).
  • Page 366 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). The number of bits to shift is specified in bits 0 to 7 of word CIO 300 (control data).
  • Page 367: Increment/Decrement Instructions

    • ON if the result is 0000/0000 0000 after execution. • OFF in all other cases. Carry Flag • ON if a digit in Wd/Wd+1 or Wd went from F to 0 during execution. • OFF in all other cases. Negative Flag •...
  • Page 368 OFF to ON. Sample program Operation of ++(590)/++L(591) In the following example, the content of D100 will be incremented by 1 every cycle as long as CIO 0.00 is ON. 0.00 Incremented every cycle while CIO 0.00 is ON.
  • Page 369 0 0 1 9 0 0 1 A The up-differentiated variation is used in the following example, so the content of D101 and D100 will be incremented by 1 only when CIO 0.00 has gone from OFF to ON. 0.00...
  • Page 370 • ON if the result is 0000/0000 0000 after execution. • OFF in all other cases. Carry Flag • ON if a digit in Wd/Wd+1 or Wd went from 0 to F during execution. • OFF in all other cases. Negative Flag •...
  • Page 371 D100 D100 0 0 2 0 0 0 1 F In the following example, the 8-digit hexadecimal content of D101 and D100 will be decremented by 1 every cycle as long as CIO 0.00 is ON. Decremented every cycle 0.00 while CIO 0.00 is ON.
  • Page 372 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...
  • Page 373 • ON if the result is 0000/0000 0000 after execution. • OFF in all other cases. Carry Flag • ON if a digit in Wd/Wd+1 or Wd went from 9 to 0 during execution. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 374 OFF to ON. Sample program Operation of ++B(594)/++BL(595) In the following example, the BCD content of D100 will be incremented by 1 every cycle as long as CIO 0.00 is ON. Incremented every cycle 0.00 while CIO 0.00 is ON.
  • Page 375 D100 D100 D100 The up-differentiated variation is used in the following example, so the BCD content of D101 and D100 will be incremented by 1 only when CIO 0.00 has gone from OFF to ON. Incremented only for 0.00 up-differentiation.
  • Page 376 • ON if the result is 0000/0000 0000 after execution. • OFF in all other cases. Carry Flag • ON if a digit in Wd/Wd+1 or Wd went from 0 to 9 during execution. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 377 OFF to ON. Sample program Operation of --B(596)/--BL(597) In the following example, the BCD 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.
  • Page 378 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 Decremented only for up-differentiation.
  • Page 379: Symbol Math Instructions

    DINT +L: First addend word +: Result word DINT +L: First result word Operand Specifications Indirect Word addresses DM/EM Registers Con- Pulse addresses Area stants bits bits Indirect using IR Au, Ad Au, Ad CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 380 (Signed binary) CY will turn ON (Signed binary) when there is a carry. +L(401) adds the binary values in Au and Au+1 and Ad and Ad+1 and outputs the result to R. (Signed binary) Au+1 (Signed binary) Ad+1 CY will turn ON...
  • Page 381 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)
  • Page 382 (Signed binary) CY will turn ON (Signed binary) when there is a carry. +CL(403) adds the binary values in Au and Au+1, Ad and Ad+1, and CY and outputs the result to R. Au+1 (Signed binary) (Signed binary) Ad+1 CY will turn ON...
  • Page 383 Label 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. • OFF in all other cases.
  • Page 384 (BCD) (BCD) CY will turn ON (BCD) when there is a carry. +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) Ad+1 CY will turn ON...
  • Page 385 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 386 (BCD) CY will turn ON (BCD) when there is a carry. +BCL +BCL(407) adds the BCD values in Au and Au+1, Ad and Ad+1, and CY and outputs the result to R, R+1. Au+1 (BCD) (BCD) Ad+1 CY will turn ON...
  • Page 387 –L: First subtrahend word –: Result word DINT –L: First result word Operand Specifications Indirect Word addresses DM/EM Registers Con- Pulse addresses Area stants bits bits Indirect using IR MI, Su – Mi, Su –L CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 388 –L –L(411) subtracts the binary values in Su and Su+1 from Mi and Mi+1 and outputs the result to R, R+1. When the result is negative, it is output to R and R+1 as a 2's complement. (Signed binary)
  • Page 389 21.00 In this example, the eight-digit binary value in CIO 121 and CIO 120 is subtracted from the value in CIO 201 and CIO 200, and the result is output in eight-digit binary to D101 and D100. If the result is negative, the instruction at (2) will be executed, and the actual result will then be output to D101 and D100.
  • Page 390 D120 If the result of the subtraction is a negative number (Mi<Su or Mi+1, Mi <Su+1, Su), the result is output as the 2's complement and the Carry Flag (CY) will turn ON to indicate that the result of the subtraction is negative.
  • Page 391 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 392 • OFF in all other cases. Function –C –C(412) subtracts the binary values in Su and CY from Mi, and outputs the result to R. When the result is negative, it is output to R as a 2's complement. (Signed binary) (Signed binary) –...
  • Page 393 D120 If the result of the subtraction is a negative number (Mi<Su or Mi+1, Mi <Su+1, Su), the result is output as a 2's complement. The Carry Flag (CY) will turn ON. To convert the 2's complement to the true number, a program which subtracts the result from 0 is necessary, as an input condition of the Carry Flag (CY).
  • Page 394 –BL Error Flag • ON when Mi is not BCD. • ON when Mi and/or Mi +1 are not BCD. • ON when Su is not BCD. • ON when Su and/or Su +1 are not BCD. • OFF in all other cases.
  • Page 395 For example, the 10's complement for 7556 is calculated as follows: 9999 - 7556 + 1 = 2444. For a four digit number, the 10's complement of A is 9999 – A + 1 = B. To obtain the true number from the 10's complement B: A = 10000 –...
  • Page 396 D120 If the result of the subtraction is a negative number (Mi<Su or Mi+1, Mi <Su+1, Su), the result is output as a 10's complement. The Carry Flag (CY) will turn ON. To convert the 10's complement to the true number, a program which subtracts the result from 0 is necessary, as an input condition of the Carry Flag (CY).
  • Page 397 –BCL Error Flag • ON when Mi is not BCD. • ON when Mi and/or Mi +1 are not BCD. • ON when Su is not BCD. • ON when Su and/or Su +1 are not BCD. • OFF in all other cases.
  • Page 398 For example, the 10's complement for 7556 is calculated as follows: 9999 - 7556 + 1 = 2444. For a four digit number, the 10's complement of A is 9999 – A + 1 = B. To obtain the true number from the 10's complement B: A = 10000 –...
  • Page 399 • OFF in all other cases. • OFF in all other cases. Negative Flag • ON when the leftmost bit of the result is 1. • ON when the leftmost bit of the result is 1. • OFF in all other cases.
  • Page 400 D122, D121 and D120. D120 Example in Function Block Definition In the following example, an array variable is used to get the result from the function block as one word. a * b → c Function Block Variables Multiplicand: a (data type: INT)
  • Page 401 Equals Flag • ON when the result is 0. • OFF in all other cases. Negative Flag • ON when the leftmost bit of the result is 1. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 402 D120. D110 D120 Example in Function Block Definition In the following example, an array variable is used to get the result from the function block as one word. a * b Function Block Variables Multiplicand: a (data type: UINT)
  • Page 403 • ON when Md is not BCD. • ON when Md and/or Md+1 are not BCD. • ON when Mr is not BCD. • ON when Mr and/or Mr +1 are not BCD. • OFF in all other cases. • OFF in all other cases.
  • Page 404 D123, D122, D121 and D120. D110 D120 Example in Function Block Definition In the following example, an array variable is used to get the result from the function block as one word. a * b Function Block Variables Multiplicand: a (data type: WORD)
  • Page 405 • ON when the divisor is 0. • OFF in all other cases. Equals Flag • ON when as a result of the division, R/R+1, R is 0. • OFF in all other cases. Negative Flag • ON when the leftmost bit of the R/R+1, R is 1.
  • Page 406 /L(431) divides the signed binary values in Dd and Dd+1 by those in Dr and Dr+1 and outputs the result to R, R+1, R+2, and R+3. The quotient is output to R and R+1 and the remainder is output to R+2 and R+3.
  • Page 407 • ON when the divisor is 0. • OFF in all other cases. Equals Flag • ON when as a result of the division R/R+1, R is 0. • OFF in all other cases. Negative Flag • ON when the leftmost bit of the R/R+1, R is 1.
  • Page 408 3. Instructions Function /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(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 409 • OFF in all other cases. Equals Flag • ON when as a result of the division R is 0. • ON when as a result of the division R+1, R is 0. • OFF in all other cases. • OFF in all other cases.
  • Page 410 3. Instructions Function /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(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 411: Conversion Instructions

    Label BINL Error Flag • ON if the content of S is not BCD. • ON if the contents of S+1, S are not BCD. • OFF in all other cases. • OFF in all other cases. Equals Flag • ON if the result is 0000.
  • Page 412 In this example, N words of BCD data is converted to binary data. If N = 3, the three words of BCD starting from D10 will be converted to binary data one word at a time when CIO 0.00 turns ON. The resulting binary data will be stored starting from D100.
  • Page 413 S must be between 0000 and 270F hexadecimal (0000 and 9999 decimal). • BCDL The content of S+1 and S must be between 0000 0000 and 05F5 E0FF hexadecimal (0000 0000 and 9999 9999 decimal). Note S to S+1 and D to D+1 must each be the same area type.
  • Page 414 The following diagram shows an example of 8-digit BCD-to-binary conversion. Sample program When CIO 0.00 is ON in the following example, the hexadecimal value in CIO 11 and CIO 10 is converted to a BCD value and stored in D100 and D101.
  • Page 415 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.
  • Page 416 Equals Flag • ON if the result is 0000/0000 0000. • OFF in all other cases. Negative Flag • ON if bit 15 of the result is ON. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 417 Note The result for 8000 0000 hex will be 8000 0000 hex. Hint • This operation (reversing the status of the bits and adding 1) is equivalent to subtracting the content of S/S+1 and S from 0000/0000 0000. Sample program When CIO 0.00 is ON in the following example, NEG(160) calculates the 2's complement of the content...
  • Page 418 Source word WORD First result word DINT R: First result word R: Contents of S R+1: #0000 or #FFFF (hex) Note R and R+1 must be in the same data area. Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses...
  • Page 419 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 420 (Returns to digit 3 after digit 0) D+3: Decoding result of 4th digit of decoded digits Note The result words must be in the same data area. C: Control Word Specifies the first digit/byte to be converted 0 to 3 (digit 0 to 3)
  • Page 421 • OFF in all other cases. Function MLPX(076) can perform 4-to-16 bit or 8-to-256 bit conversions. Set the leftmost digit of C to 0 to specify 4-to-16 bit conversion and set it to 1 to specify 8-to-256 bit conversion. 4-to-16 bit Conversion When the leftmost digit of C is 0, MLPX(076) l =1 (Convert 2 digits.)
  • Page 422 Precaution 4-to-16 bit conversion When two or more digits are being converted, MLPX(076) will read the digits in S from right to left and will wrap around to the rightmost digit after the leftmost digit, if necessary. 8-to-256 bit conversion When two bytes are being converted, MLPX(076) will read the bytes in S from right to left and will wrap around to the rightmost byte if the leftmost byte (byte 1) has been specified as the starting byte.
  • Page 423 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 424 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 425 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 spec- ified digit (or byte) in the result word.
  • Page 426 • OFF in all other cases. Function DMPX(077) can perform 16-to-4 bit or 256-to-8 bit conversions. Set the leftmost digit of C to 0 to specify 16-to-4 bit conversion and set it to 1 to specify 256-to-8 bit conversion. 16-to-4 bit Conversion When the fourth (leftmost) digit of C is 0, DMPX(077) finds the locations of the leftmost or rightmost ON bits in up to 4 source words and writes these locations to R beginning with the specified digit.
  • Page 427 256-to-8 bit conversion When two bytes are being converted, DMPX(077) will write the values to the bytes in R from right to left and will wrap around to the rightmost byte if the leftmost byte (byte 1) has been specified as the starting byte.
  • Page 428 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 429 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 ⇓ DMPX(077) D0 D100 #0000...
  • Page 430 D in the order rightmost byte, leftmost byte. Note The destination words must be in the same data area. DI: Digit Designator The digit designator specifies various parameters for the conversion, as shown in the following dia- gram. Digit number: 3 2 1 0 Specifies the first digit in S to be converted (0 to 3).
  • Page 431 • The parity bit is appended to the data to enable detection of errors when the data is transmitted. By adding this bit, the number of bits that are 1 in the data can be indicated as odd or even, and if the number of 1s in the received data is not similarly odd or even, it is assumed that an error has occurred.
  • Page 432 (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 433 (2) is designated, the leftmost bit of each ASCII character will be adjusted so that there is an odd number of ON bits. The status of the parity bit does not affect the meaning of the ASCII code. • Examples of even parity: When adjusted for even parity, ASCII “31”...
  • Page 434 (returns to to the rightmost byte after the leftmost byte. digit 0 after digit 3) DI: Digit Designator The digit designator specifies various parameters for the conversion, as shown in the following dia- gram. Digit number: 3 2 1 0 Specifies the first digit in D to receive converted data (0 to 3).
  • Page 435 • The parity bit is appended to the data to enable detection of errors when the data is transmitted. By adding this bit, the number of bits that are 1 in the data can be indicated as odd or even, and if the number of 1s in the received data is not similarly odd or even, it is assumed that an error has occurred.
  • Page 436 HEX(162) will be executed only when the parity bit in each byte is 0. An error will occur if a parity bit is non-zero. Even parity (1) HEX(162) will be executed only when there is an even number of ON bits in each byte. An error will occur if a byte has an odd number of ON bits.
  • Page 437 D300 beginning with digit 1. The digit designator setting of #1011 specifies even parity, the starting byte (when reading) = rightmost byte, the number of bytes to read = 2, and the starting digit (when writing) = digit 1.) 0.00...
  • Page 438 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...
  • Page 439 Name Label Operation Error Flag • ON if N is not within the specified range of 0000 to 000F. • OFF in all other cases. Equals Flag • ON if D is 0000 after execution. • OFF in all other cases.
  • Page 440 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 441 N-specified bit of D+15: Bit 15 of S is output N: Bit Number Specifies the bit number (0000 to 000F or &0 to &15) to be overwritten by the source word. Note D and D+15 must be in the same data area.
  • Page 442 0 1 1 1 0 0 0 1 1 0 0 0 1 0 1 0 Sample program When CIO 0.00 is ON in the following example, COLM(064) copies the 16 bits in D200 (bits 00 through 15) to bit 5 in D100 through D115.
  • Page 443 BINS: Destination word DINT BISL: First destination word C: Control Word Specifies the signed BCD format. C must be 0000 to 0003. S: Source word BINS • C = 0 (Input Data Range: -999 to 999 BCD) 3 digits BCD, 12 bits Sign bit (0: Positive;...
  • Page 444 A: Negative (–1) F: Negative (–) B to E: Error BISL • C = 0 (Input Data Range: -999 9999 to 999 9999 BCD) 7 digits BCD, 28 bits Sign bit (0: Positive; 1: Negative) Status of 3 bits: 0 •...
  • Page 445 Operation Error Flag • ON if C is not within the specified range of 0000 to 0003. • ON if C=0002 and the leftmost digit of S/S+1 is A to E. • ON if C=0003 and the leftmost digit of S/S+1 is B to E.
  • Page 446 0 to 9999 9999 0000 0000 to 05F5 E0FF Hint Some Special I/O Units output signed BCD data. Calculations using this data will normally be easier if it is first converted to signed binary data with BINS(470)/B/SL(472). CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 447 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 448 DINT BDSL: First source word BCDS: Destination word WORD DWORD BDSL: First destination word C: Control Word Specifies the signed BCD format. C must be 0000 to 0003. S: Source Word BCDS BDSL Setting Allowed values for S Setting Allowed values for S+1 and S...
  • Page 449 0 to 9: Fourth digit BCD A: Negative (–1) F: Negative (–) BDSL • C = 0 (Output Data Range: -999 9999 to 999 9999 BCD) 7 digits BCD, 28 bits Sign bit (0: Positive; 1: Negative) Status of 3 bits: 0 •...
  • Page 450 (C). Signed binary Signed BCD The following table shows the possible signed binary values for each signed BCD format. An error will occur if the source data is not within the allowed range for the specified signed BCD format. Setting...
  • Page 451 BCDS When 0.00 is ON, it is first checked if the data range of D100 is based on the data format specification 0001. Here the check result is okay, so the signed binary data in data memory D100 is converted to signed BCD and output to D200.
  • Page 452 User-specified Resolution 0 hex = 256, 1 hex = 360, 2 hex = 720, 3 hex = 1,024, 4 to F hex = Do not use. Note: The above setting is valid when the resolution is set to 0 hex in bits 00 to 03 of C.
  • Page 453 • ON if bits 04 to 07 of C are not 0 hex (= Binary Mode), 1 hex (= BCD Mode), or 2 hex (= 360 Mode). • ON if the specified encoder remainder compensation exceeds the set user-specified resolution when bits 00 to 03 of C are 0 hex (= user-specified resolution).
  • Page 454 Note If the word specified for S is allocated to an Input Unit, the input data converted by GRY(474) will be for the gray binary code from the previous CPU Unit cycle, i.e., it will be one cycle time old.
  • Page 455 3. Instructions Example 2: Converting to Angle Data with a 10-bit Resolution and Zero Point Offset of 0151 Hex C: D0 Resolution: 10-bit Conversion mode: 360 Mode Operating mode: Gray binary code conversion C+1: D1 0151 Zero point offset: 0151 hex C+2: D2 User-specified resolution: Not used.
  • Page 456 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 457 IR Flags Name Label Operation Error Flag • ON if the results of conversion is negative (i.e., if the gray code data is #8000 to #FFFF). • OFF in all other cases. Equal Flag Unchanged. Negative Flag Unchanged. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 458 D and D+1. Gray code Binary code Sample program GRAY_BIN When CIO 0.00 turns ON in the following example, the gray code in D0 is converted to binary data and stored in D10. 0.00 GRAY_BIN Result of executing...
  • Page 459 IR Flags Name Label Operation Error Flag • ON if the binary code is negative (i.e., if the gray code data is #8000 to #FFFF). • OFF in all other cases. Equal Flag Unchanged. Negative Flag Unchanged. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 460 D and D+1. Sample program BIN_GRAY When CIO 0.01 turns ON in the following example, the binary data in D10 is converted to gray code and stored in D0. 0.01...
  • Page 461 Equal Flag • ON if the result is 0. • OFF in all other cases. Negative Flag • ON when the leftmost bit of the source data is 1. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 462 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. Hexadecimal: #12345678 ASCII STR16 STR16(603) converts the numerical data in S...
  • Page 463 When CIO 0.01 is ON in the following example, the source data in D0 (&1234 in decimal) is converted to BCD data and the result is stored temporarily in D10. Next, the BCD data is converted to ASCII data and the result is output to D100 and D101.
  • Page 464 Name Label Operation Error Flag • ON if the source words contain any ASCII characters that are not hexadecimal equivalents (0 to 9, a to f, or A to F). • OFF in all other cases. Equal Flag • ON if the result is 0.
  • Page 465 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. In this case, the instruction will not be executed.
  • Page 466 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 467: Logic Instructions

    Error Flag Equals Flag • ON when the result is 0. • OFF in all other cases. Negative Flag • ON when the leftmost bit of R is 1. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 468 When the execution condition CIO 0.00 is ON, the logical AND is taken of corresponding bits in CIO 11, CIO 10 and CIO 21, CIO 20 and the results will be output to corresponding bits in D201 and D200. 0.00...
  • Page 469 Error Flag Equals Flag • ON when the result is 0. • OFF in all other cases. Negative Flag • ON when the leftmost bit of R is 1. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 470 When the execution condition CIO 0.00 is ON, the logical OR is taken of corresponding bits in CIO 21, CIO 20 and CIO 301, CIO 300 and the results will be output to corresponding bits in D501 and D500. 0.00...
  • Page 471 Error Flag Equals Flag • ON when the result is 0. • OFF in all other cases. Negative Flag • ON when the leftmost bit of R is 1. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 472 Sample program When the execution condition CIO 0.00 is ON, the logical exclusive OR is taken of corresponding bits in CIO 901, CIO 900 and D1001, D1000 and the results will be output to corresponding bits in D1201 and D1200.
  • Page 473 Error Flag Equals Flag • ON when the result is 0. • OFF in all other cases. Negative Flag • ON when the leftmost bit of R is 1. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 474 When the execution condition CIO 0.00 is ON, the logical exclusive NOR is taken of corresponding bits in CIO 801, CIO 800, and CIO 101, CIO 100 and the results will be output to corresponding bits in D501 and D500.
  • Page 475 COM(029) reverses the status of every specified bit in Wd. Wd Wd: 1 0 and 0 Note When using the COM instruction, be aware that the status of each bit will change each cycle in which the execution condition is ON. COML COML(614) reverses the status of every specified bit in Wd and Wd+1.
  • Page 476 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. 0.00 D100 D100...
  • Page 477: Special Math Instructions

    • ON if the result is 0000. • OFF in all other cases. Overflow Flag • ON if the content of S+1 and S is 4000 0000 to 7FFF FFFF. • OFF in all other cases. Underflow Flag Negative Flag...
  • Page 478 BCD, use the ROOT(072) instruction. Sample program When CIO 0.00 is ON in the following example, ROTB(620) calculates the square root of the data in CIO 2 and CIO 1, and writes the integer portion of the result in D100. CIO 2 CIO 1 0.00...
  • Page 479 Flags Name Label Operation Error Flag • ON if the data in S+1 and S is not BCD. • OFF in all other cases. Equals Flag • ON if the result is 0000. • OFF in all other cases. Function...
  • Page 480 3. Instructions Sample program 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...
  • Page 481 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 482 0000 to 0900 (BCD) 0.0000 to 0.9999 9999 (BCD) 1.0000 mal place is eliminated. Note The actual result for SIN(90 ) and COS(0 ) is 1, but 9999 (0.9999) will be output to R. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 483 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 data whether data is BCD or binary.
  • Page 484 C+ (4m+3) Ym (leftmost 16 bits) Ym (leftmost 16 bits) C+ (4m+4) C+ (4m+4) Note: The X coordinates must be in ascending order: X < X < ... < X . Input all values of (X ) as binary data, regardless of the data format specified in control word C.
  • Page 485 • 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 486 Floating-point specification 0: Integer data Note If the “Data length specification for S and D” in bit 10 of C is set to 1 and a 16-bit constant is input for S, the input data will be converted to 32-bit signed binary before the linear extrapolation calculation.
  • Page 487 Data length specification for S and D Floating-point specification 1: Floating-point data Note If the “Floating-point specification” in bit 09 of C is set to 1, a constant cannot be input for S. Sample program Sine Function (C: #0000) The following example shows APR(069) used to calculate the sine of 30 .
  • Page 488 Output and input D5 001A Hex both binary D6 0402 Hex D25 05F0 Hex D26 1F20 Hex In this case, the source word, CIO 0010, contains 0014, and f(0014) = 0726 is output to R, CIO 0011. $1F20 $0F00 (x,y) $0726 $0402...
  • Page 489 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.
  • Page 490 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)
  • Page 491 Equals Flag • ON if the result is 0. • OFF in all other cases. Function FDIV(079) divides the floating-point value in Dd and Dd+1 by that in Dr and Dr+1 and places the result in R and R+1. Quotient Dr+1...
  • Page 492 The leftmost digit can range from 0 to F; positive exponents range from 0 to 7 and negative exponents range from 8 to F (0 to -7). The rightmost 7 digits must be BCD.
  • Page 493: Application Example

    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 104 0.0079 104=0.436962 102 0.00 To perform the floating point division, the BCD value...
  • Page 494 Number of words UINT First source word UINT Variable Result word UINT N: Number of words The number of words must be 0001 to FFFF (1 to 65,535 words). Operand Specifications Indirect DM/EM Word addresses Registers Flags addresses Con- Pulse...
  • Page 495 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 496: Floating-Point Math Instructions

    • – :e = 255, f = 0, s= 1 • 0: e = 0 * NaN (not a number) is not a valid floating-point number. Executing floating-point calculation instructions will not result in NaN. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 497 Example 31 30 23 22 1 1 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sign: –...
  • Page 498 Example 31 30 23 22 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Sign: –...
  • Page 499 In this program example, the X-axis and Y-axis coordinates (x, y) are provided by 4-digit BCD content of D0 and D1. The distance (r) from the origin and the angle ( , in degrees) are found and output to D100 and D101.
  • Page 500 D210 D212 (1) This section of the program converts the data from BCD to floating-point. D204 • The data area from D200 onwards is used as a D202 D214 work area. • First BIN(023) is used to temporarily convert the...
  • Page 501 Error Flag • FIX ON if the integer portion of S+1 and S is not within the range of -32,768 to 32,767. • FIXL ON if the integer portion of S+1 and S is not within the range of -2,147,483,648 to 2,147,483,647.
  • Page 502 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. Example conversions: A floating-point value of 3.5 is converted to 3.
  • Page 503 Label Operation Error Flag Equals Flag • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Negative Flag • ON if the result is negative. • OFF in all other cases.
  • Page 504 FLTL FLTL(453) converts the 32-bit signed binary value in S+1 and 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.
  • Page 505 Subtracts one 32-bit floating-point number from FLOATING-POINT SUBTRACT –F @–F another and places the result in the specified result words. Multiplies two 32-bit floating-point numbers and FLOATING-POINT MULTIPLY places the result in the specified result words.
  • Page 506 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a 32-bit floating-point value. • OFF in all other cases. Underflow Flag •...
  • Page 507 Overflow Flag will turn ON and the result will be output as • If the absolute value of the result is less than the minimum value that can be expressed as floating- point data, the Underflow Flag will turn ON and the result will be output as 0.
  • Page 508 – (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. The Error Flag will be turned ON and the instruction will not be executed.
  • Page 509 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a 32-bit floating-point value. • OFF in all other cases. Underflow Flag •...
  • Page 510 /180 = radians Note • 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 • If the absolute value of the result is less than the minimum value that can be expressed as floating-point data, the Underflow Flag will turn ON and the result will be output as 0.
  • Page 511 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a 32-bit floating-point value. • OFF in all other cases. Underflow Flag •...
  • Page 512 180/ = degrees Note • 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 • If the absolute value of the result is less than the minimum value that can be expressed as floating-point data, the Underflow Flag will turn ON and the result will be output as 0.
  • Page 513 • ON if the absolute value of the source data exceeds 65,535. • OFF in all other cases. Equals Flag • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag...
  • Page 514 3. Instructions Function 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.)
  • Page 515 For information on converting from degrees to radians, see 3-15-22 LOGARITHM: LOG(468) DEGREES TO RADIANS: RAD(458). • 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 The following diagram shows the relationship between the angle and result.
  • Page 516 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 number (in radians) and places the result in the specified result words.
  • Page 517 For information on converting between degrees and radians, see 3-15-9 DEGREES TO RADIANS: RAD(458) and 3-15-10 RADIANS TO DEGREES: DEG(459). • If the angle is outside of the range -65,535 to 65,535, an unpredictable value will be output, but the Error Flag will not be turned ON.
  • Page 518 For information on converting between degrees and radians, see 3-15-9 DEGREES TO RADIANS: RAD(458) and 3-15-10 RADIANS TO DEGREES: DEG(459). • If the angle is outside of the range -65,535 to 65,535, an unpredictable value will be output, but the Error Flag will not be turned ON.
  • Page 519 • The Condition Flags are not refreshed. • An unpredictable value will be output if the angle data is out-of-range. • The data cannot be input or output at a Programming Console. A question mark will be displayed. TANQ TANQ(477) differs from TAN(462) in the following respects: •...
  • Page 520 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...
  • Page 521 Source (32-bit floating-point data) Result (32-bit floating-point data) The result is output to words R+1 and R as an angle (in radians) within the range of – /2 to /2. The following diagram shows the relationship between the input data and result.
  • Page 522 Source (32-bit floating-point data) Result (32-bit floating-point data) The result is output to words R+1 and R as an angle (in radians) within the range of – /2 to /2. The following diagram shows the relationship between the input data and result.
  • Page 523 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a 32-bit floating-point value. • OFF in all other cases. Underflow Flag...
  • Page 524 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 525 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a 32-bit floating-point value. • OFF in all other cases. Underflow Flag •...
  • Page 526 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.
  • Page 527 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a 32-bit floating-point value. • OFF in all other cases. Underflow Flag Negative Flag •...
  • Page 528 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.
  • Page 529 • ON if the base (B+1 and B) or exponent (E+1 and E) is not a number (NaN). • ON if the base (B+1 and B) is 0 and the exponent (E+1 and E) is less than 0. (Division by 0) •...
  • Page 530 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 531 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 when the comparison condition is true. Single-precision Floating-point Comparison LD connection AND connection...
  • Page 532 ON execution condition when comparison result is true. directly to the left bus bar. Options With the three input types and six symbols, there are 18 different possible combinations. Symbol (LD, AND, and OR cannot be Option (data format) used in a ladder program) LD=, AND=, OR=, LD<>, AND<>,...
  • Page 533 D201, D200. If the content of D101, D100 is less than that of D201, D200, execution proceeds to the next line and CIO 50.00 is turned ON. If the content of D101, D100 is not less than that of D201, D200, execution does not proceed to the next instruction line.
  • Page 534 • ON if the Data Format setting in C is not 0000 or 0001. • ON if the Total Characters setting in C+1 is not within the allowed range. (See 1. Limits on the Total Number of ASCII Characters above for details.) •...
  • Page 535 C to C+2, converts the number to ASCII text, and outputs the result to the destination words starting at D. • The content of C (Data format) specifies whether to express the number in S+1, S in decimal notation or scientific notation.
  • Page 536 A decimal point (ASCII: 2E hex) is added if the number fractional digits is greater than 0. Spaces (ASCII: 20 hex) are added if the integer part of the floating-point data is shorter than the integer part of the result (total number of characters - sign digit - decimal point - fractional digits - E digit).
  • Page 537 D0 to decimal-notation ASCII text and writes the ASCII text to the destination words beginning with D100. The contents of the control words (D10 to D12) specify the details on the data format (decimal notation, 7 characters total, 3 fractional digits).
  • Page 538 D0 to scientific-notation ASCII text and writes the ASCII text to the destination words beginning with D100. The contents of the control words (D10 to D12) specify the details on the data format (scientific notation, 11 characters total, 3 fractional digits).
  • Page 539 Error Flag • ON if the digits (integer and fractional parts) in the source data starting at S are not 30 to 39 hex (0 to • ON if the first two digits of the exponential part do not contain 45 and 2B hex (E+) or 45 and 2D hex (E-).
  • Page 540 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 541 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...
  • Page 542 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 543 S+1 and S to destination words D+1 and D. Source words Destination words Sample program W0.00 When input condition W0.00 is ON, the content of D0 and D1 (+3.0) MOVF is stored in floating-point format (IEEE754 format). +3.0 #4040 #0000 Equivalent to +3.0 in floating-point format...
  • Page 544: Double-Precision Floating-Point Instructions

    0: positive; 1: negative e: exponent The exponent (e) value ranges from 0 to 2,047. The actual exponent is the value remaining after 1,023 is subtracted from e, resulting in a range of -1,023 to 1,024. “e=0” and “e=2,047” express special numbers.
  • Page 545 Example 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
  • Page 546 Example 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0...
  • Page 547 (x,y). r = re j 360 In this example, the 4-digit BCD angle ( , in degrees) is read from D0 and the 4-digit BCD distance (r) is read from D1000. A (x, y) = A (rcos , rsin )
  • Page 548 D200 and D201. • RAD(458) converts the angle data in D200 and D1000 D1200 D201 to radians. • The floating-point data for the radius r is output to D200 D1200 and D1201. D200 2. This program section calculates the sin and the cos as single-precision floating-point values.
  • Page 549 Real number 4022 CB39 E973 5C32 3.4202014332567 400B 5C92 91AC 8EEB 9.3969262078591 Comparison of the Calculation Results When the real-number results are compared, it is clear that the double-precision calculation yields a more accurate result. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 550 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 value to 32-bit signed binary data and places the result in the specified result words.
  • Page 551 A floating-point value of -3.5 is converted to -3. FIXD FIXLD(842) converts the integer portion of the double-precision (64-bit) floating-point number in words S to S+3 (IEEE754-format) to 32-bit signed binary data and places the result in D+1 and D. S+3CH S+2CH...
  • Page 552 Label Operation Error Flag Equals Flag • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Negative Flag • ON if the result is negative. • OFF in all other cases.
  • Page 553 Function 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)
  • Page 554 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. Multiplies two double-precision (64-bit) floating- DOUBLE FLOATING-POINT...
  • Page 555 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a double-precision floating-point value. Underflow Flag •...
  • Page 556 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 – – – – – * *: The results could be zero (including underflows), a numeral, +o, or -o.
  • Page 557 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a double-precision floating-point value. • OFF in all other cases.
  • Page 558 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...
  • Page 559 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a double-precision floating-point value. • OFF in all other cases.
  • Page 560 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...
  • Page 561 • OFF in all other cases. Overflow Flag • SIND, COSD Unchanged • TAND •ON if the absolute value of the result is too large to be expressed as a double-precision (64-bit) float- ing-point value. •OFF in all other cases. Underflow Flag Unchanged Negative Flag •...
  • Page 562 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 563 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 564 • ATAND •ON if the source data is not a number (NaN). •OFF in all other cases. Equals Flag • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag Unchanged...
  • Page 565 (The floating point source data must be in IEEE754 format.) –1 The result is output to words D to D+3 as an angle (in radians) within the range of - /2 to /2. The following diagram shows the relationship between the input data and result.
  • Page 566 (The floating point source data must be in IEEE754 format.) –1 The result is output to words D to D+3 as an angle (in radians) within the range of - /2 to /2. The following diagram shows the relationship between the input data and result.
  • Page 567 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a double-precision (64-bit) float- ing-point value. • OFF in all other cases.
  • Page 568 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.
  • Page 569 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a double-precision (64-bit) float- ing-point value. • OFF in all other cases.
  • Page 570 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 571 • ON if both the exponent and mantissa of the result are 0. • OFF in all other cases. Overflow Flag • ON if the absolute value of the result is too large to be expressed as a double-precision (64-bit) floating-point value. • OFF in all other cases.
  • Page 572 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.
  • Page 573 • ON if the base data (B to B+3) or exponent data (E to E+3) is not a number (NaN). • ON if the base data (B to B+3) is 0 and the exponent data (E to E+3) is less than 0. (Division by 0) •...
  • Page 574 S2+3 S2+2 S2+1 S1+3 S1+2 S1+1 Base data For example, when the base words (B to B+3) contain 3.1 and the exponent words (E to E+3) contain 3, the result is 3.13 or 29.791. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 575 • OFF in all other cases. Greater Than or Equal Flag > = • ON if the absolute value of the result is too large to be expressed as a double-precision (64-bit) floating-point value. • OFF in all other cases.
  • Page 576 ON execution condition when comparison result is true. Options With the three input types and six symbols, there are 18 different possible combinations. Symbol (LD, AND, and OR cannot be Option (data format) used in a ladder program) LD=, AND=, OR=, LD<>, AND<>,...
  • Page 577 When CIO 0.00 is ON in the following example, the floating point data in words D100 to D103 is compared to the floating point data in words D200 to D203. If the content of D100 to D103 is less than that of D200 to D203, execution proceeds to the next line and CIO 50.00 is turned ON.
  • Page 578: 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 579 Reads the last (most recent) word of data that was stored in the stack. Decrements the pointer by one and reads the data at this address (the most recent data stored in the stack). The read data will not be cleared.
  • Page 580 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...
  • Page 581 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 582 Record-table Instructions A series of data consisting of more than one record with the same number of words in each record is called table data. Table data stored in the specified I/O memory are can be registered as the table area using the DIM instruction.
  • Page 583 Note TB and TB+(N-1) must be in the same data area. N: Number of words This number specifies the stack area that contains the stack control words and the data storage region. N must be between 5 and 65535. Operand Specifications...
  • Page 584 • 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 585 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. The stack itself begins in D4.
  • Page 586 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...
  • Page 587 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 588 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...
  • Page 589 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 590 Stack pointer Stack pointer Last word Read by LIFO(634). in stack D: D300 After the data is written to D300, the stack pointer is decremented by one. The content of D6 is left unchanged. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 591 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...
  • Page 592 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...
  • Page 593 When CIO 0.00 is ON in the following example, SNUM(638) counts the number of words from the beginning of the data region at D4 to the stack pointer position - 1 (D6) and outputs the result to D300. (In this case, the stack pointer indicates D7.) 0.00...
  • Page 594 Function Instruction Mnemonic Variations Function code Reads the data from the specified data element in the stack. The offset value indicates the location of STACK DATA READ SREAD @SREAD the desired data element (how many data ele- ments before the current pointer position).
  • Page 595 • ON if the specified read location is not within the stack area. • ON if the offset value specified in C is 0 or greater than the maximum data region size (FFFB hex). • 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).
  • Page 596 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 597 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 598 • ON if the specified write location is not within the stack area. • ON if the offset value specified in C is 0 or greater than the maximum data region size (FFFB hex). • 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).
  • Page 599 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 600 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 STACK DATA INSERT SINS @SINS downward. The offset value indicates the location of the desired data element (how many data ele- ments before the current pointer position).
  • Page 601 Hint SINS(641) can be used to insert the data for an item that is inserted in the midst of items already on a conveyor. The position of the insertion point is simply the number of items back (the offset value) from the most recent item added to the conveyor.
  • Page 602 D0. In this case, the stack pointer indicates D7 and the offset value is 3, so the source data is inserted in D4. The existing data is shifted down one word and the data in D7 is overwritten.
  • Page 603 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. The offset value indicates the location of the desired data element (how many data elements before the current pointer position).
  • Page 604 Error Flag • 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). (This is a stack underflow error.) •...
  • Page 605 Sample program 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.
  • Page 606 N: Table number Indicates the table number. N must be between 0 and15. LR: Length of each record Indicates the number of words in each record. LR must be 0001 to FFFF hexadecimal (1 to 65,535 words). NR: Number of records Indicates the number of records in the table.
  • Page 607 • As an example, if temperatures, pressures, or other set values are stored as records and the records for various models are combined into a table, it is easy to read the set values for each models for any particular conditions.
  • Page 608 Indicates the record number of the desired record. R must be 0000 to FFFE hexadecimal (0 to 65,534). Record numbers begin with 0, so the valid record numbers are 0 to NR–1 for a table with NR records. D: Destination Index Register Indicates the desired Index Register.
  • Page 609 (R) Note • The record table must be defined in advance with DIM(631). • Valid record numbers range from 0 to NR-1, where NR is the number of records specified when the table was defined with DIM(631). Sample program When CIO 0.00 is ON in the following example, SETR(635) finds the PLC memory address of the first...
  • Page 610 Operation Error Flag • ON if the PLC memory address in the specified Index Register is not within the specified table (N). • ON if the specified table number (N) has not been defined with DIM(631). • OFF in all other cases.
  • Page 611 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...
  • Page 612 R1+(W–1) #0001 to #FFFF (hex) 0000 0000 0000 Note C and C+1, R1 and R1+W-1 must be in the same data area. Output selection 0: Does not output number of matches to DR0. 1: Outputs number of matches to DR0.
  • Page 613: Related Auxiliary Area Words And Bits

    Auxiliary Area words A595 and A596 instead of IR0. • If background execution is enabled in the PLC Setup and control word C+1 is set to output the total number of matches to DR0 (C+1 = 8000 hex), the total number of matches will be output to Auxiliary Area word A597 instead of DR0.
  • Page 614 D107 D108 D109 00010067 0003 Number of matches If the table length is specified as &10 (10 decimal) or A hexadecimal, the number of matches will not be output to the data register DR0. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 615 First word in range UINT Variable N: Number of words N specifies the number of words in the range and must be 0001 to FFFF hexadecimal (or &1 to &65,535). R1: First word in range Leftmost byte Rightmost byte R1+(N–1) Note R1 and R1+(N-1) must be in the same data area.
  • Page 616 Programming Manual (W394) or the CJ2 CPU Unit Software Operation Manual (W473) for details. Sample program When CIO 0.00 is ON in the following example, SWAP(637) switches the data in the leftmost bytes with the data in the rightmost bytes in each word in the 10-word range from W0 to W9.
  • Page 617 R1: First word in range Search range W: Number of words in range &1 to &65535 (decimal) or R1+(W–1) #0001 to #FFFF (hex) Note C and C+1, R1 and R1+(W-1) must be in the same data area. 00 0000 0000 0000 Output selection 0: Does not output address to IR0.
  • Page 618 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 619 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 620 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.
  • Page 621 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...
  • Page 622 Label Operation Error Flag • 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 • ON if the maximum value is 0.
  • Page 623 Instructions using results of MAXL in W0 Sample program When CIO 0.00 turns ON in the following example, a table of four double word values starting at D0 is searched for the maximum value. The maximum value is stored in W0 and W1.
  • Page 624 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...
  • Page 625 Label Operation Error Flag • 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.
  • Page 626 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...
  • Page 627 Label Operation Error Flag • 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.
  • Page 628 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...
  • Page 629 Label Operation Error Flag • 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 • ON if the minimum value is 0.
  • Page 630 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...
  • Page 631 Label Operation Error Flag • 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.
  • Page 632 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...
  • Page 633 Label Operation Error Flag • 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.
  • Page 634 Starting byte (Effective if bit 13 is 1.) four digits are stored in D. 0: Leftmost byte Note C and C+1, all of the words in the calculation range must 1: Rightmost byte be in the same data area. Units...
  • Page 635 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. • 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 636 3. Instructions Sample program 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...
  • Page 637 The leftmost four digits are stored in D+1 and the rightmost 0: Words four digits are stored in D. 1: Bytes Note C and C+1, all of the words in the calculation range must be in the same data area. Operand Specifications Indirect DM/EM...
  • Page 638 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 639 3. Instructions Sample program 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...
  • Page 640: Tracking Instructions

    Each group of information is called a record. Tracking Instructions can be used to easily search for the necessary records in tracking data or to store tracking data according to the information contained in them.
  • Page 641 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...
  • Page 642 W0.0 Matching record found. P CY W0.1 Matching record not found. Step 2: Records moved forward with the XFER instruction to fill in the space of the matching record. W0.0 Number of records &7 D100 Record number of matching record...
  • Page 643 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...
  • Page 644 0 4 0 6 PLC memory address of search end, upper word C+5: D5 0 0 0 1 Step 1: The records are sorted in ascending order according to the delivery code using the RSORT2 instruction. RSORT2 First control word: D300 D300...
  • Page 645 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...
  • Page 646 0 0 0 0 Always 0000 hex. C+6: D306 0 0 0 0 Step 1: The records are sorted in ascending order according to the delivery code using the RSORT2 instruction. #0000 Clear first word of system work area (C+7). D307 Flag to hold ON which executing the sort.
  • Page 647 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> @RSRCH> When a record matching the specified condition is RSRCH>= @RSRCH>= found, its record number and data are output.
  • Page 648 2 hex: Enabled for end PLC memory address OFF: Do not output ON: Output Search method 0 hex: Linear (Searches records in order from the specified first record.) 1 hex: Split search, ascending 2 hex: Split search, descending Setting to End Search Disabled C+4: Always 0.
  • Page 649 • ON when the number of records specified in C times the record length in C+1 is 0. • ON when the search data offset in C+2 is greater than one less than the record length in C+1. • OFF in all other cases.
  • Page 650 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)
  • Page 651 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 652 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 653 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> @RSRCH2>...
  • Page 654 2 hex: Enabled for end PLC memory address OFF: Do not output ON: Output Search method 0 hex: Linear (Searches records in order from the specified first record.) 1 hex: Split search, ascending 2 hex: Split search, descending Setting to End Search Disabled C+4: Always 0.
  • Page 655 • ON when the number of records specified in C times the record length in C+1 is 0. • ON when the search data offset in C+2 is greater than two less than the record length in C+1. • OFF in all other cases.
  • Page 656 Destination index register DWORD S1: First word of first record to search S2: First search data word The data would be set as follows to search for #0123456789ABCDEF. # C D E F S2+1 # 8 9 A B S2+1...
  • Page 657 (0000 0000 0000 0000 to FFFF FFFF FFFF FFFF hex) Store the end data in the following order starting from C+4: Lowest 16 bits, lower 16 bits, higher 16 bits, highest 16 bits. Search data offset (in words): End PLC Memory Address Enabled...
  • Page 658 • ON when the number of records specified in C times the record length in C+1 is 0. • ON when the search data offset in C+2 is greater than four less than the record length in C+1. • OFF in all other cases.
  • Page 659 Destination index register DWORD S: First word of first record to sort C: First control word 0 0 0 0 0 0 0 0 0 0 0 0 0 0 Always 0. Number of records: 0: Ascending 1 to 32768 decimal...
  • Page 660 (1 word). When the sort operation has been completed, the Carry Flag will turn OFF and the number of records that were sorted will be output to D1. If outputting to an index register is specified in C+4, one address higher than the PLC memory address of the last word in the sorted records is output to the specified index register.
  • Page 661 If the setting to end the sort is enabled in C+4 for end data, records will be sorted through the record just before the record in which the end data specified in C+5 is found. If the end data is not found, the number of records specified in C will be sorted.
  • Page 662 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 663 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...
  • Page 664 Searching with PLC Memory Address Enabled to End the Sort C+5: Lower word of end PLC memory address C+6: Upper word of end PLC memory address 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 C+7 to C+86 System word area Always clear C+7 to 0 before starting to sort records.
  • Page 665 (2 words). When the sort operation has been completed, the Carry Flag will turn OFF and the number of records that were sorted will be output to D1. If outputting to an index register is specified in C+4, one address higher than the PLC memory address of the last word in the sorted records is output to the specified index register.
  • Page 666 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...
  • Page 667 C+5 to C+8: Sort end data (0000 0000 0000 0000 to FFFF FFFF FFFF FFFF hex) Store the end data in the following order starting from C+5: Lowest 16 bits, lower 16 bits, higher 16 bits, highest 16 bits. End PLC Memory Address Enabled...
  • Page 668 (4 words). When the sort operation has been completed, the Carry Flag will turn OFF and the number of records that were sorted will be output to D1. If outputting to an index register is specified in C+4, one address higher than the PLC memory address of the last word in the sorted records is output to the specified index register.
  • Page 669: 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...
  • Page 670 Manipulated variable (D) • The number of valid input data bits within the 16 bits of the PV input (S) is designated by the input range setting in C+6, bits 08 to 11. For example, if 12 bits (4 hex) is designated for the input range, the range from 0000 hex to 0FFF hex will be enabled as the PV.
  • Page 671: Performance Specifications

    • The upper and lower limits of the manipulated variable output can be designated. • The sampling period can be designated in units of 10 ms (0.01 to 99.99 s), but the actual PID action is determined by a combination of the sampling period and the time of PID(190) instruction execution (with each cycle).
  • Page 672 (2). When target-value PID control with two degrees of freedom is used, on the other hand, there is no overshooting, and response toward the target value and stabilization of disturbances can both be speeded up (3).
  • Page 673 4.0 or later only) designation (Pre-Ver. 4.0 operation). Bit 14 = 0 or 1 and bit 13 = 1: Bumpless operation (i.e., start from an integral manipulated variable that will not abruptly change the manipulated variable output and result in a continuous change).
  • Page 674 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 675 MV is made proportional to the deviation (the difference between from SV and PV) and gradually decreased until the SV and PV match (i.e., until the deviation is 0), at which time the MV will be at the minimum value of 0% (or 50%, depending on the setting of the manipulated variable output designation parameter).
  • Page 676 The strength of the derivative action is indicated by the derivative time, which is the time required for the manipulated variable of the derivative action to reach the same level as the manipulated variable of the proportional action with respect to the step deviation, as shown in the following illustration.
  • Page 677 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 678 1770 hex, which cannot be specified merely by setting the valid number of digits. APR(069) is thus used to convert the 0000 to 1770 hex range of the Analog Input Unit to 0000 to FFFF hex for input to PID(190) and then the manipulated variable output from PID(190) is converted back to the range 0000 to 1770 hex, again using APR(069), for output from the Analog Output Unit.
  • Page 679 • 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. If any other value is changed, be sure to turn the input condition from OFF to ON to enable the new value.
  • Page 680 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...
  • Page 681 Autotuning The status of the AT Command Bit (bit 15 of C+9) is checked every cycle. If this control bit is turned ON in a given cycle, PIDAT(191) will begin autotuning the PID constants. (The changes in the SV will not be reflected while autotuning is being performed.)
  • Page 682 PID Control • The number of valid input data bits within the 16 bits of the PV input (S) is designated by the input range setting in C+6, bits 08 to 11. For example, if 12 bits (4 hex) is designated for the input range, the range from 0000 hex to 0FFF hex will be enabled as the PV.
  • Page 683 • When changing the PID constants manually, set the PID constant change enable setting (bit 1 of C+5) to 1 so that the values in C+1, C+2, and C+3 are refreshed each sampling period in the PID calculation. This setting also allows the PID constants to be adjusted manually after autotuning.
  • Page 684 Hysteresis is higher than necessary. 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 685 Sample program Interrupting PID Control to Perform Autotuning • At the rising edge of CIO 0.00 (OFF to ON), the work area in D211 to D240 is 0.00 initialized according to the parameters (shown below) set in D200 to D208. After...
  • Page 686 Time Interrupting Autotuning Before Completion Autotuning can be interrupted by turning bit 15 of D209 (C+9) from ON to OFF. PID control will be restarted with the P, I, and D constants that were in effect before autotuning was started.
  • Page 687 • 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. • OFF in all other cases. Equals Flag • ON if the result is 0.
  • Page 688 (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 689 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...
  • Page 690 (signed 16-bit binary) is within the upper and lower limits (dead band). If the input data (S) is greater than or equal to the lower limit (C) and less than or equal to the upper limit (C+1), 0000 (hex) will be output to D and the Equals Flag will turn ON.
  • Page 691 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 692 • 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. • OFF in all other cases. Equals Flag • ON if the result is 0.
  • Page 693 8000 (hex) [–32768] – FF00 (hex) [–256] = 7F00 (hex) [32512] Sample program When CIO 0.00 is ON, a bias of –100 will be applied to the value of D100 if that value is less than 0, and the resulting value will be stored in D300.
  • Page 694 C: First Parameter Word Bits 04 to 07 of C specify the input type, i.e., whether the input word contains an input duty ratio or manipulated variable. (Set these bits to 0 hex to specify a input duty ratio or to 1 hex to specify a manipulated variable.)
  • Page 695 ON and OFF status changes is known as the control period and is set in parameter word C+1. Example: When the control period is 1 s and the input value is 50%, the bit is ON for 0.5 s and OFF for 0.5 s.
  • Page 696: Parameter Settings

    • When instruction execution starts, the output bit (R) is turned ON/OFF according to the duty ratio. • The parameters (in C to C+3) are read in real time each time that the instruction is executed. When changing the parameters, change all of them at the same time so that different sets of parameters are not mixed.
  • Page 697 (bits 00 to 03 of C). • The input read timing setting (bits 08 to 11 of C) specifies when the input word (S) is read, as shown in the following table:...
  • Page 698 • The output limiter function (bits 12 to 15 of C) can be enabled to restrict (saturate) output when it is outside the range between the output limiter lower limit (C + 2) and output limiter upper limit (C + 3).
  • Page 699 CIO 2001. In this case, CIO 20 is allocated to a Transistor Output Unit and bit CIO 2001 is connected to a solid state relay for heater control.
  • Page 700 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 701 P1+2 Scaled value for point B (Br) 0000 to 9999 (4-digit BCD) P1+3 Unscaled value for point B (Bs) Note P1 to P1+3 must be in the same area. 0000 to FFFF (binary) Operand Specifications Indirect DM/EM Word addresses Registers...
  • Page 702 Points A and B can define a line with either a positive or negative slope. Using a negative slope enables reverse scaling. • The result will be rounded to the nearest integer. If the result is less than 0000, 0000 will be output as the result.
  • Page 703 Sample program 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 704 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 < Bs and Ar > Br. The following relationship will result. R (unsigned BCD) Point A...
  • Page 705 P1: First Parameter Word Offset of linear function 8000 to 7FFF (signed binary) P1+1 8000 to 7FFF (signed binary) P1+2 Note P1 to P1+2 must be in the same area. 0000 to 9999 (BCD) Operand Specifications Indirect DM/EM Word addresses Registers...
  • Page 706 • The result in R will be the absolute BCD conversion value and the sign will be indicated by the Carry Flag. The result can thus be between –9999 and 9999. • If the result is less than –9999, –9999 will be output as the result. If the result is greater than 9999, 9999 will be output.
  • Page 707 Scaling 1 to 5-V Analog Input to 0 to 300 In the following example, it is assumed that an analog signal from 1 to 5 V is converted and input to CIO 205 as 0000 to 0FA0 hexadecimal. SCL2(486) is used to convert (scale) the value in CIO 205 to a value between 0000 and 0300 BCD.
  • Page 708 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 709 0001 to 9999 (BCD) P1+2 8000 to 7FFF (signed binary) P1+3 Maximum conversion 8000 to 7FFF (signed binary) P1+4 Minimum conversion 8000 to 7FFF (signed binary) Note P1 to P1+4 must be in the same area. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 710 Carry Flag shows the sign) contained in the source word S into signed binary data and place the result in the result word R according to the linear function defined by the slope ( X, Y) and an offset. The maximum and minimum conversion values are also specified.
  • Page 711 Sample program When a value from 0 to 200 is scaled to an analog signal (1 to 5 V, for example), a signed BCD value of 0000 to 0200 is converted (scaled) to signed binary value of 0000 to 0FA0 for an Analog Output Unit.
  • Page 712 Result first word UINT Variable N: Number of Cycles The number of cycles must be between 0001 and 0040 hexadecimal (0 to 64 cycles). R: Result First Word and R+1: First Work Area Wor Average R+1: Processing information Used by system.
  • Page 713 D200. The contents will be stored in order in the ten words from CIO 302 to CIO 311. The average of the contents of these ten words will be placed in CIO 300 and then bit 15 of CIO 301 will be turned ON.
  • Page 714 3. Instructions • In the following example, the content of CIO 40 is set to #0000 and then incremented by 1 each cycle. • For the first two cycles, AVG(195) moves the content of CIO 40 to D1002 and D1003. The contents of D1001 will also change (which can be used to confirm that the results of AVG(195) has changed).
  • Page 715: Subroutine Instructions

    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 716 Size Subroutine number N: Subroutine number Specifies the subroutine number between 0 and 1023 decimal. Note For CJ1M-CPU11 and CJ1M-CPU21 CPU Units, the subroutine number must be between the range &0 to &255 decimal. Operand Specifications Indirect DM/EM Word addresses...
  • Page 717 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. Subroutine program (SBN(092) to RET(093)) Program end Subroutines can be nested up to 16 Execution condition ON levels.
  • Page 718 In the following example, subroutine 1 is executed when CIO 0.00 is ON 0.00 and CIO 1.00 is turned ON by DIFU(013) when CIO 0.01 has...
  • Page 719 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. When CIO 0.01 is ON, subroutine 2 is executed and program execution returns to the next instruction after SBS(091) 2.
  • Page 720 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. Execution of subroutine 1 continues and program execution returns to the next instruction after SBS(091) 1 when subroutine 1 is completed.
  • Page 721 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.
  • Page 722 First input parameter word First output parameter word N: Subroutine number Specifies the subroutine number between 0 and 1023 decimal. Note For CJ1M-CPU11 and CJ1M-CPU21 CPU Units, the subroutine number must be between the range 0 to 255 decimal. Operand Specifications Indirect DM/EM...
  • Page 723 Precautions • The four words of input data (words or bits) in A600 to A603 and the four words of output data (words or bits) in A604 to A607 must be used in the subroutine called by MCRO(099). It is not possible to pass more than four words of data.
  • Page 724 A607 The second MCRO(099) instruction operates in the same way, but the input data in CIO 200 to CIO 203 is passed to A600 to A603 and (Equivalent) the output data in A604 to A607 is passed to CIO 400 to CIO 403.
  • Page 725 Size Subroutine number N: Subroutine number Specifies the subroutine number between 0 and 1023 decimal. Note For CJ1M-CPU11 and CJ1M-CPU21 CPU Units, the subroutine number must be between the range 0 to 255 decimal. Operand Specifications Indirect DM/EM Word addresses...
  • Page 726 When program execution reaches RET(093), it is automatically returned to the next instruction after the SBS(091) or MCRO(099) instruction that called the subroutine. When the subroutine has been called by MCRO(099), the output data in A604 through A607 is written to D through D+3 before program execution is returned.
  • Page 727 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 728 N: Subroutine number Specifies the subroutine number between 0 and 1023 decimal. Note For CJ1M-CPU11 and CJ1M-CPU21 CPU Units, the subroutine number must be between the range 0 to 255 decimal. Note Global subroutine numbers and regular subroutine numbers (SBS instructions and MCRO instruction operands) are shared (do not use the same number for a global subroutine and a regular subroutine).
  • Page 729 The global subroutine region (between GSBN(751) and GRET(752)) must be defined in interrupt task 0. If it is defined in another task, an error will occur and the Error Flag will be turned ON when the GSBS(750) instruction is executed.
  • Page 730 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.
  • Page 731 CIO 0.00 is ON and CIO 1.00 is turned ON by DIFU(013) when CIO 0.01 has gone from OFF to ON. If CIO 0.01 is ON in the same cycle, global subroutine 1 will be executed again but this time DIFU(013) will not detect the rising edge of CIO 0.01 and CIO 1.00 will be turned OFF.
  • Page 732 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. If CIO 0.00 is OFF in the following cycle, subroutine 1 will not be executed again and output CIO 1.00 will remain ON.
  • Page 733 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 734 GSBN Global subroutine number N: Subroutine number Specifies the subroutine number between 0 and 1023 decimal. Note For CJ1M-CPU11 and CJ1M-CPU21 CPU Units, the subroutine number must be between the range 0 to 255 decimal. Operand Specifications Indirect DM/EM Word addresses...
  • Page 735 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). GRET GRET(752) indicates the end of a global subroutine.
  • Page 736 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. If part of the main program is placed after the global subroutine region, that program section will be ignored.
  • Page 737: Interrupt Control Instructions

    • The same Special I/O Unit's data area is read by IORD(222) or written by IOWR(223). • Be sure that the interrupt task does not require more than 10 ms if a C200H Special I/O Unit or SYSMAC BUS Remote I/O Slave Rack is connected. If an interrupt task longer than 10 ms is executed during I/O refreshing with the Special I/O Unit or Slave Rack, a non-fatal will occur and the Interrupt Task Error Flag (A40213) will be turned ON.
  • Page 738 OFF interrupt task) is as follows: I/O interrupt > external interrupt > scheduled interrupt Note “A > B” indicates that A is given priority over B. On the same interrupt level, lower numbered tasks are given priority over higher numbered tasks.
  • Page 739: Scheduled Interrupts

    Power OFF Interrupt Name Description Settings Power OFF Interrupt If the Power OFF Interrupt Task setting is turned ON, then a power OFF interrupt task will start if OFF (default) Task power turns OFF. Power OFF Detection Power OFF is recognized when this time plus the default power OFF detection time (10 to 25 ms for...
  • Page 740 Inputs to a CS1W-INT01/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: Enable (unmask) the interrupt. 1: Disable (mask) the interrupt.
  • Page 741 5: Interrupt task 1 (interrupt task 3) Note 1 Only scheduled interrupt 0 can be used with the CJ1M-CPU11/21. 2 The scheduled interrupts (0 and 1) cannot be used with a CJ2 CPU Unit if the synchronous unit operation function is enabled.
  • Page 742 0 and 3. • Errors when specifying Scheduled Interrupts: • When the time units are set to 10 ms or 1 ms, the Error Flag will go ON if C is not between 0 and 9,999 decimal (0000 to 270F hex).
  • Page 743 (CJ1M CPU Units only). Note 1 The CJ1M-CPU11/21 supports only one scheduled interrupt task, interrupt task 2 for scheduled interrupt 2 The time unit used to set the scheduled interrupt time is set as the Schedule Interrupt Interval in the PLC Setup.
  • Page 744 0, and starts the internal timer. (In this case, the scheduled time interval units are set to 1 ms.) 2. When W0.01 goes from OFF to ON, the internal timer is stopped for scheduled interrupt 0, which stops the generation of timer interrupts.
  • Page 745 Inputs to a CS1W-INT01/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: 0: Interrupt enabled (unmasked). 1: Interrupt disabled (masked).
  • Page 746 Inputs to a CS1W-INT01/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: 0: Up-differentiation (Detect rising edge.) 1: Down-differentiation (Detect falling edge.) Inputs to a CJ1M CPU Unit's Built-in Inputs 0000 hex: Up-differentiation (Detect rising edge.)
  • Page 747 (CJ1M CPU Units only). Note 1 The CJ1M-CPU11/21 supports only one scheduled interrupt task, interrupt task 2 for scheduled interrupt 2 The time unit used to set the scheduled interrupt time is set as the Schedule Interrupt Interval in the PLC Setup.
  • Page 748 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 task number 3...
  • Page 749 Inputs to a CS1W-INT01/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. 1: Clear the recorded interrupt.
  • Page 750 • ON if N is not within the specified range of 0 to 5 (0, 1, or 4 to 11 for CJ1M). • ON if C is not within the specified range of 0000 to 00FF hex when N is 0 to 3 (for I/O interrupts and C200HS-INT only).
  • Page 751 CLI(691) to clear the recorded interrupts before they are executed. (2) N = 4 or 5: Setting the Time to the First Scheduled Interrupt Task When N is 4 or 5, the content of C specifies the time interval to the first scheduled interrupt task. MSKS(690) Execution of scheduled interrupt task.
  • Page 752 3. Instructions Setting the Time to the First Scheduled Interrupt 1 When W0.00 goes from OFF to ON, CLI(691) sets the time to W0.00 @CLI the first execution of scheduled interrupt 0 to 24 ms. (In this case, the scheduled time interval units are set to 1 ms in the PLC Setup.)
  • Page 753 EI(694) or the END(001) instruction in the last task. If the power OFF interrupt task is enabled, the CPU Unit will be reset after execution of the power OFF interrupt task. For details, refer to information on the power OFF interrupt task in the CS/CJ Series Programming Manual or the CJ2 CPU Unit Software Operation Manual (W473).
  • Page 754 Note When a CS1D CPU Unit for Single-CPU System or a CJ2, CS1-H, CJ1-H, or CJ1M CPU Unit is being used, the power OFF interrupt task is disabled, and A530 is set to A5A5 hex, the CPU Unit will be reset after exe- cution of EI(694) in the event that a power interruption is detected during execution of the instructions between DI(693) and EI(694).
  • Page 755 OFF interrupt processing. After DI(593) has been executed, the CPU Unit will not be reset even if a power interruption is detected. The CPU Unit will be reset after all of the instruction s between DI(693) and EI(694) have been executed. Refer to 3-21-4 DISABLE INTERRUPTS: DI(693) for details on using DI(693) to disable power OFF interrupt processing.
  • Page 756 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 757: High-Speed Counter And Pulse Output Instructions

    @INI • To change the PV of the high-speed counter. • To change the PV of interrupt inputs in counter mode. • To change the PV of the pulse output (origin fixed at 0). • To stop pulse output. INI(880)
  • Page 758 • ON if a new PV is specified for a port that is currently outputting pulses. • ON if changing the PV of a high-speed counter is specified for a port that is not specified for a high-speed counter. • ON if a value that is out of range is specified as the PV for an interrupt input in counter mode.
  • Page 759 Sample program When CIO 0.00 turns ON in the following example, SPED(885) starts outputting pulses from pulse output 0 in Continuous Mode at 500 Hz. When CIO 0.01 turns ON, pulse output is stopped by INI(880). 0.00 01F4...
  • Page 760 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) P: Port specifier Symbol C: Control data D: First destination word...
  • Page 761 00 3 hex C = 0013 hex: 10-ms sampling method for high frequency (supported only by CJ1M CPU Units Ver. 3.0 or later) C = 0023 hex: 100-ms sampling method for high frequency (supported only by CJ1M CPU Units Ver. 3.0 or later) C = 0033 hex: 1-s sampling method for high frequency (supported only by CJ1M CPU Units Ver.
  • Page 762 Not allowed. Not allowed. Not allowed. Not allowed. PWM (891) output Note CJ1M CPU Units with unit version 3.0 or later only. Reading a PV (C = 0000 hex) Port and mode Operation Setting range Pulse output (P = 0000 or 0001 hex)
  • Page 763 Counter input method: Any input method other than 4 differential phase mode: Result = 00000000 to 000186A0 hex (0 to 100,000) Note If a frequency higher than 100 kHz has been input, the output will remain at the maximum value of 000186A0 hex.
  • Page 764 Precautions If the counter is reset when P is 0010 hex (high-speed counter 0) and C is 0013, 0023, or 0033 hex (sampling method for high frequency), the data read during the sampling time when the counter was reset will not be dependable.
  • Page 765 PRV2(883) function Converts frequency to rotation speed. 0 *0 hex (The second digit of C ( ) specifies the units and the third digit (*) specifies the frequency calculation method.) 0001 hex Converts counter PV to total number of revolutions.
  • Page 766 00030D40 hex.) (2) Frequency Calculation Method When the CPU Unit is a CJ1M CPU Unit with version number 3.0 or later, 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 767 Counts the number of pulses every 1 s. The error is 0.1% max. at 1 kHz. Note At frequencies below 1 kHz, the Standard Calculation Method is used, regardless of the sampling time setting. Converting Counter PV to Total Number of Revolutions (C1 = 0001 hex) If C1 is 0001 hex, PRV2(883) calculates the cumulative number of revolutions from the counter PV and pulses/revolution setting.
  • Page 768 0001 hex Registers a range comparison table and performs one comparison. 0002 hex Registers a target value comparison table. Comparison is started with INI(880). 0003 hex Registers a range comparison table. Comparison is started with INI(880). CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 769 • For range comparison, the comparison table always contains eight ranges. The table is 40 words long, as shown below. If it is not necessary to set eight ranges, set the interrupt task number to FFFF hex for all unused ranges.
  • Page 770 • ON if the upper value is less than the lower value for any range. • ON if the set values for all ranges are disabled during a range comparison. • ON if the high-speed counter is set for incremental pulse mode and decrementing is set in the table as the direction for comparison.
  • Page 771 • The range comparison table contains 8 ranges, each of which is defined by a lower limit and an upper limit. If a range is not to be used, set the interrupt task number to FFFF hex to disable the range.
  • Page 772 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...
  • Page 773 • ON if SPED(885) or INI(880) is used to change the mode between continuous and independent output during pulse output. • ON if SPED(885) is executed in an interrupt task when an instruction controlling pulse output is being executed in a cyclic task.
  • Page 774 • The number of output pulses must be set in advance with PULS(881). Pulses will not be output for SPED(885) if PULS(881) is not executed first. • The direction set in the SPED(885) operand will be ignored if the number of pulses is set with PULS(881) as an absolute value.
  • Page 775 When CIO 0.00 turns ON in the following programming example, PULS(886) sets the number of output pulses for pulse output 0. An absolute value of 5,000 pulses is set. SPED(885) is executed next to start pulse output using the CW/CCW method in the clockwise direction in independent mode at a target frequency of 500 Hz.
  • Page 776 • The actual number of movement pulses that will be output are as follows: For relative pulse output, the number of movement pulses = the set number of pulses. For absolute pulse output, the number of movement pulses = the set number of pulses - the PV. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 777 • ON if the specified range for P, T, or N is exceeded. • ON if PULS(886) is executed for a port that is already outputting pulses. • ON if PULS(886) is executed in an interrupt task when an instruction controlling pulse output is being executed in a cyclic task.
  • Page 778 1 hex: CCW Pulse output method (See note.) 0 hex: CW/CCW 1 hex: Pulse + direction Always 0 hex. Note Use the same pulse output method when using both pulse outputs 0 and 1. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 779 • ON if PLS2(887) is executed for a port that is already outputting pulses for SPED(885) or ORG(889). • ON if PLS2(887) is executed in an interrupt task when an instruction controlling pulse output is being executed in a cyclic task.
  • Page 780 ACC(888) can be used to achieve interrupt feeding of a fixed distance. Acceleration will not be performed by PLS2(887) for this application, but if the acceleration rate is set to 0, the Error Flag will turn ON and PLS2(887) will not be executed. Always set the acceleration rate to a value other than 0.
  • Page 781 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...
  • Page 782 PLS2(887) Note Triangular Control If the specified number of pulses is less than the number required to reach the target frequency and return to zero, the function will automatically reduce the acceleration/deceleration time and perform triangular control (acceleration and deceleration only.) An error will not occur.
  • Page 783 0 with an absolute pulse specification of 100,000 pulses. Pulse output is accelerated at a rate of 500 Hz every 4 ms starting at 200 Hz until the target speed of 50 kHz is reached. From the deceleration point, the pulse output is decelerated at a rate of 250 Hz every 4 ms starting until the starting speed of at 200 Hz is reached, at which point pulse output is stopped.
  • Page 784 0 hex: CW/CCW 1 hex: Pulse + direction Always 0 hex. Note Use the same pulse output method when using both pulse outputs 0 and 1. S: First Word of Settings Table CJ1M CPU Units, no unit version 1 to 2000 Hz (#0001 to 07D0) Acceleration/deceleration rate CJ1M CPU Units, unit version 2.0...
  • Page 785 • ON if ACC(888) is executed to switch between independent and continuous mode for a port that is outputting pulses for SPED(885), ACC(888), or PLS2(887). • ON if ACC(888) is executed in an interrupt task when an instruction controlling pulse output is being executed in a cyclic task.
  • Page 786 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...
  • Page 787 3 The number of output pulses must be set in advance with PULS(881). Pulses will not be output for ACC(888) if PULS(881) is not executed first. 4 The direction set in the ACC(888) operand will be ignored if the number of pulses is set with PULS(881) as an absolute value.
  • Page 788 Note Triangular Control If the specified number of pulses is less than the number required to reach the target frequency and return to zero, the function will automatically reduce the acceleration/deceleration time and perform triangular control (acceleration and deceleration only.) An error will not occur.
  • Page 789 0 hex: CW/CCW 1 hex: Pulse + direction Mode 0 hex: Origin search 1 hex: Origin return Note Use the same pulse output method when using both pulse outputs 0 and 1. Operand Specifications Indirect DM/EM Word addresses Registers Flags...
  • Page 790 • ON if the origin search or origin return parameters set in the PLC Setup are not within range. • ON if the Origin Search High Speed is less than or equal to the Origin Search Proximity Speed or the Origin Search Proximity Speed is less than or equal to the Origin Search Initial Speed.
  • Page 791 When CIO 0.00 turns ON in the following programming example, ORG(889) starts an origin return operation for pulse output 0 by outputting pulses using the CW/CCW method. According to the PLC Setup, the initial speed is 100 pps, the target speed is 200 pps, and the acceleration and deceleration rates are 50 Hz/4 ms.
  • Page 792 Note On the CJ1M-CPU21, only PWM output 0 can be used. F: Frequency F specifies the frequency of the PWM output between 0.1 and 6,553.5 Hz (0.1 Hz units, 0001 to FFFF hex). The accuracy of the PMW(891) waveform that is actually output (ON duty +5%/ 0%) applies only to 0.1 to 1,000.0 Hz due to limitations in the output circuits.
  • Page 793 Sample program When CIO 0.00 turns ON in the following programming example, PWM(891) starts PWM 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%.
  • Page 794: Step Instructions

    Process C Proceeds to the end of the ladder step programming area d turns ON Step programming area completed Note Work bits are used as the control bits for A, B, C and D. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 795 2. To proceed to the next step control bit. 3. To end step programming execution. The step program area is from the first STEP(008) instruction (which always takes a control bit) to the last STEP(008) instruction (which never takes a control bit).
  • Page 796 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 797 • Input SNXT(009) at the end of the step program area and make sure that the control bit is a dummy bit in the Work Area. If a control bit for a step is used in the last SNXT(009) in the step program area, the corresponding step will be started when SNXT(009) is executed.
  • Page 798 • STEP(008) and SNXT(009) cannot be used inside of subroutines, interrupt programs, or block programs. • Be sure that two steps are not executed during the same cycle. • The instructions that cannot be used within step programs are listed in the following table. Function Mnemonic...
  • Page 799 0.03 (Step (B) Step (C) transition condition) W0.01 Step (C) W0.02 W0.01 0.04 (Step (C) reset conditions) Step W0.01 (B) Step (B) ladder program 0.03 W0.02 W0.02 Step W0.02 (C) Step (C) ladder program 0.04 W100.00 CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 800: Additional Information

    • In the above example, where SNXT(009) is executed for W0.02, the branching moves onto the next steps even though the same control bit is used twice. This is not picked up as an error in the program check using the CX-Programmer. A duplicate bit error will only occur in a step ladder program only when a control bit in a step instructions is also used in the normal ladder diagram.
  • Page 801 W0.00 Step (B) W0.01 Step (D) W0.02 Step W0.00 (A) Step (A) ladder program 0.04 (When both Step (B) and Step (D) are complete, moves to Step (E) 0.02 Step (E) W0.04 W0.01 0.05 (Step (C) reset conditions) W0.01 Step W0.01...
  • Page 802: Application Examples

    (4) SW4 ON stops the previous process 0.01(SW1) Additional Information Process C When another process is started from within a process (when an reset. W100.00 SNXT instruction turns ON), all outputs of the current process are turned OFF within that cycle.
  • Page 803 0.05(SW D) Programming for process A 0.03(SW A2) Process A reset. Explanation of operation W0.02 Process C Products are sorted by the guides by weight. started. (1) SWA1 ON: Conveyor (A) operates Process A W0.01 Machine (A) operates (2) SWB1 ON:...
  • Page 804 Note: When processes (B) and (D) are in operation and SW5 and W0.04 SW6 turn ON, it is judged that processes (B) and (D) are finished. Execution of SNXT W0.04 turns OFF the outputs of process (B) Programming for process E and W0.03 turns OFF.
  • Page 805: Basic I/O Unit Instructions

    • ON if St is greater than E. • ON if St and E are in different memory areas. • With the CS1D CPU Units: ON if the active and standby CPU Units could not be synchronized. • OFF in all other cases.
  • Page 806 Special I/O units (CIO words of all special I/O units, including high-density I/O units) Note The Units that can be refreshed with IORF(097) are not necessarily the same as the Units that can be refreshed with immediate refreshing specifications (!).
  • Page 807 Units will be refreshed. • An error will occur if words in both the I/O Area (CIO 0000 to CIO 0999) and the Special I/O Unit Area (CIO 2000 to CIO 2959) are specified for the same instruction.
  • Page 808 • Allocated DM Area words CPU Bus Units Note This table applies to Units mounted in a CPU Rack or an Expansion Rack. It does not apply to Units mounted in a SYSMAC Bus Slave Rack. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 809 • I/O refreshing of the CS1 CPU Bus Unit Area in the DM Area (100 words) • Refreshing of data specific to the CPU Bus Unit, such as data link data or DeviceNet Remote I/O Communications data FIORF(225) and IORF(097) both refresh the words allocated to Special I/O Units, but differ in the following ways.
  • Page 810 3. Instructions Sample program 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...
  • Page 811 • OFF if the I/O refreshing could not be performed because the CPU Bus Unit was refreshing data. • OFF if there was a CPU Bus Unit Error or CPU Bus Unit Setup Error in the specified CPU Bus Unit.
  • Page 812 Refer to the Hint below for details on the execution conditions to use for immediate refreshing. 1. The words allocated to the CPU Bus Unit in the PLC's CPU Bus Unit Areas (25 words in the CIO Area and 100 words in the DM Area) 2.
  • Page 813 Equals Flag Equals Flag • I/O refreshing will not be performed if a CPU Bus Unit Error (A402.07) or CPU Bus Unit Setup Error (A402.03) has occurred in the specified CPU Bus Unit. • I/O refreshing will be stopped if an I/O Bus Error occurs while I/O refreshing is being performed by DLNK(226).
  • Page 814 (The transmitted data is delayed up to 1 communications cycle time max.) • When receiving: The data that is input was received from the network the last time that the token right was acquired. (The data received is delayed up to 1 communications cycle time max.) Examples of Data Transfer Processing: •...
  • Page 815 Con- Pulse Area stants bits bits Indirect using IR Flags Name Label Operation Error Flag • ON if settings in Di are not within the specified ranges. • OFF in all other cases. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 816 7-segment Precaution • If more than one digit is specified for conversion in Di, digits are converted in order toward the most- significant digit. Digit 0 is the next digit after digit 3. • Results are stored in D in order from the specified portion toward higher-address words. If just one of the bytes in a destination word receives converted data, the other byte is left unchanged.
  • Page 817 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 818 WORD I: Input Word (Data Line D0 to D3 Inputs) Specify the input word allocated to the Input Unit and connect the digital switch's D0 to D3 data lines to the Input Unit as shown in the following diagram. Leftmost 4 digits...
  • Page 819: External Connections

    8-digit, specified in C1) of digital switch data line data from I, and stores the result in D and D+1. (If 4 digits are read, the result is stored in D. If 8 digits are read, the result is stored in D and D+1.) DSW(210) reads the 4-digit or 8-digit switch data once every 16 cycles, and then starts over and continues reading the data.
  • Page 820 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 821 Unit connected to the digital switch or thumbwheel switch after DSW(210) is executed. Consequently, set the input time constant for the Input Units used for the data line input word to a value that is shorter than the cycle time, or do not connect the digital switch or thumbwheel switch to the following Units.
  • Page 822 UINT I: Input Word (Data Line Inputs) Specify the input word allocated to the Input Unit and connect the ten-key keypad's 0 to 9 data lines to the Input Unit as shown in the following diagram. Bits 00 to 09 correspond to keys 0 to 9.
  • Page 823 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 824 TKY(211) is executed. Consequently, set the input time constant for the Input Units used for the data line input word to a value that is shorter than the cycle time, or do not connect the ten-key keypad to the following Units.
  • Page 825 WORD I: Input Word (Data Line D0 to D3 Inputs) Specify the input word allocated to the Input Unit and connect the hexadecimal keypad's D0 to D3 data lines to the Input Unit as shown in the following diagram. Bits 00 to 03 correspond to Input Unit inputs 0 to 3.
  • Page 826 Function HKY(212) outputs the selection signals to bits 00 to 03 of O, reads the data in order from bits 00 to 03 of I, and stores up to 8 digits of hexadecimal data in register words D and D+1.
  • Page 827 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 828 Unit connected to the hexadecimal keypad after HKY(212) is executed. Consequently, set the input time constant for the Input Units used for the data line input word to a value that is shorter than the cycle time, or do not connect the hexadecimal keypad to the following Units.
  • Page 829 System word WORD I: Input Word Specify the input word allocated to the Input Unit and connect the 8 input signal lines to the Input Unit as shown in the following diagram. Bits 00 to 07 correspond to Input Unit inputs 0 to 7.
  • Page 830 Bits 00 to 15 correspond to matrix elements 48 to 63. C: System Word Specifies a work word used by the instruction. This word cannot be used in any other application. System word (Cannot be accessed by the user.) Operand Specifications...
  • Page 831 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 832 Unit connected to the external matrix after MTR(213) is executed. Consequently, set the input time constant for the Input Units used for the data line input word to a value that is shorter than the cycle time, or do not connect the external matrix to the following Units.
  • Page 833 Digit 7 Digit 5 O: Output Word (Data and Latch Outputs) Specify the output word allocated to the Output Unit and connect the 7-segment display to the Output Unit as shown in the following diagram. • Converting 4 digits One Round Flag...
  • Page 834 7SEG(214) reads the source data, converts it to 7-segment display data, and outputs that data (as leftmost 4 digits D0 to D3, rightmost 4 digits D0 to D3, latch output signals LE0 to LE3) to the 7- segment display connected to the output indicated by O. The value of C indicates the number of digits of source data (either 4-digit or 8-digit) and the logic for the Input and Output Units.
  • Page 835 8-digit display. With a 4-digit display, the data outputs (D0 to D3) would be connected to outputs 0 to 3 and the latch outputs (LE0 to LE3) would be connected to outputs 4 to 7. Output point 12 (for 8-digit display) or output point 8 (for 4-digit display) will be turned ON when one round of data has been output, but it is not necessary to connect them unless required by the application.
  • Page 836 • When executed, 7SEG(214) begins on latch output 0 at the beginning of the round, regardless of the point at which the last instruction was stopped. • Even if the connected 7-segment display has fewer than 4 digits or 8 digits in its display, 7SEG(214) will still output 4 digits or 8 digits of data.
  • Page 837 UINT N: Unit number Specify the unit number between 0 and 95 using &0 to &95 decimal or #0000 to #005F hex. A: Analog input number Specify the analog input or inputs using a constant between &0 and &4 decimal or #0000 and #0004 hex.
  • Page 838 Special I/O Unit Area in the CIO Area. If 0 is specified for A, four words of data are stored. If 1 to 4 is specified for A, one word of data is stored. If 0 is specified for A, 0 will be stored for unused analog inputs.
  • Page 839 • 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 840 UINT N: Unit number Specify the unit number between 0 and 95 using &0 to &95 decimal or #0000 to #005F hex. A: Analog output number Specify the analog output or outputs using a constant between &0 and &4 decimal or #0000 and #0004 hex.
  • Page 841 N and outputs the conversion results immediately to the analog output or outputs specified in A. If 0 is specified for A, four words of data are stored. If 1 to 4 is specified for A, one word of data is stored.
  • Page 842 • 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 843 UINT Variable Note If IORD(222) is executed for a CPU Bus Unit running under a CPU Unit that does not support using IORD(222) for CPU Bus Units, an error will occur and the ER Flag will turn ON. Depends on Special I/O Unit or CPU Bus Unit.
  • Page 844 Flag with output branching from the same input conditions as the IORD(222) instruction. • If the Special I/O Unit or CPU Bus Unit is busy, the reading operation will not be executed. Use the Equals Flag to create a self-maintaining program, as shown below, so that IORD(222) will be executed with each cycle until the reading operation is executed.
  • Page 845 3. Instructions Sample program 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.
  • Page 846 Transfer destination and number of words UDINT Note If IOWR(223) is executed for a CPU Bus Unit running under a CPU Unit that does not support using IOWR(223) for CPU Bus Units, an error will occur and the ER Flag will turn ON.
  • Page 847 Note • When “0001” is designated for the number of words to be transferred (D+1), the data for S can be designated by a constant. If a constant is designated for S when the number of words to be transferred is not “0001,” an error will occur and the Error Flag will turn ON.
  • Page 848 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 849: Serial Communications Instructions

    The difference is shown in the following tables. Note • The TXD(236) and RXD(235) instructions transfer data only through the CPU Unit's built-in serial port or a serial port on a Serial Communications Board (Ver. 1.2 or later).
  • Page 850 3. Instructions Instructions Mode Communications ports TXD(236) and No-protocol Serial port in CPU Unit or Serial Communications Board (Version 1.2 or later) RXD(235) (custom) CPU Unit/Serial Communications Board TXD(236)/ RXD(235) RXD(235) TXD(236) TXDU(256) No-protocol Serial Port of Serial Communications Unit (Version 1.2 or later)
  • Page 851 0 to 7 hex (F hex: Automatic allocation) Note Automatic allocation can only be used on CJ2 CPU Units and Lot No. 020601 (manufactured June 1, 2002) or later of CS1-H, CJ1-H, CJ1M, and CS1D (for Single CPU System) CPU Units.
  • Page 852 Set the data specified by m (beginning with D) as the initial data for the receive buffer (backup data for receive failure). Data m can be set to 0002 to 00FA (hex) (2 to 255). If 0000 (hex) or 0001 (hex) is specified for m, the receive area will be cleared to 0 on receive failure.
  • Page 853 • ON if C1 is not within the specified ranges. • ON if the number of words of S or R exceeds 249 (when words are specified). • ON if PMCR(260) is executed in an interrupt task for a CJ2 CPU Unit with high-speed interrupt func- tion enabled.
  • Page 854: Cpu Bus Unit Area

    PMCR(260) will execute the communications sequence specified in C2 using the logical port specified in bits 12 to 15 of C1 and the physical port specified in bits 8 to 11 of C1 for the unit address specified in bits 0 to 7 of C1.
  • Page 855 CPU Rack and Expansion I/O Racks. The Unit address of the communications partner must be set in bits 0 to 7 of C1 to specify which Unit/Board is to be used and the serial port number must be set in bits 8 to 11. Unit addresses are specified as shown in the following table.
  • Page 856 PMCR(260) PMCR(260) • An error flag will not turn ON when the data of C2 is outside the range. A completion code will be stored in “Network Communications Completion Code” (A203 to A210) of the Auxiliary. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 857 W(1), 2: 2 bytes received Received 1 word starting from D201 data Note As shown above, the symbol read option, R( ), in the send message or the symbol write option, W( ), actually sends/receives data. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 858 Size First source word UINT Variable Control word UINT Number of bytes 0000 to 0100 hex (0 to 256) UINT C: Control word Byte order 0: Most significant bytes first 1: Least significant bytes first RS and ER signal control...
  • Page 859 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-pro- tocol mode is not set in the port's allocated DM Setup Area.
  • Page 860: Plc Setup Settings

    • If ER signal control is specified in C, bit 15 of S will be used as the ER signal. If RS and ER signal control is specified in C, bit 15 of S will be used as the RS signal and bit 14 of S will be used as the ER signal.
  • Page 861 Board's serial ports. In addition, the port must be set to no-protocol mode. • Data can be sent only when the port's Send Ready Flag is ON. (The Send Ready Flag is A392.05 for the CPU Unit's RS-232C port, A356.05 for Serial Communications Board port 1, or A356.13 for Serial Communications Board port 2.)
  • Page 862: Hardware Configuration

    8 bits Parity None Stop bits Start code None End code #000D (CR) Set the PLC communications settings to the same values in the PLC Setup. Only the end code needs to be set. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 863: Programming Example

    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 864 First destination word UINT Variable Control word UINT Number of bytes to store 0000 to 0100 hex (0 to 256 decimal) UINT C: Control Word Byte order 0 Hex: Most significant byte to least significant byte 1 Hex: Lest significant byte to most significant byte...
  • Page 865 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 866 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 867 Serial Communications Board's serial ports (the port is specified with bits 8 to 11 of C) and stores N bytes of data in words D to D+(N 2)-1. If N bytes of data has not been received at the port, then only the data that has been received will be stored.
  • Page 868 • 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.
  • Page 869 Hint • When RXD(235) is used to read data that was received at the CPU Unit's RS-232C port, the remaining data in the port's reception buffer is not cleared, so RXD(235) can be executed repeatedly to read a block of data in parts.
  • Page 870 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...
  • Page 871 8 bits Parity None Stop bits Start code None End code #000D (CR) Set the PLC communications settings to the same values in the PLC Setup. Only the end code needs to be set. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 872 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 873 (F: Automatic allocation) Note The serial port’s unit address can be specified directly by setting the serial port number to 0 and setting the destination unit address to the serial port’s unit address. (Set the destination unit address to 80 hex + 4 unit number for port 1 or 81 hex + 4 unit number for port 2.)
  • Page 874: Completion Codes

    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 875 2) If ER signal control is specified in C, bit 15 of S will be used as the ER signal. 3) If RS and ER signal control is specified in C, bit 15 of S will be used as the RS signal and bit 14 of S will be used as the ER signal.
  • Page 876 3. Instructions Start code / end code settings and send data 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 Data N send bytes: 256 max.
  • Page 877 Serial Communications Unit (version number 1.2 or later). Since SEND(090), RECV(098), CMND(490), PMCR(260), and RXDU(255) also use logical ports 0 to 7. • TXDU(256) cannot be executed for a logical port if that logical port is already being used by one of those instructions or another TXDU(256) instruction.
  • Page 878 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 879 (F: Automatic allocation) Note The serial port's unit address can be specified directly by setting the serial port number to 0 and setting the destination unit address to the serial port's unit address. (Set the destination unit address to 80 hex + 4...
  • Page 880 0205 hex Response timeout (This error can occur when the communications mode is set to host link mode.) Undefined command (This error can occur when the communications mode is set to protocol macro, NT Link, echoback test, or 0401 hex serial gateway mode.)
  • Page 881 • RXDU(255) reads data that has been received in no-protocol mode at the Serial Communications Unit with the unit address specified in bits 0 to 7 of C+1, through the port specified with bits 8 to 11 of C+1, and stores that data starting at D. If fewer than N bytes of data have been received at the port, then only the data that has been received will be stored.
  • Page 882 • Specify the size of the receive data, not including the start code and end code, in N. • The logical port number can be set to any value between 0 and 7 and is specified with bits 12 to 15 of C+1.
  • Page 883 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...
  • Page 884 Serial Communications Unit or CS-series Serial Communications Board. Since SEND(090), RECV(098), CMND(490), PMCR(260), and TXDU(256) also use logical ports 0 to 7, RXDU(255) cannot be executed for a logical port if that logical port is already being used by one of those instructions or another RXDU(255) instruction.
  • Page 885 3: Communications port No. 3 Most significant bytes Least significant bytes D: D100 D101 D102 Received in 1 2 3 4 5 6 7 8 A B C D E F G H I J K L specified D103 order: 10 bytes D104...
  • Page 886 1 hex: Peripheral port on CPU Unit or Port 1 on CPU Bus Unit or Inner Board 2 hex: Built-in RS-232C port on CPU Unit or Port 2 on CPU Bus Unit or Inner Board (Settings 3 and 4 hex are reserved.) Always set to 0.
  • Page 887 Note The Settings Changing Flags for port 3 and port 4 are reserved for future use. Function STUP(237) writes 10 words of data from S to S+9 to the communications setup area of the Unit with the specified unit address, as shown in the following table. When the constant #0000 is designated to S, the communications settings of the corresponding port will be set to default.
  • Page 888 When CIO 0.00 turns ON in the following example, the communications parameters for serial port 1 of the Serial Communications Board (Inner Board) are changed to the settings contained in the 10 words from D100 to D109. In this example, the setting are changed from the protocol mode to the protocol macro mode.
  • Page 889 0000 hex. An n words of data must be error will occur and the Error Flag will turn ON if any other prepared in advance. constant or a word address is given and PMCR2(264) will not be executed.
  • Page 890 • ON if C1 or C2 is not within the specified ranges. • ON if the number of words of S or R exceeds 249 (when word addresses are specified). • ON if there is no communications port (i.e., internal logical port) available (i.e., if A211 = 0).
  • Page 891 Communications Board or Serial Communications Unit. PMCR2 will execute the communications sequence specified in C2 using the port specified in C1. If a symbol is specified as the operand for a send message, the number of send words specified in S and beginning from S+1 will be used as the send area.
  • Page 892: Network Instructions

    (by the command/response format) with any Unit in any network or on the CPU Rack itself just by specifying the network address, node number, and unit number of the destination Unit. In the following example, a FINS command is sent to the CPU Unit through node number 2 in network address 00.
  • Page 893 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 Serial port 2 (Peripheral) Serial port 1...
  • Page 894 These examples show communications from a PLC to serial ports in devices in the network. The first shows communications to serial ports in devices in another PLC (the CPU Unit, CPU Bus Unit, or Inner Board) and the second shows communications to a serial port within the CPU Rack itself.
  • Page 895 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 896 Communications from a Host Computer Connected through Host Link It is possible to send FINS commands from a host computer to the PLC to which it is connected as well as other devices in the network (CPU Units, Special I/O Units, computers, etc.). In this case, the necessary Host Link header and terminator must be attached to the FINS command when it is sent.
  • Page 897 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 898 • 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 899 Auxiliary Area flags. The following operation occurs. (1) If the relevant Communications Port Enabled Flag (A202.00 to A202.07) is ON when the execution condition turns ON, it turns OFF, the Communications Port Error Flag (A219.00 to A219.07) turns...
  • Page 900 Each communications port can be used by only one instruction at a time. To specify a communications port, the following steps were necessary. • When programming, it was necessary to keep track of the ports that were being used to designate only available ports in operands.
  • Page 901 For CJ2 CPU Units and CS1-H, CJ1-H, CJ1M, and CS1D (Single CPU System) CPU Units of lot number 020601 or later (manufactured 1 June 2002 or later), the port number can be specified as “F” instead of from 0 to 7 to automatically allocate the communications port, i.e., the next open communications port is used automatically.
  • Page 902 A219 b (port) c (Standby) turns OFF in the cycle after communications instruction execution is completed and communications completion are detected from that cycle. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 903 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 904 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 905 Each flag will turn ON for just one cycle after a communications error occurs. Bits 00 to 07 correspond Network Communications to ports 0 to 7. If the flag turns ON, refer to the Communications Port Completion Code in (A203 to Error A210) to identify the cause of the error.
  • Page 906 A218 Confirms that the First Cycle Flags after Network Communications Finished Flag for (Port) the automatically allocated port number (corresponding bit for word b in A214) is ON. c (Standby) Confirms that the First Cycle Flags after Network Communications Error Flag for the automatically allocated port number (corresponding bit for word b in A215) is OFF.
  • Page 907 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.
  • Page 908 ,IR0 #0000 2 If it is possible that more than eight communications instructions will be executed at the same time, always check to be sure there is an available communications port before executing a communications instruction, even when using automatic port allocation.
  • Page 909 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 instructions that use automatic port allocation to existing ladder diagrams, as shown below.
  • Page 910 Methods for Using Explicit Message Communications There are two methods that can be used to send explicit messages from a PLC. • Use the CMND(490) or CMND2(493) to send a FINS command code of 2801 hex (EXPLICIT MESSAGE SEND). • Use the following Explicit Message Instructions. (See note.) Note These instructions are supported only by CS/CJ-series CPU Unit with unit version 2.0 or later.
  • Page 911 For error completions (i.e., when the flag is ON), the Communications Port Error Flag for FINS commands is used to determine if the explicit message was never sent (i.e., when the flag is ON) or if there was an error in the explicit message that was sent (i.e., when the flag is OFF).
  • Page 912 There are two possibilities for error ends, as described in the next two subsections. a) When the Explicit Message Could Not Be Sent In this case, the explicit message was never sent on the network, e.g., because the network was not running. Here, both the Explicit Communications Error Flag (A213.00 to A213.07: Communications ports 0 to 7) and the Communications Port Error Flag (A219.00 to A219.07: Communications ports 0 to...
  • Page 913 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.). Here, the Explicit Communications Error Flag (A213.00 to A213.07: Communications ports 0 to 7) will turn ON and the Communications Error Flag (A219.00 to...
  • Page 914 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...
  • Page 915 Port: F The automatically allocated port number stored in A218 (Used Communications Port Number 0 to 7) is moved to a user-specified work word b (port). A218 Detects when the First Cycle Flag after Network Communications Finished b (Port) for the automatically allocated communications port is ON in A214, i.e., the...
  • Page 916 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...
  • Page 917 2 hex Port 2 2) Set the destination unit address directly into bits 00 to 07 of C+2. In this case, set the serial port number in bits 08 to 11 of C+1 to 0 for direct specification. • Serial Communication Unit ports Port Port’s unit address...
  • Page 918 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 919 This is known as a broadcast transmission. • If a response is requested (bits 12 to 15 of C+3 set to 0) but a response has not been received within the response monitoring time, the data will be retransmitted up to 15 times (retries set in bits 0 to 3 of C+3).
  • Page 920 If the destination serial port is in the local PLC, set the network address to 00 (local network) in C+1, set the node address to 00 (local PLC) in C+2, and set the unit address to 00 (CPU Unit), E1 (Inner Board (CS Series only), or unit number + 10 hexadecimal (Serial Port Unit).
  • Page 921 D100 to D109 are transmitted to node number 3 in the local network where they are written to the ten words from D200 to D209. The data will be retransmitted up to 3 times if a response is not received within ten seconds.
  • Page 922 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...
  • Page 923 Note 1 Set the destination network address in the routing tables unless you are specifying a local network. Set the destina- tion network address to 00 for a local network. If there are more than one CPU Bus Unit connected in the PLC, the “local network”...
  • Page 924 When SEND2(491) is executed, the specified number of send words starting with the first source word specified in S at the source node (i.e., the local node) are sent to the destination node (i.e., the remote node) in the destination network specified in C. The data is written starting from the word specified in D in the node with the specified destination unit address.
  • Page 925 CPU Unit with node number 3 in the local network where they are written to ten words starting from D200 (D200 to D209). If a response is not received within 10 seconds, the data will be resent up to 3 times.
  • Page 926 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)
  • Page 927 2 hex Port 2 2) Set the source unit address directly into bits 00 to 07 of C+2. In this case, set the serial port number in bits 08 to 11 of C+1 to 0 for direct specification. • Serial Communication Unit ports Port Port’s unit address...
  • Page 928 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 source is a CJ2 CPU Unit.
  • Page 929 A203 to A210). Data will be received from the destination node once the flags have be set. • When an address in the current bank of the EM Area is specified for D, the transmitted data will be written to the current EM bank of the destination node.
  • Page 930 If the destination serial port is in the local PLC, set the network address to 00 (local network) in C+1, set the node address to 00 (local PLC) in C+2, and set the unit address to 00 (CPU Unit), E1 (Inner Board, CS Series only), or unit number + 10 hexadecimal (Serial Port Unit).
  • Page 931 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...
  • Page 932 Note 1 Set the source network address in the routing tables unless you are specifying a local network. Set the source net- work address to 00 for a local network. If there are more than one CPU Bus Unit connected in the PLC, the “local net- work”...
  • Page 933 When RECV2(492) is executed, the number of receive words specified in C starting with the first source word specified in S at the source node (i.e., the remote node) in the source network specified in C are received at the destination node (i.e., the local node). The data is written starting from the word specified in D at the local node.
  • Page 934 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. If a response is not received within 10 seconds, the data will be resent up to 3 times.
  • Page 935 Number of command data bytes (See note 1) 0002 to maximum data length (hex) Number of command data bytes to own CPU unit is 1990 bytes (#07C6 hex). For the network, varies by network type. Example: In the case of Controller Link, &2 to 1990 (#0002 to 07C6 hex)
  • Page 936 2 hex Port 2 2) Set the source unit address directly into bits 00 to 07 of C+2. In this case, set the serial port number in bits 08 to 11 of C+1 to 0 for direct specification. • Serial Communication Unit Ports Port Port’s unit address...
  • Page 937 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. 4 When two or more CPU Bus Units are mounted, the network address will be the unit number of the Unit with the low- est unit number.
  • Page 938 File Memory Operation Flag A343.13 ON when any FINS command is sent to the local CPU Unit (even for FINS commands not related to file memory) or when any of the following instructions or operations are performed for file memory.
  • Page 939 This is known as a broadcast transmission. • If a response is requested (bits 12 to 15 of C+4 set to 0) but a response has not been received within the response monitoring time, the command data will be retransmitted up to 15 times (retries set in bits 0 to 3 of C+3).
  • Page 940 (CS Series only), or Serial Communications Unit to send a command to the connected host computer. (Specify the serial port as 1 hex or 2 hex in bits 08 to 11 of C+2.) The command is a FINS message enclosed between a host link header and terminator. Any FINS command can be sent; the host link header code is 0F hexadecimal.
  • Page 941 The MEMORY AREA READ command reads 10 words from D10 to D19. The response contains the 2- byte command code (0101), the 2-byte completion code, and then the 10 words of data, for a total of 14 words or 28 bytes.
  • Page 942 (File Memory Operation Flag) is OFF, CMND(490) transmits FINS command 2215 (CREATE/DELETE 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 943 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...
  • Page 944 0000 hex: 2 s (default) Note 1 Refer to the operation manual for the specific network for the maximum data lengths for the command data and response data. For any FINS command passing through multiple networks, the maximum data lengths for the com- mand data and response data are determined by the network with the smallest maximum data lengths.
  • Page 945 RS-232C port: FC hex (252 decimal) 3 Set FF hex for broadcasting. Set 00 hex to sent to the local node. When specifying a serial port using a serial gate- way (converting to Host Link FINS), set the destination node address to one higher than the Host Link unit number of the destination PLC (1 to 32).
  • Page 946 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 947 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...
  • Page 948 This value also includes the number of bytes of Service Data starting at D+3. leftmost bytes of S+1 to S+5, which contain 00. (If the first or last word contains just one byte of data, the empty byte in that Also, include the number of bytes of Service Data starting at S+6.
  • Page 949 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 950 D+2. Note 1 The number of bytes of send data in S includes the 10 bytes in S+1 to S+5 as well as the number of bytes of service data beginning at S+6. (For example, if there is 1 byte of service data, there are 11 bytes of data all together, so S must be set to 000B hex.)
  • Page 951 78 08 07 Note The examples above only show the storage of received data in D+3, but send data is stored in S+6 in the same way. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 952 3. Instructions Sample program 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...
  • Page 953 (00 to 3F hex (0 to 63) for DeviceNet) Includes only the number of bytes of Service Data starting at D+1. (If the first or last word contains just one byte of data, the empty byte in that word is not counted.)
  • Page 954 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 955 D+1. Note The number of bytes of received data indicated in D is the number of bytes of service data. (For example, if there is 1 byte of service data, D will contains 0001 hex. D will contain 0001 hex regardless of the byte order setting, i.e., whether the byte is stored in the rightmost or leftmost byte of D.)
  • Page 956 Service Data:12345678Hex rightmost order in 2-digit pairs, as shown in the following diagram. The following diagrams show how data is stored in the data areas when the service data is in 2-byte or 4-byte units. Data in 2-byte Units • Storing Data from the Leftmost Byte (Bits...
  • Page 957 3. Instructions Sample program 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 (Port 6) Enabled Flag for port 06) are ON, EGATR(721) reads the A202.06...
  • Page 958 Set the number of bytes of source data from words S+1 on. For FINS unit address of relaying Communications Unit. example, set S to 0008 hex if there are 4 words of data (S+1 to CPU Bus Unit: 10 to 1F hex (unit number + 10 hex) S+4).
  • Page 959 00 to 07 of C. When the response to the explicit message is received, it is stored in the range of words beginning at D+2. The setting in bits 12 to 15 of C (0 or 8 hex) determines the byte-order of the service data stored at S+5. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 960 Service Data:12345678Hex rightmost order in 2-digit pairs, as shown in the following diagram. The following diagrams show how data is stored in the data areas when the service data is in 2-byte or 4-byte units. Data in 2-byte Units • Storing Data from the Leftmost Byte (Bits...
  • Page 961 78 08 07 Sample program In this example, ESATR(722) is used to overwrite the Number of Contact Operations set value in a DRT2 Slave (I/O Terminal). When CIO 0.00 and A202.06 (the Communications Port Communications Port...
  • Page 962 Specifies the leading word address containing the data to be read from the remote CPU Unit. D: First Destination Word in Local CPU Unit Specifies the leading word address where the read data will be stored in the local CPU Unit. C: First Control Word...
  • Page 963 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 source is a CJ2 CPU Unit.
  • Page 964 • ECHRD(723) sends an explicit message with the Service Code 1C hex (Byte Data Read). Sample program 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.
  • Page 965 WORD S: First Source Word in Local CPU Unit Specifies the leading word address in the local CPU Unit containing the write data. D: First Destination Word in Remote CPU Unit Specifies the leading word address of the write destination in the remote CPU Unit.
  • Page 966 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 967 • ECHWR(724) sends an explicit message with the Service Code 1E hex (Byte Data Write). Sample program 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 968: File Memory Instructions

    • The FREAD(700) (READ DATA FILE) instruction will read I/O memory data from a specified location from a data file in a Memory Card or EM file memory and write it to the specified portion of I/O memory. It can read from any point in the specified file.
  • Page 969 ON when the data couldn’t be written because the file was write-protected or 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 data type. No File Flag A343.11 ON when data could not be read because the specified file doesn’t exist.
  • Page 970 FINS Commands Related to File Memory Note There are other FINS commands related to file memory that are not shown in the following table that can be executed. Refer to the Communications Command Reference Manual (W342) for details on FINS com- mands.
  • Page 971: Example Program

    Hint There are other FINS commands that can be sent to the local PLC in addition to the ones related to file memory operations that are listed in the table above. The File Memory Operation Flag must be used to prevent simultaneous execution of these other FINS commands, too.
  • Page 972 (2) Number of Files in Root Directory There is a limit to the number of files that can be placed in the root directory of a Memory Card (just as there is a limit for a hard disk). Although the limit depends on the type and format of the Memory Card, it will be between 128 and 512 files.
  • Page 973 Memory Card. The Memory Card may become unusable if this is not done. Insert the Memory Card with the label facing to the right. Do not attempt to insert it in any other orientation. The Memory Card or CPU Unit may be damaged.
  • Page 974 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):...
  • Page 975 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 data type. File Missing Flag A343.11...
  • Page 976 6: Tab-delimited double-words (extension: .,TXT words/field: 2)* *: Cannot be set for CS-series CS1 CPU Units prior to V1@. Note 1 Each field will contain 1 word of I/O memory for the word data types and 2 words of I/O memory for the double-word data types.
  • Page 977 Note • S1+2 and S1+3 are used only for text and CVS data with no carriage returns (i.e., bits 08 to 11 of C set to 0 hex) or for binary data. Always set S1+2 and S1+3 to 00000000 hex when reading data with carriage returns (i.e., bits 08 to 11 of C set to between 8 and D hex).
  • Page 978 • ON if a constant was not specified for C (only for CS-series CS1 CPU Units prior to V1@). • ON if data specified for S1 is out of range (all CPU Units except for CS-series CS1 CPU Units prior to V1@).
  • Page 979 As a guideline, the transfer times for a cycle time of 10 ms for a file in the root directory with the default service time settings will be 0.92 s for 1,024 words and 4.64 s for 9,999 words.
  • Page 980 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...
  • Page 981 *: Cannot be set for CS-series CS1 CPU Units prior to V1 . Note 1 Each field will contain 1 word of I/O memory for the word data types and 2 words of I/O memory for the double-word data types.
  • Page 982 • D1+2 and D1+3 are used only when overwriting data, and only 1) For text and CVS data with no carriage returns (i.e., bits 08 to 11 of C set to 0 hex) or 2) for binary data. Always set D1+2 and D1+3 to 00000000 hex when writing data with carriage returns (i.e., bits 08 to 11 of C set to between 8 and D hex).
  • Page 983 • ON if a constant was not specified for C (only for CS-series CS1 CPU Units prior to V1). • ON if data specified for D1 is out of range (all CPU Units except for CS-series CS1 CPU Units prior to V1).
  • Page 984 If no carriage returns is specified, the data will be written continuously without carriage returns. • The number of fields specified in the write size is read from I/O memory and written to file memory in the above format.
  • Page 985 10 ms for a file in the root directory with the default service time settings will be 1.97 s (new file) or 1.33 s (existing file) for 1,024 words and 6.64 s (new file) or 6.12 s (existing file) for 9,999 words.
  • Page 986 ASCII text. • Directory name: The directory name can be 1 to 65 characters long. If the name is less than 65 characters, do not pad with spaces. Specify the absolute path from the root directory's \ (#5C) character.
  • Page 987 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 988 ASCII. • Set the filename as 1 to 8 ASCII characters, using only the “a to z”, “A to Z”, and “0 to 9" characters. If there are fewer than 8 characters, it is not necessary to add spaces after the filename. Always insert an NULL (#00) character after the filename.
  • Page 989 As a guideline, if the cycle time is 10 ms and the file is in the root directory, it will take about 440 ms (new file) or 260 ms (existing file) to write 100 bytes, and about 450 ms (new file) or 270 ms s (existing file) to write 255 bytes.
  • Page 990 3. Instructions Sample program 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.
  • Page 991: Display Instructions

    The message number must be 0000 to 0007 hexadecimal (or 0 to 7 decimal). M: First message word When displaying a message, M specifies the address of the first of the words containing the ASCII message. When clearing a message, M can be any hexadecimal constant (0000 through FFFF).
  • Page 992 16 characters 2 lines When CIO 0.00 turns ON in the following example, the 16 words of data in D100 through D115 are read as the 32 characters of ASCII data for message number 7 and displayed at the Peripheral device.
  • Page 993 3. Instructions ASCII Four leftmost bits CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 994: 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.
  • Page 995 R through R+2: Result Data Seconds: 00 to 59 (BCD) Minutes: 00 to 59 (BCD) Hour: 00 to 23 (BCD) Day: 01 to 31 (BCD) Month: 01 to 12 (BCD) Year: 00 to 99 (BCD) CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 996 R through R+2: Result Data Seconds: 00 to 59 (BCD) Minutes: 00 to 59 (BCD) Hour: 00 to 23 (BCD) Day: 01 to 31 (BCD) Month: 01 to 12 (BCD) Year: 00 to 99 (BCD) CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 997 Operation Error Flag • ON if the calendar data in C through C+2 is not within the specified ranges. • ON if the time data in T and T+1 is not within the specified ranges. • OFF in all other cases.
  • Page 998 D302 CSUB When CIO 0.00 turns ON in the following example, the time data in D200 and D201 (hours, minutes, seconds) is subtracted from the calendar data in D100 through D102 (year, month, day, hour, minutes, seconds) and the result is output to D300 through D302.
  • Page 999 D and D+1: Result Data (seconds only) Rightmost 4 digits Seconds: 0000 to 9999 (BCD) Leftmost 4 digits Seconds: 0000 to 3599 (BCD) Note S, S+1, D and D+1 must be in the same data area. CS/CJ/NSJ Series Instructions Reference Manual (W474)
  • Page 1000 • 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. • ON if the seconds data in S (bits 00 to 07) is not BCD and in the range 00 to 59.

Table of Contents