QCPU Common Instructions
QCPU Common Instructions
Programming Manual
(Common Instructions)
Mitsubishi Programmable
Logic Controller
SAFETY PRECAUTIONS
(Always read these cautions before using the product)
Before using this product, please read this manual and the related manuals introduced in this manual,
and pay full attention to safety to handle the product correctly.
Please store this manual in a safe place and make it accessible when required. Always forward a copy of
the manual to the end user.
A-1
A-1
REVISIONS
* The manual number is given on the bottom left of the back cover.
Print Date
Dec., 1999
Jun., 2000
* Manual Number
SH (NA)-080039-A First edition
SH (NA)-080039-B Addition
Revision
APPENDIX5
Correction
CONTENTS, Section 3.4, 6.6.1, 6.8.6, 6.8.8, 6.8.9, 7.6.8, 9.8, 10.3, 11.2,
APP 1.2, APP 4
Sep., 2000
SH (NA)-080039-C Addition
Section 9.9, 9.10, 9.11
Correction
CONTENTS, Section 2.5.20, Chapter 4
Section 5.2.5, 6.6.1, 6.8.6, 7.10.1, 8.11.1, 9.3, 11.2, APP 1.2, APP 3,
APP 4
Jun., 2001
Mar., 2002
A-2
A-2
INTRODUCTION
Thank you for purchasing the Mitsubishi MELSEC-Q Series (Q mode) and MELSEC-QnA Series of
Programmable Logic Controllers.
Before using the product, please read this manual carefully to develop full familiarity with the functions and
performance of the Programmable Logic Controller Q Series (Q mode)/QnA Series you have purchased, so
as to ensure correct use.
A copy of this manual should be forwarded to the end User.
CONTENTS
1. GENERAL DESCRIPTION
1 - 1 to 1 - 4
2 - 1 to 2 - 49
A-3
3 - 1 to 3 - 24
4 - 1 to 4 - 3
5. SEQUENCE INSTRUCTIONS
5 - 1 to 5 - 55
A-4
A-4
6 - 1 to 6 - 133
A-5
6.3.7 Conversion from BIN 16 and 32-bit data to Gray code (GRY, GRYP, DGRY, DGRYP) ............... 6 - 67
6.3.8 Conversion of Gray code to BIN 16 and 32-bit data (GBIN, GBINP, DGBIN, DGBINP) ............... 6 - 69
6.3.9 Complement of 2 of BIN 16- and 32-bit data (sign reversal) (NEG, NEGP, DNEG, DNEGP) ...... 6 - 71
6.3.10 Sign reversal for floating decimal point data (ENEG, ENEGP) .................................................... 6 - 73
6.3.11 Conversion from block BIN 16-bit data to BCD 4-digit data (BKBCD, BKBCDP)........................ 6 - 74
6.3.12 Conversion from block BCD 4-digit data to block BIN 16-bit data (BKBIN, BKBINP).................. 6 - 76
6.4 Data Transfer Instructions...................................................................................................................... 6 - 78
6.4.1 16-bit and 32-bit data transfers (MOV, MOVP, DMOV, DMOVP).................................................. 6 - 78
6.4.2 Floating decimal point data transfers (EMOV, EMOVP) ................................................................ 6 - 80
6.4.3 Character string transfers ($MOV, $MOVP) ................................................................................... 6 - 82
6.4.4 16-bit and 32-bit negation transfers (CML, CMLP, DCML, DCMLP).............................................. 6 - 84
6.4.5 Block 16-bit data transfers (BMOV, BMOVP) ................................................................................. 6 - 87
6.4.6 Identical 16-bit data block transfers (FMOV, FMOVP) ................................................................... 6 - 89
6.4.7 16-bit and 32-bit data exchanges (XCH, XCHP, DXCH, DXCHP)................................................. 6 - 91
6.4.8 Block 16-bit data exchanges (BXCH, BXCHP)............................................................................... 6 - 93
6.4.9 Upper and lower byte exchanges (SWAP, SWAPP)...................................................................... 6 - 95
6.5 Program Branch Instruction ................................................................................................................... 6 - 96
6.5.1 Pointer branch instructions (CJ, SCJ, JMP).................................................................................... 6 - 96
6.5.2 Jump to END (GOEND) .................................................................................................................. 6 - 99
6.6 Program Execution Control Instructions .............................................................................................. 6 - 100
6.6.1 Interrupt disable/enable instructions, interrupt program mask (DI, EI IMASK) ............................ 6 - 100
6.6.2 Recovery from interrupt programs (IRET) .................................................................................... 6 - 109
6.7 I/O Refresh Instructions ....................................................................................................................... 6 - 111
6.7.1 I/O Refresh (RFS, RFSP).............................................................................................................. 6 - 111
6.8 Other Convenient Instructions.............................................................................................................. 6 - 113
6.8.1 Count 1-phase input up or down (UDCNT1)................................................................................. 6 - 113
6.8.2 Counter 2-phase input up or down (UDCNT2) ............................................................................. 6 - 115
6.8.3 Teaching timer (TTMR) ................................................................................................................. 6 - 117
6.8.4 Special function timer (STMR) ...................................................................................................... 6 - 119
6.8.5 Rotary table near path rotation control (ROTC) ............................................................................ 6 - 122
6.8.6 Ramp signal (RAMP)..................................................................................................................... 6 - 124
6.8.7 Pulse density measurement (SPD)............................................................................................... 6 - 126
6.8.8 Fixed cycle pulse output (PLSY) ................................................................................................... 6 - 128
6.8.9 Pulse width modulation (PWM) ..................................................................................................... 6 - 130
6.8.10 Matrix input (MTR)....................................................................................................................... 6 - 132
7. APPLICATION INSTRUCTIONS
7 - 1 to 7 - 332
A-6
A-7
A-7
A-8
-1
7.12.5 COS operation on floating decimal point data (ACOS, ACOSP)............................................. 7 - 243
-1
7.12.6 TAN operation on floating decimal point data (ATAN, ATANP)............................................... 7 - 245
7.12.7 Conversion from floating decimal point angle to radian (RAD, RADP) ...................................... 7 - 247
7.12.8 Conversion from floating decimal point radian to angle (DEG, DEGP)...................................... 7 - 249
7.12.9 Square root operations for floating decimal point data (SQR, SQRP) ....................................... 7 - 251
7.12.10 Exponent operations on floating decimal point data (EXP, EXPP) .......................................... 7 - 253
7.12.11 Natural logarithm operations on floating decimal point data (LOG, LOGP)............................. 7 - 255
7.12.12 Random number generation and series updates (RND, RNDP, SRND, SRNDP).................. 7 - 257
7.12.13 BCD 4-digit and 8-digit square roots (BSQR, BSQRP, BDSQR, BDSQRP) ........................... 7 - 259
7.12.14 BCD type SIN operation (BSIN, BSINP) ................................................................................... 7 - 262
7.12.15 BCD type COS operations (BCOS, BCOSP)............................................................................ 7 - 264
7.12.16 BCD type TAN operation (BTAN, BTANP) ............................................................................... 7 - 266
-1
7.12.17 BCD type SIN operations (BASIN, BASINP).......................................................................... 7 - 268
-1
7.12.18 BCD type COS operation (BACOS, BACOSP)...................................................................... 7 - 270
-1
7.12.19 BCD type TAN operations (BATAN, BATANP)...................................................................... 7 - 272
7.13 Data Control Instructions.................................................................................................................... 7 - 274
7.13.1 Upper and lower limit controls for BIN 16-bit and BIN 32-bit data
(LIMIT, LIMITP, DLIMIT, DLIMITP) ............................................................................................. 7 - 274
7.13.2 BIN 16-bit and 32-bit dead band controls (BAND, BANDP, DBAND, DBANDP)....................... 7 - 277
7.13.3 Zone control for BIN 16-bit and BIN 32-bit data (ZONE, ZONEP, DZONE, DZONEP)............. 7 - 280
7.14 File Register Switching Instructions ................................................................................................... 7 - 283
7.14.1 Switching file register numbers (RSET, RSETP)........................................................................ 7 - 283
7.14.2 Setting files for file register use (QDRSET, QDRSETP) ............................................................ 7 - 285
7.14.3 File setting for comments (QCDSET, QCDSETP) ..................................................................... 7 - 287
7.15 Clock Instructions ............................................................................................................................... 7 - 289
7.15.1 Reading clock data (DATERD, DATERDP)................................................................................ 7 - 289
7.15.2 Writing clock data (DATEWR, DATEWRP)................................................................................ 7 - 293
7.15.3 Clock data addition operation (DATE+, DATE+P)...................................................................... 7 - 297
7.15.4 Clock data subtraction operation (DATE-, DATE-P) .................................................................. 7 - 299
7.15.5 Changing time data formats (SECOND, SECONDP, HOUR, HOURP) .................................... 7 - 301
7.16 Peripheral Device Instructions ........................................................................................................... 7 - 303
7.16.1 Message displays to peripheral devices (MSG) ......................................................................... 7 - 303
7.16.2 Keyboard input from peripheral devices (PKEY) ........................................................................ 7 - 305
7.17 Program Control Instructions ............................................................................................................. 7 - 307
7.17.1 Program standby instruction (PSTOP, PSTOPP)....................................................................... 7 - 308
7.17.2 Program output OFF standby instruction (POFF, POFFP) ........................................................ 7 - 309
7.17.3 Program scan execution registration instruction (PSCAN, PSCANP) ....................................... 7 - 311
7.17.4 Program low speed execution registration instruction (PLOW, PLOWP).................................. 7 - 313
7.18 Other Instructions ............................................................................................................................... 7 - 315
7.18.1 Resetting watchdog timer (WDT, WDTP) .................................................................................. 7 - 315
7.18.2 Timing pulse generation (DUTY)................................................................................................. 7 - 317
7.18.3 Direct 1-byte read from file register (ZRRDB, ZRRDBP) ........................................................... 7 - 319
7.18.4 File register direct 1-byte write (ZRWRB, ZRWRBP) ................................................................. 7 - 321
7.18.5 Indirect address read operations (ADRSET, ADRSETP)........................................................... 7 - 323
7.18.6 Numerical key input from keyboard (KEY).................................................................................. 7 - 324
7.18.7 Batch save or recovery of index register (ZPUSH, ZPUSHP, ZPOP, ZPOPP) ......................... 7 - 328
2
7.18.8 Batch write operation to E PROM file register (EROMWR, EROMWRP) ................................. 7 - 332
A-9
A-9
8 - 1 to 8 - 103
9 - 1 to 9 - 42
10 - 1 to 10 - 14
A - 10
A - 10
11- 1 to 11 - 46
A - 11
A - 11
Manuals
The following table lists the manuals related to the Q/QnACPU.
Please order the one you need.
Related Manuals
Manual Number
(Model Code)
Manual Name
Basic model QCPU (Q mode) User's Manual (Hardware design, Maintenance and Inspection)
Describes the specifications of the CPU module, power supply module, base unit, and extension cables.
(Sold separately)
High Performance model QCPU (Q mode) User's Manual (Hardware design, Maintenance and
Inspection)
Describes the specifications of the CPU module, power supply module, base unit, extension cables, and
memory card.
(Sold separately)
High Performance model QCPU (Q mode) User's Manual (Functions Explanation, Programming
Fundamentals)
Describes the functions, programming method, and devices to create programs with High Performance model
QCPU (Q mode).
(Sold separately)
SH-080188
(13JR44)
SH-080037
(13JL97)
SH-080038
(13JL98)
(13JR55)
SH-080315E
(13JR56)
SH-080041
Describes the system configuration, performance specifications, functions, programming, debugging, and error
codes for MELSAP3.
(Sold separately)
(13JF60)
SH-080076
Describes the system configuration, performance specifications, functions, programming, debugging, and error
codes for MELSAP-L.
(Sold separately)
(13JF61)
SH-080040
(Sold separately)
(13JR43)
SH-080314E
Describes the specifications of the CPU module, power supply module, base unit, extension cables, and
memory card.
(Sold separately)
SH-080187
(13JF59)
SH-080316E
(Sold separately)
(13JR67)
QnACPU Guidebook
Aimed at people using QnACPU for the first time. Describes procedures for everything from creating programs
and writing created programs to the CPU module, to debugging.
Also describes how to use the QnACPU most effectively.
IB-66606
(13JF10)
IB-66608
Describes the performance, functions, and handling of the Q2ACPU(S1), Q3ACPU, and Q4ACPU, and the
specifications and handling of memory cards and base units.
(Sold separately)
(13J821)
SH-3599
(13J858)
(Sold separately)
A - 12
A - 12
Manual Number
(Model Code)
Manual Name
Q4ARCPU User's Manual
Describes the Q4ARCPU features, functions, and usage. Also describes the specification and usage of the
bus switching module, system management module, power supply module, memory card, and base unit.
(Sold separately)
(13JF46)
SH-4013
Describes the dedicated instructions for special function modules available when using the Q2ACPU(S1),
Q3ACPU, and Q4ACPU.
(Sold separately)
(13JF56)
IB-66617
Describes the dedicated instructions for controlling an AD57(S1) type CRT controller module available
when using the Q2ACPU(S1), Q3ACPU, or Q4ACPU.
(Sold separately)
(13JF49)
IB-66618
Describes the dedicated instructions for PID control available when using the Q2ACPU(S1), Q3ACPU, or
Q4ACPU.
(Sold separately)
(13JF50)
IB-66619
Describes the system configuration, performance specifications, functions, programming, debugging, and
error codes for MELSAP3.
(Sold separately)
(13JF51)
IB-66690
Describes the general concept, specifications, and part names and settings for MELSECNET/10.
(Sold separately)
(13JF78)
IB-66350
Describes the general concept, specifications, and part names and settings for MELSECNET (II) and
MELSECNET/B.
(Sold separately)
(13JF70)
SH-080166
Describes the online functions of GX Developer Version 7 including the programming procedure, printing
out procedure, monitoring procedure, and debugging procedure.
(Sold separately)
(13JU14)
IB-66774
Describes how to create programs and print out data when using SW2IVD-GPPQ, and the offline functions
of SW2IVD-GPPQ such as file maintenance.
(Included with product)
A - 13
(13J852)
IB-66614
Describes how to create programs, the names of devices, parameters, and types of program.
(Sold separately)
IB-66685
(13J921)
IB-66775
(13J922)
IB-66776
(13J923)
A - 13
MEMO
A - 14
A - 14
1 GENERAL DESCRIPTION
MELSEC-Q/QnA
1. GENERAL DESCRIPTION
This manual describes the common instructions for QCPU, QnACPU, and Q2AS(H)CPU(S1) that
are required when programming with a QCPU, QnACPU, and Q2AS(H)CPU(S1).
Common instructions are all instructions except those used for special function modules such as
AJ71QC24, AJ71PT32-S3, etc.; the instructions for AD57; the instructions for PID control, and
those for MELSAP3.
This manual
QCPU (Q mode)/
QnACPU
Programming
Manual
(Common
Instructions)
1-1
QCPU (Q mode)/
QnACPU
Programming
Manual
(PID
Control Instructions)
QCPU (Q mode)/
QnACPU
Programming
Manual (SFC)
QCPU (Q mode)
Programming
Manual
(MELSAP-L)
Describes SFC.
Describes MELSAP-L.
1-1
1 GENERAL DESCRIPTION
MELSEC-Q/QnA
Basic model
QCPU (Q mode)
User's Manual
(Functions
Explanation,
Programming
fundamentals)
This manual
QCPU (Q mode)/
QnACPU
Programming
Manual
(Common
Instructions)
Process CPU
Users Manual
(Function
Explanation,
Programming
Fundamentals)
This manual
1-2
QCPU (Q mode)/
QnACPU
Programming
Manual
(Common
Instructions)
QnPHCPU
Programming
Manual
(Process Control
Instructions)
QCPU (Q mode)/
QnACPU
Programming
Manual
(SFC)
QCPU (Q mode)
Programming
Manual
(MELSAP-L)
Describes SFC.
Describes MELSAP-L.
1-2
1 GENERAL DESCRIPTION
MELSEC-Q/QnA
QnACPU
Programming
Manual
(Fundamentals)
This manual
QCPU (Q mode)/
QnACPU
Programming
Manual
(Common
Instructions)
QnACPU
Programming
Manual
(Special
Function Modules)
QnACPU
Programming
Manual
(AD57 Command)
QCPU (Q mode)/
QnACPU
Programming
Manual
(PID
Control Instructions)
QCPU (Q mode)/
QnACPU
Programming
Manual (SFC)
Describes SFC.
Q4ARCPU
Programming
Manual
(Application
PID Instructions)
1-3
1-3
1 GENERAL DESCRIPTION
MELSEC-Q/QnA
Abbreviation
Abbreviation in Tables
QCPU
Generic Name
High Performance
High Performance
model QCPU
model QCPU
Process CPU
Process CPU
QnACPU
QnA
Q2ASCPU
Q2AS
Q4ARCPU
Q4AR
MELSECNET/H
MELSECNET/10(H)
(MELSECNET/10 mode)
MELSECNET/10 Network system
Ethernet interface module
Control and Communication Link System
Master/Local Module
1-4
MELSECNET/10
Ethernet interface
Ethernet interface
module
module
CC-Link module
CC-Link module
1-4
2 INSTRUCTION TABLES
MELSEC-Q/QnA
2. INSTRUCTION TABLES
2.1 Types of Instructions
The major types of CPU module instructions consist of sequence instructions, basic instructions,
application instructions, data link instructions, QCPU instructions and redundant system
instructions. These types of instructions are listed in Table 2.1 below.
Table 2.1 Types of Instructions
Types of Instructions
Contact instruction
Connection instructions
Sequence
instructions
Output instruction
Shift instruction
Master control instruction
Termination instruction
Other instructions
Basic
instructions
Application
instructions
Data link
instructions
QCPU
instructions
Redundant system
Instructions for Q4ARCPU
instructions
2-1
Meaning
Operation start, series connection, parallel connection
Ladder block connection, creation of pulses from operation results, store/read
operation results
Bit device output, pulse output, output reversal
Bit device shift
Master control
Program termination
Program stop, instructions such as no operation which do not fit in the above
categories
Comparisons such as =, >, <
Addition, subtraction, multiplication or division of BIN or BCD
Conversion from BCD to BIN and from BIN to BCD
Transmits designated data
Program jumps
Enable or prohibit interrupt programs
Run partial refresh
Instructions for: Counter increment/decrement, teaching timer, special function
timer, rotary table shortest direction control, etc.
Logical operations such as logical sum, logical product, etc.
Rotation of designated data
Shift of designated data
Bit set and reset, bit test, batch reset of bit devices
16-bit data searches, data processing such as decoding and encoding
Repeated operation, subroutine program calls, Index modification in ladder
units
Read/Write of FIFO table
Data read/write for special function modules
Print ASCII code, LED character display, etc.
Reference
Chapter
10
2-1
2 INSTRUCTION TABLES
MELSEC-Q/QnA
BIN 16-bit
addition
and
subtraction
operations
Symbol
Processing Details
S D
+P
+P
S D
S1 S2 D
+P
+P
S1 S2 D
(D)+(S)
(S1)+(S2)
Execution
Condition
See for
Description
Category
Subset
Number of
Basic Steps
Instruction
Symbols
The instruction tables found from Section 2.3 to 2.6 have been made according to the following
format:
Table 2.2 How to Read Instruction Tables
(D)
3
6-16
6-18
(D)
Description
1
D+
Instructions
Example
Instructions
executed when ON
Real number
Example
+
instructions ........... The letter "E" is added to the first line of the instruction
E+
Real number instructions
Character
Example
string instructions ...... A dollar sign $ is added to the first line of the
instruction
+
$+
Character string instructions
2-2
2-2
2 INSTRUCTION TABLES
MELSEC-Q/QnA
S D
S1 S2 D
Indicates destination
Indicates source
Indicates destination
Indicates source
(D)
(D+1, D)+(S+1, S)
16 bits
(D+1, D)
16 bits
Indicates 16 bits
Indicates 32 bits
D+1
D
The upper 16 bits
The lower 16 bits
...........The details of conditions for the execution of individual instructions are as follows:
Symbol
Execution Condition
Instruction executed under normal circumstances, with no regard to the ON/OFF
No symbol recorded status of conditions prior to the instruction.
If the preconditions is OFF, the instruction will conduct OFF processing.
Executed during ON; instruction is executed only while the precondition is ON.
If the preconditions is OFF, the instruction is not executed, and no processing is
conducted.
Executed once at ON; instruction executed only at leading edge when precondition
goes from OFF to ON. Following execution, instruction will not be executed and no
processing conducted even if condition remains ON.
Executed during OFF; instruction is executed only while the precondition is OFF.
If the precondition is ON, the instruction is not executed, and no processing is
conducted.
Executed once at OFF; instruction executed only at trailing edge when precondition
goes from ON to OFF. Following execution, instruction will not be executed and no
processing conducted even if condition remains OFF.
2-3
...........Indicates the page numbers where the individual instructions are explained.
2-3
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Processing Details
Execution
Condition
LD
LDI
AND
ANI
OR
ORI
Contact
LDP
LDF
ANDP
ANDF
ORP
ORF
See for
Description
Symbol
Subset
Category
Number of
Basic Steps
Instruction
Symbols
5-2
5-5
REMARKS
1)
1 : The number of steps may vary depending on the device being used.
Device
Internal device, file register (R0 to R32767)
Direct access input (DX)
Devices other than above
Number of Steps
1
2
3
2) 2 : The number of steps may vary depending on the device and type of CPU module being
used.
Device
Internal device, file register (R0 to R32767)
Direct access input (DX)
Devices other than above
3)
2-4
Number of Steps
QCPU
QnACPU
1
2
3
2
2
3
2-4
2 INSTRUCTION TABLES
MELSEC-Q/QnA
ANB
ORB
MPS
MRD
MPS
MRD
MPP
MPP
Connection INV
MEP
MEF
EGP
EGF
See for
Description
Execution
Condition
ANB
ORB
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
Vn
Vn
5-7
5-9
5-13
5-14
1
5-16
REMARKS
1:The number of steps may vary depending on the type of CPU module being used.
Component
2-5
2-5
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Processing Details
OUT
Output
Execution
Condition
Device output
2
SET
SET
Set device
RST
RST
Reset device
PLS
PLS
PLF
PLF
FF
FF
DELTA
DELTA
DELTAP
DELTAP
See for
Description
Symbol
Subset
Category
Number of
Basic Steps
Instruction
Symbols
5-18
5-28
5-32
5-30
5-32
5-34
5-36
5-38
REMARKS
1)
1:
2)
2:
SFT
SFT
SFTP
SFTP
Shift
2-6
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
5-40
2-6
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Master
control
MC
Processing Details
MC
n D
Execution
Condition
See for
Description
Symbol
Subset
Category
Number of
Basic Steps
Instruction
Symbols
5-42
MCR
MCR
Program
end
FEND
Execution
Condition
FEND
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
5-46
1
END
END
5-48
Stop
STOP
STOP
NOP
Ignored
NOPLF
PAGE
2-7
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
5-50
5-52
2-7
2 INSTRUCTION TABLES
MELSEC-Q/QnA
LD=
S1 S2
AND=
S1 S2
OR=
S1 S2
LD<>
<>
S1 S2
AND<>
<>
S1 S2
OR<>
<>
S1 S2
LD>
>
S1 S2
AND>
>
S1 S2
OR>
16-bit data
comparisons
LD<=
>
S1 S2
<=
S1 S2
AND<=
<=
S1 S2
OR<=
<=
S1 S2
LD<
<
S1 S2
AND<
<
S1 S2
OR<
<
S1 S2
LD>=
>=
S1 S2
AND>=
>=
S1 S2
OR>=
>=
S1 S2
2-8
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
6-2
6-2
6-2
6-2
6-2
6-2
2-8
2 INSTRUCTION TABLES
MELSEC-Q/QnA
LDD=
D=
S1 S2
ANDD=
D=
S1 S2
ORD=
D=
S1 S2
LDD<>
D< >
S1 S2
ANDD<>
D< >
S1 S2
ORD<>
D< >
S1 S2
LDD>
D>
S1 S2
ANDD>
D>
S1 S2
ORD>
32-bit data
comparisons
LDD<=
D>
2-9
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
6-4
6-4
6-4
6-4
6-4
6-4
S1 S2
D< =
S1 S2
ANDD<=
D< =
S1 S2
ORD<=
D< =
S1 S2
LDD<
D<
S1 S2
ANDD<
D<
S1 S2
ORD<
D<
S1 S2
LDD>=
D> =
S1 S2
ANDD>=
D> =
S1 S2
ORD>=
D> =
S1 S2
2-9
2 INSTRUCTION TABLES
MELSEC-Q/QnA
REMARK
1 : The number of steps may vary depending on the device and type of CPU module being
used.
Component
Note 1:With High Performance module QCPU, (1) requires more number of steps, while it can
process the steps faster, as compared with (2).
Note 2:The number of steps may increase due to the conditions described in Section 3.8.
2 - 10
2 - 10
2 INSTRUCTION TABLES
MELSEC-Q/QnA
LDE=
E=
S1 S2
ANDE=
E=
S1 S2
ORE=
E=
S1 S2
LDE<>
E<>
S1 S2
ANDE<>
E <>
S1 S2
ORE<>
E<>
S1 S2
LDE>
E>
S1 S2
ANDE>
E>
S1 S2
ORE>
Real
number
data comLDE<=
parisons
E>
S1 S2
E< =
S1 S2
ANDE<=
E< =
S1 S2
ORE<=
E<=
S1 S2
LDE<
E<
S1 S2
ANDE<
E<
S1 S2
ORE<
E<
S1 S2
LDE>=
E> =
S1 S2
ANDE>=
E> =
S1 S2
ORE>=
E>=
S1 S2
2 - 11
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
6-6
6-6
6-6
6-6
6-6
6-6
2 - 11
2 INSTRUCTION TABLES
MELSEC-Q/QnA
LD$=
$=
S1 S2
AND$=
$=
S1 S2
OR$=
$=
S1 S2
LD$<>
$<>
S1 S2
AND$<>
$<>
S1 S2
OR$<>
$ <>
S1 S2
LD$>
$>
S1 S2
AND$>
$>
S1 S2
Character OR$>
string data
compariLD$<=
sons
$>
S1 S2
$<=
S1 S2
AND$<=
$<=
S1 S2
OR$<=
$<=
S1 S2
LD$<
$<
S1 S2
AND$<
$<
S1 S2
OR$<
$<
S1 S2
LD$>=
$>=
S1 S2
AND$>=
$ >=
S1 S2
OR$>=
$>=
S1 S2
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
6-8
6-8
6-8
6-8
6-8
6-8
REMARK
1)
2 - 12
: The conditions under which character string comparisons can be made are as shown
below
Match:
All characters in the strings must match
Larger string: If character strings are different, determines the string with the largest
number of character codes
If the lengths of the character strings are different, determines the
longest character string
Smaller string: If the character strings are different, determines the string with the
smallest number of character codes
If the lengths of the character strings are different, determines the
shortest character string
2 - 12
2 INSTRUCTION TABLES
MELSEC-Q/QnA
BKCMP = S1 S2 D n
BKCMP<>
BKCMP>
BKCMP > S1 S2 D n
BKCMP<=
BKCMP < = S1 S2 D n
BKCMP<
BKCMP < S1 S2 D n
See for
Description
Execution
Condition
Subset
Processing Details
BKCMP=
2 - 13
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
BKCMP > = S1 S2 D n
5
6-12
BKCMP = P S1 S2 D n
BKCMP< >P
BKCMP>P
BKCMP > P S1 S2 D n
BKCMP<=P
BKCMP < = P S1 S2 D
BKCMP<P
BKCMP < P S1 S2 D n
BKCMP>=P
BKCMP > = P S1 S2 D
2 - 13
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Processing Details
S D
+P
+P
S D
+
BIN 16-bit
+P
addition
and
subtraction operations
-P
S1 S2 D
+P
S1 S2 D
S D
S D
S1 S2 D
-P
S1 S2 D
D+
D+
S D
D+P
D+P
S D
D+
BIN 32-bit
D+P
addition
and
subtraction Doperations
D-P
D+
S1 S2 D
D+P
S1 S2 D
S D
D P
S D
D-
S1 S2 D
D-P
DP
S1 S2 D
S1 S2 D
BIN 16-bit
P
multiplication and
division
/
operations
/P
D
BIN 32-bit
multiplica- D P
tion and
division
D/
operations
D/P
2 - 14
(D)+(S)
(D)
(S1)+(S2)
(D) - (S)
6-16
6-18
6-16
6-18
(D)
(D)
(S1) - (S2)
(D)
(D+1, D)+(S+1, S)
(D+1, D)
(D+1, D)-(S+1, S)
(S2)
6-20
6-22
6-20
6-22
6-24
(D+1, D)
(D+1, D)
(S1)
Execution
Condition
See for
Description
Symbol
Subset
Category
Number of
Basic Steps
Instruction
Symbols
(D+1, D)
(D+1, D)
S1 S2 D
S1 S2 D
/P
S1 S2 D
S1 S2 D
D P
S1 S2 D
D/
S1 S2 D
D/P
S1 S2 D
(S1)/(S2)
(D+1)
(S1+1, S1)
D+1, D)
Quotient(D), Remainder
(S2+1, S2)
6-24
6-26
6-26
(D+3, D+2,
2 - 14
2 INSTRUCTION TABLES
MELSEC-Q/QnA
REMARKS
1)
1:The number of steps may vary depending on the device and type of CPU module being
used.
Component
Note 1)
5
Note 2)
3
Note 2)
Note 1:With High Performance module QCPU, (1) requires more number of steps, while it can
process the steps faster, as compared with (2).
Note 2:The number of steps may increase due to the conditions described in Section 3.8.
2)
2:The number of steps may vary depending on the device and type of CPU module being
used.
Component
Note 1)
6
Note 2)
4
Note 2)
Note 1:With High Performance module QCPU, (1) requires more number of steps, while it can
process the steps faster, as compared with (2).
Note 2:The number of steps may increase due to the conditions described in Section 3.8.
3)
3:The number of steps may vary depending on the device and type of CPU module being
used.
Component
QCPU
QnCPU
2 - 15
4
4
2 - 15
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Processing Details
B+
B+
S D
B+P
B+P
S D
B+
BCD 4digit
B+P
addition
and
Bsubtraction
operations
B-P
B+
S1 S2 D
B+P
S1 S2 D
S D
BP
S D
B-
S1 S2 D
B-P
BP
S1 S2 D
DB+
DB+
S D
DB+P
DB+P
S D
DB+
BCD 8digit
DB+P
addition
and
DBsubtraction
operations
DB-P
DB+
S1 S2 D
DB+P
S1 S2 D
DB
S D
DB P
S D
DB-
DB
S1 S2 D
DB-P
DB P
S1 S2 D
B
BCD 4digit multiB P
plication
and
B/
division
operations
B/P
S1 S2 D
B P
S1 S2 D
B/
S1 S2 D
B/P
S1 S2 D
DB
BCD 8digit multiDB P
plication
and
DB/
division
operations
DB/P
DB
S1 S2 D
DB P
S1 S2 D
DB/
S1 S2 D
DB/P
S1 S2 D
2 - 16
(D)+(S)
(D)
(S1)+(S2)
(D)-(S)
6-28
6-30
6-28
6-30
6-32
6-34
6-32
6-34
6-36
6-36
6-38
6-38
(D)
(D)
(S1)-(S2)
(D)
(D+1, D)+(S+1, S)
(D+1, D)
(D+1, D)-(S+1, S)
(S2)
(S1)/(S2)
(D+1)
(S1+1, S1)
D+1, D)
(D+1, D)
(D+1, D)
(S1)
Execution
Condition
See for
Description
Symbol
Subset
Category
Number of
Basic Steps
Instruction
Symbols
(D+1, D)
(D+1, D)
Quotient(D), Remainder
(S2+1, S2)
(D+3, D+2,
Quotient (D+1,
(S1+1, S1)/(S2+1, S2)
D), Remainder (D+3, D+2)
2 - 16
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Floating
decimal
point data
addition
and subtraction
operations
Floating
decimal
point data
multiplication and
division
operations
E+
E+
S D
E+P
E+P
S D
E+
E+
S1 S2 D
E+P
E+P
S1 S2 D
E-
S D
E-P
EP
S D
E-
S1 S2 D
E-P
EP
S1 S2 D
S1 S2 D
E P
E P
S1 S2 D
E/
E/
S1 S2 D
E/P
E/P
S1 S2 D
BK+
BIN block
BK+P
addition
and subtraction
BKoperations
BK-P
BK+
S1 S2 D n
BK+P
S1 S2 D n
BK
S1 S2 D n
BK P
S1 S2 D n
$+
Character
$+P
string data
combina$+
tions
$+P
2 - 17
Processing Details
$+
S D
$+P
S D
$+
S1 S2 D
$+P
S1 S2 D
(D+1, D)+(S+1, S)
(D+1, D)
(D+1, D)-(S+1, S)
6-40
6-42
6-40
6-42
6-44
6-44
6-46
6-46
6-49
6-51
(D+1, D)
(D+1, D)
(S1+1, S1)
Execution
Condition
See for
Description
Symbol
Subset
Category
Number of
Basic Steps
Instruction
Symbols
(S2+1, S2)
(D+1, D)
(D+1, D)
Quotient
2 - 17
2 INSTRUCTION TABLES
MELSEC-Q/QnA
INC
INC
INCP
INCP
DINC
DINC
DINCP
DINCP
DEC
DEC
DECP
DECP
DDEC
DDEC
DDECP
DDECP
(D)+1
Execution
Condition
(D)
2
(D+1, D)+1
(D)-1
6-53
(D+1, D)
1
BIN data
increment
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
6-55
(D)
2
(D+1, D)-1
6-53
(D+1, D)
1
6-55
REMARKS
1)
1:The number of steps may vary depending on the device and type of CPU module being
used.
Component
Note 1)
3
Note 2)
2
Note 2)
Note 1:With High Performance module QCPU, (1) requires more number of steps, while it can
process the steps faster, as compared with (2).
Note 2:The number of steps may increase due to the conditions described in Section 3.8.
2 - 18
2 - 18
2 INSTRUCTION TABLES
MELSEC-Q/QnA
BCD conversions
BIN conversions
BCD
S D
BCDP
BCDP
S D
DBCD
DBCD
S D
DBCDP
DBCDP
S D
BIN
BIN
S D
BINP
BINP
S D
DBIN
DBIN
S D
DBINP
DBINP
S D
FLT
FLT
S D
FLTP
S D
DFLT
S D
DFLTP
S D
INT
S D
INTP
S D
DINT
S D
DINTP
S D
DBL
S D
DBLP
S D
WORD
S D
WORDP
WORDP
S D
GRY
GRY
S D
GRYP
S D
DGRY
S D
DGRYP
S D
INT
Conversion
from float- INTP
ing decimal
point to
DINT
BIN
DINTP
DBL
Conversion
DBLP
between
BIN 16-bit
WORD
and 32-bit
Conversion GRYP
from BIN to
gray code DGRY
DGRYP
BCD conversion
(S)
(D)
BIN (0 to 9999)
BCD conversion
(S+1, S)
(D+1, D)
BIN (0 to 99999999)
BIN conversion
(S)
(D)
BCD (0 to 9999)
BIN conversion
(S+1, S)
(D+1, D)
BCD (0 to 99999999)
Conversion to floating
decimal point
(S+1, S)
(D)
BIN (-32768 to 32767)
Conversion to floating
decimal point
(D+1, D)
(S+1, S)
Real number
(-2147483648 to 2147483647)
Conversion to BIN
(D)
(S+1, S)
Real number
(-32768 to 32767)
Conversion to BIN
(S+1, S)
(D+1, D)
Real number
(-2147483648 to 2147483647)
Conversion
(S)
(D+1, D)
BIN (-32768 to 32767)
See for
Description
Execution
Condition
Subset
Processing Details
BCD
Conversion
FLTP
from BIN to
floating
DFLT
decimal
point
DFLTP
2 - 19
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
6-57
6-57
6-59
6-59
6-61
6-61
6-63
6-63
6-65
6-66
6-67
6-67
Conversion
(S+1, S)
(D)
BIN (-32768 to 32767)
2 - 19
2 INSTRUCTION TABLES
MELSEC-Q/QnA
GBIN
GBIN
S D
GBINP
S D
DGBIN
S D
DGBINP
S D
NEG
NEGP
NEGP
DNEG
DNEG
Conversion GBINP
from gray
code to
DGBIN
BIN
DGBINP
NEG
Complement to 2
Block conversions
2 - 20
DNEGP
DNEGP
ENEG
ENEG
ENEGP
ENEGP
BKBCD
BKBCD
S D n
BKBCDP
BKBCDP
S D n
BKBIN
BKBIN
S D n
BKBINP
BKBINP
S D n
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
6-69
6-69
6-71
BIN data
6-71
(D+1, D)
Real number data
6-73
6-74
6-76
(D)
(D)
BIN data
(D+1, D)
(D+1, D)
(D+1, D)
2 - 20
2 INSTRUCTION TABLES
MELSEC-Q/QnA
16-bit data
transfer
32-bit data
transfer
Floating
decimal
point data
transfer
MOV
MOV
S D
MOVP
MOVP
S D
DMOV
DMOV
S D
DMOVP
DMOVP
S D
EMOV
EMOV
S D
EMOVP
$MOV
S D
$MOVP
S D
CML
S D
CMLP
S D
DCML
S D
DCMLP
S D
BMOV
BMOV
S D n
BMOVP
BMOVP
S D n
FMOV
S D n
FMOVP
S D n
XCH
XCH
S D
XCHP
XCHP
S D
DXCH
DXCH
S D
DXCHP
DXCHP
S D
Multiple
FMOV
transfers of
same data
FMOVP
block
Block data
exchange
BXCH
BXCH
S D n
BXCHP
BXCHP
S D n
SWAP
SWAPP
See for
Description
6-78
(D+1, D)
(S+1, S)
6-80
6-82
(D)
(S)
(S+1, S)
6-84
6-84
(D+1, D)
(S)
(D)
n
6-87
6-89
6-91
6-91
6-93
6-95
(D)
(S)
(D)
(S)
(S+1, S)
(S)
(D+1, D)
(D)
n
Exchange SWAP
of upper
and lower
SWAPP
bytes
2 - 21
(D+1, D)
(S+1, S)
Character $MOV
string data
transfer
$MOVP
32-bit data
exchange
S D
16-bit data
exchange
(D)
(S)
6-78
EMOVP
Block
transfer
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
(S)
b15 to b8 b7 to b0
8 bits
8 bits
b15 to b8 b7 to b0
8 bits
(D) 8 bits
2 - 21
2 INSTRUCTION TABLES
MELSEC-Q/QnA
REMARK
1)
1:The number of steps may vary depending on the device and type of CPU module being
used.
Component
Note 2)
3
Note 2:The number of steps may increase due to the conditions described in Section 3.8.
2)
2:The number of steps may vary depending on the device and type of CPU module being
used.
Component
Note 1)
2
Note 2)
3
Note 2)
Note 1:With High Performance module QCPU, (1) requires more number of steps, while it can
process the steps faster, as compared with (2).
Note 2:The number of steps may increase due to the conditions described in Section 3.8.
3)
4)
4 : The number of steps may vary depending on the device and type of CPU module being
used.
Component
Note 1)
3
Note 2)
3
Note 1)
2
Note 2)
3
QnACPU
Note 2)
Note 1:With High Performance module QCPU, (1) requires more number of steps, while it can
process the steps faster, as compared with (2).
Note 2:The number of steps may increase due to the conditions described in Section 3.8.
2 - 22
2 - 22
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Processing Details
CJ
CJ
Pn
SCJ
SCJ
Pn
JMP
JMP
Pn
Jump
GOEND
GOEND
Execution
Condition
See for
Description
Symbol
Subset
Category
Number of
Basic Steps
Instruction
Symbols
6-96
6-96
6-96
6-99
Disable
interrupts
Enable
interrupts
Interrupt
disable
/enable
setting
Return
Processing Details
DI
DI
EI
EI
IMASK
IMASK
IRET
IRET
Execution
Condition
See for
Description
Symbol
Subset
Category
Number of
Basic Steps
Instruction
Symbols
6-100
6-100
6-100
6-109
I/O
Refresh
2 - 23
RFS
RFS
D n
RFSP
RFSP
D n
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
6-111
2 - 23
2 INSTRUCTION TABLES
MELSEC-Q/QnA
UDCNT1
See for
Description
UDCNT1
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
(S)+0
S D n
Up
Down
Up
(S)+1
Current Cn value 0 1 2 3 4 5 6 7 6 5 4 3 2 1 0 -1 -2 -3 -2 -1 0
6-113
6-115
6-117
6-119
6-122
6-124
6-126
6-128
6-130
6-132
Cn contact point
Up/Down
Counter
(S)+0
UDCNT2
UDCNT2
S D n
(S)+1
Current Cn value 0 1
-1
Cn contact point
Teaching
timer
Special
timer
Nearest
path
control
Ramp
signal
TTMR
(D)
D n
n = 0:1, n = 1:10, n = 2:100
STMR
ROTC
RAMP
STMR
ROTC
RAMP
S n D
S n1 n2 D
n1 n2 D1 n3 D2
Pulse
density
SPD
SPD
S n D
Pulse
output
PLSY
PLSY
n1 n2 D
Pulse
PWM
width
modulation
PWM
n1 n2 D
n2
(D)
Matrix
input
2 - 24
MTR
MTR
S D1 D2 n
2 - 24
2 INSTRUCTION TABLES
MELSEC-Q/QnA
WAND
WAND
S D
WANDP
WANDP
S D
(D)
(S)
(D)
WAND
WAND
S1 S2 D
WANDP
WANDP
S1 S2 D
(S1)
(S2)
DAND
DAND
S D
DANDP
DANDP
S D
(S+1, S)
(D+1, D)
DAND
DAND
S1 S2 D
DANDP
DANDP
S1 S2 D
(S2+1, S2)
(S1+1, S1)
BKAND
BKAND
BKANDP
BKANDP S1 S2 D n
WOR
WOR
S D
WORP
WORP
S D
WOR
WOR
S1 S2 D
WORP
WORP
S1 S2 D
(S2)
(S1)
S1 S2 D n
(S1)
(S)
DOR
DOR
S D
DORP
DORP
S D
7-8
7-10
(D)
(S+1, S)
DOR
S1 S2 D
DORP
DORP
S1 S2 D
(S1+1, S1)
BKOR
BKOR
S1 S2 D n
BKORP
BKORP
S1 S2 D n
WXOR
WXOR
S D
WXORP
WXORP
S D
WXOR
WXOR
S1 S2 D
WXORP
WXORP
S1 S2 D
(S1)
(S2+1, S2)
(S2)
(S1)
(S)
(S2)
7-10
(D+1, D)
7-12
(D)
n
(D)
7-12
(D+1, D)
DOR
7-5
7-14
7-16
(D)
(D)
2 - 25
(D)
(S2)
(D+1, D)
7-3
(D)
n
(D)
7-5
(D+1, D)
Exclusive
OR
(D+1, D)
Logical
sum
7-3
(D)
Logical
product
See for
Description
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-18
2 - 25
2 INSTRUCTION TABLES
MELSEC-Q/QnA
DXOR
DXOR
S D
DXORP
DXORP
S D
(D+1, D)
(S+1, S)
(D+1, D)
1
Exclusive
OR
DXOR
DXOR
S1 S2 D
DXORP
DXORP
S1 S2 D
(S2+1, S2)
(S1+1, S1)
BKXORP S1 S2 D n
BKXORP
BKXORP S1 S2 D n
WXNR
WXNR
S D
WXNRP
WXNRP
S D
WXNR
WXNR
S1 S2 D
WXNRP
WXNRP
S1 S2 D
(S1)
(S2)
(S1)
(S)
DXNR
S D
7-20
7-22
(D)
(S2)
DXNRP
S D
(D+1, D)
(D)
(S+1, S)
DXNR
S1 S2 D
DXNRP
DXNRP
S1 S2 D
(S1+1, S1)
(S2+1, S2)
BKXNR
S1 S2 D n
BKXNRP
BKXNRP
S1 S2 D n
(S1)
(S2)
7-22
(D+1, D)
2
BKXNR
7-26
(D+1, D)
1
DXNR
7-18
DXNR
NON
exclusive
logical sum DXNRP
(D)
n
(D)
7-16
(D+1, D)
2
BKXOR
See for
Description
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-26
(D)
n
7-28
REMARK
1)
1:The number of steps may vary depending on the device and type of CPU module being
used.
Component
Note 1)
5
Note 2)
3
Note 2)
Note 1:With High Performance module QCPU, (1) requires more number of steps, while it can
process the steps faster, as compared with (2).
Note 2:The number of steps may increase due to the conditions described in Section 3.8.
2 - 26
2 - 26
2 INSTRUCTION TABLES
2)
MELSEC-Q/QnA
2:The number of steps may vary depending on the device and type of CPU module being
used.
Component
Note 1)
6
Note 2)
4
Note 2)
Note 1:With High Performance module QCPU, (1) requires more number of steps, while it can
process the steps faster, as compared with (2).
Note 2:The number of steps may increase due to the conditions described in Section 3.8.
3)
Right
rotation
Left
rotation
Right
rotation
Left
rotation
2 - 27
ROR
ROR
D n
RORP
RORP
D n
RCR
RCR
D n
RCRP
RCRP
D n
ROL
ROL
D n
ROLP
ROLP
D n
RCL
RCL
D n
RCLP
RCLP
D n
DROR
DROR
D n
DRORP
DRORP
D n
DRCR
DRCR
D n
DRCRP
DRCRP
D n
DROL
DROL
D n
DROLP
DROLP
D n
DRCL
DRCL
D n
DRCLP
DRCLP
D n
b15
(D)
b0
See for
Description
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
SM700
7-30
7-30
7-32
7-32
7-34
7-34
7-36
7-36
(D)
b0
SM700
SM700
b15
(D)
b0
b15
(D)
b0
(D+1)
(D)
b31 to b16 b15 to b0
SM700
SM700
(D+1)
(D)
b31 to b16 b15 to b0
(D+1)
(D)
b31 to b16 b15 to b0
2 - 27
2 INSTRUCTION TABLES
MELSEC-Q/QnA
SFR
SFR
D n
b15
SFRP
SFRP
D n
b15
0 to 0
SFL
SFL
D n
SFLP
SFLP
D n
BSFR
BSFR
D n
bn
See for
Description
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
b0
b0
7-38
7-38
7-40
7-40
7-42
7-42
SM700
n-bit shift
bn
b15
b0
b15
SM700
b0
0 to 0
n
(D)
BSFRP
BSFRP
D n
BSFL
BSFL
D n
BSFLP
BSFLP
D n
SM700
0
1-bit shift
n
(D)
SM700
0
DSFR
DSFRP
DSFR
DSFRP
D n
(D)
D n
0
1-word
shift
DSFL
DSFLP
DSFL
D n
DSFLP
D n
(D)
Bit set /
reset
2 - 28
BSET
BSET
D n
BSETP
BSETP
D n
BRST
BRST
D n
BRSTP
BRSTP
D n
(D)
b15
bn
See for
Description
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
b0
7-44
7-44
1
(D)
b15
bn
b0
0
2 - 28
2 INSTRUCTION TABLES
MELSEC-Q/QnA
TEST
TEST
(S1)
b15
S1 S2 D
TESTP
TESTP
S1 S2 D
DTEST
DTEST
S1 S2 D
DTESTP
DTESTP S1 S2 D
(S1)
b31
BKRST
b0
to
b0
BKRSTP
7-46
7-46
7-48
(D)
(S)
ON
OFF
S n
Reset
OFF
OFF
n
BKRSTP
See for
Description
(D)
(S)
BKRST
to
Bit tests
Batch reset
of bit
devices
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
OFF
OFF
ON
ON
S n
SER
SER
S1 S2 D n
See for
Description
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
(S2)
(S1)
SERP
SERP
S1 S2 D n
DSER
DSER
S1 S2 D n
Data
searches
32 bits
DSERP
SUM
S D
SUMP
SUMP
S D
DSUM
DSUM
S D
DSUMP
DSUMP
S D
Bit checks
DECO
DECO
S D n
DECOP
DECOP
S D n
ENCO
ENCO
S D n
ENCOP
ENCOP
S D n
Encode
2 - 29
7-50
7-54
7-54
7-56
7-58
b0
(D): Number of 1s
(S+1)
(S)
(D): Number of 1s
Decode
(S2)
S1 S2 D n
SUM
7-50
(S1)
n
DSERP
5
(D) :Match No.
(D+1) :Number of matches
Decode
(D)
2nbits
n
Decode from 256 to 8
(S)
2nbits
Encode
(D)
n
2 - 29
2 INSTRUCTION TABLES
MELSEC-Q/QnA
7-segment
decode
SEG
SEGP
SEG
SEGP
S D
S D
DIS
DIS
S D n
DISP
DISP
S D n
UNI
UNI
S D n
UNIP
UNIP
S D n
NDIS
NDIS
S1 D S2
NDISP
NDISP
S1 D S2
NUNI
NUNI
S1 D S2
NUNIP
NUNIP
S1 D S2
WTOB
WTOB
S D n
WTOBP
WTOBP
S D n
BTOW
BTOW
S D n
BTOWP
BTOWP
S D n
MAX
MAX
S D n
Separating
and linking
MAXP
MAXP
S D n
MIN
MIN
S D n
MINP
MINP
S D n
DMAX
DMAX
S D n
DMAXP
DMAXP
S D n
b3 to b0
(S)
(D)
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-60
7-62
7-64
7-66
7-71
7SEG
7-75
4
7-77
Search
Searches the data of 2 n-points from
the device designated by (S) in 32-bit
units, and stores the maximum value at
the device designated by (D).
7-75
4
2 - 30
DMIN
DMIN
S D n
DMINP
DMINP
S D n
7-77
2 - 30
2 INSTRUCTION TABLES
MELSEC-Q/QnA
SORT
SORT
S1 n S2 D1 D2
Sort
DSORT
DSORT
WSUM
Total value WSUMP
calculations
DWSUM
DWSUMP
2 - 31
S1 n S2 D1 D2
WSUM
S D n
WSUMP
S D n
DWSUM
S D n
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-80
7-83
4
7-85
DWSUMP S D n
2 - 31
2 INSTRUCTION TABLES
MELSEC-Q/QnA
FOR
Number of
repeats
Processing Details
FOR
NEXT
BREAK
BREAK
D Pn
BREAKP
BREAKP
D Pn
CALL
CALLP
Pn S1 to Sn
CALLP
Pn S1 to Sn
RET
FCALL
FCALL
Pn S1 to Sn
FCALLP
FCALLP
Pn S1 to Sn
Pn S1 to Sn
ECALL
: Program Name
ECALLP
RET
ECALL
2
7-87
1
NEXT
CALL
Subroutine
program
calls
Execution
Condition
See for
Description
Symbol
Subset
Category
Number of
Basic Steps
Instruction
Symbols
Pn S1 to Sn
ECALLP
7-89
1
2
+
n
7-91
7-94
1
2
+
n
7-95
2
3
+
n
7-99
2
3
+
n
7-102
7-016
: Program Name
EFCALL
Pn S1 to Sn
EFCALL
: Program Name
EFCALLP
Pn S1 to Sn
EFCALLP
: Program Name
COM
IX
COM
IX
IXEND
IXDEV
IXSET
Pn D
IXSET
2
7-112
1
1
7-120
3
2 - 32
2 - 32
2 INSTRUCTION TABLES
MELSEC-Q/QnA
FIFW
FIFW
S D
FIFWP
FIFWP
S D
FIFR
FIFR
S D
FIFRP
FIFRP
S D
FPOP
FPOP
S D
FPOPP
FPOPP
S D
(S)
2 - 33
FINS
S D n
FINSP
FINSP
S D n
FDEL
FDEL
S D n
FDELP
FDELP
S D n
7-125
7-127
7-129
7-131
7-131
Pointer +1
device
(S) Pointer Pointer -1
(D)
(D)
Table
processing
FINS
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
Pointer +1 device
(S)
Designated by n
(S) Pointer Pointer -1
(D)
Designated by n
2 - 33
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Processing Details
FROM
FROM
n1 n2 D n3
FROMP
FROMP
n1 n2 D n3
DFRO
DFRO
n1 n2 D n3
DFROP
DFROP
n1 n2 D n3
TO
TO
n1 n2 S n3
TOP
TOP
n1 n2 S n3
DTO
DTO
n1 n2 S n3
DTOP
DTOP
n1 n2 S n3
Data read
Data write
Execution
Condition
See for
Description
Symbol
Subset
Category
Number of
Basic Steps
Instruction
Symbols
7-134
7-134
7-137
7-137
PR
ASCII print PR
SM701 When ON
PR
S D
PRC
LED
PRC
S D
LED
Display
LEDC
Reset
2 - 34
LEDR
LEDC
LEDR
Execution
Condition
7-140
3
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-143
7-148
2
7-150
1
7-152
2 - 34
2 INSTRUCTION TABLES
MELSEC-Q/QnA
CHKCIR
CHKCIR
CHKEND
CHKEND
SLT
SLT
SLTR
SLTR
STRA
STRA
STRAR
STRAR
PTRA
PTRA
PTRAR
PTRAR
PTRAEXE
PTRAEXE
PTRAEXE
P
PTRAEXEP
CHKST
Checks
Status
latch
Sampling
trace
Program
trace
2 - 35
CHK
CHKST
CHK
Check Condition
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-155
7-159
7-167
7-169
7-171
7-171
2 - 35
2 INSTRUCTION TABLES
MELSEC-Q/QnA
BIN to
decimal
ASCII
BIN to
hexadecimal
ASCII
BCD to
decimal
ASCII
Decimal
ASCII to
BIN
BINDA
S D
BINDAP
BINDAP
S D
DBINDA
DBINDA
S D
DBINDAP
DBINDAP S D
BINHA
BINHA
S D
BINHAP
BINHAP
S D
DBINHA
DBINHA
S D
DBINHAP
DBINHAP S D
BCDDA
BCDDA
S D
BCDDAP
BCDDAP
S D
DBCDDA
DBCDDA
S D
DBCDDAP
DBCDDAP S D
DABIN
DABIN
S D
DABINP
DABINP
S D
DDABIN
DDABIN
S D
DDABINP
DDABINP S D
HABIN
HABIN
S D
HABINP
S D
DHABIN
S D
DHABINP
DHABINP S D
See for
Description
Execution
Condition
Subset
Processing Details
BINDA
Hexadeci- HABINP
mal ASCII
to BIN
DHABIN
2 - 36
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-173
7-173
7-176
7-176
7-179
7-179
7-182
7-182
7-185
7-185
2 - 36
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Decimal
ASCII to
BCD
DABCD
S D
DABCDP
DABCDP
S D
DDABCD
DDABCD S D
Decimal
character
string to
BIN
Floating
decimal
point to
character
string
Character
string to
floating
decimal
point
2 - 37
DDABCDP S D
COMRD
COMRD
COMRDP
COMRDP S D
LEN
LEN
S D
LENP
LENP
S D
STR
BIN to
decimal
character
string
STR
S D
S1 S2 D
STRP
STRP
S1 S2 D
DSTR
DSTR
S1 S2 D
DSTRP
DSTRP
S1 S2 D
VAL
VAL
S D1 D2
VALP
VALP
S D1 D2
DVAL
DVAL
S D1 D2
DVALP
DVALP
ESTR
ESTR
ESTRP
EVAL
EVALP
ESTRP
EVAL
EVALP
S D1 D2
S1 S2 D
See for
Description
Execution
Condition
Subset
Processing Details
DABCD
DDABCDP
Device
comment
read
operation
Character
string
length
detection
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-187
7-187
7-190
7-194
7-196
7-196
7-202
7-202
7-207
7-214
S1 S2 D
S D
S D
2 - 37
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Hexadeci- ASC
mal BIN to
ASCII
ASCP
ASCII to
hexadecimal BIN
ASC
S D n
ASCP
S D n
HEX
HEX
S D n
HEXP
HEXP
S D n
RIGHT
RIGHT
S D n
RIGHTP
RIGHTP
S D n
LEFT
LEFT
S D n
LEFTP
LEFTP
S D n
MIDR
S1 D S2
MIDRP
S1 D S2
MIDW
MIDW
S1 D S2
MIDWP
MIDWP
S1 D S2
MIDR
Character
string
MIDRP
processing
Floating
decimal
point to
BCD
BCD to
floating
decimal
point data
2 - 38
INSTR
INSTR
S1 S2 D n
INSTRP
INSTRP
S1 S2 D n
EMOD
EMOD
S1 S2 D
EMODP
EMODP
S1 S2 D
EREXP
EREXP
S1 S2 D
EREXPP
EREXPP S1 S2 D
See for
Description
Execution
Condition
Subset
Processing Details
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-218
7-220
7-222
7-225
7-229
7-231
7-233
2 - 38
2 INSTRUCTION TABLES
MELSEC-Q/QnA
SIN
S D
SINP
SINP
S D
COS
COS
S D
COSP
COSP
S D
TAN
S D
TANP
S D
ASIN
S D
ASINP
S D
ACOS
ACOS
S D
ACOSP
ACOSP
S D
ATAN
ATAN
S D
ATANP
ATANP
S D
RAD
RAD
S D
RADP
S D
DEG
S D
DEGP
DEGP
S D
SQR
SQR
S D
SQRP
SQRP
S D
EXP
EXP
S D
EXPP
EXPP
S D
LOG
LOG
S D
LOGP
LOGP
S D
Conversion
RADP
between
angles and
DEG
radians
Exponent
operations
Natural
logarithms
RND
Random
number
generation RNDP
Random
number
series
update
2 - 39
RND
RNDP
SRND
SRND
SRNDP
SRNDP
Sin (S+1, S)
See for
Description
Execution
Condition
Subset
Processing Details
SIN
TAN
Trigonometric
TANP
functions
(Floating
ASIN
decimal
point data)
ASINP
Square
root
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
(D+1, D)
7-235
7-237
7-239
7-241
7-243
7-245
(D+1, D)
(S+1, S)
Conversion from
angles to radians
7-247
(D+1, D)
(S+1, S)
Conversion from
radians to angles
7-249
7-251
7-253
7-255
7-257
Cos (S+1, S)
Tan (S+1, S)
Sin-1 (S+1, S)
(D+1, D)
(D+1, D)
(D+1, D)
Cos-1 (S+1, S)
(D+1, D)
Tan-1 (S+1, S)
(S+1, S)
e(S+1,
S)
Log e (S+1, S)
(D+1, D)
(D+1, D)
(D+1, D)
(D+1, D)
2 - 39
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Square
root
Trigonometric
function
2 - 40
BSQR
BSQR
S D
BSQRP
BSQRP
S D
BDSQR
BDSQR
S D
BDSQRP
BDSQRP S D
BSIN
BSIN
S D
BSINP
BSINP
S D
BCOS
BCOS
S D
BCOSP
BCOSP
S D
BTAN
BTAN
S D
BTANP
BTANP
S D
BASIN
BASIN
S D
BASINP
BASINP
S D
BACOS
BACOS
S D
BACOSP
BACOSP
S D
BATAN
BATAN
S D
BATANP
BATANP
S D
(S)
(S+1, S)
Sin (S)
Cos (S)
Tan (S)
Sin-1 (S)
Cos-1 (S)
Tan-1 (S)
(D)+0
Integer part
+1 Decimal fraction part
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-259
7-259
(D)+0
Sign
+1
Integer part
+2 Decimal fraction part
7-262
(D)+0
Sign
+1
Integer part
+2 Decimal fraction part
7-264
(D)+0
Sign
+1
Integer part
+2 Decimal fraction part
7-266
(D)+0
Sign
+1
Integer part
+2 Decimal fraction part
7-268
(D)+0
Sign
+1
Integer part
+2 Decimal fraction part
7-270
7-272
(D)+0
+1
Integer part
Decimal fraction part
(D)+0
Sign
+1
Integer part
+2 Decimal fraction part
2 - 40
2 INSTRUCTION TABLES
MELSEC-Q/QnA
LIMIT
LIMIT
S1 S2 S3 D
LIMITP
LIMITP
S1 S2 S3 D
Upper and
lower limit
DLIMIT
controls
DLIMIT
S1 S2 S3 D
DLIMITP
DLIMITP
S1 S2 S3 D
BAND
BAND
S1 S2 S3 D
BANDP
BANDP
S1 S2 S3 D
Dead band
DBAND
controls
DBAND
S1 S2 S3 D
Zone
controls
DBANDP
DBANDP S1 S2 S3 D
ZONE
ZONE
S1 S2 S3 D
ZONEP
ZONEP
S1 S2 S3 D
DZONE
DZONE
S1 S2 S3 D
DZONEP
2 - 41
DZONEP S1 S2 S3 D
(D)
(D)
See for
Description
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-274
7-274
7-277
7-277
7-280
7-280
2 - 41
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Block
number
designations
File set
RSET
RSET
RSETP
RSETP
QDRSE
T
QDRSE
TP
QCDSE
T
QCDSE
TP
QDRSET
File Name
File Name
7-283
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-285
7-287
: n ([number of file name characters] / 2) indicates a step. (Decimal fractions are rounded up.)
2 - 42
2 - 42
2 INSTRUCTION TABLES
MELSEC-Q/QnA
(Clock device)
Read/write
clock data
DATERD
DATERD
DATERDP
DATERDP D
DATEWR
DATEWR S
DATEWRP
DATEWRP S
DATE+
Clock data DATE+P
addition/
subtraction DATEDATE-P
Clock data
translation
2 - 43
(D)+0
+1
+2
+3
+4
+5
Year
Month
Day
Hour
Minute
Sec.
of
+6 Day
week
DATE+
S1 S2 D
DATE+P
S1 S2 D
DATE
S1 S2 D
DATE P S1 S2 D
SECOND
SECOND S D
SECONDP
SECONDP S D
HOUR
HOUR
S D
HOURP
HOURP
S D
See for
Description
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-289
7-293
Year
Month
Day
Hour
Minute
Sec.
of
+6 Day
week
(Clock device)
(S1)
Hour
Minute
Sec.
(S2)
Hour
Minute
Sec.
(D)
Hour
Minute
Sec.
7-297
(S2)
Hour
Minute
Sec.
(D)
Hour
Minute
Sec.
7-299
7-301
(D)+0
+1
+2
+3
+4
+5
(S1)
Hour
Minute
Sec.
(S)
Hour
Minute
Sec.
(D)
Sec. (lower level)
Sec. (upper level)
(S)
Sec. (lower level)
Sec. (upper level)
(D)
Hour
Minute
Sec.
2 - 43
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Input/
MSG
output to
peripheral
devices
PKEY
MSG
PKEY
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-303
7-305
Switching
program
execution
statuses
PSTOP
PSTOP
Program Name
PSTOPP
PSTOPP
Program Name
POFF
POFF
Program Name
POFFP
POFFP
Program Name
PSCAN
PSCAN
Program Name
PSCANP
PSCANP
Program Name
PLOW
PLOW
Program Name
PLOWP
PLOWP
Program Name
Execution
Condition
2
+
n
2
+
n
2
+
n
2
+
n
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-308
7-309
7-311
7-313
: n ([number of program name characters] / 2) indicates a step. (Decimal fractions are rounded up.)
2 - 44
2 - 44
2 INSTRUCTION TABLES
MELSEC-Q/QnA
WDT
WDT
WDTP
WDTP
WDT reset
Timing
clock
See for
Description
Execution
Condition
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
7-315
7-317
7-319
7-321
7-323
7-324
7-328
7-332
(D)
DUTY
DUTY
n1 scan
n1 n2 D
n2 scan
ZRRDB
ZRRDB
ZRRDBP
Direct
read/write ZRWRB
operations
in 1-byte
ZRWRBP
units
ZRRDBP
n D
ZRWRB
n S
Lower 8 bits
Upper 8 bits
Lower 8 bits
Upper 8 bits
8 bits
ZRWRBP n S
ADRSET
ADRSETP
ADRSETP S D
KEY
2 - 45
0
1
2
3
(S)
ADRSET
Numerical
key input
KEY
from
keyboard
Batch
recovery of
index
register
Batch write
operation
to
E2PROM
file register
n D
S D
S n D1 D2
ZPUSH
ZPUSHP
ZPOP
ZPOP
ZPOPP
ZPOPP
EROMWR
EROMWR
EROMWRP
EROMWRP S D1 n D2
S D1 n D2
(S)
ZR0
ZR1
(D)
0
1
2
3
Lower 8 bits
Upper 8 bits
Lower 8 bits
Upper 8 bits
8 bits
ZR0
ZR1
(D)
Indirect address of
designated device
Device name
2 - 45
2 INSTRUCTION TABLES
MELSEC-Q/QnA
J.ZCOM
Network
refresh
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
Jn
JP.ZCOM Jn
Refreshes the designated network.
ZCOM
8-6
8-12
10
8-18
10
8-24
11
8-31
8-38
8-46
8-52
G.ZCOM Un
GP.ZCOM Un
QnA link
instruction:
Reading
data from
another
station
QnA link
instruction:
Writing
data to
other
stations
Jn
S1
S2
D1
D2
G.READ
Jn
S1
S2
D1
D2
JP.READ
Jn
S1
S2
D1
D2
GP.READ
Un S1
S2
D1
D2
READ
J.SREAD
Jn
S1
S2
D1
D2
D3
G.SREAD
Un S1
S2
D1
D2
D3
JP.SREAD
Jn
S1
S2
D1
D2
D3
GP.SREAD
Un S1
S2
D1
D2
D3
J.WRITE
Jn
S1
S2
D1
D2
G.WRITE
Un S1
S2
D1
D2
JP.WRITE
Jn
S1
S2
D1
D2
GP.WRITE
Un S1
S2
D1
D2
SREAD
WRITE
J.SWRITE
Jn
S1
S2
D1
D2
D3
G.SWRITE
Un S1
S2
D1
D2
D3
JP.SWRITE
Jn
S1
S2
D1
D2
D3
GP.SWRITE
Un S1
S2
D1
D2
D3
J.SEND
Jn
S1
S2
D1
G.SEND
Un S1
S2
D1
JP.SEND
Jn
S1
S2
D1
GP.SEND
Un S1
S2
D1
J.RECV
Jn
S1
S2
D1
G.RECV
Un S1
S2
D1
JP.RECV
Jn
S1
S2
D1
GP.RECV
Un S1
S2
D1
SWRITE
QnA link
instruction:
SEND
Sending
data
QnA link
instruction:
RECV
Receiving
data
QnA link
instruction:
Transient
REQ
requests
from other
stations
2 - 46
J.READ
J.REQ
Jn
S1
S2
D1
D2
G.REQ
Un S1
S2
D1
D2
JP.REQ
Jn
S1
S2
D1
D2
GP.REQ
Un S1
S2
D1
D2
2 - 46
2 INSTRUCTION TABLES
MELSEC-Q/QnA
QnA link
instruction:
Reading
data from
special
function
modules at
remote I/O
stations
JP.ZNFR
GP.ZNFR
Un S1 S2 D1
J.ZNTO
Jn S1 S2 D
JP.ZNTO
Jn S1 S2 D
G.ZNTO
Un S1 S2 D
GP.ZNTO
Un S1 S2 D
J.ZNRD
Jn
n1
D1
n2
Jn
n1
D1
n2
D2
J.ZNWR
Jn
n1
D1
n2
D2
ZNWR
G.RFRP
Jn
n1
D1
n2
See for
Description
Subset
8-64
8-69
32
8-74
8-78
32
8-81
8-85
11
8-88
11
8-92
8-96
8-100
D2
JP.ZNRD
JP.ZNWR
Execution
Condition
Jn S1 S2 D1
ZNRD
D2
Un n1 D1 n2 D2
RFRP
GP.RFRP Un n1 D1 n2 D2
G.RTOP Un n1 D1 n2 D
RTOP
GP.RTOP Un n1 D1 n2 D
Reading
routing
information
RTREAD
Registering
routing
information
RTWRITE
2 - 47
Processing Details
ZNFR
QnA link
instruction:
Writing data
to special
ZNTO
function
module at
remote I/O
station
A-series
compatible
link instruction:
Reading
device data
from other
stations
A-series
compatible
link instruction: Writing
device data
to other
stations
A-series
compatible
link instruction:
Reading
data from
special
function
module at
remote I/O
station.
A-series
compatible
link instruction: Writing
data to
special
function
modules at
remote I/O
stations.
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
Z.RTREAD
n D
ZP.RTREAD
n D
Z.RTWRITE
n S
ZP.RTWRITE
n S
2 - 47
2 INSTRUCTION TABLES
MELSEC-Q/QnA
UNIRD
UNIRD n1 D n2
Reading
module
information UNIRDP
Trace set
Load +
unload
Highspeed
block
transfer of
file register
Write to
host station
CPU
shared
memory
Read from
another
station
CPU
shared
memory
Automatic
refresh of
CPU
shared
memory
9-5
9-5
11
9-7
11
9-15
9-26
PUNLOADP S D
9-28
PSWAPP S1 S2 D
9-30
9-32
9-35
9-37
9-39
TRACE
2 - 48
TRACER
SP.FWRITE
SP.FWRITE U0 S0 D0 S1 S2 D1
SP.FREAD
SP.FREAD U0 S0 D0 S1 S2 D1
PLOADP
PLOADP
PUNLOADP
RBMOV
S D
RBMOV S D n
RBMOVP
RBMOVP S D n
S. TO
S.TO
n1 n2 n3 n4 D
SP. TO
SP.TO
n1 n2 n3 n4 D
FROM
FROM
n1 n2 D n3
FROMP
COM
See for
Description
9-2
TRACE
PSWAPP
Execution
Condition
UNIRDP n1 D n2
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
FROMP
n1 n2 D n3
COM
2 - 48
2 INSTRUCTION TABLES
MELSEC-Q/QnA
Operation
mode
setting
S.STMODE
during
CPU start
up
Operation
mode
setting
instructions S.CGMODE
during
CPU
switch
S.STMODE S1 S2
10-2
S.CGMODE S
10-4
10-6
10-10
Data
tracking
S.TRUCK
S.TRUCK
Buffer
memory
batch
refresh
S.SPREF
S.SPREF
2 - 49
Execution
Condition
See for
Description
Processing Details
Subset
Symbol
Number of
Basic Steps
Category
Instruction
Symbols
2 - 49
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
3. CONFIGURATION OF INSTRUCTIONS
3.1 Configuration of Instructions
Most CPU module instructions consist of an instruction part and a device part.
Instruction part.....Indicates the function of the instruction
Device part ..........Indicates the data that is to be used with the instruction.
The device part is classified into source data, destination data, and number of devices.
3
(1) Source S
(a) Source is the data used for operations.
(b) The following source types are available, depending on the designated device:
Constants .....................................Designates the numeric value to be used in the
operation.
This is set when the program is written, and cannot
be changed during the execution of the program.
Constants should be indexed when using them as
variable data.
Bit devices and Word devices .....Designates the device that stores the data to be
used for the operation.
Data must be stored in the designated device until
when the operation is executed.
By changing the data stored in a designated device
during program execution, the data to be used in
the instruction can be changed.
(2) Destination D
(a) The destination stores the data after the operation has been conducted.
However, some instructions require storing the data to be used in an operation at the
destination prior to the operation execution.
Example: An addition instruction involving BIN 16-bit data
+
S1
S2
(b) A device for the data storage must always be set to the destination.
3-1
3-1
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
(b) The number of devices or number of transfers can be set between 0 and 32767.
However, if the number is 0, the instruction will be a no-operation instruction.
Bit data
Numeric data
Integer data
Word data
M0
SET
Y10
The 1-point Y10 is a bit device
to
b0
Word device 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0 1/0
3-2
3-2
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
(b) Word device bit designation is done by designating Word Device Bit No. .
(Designation of bit numbers is done in hexadecimal.)
For example, bit 5 (b5) of D0 is designated as D0.5, and bit 10 (b10) of D0 is designated as
D0.A.
However, there can be no bit designation for timers (T), retentive timers (ST), counters (C)
or index register (Z). (Example Z0.0 is not available)
X0
SET
D0.5
D0.5
SET
Y10
3-3
3-3
3 CONFIGURATION OF INSTRUCTIONS
XF
to
XC XB
to
MELSEC-Q/QnA
X8 X7
to
X4 X3
X0
to
K1 designation
range
(4 points)
K2 designation range
(8 points)
K3 designation range
(12 points)
K4 designation range
(16 points)
In cases where the source is a bit device designated by digit designation, and the
destination is a word device, the word device for the destination becomes 0 following
the bit designated by digit designation at the source.
Ladder Example
Processing
K1X0 X3 X2 X1 X0
X010
MOV K1X0
Become 0
D0
b15
b4 b3 b2 b1 b0
D0 0 0 0 0 0 0 0 0 0 0 0 0 X3 X2 X1 X0
Source S data
Processing
1
X010
MOV H1234
0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0
K2M0
M8 M7
M15
K2M0
Destination D
Do not change
M0
0 0 1 1 0 1 0 0
3
b8 b7
b15
4
b0
D0 1 1 1 0 1 0 1 0 1 0 0 1 1 1 0 1
X10
MOV D0
K2M100
M115
M108 M107
K2M100
Destination D
M100
1 0 0 1 1 1 0 1
Do not change
3-4
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
D0
POINTS
(1) When digit designation processing is conducted, a random value can be used
for the bit device initial device number.
(2) Digit designation cannot be made for the direct device designation DX and DY.
3-5
3-5
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
XC XB
X8 X7
X4 X3
X0
K1 designation
range
(4 points)
K2 designation range
(8 points)
K3 designation range
(12 points)
K4 designation range
(16 points)
K5 designation range
(20 points)
K6 designation range
(24 points)
K7 designation range
(28 points)
K8 designation range
(32 points)
With 32 bit
Instructions
Number of Digits
Designated
K1 (4 points)
0 to 15
K5 (20 points)
0 to 1048575
K2 (8 points)
0 to 255
K6 (24 points)
0 to 16777215
K3 (12 points)
0 to 4095
K7 (28 points)
0 to 268435455
K4 (16 points)
0 to 65535
K8 (32 points)
-2147483648 to 2147483647
In cases where the source is a bit device designated by digit designation, and the
destination is a word device, the word device for the destination becomes 0 following the bit
designated by digit designation at the source.
Ladder Example
Processing
K1X0 X3 X2 X1 X0
Become 0
X10
DMOV K1X0
D0
Souce S data
b15
b4 b3 b2 b1 b0
D0 0 0 0 0 0 0 0 0 0 0 0 0 X3 X2 X1 X0
D1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
b31
b16
Become 0
3-6
3-6
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
(c) In cases where digit designation is made at the destination D , the number of points
designated are used as the destination.
Bit devices after the number of points designated as digits do not change.
Ladder Example
Processing
H78123456
0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0
3
0 1 1 1 1 0 0 0 0 0 0 1 0 0 1 0
X10
DMOV H78123456 K5M0
Destination D
7
8
1
2
K5M0
M15
M8M7
M0
0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0
M16
M20 M19
0 0 1 0
M31
Do not change
b15
b8 b7
b0
D0 1 1 1 0 0 1 0 0 0 1 0 1 1 1 0 1
b15
b8 b7
b0
D1 0 0 1 1 0 1 0 0 1 0 0 1 0 1 1 1
X10
DMOV D0
K5M10
Destination D
M25
M18M17
M10
1 1 1 0 0 1 0 0 0 1 0 1 1 1 0 1
M41
M30M29
M26
0 1 1 1
Do not change
POINTS
(1) When digit designation processing is conducted, a random value can be used
for the bit device initial device number.
(2) Digit designation cannot be made for the direct device designation DX and DY.
(2) When using word devices
A word device designates devices used by the lower 16 bits of data.
A 32-bit instruction uses (designation device number) and (designation device number + 1).
M0
DMOV K100
D0
3-7
3-7
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
D0
REMARK
1) In sequence programs, real numbers are designated by E
Floating decimal point data uses two word devices and is expressed in the following manner:
1. [Variable part] 2 [exponent part]
The bit configuration and meaning of the internal representation of floating decimal point data is as
follows:
b31
b30
to
b23
b22
to
b16
b15
b23 to b30
Exponent part
b0
to
b0 to b22
Variable part
b31
Sign for variable part
Exponent part
b23 to b30
FFH
Nonnumeric
FEH FDH
127
Exponent part
126
81H
80H
7FH
7EH
-1
02H
01H
-125 -126
00H
Nonnumeric
POINT
The CPU module floating decimal point data can be monitored using the
monitoring function of a peripheral device.
When this is expressed as 0, all data from b0 to b31 will be 0.
-126
128
The setting range of real numbers is 0 and 2
| value | < 2 .
3-8
3-8
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
D0
D0 NULL
NULL code (00H) designation
Character string data transfer
D0
D0 42H
41H
D1 44H
43H
D2
NULL
D0
D0 42H
41H
D1 44H
43H
D2 NULL
45H
3-9
3-9
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
Z0
MOV D10Z0
D0
X0
Index modification
Example
A case where index modification has been performed, and the actual process device, would be
as follows: (When Z0 = 20 and Z1 = -5)
Ladder Example
X0
MOV K20
X1
Z0
MOV K120
MOV K-5
Z1
MOV K100Z0
W53Z1
MOV K20
Z0
W04E
Description
K100Z....K (100+20) = K120
W53.......W (53-5) = W4E
X1
Hexadecimal number
X0
X1
MOV K2X64
MOV K-5
Z1
K1M33
Description
K2X50Z....K2X (50+14) = K2X64
K20 is converted to hexadecimal
K1M38......K1M (38-5) = K1M33
X1
MOV K2X50Z0 K1M38Z1
X0
MOV K20
Z0
X1
MOV D20
MOV K-5
Z1
MOV D0Z0
K3Y12FZ1
K3Y12A
Description
D0Z.........D (0+20) = D20
K3Y12F... K3Y (12F-5) = K3Y12A
X1
Hexadecimal number
3 - 10
3 - 10
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
Meaning
32-bit constant
Floating decimal point data
Character-string data
Bit designated for word device
Function devices
Pointers used as labels
Interrupt pointers used as labels
Index register
Step relay
SFC transfer devices 1
SFC block devices 1
Value set for timer
Value set for counter
Meaning
Application Example
T0Z0
K100
T1Z1
C0Z1
K100
C1Z0
REMARKS
1)
1: SFC transfer devices and SFC block devices are devices for SFC use.
Refer to the QCPU (Q mode)/QnACPU Programming Manual (SFC) for information on
how to use these devices.
2) For timer and counter present values, there are no limits on index register numbers used.
X0
K100
T0
K4Y30
K10
C100
3 - 11
K2Y40
3 - 11
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
(c) Other
1) Bit data
Device numbers can be index modified when performing digit designation.
However, index modification is not possible by digit designation.
BIN K4X0Z2
D0
Setting that enables device
number index modification
If Z2 = 3, then X (0+3) = X3.
BIN K4Z3X0
D0
Setting that cannot enable
digit designation index
modification
2) Both I/O numbers and buffer memories can be index modified with special function
module devices.
MOV U10Z1\G0Z2 D0
If Z1 = 2 and Z2 = 8, then
U (10+2)\G (0+8) = U12\G8.
3) Both network numbers and device numbers can be index modified with link direct
devices.
MOV J1Z1\K4X0Z2 D0
If Z1 = 2 and Z2 = 8, then
J (1+2)\K4X (0+8) = J3\K4X8.
REMARKS
1)
2)
3 - 12
3 - 12
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
K1234 @D100
Reads the contents of
D100
Device area
D0
D1
D100 W100
D101 address
3 - 13
W100
1234
3 - 13
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
Device Type
Bit devices
Internal user devices
Word devices
Bit devices
Incapable
1
@D100
@D100Z2
Capable
Word devices
Example of Indirect
Designation
Incapable
1
Capable
Capable
Index register
Incapable
File register
Capable
@J1\W10
@J1Z1\W10Z2
@U10\G0
@U10Z1\G0Z2
2
2
@R0, @ZR20000
@R0Z1, @ZR20000Z1
Nesting
Pointer
Constants
Incapable
Other
REMARKS
1)
2)
3)
(3) Cautions
The address for indirect designation is designated using two words.
Therefore, to substitute indirect designation for index modification, the addition/subtraction of
32-bit data is required.
The following is the ladder used for the addition/subtraction of the address of the device stored
in D1 and D0 for indirect designation.
[To add "1" to the address of the device for indirect designation]
DINCP
D0
Device used for indirect designation
32-bit instruction
[To subtract "1" from the address of the device for indirect designation]
DDECP
D0
Device used for indirect designation
32-bit instruction
3 - 14
3 - 14
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
Condition
Designates a bit device number in a factor of 16
Only K4 can be designated for digit designation
Does not conduct index modification
Internal device (File register ZR is not included)
No limitations
Bit device
Word device
Constants
Condition
Designates a bit device number in a factor of 32
Only K8 can be designated for digit designation
Does not conduct index modification
Internal device (File register ZR is not included)
No limitations
Bit device
Word device
Constants
Instruction Symbols
Comparison instructions
Basic arithmetic operations
(addition, subtraction,
multiplication, and division)
Data conversion instructions
=, < >, <, <=, >, >=, D=, D< >, D<, D<=, D>, D>=
+, -, , /, INC, DEC, D+, D-, D , D/, DINC, DDEC
B+, B-, B , B/
REMARK
1)
: It is only QCPU that can use three devices to conduct subset processing of the logic
operation instructions WAND, DAND, WOR, DOR, WXOR, DXOR, WXNR, or DXNR.
WAND
3 - 15
WAND
S1
S2
3 - 15
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
POINT
(1) When a file register setting has been made but no memory card has been
installed, or when no file register setting has been made, no error will be
returned even if an attempt is made to write to the file register.
However, "FFFFH" will be stored if an attempt is made to read from the file
register at which this write operation was attempted.
(1) Device range check
Device range checks for the devices used by basic instructions and application instructions in
CPU module are as indicated below:
(a) No device range check is made for instructions dealing with fixed-length devices (MOV,
DMOV, etc.).
In cases where the corresponding device range is exceeded, data is written to other
devices.
For example, in a case where the data register has been allocated 12 k points, there will be
no error even if it exceeds D12287.
DMOV K100
D12287
Device range checks are not conducted also in cases where index modification is being
performed.
(b) Device range checks are conducted for instructions dealing with variable-length devices
(BMOV, FMOV, and others which designate transfer numbers).
In cases where the corresponding device range has been exceeded, an operation error will
be returned.
For example, in a case where the data register has been allocated 12 k points, there will be
an error if it exceeds D12287.
BMOV K100 D12287
K2
REMARK
1)
3 - 16
: See section 3.4 (3) for the internal user device allocation order.
3 - 16
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
Device range checks are also conducted when index modification is performed.
However, if index modification has been conducted, there will be no error returned if the
initial device number exceeds the relevant device range.
MOV K2
Z1
(c) Because all character string data is of variable length, device range checks are performed.
In cases where the corresponding device range has been exceeded, an operation error will
be returned.
For example, in a case where the data register has been allocated 12 k points, there will be
an error if it exceeds D12287.
$MOV "ABC"
D12287
D12287 and D12288 have been indicated here, but because
D12288 does not exist, an operation error is returned.
Note that an operation error does not occur even if the head device number exceeds the
device range as the result of index modification.
(d) Device range checks are conducted when index modification is performed by direct access
output (DY).
(2) Device data check
Device data checks for the devices used by basic instructions and application instructions in
CPU module are as indicated below:
(a) When using BIN data
No error is returned even if the operation results in overflow or underflow.
The carry flag does not go on at such times, either.
(b) When using BCD data
1) Each digit is check for BCD value (0/ to 9).
An operation error is returned if individual digits are outside the 0 to 9 (A to F) range.
2) No error is returned even if the operation results in overflow or underflow.
The carry flag does not go on at such times, either.
(c) When using floating decimal point data
Operation errors are returned in the following cases:
When value of floating decimal point data is 0
When the absolute value of the floating decimal point data is 1.0 2-127 or lower
When absolute value of floating decimal point data is 1.0 2128 or higher
(d) When using character string data
No data check is conducted.
3 - 17
3 - 17
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
(3) If internal user device allocation is changed by parameter device allocation, such allocations
are made in the device order indicated below:
If the allocation of the device used is less than 28.75 k words, the area following the device
used will be empty.
Initial address
(fixed)
SM
SD
X
Y
M
L
B
F
SB
V
S
T contact and coil
ST contact and coil
C contact and coil
Present value of T
Present value of ST
Present value of C
D
W
SW
Empty area
File register
(32 k points)
REMARK
1) Refer to the User's Manual (Functions Explanation, Programming Fundamentals) of the used
CPU module or the QnACPU Programming Manual (Fundamentals), for how to change the
internal user device allocation.
3 - 18
3 - 18
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
Instruction name
Instruction name + P
Execution at ON and execution at leading edge for the MOV instruction are designated as follow:
MOV
K4X0
D0
Execution at ON
MOVP K4X0
D0
Execution at leading edge
3 - 19
3 - 19
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
D0
R0
D0
R0
D10
4 steps
Added Steps
Example
MOV U4\G10 D0
1
MOV J3\B20 D0
MOV ZR123 D0
DMOV K123 D0
EMOV E0.1 D0
$MOV "123" D0
(c) In cases where the conditions described in (a) and (b) above overlap, the number of steps
becomes a culmination of the two.
For example, if MOV U1\G10 ZR123 has been designated, 1 step is added for buffer
register designation and 1 step is added for serial number access file register designation,
making a total of 2 steps added.
3 - 20
3 - 20
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
[Circuit]
X0
M0
X1
M0
[Timing Chart]
X0
X0
M0
M0
X1
X1
M0
M0
END
END
END
ON
X0
OFF
ON
X1
OFF
ON
M0
OFF
M0 turns ON because
X1 is ON.
M0 remains OFF because X0 is OFF.
With the refresh type CPU module, when the output (Y) is specified by the OUT instruction, the
ON/OFF status of the last OUT instruction of the scan will be output.
3 - 21
3 - 21
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
[Circuit]
X0
SET M0
X1
RST M0
[Timing Chart]
X0
X0
SET M0
X1
RST M0
END
END
X0
OFF
X1
OFF
M0
OFF
SET M0
X1
RST M0
END
ON
ON
M0 turns OFF
RST M0 remains the same (ON)
because X1 is ON.
because X1 is OFF.
SET M0 remains the same (ON)
M0 turns ON because X0 is ON.
because X0 is OFF.
3 - 22
3 - 22
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
[Circuit]
X0
PLS M0
X1
PLS M0
[Timing Chart]
The ON/OFF timing of the X0 and X1 is different. (The specified device does not turn ON
throughout the scan.)
X0
X0
PLS M0
PLS M0
X1
X1
PLS M0
X0
OFF
X1
OFF
M0
OFF
PLS M0
END
END
END
ON
ON
ON
X0
PLS M0
X1
PLS M0
END
END
X0
OFF
X1
OFF
M0
OFF
PLS M0
X1
PLS M0
END
ON
ON
3 - 23
3 - 23
3 CONFIGURATION OF INSTRUCTIONS
MELSEC-Q/QnA
[Circuit]
X0
PLF M0
X1
PLF M0
[Timing Chart]
The ON/OFF timing of the X0 and X1 is different. (The specified device does not turn ON
throughout the scan.)
X0
X0
PLF M0
PLF M0
X1
PLF M0
END
X1
PLF M0
END
END
OFF
X0
ON
X1
OFF
ON
M0 OFF
M0 turns OFF because X1
M0 turns OFF because X1 is
turns OFF from ON.
not turning OFF from ON.
(M0 stays OFF.)
M0 turns ON because X0
M0 turns OFF because X0 is not turning
turns OFF from ON.
OFF from ON. (M0 stays OFF.)
X0
PLF M0
X1
PLF M0
END
END
X0
PLF M0
X1
PLF M0
END
OFF
ON
X1
OFF
ON
M0 OFF
M0 turns OFF because X1
is not turning OFF from ON.
(M0 stays OFF.)
M0 turns OFF because X0 is not turning
OFF from ON.
3 - 24
3 - 24
MELSEC-Q/QnA
1
8
2
5
6
1
2
3
Device Type
Usable
devices
X, Y, M, L,
SM, F, V, B,
SB, FX, FY
2
T, ST, C, 5
D, W, SD,
SW, FD,
@
MELSECNET/10(H) 3
Direct J \
Bit
Word
File Register
R, ZR
J
J
J
J
\X
\Y
\B
\SB
J
J
\W
\SW
Special
Function
Module
U \G
\G
Index
Register
Zn
Constant
1
Decimal
constants
Hexadecimal
constants
Real number
constant
Character
string constant
Other
P, I, J, U,
DX, DY, N,
BL, TR,
BL\S, V
1: Devices which can be set are recorded in the "Constant" and the "Other" columns.
2: FX and FY can be used only for bit data, and FD only for word data.
3: Usable with the MELSECNET/H, and MELSECNET/10.
4-1
4-1
MELSEC-Q/QnA
7
9
4: Refer to the User's Manual (Functions Explanation, Programming Fundamentals) of the used CPU
or QnA Programming Manual for details of each device.
5: When T, ST and C are used for other than the instructions below, only word data can be used.
(Bit data cannot be used .)
[Instructions that can be used with bit data]
LD, LDI, AND, ANI, OR, ORI, LDP, LDF, ANDP, ANDF, ORP, ORF, OUT, RST
4
Execution
Condition
Non-conditional
Execution
Code recorded on
description page
No symbol
recorded
4-2
Executed while ON
Executed One
Time at ON
Executed while
OFF
Executed One
Time at OFF
4-2
Discusses the data set for each instruction and the data type.
Data Type
Bit
BIN 16 bits
BIN 32 bits
BCD 4 digits
BCD 8 digits
Real number
Character string
Device name
6
7
4-3
MELSEC-Q/QnA
Meaning
Bit data or first number in bit data
BIN 16-bit data or first number in word device
BIN 32-bit data or first number in double word device
4-digit BCD data
8-digit BCD data
Floating decimal point data
Character string data
Device name data
4-3
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
5. SEQUENCE INSTRUCTIONS
Sequence instructions include instructions for relay control ladders and the like. They are divided
into the following categories:
Instruction
Contact instruction
Connection Instruction
Meaning
Operation start, series connection, parallel connection
Ladder block connection, creation of pulses from operation
results, store/read operation results
Reference
Chapter 5.1
Chapter 5.2
Output instruction
Chapter 5.3
Shift instruction
Chapter 5.4
Chapter 5.5
Termination instruction
Chapter 5.6
Other instructions
Program termination
Program stop, instructions such as no operation which do not fit
in the above categories
Chapter 5.7
5-1
5-1
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performanc e
Process CPU
QnA
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
MELSECNET/10(H)
Special
Direct J \
Function
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
DX, BL
X1/D0.1
LDI
X2/D0.2
AND
X2/D0.2
ANI
OR
X3/D0.3
ORI
X3/D0.3
[Set Data]
Set Data
S
Meaning
Devices used as connections
Data Type
Bit
[Functions]
LD, LDI
(1) LD is the A contact operation start instruction, and LDI is the B contact operation start
instruction. They read ON/OFF information from the designated device (if a word device bit
has been designated, this becomes the 1/0 status of the designated bit), and use that as an
operation result.
5-2
5-2
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
AND, ANI
(1) AND is the A contact series connection instruction, and ANI is the B contact series connection
instruction. They read the ON/OFF data of the designated bit device (if a bit designation has
been made for a word device, the 1/0 status of the designated bit is read), perform an AND
operation on that data and the operation result to that point, and take this value as the
operation result.
(2) There are no restrictions on the use of AND or ANI, but the following applies with a peripheral
device used in the ladder mode:
(a) Write............When AND and ANI are connected in series, a ladder with up to 21 stages
can be generated.
(b) Read ...........When AND and ANI are connected in series, a ladder with up to 24 stages
can be displayed.
If the number exceeds 24 stages, up to 24 will be displayed.
OR, ORI
(1) OR is the A contact single parallel connection instruction, and ORI is the B contact single
parallel connection instruction. They read ON/OFF information from the designated device (if a
word device bit has been designated, this becomes the 1/0 status of the designated bit), and
perform an OR operation with the operation results to that point, and use the resulting value as
the operation result.
(2) There are no limits on the use of OR or ORI, but the following applies with a peripheral device
used in the ladder mode.
(a) Write ................OR and ORI can be used to create connections of up to 23 ladders.
(b) Read................Up to 23 ladders connected with OR or ORI can be displayed.
The 24th or subsequent ladders cannot be displayed properly.
REMARK
Word device bit designations are made in hexadecimal
Bit b11 of D0 would be D0.0B.
See Section 3.2.1 for more information on word device bit designation.
5-3
5-3
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors with LD, LDI, AND, ANI, OR, or ORI instructions.
[Program Example]
(1) A program using LD, AND, OR, and ORI instructions.
[Ladder Mode]
[List Mode]
Steps
b15
D0
b5
1
Instruction
b0
Device
Word
device bit
designation
(2) A program linking contact points established through the use of ANB and ORB instructions.
[Ladder Mode]
b15
D6
[List Mode]
b4
1
Steps
b1b0
1
Instruction
Device
Word
device bit
designation
ORB
ANB
[List Mode]
Steps
5-4
Instruction
Device
5-4
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
5.1.2 Pulse operation start, pulse series connection, pulse parallel connection
(LDP, LDF, ANDP, ANDF, ORP, ORF)
Set
Data
Internal Devices
(System, User)
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
DX
LDP
X1/D0.1
LDF
X2/D0.2
ANDP
X2/D0.2
ANDF
ORD
X3/D0.3
ORF
X3/D0.3
[Set Data]
Set Data
Meaning
Data Type
Bit
[Functions]
LDP, LDF
(1) LDP is the leading edge pulse operation start instruction, and is ON only at the leading edge of
the designated bit device (when it goes from OFF to ON).
If a word device has been designated, it is ON only when the designated bit changes from 0 to
1.
In cases where there is only an LDP instruction, it acts identically to instructions for the
P).
creation of a pulse that are executed during ON(
A ladder using an LDP instruction
X0
MOV
K0
D0
X0
X0
M0
5-5
PLS
M0
5-5
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
(2) LDF is the trailing edge pulse operation start instruction, and is ON only at the trailing edge of
the designated bit device (when it goes from ON to OFF).
If a word device has been designated, it is ON only when the designated bit changes from 1 to
0.
ANDP, ANDF
(1) ANDP is a leading edge pulse series connection instruction, and ANDF is a trailing edge pulse
series connection instruction. They perform an AND operation with the operation result to that
point, and take the resulting value as the operation result.
The ON/OFF data used by ANDP and ANDF are indicated in the table below:
Devices Designated by ANDP
Word Device Bit
Bit Device
Designation
OFF
ON
OFF
ON
ON
OFF
ANDP State
ON
OFF
ON
OFF
0
ON
ON
OFF
ANDF State
OFF
0
ON
ORP, ORF
(1) ORP is a leading edge pulse parallel connection instruction, and ORF is a trailing edge pulse
parallel connection instruction. They perform an OR operation with the operation result to that
point, and take the resulting value as the operation result.
Devices Designated by ORP
Word Device Bit
Bit Device
Designation
OFF
ON
OFF
ON
ON
OFF
ORP State
ON
OFF
ON
OFF
0
ON
ON
OFF
ORF State
OFF
0
ON
[Operation Errors]
(1) There are no operation errors with LDP, LDF, ANDP, ANDF, ORP, or ORF instructions.
[Program Example]
(1) The following program executes the MOV instruction at input X0, or at the leading edge of b10
(bit 10) of data register D0:
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
REMARK
: Word device bit designations are performed in hexadecimal.
Bit b10 of D0 would be D0.0A.
5-6
5-6
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
Block A
Block B
Block A
ORB
ORB
Block B
[Functions]
ANB
(1) Performs an AND operation on block A and block B, and takes the resulting value as the
operation result.
(2) The symbol for ANB is not the contact symbol, but rather is the connection symbol.
(3) When programming in the list mode, up to 15 ANB instructions (16 blocks) can be written
consecutively.
ORB
(1) Conducts an OR operation on Block A and Block B, and takes the resulting value as the
operation result.
5-7
5-7
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
(2) ORB is used to perform parallel connections for ladder blocks with two or more contacts.
For ladder blocks with only one contact, use OR or ORI; there is no need for ORB in such
cases.
[Ladder Mode]
X0
[List Mode]
X1
Y10
0
X2
X3
X4
0
1
2
3
4
5
6
LD
AND
LD
AND
ORB
OR
OUT
X0
X1
X2
X3
X4
X10
(3) The ORB symbol is not the contact symbol, but rather is the connection symbol.
(4) When programming in the list mode, it is possible to use up to 15 ORB instructions
successively (16 blocks).
[Operation Errors]
(1) There are no operation errors associated with ANB or ORB instructions.
[Program Example]
(1) A program using ANB and ORB instructions
[Ladder Mode]
[List Mode]
Steps
5-8
Instruction
Device
5-8
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
MPS
MRD
MPP
[Functions]
MPS
(1) Stores in memory the operation result (ON or OFF) immediately prior to the MPS instruction.
(2) Up to 16 MPS instructions can be used successively.
However, only up to 11 can be created in the ladder mode.
If an MPP instruction is used during this process, the number of uses calculated for the MPS
instruction will be decremented by one.
MRD
(1) Reads the operation result stored for the MPS instruction, and uses that result to perform the
operation in the next step.
MPP
(1) Reads the operation result stored for the MPS instruction, and uses that result to perform the
operation in the next step.
(2) Clears the operation results stored by the MPS instruction.
(3) Subtracts 1 from the number of MPS instruction times of use.
5-9
5-9
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
POINTS
(1) The following shows ladders both using and not using the MPS, MRD, and MPP
instructions.
Ladder Using the MPS, MRD and MPP Instruction.
X0
X1
X2
X1
X2
Y10
X3
Y10
X0
X4
X1
X3
Y11
X5
Y11
X0
Y12
X4
X1
X5
Y12
(2) The MPS and MPP instructions must be used the same number of times.
Failure to observe this will not correctly display the ladder in the ladder mode of the
peripheral device.
5 - 10
5 - 10
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no errors associated with the MPS, MRD, or MPP instructions.
[Program Example]
(1) A program using the MPS, MRD, and MPP instructions.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
1
2
2
3
4
3
4
5
6
6
7
7
8
9
10
10
5 - 11
5 - 11
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[List Mode]
Steps
5 - 12
Instruction
Device
5 - 12
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
U
[Functions]
Inverts the operation result immediately prior to the INV instruction.
Operation Result Immediately
OFF
ON
ON
OFF
[Operation Errors]
(1) There are no operation errors associated with the INV instruction.
[Program Example]
(1) A program which inverts the X0 ON/OFF data, and outputs from Y10
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
[Timing Chart]
ON
X0
Y10
OFF
ON
OFF
POINTS
(1) The INV instruction operates based on the results of calculation made until the INV
instruction is given. Accordingly, use it in the same position as that of the AND instruction.
The INV instruction cannot be used at the LD and OR positions.
5 - 13
5 - 13
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
U
MEF
[Functions]
MEP
(1) If operation results up to MEP instruction are leading edge (from OFF to ON), goes ON
(continuity status).
If operation results up to MEP instruction are anything other than leading edge, goes OFF
(non-continuity status).
(2) Use of the MEP instruction simplifies pulse conversion processing when multiple contacts are
connected in series.
MEF
(1) If operation results up to MEF instruction are trailing edge (from ON to OFF), goes ON
(continuity status).
If operation results up to MEF instruction are anything other than trailing edge, goes OFF (noncontinuity status).
(2) Use of the MEF instruction simplifies pulse conversion processing when multiple contacts are
connected in series.
[Operation Errors]
(1) There are no operation errors associated with the MEP or MEF instructions.
[Program Example]
(1) A program which performs pulse conversion on the operation results of X0 and X1:
[Ladder Mode]
[List Mode]
Steps
5 - 14
Instruction
Device
5 - 14
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
POINTS
(1) The MEP and MEF instructions will occasionally not function properly when pulse
conversion is conducted for a contact that has been indexed by a sub-routine program or
by the FOR to NEXT instructions.
If pulse conversion is to be conducted for a contact that has been indexed by a sub-routine
program or by the FOR to NEXT instructions, use the EGP/EGF instructions.
(2) Because the MEP and MEF instructions operate with the operation results immediately
prior to the MEP and MEF instructions, the AND instruction should be used at the same
position.
The MEP and MEF instructions cannot be used at the LD or OR position.
5 - 15
5 - 15
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
V
Command
EGP
EGF
[Set Data]
Set Data
D
Meaning
Edge relay number where operation results are stored
Data Type
Bit
[Functions]
EGP
(1) Operation results up to the EGP instruction are stored in memory by the edge relay (V).
(2) Goes ON (continuity status) at the leading edge (OFF to ON) of the operation result up to the
EGP instruction.
If the operation result up to the EGP instruction is other than a leading edge (i.e., from ON to
ON, ON to OFF, or OFF to OFF), it goes OFF (non-continuity status).
(3) The EGP instruction is used for sub-routine programs, and for conducting pulse operations for
programs designated by index modification between FOR and NEXT instructions.
(4) The EGP instruction can be used like an AND instruction.
EGF
(1) Operation results up to the EGF instruction are stored in memory by the edge relay (V).
(2) Goes ON at the trailing edge (from ON to OFF) of the operation result up to the EGF
instruction.
If the operation result up to the EGF instruction is other than a trailing edge (i.e., from OFF to
ON, ON to ON, or OFF to OFF), it goes OFF (non-continuity status).
(3) The EGF instruction is used for sub-routine programs, and for conducting pulse operations for
programs designated by index modification between FOR and NEXT instructions.
(4) The EGF instruction can be used like an AND instruction.
5 - 16
5 - 16
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the EGP or EGF instructions.
[Program Example]
(1) A program containing a subroutine program using an EGP instruction
[Ladder Mode]
[List Mode]
Device
Instruction
Steps
1
[Operation]
END processing
ON
ON
OFF
X0 OFF
ON
X1 OFF
ON
ON
V0 OFF
Turns ON when X0
ON
turns from OFF to ON.
V1 OFF
D0
2
1
D1
POINTS
(1) Since EGP and EGF instructions are executed according to the results of operation
performed immediately before the EGP/EGF instruction, these instructions must be used in
the same position as the AND instruction (refer to 5.1.1.).
An EGP and EGF instruction cannot be used at the position of an LD or OR instruction.
(2) EGP and EGF instructions cannot be used at the circuit block positions shown below.
X0
X1 V0Z0
X0 V0Z0
SET M0
X2
5 - 17
X1
SET M0
X2
5 - 17
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
D
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Other
Constant
K, H
DY
(Other
than T, C, or F)
OUT
Bit designation of
word device D
D0.5
[Set Data]
Set Data
D
Meaning
Data Type
Bit
[Functions]
(1) Operation results up to the OUT instruction are output to the designated device.
Results
Operation
Coil
Contact
A Contact
B Contact
Bit Designated
OFF
OFF
Non-continuity
Continuity
ON
ON
Continuity
Non-continuity
[Operation Errors]
(1) See Section 3.6 for information regarding errors during index modification.
5 - 18
5 - 18
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
(1) When bit device is in use
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) When bit designation has been made for word device
[Ladder Mode]
[List Mode]
Steps
b15
b7 b6 b5
Instruction
Device
b0
D0
REMARK
The number of basic steps for OUT instructions is as follows:
When using internal device or file register (R)
:1
When using direct access output (DY)
:2
When using any other device
:3
(Including serial number access file register)
5 - 19
5 - 19
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K
Other
(Only T)
Set
value
(Other
than T,C)
Set value
Settings from 1 to 32767
are valid
D10
Set value
Contents of data register
settings from 1 to 32767
are valid
Set value
Settings from 1 to 32767
are valid
T0
OUT T
(Low speed timer)
T0
H K50
T0
OUTH T
(High speed timer)
H D10
T0
K50
ST0
OUT ST
(Low speed retentive timer)
D10
ST0
H K50
ST0
OUTH ST
(High speed retentive timer)
H D10
ST0
Set value
Contents of data register
settings from 1 to 32767
are valid
Set value
Settings from 1 to 32767
are valid
Set value
Contents of data register
settings from 1 to 32767
are valid
Set value
Settings from 1 to 32767
are valid
Set value
Contents of data register
settings from 1 to 32767
are valid
REMARK
1: Timer values can be set only as a decimal constant (K).
Hexadecimal constants (H) and real numbers cannot be used for timer settings.
2: The file register cannot be used in the Q00JCPU.
5 - 20
5 - 20
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Set Data]
Set Data
D
Set value
Meaning
Data Type
Timer number
Value set for timer
Bit
BIN 16 bits
POINT
3: The value setting for the timer cannot be designated indirectly.
Indirect designation not possible
@ D0
T0
[Functions]
(1) When the operation results up to the OUT instruction are ON, the timer coil goes ON and the
timer counts up to the value that has been set; when the time up status (total numeric value is
equal to or greater than the setting value), the contact responds as follows:
A contact
Continuity
B contact
Non-continuity
(2) The contact responds as follows when the operation result up to the OUT instruction is a
change from ON to OFF:
Type of Timer
Low speed timer
High speed timer
Low speed retentive timer
High speed retentive timer
Timer Coil
Present
Value of
Timer
OFF
OFF
Prior to Time Up
After Time Up
A Contact
B Contact
A Contact
B Contact
Noncontinuity
Continuity
Noncontinuity
Continuity
Maintains
the present
value
Noncontinuity
Continuity
Continuity
Noncontinuity
The present value is cleared from low speed retentive timers and high speed retentive timers, and the
contact is reset, by use of the RST instruction.
(3) To clear the present value of a retentive timer and turn the contact OFF after time up, use the
RST instruction.
(4) A negative number (-32768 to -1) cannot be set as the setting value for the timer.
If the setting value is 0, the timer will time out when the time the OUT instruction is executed.
(5) The following processing is conducted when the OUT instruction is executed:
OUT T coil turned ON or OFF
OUT T contact turned ON or OFF
OUT T present value updated
In cases where a JMP instruction or the like is used to jump to an OUT T instruction while
the OUT T instruction is ON, no present value update or contact ON/OFF operation is
conducted. Also, if the same OUT T instruction is conducted two or more times during the
same scan, the present value of the number of repetitions executed will be updated.
(6) Index modification for timer coils or contacts can be conducted only by Z0 or Z1.
Index modification cannot be conducted for the set value for the timer.
5 - 21
5 - 21
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
REMARKS
(1) The default value for the low speed timer and low speed retentive timer time limit is 100 ms.
The time limit for the low speed timer and low speed retentive timer can be set in the
parameter mode "PLC system settings" area in increments of 10 ms between the limits of
10 ms to 1 second.
(2) The default value for time limits for the high speed timer and the high speed retentive timer
is 10 ms.
The time limits for the high speed timer and the high speed retentive timer can be set in the
parameter mode "PLC system settings" area in increments of 1 ms between the limits of 10
ms and 100 ms.
(3) Refer to the User's Manual (Functions Explanation, Programming Fundamentals) of the
used CPU module or QnACPU Programming Manual (Fundamentals) for information on
timer counting methods.
[Cautions]
(1) When creating a program in which the operation of the timer contacttriggers the operation of
other timer, create the program according to the operation order of the timers - create the
program for the timer that operates later first.
In the following cases, all timers go ON at the same scan if the program is created in the order
the timers operate,
If the set value is smaller than a scan time.
If "1" is set.
Example
For timers T0 to T2, the program is created in the order the timer operates later.
T1
T0
X0
K1
T2
K1
T1
K1
T0
T2 timer starts counting from the next scan after the timer
T1 contact is turned ON.
T1 timer starts counting from the next scan after the timer
T0 contact is turned ON.
T0 timer starts counting if X0 is turned ON.
For timers T0 to T2, the program is created in the order of timer operation.
X0
K1
T0
T0
K1
T1
T1
K1
T2
[Operation Errors]
(1) There are no operation errors associated with the OUT T
5 - 22
instruction.
5 - 22
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
(1) The following program turns Y10 and Y14 ON 10 seconds after X0 has gone ON.
[Ladder Mode]
[List Mode]
1
Instruction
Steps
Device
(2) The following program uses the BCD data at X10 to 1F as the timer's set value.
[Ladder Mode]
Converts BCD data at X10 to 1F to BIN
and stores at D10
When X2 goes ON, the data stored at
D10 is calculated as the set value.
Y15 goes ON when T2 counts out.
[List Mode]
Steps
Instruction
Device
(3) The following program turns Y10 ON 250 m after X0 goes ON.
[Ladder Mode]
[List Mode]
2
Steps
Instruction
Device
REMARKS
(1) 1: The set value of the low speed timer indicates its default time limit (100 ms).
(2) 2: The set value of the high speed timer indicates its default time limit (10 ms)
(3) The number of basic steps of the OUT T instruction is 4.
5 - 23
5 - 23
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Bit
D
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K
Other
U
(Only C)
Set
value
(Other
than T,C)
Set value
Settings from 1 to 32767
are valid
D10
Set value
Contents of data register
settings from 1 to 32767
are valid
C0
OUT C
C1
[Set Data]
Set Data
D
Set value
Meaning
Data Type
Counter number
Counter set value
Bit
BIN 16 bits
[Functions]
(1) When the operation results up to the OUT instruction change from OFF to ON, 1 is added to
the present value (count value) and the count up status (present value = set value), and the
contacts respond as follows:
A contact
Continuity
B contact
Non-continuity
POINT
2: Counter value cannot be set by indirect designation.
@ D0
C0
REMARKS
Refer to the User's Manual (Functions Explanation, Programming Fundamentals) of the used
CPU module or QnACPU Programming Manual (Fundamentals) for counter counting methods.
1: Counter value can be set only with a decimal constant (K).
A hexadecimal constant (H) or a real number cannot be used for the counter value setting.
3: The file register cannot be used in the Q00JCPU.
5 - 24
5 - 24
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the OUT C
instruction.
[Program Example]
(1) The following program turns Y30 ON after X0 has gone ON 10 times, and resets the counter
when X1 goes ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program sets the value for C10 at 10 when X0 goes ON, and at 20 when X1 goes ON.
[Ladder Mode]
Stores 10 at D0 when X0 goes ON
Stores 20 at D0 when X1 goes ON
C10 takes data stored at D0 as set
value, and counts
Y30 goes ON when C10 reaches count
out state
[List Mode]
Steps
Instruction
Device
REMARK
The number of basic steps of the OUT C
5 - 25
instruction is 4.
5 - 25
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
(Only F)
F35
[Set Data]
Set Data
D
Meaning
Number of annunciator to be turned ON
Data Type
Bit
[Functions]
(1) Operation results up to the OUT instruction are output to the designated annunciator.
(2) The following responses occur when an annunciator (F) is turned ON.
[With Q3A, Q4A, or Q4ARCPU]
The annunciator number is displayed at the LED display device on the front of the CPU
module, and the "USER" LED goes ON.
The annunciator numbers which are ON (F numbers) are stored in special registers (SD64 to
SD79).
The value of SD63 is incremented by 1.
[With CPUs other than above]
The "USER" LED goes ON.
The annunciator numbers which are ON (F numbers) are stored in special registers (SD64 to
SD79).
The value of SD63 is incremented by 1.
(3) If the value of SD63 is 16 (which happens when 16 annunciators are already ON), even if a
new annunciator is turned ON, its number will not be stored at SD64 to SD79.
5 - 26
5 - 26
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
(4) The following responses occur when the annunciator is turned OFF by the OUT instruction.
[With Q3A, Q4A, or Q4ARCPU]
The coil goes OFF, but there are no changes in the LED display device on the front of the
CPU module, the status of the "USER" LED, and the contents of the values stored in SD63
to SD79.
Use the RST F instruction to turn OFF the LED display device on the front of the CPU
module and "USER" LED, and to delete the annunciator which was turned OFF by the OUT
F instruction from SD63 to SD79.
[With CPUs other than above]
The coil goes OFF, but there are no changes in the status of the "USER" / "ERR." LED and
the contents of the values stored in SD63 to SD79.
Use the RST F instruction to turn OFF the "USER" / "ERR." LED and to delete the
annunciator which was turned OFF by the OUT F instruction from SD63 to SD79.
[Operation Errors]
(1) There are no operation errors associated with the OUT F
instruction.
REMARKS
(1) Refer to User's Manual (Functions Explanation, Programming Fundamentals) of the used
CPU module or QnACPU Programming Manual (Fundamentals) for details of annunciators
(2) The number of basic steps for the OUT module F instruction is 4.
(3) The table below shows which CPU module features either the LED display device on front of
the CPU module or "USER" LED
Type of LED
"USER" LED
"ERR." LED
[Program Example]
(1) The following program turns F7 ON when X0 goes ON, and stores the value 7 from SD64 to
SD79.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
X0 ON
5 - 27
SD63
SD64
SD65
SD66
SD67
0
0
0
0
0
SD79
Adds 1
SD63
SD64
SD65
SD66
SD67
1
7
0
0
0
SD79
5 - 27
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
SET
Other
BL
DY
[Set Data]
Set Data
D
Meaning
Data Type
Bit
[Functions]
(1) When SET input is ON, the designated devices respond as follows:
Device
Bit device
When bit designation has been made for word
device
Device Status
Coils and contacts turned ON
Designation bit set at 1
(2) Devices turned ON will stay ON even if SET input goes to OFF.
Devices turned ON by the SET instruction can be turned OFF by the RST instruction.
ON
SET input
X5
SET
Y10
X5 OFF
ON
X7
RST
RST input
Y10
X7 OFF
ON
Y10 OFF
(3) Device status does not change when SET input is OFF.
5 - 28
5 - 28
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the SET instruction.
[Program Example]
(1) The following program sets Y8B (ON) when X8 goes ON, and resets Y8B (OFF) when X9
goes ON.
[Ladder Mode]
[List Mode]
Instruction
Steps
Device
(2) The following program sets the value of D0 bit 5 (b5) to 1 when X8 goes ON, and set the bit
value to 0 when X9 goes ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
Sets value of b5 of D0 at 1
Sets value of
b5 of D0 at 0
b5
b0
D0
REMARK
The basic SET instructions are as follows:
When internal device or file register (R0 to R32767) are in use
When direct access output (DY) or SFC program device (BL) are in use
When timer (T) or counter (C) are in use
When some other device is in use
5 - 29
: Step 1
: Step 2
: Step 4
: Step 3
5 - 29
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
BL
DY
RST
[Set Data]
Set Data
Meaning
Data Type
Bit
BIN 16 bits
[Functions]
(1) Designated devices respond as follows when RST input is turned ON:
Device
Device Status
Turns coils and contacts OFF
Sets the present value to 0, and turns coils and contacts
OFF
Bit device
Timers and counters
When bit designation has been made for word
device
Word devices other than timers and counters
(2) Device status does not change when RST input goes OFF.
(3) The functions of the word devices designated by the RST instruction are identical to the
following ladder:
X10
RST input
RST input
X10
RST
D50
MOV
K0
Device No.
D50
Device No.
[Operation Errors]
(1) There are no operation errors associated with the RST instruction.
REMARK
1) The basic number of steps of the RST instruction is as follows.
a) For bit processing
Internal device (bit to be specified by bit device or word device)
Direct output
Timer, counter
Other than above
5 - 30
:1
:2
:4
:3
5 - 30
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
:2
:2
:3
[Program Example]
(1) The following program sets the value of the data register to 0.
[Ladder Mode]
When X0 goes ON, the contents of X10
to 1F are stored at D8
When X5 goes ON, the value of D8 is
set to 0
[List Mode]
Steps
Instruction
Device
(2) The following program resets the 100 ms retentive timer and counter.
[Ladder Mode]
When T225 is set at the retentive timer,
the ON time for X4 is 30 minutes, then
T225 goes ON.
Counts the number of times T225 goes ON.
When the T225 contact goes ON, the T225
coil, contact, and present value are reset.
When C23 reaches the count out state,
Y55 goes ON.
Resets C23 when X5 goes ON.
[List Mode]
Steps
5 - 31
Instruction
Device
5 - 31
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
D
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
U
(Only F)
SET
RST
RST input
RST
[Set Data]
Instruction Name
SET
RST
Set Data
Meaning
Number of annunciator to be set (F number)
Number of annunciator to be reset (F number)
D
D
Data Type
Bit
[Functions]
SET
(1) Annunciator designated by
(2) The following responses occur when the annunciator (F) goes ON:
The annunciator number is displayed at the LED display device at the front of the CPU
module, or the "USER" LED goes ON.
The numbers (F numbers) of the annunciators turned ON are stored successively at the
special registers (SD63 to SD79).
The value of SD63 is incremented by 1.
(3) If the value of SD63 is 16 (which happens when 16 annunciators are already ON), even if a
new annunciator is turned ON, its number will not be stored at SD64 to SD79.
RST
(1) Annunciators designated by
(2) The annunciator numbers (F numbers) of annunciators that have gone OFF are deleted from
the special registers (SD64 to SD79), and the value of SD63 is decremented by 1.
REMARK
(1) Refer to the User's Manual (Functions Explanation, Programming Fundamentals) of the
used CPU module or QnACPU Programming Manual (Fundamentals), Section 4.2.5, for
details of annunciators.
5 - 32
5 - 32
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
(2) The table below shows which CPU module features either the LED display device on front of
the CPU module or "USER" LED
Type of LED
LED display device
"USER LED"
(3) If, when the value of SD63 is 16, and annunciator numbers are deleted from SD64 to SD79 by
use of the RST instruction, annunciators whose numbers are not registered in SD64 to SD79
are then turned ON, the numbers of these annunciators will be registered. If all annunciator
numbers from SD64 to SD79 are turned OFF, the LED display device on the front of the CPU
module, or the "USER" LED, will be turned OFF.
[Operations which take place when SD63 is 16]
F30 turned ON
SD63
SD64
SD65
SD66
16
233
90
700
SD64
SD65
SD66
SD78 145
SD79 1027
F90 is reset
16
233
90
700
SD64
SD65
SD66
16
233
700
28
The SD67
F number
is stored
SD77 145
SD78 1027
30
SD79
SD78 145
SD79 1027
The contents of SD63
and SD64 to
SD79 are not changed.
[Operation Errors]
(1) There are no operation errors associated with the SET F
or RST F
instructions.
[Program Example]
(1) The following program turns annunciator F11 ON when X1 goes ON, and stores the value 11
at the special register (SD64 to SD79).Further, the program resets annunciator F11 if X2 goes
ON, and deletes the value 11 from the special registers (SD64 to SD79).
[Ladder Mode]
[List Mode]
Steps
When X1 is ON
5 - 33
SD63
SD64
SD65
SD66
0
0
0
0
SD78
SD79
0
0
Adds 1
Instruction
Device
When X2 is ON
SD63
SD64
SD65
SD66
SD67
1
11
0
0
0
SD78
SD79
0
0
Subtracts 1
SD63
SD64
SD65
SD66
SD67
0
0
0
0
0
SD78
SD79
0
0
5 - 33
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
DY
PLS
PLF
PLF Command
PLF
[Set Data]
Set Data
D
Meaning
Data Type
Bit
[Functions]
PLS
(1) When turned from OFF to ON, the PLS command turns ON the specified device, and other
than when turned from OFF to ON (i.e. from ON to ON, from ON to OFF or from OFF to OFF),
it turns OFF the specified device.
When there is one PLS instruction for the device designated by D during one scan, the
specified device turns ON one scan.
See Section 3.9 for the operation to be performed when the PLS instruction for the same
device is executed more than once during one scan.
ON
X5 OFF
X5
PLS
ON
M0
M0 OFF
1 scan
1 scan
(2) If the RUN/STOP key switch is changed from RUN to STOP after the execution of the PLS
instruction, the PLS instruction will not be executed again even if the switch is set back to RUN.
X0
PLS
M0
Set CPU module RUN/STOP key
switch from STOP to RUN
LD X0
PLS M0
END 0
LD X0
PLS M0
PLS M0
END
END
ON
X0 OFF
ON
M0 OFF
1 scan of PLS M0
(3) When a latch relay (L) is specified for the PLS command, switching power OFF with the latch
relay (L) ON and then switching it ON again executes the PLS instruction to turn ON the
specified device since the PLS command turns from OFF to ON at the first scan.
The device turned ON at the first scan after power-ON turns OFF at the next PLS instruction.
5 - 34
5 - 34
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
PLF
(1) When turned from ON to OFF, the PLF command turns ON the specified device, and other
than when turned from ON to OFF (i.e. from OFF to OFF, from OFF to ON or from ON to ON),
it turns OFF the specified device.
When there is one PLF instruction for the device designated by D during one scan, the
specified device turns ON one scan.
See Section 3.9 for the operation to be performed when the PLF instruction for the same
device is executed more than once during one scan.
ON
X5 OFF
X5
PLF
ON
M0
M0 OFF
1 scan
1 scan
(2) If the RUN/STOP key switch is changed from RUN to STOP after the execution of the PLF
instruction, the PLF instruction will not be executed again even if the switch is set back to
RUN.
POINT
Note that the device designated by D may be ON more than one scan if the PLS or PLF
instruction is jumped by the CJ instruction or if the subroutine program where the PLS/PLF
instructon was executed was not called by the CALL instruction.
[Operation Errors]
(1) There are no operation errors associated with the PLS or PLF instructions.
[Program Example]
(1) The following program executes the PLS instruction when X9 goes ON.
[Ladder Mode]
[List Mode]
Instruction
Steps
Device
ON
X9 OFF
ON
M9 OFF
1 scan
(2) The following program executes the PLF instruction when X9 goes OFF.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
ON
X9 OFF
ON
M9 OFF
1 scan
5 - 35
5 - 35
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Other
Constant
K, H
DY
FF
[Set Data]
Set Data
D
Meaning
Data Type
Bit
[Functions]
(1) The status of the device designated by
OFF to ON.
Device
Bit device
Designation of word device
Prior to FF execution
After FF execution
OFF
ON
0
1
ON
OFF
1
0
[Operation Errors]
(1) There are no operation errors associated with the FF instruction.
[Program Example]
(1) The following program reverses the output of Y10 when X9 goes ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
[Timing Chart]
ON
X9
OFF
Y10
OFF
ON
5 - 36
5 - 36
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
(2) The following program reverses b10 (bit 10) of D10 when X0 goes ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
[Timing Chart]
ON
X0
b10 of D10
5 - 37
OFF
5 - 37
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
DY
DELTA
DELTAP
Command
DELTAP
[Set Data]
Set Data
D
Meaning
Data Type
Bit
[Functions]
(1) Conducts pulse output of direct access output (DY) designated by D .
If DELTA DY0 has been designated, the resulting operation will be identical to the ladder
shown below, which uses the SET/RST instructions.
[Ladder created by the DELTA instructions]
X100
DELTA DY0
SET
DY0
RST
DY0
[Operation]
END processing
DELTA DY0
DELTA DY0
ON
X100
OFF
ON
ON
DY0 OFF
(2) The DELTA (P) instruction is used by commands for leading edge execution for an intelligent
function module/special function module.
5 - 38
5 - 38
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
A direct access output number designated by D has exceeded the CPU output range. (Error
code: 4101)
[Program Example]
(1) The following program presets CH1 of the AD61 mounted at slot 0 of the main base unit, when
X20 goes ON.
[Ladder Mode]
Stores preset value (0) at addresses 1
and 2 of the AD61 buffer memory
Output of preset instruction
[List Mode]
Steps
5 - 39
Instruction
Device
5 - 39
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
DY
SFT
SFTP
Shift command
SFTP
[Set Data]
Set Data
D
Meaning
Data Type
Bit
[Functions]
(1) When bit device is used
(a) Shifts to a device designated by D the ON/OFF status of the device immediately prior to
the one designated, and turns the prior device OFF.
For example, if M11 has been designated by the SFT instruction, when the SFT instruction
is executed, it will shift the ON/OFF status of M10 to M11, and turn M10 OFF.
(b) Turn the first device to be shifted ON with the SET instruction.
(c) When the SFT and SFTP are to be used consecutively, the program starts from the device
with the larger number.
Shift range
M0
Shift input
SFTP
M14
SFTP
SFTP
M13
M12
X02 ON
SFTP
M11
6
X2
1
0
SET
M10
5 - 40
1
0
5 - 40
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
D0
Prior to shift
execution
b5b4 to b0
b15
to
0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1
After shift
execution
0
0 1 0 0 1 0 0 0 1 1 1 0 0 0 0 1
[Operation Errors]
(1) There are no operation errors associated with the SFT (P) instruction.
[Program Example]
(1) The following program shifts Y57 to Y5B when X8 goes ON.
[Ladder Mode]
[Timing Chart]
[List Mode]
ON
X8
Steps
Instruction
Device
OFF
ON
X7
OFF
ON
Y57
OFF
ON
Y58
OFF
ON
Y59
OFF
ON
Y5A
OFF
ON
Y5B
5 - 41
OFF
5 - 41
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
N
DY
n
D
MC
MCR
MCR
[Set Data]
Set Data
Meaning
Data Type
Nesting
Bit
[Functions]
The master control instruction is used to enable the creation of highly efficient ladder switching
sequence programs, through the opening and closing of a common bus for ladders.
A ladder using the master control would look as shown below:
[Ladder as displayed in GPP Ladder Mode]
[Ladder as it actually operates]
X0
X0
MC
N1
N1
M0
M0
X1 X3 M7
N1
MC
M0
X1 X3 M7
N1
Y47
M5
Y47
Executed only
when X0 is ON
M5
Y4F
X6 X4
Y4F
X6 X4
MCR
N1
X0F
MCR
N1
XF
Y10
5 - 42
M0
Y40
5 - 42
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
REMARK
: When programming in the ladder mode of a peripheral device, it is not necessary to input
contacts on the vertical bus.
These will be automatically displayed when the "conversion" operation is conducted after the
creation of the ladder and then read mode is set.
MC
(1) If the ON/OFF command of the MC instruction is ON when master control is commenced, the
operation result between the MC instruction and MCR instruction will be exactly as the
instruction (ladder) shows.
If the MC ON/OFF indicator is OFF, the operation result between the MC and MCR
instructions will be as shown below:
Device
Device Status
(2) Even when the MC instruction is OFF, instructions from the MC instruction to the MCR
instruction will be executed, so scan time will not be shortened.
POINT
If there are unnecessary contact instructions (FOR - NEXT, EI, DI, etc.) in ladders which use
master controls, the CPU module will execute these instructions regardless of the ON/OFF
state of the MC instruction.
(3) By changing the device designated by
number as often as desired.
D,
(4) Coils from devices designated by D are turned ON when the MC instruction is ON.
Further, using these same devices with the OUT instruction or other instructions will cause
them to become double coils, so devices designated by D should not be used within other
instructions.
MCR
(1) This is the instruction for recovery from the master control, and indicates the end of the master
control range of operation.
(2) Do not place contact instructions before the MCR instruction.
[Operation Errors]
(1) There are no operation errors associated with the MC or MCR instructions.
5 - 43
5 - 43
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
The master control instruction can be used in nesting.
The different master control regions are distinguished by nesting (N).
Nesting can be performed from N0 to N14.
The use of nesting enables the creation of ladders which successively limit the execution condition
of the program.
A ladder using nesting would appear as shown below:
[Ladder as displayed in the GPP ladder mode]
MC NO M15
MC NO M15
N0
M15
N0
MC
MC
N1 M16
N1
M16
N1 M16
M16
Executed
when A and
B are ON
C
MC
N2
Executed
when A
is ON
B
N1
M15
MC
N2 M17
N2
M17
MCR N2
N2 M17
M17
Executed
when A, B,
and C are ON
MCR N2
Executed
when A and
B are ON
MCR N1
MCR N1
Executed
when A
is ON
MCR N0
MCR N0
No relation
to status of
A, B, or C
5 - 44
5 - 44
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
A
MC
N1
MC N1 M15
N1 M15
M15
N1
M15
B
MC
N0
N0 M16
MC N0 M16
N0
M16
M16
MCR N1
MCR N1
MCR N0
MCR N0
(2) If the nesting architecture results in MCR instructions concentrated in one location, all master
controls can be terminated by use of just the lowest nesting number (N).
X1
X1
MC NO M15
N0
M15
MC NO M15
N0
X2
X2
MC
N1
M15
N1 M16
N1
M16
X3
N1 M16
MC
N2 M17
X3
MC N2 M17
N2
MC
M16
N2
M17
MCR N2
M17
MCR N0
MCR N1
MCR N0
5 - 45
5 - 45
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
Other
FEND
[Functions]
(1) The FEND instruction is used in cases where the CJ instruction or other instructions are used
to cause a branch in the sequence program operations, and in cases where the main routine
program is to be split from a subroutine program or an interrupt program.
(2) Execution of the FEND instruction will cause the CPU module to terminate the program it was
executing.
(3) Even sequence programs following the FEND instruction can be displayed in ladder display at
a peripheral devices. (Peripheral devices continue to display ladders until encountering an
END instruction.)
0
program
CJ
Operations when
the CJ instruction
is not executed
Main routine
program
FEND
P
CALL P
Main routine
Main routine
Jump caused by
the CJ instruction
program
Operation
performed when P
the CJ instruction
was executed
FEND
Subroutine
program
Main routine
Interrupt program
program
FEND
END
END
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
A FEND instruction is executed after the execution of a CALL, FCALL, ECALL, or EFCALL
instruction, and before the execution of the RET instruction.
(Error code: 4211)
A FEND instruction is executed after the execution of a FOR instruction, and before the
execution of a NEXT instruction.
(Error code: 4200)
5 - 46
5 - 46
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
A FEND instruction is executed during an interrupt program, and before the execution of an
IRET instruction.
(Error code: 4221)
A FEND instruction is executed between the CHKCIR and CHKEND instructions.
(Error code: 4230)
A FEND instruction is executed between the IX and IXEND instructions. (Error code: 4231)
[Program Example]
(1) The following program uses the CJ instruction.
[Ladder Mode]
[List Mode]
Steps
5 - 47
Instruction
Device
5 - 47
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
U
END
END
[Functions]
(1) Indicates termination of programs, including main routine program, subroutine program, and
interrupt programs.
Execution of the END instruction will cause the CPU module to terminate the program that was
being executed.
0
Sequence program
END
(2) An END instruction cannot be used during the execution of the main sequence program.
If it is necessary to perform END processing during the execution of a program, use the FEND
instruction.
(3) When programming in the ladder mode of a peripheral device, it is not necessary to input an
END instruction.
5 - 48
5 - 48
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
(4) The use of the END and FEND instructions is broken down as follows for main routine
programs, subroutine programs, and interrupt programs:
Main routine program
FEND
Subroutine program
Main sequence
program area
Interrupt program
END
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
An END instruction was executed before the execution of the RET instruction and after the
execution of the CALL, FCALL, ECALL, or EFCALL instruction.
(Error code: 4211)
An END instruction was executed before the execution of a NEXT instruction and after the
execution of the FOR instruction.
(Error code: 4200)
An END instruction was executed during an interrupt program prior to the execution of the
IRET instruction.
(Error code: 4221)
An END instruction was executed within the CHKCIR to CHKEND instruction loop.
(Error code: 4230)
An END instruction was executed within the IX to IXEND instruction loop.
(Error code: 4231)
5 - 49
5 - 49
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
U
STOP
[Functions]
(1) When stop input is turned ON, output Y is reset and the CPU module operations are
terminated.
(The same result will take place if the RUN/STOP (key) switch is turned to the STOP setting.)
(2) Execution of the STOP instruction will cause the value of b4 to b7 of the special register
SD203 to become "3".
b15 to b12 b11 to
SD203
b8 b7
to
b4 b3
to
b0
0 0 1 1
becomes 3
(3) In order to restart CPU module operations after the execution of the STOP instruction, return
the RUN/STOP key switch, which has been changed from RUN to STOP, back to the RUN
position.
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
A STOP instruction was executed before the execution of the RET instruction and after the
execution of the CALL, ECALL instruction.
(Error code: 4211)
A STOP instruction was executed before the execution of a NEXT instruction and after the
execution of the FOR instruction.
(Error code: 4200)
A STOP instruction was executed during an interrupt program prior to the execution of the
IRET instruction.
(Error code: 4221)
A STOP instruction was executed within the CHKCIR to CHKEND instruction loop.
(Error code: 4230)
A STOP instruction was executed within the IX to IXEND instruction loop.
(Error code: 4231)
5 - 50
5 - 50
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
(1) The following program stops the CPU module when X8 goes ON
[Ladder Mode]
Causes programmable controller to stop
when X8 goes ON.
Sequence program
[List Mode]
Steps
5 - 51
Instruction
Device
5 - 51
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
NOP
NOPLF
NOPLE
PAGE n
PAGE n
[Functions]
NOP
(1) This is a no operation instruction that has no impact on any operations up to that point.
(2) The NOP instruction is used in the following cases:
(a) To insert space for sequence program debugging.
(b) To delete an instruction without having to change the number of steps. (Replace the
instruction with NOP)
(c) To temporarily delete an instruction.
NOPLF
(1) This is a no operation instruction that has no impact on any operations up to that point.
(2) The NOPLF instruction is used when printing from a peripheral device to force a page change
at any desired location.
(a) When printing ladders
A page break will be inserted between ladder blocks with the presence of the NOPLF
instruction.
The ladder cannot be displayed correctly if an NOPLF instruction is inserted in the midst
of a ladder block.
Do not insert an NOPLF instruction in the midst of a ladder block.
(b) When printing instruction lists
The page will be changed after the printing of the NOPLF instruction.
(3) Refer to the Operating Manual for the peripheral device in use for details of printouts from
peripheral devices.
5 - 52
5 - 52
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
PAGE n
(1) This is a no operation instruction that has no impact on any operations up to that point.
(2) Causes processing from step 0 of the designated nth page of the program following the PAGE
n instruction. (Peripheral device display, printers, etc.)
(3) If there is no PAGE n instruction, processing begins from page 0.
[Operation Errors]
(1) There are no errors associated with the NOP, NOPLF, or PAGE instructions.
[Program Example]
NOP
(1) Contact closed .............. Deletes AND or ANI instruction
Before change
[Ladder Mode]
0
X8
Y97
[List Mode]
Y96
Steps
Changed to NOP
4
END
After change
[Ladder Mode]
0
X8
Y96
Instruction
Device
Y12
0
1
2
3
4
LD
AND
ANI
OUT
END
X8
Y97
Y96
Y12
[List Mode]
Steps
Y12
END
0
1
2
3
4
Instruction
LD
NOP
ANI
OUT
END
Device
X8
Y96
Y12
(2) Contact closed .............. LD, LDI changed to NOP (Note carefully that changing the LD and LDI
instructions to NOP completely changes the nature of the ladder.)
Before change
[Ladder Mode]
0
X0
X56
[List Mode]
Y16
T3
Y66
Changed to NOP
5
END
After change
[Ladder Mode]
0
X0
5 - 53
0
1
2
3
4
5
Instruction
LD
OUT
LD
AND
OUT
END
Device
X0
Y16
X56
T3
Y66
[List Mode]
Y16
T3
Steps
Y66
END
Steps
0
1
2
3
4
5
Instruction
LD
OUT
NOT
AND
OUT
END
Device
X0
Y16
T3
Y66
5 - 53
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
Before change
[Ladder Mode]
[List Mode]
0 X0
2
X56
Y16
T3
Y66
Changed to LD T3
Changed to NOP
END
After change
[Ladder Mode]
0
3
Steps
0
1
2
3
4
5
Instruction
LD
OUT
LD
AND
OUT
END
Device
X0
Y16
X56
T3
Y66
[List Mode]
X0
Y16
T3
Y66
END
Steps
0
1
2
3
4
5
Instruction
LD
OUT
NOP
LD
OUT
END
Device
X0
Y16
T3
Y66
NOPLF
[List Mode]
[Ladder Mode]
0
X0
MOV
MOV
5
5 - 54
K1
K2
D30
Instruction
0
1
LD
MOV
MOV
5
6
7
8
NOPLF
LD
OUT
END
D40
NOPLF
X1
Steps
Y40
Device
X0
K1
D30
K2
D40
X1
Y40
END
5 - 54
5 SEQUENCE INSTRUCTIONS
MELSEC-Q/QnA
X000
MOV
K
1
D30
MOV
K
2
D40
NOPLF
1
X001
6
X001
END
Printing an instruction list with the NOPLF instruction will result in the following:
0
LD
X000
MOV
K1
D30
MOV
K2
D40
Changes pages after printing NOPLF
NOPLF
LD
X001
OUT
Y040
END
PAGE n
[Ladder Mode]
[List Mode]
PAGE K5
X0
X1
Y0
2
X2
5
NOP
NOPLF
11
13
5 - 55
Y1
PAGE K6
X3
Steps
0
2
3
4
5
6
7
8
9
11
12
13
Instruction
PAGE
LD
AND
OUT
LD
NOP
OUT
NOPLF
PAGE
LD
OUT
END
Device
K5
X0
X1
Y0
X2
Y1
K6
X3
Y2
Y2
END
5 - 55
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
6. BASIC INSTRUCTIONS
The following types of basic instructions are available.
Instruction
Comparison operation
instruction
Meaning
Reference Section
Chapter 6.1
Arithmetic operation
instructions
Chapter 6.2
Chapter 6.3
Chapter 6.4
Program jumps
Chapter 6.5
Chapter 6.6
Refresh instruction
Chapter 6.7
6-1
6-1
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
S1
S2
S1
S2
AND
S1
S2
S1
S2
OR
6
[Set Data]
Set Data
Meaning
Data Type
S1
S2
BIN 16 bits
[Functions]
(1) Treats BIN 16-bit data from device designated by S1 and BIN 16-bit data from device
designated by S2 as an A contact, and performs comparison operation.
(2) The results of the comparison operations for the individual instructions are as follows:
Instruction
Symbol
in
Condition
S1
Comparison
Operation
Result
Instruction
Symbol
in
Condition
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
Continuity
Comparison
Operation
Result
Non-continuity
(3) In cases where hexadecimal constants have been designated by S1 and S2 , or when a
numerical value (8 to F) where the highest bit (b15) will be 1 has been designated, the value
will be read as a negative BIN value number for purposes of the comparison.
6-2
6-2
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the =, <>, >, <=, <, or >= instructions.
[Program Example]
(1) The following program compares the data at X0 to XF with the data at D3, and turns Y33 ON if
the data is identical.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program compares BIN value K100 to the data at D3, and establishes continuity
if the data in D3 is something other than 100.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(3) The following program compares the BIN value 100 with the data in X0 to XF, and establishes
continuity if the D3 data is less than 100.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(4) The following program compares the data in D0 and D3, and if the data in D0 is equal to or
less than the data in D3, establishes continuity.
[Ladder Mode]
[List Mode]
Steps
6-3
Instruction
Device
6-3
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
6.1.2 BIN 32-bit data comparisons (D=, D< >, D>, D<=,D<, D>=)
Internal Devices
(System, User)
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
S1
S2
S1
S2
AND
S1
S2
S1
S2
OR
[Set Data]
Set Data
Meaning
Data Type
S1
S2
BIN 32 bits
[Functions]
(1) Treats BIN 32-bit data from device designated by S1 and BIN 32-bit data from device
designated by S2 as an A contact, and performs comparison operation.
(2)The results of the comparison operations for the individual instructions are as follows:
Instruction
Symbol
in
D
D
D
D
D
D
Condition
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
Comparison
Operation
Result
Continuity
Instruction
Symbol
in
D
D
D
D
D
D
Condition
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
Comparison
Operation
Result
Non-continuity
(3) In cases where hexadecimal constants have been designated by S1 and S2 , or when a
numerical value (8 to F) where the highest bit (b31) will be 1 has been designated, the value
will be read as a negative BIN value number for the purposes of the comparison.
(4) Data used for comparison should be designated by a 32-bit instruction (DMOV instruction,
etc.).
If designation is made with a 16-bit instruction (MOV instruction, etc.), comparisons of large
and small values cannot be performed correctly.
6-4
6-4
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the =, <>, >, <=, <, or >= instructions.
[Program Example]
(1) The following program compares the data at X0 to XF with the data at D3, and turns Y33 ON if
the data is identical.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program compares BIN value K38000 to the data at D3, and D4, and establishes
continuity if the data in D3 and D4 is something other than 38000.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(3) The following program compares BIN value K-80000 to the data at D3 and D4, and establishes
continuity if the data in D3 and D4 is less than -80000.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(4) The following program compares the data in D0 and D1 with the data in D3 and D4, and
establishes continuity if the data in D0 and D1 is equal to or less than the data in D3 and D4.
[Ladder Mode]
[List Mode]
Steps
6-5
Instruction
Device
6-5
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
6.1.3 Floating decimal point data comparisons (E=, E< >, E>, E<=, E<, E>=)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
E
Other
S1
S2
indicates the signs E=, E< >, E>, E<=, E<, or E>=
S1
S2
AND
S1
S2
S1
S2
OR
[Set Data]
Set Data
Meaning
Data Type
S1
S2
Real number
[Functions]
(1) The floating decimal point data from device designated by S1 and floating decimal point data
from device designated by S2 as A contact, and performs comparison operation.
(2)The results of the comparison operations for the individual instructions are as follows.
Instruction
Symbol
in
E
E
E
E
E
E
Condition
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
Comparison
Operation
Result
Instruction
Symbol
in
Condition
E
E
E
E
E
E
Continuity
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
Comparison
Operation
Result
Non-continuity
POINT
Note that use of the = instruction can on occasion result in situations where errors cause the
two values to not be equal.
Example
X0
EMOV E1.23 D1
E=
D0
D0
E4.56 D2
E/
D2
E4.65 D2
D2
M0
6-6
6-6
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the E=, E< >, E>, E<=, E<, or, E>= instructions.
[Program Example]
(1) The following program compares floating decimal point real number data at D0 and D1 to
floating decimal point real number data at D3 and D4.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program compares the floating decimal point real number 1.23 to the floating
decimal point real number data at D3 and D4.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(3) The following program compares floating decimal point real number data at D0 and D1 to
floating decimal point real number data at D3 and D4.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(4) The following program compares the floating decimal point data at D0 and D1 to the floating
decimal point real number 1.23.
[Ladder Mode]
[List Mode]
Steps
6-7
Instruction
Device
6-7
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
6.1.4 Character string data comparisons ($=, $< >, $>, $<=, $<, $>=)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
$
Other
S1
S2
indicates the signs $=, $< >, $>, $<=, $<, or $>=
S1
S2
AND
S1
S2
S1
S2
OR
[Set Data]
Set Data
Meaning
Data Type
S1
Character string
S2
[Functions]
(1) Treats character string data stored following the device designated by S1 and character string
data stored following the device designated by S2 as A contact, and performs comparison
operation.
(2) A comparison operation involves the character-by-character comparison of the ASCII code of
the first character in the character string.
(3) The S1 and S2 character strings encompass all characters from the designated device number
to the next device number storing the code "00H".
(a) If all character strings match, the comparison result will be matched.
S1
S1
S1
b15- - - -b8
42H (B)
+1 44H (D)
+2 00H
b7- - - - b0
41H (A)
43H (C)
45H (E)
"ABCDE"
Instruction Symbol
in
$
$
$
6-8
S2
S2
S2
b15- - - -b8
42H (B)
+1 44H (D)
+2 00H
b7- - - - b0
41H (A)
43H (C)
45H (E)
"ABCDE"
Comparison Operation
Result
Continuity
Non-continuity
Non-continuity
Instruction Symbol
in
$
$
$
Comparison Operation
Result
Continuity
Non-continuity
Continuity
6-8
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(b) If the character strings are different, the character string with the larger character code will
be the larger.
S1
S1
S1
b15- - - -b8
42H (B)
+1 44H (D)
+2 00H
b7- - - - b0
41H (A)
43H (C)
46H (F)
S2
S2
S2
"ABCDF"
Instruction Symbol
in
b7- - - - b0
41H (A)
43H (C)
45H (E)
"ABCDE"
Comparison Operation
Result
$
$
$
b15- - - -b8
42H (B)
+1 44H (D)
+2 00H
Instruction Symbol
in
Non-continuity
Continuity
Continuity
$
$
$
Comparison Operation
Result
Non-continuity
Non-continuity
Continuity
(c) If the character strings are different, the first different sized character code will determine
whether the character string is larger or smaller.
S1
S1
S1
b15- - - -b8
32H (2)
+1 33H (3)
+2 00H
b7- - - - b0
31H (1)
34H (4)
35H (5)
S2
S2
S2
"12435"
Instruction Symbol
in
S1
S1
S1
b15
b8
32H (2)
+1 34H (4)
+2 36H (6)
+3 00H
b7
31H
33H
35H
37H
S1
$
$
$
and
b0
(1)
(3)
(5)
(7)
"1234567"
Instruction Symbol
in
$
$
$
6-9
Instruction Symbol
in
Non-continuity
Continuity
Continuity
b7- - - - b0
31H (1)
33H (3)
35H (5)
"12345"
Comparison Operation
Result
$
$
$
b15- - - -b8
32H (2)
+1 34H (4)
+2 00H
S2
Comparison Operation
Result
Non-continuity
Non-continuity
Continuity
S2
S2
S2
S2
b15
b8
32H (2)
+1 34H (4)
+2 36H (6)
00H
+3
b7
b0
31H (1)
33H (3)
35H (5)
00H
"123456"
Comparison Operation
Result
Non-continuity
Continuity
Non-continuity
Instruction Symbol
in
$
$
$
Comparison Operation
Result
Continuity
Continuity
Non-continuity
6-9
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The code 00H or non-matching does not exist within the relevant device range following the
device number designated by S1 or S2 . (Error code: 4101)
POINT
At the same time that it is conducting a character string comparison, character string data
comparison instruction also checks the device range.
For this reason, even in cases where the character string exceeds the device range, the
character string data is compared. If character non-matching is detected within the device
range at this time, the comparison operation results are output without returning an operation
error.
$
Example
S1
S1
M0
D12287 D10
S2
data
S2
data
D12287
"B"
"A"
D10
"Z"
"A"
W0
00H
"C"
D11
00H
"C"
In the example shown above, the S1 character string exceeds the device range, but because
its second character is different from that of S2 , the comparison result is " S1 does not equal
S2 ", and the operation result is non-continuity.
In this case, because the non-continuity detection is for D12287 (inside the device range),
there will be no operation error returned.
[Program Example]
(1) The following program compares character strings stored following D0 and characters
following D10.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program compares the character string "ABCDEF" with the character string
stored following D10.
[Ladder Mode]
[List Mode]
Steps
6 - 10
Instruction
Device
6 - 10
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(3) The following program compares the character string stored following D10 with the character
string stored following D100.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(4) The following program compares the character string stored following D10 with the character
string "12345."
[Ladder Mode]
[List Mode]
Steps
6 - 11
Instruction
Device
6 - 11
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
S1
S2
n
[Instruction Symbol] [Execution Condition]
Command
BKCMP
BKCMP
S1
S2
S1
S2
Command
BKCMP
BKCMP
[Set Data]
Set Data
S1
S2
Meaning
Data Type
Data being compared, or first number of the device where the data being
compared is being stored
First number of the device where the comparison data is being stored
BIN 16 bits
BIN 16 bits
Bit
BIN 16 bits
[Functions]
(1) Compares BIN 16-bit data the nth point from the device number designated by S1 with BIN 16bit data the nth point from the device number designated by S2 , and stores the result from the
device designated by D onward.
(a) If the comparison condition has been met, the device designated by D will be turned ON.
(b) If the comparison condition has not been met, the device designated by
OFF.
+1
+2
1234 (BIN)
5678 (BIN)
5000 (BIN)
+(n-2)
+(n-1)
7777 (BIN)
4321 (BIN)
S1
S1
S1
S1
S1
6 - 12
+1
+2
5321 (BIN)
3399 (BIN)
5678 (BIN)
+(n-2)
+(n-1)
6543 (BIN)
1200 (BIN)
S2
S2
>
S2
S2
S2
D
D +1
D +2
D +(n-2)
D +(n-1)
will be turned
Operation Results
OFF (0)
ON (1)
OFF (0)
ON
ON
(1)
(1)
6 - 12
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
S1
S2
S2
32000 (BIN)
S1
S2
S2
S2
+1
+2
+(n-2)
+(n-1)
32000 (BIN)
4321 (BIN)
32000 (BIN)
D
D +1
D +2
D +(n-2)
1234 (BIN)
5678 (BIN)
D +(n-1)
ON
OFF
ON
(1)
(0)
(1)
OFF
OFF
(0)
(0)
(4) The results of the comparison operations for the individual instructions are as follows:
Instruction
Symbols
BKCMP
BKCMP
BKCMP
BKCMP
BKCMP
BKCMP
Condition
S1
Comparison
Operation Result
Instruction
Symbols
BKCMP
BKCMP
BKCMP
BKCMP
BKCMP
BKCMP
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
ON (1)
Condition
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
S1
S2
Comparison
Operation Result
OFF (0)
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The range of the device n points from a device designated by S1 , S2 or D exceeds the
relevant device. (Error code: 4101)
The device range for n points starting from the device designated by S1 overlaps with the
device range for n points starting from the device designated by D . (Error code: 4101)
The device range for n points starting from the device designated by S2 overlaps with the
device range for n points starting from the device designated by D . (Error code: 4101)
The device range for n points starting from the device designated by S1 overlaps with the
device range for n points starting from the device designated by S2 . (Error code: 4101)
(2) See Section 3.6 for information regarding errors during index modification.
6 - 13
6 - 13
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
(1) The following program performs a comparison operation when X20 goes ON, comparing the
data for the number of points from D100 equivalent to the value stored in D0 with the data the
number of points from R0 equivalent to the value stored in D0, and stores the result from M10
onward.
[Ladder Mode]
[List Mode]
Instruction
Steps
D100
D101
D102
D103
b15- - - - - - - -b0
1000 (BIN)
2000 (BIN)
3000 (BIN)
4000 (BIN)
D0
R0
R1
R2
R3
b15- - - - - - - -b0
1000 (BIN)
2000 (BIN)
5000 (BIN)
4000 (BIN)
Device
M10
M11
M12
M13
ON
ON
OFF
ON
(2) The following program performs a comparison operation when X1C goes ON, comparing the
constant K1000 with the data 4 points from D10, and stores the result in b4 to b7 of D0.
[Ladder Mode]
[List Mode]
Steps
0
1
Instruction
LD
BKCMP<>P
b15- - - - - - - -b0
1000 (BIN)
<>
D10
D11
D12
D13
Device
X1C
K1000
D10
D0.4
K4
END
b15- - - - - - - -b0
2000 (BIN)
1000 (BIN)
1000 (BIN)
2222 (BIN)
6 - 14
6 - 14
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(3) When X20 goes ON, compares the data 3 points from D10 with the data 3 points from D30,
and stores the result from M100 onward.
The following program transfers the character string "ALL ON" to D100 onward when all
devices from M100 onward have reached the 1 "ON" state.
[Ladder Mode]
[List Mode]
Steps
D10
D11
D12
b15- - - - - - - -b0
1234 (BIN)
5678 (BIN)
9876 (BIN)
D30
D31
D32
b15- - - - - - - -b0
4321 (BIN)
5678 (BIN)
9999 (BIN)
Instruction
M100
M101
M102
b15- - - - b8 b7- - - - b0
D100 4CH (L) 41H (A)
D101 20H ( ) 4CH (L)
D102 4EH (N) 4FH (O)
6 - 15
Device
SM704
ON
ON
ON
ON
$MOV
6 - 15
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
S
D
Command
+, -
Command
+P, -P
[Set Data]
Set Data
S
D
Meaning
Addition or subtraction data, or first number of device storing addition or
subtraction data
Data to be added to or subtracted from, or first number of device storing
such data
Data Type
BIN 16 bits
[Functions]
+
(1) Adds 16-bit BIN data designated by D to 16-bit BIN data designated by
result of the addition at the device designated by D .
D
b15- - - - - - - - - b0
5678 (BIN)
and
b15- - - - - - - - - b0
1234 (BIN)
b15- - - - - - - - - b0
6912 (BIN)
(3) The judgment of whether data is positive or negative is made by the most significant bit (b15).
0 ........ Positive
1 ........ Negative
6 - 16
6 - 16
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(4) The following will happen when an underflow or overflow is generated in an operation result:
The carry flag in this case does not go ON.
K32767
(H7FFF)
K-32768
(H8000)
+K2
(H0002)
+K-2
(HFFFE)
(1) Subtracts 16-bit BIN data designated by D from 16-bit BIN data designated by
the result of the subtraction at the device designated by D .
D
b15- - - - - - - - -b0
5678 (BIN)
and
b15- - - - - - - - -b0
1234 (BIN)
b15- - - - - - - - -b0
4444 (BIN)
and stores
(3) The judgment of whether data is positive or negative is made by the most significant bit (b15).
0 ....... Positive
1 ....... Negative
(4) The following will happen when an underflow or overflow is generated in an operation result:
The carry flag in this case does not go ON.
K-32768 -K2
(H8000)
(H0002)
K32767 -K-2
(H7FFF) (H0002)
[Operation Errors]
(1) There are no operation errors associated with the +(P) or -(P) instructions.
6 - 17
6 - 17
6 BASIC INSTRUCTIONS
Internal Devices
(System, User)
Set
Data
Bit
MELSEC-Q/QnA
Usable Devices
MELSECNET/10(H)
Special
Direct J \
Function
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S1
S2
S1
S2
S1
S2
Command
+P, -P
[Set Data]
Set Data
S1
S2
Meaning
Data to be added to or subtracted from, or the first number of the device
storing such data
Addition or subtraction data, or first number of device storing addition or
subtraction data
First number of device storing addition or subtraction data
Data Type
BIN 16 bits
[Functions]
+
(1) Adds 16-bit BIN data designated by
device designated by D .
S1
b15- - - - - - - - -b0
5678 (BIN)
S1
S2
and
S1
b15- - - - - - - - -b0
1234 (BIN)
b15- - - - - - - - -b0
6912 (BIN)
S2
(3) The judgment of whether data is positive or negative is made by the most significant bit (b15).
0 .......... Positive
1 .......... Negative
(4) The following will happen when an underflow or overflow is generated in an operation result:
The carry flag in this case does not go ON.
K32767
(H7FFF)
K-32768
(H8000)
6 - 18
+K2
(H0002)
+K-2
(HFFFE)
6 - 18
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(1) Subtracts 16-bit BIN data designated by S1 from 16-bit BIN data designated by
the result of the subtraction at the device designated by D .
S1
b15- - - - - - - - -b0
5678 (BIN)
S1
S2
and
S2
b15- - - - - - - - -b0
1234 (BIN)
b15- - - - - - - - -b0
4444 (BIN)
S2
and stores
(3) The judgment of whether data is positive or negative is made by the most significant bit (b15).
0 ....... Positive
1 ....... Negative
(4) The following will happen when an underflow or overflow is generated in an operation result:
The carry flag in this case does not go ON.
K-32768 -K2
(H8000)
(H0002)
K32767 -K-2
(H7FFF) (H0002)
[Operation Errors]
(1) There are no operation errors associated with the +(P) or -(P) instructions.
[Program Example]
(1) The following program adds the contents of D3 and the contents of D0 when X5 goes ON, and
outputs result to Y38 to Y3F.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program outputs the difference between the set value for timer T3 and its
present value to Y40 to Y53.
[Ladder Mode]
[List Mode]
Steps
6 - 19
Instruction
Device
6 - 19
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
6.2.2 BIN 32-bit addition and subtraction operations (D+, D+P, D-, D-P)
Internal Devices
(System, User)
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S
D
Command
D+, D-
Command
D+P, D-P
[Set Data]
Set Data
S
D
Meaning
Data Type
BIN 32 bits
[Functions]
D+
(1) Adds 32-bit BIN data designated by D to 32-bit BIN data designated by
result of the addition at the device designated by D .
D +1
S +1
and
D +1
(3) Judgment of whether the data is positive or negative is made on the basis of the most
significant bit (b31).
0 .......... Positive
1 .......... Negative
6 - 20
6 - 20
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(4) The following will happen when an underflow or overflow is generated in an operation result:
The carry flag in this case does not go ON.
K2147483647
(H7FFFFFFF)
K-2147483648
(H80000000)
+K2
(H2)
+K-2
(HFFFE)
K-2147483647.......Because b31 is 1,
(H80000001)
the value is negative.
K2147483646........Because b31 is 0,
the value is positive.
(H7FFFFFFE)
D(1) Subtracts 32-bit BIN data designated by D from 32-bit BIN data designated by
the result of the subtraction at the device designated by D .
D +1
S +1
and
D +1
and stores
(3) Judgment of whether the data is positive or negative is made on the basis of the most
significant bit (b31).
0 ....... Positive
1 ....... Negative
(4) The following will happen when an underflow or overflow is generated in an operation result:
The carry flag in this case does not go ON.
K-2147483648
(H80000000)
K2147483647
(H7FFFFFFF)
-K2
(H2)
-K-2
(HFFFE)
K2147483646........Because b31 is 0,
(H7FFFFFFE)
the value is positive.
K-2147483647.......Because b31 is 1,
(H80000001)
the value is negative.
[Operation Errors]
(1) There are no operation errors associated with the +(P) or -(P) instructions.
6 - 21
6 - 21
6 BASIC INSTRUCTIONS
Internal Devices
(System, User)
Set
Data
Bit
MELSEC-Q/QnA
Usable Devices
MELSECNET/10(H)
Special
Direct J \
Function
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S1
S2
Command
D+, D-
S1
S2
S1
S2
Command
D+P, D-P
[Set Data]
Set Data
S1
S2
Meaning
Data to be added to or subtracted from, or the first number of the device
storing such data
Addition or subtraction data, or first number of device storing addition or
subtraction data
First number of device storing addition or subtraction data
Data Type
BIN 32 bits
[Functions]
D+
(1) Adds 32-bit BIN data designated by
device designated by D .
S1
+1
S1
S2
S1
S2
, and
S1
+1
D +1
S2
(3) Judgment of whether the data is positive or negative is made on the basis of the most
significant bit (b31).
(4) The following will happen when an underflow or overflow is generated in an operation result:
The carry flag in this case does not go ON.
K2147483647
(H7FFFFFFF)
K-2147483648
(H80000000)
6 - 22
+K2
(H2)
+K-2
(HFFFE)
K-2147483647.......Because b31 is 0,
(H80000001)
the value is positive.
K2147483646........Because b31 is 1,
(HFFFE)
the value is negative.
6 - 22
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
D(1) Subtracts 32-bit BIN data designated by S1 from 32-bit BIN data designated by
the result of the subtraction at the device designated by D .
S1
+1
S1
S2
S1
S2
, and
+1
D +1
S2
S2
and stores
(3) Judgment of whether the data is positive or negative is made on the basis of the most
significant bit (b31).
0 ....... Positive
1 ....... Negative
(4) The following will happen when an underflow or overflow is generated in an operation result:
The carry flag in this case does not go ON.
K-2147483648
(H80000000)
K2147483647
(H7FFFFFFF)
-K2
(H2)
-K-2
(HFFFE)
K2147483646........Because b31 is 0,
(H7FFFFFFE)
the value is positive.
K-2147483647.......Because b31 is 1,
(HFFFE)
the value is negateve.
[Operation Errors]
(1) There are no operation errors associated with the +(P) or -(P) instructions.
[Program Example]
(1) The following program adds 28-bit data from X10 to X2B to the data at D9 and D10 when X0
goes ON, and outputs the result of the operation to Y30 to Y4B.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program subtracts the data from M0 to M23 from the data at D0 and D1 when
XB goes ON, and stores the result at D10 and D11.
[Ladder Mode]
[List Mode]
Steps
6 - 23
Instruction
Device
6 - 23
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
Usable Devices
MELSECNET/10(H)
Special
Direct J \
Function
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
S1
S2
or /
Command
,/
S1
S2
S1
S2
Command
P, /P
[Set Data]
Set Data
S1
S2
Meaning
Data that will be multiplied or divided, or the first number of the device
storing data that will be multiplied or divided
Data to multiply or divide by, or the first number of device storing such
data
First number of the device storing the operation results of multiplication or
division operation
Data Type
BIN 16 bits
BIN 32 bits
[Functions]
(1) Multiplies BIN 16-bit data designated by S1 and BIN 16-bit data designated by
the result in the device designated by D .
(2) If
S1
S2
b15- - - - - - - - - b0
5678 (BIN)
b15- - - - - - - - - b0
1234 (BIN)
D +1
S2
, and stores
S1
S2
, and
(4) Judgments whether S1 , S2 , and (D) are positive or negative are made on the basis of the most
significant bit (b15 for S1 , and S2 , for D and b31).
0 ....... Positive
1 ....... Negative
6 - 24
6 - 24
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
/
(1) Divides BIN 16-bit data designated by
result in the device designated by D .
S1
S1
S2
b15- - - - - - - - - b0
5678 (BIN)
b15- - - - - - - - - b0
1234 (BIN)
Quotient
Remainder
D +1
S2
b15- - - - b0 b15- - - - b0
742 (BIN)
4 (BIN)
(2) If a word device has been used, the result of the division operation is stored as 32 bits, and
both the quotient and remainder are stored; if a bit device has been used, 16 bits are used and
only the quotient is stored.
Quotient .......... Stored at the lower 16 bits
Remainder ...... Stored at the higher 16 bits
(Can be stored only when a word device has been used)
(3) The values for
S1
S2
, and
(4) Judgment whether values for S1 , S2 , and D are positive or negative is made on the basis of
the most significant bit (b15 for S1 and S2 , and b15 for D ).
0 ....... Positive
1 ....... Negative
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
Attempt to divide S2 by 0. (Error code: 4100)
[Program Example]
(1) The following program divides "5678" by "1234" when X5 goes ON, and stores the result at D3
and D4.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program divides BIN data at X8 to XF by BIN data at X10 to X1B, and outputs
the result of the division operation to Y30 to Y3F.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(3) The following program outputs the value resulting when the data at X8 to XF is divided by 3.14
to Y30 to Y3F when X3 is ON.
[Ladder Mode]
[List Mode]
Steps
6 - 25
Instruction
Device
6 - 25
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S1
S2
or D/
Command
D ,D/
S1
S2
S1
S2
Command
D P,D/P
[Set Data]
Set Data
Meaning
Data Type
Data that will be multiplied or divided, or the head number of the device
storing data that will be multiplied or divided
Data to multiply or divide by, or the head number of device storing such
data
Head number of the device storing the operation results of multiplication
or division operation
S1
S2
BIN 32 bits
BIN 64 bits
[Functions]
D
(1) Multiplies BIN 32-bit data designated by S1 and BIN 32-bit data designated by
the result in the device designated by D .
S1
+1
S1
S2
+1
S2
D +3
D +2
D +1
S2
, and stores
567890 (BIN)
123456 (BIN)
70109427840 (BIN)
(2) If D is a bit device, only the lower 32 bits of the multiplication result will be considered, and the
upper 32 bits cannot be designated.
Example K1........... Lower 4 bits (b0 to 3)
K4........... Lower 16 bits (b0 to 15)
K8........... Lower 32 bits (b0 to 31)
If the upper 32 bits of the bit device are required for the result of the multiplication operation,
first temporarily store the data in a word device, then transfer the word device data to the bit
device by designating ( D +2) and ( D +3) data.
(3) The values for
32 bits).
6 - 26
S1 , S2 ,
and
6 - 26
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(4) Judgment whether values for S1 , S2 , and D are positive or negative are made on the basis of
the most significant bit (b31 for S1 and S2 , and b63 for D ).
0 ....... Positive
1 ....... Negative
D/
(1) Divides BIN 32-bit data designated by
result in the device designated by D .
S1
+1
S1
S2
+1
S1
S2
D +3
S2 ,
D +2
(2) If a word device has been used, the result of the division operation is stored as 64 bits, and
both the quotient and remainder are stored; if a bit device has been used, 32 bits are used and
only the quotient is stored.
Quotient .......... Stored at the lower 32 bits
Remainder ...... Stored at the higher 32 bits
(Can be stored only when a word device has been used)
(3) The values for S1 and S2 can be designated at between -2147483648 to 2147483647 (BIN 32 bits).
(4) Judgment whether values for S1 , S2 , D , and D +2 are positive or negative is made on the
basis of the most significant bit (b31).
(A sign is used with both the quotient and the remainder)
0 ....... Positive
1 ....... Negative
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
Attempt to divide S2 by 0. (Error code: 4100)
[Program Example]
(1) The following program divides the BIN data at D7 and D8 by the BIN data at D18 and D19
when X5 is ON, and stores the result at D1 to D4.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program outputs the value resulting when the data at X8 to XF is multiplied by
3.14 to Y30 to Y3F when X3 is ON.
[Ladder Mode]
[List Mode]
Steps
6 - 27
Instruction
Device
6 - 27
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
6.2.5 BCD 4-digit addition and subtraction operations (B+, B+P, B-, B-P)
Internal Devices
(System, User)
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S
D
Command
B+, B -
Command
B+P, B - P
[Set Data]
Set Data
S
D
Meaning
Addition or subtraction data, or head number of device storing addition or
subtraction data
Data to be added to or subtracted from, or head number of device storing
such data
Data Type
BCD 4-digit
[Functions]
B+
(1) Adds the BCD 4-digit data designated by D and the BCD 4-digit data designated by
stores the result of the addition at the device designated by D .
D
and
, and
(3) If the result of the addition operation exceeds 9999, the higher bits are ignored. The carry flag
in this case does not go ON.
6
B(1) Subtracts the BCD 4-digit data designated by D and the BCD 4-digit data designated by
and stores the result of the subtraction at the device designated by D .
D
S2
6 - 28
6 - 28
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
and
(3) The following will result if an underflow is generated by the subtraction operation:
The carry flag in this case does not go ON.
0
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The S or D BCD data is outside the 0 to 9999 range. (Error code: 4100)
[Program Example]
(1) The following program adds BCD data 5678 and 1234, stores it at D993, and at the same time
outputs it to from Y30 to Y3F.
[Ladder Mode]
Stores 5678 at D993
Adds BCD 1234 and D993, and
stores the result in D993
Outputs data at D993 to Y30 to Y3F
[List Mode]
Steps
Instruction
Device
(2) The following program subtracts the BCD data 4321 from 7654, stores the result at D10, and
at the same time outputs it to Y30 to Y3F.
[Ladder Mode]
Stores 7654 at D10 as BCD
Subtracts data in D10 from BCD
4321 and stores result at D10
Outputs data at D10 to Y30 to Y3F
[List Mode]
Steps
6 - 29
Instruction
Device
6 - 29
6 BASIC INSTRUCTIONS
Internal Devices
(System, User)
Set
Data
Bit
MELSEC-Q/QnA
Usable Devices
MELSECNET/10(H)
Special
Direct J \
Function
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S1
S2
Command
B+,B-
S1
S2
S1
S2
Command
P
B+P,B-P
[Set Data]
Set Data
S1
S2
Meaning
Data to be added to or subtracted from, or the head number of the device
storing such data
Addition or subtraction data, or head number of device storing addition or
subtraction data
Head number of device storing addition or subtraction data
Data Type
BCD 4-digit
[Functions]
B+
(1) Adds the BCD 4-digit data designated by S1 and the BCD 4-digit data designated by
stores the result of the addition at the device designated by D .
S1
S2
, and
, and
S2
S1
S2
(3) If the result of the addition operation exceeds 9999, the higher bits are ignored.
The carry flag in this case does not go ON.
6
B(1) Subtracts the BCD 4-digit data designated by S1 and the BCD 4-digit data designated by
and stores the result of the subtraction at the device designated by D .
S1
S2
S2
6 - 30
6 - 30
6 BASIC INSTRUCTIONS
S1
MELSEC-Q/QnA
,
S2
, and
(3) The following will result if an underflow is generated by the subtraction operation:
The carry flag in this case does not go ON.
0
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The S1 , S2 , or D BCD data is outside the 0 to 9999 range. (Error code: 4100)
[Program Example]
(1) The following program adds the D3 BCD data and the Z1 BCD data when X20 goes ON, and
outputs the result to Y8 to Y17.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program subtracts the BCD data at D20 from the BCD data at D10 when X20
goes ON, and stores the result at R10.
[Ladder Mode]
[List Mode]
Steps
6 - 31
Instruction
Device
6 - 31
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
6.2.6 BCD 8-digit addition and subtraction operations (DB+, DB+P, DB-, DB-P)
Set
Data
Internal Devices
(System, User)
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S
D
Command
DB+
DB -
Command
DB+P
DB - P
[Set Data]
Set Data
S
D
Meaning
Data Type
BCD 8-digit
[Functions]
DB+
(1) Adds the BCD 8-digit data designated by D and the BCD 8-digit data designated by
stores the result of the addition at the device designated by D .
D +1
S +1
0 9 8 7 1 0 6 8
D +1
, and
0 0 3 2 3 4 5 6
1 0 1 9 4 5 2 4
and
(3) If the result of the addition operation exceeds 99999999, the upper bits will be ignored.
The carry flag in this case does not go ON.
9 9 0 0 0 0 0 0
0 1 6 5 4 3 2 1
0 0 6 5 4 3 2 1
DB(1) Subtracts the BCD 8-digit data designated by D and the BCD 8-digit data designated by
and stores the result of the subtraction at the device designated by D .
D +1
S +1
0 9 8 7 1 0 6 8
D +1
0 0 3 2 3 4 5 6
0 9 5 4 7 6 1 2
6 - 32
6 - 32
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
and
(3) The following will result if an underflow is generated by the subtraction operation:
The carry flag in this case does not go ON.
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 9
9 9 9 9 9 9 9 9
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The S or D BCD data is outside the 0 to 99999999 range. (Error code: 4100)
[Program Example]
(1) The following program adds the BCD data 12345600 and 34567000, stores the result at D887
and D888, and at the same time outputs them to from Y30 to Y4F.
[Ladder Mode]
Stores 12345600 at D887,D888 as BCD
Adds BCD 34567000 and D887,D888
and stores the result in D887,D888
Outputs data at D887,D888 to Y30 to Y4F
[List Mode]
Steps
Instruction
Device
(2)The following program subtracts the BCD data 98765432 from 12345678, stores the result at
D100 and D101, and at the same time outputs it from Y30 to Y4F.
[Ladder Mode]
Stores 98765432 at D100,D101 as BCD data.
Subtracts 12345678 from data in D100,D101
and stores result as BCD data at D100,D101
Outputs data at D100,D101 to Y30 to Y4F
[Ladder Mode]
Steps
6 - 33
Instruction
Device
6 - 33
6 BASIC INSTRUCTIONS
Set
Data
Internal Devices
(System, User)
Bit
MELSEC-Q/QnA
Usable Devices
MELSECNET/10(H)
Special
Direct J \
Function
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S1
S2
Command
DB+
DB -
S1
S2
S1
S2
Command
DB+P
DB - P
[Set Data]
Set Data
S1
S2
Meaning
Data to be added to or subtracted from, or the head number of the device
storing such data
Addition or subtraction data, or head number of device storing addition or
subtraction data
Head number of device storing addition or subtraction data
Data Type
BCD 8-digit
[Functions]
DB+
(1) Adds the BCD 8-digit data designated by S1 and the BCD 8-digit data designated by
stores the result of the addition at the device designated by D .
S1
+1
S1
S2
5 6 7 8 9 1 2 3
+1
S2
+1
S2
, and
0 1 2 3 4 5 6 7
5 8 0 2 3 6 9 0
S1
S2
, and
(3) If the result of the addition operation exceeds 99999999, the upper bits will be ignored.
The carry flag in this case does not go ON.
9 9 0 0 0 0 0 0
6 - 34
0 1 6 5 4 3 2 1
0 0 6 5 4 3 2 1
6 - 34
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
DB(1) Subtracts the BCD 8-digit data designated by S1 and the BCD 8-digit data designated by
and stores the result of the subtraction at the device designated by D .
S1
+1
S1
S2
5 6 7 8 9 1 2 3
+1
S2
+1
S2
0 1 2 3 4 5 6 7
5 5 5 5 4 5 5 6
S1
S2
, and
(3) The following will result if an underflow is generated by the subtraction operation:
The carry flag in this case does not go ON.
1 2 3 4 5 6 7 8
1 2 3 4 5 6 7 9
9 9 9 9 9 9 9 9
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The S1 , S2 , or D BCD data is outside the 0 to 99999999 range. (Error code: 4100)
[Program Example]
(1) The following program adds the BCD data at D3 and D4 to the BCD data at Z1 and Z2 when
X20 goes ON, and stores the result at R10 and R11.
[Ladder Mode]
[List Mode]
Steps
6 - 35
Instruction
Device
6 - 35
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S1
S2
or B/
Command
B , B/
S1
S2
S1
S2
Command
P
B P, B/P
[Set Data]
Set Data
Meaning
Data that will be multiplied or divided, or the head number of the device
storing data that will be multiplied or divided
Data to multiply or divide by, or the head number of device storing such
data
Head number of the device storing the operation results of multiplication
or division operation
S1
S2
Data Type
BCD 4-digit
BCD 8-digit
[Functions]
B
(1) Multiplies BCD data designated by
the device designated by D .
S1
S1
S2
S1
and
S2
S2
D +1
(Upper 4 digits)
(Lower 4 digits)
B/
(1) Divides BCD data designated by
the device designated by D .
S1
S1
S2
S2
D +1(Remainder)
6 - 36
6 - 36
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(2) Uses 32 bits to store the result of the division as quotient and remainder
Quotient
(BCD 4 digits) .................. Stored at the lower 16 bits
Remainder (BCD 4 digits) .................. Stored at the upper 16 bits
(3) If
has been designated as a bit device, the remainder of the operation will not be stored.
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The S1 or S2 data is outside the 0 to 9999 range. (Error code: 4100)
Attempt to divide S2 by 0. (Error code: 4100)
[Program Example]
(1) The following program multiplies the BCD data at X0 to XF and the BCD data at D8 when X0B
goes ON, and stores the result at D0 and D1.
[Ladder Mode]
[List Mode]
D8
XF- - - - - - - - - - X0
9
7
5
3
Multiplie
Multiplicand
Device
Instruction
Steps
Multiplication result
(2) The following program divides 5678 by the BCD data 1234, stores the result at D502 and
D503, and at the same time outputs the quotient to Y30 to Y3F.
[Ladder Mode]
[List Mode]
Device
Instruction
Steps
D502
5
D503
4
Quotient
Remainder
Y3F- - - - - - - - -Y30
0
0
0
4
Quotient
6 - 37
6 - 37
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S1
S2
or DB/
Command
DB , DB/
S1
S2
S1
S2
Command
DB P,DB/P
[Set Data]
Set Data
S1
S2
Meaning
Data that will be multiplied or divided, or the head number of the device
storing data that will be multiplied or divided
Data to multiply or divide by, or the head number of device storing such
data
Head number of the device storing the operation results of multiplication
or division operation
Data Type
BCD 8 digits
BCD 16 digits
[Functions]
DB
(1) Multiplies the BCD 8-digit data designated by S1 and the BCD 8-digit data designated by
and stores the product at the device designated by D .
S1
+1
9
S1
S2
D +3
+1
9
S2
D +2
S2
D +1
(2) If D has designated a bit device, the lower 8 digits (lower 32 bits) will be used for the product,
and the higher 8 digits (upper 32 bits) cannot be designated.
K1 . . . Lower 1 digit (b0 to 3)
K4 . . . Lower 4 digits (b0 to 15)
K8 . . . Lower 8 digits (b0 to 31)
(3) The values for
6 - 38
S1
and
S2
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
DB/
(1) Divides 8-digit BCD data designated by S1 and 8-digit BCD data designated by
the result in the device designated by D .
S1
+1
7
S1
S2
+1
2
S2
, and stores
S2
D
D +3
(Lower 4 digits) Remain- (Upper 4 digits)
der
0
0
4
5
0
1
2
3
D +2
(Lower 4 digits)
(2) 64 bits are used for the result of the division operation, and stored as quotient and remainder.
Quotient
(BCD 8 digits) .................. Stored at the lower 32 bits
Remainder (BCD 8 digits) .................. Stored at the upper 32 bits
(3) If
has been designated as a bit device, the remainder of the operation will not be stored.
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The S1 or S2 data is outside the 0 to 99999999 range. (Error code: 4100)
Attempt to divide S2 by 0. (Error code: 4100)
[Program Example]
(1) The following program multiplies the BCD data 67347125 and 573682, stores the result from
D502 to D505, and at the same time outputs the upper 8 digits to Y30 to Y4F.
[Ladder Mode]
[List Mode]
6 8 3 4 7 1 2 5
0 0 5 7 3 6 8 2
Multiplicand
Multiplier
Device
Instruction
Steps
D505
D504
D503
D502
0 0 3 9
2 0 9 5
1 5 3 6
4 2 5 0
Y4F- - - - - - - - - -Y30
0 0 3 9 2 0 9 5
(2) The following program divides the BCD data from X20 to 3F by the BCD data at D8 and D9
when X0B goes ON, and stores the result from D765 to D768.
[Ladder Mode]
[List Mode]
X3F- - - - - - - - - - - - - - - - - - - - - - -X20
9
9
8
6
4
3
2
1
D9(Upper 4 digits)
/
D8(Lower 4 digits)
3
Divider
Multiplicand
D766
(Upper 4 digits)
D765
(Lower 4 digits)
D768
(Upper 4 digits)
D767
(Lower 4 digits)
Quotient
6 - 39
Device
Instruction
Steps
Remainder
6 - 39
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
6.2.9 Addition and subtraction of floating decimal point data (E+, E+P, E-, E-P)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
E
Other
S
D
Command
E+, E -
Command
P
E+P, E - P
[Set Data]
Set Data
S
D
Meaning
Data Type
Real number
[Functions]
E+
(1) Adds the floating decimal point type real number designated at D and the floating decimal
point type real number designated at S , and stores the sum in the device designated at D .
D +1
S +1
D +1
+
Floating decimal point
type real number
(2) Values which can be designated at S and D and which can be stored, are as follows:
0, 2-126 | Designated value (stored value) | < 2128
6 - 40
6 - 40
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
E(1) Subtracts a floating decimal point type real number designated by D and a floating decimal
point type real number designated by S , and stores the result at a device designated by D .
D +1
S +1
D +1
(2) Values which can be designated at S and D and which can be stored, are as follows:
0, 2-126 | Designated value (stored value) | < 2128
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The contents of the designated device or the result of the addition or subtraction operation
are not "0", or not within the following range: (Error code: 4100)
2-126 | Contents of designated device/operation result | < 2128
When the specified device contains -0 (Q4ARCPU)
(Operation error does not occur even if -0 is stored if SM707 is turned on.) (Error code: 4100)
[Program Example]
(1) The following program adds the floating decimal point type real numbers at D3 and D4 and the
floating decimal point type real numbers at D10 and D11 when X20 goes ON, and stores the
result at D3 and D4.
[Ladder Mode]
[List Mode]
Steps
D4
D3
5961.437
D11
+
D10
12003.2
Instruction
D4
Device
D3
17964.64
(2) The following program subtracts the floating decimal point type real number at D10 and D11
from the floating decimal point type real numbers at D20 and D21, and stores the result of the
subtraction at D20 and D21.
[Ladder Mode]
[List Mode]
Steps
D21
D20
97365.2
6 - 41
D11
D10
76059.8
Instruction
Device
D21
D20
21305.41
6 - 41
6 BASIC INSTRUCTIONS
Internal Devices
(System, User)
Set
Data
Bit
MELSEC-Q/QnA
Usable Devices
MELSECNET/10(H)
Special
Direct J \
Function
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
E
Other
S1
S2
Command
E+, E-
S1
S2
S1
S2
Command
E+P, E-P
[Set Data]
Set Data
S1
S2
Meaning
Data Type
Real number
[Functions]
E+
(1) Adds the floating decimal point type real number designated by S1 and the floating decimal
point type real number designated by S2 , and stores the result at the device designated by
S1
+1
S1
S2
+1
S2
D +1
D.
+
Floating decimal point
type real number
(2) Values that can be designated by S1 , S2 or D and values that can be stored, are as follows:
0, 2-126 | Designated value (stored value) | < 2128
6 - 42
6 - 42
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
E(1) Subtracts the floating decimal point type real number designated by S1 from the floating
decimal point type real number designated by S2 , and stores the result at the device
designated by D .
S1
+1
S1
S2
+1
D +1
S2
(2) Values that can be designated by S1 , S2 or D and values that can be stored, are as follows:
0, 2-126 | Designated value (stored value) | < 2128
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The contents of the designated device or the result of the addition or subtraction operation
are not "0", or not within the following range: (Error code: 4100)
0, 2-126 | Contents of designated device/ result of operation | < 2128
When the specified device contains -0 (Q4ARCPU)
(Operation error does not occur even if -0 is stored if SM707 is turned on.) (Error code: 4100)
[Program Example]
(1) The following program adds the floating decimal point type real numbers at D3 and D4 and the
floating decimal point type real numbers at D10 and D11 when X20 goes ON, and outputs the
result to R0 and R1.
[Ladder Mode]
[List Mode]
P
X20
Steps
E+
D3
D10
0
1
LD
E+P
END
X20
D3
D10
R0
END
D4
D11
D3
5961.437
Device
Instruction
R0
D4
D10
12003.2
D3
17964.64
(2) The following programs subtracts the floating decimal point type real numbers at D20 and D21
from the floating decimal point type real numbers at D11 and D10, and stores the result at D30
and D31.
[Ladder Mode]
0
SM400
[List Mode]
P
E-
Steps
D10
D20
D10
97365.2
6 - 43
0
1
LD
E-P
END
SM400
D10
D20
D30
END
D11
D21
-
Device
Instruction
D30
D20
76059.8
D21
D20
21305.41
6 - 43
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
File
Register
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
E
Other
U
S1
S2
or E/
Command
E , E/
S1
S2
S1
S2
Command
P
E P, E/P
[Set Data]
Set Data
S1
S2
Meaning
Data Type
Data that will be multiplied or divided, or the head number of the device
storing data that will be multiplied or divided
Data to multiply or divide by, or the head number of device storing such
data
Head number of the device storing the operation results of multiplication
or division operation
Real number
[Functions]
E
(1) Multiplies the floating decimal point type real numbers designated by S1 and the floating
decimal point type real numbers designated by S2 , and stores the product at the device
designated by D .
S1
+1
S1
S2
+1
S2
D +1
(2) Values that can be designated by S1 , S2 or D , and values that can be stored, are as follows:
0, 2-126 | Designated value (stored value) | < 2128
6 - 44
6 - 44
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
E/
(1) Divides floating decimal point type real numbers designated by S1 by floating decimal point
type real numbers designated by S2 , and stores the result in the device designated by D .
S1
+1
S1
S2
+1
S2
D +1
/
Floating decimal point
type real number
(2) Values that can be designated by S1 , S2 or D , and values that can be stored, are as follows:
0, 2-126 | Designated value (stored value) | < 2128
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The contents of the designated device or the result of the multiplication or division operation
are not "0", or not within the following range: (Error code: 4100)
0, 2-126 | Contents of designated device/results of operation | < 2128
When the specified device contains -0 (Q4ARCPU)
(Operation error does not occur even if -0 is stored if SM707 is turned on.) (Error code: 4100)
[Program Example]
(1) The following program multiplies the floating decimal point real numbers at D3 and D4 and the
floating decimal point real numbers at D10 and D11, and stores the result at R0 and R1.
[Ladder Mode]
[List Mode]
Steps
D4
D3
D11
36.78965
D10
11.92786
Device
Instruction
R1
R0
438.8218
(2) The following program divides the floating decimal point real numbers at D10 and D11 by the
floating decimal point real numbers at D20 and D21, and stores the result at D30 and D31.
[Ladder Mode]
[List Mode]
Steps
D11
D10
52171.39
6 - 45
D21
/
D20
9.73521
Device
Instruction
D31
D30
5359.041
6 - 45
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
S1
S2
n
[Instruction Symbol] [Execution Condition]
Command
BK+, BK -
S1
S2
S1
S2
Command
BK+P, BK - P
[Set Data]
Set Data
Meaning
Data to be added to or subtracted from, or head number of device storing
such data
Addition or subtraction data, or head number of device storing addition or
subtraction data
Head number of the devices where the operation results are stored
S1
S2
Data Type
BIN 16 bits
[Functions]
BK+
(1) Adds n-points of BIN data from the device designated by S1 and n-points of BIN data from the
device designated by S2 and stores the result from the device designated by D onward.
S1
S1
S1
S1
S1
+1
+2
+(n-2)
+(n-1)
b15 - - - - - - - b0
1234 (BIN)
4567 (BIN)
-2000 (BIN)
-1234 (BIN)
4000 (BIN)
S2
S2
S2
S2
S2
+1
+2
+(n-2)
+(n-1)
b15 - - - - - - - b0
4000 (BIN)
1234 (BIN)
-1234 (BIN)
5000 (BIN)
4321 (BIN)
D
D +1
D +2
D +(n-2)
D +(n-1)
b15 - - - - - - - b0
5234 (BIN)
5801 (BIN)
-3234 (BIN)
3766 (BIN)
8321 (BIN)
6 - 46
6 - 46
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
S1
S1
+1
+2
b15 - - - - - - - b0
1234 (BIN)
4567 (BIN)
-2000 (BIN)
S2
D +1
b15 - - - - - - - b0
4321 (BIN)
S2
D +2
-1234 (BIN)
4000 (BIN)
+(n-2)
+(n-1)
D +(n-2)
D +(n-1)
b15 - - - - - - - b0
5555 (BIN)
8888 (BIN)
2321 (BIN)
3087 (BIN)
8321 (BIN)
(4) The following happens if an underflow or overflow is generated in the operation results:
The carry flag in this case does not go ON.
K32767
(H7FFF)
K-32767
(H8000)
+K2
(H0002)
+K-2
(HFFFE)
K-32767
(H8001)
K32766
(H7FFE)
BK
(1) Subtracts n-points of BIN data from the device designated by S1 and n-points of BIN data from
the device designated by S2 and stores the result from the device designated by D onward.
S1
S1
S1
S1
S1
+1
+2
+(n-2)
+(n-1)
b15 - - - - - - - b0
8765 (BIN)
8888 (BIN)
9325 (BIN)
5000
4352
S2
S2
(BIN)
(BIN)
S2
S2
S2
+1
+2
+(n-2)
+(n-1)
b15 - - - - - - - b0
1234 (BIN)
5678 (BIN)
9876 (BIN)
D
D +1
4321 (BIN)
4000 (BIN)
D +2
D +(n-2)
D +(n-1)
b15 - - - - - - - b0
7531 (BIN)
3210 (BIN)
-551 (BIN)
679
352
(BIN)
(BIN)
S1
S1
+1
+2
+(n-2)
+(n-1)
b15 - - - - - - - b0
8765 (BIN)
8888 (BIN)
9325 (BIN)
5000
4352
S2
S2
b15 - - - - - - - b0
8880 (BIN)
(BIN)
(BIN)
D +1
D +2
D +(n-2)
D +(n-1)
b15 - - - - - - - b0
-115 (BIN)
8 (BIN)
445 (BIN)
-3880 (BIN)
-4528 (BIN)
(4) The following happens if an underflow or overflow is generated in the operation results:
The carry flag in this case does not go ON.
K-32768
(H8000)
K32767
(H8000)
-K2
(H0002)
-K-2
(H0002)
K32766
(H7FFF)
-32766
(H8001)
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The n-bit range from the S1 , S2 , or D device exceeds the range of that device.
The device range for n points starting from the device designated by S1 overlaps with the
device range for n points starting from the device designated by D . (Error code: 4101)
The device range for n points starting from the device designated by S2 overlaps with the
device range for n points starting from the device designated by D . (Error code: 4101)
The device range for n points starting from the device designated by S1 overlaps with the
device range for n points starting from the device designated by S2 . (Error code: 4101)
6 - 47
6 - 47
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
(1) When X20 is ON, the program performs additions of the following data:
The data in the number (value stored in D0) of devices starting from D100
The data in the number (value stored in D0) of devices starting from R100
Then the program stores the addition results at the number (value stored in D0) of devices
starting from D200.
[Ladder Mode]
[List Mode]
Steps
D100
D101
D102
D103
b15 - - - - - - - b0
6789 (BIN)
7821 (BIN)
5432 (BIN)
3520 (BIN)
D0
R0
R1
R2
R3
Instruction
b15 - - - - - - - b0
1234 (BIN)
2032 (BIN)
-3252 (BIN)
-1000 (BIN)
Device
D200
D201
D202
D203
b15 - - - - - - - b0
8023 (BIN)
9853 (BIN)
2180 (BIN)
2520 (BIN)
(2) When X1C is ON, the following program subtracts the constant 8765 from the data in three
devices starting from D100.
Then the program stores the subtraction results at the number of the three devices starting
from R0
[Ladder Mode]
[List Mode]
Steps
Device
Instruction
K8765
K3
5
b15 - - - - - - - b0
D100 12345 (BIN)
D101 8701 (BIN)
D102 3502 (BIN)
6 - 48
b15 - - - - - - - b0
8765 (BIN)
R0
R1
R2
b15 - - - - - - - b0
3580 (BIN)
-64 (BIN)
-5263 (BIN)
6 - 48
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
$
Other
S
D
$+
$+P
Command
$+P
[Set Data]
Set Data
Meaning
Data Type
Character string
[Functions]
(1) Character string data stored in device numbers starting with that designated at S will be
appended after character string data stored in device numbers starting with that designated at
D , and will be stored in device numbers starting with that designated at D .
The object of character string data is that character string data stored from device numbers
designated at D and S to that stored at "00H".
b15 - - - b8 b7 - - - - b0
42H (B) 41H (A)
43H (C)
D +1 44H (D)
00H
45H (E)
D +2
D
"ABCDE"
b15 - - - b8 b7 - - - - b0
32H (2) 31H (1)
S +1 34H (4)
33H (3)
S +2 36H (6)
35H (5)
S +3
00H
S
"123456"
D +1
D +2
D +3
D +4
D +5
b15 - - - b8 b7 - - - - b0
42H (B) 41H (A)
44H (D) 43H (C)
31H (1) 45H (E)
33H (2) 32H (2)
35H (3) 34H (4)
36H (6)
00H
"ABCDE123456"
(2) When character strings are linked, the "00H", which indicates the end of character string data
designated at D , is ignored, and the character string designated at S is appended to the last
character of the D string.
6 - 49
6 - 49
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD.
The entire character string linked from the device number designated by D to the final device
number of the relevant device cannot be stored.
(Error code: 4100)
The storage device numbers for the character strings designated by S and D overlap.
(Error code: 4101)
(2) See Section 3.6 for information regarding errors during index modification.
[Program Example]
(1) The following program links the character string stored from D10 to D12 to the character string
"ABCD" when X0 is ON.
[Ladder Mode]
[List Mode]
Steps
D10
D11
D12
b15 - - - b8 b7 - - - - b0
62H (b) 61H (a)
66H (d) 63H (c)
00H
65H (e)
"ABCD"
Instruction
D10
D11
D12
D13
D14
Device
b15 - - - b8 b7 - - - - b0
62H (b) 61H (a)
64H (d) 63H (c)
41H (A) 65H (e)
43H (C) 42H (B)
00H
44H (D)
6 - 50
6 - 50
6 BASIC INSTRUCTIONS
Internal Devices
(System, User)
Set
Data
Bit
Word
MELSEC-Q/QnA
Usable Devices
MELSECNET/10(H)
Special
Direct J \
Function
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
$
Other
S1
S2
$+
S1
S2
$+P
S1
S2
Command
$+P
[Set Data]
Set Data
Meaning
Data Type
S1
S2
Character string
[Functions]
(1) Appends character string data stored from the device number designated by S2 to the
character string data stored from the device number designated by S1 , and stores it from the
device number designated by D1 .
S1
S1
S1
b15 - - - b8 b7 - - - - b0
46H (F) 48H (H)
+1 2DH ( - ) 41H (A)
00H
+2
S2
S2
S2
b15 - - - b8 b7 - - - - b0
35H (5) 31H (1)
+1 39H (9) 33H (3)
00H
41H (A)
+2
D
D +1
D +2
D +3
D +4
b15 - - - b8 b7 - - - - b0
46H (F) 48H (H)
2DH ( - ) 41H (A)
35H (5) 31H (1)
39H (9) 33H (3)
00H
41H (A)
(2) When character strings are linked, the "00H" which indicates the end of character string data
indicated by S1 , is ignored, and the character string indicated by S2 is appended to the last
character of the S1 string.
6 - 51
6 - 51
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs and the error flag goes ON.
The entire character string linked from the device number designated by D to the final device
number of the relevant device cannot be stored.
The storage device numbers for the character strings designated by S1 or S2 overlap with
those for D .
[Program Example]
(1) The following program links the character string stored from D10 to D12 with the character
string "ABCD" when X0 is ON, and stores them in D100 onwards.
[Ladder Mode]
[List Mode]
Steps
b15 - - - b8 b7 - - - - b0
D10 62H (b) 61H (a)
D11 64H (d) 63H (c)
65H (e)
00H
D12
"ABCD"
Instruction
D100
D101
D102
D103
D104
Device
b15 - - - b8 b7 - - - - b0
62H (b) 61H (a)
64H (d) 63H (c)
41H (A) 65H (e)
43H (C) 42H (B)
00H
44H (D)
6 - 52
6 - 52
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
Command
INC, DEC
Command
P
INCP, DECP
[Set Data]
Set Data
D
Meaning
Data Type
BIN 16 bits
[Functions]
INC
(1) Adds 1 to device designated by
(16-bit data).
b15- - - - - - - - - b0
5678 (BIN)
+1
b15- - - - - - - - - b0
5679 (BIN)
(2) If the contents of the device designated by D were 32767, and the INC or INCP instruction
were executed on that device, the value -32768 would be stored in the device designated by
D.
DEC
(1) Subtracts 1 from device designated by
D
b15- - - - - - - - - b0
5678 (BIN)
-1
(16-bit data).
D
b15- - - - - - - - - b0
5677 (BIN)
(2) If the contents of the device designated by D were 0, and the DEC or DECP instruction were
executed on that device, the value -1 would be stored in the device designated by D .
[Operation Errors]
(1) There are no operation errors associated with the INC, INCP, DEC or DECP instructions.
6 - 53
6 - 53
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
(1) The present value stored in counter C0 to C20 is output to Y30 to Y3F as BCD data when X8
is on. (When present value is less than 9999)
[Ladder Mode]
Outputs the present value of C (D+Z1)
to Y30 to Y3F as BCD.
Executes Z1+1
With Z1=21 or X7 (reset input), sets Z to 0
[List Mode]
Steps
Instruction
Device
[List Mode]
Steps
6 - 54
Instruction
Device
6 - 54
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
indicates DINC/DDEC
Command
D
Command
P
DINCP, DDECP
[Set Data]
Set Data
D
Meaning
Data Type
Head number of device what will execute the DINC (+1) or DDEC (-1)
operation
BIN 32 bits
[Functions]
DINC
(1) Adds 1 to the device designated by
D +1
(32-bit data).
D +1
(2) If the contents of the device designated by D are 2147483647, and the DINC or DINCP
instruction is executed, the value -2147483648 will be stored at the device designated by
D.
DDEC
(1) Subtracts 1 from the device designated by
D +1
(32-bit data).
D +1
(2) If the contents of the device designated by D are 0, and the DINC or DINCP instruction is
executed, the value -1 will be stored at the device designated by D .
[Operation Errors]
(1) There are no operation errors associated with DINC(P) or DDEC(P).
6 - 55
6 - 55
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
(1) The following program adds 1 to the data at D0 and D1 when X0 is ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program adds 1 to the data set at X10 to X27 when X0 goes ON, and stores the
result at D3 and D4.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(3) The following program subtracts 1 from the data at D0 and D1 when X0 goes ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(4) The following program subtracts 1 from the data set at X10 to X27 when X0 goes ON, and
stores the result at D3 and D4.
[Ladder Mode]
[List Mode]
Steps
6 - 56
Instruction
Device
6 - 56
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
S
D
Command
BCD, DBCD
Command
P
BCDP, DBCDP
[Set Data]
Set Data
Meaning
Data Type
BIN data, or head number of the device where BIN data is stored
[Functions]
BCD
Converts BIN data (0 to 9999) at the device designated by
device designated by D .
-32768 16384 8192 4096 2048 1024 512
BIN 9999
256
128
64
32
16
D BCD 9999
Thousands
digits
BCD conversions
400
200
100
80
40
20
10
Hundreds
digits
Tens
digits
Ones
digits
DBCD
Converts BIN data (0 to 99999999) at the device designated by
at the device designated by D .
S (Lower 16 bits)
231
230
229
228
227
226
225
224
223
222
221
220
219
218
217
216
215
214
213
212
211
210
29
28
27
26
25
24
23
22
21
20
S +1 (Upper 16 bits)
100
101
104
105
106
10
8
4
2
1
8
4
2
1
8
4
2
1
8
4
2
1
8
4
2
1
8
4
2
1
8
4
2
1
8
4
2
1
102
BCD
conversions
103
S BIN 99999999
D BCD 99999999 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1
Ten
millions
digits
D +1(Upper 4 digits)
6 - 57
Tens
digits
Ones
digits
D (Lower 4 digits)
6 - 57
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The data at S was not in the 0 to 9999 range when the BCD instruction was issued.
(Error code: 4100)
The data at S +1 and S was not in the 0 to 99999999 range when the DBCD instruction was
issued.
(Error code: 4100)
[Program Example]
(1) The following program outputs the present value of C4 from Y20 to Y2F to the BCD display
device.
Output power
supply
0 1 0 1
80
40
20
10
0 1 1 0
0 1 1 1
Y23
Y22
Y21
Y20
8
4
2
1
Y27
Y26
Y25
Y24
Y2B
Y2A
Y29
Y28
800
400
200
100
8000
4000
2000
1000
COM
Y2F
Y2E
Y2D
Y2C
1 0 0 0
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program outputs 32-bit data from D0 to D1 to Y40 to Y67.
PLC Output Module
Y67 to Y64
Y63 to Y60
Y5F to Y5C
Y5B to Y58
Y57 to Y54
Y53 to Y50
Y4F to Y4C
Y4B to Y48
Y47 to Y44
Y43 to Y40
Output
power
supply
[Ladder Mode]
[List Mode]
Steps
6 - 58
Instruction
Device
6 - 58
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
6.3.2 Conversion from BCD 4-digit and 8-digit data to BIN data
(BIN, BINP, DBIN, DBINP)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
U
S
D
Command
BIN, DBIN
Command
P
BINP, DBINP
[Set Data]
Set Data
Meaning
Data Type
[Functions]
BIN
Converts BCD data (0 to 9999) at device designated by
designated by D .
8000 4000 2000 1000 800
BCD 9999 1
400
200
100
80
40
20
10
Tens digits
Ones digits
BIN conversions
32768 16384 8192 4096 2048 1024 512
256
128
64
32
16
BIN 9999
DBIN
100
101
102
103
104
105
106
8
4
2
1
8
4
2
1
8
4
2
1
8
4
2
1
8
4
2
1
8
4
2
1
8
4
2
1
8
4
2
1
107
S +1
S BCD 99999999 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1
Ten millions Millions Hundred Ten
Thousands Hundreds Ten digits Ones digits
digits
digits
thousands thousands digits
digits
digits
digits
BIN conversions
D
231
230
229
228
227
226
225
224
223
222
221
220
219
218
217
216
215
214
213
212
211
210
29
28
27
26
25
24
23
22
21
20
D +1
D BIN 99999999
0 0 0 0 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 0 0 0 0 0 1 1 1 1 1 1 1 1
Always set these to 0
6 - 59
6 - 59
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases, an operation error occurs, the error flag (SM0) turns ON, an error code
is stored in SD0, and the instruction is not executed.
When values other than 0 to 9 are designated to any digits of S .
[When QCPU is used]
When QCPU is used, the error above can be suppressed by turning ON SM722.
However, the instruction is not executed regardless of whether SM722 is turned ON or OFF if
the designated value is out of the available range.
For BCDP/DBCDP instructions, the next operation is disabled regardless of the presence of
errors unless the execution condition is turned from OFF to ON.
[Operation Example]
(1) The following program converts the BCD data at X10 to X1B to BIN when X8 is ON, and stores
it at D8.
8
4
2
1
COM
0
X13
1
X12
1
X11
0
X10
80
40
20
10
COM
0
X17
0
X16
1
X15
1
X14
0
X1B
0
X1A
1
X19
0
X18
COM
X1F
X1E
X1D
X1C
Input
power
supply
Can be
used at
other
800
400
200
100
COM
Digital
switch BCD
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program converts the BCD data at X10 to X37 to BIN when X8 is ON, and stores
it at D0 and D1.
BCD digital switch
X37 to X34 X33 to X30 X2F to X2C X2B to X28 X27 to X24 X23 to X20 X1F to X1C X1B to X18 X17 to X14 X13 to X10
Input
power
supply
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
If the data set at X10 to X37 is a BCD value which exceeds 2147483647, the value at D0 and D1
will be a negative value, because it exceeds the range of numerical values that can be handled by
a 32-bit device.
6 - 60
6 - 60
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
6.3.3 Conversion from BIN 16 and 32-bit data to floating decimal point
(FLT, FLTP, DFLT, DFLTP)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
S
D
Command
FLT, DFLT
Command
FLTP, DFLTP
[Set Data]
Set Data
S
D
Meaning
Head device number where integer data for the purpose of conversion to
floating decimal point data is being stored
Head device number that will store converted floating decimal point data
Data Type
BIN 16/32 bits
Real number
[Functions]
FLT
(1) Converts 16-bit BIN data designated by S to floating decimal point type real number, and
stores at device number designated by D .
D +1
BIN 16 bits
Floating decimal point
type real number
DFLT
(1) Converts 32-bit BIN data designated by S to floating decimal point type real number, and
stores at device number designated by D .
S +1
BIN 32 bits
D +1
6 - 61
+1 and
6 - 61
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(3) Due to the fact that floating decimal point type real numbers are processed by simple 32-bit
processing, the number of significant digits is 24 bits if the display is binary and approximately
7 digits if the display is decimal.
For this reason, if the integer exceeds the range of -16777216 to 16777215 (24-bit BIN value),
errors can be generated in the conversion value.
The conversion results round off at the 25th bit from the highest bit of the integer value, and
eliminate everything from the 26th bit and beyond.
Integer value
b31- - - - - - -b24b23- - - - - - -b16 b15- - - - - - - -b8b7- - - - - - - - b0
222030030 0 0 0 0 1 1 0 1 0 0 1 1 1 0 1 1 1 1 1 1 1 0 0 0 1 1 0 0 1 1 1 0
After conversion
Becomes 222030032
Eliminated
Rounded off
Becomes 372588912
Eliminated
Rounded off
[Operation Errors]
(1) There are no errors associated with the FLT (P) or DFLT (P) instructions.
[Program Example]
(1) The following program converts the BIN 16-bit data at D20 to a floating decimal point type real
number and stores the result at D0 and D1.
[Ladder Mode]
[List Mode]
Instruction
Steps
D20
Integer
conversion
D1
Device
D0
15923
15923
BIN value
(2) The following program converts the BIN 32-bit data at D20 and D21 to a floating decimal point
type real number, and stores the result at D0 and D1.
[Ladder Mode]
[List Mode]
Instruction
Steps
D21
D20
Integer
conversion
16543521
D20
173963112
BIN value
6 - 62
D0
16543521
Floating decimal point type real number
BIN value
D21
D1
Device
Integer
conversion
An error is generated in the operation results
because there are 7 significant digits
D1
D0
173963120
Floating decimal point type real number
6 - 62
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
6.3.4 Conversion from floating decimal point data to BIN 16- and 32-bit data
(INT, INTP, DINT, DINTP)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
E
Other
S
D
Command
INT, DINT
Command
INTP, DINTP
[Set Data]
Set Data
S
D
Meaning
Head device number storing floating decimal point data that will be
converted to BIN value
Head device number to store BIN value after conversion
Data Type
Real number
BIN 16/32 bits
[Functions]
INT
(1) Converts the floating decimal point real number designated at
stores it at the device number designated at D .
S +1
BIN 16 bits
Floating decimal point type real number
(2) The range of floating decimal point type real numbers that can be designated at
from -32768 to 32767.
(3) Stores integer values stored at
+1 or
is
(4) After conversion, the first digit after the decimal point of the real number is rounded off.
DINT
(1) Converts floating decimal point type real number designated by
stores the result at the device number designated by D .
S +1
6 - 63
D +1
BIN 32 bits
6 - 63
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(2) The range of floating decimal point type real numbers that can be designated at
from -2147483648 to 2147483647.
(3) The integer value stored at
D +1
and
+1 or
is
(4) After conversion, the first digit after the decimal point of the real number is rounded off.
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The floating decimal point type data designated by S when the INT instruction was used was
outside the -31768 to 32767 range.
The floating decimal point type data designated by S when the DINT instruction was used
was outside the -2147483648 to 2147483647 range.
[Program Example]
(1) The following program converts the floating decimal point type real number at D20 and D21 to
BIN 16-bit data, and stores the result at D0.
[Ladder Mode]
[List Mode]
Steps
D21
D20
25915.6796
Integer
conversion
Instruction
Device
D0
25916
(2) The following program converts the floating decimal point type real number at D20 and D21 to
BIN 32-bit data and stores the result at D0 and D1.
[Ladder Mode]
[List Mode]
Steps
D21
D20
-574968.321
Integer
conversion
Instruction
Device
D1
D0
-574968
BIN value
Floating decimal point type real number
Integer
D21
D20
conversion
Because the set data is larger than
2147483649.22
2147483647, an operation error is returned.
Floating decimal point type real number
6 - 64
6 - 64
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
6.3.5 Conversion from BIN 16-bit to BIN 32-bit data (DBL, DBLP)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
S
D
DBL
DBLP
Command
DBLP
[Set Data]
Set Data
Meaning
Data Type
BIN 16 bits
Head number of device where BIN 32-bit data is stored after conversion
BIN 32 bits
[Functions]
Converts BIN 16-bit data at device designated by
result at a device designated by D .
D +1
[Operation Errors]
(1) There are no errors associated with the DBL(P) instruction.
[Program Example]
(1) The following program converts the BIN 16-bit data stored at D100 to BIN 32-bit data when
X20 is ON, and stores at R100 and R101.
[Ladder Mode]
[List Mode]
Steps
D100
FB2EH
(-1234)
6 - 65
Instruction
Device
R101 R100
FFFFFB2EH
(-1234)
6 - 65
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
6.3.6 Conversion from BIN 32-bit to BIN 16-bit data (WORD, WORDP)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
S
D
WORD
WORDP
Command
WORDP
[Set Data]
Set Data
S
D
Meaning
Data Type
BIN 32 bits
BIN 16 bits
[Functions]
Converts BIN 32-bit data at device designated by S to BIN 16-bit data with sign, and stores the
result at a device designated by D .
Devices can be designated in the range from -32768 to 32767
S +1
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The contents of the data designated by S +1 and S are outside the -32768 and 32767 range. (Error code: 4100)
[Program Example]
(1) The following program converts the BIN 32-bit data at R100 and R101 to BIN 16-bit data when
X20 is ON, and stores it at D100.
[Ladder Mode]
[List Mode]
WORD R100
D100
Steps
WORD P
R101 R100
FFFF8253H
(-32173)
6 - 66
Device
Instruction
R100
D100
D100
8253H
(-32173)
6 - 66
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
S
D
Command
GRY, DGRY
Command
GRYP, DGRYP
[Set Data]
Set Data
Meaning
Data Type
BIN data, or head number of the device where BIN data is stored
[Functions]
GRY
Converts BIN 16-bit data at the device designated by
designated by D .
16 bits
S BIN
b15
1234 0 0
b0
0
b15
0 0
b0
1
DGRY
Converts BIN 32-bit data at the device designated by
designated by D .
S +1 (upper 16 bits)
S BIN
S (lower 16 bits)
b31
b16 b15
b0
305419896 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0
D +1
b31
b16 b15
b0
6 - 67
6 - 67
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The data at S is a negative number.
[Program Example]
(1) The following program converts the BIN data at D100 to Gray code when X10 is ON, and
stores result at D200.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program converts the BIN data at D10 and D11 to Gray code when X1C is ON,
and stores it at D100 and D101.
[Ladder Mode]
[List Mode]
Steps
6 - 68
Instruction
Device
6 - 68
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
S
D
Command
GBIN, DGBIN
Command
GBINP, DGBINP
[Set Data]
Set Data
Meaning
Data Type
Gray code data or the head number of device where Gray code data is
being stored
Head number of the device to store BIN data after conversion
S
D
Gray code
BIN 16/32 bits
[Functions]
GBIN
Converts Gray code data at device designated by
designated by D .
16 Bits
S Gray code 1234
b15
0 0
b0
1
D BIN
b15
0 0
b0
0
1234
DGBIN
Converts Gray code data at device designated by
designated by D .
S +1 (upper 16 bits)
b31
S (lower 16 bits)
b16 b15
b0
D +1
D BIN
6 - 69
b31
b16b15
b0
305419896 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0
6 - 69
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
Data at S when GBIN instruction was issued is outside the 0 to 32767 range.
Data at S when DGBIN instruction was issued is outside the 0 to 2147483647 range.
[Program Example]
(1) The following program converts the Gray code data at D100 when X10 is ON to BIN data, and
stores the result at D200.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program converts the Gray code data at D10 and D11 to BIN data when X1C is
ON, and stores the result at D0 and D1.
[Ladder Mode]
[List Mode]
Steps
6 - 70
Instruction
Device
6 - 70
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
Command
NEG, DNEG
Command
P
NEGP, DNEGP
[Set Data]
Set Data
D
Meaning
Data Type
[Functions]
NEG
(1) Reverses the sign of the 16-bit device designated by
D.
16 Bit
b15- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -b0
1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ............. -21846
Before execution D
1
Sign conversion
-
After execution D
b15- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -b0
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 ............. 21846
6 - 71
6 - 71
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
DNEG
(1) Reverses the sign of the 32-bit device designated by
D.
32 Bit
b31- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -b0
0 1 0 0 1 0 0 ............. -218460
1 1 1 1 1 1 1
Before execution D
1
Sign conversion
-
After execution D
b31- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -b0
0 0 0 0 0 0 0
1 0 1 1 1 0 0 ............. 218460
[Operation Errors]
(1) There are no operation errors associated with the NEG(P) or DNEG(P) instructions.
[Program Example]
(1) The following program calculates a total for the data at D10 through D20 when XA goes ON,
and seeks an absolute value if the result is negative.
[Ladder Mode]
M3 goes ON if D10 is smaller than D20
Subtracts D20 from D10
Seeks an absolute value (complement
of 2) when M3 is ON
[List Mode]
Steps
0
1
LD
AND<
4
5
6
OUT
LD
-P
8
9
12
6 - 72
Device
Instruction
AND
NEGP
END
X0A
D10
D20
M3
X0A
D20
D10
M3
D10
6 - 72
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
6.3.10 Sign reversal for floating decimal point data (ENEG, ENEGP)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
ENEG
ENEGP
Command
ENEGP
[Set Data]
Set Data
D
Meaning
Data Type
Head number of device storing floating decimal point data for which sign
will be inverted
Real number
[Functions]
(1) Reverses the sign of the floating decimal point type real number data designated by
stores at the device designated by D .
D,
and
[Operation Errors]
(1) There are no errors associated with the ENEG(P) instruction.
[Program Example]
(1) The following program inverts the sign of the floating decimal point type real number data at
D100 and D101 when X20 goes ON, and stores result at D100 and D101.
[Ladder Mode]
[List Mode]
Steps
D101
D100
1.2345
6 - 73
Instruction
D101
Device
D100
-1.2345
6 - 73
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
6.3.11 Conversion from block BIN 16-bit data to BCD 4-digit data
(BKBCD, BKBCDP)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
S
D
n
[Instruction Symbol] [Execution Condition]
Command
BKBCD
BKBCD
BKBCDP
Command
BKBCDP
[Set Data]
Set Data
Meaning
Data Type
Head number of device which will store BCD data after conversion
BIN 16 bits
[Functions]
8192
4096
2048
1024
512
256
128
64
32
16
8
4
2
1
BIN 1234 0 0 0 0 0 1 0 0 1 1 0 1 0 0 1 0
S +1
BIN 5678 0 0 0 1 0 1 1 0 0 0 1 0 1 1 1 0
S +2
BIN 1545 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 1
S +(n-2)
BIN 4321 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1
S +(n-1)
BIN 5555 0 0 0 1 0 1 0 1 1 0 1 1 0 0 1 1
8000
4000
2000
1000
800
400
200
100
80
40
20
10
8
4
2
1
BCD conversions
6 - 74
BCD 1234 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0
D +1
BCD 5678 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0
D +2
BCD 1545 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 1
D +(n-2)
BCD 4321 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1
D +(n-1)
BCD 5555 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
6 - 74
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The range n-points from the device at S or D exceeds the relevant device.
(Error code: 4101)
The data n-points from the device designated by S is outside the 0 to 9999 range.
(Error code: 4100)
The S and D devices overlap.
(Error code: 4101)
(2) See Section 3.6 for information regarding errors during index modification.
[Program Example]
(1) The following program converts BIN 16-bit data the number of points from D100 corresponding
to the value stored at D0 to BCD when X20 goes ON, and stores the result following D200.
[Ladder Mode]
[List Mode]
Device
Instruction
8192
4096
2048
1024
512
256
128
64
32
16
8
4
2
1
Steps
8000
4000
2000
1000
800
400
200
100
80
40
20
10
8
4
2
1
BCD
D0
conversions
6 - 75
6 - 75
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
6.3.12 Conversion from block BCD 4-digit data to block BIN 16-bit data
(BKBIN, BKBINP)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
S
D
n
[Instruction Symbol] [Execution Condition]
Command
BKBIN
BKBIN
BKBINP
Command
BKBINP
[Set Data]
Set Data
Meaning
Data Type
BIN 16 bits
[Functions]
S
8000
4000
2000
1000
800
400
200
100
80
40
20
10
8
4
2
1
D +1
BCD 1234 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0
BCD 5678 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0
D +2
BCD 1545 0 0 0 1 0 1 0 1 0 1 0 0 0 1 0 1
BCD 5555 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
8192
4096
2048
1024
512
256
128
64
32
16
8
4
2
1
BIN conversions
6 - 76
BIN 1234 0 0 0 0 0 1 0 0 1 1 0 1 0 0 1 0
S +1
BIN 5678 0 0 0 1 0 1 1 0 0 0 1 0 1 1 1 0
S +2
BIN 1545 0 0 0 0 0 1 1 0 0 0 0 0 1 0 0 1
S +(n-2)
BIN 4321 0 0 0 1 0 0 0 0 1 1 1 0 0 0 0 1
S +(n-1)
BIN 5555 0 0 0 1 0 1 0 1 1 0 1 1 0 0 1 1
6 - 76
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The range n-points from the S or D device exceeds the relevant device.
The data n-points at the S device is outside the 0 to 9999 range.
The S and D devices overlap.
[Program Example]
(1) The following program converts BCD data the number of points from D100 corresponding to
the value stored at D0 to BIN data when X20 goes ON, and stores the result from D200
onward.
[Ladder Mode]
[List Mode]
Instruction
Device
8000
4000
2000
1000
800
400
200
100
80
40
20
10
8
4
2
1
Steps
8192
4096
2048
1024
512
256
128
64
32
16
8
4
2
1
6 - 77
6 - 77
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S
D
indicates MOV/DMOV
Command
MOV, DMOV
Command
P
MOVP, DMOVP
[Set Data]
Set Data
Meaning
Data Type
[Functions]
MOV
(1) Transfers the 16-bit data from the device designated by
Prior to transfer S
b15
1 0
b0
1 0
D.
Transmission
b15
D
1 0
After transfer
b0
0
DMOV
(2) Transfers 32-bit data at the device designated by
S +1
Prior to transfer S
b15
1 0
6 - 78
b15
1 0
b0 b15
0 0 1
b0
0
b0
0
Transmission D
D +1
After transfer
D.
b0 b15
0 0 1
6 - 78
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the MOV(P) or DMOV(P) instructions.
[Program Example]
(1) The following program stores input data from X0 to XB at D8.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program stores the constant K155 at D8 when X8 goes ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
009BH
b15
b8b7
b0
D8 0 0 0 0 0 0 0 0 1 0 0 1 1 0 1 1
(3) The following program stores the data from D0 and D1 at D7 and D8.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(4) The following program stores the data from X0 to X1F at D0 and D1.
[Ladder Mode]
[List Mode]
Steps
6 - 79
Instruction
Device
6 - 79
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
E
Other
S
D
EMOV
EMOVP
Command
EMOVP
[Set Data]
Set Data
Meaning
Data Type
Real number
[Functions]
(1) Transfers floating decimal point type real number data being stored at the device designated
by S to a device designated by D .
S +1
D +1
Transmission
4.23542
Floating decimal point type real number
4.23542
Floating decimal point type real number
[Operation Errors]
(1) There are no operation errors associated with the EMOV(P) instruction.
6 - 80
6 - 80
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
(1) The following program stores the real numbers at D10 and D11 at D0 and D1.
[Ladder Mode]
[List Mode]
Instruction
Steps
D11
D10
36.475
D1
Device
D0
36.475
(2) The following program stores the real number -1.23 at D10 and D11 when X8 is ON.
[Ladder Mode]
[List Mode]
Instruction
Steps
D11
-1.23
6 - 81
Device
D10
-1.23
6 - 81
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
$
Other
S
D
$MOV
$MOVP
Command
$MOVP
[Set Data]
Set Data
S
D
Meaning
Character string to be transferred (maximum number of characters in a
string: 16 characters for QnA/Q4AR, 32 characters for QCPU), or the
head number of the device storing character string.
Head number of device to store transferred character string
Data Type
Character string
[Functions]
(1) Transfers character string data stored from device number designated by S from device
number designated by D onward.
A character string transfer involves the transfer of data from the device number designated by
S to the device number storing the "00H" code in one operation.
b15
b8 b7
b0
b15
b8 b7
b0
S +1
D +1
S +2
D +2
00H
nth character
00H
nth character
6 - 82
6 - 82
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(2) Processing will be performed without error even in cases where the range for the devices
storing the character data to be transferred ( S to S +n) overlaps with the range of the devices
which will store the character string data after it has been transferred ( D to D +n).
The following occurs when the character string data that had been stored from D10 to D13 is
transferred to D11 to D14:
b15
b8 b7
b0
D10 32H (2) 31H (1)
D11 34H (4) 33H (3)
D12 36H (6) 35H (5)
D13
00H
D14
b15
D10 32H
D11 32H
D12 34H
D13 36H
D14
b8 b7
(2) 31H
(2) 31H
(4) 33H
(6) 35H
00H
b0
(1) ...Remains as the
character string
(1)
it was prior to
(3)
transfer
(5)
b15
b8 b7
b0
42H (B) 41H (A)
D +1 44H (D) 43H (C)
D +2 00H
00H
D
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
There is no "00H" code stored between the device number designated by S and the relevant
device. (Error code: 4101)
It is not possible to store the entire designated character string in the number of points from
the device designated by D to the final device number cited. (Error code: 4101)
[Program Example]
(1) The character string data stored in D10 to D12 is transfered to D20 to D22 when X0 goes ON.
[Ladder Mode]
[List Mode]
Steps
b15
b8 b7
b0
D10 4DH (M) 2AH ( )
D11 45H (E) 45H (E)
00H
D12
6 - 83
Instruction
Device
b15
b8 b7
b0
D20 4DH (M) 2AH ( )
D21 45H (E) 45H (E)
00H
D22
6 - 83
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
6.4.4 16-bit and 32-bit negation transfers (CML, CMLP, DCML, DCMLP)
Internal Devices
(System, User)
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S
D
Command
CML, DCML
Command
P
CMLP, DCMLP
[Set Data]
Set Data
Meaning
Data Type
[Functions]
CML
(1) Inverts 16-bit data designated by
by D .
Before execution S
b15
1 0
After execution
b15
0 1
b0
0
b0
1
Inversion
D
DCML
(1) Inverts 32-bit data designated by
by D .
S +1
Before execution S
b15
1 0
6 - 84
b15
0 1
Inversion
D +1
After execution
b0 b15
0 0 1
b0 b15
1 1 0
b0
0
b0
1
6 - 84
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the CML(P) or DCML(P) instructions.
[Program Example]
(1) The following program inverts the data from X0 to X7, and transfers result to D0.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
b15
b8 b7
b0
D0 1 1 1 1 1 1 1 1 0 0 1 0 1 1 1 1
(2) The following program inverts the data at M16 to M23, and transfers the result to Y40 to Y47.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
M23
M16
01011100
(3) The following program inverts the data at D0 when X3 is ON, and stores the result at D16.
[Ladder Mode]
[List Mode]
Steps
D0
Instruction
Device
b15
b8 b7
b0
110 1100 110 10 1111
b15
b8 b7
b0
D16 0 0 1 0 0 1 1 0 0 1 0 1 0 0 0 0
6 - 85
6 - 85
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(4) The following program inverts the data at X0 to X1F, and transfers results to D0 and D1.
[Ladder Mode]
[List Mode]
Device
Instruction
Steps
X8 X7
0100
b31
b28 b27
b24
D0,1 1 1 1 1 1 0 1 1
X0
0 11100 10 1100
b8 b7
b0
100011010011
(5) The following program inverts the data at M16 to M35, and transfers it to Y40 to Y63.
[Ladder Mode]
[List Mode]
Steps
Device
Instruction
5
M24 M23
0 10 0
Y63
Y56
1 1 1 1 10 1 1
M16
0 1 1 10 0 10 1 10 0
Y48 Y47
Y40
10 0 0 1 10 10 0 1 1
(6) Inverts the data at D0 and D1 when X3 is ON, and stores the result at D16 and D17.
[Ladder Mode]
[List Mode]
Steps
b31
b24
00000100
b8 b7
b0
0 11100 10 1100
b31
b24
D16,D17 1 1 1 1 1 0 1 1
b8 b7
b0
1000 110 100 11
D0,D1
6 - 86
Instruction
Device
6 - 86
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
File
Register
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
S
D
n
[Instruction Symbol] [Execution Condition]
Command
BMOV
BMOV
BMOVP
Command
BMOVP
[Set Data]
Set Data
Meaning
Data Type
BIN 16 bits
[Functions]
(1) Transfers in batch 16-bit data n-points from the device designated by
from the device designated by D .
b15
S
b0
1234H
5678H
7FF0H
S +1
S +2
S +(n-2)
b15
D
D +(n-2)
6FFFH
553FH
S +(n-1)
to location n-points
b0
1234H
5678H
7FF0H
Block
D +1
transmission
D +2
n
6FFFH
553FH
D +(n-1)
(2) Transfers can be accomplished even in cases where there is an overlap between the source
and destination device.
In the case of transmission to the smaller device number, transmission is from S ; for
transmission to the larger device number, transmission is from S + (n-1).
(3) When S is a word device and D is a bit device, the object for the word device will be the
number of bits designated by the bit device digit designation.
If K1Y30 has been designated by D , the lower four bits of the word device designated by
will become the object.
b15
D100
b4 b3 b2 b1b0
D +2
1011
Y3B
6 - 87
D +1
S +1 D101
0011 n
S +2 D102
0111
Y38 Y37
Y34 Y33
Y30
0 11100 1110 11
n
6 - 87
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
and
D,
then
and
(5) Only either of S or D can be designated for the MELSECNET/10(H) direct device and
intelligent function module/special function module device.
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The device range n-points from S or D exceeds the relevant device.
(Error code: 4101)
The number of transfers exceeds 6144 when a special direct device is used. (QnACPU)
(Error code: 4101)
[Program Example]
(1) The following program outputs the lower 4 bits of data at D66 to D69 to Y30 to Y3F in 4-point
units.
[Ladder Mode]
[List Mode]
Before execution
(transfer destination)
b15
b4b3 b0
D66
1110 1
D67
00000
D68
10011
D69
0 110 1
Device
Instruction
Steps
After execution
(transfer destination)
1
0
0
1
1
0
0
1
0
0
1
0
1
0
1
1
Y33 to Y30
Y37 to Y34
Y3B to Y38
Y3F to Y3C
Ignored
(2) The following program outputs the data at X20 to X2F to D100 to D103 in 4-point units.
[Ladder Mode]
[List Mode]
Steps
X2F
X2C X2B
X28 X27
X24 X23
Device
Instruction
X20
Before execution 1 0 0 0 0 1 1 1 0 1 1 0 0 1 0 0
After execution (transfer destination)
b15
b4 b3
b0
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 D100
0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 D101
4 points
0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 D102
0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 D103
Becomes 0
6 - 88
6 - 88
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Word
Index
Register
Zn
Constant
K, H
Other
S
D
n
[Instruction Symbol] [Execution Condition]
Command
FMOV
FMOV
FMOVP
Command
FMOVP
[Set Data]
Set Data
Meaning
Data Type
BIN 16 bits
[Functions]
(1) Transfers 16-bit data from device designated by
by D .
b15
S
b0 Transmission D
3456H
b0
3456H
3456H
3456H
D +1
D +2
3456H
3456H
D +(n-2)
D +(n-1)
(2) In cases where S designates a word device and D a bit device, the number of bits designated
by digit designation for the bit device will be the object bits for the word device.
If K1Y30 has been designated by D , the object bits for the word device designated by S will
be the lower 4 bits.
D +3
b15
D100
b4 b3 b2 b1b0
Transmission
1 011
Y3B
D +2
Y39 Y38
D +1
Y38Y37
Y34 Y33
D
Y30
and
D,
then
and
6 - 89
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The device range n-points from D exceeds the device range.
(Error code: 4101)
The number of transfers exceeds 6144 when a special direct device is used. (QnACPU)
(Error code: 4101)
[Program Example]
(1) The following program outputs the lower 4 bits of D0 when XA goes ON to Y10 to Y23 in 4-bit
units.
[Ladder Mode]
[List Mode]
b15
Device
Instruction
Steps
b4 b3 b2 b1 b0
D0 1 1 0 1 1 0 1 1 1 0 0 1 1 0 1 1
1
1
1
1
1
Ignored
Transmission
0
0
0
0
0
1
1
1
1
1
1
1
1
1
1
Y13 to Y10
Y17 to Y14
Y1B to Y18 5 points
Y1F to Y1C
Y23 to Y20
(2) The following program outputs the data at X20 through X23 to D100 through D103 when XA
goes ON.
[Ladder Mode]
[List Mode]
Steps
X2F
X2C X2B
X28X27
X24X23
Device
Instruction
X20
Before execution 1 0 1 1 0 1 1 1 0 0 1 0 1 1 1 0
Ignored
b4 b3
b0
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 D100
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 D101
4 points
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 D102
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0 D103
Becomes 0
6 - 90
6 - 90
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
6.4.7 16-bit and 32-bit data exchanges (XCH, XCHP, DXCH, DXCHP)
Internal Devices
(System, User)
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
D1
D2
indicates XCH/DXCH
Command
XCH, DXCH
D1
D2
D1
D2
Command
XCHP, DXCHP
[Set Data]
Set Data
Meaning
Data Type
D1
D2
[Functions]
XCH
(1) Conducts 16-bit data exchange between
and
D1
D2
.
D2
D1
b15
b8 b7
b0
Before execution 0 1 1 1 0 0 0 0 0 0 0 0 0 1 1 1
After execution
b15
b8 b7
b0
1111 00001111 0000
D1
D2
b0
b15
b8 b7
1111000011110000
b0
b15
b8 b7
0 111000000000111
DXCH
(1) Conducts 32-bit data exchange between
D1
b31
Before execution 1 1 1 1
D1
After execution
6 - 91
b31
0000
+1
b16 b15
000111
+1
b16 b15
111111
D1
+1,
D1
b0
0000
D1
b0
1111
D1
and
D2
+1,
D2
+1
b31
0000
D2
b31
1111
D2
b16 b15
111111
+1
b16 b15
000111
D2
b0
1111
D2
b0
0000
6 - 91
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no errors associated with the XCH (P) and DXCH (P) instructions.
[Program Example]
(1) The following program exchanges the present value of T0 with the contents of D0 when X8
goes ON.
[Ladder Mode]
[List Mode]
Instruction
Steps
Device
(2) The following program exchanges the contents of D0 with the data from M16 to M31 when X10
goes ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(3) The following program exchanges the contents of D0 and D1 with the data at M16 to M47
when X10 goes ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(4) The following program exchanges the contents of D0 and D1 with those of D9 and D10 when
M0 goes ON.
[Ladder Mode]
[List Mode]
Steps
6 - 92
Instruction
Device
6 - 92
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
D1
D2
n
[Instruction Symbol] [Execution Condition]
Command
BXCH
BXCH
D1
D2
BXCHP
D1
D2
Command
BXCHP
[Set Data]
Set Data
Meaning
Data Type
D1
D2
BIN 16 bits
Number of exchanges
[Functions]
(1) Exchanges 16-bit data n-points from device designated by
device designated by D2 .
D1
D2
+1
1111111100000000
D2
+1
110000 11110000 11
+2
0000000011111111
D2
+2
1111111100000000
b15
b8 b7
b0
00 11001100 1100 11
D1
+(n-2)
101010 1010101010
D2
+(n-2) 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
D1
+(n-1)
0 10 101010 10 10 101
D2
+(n-1) 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
b15
b8 b7
b0
0011001100110011
D2
D1
6 - 93
b15
b8 b7
b0
000011110000 1111
D1
D1
D1
b15
b8 b7
b0
0000 11110000 1111
D1
+1
110000 11110000 11
D2
+1
1111111100000000
D1
+2
1111111100000000
D2
+2
0000000011111111
D1
+(n-2)
1111111111111111
D2
+(n-2) 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
D1
+(n-1)
0000000011111111
D2
+(n-1) 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
6 - 93
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The range n-points from the D1 or D2 devices exceeds relevant device.
(Error code: 4101)
D1 and D2 devices are overlapping.
(Error code: 4101)
[Program Example]
(1) The following program exchanges 16-bit data for 3 points from D200 for 16-bit data for 3 points
from R0 when X1C goes ON.
[Ladder Mode]
[List Mode]
Steps
6 - 94
Instruction
Device
b15
b8 b7
b0
D200 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1
b15
b8 b7
b0
R0 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1
D201 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
R1 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
D202 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
R2 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0
b15
b8 b7
b0
D200 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 1
b15
b8 b7
b0
R0 0 0 1 1 1 1 0 0 1 1 1 1 1 1 1 1
D201 0 0 1 1 0 0 1 1 0 0 1 1 0 0 1 1
R1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
D202 1 1 0 0 0 0 0 0 1 1 0 0 0 0 0 0
R2 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0
6 - 94
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
SWAP
SWAPP
Command
SWAPP
[Set Data]
Set Data
D
Meaning
Data Type
BIN 16 bits
[Functions]
(1) Exchanges the higher and lower 8 bits of the device designated by
b15
b8 b7
b4 b3
D.
b0
010 10 10 1101010 10
b15
b12 b11
b12 b11
b8 b7
b4 b3
b0
10 10 10100 10 1010 1
[Operation Errors]
(1) There are no operation errors associated with the SWAP(P) instruction.
[Program Example]
(1) The following program exchanges the higher 8 bits and lower 8 bits of R10 when X10 goes
ON.
[Ladder Mode]
[List Mode]
Steps
b15
b12 b11
b8 b7
b4 b3
Instruction
Device
b0
R10 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
b15
b12 b11
b8 b7
b4 b3
b0
R10 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0
6 - 95
6 - 95
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
P
CJ
SCJ
SCJ
JMP
JMP
Command
Label
Command
[Set Data]
Set Data
P
Meaning
Pointer number of jump destination
Data Type
Device name
[Functions]
CJ
(1) Executes program of designated pointer number within the same program file when jump
command is ON.
(2) Executes next step in program when jump command is OFF.
ON
Jump command OFF
CJ
SCJ
(1) Executes program of designated pointer number within the same program file from next scan
when jump command goes from OFF to ON.
6 - 96
6 - 96
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(2) Executes next step in program when jump command is OFF or when it goes from ON to OFF.
ON
Jump command OFF
SCJ
Executed each
scan
1 scan
JMP
(1) Unconditionally executes program of designated pointer number within the same program file.
POINTS
Note the following points when using the jump instruction.
(1) After the timer coil has gone ON, accurate measurements cannot be made if there is an
attempt to jump the timer of a coil that has been turned ON using the CJ, SCJ or JMP
instructions.
(2) Scan time is shortened if the CJ, SCJ or JMP instruction is used to force a jump to the OUT
instruction.
(3) Scan time is shortened if the CJ, SCJ or JMP instruction is used to force a jump to the rear.
(4) The CJ, SCJ, and JMP instructions can be used to jump to a step prior to the step currently
being executed.
However, it is necessary to consider methods to get out of the loop so that the watchdog
timer does not time out in the process.
P8
Closed
loop when
X3 is ON
X0
Y40
X7
CJ
P9
CJ
P8
X3
P9
X6
Y42
(5) The device to which a jump has been made with CJ, SCJ or JMP does not change.
XB
10
CJ
P19
Y43
XC
14
XB
16
P19
18
Y49
X9
Y4C
CJ
P9
M33
14
Y30
M3
Occupies step 1
16
P9
18
Y36
M36
Y39
X9
21
Y3B
(7) Jump instructions can be used only for pointer numbers within the same program file.
(8) If a jump is made to a pointer number inside the skip range during a skip operation,
program execution will be taken up following the pointer number of the jump destination.
6 - 97
6 - 97
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) In the following cases an operation is returned, the error flag (SM0) goes ON, and the error
code is stored at SD0.
The pointer number designated does not come prior to the END instruction.
(Error code: 4210)
A pointer number which is not in use as a label in the same program has been designated.
(Error code: 4210)
A common pointer has been designated.
(Error code: 4210)
[Program Example]
(1) The following program jumps to P3 when X9 goes ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
(2) The following program jumps to P3 from the next scan after XC goes ON.
[Ladder Mode]
[List Mode]
Steps
6 - 98
Instruction
Device
6 - 98
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
GOEND
[Functions]
(1) Jumps to FEND or END instruction in the same program file.
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
A GOEND instruction has been executed after the execution of a CALL, ECALL instruction,
and prior to the execution of the RET instruction.
(Error code: 4211)
A GOEND instruction has been executed after the execution of a FOR instruction, and prior
to the execution of the NEXT instruction.
(Error code: 4200)
A GOEND instruction has been executed during an interrupt program but prior to the
execution of the IRET instruction.
(Error code: 4221)
A GOEND instruction was executed between the CHKCIR and CHKEND instruction block.
(Error code: 4230)
A GOEND instruction was executed between the IX and IXEND instruction block.
(Error code: 4231)
[Program Example]
(1) The following program jumps to the END instruction if D0 holds a negative number.
[Ladder Mode]
[List Mode]
Steps
6 - 99
Instruction
Device
6 - 99
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
MELSECNET/10(H)
Special
Direct J \
Function
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
DI
Sequence program
IMASK
IMASK
EI
EI
[Set Data]
Set Data
S
Meaning
Interrupt mask data or head number of device where interrupt mask data
is being stored
Data Type
BIN 16 bits
[Functions]
DI
(1) Disables the execution of an interrupt program until the EI instruction has been executed, even
if a start cause for the interrupt program occurs.
(2) A DI state is entered when power is turned ON or when the system has been reset.
EI
(1) The EI instruction is used to clear the interrupt disable state resulting from the execution of the
DI instruction, and to create a state in which the interrupt program designated by the interrupt
pointer number certified by the IMASK instruction can be executed.
When the IMASK instruction is not executed, I32 to I47 are disabled.
(2) Be sure to execute the EI instruction before executing a periodic program.
Sequence program
DI
Sequence program
EI
In
FEND
Interrupt program
6 - 100
6 - 100
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
IMASK
(1) Enables/disables the execution of the interrupt program marked by the designated interrupt
pointer by using the bit pattern of 8 points from the device designated by S .
1 (ON) ......Interrupt program execution enabled
0 (OFF).....Interrupt program execution disabled
(2) The interrupt pointer numbers corresponding to the individual bits are as shown below:
b15 b14 b13 b12 b11 b10 b9
b8
b7
b6
b5
b4
b3
b2
b1
b0
I8
I7
I6
I5
I4
I3
I2
I1
I0
I15 I14
I9
S +1
I31 I30
I25 I24
S +2
I47 I46
S +3
I63 I62
S +4
I79 I78
I68
S +5
I95 I94
I58
S + 6 I111 I110 I109 I108 I107 I106 I105 I104 I103 I102 I101 I100 I99 I98 I97 I96
S + 7 I127 I126 I125 I124 I123 I122 I121 I120 I119 I118 I117 I116 I115 I114 I113 I112
(3) When the power is turned ON or when the CPU module has been reset with the execution of
interrupt programs I0 to I31 is enabled.
(4) The statuses of devices S , S +1, S +2, and S +3 to S +7 are stored in SD715 to SD717
and SD781 to SD785 (storage area for IMASK instruction mask pattern).
(5) Although the special registers are separated as SD715 to SD717 and SD781 to SD785, device
numbers should be designated as S to S +7 successively.
POINTS
(1) An interrupt pointer occupies 1 step.
I10
Stored at step 50
X1C
50
Y10
X5
53
Y30
55
IRET
(2) Refer to the Basic model QCPU (Q mode) User's Manual (Function Explanation, Program
Fundamentals) for information on interrupt conditions.
(3) The DI state (interrupt disabled) is active during the execution of an interrupt program.
Do not insert EI instructions in interrupt programs to attempt the execution of multiple
interrupts, with interrupt programs running inside interrupt programs.
(4) If there are EI and DI instructions within a master control, these instructions will be
executed regardless of the execution/non-execution status of the MC instruction.
6 - 101
6 - 101
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the DI and EI instructions.
(2) There are no operation errors associated with the IMASK instruction.
[Program Example]
(1) The following program is designed to enable the execution of only the interrupt programs
having the interrupt pointer numbers I1 and I3 while X0 is ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
P10
6 - 102
6 - 102
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
DI
Sequence program
IMASK
IMASK
EI
EI
[Set Data]
Set Data
S
Meaning
Interrupt mask data or head number of device where interrupt mask data
is being stored
Data Type
BIN 16 bits
[Functions]
DI
(1) Disables the execution of an interrupt program until the EI instruction has been executed, even
if a start cause for the interrupt program occurs.
(2) A DI state is entered when power is turned ON or when the system has been reset.
EI
(1) The EI instruction is used to clear the interrupt disable state resulting from the execution of the
DI instruction, and to create a state in which the interrupt program designated by the interrupt
pointer number certified by the IMASK instruction can be executed.
When the IMASK instruction is not executed, I32 to I47 are disabled.
(2) Be sure to execute the EI instruction before executing a periodic program.
Sequence program
DI
Sequence program
EI
In
FEND
Interrupt program
6 - 103
6 - 103
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
IMASK
(1) Enables/disables the execution of the interrupt program marked by the designated interrupt
pointer by using the bit pattern of 16 points from the device designated by S .
1 (ON) ......Interrupt program execution enabled
0 (OFF).....Interrupt program execution disabled
(2) The interrupt pointer numbers corresponding to the individual bits are as shown below:
b15 b14 b13 b12 b11 b10 b9
b8
b7
b6
b5
b4
b3
b2
b1
b0
I15 I14
I9
I8
I7
I6
I5
I4
I3
I2
I1
I0
S +1
I31 I30
I25 I24
S +2
I47 I46
S +3
I63 I62
S +4
I79 I78
I68
S +5
I95 I94
I58
S + 6 I111 I110 I109 I108 I107 I106 I105 I104 I103 I102 I101 I100 I99 I98 I97 I96
S + 7 I127 I126 I125 I124 I123 I122 I121 I120 I119 I118 I117 I116 I115 I114 I113 I112
S + 8 I143 I142 I141 I140 I139 I138 I137 I136 I135 I134 I133 I132 I131 I130 I129 I128
S + 9 I159 I158 I157 I156 I155 I154 I153 I152 I151 I150 I149 I148 I147 I146 I145 I144
S +10 I175 I174 I173 I172 I171 I170 I169 I168 I167 I166 I165 I164 I163 I162 I161 I160
S +11 I191 I190 I189 I188 I187 I186 I185 I184 I183 I182 I181 I180 I179 I178 I177 I176
S +12 I207 I206 I205 I204 I203 I202 I201 I200 I199 I198 I197 I196 I195 I194 I193 I192
S +13 I223 I222 I221 I220 I219 I218 I217 I216 I215 I214 I213 I212 I211 I210 I209 I208
S +14 I239 I238 I237 I236 I235 I234 I233 I232 I231 I230 I229 I228 I227 I226 I225 I224
S +15 I255 I254 I253 I252 I251 I250 I249 I248 I247 I246 I245 I244 I243 I242 I241 I240
(3) When the power is turned ON or when the CPU module has been reset, the execution of
interrupt programs I0 to I31,I48 to I255 is enabled, and the execution of interrupt programs I32
to I47 is disabled.
(4) The statuses of devices S , S +1, S +2, and S +3 to S +15 are stored in SD715 to SD717
and SD781 to SD793 (storage area for IMASK instruction mask pattern).
(5) Although the special registers are separated as SD715 to SD717 and SD781 to SD793, device
numbers should be designated as S to S +15 successively.
POINTS
(1) An interrupt pointer occupies 1 step.
I10
Stored at step 50
X1C
50
Y10
X5
53
Y30
55
IRET
(2) Refer to the Users Manual (Function Explanation, Program Fundamentals) of the CPU
module in use for interrupt conditions.
(3) The DI state (interrupt disabled) is active during the execution of an interrupt program.
Do not insert EI instructions in interrupt programs to attempt the execution of multiple
interrupts, with interrupt programs running inside interrupt programs.
(4) If there are EI and DI instructions within a master control, these instructions will be
executed regardless of the execution/non-execution status of the MC instruction.
6 - 104
6 - 104
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the DI and EI instructions.
(2) There are no operation errors associated with the IMASK instruction.
[Program Example]
(1) The following program creates an execution enabled state for the interrupt program marked by
the interrupt pointer number when X0 is ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
P10
6 - 105
6 - 105
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
DI
Sequence program
IMASK
IMASK
EI
EI
[Set Data]
Set Data
S
Meaning
Interrupt mask data or head number of device where interrupt mask data
is being stored
Data Type
BIN 16 bits
[Functions]
DI
(1) Disables the execution of an interrupt program until the EI instruction has been executed, even
if a start cause for the interrupt program occurs.
(2) A DI state is entered when power is turned ON or when the system has been reset.
EI
The EI instruction is used to clear the interrupt disable state resulting from the execution of the
DI instruction, and to create a state in which the interrupt program designated by the interrupt
pointer number certified by the IMASK instruction can be executed.
Sequence program
DI
Sequence program
EI
In
FEND
Interrupt program
6 - 106
6 - 106
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
IMASK
(1) Enables or disables the execution of the interrupt program marked by the designated interrupt
pointer by use of the bit pattern in the three points from the device designated by S .
1 (ON) ......... Interrupt program execution enabled
0 (OFF)........ Interrupt program execution disabled
(2) The interrupt pointer numbers corresponding to the individual bits are as shown below:
b15 b14 b13 b12 b11 b10 b9
b8
b7
b6
b5
b4
b3
b2
b1
b0
I15 I14
I9
I8
I7
I6
I5
I4
I3
I2
I1
I0
S +1
I31 I30
I25 I24
S +2
I47 I46
(3) When the power is turned ON, or when the CPU module has been reset, interrupt programs
from I0 to I31 are in the execution enabled state, and interrupt programs from I32 to I47 are in
the execution disabled state.
(4) The statuses of the S , S +1, and S +2 devices are stored from SD715 to SD717 (the IMASK
instruction mask pattern storage area).
POINTS
(1) An interrupt pointer occupies 1 step.
T10
Stored at step 50
X1C
50
Y10
X5
53
Y30
55
IRET
(2) Refer to the QnACPU Programming Manual (Fundamentals) for interrupt conditions.
(3) The DI state (interrupt disabled) is active during the execution of an interrupt program.
Do not insert EI instructions in interrupt programs to attempt the execution of multiple
interrupts, with interrupt programs running inside interrupt programs.
(4) If there are EI and DI instructions within a master control, these instructions will be
executed regardless of the execution/non-execution status of the MC instruction.
6 - 107
6 - 107
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the DI and EI instructions.
(2) There are no operation errors associated with the IMASK instruction.
[Program Example]
(1) The following program creates an execution enabled state for the interrupt program marked by
the interrupt pointer number when X0 is ON.
[Ladder Mode]
[List Mode]
Steps
6 - 108
Instruction
Device
6 - 108
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
Process CPU
QnA
Q4AR
Set
Data
Internal Devices
(System, User)
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
IRET
[Functions]
(1) Indicates the completion of interrupt program processing.
(2) Returns to sequence program processing following the execution of the IRET instruction.
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
There is no pointer corresponding to the interrupt number.
(Error code: 4220)
The IRET instruction has been issued prior to the execution of the interrupt program.
(Error code: 4223)
An END, FEND, GOEND, or STOP instruction as been executed after the generation of an
interrupt and prior to the execution of the IRET instruction.
(Error code: 4221)
6 - 109
6 - 109
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
(1) The following program adds 1 to D0 if M0 is ON when the number 3 interrupt is generated.
[Ladder Mode]
[List Mode]
Steps
6 - 110
Instruction
Device
6 - 110
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
S
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
(Only X, Y)
RFS
RFSP
Command
RFSP
[Set Data]
Set Data
Meaning
Head device number of the device that will conduct refresh operation
Data Type
Bit
BIN 16 bits
[Functions]
(1) Refreshes only the device being scanned during a scan, and functions to fetch input from
external sources or to output data to an output module.
(2) Fetching of input from or sending output to an external source is conducted in batch only after
the execution of an END instruction, so it is not possible to output a pulse signal to an outside
source during the execution of a scan.
When a refresh operation is conducted, inputs (X) or outputs (Y) of the device numbers
relevant to the program being executed are forcibly refreshed, so it is possible to output a
pulse signal to an external source during a scan.
6 - 111
6 - 111
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(3) Use direct access inputs (DX) or direct access outputs (DY) to refresh inputs (X) or outputs (Y)
in 1-point units.
[Program based on the RFS instruction]
Command
RFS
X0
K1
Refreshes X0
X0
Y20
Command
RFS
Y20
K1
Refreshes Y20
[Operation Errors]
(1) In the following cases an operation error occurs, the error flag (SM0) turns ON, and an error
code is stored at SD0.
The range n points from the device designated by S exceeds the proximate I/O range.
[Program Example]
(1) The following program refreshes X100 to X11F and Y200 to Y23F when M0 goes ON.
[Ladder Mode]
[List Mode]
Steps
6 - 112
Instruction
Device
6 - 112
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
S
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
(Only X)
(Only C)
: Local devices and the file registers set for individual programs cannot be used.
[Instruction Symbol] [Execution Condition]
Command
UDCNT1
UDCNT1
[Set Data]
Set Data
Meaning
S +0: Input number for count input
S +1: For setting count upper down
OFF : Count up (add numbers when counting)
ON : Count down (subtract numbers when counting)
Number of counter that will perform count on UDCNT1 instruction
Set value
Data Type
Bit
Word
BIN16
[Functions]
(1) When the input designated at S goes from OFF to ON, the present value of the counter
designated at D will be updated.
(2) The direction of the count is determined by the ON/OFF status of the input designated by
+1.
OFF : Count up (counts by adding to the present value)
ON
: Count down (counts by subtracting from the present value)
6 - 113
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
-32767
-2
-1
32766
32767
When counting up
When counting down
(4) Count processing based on the UDCNT1 instruction starts the count when the count command
goes from OFF to ON, and suspends the count when it goes from ON to OFF.
When the count command goes from OFF to ON once again, the count is restarted from the
value in effect when it was suspended.
(5) The RST instruction clears the present value of the counter designated at
contact OFF.
POINTS
(1) The UDCNT1 instruction registers the argument device data to the work area of the CPU
module and the actual counting operation is processed as a system interrupt.
(The device data registered to the work area of the CPU module are cleared when the
command input is turned OFF or when the CPU module is STOPped and then RUN.)
Therefore, to count pulses, it is necessary to provide their ON and OFF time as long as the
interrupt time of the CPU module or longer.
The interrupt time of individual CPU module is shown below:
CPU module Type Name
High Performance model QCPU, Process CPU
QnACPU
Interrupt Time
1ms
5ms
(2) The setting values cannot be changed during a count based on the UDCNT1 instruction
(while the command input is ON)).
To change the setting values, first turn the command input off.
(3) Counters which have been designated by the UDCNT1 instruction cannot be used by other
instructions. If they are used by other instructions, they will not be capable of returning an
accurate count.
(4) The UDCNT1 instruction can be used as many as 6 times within all the programs being
executed.
The seventh and the subsequent UDCNT1 instructions are not processed.
[Operation Errors]
(1) There are no operation errors associated with the UDCNT1 instruction.
[Program Example]
(1) This program uses C0 (up and down counter) to count the number of times X0 goes from off to
ON after X20 has gone ON.
[Ladder Mode]
[List Mode]
Steps
Instruction
Down
Up
Device
[Operation]
X20
X0
X1
Up
Present
value of COM 0 1 2 3 4 5 6 7 6 5 4 3 2 1 0-1-2 -3 -2 -1 0 1 1
C0 contact
6 - 114
6 - 114
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
S
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
(Only X)
(Only C)
: Local devices and the file registers set for individual programs cannot be used.
[Instruction Symbol] [Execution Condition]
Command
UDCNT2
UDCNT2
[Set Data]
Set Data
Meaning
Input number for count input: S +0 (A phase pulse)
Input number for count input: S +1 (B phase pulse)
Number of counter that will perform count onUDCNT2 instruction
Set value
Data Type
Bit
Word
BIN16
[Functions]
(1) The present value of the counter designated by D is updated depending on the status of the
input designated by S (A phase pulse) and the status of the input designated by S +1 (B
phase pulse).
(2) Direction of the count is determined in the following manner:
When S is ON, if S +1 goes from OFF to ON, count up operation is performed (values are
added to the present value of the counter).
When S is ON, if S +1 goes from ON to OFF, count down operation is performed (values
are subtracted from the present value of the counter).
No count operation is performed if S is OFF.
(3) Count processing is conducted as described below:
When the count is going up, the counter contact designated at D goes ON when the present
value becomes identical with the setting value designated by n.
However, the present value count will continue even when the contact of the counter
designated at D goes ON. (See Program Example (1))
When the count is going down, the counter for the contact designated at D goes OFF when
the present value reaches the setting value minus 1. (See Program Example (1))
The counter designated at D is a ring counter.
If it is counting up when the present value is 32767, the present value will become -32768.
Further, if it is counting down when the present value is -32768, the present value will
become 32767.
6 - 115
6 - 115
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
-32767
-2
-1
32766
32767
When counting up
When counting down
(4) Count processing conducted according to the UDCNT2 instruction begins when the count
command goes from OFF to ON, and is suspended when it goes from ON to OFF.
When the count command goes from OFF to ON once again, the count is restarted from the
value in effect when it was suspended.
(5) The RST instruction clears the present value of the counter designated at
contact OFF.
POINTS
(1) The UDCNT2 instruction registers the argument device data to the work area of the CPU
module and the actual counting operation is processed as a system interrupt.
(The device data registered to the work area of the CPU module are cleared when the
command input is turned OFF or when the CPU module is STOPped and then RUN.)
Therefore, to count pulses, it is necessary to provide their ON and OFF time as long as the
interrupt time of the CPU module or longer.
The interrupt time of individual CPU module is shown below:
CPU module Type Name
High Performance model QCPU, Process CPU
QnACPU
Interrupt Time
1ms
5ms
(2) The set value cannot be changed while a count operation performed according to the
UDCNT2 instruction is being executed (while the command input is ON).To change the set
value, first turn the command input off.
(3) Counters designated by the UDCNT2 instruction cannot be used by any other instruction.
If they are used by other instructions, they will not be capable of returning an accurate
count.
(4) The UDCNT2 instruction can be used as many as 5 times within all the programs being
executed.
The sixth and the subsequent UDCNT2 instructions are not processed.
[Operation Errors]
(1) There are no operation errors associated with the UDCNT2 instruction.
[Program Example]
(1) The following program performs a count operation as instructed by C0 (count up or down) on
the status of X0 and X1 after X20 has gone ON.
[Ladder Mode]
[List Mode]
Device
Instruction
Steps
[Operation]
X20
X0
X1
Present
value of COM 0 1
0 -1 -2
-1
-1
C0 contact
6 - 116
6 - 116
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
QnA
Process CPU
High Performance
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
TTMR
[Set Data]
Set Data
D
Meaning
D +0: Storage device for measurement value
D +1: For CPU module system use
Measurement value multiplier
Data Type
BIN 16 bits
[Functions]
(1) The time that the measurement command is on is measured in units of seconds, then
multiplied by the multiplier designated by n and the product is stored at the device designated
by D .
(2) When the measurement command goes from OFF to ON, the device designated by
+1 is cleared.
or
6 - 117
Multiplier
10
100
6 - 117
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
POINTS
(1) Time measurements are conducted when the TTMR instruction is executed.
Using the JMP or similar instruction to jump the TTMR instruction will make it impossible to
get an accurate measurement.
(2) Do not change the multiplier designated by n while the TTMR instruction is being executed.
Changing this multiplier will result in an inaccurate value being returned.
(3) The TTMR instruction can also be used in low speed type programs.
(4) The device designated by D +1 is used by the CPU system, so users should not change
its value.
If users do change this value, the value stored in the device designated by D will no longer
be accurate.
(4) No processing is performed when the value specified by "n" is other than 0 to 2.
[Operation Errors]
(1) There are no errors associated with the TTMR instruction.
[Program example]
(1) The following program stores the amount of time that X0 is ON at D0.
[Ladder Mode]
[List Mode]
Steps
6 - 118
Instruction
Device
6 - 118
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
K, H
Other
n
D
STMR
[Set Data]
Set Data
Meaning
Timer number
Set value
D +0: Off delay timer output
D +1: One shot timer output after OFF
D +2: One shot timer output after ON
D +3: ON delay timer output
Data Type
Word
BIN 16 bits
Bit
[Functions]
(1)The STMR instruction uses the 4 points from the device designated by D to perform four
types of timer output.
OFF delay timer output ( D +0)
Goes ON at the leading edge of the command for the STMR instruction, and, after the
trailing edge of the command, goes OFF when the amount of time designated by n has
passed.
One shot timer output after OFF ( D +1)
Goes ON at the trailing edge of the command for the STMR instruction, and goes OFF when
the amount of time designated by n has passed.
One shot timer output after ON ( D +2)
Goes ON at the leading edge of the command for the STMR instruction, and goes OFF
either when the amount of time designated by n has passed, or when the command for the
STMR instruction goes OFF.
ON delay timer output ( D +3)
Goes ON at the trailing edge of the timer coil, and after the trailing edge of the command for
the SRMR instruction, goes OFF when the amount of time designated by n has passed.
6 - 119
6 - 119
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(2) The timer coil designated by S goes ON at the leading edge of the command for the STMR
instruction, and begins the measurement of the present value.
The timer coil measures to the point where the value reaches the set value designated by n,
then enters a time up state and goes OFF.
If the command for the SRMR instruction goes OFF before the timer coil reaches the time up
state, it will remain ON.
Timer measurement is suspended at this time.
When the STRM instruction command goes ON once again, the present value will be
cleared to 0 and measurement will begin once again.
(3) The timer contact goes ON at the leading edge of the command for the STMR instruction, and
after the trailing edge is reached, the timer coil goes OFF at the trailing edge of the STMR
instruction command.
The timer contact is used by the CPU module system, and cannot be used by the user.
Command for
STMR instruction
S (Coil)
S (Contact)
D +0
D +1
D +2
D +3
ON delay timer
Set value
designated
by n1
Set value
designated
by n1
Set value
designated
by n1
Set value
designated
by n1
(4) Measurement of the present value of the timer designated by the STMR instruction is
conducted during the execution of the STMR instruction.
If the STMR instruction is jumped with the JMP or similar instruction, it will not be possible to
get accurate measurement.
(5) Measurement unit for the timer designated by
[Operation Errors]
(1) There are no errors associated with the STMR instruction.
6 - 120
6 - 120
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Program Example]
(1) The following program turns Y0 and Y1 ON and OFF once each second (flicker) when X20 is
ON. (Uses the 100ms timer)
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
X20
M1,Y0
M2,Y1
M3
1s
6 - 121
1s
6 - 121
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
Other
n
n2
D
ROTC
n1
n2
[Set Data]
Set Data
S
n1
n2
Meaning
Data Type
BIN 16 bits
Bit
[Functions]
(1) This control functions to enable near path rotation of the rotary table to the position of the
station number designated by S +1 in order to remove or deposit an item whose number has
been designated by S +2 on a rotary table with equal divisions of the value designated by n1.
(2) The item number and station number are controlled as items allocated by counterclockwise
rotation.
(3) The system uses S +0 as a counter to instruct it as to what item is at which number counting
from station number 0.
Do not rewrite the sequence program data.
Accurate controls will not be possible in cases where users have rewritten the data.
(4) The value of n2 should be less than the number of table divisions that were designated by n1.
(5)
6 - 122
+0 and D +1 are A and B phase input signals that are used to detect whether the direction
of the rotary table rotation is forward or reverse.
D
6 - 122
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
The direction of rotation is judged by whether the B phase pulse is at its leading or trailing
edge when the A phase pulse is ON:
When the B phase is at the leading edge : Forward rotation (clockwise rotation)
When the B phase is at the trailing edge: Reverse rotation (counterclockwise rotation)
(6)
D +2 is the 0 point detection output signal that goes ON when item number 0 has arrived at
the No. 0 station.
When the device designated by D +2 goes ON while the ROTC instruction is being executed,
S +0 is cleared.
It is best to perform this clear operation first, then to begin near path rotation with the ROTC
instruction.
(7) The data from D +3 to D +7 consists of output signals needed to control the table's operation.
The output signal of one of the devices from D +3 to D +7 will go ON in response to the
execution results of the ROTC instruction.
(8) If operation results immediately prior to the ROTC instruction are OFF, all signals from
D +7 will be OFF without near path rotation controls having been performed.
+3 to
(9) The ROTC instruction can be used only one time in all programs where it is executed.
Attempts to use it more than one time will result in inaccurate operations.
(10) No processing is performed when the value of
n1.
+0 to
[Operation Errors]
(1) There are no errors associated with the ROTC instruction.
[Program Example]
(1) The following program deposits the item at section D2 on a 10-division rotary table at the
station at section D1, and the two sections ahead and behind this determine the rotation
direction and control speed of the motor when the table is being rotated at low speed.
[Ladder Mode]
[List Mode]
Device
Instruction
Steps
Station No. 0
0 point detection
X002
8
9
0
Part
X000
6
1
Detection
switch
Forward
rotation
X001
3
5
Rotary table
Station No. 1
6 - 123
6 - 123
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
K, H
Other
n1
n2
D1
n3
D2
RAMP
n1
n2
n3
D1
D2
[Set Data]
Set Data
Meaning
Data Type
n1
Initial value
n2
Final value
D1 +0: Present value
D1 +1: Number of times executed (for system use)
Number of times moved
D2 +0: Completion device
D2 +1: Selected bit where data is to be saved at completion.
D1
n3
D2
BIN 16 bits
Bit
[Functions]
(1) Stores in D1 +1 the value which varies the value specified in n1 to the value specified in n2
linearly by the number of shifts specified in n3.
The value to be stored in D1 +1 is calculated every scan with the following expression.
{(Value specified in n2) - (Value specified in n1)}
(Number of shifts)
(Number of executions)
One variation
D1
+0
150
250
300
200
100
50
Value (350)
specified in n2
When the calculated one variation is indivisible, compensation is made to achieve the value
specified in n2 by the number of shifts specified in n3.
Hence, a linear ramp may not be made.
6 - 124
6 - 124
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
(2) For n3, designate the number of scans required to move data from n1 to n2.
No processing is performed when n3 = 0.
(3) The system uses
D1
(4) When the move is completed to the final value, the completion device designated by D2 +0 will
go ON.
The ON/OFF status of the completion device and the contents of D1 +0 are determined by the
ON/OFF status of the device designated by D2 +1.
When D2 +1 is OFF, D2 +0 will go OFF at the next scan, and the RAMP instruction will begin
a new move operation from the value currently at D1 +0.
When D2 +1 is ON, D2 +0 will remain ON, and the contents of D1 +0 will not change.
(5) When the command is turned OFF during the execution of this instruction, the contents of D1
+0 will not change following this.
When the command goes ON again, the RAMP instruction will begin a new move from the
present value at D1 +0.
(6) Do not change the specified values in n1 and n2 before the completion device specified in
D2 +0 turns ON.
Since the same expression is used every scan to calculate the value stored in D1 +1, changing
n1/n2 may cause a sudden variation.
[Operation Errors]
(1) There are no operation errors associated with the RAMP instruction.
[Program Example]
(1) The following program changes the contents of D0 from 10 to 100 in a total of 6 scans, and
saves the contents of D0 when the move has been completed.
[Ladder Mode]
[List Mode]
Steps
Instruction
Device
[Operation]
ON
X0 OFF
D0
D1
25
1
40
2
1 scan
55
3
1 scan
85
5
70
4
1 scan
1 scan
100
6
1 scan
ON
M0 OFF
ON
M1 OFF
6 - 125
6 - 125
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
Other
(X only)
n
D
: Local devices and the file registers set for individual programs cannot be used.
[Instruction Symbol] [Execution Condition]
Command
SPD
SPD
[Set Data]
Set Data
Meaning
Data Type
Pulse input
Bit
BIN 16 bits
[Functions]
(1) Input from the device designated by S is counted for just the amount of time designated by
n1, and results of the count are stored in the device designated by D .
Measurement begins
n [ms]
n [ms]
ON
Command OFF
ON
S
OFF
Measurement results
stored at D
Measurement results
stored at D
(2) When measurement directed by the SPD instruction has been completed, measurement is
done again from 0.
To suspend measurement directed by the SPD instruction, turn the command OFF.
6 - 126
6 - 126
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
POINTS
(1) The SPD instruction registers the data from the argument device in the CPU module work
area, and the actual count operation is conducted during a system interrupt.
(The device data registered to the work area of the CPU module are cleared when the
command input is turned OFF or when the CPU module is STOPped and then RUN.)
Therefore, to count the pulses, it is necessary to provide their ON and OFF time as long as
the interrupt time of the CPU module or longer.
The interrupt time of individual CPU module is shown below:
CPU module Type Name
Interrupt Time
1ms
QnACPU
5ms
[Operation Errors]
(1) There are no operation errors associated with the SPD instruction.
[Program Example]
(1) The following program measures the pulses input to X0 for a period of 500 ms when X10 goes
ON, and stores the result at D0.
[Ladder Mode]
[List Mode]
Steps
6 - 127
Instruction
Device
6 - 127
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
Other
n1
n2
D
PLSY
n1
n2
[Set Data]
Set Data
Meaning
n1
n2
Data Type
BIN 16 bits
Bit
[Functions]
(1) Outputs a pulse at a frequency designated by n1 the number of times designated by n2, to the
output module with the output signal (Y) designated by D1.
(2) Frequencies between 1 to 100 Hz can be designated by n1.
If n1 is other than 1 to 100 Hz, the PLSY instruction will not be executed.
(3) The number of outputs that can be designated by n2 is between 1 to 65535
(0000H to 0FFFFH).
(4) Only an output number corresponding to the output module can designated for pulse output at
D.
(5) Pulse output commences with the command leading edge of the PLSY instruction.
Do not turn the command of the PLSY instruction OFF during pulse output.
Pulse output is suspended when the PLSY instruction command goes OFF.
6 - 128
6 - 128
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
POINT
(1) The PLSY instruction registers the argument device data in the CPU module work area,
and the actual output operation is processed during system interrupts.
(The device data registered to the work area of the CPU module are cleared when the
command input is turned OFF or when the CPU module is STOPped and then RUN.)
Therefore, to count the pulses, it is necessary to provide their ON and OFF time as long as
the interrupt time of the CPU module or longer.
The interrupt time of individual CPU module is shown below:
CPU module Type Name
Interrupt Time
1ms
QnACPU
5ms
(2) Do not change the argument of the PLSY instruction during pulse output by the PLAY
instruction (while the command input is ON).
Turn OFF the command input before changing the argument.
(3) For this reason, the PLSY instruction can be used only once in the entire program executed
by the CPU module.
[Operation Errors]
(1) There are no operation errors associated with the PLSY instruction.
[Program Example]
(1) The following program outputs a 10 Hz pulse 5 times to Y20 when X0 is ON.
[Ladder Mode]
[List Mode]
Steps
6 - 129
Instruction
Device
6 - 129
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
File
Register
Index
Register
Zn
Constant
Other
n1
n2
D
PWM
n1
n2
[Set Data]
Set Data
Meaning
Data Type
n1
n2
BIN 16 bits
Bit
[Functions]
(1) Outputs the pulse of the cycle set by n2, for the amount of time ON designated by n1, to the
output module designated by D .
n1
n2
and n2 [ms]
The value designated for n1 should be the same as the value designated for n2 or smaller.
6 - 130
6 - 130
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no operation errors associated with the PWM instruction.
POINT
(1) The PWM instruction registers the designated device data to the work area of the CPU
module.
The actual output operation is processed as the interruption by the CPU module.
(The device data registered to the work area of the CPU module is cleared when the
command input is turned OFF or when the CPU module is STOPped and then RUN.)
The interrupt time of individual CPU module is shown below:
CPU module Type Name
Interrupt Time
1ms
QnACPU
5ms
For this reason, the PWM instruction can be used only once within all the programs being
executed by the CPU module.
(2) The instruction is not processed in the following cases:
When both n1 and n2 are 0
When n1 and n2 are not multiples of 5 (only when QnACPU is used)
When n2 n1
(3) Do not change the arguments of the PWM instruction while pulses are being output by the
PWM instruction (while the command input is ON).
Before changing the arguments, turn OFF the command input.
[Program Example]
(1) The following program outputs a 100 ms pulse once each second to Y20 when X0 is ON.
[Ladder Mode]
[List Mode]
Steps
6 - 131
Instruction
Device
6 - 131
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
QCPU
PLC CPU
Basic
High Performance
QnA
Process CPU
Q4AR
Set
Data
Bit
Word
File
Register
Usable Devices
Special
MELSECNET/10(H)
Function
Direct J \
Module
Bit
Word
U \G
Index
Register
Zn
Constant
Other
S
D1
D2
MTR
D1
D2
[Set Data]
Set Data
Meaning
Data Type
D1
D2
Bit
BIN 16 bits
[Functions]
(1) Successively reads the input from 16 points starting from the input number designated by S ,
multiplied by n-rows, then stores the data fetched in this operation from the device designated
by D2 onward.
(2) One row (16 points) can be fetched in 1 scan.
(3) Fetching from the first to the nth row is progressively repeated.
(4) The first through the 16th points store the first row of data and the next 16 points store the
second row of data at the devices following the device designated by D2 .
For this reason, the space of 16xn-points from the device designated by D2 are occupied by
the MTR instruction.
(5)
is the output needed to select the row which will be fetched, and the system automatically
turns it ON and OFF.
It uses the n-points from the device designated by D1 .
D1
D1
and
D2
6 - 132
6 - 132
6 BASIC INSTRUCTIONS
MELSEC-Q/QnA
[Operation Errors]
(1) There are no errors associated with the MTR instruction.
[Program Example]
(1) The following program fetches 16 points x 3 rows starting from X10 when X0 is ON, and stores
it from M30 onward.
[List Mode]
Device
Instruction
Steps
M77
M76
M75
M74
M73
M72
M71
M70
M69
M68
M67
M66
M65
M64
M63
M62
Third row
[Ladder Mode]
X011 X012 X013 X014 X015 X016 X017 X018 X019 X01A X01B X01C X01D X01E X01F
M61
M60
M59
M58
M57
M56
M55
M54
M53
M52
M51
M50
M49
M48
M47
M46
Second row
X011 X012 X013 X014 X015 X016 X017 X018 X019 X01A X01B X01C X01D X01E X01F
M45
M44
M43
M42
M41
M40
M39
M38
M37
M36
M35
M34
M33
M32
M31
M30
First row
X010 X011 X012 X013 X014 X015 X016 X017 X018 X019 X01A X01B X01C X01D X01E X01F
[Caution]
(1) Note that the MTR instruction directly operates on actual input and cutput.
The output D1 that had been turned ON by the MTR instruction does not turn OFF when the
MTR command turns OFF. Turn OFF the specified output D1 in the sequence program.
(2) An MTR instruction execution interval must be longer than the total of response time of
input and output modules.
If the set interval is shorter than the value indicated above, an input cannot be read
correctly.
If the scan time in a sequence program is short, select the constant scan and set the scan
time longer than the total of response time.
6 - 133
6 - 133