Вы находитесь на странице: 1из 135

2.

4 Instruction Details
3-56
2
Chapter 2 Instructions
2.4 Instruc tion Details
2.4.1 Basic Instructions
This section describes the basic instructions used for programming. You can create
complete programs with only these basic instructions.
Instruction Mnemonic Reference page
Load LD 3-57
Load Bar LDB 3-57
And AND 3-58
And Bar ANB 3-58
OR: Or OR 3-60
ORB: Or Bar ORB 3-60
ANL: And Load ANL 3-61
Or Load ORL 3-63
OUT: Out OUT 3-65
OUB: Out Bar OUB 3-65
SET: Set SET 3-66
RES: Reset RES 3-66
TMR: 0.1-s Timer TMR 3-67
TMH: 0.01-s Timer TMH (FUN49) 3-68
TMS: 1-ms Timer TMS (FUN51) 3-69
C: Counter C 3-72
UDC: Up-Down Counter UDC (FUN52) 3-76
DIFU: Differentiate Up DIFU (FUN10) 3-78
DIFD: Differentiate Down DIFD (FUN09) 3-78
KEEP: Keep KEEP (FUN22) 3-80
SFT: Shift SFT (FUN39) 3-82
HSP: High Speed HSP (FUN18) 3-86
MC: Master Control MC (FUN24) 3-89
MCR: Master Control Reset MCR (FUN25) 3-89
MEMSW: Memory Switch MEMSW (FUN26) 3-92
NOP: No Operation NOP 3-94
END: End END 3-94
ENDH: End Hi END 3-94
2.4 Instruction Details
1
2
3-57
Chapter 2 Instructions
Example
Coding
When input relay 0000 turns ON, output relay 0500 turns ON.
When input relay 0001 turns OFF, output relay 0501 turns ON.
Description
LD and LDB instructions are used to connect a contact to the bus.
LD and LDB instructions are also used to separate program blocks when ANL or
ORL instruction is used.
Operands
Key operation
Example: LD C014
LD: Load
LDB: Load Bar
Connects N.O. contact to bus.
Connects N.C. contact to bus.
LD
7
LDB
4
nnnn
nnnn
0000 0500
0001 0501
Line No. Instruction Operand
0000 LD 0000
0001 OUT 0500
0002 LDB 0001
0003 OUT 0501
( )
LD
7
Operand
ENT
R-SRCH
ENT
R-SRCH
LD
7
LDB
4
LDB
4
CTR
(
C
)
SET
1
:
:
LD / LDB
Visual KV KV-300 KV-10/16 KV-24/40/80
0000 to 17915 0000 to 0009 0000 to 2915 0000 to 6915
T000 to T249 0500 to 17915 T000 to T063 T000 to T119
C000 to C249 T000 to T249 C000 to C063 C000 to C119
CTC0 to CTC3 C000 to C249 CTC0 to CTC3 CTC0 to CTC3
CTC0 to CTC3
2.4 Instruction Details
3-58
2
Chapter 2 Instructions
AND: And
ANB: And Bar
Connects N.O. contact in series with
previous contact.
Connects N.C. contact in series with
previous contact.
AND
8
ANB
5
nnnn
nnnn
Example
Coding
To turn ON 0503, 0002 must be ON, 0003 OFF, and 0004 ON at the same time. The
AND and ANB instructions are used when two or more conditions (in this case,
0002: ON, 0003: OFF, 0004: ON) must be satisfied at the same time.
Description
As many contacts as desired can be connected in series provided these contacts
are used in the same program.
As OUT 0503 shown in the above example, when an AND or ANB instruction is
used immediately after an OUT instruction to connect the other relay via a
contact (0004 in the example), the AND or ANB can be used as many times as
desired, provided the program syntax is correct.
The following two circuits operate in the same manner, but the coding for these
circuits are different.
Coding Coding
0000 0500
0002
0001
0004
0003 0501
0502
0503
Line No. Instruction Operand
0000 LD 0000
0001 AND 0001
0002 OUT 0500
0003 LD 0002
0004 ANB 0003
0005 OUT 0501
0006 OUT 0502
0007 AND 0004
0008 OUT 0503
0000 0001 0501
0500
Line No. Instruction Operand
0000 LD 0000
0001 OUT 0500
0002 AND 0001
0003 OUT 0501
Line No. Instruction Operand
0000 LD 0000
0001 MPS
0002 AND 0001
0003 OUT 0501
0004 MPP
0005 OUT 0500
0000 0001 0501
0500
:
:
AND / ANB
"MPS instruction" (p. 3-103)
"MPP instruction" (p. 3-103)
2.4 Instruction Details
1
2
3-59
Chapter 2 Instructions
Operand
Key operation
Example: AND T012
( )
SET
1
TMR
(
T
)
AND
8
AND
8
ANB
5
ANL
2
Operand
ENT
R-SRCH
ENT
R-SRCH
AND / ANB
Visual KV KV-300 KV-10/16 KV-24/40/80
0000 to 17915 0000 to 0009 0000 to 2915 0000 to 6915
T000 to T249 0500 to 17915 T000 to T063 T000 to T119
C000 to C249 T000 to T249 C000 to C063 C000 to C119
CTC0 to CTC3 C000 to C249 CTC0 to CTC3 CTC0 to CTC3
2.4 Instruction Details
3-60
2
Chapter 2 Instructions
OR: Or
ORB: Or Bar
Connects N.O. contact in parallel with
previous contact.
Connects N.C. contact in parallel with
previous contact.
Example
Coding
The OR and ORB instructions are used when at least one of the conditions (here,
two sets of conditions: <0003: ON, 0004: ON>, and <0000: ON, 0001: ON, 0002:
OFF> are given) must be satisfied.
Description
The OR and ORB instructions are used to connect in parallel the contacts for
these instructions with contacts on the previous line. An LD or LDB instruction is
used together with the OR and ORB instructions.
As many contacts as desired can be connected in parallel provided they are used
in the same program.
Note: Output circuits (except for and )
cannot be included in the parallel connection.
Operands
Key operation
Example: OR T018
OR
9
ORB
6
nnnn
nnnn
0000 0003 0500
0004
0002
0001
Line No. Instruction Operand
0000 LD 0000
0001 OR 0000
0002 ORB 0002
0003 AND 0003
0004 OR 0004
0005 OUT 0500
( )
SET
1
TMR
(
T
)
AND
8
OR
9
OR
9
ORB
6
Operand
ENT
R-SRCH
ENT
R-SRCH
:
:
OR / ORB
0000 0500
0501 0001
To turn ON 0500,
0000 must be ON or
0001 ON or
0002 OFF.
0003 must be ON, and
or,
0004 must be ON.
Incorrect
Visual KV KV-300 KV-10/16 KV-24/40/80
0000 to 6915 0000 to 0009 0000 to 2915 0000 to 6915
T000 to T119 0500 to 17915 T000 to T063 T000 to T119
C000 to C119 T000 to T249 C000 to C063 C000 to C119
CTC0 to CTC3 C000 to C249 CTC0 to CTC3 CTC0 to CTC3
CTC0 to CTC3
2.4 Instruction Details
1
2
3-61
Chapter 2 Instructions
Example
Coding
Description
The above example shows a serial connection between Block A
0000
0002
and Block B
0001
0003
. The ANL instruction is used to connect two or more blocks in
series.
Operands
Key operation
ANL: And Load
Connects in series blocks made of one or
more contacts.
ANL
2
0000 0001 0500
0003 0002
ANL
Line No. Instruction Operand
0000 LD 0000
0001 OR 0002
0002 LD 0001
0003 OR 0003
0004 ANL
0005 OUT 0500
:
ANL
ANL
2
ENT
R-SRCH
2.4 Instruction Details
3-62
2
Chapter 2 Instructions
ANL
0000 0002 0500
0003 0005 0001
0004
Line No. Instruction Operand
0000 LD 0000
0001 OR 0001
0002 LD 0002
0003 OR 0003
0004 ANL
0005 LD 0004
0006 OR 0005
0007 ANL
0008 OUT 0500
Line No. Instruction Operand
0000 LD 0000
0001 OR 0001
0002 LD 0002
0003 OR 0003
0004 LD 0004
0005 OR 0005
0006 ANL
0007 ANL
0008 OUT 0500
Applications of ANL Instruction
Coding (1) Coding (2)
The ANL instruction can be used as many times as desired. Note, however, that
in example (2) above, ANL is entered one less time than the number of blocks to
be connected.
Also, ANL can be used only 8 times or less in example (2), whereas in example
(1) it can be used as many times as desired.
Note: "LOGIC ERROR" is displayed on the programmer when ANL is used 9 or
more times in example (2).
2.4 Instruction Details
1
2
3-63
Chapter 2 Instructions
Example
Coding
Description
The above example shows a parallel connection of Block A
0000 0001
and Block B
0002 0003
. The ORL instruction is used to connect two or more blocks in
parallel.
Operands
Key operation
ORL: Or Load
Connects in parallel blocks made of one or
more contacts.
ORL
3
Line No. Instruction Operand
0000 LD 0000
0001 AND 0001
0002 LD 0002
0003 AMD 0003
0004 ORL
0005 OUT 0500
0000 0001 0050
0003 0002
ORL
ORL
3
ENT
R-SRCH
:
ORL
2.4 Instruction Details
3-64
2
Chapter 2 Instructions
Applications of ORL Instruction
Coding (1) Coding (2)
The ORL instruction can be used as many times as desired. Note, however, that
in example (2) above, ORL is entered one less time than the number of blocks to
be connected.
Also, ORL can be used only 8 times or less in example (2), whereas in example
(1) it can be used as many times as desired.
Note: "LOGIC ERROR" is displayed on the programmer when ORL is used 9 times
or more in example (2).
0000 0001 0500
0003 0002
0005 0004
Line No. Instruction Operand
0000 LD 0000
0001 AND 0001
0002 LD 0002
0003 AND 0003
0004 ORL
0005 LD 0004
0006 AND 0005
0007 ORL
0008 OUT 0500
Line No. Instruction Operand
0000 LD 0000
0001 AND 0001
0002 LD 0002
0003 AND 0003
0004 LD 0004
0005 AND 0005
0006 ORL
0007 ORL
0008 OUT 0500
Block
Block
Block
ORL
2.4 Instruction Details
1
2
3-65
Chapter 2 Instructions
Example
Coding
Description
When input relay 0000 turn ON, output relay 0500 turns ON and output relay
0501 turns OFF.
The OUT and OUB instructions are used to drive relay coils for output relays,
internal utility relays, and latch relays. These instructions are not used for input
relays, timers, counters, or data memories.
Note: Double coil
When one output relay receives input from two or more OUT or OUB instructions,
priority is given to the instruction that is entered last.
When 0001 is OFF, 0500 does not turn ON even if 0000 turns ON.
Operands
Key operation
OUT: Out
OUB: Out Bar
Outputs ON/OFF status of input to relay coil.
Outputs inverted ON/OFF status of input to
relay coil.
OUT
A
OUB
B
nnnn
nnnn
0000 0500
0501
Line No. Instruction Operand
0000 LD 0000
0001 OUT 0500
0002 OUB 0501
OUT
A
Operand
ENT
R-SRCH
OUB
B
Operand
ENT
R-SRCH
:
:
OUT / OUB
Visual KV KV-300 KV-10/16 KV-24/40/80
0000 to 1915 0500 to 1915 0500 to 1915 0500 to 1915
2009 2009 2009 2009
2300 to 17915 2300 to 17915 2300 to 2915 2300 to 6915
2.4 Instruction Details
3-66
2
Chapter 2 Instructions
Example
Coding
Description
Output relay 0500 remains ON after input relay 0000 turns OFF. Output relay
0500 turns OFF when input relay 0001 turns ON.
SET instruction sets a latch whereas RES instruction resets it.
RES instruction not only turns OFF relay coils but serves as a reset signal when
a timer or counter is used as an operand.
Note: The SET and RES instructions can be entered in any order. Note, however,
that priority is given to the instruction that is entered last.
In the above example, when both 0000 and 0001 are ON, RES has priority over
SET, causing 0500 to remain OFF.
Tips
Differences between SET/RES and KEEP
Basically , SET/RES and KEEP ( See above and p. 3-80) serve the same purpose.
SET and RES can be used separately. Therefore, RES can be placed before
SET.
Another instruction may be placed between SET and RES.
KEEP needs only three lines of program, therefore saving memory space when
used a number of times.
Operands
Key operation
SET: Set
RES: Reset
Turns ON specified relay when input is ON
and enables this relay to remain ON.
Turns OFF specified relay, timer, or counter
when input is ON.
SET
1
RES
0
nnnn
RES
nnnn
SET
0000
0001
0500
SET
0500
RES
Line No. Instruction Operand
0000 LD 0000
0001 SET 0500
0002 LD 0001
0003 OUB 0500
0001 0002 0001
0002 C000
RES
#00100
00000
C000
#00100
0000
C000
0000
0001 0500
SET
0500
RES
0000
0001
RES
KEEP
0500
SET
LD 0000
RES 0500
LD 0001
SET 0500
LD 0000
LD 0001
KEEP 0500
SET
1
RES
0
Operand
ENT
R-SRCH
Operand
ENT
R-SRCH
:
:
SET / RES
Visual KV KV-300 KV-10/16 KV-24/40/80
0500 to 1915 0500 to 1915 0500 to 1915 0500 to 1915
2009 2009 2009 2009
2100 to 17915 2100 to 17915 2100 to 2915 2100 to 6915
T000 to T249 T000 to T249 T000 to T063 T000 to T119
C000 to C249 C000 to C249 C000 to C063 C000 to C119
CTH0 to CTH1 (RES only)
CTC0 to CTC3 (RES only)
2.4 Instruction Details
1
2
3-67
Chapter 2 Instructions
Example
Coding
Timing diagram (TMR000 #00010 and 0500 in the above example)
0500 and 0501 turn ON 1 second and 3.5 seconds respectively after 0000 turns
ON.
TMR000 is a subtraction timer. When the current value reaches "#00000",
contact T000 turns ON, and then output relay 0500 turns ON.
When input relay 0000 turns OFF, contact T000 and T001 turn OFF and the
current values of TMR000 and TMR001 are reset.
Note 1: The TMR number cannot be the same as any other TMS, TMH, TMR, C, or UDC
instructions in the same program.
Note 2: The current value of TMR is not retained but is reset to the preset value if a power
failure occurs or if power is turned OFF.
Tips
When the number specified by TMR is used as a contact (T000 in the above
example), this contact can be used as many times as desired. It can also be
used as both N.O. and N.C. contacts.
Timer accuracy = 0.1 sec. + (1 scan time) (max.)
Operands
Key operation
TMR: 0.1-s Timer
Sets a 16-bit on-delay timer that counts
down in 0.1-s decrements.
*1 0.1 s x 10 = 1 s
*2 0.1 s x 35 = 3.5 s

TMR
(
T
)
#ddddd

Txxx
0000
T000
T001
0500
0501
#00010

T000
#00035

T001
Preset value: 1 s
Preset value: 3.5 s
Line No. Instruction Operand
0000 LD 0000
0001 TMR 000 #00010*
1
0002 TMR 001 #00035*
2
0003 LD T000
0004 OUT 0500
0005 LD T001
0006 OUT 0501
OFF
ON
ON
#00010
#00000
Output 0500
Scan
Input 0000
Current
value of
TMR000
TMR
(
T
)
Operand
(TMR No.)
Operand
(Preset value)
ENT
R-SRCH
:
TMR
Visual KV KV-300 KV-10/16 KV-24/40/80
No.: 000 to 249 No.: 000 to 249 No.: 000 to 063 No.: 000 to 119
Preset value: Preset value: Preset value: Preset value:
#00000 to #65535 #00000 to #65535 #00000 to #65535 #00000 to #65535
2.4 Instruction Details
3-68
2
Chapter 2 Instructions
Example
Coding
Description
0500 and 0501 turn ON 0.1-s after 0000 turns ON.
TMH is a subtraction timer. When the current value reaches "#00000", the
contact of the timer No. turns ON.
When input relay 0000 turns OFF, contact T000 turns OFF and the current value
of TMH000 is reset.
Note 1: The TMH number cannot be the same as any other TMS, TMH, TMR, C, or
UDC instructions in the same program.
Note 2: The current value of TMH is not retained but is reset to the preset value if
power failure occurs or if power is turned OFF.
When the number specified by TMH is used as a contact (T000 in the above
example), this contact can be used as many times as desired. It can also be
used as both N.O. and N.C. contacts.
Timer accuracy = 0.01 sec. + (1 scan time) (max.)
Operand
Key operations
TMH: 0.01-s Timer
Sets a 16-bit on-delay timer that
counts down in 0.01-s decrements.
*1 0.01 s x 10 = 0.1 s
LDB
4
OR
9
FUN
#ddddd
Txxx
T
H
0000
T000 0500
#00010

T000
T
H
Line No. Instruction Operand
0000 LD 0000
0001 TMH 000 #00010*
1
0002 LD T000
0003 OUT 0500
FUN
LDB
4
OR
9
Operand
(Preset value)
Operand
(TMH No.)
ENT
R-SRCH
ENT
R-SRCH
:
TMH
Visual KV KV-300 KV-10/16 KV-24/40/80
No.: 000 to 249 No.: 000 to 249 No.: 000 to 063 No.: 000 to 119
Preset value: Preset value: Preset value: Preset value:
#00000 to #65535 #00000 to #65535 #00000 to #65535 #00000 to #65535
2.4 Instruction Details
1
2
3-69
Chapter 2 Instructions
Example
Coding
Description
0500 and 0501 turn ON 0.1-s after 0000 turns ON.
TMS is a subtraction timer. When the current value reaches "#00000", the
contact of the timer No. turns ON.
When input relay 0000 turns OFF, contact T000 turns OFF and the current value
of TMS000 is reset.
Note 1: The TMS number cannot be the same as any other TMS, TMH, TMR, C, or
UDC instructions in the same program.
Note 2: The current value of TMS is not retained but is reset to the preset value if
power failure occurs or if power is turned OFF.
When the number specified by TMS is used as a contact (T000 in the above
example), this contact can be used as many times as desired. It can also be
used as both N.O. and N.C. contacts.
Timer accuracy = 0.001 sec. + (1 scan time) (max.)
Operand
Key operations
TMS: 1-ms Timer
Sets a 16-bit on-delay timer that
counts down in 0.01 ms decrements.
*1 0.001 s x 100 = 0.1 s
SET
1
ANB
5
FUN
#ddddd

Txxx
T
S
0000
T000 0500
#00100

T000
T
S
Preset value: 0.1 s
Line No. Instruction Operand
0000 LD 0000
0001 TMS 000 #00010*
1
0002 LD T000
0003 OUT 0500
SET
1
ANB
5
FUN
ENT
R-SRCH
ENT
R-SRCH
Operand
(Preset value)
Operand
(TMS No.)
:
TMS
Visual KV KV-300 KV-10/16 KV-24/40/80
No.: 000 to 249 No.: 000 to 249 No.: 000 to 063 No.: 000 to 119
Preset value: Preset value: Preset value: Preset value:
#00000 to #65535 #00000 to #65535 #00000 to #65535 #00000 to #65535
2.4 Instruction Details
3-70
2
Chapter 2 Instructions
Applications of TMR instruction
I One-shot circuit
When input relay 0000 turns ON, output relay 0500 turns ON and remains ON for a
specified time.
Timing diagram
Coding
I Off-delay circuit
When input relay 0000 turns ON, output relay 0500 turns ON. 0500 turns OFF in a
specified time after 0000 turns OFF.
Timing diagram
Coding
0000
T000 0500 0500
#00020

T000
OFF
ON
ON ON
0000
0500
Line No. Instruction Operand
0000 LD 0000
0001 OR 0500
0002 TMR 000 #00020
0003 ANB T000
0004 OUT 0500
0000 T000
0000 0500
0500

#00020
T000
OFF
ON
ON
0000
0500
Line No. Instruction Operand
0000 LD 0000
0001 OR 0500
0002 ANB T000
0003 OUT 0500
0004 ANB 0000
0005 TMR 000 #00020
2 sec.
2 sec.
2 sec.
2 sec.
2 sec.
TMR
2.4 Instruction Details
1
2
3-71
Chapter 2 Instructions
I On-delay circuit
Output relay 0500 turns ON in a specified time after input relay 0000 turns ON.
When input relay 0000 turns OFF, output relay 0500 also turns OFF.
Timing diagram
Coding
I Flicker circuit
Output relay 0500 turns ON and OFF repeatedly while input relay 0000 is ON.
Timing diagram
Coding
0000
T000 0500
#00020
T000
OFF
ON
ON
0000
0500
Line No. Instruction Operand
0000 LD 0000
0001 TMR 000 #00020
0002 LD T000
0003 OUT 0500
0000 T001
T000
0500

#00020
T000
#00010
T001
2 sec.
2 sec.
1 sec.
OFF
ON
ON ON
0000
0500
ON
Line No. Instruction Operand
0000 LD 0000
0001 ANB T001
0002 TMR 000 #00020
0003 LD T000
0004 AMR 001 #00010
0005 OUT 0500
2 s 1 s
2 s 1 s 2 s 1 s 2 s 1 s
TMR
2.4 Instruction Details
3-72
2
Chapter 2 Instructions
0001
0000
#00010
C000
Example
Coding
Timing diagram (C000#00010 and 0500 in the above example)
Description
The counter performs one counting at the rising edge of clock pulse. When the
current value reaches the preset value, the coil of specified No. turns ON.
When a reset input (b [N.C.] contact) turns ON, the current counter value is reset
to "00000".
Since C is software counter which is set on the program, the response speed
depends on the scan time.
Note 1: When a reset input is provided using an a (N.O.) contact, the current
counter value is reset at power-off.
Note 2: The C number cannot be the same as any other TMS, TMH, TMR, C, or
UDC instructions in the same program.
Note 3: The current C value is stored more than two months (KV-10xx: More than
20 days) at 25C even when the KV is not in operation or is turned off.
Tips
By entering relay 2007 (which can turn the counter OFF for only the first scan time
when the operation is started) using an 'a' (N.O.) contact in series as the input relay
for resetting counter, you can reset the current C value whenever the operation is
started.
C: Counter Sets a 16-bit up-counter.
#ddddd
nnnn
Cxxx
CTR
(
C
)
0001
C000 0500
0000
#00010
C000
Line No. Instruction Operand
0000 LDB 0001
0001 C 000 #00010 0000
0002 LD C000
0003 OUT 0500
ON
#00010 1
2
3
4
5
6
7
8
9
10
C000
0500
OFF
ON
:
Reset input Preset value
Counter No.
Count input
0000
(Count input)
0001
(Reset input)
Current value
of C000
C
2.4 Instruction Details
1
2
3-73
Chapter 2 Instructions
Details of counter
I Extended ladder
The counter for the KV Series supports the extended ladder method.
The extended ladder allows you to connect contacts or output coils after the
counter in series, reducing the number of ladder program lines.
In the following example, the counter starts counting when counter input relay 0004
turns ON. When the current counter value reaches "300", output relay 0500 turns
ON.
Coding
"CON instruction" (p. 3-102)
For details of the extended ladder, refer to "1.5 Extended Ladder Diagrams"
(p.3-29).
Operands
Key operation
0002 C002 0500
0004
#00300
C002
Line No. Instruction Operand
0000 LDB 0002
0001 C 002 #00300 0004
0002 CON
0003 AND C002
0004 OUT 0500
0001 2007
0000
#00010
C005
C
CTR
(
C
)
Operand
(Counter No.)
Operand
(Preset value)
Operand
(Count input)
ENT
R-SRCH
KV counter
Visual KV KV-300 KV-10/16 KV-24/40/80
No.: 000 to 249 No.: 000 to 249 No.: 000 to 063 No.: 000 to 119
Count input: Count input: Count input: Count input:
0000 to 17915 0000 to 0009, 0000 to 2915 0000 to 6915
0500 to 17915
Preset value: Preset value: Preset value: Preset value:
#00001 to #65535 #00000 to #65535 #00000 to #65535 #00000 to #65535
2.4 Instruction Details
3-74
2
Chapter 2 Instructions
0001
2009
0000
#09999
C002
2002 0500 #01000
CMP
2009 0501 #02000
CMP
2009 0502 #03000
CMP
C002
LDA
Applications of C (counter) instruction
I Long-duration timer
Sets a long-duration timer by combining a timer and a counter.
Output 0500 turns ON in 1 hour.
Coding
"1.3.7 Special Utility Relays" (p. 3-12)
I Accumulator timer (Remains ON in case of power failure)
Coding
I Large capacity counter
Coding
I Multi-level setting
Sets a multi-level counter using arithmetic instructions.
Outputs in 3 different levels according to the current counter value.
Current counter value
1000 or more 0500 turns ON.
2000 or more 0501 turns ON.
3000 or more 0502 turns ON.
"2.4.3 Arithmetic Instructions" (p. 3-134)
0000
2006
#03600
C002
C002 0500
Special utility relay
(1-second clock)
Line No. Instruction Operand
0000 LDB 0000
0001 C 002 #03600 2006
0002 LD C002
0003 OUT 0500
0001 C001
2006
#03600
C001
0001
1000
#00600
C002
C001 1000
Line No. Instruction Operand
0000 LDB 0001
0001 ANB C001
0002 C 001 #03600 2006
0003 LD C001
0004 OUT 1000
0005 LDB 0001
0006 C 002 #00600 1000
0002 C000
0000
#10000
C000
0002
1000
#65535
C001
C000 1000
Line No. Instruction Operand
0000 LDB 0002
0001 ANB C001
0002 C 001 #10000 0000
0003 LD C000
0004 OUT 1000
0005 LDB 0002
0006 C 001 #65535 1000
C
2.4 Instruction Details
1
2
3-75
Chapter 2 Instructions
Coding
I Counter multi-level setting
Outputs in 3 different levels according to the counter current value.
Current counter value
00000 to 00999 0500 turns ON.
01000 to 01999 0501 turns ON.
02000 to 02999 0502 turns ON.
Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB 0002 0010 MRD
0001 C 002 #09999 0000 0011 CMP #02000
0002 LD 2002 0012 CON
0003 LDA C002 0013 ANB 2009
0004 CON 0014 OUT 0501
0005 MPS 0015 MPP
0006 CMP #01000 0016 CMP #03000
0007 CON 0017 CON
0008 ANB 2009 0018 ANB 2009
0009 OUT 0500 0019 OUT 0502
C
0001
2011
0000
#09999
C000
2002 0500 #00999
CMP
2011 0501 #01999
CMP
2011
0500
0500 0501 0502 #02999
CMP
C000
LDA
Line No. Instruction Operand
0000 LDB 0001
0001 C 000 #09999 0000
0002 LD 2002
0003 LDA C000
0004 CON
0005 MPS
0006 CMP #00999
0007 CON
0008 ANB 2011
0009 OUT 0500
0010 MRD
0011 CMP #01999
0012 CON
0013 ANB 2011
0014 ANB 0500
0015 OUT 0501
0016 MPP
0017 CMP #02999
0018 CON
0019 ANB 2011
0020 ANB 0500
0021 ANB 0501
0022 OUT 0502
2.4 Instruction Details
3-76
2
Chapter 2 Instructions
Example
Coding
Timing diagram
When UP input relay (0001) turns ON, the current value of the counter is
incremented by one. When DOWN input relay (0002) turns ON, the current value
is decremented by one.
C000 turns ON when the digit shifts (#00009 to #00000, or #00000 to #00009).
Note 1: The UDC number cannot be the same as any other TMS, TMH, TMR, C, or
UDC instructions in the same program.
Note 2: The current UDC value is stored more than two months (KV-10xx: More
than 20 days) at 25C even when the KV is not in operation or is turned off.
Operands
Key operation
UDC: Up-Down Counter Sets a 16-bit up-down-counter.
UDC xxx
#ddddd
UP
DW
RES
ANB
5
ANL
2
FUN
0001
0002
0003
C000 0500
UDC 000
UP
#00009
DW
RES
Line No. Instruction Operand
0000 LD 0001
0001 LD 0002
0002 LD 0003
0003 UDC 000 #00009
0004 LD C000
0005 OUT 0500
1
2
3
4
5
6
7
8
9
OFF
ON
OFF
ON
OFF
ON
OFF
ON
ANB
5
ANL
2
FUN
Operand
(Preset value)
Operand
(C No.)
ENT
R-SRCH
ENT
R-SRCH
UP input
DOWN input
RESET input
Current value of C000
Carry
Time
Carry
ON
C000
Input for up 0001
Input for down 0002
Input for resetting
0003
:
UDC
Visual KV KV-300 KV-10/16 KV-24/40/80
No.: 000 to 249 No.: 000 to 249 No.: 000 to 063 No.: 000 to 119
Preset value: Preset value: Preset value: Preset value:
#00000 to #65535 #00000 to #65535 #00000 to #65535 #00000 to #65535
2.4 Instruction Details
1
2
3-77
Chapter 2 Instructions
Application of UDC instruction
I Multi-level UP/DOWN counter
UP/DOWN counter which allows a count setting value up to 99,990,000.
Coding
The example below outputs the high-order 4 digits of 8-digit BCD to UDC001 and
the low-order 4 digits of 8-digit BCD to UDC000.
Low-order 4 digits
0001
0002
0003
UDC 000
UP
#09999
DW
RES
C000
C000
0001
0002
0003
UDC 001
UP
#09999
DW
RES
0001
0002
BCD
BCD
High-order 4 digits
Line No. Instruction Operand
0000 LD 0001
0001 LD 0002
0002 LD 0003
0003 UDC 000 #09999
0004 LD C000
0005 AND 0001
0006 LD C000
0007 AND 0002
0008 LD 0003
0009 UDC 001 #09999
0004 C000
LDA TBCD
0500
STA
C001
LDA TBCD
0600
STA
Up-input
Down-input
Low-order
4 digits
High-order
4 digits
UDC
2.4 Instruction Details
3-78
2
Chapter 2 Instructions
Example
Coding
Timing diagram (0000, 1000, and 1001 in the above example)
The DIFU instruction turns ON the relay specified by the operand for only the 1st
scan time at the rising edge of input signal (0000).
The DIFD instruction turns ON the relay specified by the operand for only the 1st
scan time at the falling edge of input signal (0000).
Note 1: Any DIFU/DIFD operand relay No. cannot be duplicated in a program.
Note 2: When an expanded ladder is used, the DIFU instruction in example a)
operates without any problems. However, with the DIFD instruction in example b),
output relay 0500 does not turn ON because 1000 turns ON at the next scan after
the falling edge of input relay 0000 though input relay 0000 is already OFF. In this
case, change the ladder diagram as in example c).
Operands
* Note that of I/O Nos.7000 to 9915, those that are not assigned to expansion or I/O
terminal module ports can be used for internal utility relays.
Key operation
DIFU: Differentiate Up
DIFD: Differentiate Down:
Detects rising edge of input signal and turns
ON specified relay for 1st scan time only.
Detects falling edge of input signal and turns
ON specified relay for 1st scan time only.
nnnn

DIFD
nnnn

DIFU
SET
1
RES
0
RES
0
FUN
FUN
OR
9
0000

1000
DIFU

1001
DIFD
Line No. Instruction Operand
0000 LD 0000
0001 DIFU 1000
0002 DIFD 1001
ON
ON
0000
1000
1001
OFF
ON
0000 1000

1000
DIFU
0500 0000 1000

1000
DIFD

1000
DIFD
0500
0000
1000 0500
a) 0500 turns ON for one scan at the rising edge
of input relay 0000.
c) 0500 turns ON for one scan at the
falling edge of input relay 0000.
b) 0500 does not turn ON for one scan at
the falling edge of input relay 0000.
SET
1
RES
0
RES
0
FUN FUN
OR
9
Operand
(Relay No.)
Operand
(Relay No.)
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
:
:
ON for 1st scan time only
ON for 1st scan time only
DIFU / DIFD
Visual KV KV-300 KV-10/16 KV-24/40/80
1000 to 1915 1000 to 1915 1000 to 1915 1000 to 1915
3000 to 9915 3000 to 6915 3000 to 6915
*7000 to 9915
2.4 Instruction Details
1
2
3-79
Chapter 2 Instructions
Application of DIFU, DIFD instructions
I One-shot circuit using the differentiate instruction
When input relay 0000 turns ON/OFF, output relay 0500 and 0501 turns ON one-
shot (1 second).
Coding
Timing diagram
I Alternating circuit
Every time input relay 0000 turns ON, output relay 0500 turns ON and OFF alter-
nately.
Coding
0000
1000 T001
0500
1001 T002
0501
0500

1000
DIFU
1001
DIFD
#00010
T001
0501
#00010
T002
Line No. Instruction Operand
0000 LD 0000
0001 DIFU 1000
0002 DIFD 1001
0003 LD 1000
0004 OR 0500
0005 ANB T001
0006 OUT 0500
0007 TMR 001 #00010
0008 LD 1001
0009 OR 0501
0010 ANB T002
0011 OUT 0501
0012 TMR 002 #00010
ON
ON
0000
1000
1001
0500
0501
OFF
ON
OFF
ON
OFF
ON
0000

1000
DIFU
1000
1000
0500
0500 0500
Line No. Instruction Operand
0000 LD 0000
0001 DIFU 1000
0002 LD 1000
0003 ANB 0500
0004 LDB 1000
0005 AND 0500
0006 ORL
0007 OUT 0500
1 s
1 s
DIFU / DIFD
2.4 Instruction Details
3-80
2
Chapter 2 Instructions
ANL
2
ANL
2
FUN
Operand
(Relay No.)
ENT
R-SRCH
ENT
R-SRCH
Example
Coding
Description
When SET input relay No. 0001 is ON and RESET input relay No. 0002 is OFF,
0500 turns ON.
When RES input (0002) is ON, output relay 0500 turns OFF.
When both 0001 and 0002 are OFF, the previous status is retained.
Note 1: When 0500 used for KEEP instruction in the above example is changed to
OUT instruction ( ), it forms a double coil. In such a case, priority is given to the
instruction that is entered last "Double coil" (p. 3-65)
Note 2: When both 0001 and 0002 are ON, RESET (0002) has priority over SET
(0001), causing 0500 to turn OFF.
Tips
Internal utility relay latching function
The ON/OFF status of an internal utility relay immediately before power-off can be
stored by setting the memory switch (MEMSW).
"MEMSW instruction" (p. 3-92)
If this stored utility relay is used for a latching instruction (SET or KEEP), the relay
settings can be stored while the power is off.
Coding
Operands
Key operation
Line No. Instruction Operand
0000 LD 0000
0001 DIFU 1000
0002 DIFD 1001
KEEP: Keep
Turns ON specified relay when SET input
relay turns ON and enables this relay to
remain ON. And, turns OFF specified relay
when RESET input relay turns ON.
OR
9
ORL
3
FUN
KEEP

SET
RES
nnnn
0001
0002
KEEP
SET
0500
RES RES RESET input
SET input
0001
0002
1000
KEEP
MEMSW
SET
1000
$0004
RES RES
0500
Stores the status of
internal utility relays
1000 through 1915.
Line No. Instruction Operand
0000 MEMSW $0004
0001 LD 0001
0002 LD 0002
0003 KEEP 1000
0004 LD 1000
0005 OUT 0500
:
KEEP
0500
Visual KV KV-300 KV-10/16 KV-24/40/80
0500 to 1915 0500 to 1915 0500 to 1915 0500 to 1915
2009 2009 2009 2009
2100 to 17915 2100 to 17915 2100 to 2915 2100 to 6915
2.4 Instruction Details
1
2
3-81
Chapter 2 Instructions
Application of KEEP instruction
I Detection of chewing gum packs
Detects chewing gum packs over the carton using the proximity switch ES series
(0001 to 0003). If the switch detects that one or more packs of chewing gum are
missing, output relay 0500 turns ON for 1 s.
The timing clock is generated from the visible beam photoelectric switch PZ2 (0000).
Executes SET when all input relays 0000 to 0003 are ON.
Detects presence/absence of chewing gum packs at DOWN edge of 0000.
Outputs 1-s one-shot pulse from output relay 0500 when 1000 is OFF.
Coding
Timing diagram
Reflector R-2
ES
PZ2-61
ES
ON
Gum
Gum
Gum
Gum
Gum
Gum
Gum
Gum
OFF ON
0000
1001
0000 1001
DIFD
#00010
T001
1001 1000 T001
0500
0001 0002 0003
KEEP
SET
1000
RES RES
0500
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0000 0007 DIFD 1001
0001 AND 0001 0008 LD 1001
0002 AND 0002 0009 ANB 1000
0003 AND 0003 0010 OR 0500
0004 LD 1001 0011 ANB T001
0005 KEEP 1000 0012 OUT 0500
0006 LD 0000 0013 TMR 001 #00010
0000
0001
0002
0003
0500
OFF
ON
OFF
ON
OFF
ON
OFF
ON
OFF
ON
ON ON
Executes SET when all input relays
0000 to 0003 are ON.
Detects presence/absence of chewing
gum packs all Down edge of 0000.
Outputs 1-s one-shot plus from output
relay 0500 when 1000 is OFF.
1 s
KEEP
2.4 Instruction Details
3-82
2
Chapter 2 Instructions
SFT: Shift Sets a shift register.
Example
Coding
Timing diagram
Description
First relay No. 1000 turns ON (OFF) when the data input relay is ON (OFF) at the
rising edge of the clock pulse.
Clock pulse A) shifts the ON status of input relay 0001 to relay 1000, and shifts
the status of other relays in sequence as shown in A) on the right.
When the data input is OFF as for clock pulse E), OFF status is shifted to relay
1000.
When the RESET input relay turns ON, all the relays (from the first one to the last
one) turn OFF.
Several SFT instructions can be used in a program.
Note: No SFT operand relay No. can be duplicated in a program.
SFT
nnnn
mmmm
D
CLK
RES
OR
9
ORL
3
FUN
0001
0002
0003
1002 0500
SFT
D
1000
CLK
1002
RES
Line No. Instruction Operand
0000 LD 0001
0001 LD 0002
0002 LD 0003
0003 SFT 1000 1002
0004 LD 1002
0005 OUT 0500
0500
1002
1001
1000
0002
OFF
ON
0001
0003
OFF
ON
OFF
ON
ON
ON ON
ON ON
1002 1001 1000 0001
0 OFF
1 ON
0 0 1 1 A)
ON ON
ON ON
1002 1001 1000 0001
0 1 1 1 B)
1002 1001 1000 0001
1 1 1 1 C)
1002 1001 1000 0001
1 1 1 1 D)
1002 1001 1000 0001
1 1 0 0 E)
1002 1001 1000 0001
1 0 0 1 F)
1002 1001 1000 0001
0 0 1 1 G)
A B C D E F G
RESET input
Data input
First relay No.
Clock
Last relay No.
RESET input
Data input
Clock
:
SFT
Relay shift
operation
Lost
Lost
Lost
Lost
Lost
Lost
Lost
2.4 Instruction Details
1
2
3-83
Chapter 2 Instructions
Operands
* Note that of I/O Nos. 7000 to 9915, those that are not assigned to expansion or remote I/O
unit ports can be used for internal utility relays.
Key operation
Applications of SFT instruction
I Alternating circuit
Every time input relay No. 0000 turns ON, 0500 turns alternately ON and OFF.
Coding
Timing diagram
Reference: Alternating circuit can be configured without SFT instruction.
The following circuit does the same operation as the circuit above.
"DIFU instruction" (p. 3-78)
Coding
1000
0000
2003
1000 0500
SFT
D
1000
CLK
1000
RES
Line No. Instruction Operand
0000 LDB 1000
0001 LD 0000
0002 LD 2003
0003 SFT 1000 1000
0004 LD 1000
0005 OUT 0500
ON
OFF
ON ON ON ON ON
0000
0500
Line No. Instruction Operand
0000 LD 0000
0001 DIFU 1000
0002 LD 1000
0003 ANB 0500
0004 LDB 1000
0005 AND 0500
0006 ORL
0007 OUT 0500
SFT
FUN
OR
9
ORL
3
Operand
(Relay No.)
Operand
(Relay No.)
ENT
R-SRCH
ENT
R-SRCH
0000

1000
DIFU
1000
1000
0500
0500 0500
Visual KV KV-300 KV-10/16 KV-24/40/80
1000 to 1915 1000 to 1915 1000 to 1915 1000 to 1915
3000 to 6915 3000 to 6915 3000 to 6915
*7000 to 9915
2.4 Instruction Details
3-84
2
Chapter 2 Instructions
Line No. Instruction Operand
0000 LD 2008
0001 SET 1000
0002 LDB T001
0003 T001 #00010
0004 LD 2003
0005 LD T001
0006 LD 2003
0007 SFT 1000 1005
0008 LD 1000
0009 OUT 0500
0010 LD 1001
0011 OUT 0501
0012 LD 1002
0013 OUT 0502
0014 LD 1003
0015 OUT 0503
0016 LD 1004
0017 OUT 0503
0018 LD 1005
0019 SET 1000
I Resetting internal utility relays
When input relay No. 0000 turns ON, all internal utility relays No. 1000 through 1915
turn OFF.
SFT instruction can be substituted for RES instruction. This application can be used
to reset many relays at one time.
(All relays 3000 through 9915 can also be turned OFF at one time.)
Coding
I Repeat shift circuit
Turns ON every output for a second sequentially. Sets 1000 to 2008 (ON for 1st
scan only at startup) and shifts outputs from 0500 to 0504 every second at T001.
When 1005 turns ON, 1000 is set and the same sequence as above repeats.
Coding
2003
2003
0000
SFT
D
1000
CLK
1915
RES
Line No. Instruction Operand
0000 LD 2003
0001 LD 2003
0002 LD 0000
0003 SFT 1000 1915
2003
T001
2008
T001
2003
SFT
D
1000
CLK
1005
RES
1000
1001
1002
1003
1004
1005
#00010
T001

1000
SET
0500
0501
0502
0503
0504
1000
SET
SFT
2.4 Instruction Details
1
2
3-85
Chapter 2 Instructions
I Asynchronous shift register
Turns ON input relay 0002 to reset the shift register (1000 to 1010) when the data
input to 0000 does not synchronize with the clock input to 0001.
Coding
Timing diagram
2003
0001
0002
SFT
D
1000
CLK
1010
RES
1100
0000 1100
DIFU
1000
SET
Line No. Instruction Operand
0000 LD 0000
0001 DIFU 1100
0002 LD 1100
0003 SET 1000
0004 LD 2003
0005 LD 0001
0006 LD 0002
0007 SFT 1000 1010
ON
OFF
ON
OFF
ON
OFF
ON
OFF
ON
OFF
1001
0000
0001
1002
1000
Scan
SFT
2.4 Instruction Details
3-86
2
Chapter 2 Instructions
HSP: High Speed
Shortens time constant of specified input
relay to 10 s to increase input response.
SET
1
AND
8
FUN
HSP
nnnn
0000 HSP
0001
0001 0500
SET
0002 0501
SET
0003 0500
RES
0501
RES
Example
Coding
Timing diagram
Description
When enable input 0000 turns ON, the time constant of input 0001 (specified by
HSP) changes from 10 ms to 10 s.
When enable input relay 0000 is ON and the scan time is 1 ms, and when the
ON time ( ) of input relays 0001 and 0002 is 5 ms, output relay 0500 turns ON
but 0502 does not.
"1.4.3 Constant Scan Time Mode" (p. 3-25)
Note 1: The time constant is switched by special utility relays 2609 through 2612
with the expansion units, or by the provided switches with I/O distribution module.
Note 2: The HSP instruction is used for the input to basic units only.
Enable input
Line No. Instruction Operand
0000 LD 0000
0001 HSP 0001
0002 LD 0001
0003 SET 0500
0004 LD 0002
0005 SET 0501
0006 LD 0003
0007 RES 0500
0008 RES 0501
ON ON ON
ON
0000
0002
0001
0003
0500
0501
ON ON
ON ON
ON ON
ON
OFF
ON
5 ms 5 ms 15 ms
:
HSP
2.4 Instruction Details
1
2
3-87
Chapter 2 Instructions
Note 3: The HSP instruction must be specified when the INT instruction or high-
speed counter is used.
Note 4: When special utility relay 2813 and HSP instruction turn ON at the same
time, priority is given to the HSP instruction and the time constant is changed to 10
s.
Note 5: Connect a non-contact input for the HSP instruction to prevent a contact
bounce from being entered.
Details of HSP Instruction
This section describes the operation of the HSP instruction.
I Input signal width
Even if the input signal width is shorter than the scan time, the signal can be fetched
when it turns ON during input process as in 1). However, it cannot be fetched when
it turns ON any other time than the input process as in 2).
For reliable signal reception, the input signal width must be longer than the scan
time as in 3).
Scan time < Input signal width < Normal time constant (10 ms 20%)
I Switching the input time constant of expansion units
Expansion input unit Expansion I/O unit
KV-E4X KV-E4XT(P)
KV-E8X KV-E4XR
KV-E16X
The input time constant of an expansion unit is initially set to 10 ms.
It can be changed to 10 s by creating a ladder program or by using the Access
Window, the LADDER BUILDER for KV programming support software, or with the
KV-P3E(01) handheld programmer.
Change the values of special utility relays 2609 to 2612.
Operands
Key operation
HSP
OFF
ON
1) 2) 3)
Scan time
O
u
t
p
u
t

d
e
v
i
c
e
Program
execution
Program
execution
Program
execution
Scan time Scan time
I
n
p
u
t
d
e
v
i
c
e
O
u
t
p
u
t

d
e
v
i
c
e
O
u
t
p
u
t

d
e
v
i
c
e
I
n
p
u
t
d
e
v
i
c
e
I
n
p
u
t
d
e
v
i
c
e
Special utility relay Description
2609 Input time constant of 1st unit. OFF: 10 ms, ON: 10 s
2610 Input time constant of 2nd unit. OFF: 10 ms, ON: 10 s
2611 Input time constant of 3rd unit. OFF: 10 ms, ON: 10 s
2612 Input time constant of 4th unit. OFF: 10 ms, ON: 10 s
FUN
SET
1
AND
8
Operand
(Relay No.)
ENT
R-SRCH
ENT
R-SRCH
KV-300 KV-10 KV-16 KV-24 KV-40/80
0000 to 0009 0000 to 0005 0000 to 0009 0000 to 0015 0000 to 0107
2.4 Instruction Details
3-88
2
Chapter 2 Instructions
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0007 END
0001 EI 0008 INT 0000
0002 SET 2813 0009 LD 2002
0003 LD 0500 0010 SET 0500
0004 T000 #00010 0011 RET1
0005 LD T000 0012 ENDH
0006 RES 0500
Applications of HSP Instruction
I High-speed fetching of input data
When the input signal at 0000 has pulses of 5-ms interval and 2-ms scan time and
input relay 0001 is ON, fetches data from input relay 0000 at high speed and outputs
1-s one-shot pulse from output relay 0500.
Coding
Timing diagram
* To input a signal having pulse interval shorter than the scan time, use the inter-
rupt instruction.
Refer to "Chapter 3 Interrupts" (p. 3-191).
I When using the interrupt instruction
Coding
0001 HSP
0000
0000
0500 T000 0500
#00010
T000
Line No. Instruction Operand
0000 LD 0001
0001 HSP 0000
0002 LD 0000
0003 OR 0500
0004 TMR 000 #00010
0005 ANB T000
0006 OUT 0500
ON
OFF
ON
OFF
0500
0000
0001
ON

2813
SET
EI
#00010
T000
2008
0500
T000

END

RETI

ENDH

INT
0500
RES
2002 0500
SET
0000
Turn ON for 1st scan only at startup.
Input time constant 10 s
Turns ON
timer for 1s
when 0500
is ON.
Resets 0500 when T000 turns ON.
Sets 0500 when 0000 turns ON.
Interrupt enabled
Initial settings
Sets interrupt input at 0000.

1-s timer
Scan
1 s
Turn ON for 1st
scan only at startup.
HSP
2.4 Instruction Details
1
2
3-89
Chapter 2 Instructions
MC: Master Control
MCR: Master Control
Reset
Selects ON/OFF status of relay coils, timers,
or counters set before MCR instruction.
Used in pairs with MC instruction to end the
execution of MC instruction.
LDB
4
ANB
5
ANL
2
ANL
2
MCR

MC

FUN
FUN
0000 MC
MCR

0001 0500
0501
Example
Coding
Description
When 0000 is OFF, both 0500 and 0501 do not turn ON, even if 0001 is turned
ON.
When 0000 is ON, 0500 turns ON and 0501 turns OFF as soon as 0001 is turned
ON.
Regard the function of MC-MCR instructions as "power switch" or "main switch".
When the input relay for MC is OFF, the instructions entered between MC and
MCR instructions function as follows:
Note: MC-MCR instructions cannot be used in the following configuration.
1. Nesting 2. Improper combination with STP-STE
instructions
"STP, STE instructions" (p. 3-114)
Operands
Key operation
Line No. Instruction Operand
0000 LD 0000
0001 MC
0002 LD 0001
0003 OUT 0500
0004 OUB 0501
0005 MCR
MC

MC

MCR

MCR

STP
x x x x
MC

STE

MCR

FUN FUN
LDB
4
ANB
5
ANL
2
ANL
2
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
:
:
MC / MCR
Instructions Function
OUT and OUB Corresponding relay is OFF
TMR, TMH, and TMS Timer is reset
C, SFT, KEEP, SET, RES, and CTH Previous status is retained
Other instructions such as TMIN Instruction is not executed.
2.4 Instruction Details
3-90
2
Chapter 2 Instructions
Details of MC-MCR Instructions
I Position of MC-MCR instructions
MC-MCR instructions can be used in the following positions.
Making an input condition
The input condition for an MC instruction can be made as shown below:
Note: The scan time is not shortened even if the input relay of the MC instruction is
OFF.
Output relays 0500 within and outside of the MC-MCR instructions form a double
coil as shown below. "Double coil" (p. 3-65)
In this case, priority is given to the instruction that is entered last.
1. MC-MCR instructions can
be placed before or after
STP-STE instructions.
This relay is ignored.
MC

STP
x x x x
STE

MCR

STP
x x x x
MC

MCR

STE

STP
x x x x

STE

MC

MCR

2. MC-MCR instructions can
be placed between STP
and STE instructions.
3. STP-STE instructions can
be placed between MC
and MCR instructions.
0000 0001 0002 MC
MCR

0003 0500
MC
0003
0001
0500
MCR
0002 0500
The last relay has priority.
MC / MCR
2.4 Instruction Details
1
2
3-91
Chapter 2 Instructions
Application of MC-MCR Instruction
I Emergency stop circuit
When input relay 0000 is ON, 0500 turns ON for 1 s, then 0501 turns ON for 2 s,
and then 0502 turns ON for 3 s, repeatedly.
Once input relay 0000 turns OFF, 0500 turns ON when 0001 is ON, 0501 turns ON
when 0002 is ON, and 0502 turns ON when 0003 is ON.
Timing diagram
Coding
ON ON
ON
ON
ON
ON ON
ON ON
0003
0501
0001
0502
0000
Scan
0500
0002
ON
OFF
ON
OFF
ON
OFF
ON
OFF
1102
RES
1101
RES
1100
RES
0000
0001
0020
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
MC
MCR
MCR
END
ENDH
1001 1000
0001 1203
1200
1203
0500
1201
1204
0501
1202
1205
0502
0002 1204
0003 1205
1200
0000
T000
1000
MC 1001
1002
DIFU
1002
T000
#00010
STG
1100
J MP
1101
1201 T001
T001
#00020
STG
1101
J MP
1102
1202 T002
T002
#00030
STG
1102
J MP
1100
MC / MCR
Line No. Instruction Operand
0000 LD 0000
0001 OUT 1000
0002 CON
0003 OUB 1001
0004 LD 0000
0005 DIFU 1002
0006 CON
0007 AND 1002
0008 RES 1100
0009 CON
0010 RES 1101
0011 CON
0012 RES 1102
0013 LD 1000
0014 MC
0015 STG 1100
0016 OUT 1200
0017 CON
0018 TMR 000 #00010
0019 CON
0020 AND T000
0021 JMP 1101
0022 STG 1101
0023 OUT 1201
0024 CON
0025 TMR 001 #00020
0026 CON
0027 AND T001
0028 JMP 1102
0029 STG 1102
0030 OUT 1202
0031 CON
0032 TMR 002 #00030
0033 CON
0034 AND T002
0035 JMP 1100
0036 MCR
0037 LD 1001
0038 MC
0039 LD 0001
0040 OUT 1203
0041 LD 0002
0042 OUT 1204
0043 LD 0003
0044 OUT 1205
0045 MCR
0046 LD 1200
0047 OR 1203
0048 OUT 0500
0049 LD 1201
0050 OR 1204
0051 OUT 0501
0052 LD 1202
0053 OR 1204
0054 OUT 0502
0055 END
0056 ENDH
2.4 Instruction Details
3-92
2
Chapter 2 Instructions
FUN
ANL
2
ORB
6
Operand
ENT
R-SRCH
ENT
R-SRCH
Key operation
Operands
$0000 to $FFFF
Example
Coding
Specify 3 of SW3 and 0 and 1 of SW4 to reset the values of DM1900 to DM1999, counter,
up-down counter, CTH, and CTC when the operation is started.
Description
Switch Nos. and functions are as follows. The switch consists of 16 bits. The func-
tion of the switch is specified by turning a certain bit ON or OFF.
MEMSW:
Memory Switch
Sets memory switches.
FUN
MEMSW
$nnnn
ANL
2
ORB
6
0 0 1 1
3 2 1 0
1 0 0 0
3 2 1 0
0 0 0 0
3 2 1 0
0 0 0 0
3 2 1 0
SW4 SW3 SW2 SW1
MEMSW
$3800
SW1 SW2 SW3 SW4
Cancels error and
starts operation.
Loads memory
from EEPROM
Does not load
memory from
EEPROM
Uses latch
function.
Doesn't use
latch function.
Uses latch
function.
Uses latch
function.
Uses latch
function.
Uses latch
function.
Doesn't use
latch function.
Doesn't use
latch function.
Doesn't use
latch function.
Doesn't use
latch function.

Clears DM.

24-bit 16-bit
Retains DM.
:
MEMSW
MEMSW
$3800
Line No. Instruction Operand
0000 MEMSW $3800
Write-protects
program.
Doesn't write-
protect program.
Clears values. Retains values.
24-bit 16-bit
Read-protects
program.
Doesn't read-
protect program.
Switch
No.
OFF
Function of switch ON
Retains error. 0 Cancels error when power is ON.
1 Action when "Memory error" occurs at
startup (due to data memory, counter
value, or retained content being erased).
2 Uses latch function of internal utility relays
1000 through 1915.
3 Uses latch function of internal utility relays
3000 through 3915.
0 Uses latch function of internal utility relays
4000 through 4915.
1 Uses latch function of internal utility relays
5000 through 5915.
2 Uses latch function of internal utility relays
6000 through 6915.
3 Not used.
0 Not used.
1 Clears DM0000 to DM0999 at power-on.
2 Clears DM1000 to DM1899 at power-on.
3 Switches between 24- and 16-bit compara-
tors for CTH0.
0 Switches between 24- and 16-bit compara-
tors for CTH1.
1 Clears values of counter, CTH, and CTC.
2 Write-protects program in KV PLC.
3 Read-protects program in KV PLC.

Clears DM.
Retains DM.
2.4 Instruction Details
1
2
3-93
Chapter 2 Instructions
(8)
2
3
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1
(4)
2
2
0
0
0
0
1
1
1
1
0
0
0
0
1
1
1
1
(2)
2
1
0
0
1
1
0
0
1
1
0
0
1
1
0
0
1
1
(1)
2
0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
0 0 0 0
3 2 1 0
0
0 0 1 0
3 2 1 0
2
0 1 1 0
3 2 1 0
6
1 0 0 1
3 2 1 0
9
SW4 SW3 SW2 SW1
MEMSW
$0269
Retains all errors when power is ON.
Retains utility relays 3000 through 3999.
(Switch No.)
(Example)
Hexadecimal
number
Clears DM0000 to DM0999
when power is ON.
Retains Internal utility relay
5000 through 5999 and 6000
through 6999.
MEMSW
Note 1: When a read-protected program is transferred into the KV PLC it cannot
be read or modified from this PLC. Before read-protecting a program, be sure to
create a backup copy of the program.
Note 2: When a 24-bit high-speed counter comparator is used, the ladder program
which specifies the numerical values of a 24-bit CTC is required before starting the
high-speed counter.
Note 3: The value of MEMSW can be changed even during operation. However,
the new operation is not actually performed. The change is effective only after the
KV is turned off or stopped once and then restarted.
Details of MEMSW
I Setting memory switches
Specify a hexadecimal number for each switch No.
Tips
The data entered for the memory switch is set into the KV PLC when the pro-
gram is transferred to the KV PLC.
When MEMSW instruction is not entered into the program, "$0000" is set.
If you try transfer a program into the KV PLC which is write-disabled, warning
message "WRITE PROTECTED REPLACE OK?" is displayed. When executing
the transfer regardless of the message, press .
Description
Hexadeci-
mal number
To use internal utility
relays 1000 through
1915 as latch relays.
To clear a counter when
operation is started.
To use a 24-bit high-
speed counter CTH1.
To clear a DM when
operation is started.
To read-protect a
program.
To use a 24-bit high-
speed counter CTH0.
MEMSW
$0004
MEMSW
$0E00
MEMSW
$8000
MEMSW
$2000
MEMSW
$0800
MEMSW
$1000
ENT
R-SRCH
2.4 Instruction Details
3-94
2
Chapter 2 Instructions
NOP: No Operation Performs no operation.
END: End
ENDH: End Hi
Indicates end of each routine of program.
Indicates end of entire program.
Normal program
RES
0
ORL
3
FUN
END
DM
ENDH
TM
END

ENDH

END

ENDH
ENDH


END

Subroutine program
Interrupt program
Normal program
END
DM
ENDH
TM
ENT
R-SRCH
ENT
R-SRCH
:
:
:
NOP END / ENDH
When ALL CLEAR [FNC60] or HANDHELD PROGRAMMER CLEAR (P3E CLEAR)
[FNC61] is executed to delete the program, NOP appears on all lines of the deleted
program.
NOP is not written by the KV IncrediWare (DOS)/LADDER BUILDER for KV pro-
gramming support software.
Description
END and ENDH instructions must be used at the end of a program.
A subroutine or interrupt program can be written between END and ENDH.
When not using either subroutine or interrupt programs, write ENDH immediately
after END.
Note: When a program does not have END or ENDH, "ENTER END", "ENTER
ENDH" or "LOGIC ERROR" occurs when the program is converted or transferred.
Operands
Key operation
2.4 Instruction Details
1
2
3-95
Chapter 2 Instructions
Instruction Mnemonic Reference page
W-ON: Wait ON W-ON 3-96
W-OFF: Wait OFF W-OFF 3-96
W-UE: Wait Up Edge W-UE 3-98
W-DE: Wait Down Edge W-DE 3-98
CON: Connect CON (FUN06) 3-102
MPS: Push MPS 3-103
MRD: Read MRD 3-103
MPP: Pop MPP 3-103
STG: Stage STG (FUN44) 3-106
JMP: Jump JMP (FUN21) 3-106
ENDS: End Stage END (FUN14) 3-106
STP: Step STP (FUN45) 3-114
STE: Step End STE (FUN43) 3-114
ITVL: Interval Timer ITVL 3-117
16-bit high-speed counter CTH 3-204
16-bit high-speed counter comparator CTC 3-204
16-bit high-speed counter CTH 3-204
16-bit high-speed counter comparator CTC 3-204
CALL: Subroutine Call CALL (FUN03) 3-122
SBN: Subroutine Entry SBN (FUN38) 3-122
RET: Subroutine Return RET (FUN33) 3-122
FOR: Repeat Start FOR (FUN16) 3-125
NEXT: Repeat End NEXT (FUN29) 3-125
HKEY: 16 Key input HKEY (FUN17) 3-131
2.4.2 Application Instructions
Application instructions are used for batch processing of input signals. Data is
transmitted to specified memory locations or changed into different formats. More-
over, parts of a program can be repeated or skipped with the instruction.
2.4 Instruction Details
3-96
2
Chapter 2 Instructions
Example
Coding
Timing chart
W-ON
When input relay 0000 is ON, output relay 0500 turns ON as soon as input operand
0001 turns ON. 0500 remains ON until 0000 turns OFF.
W-OFF
When input relay 0002 is ON, output relay 0501 turns ON as soon as input operand
0003 turns OFF. 0501 remains ON until 0002 turns OFF.
W-ON: Wait ON
W-OFF: Wait OFF
Turn ON second operand relay when first
operand relay contact turns ON.
Turns ON second operand relay when first
operand relay contact turns OFF.
Line No. Instruction Operand
0000 LD 0000
0001 W-ON 0001 1000
0002 LD 1000
0003 OUT 0500
0004 LD 0002
0005 W-OFF 0003 1001
0006 LD 1001
0007 OUT 0501
nnnn
OFF
mmmm
nnnn
ON
mmmm
W-ON
F
W-OFF
Li
0000
1000 0500
0001
ON
1000
0002
1001 0501
0003
OFF
1001
W-ON
W-OFF
ON
0000
0001
1000
0500
OFF
ON
OFF
ON
ON
ON
0002
0003
1001
0501
OFF
ON
OFF
ON
ON
:
:
W-ON / W-OFF
2.4 Instruction Details
1
2
3-97
Chapter 2 Instructions
Description
W-ON
When input relay 0000 is ON, output operand 1000 turns ON as soon as the
contact of input operand 0001 turns ON.
W-OFF
When input relay 0002 is ON, output operand 1001 turns ON as soon as the
contact of input operand 0003 turns OFF.
Note: Output operand relay Nos. for W-ON/W-OFF instructions cannot be dupli-
cated in a program.
Operands
* Note that of I/O Nos. 7000 to 9915, those that are not assigned to expansion or
remote I/O unit ports can be used for internal utility relays.
Key operation
0002 0003
1001
0002
0003
OFF
1001
1001
0000 0001
1000
0000
0001
ON
1000
1000
Same
operation
Input operand
Output operand
W-ON
F
W-OFF
Li
First operand
(nnnn)
Second operand
(mmmm)
ENT
R-SRCH
Same
operation
Input operand
Output operand
W-ON / W-OFF
Visual KV KV-300 KV-10/16 KV-24/40/80
nnnn: nnnn: nnnn: nnnn:
0000 to 17915 0000 to 0009 0000 to 2915 0000 to 6915
T000 to T249 0500 to 17915 T000 to T063 T000 to T119
C000 to C249 T000 to T249 C000 to C063 C000 to C119
CTC0 to CTC3 C000 to C249 CTC0 to CTC3 CTC0 to CTC3
mmmm: CTC0 to CTC3 mmmm: mmmm:
1000 to 1915 mmmm: 1000 to 1915 1000 to 1915
3000 to 9915 1000 to 1915 3000 to 6915
3000 to 6915
*7000 to 9915
2.4 Instruction Details
3-98
2
Chapter 2 Instructions
Example
Coding
Timing chart
G W-UE
When input relay 0000 is ON, output relay 0500 turns ON at rising edge of first
operand relay 0001.
As soon as input relay 0000 turns OFF, output relay 0500 turns OFF.
G W-DE
When input relay 0002 is ON, output relay 0501 turns ON at falling edge of first
operand relay 0003.
As soon as input relay 0002 turns OFF, output relay 0501 turns OFF.
W-UE: Wait Up Edge
W-DE: Wait Down Edge
Turns ON second operand relay at rising
edge of first operand relay contact.
Turns ON second operand relay at falling
edge of first operand relay contact.
Line No. Instruction Operand
0000 LD 0000
0001 W-UE 0001 1000
0002 LD 1000
0003 OUT 0500
0004 LD 0002
0005 W-DE 0003 1001
0006 LD 1001
0007 OUT 0501
nnnn
mmmm
nnnn
mmmm
W-UE
E
W-DE
Lo
0000

1000 0500
0001
1000
0002

1001 0501
0003
1001
W-UE
W-DE
ON
0000
0001
1000
0500
OFF
ON
OFF
ON
ON
0002
0003
1001
0501
OFF
ON
OFF
ON
:
:
W-UE / W-DE
2.4 Instruction Details
1
2
3-99
Chapter 2 Instructions
Description
W-UE
When input relay 0000 is ON, the output operand turns ON at the rising edge of
the input operand.
W-DE
When input relay 0002 is ON, the output operand turns ON at the falling edge of
the input operand.
Note 1: If the input operand is already ON before input relay 0000 turns ON, the
output operand does not turn ON.
Note 2: The W-UE/W-DE instruction must be used in subroutine programs that are
executed every scan time (because rising and falling edges cannot be recognized).
Note 3: Output operand relay Nos. for W-UE/W-DE instructions cannot be dupli-
cated in a program.
Operands
* Note that of I/O Nos. 7000 to 9915, those that are not assigned to expansion or
remote I/O unit ports can be used for internal utility relays.
Key operation
0000 1002
0001
1000
0000
0001
1000
1000
1002
DIFU
Same
operation
Input operand
Output operand
0002 1003
1001
0002
0003
1001
1001
0003 1003
DIFD
Same
operation
Input operand
Output operand
W-UE
E
W-DE
Lo
First operand
(nnnn)
Second operand
(mmmm)
ENT
R-SRCH
W-UE / W-DE
Visual KV KV-300 KV-10/16 KV-24/40/80
nnnn: nnnn: nnnn: nnnn:
0000 to 17915 0000 to 0009 0000 to 6915 T000 to T119
T000 to T249 00500 to 17915 0000 to 2915 C000 to C119
C000 to C249 T000 to T249 T000 to T063 CTC0 to CTC3
CTC0 to CTC3 C000 to C249 CTC0 to CTC3 mmmm:
mmmm: CTC0 to CTC3 mmmm: 1000 to 1915
1000 to 1915 mmmm: 1000 to 1915 3000 to 6915
3000 to 9915 1000 to 1915
3000 to 6915
*7000 to 9915
2.4 Instruction Details
3-100
2
Chapter 2 Instructions
Details of W-ON and W-UE Instructions
A combination of W-ON, W-OFF, W-UE, and W-DE instructions is much more
effective when used in programs controlling sequential operation where the comple-
tion of one operational step starts the next step.
This section describes minute differences in the operation of these instructions.
I Difference between W-ON and W-UE
W-ON: Output relay 0500 turns ON when both input relays 0000 and 0001 turn
ON in any order.
W-UE: Output relay 0501 turns ON only when input relay 0000 turns ON before
input relay 0001.
Note: An input operand relay No. for these instructions can be duplicated in a
program, but output operand relay Nos. cannot be duplicated.
As shown above, W-UE requires a certain order for turning ON relays 0000 and
0001, but W-ON does not. Therefore, W-UE is suitable for circuits to be executed at
every input; W-ON is suitable for circuits that go on to the next operation when a
certain condition is satisfied.
The operation of W-OFF and W-DE instructions are same as above by the operation
which turns relays OFF.
Output relay 0100 turns ON when both input relays
0000 and 0001 turn ON in any order.
Output relay 1001 turns ON only when input relay
0000 turns ON before input relay 0001.
0000

0100 0500
0001
ON
1000
0001
1001

1001 0501
ON
0000
0001
(W-ON)
(W-UE)
1000
0500
1001
0501
OFF
ON
OFF
ON
ON
ON
W-UE / W-DE
2.4 Instruction Details
1
2
3-101
Chapter 2 Instructions
Application of W-UE Instruction
I Input sequence check
Output relay 0500 turns ON when input relay 0000 is ON and input 0001, 0002, and
0003 turn ON in this sequence.
Output relay 0500 turns OFF when input relay 0000 is OFF.
Coding
Timing diagram
I Fork lift truck IN/OUT judgement
Checks the input sequence. Output relay 0500 turns ON when input relay 0000 turns
ON and then 0001 turns ON. Output relay 0501 turns ON when input relay 0001
turns ON and then 0000 turns ON.
Coding
Timing diagram
0000
0500
0001
1000
1000 0002
1001
1001 0003
1002
1002
Line No. Instruction Operand
0000 LD 0000
0001 W-UE 0001 1000
0002 LD 1000
0003 W-UE 0002 1001
0004 LD 1001
0005 W-UE 0003 1002
0006 LD 1002
0007 OUT 0500
ON
ON
OFF
ON
OFF
ON
OFF
ON
OFF 0003
0001
0000
0500
0002
0000 0500
0501
1001
1000
0001
1000
1001 0000
1001
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0000 0005 LD 0001
0001 W-UE 0001 1000 0006 W-UE 0000 1001
0002 CON 0007 CON
0003 AND 1000 0008 AND 1001
0004 OUT 0500 0009 OUT 0501
ON
ON
OFF
ON
OFF
0500
0000
0501
0001
ON
Scan
Leave warehouse
Enter warehouse
Scan
W-UE
2.4 Instruction Details
3-102
2
Chapter 2 Instructions
Example
Coding
Description
When input relay 0000 turns ON, 0500, 0501, 0502, and 0503 turn ON.
When input relay 0000 turns OFF, 0500, 0501, 0502, and 0503 turn OFF.
The CON instruction is used to connect instructions after output instructions
when the extended ladder is used.
When the LADDER BUILDER for KV programming support software is used, the
CON instruction is automatically converted into a mnemonic and entered in the
ladder diagram by just writing a connection line.
The CON instruction does not affect the scan time.
Refer to "1.5 Extended Ladder Diagrams" (p. 3-29) for details of eetecded ladders.
Operands
Key operation
CON: Connect
Represents series connection of output
instruction with another instruction.
RES
0
ORB
6
FUN
0000 0503 0502 0501 0500
CON CON CON
Line No. Instruction Operand
0000 LD 0000
0001 OUT 0500
0002 CON
0003 OUT 0501
0004 CON
0005 OUT 0502
0006 CON
0007 OUT 0503
RES
0
ORB
6
FUN
ENT
R-SRCH
ENT
R-SRCH
:
CON
2.4 Instruction Details
1
2
3-103
Chapter 2 Instructions
Example
Coding
Description
When input relay 0000 is ON:
0500 turns ON as soon as 0001 turns ON.
0501 turns ON as soon as 0002 turns ON.
0502 turns ON as soon as 0003 turns ON.
The MPS instruction is used at the start of an output branch.
The MRD instruction is used to connect an output branch.
The MPP instruction is used at the end of an output branch.
When the KV IncrediWare (DOS)/LADDER BUILDER for KV programming
support software is used, the MPS, MRD, and MPP instructions are automatically
converted into mnemonics and entered in the ladder diagram.
Note 1: Limit the number of MPS instructions to 8 or less in a circuit.
Note 2: An MPS instruction must have a corresponding MPP instruction. This
means that the same number of MPS and MPP instructions must be used in a
program. An MPS or MPP instruction without a corresponding MPP or MPS instruc-
tion results in a logic error.
Operands
Key operation
MPS: Push
MRD: Read
MPP: Pop
Stores current input and arithmetic flag
status.
Reads input and arithmetic flag status
stored with PUSH.
Reads and clears input and arithmetic flag
status stored with PUSH.
Line No. Instruction Operand
0000 LD 0000
0001 MPS
0002 AND 0001
0003 OUT 0500
0004 MRD
0005 AND 0002
0006 OUT 0501
0007 MPP
0008 AND 0003
0009 OUT 0502
MPS
C
MRD
D
MPP
c h
0000

0501
0500

0001
0002
0003 0502
MRD
MPP
MPS
MPS
C
MRD
D
MPP
ch
ENT
R-SRCH
:
:
:
MPS / MRD / MPP
2.4 Instruction Details
3-104
2
Chapter 2 Instructions
MPS/MRD/MPP applications
MPS, MRD, and MPP instructions are used as follows:
Coding
Coding
Start of branch
0002 0003 0004 0500
0006 0501
0007 0502
0008 0503
MPS
MRD
MRD
MPP
Connection of branch
End of branch
Connection of branch
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0000 0009 MPP
0001 MPS 0010 AND 0004
0002 AND 0001 0011 MPS
0003 MPS 0012 AND 0005
0004 AND 0002 0013 OUT 0502
0005 OUT 0500 0014 MPP
0006 MPP 0015 AND 0006
0007 AND 0003 0016 OUT 0503
0008 OUT 0501
0000 0001
0004
0002 0500
0003 0501
0005 0502
0006 0503
MPS
MPS
MPS
MPP
MPP
MPP
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0002 0007 OUT 0501
0001 AND 0003 0008 MRD
0002 MPS 0009 AND 0007
0003 AND 0004 0010 OUT 0502
0004 OUT 0500 0011 MPP
0005 MRD 0012 AND 0008
0006 AND 0006 0013 OUT 0503
MPS / MRD / MPP
2.4 Instruction Details
1
2
3-105
Chapter 2 Instructions
Coding
0000 0001 0002 0003 0004 0500
0501
0502
0503
0504
MPS MPS MPS MPS
MPP
MPP
MPP
MPP
Line No. Instruction Operand
0000 LD 0000
0001 MPS
0002 AND 0001
0003 MPS
0004 AND 0002
0005 MPS
0006 AND 0003
0007 MPS
0008 AND 0004
0009 OUT 0500
0010 MPP
0011 OUT 0501
0012 MPP
0013 OUT 0502
0014 MPP
0015 OUT 0503
0016 MPP
0017 OUT 0504
MPS / MRD / MPP
2.4 Instruction Details
3-106
2
Chapter 2 Instructions
Example
1) When transition condition relay 0000 is ON, transfers execution to STG1001.
2) 0500 turns ON. When transition condition relay 0001 is ON, transfers execution
to STG1002.
3) 0501 turns ON. When transition condition relay 0002 is ON, transfers execution
to STG1001 and repeats the process above.
When transition condition relay 0003 turns ON, transfers execution to STG1000
and 1003.
4) 0502 turns ON. The process finishes when transition condition relay 0004 turns
ON.
Coding
STG: Stage
JMP: Jump
ENDS: End Stage
Executes instructions in STG block when operand relay is ON.
When transition condition relay is ON, turns OFF relay of current
stage and transfers execution to stage specified by operand.
When transition condition relay is ON, turns OFF relay
of current stage.


ENDS
nnnn

J MP
nnnn

STG
LDB
4
LDB
4
LDB
4
SET
1
SET
1
ANL
2
FUN
FUN
FUN
Initial setting
2008
0000
0500

1001
J MP
1000
STG
0001 1002
J MP
1001
STG
0502 0004
ENDS
1003
STG
0501 0002 1001
J MP
1002
STG
0003 1000
J MP
1003
J MP
1000
SET
1)
2)
3)
4)
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0013 MPS
0001 SET 1000 0014 AND 0002
0002 STG 1000 0015 JMP 1001
0003 AND 0000 0016 MPP
0004 JMP 1001 0017 AND 0003
0005 STG 1001 0018 JMP 1000
0006 OUT 0500 0019 JMP 1003
0007 CON 0020 STG 1003
0008 AND 0001 0021 OUT 0502
0009 JMP 1002 0022 CON
0010 STG 1002 0023 AND 0004
0011 OUT 0501 0024 ENDS
0012 CON
:
:
:
STG / JMP / ENDS
2.4 Instruction Details
1
2
3-107
Chapter 2 Instructions
Note 1: The following table shows the status of each instruction between STG and
JMP/ENDS when STG operand relay turns OFF.
Note 2: STG/JMP/ENDS operand relay Nos. cannot be duplicated in a program.
Note 3: The STG instruction must be used in combination with the JMP or ENDS
instruction.
Note 4: The following instructions are not properly executed between STG and JMP/
ENDS instructions:
DIFU, DIFD, KEEP, UDC, SFT, FOR, NEXT, and
Differentiation type instruction (@xxx)
Operands
* Note that of I/O Nos. 7000 to 9915, those that are not assigned to expansion or
remote I/O unit ports can be used for internal utility relays.
Key operation
FUN
FUN
ANL
2
FUN
LDB
4
LDB
4
LDB
4
SET
1
SET
1
Operand
(nnnn)
Operand
(nnnn)
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
Instruction Function
Relay for OUT instruction Turned OFF.
Relay for OUB instruction Turned ON.
TMR, TMH, TMS, Reset.
C (counter) instructions
SET, RES instructions Current status is retained.
Other instructions Not executed.
STG / JMP / ENDS
Visual KV KV-300 KV-10/16 KV-24/40/80
1000 to 1915 1000 to 1915 1000 to 1915 1000 to 1915
3000 to 9915 3000 to 6915
*7000 to 9915
2.4 Instruction Details
3-108
2
Chapter 2 Instructions
Details of STG instruction
I STG instruction
The STG instruction is suitable for sequential step-by-step processing.
The whole process is divided into several operational steps, and one program is
assigned to each step.
The process to turn on several lamps sequentially can be divided into the following
five steps:
1) Wait until the start switch is turned ON.
2) Turn on lamp 1 for 1 second.
3) Turn on lamp 2 for 3 second.
4) Turn on lamp 3 for 5 second.
5) Turn on lamps 1, 2, and 3 simultaneously for 7 seconds.
These five steps are sequentially performed in order as shown in the flowchart
below.
If a ladder program is written for such sequential processing without any STG
instructions, the resulting program may be complicated and difficult to review by
others.
I I/O assignments
Assign the input and output of the Visual KV Series as follows:
1) Start switch: Turned on when 0000 turns ON.
2) Lamp 1: Lights when 0500 turns ON.
3) Lamp 2: Lights when 0501 turns ON.
4) Lamp 3: Lights when 0502 turns ON.
NO
YES
Start
Start
SW ON?
Turn on lamp 1
for 1 second.
Turn on lamp 2
for 3 second.
Turn on lamp 3
for 5 second.
Turn on lamps 1, 2,
and 3 simultaneously
for 7 seconds.
Sequential processing
0000 0500
KV
COM COM
0502
0501
Lamp 3
I/O assignment
Start SW
Lamp 1
Lamp 2
STG
2.4 Instruction Details
1
2
3-109
Chapter 2 Instructions
I Sequence program
Assign the relays to execute the five processes on the previous page as follows:
1 Wait until the start switch is turned ON.: Input relay 0000
2 Turn on lamp 1 for 1 second.: Output relay 0500
3 Turn on lamp 2 for 3 second.: Output relay 0501
4 Turn on lamp 3 for 5 second.: Output relay 0502
5 Turn on lamps 1, 2, and 3 simultaneously: Output relays 0500, 0501, and 0502
for 7 seconds.
The following is the ladder diagram for the I/O assignments above, and is written
with and without STG instructions.
Without STG instruction
With STG instruction
0000 T000
#00010
T000
1000
SET
1000
T000 T001 1001
1000
#00030
T001
1001
T001
T003
T002 1002
T002 T003 1100
1101
1102
#00050
T002
#00070
T003
1002
1100
1100
0500 1000
1101
0501 1001
1102
0502 1002
2008
0000 T000 1001
STG
1002
J MP
#00010
T000
0500
T001 1002
STG
1003
J MP
#00030
T001
0501
T002 1003
STG
1004
J MP
#00050
T002
T003 1001
J MP
#00070
T003
0502
1004
STG
0500 0501 0502
1001
SET
OR circuit is required because
double coil cannot be used.
1000 (0500) turns ON for 1 second
when input 0000 turns ON.
1001 (0501) turns ON for 3 seconds
when T000 turns ON.
1002 (0502) turns ON for 5 seconds
when T001 turns ON.
1100 (0500), 1101
(0501), and 1102 (0502)
turn ON for 7 seconds
when T002 turns ON.
The process is repeated from the
beginning when T003 turns ON.
The process is repeated from the
beginning when T003 turns ON.
1001 turns ON at the start of operation.
0500 turns ON for 1 second when input
0000 turns ON. Then, 1002 turns ON.
0501 turns ON for 3 seconds when
1002 turns ON. Then, 1003 turns ON.
0502 turns ON for 5 seconds when 1003
turns ON. Then, 1004 turns ON.
0500, 0501, and 0502 turn ON for 7
seconds when 1004 turns ON.
STG
2.4 Instruction Details
3-110
2
Chapter 2 Instructions
I Process progression with Wait instruction
Description
When using the W-UE instruction in a program with STG instructions on the previ-
ous page, you can create a program for an operation which moves to the next stage
every time when start switch 0000 turns ON (process progression).
"W-UE instruction" (p. 3-98)
Tips
Resetting STG instructions (in the above example)
Use the SFT instruction to turn OFF all STG instructions in an emergency.
Enter the initial setting process depending on the program. The above example
cannot start the next operation without the initial setting.
"SFT instruction" (p. 3-82)
Note 1: The scan time is not affected by any instructions between STG and JMP/
ENDS instructions which are not executed.
Note 2: STG operand relay Nos. cannot be duplicated in a program.
Note 3: The STG instruction must be connected to the bus.
Note 4: The STG, JMP, or ENDS instruction cannot be used in subroutines.
2008
1100
0500

1001
J MP
1000
STG
1002
J MP
1001
STG
0501 1003
J MP
1002
STG
0502
0500 0501 0502
1003
STG
1004
STG
1004
J MP
1000
SET
0000
1100
1104 1000
J MP
0000
1104
1101
1102
1103
0000
1101
0000
1102
0000
1103
2003
2003
SFT
D
1000
CLK
1004
RES
1000
SET Initial setting
Reset input
STG start relay
Reset input
STG end relay
STG
2.4 Instruction Details
1
2
3-111
Chapter 2 Instructions
Cautions for using STG instruction
Interlock
When an STG instruction moves to another stage, the previous and next stages turn
ON simultaneously only for one scan. Provide an interlock circuit for the output
which may be dangerous when turned ON in such occasions (e.g., motor's normal/
reverse rotation).
Double coil
A double coil can be used for an STG instruction.
Note: When STG 1000 and 1002 turn ON simultaneously, priority is given to output
relay 0500 of STG 1002, which is entered last.
Retaining output
Use the SET instruction to retain output.
When no JMP is used
When no JMP instruction is used, the STG instruction does not turn OFF even if
0001 turns ON. Be sure to use JMP after STG.
STG operand
When the STG operand relay remains ON, 0500 does not turn OFF even if 0001
turns ON.
Use a differentiation type instruction for the condition of the first STG instruction.
Double coil
0001
0501
0500

1001
J MP
1000
STG
1002
J MP
1001
STG
0002
0501
0500
1100
0501
0500

1001
J MP
1000
STG
1002
J MP
1001
STG
1101
0001
ON
1100
0002
ON
1101
0500 1003
J MP
1002
STG
1102 0003
ON
1102
0000

1001
1002
J MP
1000
STG

J MP
1001
STG
0001
0500
SET
0501
SET
0001 1000
STG
0500 0501
0001
0000
1000
STG
1001
J MP
0500
1000
SET
0001
1100 0000
1000
STG
1100
DIFU
1001
J MP
0500
1000
SET
Interlock
STG
2.4 Instruction Details
3-112
2
Chapter 2 Instructions
JMP operand
Unlike the STG operand relay, the JMP operand relay No. can be duplicated in a
program.
DIFU/DIFD instructions in an STG block
The operand relay for an STG instruction cannot be used as the input operand relay
for a DIFU or DIFD instruction.
Application of STG and JMP instructions
I Enabling a double coil
When start SW 0000 is pressed, the following output operation is repeated:
Output relay 0500 turns ON for 1 second.
Output relays 0500 and 0501 turn ON for 2 seconds.
Output relays 0500, 0501, and 0502 turn ON for 3 seconds.
Coding
0002 1001
STG
1002
J MP
0501
0001 1000
STG
1001
J MP
1002
J MP
0500
0501
0001
3000
1000
STG
3000
DIFU
1001
J MP
0500
1100
T000 1001
J MP
1100
DIFU
#00010
T000
0500 1000
STG
T001 1002
J MP
#00020
T001
0501 0500 1001
STG
T002 1000
J MP
#00030
T002
0502 0501 0500 1002
STG
1000
SET
0000
Outputs 0500, 0501, and 0502 turn ON for
3 seconds.
1000 turns ON at the rising edge of input 0000.
Output 0500 turns ON for 1 second.
Outputs 0500 and 0501 turn ON for 2 seconds.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0000 0016 CON
0001 DIFU 1100 0017 TMR 001 #00020
0002 CON 0018 CON
0003 AND 1100 0019 AND T001
0004 SET 1000 0020 JMP 1002
0005 STG 1000 0021 STG 1002
0006 OUT 0500 0022 OUT 0500
0007 CON 0023 CON
0008 TMR 000 #00010 0024 OUT 0501
0009 CON 0025 CON
0010 AND T000 0026 OUT 0502
0011 JMP 1001 0027 CON
0012 STG 1001 0028 TMR 002 #00030
0013 OUT 0500 0029 CON
0014 CON 0030 AND T002
0015 OUT 0501 0031 JMP 1000
STG / JMP
2.4 Instruction Details
1
2
3-113
Chapter 2 Instructions
Note: The double coils in different STG instruction blocks operate properly. How-
ever, when several STG instructions turn ON simultaneously, priority is given to the
one programmed last.
I Conditional branching
When input relay 0000 (start SW) turns ON, output relay 0500 turns ON. Then, as
programmed for conditional branching, output relay 0501 turns on for 1 second
when 0001 turns ON, and 0502 turns ON for 2 seconds when 0002 turns ON. After
each operation is completed, the program returns to the conditional branch and
repeats the same steps.
Coding
1100
0001 1001
J MP
1100
DIFU
1000
STG
0002 1002
J MP
0500
T000 1000
J MP
#00010
T000
0501 1001
STG
T001 1000
J MP
#00020
T001
0502 1002
STG
1000
SET
0000
Line No. Instruction Operand
0000 LD 0000
0001 DIFU 1100
0002 CON
0003 AND 1100
0004 SET 1000
0005 STG 1000
0006 OUT 0500
0007 CON
0008 MPS
0009 AND 0001
0010 JMP 1001
0011 MPP
0012 AND 0002
0013 JMP 1002
0014 STG 1001
0015 OUT 0501
0016 CON
0017 TMR 000 #00010
0018 CON
0018 AND T000
0020 JMP 1000
0021 STG 1002
0022 OUT 0502
0023 CON
0024 TMR 001 #00020
0025 CON
0026 AND T001
0027 JMP 1000
STG / JMP
2.4 Instruction Details
3-114
2
Chapter 2 Instructions
When 1000 is OFF,
steps 1) through 3) are
not executed.
1000
STP
STP
1001
STE
STE
1)
2)
3)
4)
Example
Coding
Description
When 1000 is ON, 0500 turns ON/OFF as soon as 0001 turns ON/OFF.
When 1000 is OFF, 0500 remains OFF after 0001 turns ON. When 0001 and
0500 are ON, 0500 remains ON after 0001 turns OFF.
The program step specified with
STP-STE instructions are ex-
ecuted when the STP operand
relay is ON. When the operand
relay is OFF, the program
execution jumps to STE instruc-
tion. (Fig 1).
STP-STE instructions can be
nested up to 8 levels deep as
shown in Fig. 2. When 1000 is
OFF, steps 1) through 3) are not
executed. Control jumps to the
STE instruction just above step
4), then step 4) is executed.
When 1000 and 1001 are ON,
steps 1) through 3) are executed
in that order. When 1000 is ON
and 1001 is OFF, steps 1), 3),
and 4) are executed in that
order, while step 2) is left unex-
ecuted.
Note 1: STP/STE operand relay Nos. cannot be duplicated in a program.
Note 2: When an STP operand turns OFF during program execution between STP
and STE instructions, the state of the instructions between STP and STE are re-
tained.
Note 3: The scan time is not affected by any instructions between STP and STE
which are not executed.
STP: Step
STE: Step End
Executes instructions between STP and
STE when operand relay is ON.
Used with STP to make a program step.
When 1000 is OFF,
A is not executed.

LDB
4
LDB
4
ANB
5
ORL
3
STE

STP
nnnn FUN
FUN
STP
1000
STE

0001 0500
0000 1000
Line No. Instruction Operand
0000 LD 0000
0001 OUT 1000
0002 STP 1000
0003 LD 0001
0004 OUT 0500
0005 STE
1000
STP
STE
A
B
:
:
Fig. 1
Fig. 2
STP / STE
2.4 Instruction Details
1
2
3-115
Chapter 2 Instructions
Tips
I Operation when STP turns OFF
Using a timer in an STP block
When a timer is used in a program defined with an STP instruction, the operation is
as follows:
a) 1000 is reset immediately when the
timer turns ON. The STE instruction is
started with the timer remaining ON.
b) 1000 is not reset immediately when the
timer turns ON but is reset at the next
scan. The timer is reset before the STE
instruction is started.
I Usage of STG and STP instructions
STG instruction
Use the STG instruction for process progression with branches.
STP instruction
Use the STP instruction for process progression without branches.
T
i
m
e
r

i
s

r
e
s
e
t
.
0000
T000
1000
SET
1000
T000 1000
RES
0500
#00050
T000
STP
1000
STE
a)
Jump
Timer
remains
ON.
Scan
0000
T000
1000
SET
T000
1000
1000
RES
0500
#00050
T000
STP
1000
STE
b)
Jump
Timer
remains
ON.
Scan
STP / STE
0000

ENDS

ENDS
1002

J MP
1001

J MP
1000

STG
1001

STG
1002

STG
0001
0002
0003
0004
0500
0501
0502
1000
SET
0000
0002
1000
SET
0001
0003
0004
1000
RES
1001
SET
0500
1002
SET
1001
RES
STE
STP
1001
STP
1000
0501
STE
2.4 Instruction Details
3-116
2
Chapter 2 Instructions
0000 1000
T000
1001
SET
T000
1001
T000
1001
RES
0500
0501
1002
RES
STE
STE
END
ENDH
STP
1002
STP
1001
1002
SET
1000
DIFU
#00020
T000
1002
T001
T001
#00030
T001
Line No. Instruction Operand
0000 LD 0000
0001 DIFU 1000
0002 CON
0003 AND 1000
0004 SET 1001
0005 STP 1001
0006 LD T000
0007 RES 1001
0008 LDB T000
0009 OUT 0500
0010 LD 1001
0011 TMR 000 #00020
0012 LD T000
0013 SET 1002
0014 STE
0015 STP 1002
0016 LD T001
0017 RES 1002
0018 LDB T001
0019 OUT 0501
0020 LD 1002
0021 TMR 001 #00030
0022 STE
0023 END
0024 ENDH
Operands
* Note that of I/O Nos.7000 to 9915, those that are not assigned to expansion or remote I/O
unit ports can be used for internal utility relays.
Key operation
Application of STP and STE instructions
I Process progression
When input relay 0000 turns ON, output relay 0500 turns ON for 2 seconds, then
output relay 0501 turns ON for 3 seconds automatically.
Coding
The double coils in different STP blocks operate properly.
STP / STE
FUN
FUN
LDB
4
LDB
4
ANB
5
ORL
3
Operand
(nnnn)
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
Visual KV KV-300 KV-10/16 KV-24/40/80
0000 to 17915 0000 to 0009 0000 to 2915 0000 to 6915
T000 to T249 0500 to 6915 T000 to T063 T000 to T119
C000 to C249 *7000 to 9915 C000 to C063 C000 to C119
CTC0 to CTC3 T000 to T249 CTC0 to CTC3 CTC0 to CTC3
C000 to C249
CTC0 to CTC3
2.4 Instruction Details
1
2
3-117
Chapter 2 Instructions
Example
Coding
Operation in the above example
Measures pulse-to-pulse interval or pulse width for input relay 0000.
ITVL instruction has two functions:
Measures pulse-to-pulse interval (cycle) or pulse width. (Minimum unit: 10 ms)
Obtains the average of the contents of data memory.
Each input has the following functions:
PLS
Executes measurement. In data memory measurement, however, PLS input is
disabled in modes 0006 to 1999. Values are fetched only at the scan when PLS
input is ON in modes 10000 to 11999.
The measured value is written into the specified data memory (DM).
In the above example, the measured value of input relay 0000 is
written into DM0004 (DM0000 + 4 addresses).
PAUSE
Pauses the measurement when turned ON.
RES
Initializes the contents of data memory (DM) when turned ON.
In the above example, DM0004 to DM0015 are reset to "#00000".
DM0000 to DM0003 are designated as the area to write the initial setting.
Note: ITVL operand relay Nos. cannot be duplicated in a program.
Operands
* Note that of I/O Nos.7000 to 9915, those that are not assigned to expansion or remote I/O
unit ports can be used for internal utility relays.
Key operation
ITVL: Interval Timer
Measures pulse-to-pulse interval or pulse
width in specified mode.
ITVL
PLS
DMnnnn
PAUSE
mmmm
RES
ITVL
#TM
0000
0001
0002
PLS
DM0000
PAUSE
1000
RES
ITVL
"Reset" input
"Pulse" input
Beginning of workpiece data table
"Measurement Pause" input
First flag relay
ITVL
#TM
First operand
(nnnn)
Second operand
(mmmm)
ENT
R-SRCH
Line No. Instruction Operand
0000 LD 0000
0001 LD 0001
0002 LD 0002
0003 ITVL DM0000 1000
:
ITVL
Visual KV KV-300 KV-10/16 KV-24/40/80
Data table No.: Data table No.: DM0000 to DM0985 DM0000 to DM1985
DM0000 to DM1984 DM0000 to DM9985 1000 to 1912 1000 to 1912
1000 to 1912 Flag relay No.: 3000 to 6912
Flag relay No.: 1000 to 1912
3000 to 9912 3000 to 9912
*7000 to 9915
2.4 Instruction Details
3-118
2
Chapter 2 Instructions
Setting procedure
The ITVL instruction reserves 16 data memories: 1 specified data memory and 15
successive data memories. It also reserves 4 relays: 1 specified relay and 3 succes-
sive relays.
Note: Do not use the 16 data memories and 4 relays specified with the ITVL instruc-
tion for any other purpose.
I Data memory (DM) assignment
Set the initial setting data to the first four data memories.
Data memory
Mode DM XX + 00
01
02
03
04
05
06
07
08
09
10
11 to 12
MAX value
MIN value
Measured value
MAX measured value
MIN measured value
Mean
Preset No.of
measurements
No.of measurements
performed*
Higher digits*
Lower digits*
Work memory
MAX error Relay +0
+1
+2
+3
MIN error
Every
measurements
completion
Measurements
completion for
mean calculation
Used for computing measured values, Max.
measured values, Min. measured values, mean
values, and accumulating totals. (Cannot be used)
Specifies measurement mode (0 to 5).
Presets highest value in measurement
range.
Presets lowest value in measurement
range.
Specifies number of measurements for
mean calculation (1 to 65535).
Stores current measured value.
Stores Max. measured value.
Stores Min. measured value.
Stores mean value.
Stores number of times measurements
actually performed.
Stores higher 16 bits of accumulating
total of measurements. (#00000 to
#65535) ($0000 to $FFFF)
Initial
setting
is to be
specified
by user.
Stores lower 16 bits of accumulating
total of measurements. (#00000 to
#65535)($0000 to $FFFF)
Turns ON and remains ON for one scan time when
measured value exceeds Max preset value.
Turns ON and remains On for one scan time when
measured value goes below Min preset value.
Turns ON at completion of every measurement and
remains ON for one scan time.
Turns ON for one scan time at completion of the
specified No. of measurements for mean value
calculation, then remains ON for one scan time.
I Relay assignment
Relay
Note 1: When 0 (zero) is specified as the number of measurements, mean value
calculation will not be performed. In this case, the number of measurements will be
accumulated until RES input turns ON, which may cause overflow.
Note 2: Data in the No. of measurements, Higher digits, and Lower digits are reset
when the No. of measurements performed reaches the preset No. of measurements.
Note 3: Once ITVL instruction is defined in MC-MCR block, the measurement
process pauses when the block is not executed.
Note 4: For programs containing subroutines, interrupts, steps, or stages, ITVL
instructions must be defined so that they are executed unconditionally for every scan
time.
ITVL
2.4 Instruction Details
1
2
3-119
Chapter 2 Instructions
I Mode setting
Write the desired mode No. into the first data memory.
Mode for pulse measurement
Mode for DM measurement
Write the desired mode No. into the specified data memory.
Example
Write "#0006" to obtain the average of the contents of DM0006.
Note 1: When the mode No. is set to 10000 through 11999, values are fetched at
the scan only when the PLS input relay is ON.
Note 2: When the average of a data memory is calculated, values "32768" to
"65535" are converted into corresponding compliment numbers (-32767 to -1) .
Note 3: Some data memories after DM1000 are assigned to special functions. Be
careful when specifying data memory for the ITVL instruction.
Refer to "1.3.10 Data Memories" (p. 3-19) for data memory assignments.
Mode
Pulse-to-pulse
interval
Unit
Mode
Pulse width Unit
10 m sec
100 m sec
1 sec
10 m sec
100 m sec
1 sec
Mode No. DM No. Description
10000 DM0000
Measure the contents of DM0000 and obtain the
average.
10001 DM0001
Measure the contents of DM0001 and obtain the
average.


10005 DM0005 Measure the contents of DM0005 and obtain the
average.
0006
10006 DM0006
Measure the contents of DM0006 and obtain the
average.
0007 10007 DM0007 Measure the contents of DM0007 and obtain the
average.


1999 11999 DM1999 Measure the contents of DM1999 and obtain the
average.
2000 to 9999 12000 or more Not provided Cannot be used.
Pulse-to-pulse interval measurement Pulse width measurement
0 1
2 3
4 5
ITVL
2.4 Instruction Details
3-120
2
Chapter 2 Instructions
ON
0500
1000
0000
500ms 400ms 600ms
1001
ON
OFF
ON
ON ON
1 scan
3 sec. 3 sec.
1 scan
Application of ITVL instruction
This section describes examples of pulse interval measurement.
I Pulse interval measurement
Turns ON output relay 0500 for 3 seconds when the pulse interval is not within the
range of 490 to 510 ms.
Coding
Timing diagram
2008
2008
2008
2008
0000
0001
0002
T000 1000
1001
0500
#00000
LDA
DM0000
STA
#00051
LDA
DM0001
STA
#00049
LDA
DM0002
STA
#00010
LDA
DM0003
STA
PLS
DM0000
PAUSE
1000
RES
ITVL
0500
#00030
T000
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0013 LDA #00010
0001 LDA #00000 0014 CON
0002 CON 0015 STA DM0003
0003 STA DM0000 0016 LD 0000
0004 LD 2008 0017 LD 0001
0005 LDA #00051 0018 LD 0002
0006 CON 0019 ITVL DM0000 1000
0007 STA DM0001 0020 LD 1000
0008 LD 2008 0021 OR 1001
0009 LDA #00049 0022 OR 0500
0010 CON 0023 ANB T000
0011 STA DM0002 0024 OUT 0500
0012 LD 2008 0025 TMR 000 #00030
1001 turns ON for one scan when measured value
is below min. setting value (490 ms).
Sets mode 0 (Unit:10 ms).
Sets max. setting value of measurement range to 510 ms.
Sets min. setting value of measurement range to 490 ms.
Sets number of averaging measurements to 10.
Measures pulse interval when input relay 0000 turns ON.
Pauses measurement while input relay 0001 turns ON.
Resets measurement when input relay 0002 turns ON.
1000 turns ON for one scan when measured
value exceeds max. setting value (510 ms).
ITVL
2.4 Instruction Details
1
2
3-121
Chapter 2 Instructions
ITVL
I A/D data measurement
Turns ON output relay 0500 when the analog input from the KL-4AD to DM1600
(range: 1 to 5 V) exceeds +3 V. Turns ON output relay 0501 when the input is below
+2 V. Writes the average into DM0100.
Refer to the "KL-4AD/KL-2AD Users Manual" for data memory settings for the KL-
4AD.
Coding
2008
2008
2008
2008
2003
0001
0002
1000
#01600
LDA
DM0000
STA
#02000
LDA
DM0001
STA
#01000
LDA
DM0002
STA
#00100
LDA
DM0003
STA
PLS
DM0000
PAUSE
1000
RES
ITVL
1001
1003 DM0100
STA
DM0007
LDA
0500
0501
Writes average into DM0100 every 100 measurement.
Measures contents of DM1600.
Sets max. setting value to +3 V (2000).
Sets min. setting value to +2 V (1000).
Sets number of averaging measurements to 100.
Pauses measurement when input relay 0001 turns ON.
Resets measurement when input relay 0002 turns ON.
0500 turns ON when measured value exceeds max. setting value.
0501 turns ON when measured value is below min. value.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0014 CON
0001 LDA #01600 0015 STA DM0003
0002 CON 0016 LD 2003
0003 STA DM0000 0017 LD 0001
0004 LD 2008 0018 LD 0002
0005 LDA #02000 0019 ITVL DM0000 1000
0006 CON 0020 LD 1000
0007 STA DM0001 0021 OUT 0500
0008 LD 2008 0022 LD 1001
0009 LDA #01000 0023 OUT 0501
0010 CON 0024 LD 1003
0011 STA DM0002 0025 LDA DM0007
0012 LD 2008 0026 STA DM0100
0013 LDA #00100
2.4 Instruction Details
3-122
2
Chapter 2 Instructions
Example
Coding
Description
When input relay 0000 turns ON, the subroutine specified by SBN00 and RET is
executed. When the subroutine ends, instructions following CALL are executed.
When the input relay is ON, the CALL instruction executes the subroutine speci-
fied by the operand.
A subroutine program must be defined between the SBN and RET instructions.
A subroutine must be defined between END and ENDH instructions.
Once a CALL instruction has been encountered, program execution transfers to
the subroutine specified by the SBN and RET instructions. Once a RET instruc-
tion has been encountered, program execution returns to the instruction immedi-
ately following the CALL instruction.
Operand
Key operations
CALL: Subroutine Call
SBN: Subroutine Entry
RET: Subroutine Return
Executes subroutine specified by operand.
Represents beginning of subroutine speci-
fied by operand.
Represents end of subroutine.
RES
0
RES
0
AND
8
ORL
3
ORL
3
ORL
3
FUN
FUN
FUN
RET
SBN
nn
CALL
nn
Line No. Instruction Operand
0000 : :
: : :
: LD 0000
: CALL 00
: : :
: END :
: SBN 00
: : :
: RET :
: ENDH :
0000 00
CALL
END
SBN
00
RET
ENDH
RES
0
AND
8
ORL
3
ORL
3
ORL
3
ORL
3
FUN
FUN
FUN
Operand
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
:
:
:
CALL / SBN / RET
CALL 00 to 99
SBN 00 to 99
RET
2.4 Instruction Details
1
2
3-123
Chapter 2 Instructions
Application of subroutine
When CALL00 is encountered during normal scan execution, the subroutine is
executed. At the completion of this subroutine, program execution returns to pro-
gram at B) immediately following CALL00. Then, the normal scan is continued until
an END instruction is encountered.
With no CALL instruction With CALL instruction
I Nesting structure of a subroutine
Subroutine instructions can be nested up to 4 levels deep.
A subroutine which is called from another subroutine should be defined before
the call.
00

CALL
0000
A)
B)
00

CALL
SBN
00
2008
ENDH
RET
END
B)
A)
Subroutine program
Normal scan
Subroutine
Program
Program
Program
Program
00

CALL
0000
B)
A) Program
Program
Subroutine program
00

CALL
SBN
01
0001
01

CALL
0000
SBN
00
ENDH
RET
RET
END
Call
Program
Subroutine program
CALL / SBN / RET
2.4 Instruction Details
3-124
2
Chapter 2 Instructions
I Calling a subroutine from an interrupt program
Subroutines can be called from interrupt programs.
A subroutine which is called from an interrupt program should be defined before
the call.
Note 1: Subroutine Nos. for SBN instructions cannot be duplicated in a program.
(It can be duplicated for CALL instructions.)
Note 2: When a subroutine is executed, the scan time is extended by the time
needed for subroutine execution.
Note 3: The following instructions cannot be used in subroutines:
STG, JMP, ENDS, INT, RETI, and MEMSW
Note 4: The following instructions can be used only in subroutines which are ex-
ecuted every scan time:
TMR, TMH, TMS, C, SFT, UDC, DIFU, DIFD, W-UE, W-DE, HKEY, ITVL,
and Differentiation type instruction (@xxx)
SBN
00
0001
00

CALL
0002
INT
0000
ENDH
RET
RETI
END
0500
Call
Program
Subroutine program
CALL / SBN / RET
2.4 Instruction Details
1
2
3-125
Chapter 2 Instructions
Example
Coding
Description
Use FOR-NEXT instructions in a subroutine program (between SBN and RET) to
initialize data memory (DM0100 through DM0149) when the operation is started.
The indirect addressing method is used to change the data memory, so the initializa-
tion is completed when the TM02 value becomes "50 + 1" between the FOR and
NEXT instructions.
"Indirect addressing" (p. 3-127)
The FOR instruction takes either of the following two types of operands: the
number of repetitions or the location (DM No.) of the data memory containing the
number of repetitions.
Define the program to be repeated between the FOR and NEXT instructions.
The FOR instruction repeats the desired sequence by the specified number of
times during each scan time.
FOR: Repeat Start
NEXT: Repeat End
Executes program between FOR and NEXT
by number of times specified by operand.
Represents end of repetition.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0107 FOR #00050
0001 CALL 00 0108 LD 2002
: : 0109 STA #TM02
0099 END 0110 CON
0100 SBN 00 0111 INC TM02
0101 LD 2002 0112 NEXT
0102 LDA #00100 0113 RET
0103 CON :
0104 STA TM02 :
0105 CON :
0106 LDA #00000 0199 ENDH
FUN
FUN
SET
1
ANL
2
OR
9
ORB
6
NEXT
FOR
nnnn
Specify the first DM No.
Specify the number of DMs to be
initialized.
2008
#00100
LDA
2002
2002
00
CALL
END
SBN
00
#00050
FOR
NEXT
RET
ENDH
TM02
STA
#00000
LDA
#TM02
STA
TM02
INC
(DM100)
:
:
FOR / NEXT
2.4 Instruction Details
3-126
2
Chapter 2 Instructions
Tips
Note 1: The FOR-NEXT instruction pair repeats the program for a specified time
period at each scan. It usually is used in steps or subroutines.
Note 2: When a large number of loops or long programs are defined between FOR
and NEXT instructions, the processing time for one scan may become too long,
resulting in "Cycle time error". In such a case, reduce the number of loops or shorten
the ladder program.
The FOR-NEXT instruction set can be nested up to 8 levels deep. Nine or more
nested levels will result in a FOR-NEXT error.
After repeating FOR-NEXT 3) five times, program execution transfers to the
instructions following the NEXT instruction.
FOR-NEXT 2) is repeated twice while FOR-NEXT 3) is executed once.
Thus, FOR-NEXT 2) is executed 10 times.
FOR-NEXT 1) is repeated 5 times while FOR-NEXT 2) is executed once.
Thus, FOR-NEXT 1) is executed up to 50 (5 x 2 x 5) times.
Operands
Key operation
NEXT
NEXT
NEXT
FOR
#05
FOR
#02
FOR
#05
1) 2) 3)
FOR / NEXT
FUN
FUN
SET
1
ANL
2
OR
9
ORB
6
Operand
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
Visual KV KV-300 KV-10/16 KV-24/40/80
#0000 to #65535 DM0000 to DM1984 #00000 to #65535 #00001 to #65535
DM0000 to DM1999 DM0000 to DM9999 DM0000 to DM0999 DM0000 to DM1999
TM02 to TM28 TM00 to TM29 TM00 to TM29 TM00 to TM29
2.4 Instruction Details
1
2
3-127
Chapter 2 Instructions
Indirect addressing
I Indirect addressing
Indirect addressing is used to so you don't have to use fixed data memories or relay
Nos. when the contents of data memory or a relay is stored in internal registers, or
when the contents of the internal memory is stored in data memory or a relay.
I Method for indirect addressing
Specify the operand for instructions as "#TMxx". The contents of "TMxx" is
considered to be the specification No. (indirect addressing).
Example
When TM02 value is "0000", "#TM02" represents DM0000.
When TM02 value is "10000", "#TM02" represents 0000 (relay).
Any of "02" through "29" can be specified for "xx".
Specify the desired decimal number for "xx".
Numbers "0000" through "1999" specify DM0000 through DM1999 (data
memory).
Numbers "10000" through "27915" specify 0000 through 17915 (relay).
Example: LDA #TM15
This is the same operation whether "LDA DM0020" or "LDA 1000" is specified. The
specified data memory or relay can be changed as desired by changing the value of
TM15.
Example: STA #TM02
This is the same operation whether "STA DM0000" or "STA 3000" is specified. The
specified data memory or relay can be changed as desired by changing the value of
TM02.
I Range of DM and relay Nos. that can be specified by "TMxx"
I Instructions which can use indirect addressing:
Specify "#TMxx" as an operand relay.
LDA, @LDA, STA, @STA, CMP, @CMP, ADD, @ADD, SUB, @SUB, MUL, @MUL,
DIV, @DIV, ANDA, @ANDA, ORA, @ORA, EORA, @EORA
Note 1: "2000" to "9999" cannot be used as a TMxx value.
Note 2: If there is no data memory or relay corresponding to the number specified
with "#TMxx", special utility relay 2012 turns ON.
TM15 value Data entered into internal register
20 DM0020
11000 1000 to 1015
TM02 value Specified destination
00 DM0000
13000 3000 to 3015
TMxx value DM/relay
0000 to 1999 DM0000 to DM1999
2000 to 9999 Cannot be used.
10000 to 27915 0000 to 17915
FOR / NEXT
2.4 Instruction Details
3-128
2
Chapter 2 Instructions
I Data memory block transfer
Comparison between a program with normal addressing and one with indirect
addressing.
Program with normal addressing Program with indirect addressing
0000
1000
1000
1000
1000
DM0000
LDA
DM0100
STA
DM0001
LDA
DM0101
STA
DM0002
LDA
DM0102
STA
DM0003
LDA
DM0103
STA
1000 DM0098
LDA
DM0198
STA
1000 DM0099
LDA
DM0199
STA
1000

DIFU
END
ENDH
0000
1000
2002 #00000
LDA
TM02
STA
#00100
LDA
TM03
STA
2002 #TM02
LDA
#TM03
STA
TM02
INC
TM03
INC
SBN
0 0
FOR
#0100
NEXT
RET
ENDH
END
1000
DIFU
00
CALL
1)
2)
3)
4)
The contents of DM0000 are transferred
to DM0100.
The contents of DM0001 are transferred
to DM0101.
The contents of DM0002 are transferred
to DM0102.

The contents of DM0099 are transferred


to DM0199.
DM0000
DM0099
DM0100
DM0199

The block of 100 data is


transferred.
The contents of DM0000 are
transferred to DM0100.
The contents of DM0099 are
transferred to DM0199.
Transfer a
block of
data.
Program steps
are reduced by
one-eighth.
No. of data
memory to be
transferred.
The first No. of the source DM block is specified
(DM0000).
The first No. of the destination DM block is specified
(DM0100).
The contents of the DM indirectly addressed by
"#TM02" is transferred to the internal register.
The contents of the internal register are transferred
to the DM indirectly addressed by "#TM03".
Add "1" to both "TM02" and "TM03" to increment
the Nos. of the source and destination DMs by one.

L
FOR / NEXT
2.4 Instruction Details
1
2
3-129
Chapter 2 Instructions
Description
On line 1), "TM02" is assigned to the first No. of the source 0000 and "TM03" is
assigned to the first No. of the destination 0100. This is the initial setting.
On lines 2) to 4), the contents of DM0000 to DM0099 are transferred to DM0100
to DM0199.
The ladder program on line 3) is executed 100 times in one scan.
1st operation: TM02 value: 0000, TM03 value: 0100
2nd operation: TM02 value: 00001, TM03 value: 0101
100th operation: TM02 value: 0099, TM03 value: 0199
When the ladder program on line 3) is repeated 100 times, the contents of the
specified DM block are transferred.
This operation is repeated.
2002 #TM02
LDA
#TM03
STA
TM02
INC
TM03
INC
2002 #TM02
LDA
#TM03
STA
TM02
INC
TM03
INC
2002 #TM02
LDA
#TM03
STA
TM02
INC
TM03
INC

Add "1" to the


current value of
"TM03".
DM0000 is
indirectly
addressed.
DM0100 is
indirectly
addressed.
Add "1" to the
current value of
"TM02".
Add "1" to the
current value of
"TM03".
DM0001 is
indirectly
addressed.
DM0101 is
indirectly
addressed.
Add "1" to the
current value of
"TM02".
Add "1" to the
current value
of "TM03".
DM0099 is
indirectly
addressed.
DM0199 is
indirectly
addressed.
Add "1" to the
current value
of "TM02".
FOR / NEXT
2.4 Instruction Details
3-130
2
Chapter 2 Instructions
Application of SBN-RET and FOR-NEXT instructions
I Data memory shift
Shifts the contents of the current data memory (DM) to the next DM at the rising
edge of the synchronous (timing) signal. As the number of DMs to be shifted in-
creases, the required scan time becomes longer.
Coding
0000 1000
2002
#00010
LDA
TM03
LDA
TM04
STA
TM02
SUB
TM05
STA
#00001
ADD
2002 TM03
DEC
#TM03
LDA
#TM04
STA
TM04
DEC
TM02
STA
#00030 TM03
LDA STA
00
CALL
1000
DIFU
END
NEXT
SBN
00
FOR
2002 #00000
LDA
#TM02
STA
RET
TM05
ENDH
Synchronous
signal
Shift start DM
No. (DM0010)
is designated.
Shift end DM
No. (DM0030)
is designated.
Shift level
Indirect addressing is used
to designate DM Nos.
Program lines which execute
data shift are grouped as a
subroutine.
Data is shifted from DM0010 to
DM0030.
Shift start DM No. is cleared to
"#00000" after data is shifted.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0000 0020 STA TM04
0001 DIFU 1000 0021 CON
0002 CON 0022 SUB TM02
0003 AND 1000 0023 CON
0004 LDA #00010 0024 STA TM05
0005 CON 0025 FOR TM05
0006 STA TM02 0026 LD 2002
0007 CON 0027 DEC TM03
0008 LDA #00030 0028 CON
0009 CON 0029 DEC TM04
0010 STA TM03 0030 CON
0011 CON 0031 LDA #TM03
0012 CALL 00 0032 CON
0013 END 0033 STA #TM04
0014 SBN 00 0034 NEXT
0015 LD 2002 0035 LD 2002
0016 LDA TM03 0036 LDA #00000
0017 CON 0037 CON
0018 ADD #00001 0038 STA #TM02
0019 CON 0039 RET
0040 ENDH
FOR / NEXT
2.4 Instruction Details
1
2
3-131
Chapter 2 Instructions
HKEY: 16-Key Input
Reads hexadecimal key data on time-
sharing basis and outputs these data to
special utility relays 2900 to 2915.
FUN
SET
1
LD
7
HKEY
nnnn
mmmm
0005
HKEY
0000
0500
Input relay
Output relay
Line No. Instruction Operand
0000 LD 0005
0001 HKEY 0000 0500
COM
24
VDC
+
-
000 001
KV
002 003
0
COM 500 501 502 503
4
8
C
1
5
9
D
2
6
A
E
3
7
B
F
Pressing two or more keys
simultaneously is OK.
(With diode)
Pressing two or more keys
simultaneously is invalid.
:
ON: Key input read operation has
completed.
Relay No. 2900 2901 2902 2903 2904 2905 2906 2907 2908 2909 2910 2911 2912 2913 2914 2915
Hex key 0 1 2 3 4 5 6 7 8 9 A B C D E F
ON: Pressing two or more keys
simultaneously is not valid.
R: Reading W: Writing
Example
Coding
Description
When input relay 0005 turns ON, the operand hexadecimal key data is read.
HKEY instruction employs four inputs and four outputs arranged as shown below.
Refer to "Fetching 16-key input" (p. 3-133) for the programming example.
The HKEY instruction employs four input relays and four output relays from the
specified number.
Inputs are processed on a time-sharing basis, so that input processing requires 8
scan time cycles (approx. 160 msec when the scan time is 20 msec or less).
When a hexadecimal key is pressed, the HKEY instruction turns ON the corre-
sponding special utility relay (2900 to 2915).
The special utility relay status indicates whether two or more keys can be
pressed simultaneously or whether a key input read operation has completed, as
shown in the following table:
Note 1: An HKEY instruction can be defined only once in a program.
Note 2: The HKEY instruction turns output relays ON/OFF every scan time. Connect
the device with transistor output.
Note 3: If the scan time is shorter than 8 ms, set the input time constant smaller
than the scan time.
Relay No. 2814 R/W 2815 R
Status
HKEY
2.4 Instruction Details
3-132
2
Chapter 2 Instructions
2002 0001 C000
2815
0005
#09999
C000
0000
HKEY
0104
0512
ENDH
END
2900
LDA TBIN
C000
STA
0600
HKEY
FUN
SET
1
LD
7
Output relay Input relay
ENT
R-SRCH
ENT
R-SRCH
Note 4: When two or more keys are pressed simultaneously even once during the
scan while relay 2814 is ON, relays 2900 through 2915 keep the current status as
soon as relay 2815 turns ON.
Note 5: The HKEY instruction does not properly operate if the scan time is longer
than 200 ms.
Note 6: When the expansion I/O module is used as an operand, the fetch may fail
unless the scan time is fixed to 2 ms or longer.
Operands
Key operation
Application of HKEY instruction
I Changing the preset value of internal counters using a BCD digital switch
Coding
As soon as 0005 turns ON, the preset value is replaced with the new preset
value specified by the digital switches.
"TBIN instruction" (p. 3-180), "LDA, STA instructions" (p. 3-140)
The digital switches are connected to the KV PLC as shown in the following
diagram: (Be sure to add the diodes at the specified points.)
The preset values range from #0000 to #9999.
The preset value is updated as soon as special utility relay 2815 turns ON.
Line No. Instruction Operand
0000 LD 2002
0001 ANB 0001
0002 C 000 #09999 0000
0003 CON
0004 AND C000
0005 OUT 0600
0006 LD 0005
0007 HKEY 0104 0512
0008 LD 2815
0009 LDA 2900
0010 CON
0011 TBIN
0012 CON
0013 STA C000
0014 END
0015 ENDH
Visual KV KV-300 KV-10/16/24/40/80
Input relay Output relay Input relay Output relay Input relay Output relay
0000 to 0500 to 00000 to 00500 to 0000 to 0500 to
0415 0915 00009 00503 0415 0915
10000 to 10500 to
10415 10915
: :
17000 to 17500 to
17415 17915
2.4 Instruction Details
1
2
3-133
Chapter 2 Instructions
COM
24
VDC
+
-
0104 0105
KV
0106 0107
1
10
0
10
1
10
2
10
3
2 4 8
COM 0512 0513 0514 0515
BCD Digital switch
Diode
2815
2002
2008
2010 2010 2900
LDA
$03FF
ANDA
TM05
CMP
TM05
CMP
TM05
STA
TM06
STA DMX
2815
2815 2915
2010 2010
DM0000
STA
#00000
DM0000
DW
TM06
STA
#04
SLA
DM0000
LDA
2900
LDA
$03FF
ANDA
TM05
STA
END
ENDH
2814
SET
HKEY
0500
0000
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0020 CON
0001 SET 2814 0021 AND 2010
0002 LD 2002 0022 ANDA $03FF
0003 HKEY 0000 0500 0023 CON
0004 LD 2815 0024 CMP TM05
0005 LDA 2900 0025 CON
0006 CON 0026 ANB 2010
0007 ANB 2010 0027 STA TM05
0008 ANDA $03FF 0028 CON
0009 CON 0029 LDA DM0000
0010 CMP TM05 0030 CON
0011 CON 0031 SLA #04
0012 ANB 2010 0032 CON
0013 STA TM05 0033 ORA TM06
0014 CON 0034 CON
0015 DMX 0035 STA DM0000
0016 CON 0036 LD 2815
0017 STA TM06 0037 AND 2915
0018 LD 2815 0038 DW #0000 DM0000
0019 LDA 2900 0039 END
0040 ENDH
HKEY
I Fetching 16-key input
Writes the following 16-key input value into DM0000 as 4-digit BCD.
Pressing the [F] key clears the input value.
Coding
2.4 Instruction Details
3-134
2
Chapter 2 Instructions
2.4.3 Arithmetic Instructions
Arithmetic instructions handle data as integers to perform arithmetic, comparative, or
logical operations.
Instruction Mnemonic Reference page
DW: Data Memory Write DW 3-136
Trimmer In TMIN (FUN50), @TMIN @(FUN50) 3-138
LDA/@LDA: Load A LDA (FUN23), @LDA@ (FUN23) 3-140
STA/@STA: Store A STA (FUN42), @STA@ (FUN42) 3-140
CMP/@CMP: Compare CMP (FUN04), @CMP @(FUN04) 3-146
ADD/@ADD: Add ADD (FUN00), @ADD @(FUN00) 3-150
SUB/@SUB: Subtract SUB (FUN46), @SUB @(FUN46) 3-150
MUL/@MUL: Multiply MUL (FUN28),@ MUL @(FUN28) 3-150
DIV/@DIV: Divide DIV (FUN11), @DIV @(FUN11) 3-150
ANDA/@ANDA: And A ANDA (FUN01), @ANDA @(FUN01) 3-159
ORA/@ORA: Or A ORA (FUN31), @ORA @(FUN31) 3-161
EORA/@EORA: Exclusive Or A EORA (FUN15), @EORA@ (FUN15) 3-164
SRA/@SRA: Shift Right A SRA (FUN41), @SRA @(FUN41) 3-166
SLA/@SLA: Shift left A SLA (FUN40), @SLA @(FUN40) 3-166
RRA/@RRA: Rotate Right A RRA (FUN37), @RRA@ (FUN37) 3-169
RLA/@RLA: Rotate Left A RLA (FUN35), @RLA @(FUN35) 3-169
COM/@COM: Complement COM (FUN05), @COM @(FUN05) 3-171
INC/@INC: Increment Memory INC (FUN19), @INC @(FUN19) 3-172
DEC/@DEC: Decrement Memory DEC (FUN07), @DEC@ (FUN07) 3-172
MPX/@MPX: Multiplexer MPX (FUN27), @MPX@(FUN27) 3-176
DMX/@DMX: Demultiplexer DMX (FUN12), @DMX @(FUN12) 3-176
TBCD/@TBCD: Transfer BCD TBCD (FUN47), @TBCD @(FUN47) 3-180
TBIN/@TBIN: Transfer BIN TBIN (FUN48), @TBIN @(FUN48) 3-180
ASC/@ASC: ASCII Convert ASC (FUN02), @ASC @(FUN02) 3-183
RASC/@RASC: Reverse ASCII Convert RASC (FUN32), @RASC @(FUN32) 3-183
ROOT/@ROOT: Square Root ROOT (FUN36), @ROOT @(FUN36) 3-185
2.4 Instruction Details
1
2
3-135
Chapter 2 Instructions
Internal register
KV executes all arithmetic instructions (i.e. data exchange) by using an internal
register, in order to increase the processing speed.
This section begins by describing details of the internal register.
I Internal register
An internal register stores 16-digit binary data. That is, the resister uses 16 bits for
storing ON-OFF status data (1-0 status data). The internal register is required when
the KV performs arithmetic operation. Because this is not an instruction nor operand,
it is not necessary to take into consideration how the internal register functions or
operates.
I Arithmetic instructions executed using internal register
1. ON-OFF status of the specified relay and 15 successive relays is stored into the
resister.
2. Current T/C value (decimal value = #*****) is automatically converted into a
binary value and input to the internal register.
3. Constant (decimal value = #*****, hexadecimal value = $****) is automatically
converted into a binary value and input to the internal register.
4. The range of numbers that can be specified is as follows:
Decimal #00000 to #65535
Hexadecimal $0000 to $FFFF
The constants can be entered by using
@
#, $
and the corresponding alphanumeric
keys.
(Pressing
@
#, $ once allows you to enter decimal values, and pressing twice to enter
hexadecimal values.)
5. The contents of the internal register (binary) is automatically converted into a
decimal value and (#*****) input to a timer/counter as the preset value.
Note 1: The internal structure of the internal register is the same as that of the data
memories. Although the data memories can store data when the power is being
OFF, the internal register cannot do so.
Note 2: Even for running one program, the contents of the internal register is rewrit-
ten each time when an instruction is executed.
Note 3: The internal register cannot be monitored.
CMP MPX
ADD DMX
SUB TBCD
MUL TBIN
DIV ASC
ANDA RASC
ORA
EORA
SRA
SLA
RRA
RLA
COM
INC
DEC
TMIN
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
(Arithmetic instructions executed as binary code.)
Relay No.
1.
Current T/C
value.
2.
Constant
3. 4.
(decimal,
hexadecimal)
Data memory,
temporary
memory
Data memory accessed
in indirect addressing via
temporary memory
LDA instruction
Internal register
STA direction
Relay No
Preset T/C
value.
5.
Data memory,
temporary
memory
D
a
t
a

m
e
m
o
r
i
e
s
,
t
e
m
p
o
r
a
r
y

m
e
m
o
r
i
e
s
Data memory accessed
in indirect addressing via
temporary memory
Con-
stant
2.4 Instruction Details
3-136
2
Chapter 2 Instructions
Example
Coding
When starting operation, $0018 is written into DM0000 and #00050 into DM0001.
Description
Values are directly written into data memories, without using the internal register.
Note: The contents of the internal register and the arithmetic flag do not change
even after the DW instruction is executed.
Tips
The DW instruction can be used to reset the contents of data memories.
Operands
Key operation
Arithmetic flag
2009, 2010, 2011 No change
2012 No change
DW: Data Memory Write Directly writes constant into data memory.
DW
nnnn
DMmmmm
DW
2008 #00050
DM0001
DW
$0018
DM0000
DW
Line No. Instruction Operand
0000 LD 2008
0001 DW $0018 DM0000
0002 CON
0003 DW #00050 DM0001
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
2008 #00000
DM0001
DW
#00000
DM0000
DW
DW
reraly
First operand Second operand
ENT
R-SRCH
:
First operand
Second operand
Operand
Data memory
DW
Visual KV KV-300 KV-10/16 KV-24/40/80
nnnn: nnnn nnnn nnnn
#00000 to #65535 #00000 to #65535 #00000 to #65535 #00000 to #65535
$0000 to $FFFF $0000 to $FFFF $0000 to $FFFF $0000 to $FFFF
DM mmmm: DMmmmm DMmmmm DMmmmm
DM0000 to DM1999 DM0000 to DM9999 DM0000 to DM0999 DM0000 to DM1999
2.4 Instruction Details
1
2
3-137
Chapter 2 Instructions
Example
Description
Arithmetic instructions have two instruction types: differentiation type and every-
scan type.
The differentiation type instruction is executed only at the rising edge of input
relay 0000.
The every-scan type instruction is executed every scan time while input relay
0000 is ON.
Timing diagram
Instructions with the DIFFERENTIATION function are as follows:
LDA, SAT, CMP, ADD, SUB, MUL, DIV, ANDA, ORA, EORA, SRA, SLA, RRA,
RLA, COM, INC, DEC, MPX, DMX, TBCD, TBIN, ASC, RASC, ROOT
Note:
In the top program, an INC instruction is
executed every scan time, incrementing
the contents of DM0000 by one, while
input relay 0000 is ON.
In the middle program, an INC instruc-
tion is executed and the contents of
DM0000 is incremented only when input
relay 0000 is turned from OFF to ON.
The bottom program uses the
every-scan type instruction which
performs the same operation as the
differentiation type instruction.
Operands
Key operation
@xxxx: Differentiation
Executes instruction only at rising edge of
input to input relay.
@
#,$
FUN
xxxx
0000 0000 DM0000
INC
DM0000
INC
Every-scan type instruction Differentiation type instruction
ON
OFF 0000
INC
ON
OFF 0000
INC
Executed only once at the rising
edge of input relay 0000.
Differentiation type instruction
Executed Stopped Stopped Stopped
Every-scan type instruction
Stopped
0000 DM0000
INC
0000 DM0000
INC
0000 1000 DM0000
INC
1000
DIFU
@
#,$
FUN
Function No.
ENT
R-SRCH
:
@xxxx
2.4 Instruction Details
3-138
2
Chapter 2 Instructions
T000 preset value can be changed with trimmer as follows (#00000 to #65535):
Coding
Description
The TMIN instruction transfers the value of the KV series digital trimmer (0 to
65535) to the internal register. Additionally, if this value is transferred to a timer,
counter, relay, or data memory (by using the STA instruction), the numeric data of
the destination can be changed without modifying the program.
Note: To check the setting value of the digital trimmer with the KV-P3E(01)
handheld programmer, select the "READ TRIMMER SETTING" function (FUN73).
(Only values 0 to 9999 can be displayed.)
The @TMIN instruction is executed only once at the rising edge of the input relay.
Refer to "Chapter 3: Access Window" on page 1-79 for the functions and operation
procedures for the digital trimmer of the Access Window.
Operands
Key operation
Arithmetic flag
2009 No change
2010 Turns ON when "0" is entered by the TMIN instruction. Turns
OFF at other times.
2011, 2012 No change
TMIN: Trimmer In
@TMIN: Trimmer Setting
Inputs numerical value specified by digital
trimmer of access window (0 to 65535) to
internal register.
@
#,$
FUN
FUN
RES
0
ANB
5
RES
0
ANB
5
n
TMIN
n
TMIN
Inputs trimmer rotation angle of 0 to internal register.
Transfers contents of internal register to timer T000
for use as preset value.
Turns ON output 0500 when current value of
T000 reaches "#00000".
Timer T000 operates as ON-delay timer when 0000 is ON.
0 2002
TMIN
T000
STA
#00010 0000 T000 0500
T000
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0005 TMR 000 #65535
0001 TMIN 0 0006 CON
0002 CON 0007 AND T000
0003 STA T000 0008 OUT 0500
0004 LD 0000
STA TMIN
Digital trimmer
value of access
window [0 to 65535]
Internal
register
Destination
Transfer
Numeric data
0 to 65535
Input
Timer/counter preset
value
Relay ch No.
Data memory
Temporary memory
@
#,$
FUN
FUN
RES
0
ANB
5
ENT
R-SRCH
ENT
R-SRCH
Operand
:
:
TMIN / @TMIN
Visual KV KV-300/24/40/80 KV-10/16
0, 1 0, 1 0
2.4 Instruction Details
1
2
3-139
Chapter 2 Instructions
Applications of TMIN (Analog timer) instruction
I Changing the timer setting value
Uses the digital trimmer (TMIN0) to change the setting value of a timer (0 to 6553.5
sec.).
Coding
I Changing setting values for multiple timers
Uses the digital trimmer (TMIN0) to change setting values for multiple timers (0 to
6553.5 sec.).
Coding
In the above example, T000, T001, and T002 have the same setting value.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0005 OR 0500
0001 TMIN 0 0006 TMR 000 #00010
0002 CON 0007 ANB T000
0003 STA T000 0008 OUT 0500
0004 LD 0000
0
TMIN
T000
STA
2002
0000
0500 0500 T000
#00010
T000
0
TMIN
T000
STA
T001
STA
T002
STA
#00010
T000
2002
0000
0500 T000
#00010
T001
0001
0501 T001
0500
0501
#00010
T002
0002
0502 T002 0502
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0012 OUT 0500
0001 TMIN 0 0013 LD 0001
0002 CON 0014 OR 0501
0003 STA T000 0015 TMR 001 #00010
0004 CON 0016 ANB T001
0005 STA T001 0017 OUT 0501
0006 CON 0018 LD 0002
0007 STA T002 0019 OR 0502
0008 LD 0000 0020 TMR 002 #00010
0009 OR 0500 0021 ANB T002
0010 TMR 000 #00010 0022 OUT 0502
0011 ANB T000
TMIN / @TMIN
2.4 Instruction Details
3-140
2
Chapter 2 Instructions
The LDA instruction inputs each data item to the internal register.
The STA instruction transfers the contents of the internal register to the specified
destination.
"Internal Register" (p. 3-126)
Operands
Key operation
LDA: Load A
@LDA: Load A
STA: Store A
@STA: Store A
Inputs value specified by operand to internal
register.
Transfers contents of internal register to
destination specified by operand.
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LDB
4
ANL
2
ORL
3
ORL
3
LDB
4
ANL
2
ORL
3
ORL
3
nnnn
STA
nnnn
STA
nnnn
LDA
nnnn
LDA
@
#,$
FUN
FUN
@
#,$
FUN
FUN
ORL
3
LDB
4
ANL
2
ANL
2
ENT
R-SRCH
ENT
R-SRCH
Operand
ENT
R-SRCH
ENT
R-SRCH
Operand
(#XXXXX)
($XXXXX)
T XXX
C XXX
DM XXXX
TM XX
XXXX
1
2
3
T XXX
C XXX
DM XXXX
TM XX
XXXX
5
6
7 4
LDA STA
Constant
Decimal
Hexadecimal
T/C current
value
Data memory
Temporary memory
Relay No.
Relay No.
Storage Transfer Destination
I
n
t
e
r
n
a
l

r
e
g
i
s
t
e
r
T/C preset
value
Data memory
Temporary memory
Relay No.
Input Source
(Data type: operand)
Relay No.
(Data type: operand)
LDA / @LDA / STA @STA
Visual KV KV-300 KV-10/16 KV-24/40/80
LDA STA LDA STA LDA STA LDA STA
0000 to 0500 to 0000 to 0000 to 0000 to
17915 1915 0009 2915 6915
T000 to 2100 to 0500 to 0500 to T000 to 0500 to T000 to 0500 to
T249 17915 17915 1915 T063 1915 T119 1915
(Current
value)
C000 T000 to T000 to 2100 to C000 to 2100 to C000 to 2100 to
to 249 T249 T249 17915 C063 2915 C119 6915
(Current (Preset
value) value)
CTH0 to C000 C000 to T000 to CTH0 to T000 to CTH0 to T000 to
CTH1 to C249 C249 T249 CTH1 T063 CTH1 T119
(Preset
value)
DM0000 to CTC0 to CTH0 to C000 to DM0000 to C000 to DM0000 to C000 to
DM1999 CTC3 CTH1 C249 DM0999 C063 DM1999 C119
TM00 to DM0000 to DM0000 to CTC0 to TM00 to CTC0 to TM00 to CTC0 to
TM31 DM1999 DM9999 CTC3 TM31 CTC3 TM31 CTC3
#00000 to TM00 TM00 to DM0000 to #00000 to DM0000 to #00000 to DM0000 to
#65535 to TM29 TM31 DM9999 #65535 DM0999 #65535 DM1999
$0000 to #TM00 to #00000 to TM00 to $0000 to TM00 to $0000 to TM00 to
$FFFF #TM29 #65535 TM29 $FFFF TM29 $FFFF TM29
#TM00 to $0000 to #TM00 to #TM00 to #TM00 to #TM00 to #TM00 to
#TM29 $FFFF #TM29 #TM29 #TM29 #TM29 #TM29
#TM00 to
#TM29
2.4 Instruction Details
1
2
3-141
Chapter 2 Instructions
Arithmetic flag
2009 No change
2010 Turns ON when the contents of the internal register is "0" after
"LDA #00000" is executed. Turns OFF at other times.
2011 No change
2012 Turns ON when the DM or relay indirectly addressed with #TM is
out of range.
"Indirect addressing" (p. 3-127)
Application of LDA and STA instructions
I Changing the counter setting value
Coding
Description
In step a), contents of DM00100 is transferred to C001 via the internal register for
use as the C001 preset value, when 0000 is ON.
In step b) , contents of #00200 is transferred to C001 via the internal register for
use as the C001 preset value, when 0002 is OFF.
Although the C001 preset value is #09999 in the above example, any value
except #00000 can be given because the preset value is changed to the speci-
fied value by turning ON/OFF 0000.
Note 1: If an STA instruction is executed when the current value is larger than the
preset value, the current value will be changed to the preset value.
Note 2: Do not specify "#00000" as the setting value for C001.
When 0000 is ON, #00100 is transferred as C001
preset value.
When 0000 is OFF, #00200 is transferred as C001
preset value.
When C001 current value equals to its preset value,
0500 turns ON.
0000
C001 0500
b)
#00100
LDA
C001
STA
0000
0002
#00200
LDA
C001
STA
#09999
C001
0001
a)
Line No. Instruction Operand
0000 LD 0000
0001 LDA #00100
0002 CON
0003 STA C001
0004 LDB 0000
0005 LDA #00200
0006 CON
0007 STA C001
0008 LD 0002
0009 C 001 #09999 0001
0010 CON
0011 AND C001
0012 OUT 0500
LDA / @LDA / STA @STA
2.4 Instruction Details
3-142
2
Chapter 2 Instructions
I Transferring the current counter value to data memory (DM)
Coding
Description
In step a), the C010 current value is transferred via the internal register and stored
into DM0000, throughout the operation.
I Transferring the contents of data memory as a setting value for a timer
Coding
Description
In step a), contents of DM0010 is transferred to T002 via the internal register for
use as the T002 preset value, when 0002 is ON.
In step b), contents of DM0011 is transferred to T002 via the internal register for
use as the T002 preset value, when 0002 is OFF.
Although the preset value of T002 is #00010 in the above example, any value
except #00000 can be given because the preset value is changed to the speci-
fied value by turning ON/OFF 0002. Once the counter value has been changed,
the changed value will be stored until it is changed again.
The setting values of timers and counters are reset to the original setting values
after the power is turned OFF once and then ON again.
Note 1: If an STA instruction is executed when the current value is larger than the
preset value, the current value will be changed to the preset value.
Note 2: Do not change the setting value of T002 to "#00000".
The C010 current value is transferred to DM0000.
0001
2002 C010
LDA
DM0000
STA
#09999
C010
0000
a)
Line No. Instruction Operand
0000 LDB 0001
0001 C 010 #099999 0000
0002 LD 2002
0003 LDA C010
0004 CON
0005 STA DM0000
0002
T002 0500
b)
DM0010
LDA
T002
STA
0002
0003
DM0011
LDA
T002
STA
#00010
T002
a)
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0002 0007 STA T0002
0001 LDA DM0010 0008 LD 0003
0002 CON 0009 TMR 002 #00010
0003 STA T002 0010 CON
0004 LDB 0002 0011 AND T002
0005 LDA DM0011 0012 OUT 0500
0006 CON
LDA / @LDA / STA @STA
2.4 Instruction Details
1
2
3-143
Chapter 2 Instructions
I Outputting the input (ON/OFF status) of a basic unit directly to an expan-
sion output unit
The ON/OFF status of a KV series basic unit is output to a KV-E16T(P) unit con-
nected next to the basic unit.
Coding
Description
The LDA instruction transfers the input (ON/OFF status) of the KV basic unit to
the internal register using binary numbers.
The STA instruction outputs the binary data in the internal register as the ON/
OFF status from the KV-E16T(P) (output unit).
Refer to "1.3 Device Configuration" (p. 3-5) for relay number assignments.
Note 1: When "LDA 0004" and "STA 0604" are programmed in the above example,
the LDA instruction can transfer inputs 0100 through 0103 to the internal register;
however, the STA instruction cannot output data across the channels. As a result,
the ON/OFF status of inputs 0100 through 0103 cannot be output even if they are
fetched by the LDA instruction.
Note 2: Relays 0000 through 0415 are assigned as input relays, and 0500 through
0915 are assigned as output relays.
"1.3 Device Configuration" (p. 3-5)
2002 0000
LDA
0600
STA
Line No. Instruction Operand
0000 LD 2002
0001 LDA 0000
0002 CON
0003 STA 0600
1 : ON
0 : OFF
D0
D1
D2
D3
D4
D5
D6
D7
D8
D9
D10
D11
D12
D13
D14
D15
00
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
1
1
1
1
0
0
0
0
1
1
1
1
0
0
0
0
000
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
0600
0601
0602
0603
0604
0605
0606
0607
0608
0609
0610
0611
0612
0613
0614
0615
ON
ON
ON
ON
OFF
OFF
OFF
OFF
ON
ON
ON
ON
OFF
OFF
OFF
OFF
0000
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
ON
ON
ON
ON
OFF
OFF
OFF
OFF
ON
ON
ON
ON
OFF
OFF
OFF
OFF
0600
<STA>
0000
<LDA>
Out-
put
Input
(KV basic unit)
(Internal register)
16-bit
Binary number
Output
(KV-E16T(P))
Input
LDA / @LDA / STA @STA
2.4 Instruction Details
3-144
2
Chapter 2 Instructions
I When a BCD (2-digit) digital switch is connected to inputs 0000 through
0007 and a toggle switch is connected to inputs 0008 through 0015
a) Use the value of the digital switch (2 digits) as the setting value of a counter
(C001).
b) The current value of the counter (C001) is output to 0500 to 0515 using BCD
output.
Coding
Description
In example a), the LDA instruction reads the ON/OFF status of input relays 0000
through 0015 to the internal register.
"ANDA $00FF" instruction is used to leave only the digital switch input (2 digits).
BCD data is then converted into BIN (binary) data. (BIN is used in the KV series.)
The contents of the internal register is input as the setting value of C001.
In example b), the current value of counter C001 is read and output to output
relays 0500 through 0515.
Note 1: An LDA instruction can read the current value of a counter or a timer, but
cannot read the setting value.
Note 2: An STA instruction can change the setting value of a counter or a timer, but
cannot change the current value.
(C001)
<59>
2
0
+ 2
1
+ 2
3
+ 2
4
+ 2
5
= 1 + 2 + 8 + 16 + 32 = 59
D0
D1
D2
D3
D4
D5
D6
D7
D8
D9
D10
D11
D12
D13
D14
D15
D0
D1
D2
D3
D4
D5
D6
D7
D8
D9
D10
D11
D12
D13
D14
D15
1
1
0
1
1
1
0
0
0
0
0
0
0
0
0
0
C001
<STA>
1
1
0
1
1
1
0
0
0
0
0
0
0
0
0
0
<TBIN>
1
0
0
1
1
0
1
0
0
0
0
0
0
0
0
0
$00FF
<ANDA>
1
0
0
1
1
0
1
0
0
1
1
1
0
0
0
0
ON
OFF
OFF
ON
ON
OFF
ON
OFF
OFF
ON
ON
ON
OFF
OFF
OFF
OFF
000
001
002
003
004
005
006
007
008
009
010
011
012
013
014
015
07000
<LDA>
(Decimal
number)
Digital switch
Reset input
Proximity
SW input
SW input
Internal register
Counter
setting
value
ON/OFF
status is
trans-
ferred to
internal
register.
Only low-
order 2
digits is
used.
BCD
data is
converted
into binary
data.
Data is
transferred
as setting
value of
counter.
0008
0010 0000
LDA
$00FF
ANDA TBIN
C001
STA
#09999
C001
0009
0011 C001
LDA TBCD
0500
STA b)
a)
Line No. Instruction Operand
0000 LDB 0008
0001 C 001 #09999 0009
0002 LD 0010
0003 LDA 0000
0004 CON
0005 ANDA $00FF
0006 CON
0007 TBIN
0008 CON
0009 STA C001
0010 LD 0011
0011 LDA C001
0012 CON
0013 TBCD
0014 CON
0015 STA 0500
LDA / @LDA / STA @STA
2.4 Instruction Details
1
2
3-145
Chapter 2 Instructions
Note 3: When an STA instruction is executed while the setting value of a counter or
a timer is smaller than the current value, the current value is changed to be the
setting value.
I First-in first-out (FIFO)
The data once fetched is written into DM0004,
DM0003, , to DM0000 in this order. At the
unloading timing, data is fetched from
DM0004 and the contents of DM are shifted
to the next DM.
The OK/NG judgment and unloading timings can be used in asynchronous pro-
grams.
Coding
DM0000
DM0001
DM0002
DM0003
DM0004
Unloading
timing
OK/NG
judgment
Data
shift
0000 1000 0001
DM0004
LDA
$1111
LDA
DM0000
STA
$0000
CMP
DM0003
LDA
DM0004
STA
$0000
LDA
DM0003
STA
1000
0001 $5555
LDA
DM0000
STA

DIFU
2002 2010
DM0003
LDA
$0000
CMP
DM0002
LDA
DM0003
STA
$0000
LDA
DM0002
STA
2002 2010
DM0002
LDA
$0000
CMP
DM0001
LDA
DM0002
STA
$0000
LDA
DM0001
STA
2002 2010
DM0001
LDA
$0000
CMP
DM0000
LDA
DM0001
STA
$0000
LDA
DM0000
STA
2002
$0000 DM0004
STA
0002
2010
LDA
Contents of DM is compared with "$0000".
When two values match, contents of one
previous DM is transferred, then "$0000" is
transferred to DM.
"$0000" is transferred to DM
at unloading timing.
OK/NG judgment
timing OK/NG judgment
"$1111" is transferred to
DM0000.
"$5555" is transferred to DM0000.
Unloading
timing
Line No. Instruction Operand
0000 LD 0000
0001 DIFU 1000
0002 CON
0003 AND 1000
0004 MPS
0005 AND 0001
0006 LDA $1111
0007 CON
0008 STA DM0000
0009 MPP
0010 ANB 0001
0011 LDA $5555
0012 CON
0013 STA DM0000
0014 LD 2002
0015 LDA DM0004
0016 CON
0017 CMP $0000
0018 CON
0019 AND 2010
0020 LDA DM0003
0021 CON
0022 STA DM0004
0023 CON
0024 LDA $0000
0025 CON
0026 STA DM0003
0027 LD 0002
0028 LDA DM0003
0029 CON
0030 CMP $0000
0031 CON
0032 AND 2010
0033 LDA DM0002
0034 CON
Line No. Instruction Operand
0035 STA DM0003
0036 CON
0037 LDA $0000
0038 CON
0039 STA DM0002
0040 LD 2002
0041 LDA DM0002
0042 CON
0043 CMP $0000
0044 CON
0045 AND 2010
0046 LDA DM0001
0047 CON
0048 STA DM0002
0049 CON
0050 LDA $0000
0051 CON
0052 STA DM0001
0053 LD 2002
0054 LDA DM0001
0055 CON
0056 CMP $0000
0057 CON
0058 AND 2010
0059 LDA DM0000
0060 CON
0061 STA DM0001
0062 CON
0063 LDA $0000
0064 CON
0065 STA DM0000
0066 LD 0002
0067 @LDA $0000
0068 CON
0069 @STA DM0004
LDA / @LDA / STA @STA
2.4 Instruction Details
3-146
2
Chapter 2 Instructions
CMP instruction compares the contents of the internal register with the value speci-
fied by the operand, and turns ON/OFF the special utility relays (2009, 2010, 2011)
according to the result of comparison.
Comparing the current value of the counter and CMP value
1) Output relay 0500 turns ON when the counter value is smaller than "1000" (C001
< #01000).
2) Output relay 0501 turns ON when the counter value is equal to "1000" (C001 =
#01000).
3) Output relay 0502 turns ON when the counter value is greater than "1000" (C001
> #01000).
4) Output relay 0503 turns ON when the counter value is equal to or greater than
"2000" (C001 #02000).
Coding
CMP: Compare
@CMP: Compare
Compares contents of internal register with
value specified by operand.
@
#,$
FUN
FUN
LDB
4
RES
0
LDB
4
RES
0
nnnn
CMP
nnnn
CMP
2009 2010 2011
(Internal register) < (Operand) ON OFF OFF
(Internal register) = (Operand) OFF ON OFF
(Internal register) > (Operand) OFF OFF ON
0001
C001
LDA
#01000
CMP
0500
#09999
0003
C001
2) (=)
1) (<)
3) (>)
4) ()
2002
C001
LDA
#02000
CMP
2002
2009
0501 2010
0502 2011
0503 2009
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB 0001 0012 OUT 0501
0001 C 001 #099999 0003 0013 MPP
0002 LD 2002 0014 AND 2011
0003 LDA C001 0015 OUT 0502
0004 CON 0016 LD 2002
0005 CMP #01000 0017 LDA C001
0006 CON 0018 CON
0007 MPS 0019 CMP #02000
0008 AND 2009 0020 CON
0009 OUT 0500 0021 ANB 2009
0010 MRD 0022 OUT 0503
0011 AND 2010
:
:
CMP / @CMP
2.4 Instruction Details
1
2
3-147
Chapter 2 Instructions
Operands
Key operation
Arithmetic flag
2009 Turns ON when the result of the CMP operation is negative. Turns OFF at
other times.
2010 Turns ON when the result of the CMP operation is "0". Turns OFF at other
times.
2011 Turns ON when the result of the CMP operation is positive. Turns OFF at
other times.
2012 The DM or relay indirectly addressed with #TM is out of range.
"Indirect addressing" (p. 3-127)
Description
As shown in the above example, the CMP instruction is used by connecting the
special utility relay (2009 to 2011) immediately after the instruction.
The operation of the CMP instruction varies depending on the contents of the
internal register.
Note: Special utility relays 2009 to 2011 are used as arithmetic flags. The function
varies depending on the execution of other arithmetic instructions.
Tips
An operand is compared with the internal register using the following program.
When the internal register is assumed as "a" and the operand is "b" such as , the
statuses of the special utility relays are as follows:
@
#,$
FUN
FUN
LDB
4
RES
0
ENT
R-SRCH
ENT
R-SRCH
Operand
#00999
CMP
DM0000
LDA
2009
a
LDA CMP
b
2009
a < b, a b, a = b, a b, a > b
2011 2010 2009 2011
CMP / @CMP
Visual KV KV-300 KV-10/16 KV-24/40/80
DM0000 to DM1999 DM0000 to DM9999 DM0000 to DM0999 DM0000 to DM1999
TM00 to TM31 TM00 to TM31 TM00 to TM31 TM00 to TM31
#00000 to #65535 #00000 to #65535 #00000 to #65535 #00000 to #65535
$0000 to $FFFF $0000 to $FFFF $0000 to $FFFF $0000 to $FFFF
#TM00 to #TM29 #TM00 to #TM29 #TM00 to #TM29 #TM00 to #TM29
2.4 Instruction Details
3-148
2
Chapter 2 Instructions
2009
2010
2011
2002
0502
0501
0500
DM0000<#01000
DM0000=#01000
DM0000>#01000
DM0000
LDA
#01000
CMP
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0007 MRD
0001 LDA DM0000 0008 AND 2010
0002 CON 0009 OUT 0501
0003 CMP #01000 0010 MPP
0004 MPS 0011 AND 2011
0005 AND 2009 0012 OUT 0502
0006 OUT 0500
Application of CMP instruction
I Multi-level counter
Coding
Description
The following outputs are provided according to the current value of the counter.
(Current value) (Output)
0000 to 0999 0500 turns ON.
1000 to 1999 0501 turns ON.
2000 to 2999 0502 turns ON.
I When comparing values with no specific range
Turns ON 0500 when the DM0000 value is smaller than the CMP value.
Turns ON 0501 when the DM0000 value is equal to the CMP value.
Turns ON 0502 when the DM0000 value is greater than the CMP value.
Coding
0001
C000
LDA
#00999
CMP
#01999
CMP
#02999
CMP
0500
#09999
0000
C000
2002 2011
0501 2011
0502 2011
0500
0500 0501
Line No. Instruction Operand
0000 LDB 0001
0001 C 000 #099999
0000
0002 LD 2002
0003 LDA C000
0004 CON
0005 MPS
0006 CMP #00999
0007 CON
0008 ANB 2011
0009 OUT 0500
0010 MRD
0011 CMP #01999
0012 CON
0013 ANB 2011
0014 ANB 0500
0015 OUT 0501
0016 MPP
0017 CMP #02999
0018 CON
0019 ANB 2011
0020 ANB 0500
0021 ANB 0501
0022 OUT 0502
CMP / @CMP
2.4 Instruction Details
1
2
3-149
Chapter 2 Instructions
I Setting the upper/lower limit
Turns ON 0500 when the C001 value is 1000 or less.
Turns ON 0501 when the C001 value is 2000 or more.
Coding
I Changing the CMP setting value
Compares the current value of counter C000 with the CMP setting value. The setting
value of the CMP instruction is specified with the digital trimmer (TMIN0). The
following example changes the setting value to the range from "0" through "100".
The upper limit of the digital trimmer is set to "100".
0500 turns ON when the current value of C000 is smaller than the CMP setting
value.
0501 turns ON when the current value of C000 is equal to or greater than the CMP
setting value.
Coding
2011
2009
0001
2002
2002
C001#01000
C001#02000
C001
LDA
C001
LDA
#01000
CMP
#02000
CMP
0500
0501
#09999
0000
C001
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB 0001 0008 OUT 0500
0001 C 001 #09999 0000 0009 LD 2002
0002 LD 2002 0010 LDA C001
0003 LDA C001 0011 CON
0004 CON 0012 CMP #02000
0005 CMP #01000 0013 CON
0006 CON 0014 ANB 2009
0007 ANB 2011 0015 OUT 0501
Sets range of TMIN from 0 to 100.
2009
2009
0001
2002
2002
C000
LDA
DM0000
CMP
DM0000
STA
0
TMIN
0500
0501
#09999
00000
C000
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0011 C 000 #09999 0000
0001 TMIN 0 0012 LD 02002
0002 CON 0013 LDA C000
0003 ADD #00001 0014 CON
0004 CON 0015 CMP DM0000
0005 MUL #00004 0016 MPS
0006 CON 0017 AND 2009
0007 DIV #00010 0018 OUT 0500
0008 CON 0019 MPP
0009 STA DM0000 0020 ANB 2009
0010 LDB 0001 0021 OUT 0501
CMP / @CMP
2.4 Instruction Details
3-150
2
Chapter 2 Instructions
ADD, SUB, MUL, and DIV allow arithmetic instructions between the contents of
internal register and the value specified by the operand.
Note: Arithmetic instructions use binary numbers (BIN). Therefore, the contents of
the internal register used for the arithmetic instruction must be BIN data. Use the
TBIN instruction to convert BCD data into BIN data.
Operands
Key operation
ADD: Add
@ADD: Add
SUB: Subtract
@SUB: Subtract
MUL: Multiply
@MUL: Multiply
DIV: Divide
@DIV: Divide
Adds value specified by operand to contents of
internal register, and inputs result back to same
internal register.
@
#,$
FUN
FUN
@
#,$
FUN
FUN
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LDB
4
SET
1
SET
1
RES
0
RES
0
AND
8
ANL
2
ORB
6
LDB
4
SET
1
SET
1
RES
0
RES
0
AND
8
ANL
2
ORB
6
nnnn
DIV
nnnn
DIV
nnnn
MUL
nnnn
MUL
nnnn
SUB
nnnn
SUB
nnnn
ADD
nnnn
ADD
ADD
SUB
MUL
DIV
(#XXXXX)
($XXXX)
DM0000 to DM1999
TM00 to TM31
#TM00 to #TM29
@
#,$
FUN
FUN
@
#,$
FUN
FUN
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LDB
4
SET
1
SET
1
RES
0
RES
0
ANL
2
ORB
6
AND
8
ENT
R-SRCH
ENT
R-SRCH
Operand
ENT
R-SRCH
ENT
R-SRCH
Operand
ENT
R-SRCH
ENT
R-SRCH
Operand
ENT
R-SRCH
ENT
R-SRCH
Operand
I
n
t
e
r
n
a
l

r
e
g
i
s
t
e
r
O
p
e
r
a
n
d
C
o
n
s
t
a
n
t
s
D
a
t
a

m
e
m
o
r
i
e
s
Hexadecimal
Result Arithmetic operation
Decimal
I
n
t
e
r
n
a
l

r
e
g
i
s
t
e
r
:
:
:
:
:
:
:
:
Subtracts value specified by operand from
contents of internal register, and inputs results
back to same register.
Multiplies contents of internal register by value
specified by operand, and inputs result back to
same register.
Divides contents of internal register by value
specified by operand, and inputs result back to
same register.
ADD / @ADD / SUB / @SUB / MUL / @MUL / DIV / @DIV
Visual KV KV-300 KV-10/16 KV-24/40/80
DM0000 to DM1999 DM0000 to DM9999 DM0000 to DM0999 DM0000 to DM1999
TM00 to TM31 TM00 to TM31 TM00 to TM31 TM00 to TM31
#00000 to #65535 #00000 to #65535 #00000 to #65535 #00000 to #65535
$0000 to $FFFF $0000 to $FFFF $0000 to $FFFF $0000 to $FFFF
#TM00 to #TM29 #TM00 to #TM29 #TM00 to #TM29 #TM00 to #TM29
2.4 Instruction Details
1
2
3-151
Chapter 2 Instructions
ADD (Addition)
Coding
Description
The ADD instruction adds the operand value to the contents of the internal
register and inputs the result back to the internal register.
In the above example, "#00100" is added to the contents of DM0000 and the
result is stored in DM0001.
When the contents of DM0000 is "#00100", for example, "#00200" is stored in
DM0001.
DM0000 (#00100) + #00100 DM0001(#00200)
Note 1: An overflow occurs when the operation result exceeds 16 bits ($FFFF,
#65535). In such a case, only the data of the low-order 16 bits is input back to the
internal register. For example, when the contents of the internal register is "$FFFF"
and the operand is "$0001", the result will overflow.
Note 2: When an overflow occurs, special utility relay 2009 turns ON.
Tips
Solution when operation result overflows 16 bits
DM0000 + DM0001 = DM0003 (High-order 16 bits), DM0002 (Low-order 16 bits)
DM0000 and DM0001 must be 16 bits or less.
Arithmetic flag
2009 Turns ON when the result of an ADD operation exceeds the range of 16 bits
($FFFF). Turns OFF at other times.
2010 Turns ON when the contents of the internal register is "0" after an ADD
operation. Turns OFF at other times.
2011 No change
2012 The DM or relay indirectly addressed with #TM is out of range.
"Indirect addressing" (p. 3-127)
DM0000
LDA
#00100
ADD
DM0001
STA
2002
Line No. Instruction Operand
0000 LD 2002
0001 LDA DM0000
0002 CON
0003 ADD #00100
0004 CON
0005 STA DM0001
Example:
Internal register
1
1
= $FFFF 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0
+ = $0002 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
0 = $0001
2009
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
Operand
Overflow
Special
utility relay
Input back internal register Result
DM0000
LDA
DM0001
ADD
DM0002
STA
#00000
LDA
DM0003
STA
DM0002
STA
#00001
LDA
DM0003
STA
2002 2009
2009
ADD / @ADD
2.4 Instruction Details
3-152
2
Chapter 2 Instructions
Application of ADD instruction
I Total count
Writes the total count of counters C001 to C003 into DM0100. The total count must
be within #65535.
Coding
Writes C001 current value into DM0001.
C001
LDA
DM0001
STA
0000
C002
LDA
DM0002
STA
0000
C003
LDA
DM0003
STA
0000
DM0002
ADD
DM0001
LDA
DM0003
ADD
DM0100
STA
2002
#09999
C003
#09999
C001
0001
0002
#09999
C002
0003
Writes C002 current value into DM0002.
Writes C003 current value into DM0003.
Writes total count (DM0001 + DM0002 +
DM0003) into DM100.
Line No. Instruction Operand
0000 LDB 0001
0001 C 010 #099999 0000
0002 CON
0003 LDA C001
0004 CON
0005 STA DM0001
0006 LDB 0000
0007 C 002 #099999 0002
0008 CON
0009 LDA C002
0010 CON
0011 STA DM0002
0012 LDB 0000
0013 C 003 #099999 0003
0014 CON
0015 LDA C003
0016 CON
0017 STA DM0003
0018 LD 2002
0019 LDA DM0001
0020 CON
0021 ADD DM0002
0022 CON
0023 ADD DM0003
0024 CON
0025 STA DM0100
ADD / @ADD
2.4 Instruction Details
1
2
3-153
Chapter 2 Instructions
SUB (Subtraction)
Coding
Description
The SUB instruction subtracts the operand value from the contents of the internal
register and inputs the result back into the internal register.
In the above example, "#00100" is subtracted from the contents of DM0000 and
the result is stored in DM0001.
When the contents of DM0000 is "#00150", for example, "#00050" is stored in
DM0001.
DM0000 (#00150) #00100 DM0001 (#00050)
Note 1: When the operation result is a negative value (-), the 2's complement value
is also stored in the internal register.
Special utility relay 2009 turns ON.
Note 2: To convert the complement into an antilogarithm, add the following opera-
tion:
Inverted bit of complement + 1 = Antilogarithm
Tips
Solution when operation result is a negative value
When DM0000 is "#10" and DM0001 is "#30", "#20" is stored in DM0003.
Arithmetic flag
2009 Turns ON when the result of a SUB operation is negative. Turns OFF at
other times.
2010 Turns ON when the contents of the internal register is "0" after a SUB
operation. Turns OFF at other times.
2011 Turns ON when the result of a SUB operation is positive. Turns OFF at other
times.
2012 The DM or relay indirectly addressed with #TM is out of range.
"Indirect addressing" (p. 3-127)
DM0000
LDA
#00100
SUB
DM0001
STA
2002
Line No. Instruction Operand
0000 LD 2002
0001 LDA DM0000
0002 CON
0003 SUB #00100
0004 CON
0005 STA DM0001
0
1
= $0001 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1
1
- = $FFFF 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1
0 = $0002 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0
2009
2's complement is stored.
Internal register
Operand
Underflow
DM0000
LDA
DM0001
SUB
DM0002
STA
COM
#0001
ADD
DM0003
STA
2002 2009
2009
DM0000 - DM0001 =
(Stores positive value)
(Stores negative value)
Absolute value
is stored.
Positive value DM0002
Negative value DM0003
SUB / @SUB
2.4 Instruction Details
3-154
2
Chapter 2 Instructions
Application of SUB instruction
I Comparing absolute values
Compares the DM0000 value to the DM0001 value and turns ON 0500 when the
difference between the two absolute values is greater than 5.
Coding
2002 2009 2009 DM0000
LDA
DM0001
SUB
#0005
CMP
1001
1000
2009 DM0001
LDA
DM0000
SUB
1000
2009 #00005
CMP
1001
0500
Line No. Instruction Operand
0000 LD 2002
0001 LDA DM0000
0002 CON
0003 SUB DM0001
0004 MPS
0005 ANB 2009
0006 CMP #00005
0007 CON
0008 ANB 2009
0009 OUT 1000
0010 MPP
0011 AND 2009
0012 LDA DM0001
0013 CON
0014 SUB DM0000
0015 CON
0016 CMP #00005
0017 CON
0018 ANB 2009
0019 OUT 1001
0020 LD 1000
0021 OR 1001
0022 OUT 0500
SUB / @SUB
2.4 Instruction Details
1
2
3-155
Chapter 2 Instructions
MUL (Multiplication)
Coding
Description
The MUL instruction multiplies the contents of the internal register by the oper-
and value and inputs the result back to the internal register.
In the above example, the contents of DM0000 are multiplied by "#00100" and
the result is stored in DM0001.
When the contents of DM0000 is "#00200", for example, "#20000" is stored in
DM0001.
DM0000 (#00200) x #00100DM0001 (#20000)
Note 1: An overflow occurs when the operation result exceeds 16 bits (#65535). In
such a case, only the data of the low-order 16 bits are stored in the internal register,
and the overflow data of the high-order 16 bits is stored in TM00. (The data of the
high-order 16 bits is always stored in TM00.)
Note 2: When an overflow occurs, special utility relay 2009 turns ON.
Tips
Solution when operation result overflows 16 bits
DM0000 x DM0001 = DM0003 (High-order 16 bits) DM0002 (Low-order 16 bits)
The operation result must be 32 bits or less.
Arithmetic flag
2009 Turns ON when the result of a MUL operation exceeds 16 bits. Turns OFF at
other times.
2010 Turns ON when all 32 bits are "0" after a MUL operation. Turns OFF at other
times.
2011 No change
2012 The DM or relay indirectly addressed with #TM is out of range.
"Indirect addressing" (p. 3-127)
DM0000
LDA
#00100
MUL
DM0001
STA
2002
Line No. Instruction Operand
0000 LD 2002
0001 LDA DM0000
0002 CON
0003 MUL #00100
0004 CON
0005 STA DM0001
F
(TM00)
F F F
0 0 0 2
F F F F 0 0 0 1
(Internal register)
Internal register
Operand Hexadecimal number
2002 DM0000
LDA
DM0001
MUL
DM0002
STA
TM00
LDA
DM0003
STA
MUL / @MUL
2.4 Instruction Details
3-156
2
Chapter 2 Instructions
2002 DM0001
LDA
TM00
STA
DM0000
LDA
#00100
DIV
DM0002
STA
TM00
LDA
DM0003
STA
TM01
LDA
DM0004
STA
Line No. Instruction Operand
0000 LD 2002
0001 LDA DM0001
0002 CON
0003 STA TM00
0004 CON
0005 LDA DM0000
0006 CON
0007 DIV #00100
0008 CON
0009 STA DM0002
0010 CON
0011 LDA TM00
0012 CON
0013 STA DM0003
0014 CON
0015 LDA TM01
0016 CON
0017 STA DM0004
Application of MUL instruction
I Multiplying the counter current value by the DM value
Multiplies the counter current value by the DM0000 value and writes the high-order
16 bits of the product into DM0101 and low-order 16 bits of the product into
DM0100.
Coding
DIV (Division)
Coding
0001
C001
LDA
DM0000
MUL
DM0100
STA
TM00
LDA
DM0101
STA
2002
#09999
0000
C001
Line No. Instruction Operand
0000 LDB 0001
0001 C 001 #099999 0000
0002 LD 2002
0003 LDA C001
0004 CON
0005 MUL DM0000
0006 CON
0007 STA DM0100
0008 CON
0009 LDA TM00
0010 CON
0011 STA DM0101
High-order Low-order Low-order High-order Remainder
MUL / @MUL / DIV / @DIV
2.4 Instruction Details
1
2
3-157
Chapter 2 Instructions
Arithmetic flag
2009 No change
2010 Turns ON when all 32 bits are "0" after a DIV operation. Turns OFF at other
times.
2011 No change
2012 Turns ON when the divisor of a DIV operation is "0" or the DM or relay
indirectly addressed with #TM is out of range.
"Indirect addressing" (p. 3-127)
Description
The 32-bit value (binary) consisting of the higher 16 bits from TM00 and lower 16
bits from the internal register is divided by the value specified by the operand.
The higher 16 bits of the result is input back to TM00 and lower 16 bits to the
same internal register. The remainder is stored in TM01.
Note 1: When data of 16 bits or less is divided by the operand value, the contents of
TM00 must be cleared (set to "#00000") before the DIV operation.
Note 2: If the contents of TM00 are not cleared, the data stored in TM00 is also
used for the operation.
Tips
Solution when data of 16 bits or less is divided
TM00
TM00 TM01
DM0000 DM0001
DM0002 DM0003 DM0004
#00100
Quotient
Example
Low-order 16 bits
Remainder (16 bits)
Internal register Operand
High-order 16 bits
Internal register
Remainder (16 bits)
Low-order 16 bits High-order 16 bits
Low-order 16 bits High-order 16 bits
Low-order 16 bits High-order 16 bits
Quotient
02002 #00000
LDA
TM00
STA
DM0000
LDA
DM0001
DIV
DM0002
STA
TM01
LDA
DM0003
STA
TM00 DM0000 = TM00 DM0002 DM0003
High-order
16 bits
Quotient
Remainder Low-order
16 bits
High-order
16 bits
Low-order
16 bits
DIV / @DIV
2.4 Instruction Details
3-158
2
Chapter 2 Instructions
Application of DIV instruction
I Total count average
Outputs the average of 3 counter values in 4-digit BCD.
(C001 + C002 + C003) 3 BCD output value
The BCD value is output to 500 to 515.
Coding
C001
LDA
DM0001
STA
0000
C002
LDA
DM0002
STA
0000
C003
LDA
DM0003
STA
0000
DM0001
LDA
DM0002
ADD
DM0003
ADD
2002
#09999
C003
0003
#09999
C001
#09999
0001
0002
C002
(DM0001+DM0002+DM0003)
TM00
STA
#00000
LDA
2002
#00003
DIV TBCD
0500
STA
2002
3 Output to 0500 to 0515 in 4-digit BCD.
Writes the C001 current value into DM0001.
Writes the C002 current value into DM0002.
Writes the C003 current value into DM0003.
Line No. Instruction Operand
0000 LDB 0000
0001 C 001 #099999 0001
0002 CON
0003 LDA C001
0004 CON
0005 STA DM0001
0006 LDB 0000
0007 C 002 #099999 0002
0008 CON
0009 LDA C002
0010 CON
0011 STA DM0002
0012 LDB 0000
0013 C 003 #099999 0003
0014 CON
0015 LDA C003
0016 CON
0017 STA DM0003
0018 LD 2002
0019 LDA DM0001
0020 CON
0021 ADD DM0002
0022 CON
0023 ADD DM0003
0024 LD 2002
0025 DIV #0003
0026 CON
0027 TBCD
0028 CON
0029 STA 500
DIV / @DIV
2.4 Instruction Details
1
2
3-159
Chapter 2 Instructions
Example
Coding
Description
The contents of DM0000 are transferred to the internal register when input relay
0000 is ON.
The contents of the internal register (DM0000) and the value specified by the
operand ($00FF) are ANDed for each bit and the result (logical product) is input
back to the same register.
When the operation result is "0", special utility relay 2010 turns ON.
The contents of the internal register are transferred to DM0001.
The following shows the case when DM0000 is "$F0F0".
Operands
Key operation
ANDA:
@ANDA:
ANDs contents of internal register and
value specified by operand for each of
16 bits, and inputs result back to same
register.
AND A
(Logical product)
@
#,$
FUN
FUN
SET
1
RES
0
SET
1
RES
0
nnnn
ANDA
nnnn
ANDA
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 ANDA $00FF
0004 CON
0005 STA DM0001
0000 DM0000
LDA
$00FF
ANDA
DM0001
STA
(DM0000) ^ ($00FF) = (DM0001)
Logical product
Contents of DM0000
are transferred to the
internal register.
1
AND
1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0
DM0000
LDA
$00FF
ANDA
DM0001
STA
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Only when both bits of the
internal register and the
operand are "1", will the logical
product be "1".
@
#,$
FUN
FUN
SET
1
RES
0
ENT
R-SRCH
ENT
R-SRCH
Operand
These values are ANDed for
each bit to obtain logical product.
The result is transferred
to DM0001.
Internal
register
Operand ($F0F0)
Internal
register
AND (Logical product)
truth table
(Result)
:
:
DM0000 ($F0F0)
($F0F0)
($F0F0)
DM0001 ($00F0)
Internal Operand Internal
register register
1 1 1
1 0 0
0 1 0
0 0 0
ANDA / @ANDA
Visual KV KV-300 KV-10/16 KV-24/40/80
0000 to 17915 0000 to 17915 0000 to 2915 0000 to 6915
DM0000 to DM1999 DM0000 to DM9999 DM0000 to DM0999 DM0000 to DM1999
TM00 to TM31 TM00 to TM31 TM00 to TM31 TM00 to TM31
#00000 to #65535 #00000 to #65535 #00000 to #65535 #00000 to #65535
$0000 to $FFFF $0000 to $FFFF $0000 to $FFFF $0000 to $FFFF
#TM00 to #TM29 #TM00 to #TM29 #TM00 to #TM29 #TM00 to #TM29
2.4 Instruction Details
3-160
2
Chapter 2 Instructions
Arithmetic flag
2009 No change
2010 Turns ON when the internal register is "0" after an ANDA operation.
Turns OFF at other times.
2011 No change
2012 The DM or relay indirectly addressed with #TM is out of range.
"Indirect addressing" (p. 3-127)
Tips
Solution when connecting one-digit data of a BCD digital switch to inputs 0100
to 0103, while ignoring other inputs
Only one-digit data of the BCD digital switch is transferred as the setting value of the
fetching counter (C004).
Other inputs (0104 to 0115) are ignored.
Application of ANDA instruction
I Fetch input data separately
Sets the low-order 2 digits of the BCD digital switch (7000 to 7007) to counter C000
and the high-order 2 digits (7008 to 7015) to timer T001.
Coding
0004
2002
#00300
C004
0005
0100
LDA
$000F
ANDA TBIN
C004
STA
7000
LDA
$00FF
ANDA TBIN
C000
STA
2002
TBIN
#08
SRA
$FF00
ANDA
7000
LDA
T001
STA
2002
0001
0001
#09999
C000
0000
#09999
T001
Line No. Instruction Operand
0000 LD 2002
0001 LDA 7000
0002 CON
0003 ANDA $00FF
0004 CON
0005 TBIN
0006 CON
0007 STA C000
0008 LD 2002
0009 LDA 7000
0010 CON
0011 ANDA $FF00
0012 CON
0013 SRA #08
0014 CON
0015 TBIN
0016 CON
0017 STA T001
0018 LDB 0001
0019 C 000 #09999 0000
0020 LDB 0001
0021 T 001 #09999
Converts data of 7000 to 7007 to BIN and
writes it into C000.
Shifts data to right by 8 bits, converts it to BIN,
and writes it into T001.
Sets C000.
Sets T001.
ANDA / @ANDA
2.4 Instruction Details
1
2
3-161
Chapter 2 Instructions
Example
Coding
Description
The contents of DM0000 are transferred to the internal register when input relay
0000 is ON.
The contents of the internal register (DM0000) and the value specified by the
operand ($00FF) are ORed for each bit and the result (logical sum) is input back
to the same register.
When the operation result is "0", special utility relay 2010 turns ON.
The contents of the internal register are transferred to DM0001.
The following shows the case when DM0000 is "$F0F0".
Operands
Key operation
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 ORA $00FF
0004 CON
0005 STA DM0001
ORA:
@ORA:
ORs contents of internal register and value
specified by operand for each of 16 bits,
and inputs result back to same register.
Or A
(Logical sum)
@
#,$
FUN
FUN
SET
1
ORL
3
SET
1
ORL
3
nnnn
ORA
nnnn
ORA
1
OR
1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1
1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1
DM0000
LDA
$00FF
ORA
DM0001
STA
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Contents of DM0000 are
transferred to the internal
register.
Only when both bits of the
internal register and the
operand are "0", will the logical
sum be "0".
These values are ORed for
each bit to obtain logical sum.
The result is transferred
to DM0001.
Internal
register
Operand ($00FF)
Internal
register
OR (Logical sum)
truth table
(Result)
@
#,$
FUN
FUN
SET
1
ORL
3
ENT
R-SRCH
ENT
R-SRCH
Operand
0000 DM0000
LDA
$00FF
ORA
DM0001
STA
(DM0000) U ($00FF) = (DM0001)
Logical sum
:
:
DM000 ($F0F0)
($F0F0)
($F0FF)
Internal
Operand
Internal
register register
1 1 1
1 0 1
0 1 1
0 0 0
ORA / @ORA
Visual KV KV-300 KV-10/16 KV-24/40/80
0000 to 17915 0000 to 0009 0000 to 2915 0000 to 6915
DM0000 to DM1999 0500 to 17915 DM0000 to DM0999 DM0000 to DM1999
TM00 to TM31 DM0000 to DM9999 TM00 to TM31 TM00 to TM31
#00000 to #65535 TM00 to TM31 #00000 to #65535 #00000 to #65535
$0000 to $FFFF #00000 to #65535 $0000 to $FFFF $0000 to $FFFF
#TM00 to #TM29 $0000 to $FFFF #TM00 to #TM29 #TM00 to #TM29
#TM00 to #TM29
2.4 Instruction Details
3-162
2
Chapter 2 Instructions
0000
TBCD
C000
LDA
0500
STA
DM0000
ORA
$00FF
ANDA
$FF00
ANDA
0500
LDA
DM0000
STA
2002
2002
2002
#00099
C000
0001
Sets C000.
Writes data of 0008 to 0015 into DM0000.
ORs the data in the internal register and the DM0000
data and sends the ORed data to 0500 to 0515.
2002 0100
LDA
$000F
ANDA
DM0000
STA
0200
LDA
$000F
ANDA
#04
SLA
DM0000
ORA
C004
STA
#00300

C004
0005
TBIN
0004
Converts the current value of C000 to BCD and retains
the low-order 2 digits of BCD in the internal register.
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB 0000 0009 LDA C000
0001 C 001 #00099 0001 0010 CON
0002 LD 2002 0011 TBCD
0003 LDA 0500 0012 CON
0004 CON 0013 ANDA $00FF
0005 ANDA $FF00 0014 LD 2002
0006 CON 0015 ORA DM0000
0007 STA DM0000 0016 CON
0008 LD 2002 0017 STA 0500
ORA / @ORA
Arithmetic flag
2009 No change
2010 Turns ON when the internal register is "0" after an ORA operation. Turns
OFF at other times.
2011 No change
2012 The DM or relay indirectly addressed with #TM is out of range.
"Indirect addressing" (p. 3-127)
Tips
Solution when connecting two-digit data of a BCD digital switch (inputs 0100
to 0103 for the first digit and 0200 to 0203 for the second digit) separately
Fetches the two-digit data of the BCD digital switch, which are separated into the
first digit (0100 to 0103) and the second digit (0200 to 0203), and transfers the
values as the setting value of a counter (C004).
Application of ORA instruction
I Output of BCD 2-digit data
Converts the current value of counter C000 to BCD and sends 2 digits of BCD data
to output relays 0500 to 0507.
However, retain ON/OFF of 0508 to 0515 which are loaded.
Coding
2.4 Instruction Details
1
2
3-163
Chapter 2 Instructions
0000
ANDA
0100
LDA
DM0000
ORA TBIN
C001
STA
#04
SLA
$000F
$000F
ANDA
0000
LDA
DM0000
STA
2002
2002
2002
#00099
C000
0001
Line No. Instruction Operand
0000 LDB 0001
0001 C 001 #00099 0001
0002 LD 2002
0003 LDA 0000
0004 CON
0005 ANDA $000F
0006 CON
0007 STA DM0000
0008 LD 2002
0009 LDA 0100
0010 CON
0011 ANDA $000F
0012 LD 2002
0013 SLA #04
0014 CON
0015 ORA DM0000
0016 CON
0017 TBIN
0018 CON
0019 STA C001
Sets C001.
Writes data of 7000 to 7003 into DM0000.
Writes data of 8000 to 8003 into internal regis-
ter.
ORA / @ORA
I Separate input of 2-digit BCD
Fetches only 2 digits of the BCD digital switch (0000 to 0003 for the 1st digit, 0100
to 0103 for the 2nd digit) and sets it as the counter value.
Coding
ORs content of internal register which is shifted
to left by four bits and data of 7000 to 7003,
converts ORed data into BIN, and write it into
C001.
2.4 Instruction Details
3-164
2
Chapter 2 Instructions
Example
Coding
Description
The contents of DM0000 is transferred to the internal register when input relay
0000 is ON.
The contents of the internal register (DM0000) and the value specified by the
operand ($00FF) are EORed (exclusive OR) for each bit and the result is input
back to the same register.
When the operation result is "0", special utility relay 2010 turns ON.
The contents of the internal register is transferred to DM0001.
The following shows the case when DM0000 is "$F0F0".
Operands
Key operation
EORA:
@EORA:
EXCLUSIVE ORs contents of internal
register and operand for each of 16 bits,
and inputs result back to same register.
Exclusive Or A
(Exclusive
logical sum)
@
#,$
FUN
FUN
SET
1
ANB
5
SET
1
ANB
5
nnnn
EORA
nnnn
EORA
0000 DM0000
LDA
$00FF
EORA
DM0001
STA
(DM0000) ($00FF) = (DM0001) U
Exclusive
logical sum
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 EORA $00FF
0004 CON
0005 STA DM0001
1
EORA
1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1
1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1
DM0000
LDA
$00FF
EORA
DM0001
STA
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Contents of DM0000 are
transferred to the internal
register.
Only when the bits of the
internal register and the
operand have different values,
will the exclusive logical sum
be "1".
These values are EORed for each
bit to obtain exclusive OR value.
The result is trans-
ferred to DM0001.
Internal
register
Operand ($00FF)
Internal
register
EOR (Exclusive OR)
truth table
(Result)
:
:
@
#,$
FUN
FUN
SET
1
ANB
5
ENT
R-SRCH
ENT
R-SRCH
Operand
Internal Internal
register register
1 1 0
1 0 1
0 1 1
0 0 0
DM0000 ($F0F0)
($F0F0)
($F00F)
DM0000 ($F00F)
EORA / @EORA
Visual KV KV-300 KV-10/16 KV-24/40/80
0000 to 17915 00000 to 0009 0000 to 2915 0000 to 6915
DM0000 to DM1999 0500 to 17915 DM0000 to DM0999 DM0000 to DM1999
TM00 to TM31 DM0000 to DM9999 TM00 to TM31 TM00 to TM31
#00000 to #65535 TM00 to TM31 #00000 to #65535 #00000 to #65535
$0000 to $FFFF #00000 to #65535 $0000 to $FFFF $0000 to $FFFF
#TM00 to #TM29 $0000 to $FFFF #TM00 to #TM29 #TM00 to #TM29
#TM00 to #TM29
Operand
2.4 Instruction Details
1
2
3-165
Chapter 2 Instructions
Arithmetic flag
2009 No change
2010 Turns ON when the internal register is "0" after an EORA operation. Turns
OFF at other times.
2011 No change
2012 The DM or relay indirectly addressed with #TM is out of range.
"Indirect addressing" (p. 3-127)
Tips
Turning output 0500 ON when inputs 0000 through 0015 have the same value as a
constant ($0F0F)
When the values match, special internal relay 2010 turns ON and output relay 0500
turns ON.
In this example, the constant is "$0F0F", or "0000 1111 0000 1111". Therefore,
output relay 0500 turns ON when input relays 0000 through 0003 and 0008 through
0011 are ON.
Application of EORA instruction
I Judgment of matching data
Turns ON 0500 when the ON/OFF statuses of input relays 0100 to 0107 match the
DM0000 setting value.
Coding
When 2010 is ON, the two values match.
When 2010 is OFF, the two values do not match.
2002 2010 0500 $0F0F
EORA
0000
LDA
STA
$00AA DM0000
LDA
$00FF
ANDA
0100
LDA
DM0000
EORA
2008
2002 2010 0500
1
ANDA
0100 to 0115 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 0 1 1 1 0 1 1
0 DM0000 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0
0
$BBBB
$00FF
$00BB
$00AA
$0011 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1
EORA
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Operand
Internal register
Internal register 2010 is OFF. When the
value of internal register is 0000, 2010 turns ON.
Judges match between the operand and the
data of 0100 to 0107.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0007 ANDA $00FF
0001 LDA $00AA 0008 CON
0002 CON 0009 EORA DM0000
0003 STA DM0000 0010 CON
0004 LD 2002 0011 AND 2010
0005 LDA 0100 0012 OUT 0500
0006 CON
EORA / @EORA
2.4 Instruction Details
3-166
2
Chapter 2 Instructions
Example
Coding
Operands
#01 to #16
Key operation
Arithmetic flag
2009 Turns ON when "1" enters 2009 after an SRA/SLA operation. Turns OFF at
other times.
2010 Turns ON when the internal register is "0" after an SRA/SLA operation.
Turns OFF at other times.
2011 No change
2012 No change
SRA: Shift Right A
@SRA: Shift Right A
SLA: Shift Left A
@SLA: Shift Left A
Moves contents of internal register
serially right by value specified by oper-
and.
Moves contents of internal register
serially left by value specified by operand.
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LDB
4
LDB
4
SET
1
RES
0
LDB
4
LDB
4
SET
1
RES
0
#dd
SRA
#dd
SRA
#dd
SLA
#dd
SLA
0000 DM0000
LDA
#05
SRA
DM0001
STA
0001 DM0010
LDA
#10
SLA
DM0011
STA
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 SRA #05
0004 CON
0005 STA DM0001
0006 LD 0001
0007 LDA DM0010
0008 CON
0009 SLA #10
0010 CON
0011 STA DM0011
:
:
:
:
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LDB
4
LDB
4
SET
1
RES
0
ENT
R-SRCH
ENT
R-SRCH
Operand
ENT
R-SRCH
ENT
R-SRCH
Operand
SRA / @SRA / SLA / @SLA
2.4 Instruction Details
1
2
3-167
Chapter 2 Instructions
Description
Operations using the SRA instruction
When input relay 0000 is ON, the contents of DM0000 are transferred to the internal
register and shifted serially right by the operand value (5). The operation result is
written into DM0001. The contents of D0 are shifted to carry bit 2009.
In the above example, the contents shift to the right by the operand value (5) every
scan time while input relay 0000 is ON.
Use @SRA, a differentiation type instruction, to execute the instruction only once
when input relay 0000 turns ON.
Operation using the SLA instruction
When input relay 0001 is ON, the contents of DM0000 are transferred to the internal
register and shifted serially left by the operand value (10). The operation result is
written into DM0011. The contents of D15 are shifted to carry bit 2009.
In the above example, the contents shift to the left by the operand value (10) every
scan time while input relay 0001 is ON.
Use @SLA, a differentiation type instruction, to execute the instruction only once
when input relay 0001 turns ON.
Note: Special utility relay 2009 may turn ON in accordance with the operation
results; however, it changes immediately when another operation is executed.
Carry
1 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0
0
2009
0 0 0 0 0 1 1 0 0 1 0 0 0 1 1 1 0
2009
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Carry
1 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0
0
2009
1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 1
2009
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Carry
Carry
SRA / @SRA / SLA / @SLA
2.4 Instruction Details
3-168
2
Chapter 2 Instructions
Application of SRA/SLA instructions
I Fetching four-digit data of the BCD digital switch (inputs 0004 through 0011
for low-order 2 digits and 0100 through 0107 for high-order 2 digits) to
transfer them as a counter setting value
I Separate input of BCD
Fetches only 2 digits of the BCD digital switch (0112 to 0115 for the 1st digit, 0000 to
0003 for the 2nd digit) and sets it as the counter value.
Coding
2002 0000
LDA
$0FF0
ANDA
#04
SRA
DM0000
STA
0100
LDA
$00FF
ANDA
#08
SLA
DM0000
ORA
C004
STA
0001 #09999

C004
0000
Line No. Instruction Operand
0000 LD 0001
0001 C 001 #00099 0000
0002 LD 2002
0003 LDA 0100
0004 CON
0005 ANDA $F000
0006 LD 2002
0007 SRA #12
0008 CON
0009 STA DM0000
0010 LD 2002
0011 LDA 0000
0012 CON
0013 ANDA $000F
0014 LD 2002
0015 SLA #04
0016 CON
0017 ORA DM0000
0018 LD 2002
0019 TBIN
0020 CON
0021 STA C001
0001
STA
#12
SRA
$000F
ANDA
0000
LDA
$F000
DM0000
ANDA
0100
LDA
2002
2002
2002
#00099
C001
0000
DM0000
ORA
#04
SLA
2002
C001
STA TBIN
2002
Converts the data of internal register to BIN data and writes it into
C001.
Sets C001.
Sends the data of 0112 to 0115 to internal register.
Shifts the value of internal register to right by 12 bits and writes it
into DM0000.
Sends the data of 0000 to 0003 to internal register.
Shifts the data of internal register to left by 4 bits, ORs the internal
register data and the data of DM0000, and sends the ORed data to
the internal register.
SRA / @SRA / SLA / @SLA
2.4 Instruction Details
1
2
3-169
Chapter 2 Instructions
Example
Coding
Operands
#01 to #16
Key operation
Arithmetic flag
2009 Turns ON when "1" enters 2009 after an RRA/RLA operation. Turns
OFF at other times.
2010 Turns ON when the internal register is "0" after an RRA/RLA operation.
Turns OFF at other times.
2011, 2012 No change
Description
Operation when using the RRA instruction
When input relay 0000 is ON, the contents of DM0000 are transferred to the internal
register. The contents of the internal register and carry (2009) are rotated clockwise
by the operand value.
In the above example, the contents are rotated clockwise every scan time while
input relay 0000 is ON.
RRA: Rotate Right A
@RRA: Rotate Right A
RLA: Rotate Left A
@RLA: Rotate Left A
Rotates contents of internal register and
carry (2009) clockwise by operand value.
Rotates contents of internal register and
carry (2009) counterclockwise by operand
value.
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LD
7
ANB
5
ORL
3
ORL
3
LD
7
ANB
5
ORL
3
ORL
3
#dd
RRA
#dd
RRA
#dd
RLA
#dd
RLA
0000 DM0000
LDA
#01
RRA
DM0001
STA
0001 DM0010
LDA
#04
RLA
DM0011
STA
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 RRA #01
0004 CON
0005 STA DM0001
0006 LD 0001
0007 LDA DM0010
0008 CON
0009 RLA #04
0010 CON
0011 STA DM0011
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LD
7
ANB
5
ORL
3
ORL
3
ENT
R-SRCH
ENT
R-SRCH
Operand
ENT
R-SRCH
ENT
R-SRCH
Operand
:
:
:
:
RRA / @RRA / RLA / @RLA
2.4 Instruction Details
3-170
2
Chapter 2 Instructions
Writes the TM10 data into DM0000, and then writes
#00000 to TM10.
#01
RRA
2002
2002 2009
TM10
STA
#00000 DM0000 TM10
LDA LDA
TM10
INC
0000
LDA
STA
2002
NEXT
FOR
#00016

Writes the data of 0000 to 0015 into internal register.
Executes FOR-NEXT instruction 16 times.
Shifts the data including carry (2009) to right, and
increments TM10 by 1 when 2009 is ON.
Use @RRA, a differentiation type instruction, to execute the instruction only once
when input relay 0000 turns ON.
Operation using the RLA instruction
When input relay 0001 is ON, the contents of DM0000 are transferred to the internal
register. The contents of the internal register and carry (2009) are rotated counter-
clockwise by the operand value.
In the example above, the contents are rotated counterclockwise every scan time
while input relay 0001 is ON.
Use @RLA, a differentiation type instruction, to execute the instruction only once
when input relay 0001 turns ON.
Note: Special utility relay 2009 may turn ON in accordance with the operation
results; however, it changes immediately when another operation is executed.
Application of RRA/RLA instructions
I Error input count
Writes the number of error detection sensors, which are connected to input relays
(0000 to 0015) and turn ON, into DM0000.
Coding
1 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0 0
2009
0 1 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0
2009
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Carry
Carry
1 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0 0
2009
1 0 0 0 1 1 1 0 0 1 0 0 0 1 1 0 0
2009
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
Carry
Carry
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0009 LD 2002
0001 LDA 0000 0010 LDA TM10
0002 FOR #00016 0011 CON
0003 LD 02002 0012 STA DM0000
0004 RRA #01 0013 CON
0005 CON 0014 LDA #00000
0006 AND 2009 0015 CON
0007 INC TM10 0016 STA TM10
0008 NEXT
SRA / @SRA / SLA / @SLA
2.4 Instruction Details
1
2
3-171
Chapter 2 Instructions
Example
Coding
Description
Each time input relay 0000 turns from OFF to ON, the contents of DM0000 are
transferred to the internal register. The COM instruction inverts the status of each
bit and transfers the result to DM0001.
Special utility relay 2010 turns ON when the result is "0".
The following shows the case when DM0000 is "$5F5F".
Note:
When an every-scan type COM instruction is used, the status of bits are inverted
every scan time while input relay 0000 is ON.
Use @COM, a differentiation type instruction, to execute the instruction only once
when input relay 0000 turns ON, as shown in the example.
Operands
Key operation
Arithmetic flag
2009 No change
2010 Turns ON when the internal register is "0" after a COM operation. Turns
OFF at other times.
2011 No change
2012 No change
COM:
@COM:
Inverts contents of each bit in internal
register. @
#,$
FUN
FUN
RES
0
ANB
5
RES
0
ANB
5
COM
COM
Complement
(Bit inversion)
0000
COM
DM0001
STA
DM0000
LDA
Line No. Instruction Operand
0000 LD 0000
0001 @LDA DM0000
0002 CON
0003 @COM
0004 CON
0005 @STA DM0001
0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1
DM0001
DM0000
= $5F5F
= $A0A0 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
COM instruction Bit inversion
0000 DM0000
LDA COM
DM0001
STA
@
#,$
FUN
FUN
RES
0
ANB
5
ENT
R-SRCH
ENT
R-SRCH
:
:
COM / @COM
2.4 Instruction Details
3-172
2
Chapter 2 Instructions
Example
Coding
Description
Operation using the @INC instruction
Every time input relay 0000 turns ON, "1" is added to the contents of the data
memory specified by the operand. The result is then input back to the same data
memory. (In the above example, "1" is added to the contents of DM0000. DM0000 +
1 DM0000) When the data memory specified by the operand is "#65535", the
result of the addition is "#00000" so that special utility relay 2009 turns ON.
Operation using the @DEC instruction
Every time input relay 0000 turns ON, "1" is subtracted from the contents of the data
memory specified by the operand. The result is then input back to the same data
memory. (In the above example, "1" is subtracted from the contents of DM0001.
DM0001 - 1 DM0001) When the data memory specified by the operand is
"#00001", the result of the subtraction is "#00000" so that special utility relay 2010
turns ON.
When the specified data memory is "00000", the result of the subtraction is "#65535
($FFFF)" so that special utility relay 2009 turns ON.
Operands
INC: Increment Memory
@INC: Increment Memory
DEC: Decrement Memory
@DEC: Decrement Memory
Adds 1 to contents of data memory
specified by operand.
Subtracts 1 from contents of data
memory specified by operand.
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LD
7
SET
1
SET
1
RES
0
LD
7
RES
0
OR
9
OR
9
nnnn
INC
nnnn
INC
nnnn
DEC
nnnn
DEC
0000 DM0000
INC
DM0001
DEC
Line No. Instruction Operand
0000 LD 0000
0001 @INC DM0000
0002 @DEC DM0001
Contents of data memory specified by operand
Contents of data memory specified by operand
1 is subtracted.
Contents of data memory specified by operand
Contents of data memory specified by operand
1 is added.
0 0 1 0
@
0 0 0 1
+
0 0 1 1
0 0 1 1
@
0 0 0 1

0 0 1 0
:
:
:
:
INC instruction
DEC instruction
INC / @INC / DEC / @DEC
Visual KV KV-300 KV-10/16 KV-24/40/80
DM0000 to DM1999 DM0000 to DM9999 DM0000 to DM0999 DM0000 to DM1999
TM00 to TM29 TM00 to TM29 TM00 to TM29 TM00 to TM29
2.4 Instruction Details
1
2
3-173
Chapter 2 Instructions
Key operation
Arithmetic flag
2009 Turns ON when the result is "0" after an INC operation, or when the
result is "$FFFF (#65535)" after DEC operation. Turns OFF at other
times.
2010 Turns ON when the internal register is "0" after an INC or DEC opera-
tion. Turns OFF at other times.
2011, 2012 No change
Note: When an every-scan type INC/DEC instruction is used, INC (+1) or DEC (-1)
instruction is executed every scan time while input relay 0000 is ON.
Use a differentiation type instruction (@INC or @DEC) to execute the instruction
only once when input relay 0000 turns ON, as shown in the example.
Tips
When using DM0000 as an UP/DOWN counter
Performs an UP count (addition) when input relay 0000 turns ON.
Performs a DOWN count (subtraction) when input relay 0001 turns ON.
Applications of INC/DEC instructions
I UP/DOWN count
Performs an UP count when input relay 0000 turns ON.
Performs a DOWN count when input relay 0001 turns ON.
Writes the count value into DM0000.
Reset input relay is 0005.
Coding
0000 DM0000
INC
0001 DM0000
DEC
#00000
LDA
2008
0000
DM0000
STA
0005 #00000
DW
DM0000
INC
0001 DM0000
DEC
DM0000
0000 DM0000
INC
0000 DM0000
INC
Clears DM0000 to #00000 when 0005
turns ON.
Sets #00000 to DM0000 at startup.
Increments DM0000 by 1 at UP edge
of input relay 0000.
Decrements DM0000 by 1 at UP edge
of input relay 0001.
@
#,$
FUN
FUN
@
#,$
FUN
FUN
SET
1
OR
9
LD
7
RES
0
ENT
R-SRCH
ENT
R-SRCH
Operand
ENT
R-SRCH
ENT
R-SRCH
Operand
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0005 @INC DM0000
0001 LDA #00000 0006 LD 0001
0002 CON 0007 @DEC DM0000
0003 STA DM0000 0008 LD 0005
0004 LD 0000 0009 DW #00000 DM0000
INC / @INC / DEC / @DEC
2.4 Instruction Details
3-174
2
Chapter 2 Instructions
I Total count 1
Writes the total count of 4 lines (0000 to 0003) into DM0000.
Reset input relay is 0005.
Coding
I Total count 2
Counts the number of boxes transferred on 5 production lines. Produces output
when the number becomes 100 or more.
#00000
LDA
2008
0000
DM0000
STA
0005 #00000
DW
DM0000
INC
0001 DM0000
INC
0002 DM0000
INC
0003 DM0000
INC
DM0000
Clears DM0000 to #00000 when 0005 turns ON.
Sets #00000 to DM0000 at startup.
Increments DM0000 by 1 at UP edge of input relay 0000.
Increments DM0000 by 1 at UP edge of input relay 0001.
Increments DM0000 by 1 at UP edge of input relay 0002.
Increments DM0000 by 1 at UP edge of input relay 0003.
Line No. Instruction Operand
0000 LD 2008
0001 LDA #00000
0002 CON
0003 STA DM0000
0004 LD 0000
0005 @INC DM0000
0006 LD 0001
0007 @INC DM0000
0008 LD 0002
0009 @INC DM0000
0010 LD 0003
0011 @INC DM0000
0012 LD 0005
0013 DW #00000 DM0000
0000
0005
2002
$0000
DW
DM0000
INC
0001 DM0000
INC
0002 DM0000
INC
0003 DM0000
INC
0004 DM0000
INC
DM0000
0500 2009 #00100 DM0000
CMP LDA
Turns output relay 0500 ON when value
of DM0000 is 100 or more.
Increments DM0000 by 1 at UP edge of
input relay 0000.
Increments DM0000 by 1 at UP edge of
input relay 0001.
Increments DM0000 by 1 at UP edge of
input relay 0002.
Increments DM0000 by 1 at UP edge of
input relay 0003.
Increments DM0000 by 1 at UP edge of
input relay 0004.
Clears DM0000 when input relay 0005
turns ON.
INC / @INC / DEC / @DEC
2.4 Instruction Details
1
2
3-175
Chapter 2 Instructions
Coding
I Programming technique
Two kinds of instructions can be used for the counting operation: a C (counter)
instruction and an INC instruction with data memory.
The following examples show how to program the total count with each instruction.
As the example of the INC instruction shows, using different instructions sometimes
simplifies the program even for the same control.
Simpler programming reduces the time for debugging.
It is convenient to use the CMP instruction for comparator outputs.
I OR instruction
Compare the following two programs.
With program 1), input relays 0000 through 0004 are individually counted even when
they turn ON simultaneously.
With program 2), when some input relays 0000 through 0004 turn ON simulta-
neously, duplicated inputs are ignored.
Use the appropriate program according to your application.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0000 0011 DW #00000 DM0000
0001 @INC DM0000 0012 LD 2002
0002 LD 0001 0013 LDA DM0000
0003 @INC DM0000 0014 CON
0004 LD 0002 0015 CMP #00100
0005 @INC DM0000 0016 CON
0006 LD 0003 0017 ANB 2009
0007 @INC DM0000 0018 OUT 0500
0008 LD 0004 0019 END
0009 @INC DM0000 0020 ENDH
0010 LD 0005
0005 DM0001
STA
C001
LDA
#09999
0000
C001
DM0002
STA
C002
LDA
#09999
0001
C002
DM0003
STA
C003
LDA
#09999
0002
C003
DM0004
STA
C004
LDA
#09999
0003
C004
DM0005
STA
C005
LDA
#09999
0004
C005
DM0000
STA
DM0005
ADD
DM0004
ADD
DM0003
ADD
DM0002
ADD
DM0001
LDA
2002 $0000
DW
0005
0000
0001
0002
0003
0004
DM0000
INC
DM0000
INC
DM0000
INC
DM0000
INC
DM0000
INC
DM0000
Programming with the INC instruction
with data memory
Programming with the C instruction
0000 DM0000
INC
0001 DM0000
INC
0002 DM0000
INC
0003 DM0000
INC
0004 DM0000
INC
0000 DM0000
INC
0001
0002
0003
0004
1) 2)
INC / @INC / DEC / @DEC
2.4 Instruction Details
3-176
2
Chapter 2 Instructions
Example
Coding
Operands
#0 to #3
Key operation
Arithmetic flag
2009, 2010, 2011 No change
2012 Turns ON when no bit is ON after a DMX operation (the result is
"0"). Turns OFF at other times.
MPX:
@MPX:
DMX:
@DMX:
Converts 4-bit data of internal
register into 16-bit data. The 4-bit
data to be converted is specified as
operand.
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LD
7
LD
7
SET
1
ANL
2
SET
1
ANL
2
ANL
2
ANL
2
#n
MPX
#n
MPX
DMX
DMX
Multiplexer
(4-to-16 decoder),
Demultiplexer
(16-to-4 encoder)
0000 0000
LDA
#1
MPX
1000
STA
0001 0100
LDA DMX
DM0000
STA
Line No. Instruction Operand
0000 LD 0000
0001 LDA 0000
0002 CON
0003 MPX #1
0004 CON
0005 STA 1000
0006 LD 0001
0007 LDA 0100
0008 CON
0009 DMX
0010 CON
0011 STA DM0000
@
#,$
FUN
FUN
@
#,$
FUN
FUN
SET
1
OR
9
LD
7
RES
0
ENT
R-SRCH
ENT
R-SRCH
Operand
ENT
R-SRCH
ENT
R-SRCH
Operand
:
:
:
: Converts position of most signifi-
cant bit with 1 in internal register
into 4-bit data.
MPX / @MPX / DMX / @DMX
2.4 Instruction Details
1
2
3-177
Chapter 2 Instructions
Description
Operation with the MPX instruction
When input relay 0000 is ON, the ON/OFF status of input relays 0000 through 0015
is transferred to the internal register. The section of the internal register specified by
the operand (input relays 0004 through 007: 4 bits) is converted into a hexadecimal
number (0 to F). Only the bit at the position specified by the hexadecimal number is
set to "1" and other bits are set to "0". The resulting ON/OFF status is input back to
the internal register, and then output to inputs 1000 to 1015.
In the example, when the value specified by inputs 0004 to 0007 are converted into
"A", internal relay 1010 turns ON.
Operation with the DMX instruction
When input relay 0001 is ON, the ON/OFF status of input relays 0100 through 0115
is sent to the internal register. Within the 16-bit data of the internal register, the
number corresponding to the position of the most significant bit with "1" (0 to F) is
converted into 4-bit data and input back to the internal register. The contents of the
internal register are then transferred to DM0000.
In the example, when input relay 0114 turns ON, "E" is input to DM0000.
The DMX instruction is disabled when all bits in the internal register are OFF. In
such a case, special utility relay 2012 turns ON.
Application of MPX and DMX instructions
I MPX instruction
Connect the one-digit data of a BIN digital switch to input relays 0004 through 0007.
Connect output relays 0500 through 0515 to lamps 0 to 15.
An operator turns on the lamp corresponding to the digital switch using binary
numbers.
When the digital switch shows "8", output 0508 turns ON, therefore, lamp 8 lights.
1 0 1 0
#3 #2 #1
A
#0
0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0
F E D C B A 9 8 7 6 5 4 3 2 1 0
No. represented by the section of the
internal register specified by operand
Operand
Internal register
Internal register
0 to F
0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 0
0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0
F E D C B A 9 8 7 6 5 4 3 2 1 0
The value is converted into a hexadecimal number.
Most significant bit with "1"
Enter the number of the most
significant bit with "1".
2002 0000
LDA
#1
MPX
0500
STA
MPX / @MPX / DMX / @DMX
2.4 Instruction Details
3-178
2
Chapter 2 Instructions
a
d
g
f b
a : 0600 b : 0601 c : 0607
d : 0603 c : 0604 f : 0605
g : 0606
e c
I DMX instruction
Connect sensors 0 to 15 to input relays 0000 through 0015.
Connect output relays 0500 through 0503 to the one-digit data of a BIN indicator.
The sensors which are currently ON are shown by the BIN indicator.
* Assume that several sensors do not turn on simultaneously.
When sensor 8 is ON, the indicator shows "8".
I Output of error input No. in BCD
Outputs the error sensor No. from input relay 0000 to 0015 to output relays 0500 to
0507 in 2-digit BCD.
Coding
I Display of 7-segment LED
Displays the current value of counter C007 to the 7-segment LED.
Outputs from 0600 to 0615.
7-segment configuration
2002 0000
LDA DMX
0500
STA
Line No. Instruction Operand
0000 LD 2002
0001 LDA 0000
0002 CON
0003 DMX
0004 LD 2002
0005 TBCD
0006 CON
0007 ANDA $00FF
0008 CON
0009 STA 0500
0000
LDA
2002
2002
DMX
TBCD
$00FF
ANDA
0500
STA
Converts internal register data to BCD data, executes an
ANDA instruction, and outputs the data to 0500 to 0507.
Converts the most significant bit of 16-bit data (0000 to
0015) to 4-bit BIN data and sends it to internal register.
MPX / @MPX / DMX / @DMX
2.4 Instruction Details
1
2
3-179
Chapter 2 Instructions
C000
LDA
#0
MPX
C000 #00009
C000
0000
1000
STA
$003F
LDA
0600
STA
1000
0
$0006
LDA
0600
STA
1001
1
$005B
LDA
0600
STA
1002
2
$004F
LDA
0600
STA
1003
3
$0066
LDA
0600
STA
1004
4
$006D
LDA
0600
STA
1005
5
$007D
LDA
0600
STA
0600
STA
1006
6
$0007
LDA
1007
7
$007F
LDA
0600
STA
1008
8
$006F
LDA
0600
STA
1009
9
Converts the counter value to 16-bit
data using the MPX instruction.
7-segment display
Auto-reset
counter
Sends internal register data to
output relays starting from 0600.
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB C000 0024 LD 1004
0001 C 000 #00009 0000 0025 LDA $0066
0002 CON 0026 CON
0003 LDA C000 0027 STA 0600
0004 CON 0028 LD 1005
0005 MPX #0 0029 LDA $006D
0006 CON 0030 CON
0007 STA 1000 0031 STA 0600
0008 LD 1000 0032 LD 1006
0009 LDA $003F 0033 LDA $007D
0010 CON 0034 CON
0011 STA 0600 0035 STA 0600
0012 LD 1001 0036 LD 1007
0013 LDA $0006 0037 LDA $0007
0014 CON 0038 CON
0015 STA 0600 0039 STA 0600
0016 LD 1002 0040 LD 1008
0017 LDA $005B 0041 LDA $007F
0018 CON 0042 CON
0019 STA 0600 0043 STA 0600
0020 LD 1003 0044 LD 1009
0021 LDA $004F 0045 LDA $006F
0022 CON 0046 CON
0023 STA 0600 0047 STA 0600
Coding
MPX / @MPX / DMX / @DMX
2.4 Instruction Details
3-180
2
Chapter 2 Instructions
Example
Coding
Operands
Key operation
Arithmetic flag
2009, 2010, 2011 No change
2012 Turns ON when the contents of the internal register are greater
than "$270F (#09999)" before TBCD operation, or when the
contents of the internal register are not BCD data before the
TBIN operation (In these cases, the TBCD or TBIN instruction
will not be executed.). Turns OFF at other times.
TBCD: Transfer BCD
@TBCD: Transfer BCD
TBIN: Transfer BIN
@TBIN: Transfer BIN
Converts contents of internal register
(16-bit binary) into 4-digit BCD data.
Converts contents of internal register
(4-bit binary) into 16-digit BCD data.
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LD
7
LDB
4
LDB
4
AND
8
LD
7
LDB
4
LDB
4
AND
8
TBCD
TBCD
TBIN
TBIN
TBCD
TBIN
0000
0001
DM0000
LDA
DM0001
STA
DM0010
LDA
DM0011
STA
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 @TBCD
0004 CON
0005 @STA DM0001
0006 LD 0001
0007 LDA DM0010
0008 CON
0009 @TBIN
0010 CON
0011 @STA DM0011
@
#,$
FUN
FUN
@
#,$
FUN
FUN
LD
7
LDB
4
LDB
4
AND
8
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
:
:
:
:
TBCD / @TBCD / TBIN / @TBIN
2.4 Instruction Details
1
2
3-181
Chapter 2 Instructions
Description
Operation using the TBCD instruction
When input relay 0000 turns ON, the contents of DM0000 are transferred to the
internal register. The contents of the internal register (16-bit binary data) are con-
verted into 4-digit BCD data, which is input back to the internal register, and then
transferred to DM0001.
Operation using the TBIN instruction
When input relay 0001 turns ON, the contents of DM0010 are transferred to the
internal register. The contents of the internal register (4-digit BCD data) are con-
verted into 16-bit binary data, which is input back to the internal register, and then
transferred to DM0011.
Note 1: The TBCD instruction can only convert data up to "#09999". When the
conversion of data of "#10000" or greater is attempted, special utility relay 2012
turns ON and the conversion is disabled.
Note 2: When the data in the internal register is not BCD data, special utility relay
2012 turns ON and the TBIN instruction is disabled.
Applications of TBCD instruction
I Output of 4-digit BCD data
Outputs the current value of counter C001 to 0700 to 0715 in 4-digit BCD data.
Coding
Data is converted into BCD of "0" through "9999".
Data is converted into binary number of "0" through "9999".
10
3
(0)
10
2
(0)
10
1
(2)
10
0
(4)
0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0
2
16
2
0
0 0 0 0 0 0 0 0 0 0 1 0 0 1 0 0
8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1
(5)
10
3
(5)

10
2
(5)
10
1
(5)
10
0
0 0 0 1 0 1 0 1 1 0 1 1 0 0 1 1
0 1 0 1 0 0 0 1 0 1 0 1 0 1 0 1
8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
0001
2002 C001
LDA
0700
STA TBCD
#09999

C001
0000
Converts current value of C001 into BCD data,
and outputs it to 0700 to 0715.
Sets C001.
Line No. Instruction Operand
0000 LDB 0001
0001 C 001 #00009 0000
0002 LD 2002
0003 LDA C001
0004 CON
0005 TBCD
0006 CON
0007 STA 0700
TBCD / @TBCD / TBIN / @TBIN
2.4 Instruction Details
3-182
2
Chapter 2 Instructions
0400
LDA
C001
STA
2002
0001
TBIN
#09999
C001
0000
Line No. Instruction Operand
0000 LD 2002
0001 LDA 0400
0002 CON
0003 TBIN
0004 CON
0005 STA C001
0006 LDB 0001
0007 C 001 #09999 0000
Converts data of 0400 to 0415 to BIN data and writes
into C001.
Sets C001
I Output of 8-digit BCD data
Outputs the calculated product of DM0000 x DM0001 (0 to 99999999) in BCD of 8
digits at maximum as below:
High-order 4-digit BCD data To 0600 to 0615
Low-order 4-digit BCD data To 0500 to 0515
Coding
Application of TBIN instruction
I Input of 4-digit BCD data
Sets 4 digits of the BCD digital switch (0400 to 0415) as the counter C001 value.
Coding
DM0000
LDA
DM0001
MUL
DM0101
STA
#10000
DIV
TM01
LDA TBCD
0500
STA
2002
DM0101
LDA TBCD
0600
STA
TM00 DM0000 x DM0001 =
TM00
0600 to 0615 0500 to 0515
... TM01
#10000
=
Display
Internal register
High-order 4 digits Low-order 4 digits
High-order 4 digits
Internal register
Internal register
TM00
Low-order 4 digits Remainder
High-order 4 digits Low-order 4 digits
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0010 CON
0001 LDA DM0000 0011 TBCD
0002 CON 0012 CON
0003 MUL DM0001 0013 STA 0500
0004 CON 0014 CON
0005 DIV #10000 0015 LDA DM0101
0006 CON 0016 CON
0007 STA DM0101 0017 TBCD
0008 CON 0018 CON
0009 LDA TM01 0019 STA 0600
TBCD / @TBCD / TBIN / @TBIN
2.4 Instruction Details
1
2
3-183
Chapter 2 Instructions
Example
Coding
Operands
Key operation
Arithmetic flag
2009, 2010, 2011 No change
2012 Turns ON when the high- and low-order 8-bit value is not within
the range of "$30" to "$39" and "$41" to "$46", respectively,
before the RASC instruction is executed (In this case, the RASC
instruction will not be executed.). Turns OFF at other times.
ASC: ASCII Convert
@ASC: ASCII Convert
RASC: Reverse ASCII Convert
@RASC: Reverse ASCII Convert
Converts contents of lower order byte
of internal register into 2-digit ASCII
code.
Converts 2-digit ASCII into byte data
representing 2-digit hex number.
@
#,$
FUN
FUN
ORL
3
ORL
3
@
#,$
FUN
FUN
RES
0
ANL
2
ANL
2
ANL
2
RES
0
ANL
2
ASC
ASC
RASC
RASC
ASC
RASC
0000
0001
DM0000
LDA
DM0001
STA
DM0010
LDA
DM0011
STA
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 @ASC
0004 CON
0005 @STA DM0001
0006 LD 0001
0007 LDA DM0010
0008 CON
0009 @RASC
0010 CON
0011 @STA DM0011
ORL
3
@
#,$
FUN
FUN
@
#,$
FUN
FUN
RES
0
ANL
2
ANL
2
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ASC / @ASC / RASC / @RASC
:
:
:
:
2.4 Instruction Details
3-184
2
Chapter 2 Instructions
Hex number Bit configuration Code Bit configuration
0 0 0 0 0 $30 0 0 1 1 0 0 0 0
1 0 0 0 1 $31 0 0 1 1 0 0 0 1
2 0 0 1 0 $32 0 0 1 1 0 0 1 0
3 0 0 1 1 $33 0 0 1 1 0 0 1 1
4 0 1 0 0 $34 0 0 1 1 0 1 0 0
5 0 1 0 1 $35 0 0 1 1 0 1 0 1
6 0 1 1 0 $36 0 0 1 1 0 1 1 0
7 0 1 1 1 $37 0 0 1 1 0 1 1 1
8 1 0 0 0 $38 0 0 1 1 1 0 0 0
9 1 0 0 1 $39 0 0 1 1 1 0 0 1
A 1 0 1 0 $41 0 1 0 0 0 0 0 1
B 1 0 1 1 $42 0 1 0 0 0 0 1 0
C 1 1 0 0 $43 0 1 0 0 0 0 1 1
D 1 1 0 1 $44 0 1 0 0 0 1 0 0
E 1 1 1 0 $45 0 1 0 0 0 1 0 1
F 1 1 1 1 $46 0 1 0 0 0 1 1 0
Description
Operation using the ASC instruction
When input relay 0000 turns ON, the contents of DM0000 are transferred to the
internal register. The contents of the internal register (low-order 8-bit, 2-digit numeri-
cal value) are converted into 2-digit ASCII code. This 2-digit code is input back to the
internal register, and then transferred to DM0001.
Operation using the RASC instruction
When input relay 0001 turns ON, the contents of DM0010 are transferred to the
internal register. The contents of the internal register (2-digit ASCII code) is con-
verted into a low-order 8-bit, 2-digit numeric value. This 2-digit numeric value is input
back to the internal register, then transferred to DM0011..
The value is converted only when the high- and low-order 8-bit value of the internal
register is within the range of "$30" to "$39" and "$41" to "$46", respectively, before
the conversion. (When either of the high- or low-order 8-bit value is not within the
range, the conversion is disabled. In this case, special utility relay 2012 turns ON.)
Example of conversion between hex and ASCII numbers
1 0 1 0 0 1 0 1
0 1 0 0 0 0 0 1 0 0 1 1 0 1
4 1 3 5
A 5
0 1
0 0 0 0 0 0 0 0 0 1 1 0 1 1
4 3 3 6
6 C
0 0
0 0 1 1 0 1 1 0 0 1 0 0 0 0 1 1
ASC / @ASC / RASC / @RASC
2.4 Instruction Details
1
2
3-185
Chapter 2 Instructions
Example
Coding
Description
The ROOT instruction takes the square root of 32-bit data (binary number) of
which the high-order 16 bits are contained in DM0001 and low-order 16 bits are
contained in DM0000, and then input the result to DM0100.
The figures to the right the decimal point of the obtained square root are omitted,
and the result is input back to the same register.
When the result is 0, special utility relay No. 2010 turns ON.
The ROOT instruction takes the square root of a 32-bit numerical value. In this
case, the high-order 16 bits are contained in TM00, and the low-order 16 bits are
contained in the internal register.
Operands
Key operation
ROOT: Square Root
@ROOT: Square Root
Takes square root of 32-bit data (TM00:
higher order byte, internal register: lower
order byte), and inputs result back to same
register.
ROOT
ROOT
ORB
6
ORL
3
ORB
6
ORL
3
@
#,$
FUN
FUN
ROOT
0000 TM00
STA
DM0001
LDA
DM0000
LDA
DM0100
STA
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0001
0002 CON
0003 STA TM00
0004 CON
0005 LDA DM0000
0006 CON
0007 ROOT
0008 CON
0009 STA DM0100
T M 0 0 Internal register Internal register
Higher order 16 bits Lower order 16 bits
ORL
3
ORB
6
@
#,$
FUN
FUN
ENT
R-SRCH
ENT
R-SRCH
:
:
ROOT / @ROOT
2.4 Instruction Details
3-186
2
Chapter 2 Instructions
Change in status of special utility relays (arithmetic flags) by arithmetic
instructions (1/3)
Instruction Mnemonic Operand A < 0 A = 0 A > 0 Error
2009 2010 2011 2012
DATA
MEMORY DW $,# constant
WRITE
3-136
Relay No. 5
LOAD A LDA Timer/counter No. 5
3-140 [FUN23] Data memory No. 5
$,# constant 5
# TM 5 H
Relay No.
STORE A STA Timer/counter No.
3-140 [FUN42] Data memory No.
# TM H
COMPARE
CMP
Data memory No. 1 2 3
3-146
[FUN04]
$,# constant 1 2 3
# TM 1 2 3 H
ADD
ADD
Data memory No. 4 5
3-150
[FUN00]
$,# constant 4 5
# TM 4 5 H
SUBTRACT
SUB
Data memory No. 6 5 7
3-150
[FUN46]
$,# constant 6 5 7
# TM 6 5 7 H
MULTIPLY
MUL
Data memory No. I 8
3-150
[FUN28]
$,# constant I 8
# TM I 8 H
DIVIDE
DIV
Data memory No. 8 9
3-150
[FUN11]
$,# constant 8 9
# TM 8 H9
AND A
ANDA
Data memory No. 5
3-159
[FUN01]
$,# constant 5
# TM 5 H
: No change in arithmetic flag
Refer to the description of each instruction for details of the operating conditions of the flag.
2.4 Instruction Details
1
2
3-187
Chapter 2 Instructions
Change in status of special utility relays (arithmetic flags) by arithmetic
instructions (2/3)
Instruction Mnemonic Operand A < 0 A = 0 A > 0 Error
2009 2010 2011 2012
OR A
ORA
Data memory No. 5
3-161
[FUN31]
$,# constant 5
# TM 5 H
EXCLUSIVE
EORA
Data memory No. 5
OR A
[FUN15]
$,# constant 5
3-164 # TM 5 H
SHIFT
SRA
Number of shifts 0 5
RIGHT A
[FUN41]
3-166
SHIFT
SLA
Number of shift 0 5
LEFT A
[FUN40]
3-166
ROTATE
RRA
Number of rotations 0 5
RIGHT A
[FUN37]
3-169
ROTATE
RLA
Number of rotations 0 5
LEFT A
[FUN40]
3-169
COMPLE-
COM
5
MENT
[FUN05]
3-171
INCREMENT
INC
Data memory No. A 5
MEMORY
[FUN19]
3-172
DECRE-
MENT DEC Data memory No. B 5
MEMORY [FUN07]
3-172
MULTI-
MPX
Digit No.
PLEXER
[FUN27]
3-176
DEMULTI-
DMX
C
PLEXER
[FUN12]
3-176
TRANSFER
TBCD
D
BCD
[FUN47]
3-180
TRANSFER
TBIN
E
BIN
[FUN48]
3-180
ASCII
ASC

CONVERT
[FUN02]
3-183
REVERSE
ASCII RASC F
CONVERT [FUN32]
3-183
SQUARE
ROOT
5
ROOT
[FUN36]
3-185
TRIMMER
TMIN
G
SETTING
[FUN50]
3-138
: No change in arithmetic flag
Refer to the description of each instruction for details of the operating conditions of the flag.
2.4 Instruction Details
3-188
2
Chapter 2 Instructions
Change in status of special utility relays (arithmetic flags) by arithmetic
instructions (3/3)
1 When the result of COMPARE is negative, the relay turns ON. When the result is
not negative, the relay remains OFF.
2 When the result of COMPARE is "0", the relay turns ON. When the result is not
"0", the relay remains OFF.
3 When the result of COMPARE is positive, the relay turns ON. When the result is
not positive, the relay remains OFF.
4 When the result of the arithmetic operation exceeds the 16-bit range ($FFFF),
the relay turns ON. When the result is within the 16-bit range, the relay remains
OFF.
5 When, as a result of the arithmetic operation, the data in the internal register is
"0", the relay turns ON. When the data is not "0", the relay remains OFF.
6 When the result of the arithmetic operation is negative, the relay turns ON.
When the result is not negative, the relay remains OFF.
7 When the result of the arithmetic operation is positive, the relay turns ON.
When the result is not positive, the relay remains OFF.
8 When, as a result of the arithmetic operation, all of the 32 bits are "0", the relay
turns ON. When any of them is not "0", the relay remains OFF.
9 When the divisor is "0", in the division, the relay turns ON. In this case, DIVIDE is
not executed.
0 When, as a result of SHIFT or ROTATE, "1" is entered into 2009, it turns ON.
When "1" is not entered, it remains OFF.
A When as a result of INCREMENT MEMORY, the data of the data memory is "0",
the relay turns ON. When the data is not "0", the relay remains OFF.
B When as a result of DECREMENT MEMORY, the data of the data memory
EXCEEDS 16 BIT RANGE ($FFFF), the relay turns ON. When the data is within
the 16-bit range, the relay remains OFF.
C When there is no "ON" bit in the internal register at execution of
DEMULTIPLEXER, the relay turns ON. (In this case, "0" is entered in the internal
register.) When there is a "ON" bit(s), the relay remains OFF.
D When the data in the internal register exceeds $270F (#09999) at execution of
TRANSFER BCD, the relay turns ON. (In this case, TRANSFER BCD is not
executed.) When the data does not exceed $270F, the relay remains OFF.
E When the data in the internal register is not BCD data at execution of TRANS-
FER BIN, the relay turns ON. (In this case, TRANSFER BIN is not executed.)
When the data is BCD, the relay remains OFF.
F When the higher-order byte or lower-order byte in the internal register is respec-
tively not within the range of $30 through $39, or the range of $41 through $46 at
execution of REVERSE ASCII CONVERT, the relay turns ON. (In this case,
REVERSE ASCII CONVERT is not executed.)
When the value is within the range, the relay remains OFF.
G When the input value for TRIMMER SETTING is "0", the relay turns ON.
When the value is not "0", the relay remains OFF.
H During indirect addressing, there is no data memory or relay by the number
specified by "TMxx".
I When the result of the arithmetic operation exceeds the 16-bit range, the relay
turns ON. When the result is within the 16-bit range, the relay remains OFF.
2.5 Programming Notes
1
2
3-189
Chapter 2 Instructions
2.5 Programming Notes
This section describes important points and precautions for creating ladder pro-
grams.
Circuits that must be modified
1. The circuit shown below left cannot be programmed. Modify it as shown on the
right.
2. Output is disabled in 0500 in the circuit shown below left. By modifying it as
shown on the right, output of one scan only is disabled.
3. If the same coil is used in two positions, the latter position has priority and the
coil in the former position is ignored.
4. The circuit shown below left cannot be programmed. Modify it as shown on the
right.
5. The circuit shown below left cannot be programmed. Modify it as shown on the
right.
C D
A B 0500
E
A E
C E 0500
A
D
B
C
1000
A 1000
0500
A 1000 0500
A 1000
E
A
C
B 0500
0500
A B 0500
C E
A B C
D E
F
0500 B C
D E
A
E
0500
F
A B 0500
0501
C D
E
C D
E
A
B 0500
0501 C
2.5 Programming Notes
3-190
2
Chapter 2 Instructions
0500
2002
#0010
T000
0500
#0010
T000
A B D E E 0500
C
A B
0500
C
D
B C 0500
0501
A
B C
0500
A
A B D 0500
D 0501
Programming precautions
1. A coil output or timer/counter cannot be connected directly from a bus. When an
output coil or a timer/counter is required, insert a 'b' contact of an unused internal
utility relay, a 'b' contact of an unused special utility relay, or a special utility relay
2002 (always ON) as a dummy.
2. A contact cannot be connected to an output line.
3. Make sure that every contact/coil is located on a path from a bus to an output
line. Make sure that there are no unconnected portions.
4. Make sure that illegal short-circuits are not generated in parallel connections.
5. Circuits including output coils cannot be connected in parallel.
However, parallel connection is enabled when each circuit in parallel connection
is connected to an output line.
6 . When the following program is entered with the programming support software
and sent to the KV, and then read from the KV with the software, reading is
disabled due to a "Reverse Compilation Error".
When a return is included in parallel connection in a ladder program, a
decompilation (reverse compilation) error is generated as shown below.
To prevent this error, change the ladder diagram to eliminate the return, or
separate the parallel connection.

Вам также может понравиться