You are on page 1of 392

Visual KV Series

96M0366
INDEX

1 2 3
Installation Support Programming
1. Configuration and Software 1. Programming

3
Specifications 1. Introduction 2. Instructions
User’s Manual

Programming
2. System Installation
2. Editor 3. Interrupts
3. Access Window
3. Simulator 4. High-speed Counters
4. KV-D20 Operator
Interface Panel 4. Monitor 5. Positioning Control Visual KV Series
5. Appendices 6. Interrupts, High-speed
5. KV-10/80 Hardware
Counters, Positioning
6. Handheld Program-
mer
Control 3
7. Serial Communication

Programming

User’s Manual
7. KV-L2 Serial Interface
8. Programming
Module
Examples
8. KV-AN6 Analog I/O
Module
9. KV-AD4/DA4 Analog
I/O Unit
10. Troubleshooting
11. Appendices

Specifications are subject to change without notice.

KEYENCE CORPORATION
1-3-14, Higashi-Nakajima, Higashi-Yodogawa-ku, Osaka, 533-8555, Japan PHONE: +81-6-6379-2211

AUSTRIA GERMANY MALAYSIA SWITZERLAND


Phone: +43-2236-378266-0 Phone: +49-6102-36 89-0 Phone: +60-3-2092-2211 Phone: +41 43 455 77 30
BELGIUM HONG KONG MEXICO TAIWAN
Phone: +32 2 716 40 63 Phone: +852-3104-1010 Phone: +52-81-8220-7900 Phone: +886-2-2718-8700
CANADA HUNGARY NETHERLANDS THAILAND
Phone: +1-905-696-9970 Phone: +36 14 748 313 Phone: +31 40 20 66 100 Phone: +66-2-369-2777 How this manual is organized:
CHINA ITALY POLAND UK & IRELAND The Visual KV Series User’s Manual is composed of 3 separate
Phone: +86-21-68757500 Phone: +39-2-6688220 Phone: +48 71 36861 60 Phone: +44-1908-696900
manuals; 1-Installation, 2-Support Software, 3-Programming.
CZECH REPUBLIC JAPAN SINGAPORE USA
Phone: +420 222 191 483 Phone: +81-6-6379-2211 Phone: +65-6392-1011 Phone: +1-201-930-0100 Please read each manual relevant to your purpose.
FRANCE KOREA SLOVAKIA
Phone: +33 1 56 37 78 00 Phone: +82-31-642-1270 Phone: +421 2 5939 6461
A5WW1-MAN-0069

Copyright (c) 1999 KEYENCE CORPORATION. All rights reserved.


084024E-3 0109-5 96M0366 Printed in Japan
Safety Precautions WARRANTIES AND DISCLAIMERS:
This instruction manual describes the operation and function of the KV Series PLC. (1) KEYENCE warrants the Products to be free of defects in materials and workmanship for a period of
Read this manual carefully to ensure safe use and maximum performance from your one (1) year from the date of shipment. If any models or samples were shown to Buyer, such models or
KV Series PLC. samples were used merely to illustrate the general type and quality of the Products and not to represent
that the Products would necessarily conform to said models or samples. Any Products found to be defec-
tive must be shipped to KEYENCE with all shipping costs paid by Buyer or offered to KEYENCE for in-
Symbols spection and examination. Upon examination by KEYENCE, KEYENCE, at its sole option, will refund the
purchase price of, or repair or replace at no charge any Products found to be defective. This warranty
The following symbols alert you to important messages. Be sure to read these does not apply to any defects resulting from any action of Buyer, including but not limited to improper
messages carefully. installation, improper interfacing, improper repair, unauthorized modification, misapplication and mishan-
dling, such as exposure to excessive current, heat, coldness, moisture, vibration or outdoors air. Compo-
Failure to follow instructions may lead to injury. (electric nents which wear are not warranted.
WARNING shock, burn, etc.)
(2) KEYENCE is pleased to offer suggestions on the use of its various Products. They are only sugges-
tions, and it is Buyer’s responsibility to ascertain the fitness of the Products for Buyer’s intended use.
KEYENCE will not be responsible for any damages that may result from the use of the Products.
Failure to follow instructions may lead to product damage. (3) The Products and any samples (“Products/Samples”) supplied to Buyer are not to be used internally
CAUTION
in humans, for human transportation, as safety devices or fail-safe systems, unless their written specifica-
tions state otherwise. Should any Products/Samples be used in such a manner or misused in any way,
Note: Provides additional information on proper operation. KEYENCE assumes no responsibility, and additionally Buyer will indemnify KEYENCE and hold
KEYENCE harmless from any liability or damage whatsoever arising out of any misuse of the Products/
Samples.
Conventions (4) OTHER THAN AS STATED HEREIN, THE PRODUCTS/SAMPLES ARE PROVIDED WITH NO
OTHER WARRANTIES WHATSOEVER. ALL EXPRESS, IMPLIED, AND STATUTORY WARRANTIES,
This manual describes the operation/function of all Keyence KV Series PLC.
INCLUDING, WITHOUT LIMITATION, THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
Note following conventions when you use.
PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF PROPRIETARY RIGHTS, ARE EXPRESSLY
Visual KV (Series) KV-10AR/AT/DR/DT KV-16AR/AT/DR/DT DISCLAIMED. IN NO EVENT SHALL KEYENCE AND ITS AFFILIATED ENTITIES BE LIABLE TO ANY
KV-10xx, 16xx, 24xx, 40xx KV-24AR/AT/DR/DT KV-40AR/AT/DR/DT PERSON OR ENTITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, PUNITIVE, SPECIAL OR CONSE-
Conventional KV (Series) KV-10R(W)/T(W) KV-16R(W)/T(W) QUENTIAL DAMAGES (INCLUDING, WITHOUT LIMITATION, ANY DAMAGES RESULTING FROM
KV-300 (Series) KV-24R(W)/T(W) KV-40R(W)/T(W) LOSS OF USE, BUSINESS INTERRUPTION, LOSS OF INFORMATION, LOSS OR INACCURACY OF
KV-10/80 (Series) KV-80R(W)/T(W) DATA, LOSS OF PROFITS, LOSS OF SAVINGS, THE COST OF PROCUREMENT OF SUBSTITUTED
KV-300 GOODS, SERVICES OR TECHNOLOGIES, OR FOR ANY MATTER ARISING OUT OF OR IN CONNEC-
TION WITH THE USE OR INABILITY TO USE THE PRODUCTS, EVEN IF KEYENCE OR ONE OF ITS
AFFILIATED ENTITIES WAS ADVISED OF A POSSIBLE THIRD PARTY’S CLAIM FOR DAMAGES OR
General Precautions ANY OTHER CLAIM AGAINST BUYER. In some jurisdictions, some of the foregoing warranty disclaimers
• At startup and during operation, be sure to monitor the functions and perfor- or damage limitations may not apply.
mance of the KV Sereis PLC.
BUYER’S TRANSFER OBLIGATIONS: If the Products/Samples purchased by Buyer are to be resold or
• We recommend that you take substantial safety measures to avoid any damage delivered to a third party, Buyer must provide such third party with a copy of this document, all specifica-
in the event a problem occurs. tions, manuals, catalogs, leaflets and written information provided to Buyer pertaining to the Products/
Samples.
• Do not open or modify the KV Series PLC or use it in any way other than de-
scribed in the specifications.

• When the KV Series PLC is used in combination with other instruments, func-
tions and performance may be degraded, depending on operating conditions and
the surrounding environment.

• Do not use the KV Series PLC for the purpose of protecting the human body.

Note: The built-in display may show the error message "Error 40" blinking the very
first time you turn on the power supply to the Visual KV Series. Press any key
around the display to cancel this message.
The Visual KV Series shows this message when no program is loaded.

(1) 3-367
Note to User
When using the Visual KV Series in the following conditions or environments, be
sure to use the Visual KV Series with sufficient margin regarding the rating and
functions, take appropriate safety precautions such as fail-safe, and contact our
sales personnel if any questions arise.
• Use in conditions or environments not described in this manual
• Use for nuclear power control, railway facilities, air service facilities, vehicles,
combustion devices, medical equipment, amusement machines, safety equip-
ment, etc.
• Use for applications where large effects are predicted to be given on human lives
and properties and safety is especially requested.

Restriction on Acquiring the CE Marking


■ Restriction to be compatible with EMC directives
• When using a relay output type unit (whose model name ends with "R"), connect
spark killers having the appropriate withstand voltage against the load to the
output terminals in parallel to contacts (because the unit discharges when a relay
contact becomes open and noise is generated). In our experiments, we use the
following models of spark killers.
XEB0101 0.1 µF-10 Ω manufactured by OKAYA DENKI SANGYO
The following 1-turn ferrite core is added to the AC power input circuit of the KV-
40AR/T, the KV-24AR/T and to the DC power input circuit of the KV-40DR/T.
ZCAT3035-1330 manufactured by TDK

Note: The contents above do not by themselves ensure that the entire machine
manufactured in accordance with the above contents is compatible with EMC
directives.
You must judge by yourself whether or not the entire machine is compatible with
EMC directives because compatibility may change depending on the component
configuration, wiring and location inside of the machine.

■ Restriction on compatibility with low-voltage directives (IEC-1010-1)


• Use insulated type crimp-style terminals.
• For wiring materials, use lead wires whose sheath is 0.4 mm or more.
• The Visual KV Series is allowed to be installed in a vertical position only.
(Spacers for expansion units are not available.)
• Be sure to use the Visual KV Series inside the control panel.

96M0366
(2)

KVNKA Front_Pro.p65 3 09.10.9, 21:29


Features of the Visual KV Series
● Extremely small
The Visual KV Series is the smallest in the world among AC type PLCs equipped
with screw terminal blocks, and saves installation space.

● Extremely fast
The minimum scan time is 140 µs and minimum instruction execution time is 0.7
µs, which is the fastest control in its class.

● AC power built-in type newly added


AC power built-in type units are newly added. This type can be used in small
spaces where a switching power supply unit cannot be installed.

● Excellent Access Window


An Access Window with two-color backlight is adopted in all models to facilitate
changing and monitoring of device data. Changing between RUN mode and
PROGRAM mode, checking the error code when an error has occurred, etc. can
be performed in a Visual KV Series unit without the need for any handheld
programmer.
The analog trimmer, which has been popular in the conventional KV Series, is
digitized to enable more detail settings. [Digital trimmers]

● User message setting function


In the Access Window, 256 different user messages can be displayed. This
function can be used to give instructions on works on the production line, indicate
abnormalities in the units, etc.

● Program write in RUN mode


Ladder programs can be changed even while the system is running.

● Equipped with two serial ports


Visual KV Series basic units are equipped with two serial ports to connect periph-
eral units, improving the debug environment.
(The KV-10xx is equipped with only one serial port.)

● Easy Ramp-up/down control function


The one-axis motor control function is offered separately from high-speed
counters so that feedback control is enabled.

● Equipped with two 24-bit high-speed 30 kHz, two-phase counters


The Visual KV Series is equipped with two high-speed counters each with a two-
point comparator output function that enables high-speed encoder input.

● Specified frequency pulse output function


High-speed counters can function as pulse oscillators of 50 kHz maximum with
easy setting, without creating a complicated ladder program.

● Frequency counter function


High-speed counters can function as frequency counters with easy setting,
without creating complicated ladder programs.

● Cam switch function


High-speed counters can function as cam switches with easy setting, without
creating complicated ladder programs.

(3)

KVNKA Front_Pro.p65 4 08.3.11, 0:13 PM


● Interrupt function
The Visual KV Series is equipped with four high-speed interrupt inputs of
10 µs maximum.

● Input time constant change function


The time constant can be set in 7 steps from 10 µs to 10 ms.

● Double memory backup functions


In addition to a conventional SRAM battery backup function, the Visual KV Series
is also equipped with an EEPROM backup function.

Compatibility with Conventional KV Series Peripheral Units


The Visual KV Series functions as a high-end compatible model of the conventional
KV Series. Peripheral units of the conventional KV Series such as the ladder support
software "KV IncrediWare (DOS)" and "LADDER BUILDER for KV" and the
handheld programmer KV-P3E(01) can be used since they are part of the Visual KV
Series.
However, it should be noted that the contents have changed as follows.

• The internal clock cycle of high-speed counters consists of three types: 1 µs, 10
µs, and 100 µs.
• The time constant for an input relay specified by the HSP instruction is 10 µs.
• The analog trimmer function is set with the Access Window built into the basic
unit.
• The available device setting range of the TMIN instruction is from 0 to 65535.
[Handheld programmer KV-P3E(01) can display 0 to 9999 .]
• The RUN/PROGRAM LED is displayed in the Access Window provided on the
front face of the basic unit.
• Transistor output is not independent, but is common.
• With the transistor type, the output terminal layout is different.
• The specifications for output current of transistor outputs Nos. 500 to 502 is 100
mA.
• Conventional KV Series expansion units are not available as expansion units for
the Visual KV Series.
• The channel setting switch is not provided for expansion units. Channels are
determined in connection order.
• Scans in expansion I/O units are not synchronous with the scan time in Visual KV
Series basic units.
• Assignment of special utility relays has partially changed.
• Data memory device Nos. DM1000 to DM1999 are assigned as special data
memories.

(4)

KVNKA Front_Pro.p65 5 08.3.11, 0:13 PM


Cautions when using the previous version of ladder support software
Pay strict attention to the following items when using the ladder support software.
• When using the ladder support software "KV IncrediWare (DOS)" or "LADDER
BUILDER for KV Ver. 1.0x", set the model to "KV-300".
• DM0 to DM1999 are only available.

When the ladder support software "LADDER BUILDER for KV Ver. 1.0x" is
CAUTION used, do not use the monitor’s Change All function. If the Change All function
is used, the basic unit may be damaged. Never use the Change All function.

Peripheral units and other units incompatible with the Visual KV Series
Peripheral units in the conventional KV Series and other units shown below are not
compatible with the Visual KV Series.
• Expansion I/O units for the conventional KV Series: KV-8ER/8ET/8EX/16EX/
8EYR/8EYT/16EYR/16EYT
• Analog I/O units for the conventional KV Series: KV-AD4/DA4

Cautions when Using the Serial Port


The KV-16xx/24xx/40xx units are equipped with two RJ-11 modular connectors for
serial communication.
When using them, pay strict attention to the following contents:

• Programs can be transferred and monitored using either communication port A or


B. However, never connect the ladder software and a handheld programmer to
the two ports at the same time.
• The KV-D20 operator interface panel can be connected to either communication
port A or B. However, only one KV-D20 unit can be connected to a single basic
unit.
• Never leave both the KV-D20 operator interface panel and KV-P3E(01) handheld
programmer on simultaneously for a long period of time.

(5)

KVNKA Front_Pro.p65 6 08.3.11, 0:13 PM


(6)

KVNKA Front_Pro.p65 7 08.3.11, 0:13 PM


How this manual is organized
The Visual KV Series User’s Manual is composed of 3 separate manuals;
1-Installation, 2-Support Software, 3-Programming. Please read each manual
relevant to your purpose.

1 Installation
Chapter 1 Configuration and Specifications [Visual KV Series Only]
Describes the system configuration of the Visual KV Series, the names and functions of
each part, and the specifications.

Chapter 2 System Installation [Visual KV Series Only]


Describes the installation and connection of each Visual KV Series unit as well as
system maintenance.

Chapter 3 Access Window [Visual KV Series Only]


Describes the Access Window used for changing and monitoring data.

Chapter 4 KV-D20 Operator Interface Panel [Visual KV Series Only]


Describes the KV-D20 Operator Interface Panel used for changing, monitoring, and
displaying the status of inside relays, timers, counters and data memories.

Chapter 5 KV-300, KV-10/80 Hardware [KV-300, KV-10/80 Series Only]


Describes the hardware specifications and wirings for KV-300 and KV-10/80 Series.

Chapter 6 Handheld Programmer


Describes how to use the handheld programmer and memory card.

Chapter 7 KV-L2 Serial Interface Module [KV-300 Series Only]


Describes the serial interface modules for KV-300 Series.

Chapter 8 KV-AN6 Analog I/O Module [KV-300 Series Only]


Describes the optional Analog I/O module for KV-300 Series

Chapter 9 KV-AD4/DA4 Analog I/O Unit [KV-10/80 Series Only]


Describes the optional Analog I/O unit for KV-10/80 Series.

Chapter 10 Troubleshooting
This chapter describes the error code list, countermeasures against problems, and error
indications for each unit.

Appendices
The appendix includes a list of ladder program applications and the index.

2 Support Software
Chapter 1 Introduction
Describes the items included in the package, the product outline, the method to connect
a personal computer, the installation method, etc.

(7)

KVNKA Front_Pro.p65 8 08.3.11, 0:13 PM


Chapter 2 Editor
Describes the operating procedures in Editor mode.

Chapter 3 Simulator
Describes the operating procedures in Simulator mode.

Chapter 4 Monitor
Describes the operating procedures in Monitor mode.

Appendices
Includes instructions list, devices list, sample program list and quick reference for key
operation and shortcuts.

3 Programming
Chapter 1 Programming
Describes basic knowledge including program creation procedures, device configuration,
relay assignments, special functions to set and confirm Visual KV Series operations, as
well as the extended ladder diagrams. Understand the contents described here com-
pletely at first before creating programs.

Chapter 2 Instructions
Describes the concrete usage of instructions in the KV Series.
Refer to "Chapter 3 Interrupts" on page 3-183 for details of interrupt instructions.
Refer to "Chapter 4 High-speed counters" on page 3-195 for details of the high-speed
counters used in the application instruction.

Chapter 3 Interrupts [Visual KV Series Only]


The interrupt processing function executes an interrupt program when an external input
or request from the high-speed counter comparator (interrupt factor) is encountered
during KV operation.
This chapter describes the types of interrupt factors as well as inputs and outputs
encountered during interrupt processing.

Chapter 4 High-speed Counters [Visual KV Series Only]


Describes high-speed counters and high-speed counter comparators, which allow high-
speed pulse measurement and pulse output, independent of the scan time.

Chapter 5 Positioning Control [Visual KV Series Only]


Describes ramp-up/down control of stepping motors and servo motors.

Chapter 6 Interrupts, High-speed Counters, Positioning Control [KV-300, KV-10/80 Series Only]
Describes ramp-up/down control of stepping motors and servo motors.

Chapter 7 Serial Communication


The KV Series can be connected to an external device with an RS-232C interface to
establish communication.
This chapter describes communications specifications, how to connect the KV Series to
external devices, and how to perform communication.

Chapter 8 Programming Examples


Describes the typical programming examples for KV-10/80 Series. These programs can
be used for Visual KV Series. However, pay attention to the I/O addressing compatibility
before use.

(8)

KVNKA Front_Pro.p65 9 08.3.11, 0:13 PM


Contents
3 Programming

Chapter 1 Programming
1.1 Before Creating Programs .............................................................................. 3-2
1.1.1 Flow from Introduction to Operation ................................................................... 3-2
1.1.2 Scan Time ........................................................................................................... 3-3
Scan time ..................................................................................................... 3-3
Input response time delay ............................................................................ 3-3
1.2 User Memory .................................................................................................... 3-4
1.2.1 Program Capacity ............................................................................................... 3-4
Maximum number of lines in a program ....................................................... 3-4
Calculating the byte count used ................................................................... 3-4
1.3 Device Configuration ....................................................................................... 3-5
1.3.1 Device List .......................................................................................................... 3-5
Relay list ...................................................................................................... 3-5
List of I/O relays in basic units ..................................................................... 3-5
List of relays in expansion units ................................................................... 3-6
1.3.2 Relay No. ............................................................................................................ 3-7
Address No. ................................................................................................. 3-7
Contact No. .................................................................................................. 3-8
Channel No. ................................................................................................. 3-8
1.3.3 Assigning Relay Nos. .......................................................................................... 3-8
1.3.4 Input Relays ........................................................................................................ 3-9
Basic unit ..................................................................................................... 3-9
Expansion unit ........................................................................................... 3-10
1.3.5 Output Relays ................................................................................................... 3-10
Output operation time ................................................................................ 3-10
1.3.6 Internal Utility Relays ........................................................................................ 3-11
Retentive function of internal utility relays .................................................. 3-11
1.3.7 Special Utility Relays ........................................................................................ 3-12
Description ................................................................................................. 3-12
1.3.8 Special Utility Relay List ................................................................................... 3-14
Special relays and arithmetic operation flags ............................................ 3-14
Special utility relays for high-speed counter(0) .......................................... 3-14
Special utility relays for high-speed counter(1) .......................................... 3-15
Other special utility relays .......................................................................... 3-15
1.3.9 Timers and Counters ........................................................................................ 3-18
Timer/Counter list ....................................................................................... 3-18
Description ................................................................................................. 3-18
1.3.10 Data Memories ................................................................................................. 3-19
1.3.11 Temporary Data Memory .................................................................................. 3-21
1.3.12 Relay Nos. and Functions ................................................................................. 3-22
1.4 Special Functions .......................................................................................... 3-23
1.4.1 Input Time Constant Change Function ............................................................. 3-23
Setting the input time constant for basic units using special utility relays .. 3-23
1.4.2 Modifying the Input Relay Time Constant ......................................................... 3-24
Modification within the CPU ....................................................................... 3-24
1.4.3 Constant Scan Time Mode ............................................................................... 3-25
1.4.4 Output Disabled Function ................................................................................. 3-26
1.4.5 Input Refresh Disabled Function ...................................................................... 3-26
1.4.6 Contact Comment Save Function ..................................................................... 3-27
1.4.7 Special Functions ............................................................................................. 3-28
Constant Scan Time Mode ........................................................................ 3-28
Output Disabled Function .......................................................................... 3-28
Input Refresh Disabled Function ................................................................ 3-28
1.5 Extended Ladder Diagrams .......................................................................... 3-29
1.5.1 Features of Extended Ladder Diagrams ........................................................... 3-29
1.5.2 Advantages of Extended Ladder Diagrams ...................................................... 3-30
1.5.3 Example of an Extended Ladder Diagram ........................................................ 3-31

(9)

KVNKA Front_Pro.p65 10 08.3.11, 0:13 PM


Chapter 2 Instructions
2.1 Instruction List [Visual KV Series] .............................................................. 3-34
2.1.1 Basic Instructions ..............................................................................................3-34
2.1.2 Application Instructions ..................................................................................... 3-36
2.1.3 Arithmetic Instructions ...................................................................................... 3-38
2.1.4 Interrupt Instructions .........................................................................................3-41
2.1.5 Function No. List (Alphabetical order) .............................................................. 3-41
2.2 Instruction List [KV-300 Series, KV-10/80] ................................................. 3-42
2.2.1 Basic Instructions ..............................................................................................3-42
2.2.2 Application Instructions ..................................................................................... 3-45
2.2.3 Arithmetic Instructions ...................................................................................... 3-48
2.2.4 Interrupt Instructions .........................................................................................3-54
2.3 Convention Details ........................................................................................ 3-55
2.4 Instruction Details .......................................................................................... 3-56
2.4.1 Basic Instructions ..............................................................................................3-56
2.4.2 Application Instructions ..................................................................................... 3-95
2.4.3 Arithmetic Instructions .................................................................................... 3-134
2.5 Programming Notes ..................................................................................... 3-189

Chapter 3 Interrupts Visual KV


3.1 Interrupt Instructions ................................................................................... 3-192
3.2 Interrupt Processing .................................................................................... 3-194
3.2.1 Interrupt Processing ........................................................................................ 3-194
3.2.2 Types of Interrupts .......................................................................................... 3-195
3.2.3 Interrupt Priority .............................................................................................. 3-196
3.2.4 Interrupt Program ............................................................................................ 3-196
3.3 Direct Input/Output ...................................................................................... 3-197
3.3.1 Direct Input ..................................................................................................... 3-197
3.3.2 Direct Output ................................................................................................... 3-197
3.4 Applications of Interrupt Programs ........................................................... 3-198
3.4.1 Interrupt with a Signal Converter .................................................................... 3-198
3.4.2 Interrupt with a High-speed Counter ............................................................... 3-199
3.4.3 Measuring the ON Time of High-speed Pulses .............................................. 3-200
3.4.4 Measuring the Period in which a Target Passes between Two Points ........... 3-201

Chapter 4 High-speed Counters Visual KV


4.1 High-speed Counter Instructions ............................................................... 3-204
4.2 Outline of High-speed Counters ................................................................. 3-206
4.2.1 High-speed Counters and High-speed Counter Comparators ........................ 3-206
Structure of high-speed counters and high-speed counter comparators . 3-206
Specifications of high-speed counters ..................................................... 3-208
High-speed counter comparators ............................................................. 3-209
4.2.2 Internal Clock for High-speed Counters .......................................................... 3-210
4.3 Setting and Operation of High-speed Counters ........................................ 3-211
4.3.1 Reading the Current Value of the High-speed Counter .................................. 3-211
4.3.2 Preset Value of the High-speed Counter Comparator .................................... 3-211
4.3.3 Comparator Output ......................................................................................... 3-211
4.3.4 Count Input Method ........................................................................................ 3-212
4.3.5 Resetting the High-speed Counter ................................................................. 3-214
4.3.6 Differences with the CTH Instruction between the
Conventional and Visual KV Series ................................................................ 3-216
4.3.7 Applications of High-speed Counters ............................................................. 3-217
4.4 Extended Functions of High-speed Counters ........................................... 3-221
4.4.1 24-bit High-speed Counter .............................................................................. 3-221
4.4.2 Changing the Current Value of a 24-bit High-speed Counter ......................... 3-223
4.4.3 Application Example of 24-bit High-speed Counter (single-phase input) ....... 3-224
4.4.4 Ring Counter Function .................................................................................... 3-225
4.4.5 Applications of Ring Counters ........................................................................ 3-226
4.5 Special Functions Using High-speed Counters ........................................ 3-228

(10)

KVNKA Front_Pro.p65 11 08.3.11, 0:13 PM


4.5.1 Specified Frequency Pulse Output Function .................................................. 3-228
4.5.2 Applications of the Specified Frequency Pulse Output ................................... 3-229
4.5.3 Frequency Counter Function .......................................................................... 3-231
4.5.4 Applications of Frequency Counters ............................................................... 3-232
4.5.5 Cam Switch Function ...................................................................................... 3-233
Cam switch mode .................................................................................... 3-233
Multi-step comparator mode .................................................................... 3-234
Setting method ......................................................................................... 3-234
4.5.6 Application of the Cam Switch (Cam Switch Mode) ....................................... 3-236
4.6 Direct Clock Pulse Output ........................................................................... 3-237
4.6.1 Outline of Direct Clock Pulse Output .............................................................. 3-237
4.6.2 Pulse Output Setting with the High-speed Counter Comparator .................... 3-238
Changing the pulse period and width ....................................................... 3-238
Calculating the pulse period and comparator preset value ...................... 3-239
Operation with special utility relays .......................................................... 3-239
4.7 Examples of Direct Clock Pulse Output .................................................... 3-242
4.7.1 Example of Outputting a Pulse with 1:1 ON/OFF Ratio .................................. 3-242
4.7.2 Example of Outputting a Pulse with Variable ON/OFF Ratio .......................... 3-245
4.7.3 Example of Stopping the Pulse Output at a Specified Pulse Count ............... 3-249
4.7.4 Application of Direct Clock Pulse Output (Ramp-up/down control) ................ 3-251

Chapter 5 Positioning Control Visual KV


5.1 Outline of Positioning Control .................................................................... 3-254
5.1.1 Ramp-up/down Control ................................................................................... 3-254
5.2 Parameter Setting and Operating Procedures .......................................... 3-255
5.2.1 Parameter Setting Procedure ......................................................................... 3-255
5.2.2 Operating Procedure ...................................................................................... 3-257
5.3 Examples of Using the Positioning Control Function .............................. 3-258
5.3.1 Connection Example ....................................................................................... 3-258
5.3.2 Tips ................................................................................................................. 3-258
5.3.3 Application Examples of the Positioning Control Function ............................. 3-259

Chapter 6 Interrupts, High-speed Counters,


Positioning Control KV-300, KV-10/80
6.1 Interrupt Instructions ................................................................................... 3-268
6.1.1 Description of Interrupts .................................................................................. 3-268
Input processing for routine program and interrupt routine ...................... 3-268
Types of interrupt ..................................................................................... 3-268
Interrupt priority ........................................................................................ 3-269
Interrupt routine ........................................................................................ 3-269
Direct output ............................................................................................. 3-270
Direct input ............................................................................................... 3-270
6.1.2 Interrupt Instructions ....................................................................................... 3-271
6.2 Direct Clock Pulse ........................................................................................ 3-276
6.2.1 Output of Direct Clock Pulse ........................................................................... 3-276
Outline of High-Speed Counters .............................................................. 3-276
Outline of Pulse Output ............................................................................ 3-279
Examples of Pulse Output ....................................................................... 3-284
6.3 Positioning Control ...................................................................................... 3-296
6.3.1 Positioning Control (Ramp-up/down Control) ................................................. 3-296
Outline of positioning control .................................................................... 3-296
Setting and application of parameters ..................................................... 3-297
Examples of stepping motor control ......................................................... 3-300

Chapter 7 Serial Communication


7.1 Communications Specifications ................................................................ 3-306
7.1.1 Communications Specification ........................................................................ 3-306
7.1.2 Connection with the KV Unit ........................................................................... 3-306
7.1.3 Connecting the KV-300 CPU to a Personal Computer ................................... 3-307
7.2 Serial Communication ................................................................................. 3-308
7.2.1 Command Transmission Procedure ............................................................... 3-308

(11)

KVNKA Front_Pro.p65 12 08.3.11, 0:13 PM


7.2.2 Format of Commands/Responses .................................................................. 3-309
7.2.3 Communication Command/Response List ..................................................... 3-310
7.2.4 Setting Communication Commands and Responses to Commands .............. 3-311
7.2.5 Other Response Codes .................................................................................. 3-315
7.2.6 Error Code List ................................................................................................ 3-316
7.2.7 Example Program ........................................................................................... 3-317
7.3 Loading Text Data ........................................................................................ 3-318
7.3.1 Receiving Text Data ....................................................................................... 3-318
7.3.2 Transmitting Text Data ................................................................................... 3-319
7.3.3 Sample Program ............................................................................................. 3-320
7.4 ASCII Code List ............................................................................................ 3-321

Chapter 8 Programming Examples


8.1 List ......................................................................................................... 3-324
8.2 Details ......................................................................................................... 3-326
8.2.1 Reference Program Examples ........................................................................ 3-326
Basic Instructions ..................................................................................... 3-326
Application Instructions ............................................................................ 3-334
Arithmetic Instructions .............................................................................. 3-343

WARRANTIES AND DISCLAIMERS 3-367

1 Installation
Chapter 1 Configuration and Specifications Visual KV
1.1 System Configuration ...................................................................................... 1-2
1.1.1 System Configuration ......................................................................................... 1-2
1.2 Specifications ...................................................................................................1-4
1.2.1 General Specifications ........................................................................................ 1-4
1.2.2 AC Power Specifications .................................................................................... 1-5
Visual KV Series operation at power interruption ........................................ 1-5
1.2.3 Performance Specifications ................................................................................ 1-6
Data backup function against instantaneous power interruption ................. 1-7
1.3 Common I/O Specifications of Basic Units ................................................... 1-8
1.3.1 Model of a Basic Unit .......................................................................................... 1-8
1.3.2 Common I/O Specifications ................................................................................ 1-8
1.4 KV-10AR/AT(P)/DR/DT(P) (10-I/O Basic Unit) ............................................. 1-10
1.4.1 Part Names and Functions ............................................................................... 1-10
1.4.2 Terminal Layout Drawings and I/O Circuit Diagrams ........................................ 1-11
KV-10AR/DR (Relay output type) .............................................................. 1-11
KV-10AT(P)/DT(P) (Transistor output type) ............................................... 1-13
1.4.3 AC Power Input (KV-10AR/AT(P)) .................................................................... 1-14
1.4.4 Relationship between Continuous Simultaneous ON Ratio and Ambient Temperature 1-15
1.4.5 Dimensions ....................................................................................................... 1-16
1.5 KV-16AR/AT(P)/DR/DT(P) (16-I/O Basic Unit) ............................................. 1-17
1.5.1 Part Names and Functions ............................................................................... 1-17
1.5.2 Terminal Layout Drawings and I/O Circuit Diagrams ........................................ 1-18
KV-16AR/DR (Relay output type) .............................................................. 1-18
KV-16AT(P)/DT(P) (Transistor output type) ............................................... 1-20
1.5.3 AC Power Input (KV-16AR/AT(P)) .................................................................... 1-21
1.5.4 Relationship between Continuous Simultaneous ON Ratio and Ambient Temperature 1-22
1.5.5 Dimensions ....................................................................................................... 1-23
1.6 KV-24AR/AT(P)/DR/DT(P) (24-I/O Basic Unit) ............................................. 1-24
1.6.1 Part Names and Functions ............................................................................... 1-24
1.6.2 Terminal Layout Drawings and I/O Circuit Diagrams ........................................ 1-25
KV-24AR/DR (Relay output type) .............................................................. 1-25
KV-24AT(P)/DT(P) (Transistor output type) ............................................... 1-27
1.6.3 AC Power Input (KV-24AR/AT(P)) .................................................................... 1-28
1.6.4 Relationship between Continuous Simultaneous ON Ratio and Ambient Temperature 1-29
1.6.5 Dimensions ....................................................................................................... 1-30
1.7 KV-40AR/AT(P)/DR/DT(P) (40-I/O Basic Unit) .............................................. 1-31

(12)

KVNKA Front_Pro.p65 13 08.3.11, 0:13 PM


1.7.1 Part Names and Functions ............................................................................... 1-31
1.7.2 Terminal Layout Drawings and I/O Circuit Diagrams ........................................ 1-32
KV-40AR/DR (Relay output type) .............................................................. 1-32
KV-40AT(P)/DT(P) (Transistor output type) ............................................... 1-34
1.7.3 AC Power Input (KV-40AR/AT(P)) .................................................................... 1-35
1.7.4 Relationship between Continuous Simultaneous ON Ratio and Ambient Temperature 1-36
1.7.5 Dimensions ....................................................................................................... 1-37
1.8 KV-E4X/E8X/E16X (Expansion Input Unit) .................................................. 1-38
1.8.1 Part Names and Functions ............................................................................... 1-38
1.8.2 Input Specifications ........................................................................................... 1-38
1.8.3 Terminal Layout Drawings and Input Circuit Diagrams .................................... 1-39
KV-E4X (4-I/O expansion input unit) .......................................................... 1-39
KV-E8X (8-I/O expansion input unit) .......................................................... 1-40
KV-E16X (16-I/O expansion input unit) ...................................................... 1-41
1.8.4 Dimensions ....................................................................................................... 1-42
1.9 KV-E4R/E4T/E8R/E8T(P)/E16R/E16T(P) (Expansion Output Unit) ............. 1-43
1.9.1 Part Names and Functions ............................................................................... 1-43
1.9.2 Output Specifications ........................................................................................ 1-43
KV-E4R/E8R/E16R (Relay output type) ..................................................... 1-44
KV-E4T/E8T(P)/E16T(P) [Transistor output type (NPN/PNP)] .................. 1-44
1.9.3 Terminal Layout Drawings and Input Circuit Diagrams .................................... 1-45
KV-E4R [4-I/O expansion output unit (relay output type)] .......................... 1-45
KV-E4T [4-I/O expansion output unit transistor output type)] .................... 1-46
KV-E8R [8-I/O expansion output unit (relay output type)] .......................... 1-47
KV-E8T(P) [8-I/O expansion output unit (transistor output type)] .............. 1-48
KV-E16R [16-I/O expansion output unit (relay output type)] ...................... 1-49
KV-E16T(P) [16-I/O expansion input unit (transistor output)] .................... 1-50
1.9.4 Dimensions ....................................................................................................... 1-51
1.10 KV-E4XR/E4XT(P) (Expansion I/O Unit) ....................................................... 1-52
1.10.1 Part Names and Functions ............................................................................... 1-52
1.10.2 Input Specifications ........................................................................................... 1-53
1.10.3 Output Specifications ........................................................................................ 1-53
KV-E4XR (Relay output type) .................................................................... 1-53
KV-E4XT(P) (Transistor output type) ......................................................... 1-53
1.10.4 Terminal Layout Drawings and Input Circuit Diagrams .................................... 1-54
KV-E4XR (Relay output type) .................................................................... 1-54
KV-E4XT(P) (Transistor output type) ......................................................... 1-56
1.10.5 Dimensions ....................................................................................................... 1-58
1.11 KV-D20 (Operator Interface Panel) ............................................................... 1-59
1.11.1 Part Names and Functions ............................................................................... 1-59
1.11.2 General Specifications ...................................................................................... 1-60
1.11.3 Functional Specifications .................................................................................. 1-60
1.11.4 Dimensions ....................................................................................................... 1-61

Chapter 2 System Installation Visual KV


2.1 Installation Environment ............................................................................... 1-64
2.1.1 Installation Environment ................................................................................... 1-64
2.1.2 Installation Position ........................................................................................... 1-65
2.1.3 Installation Procedure ....................................................................................... 1-66
Expansion unit spacer ................................................................................ 1-66
2.1.4 Cautions on Wiring for Each Unit ...................................................................... 1-67
Wiring procedures for basic units ............................................................... 1-67
Cautions on wiring for I/O units .................................................................. 1-68
Terminal ..................................................................................................... 1-68
Cautions on grounding ............................................................................... 1-69
2.1.5 Contact Protection ............................................................................................ 1-69
2.2 Connecting Visual KV Series Expansion Units .......................................... 1-70
2.2.1 Visual KV Series Expansion Units .................................................................... 1-70
2.2.2 Connecting Visual KV Series Expansion Units ................................................. 1-71
Connection methods .................................................................................. 1-72
Number of connectable units ..................................................................... 1-73
2.2.3 Confirming the Connection Settings of Expansion Units .................................. 1-74
Expansion unit relay list ............................................................................. 1-74
Connection information for expansion units ............................................... 1-75
Input time constant for expansion units ..................................................... 1-76

(13)

KVNKA Front_Pro.p65 14 08.3.11, 0:13 PM


Clearing the input value when disconnecting ............................................. 1-76
2.2.4 Transferring I/O Information between Expansion Units and the Basic Unit ...... 1-77
When inputting ........................................................................................... 1-77
In the case of output .................................................................................. 1-77
2.3 Inspection and Maintenance ......................................................................... 1-78
2.3.1 Inspection .........................................................................................................1-78
2.3.2 Maintenance ..................................................................................................... 1-78

Chapter 3 Access Window Visual KV


3.1 Overview of the Access Window .................................................................. 1-80
3.1.1 What is the Access Window ............................................................................. 1-80
3.1.2 Access Window Use Examples ........................................................................ 1-80
3.2 Basic Operating Procedures ......................................................................... 1-81
3.2.1 Operation Mode ................................................................................................ 1-81
3.2.2 Access Window Modes ..................................................................................... 1-81
3.2.3 Part Names and Functions of the Access Window ........................................... 1-82
3.2.4 Selecting Modes and Setting/Resetting Key Lock ............................................ 1-82
3.2.5 Turbo Function .................................................................................................. 1-83
3.3 Digital Trimmer Mode .................................................................................... 1-84
3.3.1 Function and Operating Procedure ................................................................... 1-84
Key operation and screen display .............................................................. 1-84
Function and operating procedure ............................................................. 1-84
3.4 Device Mode ...................................................................................................1-87
3.4.1 Function and Operating Procedure ................................................................... 1-87
Devices that can be displayed and changed ............................................. 1-87
Key operation and screen display .............................................................. 1-87
Selecting the device and displaying the current value/set value ................ 1-88
Changing a numeric value ......................................................................... 1-89
Holding the setting ..................................................................................... 1-91
3.4.2 Screen Display for Each Device Type .............................................................. 1-91
Data memory (DM) .................................................................................... 1-91
Temporary data memory (TM) ................................................................... 1-91
Timer/counter (T/C) .................................................................................... 1-92
High-speed counter comparator (CTC) ...................................................... 1-92
Trimmer (TRM) .......................................................................................... 1-93
Relay (RLY) ............................................................................................... 1-93
3.5 System Mode .................................................................................................. 1-94
3.5.1 Function and Operating Procedure ................................................................... 1-94
Key operation and screen display .............................................................. 1-94
LOAD mode and SAVE mode .................................................................... 1-96
Display in LOAD/SAVE mode .................................................................... 1-96
3.6 Message Display ............................................................................................ 1-97
3.6.1 Error Messages and Error Status ..................................................................... 1-97
3.6.2 User Messages .................................................................................................1-97
How to use the user messages .................................................................. 1-98

Chapter 4 KV-D20 Operator Interface Panel Visual KV


4.1 Before Operation .......................................................................................... 1-100
4.1.1 Checking Package Contents .......................................................................... 1-100
4.1.2 Part Names and Functions ............................................................................. 1-101
4.1.3 Details about the KV-D20 ............................................................................... 1-102
General specifications .............................................................................. 1-102
Functional specifications .......................................................................... 1-102
Dimensions .............................................................................................. 1-103
4.1.4 Installation and Environment .......................................................................... 1-104
Use environment ...................................................................................... 1-104
Panel mounting ........................................................................................ 1-105
4.1.5 Inspection and Maintenance ........................................................................... 1-106
Inspection ................................................................................................. 1-106
Maintenance ............................................................................................ 1-106
4.2 Overview and Operation .............................................................................. 1-107
4.2.1 Use Examples for the KV-D20 ........................................................................ 1-107

(14)

KVNKA Front_Pro.p65 15 08.3.11, 0:13 PM


4.2.2 Connection with the KV Series ....................................................................... 1-108
Connection ............................................................................................... 1-108
Precautions .............................................................................................. 1-108
4.2.3 Overview of the KV-D20 ................................................................................. 1-109
Switching the display mode ..................................................................... 1-109
Overview of each display mode ............................................................... 1-110
Assignment of relays/DM ......................................................................... 1-111
Other functions ......................................................................................... 1-112
Precautions about screen change function .............................................. 1-115
4.2.4 Operator Mode ................................................................................................ 1-117
Screen selection in operator mode .......................................................... 1-117
Operator screen ....................................................................................... 1-118
Direct access screen ................................................................................ 1-126
KV-I/O monitor screen ............................................................................. 1-127
Switch comment screen ........................................................................... 1-128
Lamp comment screen ............................................................................ 1-128
Screen change permission in operator mode .......................................... 1-129
4.2.5 Device Mode ................................................................................................... 1-130
Device mode ............................................................................................ 1-130
Operation example for device mode ........................................................ 1-132
4.2.6 System Mode .................................................................................................. 1-134
System mode ........................................................................................... 1-134
4.3 Examples of Ladder Programs ................................................................... 1-135
4.3.1 Basic Ladder Programs .................................................................................. 1-135
Before creating ladder programs ............................................................. 1-135
Basic ladder programs ............................................................................. 1-136
4.3.2 Examples of Ladder Programs ....................................................................... 1-143
Example of displaying user messages ..................................................... 1-143
Example of displaying messages with titles ............................................. 1-145
Example of position control ...................................................................... 1-146
Example of frequency counter ................................................................. 1-149
Example of 24-bit high-speed counter ..................................................... 1-152
Example of cam switch function ............................................................... 1-154
4.4 Appendix ....................................................................................................... 1-158
4.4.1 Troubleshooting .............................................................................................. 1-158
4.4.2 Available Character List .................................................................................. 1-162
4.4.3 Comment Draft Sheet ..................................................................................... 1-163

Chapter 5 KV-300, KV-10/80 Hardware KV-300, KV-10/80


5.1 System Configuration .................................................................................. 1-166
5.1.1 KV-300 ............................................................................................................ 1-166
5.1.2 KV-10/80 ......................................................................................................... 1-167
5.2 Module/Unit Specifications ......................................................................... 1-168
5.2.1 Wiring: KV-U4 Power Supply Module ............................................................. 1-168
Parts and functions .................................................................................. 1-168
5.2.2 Wiring: KV-U5 DC Power Distribution Module ................................................ 1-169
Parts and functions .................................................................................. 1-169
5.2.3 Wiring: KV-300 CPU ....................................................................................... 1-170
Parts and functions .................................................................................. 1-170
5.2.4 Wiring: KV-C16X/C32X Connector Input Module ........................................... 1-171
Parts and functions .................................................................................. 1-171
5.2.5 Wiring: KV-C32T/B16R/B16S Connector Output Module ............................... 1-172
Parts and functions .................................................................................. 1-172
5.2.6 Wiring: KV-R1A I/O Distribution Module ......................................................... 1-173
Parts and functions .................................................................................. 1-173
5.2.7 Wiring: KV-R8X/R16X/R8R/R16R/R8T/R16T I/O Terminal Modules ............. 1-174
Parts and functions .................................................................................. 1-174
5.2.8 Module Names and Functions ........................................................................ 1-175
5.2.9 Peripheral Equipment Names and Functions ................................................. 1-176
5.3 Module/Unit Connections ............................................................................ 1-178
5.3.1 Environmental Requirements ......................................................................... 1-178
5.3.2 Installation Guidelines ..................................................................................... 1-178
5.3.3 Assembling the System .................................................................................. 1-179
Connecting modules ................................................................................ 1-179
5.3.4 Mounting to the DIN Rail ................................................................................. 1-180
5.3.5 Removing the Terminal Block ......................................................................... 1-181

(15)

KVNKA Front_Pro.p65 16 08.3.11, 0:13 PM


5.3.6 Connecting the AC Power Supply Module and DC Power Distribution Module .... 1-182
KV-U4 AC Power Supply Module ............................................................ 1-182
KV-U5 DC Power Distribution Module ..................................................... 1-182
5.3.7 I/O Connectors ................................................................................................ 1-183
KV-300 CPU ............................................................................................ 1-183
KV-C16X/C32X ........................................................................................ 1-184
KV-C32T/B16R/B16S .............................................................................. 1-185
KV-R8X/R16X/R8R/R16R/R8T/R16T ...................................................... 1-186
5.3.8 I/O Terminal Modules: Communication Cables and Power Distribution ......... 1-187
Transmission distance by cable type ....................................................... 1-187
Connection patterns ................................................................................. 1-187
Incorrect wiring patterns ........................................................................... 1-188
Power distribution .................................................................................... 1-188
5.3.9 Connector Assembly Instructions ................................................................... 1-189
5.3.10 KV-300 CPU I/O Indicators ............................................................................. 1-191
5.3.11 KV-10/80 Expansion Units .............................................................................. 1-192
5.3.12 Mounting Environment .................................................................................... 1-194

Chapter 6 Handheld Programmer


6.1 Using the Handheld Programmer ............................................................... 1-196
6.1.1 Outline of the Handheld Programmer ............................................................. 1-196
6.1.2 Precautions ..................................................................................................... 1-198
6.2 Basic Operations ......................................................................................... 1-200
6.2.1 Basic Programming Operation ........................................................................ 1-200
6.3 Functions ...................................................................................................... 1-216
Function Nos. list ..................................................................................... 1-216
ALL CLEAR .............................................................................................. 1-217
HANDHELD PROGRAMMER CLEAR ..................................................... 1-217
COUNTER CLEAR .................................................................................. 1-218
HIGH-SPEED COUNTER CLEAR ........................................................... 1-218
ALL DATA MEMORY CLEAR .................................................................. 1-219
ALL LATCHING RELAYS RESET ........................................................... 1-219
PROGRAM SENT OR RECEIVED .......................................................... 1-220
OFFLINE EDITOR START ...................................................................... 1-221
OFFLINE EDITOR STOP ........................................................................ 1-221
TIMER/COUNTER CURRENT VALUE CHANGE ................................... 1-222
TIMER/COUNTER SETTING CHANGE .................................................. 1-224
RELAY ON/OFF ....................................................................................... 1-226
WRITE INTO DATA MEMORY ................................................................ 1-227
READ TRIMMER SETTING ..................................................................... 1-228
SYNTAX CHECK ..................................................................................... 1-228
PROGRAM CAPACITY CHECK .............................................................. 1-229
6.4 Memory Card ................................................................................................ 1-230
6.4.1 Functions [used with KV-P3E(01)] .................................................................. 1-230
6.4.2 Storage Capacity ............................................................................................ 1-230
CLEAR ..................................................................................................... 1-232
NEW ......................................................................................................... 1-233
ACCS ....................................................................................................... 1-234
ACCS: SAVE ........................................................................................... 1-235
ACCS: LOAD ........................................................................................... 1-236
ACCS: VERIFY ........................................................................................ 1-236
ACCS: DELETE ....................................................................................... 1-237

Chapter 7 KV-L2 Serial Interface Module KV-300


7.1 Outline ......................................................................................................... 1-240
7.1.1 Features .......................................................................................................... 1-240
7.2 Configuration ............................................................................................... 1-241
7.2.1 Parts and Functions ........................................................................................ 1-241
7.2.2 System Configuration ..................................................................................... 1-242
7.2.3 Outline of Operation Modes ............................................................................ 1-244
7.3 Installation .................................................................................................... 1-245
7.3.1 Setting the Operation Mode ............................................................................ 1-245
7.3.2 Communications Protocols ............................................................................. 1-247
7.3.3 Connector Wiring ............................................................................................ 1-248

(16)

KVNKA Front_Pro.p65 17 08.3.11, 0:13 PM


7.3.4 Connecting to External Units .......................................................................... 1-249
Connecting to An External Display .......................................................... 1-249
Connecting to an IBM PC-AT Computer .................................................. 1-249
Connecting to the KV-10/16/24/40/80 ...................................................... 1-250
Connecting KV-L2s .................................................................................. 1-250
7.4 Software Setup ............................................................................................. 1-252
7.4.1 Using KV Software [KV IncrediWare (DOS)] .................................................. 1-252
Starting KV IncrediWare (DOS) from the KV-L2 ........................................................ 1-252
7.5 KV Mode Programming ............................................................................... 1-253
7.5.1 Operating in KV Mode .................................................................................... 1-253
Communications protocol ........................................................................ 1-253
7.5.2 Serial Communications Procedure ................................................................. 1-255
Command transmission procedure .......................................................... 1-255
Command/response format ..................................................................... 1-256
Communications commands and responses ........................................... 1-256
Communications commands .................................................................... 1-257
7.5.3 Transmission and Reception of Text Data ...................................................... 1-262
Assigning relay nos. and data memory address nos. .............................. 1-262
Transmitting Text Data ............................................................................. 1-264
Receiving text data .................................................................................. 1-265
ASCII code/binary conversion function .................................................... 1-266
Example program ..................................................................................... 1-269
7.6 Display Interface Mode Programming ....................................................... 1-270
7.6.1 Operating in Display Interface Mode .............................................................. 1-270
Communications protocols ....................................................................... 1-270
Communications control procedure ......................................................... 1-271
7.6.2 Command and Response Format ................................................................... 1-273
7.6.3 Commands and Responses ........................................................................... 1-275
List of commands and responses ............................................................ 1-275
Description of commands and responses ................................................ 1-277
End codes ................................................................................................ 1-291
7.7 Non-procedure Mode Programming .......................................................... 1-292
7.7.1 Operating in Non-procedure Mode ................................................................. 1-292
Communications protocol ........................................................................ 1-292
Connecting to the KV-L2 .......................................................................... 1-293
7.7.2 Assignment of Relay Nos. and Data Memory Address Nos. .......................... 1-294
Assigning relay nos. and data memory address nos. .............................. 1-294
7.7.3 Transmitting Text Data ................................................................................... 1-297
Data transmission and internal data memory addresses ......................... 1-297
7.7.4 Receiving Text Data ....................................................................................... 1-298
Format of received data and data memory addresses ............................ 1-298
7.7.5 ASCII code/Binary Conversion Function ........................................................ 1-300
7.8 Troubleshooting Guide ............................................................................... 1-304
7.8.1 Troubleshooting .............................................................................................. 1-304
7.8.2 Precautions ..................................................................................................... 1-305
7.9 Specifications ............................................................................................... 1-306
7.9.1 Specifications .................................................................................................. 1-306
General specifications .............................................................................. 1-306
Communications protocol ........................................................................ 1-306
RS-232C connector specifications ........................................................... 1-306
RS-422A terminal block specifications ..................................................... 1-306
7.9.2 Dimensions ..................................................................................................... 1-307
7.10 Command List .............................................................................................. 1-308
7.10.1 List of Commands and Responses ................................................................. 1-308
7.10.2 List of Commands and Responses in Display Interface mode ....................... 1-309

Chapter 8 KV-AN6 Analog I/O Module KV-300


8.1 Outline ......................................................................................................... 1-312
Features ................................................................................................... 1-312
8.2 Configuration ............................................................................................... 1-313
8.2.1 Parts and Functions ........................................................................................ 1-313
8.2.2 System Configuration ..................................................................................... 1-314
8.3 Installation .................................................................................................... 1-315
8.3.1 Terminal Nos. ................................................................................................. 1-315

(17)

KVNKA Front_Pro.p65 18 08.3.11, 0:13 PM


8.3.2 Removing the Terminal Block ......................................................................... 1-316
8.3.3 Example of Voltage I/O Wiring ........................................................................ 1-317
8.3.4 Example of Current I/O Wiring ........................................................................ 1-318
8.3.5 Setting I/O Ranges ......................................................................................... 1-319
8.4 Programming ................................................................................................ 1-320
8.4.1 Input Characteristics (A/D) .............................................................................. 1-320
8.4.2 Calculating Input Data (A/D) ........................................................................... 1-321
8.4.3 Output Characteristics (D/A) ........................................................................... 1-322
8.4.4 Calculating Output Data (D/A) ........................................................................ 1-323
8.4.5 Assigning Data Memory (DM) Addresses ....................................................... 1-324
8.4.6 Reading Analog Input ..................................................................................... 1-325
8.4.7 Measuring Analog Input Average ................................................................... 1-326
8.4.8 Writing Analog Output ..................................................................................... 1-327
8.4.9 Converting Analog Input to Analog Output ..................................................... 1-328
8.5 KV-AN6 Appendices .................................................................................... 1-329
8.5.1 Troubleshooting .............................................................................................. 1-329
8.5.2 Precautions ..................................................................................................... 1-330
8.5.3 Specifications .................................................................................................. 1-331
Environmental specifications ................................................................... 1-331
System specifications .............................................................................. 1-331
8.5.4 Dimensions ..................................................................................................... 1-332

Chapter 9 KV-AD4/DA4 Analog I/O Unit KV-10/80


9.1 Outline ......................................................................................................... 1-334
Features ................................................................................................... 1-334
9.2 Configuration ............................................................................................... 1-335
9.2.1 Part Names and Functions ............................................................................. 1-335
KV-AD4 .................................................................................................... 1-335
KV-DA4 .................................................................................................... 1-336
9.2.2 Specifications .................................................................................................. 1-337
KV-AD4 .................................................................................................... 1-337
KV-DA4 .................................................................................................... 1-339
9.2.3 System Configuration ..................................................................................... 1-341
9.3 Installation .................................................................................................... 1-342
9.3.1 Installation Procedure ..................................................................................... 1-342
9.3.2 Checking the Installation Environment ........................................................... 1-343
9.3.3 Setting the KV-AD4 Input Mode ...................................................................... 1-344
Setting the input mode ............................................................................. 1-344
9.3.4 Connecting External Instruments .................................................................... 1-345
Wiring ....................................................................................................... 1-345
Wiring diagrams ....................................................................................... 1-346
9.3.5 Connecting to the KV-10 to 80 ........................................................................ 1-348
9.3.6 Maintenance ................................................................................................... 1-349
Inspection and Cleaning .......................................................................... 1-349
9.4 Programming ................................................................................................ 1-350
9.4.1 Programming the KV-AD4 .............................................................................. 1-350
A/D Conversion Mechanism .................................................................... 1-350
About Digital Data after A/D Conversion .................................................. 1-351
Calculating Voltage and Current Values from Digital Data ...................... 1-352
9.4.2 Programming the KV-DA4 .............................................................................. 1-353
D/A Conversion Mechanism .................................................................... 1-353
Converting Digital Data to Voltage or Current Values to be Output ......... 1-354
Writing Digital Data to Data Memory for D/A Conversion ........................ 1-356
9.4.3 A/D and D/A Conversion Tables ..................................................................... 1-357
Voltage Conversion Table ........................................................................ 1-357
Current Conversion Table ........................................................................ 1-358
9.5 Programming Examples .............................................................................. 1-359
Calculating Analog Data Values from Digital Data ................................... 1-359
Writing Data to be Analog-output ............................................................. 1-361
Outputting Analog Trimmer Values .......................................................... 1-364
Outputting Analog Input Data ................................................................... 1-365
Outputting Analog Input from a Pressure Sensor to an Air Valve ............ 1-366
Setting the Minimum and Maximum Voltage Limits and Measuring the
Average Voltage ...................................................................................... 1-367
9.6 Troubleshooting ........................................................................................... 1-370

(18)

KVNKA Front_Pro.p65 19 08.3.11, 0:13 PM


Chapter 10 Troubleshooting
10.1 Error List ....................................................................................................... 1-372
10.1.1 List of Error Codes in Basic Units ................................................................... 1-372
10.1.2 Error indication in Expansion Units ................................................................. 1-374
10.1.3 Program Errors ............................................................................................... 1-375
10.1.4 Memory Card Errors and Other Errors ........................................................... 1-376
10.2 Replacing Relays ......................................................................................... 1-377
Replacement procedure ........................................................................... 1-377
10.3 Troubleshooting ........................................................................................... 1-378
10.3.1 Troubleshooting List ....................................................................................... 1-378
10.4 Error Messages ............................................................................................ 1-380

Appendices
Appendix A. Specifications and Dimensions [Visual KV Series] .................... 1-382
A.1 System Specifications [Visual KV Series] ....................................................... 1-382
Hardware ................................................................................................. 1-382
Software and Programming ..................................................................... 1-383
AC power supply unit ............................................................................... 1-384
A.2 Common I/O Specifications of Basic Units ..................................................... 1-384
Input specifications .................................................................................. 1-384
Output specifications (relay output): KV-10AR/DR, KV-16AR/DR,
KV-24AR/DR, and KV-40AR/DR .............................................................. 1-385
Output specifications (transistor output): KV-10AT(P)/DT(P),
KV-16AT(P)/DT(P), KV-24AT(P)/DT(P), and KV-40AT(P)/DT(P) ............ 1-385
A.3 Expansion Unit Specifications ........................................................................ 1-385
A.4 Dimensions ..................................................................................................... 1-389
Appendix B. Specifications and Dimensions [KV-300 Series] ......................... 1-392
B.1 System Specifications [KV-300 Series] .......................................................... 1-392
Hardware ................................................................................................. 1-392
Software and Programming ..................................................................... 1-393
AC Power supply module/DC power distribution module ........................ 1-394
B.2 Module Specifications ..................................................................................... 1-398
KV-300 CPU ............................................................................................ 1-398
KV-C16X/C32X Input Modules ................................................................ 1-399
KV-C32T/B16R/B16S Output Modules ................................................... 1-400
KV-R8X/R16X I/O Terminal Modules ....................................................... 1-401
KV-R8T/R16T/R8R/R16R I/O Terminal Modules ..................................... 1-402
KV-R8T/R16T/R8R/R16R I/O Terminal Modules (RUN Output) .............. 1-403
KV-R1A I/O Distribution Module .............................................................. 1-403
B.3 Dimensions ..................................................................................................... 1-404
Appendix C. Ladder Program List ...................................................................... 1-406
Appendix D. A/D and D/A Conversion Tables [KV-AN6] ..................................... 1-408
Voltage conversion table .......................................................................... 1-408
Current conversion table .......................................................................... 1-409
WARRANTIES AND DISCLAIMERS 1-419

2 Support software
Chapter 1 Introduction
1.1 Items Included in the Package ........................................................................ 2-2
1.2 Outline of the Ladder Builder for KV .............................................................. 2-3
1.2.1 Operating environment and system configuration .............................................. 2-3
1.2.2 Features and functions of the Ladder Builder for KV .......................................... 2-4
Features of the Ladder Builder for KV ......................................................... 2-4
Functions of the Ladder Builder for KV ........................................................ 2-6
1.3 Before Programming ....................................................................................... 2-7
Machines to be prepared ............................................................................. 2-7
1.3.1 Differences from the KV IncrediWare (DOS) ...................................................... 2-8
1.3.2 Differences from the Ladder Builder for KV Ver 1.0 ........................................... 2-8
1.4 Installing the Software ..................................................................................... 2-9

(19)

KVNKA Front_Pro.p65 20 08.3.11, 0:13 PM


1.4.1 Preparation for installation .................................................................................. 2-9
1.4.2 Installation Procedure ....................................................................................... 2-10
Installation in Windows 95 ......................................................................... 2-10
Installation in Windows 3.1 ........................................................................ 2-12
1.5 Cautions for Use ............................................................................................ 2-13
1.6 Basic Operations ........................................................................................... 2-14
1.6.1 Program creation flow and available modes ..................................................... 2-14
1.6.2 Starting up and exiting from the software ......................................................... 2-16
1.6.3 Screen ..............................................................................................................2-18
1.6.4 Mouse operation and keyboard operation ........................................................ 2-21
1.6.5 Online Help ....................................................................................................... 2-23

Chapter 2 Editor KV-300


2.1 Outline of the Editor Functions .................................................................... 2-26
2.1.1 Cautions for editing ladder programs ................................................................ 2-26
2.2 Edit Screen ..................................................................................................... 2-27
2.2.1 Name and function of each part of the screen .................................................. 2-27
2.2.2 Ladder program window screen ....................................................................... 2-28
2.3 File Management ............................................................................................ 2-29
2.3.1 Creating a new file ............................................................................................ 2-29
2.3.2 Setting the automatic file read function ............................................................. 2-30
2.3.3 Setting automatic file save for the file ............................................................... 2-31
2.3.4 Saving and reading files ................................................................................... 2-32
2.3.5 Reading and saving a file in another format ..................................................... 2-33
2.3.6 Saving a ladder diagram in text format ............................................................. 2-36
2.3.7 Verifying files .................................................................................................... 2-36
2.4 Entering/Deleting Symbols and Connection Lines .................................... 2-37
2.4.1 Entering symbols ..............................................................................................2-37
2.4.2 Deleting symbols ..............................................................................................2-42
2.4.3 Entering contacts/coils directly ......................................................................... 2-42
2.4.4 Changing the device at the current cursor position .......................................... 2-43
2.4.5 Entering/Deleting connection lines ................................................................... 2-44
2.4.6 Canceling edit operations ................................................................................. 2-45
2.5 Entering Comments/Labels ......................................................................... 2-46
2.5.1 Editing comments/labels ................................................................................... 2-46
2.5.2 Editing line comments ....................................................................................... 2-50
2.5.3 Changing ladder lines into comments ............................................................... 2-51
2.6 Edit and Arrangement .................................................................................. 2-52
2.6.1 Copy, move, and delete .................................................................................... 2-52
2.6.2 Inserting and deleting lines ............................................................................... 2-57
2.7 Jump, Search, and Replace ......................................................................... 2-58
2.7.1 Jump .................................................................................................................2-58
2.7.2 Searching for instruction words/operands ........................................................ 2-62
2.7.3 Searching for the device at the cursor position ................................................. 2-63
2.7.4 Replacing operands .......................................................................................... 2-64
2.7.5 Converting a/b contacts .................................................................................... 2-65
2.8 Editing the Mnemonic List ........................................................................... 2-67
2.8.1 Displaying and terminating a mnemonic list ..................................................... 2-67
2.8.2 Copy, move, and delete .................................................................................... 2-69
2.9 Displaying the Use Status ............................................................................. 2-70
2.9.1 Displaying a use status list ............................................................................... 2-70
2.10 Setting the System .........................................................................................2-71
2.10.1 Setting the system ............................................................................................ 2-71
2.11 Entering and Developing Macros ................................................................ 2-72
2.11.1 Creating a macro file .........................................................................................2-72
2.11.2 Entering and developing macros ...................................................................... 2-74
2.12 Compilation .................................................................................................... 2-75
2.12.1 Executing compilation ....................................................................................... 2-75
2.12.2 Error display ......................................................................................................2-76
2.12.3 Double coil check ..............................................................................................2-76
2.13 Printing Functions .........................................................................................2-77

(20)

KVNKA Front_Pro.p65 21 08.3.11, 0:13 PM


2.13.1 Printing ..............................................................................................................2-77
2.13.2 Preview display ................................................................................................. 2-81
2.14 Changing the Display Color on the Screen ................................................. 2-82
2.14.1 Changing display colors on the screen ............................................................. 2-82

Chapter 3 Simulator
3.1 Outline of the Simulator Functions .............................................................. 2-84
3.1.1 Outline of the functions ..................................................................................... 2-84
3.1.2 Restrictions in the simulator .............................................................................. 2-84
3.2 Starting up and Exiting from the Simulator ................................................. 2-86
3.2.1 Operating procedure for startup and exit .......................................................... 2-86
3.2.2 Name and function of each part of the screen .................................................. 2-88
3.3 Ladder Monitor ............................................................................................... 2-89
3.3.1 Outline of the ladder monitor ............................................................................ 2-89
3.3.2 Executing scans ................................................................................................ 2-89
3.3.3 Executing steps .............................................................................................. 2-101
3.3.4 Jump and search ............................................................................................ 2-105
3.3.5 Stop/reset and device all clear ........................................................................ 2-108
3.4 Monitor All .................................................................................................... 2-109
3.4.1 Outline of monitor all ....................................................................................... 2-109
3.4.2 Displaying, saving, and reading the monitor all window ................................. 2-109
3.4.3 Monitor all window .......................................................................................... 2-113
3.4.4 Registering devices ........................................................................................ 2-113
3.4.5 Selecting and changing devices ..................................................................... 2-116
3.5 Registration Monitor .................................................................................... 2-119
3.5.1 Outline of the registration monitor ................................................................... 2-119
3.5.2 Displaying, saving, and reading the registration monitor ................................ 2-119
3.5.3 Registration monitor window ........................................................................... 2-122
3.5.4 Registering devices ........................................................................................ 2-122
3.5.5 Selecting and changing devices ..................................................................... 2-123
3.5.6 Manipulating timing charts .............................................................................. 2-128
3.5.7 Printing out the registration monitor ................................................................ 2-131

Chapter 4 Monitor
4.1 Outline of the Monitor Functions ............................................................... 2-134
4.1.1 Outline of the functions ................................................................................... 2-134
4.1.2 Restrictions in the monitor .............................................................................. 2-134
4.1.3 Precautions for communication ...................................................................... 2-135
4.2 Communicating with the PLC ..................................................................... 2-136
4.2.1 Setting the PLC communication parameters .................................................. 2-136
4.2.2 Setting the comment transfer .......................................................................... 2-138
4.3 Starting up and Exiting from the Monitor .................................................. 2-139
4.3.1 Operating procedures for startup and exit ...................................................... 2-139
4.3.2 Name and function of each part of the screen ................................................ 2-143
4.4 Ladder Monitor ............................................................................................. 2-144
4.4.1 Outline of the ladder monitor .......................................................................... 2-144
4.4.2 Displaying the ladder monitor window ............................................................ 2-144
4.4.3 PLC error check .............................................................................................. 2-144
4.4.4 Starting the monitor ........................................................................................ 2-145
4.4.5 Stopping the monitor ....................................................................................... 2-145
4.4.6 Screen displayed while the monitor is running ............................................... 2-146
4.4.7 Setting the PLC operation mode ..................................................................... 2-147
4.5 Monitor All and Registration Monitor ......................................................... 2-148
4.5.1 Functions of the monitor all window ................................................................ 2-148
4.5.2 Functions of the registration monitor .............................................................. 2-148
4.6 Monitor Function .......................................................................................... 2-149
4.6.1 Disabling the input refresh/Disabling the output ............................................. 2-149
4.6.2 Changing the current values all at once ......................................................... 2-150
4.6.3 Device all clear ............................................................................................... 2-154

(21)

KVNKA Front_Pro.p65 22 08.3.11, 0:13 PM


Appendices
Appendix A Error Message List ......................................................................... 2-156
A-1 System errors ................................................................................................. 2-156
A-2 Memory errors ................................................................................................ 2-156
A-3 File errors ........................................................................................................ 2-157
A-4 Installation errors ............................................................................................ 2-157
A-5 Errors that occur in the editor ......................................................................... 2-158
A-6 Errors that occur in the monitor/simulator ....................................................... 2-159
A-7 Communication errors (displayed in the monitor) ........................................... 2-159
A-8 PLC errors ...................................................................................................... 2-160
A-9 Errors that occur during compilation ............................................................... 2-161
Appendix B Instruction List ............................................................................... 2-163
B-1 Basic instructions ............................................................................................ 2-163
B-2 Application instructions ................................................................................... 2-164
B-3 Arithmetic instructions ..................................................................................... 2-165
B-4 Interrupt instructions ....................................................................................... 2-166
Appendix C Relay No. List .................................................................................. 2-167
C-1 Relays, timers, counters, and memory numbers for each model ................... 2-167
Appendix D Special Utility Relay List ................................................................ 2-168
D-1 Special relays and arithmetic operation flags ................................................. 2-168
D-2 Special utility relays for high-speed counter (0) .............................................. 2-168
D-3 Special utility relays for high-speed counter (1) .............................................. 2-169
D-4 Other special utility relays ............................................................................... 2-169
D-5 Memory switches ............................................................................................ 2-172
D-6 Special memory list ......................................................................................... 2-172
Appendix E Devices for KV-10R(W)/T(W) to 80R(W)/T(W), KV-300 ................ 2-174
E-1 Special utility relays ........................................................................................ 2-174
E-2 Memory switches ............................................................................................ 2-176
E-3 Special memory list ......................................................................................... 2-176
Appendix F Sample Program List ..................................................................... 2-178
F-1 Description of sample ladder programs .......................................................... 2-178
Appendix G Quick Reference ............................................................................. 2-180
G-1 Editor .............................................................................................................. 2-180
G-2 Simulator ......................................................................................................... 2-188
G-3 Monitor ............................................................................................................ 2-195
Appendix H Notes for Programming ................................................................. 2-201
H-1 Circuits that must be modified ........................................................................ 2-201
H-2 Precautions for programming ......................................................................... 2-202
H-3 Programs which cannot be decompiled .......................................................... 2-203
Appendix I List of Files Used ............................................................................ 2-204
Appendix J Countermeasures for Frequent Communication Errors ............ 2-205

WARRANTIES AND DISCLAIMERS 2-215

(22)

KVNKA Front_Pro.p65 23 08.3.11, 0:13 PM


WARRANTIES AND DISCLAIMERS
See 3-367.

Caution
• No part of this manual may be reprinted or reproduced in any form or by any
means without the prior written permission of KEYENCE CORPORATION.
• The content of this manual is subject to change without notice.
• KEYENCE has thoroughly checked and reviewed this manual. Please contact
the sales office listed at the end of this manual if you have any questions or
comments regarding this manual or if you find an error.
• KEYENCE assumes no liability for damages resulting from the use of the infor-
mation in this manual, item 3 above notwithstanding.
• KEYENCE will replace any incomplete or incorrectly collated manual.

All company names and product names in this manual are registered trademarks or
trademarks of their respective owners.

(23)

KVNKA Front_Pro.p65 24 08.3.11, 0:13 PM


Chapter 1
Programming
This chapter describes basic knowledge including program creation procedures,
device configuration, relay assignments, special functions to set and confirm Visual
KV Series operations, as well as the extended ladder diagrams. Understand the
contents described here completely at first before creating programs.
➮ For a detailed description of instructions, refer to "2.4. Instruction Details" (p.3-56).

1.1 Before Creating Programs .......................................................... 3-2


1.1.1 Flow from Introduction to Operation ........................................................... 3-2
1.1.2 Scan Time .................................................................................................. 3-3
1.2 User Memory ................................................................................ 3-4
1.2.1 Program Capacity ...................................................................................... 3-4
1.3 Device Configuration ................................................................... 3-5
1.3.1 Device List .................................................................................................. 3-5
1.3.2 Relay No. ................................................................................................... 3-7
1.3.3 Assigning Relay Nos. ................................................................................. 3-8
1.3.4 Input Relays ............................................................................................... 3-9
1.3.5 Output Relays .......................................................................................... 3-10
1.3.6 Internal Utility Relays ............................................................................... 3-11
1.3.7 Special Utility Relays ................................................................................ 3-12
1.3.8 Special Utility Relay List ........................................................................... 3-14
1.3.9 Timers and Counters ................................................................................ 3-18
1.3.10 Data Memories ......................................................................................... 3-19
1.3.11 Temporary Data Memory ......................................................................... 3-21
1.3.12 Relay Nos. and Functions ........................................................................ 3-22
1.4 Special Functions ...................................................................... 3-23
1.4.1 Input Time Constant Change Function .................................................... 3-23
1.4.2 Modifying the Input Relay Time Constant ................................................ 3-24
1.4.3 Constant Scan Time Mode ....................................................................... 3-25
1.4.4 Output Disabled Function ......................................................................... 3-26
1.4.5 Input Refresh Disabled Function .............................................................. 3-26
1.4.6 Contact Comment Save Function ............................................................ 3-27
1.4.7 Special Functions ..................................................................................... 3-28
1.5 Extended Ladder Diagrams ...................................................... 3-29
1.5.1 Features of Extended Ladder Diagrams .................................................. 3-29
1.5.2 Advantages of Extended Ladder Diagrams ............................................. 3-30
1.5.3 Example of an Extended Ladder Diagram ............................................... 3-31

KVNKA Chap 01P.p65 1 08.3.11, 11:49 AM


1.1 Before Creating Programs

1.1 Before Creating Programs


This section describes what you should know before creating programs and opera-
tions for the Visual KV Series.

1.1.1 Flow from Introduction to Operation


This section describes an overview of program creation procedures, functions used,
and setting items.
In the example described below, a latch circuit is created as a program for the Visual
KV Series.
Introduction


Examining contents of operations
Figure 1 shows a latch circuit which operates as follows. Fig. 1
PB1 = N.O. contact switch
Pushbutton switch PB1: ON
➞Pilot lamp (PL) turns on. PB2 = N.C. contact switch
Pushbutton switch PB2: OFF
▲ PB1 PB2

Pushbutton switch PB1: OFF ➞Pilot lamp (PL) remains


Pushbutton switch PB2: OFF lit even if PB1 turns
▲ OFF.
Pushbutton switch PB1: OFF ➞Pilot lamp (PL) goes out
1 Pushbutton switch PB2: ON when PB2 is set to ON. RL
(Relay)
Time chart
ON
PB1 contact OFF
ON
PB2 contact OFF
ON
PL
PL OFF

Next, a program is created that will use the same operation as this circuit to control a PLC.

Program examination
Circuit 1 shows relay symbols for the latch circuit.
Examine which contact in the Visual KV Series is used for each pushbutton switch and pilot lamp
(Table 1). When many I/O devices are required for control, expansion units should also be considered.

Circuit 1 Table 1
I/O device Contact No.
RL
PB1 PB2 Pushbutton switch PB1 (N.O. contact) Input relay (0000)
RL Relay (coil)
Relay (contact) Pushbutton switch PB2 (N.C. contact) Input relay (0001)
RL
Relay (contact)
PL
Relay RL Internal relay (1000)
Pilot lamp
Pilot lamp PL Output coil (0500)

Program creation
Edit a program using the "LADDER BUILDER for KV" programming support software creation tool.

Ladder diagram Coding list


0000 0001*
1000 LD 0000
OR 1000
1000 AND 0001
1000
0500 OUT 1000
LD 1000 * Enter "N.O. (AND X001)" to 0001 to
OUT 0500 use N.C. contact.
END

Transferring and confirming the program


Transfer the created program to the Visual KV Series, perform a test run, and then confirm operations
with the actual devices.

Operation

3-2 Chapter 1 Programming

KVNKA Chap 01P.p65 2 08.3.11, 11:49 AM


1.1 Before Creating Programs

1.1.2 Scan Time


Scan time
The Visual KV Series repeatedly executes a ladder based on the sequence circuit
as follows.

Writes the ON/OFF status of all input terminals to the input


Input processing memory before executing the program.

Reads the ON/OFF status of each device (internal utility relay,


timer, counter, etc.) based on the instructions, and performs
Program execution arithmetic operations.
Writes the arithmetic operation result to the output memory.

Outputs the contents of the output memory to output terminals.


Output processing

The duration of time required to perform one cycle is called the scan time (or cycle
time). The scan time varies based on program size and the instructions used in the
program.

Input response time delay


In addition to the I/O processing time, there is also an input time delay in the Visual
11
KV Series caused by the scan time. The input time delay is generated because the
input status can only be read during the input processing time. If the input status is
changed after input processing, the changed contents can only be read during the
next scan time.
In the figure below, 1 and 2 can be read but 3 cannot be read.

1 2 3
Input signal
ON

OFF
Read Read
Output processing

Output processing

Output processing

Output processing

Output processing
Input processing
Input processing

Input processing

Input processing

Input processing

Program Program Program Program


execution execution execution execution

Scan time Scan time

Reference: The maximum and minimum values of the input response time are as
follows.
Maximum value: Input time constant + Scan time x 2 + Output response delay time
Minimum value: Input time constant + Scan time + Output response delay time

Note 1: When the input time constant is made small by setting the HSP instruction,
special utility relay 2813, and data memory DM1940, a signal may not be received if
its ON time is shorter than the scan time.
Note 2: The INT instruction is independent of the scan time.
Note 3: The minimum scan time is 140 µs (with the basic unit).

Chapter 1 Programming 3-3

KVNKA Chap 01P.p65 3 08.3.11, 11:49 AM


1.2 User Memory

1.2 User Memory


This section describes the allowable size (capacity) of a program which can be
created in the Visual KV Series.

1.2.1 Program Capacity


When a user program is created for the Visual KV Series, the maximum number of
steps a program can contain using the mnemonic diagram varies based on the byte
count of the instructions used. The instruction byte count is determined individually
for each instruction.
➮ For more about byte counts for each instruction, refer to "2.1 Instruction List" (p.3-34).

Maximum number of lines in a program


In the KV-10xx/16xx, a program with approximately 2,000 steps can be written. In
the KV-24xx/40xx, a program with approximately 4,000 steps can be written.
• Total byte count of the memory used by instructions ≤ 6,000 bytes / 12,000
bytes
• Total byte count of the memory used by objects of instructions ≤ 12,000
bytes / 24,000 bytes
1 * In the description above, a value on the left side indicates the byte count for
the KV-10xx/16xx, while a value on the right side indicates the byte count for
the KV-24xx/40xx.
* The memory occupied by objects indicates the memory required to execute a
program when operation is started.

For example, the allowable number of steps to be written can be calculated from the
memory occupied by the instructions as follows.
12,000 bytes / 3 bytes (average byte count of an instruction) = 4,000 steps

Note: If either the memory occupied by the instructions or the memory occupied by
objects of a program exceeds the specified memory capacity, the program cannot
be written or executed.

Calculating the byte count used


The byte count used in this program can be calculated as shown in the table below.
0000 #00020
T000

0500 T000 0500

Line No. Instruction Operand Byte count Number of objects


00000 LD 0000 3 5
00001 OR 0500 3 4
00002 TMR 000#00020 2 7
00003 ANB T000 3 8
00004 OUT 0500 3 8
Total 14 bytes 32 bytes

3-4 Chapter 1 Programming

KVNKA Chap 01P.p65 4 08.3.11, 11:49 AM


1.3 Device Configuration

1.3 Device Configuration


"Device" is a general name for relays, registers, etc. processed by instructions.
This section describes the available devices in the Visual KV Series and their
general use.

1.3.1 Device List


Relay list
High-speed
Relay No. Normal use High-speed use (2) Remarks
use (1)
0000 They function as B phase of high-speed
Input relays (Polarity inversion counters through specification of utility relays in
0001 Interrupt inputs KV-10.
(Direct input allowed)
INT0 to INT3
0002 allowed area) Input captures –
0003 –
High-speed High-speed
0004 –
counter 0 input counter 0 A phase
High-speed High-speed input
0005 –
counter 1 input counter 1
High-speed
0006 –
counter 0 B phase
Input relays
High-speed input 11
0007 –
counter 1

High-speed
0008 –
counter 0 Preset
High-speed input
0009 –
counter 1
0010 to 0415 Input relays –
0500 High-speed counter 0 output 70 points
High-speed
Output relays Specified frequency
0501 counter 1 –
(Direct output pulse output
output
allowed area)
0502 Ramp-up/down control output –
0503 – –
0504 to 0915 Output relays 76 points
1000 to 1915 Internal utility relays 160 points
2000 to 2815 Special utility relays 144 points
2900 to 2915 Special utility relays HKEY information storage area
3000 to 17915 Internal utility relays 2,144 points

Note 1: The ON/OFF status of the set functions is always cleared when the opera-
tion mode is changed from PROGRAM to RUN. However, special utility relays 2700
to 2715 are held even when the operation mode is changed from PROGRAM to
RUN or when the power is turned off.
Note 2: Internal utility relays can be held by setting the MEMSW instruction

List of I/O relays in basic units


Model KV-10xx KV-16xx KV-24xx KV-40xx
Basic input relays 0000 to 0005 0000 to 0009 0000 to 0015 0000 to 0107
Basic output relays 0500 to 0503 0500 to 0505 0500 to 0507 0500 to 0515

Chapter 1 Programming 3-5

KVNKA Chap 01P.p65 5 08.3.11, 11:49 AM


1.3 Device Configuration

List of relays in expansion units


■ Input units
Connection KV-E4X KV-E8X KV-E16X
order KV-10/16/24 KV-40 KV-10/16/24 KV-40 KV-10/16/24 KV-40
1st input
100 to 103 200 to 203 100 to 107 200 to 207 100 to 115 200 to 215
module
2nd input
200 to 203 300 to 303 200 to 207 300 to 307 200 to 215 300 to 315
module
3rd input
300 to 303 400 to 403 300 to 307 400 to 407 300 to 315 400 to 415
module
4th input
400 to 403 400 to 407 400 to 415
module

■ Output units
Connection
KV-E4T(P)/R KV-E8T(P)/R KV-E16T(P)/R
order
1st output
600 to 603 600 to 607 600 to 615
module
2nd output
700 to 703 700 to 707 700 to 715
module
3rd output
800 to 803 800 to 807 800 to 815
1 module
4th output
900 to 903 900 to 907 900 to 915
module

■ I/O units
KV-E4XR/T(P)
Connection
Input relays Output relays
order
KV-10/16/24 KV-40 KV-10/16/24 KV-40
1st input
100 to 103 200 to 203
module
2nd input
200 to 203 300 to 303
module
3rd input
300 to 303 400 to 403
module
4th input
400 to 403
module
1st output
600 to 603 600 to 603
module
2nd output
700 to 703 700 to 703
module
3rd output
800 to 803 800 to 803
module
4th output
900 to 903 900 to 903
module

* Relay Nos. of expansion units are automatically assigned in the order of connection.
* The connection order is counted only for input and output units. When I/O units are
connected, they are counted as input units and output units separately.

3-6 Chapter 1 Programming

KVNKA Chap 01P.p65 6 08.3.11, 11:49 AM


1.3 Device Configuration

1.3.2 Relay No.


The relay No. configuration is shown below.

Channel No.

12515
Contact No.
(00 to 15)

Address No.
(Input: 0 to 4, output: 5 to 9)

Address No.
Address Nos. are assigned to basic units, input expansion units, output expansion
units, and I/O expansion units. Zero to 4 are assigned to input units, while 5 to 9 are
assigned to output units. Address Nos. assigned in a unit vary based on the number
of I/O terminals and the connection position of the unit.

Model Address Nos.


KV-10xx 0, 5 11
KV-16xx 0, 5
Basic units
KV-24xx 0, 5
KV-40xx 0, 1, 5
kV-E4X 1 to 4*
Input expansion units KV-E8X 1 to 4*
KV-E16X 1 to 4*
KV-E4R/E4T(P) 6 to 9
Output expansion units KV-E8R/E8T(P) 6 to 9
KV-E16R/E16T(P) 6 to 9
I/O expansion units KV-E4XR/E4XT(P) 1 to 4*, 6 to 9
* 2 to 4 in KV-40xx

■ Address No. assignment procedure


• The address No. is represented as a number 0 to 9.
• Address Nos. 0 to 4 are provided for inputs, while address Nos. 5 to 9 are pro-
vided for outputs.

Chapter 1 Programming 3-7

KVNKA Chap 01P.p65 7 08.3.11, 11:49 AM


1.3 Device Configuration

Contact No.
• Contact Nos. are input/output terminal Nos. of basic units, input expansion units,
output expansion units, and I/O expansion units.
• The contact No. is represented as a number 0 to 15.
Example
In the KV-E4X, with 4 input terminals, the contact Nos. are 0 to 3. In the KV-
E16T(P), with 16 input terminals, the contact Nos. are 0 to 15.
• In a unit with 16 or more terminals, the contact No. of the 17th terminal returns to
0 and its address No. is increased by 1.
Example
In the KV-40AR, with 40 terminals (24 input and 16 output terminals), address
No. 0 is assigned to input terminal Nos. 1 to 16 and address No. 1 is assigned to
input terminal Nos. 17 to 24

Channel No.
The channel No. is the higher order digit in the contact No.

1 1.3.3 Assigning Relay Nos.


When assigning relay Nos., the unit No. is based on the connection position of the
unit, and the address No. is determined based on the unit type and I/O contacts.
a) KV-16AR b) KV-E4X Input c) KV-E8R Output
Basic unit expansion expansion unit
Input: 10 points unit Output: 8 points
Output: 6 points Input: 4 points

With the connections above, the relay Nos. for each unit are assigned as shown in
the table below.
Unit Assigned relay Nos.
a) KV-16AR 0000 to 0009 (input) and 0500 to 0505 (output)
b) KV-E4X 0100 to 0103 (input)
c) KV-E8R 0600 to 0607 (output)

3-8 Chapter 1 Programming

KVNKA Chap 01P.p65 8 08.3.11, 11:49 AM


1.3 Device Configuration

1.3.4 Input Relays


Input relays receive ON/OFF signals sent from external input equipment.

Note 1: Input relays function as contacts in programs. They cannot be used as relay
coils (outputs).
Note 2: There is no restriction of the contact type (N.O. or N.C.) used, the order the
relay Nos. are used, or the number of relays used.

Basic unit
■ Input relay time constant
Though the time constant is usually 10 ms ±20%, it can be changed using the
following settings.
• When the HSP instruction is used: 10 µs ±20%
• While special utility relay 2813 remains ON, the time constant can be changed in
7 steps by setting data memory DM1940 as follows.
When DM1940 is set to 0: 10µs ±20%
1: 20 µs ±20%
2: 500 µs ±20%
3: 1 ms ±20%
4: 2.5 ms ±20% 11
5: 5 ms ±20%
6: 10 ms ±20%
Never set a numeric value of 7 or larger.
➮ For more about changing the input time constant, refer to "1.4.1 Input Time Constant Change
Function" (p.3-23).

■ Hardware input (independent of scan time)


• High-speed counter
When the time constant is set to 10 µs using the HSP instruction or data memory
DM1940 (only while special utility relay 2813 remains ON), the maximum input
response of input relays 0004 and 0005 of CTH0 and CTH1 becomes 30 kHz.
• INT instruction: 0000 to 0003
This instruction can receive any signal without regard to the scan time as far as
the signal ON time is longer than the input time constant.

➮ "HSP instruction" (p.3-86), "INT instruction" (p.3-192), "4.1 High-speed Counter Instructions"
(p.3-204)

Note 1: While special utility relay 2813 remains ON, the input time constant can be
specified for all input relays in a basic unit.
Note 2: Never enter a number of 7 or larger to data memory DM1940.
Note 3: The input time constant specified by data memory DM1940 becomes
effective at the rising edge of special utility relay 2813. To change the input time
constant, first change data memory DM1940, then set special utility relay 2813 to
OFF and ON again. Or change the operation mode of a KV basic unit from PRO-
GRAM to RUN.
Note 4: If the HSP instruction and special utility relay 2813 are used at the same
time, priority is given to the HSP instruction.
Note 5: Only when a high-speed counter input or INT instruction is given, available
input signals do not depend on the scan time.

Chapter 1 Programming 3-9

KVNKA Chap 01P.p65 9 08.3.11, 11:49 AM


1.3 Device Configuration

Expansion unit
■ Input relay time constant
By setting special utility relays 2609 to 2612 to ON, the time constant in input expan-
sion units can be set to 10 µs.
Special utility
Function
relay No.
Input time constant of input expansion unit
2609* OFF: 10 ms, ON: 10 µs
with relay Nos. 0100 to 0115
Input time constant of input expansion unit
2610 OFF: 10 ms, ON: 10 µs
with relay Nos. 0200 to 0215
Input time constant of input expansion unit
2611 OFF: 10 ms, ON: 10 µs
with relay Nos. 0300 to 0315
Input time constant of input expansion unit
2612 OFF: 10 ms, ON: 10 µs
with relay Nos. 0400 to 0415
* Not available with the KV-40xx

1.3.5 Output Relays


Output relays output the program execution results to the outside. There are two
types of outputs, relay and transistor.

1 Note 1: Output relays function as contacts and relay coils in programs.


Note 2: There is no restriction of the contact type (N.O. or N.C.) used, the order the
relay Nos. are used, or the number of relays used.

Output operation time


• Transistor output
OFF ➞ ON: 50 µs or less (10 µs or less in 500 to 502)
ON ➞ OFF: 250 µs or less (10 µs or less in 500 to 502, 100 µs or less for other
outputs in the basic unit)

• Relay output
OFF ➞ ON: 10 ms or less
ON ➞ OFF: 10 ms or less

Transistor output type Relay output type


KV-10AT(P)/DT(P) KV-16AT(P)/DT(P) KV-10AR/DR KV-16AR/DR
KV-24AT(P)/DT(P) KV-40AT(P)/DT(P) KV-24AR/DR KV-40AR/DR
KV-E4T KV-E8T(P) KV-E4R KV-E8R
KV-E16T(P) KV-E4XT(P) KV-E16R KV-E4XR

Note 1: When programming direct clock pulses, output relays 0500 and 0501 are
used to output pulses in a transistor-type output unit.
Note 2: When the ramp-up/down control function is used, output relay 0502 outputs
positioning pulses in a transistor-type output unit.
➮ "Chapter 5. Positioning Control" (p.3-253)
Note 3: When the specified frequency pulse output function is used, output relay
0501 outputs pulses in a transistor-type output unit.
➮ "4.5.1 Specified Frequency Pulse Output Function" (p.3-228)

3-10 Chapter 1 Programming

KVNKA Chap 01P.p65 10 08.3.11, 11:49 AM


1.3 Device Configuration

1.3.6 Internal Utility Relays


In a relay circuit, when one relay contact is used twice or more inside the circuit, a
multi-pole relay with the same number of poles as the number used may be needed.
Internal utility relays function only in programs, and eliminate the complexity of relay
circuits to facilitate circuit design.

Note 1: Internal utility relays function as contacts and relay coils in programs.
Note 2: There is no restriction of the contact type (N.O. or N.C.) used, the order the
relay Nos. are used, or the number of relays used.

Retentive function of internal utility relays


Except for internal utility relays, all relays turn OFF when the operation mode is
changed or when operation is stopped via a power shutdown. When operation is
restarted, all relays remain OFF except relays whose input condition is ON. How-
ever, internal utility relays can be set using the MEMSW (memory switch) whether or
not they are to be retained. (Internal utility relays 2700 to 2715, however, are always
retained.)

When an internal utility relay is set to be retained, its ON/OFF status is stored even if
the power is turned off. By using the retained relay all clear function (FUN65), all
relays which are set to be retained can be set to OFF. 11
➮ For more about setting the memory switch, refer to "MEMSW instruction" (p.3-92).

Application example of a retentive function: Lift vertical movement control


Internal utility relays 1000 and 1001 are set to be retained.
When the upper/lower limit switch turns ON, the direction of lift movement is
inverted. Even if the power is turned off while the lift is moving up (or down), the lift
continues to move up (or down) when the power is turned on again.

MEMSW
$0004

0000 0001 1000


Upper limit
switch
1000 #00010
(0000) T000

0001 0000 1001

1001 #00010
Lower limit T001
switch
(0001) T000 0501 0500
Move-down
(0500)
T001 0500 0501

END
Move-up
(0501) ENDH

Note: The retentive function is effective only when internal utility relays retained by
the self-retentive circuit or the SET/SFT/KEEP instruction are also retained by the
memory switch.
Internal utility relays are not retained in the program shown below.

0000 1001

Chapter 1 Programming 3-11

KVNKA Chap 01P.p65 11 08.3.11, 11:49 AM


1.3 Device Configuration

1.3.7 Special Utility Relays


Each special utility relay has a unique function. By using special utility relays effec-
tively, programs can be simplified and program control improved.

Note 1: A special utility relay can be used as many times as desired in one program.
Note 2: Special utility relays dedicated for reading can be used as contacts, but
cannot be used as outputs.
➮ For more about relays dedicated for reading, refer to "1.3.8 Special Utility Relay List" (p.3-14).

Description
Relay 2002: Always ON
By setting an output relay to ON using relay 2002, the output relay can be used as a
"running indicator output".

2002 HSP
0100

2002 00000
LDA

DM0000
STA

Set the input time constant of relay 0100 to 10 µs.


1 Transfer the ON/OFF status data of channel 0000 to DM0000.

Relay 2003: Always OFF.


Opposite that of relay 2002, use relay 2003 where it is not required to be turned on.
For example, when using only the up function of an up/down counter, use relay 2003
in the DW (down) input.

Relays 2004, 2005 and 2006: Clock pulse


For each relay, the time ratio is "ON:OFF = 1:1". (Accordingly, the ON time of relay
2005 is 0.05 sec/pulse.)
However, because these relays depend on the scan time, error as much as the scan
time is generated.

• By combining an output relay, an "intermittent output" can be made.


• By using relay 2006 as input for a counter, the counter can be used as a long-
term timer.

1000 #03600
C000
2006
C000 1000

1000 turns ON at every hour.

Relay 2007: Remains OFF during only one scan when operation is started.
This relay can be used when a signal needs to be sent after a specific period
(equivalent to one scan) after operation is started. This relay can also be used for
an initial reset at the start of operation.
After one scan, this relay remains ON.

1000 2007 #00100


C005
0000

When operation is started, this relay returns


the current value of C005 to 0.

3-12 Chapter 1 Programming

KVNKA Chap 01P.p65 12 08.3.11, 11:49 AM


1.3 Device Configuration

Relay 2008: Remains ON during only one scan when operation is started.
This relay can be used for an initial reset at the start of operation.
After one scan, this relay remains OFF.

0000 SFT
D
1100
1000
CLK
1100
2008
RES

When operation is started, this relay sets all internal


utility relays used by the SFT instruction to OFF.

2008 #00000
LDA

DM0000
STA

When operation is started, this relay returns the current


value of DM0000 to 0.

Relay 2813: Sets the input time constant of the CPU.


While relay 2813 remains ON, the input time constant of a basic unit can be set
using the value of DM1940. 11

Chapter 1 Programming 3-13

KVNKA Chap 01P.p65 13 08.3.11, 11:49 AM


1.3 Device Configuration

1.3.8 Special Utility Relay List


Special relays and arithmetic operation flags
➮ "1.3.7 Special Utility Relays" (p.3-12)
Relay No. Function
2002* Always ON.
2003* Always OFF.
2004* 0.01-s clock pulse (duty cycle: 50%)
2005* 0.1-s clock pulse (duty cycle: 50%)
2006* 1.0-s clock pulse (duty cycle: 50%)
2007* Remains OFF during first scan after startup.
2008* Remains ON during first scan after startup.
Turns ON when result of arithmetic operation is negative or when an
2009*
overflow is generated.
2010* Turns ON when result of arithmetic operation is 0.
2011* Turns ON when result of arithmetic operation is positive.
2012* Turns ON when an arithmetic operation generates an error.
* Read-only relay.

Special utility relays for high-speed counter(0)


1
➮ "Chapter 4. High-Speed Counters" (p.3-203)

Relay No. Function


2100* Internal clock used only for CTH0 (1 µs)
2101* Internal clock used only for CTH0 (10 µs)
2102* Internal clock used only for CTH0 (100 µs)
2103 Automatic clear of CTH0 when comparator CTC0 ON: Cleared
turns ON. OFF: Not cleared
2104 Prohibits/permits direct output to 0500 when ON: Prohibited
comparator CTC0 turns ON. OFF: Permitted
2105 Direct output to 0500 is set to OFF when comparator ON: Set to OFF
CTC0 turns ON. OFF: Not set to OFF
2106 Direct output to 0500 is set to ON when comparator ON: Set to ON
CTC0 turns ON. OFF: Not set to ON
2107 ON/OFF status of output to 0500 is reversed each ON: Reversed
time comparator CTC0 turns ON. OFF: Not reversed
2108 Prohibits/permits direct output to 0500 when ON: Prohibited
comparator CTC1 turns ON. OFF: Permitted
2109 Direct output to 0500 is set to OFF when comparator ON: Set to OFF
CTC1 turns ON. OFF: Not set to OFF
2110 Direct output to 0500 is set to ON when comparator ON: Set to ON
CTC1 turns ON. FF: Not set to ON
2111 ON/OFF status of output to 0500 is reversed each ON: Reversed
time comparator CTC1 turns ON. OFF: Not reversed
2112 Automatic clear of CTH0 when comparator CTC1 ON: Cleared
turns ON. OFF: Not cleared
2113 Selects multiplication mode for comparator CTH0.
OFF ON OFF ON
2114 OFF: 1 pulse OFF: x2 ON: x4 ON: 2 pulses
* Read-only relay.
Multiplication
1 pulse x2 x4 2 pulses
mode
2113 OFF ON OFF ON
2114 OFF OFF ON ON

Note: Never use special utility relays that are not shown above.

3-14 Chapter 1 Programming

KVNKA Chap 01P.p65 14 08.3.11, 11:49 AM


1.3 Device Configuration

Special utility relays for high-speed counter(1)


➮ "Chapter 4. High-Speed Counters" (p.3-203)
Relay No. Function
2200* Internal clock used only for CTH1 (1 µs)
2201* Internal clock used only for CTH1 (10 µs)
2202* Internal clock used only for CTH1 (100 µs)
2203 Automatic clear of CTH1 when comparator CTC2 ON: Cleared
turns ON. OFF: Not cleared
2204 Prohibits/permits direct output to 0501 when ON: Prohibited
comparator CTC2 turns ON. OFF: Permitted
2205 Direct output to 0501 is set to OFF when comparator ON: Set to OFF
CTC2 turns ON. OFF: Not set to OFF
2206 Direct output to 0501 is set to ON when comparator ON: Set to ON
CTC2 turns ON. OFF: Not set to ON
2207 ON/OFF status of output to 0501 is reversed each ON: Reversed
time comparator CTC2 turns ON. OFF: Not reversed
2208 Prohibits/permits direct output to 0501 when ON: Prohibited
comparator CTC3 turns ON. OFF: Permitted
2209 Direct output to 0501 is set to OFF when comparator ON: Set to OFF
CTC3 turns ON. OFF: Not set to OFF
2210 Direct output to 0501 is set to ON when comparator ON: Set to ON
CTC3 turns ON. OFF: Not set to ON 11
2211 ON/OFF status of output to 0501 is reversed each ON: Reversed
time comparator CTC3 turns ON. OFF: Not reversed
2212 Automatic clear of CTH1 when comparator CTC3 ON: Cleared
turns ON. OFF: Not cleared
2213 Selects multiplication mode for comparator CTH1.
OFF ON OFF ON
2214 OFF: 1 pulse OFF: x2 ON: x4 ON: 2 pulses
* Read-only relay.
Multiplication
1 pulse x2 x4 2 pulses
mode
2213 OFF ON OFF ON
2214 OFF OFF ON ON

Note: Never use special utility relays that are not shown above.

Other special utility relays


Relay No. Function
External outputs disabled ON: Disabled
2300
(outputs 0500 to 0915) OFF: Not disabled
External refresh inputs disabled ON: Disabled
2301
(inputs 0000 to 0415) OFF: Not disabled
Constant scan time mode ON: Enabled
2303
(write preset value in TM29) OFF: Disabled
Remains ON for one scan when scan time exceeds
2304
preset constant scan time.
2305 Start flag for frequency counter operation.
ON: Enabled
2306 Specified frequency pulse output
OFF: Disabled
2307 Error flag for specified frequency pulse output
2308 Stops motor driver when turned ON.
Turns ON when motor driver is in operation. Stops motor driver in
2309
emergencies when turned OFF by interrupt instruction.
2310 Starts motor driver when turned ON (detection at rising edge).
2314 Start flag for cam switch operation.
2315 Turns ON when an error occurs in cam switch operation.
* Read-only relay.

Chapter 1 Programming 3-15

KVNKA Chap 01P.p65 15 08.3.11, 11:49 AM


1.3 Device Configuration

Relay No. Function


Timing of CTH0 external signal
2400
OFF External preset OFF ON ON
At falling edge At rising edge Level
2401 OFF not used ON OFF ON
Interrupt polarity of INT
2402
OFF OFF ON ON
At rising edge At falling edge At rising edge At both edges
2403 OFF ON OFF ON
Interrupt polarity of INT1
2404
OFF OFF ON ON
At rising edge At falling edge At rising edge At both edges
2405 OFF ON OFF ON
2406 CTH0 set as ring counter ON: Set OFF: Not set
Ignore phase B input when CTH0 is set to no multiplication mode.
2407 ON: Ignore phase B input and always count up.
OFF: Use phase B input as usual.
Timing of CTH1 external preset
2408
OFF External preset OFF ON ON
At falling edge At rising edge Level
2409 OFF not used ON OFF ON
Interrupt polarity of INT2
2410
OFF OFF ON ON
At rising edge At falling edge At rising edge At both edges
2411 OFF ON OFF ON
Interrupt polarity of INT3
2412
OFF OFF ON ON
At rising edge At falling edge At rising edge At both edges
2413 OFF ON OFF ON

1 2414 CTH1 set as ring counter ON: Set OFF: Not set
Ignore phase B input when CTH1 is set to no multiplication mode.
2415 ON: Ignore phase B input and always count up.
OFF: Use phase B as usual.

2500 Customized switch [F1] on KV-D20 operator interface panel is assigned.


2501 Customized switch [F2] on KV-D20 operator interface panel is assigned.
2502 Customized switch [F3] on KV-D20 operator interface panel is assigned.
2503 Customized switch [F4] on KV-D20 operator interface panel is assigned.
Customized indicator lamp 1 on KV-D20 operator interface panel is
2504
assigned.
Customized indicator lamp 2 on KV-D20 operator interface panel is
2505
assigned.
Customized indicator lamp 3 on KV-D20 operator interface panel is
2506
assigned.
Customized indicator lamp 4 on KV-D20 operator interface panel is
2507
assigned.
Permits change between operator
OFF: Not
2508 mode and device mode of KV-D20 ON: Permitted
permitted
operator interface panel .
Permits the KV-D20 operator interface
OFF: Not
2509 panel to be shifted between operator ON: Permitted
permitted
mode and system mode.
Specifies the display language for the
2510 ON: Japanese OFF: English
KV-D20 operator interface panel
Sets the beep for the KV-D20 operator
2511 ON: Use beep OFF: No beep
interface panel
2512 Reserved for system
2513 Reserved for system
Displays a user message (contents of ON: Display OFF: Do not
2515
DM1950) in the Access Window message display message

3-16 Chapter 1 Programming

KVNKA Chap 01P.p65 16 08.3.11, 11:49 AM


1.3 Device Configuration

Relay No. Function


Input time constant of input expansion unit with relay OFF: 10 ms
2609
Nos. 0100 to 0115 ON: 10 µs
Input time constant of input expansion unit with relay OFF: 10 ms
2610
Nos. 0200 to 0215 ON: 10 µs
Input time constant of input expansion unit with relay OFF: 10 ms
2611
Nos. 0300 to 0315 ON: 10 µs
Input time constant of input expansion unit with relay OFF: 10 ms
2612
Nos. 0400 to 0415 ON: 10 µs
OFF: Cleared
2613 Clearing of input at expansion disconnect
ON: Not cleared
This area is stored
even when the
Disconnect error OFF: Normal operation mode is
2712 changed from
ON: Disconnection in connected unit
PROGRAM to RUN,
or when the power is
turned off (without
being affected by the
MEMSW instruction).
Use of high-speed input correction circuit
2714 This area is not
ON: Used OFF: Not used cleared even if the
utility relay All Clear
function is activated.
However, this area is
cleared when an All 11
2715 ON while cam switch is in operation. Clear is executed
without registering a
program.
2800 Break signal send to communication port A (remains ON while sending).
Receives text data from communication port A, and remains ON during only
2801
1 scan while receiving text data.
Communication port A text data acceptance error. Remains ON during only
2802 1 scan ON when text data is received while either relay 2801 or relay 2803
is ON.
Communication port A text data receive error
2803
Remains ON during only 1 scan when a text data receive error occurs.
2804 Communication port A text data send start (remains ON during sending.)
2805 Break signal send to communication port B (remains ON while sending).
Receives communication port B text data, and remains ON during only 1
2806
scan while receiving text data.
Communication port B text data acceptance error.
2807 Remains ON during only 1 scan ON when text data is being received while
relay 2806 or relay 2808 is ON.
Communication port B text data receive error
2808
Remains ON during only 1 scan when a text data receive error occurs.
2809 Communication port B text data send start (remains ON during sending.)
2812 Turns ON when an abnormality occurs with backup battery.
Sets input time constant to all inputs in basic module (except inputs used by
HSP instruction).
2813
OFF: Sets input time constant to 10 ms.
ON: Refers to value stored in DM1940, then determines input time constant.
2814 HKEY instruction: Multiple keys are prohibited.
2815 HKEY instruction: Scan is finished.
2900 to 2915 HKEY information storage area.

Note: Never use special utility relays that are not shown above.

Chapter 1 Programming 3-17

KVNKA Chap 01P.p65 17 08.3.11, 11:49 AM


1.3 Device Configuration

1.3.9 Timers and Counters


Timers and counters can be set in a program, and their outputs can be used as
contacts elsewhere in the program. [There is no restriction on the contact type (N.O.
or N.C.) and the order of use.]
A same number can be assigned to only one timer or counter. For example, T005
and C005 cannot be used in the same program.

Timer/Counter list
Coil
Name Contact Number
(instruction)
Timer (0.1-s timer) TMR000 to 249
High-speed timer
TMH000 to 249
Timer (0.01-s timer) T000 to T249
High-speed 1-ms timer 250 in total
TMS000 to 249
(0.001-s timer)
Counter C000 to 249
Counter C000 to C249
Up/down counter UDC000 to 249

Description
1 ■ Timers
• When 0.1-s timers (TMR) and high-speed 0.001-s timers (TMS) are used as
contacts, the "Tnnn" No. is used for both types. However, the form for setting is
different. "TMRnnn#ddddd" is used for 0.1-s timers, "TMHnnn#ddddd" is used for
high-speed 0.01-s timers, and "TMSnnn#ddddd" is used for high-speed 1-ms
timers (nnn = timer No, ddddd = timer set value).
• In a single program, different timer Nos. must be assigned to each of TMRnnn,
TMHnnn, and TMSnnn.
• When the PLC is stopped, all timers are reset and their current values become
equivalent to set values.

■ Counters
• When counters (C) and up/down counters (UDC) are used as contacts, the
"Cnnn" No. is used for both types. However, the form for setting is different.
"Cnnn#ddddd" is used for counters, while "UDCnnn#ddddd" is used for up/down
counters.
• In one program, different numbers must be assigned to each of the counters and
up/down counters.
• Even when operation is stopped, each counter stores whatever value it has at
that time.
➮ "TMR instruction" (p.3-67), "TMH instruction" (p.3-68), "TMS instruction" (p.3-69), "C instruction" (p.3-
72), "UDC instruction" (p.3-76).

■ High-speed counters and high-speed counter comparators


The Visual KV Se ries is equipped with two high-speed counters (CTH0 and CTH1)
and four high-speed counter comparators (CTC0, CTC1, CTC2, and CTC3) with a
30-kHz input response speed (frequency), two phases, and size of 16 or 24 bits.

Note: When a high-speed counter or high-speed counter comparator will be used as


a 24-bit device, a set value is required to be stored in a data memory using the
MEMSW instruction.
➮ For details about high-speed counters and high-speed counter comparators, refer to "Chapter 4 High-
speed Counters" (p.3-203).

3-18 Chapter 1 Programming

KVNKA Chap 01P.p65 18 08.3.11, 11:49 AM


1.3 Device Configuration

1.3.10 Data Memories


Data memories store various types of data.
Data memories are not usually used in a program that consists of contacts, coils,
timers, and counters. When arithmetic instructions are used, however, data memo-
ries can be used to store data for arithmetic operations as well as the results of
arithmetic operations.

DM No. Description
DM0 to DM999 Not specified (can be used by user)
DM1000 to DM1099 Text receive port A
DM1100 to DM1199 Text send port A
DM1200 to DM1299 Text receive port B
DM1300 to DM1399 Text send port B
DM1400 Cam switch function: The first output relay No.
Cam switch function: Comparison value in multi-step comparator
DM1401
mode
Cam switch function: Pulse count of one cycle of equipment input
DM1402
to CTH0
DM1403 Not specified (can be used by user)
DM1404 Measurement cycle (ms)
DM1405 Result of frequency count (Hz) 11
Cam switch function: Set value of angle at which output relay
DM1406/DM1407
turns ON/OFF
Cam switch function: Set value of angle at which output relay +1
DM1408/DM1409 turns ON/OFF
: :
DM1468/DM1469 Cam switch function: Set value of angle at which output relay +31
turns ON/OFF
DM1470 Reserved by system (cannot be used by user)
DM1471 to DM1479 Not specified (can be used by user)
Ramp-up/down control function: Startup frequency (Hz) (200 to
DM1480
50,000)
Ramp-up/down control function: Operating frequency (Hz) (200 to
DM1481
50,000)
Ramp-up/down control function: Acceleration time (ms)
DM1482
(0 to 4,000)
DM1483 Not specified (can be used by user)
Ramp-up/down control function: Output pulse count (lower digit)
DM1484
(0 to 65,535)
Ramp-up/down control function: Output pulse count (upper digit)
DM1485
(0 to 65,535)
DM1486 Ramp-up/down control function: Error code (11 to 17)
DM1487 to DM1499 Not specified (can be used by user)
DM1565 to DM1569 Not specified (can be used by user)
DM1578 and DM1579 Not specified (can be used by user)
DM1580 to DM1599 KV-D20 Operator interface panel: Display device No.
DM1664 to DM1699 Not specified (can be used by user)
DM1670 to DM1675 Reserved by system (cannot be used by user)
KV-D20 Operator interface panel: Screen shift permission setting
DM1676
in operator mode

Chapter 1 Programming 3-19

KVNKA Chap 01P.p65 19 08.3.11, 11:49 AM


1.3 Device Configuration

DM No. Description
Area for direct access mode for the KV-D20 operator interface
DM1677 to DM1679
panel
DM1680 to DM1699 KV-D20 Operator interface panel: Display device attributes
DM1764 to DM1799 Not specified (can be used by user)
DM1806 to DM1809 Not specified (can be used by user)
DM1826 to DM1899 Not specified (can be used by user)
DM1900/DM1901* 24-bit value read from CTH0 (lower digit/upper digit)
DM1902/DM1903* 24-bit value read from CTH1 (lower digit/upper digit)
DM1904/DM1905* 24-bit value read from CTC0 (lower digit/upper digit)
DM1906/DM1907* 24-bit value read from CTC1 (lower digit/upper digit)
DM1908/DM1909* 24-bit value read from CTC2 (lower digit/upper digit)
DM1910/DM1911* 24-bit value read from CTC3 (lower digit/upper digit)
DM1912/DM1913 24-bit current value written to CTH0 (lower digit/upper digit)
DM1914/DM1915 24-bit current value written to CTH1 (lower digit/upper digit)
DM1916/DM1917 24-bit current value written to CTC0 (lower digit/upper digit)
DM1918/DM1919 24-bit current value written to CTC1 (lower digit/upper digit)
DM1920/DM1921 24-bit current value written to CTC2 (lower digit/upper digit)
DM1922/DM1923 24-bit current value written to CTC3 (lower digit/upper digit)
DM1924/DM1925 CTH0 preset input (lower digit/upper digit)
1 DM1926/DM1927 CTH1 preset input (lower digit/upper digit)
DM1928/DM1929* Input capture when INT0 is generated (lower digit/upper digit)
DM1930/DM1931* Input capture when INT1 is generated (lower digit/upper digit)
DM1932/DM1933* Input capture when INT2 is generated (lower digit/upper digit)
DM1934/DM1935* Input capture when INT3 is generated (lower digit/upper digit)
DM1936 Specified frequency pulse output function: Set frequency (Hz)
DM1937 I/O expansion unit connection information
DM1938 Digital trimmer No. 0: Upper limit value
DM1939 Digital trimmer No. 1: Upper limit value
Input time constant setting
0: 10 µs 1: 20 µs 2: 500 µs
DM1940
3: 1 ms 4: 2.5 ms 5: 5 ms 6: 10 ms
Any other value cannot be set.
DM1941 to DM1943 Reserved by system (cannot be used by user)
Number of instructions converted into 1 scan when division
DM1944
conversion is performed
DM1945 to DM1949 Not specified (can be used by user)
DM1950 Access window error display (0 to 255)
DM1951 to DM1999 Not specified (can be used by user)
* Read-only relay.

Note 1: 16-bit binary data is stored in each of the data memories as for internal
registers.
Note 2: The data stored in data memories is held even when the power is turned off
or when the All Clear function is executed. The backup time is 20 days or more in
the KV-10xx, and 2 months or more in other models.
Note 3: DM1000 to DM1999 are assigned as special data memories.

3-20 Chapter 1 Programming

KVNKA Chap 01P.p65 20 08.3.11, 11:49 AM


1.3 Device Configuration

1.3.11 Temporary Data Memory


These data memories are used for temporary storage. When arithmetic instructions
are used, temporary data memories can be used to temporarily store the data for
arithmetic operations as well as the results of arithmetic operations.
TM No. Usage Attribute
TM00 Used for arithmetic operations (DIV/MUL) R/W
TM01 Used for arithmetic operations (DIV) R/W
TM02 to TM27 Not specified (can be used by user) R/W
Stores scan time (module: 1 ms) beyond set value while
TM28 R*
constant scan time operation is performed.
Stores set value (module: 1 ms) of constant scan time
TM29 R/W
operation
TM30 Stores CTC0 value when INT3 interruption is given. R*
Stores measured scan time (mean value of every 10
TM31 R
scans) (module: 0.1 ms).

Attribute R: Read W: Write

* Both R and W are enabled when special functions are not used.

Note 1: Temporary data memories are initialized when the power is turned on.
Note 2: TM20, TM30, and TM31 are read-only, so cannot be used for writing.
11
However, TM28 can be used for both reading and writing if special functions are not
used.
Note 3: TM00 and TM01 are used by the MUL and DIV instructions. Never use them
for any other purpose.

Chapter 1 Programming 3-21

KVNKA Chap 01P.p65 21 08.3.11, 11:49 AM


1.3 Device Configuration

1.3.12 Relay Nos. and Functions


Assignment of Relay Nos.
The components of a relay no. are shown below.

0 7 5 1 5
Channel No. Relay No. (00 to 15)

Module No. (07 to 17)


Address No. Input (0 to 4)
Output (5 to 9)

■ Unit Nos.
Unit nos. are assigned to units within the KV-300 system, with the unit connected to
the right of the KV-300 CPU (see the figure below) assigned as no. 7. The CPU is
assigned as unit no. 0.

Power supply unit CPU


0 7 8 9 16 17

■ Address Nos.
Address nos. are assigned to the input units, output units, and I/O terminal units.
The following table shows the assignment of address nos. to units.

Unit Address No.


KV-300 CPU CPU 0, 5
KV-C16X 16-input unit 0
KV-C32X 32-input unit 0. 1
KV-B16R 16-output unit 5
KV-B16S 16-output unit 5
KV-C32T 32-output unit 5, 6
KV-R8X 8-input terminal unit 0 to 4 *
KV-R16X 16-input terminal unit
KV-R8R 8-output terminal unit 5 to 9 *
KV-R16R 16-output terminal unit
KV-R8T 8-output terminal unit
KV-R16T 16-output terminal unit

* The KV-R1A I/O Distribution Unit accommodates 5 input units and 5 output units.
Addresses are set with address switches.

3-22 Chapter 1 Programming

KVNKA Chap 01P.p65 22 08.3.11, 11:49 AM


1.4 Special Functions

1.4 Special Functions


This section describes special functions to set and confirm operations on the Visual
KV Series, and useful functions for program debugging and adjustment of external
equipment.

1.4.1 Input Time Constant Change Function


The input time constant can be changed when a signal is read from an input contact.
When connecting external equipment which has no contact in which chattering such
as transistor outputs does not occur, and inputting pulses of short width, the input
time constant change function can be used to decrease the input time constant.

Setting the input time constant for basic units using special utility relays
The input time constant for a basic unit can be changed using data memory DM1940
and special utility relay 2813.
Though the input time constant is usually 10 ms, it can be changed to a value that
corresponds to the number stored in DM1940 by setting special utility relay 2813 to
ON.
If the HSP instruction and special utility relay 2813 are used at the same time,
priority is given to the HSP instruction and the number stored in DM1940 is ignored.
11
■ Special utility relay 2813
OFF: Sets the input time constant to 10 ms.
ON: Refers to the number stored in DM1940, then determines the input time
constant.
Number stored in DM1940 Input time constant
0 10 µs
1 20 µs
2 500 µs
3 1 ms
4 2.5 ms
5 5 ms
6 10 ms
7 or more Not allowed

Note 1: Be sure to set the input time constant to 10 µs when using the 30-kHz high-speed
counter input.
Note 2: Never enter a number that is 7 or larger to data memory DM1940.
Note 3: The input time constant specified by data memory DM1940 becomes effective at the
rising edge of special utility relay 2813.
To change the input time constant, first change data memory DM1940, then set special utility
relay to OFF and ON again. Or change the operation mode of the KV basic unit from
PROGRAM to RUN.
Note 4: The input time constant for input relays set by the HSP instruction is 10 µs.
➮ For more about the HSP instruction, refer to "HSP instruction" (p.3-86).
➮ For more about setting the input time constant for expansion units, refer to "Input time
constant for expansion units" (p.1-76).
Note 5: Set the special utility relay using the SET/RES instructions.
Note 6: When the input time constant is set to 1 ms or less, connect the output equipment
without contacts. If connecting output equipment with contacts, contact bounds may enter.
Note 7: Except for interrupts and high-speed counters, signals whose ON time is shorter than
the scan time may not be received even if the input time constant is set to a small value.

Chapter 1 Programming 3-23

KVNKA Chap 01P.p65 23 08.3.11, 11:49 AM


1.4 Special Functions

1.4.2 Modifying the Input Relay Time Constant KV-300 PLC Only

■ Modifying with External Switches

KV-C32X/C16X KV-R16X/R8X

Input time constant


selection switch
1 ms
4 0 ms 10 ms
3

2
24V 5V 0 ms 10 ms
1
0
1 ms

As shown in above figures, an external switch can be used to select the input time
constant only on the KV-C32X/C16X Connector Input Units and KV-R16X/R8X I/O
Terminal Units.

1 In the following table, white represents the switch position.

Input time constant KV-C32X/C16X KV-R16X/R8X


0ms 1ms 10ms
25 µs ±20%
0ms 1ms 10ms
0ms 1ms 10ms
1 ms ±20% 0ms 1ms 10ms
0ms 1ms 10ms
10 ms ±20% 0ms 1ms 10ms

Note: Connect a solid-state contact output device when the input time constant is
set to 1 ms for 25 µs. Connection of a contact output device may result in contact
bounce.

Modification within the CPU


The input time constant for KV-300 CPU input relay nos. 0000 to 0009 can be
modified in the program.

Input time constant Setting


10 µs ±20% Turn ON special utility relay 2813 (0000 to 0009).
25 µs ±20% Use the HSP instruction.
10 ms ±20% Default

Note 1: When using the 30 kHz high-speed counter input, turn ON special utility
relay 2813.
Note 2: When special utility relay 2813 is ON, the input time constant of input relays
0000 to 0009 is set to 10 µs ±20%.
Note 3: The input time constant remains 10 ms ±20% if the HSP instruction is used
when special utility relay 2813 is ON.
Note 4: When the input time constant is set to 10 µs or 25 µs, a solid-state output
device must be connected. Connection of a contact output device may result in
contact bounce.

3-24 Chapter 1 Programming

KVNKA Chap 01P.p65 24 08.3.11, 11:49 AM


1.4 Special Functions

1.4.3 Constant Scan Time Mode


This function executes a program while keeping the scan time at a constant value
which usually changes based on the processing contents. This section describes
how to set this function.

Though the scan time changes usually depending on the processing contents, it can
be kept at a constant value by using this function. This function can be used to
acquire data from external equipment at a constant time interval.
The set value should be longer than the maximum scan time because the scan time
is kept at a constant value until the end of processing.

■ Setting procedure
Set the desired scan time to temporary data memory TM29.
Set special utility relay 2303 to ON.
The scan time is written to TM31.
The scan time can be set in 1-ms increments.
Enter the desired scan time (ms) to the temporary data memory.

■ Setting example
In this example, the scan time is kept at 20 ms.

11
2008 #00020 TM29 2303
LDA STA SET

Note 1: Be sure to set the constant scan time value so it is larger than the actual
scan time.
Note 2: If the actual scan time exceeds the set scan time, special utility relay 2304
turns ON (during the next 1 scan) while the actual scan time is written to TM28 (unit:
1 ms).
Note 3: The scan time can be set up to 200 ms in temporary data memory TM29. If
a value larger than 200 ms is input, it will be treated as 200 ms.

Chapter 1 Programming 3-25

KVNKA Chap 01P.p65 25 08.3.11, 11:49 AM


1.4 Special Functions

1.4.4 Output Disabled Function


This function disables outputs from each unit in RUN mode without regard to the
program used. By disabling external outputs, the program can be debugged while
external equipment is connected, even when output of signals to the external
equipment is not desired.

■ Setting procedure
When special utility relay 2300 turns ON, all outputs from all output relays (0500 to
0915) to the outside are cleared after 1 scan is finished.
However, the display in the Access Window and the output indicator lamps are not
cleared.

■ Setting example
By setting/resetting special utility relay 2300 using the Access Window, the "KV
IncrediWare (DOS)" or "LADDER BUILDER for KV" programming support software,
or the KV-P3E(01) handheld programmer, the external output prohibition function
can be used.
External outputs are prohibited while input 0000 is ON. External outputs are permit-
ted, though, while input 0000 is OFF.

0000 2300

1
➮ For more about operating procedures, refer to the "Chapter 6. Handheld Programmer" (p.1-195).

1.4.5 Input Refresh Disabled Function


This function disables the update of inputs from each unit triggered by input signals
from external equipment.
By disabling external input refresh, inputs from each unit can be set to ON/OFF in
monitor status without mechanical operations to enable a program check.

■ Setting procedure
When special utility relay 2301 turns ON, input refresh (read of input relays) for all
input relays (0000 to 0415 used by the QL Series) is skipped.
In this status, inputs can be set to ON/OFF from the Access Window, the "KV
IncrediWare (DOS)" or "LADDER BUILDER for KV" programming support software,
or the KV-P3E(01) handheld programmer.

■ Setting example
By setting/resetting special utility relay 2301 using the Access Window, the "KV
IncrediWare (DOS)" or "LADDER BUILDER for KV" programming support software,
or the KV-P3E(01) handheld programmer, the external input refresh prohibition
function can be used.
External input refresh is prohibited while input 0000 is ON. External input refresh is
permitted, though, while input 0000 is OFF.
0000 2301

➮ For more about operating procedures, refer to the "Chapter 6. Handheld Programmer" (p.1-195).

Note: Once external input refresh is prohibited, it can be permitted only by setting
special utility relay 2301 to OFF from the Access Window, the "KV IncrediWare
(DOS)" or "LADDER BUILDER for KV" programming support software, or the KV-
P3E(01) handheld programmer.

3-26 Chapter 1 Programming

KVNKA Chap 01P.p65 26 08.3.11, 11:49 AM


1.5 Extended Ladder Diagrams

1.4.6 Contact Comment Save Function


• This function transfers contact comments to the Visual KV Series using the "KV
IncrediWare (DOS)" or "LADDER BUILDER for KV" programming support
software.
• The Visual KV Series can store not only programs but also comments registered
to each contact using the "KV IncrediWare (DOS)" or "LADDER BUILDER for
KV" programming support software.
A program may not be easy to understand if only device Nos. are used. By
registering comments to the contacts, the program can be easily debugged and
more efficiently maintained.
• The number of contact comments that can be transferred is up to 1,000 for both
normal transfer and compression transfer.
• The KV-D20 operator interface panel includes the contact comment display
function.

➮ For more about operating procedures, refer to "2.5 Entering Comments/Labels" (p.1-46) and "4.2.2
Setting the comment transfer" (p.2-138).

Note 1: Line comments cannot be stored.


Note 2: The KV-P3E(01) handheld programmer cannot read or write contact com-
ments. 11
Note 3: The KV-D20 operator interface panel cannot display contact comments
which have been compressed and transferred.

Chapter 1 Programming 3-27

KVNKA Chap 01P.p65 27 08.3.11, 11:49 AM


1.4 Special Functions

1.4.7 Special Functions KV-300 PLC only

Constant Scan Time Mode


In this mode, operation can take place according to a preset scan time (in ms).

■ Setting
Write the desired scan time into TM29 (temporary data memory), then turn on
special utility relay No. 2303. The scan time can also be written into TM31. Specify a
scan time in increments of 10 ms (a value of less than 10 ms is invalid).
Here, write a value into TM equivalent to 10 times the scan time.

Example
Set the constant scan time to 20 ms.

02008 #00200 TM29 2303


LDA STA SET

Note 1: The set value for the constant scan time must be greater than the actual
scan time. Otherwise, special utility relay 2304 turns on during every scan to disable
constant scan time mode.
Note 2: If the scan time exceeds the set value, special utility relay no. 2304 turns on
1 during the next scan.

Output Disabled Function


During checking of a program, this function clears output from output relays regard-
less of the program currently running.

■ Setting
Turn on special utility relay No. 2300. After one scan is completed, all output relays
(00500 to 00503, 07500 to 17915) are cleared.

Example
Use the output disabled function by executing FORCED RESET/RESET to special
utility relay No. 2300 from the monitor display.
➮ To execute FORCED RESET or RESET, refer to "Chapter 6 Handheld Programmer" (p.1-195).

Input Refresh Disabled Function


Set this function if it is desired to turn ON/OFF input relays from the monitor display
without activating the machine when checking a program.

■ Setting
Turn ON special utility relay No. 2301 to skip input refresh (reading from input
relays). Input relays can then be turned ON/OFF with the KV-P3E(01) or with KV
IncrediWare (DOS) on the monitor display.

Example
Set input relay No. 0000 to ON to disable input refresh; set to OFF to enable input
refresh.
0000 2301

Note: If input refresh is disabled, it is not enabled until input relay No. 0000 is turned
on from the handheld programmer.

3-28 Chapter 1 Programming

KVNKA Chap 01P.p65 28 08.3.11, 11:49 AM


1.5 Extended Ladder Diagrams

1.5 Extended Ladder Diagrams


This section describes KEYENCE’s unique extended ladder diagram.

1.5.1 Features of Extended Ladder Diagrams


The extended ladder diagram is a programming method developed to reduce
problems related to design, testing, operation, and maintenance of programs.
In a conventional ladder diagram, output instructions can be written only on the right
side of a ladder diagram. On the other hand, in an extended ladder diagram, output
instructions can be written anywhere except on the left. As the result, the programs
shown below can be written.

Mixture of input and output circuits


Conventional ladder diagram Extended ladder diagram

Only input circuits Only output Only input Both input Only output
can be written. circuits can circuits can circuits and circuits can
be written. be output circuits be
assembled. can be
assembled.
assembled. 11

Connection of two or more instructions on one line


Conventional ladder diagram Extended ladder diagram

Instructions can be written only from the


left end to the right end on one line.

Many instructions can be connected.

Branch from output coil


Conventional ladder diagram Extended ladder diagram

Branches can be made only from input Branches can also be made from output
contacts. coils.

There is only a single line, so the ladder


diagram is easier to understand.

Three lines are required.

Chapter 1 Programming 3-29

KVNKA Chap 01P.p65 29 08.3.11, 11:49 AM


1.5 Extended Ladder Diagrams

1.5.2 Advantages of Extended Ladder Diagrams


The number of lines in a ladder diagram can be reduced.
Because both output instructions and input instructions can be written side by side,
the number of program lines can be reduced.
As the result, the contents of the program can be seen at a glance.
Example
When DM0000 stores 1000, 0500 turns ON.
2000, 0501 turns ON.
3000, 0502 turns ON.
Conventional ladder diagram Extended ladder diagram
2002 DM0000 2002 DM0000 #01000 2010 0500
LDA LDA CMP

#01000 #02000 2010 0501


CMP CMP

2010 0500 #03000 2010 0502


CMP

2002 #02000
CMP In a conventional ladder diagram, operations
2010 0501
performed by the program cannot be easily
understood. In an extended ladder diagram,
2002 #03000
operations performed by the program can be
CMP understood at a glance.
2010 0502
1
Processing sequence is clear.
Ladder symbols can be laid out in processing sequence, so the program flow is
easier to understand. In addition, maintainability is considerably improved.
Example
When the start switch is set to ON, a lamp is lit for three seconds, a buzzer is
sounded for two seconds, and then the motor starts to rotate.
0000 1100 1100 1000 When the start switch (0000) is set to ON, a lamp (0500) is lit and
DIFU SET timer 0 is activated.
1000 0500 #00030 T000 1001 When timer 0 turns ON three seconds later, the lamp goes out, a
STG T000 JMP
buzzer (0501) is sounded, and timer 1 is activated.
1001 0501 #00020 T001 1002
STG T001 JMP When timer 1 turns ON two seconds later, the buzzer is stopped
and the motor (0502) starts to rotate.
1002 0502 0000
STG ENDS When the start switch (0000) is set to OFF, the motor is stopped
and all operations are reset.

Conventional ladder diagram Extended ladder diagram


0000 1000 0000 1000 1000 1001
DIFU DIFU SET

1000 T000 #00010 1001 0500 #00010 T000 1002


T000 STG T000 JMP

1001 1001 1002 0501 #00020 T001 1003


STG T001 JMP

T002 1003 0500 0501 #00030 T002 1001


STG T002 JMP

T000 T001 #00020


T001
By using an extended ladder diagram as shown
1002 1002 above, the program can be executed in the
sequence of the processing to be performed. So
T001 T002 #00030 even a person who uses a relay sequence for the
T002
first time can understand the processing contents.
1003 1003 By combining the STG instruction, double coils
can also be used.
1001 0500

1003

1002 0501

1003

3-30 Chapter 1 Programming

KVNKA Chap 01P.p65 30 08.3.11, 11:49 AM


1.5 Extended Ladder Diagrams

Note: When an extended ladder diagram is used, the number of lines in ladder
diagram may be reduced. However, this may not necessarily reduce the number of
mnemonics in the program.

Conventional ladder diagram Extended ladder diagram


0000 0500 0000 0500 0501

0501

LD 0000 LD 0000
OUT 0500 OUT 0500
OUT 0501 CON
OUT 0501
The CON instruction for connection is added.
(The scan time is not affected.)

1.5.3 Example of an Extended Ladder Diagram


■ Using W-UE
Only when inputs are given in the order "0000 ➞ 0001 ➞ 0002", output 0500 turns
ON.
Conventional ladder diagram Extended ladder diagram
11
0000 0001 1000 0002 1001 0500
0001 1002 At the rising edge of input
DIFU
0001, 1002 turns ON. 1000 1001
0002 1003
DIFU At the rising edge of input
Input 0000 Input 0001 Input 0002 Output 0500
1003, 1002 turns ON.
1002 0000 1000 turns ON. turns ON. turns ON. turns ON.
If input 0000 is ON, 1000
turns ON.
1000

1003 1000 1001


If 1000 is ON, 1001 turns ON.
1001

1001 0500
When 1001 turns ON, output 0500
turns ON.

Because the program can be written in only one line when an extended adder
diagram is used, it is easier to look at and understand compared with a program
written using a conventional ladder diagram.

Chapter 1 Programming 3-31

KVNKA Chap 01P.p65 31 08.3.11, 11:49 AM


1.5 Extended Ladder Diagrams

3-32 Chapter 1 Programming

KVNKA Chap 01P.p65 32 08.3.11, 11:49 AM


Chapter 2
Instructions
Describes the concrete usage of instructions in the KV Series.
Refer to "Chapter 3 Interrupts" on page 3-191 for details of interrupt instructions.
Refer to "Chapter 4 High-speed counters" on page 3-203 for details of the high-
speed counters used in the application instruction.

2.1 Instruction List [Visual KV Series] ....................................... 3-34


2.1.1 Basic Instructions ................................................................................. 3-34
2.1.2 Application Instructions ........................................................................ 3-36
2.1.3 Arithmetic Instructions .......................................................................... 3-38
2.1.4 Interrupt Instructions ............................................................................ 3-41
2.1.5 Function No. List (Alphabetical order) .................................................. 3-41
2.2 Instruction List [KV-300 Series, KV-10/80] .......................... 3-42
2.2.1 Basic Instructions ................................................................................. 3-42
2.2.2 Application Instructions ........................................................................ 3-45
2.2.3 Arithmetic Instructions .......................................................................... 3-48
2.2.4 Interrupt Instructions ............................................................................ 3-54
2.3 Convention Details ................................................................. 3-55
2.4 Instruction Details .................................................................. 3-56
2.4.1 Basic Instructions ................................................................................. 3-56
2.4.2 Application Instructions ........................................................................ 3-95
2.4.3 Arithmetic Instructions .......................................................................... 3-134
2.5 Programming Notes ............................................................... 3-189

KVNKA Chap 02_1&2&3P.p65 33 08.3.11, 11:51 AM


2.1 Instruction List Visual KV Series

2.1 Instruction List Visual KV Series

The KV Series uses 80 instructions.


The instructions are divided into four categories according to their functions: basic
instructions, application instructions, arithmetic instructions, and interrupt instruc-
tions.
The following is an overview of applications and functions. For details, refer to the
respective description pages for each instruction.

2.1.1 Basic Instructions

Instruction Exec.time
Symbol Mnemonic Operand Operand value Function Bytes Page
(µs)
nnnn
LOAD LD Connects N.O. contact to bus. 0.7 to 1.6 3 (12) 3-57

nnnn
LOAD BAR LDB Connects N.C. contact to bus. 0.7 to 1.6 3 (12) 3-57

nnnn Connects N.O. contact in


AND AND 0.7 to 0.9 3 (8) 3-58
0000 to 17915 series with previous contact.
R No. T000 to T249
nnnn
T/C No. C000 to C249 Connects N.C. contact in
AND BAR ANB 0.7 to 0.9 3 (8) 3-58
CTC0 to CTC3 series with previous contact.

Connects N.O. contact in


2 OR nnnn OR parallel with previous contact.
0.7 to 0.9 3 (8) 3-60

Connects N.C. contact in


OR BAR nnnn ORB 0.7 to 0.9 3 (8) 3-60
parallel with previous contact.
Connects in series blocks
AND LOAD ANL made of one or more 0.8 1 (4) 3-61
contacts.
Connects in parallel blocks
OR LOAD ORL made of one or more 0.8 1 (4) 3-63
contacts.
nnnn
OUT Outputs input ON/OFF status 1.5 3 (12)
OUT 3-65
0500 to 1915 to R coil.
R No. 2009
nnnn 2300 to 17915 Outputs inverted input ON/ 1.5 3 (12) 3-65
OUT BAR OUB
OFF status to R coil.

0500 to 1915
2009
nnnn
SET SET SET 2300 to 17915 Forces relay ON and holds 1.9 to 12.8 3 (14) 3-66
T000 to T249 this status when input is ON.
C000 to C249
R No.
T/C No. 0500 to 1915
2009
nnnn 2100 to 17915
Forces R/T/C OFF when input 1.9 to 20.5 3 (14) 3-66
RESET RES RES T000 to T249
is ON.
C000 to C249
CTH0 to CTH1
CTC0 to CTC3

0.1-s #ddddd 16-bit on-delay T that counts


Txxx TMR T No., down in 0.1-s decrements. 12.0 to 17.8 2 (6) 3-67
TIMER 000 to 249
# preset #00000 to
0.01-s #ddddd TMH value #65535 16-bit on-delay T that counts
Txxx
T 12.0 to 17.8 2 (6) 3-68
TIMER H
(FUN49) down in 0.01-s decrements.

3-34 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 34 08.3.11, 11:52 AM


2.1 Instruction List Visual KV Series

Exec.time
Instruction Symbol Mnemonic Operand Operand value Function Bytes Page
(µs)
T No., 16-bit on-delay T that
1-ms #ddddd TMS 000 to 249
12.0 to 17.8 2 (7) 3-69
TIMER
T
S Txxx (FUN51) # preset value #0000 to #65535 counts down in 1-ms
decrements.
#00000 to
#ddddd
# preset value, #65535
COUNTER Cxxx C C No., counter 000 to 249 Sets 16-bit up-counter. 12.0 to 17.8 4 (7) 3-72
nnnn
input R 0000 to 17915

UDC xxx UDC C No., 000 to 249


UP-DOWN UP Sets a 16-bit up-down
DW #ddddd (FUN52) # preset value #00000 to 13.0 to 24.0 2 (10) 3-76
COUNTER RES counter.
#65535

DIFFEREN- nnnn DIFU Turns ON R for 1 scan


TIATE UP DIFU time at rising edge of 11.2 to 13.2 3 (10) 3-78
(FUN10)
1000 to 1915 input.
R No. 3000 to 9915
DIFFEREN- Turns ON R for 1 scan
nnnn DIFD 10.0 to 12.8 3 (10) 3-78
TIATE DIFD time at falling edge of
(FUN09) input.
DOWN
Turns ON R and holds this
KEEP KEEP 0500 to 1915 status when SET input is ON.
KEEP SET nnnn R No. 2009 8.2 to 19.8 3 (11) 3-80
RES (FUN22) Turns OFF R when RESET
2100 to 17915 input is ON.

SFT nnnn: 1st R


D
nnnn SFT 1000 to 1915 3-82
SHIFT CLK No. mmmm: Sets shift register. (*) 5 (15)
RES mmmm (FUN39) 3000 to 9915
Last R No.

(KV-10)
0000 to 0005
(KV-16) Reduces input relay time
HIGH HSP
HSP 0000 to 0009
SPEED nnnn
(FUN18)
R No.
(KV-24)
constant to 10 µs for
higher input response.
3.8 to 9.4 3 (8) 3-86
12
0000 to 0015
(KV-40)
0000 to 0107

MASTER MC MC Selects ON/OFF status of


CONTROL (FUN24) 0.2 1 (4) 3-89
R coils, Ts, or Cs.
MASTER MCR MCR
CONTROL Represents end of MC. 0.2 1 (0) 3-89
(FUN25)
RESET
MEMORY MEMSW MEMSW $ 0000 to 3-92
$xxxx $ constant Sets memory switches. –– 3 (0)
SWITCH (FUN26) $ FFFF

NOP
NOP (FUN30) Performs no operation. –– 1 (0) 3-94

END Indicates end of each


END END –– 1 (1) 3-94
routine of program.

ENDH Indicates end of entire


END HI ENDH –– 1 (0) 3-94
program.

• Number of bytes represents the memory capacity required for each instruction.
• Number in ( ) represents the memory capacity required for object code of each
instruction.
• *1 34 + 0.25 + n x 0.25 (n: No. of shift steps)
• All operand values are shown in normal notation. The corresponding relay num-
bers in X-Y-M notation are shown below:

Normal notation X-Y-M notation


0000 to 0415 X000 to X04F
0500 to 0915 Y050 to Y09F
1000 to 6915 M1000 to M6915
7000 to 17915 X700 to X174F or Y750 to Y179F

Chapter 2 Instructions 3-35

KVNKA Chap 02_1&2&3P.p65 35 08.3.11, 11:52 AM


2.1 Instruction List Visual KV Series

2.1.2 Application Instructions


Exec.time
Instruction Symbol Mnemonic Operand Operand value Function (µs) Bytes Page

nnnn
R (output operand [mmmm])
WAIT ON ON W-ON 17915 when R, T, or C (input operand 10.4 to 12.6 5 (12) 3-96
mmmm [nnnn]) is ON.
nnnn: T000 to T249
R, T, CC000 to C249 Turns ON R (output operand
nnnn
WAIT OFF OFF W-OFF Nos. CTC0 to CTC3 [mmmm]) when R, T, or C (input 13.6 to 18.5 5 (12) 3-96
mmmm mmmm: operand [nnnn]) is OFF.
nnnn mmmm: 1000 to 1915 Turns ON R (output operand
WAIT UP 3000 to 9915 [mmmm]) at rising edge of R, T, 13.6 to 18.5 3-98
W-UE R No. 5 (12)
EDGE mmmm 1000 to 1915 or C (input operand [nnnn]).
R No.
WAIT nnnn Turns ON R (output operand
DOWN W-DE [mmmm]) at falling edge of R, T, 6.8 to 5.3 1 (0) 3-98
mmmm
EDGE or C (input operand [nnnn]).
CON Represents series connection
CONNECT (FUN 06) of output instruction together 1 (4) 3-102
with another instruction.

PUSH MPS Stores input status and 3-103


3.2 1 (4)
arithmetic flag.
Reads input status and
READ MRD arithmetic flag stored with 6.8 1 (4) 3-103
PUSH.
Reads & clears input status
POP MPP and arithmetic flag stored 10.5 to 13.0 3 (10) 3-103
with PUSH.

nnnn STG Executes instructions in STG


STAGE STG block when R (operand) is ON. 4.5 to 12.5 3 (8) 3-106
(FUN 44)
R, T, C 3000 to 9915
2 JUMP nnnn JMP Nos. 0000 to 0009 When input is ON, turns R of
current stage OFF and moves 4.3 to 7.5
JMP (FUN 21) 1 (4) 3-106
to stage specified by operand.
END ENDS Turns current stage OFF and
ENDS next stage ON when input is 2.5 3 (10) 3-106
STAGE (FUN 14)
ON.

R No. 0500 to 9915


Executes program between
STP nnnn: T000 to T249 STP & STE when R (oper-
STEP STP C000 to C249 and) is ON. 5 (12) 1 (0) 3-114
nnnn 0000 to
(FUN 45) CTC0 to CTC3
11.2 to 13.4

STE STE Is used with STEP to make


STEP END Turns ON 3-114
(FUN 43) program step.

• Number of bytes represents the memory capacity required for each instruction.
• Number in ( ) represents the memory capacity required for object code of each
instruction.
• All operand values are shown in normal notation. The corresponding relay
numbers in X-Y-M notation are shown below:

Normal notation X-Y-M notation


0000 to 0415 X000 to X04F
0500 to 0915 Y050 to Y09F
1000 to 6915 M1000 to M6915
7000 to 17915 X700 to X174F or Y750 to Y179F

3-36 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 36 08.3.11, 11:52 AM


2.1 Instruction List Visual KV Series

Exec.time
Instruction Symbol Mnemonic Operand Operand value Function Bytes Page
(µs)
ITVL
DMnnnn:
PLS DMnnnn: DM0000 to Measures pulse-to-pulse
DMnnnn DM No. DM1985
INTERVAL ITVL interval & pulse width in 20.0 to 80.0 5 (10)
PAUSE 3-117
TIMER mmmm mmmm: R mmmm: specified mode.
RES No. 1000 to 1912
3000 to 9912
0004 16-bit (0 to 65535) up-
16-BIT CTH0 Count input 2100 down counter for clock
nnnn CTH 14.4 4 (6) 3-204
COUNTER R 2101 pulses with input response
2102 frequency of 30 kHz.
n: Hardware-based comparator
16-BIT Comparator between preset & current
No. n: 0,1
COUNTER #ddddd values of high-speed counter
CTCn CTC ddddd: #00001 2.3 to 3.5 2 (6) 3-204
COMPARA- ddddd: (CTH0). This comparator is
to #65535
TOR # preset turned ON when these
value values are equal.

0005 16-bit (0 to 65535) up-


CTH1 0500 down counter for clock
16-BIT Count input pulses with input
nnnn CTH R 2200 14.4 4 (6) 3-204
COUNTER response frequency of 30
2201
2202 kHz.

n: Hardware-based comparator
16-BIT Comparator between preset & current
No. n: 2,3
COUNTER #ddddd values of high-speed counter 2.3 to 3.5 2 (6) 3-204
CTCn CTC ddddd: ddddd: #00001
COMPARA- (CTH1). This comparator is
# preset to #65535
TOR turned ON when these
value values are equal.
SUBROUTINE nn Subroutine Executes subroutine
CALL CALL
CALL
(FUN 03) No. 00 to 99 specified by operand.
5.4 to 6.5 2 (8) 3-122 12
Represents beginning of
SUBROUTINE SBN SBN Subroutine
nn 00 to 99 subroutine specified by 2 (4) 3-122
ENTRY (FUN 38) No. operand.
SUBROUTINE RET RET Represents end of
4.3 1 (4) 3-122
RETURN (FUN 33) subroutine.

#00000 to
# constant, Executes program
FOR #65535
REPEAT FOR between FOR & NEXT 12.0 to
nnnn DM No. DM0000 to 3 (20) 3-125
START (FUN 16) for number of times 18.0
TMxx DM1999 specified by operand.
TM00 to TM29

NEXT
NEXT Represents end of
REPEAT END 0.5 1 (4) 3-125
repetition.
(FUN 29)

nnnn: nnnn: Reads 16-key data by


HKEY
16-KEY INPUT nnnn HKEY Input R 0000 to 415 time-sharing and outputs 22.1 to
5 (10) 3-131
mmmm (FUN 17) mmmm: mmmm: these data into special 180.0
Output R 0500 to 915 utility Rs 2900 to 2915.

• Number of bytes represents the memory capacity required for each instruction.
• Number in ( ) represents the memory capacity required for object code of each
instruction.
• All operand values are shown in normal notation. The corresponding relay
numbers in X-Y-M notation are shown below:

Normal notation X-Y-M notation


0000 to 0415 X000 to X04F
0500 to 0915 Y050 to Y09F
1000 to 6915 M1000 to M6915
7000 to 17915 X700 to X174F or Y750 to Y179F

Chapter 2 Instructions 3-37

KVNKA Chap 02_1&2&3P.p65 37 08.3.11, 11:52 AM


2.1 Instruction List Visual KV Series

2.1.3 Arithmetic Instructions


Exec.time
Instruction Symbol Mnemonic Operand Operand value Function Bytes Page
(µs)
nnnn:
#0000 to
nnnn: #65535
DATA Writes constant into data
nnnn #/$ constant $0000 to 3-136
MEMORY DW DW memory. 8.0 5 (8)
DMmmmm DMmmmm: $FFFF
WRITE
DM No. DMmmmm:
DM0000 to
DM1999

n TMIN
TMIN Inputs value set by 8.9 1 (6)
(FUN 50) access window’s digital
TRIMMER Trimmer No. 0 to 1 trimmer (0 to 65535) to 3-138
SETTING
n @TMIN internal register.
TMIN 20.9 1 (16)
@(FUN 50)
0000 to 17915
T000 to T249
nnnn LDA C000 to C249
LDA CTH0 to CTH1 6.4 to 14.0 3 (8)
(FUN 23) R No.,
C/T No., DM0000 to Inputs value specified by
DM No, DM1999 operand into internal
LOAD A TM00 to TM31 3-140
TM xx, register or inputs current
#00000 to value when T/C is
#/$ constant, #65535
nnnn @LDA #TMxx specified as operand.
LDA $0000 to $FFFF 18.4 to 26.0 3 (18)
@(FUN 23) #TM00 to
#TM29

2 0500 to 1915
STA 2100 to 17915
nnnn
STA (FUN 42) T000 to T249 Transfers content of 6.6 to 28.5 3 (8)
R No., C000 to C249 internal register to
C/T No., CTH0 to location specified by
STORE A DM No., CTC3 operand, or changes 3-140
TM xx, DM0000 to preset value when T/C is
nnnn @STA #TMxx DM1999 specified as operand.
STA TM00 to TM29 18.0 to 40.5 3 (18)
@(FUN 42)
#TM00 to
#TM29

nnnn CMP
CMP (FUN 04) Compares content of 10.8 to 35.6 3 (6)
internal register and
COMPARE 3-146
value specified by
nnnn @CMP operand. 22.8 to 47.6 3 (16)
CMP
@(FUN 04)

nnnn ADD DM0000 to Adds content of internal


ADD
(FUN00) register and value 9.4 to 34.2 3 (6)
DM1999
ADD TM00 to TM31 specified by operand and 3-150
nnnn @ADD #00000 to inputs result back to
ADD same register. 21.4 to 46.2 3 (16)
@(FUN 00) DM/TM No. #65535
TMxx, $0000 to
nnnn SUB #/$ constant, $FFFF Subtracts value specified
SUB #TMxx 10.8 to 35.6 3 (6)
(FUN 46) #TM00 to by operand from content
SUBTRACT #TM29 of register and inputs 3-150
nnnn @SUB result back to same
SUB 22.8 to 47.6 3 (16)
@(FUN 46) register.

nnnn MUL Multiplies content of


MUL (FUN 28) 14.4 to 38.1 3 (6)
internal register by value
MULTIPLY specified by operand and 3-150
nnnn @MUL inputs result back to
MUL @(FUN28) 26.4 to 50.1 3 (16)
same register.

• Number of bytes represents the memory capacity required for each instruction.
• Number in ( ) represents the memory capacity required for object code of each
instruction.

3-38 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 38 08.3.11, 11:52 AM


2.1 Instruction List Visual KV Series

Exec.time
Instruction Symbol Mnemonic Operand Operand value Function Bytes Page
(µs)
DM0000 to
nnnn DIV DM1999
DIV 17.4 to 43.3 3 (6)
(FUN 11) R No., TM00 to TM31 Divides content of internal
DM No., #00000 to register by value specified
DIVIDE TM xx, #65535 3-150
by operand and inputs
#/$ constant, $0000 to result back to same
nnnn @DIV #TMxx $FFFF 3 (16)
DIV register. 29.4 to 55.3
@(FUN 11) #TM00 to
#TM29
nnnn ANDA ANDs each of 16 bits of
ANDA 0000 to 17915 8.2 to 33.1 3 (8)
(FUN 01) internal register and that
AND A DM0000 to of value specified by 3-159
nnnn @ANDA R No., DM1999 operand, and inputs result
ANDA TM00 to TM31 back to same register. 20.2 to 45.1 3 (18)
@(FUN 01) DM No.,
TM xx, #00000 to
#/$ constant, #65535
nnnn ORA ORs each of 16 bits of
ORA #TMxx $0000 to 8.2 to 33.1 3 (8)
(FNC 31) internal register and that
$FFFF
OR A of value specified by 3-161
#TM00 to
nnnn @ORA operand, and inputs result 20.2 to 45.1
ORA #TM29 3 (18)
@(FUN 31) back to same register.

0000 to 17915
nnnn EORA
EORA DM0000 to 8.2 to 33.1 3 (8)
(FUN 15) DM1999 EXCLUSIVE-ORs each of
R No.,
TM00 to TM31 16 bits of internal register
DM No.,
EXCLUSIVE #00000 to and that of value specified
TM xx, 3-164
OR A #65535 by operand, and inputs
#/$ constant,
$0000 to result back to same
nnnn
@EORA #TMxx
$FFFF register.
EORA
@(FUN 15) #TM00 to
20.2 to 45.1 3 (18) 12
#TM29

#dd SRA
SRA Moves content of internal 9.3 to 27.6 2 (6)
(FNC 41)
SHIFT register serially right by
value specified by 3-166
RIGHT A #dd @SRA
SRA operand. 21.3 to 39.6 2 (16)
@(FUN 41)

#dd SLA
SLA Moves content of internal 9.2 to 27.6 2 (6)
(FNC 40)
SHIFT LEFT register serially left by 3-166
A value specified by
#dd @SLA operand.
SLA 21.2 to 39.6 2 (16)
@(FUN 40)
# constant #01 to #16
#dd RRA 10.3 to 28.6 2 (6)
RRA Rotates contents of
(FUN 37)
ROTATE internal register and carry 3-169
RIGHT A bit (2009) clockwise by
#dd @RRA operand value.
RRA @(FUN 37) 22.3 to 40.6 2 (16)

#dd RLA
RLA (FUN 35) Rotates contents of 10.3 to 28.6 2 (6)
ROTATE internal register and carry 3-169
LEFT A @RLA bit (2009) counterclock-
#dd
RLA wise by operand value. 22.3 to 40.6 2 (16)
@(FUN 35)

• Number of bytes represents the memory capacity required for each instruction.
• Number in ( ) represents the memory capacity required for object code of each
instruction.
• All operand values are shown in normal notation. The corresponding relay num-
bers in X-Y-M notation are shown below:

Normal notation X-Y-M notation


0000 to 0415 X000 to X04F
0500 to 0915 Y050 to Y09F
1000 to 6915 M1000 to M6915
7000 to 17915 X700 to X174F or Y750 to Y179F

Chapter 2 Instructions 3-39

KVNKA Chap 02_1&2&3P.p65 39 08.3.11, 11:52 AM


2.1 Instruction List Visual KV Series

Operand Exec.time
Instruction Symbol Mnemonic Operand Function Bytes Page
value (µs)
COM
COM 5.6 1 (4)
(FUN 05)
COMPLE- Inverts content of each bit
3-171
MENT in internal register.
@COM
COM 17.6 1 (14)
@(FUN 05)

nnnn INC
INC
Adds 1 to content of data 9.8 3 (6)
(FNC 19) DM0000 to
INCREMENT DM1999 memory specified by 3-172
DM/TM No.
MEMORY TM00 to operand.
nnnn @INC 21.8 3 (16)
INC TM29
@(FUN 19)

nnnn DEC
DEC (FNC 07) 10.4 3 (6)
DECRE- DM0000 to Subtracts 1 from content
MENT DM/TM No. DM1999 of data memory specified 3-172
MEMORY nnnn @DEC TM00 to by operand.
DEC @(FUN 07) TM29 22.4 3 (16)

#n MPX
MPX Converts 4-bit data 10.1 1 (6)
(FUN 27)
MULTI- # constant #0 to #3 (specified by operand) of 3-176
PLEXER @MPX internal register into 16-bit
#n data. 22.1 1 (16)
MPX @(FUN 27)

DMX
DMX Converts position of 22.6 1 (4)
(FUN 12)
DEMULTI- highest order bit with 1 in
internal register into 4-bit 3-176
PLEXER
DMX
@DMX data. 34.6
@(FUN 12) 1 (14)

2 TBCD Converts content of 5.6


TBCD 1 (4)
TRANSFER (FUN 47) internal register (16-bit
BCD binary) into 4-digit BCD 3-180
@TBCD data. 17.6
TBCD 1 (14)
@(FUN 47)

TBIN 9.6
TBIN (FUN 48) Converts content of 1 (4)
TRANSFER internal register (4-digit
BCD) into 16-bit binary 3-180
BIN @TBIN
TBIN
data. 21.6 1 (14)
@(FUN 48)

ASC 9.7
ASC (FUN 02) Converts content of lower 1 (4)
ASCII order 8 bytes of internal
CONVERT 3-183
register into 2-digit ASCII
@ASC 21.7 1 (14)
ASC code.
@(FUN 02)

RASC Converts 2-digit ASCII 9.3 1 (4)


RASC
REVERSE (FUN 32) code of internal register
ASCII into 2-digit numerical 3-183
CONVERT @RASC value. 21.3 1 (14)
RASC
@(FUN 32)

ROOT Takes square root of 32-


ROOT bit data (TM00: higher 95.7 1 (4)
(FUN 36)
SQUARE order byte, internal 3-185
ROOT register: lower order byte)
@ROOT and inputs result back to 107.7 1 (14)
ROOT @(FUN 36) same register.

• Number of bytes represents the memory capacity required for each instruction.
• Number in ( ) represents the memory capacity required for object code of each
instruction.
• All operand values are shown in normal notation. The corresponding relay
numbers in X-Y-M notation are shown below:

Normal notation X-Y-M notation


0000 to 0415 X000 to X04F
0500 to 0915 Y050 to Y09F
1000 to 6915 M1000 to M6915
7000 to 17915 X700 to X174F or Y750 to Y179F (OUTPUT)

3-40 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 40 08.3.11, 11:53 AM


2.1 Instruction List Visual KV Series

2.1.4 Interrupt Instructions


Exec.time
Instruction Symbol Mnemonic Operand Operand value Function Bytes Page
(µs)
INTERRUPT DI Disables execution of 1 (12)
DI 2.2 3-193
DISABLED (FUN 08) interrupt.

INTERRUPT EI Enables execution of


EI 4.0 1 (10) 3-193
ENABLED (FUN 13) interrupt.

Executes interrupt
INT
instructions between INT
60.0 to 1 (8)
nnnn R No. 000 to 003 and RETI at rising/falling 3-192
90.0
edge of input relays 0000
through 0003.
INTERRUPT INT
(FUN 20)
Used with comparators
INT Comparator CTC0 to CTC0 to CTC3 and 60.0 to
CTCn 1 (8) 3-192
No. CTC3 executes instructions 90.0
between INT and RETI.

RETURN RETI RETI Represents end of 18.0 to 1 (4) 3-192


INTERRUPT (FUN 34) interrupt. 22.0

• Number of bytes represents the memory capacity required for each instruction.
• Number in ( ) represents the memory capacity required for object code of each
instruction.
• All operand values are shown in normal notation. The corresponding relay
numbers in X-Y-M notation are shown below: 12
Normal notation X-Y-M notation
0000 to 0415 X000 to X04F
0500 to 0915 Y050 to Y09F
1000 to 6915 M1000 to M6915
7000 to 17915 X700 to X174F or Y750 to Y179F

2.1.5 Function No. List (Alphabetical order)


The following list shows the function Nos. used to enter instructions with the KV-
P3E(01) handheld programmer.
➮ Refer to "Chapter 6 Handheld Programmer" on page 1-195 for details.

Function No. Instruction Function No. Instruction Function No. Instruction Function No. Instruction
00 ADD 13 EI 26 MEMSW 39 SFT
01 ANDA 14 ENDS 27 MPX 40 SLA
02 ASC 15 EORA 28 MUL 41 SRA
03 CALL 16 FOR 29 NEXT 42 STA
04 CMP 17 HKEY 30 NOP 43 STE
05 COM 18 HSP 31 ORA 44 STG
06 CON 19 INC 32 RASC 45 STP
07 DEC 20 INT 33 RET 46 SUB
08 DI 21 JMP 34 RET1 47 TBCD
09 DIFD 22 KEEP 35 RLA 48 TBIN
10 DIFU 23 LDA 36 ROOT 49 TMH
11 DIV 24 MC 37 RRA 50 TMIN
12 DMX 25 MCR 38 SBN 51 TMS
52 UDC

Reference: To find function No. assigned to desired function:


1. Press the [FUN] key.
2. When the cursor appears at the position where the function No. is to be entered,
press the ON or OFF key and scroll the functions and assigned Nos. to find the
desired function.

Chapter 2 Instructions 3-41

KVNKA Chap 02_1&2&3P.p65 41 08.3.11, 11:53 AM


2.2 Instruction List KV-300
KV-300 Series,
Series, KV-10/80

2.2 Instruction List KV-300 Series, KV-10/80

• Number of bytes represents the memory capacity required for each instruction.
• Number in ( ) represents the memory capacity required for object code of each
instruction.
• Abbreviations: R: Relay, T: Timer, C: Counter, #: Decimal, $: Hex.

2.2.1 Basic Instructions


KV-10/16/24/40/80
KV-10/16/24/40/80
Instruction Symbol Mnemonic Operand Operand value Operand value Exec.time Function Page
Bytes
KV-10/16 KV-24/40/80 (µs)
nnnn Connects N.O. contact
LOAD LD 1.5 to 2.5 3 (4) 3-57
to bus.

nnnn Connects N.C. contact


LOAD BAR LDB 2.1 to 3.5 3 (6) 3-57
to bus.
nnnn Connects N.O. contact
AND AND 3 (4) in series with previous
0000 to 2915 0000 to 6915 1.5 to 2.5 3-58
R No. contact.
T000 to T063 T000 to T119
T/C No. Connects N.C. contact
nnnn C000 to C063 C000 to C119
AND BAR ANB 2.7 to 4.5 3 (8) in series with previous 3-58
CTC0 to CTC3 CTC0 to CTC3
contact.
Connects N.O. contact
OR nnnn
OR 1.5 to 2.5 3 (4) in parallel with previous 3-60
contact.

2 OR BAR nnnn ORB 2.7 to 4.5


Connects N.C. contact
3 (8) in parallel with previous 3-60
contact.
Connects in series
AND LOAD ANL 1.0 to 1.4 1 (2) blocks made of one or 3-61
more contacts.
Connects in parallel
OR LOAD ORL 1.0 to 1.4 1 (2) blocks made of one or 3-63
more contacts.
nnnn Outputs input ON/OFF
OUT OUT 5.2 to 8.4 3 (13) status to R coil. 3-65
0500 to 1915 0500 to 1915
Outputs inverted input
2009 2009
nnnn 2300 to 2915 2300 to 6915 6.4 to 10.4 3 (17) ON/OFF status to R
OUT BAR OUB 3-65
coil.

0500 to 1915 0500 to 1915


nnnn 2009 2009 Forces R ON and holds
SET SET R No.
(SET) 2100 to 2915 2100 to 6915 3.1 to 23.0 3 (8) this status when input is 3-66
T000 to T063 T000 to T119 ON.
C000 to C063 C000 to C119
0500 to 1915 0500 to 1915
2009 2009
nnnn
2100 to 2915 2100 to 6915 Forces R/T/C OFF
RESET RES T000 to T063 T000 to T119 3.1 to 24.0 3 (8) 3-66
(RES) when input is ON.
C000 to C063 C000 to C119
CTH0 to CTH1 CTH0 to CTH1
CTC0 to CTC3 CTC0 to CTC3
16-bit on-delay T that
#ddddd
0.1-s TIMER TMR 17.0 to 22.0 2 (5) counts down in 0.1-s 3-67
T xxx
decrements.
T No., 000 to 063 000 to 119 16-bit on-delay T that
0.01-s #ddddd TMH #00000 to
# preset #00000 to 17.0 to 22.0 2 (5) counts down in 0.01-s 3-68
TIMER H xxx (FNC49) #65535
value #65535 decrements.
TMS 16-bit on-delay T that
#ddddd 3-69
1-ms TIMER 17.0 to 22.0 2 (5) counts down in 1-ms
S xxx (FNC51)
decrements.
# preset #00000 to #00000 to
#ddddd value, C 65535 #65535
COUNTER C xxx C 19.0 to 21.0 4 (7) Sets 16-bit up-counter. 3-72
nnnn No., clock 000 to 063 000 to 119
source R 0000 to 6915 0000 to 6915
UDC xxx
UDC C No., 000 to 063 000 to 119
UP-DOWN UP #ddddd Sets a 16-bit up-down
DW
(FNC52) # preset #00000 to #00000 to 21.0 to 26.0 2 (5) 3-76
COUNTER RES counter.
value #65535 #65535

3-42 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 42 08.3.11, 11:53 AM


2.2 Instruction List KV-300 Series, KV-10/80

KV-10/16/24/40/80
Instruction Symbol Mnemonic Operand Operand value Operand value Exec.time Function Page
Bytes
KV-10/16 KV-24/40/80 (µs)
nnnn Turns ON R for 1
DIFFEREN- DIFU
DIFU 11.0 to 13.0 3 (5) scan time at rising 3-78
TIATE UP (FNC10) edge of input.
R No. 1000 to 1915 1000 to 1915
DIFFEREN- nnnn
3000 to 6915 Turns ON R for 1
TIATE DIFD 11.0 to 13.0 3 (5)
DIFD scan time at falling 3-78
DOWN (FNC09)
edge of input.
KEEP 0500 to 1915 0500 to 1915 Turns ON R and
SET KEEP R No. 2009 9.0 to 26.0 3 (5) holds this status when
KEEP nnnn 2009 3-80
RES (FNC22) 2100 to 6915
2100 to 2915 SET input is ON.
SFT R No.1st 1000 to
D SFT & last R (*) 5 (7) Turns OFF R when 3-82
SHIFT CLK
nnnn
1000 to 1915 19153000 to
RES mmmm (FNC39) Nos. RESET input is ON.
6915
(KV-10) (KV-24)
HIGH HSP HSP 0000 to 0005 0000 to 0015
nnnn R No. 8.0 to 9.0 3 (4) Sets shift register. 3-86
SPEED (FNC18) (KV-16) (KV-40)
0000 to 0009 0000 to 0107
Reduces input relay time
MASTER MC MC
1.8 to 3.2 1 (7) constant to 25 ms for 3-89
CONTROL (FNC24)
higher input response.
MASTER Selects ON/OFF
MCR MCR
CONTROL 0.6 to 1.0 1 (2) status of R coils, Ts, 3-89
(FNC25)
RESET or Cs.
MEMORY MEMSW MEMSW $ constant Represents end of MC.
$xxxx
$xxxx $ 0000 to $ FFFF –– 3 (0) 3-92
SWITCH (FNC26) Sets memory switches.

NOP NOP Performs no opera-


–– 1 (0) tion. 3-94
(FNC30)

END
END
END –– 1 (3) Indicates end of each 3-94
12
routine of program.

ENDH Indicates end of entire


END HI ENDH –– 1 (0) program. 3-94

KV-300
KV-300
Instruction Symbol Mnemonic Operand Exec.time Function Page
Operand value Bytes
(µs)
nnnn Connects N.O. contact
LOAD LD 0.15 to 0.70 3 (5) 3-57
to bus.

nnnn Connects N.C. contact


LOAD BAR LDB 0.15 to 0.90 3 (7) 3-57
to bus.
nnnn 0000 to 0009 Connects N.O. contact
AND AND 0500 to 17915 0.15 to 0.50 3 (4) in series with previous 3-58
R No. T000 to T249 contact.
T/C No. C000 to C249 Connects N.C. contact
nnnn CTC0 to CTC3
AND BAR ANB 0.15 to 0.80 3 (8) in series with previous 3-58
contact.
Connects N.O. contact
OR nnnn OR 0.15 to 0.50 3 (4) in parallel with 3-60
previous contact.
Connects N.C. contact
OR BAR
nnnn
ORB 0.15 to 0.80 3 (8) in parallel with 3-60
previous contact.
Connects in series
AND LOAD ANL 0.55 1 (3) blocks made of one or 3-61
more contacts.
Connects in parallel
OR LOAD ORL 0.55 1 (3) blocks made of one or 3-63
more contacts.

Chapter 2 Instructions 3-43

KVNKA Chap 02_1&2&3P.p65 43 08.3.11, 11:53 AM


2.2 Instruction List KV-300
KV-300 Series,
Series, KV-10/80

KV-300
Instruction Symbol Mnemonic Operand Operand value Exec.time Function Page
Bytes
(µs)
nnnn
OUT 0.20 to 0.56 3 (8) Outputs input ON/OFF 3-65
OUT 0500 to 1915 status to R coil.
2009
nnnn 2300 to 17915 Outputs inverted input
OUT BAR OUB 0.50 to 1.20 3 (11) ON/OFF status to R 3-65
coil.
0500 to 1915
nnnn 2009 Forces R ON and holds
SET (SET) SET R No. 2100 to 17915 0.20 to 5.70 3 (12) this status when input 3-66
T000 to T249 is ON.
C000 to C249

0500 to 1915
2009
nnnn 2100 to 17915
T000 to T249 Forces R/T/C OFF 3-66
RESET (RES) RES 0.50 to 4.40 3 (12) when input is ON.
C000 to C249
CTH0 to CTH1
CTC0 to CTC3

#ddddd
16-bit on-delay T that
0.1-s TIMER TMR 5.60 to 10.40 2 (7) counts down in 0.1-s 3-67
T xxx
decrements.
T No., 000 to 249 16-bit on-delay T that
#ddddd TMH # preset 5.60 to 10.40 2 (7) counts down in 0.01-s 3-68
0.01-s TIMER H xxx (FNC49) #00000 to 65535
value decrements.
16-bit on-delay T that
#ddddd TMS 2 (7)
1-ms TIMER S xxx
5.60 to 10.40 counts down in 1-ms 3-69
(FNC51)
decrements.
2 #ddddd
# preset
value, C
#00000 to #65535
COUNTER C 000 to 249 4 (7) Sets 16-bit up-counter.
C xxx
No., clock 7.60 to 9.45 3-72
nnnn 0000 to 0009
source R 0500 to 17915
UDC xxx C No., 000 to 249
UP-DOWN UP #ddddd UDC 8.00 to 11.60 2 (10) Sets a 16-bit up-down
COUNTER
DW
RES (FNC52) # preset #00000 to #65535 counter. 3-76
value
DIFFEREN- Turns ON R for 1 scan
nnnn DIFU 6.70 3 (10) time at rising edge of 3-78
TIATE UP DIFU FNC10) 1000 to 1915
3000 to 6915 input.
R No. Turns ON R for 1 scan
DIFFEREN- nnnn DIFD (*) 7000 to 9915
6.70 3 (10) time at falling edge of 3-78
TIATE DOWN DIFD (FNC09)
input.
KEEP 0500 to 1915 Turns ON R and holds
KEEP 6.10 to 7.90 3 (11) this status when SET
KEEP
SET
nnnn R No. 2009 3-80
RES (FNC22)
2100 to 17915 input is ON.
SFT SFT 1st & 1000 to 1915
SHIFT
D
CLK
nnnn
last R 3000 to 6915 6.40 to 8.20 5 (15) Turns OFF R when 3-82
RES mmmm (FNC39) RESET input is ON.
Nos. (*) 7000 to 9915

HIGH HSP HSP 0000 to 0009 4.66 to 4.92 3 (8) Sets shift register. 3-86
nnnn R No.
SPEED (FNC18)

MASTER MC Reduces input relay time


MC 1 (4) constant to 25 ms for 3-89
CONTROL 0.20
(FNC24)
higher input response.
MASTER MCR
MCR — Selects ON/OFF status
CONTROL 1 (0) 3-89
(FNC25) of R coils, Ts, or Cs.
RESET
MEMORY MEMSW MEMSW $ constant Represents end of MC.
SWITCH $xxxx
$xxxx $0000 to $FFFF — 3 (0) 3-92
(FNC26) Sets memory switches.

NOP
NOP — 1 (0) Performs no operation. 3-94
(FNC30)

END
END
0.95 1 (1) Indicates end of each 3-94
END
routine of program.

ENDH Indicates end of entire


END HI ENDH — 1 (0) 3-94
program.

Note: 14.0 + 3.0 x (n) to 17.0 + 3.0 x (n) (n represents number of times the original
data is generated.)

3-44 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 44 08.3.11, 11:53 AM


2.2 Instruction List KV-300 Series, KV-10/80

2.2.2 Application Instructions


KV-10/16/24/40/80
KV-10/16/24/40/80
Instruction Symbol Mnemonic Operand Operand value Operand value Exec.time Function Page
(µs) Bytes
KV-10/16 KV-24/40/80
nnnn Turns ON R (2nd operand
WAIT ON W-ON 11.0 to [mmmm]) when R, T, or C (1st
ON 5 (7) 3-96
mmmm nnnn: nnnn: 13.0 operand [nnnn]) turns ON.
0000 to 2915 0000 to 6915
nnnn 11.0 to When R, T, or C (1st operand
T000 to T063 T000 to T119 5 (7) [nnnn]) turns OFF, R (2nd 3-96
WAIT OFF OFF W-OFF 13.0
mmmm nnnn: C000 to C063 C000 to C119 operand [mmmm]) turns ON.
nnnn R,T, or C CTC0 to CTC3 CTC0 to CTC3
R (2nd operand [mmmm])
WAIT UP W-UE No. 14.0 to 5 (7) 3-98
↑ turns ON at rising edge of R, T,
EDGE mmmm mmmm: mmmm: 18.0
or C (1st operand [nnnn]).
1000 to 1915 1000 to 1915
nnnn 3000 to 6915 14.0 to R (2nd operand [mmmm])
WAIT DOWN ↓ W-D 5 (7) turns ON at falling edge of R, 3-98
EDGE mmmm
18.0
T, or C (1st operand [nnnn]).
CON 0.4 to Represents series connection
CONNECT 301 of output instruction together 3-102
[FNC 06] 0.6
with another instruction.

MPS 11.0 to 1 (3) Stores input status and


PUSH 3-103
14.0 arithmetic flag.

Reads input status and


READ 8.0 to
MRD 1 (3) arithmetic flag stored with 3-103
10.0 PUSH.
Reads & clears input status
POP MPP 10.0 to 1 (3) and arithmetic flag stored with 3-103
12.0 PUSH.

STAGE
nnnn
STG
STG 11.0 to
Executes instructions between
3 (7) STG & JMP when R 3-106
12
[FNC 44] 1000 to 1915 14.0 (operand) is ON.
R No. 1000 to 1915
3000 to 6915 Turns current stage OFF and
nnnn JMP 10.0 to
JUMP 3 (5) next stage ON when input is 3-106
JMP [FNC 21] 13.0
ON.
ENDS 7.0 to
END
ENDS [FNC 14] 1 (3) Turns current stage OFF when 3-106
STAGE 9.0 input is ON.
0000 to 2915 0000 to 6915
STP T000 to T119 Executes program between
STP R, T, C T000 to T063 3.7 to 3 (7) STP & STE when R (operand) 3-114
STEP nnnn [FNC 45] C000 to C119
Nos. C000 to C063 5.3 is ON.
CTC0 to CTC3 CTC0 to CTC3

STE
1 (0) Is used with STEP to make
STE
STEP END 0.00 3-114
[FNC 43] program step.

DM0000 to
ITVL DM0000 to DM1985 Measures pulse-to-pulse
INTERVAL PLS DM & R 29.0 to 5 (7) interval & pulse width in
DM nnnn ITVL DM0985 3-117
TIMER PAUSE mmmm
No. 1000 to 1912 79.0
RES 1000 to 1912 specified mode.
3000 to 6912

Clock 8-bit (0 to255) up-counter for


8-BIT CTH0 0004 9.0 to 4 (4) clock pulses with input
nnnn CTH source Rs 3-277
COUNTER 2100 to 2102 39.0 response frequency of 10 kHz.
n: Hardware-based comparator
8-BIT Comparator
#ddddd between preset & current
COUNTER No. n: 0,1
CTCn CTC 3.0 to 4.0 2 (5) values of high speed counter. 3-277
COMPARA- ddddd: # ddddd: #00000 to #00255 This comparator is turned ON
TOR preset value when these values are equal.
16-BIT CTH1 Clock 0005 8.0 to 16-bit (0 to 65535) up-counter
nnnn CTH 4 (4) for clock pulses with input 3-204
COUNTER source Rs 2200 to 2202 48.0
response frequency of 10 kHz.
16-BIT n: Compara- Hardware-based comparator
COUNTER #ddddd tor No. n: 2,3 between preset & current
CTCn CTC 3.0 to 4.0 2 (5) values of high speed counter. 3-204
COMPARA- ddddd: # ddddd: #00000 to #65535
preset value This comparator is turned ON
TOR when these values are equal.
SUBROU- nn CALL Subrou- 8.0 to
CALL
00 to 99 2 (6) Executes subroutine specified 3-122
TINE CALL [FNC 03] tine No. 10.0 by operand.

SUBROU- SBN SBN Subrou- Represents beginning of


nn tine No. 00 to 99 0.00 2 (0) subroutine specified by 3-122
TINE ENTRY [FNC 38]
operand.
SUBROU- RET
RET
TINE [FNC 33] 4.6 to 6.2 1 (5) Represents end of subroutine. 3-122
RETURN

Chapter 2 Instructions 3-45

KVNKA Chap 02_1&2&3P.p65 45 08.3.11, 11:53 AM


2.2 Instruction List KV-300
KV-300 Series,
Series, KV-10/80

KV-10/16/24/40/80
Instruction Symbol Mnemonic Operand Operand value Operand value Exec.time Function Page
Bytes
KV-10/16 KV-24/40/80 (µs)
#00000 to #00000 to
#65535 #65535 Executes program
REPEAT FOR FOR # constant, between FOR & NEXT
nnnn
[FNC 16] DM No. DM0000 to DM0000 to 5.0 to 20.0 3 (15) 3-125
START for number of times
DM0999 DM1999
specified by operand.
TM00 to TM29 TM00 to TM29

REPEAT NEXT NEXT Represents end of


1.7 to 2.3 1 (3) 3-125
END [FNC 29] repetition.

nnnn:0000 to 0009
10000 to 10415 Reads 16-key data by
HKEY HKEY : time-sharing and
16-KEY nnnn
mmmm
I/O R 71 to 370 5 (7) outputs these data into 3-131
[FNC 17] 17000 to 17415
INPUT special utility Rs 2900
mmmm:10500 to 10915
: to 2915.
17500 to 17915

KV-300
KV-300
Instruction Symbol Mnemonic Operand Exec.time Function Page
Operand value Bytes
(µs)
nnnn Turns ON R (2nd operand
WAIT ON W-ON nnnn: [mmmm]) when R, T, or C (1st
ON 5.00 to 6.10 5 (9) 3-96
mmmm 0000 to 0009 operand [nnnn]) turns ON.
0500 to 17915
nnnn
T000 to T249 When R, T, or C (1st operand
WAIT OFF OFF W-OFF 5.00 to 6.10 5 (9) [nnnn]) turns OFF, R (2nd 3-96
mmmm C000 to C249
nnnn: operand [mmmm]) turns ON.
2 WAIT UP
nnnn R,T, or
CTC0 to CTC3
R (2nd operand [mmmm])
↑ W-UE C No. mmmm: 6.10 to 7.50 5 (10) turns ON at rising edge of R, 3-98
EDGE mmmm T, or C (1st operand [nnnn]).
1000 to 1915
nnnn 3000 to 6915 R (2nd operand [mmmm])
WAIT DOWN W-DE 6.10 to 7.50 5 (10) turns ON at falling edge of R,
↓ (*)7000 to 9915 3-98
EDGE mmmm T, or C (1st operand [nnnn]).
CON Represents series connection
CONNECT — 1 (0) of output instruction together 3-102
[FNC 06]
with another instruction.

PUSH MPS Stores input status and


1.30 1 (9) 3-103
arithmetic flag.
Reads input status and
READ MRD 2.70 1 (18) arithmetic flag stored with 3-103
PUSH.
Reads & clears input status
POP MPP 1.40 1 (9) and arithmetic flag stored 3-103
with PUSH.
nnnn STG Executes instructions
STAGE STG 5.60 to 6.50 3 (10) between STG & JMP when R 3-106
[FNC 44] 1000 to 1915
R No. (operand) is ON.
3000 to 6915
nnnn JMP (*)7000 to 9915 Turns current stage OFF and
JUMP JMP 3.80 to 6.00 3 (7) next stage ON when input is 3-106
[FNC 21]
ON.
END ENDS Turns current stage OFF
ENDS — 1 (0) 3-106
STAGE [FNC 14] when input is ON.
0000 to 0009
0500 to 6915 Executes program between
STP STP (*)7000 to 9915
STEP nnnn R, T, 1.30 3 (9) STP & STE when R 3-114
[FNC 45] T000 to T249
C Nos. (operand) is ON.
C000 to C249
CTC0 to CTC3
STE STE Is used with STEP to make
STEP END — 1 (0) program step. 3-114
[FNC 43]
DMnnnn:
DM0000 to DM9985
ITVL mmmm: 13.80 to Measures pulse-to-pulse
INTERVAL PLS
ITVL DM & R No. 5 (11) interval & pulse width in 3-117
TIMER
DM nnnn
PAUSE mmmm
1000 to 1912 17.30
RES 3000 to 6912 specified mode.
(*)7000 to 9912
0004 16-bit (0 to 65535) up-counter
16-BIT CTH0 Clock 2100 4 (7) for clock pulses with input
nnnn CTH 3.85 3-204
COUNTER source Rs 2101 response frequency of 30
2102 kHz.

3-46 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 46 08.3.11, 11:53 AM


2.2 Instruction List KV-300 Series, KV-10/80

KV-300
Instruction Symbol Mnemonic Operand Exec.time Function Page
Operand value Bytes
(µs)
n: Hardware-based comparator
16-BIT Comparator between preset & current
COUNTER #ddddd
CTC n: 0, 1 —
CTCn
No. ddddd: 2 (0) values of high speed counter. 3-204
COMPARA- ddddd: # This comparator is turned ON
TOR #00000 to #65535
preset value when these values are equal.

0005 16-bit (0 to 65535) up-


16-BIT Clock
CTH1 CTH
2200 3.85 4 (7) counter for clock pulses with 3-204
COUNTER nnnn source Rs 2201 input response frequency of
2202 30 kHz.

#ddddd n: Hardware-based comparator


16-BIT n: 2, 3
CTCn Comparator between preset & current
COUNTER CTC ddddd: — 2 (0) values of high speed counter. 3-204
No.
COMPARA- #00000 to #65535 This comparator is turned ON
ddddd: #
TOR when these values are equal.
preset value

SUBROU- nn CALL Subroutine


00 to 99 3.16 2 (17) Executes subroutine 3-122
TINE CALL CALL [FNC 03] No. specified by operand.

SBN Represents beginning of


SUBROU- SBN Subroutine —
nn 00 to 99 2 (0) subroutine specified by 3-122
TINE ENTRY [FNC 38] No. operand.
SUBROU- RET RET Represents end of
TINE 1.15 to 1.45 1 (6) subroutine. 3-122
[FNC 33]
RETURN
REPEAT FOR FOR # constant,
#00000 to #65535
1.55
Executes program between
3 (19) FOR & NEXT for number of
12
nnnn
[FNC 16] DM0000 to DM9999 3-125
START DM No. TM00 to TM29 times specified by operand.

REPEAT NEXT NEXT — 1 (0) Represents end of repetition. 3-125


END [FNC 29]

nnnn:0000 to 0009
10000 to 10415
: Reads 16-key data by time-
16-KEY HKEY HKEY
nnnn
mmmm
I/O R 17000 to 17415 16.50 5 (9) sharing and outputs these 3-131
INPUT [FNC 17] mmmm:0500 to 0503 data into special utility Rs
10500 to 10915 2900 to 2915.
:
17500 to 17915

Chapter 2 Instructions 3-47

KVNKA Chap 02_1&2&3P.p65 47 08.3.11, 11:53 AM


2.2 Instruction List KV-300
KV-300 Series,
Series, KV-10/80

2.2.3 Arithmetic Instructions


KV-10/16/24/40/80
KV-10/16/24/40/80
Instruction Symbol Mnemonic Operand Operand value Operand value Exec.time Function Page
Bytes
KV-10/16 KV-24/40/80 (µs)
#00000 to #0000 to
#/$ #65535 #65535
DATA nnnn
MEMORY < DW > constant, $0000 to $0000 to 3.6 to 6.0 5 (6) Writes constant into 3-136
DW data memory.
DMmmmm DM No. $FFFF $FFFF
WRITE
DM0000 to DM0000 to
DM0999 DM1999

n TMIN
< TMIN > [FNC 50] 13.0 to 15.0 1 (4) Converts trimmer
TRIMMER Trimmer rotation angle into 0
No. 0 0 to 1 3-138
SETTING to 249 and inputs it
n @TMIN 25.0 to 29.0 1 (11) into internal register.
↑ TMIN > @[FNC 50]
0000 to 2915 0000 to 6915
T000 to T063 T000 to T119
nnnn LDA C000 to C063 C000 to C119 10.0 to 46.0 3 (5)
< LDA > [FNC 23] R No., CTH0 to CTH1 CTH0 to CTH1
C/T No., DM0000 to DM0000 to Inputs value specified
DM/TM DM0999 DM1999 by operand into
LOAD A No., TM00 to TM31 TM00 to TM31 internal register or 3-140
#/$ #00000 to #00000 to inputs current value
constant, #65535 #65535 when T/C is specified
nnnn @LDA #TMxx $0000 to $0000 to 22.0 to 60.0 3 (12) as operand.
↑ LDA > @[FNC 23] $FFFF $FFFF
#TM00 to #TM00 to
#TM29 #TM29
0500 to 1915 0500 to 1915
2 nnnn STA R No., 2100 to 2915 2100 to 6915 Transfers content of
< STA > [FNC 42] C/T No., T000 to T063 T000 to T119 9.0 to 99.0 3 (5) internal register to
DM/TM C000 to C063 C000 to C119 location specified by
STORE A No., DM0000 to DM0000 to operand, or changes 3-140
#/$ DM0999 DM1999 preset value when T/
nnnn @STA constant, TM00 to TM29 TM00 to TM29 21.0 to 113.0 3 (12) C is specified as
↑ STA > @[FNC 42] #TMxx #TM00 to
#TM00 to operand.
#TM29 #TM29

nnnn CMP
< CMP > [FNC 04] DM0000 to DM0000 to 14.0 to 68.0 3 (5) Compares content of
DM0999 DM1999 internal register and
COMPARE value specified by 3-146
nnnn @CMP DM/TM TM00 to TM31 TM00 to TM31
↑ CMP > #00000 to #00000 to 26.0 to 82.0 3 (12) operand.
@[FNC 04] No.,
#/$ #65535 #65535
constant, $0000 to $0000 to Adds content of
nnnn ADD
< ADD > [FNC 00] #TMxx $FFFF $FFFF 13.0 to 65.0 3 (5) internal register and
#TM00 to #TM00 to value specified by
ADD 3-150
#TM29 #TM29 operand and inputs
nnnn @ADD
↑ ADD >
25.0 to 79.0 3 (12) result back to same
@[FNC 00]
register.
Subtracts value
nnnn SUB 15.0 to 68.0 3 (5) specified by operand
< SUB > [FNC 46] from content of
SUBTRACT register and inputs 3-150
nnnn @SUB
↑ SUB >
DM0000 to DM0000 to 27.0 to 82.0 3 (12) result back to same
@[FNC 46] DM0999 register.
DM1999
TM00 to TM31 TM00 to TM31 Multiplies content of
nnnn MUL #00000 to #00000 to 17.0 to 71.0 3 (5) internal register by
< MUL > [FNC 28] DM/TM #65535
No., #65535 value specified by
MULTIPLY $0000 to $0000 to 3-150
@MUL #/$ No., operand and inputs
nnnn $FFFF $FFFF
↑ MUL > @[FNC 28] #TMxx 29.0 to 85.0 3 (12) result back to same
#TM00 to #TM00 to register.
#TM29 #TM29
nnnn Divides content of
DIV 22.0 to 79.0 3 (5) internal register by
< DIV > [FNC 11]
value specified by
DIVIDE 3-150
operand and inputs
nnnn @DIV
34.0 to 93.0 3 (12) result back to same
↑ DIV > @[FNC 11]
register.

3-48 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 48 08.3.11, 11:53 AM


2.2 Instruction List KV-300 Series, KV-10/80

KV-10/16/24/40/80
Instruction Symbol Mnemonic Operand Operand value Operand value Exec.time Function Page
Bytes
KV-10/16 KV-24/40/80 (µs)
nnnn ANDA ANDs each of 16 bits
<ANDA> 0000 to 2915 0000 to 6915 11.0 to 64.0 3 (5) of internal register and
[FNC 01]
DM0000 to DM0000 to that of value specified
AND A 3-159
DM0999 DM1999 by operand, and inputs
nnnn @ANDA
R No., TM00 to TM31 TM00 to TM31 23.0 to 78.0 3 (12) result back to same
↑ANDA> @[FNC 01]
DM/TM No., #00000 to #00000 to register.
#/$ No., #65535 #65535 ORs each of 16 bits of
nnnn ORA #TMxx $0000 to $0000 to
< ORA > 11.0 to 63.0 3 (5) internal register and
[FNC 31] $FFFF $FFFF
OR A that of value specified
#TM00 to #TM00 to 3-161
@ORA by operand, and
nnnn #TM29 #TM29 23.0 to 77.0 3 (12) inputs result back to
↑ ORA > @[FNC 31]
same register.

0000 to 2915 0000 to 6915


nnnn EORA DM0000 to DM0000 to 10.0 to 63.0 3 (5) EXCLUSIVE-ORs
<EORA> [FNC 15] DM0999 DM1999 each of 16 bits of
R No., TM00 to TM31 TM00 to TM31 internal register and
EXCLU- DM/TM No., #00000 to #00000 to that of value 3-164
SIVE #/$ No., #65535 #65535 specified by operand,
OR A #TMxx $0000 to $0000 to and inputs result
nnnn @EORA $FFFF $FFFF
↑EORA> @[FNC 15] 22.0 to 77.0 3 (12) back to same
#TM00 to #TM00 to register.
#TM29 #TM29

#dd SRA Moves content of


< SRA > 11.0 to 28.0 2 (4)
[FNC 41] internal register
SHIFT serially right by 3-166
RIGHT A @SRA value specified by
#dd
23.0 to 42.0 2 (11) operand.
↑ SRA > @[FNC 41] 12
#dd SLA
[FNC 40] 10.0 to 28.0 2 (4) Moves content of
< SLA >
SHIFT internal register
3-166
LEFT A serially left by value
#dd @SLA
↑ SLA > @[FNC 40] 22.0 to 42.0 2 (11) specified by operand.
# constant #01 to #16
RRA Moves content of
#dd 12.0 to 30.0 2 (4)
< RRA > [FNC 37] internal register serially
ROTATE right, allowing each bit
3-169
RIGHT A that leaves right end to
#dd @RRA
↑ RRA > @[FNC 37] 24.0 to 44.0 2 (11) enter carry bit and then
leftmost bit.
#dd RLA Moves content of
< RLA > [FNC 35] 12.0 to 29.0 2 (4) internal register serially
ROTATE left, allowing each bit 3-169
LEFT A that leaves left end to
#dd @RLA
24.0 to 43.0 2 (11) enter carry bit and then
↑ RLA > @[FNC 35]
rightmost bit.
COM
< COM > 5.0 to 6.0 1 (3)
[FNC 05] Inverts content of
COMPLE-
each bit in internal 3-171
MENT
@COM register.
↑ COM > 17.0 to 20.0 1 (10)
@[FNC 05]

nnnn INC
< INC > 12.0 to 15.0 3 (5)
INCRE- [FNC 19] Adds 1 to content of
MENT data memory 3-172
MEMORY nnnn @INC 24.0 to 29.0 3 (12) specified by operand.
↑ INC > @[FNC 19]
DM0000 to DM0000 to
DM/TM No. DM0999 DM1999TM00
nnnn DEC
TM00 to TM29 to TM29 14.0 to 17.0 3 (5) Subtracts 1 from
DECRE- < DEC > [FNC 07]
MENT content of data
memory specified by 3-172
MEMORY nnnn @DEC
↑ DEC > @[FNC 07] 26.0 to 31.0 3 (12) operand.

#n MPX Converts 4-bit data


< MPX > [FNC 27] 24.0 to 25.0 1 (4)
MULTI- (specified by
# constant #0 to #3 3-176
PLEXER operand) of internal
#n @MPX
36.0 to 39.0 1 (11) register into 16bit
↑ MPX > @[FNC 27] data.

Chapter 2 Instructions 3-49

KVNKA Chap 02_1&2&3P.p65 49 08.3.11, 11:53 AM


2.2 Instruction List KV-300
KV-300 Series,
Series, KV-10/80

KV-10/16/24/40/80
Instruction Symbol Mnemonic Operand Operand value Operand value Exec.time Function Page
Bytes
KV-10/16 KV-24/40/80 (µs)
DMX
< DMX > [FNC 12] 28.0 to 30.0 1 (3) Converts position of
DEMULTI- highest order bit with 3-176
PLEXER 1 in internal register
@DMX
↑ DMX > @[FNC 12] 40.0 to 44.0 1 (10) into 4-bit data.

TBCD Converts content of


<TBCD> [FNC 47] 19.0 to 21.0 1 (3)
TRANSFER internal register (16-
BCD bit binary) into 4-digit 3-180
@TBCD
↑ TBCD> @[FNC 47] 31.0 to 35.0 1 (10) BCD data.

TBIN
< TBIN > [FNC 48] 18.0 to 20.0 1 (3) Converts content of
TRANSFER internal register (4-
digit BCD) into 16-bit 3-180
BIN @TBIN
↑ TBIN>
30.0 to 34.0 1 (10) binary data.
@[FNC 48]

ASC 8.0 1 (3)


< ASC > [FNC 02] Converts content of
ASCII lower order byte of
CONVERT internal register into 3-183
@ASC
↑ ASC > 20.0 to 22.0 1 (10) 2-digit ASCII code.
@[FNC 02]

RASC 1 (3)
<RASC> 12.0 to 14.0
REVERSE [FNC 32] Converts 2-digit ASCII
ASCII code into one byte 3-183
CONVERT @RASC data.
↑ RASC> 24.0 to 28.0 1 (10)
2 @[FNC 32]
Takes square root of 32-
ROOT 102.0 to
<ROOT> 1 (3) bit data (TM00: higher
[FNC 36] 103.0 order byte, internal
SQUARE 3-185
register: lower order
ROOT @ROOT 114.0 to
↑ ROOT> 1 (10) byte) and inputs result
@[FNC 36] 117.0 back to same register.

KV-300
KV-300
Instruction Symbol Mnemonic Operand Exec.time Function Page
Operand value Bytes
(µs)
nnnn:
DATA nnnn #/$ #0000 to #65535 0.60 to
MEMORY < DW > DW constant, $0000 to $FFFF 1.40 5 (11) Writes constant into 3-136
WRITE DMmmmm DM No. DMmmmm: data memory.
DM0000 to DM9999
n TMIN 5.10 to
< TMIN > [FNC 50] 1 (11) Converts trimmer
5.60
TRIMMER Trimmer 0, 1 rotation angle into 0 to
249 and inputs it into 3-138
SETTING No.
n @TMIN 2.00 to 1 (25) internal register.
↑ TMIN > @[FNC 50] 5.70

0000 to 0009
nnnn LDA 0500 to 17915 0.30 to 3 (12)
< LDA > [FNC 23] T000 to T249 28.00
R No., Inputs value specified
C000 to C249
C/T No., by operand into internal
LOAD A CTH0 to CTH1
DM/TM register or inputs 3-140
DM0000 to DM9999
No., current value when T/C
TM00 to TM31
@LDA #/$ is specified as operand.
nnnn #00000 to #65535 2.30 to 3 (26)
↑ LDA > @[FNC 23] constant, $0000 to $FFFF 30.00
#TMxx
#TM00 to #TM29

0500 to 1915
nnnn STA R No., 0.20 to 3 (12) Transfers content of
2100 to 17915
< STA > [FNC 42] C/T No., 30.00 internal register to
T000 to T249
DM/TM C000 to C249 location specified by
STORE A 3-140
No., CTC0 to CTC3 operand, or changes
@STA #/$ DM0000 to DM9999 preset value when T/C
nnnn 2.20 to
↑ STA > @[FNC 42] constant, TM00 to TM29 3 (26) is specified as operand.
32.00
#TMxx #TM00 to #TM29

3-50 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 50 08.3.11, 11:53 AM


2.2 Instruction List KV-300 Series, KV-10/80

KV-300
Instruction Symbol Mnemonic Operand Exec.time Function Page
Operand value Bytes
(µs)
nnnn CMP 9.20 to
< CMP > 3 (12) Compares content of
[FNC 04] 36.00 internal register and
COMPARE 3-146
nnnn value specified by
@CMP DM0000 to DM9999 11.20 to
↑ CMP > DM/TM 3 (26) operand.
@[FNC 04] TM00 to TM31 38.00
No.,
#/$ #00000 to #65535
nnnn ADD $0000 to $FFFF 7.70 to Adds content of internal
< ADD > constant, 3 (12)
[FNC 00] #TM00 to #TM29 35.00 register and value
ADD #TMxx
specified by operand 3-150
nnnn @ADD
↑ ADD >
9.70 to 3 (26) and inputs result back
@[FNC 00] 37.00 to same register.

nnnn SUB Subtracts value


8.40 to
< SUB > [FNC 46] 3 (12) specified by operand
35.00
SUBTRACT from content of register 3-150
nnnn @SUB 10.40 to and inputs result back
↑ SUB > @[FNC 46] 3 (26) to same register.
37.00

nnnn Multiplies content of


MUL DM/TM DM0000 to DM9999 9.80 to
< MUL > 3 (12) internal register by
[FNC 28] No., TM00 to TM31 37.00 value specified by
MULTIPLY #/$ No., #00000 to #65535 3-150
operand and inputs
nnnn @MUL #TMxx $0000 to $FFFF 11.80 to
↑ MUL > 3 (26) result back to same
@[FNC 28] #TM00 to #TM29 39.00 register.
nnnn DIV 13.70 to Divides content of
< DIV >
[FNC 11] 41.00 3 (12) internal register by
DIVIDE value specified by
operand and inputs 3-150
nnnn @DIV 15.70 to
↑ DIV > @[FNC 11] 42.00
3 (26) result back to same
register. 12
nnnn ANDA 6.90 to ANDs each of 16 bits of
<ANDA> [FNC 01] 33.00 3 (12) internal register and that
AND A of value specified by 3-159
0000 to 0009 operand, and inputs
nnnn @ANDA 0500 to 17915 8.90 to 3 (26) result back to same
↑ANDA> R No., 35.00
@[FNC 01] DM0000 to DM9999
DM/TM register.
No., TM00 to TM31
nnnn ORA 6.90 to ORs each of 16 bits of
#/$ No., #00000 to #65535
< ORA > [FNC 31] 33.00 3 (12) internal register and
#TMxx $0000 to $FFFF
that of value specified
OR A #TM00 to #TM29 3-161
by operand, and inputs
nnnn @ORA 8.90 to
↑ ORA > @[FNC 31] 3 (26) result back to same
35.00 register.
0000 to 0009 EXCLUSIVE-ORs each
nnnn EORA R No., 0500 to 17915 6.90 to
<EORA> [FNC 15] 3 (12) of 16 bits of internal
DM/TM DM0000 to DM9999TM00 to 33.00
EXCLUSIVE register and that of value 3-164
No., TM31
OR A #00000 to #65535 specified by operand,
nnnn @EORA #/$ No., 8.9 to
↑EORA> @[FNC 15] #TMxx $0000 to $FFFF 3 (26) and inputs result back to
35.00 same register.
#TM00 to #TM29

Chapter 2 Instructions 3-51

KVNKA Chap 02_1&2&3P.p65 51 08.3.11, 11:53 AM


2.2 Instruction List KV-300
KV-300 Series,
Series, KV-10/80

KV-300
Instruction Symbol Mnemonic Operand Exec.time Function Page
Operand value Bytes
(µs)
#dd SRA
< SRA > 10.80 2 (22) Moves content of
SHIFT [FNC 41] internal register serially
RIGHT A right by value specified 3-166
#dd @SRA
↑ SRA > @[FNC 41] 12.80 2 (25) by operand.

#dd SLA
< SLA > [FNC 40] 10.80 2 (11) Moves content of
internal register serially
SHIFT left by value specified by 3-166
LEFT A #dd @SLA
↑ SLA > 12.80 2 (25) operand.
@[FNC 40]
# constant #01 to #16
Moves content of
#dd RRA
< RRA > [FNC 37] 12.00 2 (11) internal register serially
ROTATE right, allowing each bit
RIGHT A that leaves right end to 3-169
#dd @RRA
@[FNC 37] 14.00 2 (25) enter carry bit and then
↑ RRA > leftmost bit.
#dd RLA Moves content of
< RLA > [FNC 35] 12.00 2 (11) internal register serially
ROTATE left, allowing each bit
LEFT A that leaves left end to 3-169
#dd @RLA
↑ RLA > @[FNC 35] 14.00 2 (25) enter carry bit and then
rightmost bit.
COM
< COM > [FNC 05] 6.10 1 (9)
COMPLE- Inverts content of each
MENT bit in internal register. 3-171
@COM
↑ COM > 8.10 1 (23)
2 @[FNC 05]

nnnn INC
< INC > [FNC 19] 7.70 3 (12)
Adds 1 to content of
INCREMENT data memory specified 3-172
MEMORY nnnn @INC by operand.
↑ INC > @[FNC 19] 9.70 3 (26)
DM/TM DM0000 to DM9999
nnnn DEC No. TM00 to TM29
< DEC > [FNC 07] 7.70 3 (12)
Subtracts 1 from content
DECREMENT of data memory 3-172
MEMORY @DEC
nnnn
9.70 3 (26) specified by operand.
↑ DEC > @[FNC 07]

#n MPX
< MPX > [FNC 27] 7.30 1 (11) Converts 4-bit data
MULTI- (specified by operand)
# constant #0 to #3 3-176
PLEXER of internal register into
#n @MPX
9.30 1 (25) 16- bit data.
↑ MPX > @[FNC 27]

DMX
< DMX > [FNC 12] 6.70 1 (9) Converts position of
DEMULTI-
highest order bit with 1 3-176
PLEXER
@DMX in internal register into
↑ DMX > 8.70 1 (23) 4-bit data.
@[FNC 12]

3-52 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 52 08.3.11, 11:53 AM


2.2 Instruction List KV-300 Series, KV-10/80

KV-300
Instruction Symbol Mnemonic Operand Exec.time Function Page
Operand value Bytes
(µs)

TBCD 13.20 1 (9) Converts content of


<TBCD> [FNC 47]
TRANSFER internal register (16-bit 3-180
BCD binary) into 4-digit BCD
@TBCD
↑ TBCD> @[FNC 47] 15.20 1 (23) data.

TBIN Converts content of


< TBIN > 14.00 1 (9)
[FNC 48] internal register (4-digit
TRANSFER 3-180
BIN BCD) into 16-bit binary
@TBIN
16.00 1 (23) data.
↑ TBIN> @[FNC 48]

ASC 8.50 1 (9)


< ASC > [FNC 02] Converts content of
ASCII lower order byte of
3-183
CONVERT @ASC internal register into 2-
↑ ASC > 10.50 1 (23) digit ASCII code.
@[FNC 02]

RASC 6.80 1 (9)


<RASC> [FNC 32]
REVERSE Converts 2-digit ASCII
ASCII code into one byte data. 3-183
CONVERT @RASC
↑ RASC> @[FNC 32] 8.80 1 (23)

ROOT Takes square root of 32-


77.70 1 (9) bit data (TM00: higher
<ROOT> [FNC 36]
SQUARE order byte, internal 3-185
ROOT register: lower order
@ROOT 79.70 1 (23) byte) and inputs result
↑ ROOT>
@[FNC 36] back to same register. 12

Chapter 2 Instructions 3-53

KVNKA Chap 02_1&2&3P.p65 53 08.3.11, 11:53 AM


2.2 Instruction List KV-300
KV-300 Series,
Series, KV-10/80

2.2.4 Interrupt Instructions


KV-10/16/24/40/80
KV-10/16/24/40/80
Instruction Symbol Mnemonic Operand Operand value Operand value Exec.time Function Page
Bytes
KV-10/16 KV-24/40/80 (µs)

INTERRUPT DI 1 (4) Disables execution


< DI > 3.0 to 4.6 3-193
DISABLED [FNC 08] of interrupt.

INTERRUPT EI 1 (4) Enables execution


< EI > 3.0 to 4.6 3-193
ENABLED [FNC 13] of interrupt.
Executes instruc-
tions between INT
INT 35.0 to 48.0 and RETI at rising
R No. 000 to 003
nnn
edge of any of input 3-192
000 to 003 or at
INT falling edge of 003.
INTERRUPT 1 (8)
[FNC 20]
Used with compara-
Comparator 35.0 to tors CTC0 to CTC3
INT CTC0 to CTC3 and executes 3-192
CTCn No. 48.8
instructions between
INT and RETI.

RETURN RETI RETI 20.0 to Represents end of


1 (3) 3-192
INTERRUPT [FNC 34] 23.0 interrupt.

KV-300
2 KV-300
Instruction Symbol Mnemonic Operand Exec.time Function Page
Operand value Bytes
(µs)
INTERRUPT DI Disables execution
< DI > 3.20 1 (9) 3-193
DISABLED [FNC 08] of interrupt.

INTERRUPT EI Enables execution


< EI > 5.80 1 (0) 3-193
ENABLED [FNC 13] of interrupt.
Executes instructions
between INT and
INT RETI at rising edge
nnn R No. 000 to 003 40.00 to 1 (0) 3-192
80.00 of any of input 000 to
003 or at falling edge
INTERRUPT INT of 003.
[FNC 20]
Used with compara-
INT 40.00 to tors CTC0 to CTC3
Comparator CTC0 to CTC3 1 (0) 3-192
CTCn 80.00 and executes
No.
instructions between
INT and RETI.

RETURN RETI RETI Represents end of


60 to 100 1 (0) 3-192
INTERRUPT [FNC 34] interrupt.

3-54 Chapter 2 Instructions

KVNKA Chap 02_1&2&3P.p65 54 08.3.11, 11:53 AM


2.3 Convention Details

2.3 Convention Details


In this chapter, each instruction is described as follows:

Instruction Instruction key Ladder symbol


Describes the name Represents the key or Represents the form
and brief function of function No. for entry. of the instruction on a
the instruction. ladder diagram.

SET / RES
2.4 Instruction Details

Turns ON specified relay when input is ON


SET: Set SET
:
nnnn
SET and enables this relay to remain ON.
Mnemonic RES
1
nnnn Turns OFF specified relay, timer, or counter
RES: Reset : RES
Represents the instruc- 0 when input is ON.

tion in ladder language.


Example
0000 0500
SET

0001 0500
RES
• Example
Coding
• Timing diagram
Line No. Instruction Operand
• Description 0000 LD 0000
0001 SET 0500 Coding
Perform programming 0002 LD 0001
Shows the
using the given example
12
0003 OUB 0500
Description coding for
to gain experience. • Output relay 0500 remains ON after input relay 0000 turns OFF. Output relay
0500 turns OFF when input relay 0001 turns ON. the given
• 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
example.
a timer or counter is used as an operand.
2 0001 #00100 0001 0002 #00100
C000 C000
00000 0000
0002 C000
RES

Note: The SET and RES instructions can be entered in any order. Note, however,
Note that priority is given to the instruction that is entered last.
Describes the notes In the above example, when both 0000 and 0001 are ON, RES has priority over
SET, causing 0500 to remain OFF.
for the instruction. Tips
Differences between SET/RES and KEEP
Basically , SET/RES and KEEP (➮ p. 3-57 and p. 3-71) serve the same purpose.
Tips • SET and RES can be used separately. Therefore, RES can be placed before
SET.
Describes hands-on Another instruction may be placed between SET and RES.
• KEEP needs only three lines of program, therefore saving memory space when
techniques for efficient used a number of times.

programming. 0000 0500 LD 0000 0000 KEEP LD 0000


RES SET
RES 0500 0500 LD 0001
0001 0500 LD 0001 0001 KEEP 0500
SET RES
SET 0500

Operand Operands
NEW KV KV-300 KV-10/16 KV-24/40/80
Shows operands (element 0500 to 1915 0500 to 1915 0500 to 1915 0500 to 1915
2009 2009 2009 2009
Nos.) that can be used for 2100 to 17915 2100 to 17915 2100 to 2915 2100 to 6915
T000 to T249 T000 to T249 T000 to T063 T000 to T119
the instruction. C000 to C249 C000 to C249 C000 to C063 C000 to C119
CTH0 to CTH1 (RES only)
CTC0 to CTC3 (RES only)

Key operation Key operation

Describes the basic key SET


1 Operand ENT
R-SRCH
RES
0 Operand ENT
R-SRCH

operations on the handheld


programmer. Set the mode 3-66 Chapter 2 Instructions

switch to PROGRAM.
* The above page is created for explanation purposes only.
This page may be different from the actual page.

Chapter 2 Instructions 3-55

KVNKA Chap 02_1&2&3P.p65 55 08.3.11, 11:53 AM


2.4 Instruction Details

2.4 Instruction 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
2 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

3-56 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 56 08.3.11, 11:57 AM


LD / LDB
2.4 Instruction Details

nnnn
LD: Load LD
7 : Connects N.O. contact to bus.
LDB nnnn
LDB: Load Bar 4 : Connects N.C. contact to bus.

Example
0000 0500

0001 0501

Coding
Line No. Instruction Operand
0000 LD 0000
0001 OUT 0500
0002 LDB 0001
0003 OUT 0501

When input relay 0000 turns ON, output relay 0500 turns ON.
When input relay 0001 turns OFF, output relay 0501 turns ON.

Description 12
• 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
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

Key operation
Example: LD C014

LD
7
LDB
Operand ENT
R-SRCH ( L D CTR SET LDB
7 (C ) 1 4
ENT
R-SRCH )
4

Chapter 2 Instructions 3-57

KVNKA Chap 02_4aP.p65 57 08.3.11, 11:57 AM


AND / ANB
2.4 Instruction Details

Connects N.O. contact in series with


AND nnnn
AND: And 8 : previous contact.
nnnn
ANB: And Bar ANB
5 : Connects N.C. contact in series with
previous contact.

Example
0000 0001 0500

0002 0003 0501

0502

0004 0503

Coding
Line No. Instruction Operand
0000 LD 0000
0001 AND 0001
0002 OUT 0500
0003 LD 0002
0004 ANB 0003
2 0005 OUT 0501
0006 OUT 0502
0007 AND 0004
0008 OUT 0503

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.

0000 0001 0501 0000 0001 0501

0500 0500

Coding Coding

Line No. Instruction Operand Line No. Instruction Operand


0000 LD 0000 0000 LD 0000
0001 OUT 0500 0001 MPS
0002 AND 0001 0002 AND 0001
0003 OUT 0501 0003 OUT 0501
0004 MPP
0005 OUT 0500
➮ "MPS instruction" (p. 3-103)
➮ "MPP instruction" (p. 3-103)

3-58 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 58 08.3.11, 11:57 AM


AND / ANB
2.4 Instruction Details

Operand
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

Key operation
Example: AND T012
AND
8
ANB
Operand ENT
R-SRCH ( AND TMR SET ANL
8 (T) 1 2
ENT
R-SRCH )
5

12

Chapter 2 Instructions 3-59

KVNKA Chap 02_4aP.p65 59 08.3.11, 11:57 AM


OR / ORB
2.4 Instruction Details

OR nnnn Connects N.O. contact in parallel with


OR: Or 9 : previous contact.
nnnn
ORB: Or Bar
ORB
6 : Connects N.C. contact in parallel with
previous contact.

Example
0000 0003 0500

0001

0002

0004

Coding
Line No. Instruction Operand
0000 LD 0000
0001 OR 0000
0002 ORB 0002
0003 AND 0003
0004 OR 0004

2 0005 OUT 0500


0000 must be ON or
0003 must be ON, and 0001 ON or
To turn ON 0500, or, 0002 OFF.
0004 must be ON.

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 ) 0000 0500
cannot be included in the parallel connection.
Incorrect 0001 0501

Operands
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

Key operation
Example: OR T018
OR
9
ORB
Operand ENT
R-SRCH ( O R TMR SET AND
9 (T ) 1 8
ENT
R-SRCH )
6

3-60 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 60 08.3.11, 11:57 AM


ANL
2.4 Instruction Details

ANL Connects in series blocks made of one or


ANL: And Load 2 : more contacts.

Example
0000 0001 0500

0002 0003

ANL
Coding
Line No. Instruction Operand
0000 LD 0000
0001 OR 0002
0002 LD 0001
0003 OR 0003
0004 ANL
0005 OUT 0500

Description 12
0000

The above example shows a serial connection between Block A 0002


0001

and Block B 0003 . The ANL instruction is used to connect two or more blocks in
series.

Operands

Key operation
ANL ENT
2 R-SRCH

Chapter 2 Instructions 3-61

KVNKA Chap 02_4aP.p65 61 08.3.11, 11:57 AM


ANL
2.4 Instruction Details

Applications of ANL Instruction

0000 0002 0004 0500

0001 0003 0005

Coding (1) Coding (2)

Line No. Instruction Operand Line No. Instruction Operand


0000 LD 0000 0000 LD 0000
0001 OR 0001 0001 OR 0001
0002 LD 0002 0002 LD 0002
0003 OR 0003 0003 OR 0003
0004 ANL 0004 LD 0004
0005 LD 0004 0005 OR 0005
0006 OR 0005 0006 ANL
0007 ANL 0007 ANL
0008 OUT 0500 0008 OUT 0500

• 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
2 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).

3-62 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 62 08.3.11, 11:57 AM


ORL
2.4 Instruction Details

ORL
Connects in parallel blocks made of one or
ORL: Or Load 3 : more contacts.

Example
0000 0001 0050

0002 0003
ORL

Coding
Line No. Instruction Operand
0000 LD 0000
0001 AND 0001
0002 LD 0002
0003 AMD 0003
0004 ORL
0005 OUT 0500

Description
0000 0001
The above example shows a parallel connection of Block A 12
0002 0003
and Block B . The ORL instruction is used to connect two or more blocks in
parallel.

Operands

Key operation
ORL ENT
3 R-SRCH

Chapter 2 Instructions 3-63

KVNKA Chap 02_4aP.p65 63 08.3.11, 11:57 AM


ORL
2.4 Instruction Details

Applications of ORL Instruction

0000 0001 Block 0500

0002 0003 Block

0004 0005 Block

Coding (1) Coding (2)

Line No. Instruction Operand Line No. Instruction Operand


0000 LD 0000 0000 LD 0000
0001 AND 0001 0001 AND 0001
0002 LD 0002 0002 LD 0002
0003 AND 0003 0003 AND 0003
0004 ORL 0004 LD 0004
0005 LD 0004 0005 AND 0005
0006 AND 0005 0006 ORL
0007 ORL 0007 ORL
0008 OUT 0500 0008 OUT 0500

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).

3-64 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 64 08.3.11, 11:57 AM


OUT / OUB
2.4 Instruction Details

nnnn
OUT: Out OUT
: Outputs ON/OFF status of input to relay coil.
A
OUB nnnn
OUB: Out Bar B : Outputs inverted ON/OFF status of input to
relay coil.

Example
0000 0500

0501

Coding

Line No. Instruction Operand


0000 LD 0000
0001 OUT 0500
0002 OUB 0501

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, 12
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
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

Key operation
OUT Operand ENT OUB Operand ENT
A R-SRCH B R-SRCH

Chapter 2 Instructions 3-65

KVNKA Chap 02_4aP.p65 65 08.3.11, 11:57 AM


SET / RES
2.4 Instruction Details

Turns ON specified relay when input is ON


SET: Set SET
:
nnnn
SET and enables this relay to remain ON.
1
RES nnnn Turns OFF specified relay, timer, or counter
RES: Reset 0 : RES
when input is ON.

Example
0000 0500
SET

0001 0500
RES

Coding
Line No. Instruction Operand
0000 LD 0000
0001 SET 0500
0002 LD 0001
0003 OUB 0500
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.
2 0001 #00100 0001 0002 #00100
C000 C000
00000 0000
0002 C000
RES

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.

0000 0500 LD 0000 0000 KEEP LD 0000


RES SET
RES 0500 0500 LD 0001
0001 0500 LD 0001 0001 KEEP 0500
SET RES
SET 0500

Operands
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)

Key operation
SET ENT RES ENT
1 Operand R-SRCH 0 Operand R-SRCH

3-66 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 66 08.3.11, 11:57 AM


TMR
2.4 Instruction Details

TMR #ddddd Sets a 16-bit on-delay timer that counts


TMR: 0.1-s Timer ( T) : Txxx
down in 0.1-s decrements.

Example
0000 #00010
T000 Preset value: 1 s

#00035
T001 Preset value: 3.5 s

T000 0500

T001 0501

Coding
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
*1 0.1 s x 10 = 1 s
0006 OUT 0501 *2 0.1 s x 35 = 3.5 s

12
Timing diagram (TMR000 #00010 and 0500 in the above example)
Scan
ON
Input 0000 OFF

Current #00010
value of
TMR000
#00000
ON
Output 0500

• 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
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

Key operation
TMR Operand Operand ENT
(T) (TMR No.) (Preset value) R-SRCH

Chapter 2 Instructions 3-67

KVNKA Chap 02_4aP.p65 67 08.3.11, 11:57 AM


TMH
2.4 Instruction Details

LDB OR #ddddd Sets a 16-bit on-delay timer that


TMH: 0.01-s Timer FUN 4 9 : Txxx
T
H
counts down in 0.01-s decrements.

Example
0000 #00010
T000
T
H

T000 0500

Coding

Line No. Instruction Operand


0000 LD 0000
0001 TMH 000 #00010*1
0002 LD T000
0003 OUT 0500 *1 0.01 s x 10 = 0.1 s

Description
• 0500 and 0501 turn ON 0.1-s after 0000 turns ON.
2 • 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

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

Key operations
LDB OR ENT Operand Operand ENT
FUN 4 9 R-SRCH (TMH No.) (Preset value) R-SRCH

3-68 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 68 08.3.11, 11:58 AM


TMS
2.4 Instruction Details

ANB SET #ddddd Sets a 16-bit on-delay timer that


TMS: 1-ms Timer FUN 5 1 : T Txxx
S
counts down in 0.01 ms decrements.

Example

0000 #00100
T000
T
S
Preset value: 0.1 s

T000 0500

Coding
Line No. Instruction Operand
0000 LD 0000
0001 TMS 000 #00010*1
0002 LD T000
0003 OUT 0500 *1 0.001 s x 100 = 0.1 s

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
12
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
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

Key operations
ANB SET ENT Operand Operand ENT
FUN 5 1 R-SRCH (TMS No.) (Preset value) R-SRCH

Chapter 2 Instructions 3-69

KVNKA Chap 02_4aP.p65 69 08.3.11, 11:58 AM


TMR
2.4 Instruction Details

Applications of TMR instruction


■ One-shot circuit
When input relay 0000 turns ON, output relay 0500 turns ON and remains ON for a
specified time.
0000 #00020 2 sec.
T000

0500 T000 0500

Timing diagram
ON
OFF
0000
ON ON
0500
2 sec. 2 sec.

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

■ 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.
0000 T000 0500

0500 0000 #00020 2 sec.


T000

Timing diagram
ON
OFF
0000
ON
0500
2 sec.

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

3-70 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 70 08.3.11, 11:58 AM


TMR
2.4 Instruction Details

■ 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.

0000 #00020 2 sec.


T000

T000 0500

Timing diagram

ON
OFF
0000

0500 ON

2s 1s

Coding
Line No. Instruction Operand
0000 LD 0000
0001 TMR 000 #00020
0002 LD T000
0003 OUT 0500 12

■ Flicker circuit
Output relay 0500 turns ON and OFF repeatedly while input relay 0000 is ON.

0000 T001 #00020 2 sec.


T000

T000 #00010 1 sec.


T001

0500

Timing diagram
ON
OFF
0000

ON ON ON
0500
2s 1s 2s 1s 2s 1s

Coding
Line No. Instruction Operand
0000 LD 0000
0001 ANB T001
0002 TMR 000 #00020
0003 LD T000
0004 AMR 001 #00010
0005 OUT 0500

Chapter 2 Instructions 3-71

KVNKA Chap 02_4aP.p65 71 08.3.11, 11:58 AM


C
2.4 Instruction Details

CTR #ddddd
C: Counter (C) : Cxxx
nnnn
Sets a 16-bit up-counter.

Example
Reset input Preset value

0001 #00010 Counter No.


C000
0000 Count input
C000 0500

Coding
Line No. Instruction Operand
0000 LDB 0001
0001 C 000 #00010 0000
0002 LD C000
0003 OUT 0500

Timing diagram (C000#00010 and 0500 in the above example)

0000 ON

2 (Count input) OFF

0001
(Reset input)
Current value 9
10
8
of C000 6
7
5
4
3
2
#00010 1

C000 ON
0500

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 25°C 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.
0001 #00010
C000
0000

3-72 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 72 08.3.11, 11:58 AM


C
2.4 Instruction Details

Details of counter
■ Extended ladder
• The counter for the KV Series supports the extended ladder method.
KV counter
0001 2007 #00010
C005
0000

• 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.

0002 #00300 C002 0500


C002
0004

Coding
Line No. Instruction Operand
0000 LDB 0002
0001 C 002 #00300 0004
0002 CON
0003 AND C002
12
0004 OUT 0500
➮ "CON instruction" (p. 3-102)

For details of the extended ladder, refer to "1.5 Extended Ladder Diagrams"
(p.3-29).

Operands
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

Key operation

CTR Operand Operand Operand ENT


(C ) (Counter No.) (Preset value) (Count input) R-SRCH

Chapter 2 Instructions 3-73

KVNKA Chap 02_4aP.p65 73 08.3.11, 11:58 AM


C
2.4 Instruction Details

Applications of C (counter) instruction


■ Long-duration timer
Sets a long-duration timer by combining a timer and a counter.
Output 0500 turns ON in 1 hour.
Special utility relay
Coding
(1-second clock)
Line No. Instruction Operand
0000 #03600
C002 0000 LDB 0000
2006 0001 C 002 #03600 2006
C002 0500
0002 LD C002
0003 OUT 0500
➮ "1.3.7 Special Utility Relays" (p. 3-12)

■ Accumulator timer (Remains ON in case of power failure)

Coding
0001 C001 #03600 Line No. Instruction Operand
C001
2006 0000 LDB 0001
C001 1000 0001 ANB C001
0002 C 001 #03600 2006
0001 #00600 0003 LD C001
C002
1000 0004 OUT 1000
0005 LDB 0001
0006 C 002 #00600 1000
2
■ Large capacity counter

Coding
0002 C000 #10000 Line No. Instruction Operand
C000
0000 0000 LDB 0002
C000 1000 0001 ANB C001
0002 C 001 #10000 0000
0002 #65535 0003 LD C000
C001
1000 0004 OUT 1000
0005 LDB 0002
0006 C 001 #65535 1000

■ Multi-level setting
Sets a multi-level counter using arithmetic instructions.

0001 #09999
C002
0000
2002 C002 #01000 2009 0500
LDA CMP

#02000 2009 0501


CMP

#03000 2009 0502


CMP

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)

3-74 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 74 08.3.11, 11:58 AM


C
2.4 Instruction Details

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

■ Counter multi-level setting

0001 #09999
C000
0000
2002 C000 #00999 2011 0500
LDA CMP

#01999 2011 0500 0501


CMP

#02999 2011 0500 0501 0502


CMP

Outputs in 3 different levels according to the counter current value. 12


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
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

Chapter 2 Instructions 3-75

KVNKA Chap 02_4aP.p65 75 08.3.11, 11:58 AM


UDC
2.4 Instruction Details

UDC xxx
UDC: Up-Down Counter FUN 5
ANB ANL
2 : UP
DW #ddddd
RES
Sets a 16-bit up-down-counter.

Example UP input
UDC 000
0001
UP
#00009 DOWN input
0002
DW
RESET input
0003
RES

C000 0500

Coding
Line No. Instruction Operand
0000 LD 0001
0001 LD 0002
0002 LD 0003
0003 UDC 000 #00009
0004 LD C000
0005 OUT 0500
2
Timing diagram
9
8
7
6
5
4
2 3
Current value of C000 1 Carry Carry Time
ON ON

C000 OFF

ON
Input for up 0001 OFF

ON
OFF
Input for down 0002
Input for resetting ON
0003 OFF

• 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 25°C even when the KV is not in operation or is turned off.

Operands
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

Key operation
ANB ANL ENT Operand Operand ENT
FUN 5 2 R-SRCH (C No.) (Preset value) R-SRCH

3-76 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 76 08.3.11, 11:58 AM


UDC
2.4 Instruction Details

Application of UDC instruction


■ Multi-level UP/DOWN counter
UP/DOWN counter which allows a count setting value up to 99,990,000.
UDC 000
0001
UP BCD
#09999 Low-order 4 digits
0002
DW

0003
RES
UDC 001
C000 0001
UP BCD
#09999 High-order 4 digits
C000 0002
DW

0003
RES
Up-input 0001
Down-input 0002

Coding
Line No. Instruction Operand
0000 LD 0001
0001 LD 0002 12
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

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.

0004 C000 0500 Low-order


LDA TBCD STA 4 digits
C001 0600
LDA TBCD STA High-order
4 digits

Chapter 2 Instructions 3-77

KVNKA Chap 02_4aP.p65 77 08.3.11, 11:58 AM


DIFU / DIFD
2.4 Instruction Details

SET RES nnnn Detects rising edge of input signal and turns
DIFU: Differentiate Up FUN 1 0 : DIFU
ON specified relay for 1st scan time only.
RES OR nnnn Detects falling edge of input signal and turns
DIFD: Differentiate Down: FUN 0 9 : DIFD
ON specified relay for 1st scan time only.

Example
0000 1000
DIFU

1001
DIFD

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

Timing diagram (0000, 1000, and 1001 in the above example)


ON
OFF
0000
ON
1000 ON for 1st scan time only
2 1001
ON
ON for 1st scan time only

• 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).
a) 0500 turns ON for one scan at the rising edge b) 0500 does not turn ON for one scan at
of input relay 0000. the falling edge of input relay 0000.
0000 1000 1000 0500 0000 1000 1000 0500
DIFU DIFD

c) 0500 turns ON for one scan at the


falling edge of input relay 0000.
0000 1000
DIFD

1000 0500

Operands
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
* 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
SET RES ENT Operand ENT FUN RES OR ENT Operand ENT
FUN 1 0 R-SRCH (Relay No.) R-SRCH 0 9 R-SRCH (Relay No.) R-SRCH

3-78 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 78 08.3.11, 11:58 AM


DIFU / DIFD
2.4 Instruction Details

Application of DIFU, DIFD instructions


■ 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
0000 1000 Line No. Instruction Operand
DIFU
0000 LD 0000
1001 0001 DIFU 1000
DIFD
0002 DIFD 1001
1000 T001 0500 0003 LD 1000
0004 OR 0500
0500 #00010 0005 ANB T001
T001 0006 OUT 0500
1001 T002 0501 0007 TMR 001 #00010
0008 LD 1001
0501 #00010 0009 OR 0501
T002 0010 ANB T002
0011 OUT 0501
0012 TMR 002 #00010

Timing diagram
ON
OFF
0000
ON
OFF
12
1000
ON
OFF
1001
ON
0500
1s
ON
0501
1s

■ Alternating circuit
Every time input relay 0000 turns ON, output relay 0500 turns ON and OFF alter-
nately.

Coding
0000 1000 Line No. Instruction Operand
DIFU 0000 LD 0000
1000 0500 0500 0001 DIFU 1000
0002 LD 1000
0003 ANB 0500
1000 0500 0004 LDB 1000
0005 AND 0500
0006 ORL
0007 OUT 0500

Chapter 2 Instructions 3-79

KVNKA Chap 02_4aP.p65 79 08.3.11, 11:58 AM


KEEP
2.4 Instruction Details

Turns ON specified relay when SET input


KEEP relay turns ON and enables this relay to
KEEP: Keep FUN 3
ORL O R
9 : SET
RES
nnnn
remain ON. And, turns OFF specified relay
when RESET input relay turns ON.

Example
KEEP SET input
0001
SET
0500
0002
RES RESET input

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

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.
2 Note 1: When 0500 used for KEEP instruction in the above example is changed to
0500
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.
Stores the status of
internal utility relays Coding
MEMSW 1000 through 1915.
Line No. Instruction Operand
$0004
0000 MEMSW $0004
0001 KEEP 0001 LD 0001
SET 0002 LD 0002
1000
0002 0003 KEEP 1000
RES 0004 LD 1000
1000 0500 0005 OUT 0500

Operands
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

Key operation
ANL ANL ENT Operand ENT
FUN 2 2 R-SRCH (Relay No.) R-SRCH

3-80 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 80 08.3.11, 11:58 AM


KEEP
2.4 Instruction Details

Application of KEEP instruction


■ 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.

Reflector R-2

ES

ON OFF ON
ES
Gum Gum
Gum Gum Gum PZ2-61
Gum Gum Gum

KEEP
0000 0001 0002 0003
SET Executes SET when all input relays
12
1000 0000 to 0003 are ON.
1001
RES

0000 1001
DIFD Detects presence/absence of chewing
gum packs all Down edge of 0000.
1001 1000 T001 0500

Outputs 1-s one-shot plus from output


0500 #00010 relay 0500 when 1000 is OFF.
T001

Coding
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

Timing diagram
ON
OFF
0000
ON
OFF
0001
ON
OFF
0002
ON
OFF
0003
ON
OFF ON ON
0500
1s

Chapter 2 Instructions 3-81

KVNKA Chap 02_4aP.p65 81 08.3.11, 11:58 AM


SFT
2.4 Instruction Details

SFT
ORL O R D
SFT: Shift FUN 3 9 : CLK nnnn
RES mmmm
Sets a shift register.

Example
Data input
SFT
0001
Relay shift D
operation
1000 First relay No.
0002
CLK Clock
1002 Last relay No.
0003
RES RESET input

1002 0500

Coding
Line No. Instruction Operand
0000 LD 0001
0001 LD 0002
0002 LD 0003
0003 SFT 1000 1002
2 0004 LD 1002
0005 OUT 0500

Timing diagram
0 OFF
1 ON
RESET input ON
1002 1001 1000 0001
0003 OFF Lost 0 0 1 1 A)

ON
Data input 1002 1001 1000 0001
0 1 1 1 B)
0001 OFF Lost
A B C D E F G
ON
Clock 1002 1001 1000 0001
0002 OFF Lost 1 1 1 1 C)
ON
1002 1001 1000 0001
ON ON Lost 1 1 1 1 D)
1000
1002 1001 1000 0001
ON ON Lost 1 1 0 0 E)
1001
1002 1001 1000 0001
ON ON Lost 1 0 0 1 F)
1002
1002 1001 1000 0001
ON ON Lost 0 0 1 1 G)
0500

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.

3-82 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 82 08.3.11, 11:58 AM


SFT
2.4 Instruction Details

Operands
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
* 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
ORL OR ENT Operand Operand ENT
FUN 3 9 R-SRCH (Relay No.) (Relay No.) R-SRCH

Applications of SFT instruction


■ Alternating circuit
Every time input relay No. 0000 turns ON, 0500 turns alternately ON and OFF.

SFT Coding
1000
D Line No. Instruction Operand
1000 0000 LDB 1000
0000
CLK 0001 LD 0000
1000 0002 LD 2003
2003 0003 SFT 1000 1000
RES
0004 LD 1000
1000 0500 0005 OUT 0500 12

Timing diagram
ON
OFF
0000

0500 ON ON ON ON ON

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
0000 1000 Line No. Instruction Operand
DIFU 0000 LD 0000
1000 0500 0500 0001 DIFU 1000
0002 LD 1000
0003 ANB 0500
1000 0500
0004 LDB 1000
0005 AND 0500
0006 ORL
0007 OUT 0500

Chapter 2 Instructions 3-83

KVNKA Chap 02_4aP.p65 83 08.3.11, 11:58 AM


SFT
2.4 Instruction Details

■ 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
SFT
2003 Line No. Instruction Operand
D
0000 LD 2003
1000
2003 0001 LD 2003
CLK 0002 LD 0000
1915 0003 SFT 1000 1915
0000
RES

■ 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

2 2008 1000
SET
Line No. Instruction Operand
0000 LD 2008
T001 #00010 0001 SET 1000
T001
0002 LDB T001
SFT
2003 0003 T001 #00010
D
0004 LD 2003
1000
T001 0005 LD T001
CLK
0006 LD 2003
1005
2003 0007 SFT 1000 1005
RES
0008 LD 1000
1000 0500 0009 OUT 0500
0010 LD 1001
1001 0501 0011 OUT 0501
0012 LD 1002
1002 0502 0013 OUT 0502
0014 LD 1003
1003 0503 0015 OUT 0503
0016 LD 1004
1004 0504 0017 OUT 0503
0018 LD 1005
1005 1000 0019 SET 1000
SET

3-84 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 84 08.3.11, 11:58 AM


SFT
2.4 Instruction Details

■ 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.

0000 1100 Coding


DIFU
Line No. Instruction Operand
1100 1000 0000 LD 0000
SET 0001 DIFU 1100
SFT 0002 LD 1100
2003
D 0003 SET 1000
1000 0004 LD 2003
0001 0005 LD 0001
CLK
0006 LD 0002
1010
0002 0007 SFT 1000 1010
RES

Timing diagram

Scan
ON
0001 OFF
ON
0000 OFF
ON
1000 OFF

1001
ON
OFF
ON
12
1002 OFF

Chapter 2 Instructions 3-85

KVNKA Chap 02_4aP.p65 85 08.3.11, 11:58 AM


HSP
2.4 Instruction Details

SET AND HSP Shortens time constant of specified input


HSP: High Speed FUN 1 8 : nnnn
relay to 10 µs to increase input response.

Example
Enable input
0000 HSP
0001
0001 0500
SET

0002 0501
SET

0003 0500
RES

0501
RES

Coding
Line No. Instruction Operand
0000 LD 0000
0001 HSP 0001
0002 LD 0001
2 0003 SET 0500
0004 LD 0002
0005 SET 0501
0006 LD 0003
0007 RES 0500
0008 RES 0501

Timing diagram
ON
OFF
0000
ON ON ON
0001
ON ON ON
0002
5 ms 5 ms 15 ms
ON ON
0003

ON ON
0500

ON
0501

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.

3-86 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 86 08.3.11, 11:58 AM


HSP
2.4 Instruction Details

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.

■ Input signal width


ON
OFF
1) 2) 3)
Output device

Output device
Output device

Inputdevice
Inputdevice

Inputdevice
Program Program Program
execution execution execution

Scan time Scan time Scan time

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 12
time as in 3).

Scan time < Input signal width < Normal time constant (10 ms ± 20%)

■ 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.


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

Operands
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

Key operation
SET AND ENT Operand ENT
FUN 1 8 R-SRCH (Relay No.) R-SRCH

Chapter 2 Instructions 3-87

KVNKA Chap 02_4aP.p65 87 08.3.11, 11:58 AM


HSP
2.4 Instruction Details

Applications of HSP Instruction


■ 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
0001 HSP Line No. Instruction Operand
0000
1-s timer 0000 LD 0001
0000 #00010 0001 HSP 0000
T000
Turns ON
0002 LD 0000
0500 T000 0500 timer for 1s 0003 OR 0500
when 0500 0004 TMR 000 #00010
is ON.
0005 ANB T000
0006 OUT 0500
Timing diagram

Scan

ON
0000 OFF

ON
0001 OFF

0500 ON

1s
2 * 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).

■ When using the interrupt instruction


Turn ON for 1st
scan only at startup.
2008
EI Interrupt enabled 
 Initial settings
2813
SET Input time constant 10 µs 
0500 #00010
T000 Turn ON for 1st scan only at startup.
T000 0500
RES Resets 0500 when T000 turns ON.
END

INT
0000 Sets interrupt input at 0000.
2002 0500
SET Sets 0500 when 0000 turns ON.

RETI

ENDH

Coding
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

3-88 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 88 08.3.11, 11:58 AM


MC / MCR
2.4 Instruction Details

MC: Master Control ANL LDB MC Selects ON/OFF status of relay coils, timers,
FUN 2 4 : or counters set before MCR instruction.
MCR: Master Control ANL ANB MCR
FUN 2 5 : Used in pairs with MC instruction to end the
Reset execution of MC instruction.

Example
0000 MC

0001 0500

0501

MCR

Coding
Line No. Instruction Operand
0000 LD 0000
0001 MC
0002 LD 0001
0003 OUT 0500
0004 OUB 0501
0005 MCR 12
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:

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.

Note: MC-MCR instructions cannot be used in the following configuration.


1. Nesting 2. Improper combination with STP-STE
instructions
MC STP
xxxx
MC MC

MCR STE

MCR MCR

➮ "STP, STE instructions" (p. 3-114)

Operands

Key operation
ANL LDB ENT ENT ANL ANB ENT ENT
FUN 2 4 R-SRCH R-SRCH
FUN 2 5 R-SRCH R-SRCH

Chapter 2 Instructions 3-89

KVNKA Chap 02_4aP.p65 89 08.3.11, 11:58 AM


MC / MCR
2.4 Instruction Details

Details of MC-MCR Instructions


■ Position of MC-MCR instructions
MC-MCR instructions can be used in the following positions.

1. MC-MCR instructions can 2. MC-MCR instructions can 3. STP-STE instructions can


be placed before or after be placed between STP be placed between MC
STP-STE instructions. and STE instructions. and MCR instructions.
STP STP MC
xxxx xxxx
STE MC STP
xxxx
MC MCR STE

MCR STE MCR

Making an input condition


The input condition for an MC instruction can be made as shown below:

0000 0001 0002 MC

0003 0500

MCR

Note: The scan time is not shortened even if the input relay of the MC instruction is
2 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.

0003 0500
This relay is ignored.
0001 MC

0002 0500
The last relay has priority.
MCR

3-90 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 90 08.3.11, 11:58 AM


MC / MCR
2.4 Instruction Details

Application of MC-MCR Instruction


■ 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
Scan
ON
0000 OFF
ON
0001 OFF
ON
0002 OFF
ON
0003 OFF

0500 ON ON ON
0501 ON ON ON
Coding
0502 ON ON ON
Line No. Instruction Operand
0000 LD 0000
0001 OUT 1000
0002 CON
0003 OUB 1001
0000 1000 1001 0004 LD 0000
0001
0005 DIFU 1002
0000 1002 1002 1100 1101 1102 0006 CON
0002 DIFU RES RES RES
0007 AND 1002
1000 MC
0003 0008 RES 1100
0009 CON
1100 1200 #00010 T000 1101
0004 STG T000 JMP 0010
0011
RES
CON
1101
12
1101 1201 #00020 T001 1102
0005 STG T001 JMP 0012 RES 1102
1102 1202 #00030 T002 1100 0013 LD 1000
0006 STG T002 JMP 0014 MC
MCR 0015 STG 1100
0007 0016 OUT 1200
1001 MC 0017 CON
0008
0018 TMR 000 #00010
0001 1203 0019 CON
0009
0020 AND T000
0002 1204 0021 JMP 1101
0010
0022 STG 1101
0003 1205
0011 0023 OUT 1201
0024 CON
MCR
0012 0025 TMR 001 #00020
0026 CON
1200 0500
0013 0027 AND T001
1203
0028 JMP 1102
0014 0029 STG 1102
1201 0501 0030 OUT 1202
0015 0031 CON
1204 0032 TMR 002 #00030
0016
0033 CON
1202 0502 0034 AND T002
0017
0035 JMP 1100
1205 0036 MCR
0018
0037 LD 1001
END 0038 MC
0019
0039 LD 0001
ENDH
0020 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

Chapter 2 Instructions 3-91

KVNKA Chap 02_4aP.p65 91 08.3.11, 11:58 AM


MEMSW
2.4 Instruction Details

MEMSW: ANL ORB MEMSW

Memory Switch
FUN 2 6 : $nnnn Sets memory switches.

Key operation
ANL ORB ENT Operand ENT
FUN 2 6 R-SRCH R-SRCH

Operands
$0000 to $FFFF

Example
MEMSW
$3800

Coding
Line No. Instruction Operand
0000 MEMSW $3800

• 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-
2 tion of the switch is specified by turning a certain bit ON or OFF.
SW4 SW3 SW2 SW1
MEMSW
3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 $3800
0 0 1 1 1 0 0 0 0 0 0 0 0 0 0 0
SW4 SW3 SW2 SW1

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

3-92 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 92 08.3.11, 11:58 AM


MEMSW
2.4 Instruction Details

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
■ Setting memory switches
Specify a hexadecimal number for each switch No.

SW4 SW3 SW2 SW1 (Switch No.)


3 2 1 0 3 2 1 0 3 2 1 0 3 2 1 0 MEMSW
(Example) 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 1 $0269
(8) (4) (2) (1)
Hexadeci- 0 2 6 9 Hexadecimal
23 22 21 20 mal number
number
0 0 0 0 0
0 0 0 1 1
0 0 1 0 2
Clears DM0000 to DM0999
0 0 1 1 3
0 1 0 0 4
when power is ON.
12
0 1 0 1 5
0 1 1 0 6
Retains Internal utility relay
0 1 1 1 7 5000 through 5999 and 6000
1 0 0 0 8 through 6999.
1 0 0 1 9
Retains all errors when power is ON.
1 0 1 0 A Retains utility relays 3000 through 3999.
1 0 1 1 B
1 1 0 0 C
1 1 0 1 D
1 1 1 0 E
1 1 1 1 F

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 ENT
R-SRCH
.

Description
To use internal utility MEMSW
To clear a DM when MEMSW
relays 1000 through $0004 operation is started. $0E00
1915 as latch relays.

To read-protect a MEMSW To clear a counter when MEMSW


$8000 $2000
program. operation is started.

To use a 24-bit high- MEMSW To use a 24-bit high- MEMSW


$0800 $1000
speed counter CTH0. speed counter CTH1.

Chapter 2 Instructions 3-93

KVNKA Chap 02_4aP.p65 93 08.3.11, 11:58 AM


NOP END / ENDH
2.4 Instruction Details

NOP: No Operation FUN 3


ORL RES
0 : Performs no operation.

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.

END END
END: End DM : Indicates end of each routine of program.
ENDH
ENDH: End Hi ENDH
TM : Indicates end of entire program.

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.
2
Normal program
END
Normal program
END

Subroutine program
Interrupt program ENDH

ENDH

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
END ENT ENDH ENT
DM R-SRCH TM R-SRCH

3-94 Chapter 2 Instructions

KVNKA Chap 02_4aP.p65 94 08.3.11, 11:58 AM


2.4 Instruction Details

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.

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
12
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

Chapter 2 Instructions 3-95

KVNKA Chap 02_4bP.p65 95 08.3.11, 11:59 AM


W-ON / W-OFF
2.4 Instruction Details

W-ON nnnn Turn ON second operand relay when first


W-ON: Wait ON F : ON
mmmm operand relay contact turns ON.
W-OFF: Wait OFF W-OFF nnnn Turns ON second operand relay when first
Li : OFF
mmmm operand relay contact turns OFF.

Example
0000 0001
ON
1000 W-ON
1000 0500

0002 0003
OFF
1001
W-OFF
1001 0501

Coding
Line No. Instruction Operand
0000 LD 0000
0001 W-ON 0001 1000
0002 LD 1000
0003 OUT 0500

2 0004 LD 0002
0005 W-OFF 0003 1001
0006 LD 1001
0007 OUT 0501

Timing chart
• W-ON
ON
OFF
0000
ON
OFF
0001

1000 ON ON
0500

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
ON
OFF
0002 ON

OFF
0003

1001 ON ON
0501

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.

3-96 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 96 08.3.11, 11:59 AM


W-ON / W-OFF
2.4 Instruction Details

Description
W-ON
Input operand
Same
0001 operation
0000 0001 0000 1000
ON
1000
1000

Output operand

• When input relay 0000 is ON, output operand 1000 turns ON as soon as the
contact of input operand 0001 turns ON.

W-OFF
Input operand
Same
0002 0003 operation 0003 0002 1001
OFF
1001
1001

Output operand

• 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.
12
Operands
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

* 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
W-ON
F ENT
First operand Second operand
(nnnn) (mmmm) R-SRCH
W-OFF
Li

Chapter 2 Instructions 3-97

KVNKA Chap 02_4bP.p65 97 08.3.11, 11:59 AM


W-UE / W-DE
2.4 Instruction Details

W-UE nnnn Turns ON second operand relay at rising


W-UE: Wait Up Edge E : mmmm edge of first operand relay contact.
W-DE: Wait Down Edge W-DE
: nnnn Turns ON second operand relay at falling
Lo mmmm edge of first operand relay contact.

Example
0000 0001

1000
W-UE
1000 0500

0002 0003

1001
W-DE
1001 0501

Coding

Line No. Instruction Operand


0000 LD 0000
0001 W-UE 0001 1000
0002 LD 1000
0003 OUT 0500
2 0004 LD 0002
0005 W-DE 0003 1001
0006 LD 1001
0007 OUT 0501

Timing chart
● W-UE

ON
OFF
0000
ON
OFF
0001

1000 ON
0500

• 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.

● W-DE
ON
OFF
0002
ON
OFF
0003

1001 ON
0501

• 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.

3-98 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 98 08.3.11, 11:59 AM


W-UE / W-DE
2.4 Instruction Details

Description
W-UE
Input operand 0001 1002
Same DIFU

0000 0001 operation 1002 0000 1000

1000
1000

Output operand

• When input relay 0000 is ON, the output operand turns ON at the rising edge of
the input operand.

W-DE
Input operand 0003 1003
Same DIFD

0002 0003 operation 1003 0002 1001

1001
1001

Output operand

• 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). 12
Note 3: Output operand relay Nos. for W-UE/W-DE instructions cannot be dupli-
cated in a program.

Operands
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

* 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
W-UE
E
First operand Second operand ENT
(nnnn) (mmmm) R-SRCH
W-DE
Lo

Chapter 2 Instructions 3-99

KVNKA Chap 02_4bP.p65 99 08.3.11, 0:00 PM


W-UE / W-DE
2.4 Instruction Details

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.

■ Difference between W-ON and W-UE

0000 0001 Output relay 0100 turns ON when both input relays
ON
1000 0000 and 0001 turn ON in any order.
0001
Output relay 1001 turns ON only when input relay
1001 0000 turns ON before input relay 0001.
0100 0500

1001 0501

ON
OFF
0000
ON
OFF
0001
1000
0500 ON ON
(W-ON)
1001
0501 ON (W-UE)

2
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.

3-100 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 100 08.3.11, 0:00 PM


W-UE
2.4 Instruction Details

Application of W-UE Instruction


■ 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
0000 0001
Line No. Instruction Operand
1000
1000 0002 0000 LD 0000
1001 0001 W-UE 0001 1000
1001 0003 0002 LD 1000
1002 0003 W-UE 0002 1001
1002 0500
0004 LD 1001
0005 W-UE 0003 1002
0006 LD 1002
0007 OUT 0500
Timing diagram

Scan
ON
0000 OFF
ON
0001 OFF

0002
ON
OFF
12
ON
0003 OFF

0500 ON

■ 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.

0000 1001 1000 0500


Leave warehouse
1000
0001 0000 1001 0501
Enter warehouse
1001

Coding
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

Timing diagram

Scan

ON
0000 OFF
ON
0001 OFF

0500 ON

0501 ON

Chapter 2 Instructions 3-101

KVNKA Chap 02_4bP.p65 101 08.3.11, 0:00 PM


CON
2.4 Instruction Details

RES ORB Represents series connection of output


CON: Connect FUN 0 6 : instruction with another instruction.

Example
0000 0500 0501 0502 0503

CON CON CON

Coding
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

Description
• When input relay 0000 turns ON, 0500, 0501, 0502, and 0503 turn ON.
2 • 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
RES ORB ENT ENT
FUN 0 6 R-SRCH R-SRCH

3-102 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 102 08.3.11, 0:00 PM


MPS / MRD / MPP
2.4 Instruction Details

MPS Stores current input and arithmetic flag


MPS: Push C : status.
MRD: Read MRD
: Reads input and arithmetic flag status
D
stored with PUSH.
MPP
MPP: Pop ch : Reads and clears input and arithmetic flag
status stored with PUSH.

Example
0000 MPS 0001 0500

0002 0501
MRD

0003 0502
MPP

Coding
Line No. Instruction Operand
0000 LD 0000
0001 MPS
0002 AND 0001
0003 OUT 0500
0004 MRD
0005 AND 0002
12
0006 OUT 0501
0007 MPP
0008 AND 0003
0009 OUT 0502

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


C
MRD ENT
D R-SRCH

MPP
ch

Chapter 2 Instructions 3-103

KVNKA Chap 02_4bP.p65 103 08.3.11, 0:00 PM


MPS / MRD / MPP
2.4 Instruction Details

MPS/MRD/MPP applications
MPS, MRD, and MPP instructions are used as follows:

0002 0003 0004 0500


Start of branch

MPS 0006 0501


Connection of branch

MRD 0007 0502


Connection of branch

MRD 0008 0503


End of branch

MPP

Coding
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
2

0000 0001 0002 0500

MPS MPS 0003 0501

0004 MPP 0005 0502

MPP MPS 0006 0503

MPP

Coding
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

3-104 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 104 08.3.11, 0:00 PM


MPS / MRD / MPP
2.4 Instruction Details

0000 0001 0002 0003 0004 0500

MPS MPS MPS MPS 0501

MPP 0502

MPP 0503

MPP 0504

MPP

Coding
Line No. Instruction Operand
0000 LD 0000
0001 MPS
0002 AND 0001
0003 MPS
0004 AND 0002
0005 MPS
0006 AND 0003
0007 MPS 12
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

Chapter 2 Instructions 3-105

KVNKA Chap 02_4bP.p65 105 08.3.11, 0:00 PM


STG / JMP / ENDS
2.4 Instruction Details

nnnn
STG: Stage LDB LDB
FUN 4 4 : STG Executes instructions in STG block when operand relay is ON.
nnnn
When transition condition relay is ON, turns OFF relay of current
JMP: Jump ANL SET
FUN 2 1 : JMP stage and transfers execution to stage specified by operand.
ENDS: End Stage When transition condition relay is ON, turns OFF relay
SET LDB
FUN 1 4 : ENDS
of current stage.

Example
2008 1000
SET Initial setting

1000 0000 1001


1) STG JMP

1001 0500 0001 1002


2) STG JMP

1002 0501 0002 1001


3) STG JMP

0003 1000
JMP

1003
JMP
1003 0502 0004
4) STG ENDS
2
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

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

3-106 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 106 08.3.11, 0:00 PM


STG / JMP / ENDS
2.4 Instruction Details

Note 1: The following table shows the status of each instruction between STG and
JMP/ENDS when STG operand relay turns OFF.
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.

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
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
12
* 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
LDB LDB ENT Operand ENT
FUN 4 4 R-SRCH (nnnn) R-SRCH

ANL SET ENT Operand ENT


FUN 2 1 R-SRCH (nnnn) R-SRCH

SET LDB ENT ENT


FUN 1 4 R-SRCH R-SRCH

Chapter 2 Instructions 3-107

KVNKA Chap 02_4bP.p65 107 08.3.11, 0:00 PM


STG
2.4 Instruction Details

Details of STG instruction


■ 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.

Sequential processing
Start

NO Start
SW ON?

2 YES
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.

■ 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.

I/O assignment
Lamp 1
KV

0000 0500
Start SW
Lamp 2

0501

Lamp 3

0502
COM COM

3-108 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 108 08.3.11, 0:00 PM


STG
2.4 Instruction Details

■ 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

0000 T000 1000 1000 (0500) turns ON for 1 second


when input 0000 turns ON.
1000 #00010
T000

T000 T001 1001 1001 (0501) turns ON for 3 seconds


when T000 turns ON.
1001 #00030
T001

T001 T002 1002 1002 (0502) turns ON for 5 seconds


when T001 turns ON.
1002 #00050
T002

T002 T003 1100


1100 (0500), 1101
(0501), and 1102 (0502)
12
1100 1101
turn ON for 7 seconds
1102
when T002 turns ON.

#00070
T003

T003 1000 The process is repeated from the


SET
beginning when T003 turns ON.
1000 0500

1100

1001 0501 OR circuit is required because


double coil cannot be used.
1101

1002 0502

1102

• With STG instruction

2008 1001
SET 1001 turns ON at the start of operation.

1001 0000 0500 #00010 T000 1002 0500 turns ON for 1 second when input
STG T000 JMP
0000 turns ON. Then, 1002 turns ON.
1002 0501 #00030 T001 1003
STG T001 JMP 0501 turns ON for 3 seconds when
1002 turns ON. Then, 1003 turns ON.
1003 0502 #00050 T002 1004
STG T002 JMP 0502 turns ON for 5 seconds when 1003
turns ON. Then, 1004 turns ON.
1004 0500 0501 0502
STG
0500, 0501, and 0502 turn ON for 7
seconds when 1004 turns ON.
#00070 T003 1001
T003 JMP The process is repeated from the
beginning when T003 turns ON.

Chapter 2 Instructions 3-109

KVNKA Chap 02_4bP.p65 109 08.3.11, 0:00 PM


STG
2.4 Instruction Details

■ Process progression with Wait instruction


2008 1000
SET

1000 0000 1100 1001


STG JMP
1100
1001 0500 0000 1101 1002
STG JMP
1101
1002 0501 0000 1102 1003
STG JMP
1102
1003 0502 0000 1103 1004
STG JMP
1103
1004 0500 0501 0502
STG

0000 1104 1000


JMP
1104

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)
2 Use the SFT instruction to turn OFF all STG instructions in an emergency.
SFT
2003
D

2003
1000 STG start relay
CLK
Reset input 1004 STG end relay
RES
Reset input
1000
SET Initial setting

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.

3-110 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 110 08.3.11, 0:00 PM


STG
2.4 Instruction Details

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).
1000 0501 0500 0001 1001
STG JMP

1001 0500 0501 0002 1002


STG JMP

Interlock
Double coil
A double coil can be used for an STG instruction.
1000 0500 0001 1100 1001
STG ON JMP
1100
1001 0501 0002 1101 1002
STG ON JMP
1101
1002 0500 0003 1102 1003
STG ON JMP
1102
Double coil

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. 12
1000 0500 0000 1001
STG SET JMP

1001 0501 0001 1002


STG SET JMP

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.
1000 0500 0001 0501
STG

STG operand
When the STG operand relay remains ON, 0500 does not turn OFF even if 0001
turns ON.
0000 1000
SET

1000 0500 0001 1001


STG JMP

Use a differentiation type instruction for the condition of the first STG instruction.
0000 1100 1100 1000
DIFU SET

1000 0500 0001 1001


STG JMP

Chapter 2 Instructions 3-111

KVNKA Chap 02_4bP.p65 111 08.3.11, 0:00 PM


STG / JMP
2.4 Instruction Details

JMP operand
Unlike the STG operand relay, the JMP operand relay No. can be duplicated in a
program.
1000 0500 0001 1001
STG JMP

1002
JMP

1001 0501 0002 1002


STG JMP

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.
1000 3000 0001 0500 1001
STG DIFU JMP

3000 0501

Application of STG and JMP instructions


■ 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.
2 Output relays 0500, 0501, and 0502 turn ON for 3 seconds.
0000 1100 1100 1000
DIFU SET 1000 turns ON at the rising edge of input 0000.
1000 0500 #00010 T000 1001
STG T000 JMP Output 0500 turns ON for 1 second.
1001 0500 0501 #00020 T001 1002
STG T001 JMP Outputs 0500 and 0501 turn ON for 2 seconds.
1002 0500 0501 0502 #00030 T002 1000
STG T002 JMP Outputs 0500, 0501, and 0502 turn ON for
3 seconds.

Coding

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

3-112 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 112 08.3.11, 0:00 PM


STG / JMP
2.4 Instruction Details

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.

■ 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.

0000 1100 1100 1000


DIFU SET

1000 0500 0001 1001


STG JMP

0002 1002
JMP

1001 0501 #00010 T000 1000


STG T000 JMP

1002 0502 #00020 T001 1000


STG T001 JMP

Coding
12
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

Chapter 2 Instructions 3-113

KVNKA Chap 02_4bP.p65 113 08.3.11, 0:00 PM


STP / STE
2.4 Instruction Details

LDB ANB STP Executes instructions between STP and


STP: Step FUN 4 5 : nnnn
STE when operand relay is ON.
STE
STE: Step End LDB ORL
FUN 4 :
3 Used with STP to make a program step.

Example
0000 1000

STP
1000

0001 0500

STE

Coding
Line No. Instruction Operand
0000 LD 0000
0001 OUT 1000
0002 STP 1000
0003 LD 0001
0004 OUT 0500
0005 STE
2
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- STP
1000
ecuted when the STP operand When 1000 is OFF,
A A is not executed.
relay is ON. When the operand
relay is OFF, the program STE

execution jumps to STE instruc-


B
tion. (Fig 1). Fig. 1

• STP-STE instructions can be


nested up to 8 levels deep as STP
shown in Fig. 2. When 1000 is 1000

OFF, steps 1) through 3) are not 1)


executed. Control jumps to the STP
STE instruction just above step 1001

4), then step 4) is executed. When 1000 is OFF,


2)
steps 1) through 3) are
When 1000 and 1001 are ON, STE not executed.
steps 1) through 3) are executed
in that order. When 1000 is ON 3)
and 1001 is OFF, steps 1), 3), STE
and 4) are executed in that
order, while step 2) is left unex- 4) Fig. 2
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.

3-114 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 114 08.3.11, 0:00 PM


STP / STE
2.4 Instruction Details

Tips
■ 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 a)


Scan
timer turns ON. The STE instruction is 0000 1000
SET
started with the timer remaining ON.
STP
1000

T000 0500

1000 #00050
T000 Timer Jump
T000 1000 remains
RES ON.
STE

b) 1000 is not reset immediately when the b)


Scan
timer turns ON but is reset at the next 0000 1000
SET
scan. The timer is reset before the STE
STP
instruction is started. 1000

Timer is reset.
T000 1000
RES

T000 0500
Timer Jump 12
1000 #00050 remains
T000
ON.
STE

■ Usage of STG and STP instructions


STG instruction
Use the STG instruction for process progression with branches.
0000 1000
SET

1000 0500 0001 1001


STG JMP

0002 1002
JMP

1001 0501 0003


STG ENDS

1002 0502 0004


STG ENDS

STP instruction
Use the STP instruction for process progression without branches.
0000 1000
SET

STP
1000

0002 1000 1001


RES SET

0001 0500

STE

STP
1001

0003 1001 1002


RES SET

0004 0501

STE

Chapter 2 Instructions 3-115

KVNKA Chap 02_4bP.p65 115 08.3.11, 0:00 PM


STP / STE
2.4 Instruction Details

Operands
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

* 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
LDB ANB ENT Operand ENT
FUN 4 5 R-SRCH (nnnn) R-SRCH

LDB ORL ENT ENT


FUN 4 3 R-SRCH R-SRCH

Application of STP and STE instructions


■ 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
2
0000 1000 1000 1001 Line No. Instruction Operand
DIFU SET
0000 LD 0000
STP
1001 0001 DIFU 1000
T000 1001
0002 CON
RES 0003 AND 1000
T000 0500 0004 SET 1001
0005 STP 1001
1001 #00020
T000 0006 LD T000
T000 1002 0007 RES 1001
SET
0008 LDB T000
STE 0009 OUT 0500
0010 LD 1001
STP
1002 0011 TMR 000 #00020
T001 1002 0012 LD T000
RES
0013 SET 1002
T001 0501 0014 STE
0015 STP 1002
1002 #00030
T001 0016 LD T001
STE 0017 RES 1002
0018 LDB T001
END 0019 OUT 0501
0020 LD 1002
ENDH
0021 TMR 001 #00030
0022 STE
0023 END
0024 ENDH
The double coils in different STP blocks operate properly.

3-116 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 116 08.3.11, 0:00 PM


ITVL
2.4 Instruction Details

ITVL
PLS
DMnnnn
ITVL Measures pulse-to-pulse interval or pulse
ITVL: Interval Timer #TM : PAUSE
mmmm
width in specified mode.
RES

Example "Pulse" input

0000 ITVL
PLS

0001
DM0000 Beginning of workpiece data table
PAUSE "Measurement Pause" input
0002
1000 First flag relay
RES

"Reset" input

Coding
Line No. Instruction Operand
0000 LD 0000
0001 LD 0001
0002 LD 0002
0003 ITVL DM0000 1000

Operation in the above example


Measures pulse-to-pulse interval or pulse width for input relay 0000.

ITVL instruction has two functions: 12


• 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 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
* 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 First operand Second operand ENT
#TM (nnnn) (mmmm) R-SRCH

Chapter 2 Instructions 3-117

KVNKA Chap 02_4bP.p65 117 08.3.11, 0:00 PM


ITVL
2.4 Instruction Details

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.

■ Data memory (DM) assignment


• Set the initial setting data to the first four data memories.

Data memory

DM XX + 00 Mode Specifies measurement mode (0 to 5).


Initial
01 MAX value Presets highest value in measurement
setting
range. is to be
02 MIN value Presets lowest value in measurement specified
range.
Preset No.of by user.
03 Specifies number of measurements for
measurements mean calculation (1 to 65535).
04 Measured value Stores current measured value.
05 MAX measured value Stores Max. measured value.
06 MIN measured value Stores Min. measured value.
07 Mean Stores mean value.
08 No.of measurements Stores number of times measurements
performed* actually performed.
2 09 Higher digits*
Stores higher 16 bits of accumulating
total of measurements. (#00000 to
#65535) ($0000 to $FFFF)
Stores lower 16 bits of accumulating
10 Lower digits* total of measurements. (#00000 to
#65535)($0000 to $FFFF)
Used for computing measured values, Max.
11 to 12 Work memory measured values, Min. measured values, mean
values, and accumulating totals. (Cannot be used)

■ Relay assignment
Relay

Relay +0 MAX error Turns ON and remains ON for one scan time when
measured value exceeds Max preset value.
+1
MIN error Turns ON and remains On for one scan time when
measured value goes below Min preset value.
Every
+2 measurements Turns ON at completion of every measurement and
completion remains ON for one scan time.

Measurements
+3 completion for Turns ON for one scan time at completion of the
mean calculation specified No. of measurements for mean value
calculation, then remains ON for one scan time.

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.

3-118 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 118 08.3.11, 0:00 PM


ITVL
2.4 Instruction Details

■ Mode setting
Write the desired mode No. into the first data memory.

Mode for pulse measurement

Pulse-to-pulse interval measurement Pulse width measurement


Pulse-to-pulse
Mode Unit Mode Pulse width Unit
interval

0 10 m sec 1 10 m sec

2 100 m sec 3 100 m sec

4 1 sec 5 1 sec

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.
Mode No. DM No. Description
Measure the contents of DM0000 and obtain the
10000 DM0000
average.
Measure the contents of DM0001 and obtain the
10001 DM0001
average.
• • • 12
• • •
10005 DM0005 Measure the contents of DM0005 and obtain the
average.
0006 Measure the contents of DM0006 and obtain the
10006 DM0006
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.

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.

Chapter 2 Instructions 3-119

KVNKA Chap 02_4bP.p65 119 08.3.11, 0:00 PM


ITVL
2.4 Instruction Details

Application of ITVL instruction


This section describes examples of pulse interval measurement.

■ 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.

2008 #00000 DM0000


LDA STA Sets mode 0 (Unit:10 ms).

2008 #00051 DM0001


LDA STA Sets max. setting value of measurement range to 510 ms.

2008 #00049 DM0002


LDA STA Sets min. setting value of measurement range to 490 ms.

2008 #00010 DM0003


LDA STA Sets number of averaging measurements to 10.
ITVL
0000
PLS Measures pulse interval when input relay 0000 turns ON.
DM0000
0001
PAUSE Pauses measurement while input relay 0001 turns ON.
1000
0002
RES Resets measurement when input relay 0002 turns ON.

1000 T000 0500


1000 turns ON for one scan when measured
value exceeds max. setting value (510 ms).
2 1001 #00030
T000 1001 turns ON for one scan when measured value
is below min. setting value (490 ms).
0500

Coding
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

Timing diagram
ON
0000 OFF
500ms 400ms 600ms

1000 ON

1 scan
1001 ON

1 scan
0500 ON ON

3 sec. 3 sec.

3-120 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 120 08.3.11, 0:00 PM


ITVL
2.4 Instruction Details

■ 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 User’s Manual" for data memory settings for the KL-
4AD.

2008 #01600 DM0000


LDA STA Measures contents of DM1600.

2008 #02000 DM0001


LDA STA Sets max. setting value to +3 V (2000).

2008 #01000 DM0002


LDA STA Sets min. setting value to +2 V (1000).

2008 #00100 DM0003


LDA STA Sets number of averaging measurements to 100.

ITVL
2003
PLS
DM0000
0001 Pauses measurement when input relay 0001 turns ON.
PAUSE
Resets measurement when input relay 0002 turns ON.
1000
0002
RES 12

1000 0500
0500 turns ON when measured value exceeds max. setting value.

1001 0501
0501 turns ON when measured value is below min. value.

1003 DM0007 DM0100


LDA STA Writes average into DM0100 every 100 measurement.

Coding

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

Chapter 2 Instructions 3-121

KVNKA Chap 02_4bP.p65 121 08.3.11, 0:00 PM


CALL / SBN / RET
2.4 Instruction Details

nn
RES RES
CALL: Subroutine Call FUN 0 0 : Executes subroutine specified by operand.
CALL

SBN Represents beginning of subroutine speci-


SBN: Subroutine Entry FUN ORL
3
AND
8 : nn
fied by operand.
RET: Subroutine Return ORL ORL RET
Represents end of subroutine.
FUN 3 3 :

Example
0000 00
CALL

END

SBN
00

RET

ENDH

Coding
Line No. Instruction Operand
0000 : :
: : :
2 : LD 0000
: CALL 00
: : :
: END :
: SBN 00
: : :
: RET :
: ENDH :

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
CALL 00 to 99
SBN 00 to 99
RET —

Key operations
RES ORL
FUN 0 3
ENT Operand ENT
R-SRCH R-SRCH
ORL AND
FUN 3 8
ORL ORL ENT ENT
FUN 3 3 R-SRCH R-SRCH

3-122 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 122 08.3.11, 0:00 PM


CALL / SBN / RET
2.4 Instruction Details

Application of subroutine
Program A)

2008 00
CALL
Normal scan
Program B)

END

SBN
00

Subroutine program
Subroutine
RET

ENDH

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

Program A) Program A)

12
0000 00 0000 00
CALL CALL Subroutine program

Program B) Program B)

■ 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.

0001 00
CALL

Program

END

SBN
01

Subroutine program

RET

SBN
00

0000 01
CALL
Call
RET

ENDH

Chapter 2 Instructions 3-123

KVNKA Chap 02_4bP.p65 123 08.3.11, 0:00 PM


CALL / SBN / RET
2.4 Instruction Details

■ 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.

0001 0500

Program

END

SBN
00

Subroutine program
RET

INT
0000

0002 00
CALL
Call
RETI

ENDH

Note 1: Subroutine Nos. for SBN instructions cannot be duplicated in a program.


(It can be duplicated for CALL instructions.)
2 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)

3-124 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 124 08.3.11, 0:00 PM


FOR / NEXT
2.4 Instruction Details

FOR
SET ORB
FOR: Repeat Start FUN 1 6 : nnnn Executes program between FOR and NEXT
NEXT
by number of times specified by operand.
ANL OR
NEXT: Repeat End FUN 2 9 : Represents end of repetition.

Example
2008 00
CALL

END

SBN
00

2002 #00100 TM02 #00000


LDA STA LDA

Specify the first DM No.(DM100) FOR


#00050
Specify the number of DMs to be
2002 initialized. #TM02 TM02
STA INC

NEXT

RET
12
ENDH

Coding
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

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.

Chapter 2 Instructions 3-125

KVNKA Chap 02_4bP.p65 125 08.3.11, 0:00 PM


FOR / NEXT
2.4 Instruction Details

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.

FOR
#05

FOR
#02

FOR
#05
1) 2) 3)
NEXT

NEXT

NEXT

• 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.
2 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
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

Key operation
SET ORB ENT Operand ENT
FUN 1 6 R-SRCH R-SRCH

ANL OR ENT ENT


FUN 2 9 R-SRCH R-SRCH

3-126 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 126 08.3.11, 0:00 PM


FOR / NEXT
2.4 Instruction Details

Indirect addressing
■ 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.

■ 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

TM15 value Data entered into internal register


20 DM0020
11000 1000 to 1015
12
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

TM02 value Specified destination


00 DM0000
13000 3000 to 3015

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.

■ Range of DM and relay Nos. that can be specified by "TMxx"

TMxx value DM/relay


0000 to 1999 DM0000 to DM1999
2000 to 9999 Cannot be used.
10000 to 27915 0000 to 17915

■ 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.

Chapter 2 Instructions 3-127

KVNKA Chap 02_4bP.p65 127 08.3.11, 0:00 PM


FOR / NEXT
2.4 Instruction Details

■ Data memory block transfer


The contents of DM0000 are
transferred to DM0100.
DM0000
••••••
The block of 100 data is
transferred.
Transfer a The contents of DM0099 are
DM0099
block of transferred to DM0199.
DM0100 data.
••••••

DM0199

• Comparison between a program with normal addressing and one with indirect
addressing.

Program with normal addressing Program with indirect addressing

0000 1000 0000 1000


DIFU DIFU

1000 DM0000 DM0100 1000 00


LDA STA CALL
Program steps
1000 DM0001 DM0101 are reduced by END
LDA STA
one-eighth.
1000 DM0002 DM0102 No. of data
SBN
LDA STA 00 memory to be
1000 DM0003 DM0103 2002 #00000 TM02 #00100 TM03
transferred.
2 LDA STA LDA STA LDA STA 1)
FOR
#0100 2)
1000 DM0098 DM0198 2002 #TM02 #TM03 TM02 TM03
LDA STA LDA STA INC INC 3)
1000 DM0099 DM0199 NEXT
LDA STA 4)
END RET

ENDH ENDH

The contents of DM0000 are transferred The first No. of the source DM block is specified
to DM0100. (DM0000).
The contents of DM0001 are transferred The first No. of the destination DM block is specified
to DM0101. (DM0100).
The contents of DM0002 are transferred The contents of the DM indirectly addressed by

to DM0102. "#TM02" is transferred to the internal register.



• The contents of the internal register are transferred



• to the DM indirectly addressed by "#TM03".


The contents of DM0099 are transferred Add "1" to both "TM02" and "TM03" to increment
to DM0199. the Nos. of the source and destination DMs by one.

3-128 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 128 08.3.11, 0:00 PM


FOR / NEXT
2.4 Instruction Details

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

2002 #TM02 #TM03 TM02 TM03


LDA STA INC INC

DM0000 is DM0100 is Add "1" to the Add "1" to the


indirectly indirectly current value of current value of
addressed. addressed. "TM02". "TM03".

2nd operation: TM02 value: 00001, TM03 value: 0101

2002 #TM02 #TM03 TM02 TM03


LDA STA INC INC

DM0001 is DM0101 is Add "1" to the Add "1" to the


indirectly indirectly current value of current value of
addressed. addressed. "TM02". "TM03".
• • • •

This operation is repeated.


12
100th operation: TM02 value: 0099, TM03 value: 0199

2002 #TM02 #TM03 TM02 TM03


LDA STA INC INC

DM0099 is DM0199 is Add "1" to the Add "1" to the


indirectly indirectly current value current value
addressed. addressed. of "TM02". of "TM03".

When the ladder program on line 3) is repeated 100 times, the contents of the
specified DM block are transferred.

Chapter 2 Instructions 3-129

KVNKA Chap 02_4bP.p65 129 08.3.11, 0:00 PM


FOR / NEXT
2.4 Instruction Details

Application of SBN-RET and FOR-NEXT instructions


■ 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.

0000 1000 1000 #00010 TM02 #00030 TM03 00


DIFU LDA STA LDA STA CALL Data is shifted from DM0010 to
Synchronous Shift start DM Shift end DM
No. (DM0010) No. (DM0030) DM0030.
signal END
is designated. is designated.

SBN
00

2002 TM03 #00001 TM04 TM02 TM05


LDA ADD STA SUB STA

Shift level FOR


TM05

2002 TM03 TM04 #TM03 #TM04


DEC DEC LDA STA
Indirect addressing is used Program lines which execute
to designate DM Nos.
NEXT data shift are grouped as a
subroutine.
2002 #00000 #TM02
LDA STA
Shift start DM No. is cleared to
"#00000" after data is shifted. RET

ENDH

2 Coding

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

3-130 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 130 08.3.11, 0:00 PM


HKEY
2.4 Instruction Details

HKEY
Reads hexadecimal key data on time-
HKEY: 16-Key Input FUN 1
SET LD
7 : nnnn
mmmm
sharing basis and outputs these data to
special utility relays 2900 to 2915.

Example Input relay

0005 HKEY
0000
0500

Output relay
Coding
Line No. Instruction Operand
0000 LD 0005
0001 HKEY 0000 0500

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.

12

Pressing two or more keys


+ COM 000 001 002 003 simultaneously is invalid.
24 KV
VDC - COM 500 501 502 503
0 1 2 3

4 5 6 7
Pressing two or more keys
8 9 A B simultaneously is OK.
(With diode)
C D E F

• 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).

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

• 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:

Relay No. 2814 R/W 2815 R


Status ON: Pressing two or more keys ON: Key input read operation has
simultaneously is not valid. completed.
R: Reading W: Writing
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.

Chapter 2 Instructions 3-131

KVNKA Chap 02_4bP.p65 131 08.3.11, 0:00 PM


HKEY
2.4 Instruction Details

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
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

Key operation
SET LD ENT Input relay Output relay ENT
FUN 1 7 R-SRCH R-SRCH

2 Application of HKEY instruction


■ Changing the preset value of internal counters using a BCD digital switch

Coding
2002 0001 #09999 C000 0600 Line No. Instruction Operand
C000
0000 0000 LD 2002
0005 HKEY
0104 0001 ANB 0001
0512 0002 C 000 #09999 0000
2815 2900 C000
LDA TBIN STA 0003 CON
0004 AND C000
END
0005 OUT 0600
0006 LD 0005
ENDH
0007 HKEY 0104 0512
0008 LD 2815
0009 LDA 2900
0010 CON
0011 TBIN
0012 CON
0013 STA C000
0014 END
0015 ENDH

• 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.

3-132 Chapter 2 Instructions

KVNKA Chap 02_4bP.p65 132 08.3.11, 0:00 PM


HKEY
2.4 Instruction Details

100 101 102 103


BCD Digital switch

Diode

1 2 4 8
+ COM 0104 0105 0106 0107
24 KV
VDC - COM 0512 0513 0514 0515

■ 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.
2008 2814
SET

2002 HKEY
0000
0500
2815 2900 2010 $03FF TM05 2010 TM05 TM06
LDA ANDA CMP STA DMX STA

2815 2900
LDA
2010 $03FF
ANDA
TM05
CMP
2010 TM05
STA 12
DM0000 #04 TM06 DM0000
LDA SLA STA STA

2815 2915 #00000


DW
DM0000
END

ENDH

Coding

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

Chapter 2 Instructions 3-133

KVNKA Chap 02_4bP.p65 133 08.3.11, 0:00 PM


2.4 Instruction Details

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


2 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

3-134 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 134 08.3.11, 0:02 PM


2.4 Instruction Details

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.

■ 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.

■ Arithmetic instructions executed using internal register

(Arithmetic instructions executed as binary code.)


Constant 3. 4. Data memory, Data memory accessed
Current T/C
Relay No.1. (decimal, temporary in indirect addressing via
value. 2.
hexadecimal) memory temporary memory

LDA instruction

TMIN
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
CMP MPX Con-
ADD DMX
SUB TBCD
stant
Internal register MUL TBIN

temporary memories
Data memories,
DIV ASC

STA direction
ANDA
ORA
EORA
RASC
12
SRA
SLA
Preset T/C Data memory, Data memory accessed RRA
Relay No value. 5. temporary in indirect addressing via RLA
COM
memory temporary memory INC
DEC

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.

Chapter 2 Instructions 3-135

KVNKA Chap 02_4cP.p65 135 08.3.11, 0:02 PM


DW
2.4 Instruction Details

DW nnnn
DW: Data Memory Write : DW
DMmmmm
Directly writes constant into data memory.

Example
First operand

2008 $0018 #00050


DW DW
DM0000 DM0001

Second operand

Coding
Line No. Instruction Operand
0000 LD 2008
0001 DW $0018 DM0000
0002 CON
0003 DW #00050 DM0001

• 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.

2 D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

Operand

D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0


Data memory

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.

2008 #00000 #00000


DW DW
DM0000 DM0001

Operands
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
Key operation
DW First operand Second operand ENT
reraly R-SRCH

Arithmetic flag
2009, 2010, 2011 No change
2012 No change

3-136 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 136 08.3.11, 0:02 PM


@xxxx
2.4 Instruction Details

@ Executes instruction only at rising edge of


@xxxx: Differentiation #,$ FUN : xxxx
input to input relay.

Example
Differentiation type instruction Every-scan type instruction

0000 DM0000 0000 DM0000


INC INC

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
Every-scan type instruction Differentiation type instruction

ON ON
0000 OFF 0000 OFF

INC Stopped Executed Stopped INC Stopped Stopped 12


Executed only once at the rising
edge of input relay 0000.

• 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
0000 DM0000 executed every scan time, incrementing
INC the contents of DM0000 by one, while
input relay 0000 is ON.

0000 DM0000 In the middle program, an INC instruc-


INC tion is executed and the contents of
DM0000 is incremented only when input
relay 0000 is turned from OFF to ON.

0000 1000 1000 DM0000


DIFU INC The bottom program uses the
every-scan type instruction which
performs the same operation as the
differentiation type instruction.

Operands

Key operation @ ENT


FUN Function No.
#,$ R-SRCH

Chapter 2 Instructions 3-137

KVNKA Chap 02_4cP.p65 137 08.3.11, 0:02 PM


TMIN / @TMIN
2.4 Instruction Details

ANB RES n
TMIN: Trimmer In FUN 5 0 : TMIN Inputs numerical value specified by digital
trimmer of access window (0 to 65535) to
@ ANB RES n
@TMIN: Trimmer Setting #,$ FUN 5 0 : TMIN internal register.

T000 preset value can be changed with trimmer as follows (#00000 to #65535):
Inputs trimmer rotation angle of 0 to internal register.
Transfers contents of internal register to timer T000
for use as preset value.
2002 0 T000
TMIN STA
0000 #00010 T000 0500
T000
Turns ON output 0500 when current value of
T000 reaches "#00000".
Timer T000 operates as ON-delay timer when 0000 is ON.

Coding
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
2 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.
• Timer/counter preset
value
Internal • Relay ch No.
TMIN STA
register
• Data memory
• Temporary memory

Digital trimmer Input Numeric data Transfer


value of access Destination
0 to 65535
window [0 to 65535]

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
Visual KV KV-300/24/40/80 KV-10/16
0, 1 0, 1 0

Key operation
FUN
ANB RES ENT Operand ENT
@ 5 0 R-SRCH R-SRCH
#,$ FUN
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

3-138 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 138 08.3.11, 0:02 PM


TMIN / @TMIN
2.4 Instruction Details

Applications of TMIN (Analog timer) instruction


■ Changing the timer setting value
Uses the digital trimmer (TMIN0) to change the setting value of a timer (0 to 6553.5
sec.).
2002 0 T000
TMIN STA

0000 #00010
T000

0500 T000 0500

Coding

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

■ Changing setting values for multiple timers


Uses the digital trimmer (TMIN0) to change setting values for multiple timers (0 to
6553.5 sec.). 12
2002 0 T000 T001 T002
TMIN STA STA STA

0000 #00010
T000

0500 T000 0500

0001 #00010
T001

0501 T001 0501

0002 #00010
T002

0502 T002 0502

Coding
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
In the above example, T000, T001, and T002 have the same setting value.

Chapter 2 Instructions 3-139

KVNKA Chap 02_4cP.p65 139 08.3.11, 0:02 PM


LDA / @LDA / STA @STA
2.4 Instruction Details

ANL ORL nnnn


LDA: Load A FUN 2 3 LDA Inputs value specified by operand to internal
nnnn
register.
@ ANL ORL
@LDA: Load A #,$ FUN 2
LDA
3
LDB ORL nnnn
STA: Store A FUN 4 3 STA
Transfers contents of internal register to
@ LDB ORL nnnn
@STA: Store A #,$ FUN 4 3 STA destination specified by operand.

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.
Source Input Storage Transfer Destination

1 Constant Decimal (#XXXXX) T/C preset T XXX


value 5
Hexadecimal ($XXXXX) C XXX

Internal register
T/C current T XXX
2
value C XXX Data memory DM XXXX
LDA STA 6
Data memory DM XXXX Temporary memory TM XX
3 Temporary memory
TM XX

4 Relay No. Relay No. XXXX Relay No. Relay No. XXXX 7
(Data type: operand) (Data type: operand)
➮ "Internal Register" (p. 3-126)

Operands
2 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

Key operation
FUN
ANL ORL ENT ENT
2 3 R-SRCH
Operand R-SRCH
@ FUN
#,$

FUN
LDB ANL ENT Operand ENT
@ 4 2 R-SRCH R-SRCH
#,$ FUN

3-140 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 140 08.3.11, 0:02 PM


LDA / @LDA / STA @STA
2.4 Instruction Details

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


■ Changing the counter setting value

0000 #00100 C001 When 0000 is ON, #00100 is transferred as C001


a) LDA STA preset value.
0000 #00200 C001 When 0000 is OFF, #00200 is transferred as C001
b) LDA STA preset value.

0002 #09999 C001 0500 When C001 current value equals to its preset value,
C001
0001 0500 turns ON.

Coding

Line No. Instruction Operand


0000 LD 0000
0001 LDA #00100 12
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

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.

Chapter 2 Instructions 3-141

KVNKA Chap 02_4cP.p65 141 08.3.11, 0:02 PM


LDA / @LDA / STA @STA
2.4 Instruction Details

■ Transferring the current counter value to data memory (DM)


0001 #09999
C010
0000
2002 C010 DM0000
a) LDA STA The C010 current value is transferred to DM0000.

Coding
Line No. Instruction Operand
0000 LDB 0001
0001 C 010 #099999 0000
0002 LD 2002
0003 LDA C010
0004 CON
0005 STA DM0000

Description
In step a), the C010 current value is transferred via the internal register and stored
into DM0000, throughout the operation.

■ Transferring the contents of data memory as a setting value for a timer

0002 DM0010 T002


a) LDA STA

2 0002 DM0011 T002


b) LDA STA

0003 #00010 T002 0500


T002

Coding
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

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".

3-142 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 142 08.3.11, 0:02 PM


LDA / @LDA / STA @STA
2.4 Instruction Details

■ 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.

2002 0000 0600


LDA STA

Coding
Line No. Instruction Operand
0000 LD 2002
0001 LDA 0000
0002 CON
0003 STA 0600

Description
Input (Internal register) Output
1 : ON
(KV basic unit) 16-bit (KV-E16T(P))
0 : OFF
000 ON 0000 1 D0 0600 ON 00
001 ON 0001 1 D1 0601 ON 01
002 ON 0002 1 D2 0602 ON 02
003 ON 0003 1 D3 0603 ON 03
004 OFF 0004 0 D4 0604 OFF 04
005 OFF 0005 0000 0 D5 0600 0605 OFF 05 12
006 OFF 0006 <LDA> 0 D6 <STA> 0606 OFF 06
007 OFF 0007 0 D7 0607 OFF 07 Out-
Input
008 ON 0008 1 D8 0608 ON 08 put
009 ON 0009 1 D9 0609 ON 09
010 ON 0010 1 D10 0610 ON 10
011 ON 0011 1 D11 0611 ON 11
012 OFF 0012 0 D12 0612 OFF 12
013 OFF 0013 0 D13 0613 OFF 13
014 OFF 0014 0 D14 0614 OFF 14
015 OFF 0015 0 D15 0615 OFF 15
Binary number

• 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)

Chapter 2 Instructions 3-143

KVNKA Chap 02_4cP.p65 143 08.3.11, 0:02 PM


LDA / @LDA / STA @STA
2.4 Instruction Details

■ 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
0008 #09999 Line No. Instruction Operand
C001
0009 0000 LDB 0008
0010 0000 $00FF C001 0001 C 001 #09999 0009
a) LDA ANDA TBIN STA
0002 LD 0010
0011 C001 0500 0003 LDA 0000
b) LDA TBCD STA
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
2 Description
Counter
setting
Digital switch value
Internal register
<59> (C001)
000 ON 1 D0 1 1 1 D0
001 OFF 0 D1 0 1 1 D1
002 OFF 0 D2 0 0 0 D2
003 ON 1 D3 1 1 1 D3
004 ON 1 D4 1 1 1 D4
005 OFF 07000 0 D5 $00FF 0 1 C001 1 D5
006 ON <LDA> 1 D6 <ANDA> 1 <TBIN> 0 <STA> 0 D6
007 OFF 0 D7 0 0 0 D7
Reset input 008 OFF ON/OFF 0 D8 Only low- 0 BCD 0 Data is 0 D8
order 2
Proximity 009 ON status is 1 D9 0 data is 0 transferred 0 D9
SW input trans- digits is converted as setting
010 ON ferred to 1 D10 used. 0 into binary 0 value of 0 D10
SW input
011 ON internal 1 D11 0 data. 0 counter. 0 D11
register.
012 OFF 0 D12 0 0 0 D12
013 OFF 0 D13 0 0 0 D13
014 OFF 0 D14 0 0 0 D14
015 OFF 0 D15 0 0 0 D15
0 1 3 4 5
2 + 2 + 2 + 2 + 2 = 1 + 2 + 8 + 16 + 32 = 59 (Decimal
number)

• 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.

3-144 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 144 08.3.11, 0:02 PM


LDA / @LDA / STA @STA
2.4 Instruction Details

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.

■ First-in first-out (FIFO) OK/NG


judgment
The data once fetched is written into DM0004, DM0000
DM0003, …, to DM0000 in this order. At the DM0001
Data
unloading timing, data is fetched from DM0002
shift
DM0004 and the contents of DM are shifted DM0003
to the next DM. DM0004

Unloading
timing

The OK/NG judgment and unloading timings can be used in asynchronous pro-
grams.
0000 1000 1000 0001 $1111 DM0000
DIFU LDA STA
OK/NG judgment "$1111" is transferred to
timing OK/NG judgment DM0000.
0001 $5555 DM0000
LDA STA
"$5555" is transferred to DM0000.

2002 DM0004 $0000 2010 DM0003 DM0004 $0000 DM0003


LDA CMP LDA STA LDA STA

2002 DM0003 $0000 2010 DM0002 DM0003 $0000 DM0002


Contents of DM is compared with "$0000".
LDA CMP LDA STA LDA STA When two values match, contents of one
2002 DM0002 $0000 2010 DM0001 DM0002 $0000 DM0001
previous DM is transferred, then "$0000" is
LDA CMP LDA STA LDA STA transferred to DM.
2002 DM0001 $0000 2010 DM0000 DM0001 $0000 DM0000
12
LDA CMP LDA STA LDA STA

0002 $0000 DM0004


LDA STA
Unloading "$0000" is transferred to DM
timing at unloading timing.

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0000 0035 STA DM0003
0001 DIFU 1000 0036 CON
0002 CON 0037 LDA $0000
0003 AND 1000 0038 CON
0004 MPS 0039 STA DM0002
0005 AND 0001 0040 LD 2002
0006 LDA $1111 0041 LDA DM0002
0007 CON 0042 CON
0008 STA DM0000 0043 CMP $0000
0009 MPP 0044 CON
0010 ANB 0001 0045 AND 2010
0011 LDA $5555 0046 LDA DM0001
0012 CON 0047 CON
0013 STA DM0000 0048 STA DM0002
0014 LD 2002 0049 CON
0015 LDA DM0004 0050 LDA $0000
0016 CON 0051 CON
0017 CMP $0000 0052 STA DM0001
0018 CON 0053 LD 2002
0019 AND 2010 0054 LDA DM0001
0020 LDA DM0003 0055 CON
0021 CON 0056 CMP $0000
0022 STA DM0004 0057 CON
0023 CON 0058 AND 2010
0024 LDA $0000 0059 LDA DM0000
0025 CON 0060 CON
0026 STA DM0003 0061 STA DM0001
0027 LD 0002 0062 CON
0028 LDA DM0003 0063 LDA $0000
0029 CON 0064 CON
0030 CMP $0000 0065 STA DM0000
0031 CON 0066 LD 0002
0032 AND 2010 0067 @LDA $0000
0033 LDA DM0002 0068 CON
0034 CON 0069 @STA DM0004

Chapter 2 Instructions 3-145

KVNKA Chap 02_4cP.p65 145 08.3.11, 0:02 PM


CMP / @CMP
2.4 Instruction Details

RES LDB nnnn


CMP: Compare FUN 0 4 : CMP
Compares contents of internal register with
@ RES LDB nnnn value specified by operand.
@CMP: Compare #,$ FUN 0 4 : CMP

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.
2009 2010 2011
(Internal register) < (Operand) ON OFF OFF
(Internal register) = (Operand) OFF ON OFF
(Internal register) > (Operand) OFF OFF ON

Comparing the current value of the counter and CMP value


0001 #09999
C001
0003
2002 C001 #01000 2009 0500
LDA CMP 1) (<)
2010 0501
2) (=)
2011 0502
3) (>)
2 2002 C001 #02000 2009 0503
LDA CMP 4) (≥)

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

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

3-146 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 146 08.3.11, 0:02 PM


CMP / @CMP
2.4 Instruction Details

Operands
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

Key operation
FUN
RES LDB ENT Operand ENT
@ 0 4 R-SRCH R-SRCH
#,$ FUN

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 12
• 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.
DM0000 #00999 2009
LDA CMP

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:
a b
LDA CMP

2009 2011 2010 2009 2011


a < b, a ≤ b, a = b, a ≥ b, a>b

Chapter 2 Instructions 3-147

KVNKA Chap 02_4cP.p65 147 08.3.11, 0:02 PM


CMP / @CMP
2.4 Instruction Details

Application of CMP instruction


■ Multi-level counter
Coding
0001 #09999 Line No. Instruction Operand
C000
0000 0000 LDB 0001
2002 C000 #00999 2011 0500
LDA CMP 0001 C 000 #099999
0000
#01999 2011 0500 0501 0002 LD 2002
CMP
0003 LDA C000
#02999 2011 0500 0501 0502 0004 CON
CMP
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
2 0018 CON
0019 ANB 2011
0020 ANB 0500
0021 ANB 0501
0022 OUT 0502
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.

■ 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.

2002 DM0000 #01000 2009 0500


LDA CMP DM0000<#01000

2010 0501
DM0000=#01000

2011 0502
DM0000>#01000

Coding

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

3-148 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 148 08.3.11, 0:02 PM


CMP / @CMP
2.4 Instruction Details

■ 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.

0001 #09999
C001
0000
2002 C001 #01000 2011 0500
LDA CMP C001≤#01000

2002 C001 #02000 2009 0501


LDA CMP C001≥#02000

Coding

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

■ Changing the CMP setting value


Compares the current value of counter C000 with the CMP setting value. The setting 12
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.

2002 0 DM0000
TMIN STA Sets range of TMIN from 0 to 100.

0001 #09999
C000
00000
2002 C000 DM0000 2009 0500
LDA CMP

2009 0501

Coding
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

Chapter 2 Instructions 3-149

KVNKA Chap 02_4cP.p65 149 08.3.11, 0:02 PM


ADD / @ADD / SUB / @SUB / MUL / @MUL / DIV / @DIV
2.4 Instruction Details

RES RES nnnn


ADD: Add FUN 0 0 : ADD Adds value specified by operand to contents of
nnnn
internal register, and inputs result back to same
@ADD: Add @ RES RES
#,$ FUN 0 0 : ADD internal register.
LDB ORB nnnn
SUB: Subtract FUN 4 : SUB Subtracts value specified by operand from
6
contents of internal register, and inputs results
@ LDB ORB nnnn
@SUB: Subtract #,$ FUN 4 6 : SUB back to same register.
ANL AND nnnn
MUL: Multiply FUN 2 8 : MUL Multiplies contents of internal register by value
specified by operand, and inputs result back to
@ ANL AND nnnn
@MUL: Multiply #,$ FUN 2 8 : MUL same register.
SET SET nnnn
DIV: Divide FUN 1 : DIV Divides contents of internal register by value
1
specified by operand, and inputs result back to
@ SET SET nnnn
@DIV: Divide #,$ FUN 1 1 : DIV same register.

ADD, SUB, MUL, and DIV allow arithmetic instructions between the contents of
internal register and the value specified by the operand.

Decimal (#XXXXX)
Constants

ADD
Internal register

Internal register
Hexadecimal ($XXXX)
Operand

SUB
Data memories

MUL DM0000 to DM1999

2 DIV
TM00 to TM31
#TM00 to #TM29

Arithmetic operation Result

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
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

Key operation
FUN
RES RES ENT Operand ENT
@ 0 0 R-SRCH R-SRCH
#,$ FUN

FUN
LDB ORB ENT Operand ENT
@ 4 6 R-SRCH R-SRCH
#,$ FUN

FUN
ANL AND ENT Operand ENT
@ 2 8 R-SRCH R-SRCH
#,$ FUN

FUN
SET SET ENT Operand ENT
@ 1 1 R-SRCH R-SRCH
#,$ FUN

3-150 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 150 08.3.11, 0:02 PM


ADD / @ADD
2.4 Instruction Details

ADD (Addition)
2002 DM0000 #00100 DM0001
LDA ADD STA

Coding
Line No. Instruction Operand
0000 LD 2002
0001 LDA DM0000
0002 CON
0003 ADD #00100
0004 CON
0005 STA DM0001

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
12
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.

Example:
Internal register 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 = $FFFF

Operand + 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 = $0002

0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 = $0001
Overflow 1
Special 2009 Input back internal register Result
utility relay

Tips
Solution when operation result overflows 16 bits

2002 DM0000 DM0001 2009 DM0002 #00000 DM0003


LDA ADD STA LDA STA

2009 DM0002 #00001 DM0003


STA LDA STA

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)

Chapter 2 Instructions 3-151

KVNKA Chap 02_4cP.p65 151 08.3.11, 0:02 PM


ADD / @ADD
2.4 Instruction Details

Application of ADD instruction


■ Total count
Writes the total count of counters C001 to C003 into DM0100. The total count must
be within #65535.

0000 #09999 C001 DM0001


C001 LDA STA Writes C001 current value into DM0001.
0001
0000 #09999 C002 DM0002
C002 LDA STA Writes C002 current value into DM0002.
0002
0000 #09999 C003 DM0003
C003 LDA STA Writes C003 current value into DM0003.
0003
2002 DM0001 DM0002 DM0003 DM0100 Writes total count (DM0001 + DM0002 +
LDA ADD ADD STA DM0003) into DM100.

Coding

Line No. Instruction Operand


0000 LDB 0001
0001 C 010 #099999 0000
0002 CON
0003 LDA C001
0004 CON
2 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

3-152 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 152 08.3.11, 0:02 PM


SUB / @SUB
2.4 Instruction Details

SUB (Subtraction)
2002 DM0000 #00100 DM0001
LDA SUB STA

Coding

Line No. Instruction Operand


0000 LD 2002
0001 LDA DM0000
0002 CON
0003 SUB #00100
0004 CON
0005 STA DM0001

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. 12
Special utility relay 2009 turns ON.

Internal register 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 = $0001

Operand - 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 1 = $FFFF

0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 = $0002
Underflow 1
2's complement is stored.
2009

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
2002 DM0000 DM0001 2009 DM0002
LDA SUB STA (Stores positive value)
Absolute value
2009 #0001 DM0003
COM ADD STA (Stores negative value) is stored.

Positive value DM0002


DM0000 - DM0001 =
Negative value DM0003

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)

Chapter 2 Instructions 3-153

KVNKA Chap 02_4cP.p65 153 08.3.11, 0:02 PM


SUB / @SUB
2.4 Instruction Details

Application of SUB instruction


■ 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.

2002 DM0000 DM0001 2009 #0005 2009 1000


LDA SUB CMP

2009 DM0001 DM0000 #00005 2009 1001


LDA SUB CMP

1000 0500

1001

Coding

Line No. Instruction Operand


0000 LD 2002
0001 LDA DM0000
0002 CON
0003 SUB DM0001
0004 MPS
0005 ANB 2009
0006 CMP #00005
2 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

3-154 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 154 08.3.11, 0:02 PM


MUL / @MUL
2.4 Instruction Details

MUL (Multiplication)
2002 DM0000 #00100 DM0001
LDA MUL STA

Coding

Line No. Instruction Operand


0000 LD 2002
0001 LDA DM0000
0002 CON
0003 MUL #00100
0004 CON
0005 STA DM0001

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 #00100→DM0001 (#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, 12
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.

Internal register F F F F

Operand 0 0 0 2 Hexadecimal number

0 0 0 1 F F F F

(TM00) (Internal register)

Tips
Solution when operation result overflows 16 bits
2002 DM0000 DM0001 DM0002 TM00 DM0003
LDA MUL STA LDA STA

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)

Chapter 2 Instructions 3-155

KVNKA Chap 02_4cP.p65 155 08.3.11, 0:02 PM


MUL / @MUL / DIV / @DIV
2.4 Instruction Details

Application of MUL instruction


■ 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.

0001 #09999
C001
0000
2002 C001 DM0000 DM0100 TM00 DM0101
LDA MUL STA LDA STA

Coding

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
2 0011 STA DM0101

DIV (Division)

2002 DM0001 TM00 DM0000 #00100 DM0002 TM00 DM0003 TM01 DM0004
LDA STA LDA DIV STA LDA STA LDA STA

High-order Low-order Low-order High-order Remainder

Coding

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

3-156 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 156 08.3.11, 0:02 PM


DIV / @DIV
2.4 Instruction Details

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.

TM00 Internal register Operand


High-order 16 bits Low-order 16 bits

TM00 Internal register TM01


High-order 16 bits Low-order 16 bits Remainder (16 bits)

Quotient
Example

DM0001 DM0000
High-order 16 bits Low-order 16 bits
#00100
12
DM0003 DM0002 DM0004
High-order 16 bits Low-order 16 bits Remainder (16 bits)

Quotient

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

02002 #00000 TM00 DM0000 DM0001 DM0002 TM01 DM0003


LDA STA LDA DIV STA LDA STA

TM00 • DM0000 = TM00 • DM0002 ••• DM0003


High-order Low-order High-order Low-order Remainder
16 bits 16 bits 16 bits 16 bits

Quotient

Chapter 2 Instructions 3-157

KVNKA Chap 02_4cP.p65 157 08.3.11, 0:02 PM


DIV / @DIV
2.4 Instruction Details

Application of DIV instruction


■ 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.

0000 #09999 C001 DM0001


C001 LDA STA Writes the C001 current value into DM0001.
0001
0000 #09999 C002 DM0002
C002 LDA STA Writes the C002 current value into DM0002.
0002
0000 #09999 C003 DM0003
C003 LDA STA Writes the C003 current value into DM0003.
0003
2002 DM0001 DM0002 DM0003
LDA ADD ADD (DM0001+DM0002+DM0003)

2002 #00000 TM00


LDA STA

2002 #00003 0500


DIV TBCD STA ÷ 3 ➞ Output to 0500 to 0515 in 4-digit BCD.

Coding

Line No. Instruction Operand


2 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

3-158 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 158 08.3.11, 0:02 PM


ANDA / @ANDA
2.4 Instruction Details

RES SET nnnn ANDs contents of internal register and


ANDA: AND A FUN 0 1 : ANDA
value specified by operand for each of
@ nnnn 16 bits, and inputs result back to same
@ANDA: (Logical product) #,$ FUN
RES SET
0 1 : ANDA
register.

Example
0000 DM0000 $00FF DM0001
LDA ANDA STA

(DM0000) ^ ($00FF) = (DM0001)


Logical product
Coding
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 ANDA $00FF
0004 CON
0005 STA DM0001

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.
12
• 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".

D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0


AND (Logical product)
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 DM0000 ($F0F0) truth table (Result)
Contents of DM0000 Internal Operand Internal
are transferred to the DM0000 register register
internal register. LDA
1 1 1
Internal
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 ($F0F0) 1 0 0
register
AND 0 1 0
0 0 0

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 Operand ($F0F0)
Only when both bits of the
$00FF These values are ANDed for internal register and the
ANDA each bit to obtain logical product. operand are "1", will the logical
Internal ($F0F0)
product be "1".
0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0
register
The result is transferred DM0001
to DM0001. STA

0 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 DM0001 ($00F0)

Operands
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

Key operation FUN


RES SET ENT Operand ENT
@ 0 1 R-SRCH R-SRCH
#,$ FUN

Chapter 2 Instructions 3-159

KVNKA Chap 02_4cP.p65 159 08.3.11, 0:02 PM


ANDA / @ANDA
2.4 Instruction Details

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.
0004 #00300
C004
0005
2002 0100 $000F C004
LDA ANDA TBIN STA

Application of ANDA instruction


■ 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.
2
2002 7000 $00FF C000
LDA ANDA TBIN STA Converts data of 7000 to 7007 to BIN and
writes it into C000.
2002 7000 $FF00 #08 T001
LDA ANDA SRA TBIN STA Shifts data to right by 8 bits, converts it to BIN,
and writes it into T001.
0001 #09999
C000 Sets C000.
0000
0001 #09999
T001 Sets T001.

Coding

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

3-160 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 160 08.3.11, 0:02 PM


ORA / @ORA
2.4 Instruction Details

ORL SET nnnn


ORA: Or A FUN 3 1 : ORA ORs contents of internal register and value
nnnn
specified by operand for each of 16 bits,
@ORA: (Logical sum) @ ORL SET
#,$ FUN 3 1 : ORA and inputs result back to same register.

Example 0000 DM0000 $00FF DM0001


LDA ORA STA

(DM0000) U ($00FF) = (DM0001)


Logical sum

Coding
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 ORA $00FF
0004 CON
0005 STA DM0001

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.
12
• The contents of the internal register are transferred to DM0001.
• The following shows the case when DM0000 is "$F0F0".

D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0


OR (Logical sum)
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 DM000 ($F0F0) truth table (Result)

Contents of DM0000 are Internal Internal


transferred to the internal DM0000 register Operand register
register. LDA
1 1 1
Internal
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 ($F0F0) 1 0 1
register
OR 0 1 1
0 0 0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 Operand ($00FF)

$00FF These values are ORed for Only when both bits of the
ORA each bit to obtain logical sum. internal register and the
Internal
operand are "0", will the logical
1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1 ($F0FF) sum be "0".
register

The result is transferred DM0001


to DM0001. STA

1 1 1 1 0 0 0 0 1 1 1 1 1 1 1 1

Operands
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
Key operation
FUN
ORL SET ENT Operand ENT
@ 3 1 R-SRCH R-SRCH
#,$ FUN

Chapter 2 Instructions 3-161

KVNKA Chap 02_4cP.p65 161 08.3.11, 0:02 PM


ORA / @ORA
2.4 Instruction Details

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).
0004 #00300
C004
0005
2002 0100 $000F DM0000 0200
LDA ANDA STA LDA

$000F #04 DM0000 C004


ANDA SLA ORA TBIN STA

2
Application of ORA instruction
■ 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.

0000 #00099
C000 Sets C000.
0001
2002 0500 $FF00 DM0000
LDA ANDA STA Writes data of 0008 to 0015 into DM0000.

2002 C000 $00FF


LDA TBCD ANDA Converts the current value of C000 to BCD and retains
the low-order 2 digits of BCD in the internal register.
2002 DM0000 0500
ORA STA ORs the data in the internal register and the DM0000
data and sends the ORed data to 0500 to 0515.

Coding
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

3-162 Chapter 2 Instructions

KVNKA Chap 02_4cP.p65 162 08.3.11, 0:02 PM


ORA / @ORA
2.4 Instruction Details

■ 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.
0000 #00099
C000 Sets C001.
0001
2002 0000 $000F DM0000
LDA ANDA STA Writes data of 7000 to 7003 into DM0000.

2002 0100 $000F


Writes data of 8000 to 8003 into internal regis-
LDA ANDA
ter.
2002 #04 DM0000 C001
SLA ORA TBIN STA 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.
Coding
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
12
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

Chapter 2 Instructions 3-163

KVNKA Chap 02_4cP.p65 163 08.3.11, 0:02 PM


EORA / @EORA
2.4 Instruction Details

EORA: Exclusive Or A SET ANB nnnn


FUN 1 5 : EORA EXCLUSIVE ORs contents of internal
register and operand for each of 16 bits,
@EORA: (Exclusive @ SET ANB
: nnnn
and inputs result back to same register.
#,$ FUN 1
EORA
logical sum) 5

Example
0000 DM0000 $00FF DM0001
LDA EORA STA

(DM0000) U ($00FF) = (DM0001)


Exclusive
logical sum

Coding
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 EORA $00FF
0004 CON
0005 STA DM0001
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
2 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".
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 EOR (Exclusive OR)
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 DM0000 ($F0F0) truth table (Result)

Contents of DM0000 are Internal Internal


Operand
transferred to the internal DM0000 register register
LDA
register. 1 1 0
Internal
1 1 1 1 0 0 0 0 1 1 1 1 0 0 0 0 register ($F0F0) 1 0 1
EORA 0 1 1
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 Operand ($00FF) 0 0 0

$00FF These values are EORed for each Only when the bits of the
EORA bit to obtain exclusive OR value. internal register and the
Internal operand have different values,
1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 register ($F00F) will the exclusive logical sum
be "1".
The result is trans-
DM0001
ferred to DM0001. STA

1 1 1 1 0 0 0 0 0 0 0 0 1 1 1 1 DM0000 ($F00F)

Operands
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

Key operation
FUN
SET ANB ENT Operand ENT
@ 1 5 R-SRCH R-SRCH
#,$ FUN

3-164 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 164 08.3.11, 0:03 PM


EORA / @EORA
2.4 Instruction Details

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.

2002 0000 $0F0F 2010 0500


LDA EORA

Application of EORA instruction


■ Judgment of matching data
Turns ON 0500 when the ON/OFF statuses of input relays 0100 to 0107 match the
DM0000 setting value.
12
2008 $00AA DM0000
LDA STA

2002 0100 $00FF DM0000 2010 0500


LDA ANDA EORA

Coding
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

D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

$BBBB 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 0100 to 0115


ANDA

$00FF 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 Operand

$00BB 0 0 0 0 0 0 0 0 1 0 1 1 1 0 1 1 Internal register


EORA

$00AA 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 DM0000

$0011 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 Internal register 2010 is OFF. When the


value of internal register is 0000, 2010 turns ON.

When 2010 is ON, the two values match. Judges match between the operand and the
When 2010 is OFF, the two values do not match. data of 0100 to 0107.

Chapter 2 Instructions 3-165

KVNKA Chap 02_4dP.p65 165 08.3.11, 0:03 PM


SRA / @SRA / SLA / @SLA
2.4 Instruction Details

LDB SET #dd


FUN 4 1 : SRA
SRA: Shift Right A Moves contents of internal register
#dd
@SRA: Shift Right A
@
#,$ FUN
LDB SET
4 1 : SRA serially right by value specified by oper-
#dd and.
SLA: Shift Left A LDB RES
FUN 4 0 : SLA

@SLA: Shift Left A Moves contents of internal register


@ LDB RES : #dd
#,$ FUN 4 0 SLA serially left by value specified by operand.

Example
0000 DM0000 #05 DM0001
LDA SRA STA

0001 DM0010 #10 DM0011


LDA SLA STA

Coding
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 SRA #05
0004 CON
0005 STA DM0001
2 0006 LD 0001
0007 LDA DM0010
0008 CON
0009 SLA #10
0010 CON
0011 STA DM0011

Operands
#01 to #16

Key operation
FUN
LDB SET ENT Operand ENT
@ 4 1 R-SRCH R-SRCH
#,$ FUN

FUN
LDB RES ENT Operand ENT
@ 4 0 R-SRCH R-SRCH
#,$ FUN

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

3-166 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 166 08.3.11, 0:03 PM


SRA / @SRA / SLA / @SLA
2.4 Instruction Details

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.
Carry
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 2009
1 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0
0

Carry
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 2009
0 0 0 0 0 1 1 0 0 1 0 0 0 1 1 1 0

• 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. 12
Carry
2009 D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

1 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0
0

Carry
2009 D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

1 1 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0

Note: Special utility relay 2009 may turn ON in accordance with the operation
results; however, it changes immediately when another operation is executed.

Chapter 2 Instructions 3-167

KVNKA Chap 02_4dP.p65 167 08.3.11, 0:03 PM


SRA / @SRA / SLA / @SLA
2.4 Instruction Details

Application of SRA/SLA instructions


■ 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
2002 0000 $0FF0 #04 DM0000
LDA ANDA SRA STA

0100 $00FF #08 DM0000 C004


LDA ANDA SLA ORA STA

0001 #09999
C004
0000

■ 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.
0001 #00099
C001 Sets C001.
0000
2002 0100 $F000
LDA ANDA Sends the data of 0112 to 0115 to internal register.

2002 #12 DM0000 Shifts the value of internal register to right by 12 bits and writes it
SRA STA
into DM0000.
2 2002 0000 $000F
LDA ANDA Sends the data of 0000 to 0003 to internal register.

2002 #04 DM0000 Shifts the data of internal register to left by 4 bits, ORs the internal
SLA ORA
register data and the data of DM0000, and sends the ORed data to
the internal register.
2002 C001
TBIN STA Converts the data of internal register to BIN data and writes it into
C001.

Coding
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

3-168 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 168 08.3.11, 0:03 PM


RRA / @RRA / RLA / @RLA
2.4 Instruction Details

ORL LD #dd
RRA: Rotate Right A FUN 3 7 : RRA Rotates contents of internal register and
#dd
carry (2009) clockwise by operand value.
@ ORL LD
:
@RRA: Rotate Right A #,$ FUN 3 7 RRA

ORL ANB #dd Rotates contents of internal register and


RLA: Rotate Left A FUN 3 5 : RLA
carry (2009) counterclockwise by operand
@ ORL ANB #dd value.
@RLA: Rotate Left A #,$ FUN 3 5 : RLA

Example
0000 DM0000 #01 DM0001
LDA RRA STA

0001 DM0010 #04 DM0011


LDA RLA STA

Coding
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 RRA #01
0004 CON
0005 STA DM0001
0006 LD 0001 12
0007 LDA DM0010
0008 CON
0009 RLA #04
0010 CON
0011 STA DM0011

Operands
#01 to #16

Key operation
FUN
ORL LD ENT Operand ENT
@ 3 7 R-SRCH R-SRCH
#,$ FUN

FUN
ORL ANB ENT Operand ENT
@ 3 5 R-SRCH R-SRCH
#,$ FUN

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.

Chapter 2 Instructions 3-169

KVNKA Chap 02_4dP.p65 169 08.3.11, 0:03 PM


SRA / @SRA / SLA / @SLA
2.4 Instruction Details

Use @RRA, a differentiation type instruction, to execute the instruction only once
when input relay 0000 turns ON.
Carry
2009 D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

0 1 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0

Carry
2009 D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

0 0 1 1 0 0 1 0 0 0 1 1 1 0 0 1 0

• 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.
Carry
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 2009
1 1 0 0 1 0 0 0 1 1 1 0 0 1 0 0 0

Carry
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0 2009

2 1 0 0 0 1 1 1 0 0 1 0 0 0 1 1 0 0

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


■ Error input count
Writes the number of error detection sensors, which are connected to input relays
(0000 to 0015) and turn ON, into DM0000.

2002 0000
LDA Writes the data of 0000 to 0015 into internal register.

FOR
#00016 Executes FOR-NEXT instruction 16 times.

2002 #01 2009 TM10


RRA INC Shifts the data including carry (2009) to right, and
increments TM10 by 1 when 2009 is ON.
NEXT

2002 TM10 DM0000 #00000 TM10


LDA STA LDA STA Writes the TM10 data into DM0000, and then writes
#00000 to TM10.

Coding

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

3-170 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 170 08.3.11, 0:03 PM


COM / @COM
2.4 Instruction Details

RES ANB
COM: Complement FUN 0 5 : COM
Inverts contents of each bit in internal
@COM: (Bit inversion) @ RES ANB
: register.
#,$ FUN 0
COM
5

Example
0000 DM0000 DM0001
LDA COM STA

Coding
Line No. Instruction Operand
0000 LD 0000
0001 @LDA DM0000
0002 CON
0003 @COM
0004 CON
0005 @STA DM0001

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". 12
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

DM0000 0 1 0 1 1 1 1 1 0 1 0 1 1 1 1 1 = $5F5F

Bit inversion COM instruction

DM0001 1 0 1 0 0 0 0 0 1 0 1 0 0 0 0 0 = $A0A0

Note:
0000 DM0000 DM0001
LDA COM STA

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
FUN
RES ANB ENT ENT
@ 0 5 R-SRCH R-SRCH
#,$ FUN

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

Chapter 2 Instructions 3-171

KVNKA Chap 02_4dP.p65 171 08.3.11, 0:03 PM


INC / @INC / DEC / @DEC
2.4 Instruction Details

nnnn
INC: Increment Memory FUN 1
SET OR
9 : INC
Adds 1 to contents of data memory
@ SET OR nnnn specified by operand.
@INC: Increment Memory #,$ FUN 1 9 : INC

RES LD nnnn
DEC: Decrement Memory FUN 0 7 : DEC Subtracts 1 from contents of data
nnnn memory specified by operand.
@DEC: Decrement Memory @
#,$ FUN
RES LD
0 7 : DEC

Example 0000 DM0000


INC

DM0001
DEC

Coding
Line No. Instruction Operand
0000 LD 0000
0001 @INC DM0000
0002 @DEC DM0001

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
2 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.
@ INC instruction
0 0 1 0 Contents of data memory specified by operand

0 0 0 1 1 is added.
+

0 0 1 1 Contents of data memory specified by operand

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.
@ DEC instruction

0 0 1 1 Contents of data memory specified by operand

0 0 0 1 1 is subtracted.

0 0 1 0 Contents of data memory specified by operand

Operands

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

3-172 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 172 08.3.11, 0:03 PM


INC / @INC / DEC / @DEC
2.4 Instruction Details

Key operation
FUN
SET OR ENT ENT
1 9 R-SRCH
Operand R-SRCH
@ FUN
#,$

FUN
RES LD ENT ENT
0 7 R-SRCH
Operand R-SRCH
@ FUN
#,$

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.
0000 DM0000 0000 DM0000
INC INC

Tips 12
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.
0000 DM0000
INC

0001 DM0000
DEC

Applications of INC/DEC instructions


■ 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.

2008 #00000 DM0000


LDA STA Sets #00000 to DM0000 at startup.

0000 DM0000 Increments DM0000 by 1 at UP edge


INC
of input relay 0000.
0001 DM0000 Decrements DM0000 by 1 at UP edge
DEC
of input relay 0001.
0005 #00000
DW Clears DM0000 to #00000 when 0005
DM0000 turns ON.

Coding
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

Chapter 2 Instructions 3-173

KVNKA Chap 02_4dP.p65 173 08.3.11, 0:03 PM


INC / @INC / DEC / @DEC
2.4 Instruction Details

■ Total count 1
Writes the total count of 4 lines (0000 to 0003) into DM0000.
Reset input relay is 0005.

2008 #00000 DM0000


LDA STA Sets #00000 to DM0000 at startup.

0000 DM0000
INC Increments DM0000 by 1 at UP edge of input relay 0000.

0001 DM0000
INC Increments DM0000 by 1 at UP edge of input relay 0001.

0002 DM0000
INC Increments DM0000 by 1 at UP edge of input relay 0002.

0003 DM0000
INC Increments DM0000 by 1 at UP edge of input relay 0003.

0005 #00000
DW Clears DM0000 to #00000 when 0005 turns ON.
DM0000

Coding
Line No. Instruction Operand
0000 LD 2008
0001 LDA #00000
0002 CON
0003 STA DM0000
2 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

■ Total count 2
Counts the number of boxes transferred on 5 production lines. Produces output
when the number becomes 100 or more.

0000 DM0000 Increments DM0000 by 1 at UP edge of


INC
input relay 0000.
0001 DM0000 Increments DM0000 by 1 at UP edge of
INC
input relay 0001.
0002 DM0000
INC Increments DM0000 by 1 at UP edge of
input relay 0002.
0003 DM0000 Increments DM0000 by 1 at UP edge of
INC
input relay 0003.
0004 DM0000 Increments DM0000 by 1 at UP edge of
INC
input relay 0004.
0005 $0000
DW Clears DM0000 when input relay 0005
DM0000 turns ON.
2002 DM0000 #00100 2009 0500
LDA CMP Turns output relay 0500 ON when value
of DM0000 is 100 or more.

3-174 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 174 08.3.11, 0:03 PM


INC / @INC / DEC / @DEC
2.4 Instruction Details

Coding
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

■ 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.

Programming with the C instruction Programming with the INC instruction


with data memory
0005 #09999 C001 DM0001 0000 DM0000
C001 LDA STA INC
0000
#09999 C002 DM0002 0001 DM0000
C002 LDA STA INC
0001
#09999 C003 DM0003 0002 DM0000
C003
0002
LDA

#09999 C004
STA

DM0004 0003
INC

DM0000
12
C004 LDA STA INC
0003
#09999 C005 DM0005 0004 DM0000
C005 LDA STA INC
0004
2002 DM0001 DM0002 DM0003 DM0004 DM0005 DM0000 0005 $0000
LDA ADD ADD ADD ADD STA DW
DM0000

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.

■ 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.

0000 DM0000 0000 DM0000


INC INC

0001 DM0000 0001


INC

0002 DM0000 0002


INC

0003 DM0000 0003


INC

0004 DM0000 0004


INC

1) 2)

Chapter 2 Instructions 3-175

KVNKA Chap 02_4dP.p65 175 08.3.11, 0:03 PM


MPX / @MPX / DMX / @DMX
2.4 Instruction Details

ANL LD #n Converts 4-bit data of internal


MPX: Multiplexer FUN 2 7 : MPX
register into 16-bit data. The 4-bit
@ ANL LD #n data to be converted is specified as
@MPX: (4-to-16 decoder), #,$ FUN 2 7 : MPX
operand.
SET ANL
DMX: Demultiplexer FUN 1 2 : DMX
Converts position of most signifi-
cant bit with 1 in internal register
@DMX: (16-to-4 encoder) @ SET ANL
:
#,$ FUN 1
DMX
2 into 4-bit data.

Example
0000 0000 #1 1000
LDA MPX STA

0001 0100 DM0000


LDA DMX STA

Coding
Line No. Instruction Operand
0000 LD 0000
0001 LDA 0000
0002 CON
0003 MPX #1
0004 CON
0005 STA 1000
2 0006 LD 0001
0007 LDA 0100
0008 CON
0009 DMX
0010 CON
0011 STA DM0000

Operands
#0 to #3

Key operation

FUN
SET OR ENT Operand ENT
@ 1 9 R-SRCH R-SRCH
#,$ FUN

FUN
RES LD ENT Operand ENT
@ 0 7 R-SRCH R-SRCH
#,$ FUN

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.

3-176 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 176 08.3.11, 0:04 PM


MPX / @MPX / DMX / @DMX
2.4 Instruction Details

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.

#3 #2 #1 #0 Operand

1 0 1 0 Internal register

No. represented by the section of the


A
internal register specified by operand

0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 Internal register
F E D C B A 9 8 7 6 5 4 3 2 1 0

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 12
internal register are then transferred to DM0000.
In the example, when input relay 0114 turns ON, "E" is input to DM0000.

Most significant bit with "1"

0 1 0 1 1 0 0 1 0 1 0 0 0 1 0 0
F E D C B A 9 8 7 6 5 4 3 2 1 0 Enter the number of the most
significant bit with "1".

0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 0

0 to F
The value is converted into a hexadecimal number.

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


■ 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.

2002 0000 #1 0500


LDA MPX STA

When the digital switch shows "8", output 0508 turns ON, therefore, lamp 8 lights.

Chapter 2 Instructions 3-177

KVNKA Chap 02_4dP.p65 177 08.3.11, 0:04 PM


MPX / @MPX / DMX / @DMX
2.4 Instruction Details

■ 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.

2002 0000 0500


LDA DMX STA

When sensor 8 is ON, the indicator shows "8".

■ 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.

2002 0000
LDA DMX Converts the most significant bit of 16-bit data (0000 to
0015) to 4-bit BIN data and sends it to internal register.
2002 $00FF 0500
TBCD ANDA STA Converts internal register data to BCD data, executes an
ANDA instruction, and outputs the data to 0500 to 0507.

Coding

Line No. Instruction Operand


0000 LD 2002
2 0001 LDA 0000
0002 CON
0003 DMX
0004 LD 2002
0005 TBCD
0006 CON
0007 ANDA $00FF
0008 CON
0009 STA 0500

■ 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
a

f b
g a : 0600 b : 0601 c : 0607
d : 0603 c : 0604 f : 0605
g : 0606
e c
d

3-178 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 178 08.3.11, 0:04 PM


MPX / @MPX / DMX / @DMX
2.4 Instruction Details

Converts the counter value to 16-bit


Auto-reset data using the MPX instruction.
counter
C000 #00009 C000 #0 1000
C000 LDA MPX STA
0000
Sends internal register data to
output relays starting from 0600.

1000 $003F 0600


LDA STA 0

1001 $0006 0600


LDA STA 1

1002 $005B 0600


LDA STA 2

1003 $004F 0600


LDA STA 3

1004 $0066 0600


LDA STA 4 7-segment display

1005 $006D 0600


LDA STA 5

1006 $007D 0600


LDA STA 6

1007 $0007 0600


LDA STA 7

1008 $007F
LDA
0600
STA 8
12
1009 $006F 0600
LDA STA 9

Coding
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

Chapter 2 Instructions 3-179

KVNKA Chap 02_4dP.p65 179 08.3.11, 0:04 PM


TBCD / @TBCD / TBIN / @TBIN
2.4 Instruction Details

LDB LD Converts contents of internal register


TBCD: Transfer BCD FUN 4 7 : TBCD
(16-bit binary) into 4-digit BCD data.
@ LDB LD
@TBCD: Transfer BCD #,$ FUN 4 7 : TBCD

LDB AND : Converts contents of internal register


TBIN: Transfer BIN FUN 4 8 TBIN
(4-bit binary) into 16-digit BCD data.
@ LDB AND
:
@TBIN: Transfer BIN #,$ FUN 4 8 TBIN

Example
0000 DM0000 DM0001
LDA TBCD STA

0001 DM0010 DM0011


LDA TBIN STA

Coding
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 @TBCD
0004 CON
0005 @STA DM0001
2 0006 LD 0001
0007 LDA DM0010
0008 CON
0009 @TBIN
0010 CON
0011 @STA DM0011

Operands

Key operation
FUN
LDB LD ENT ENT
@ 4 7 R-SRCH R-SRCH
#,$ FUN

FUN
LDB AND ENT ENT
@ 4 8 R-SRCH R-SRCH
#,$ FUN

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.

3-180 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 180 08.3.11, 0:04 PM


TBCD / @TBCD / TBIN / @TBIN
2.4 Instruction Details

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.

216 20

0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0

Data is converted into BCD of "0" through "9999".


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
103 102 101 100
(0) (0) (2) (4)

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.

(5) (5) (5) (5)


103 102 101 100
8 4 2 1 8 4 2 1 8 4 2 1 8 4 2 1
12
0 1 0 1 0 0 0 1 0 1 0 1 0 1 0 1

Data is converted into binary number of "0" through "9999".


0 0 0 1 0 1 0 1 1 0 1 1 0 0 1 1
D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0

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


■ Output of 4-digit BCD data
Outputs the current value of counter C001 to 0700 to 0715 in 4-digit BCD data.

0001 #09999
C001 Sets C001.
0000
2002 C001 0700
LDA TBCD STA Converts current value of C001 into BCD data,
and outputs it to 0700 to 0715.

Coding
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

Chapter 2 Instructions 3-181

KVNKA Chap 02_4dP.p65 181 08.3.11, 0:04 PM


TBCD / @TBCD / TBIN / @TBIN
2.4 Instruction Details

■ 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

DM0000 x DM0001 = TM00 Internal register


High-order 4 digits Low-order 4 digits

TM00 Internal register ÷ #10000

= TM00 Internal register ... TM01


High-order 4 digits Low-order 4 digits Remainder

Display
0600 to 0615 0500 to 0515
High-order 4 digits Low-order 4 digits

2002 DM0000 DM0001 #10000 DM0101 TM01 0500


LDA MUL DIV STA LDA TBCD STA

DM0101 0600
LDA TBCD STA

Coding

2 Line No.
0000
Instruction
LD
Operand
2002
Line No.
0010
Instruction
CON
Operand

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

Application of TBIN instruction


■ Input of 4-digit BCD data
Sets 4 digits of the BCD digital switch (0400 to 0415) as the counter C001 value.
2002 0400 C001
LDA TBIN STA Converts data of 0400 to 0415 to BIN data and writes
into C001.
0001 #09999
C001 Sets C001
0000

Coding
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

3-182 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 182 08.3.11, 0:04 PM


ASC / @ASC / RASC / @RASC
2.4 Instruction Details

RES ANL
ASC: ASCII Convert FUN 0 2 : ASC
Converts contents of lower order byte
@ RES ANL of internal register into 2-digit ASCII
@ASC: ASCII Convert #,$ FUN 0 2 : ASC
code.
ORL ANL
RASC: Reverse ASCII Convert FUN 3 2 : RASC Converts 2-digit ASCII into byte data
representing 2-digit hex number.
@ ORL ANL
:
@RASC: Reverse ASCII Convert #,$ FUN 3 2 RASC

Example
0000 DM0000 DM0001
LDA ASC STA

0001 DM0010 DM0011


LDA RASC STA

Coding
Line No. Instruction Operand
0000 LD 0000
0001 LDA DM0000
0002 CON
0003 @ASC
0004 CON
0005 @STA DM0001
0006 LD 0001 12
0007 LDA DM0010
0008 CON
0009 @RASC
0010 CON
0011 @STA DM0011

Operands

Key operation

FUN
RES ANL ENT ENT
@ 0 2 R-SRCH R-SRCH
#,$ FUN

FUN
ORL ANL ENT ENT
@ 3 2 R-SRCH R-SRCH
#,$ FUN

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.

Chapter 2 Instructions 3-183

KVNKA Chap 02_4dP.p65 183 08.3.11, 0:04 PM


ASC / @ASC / RASC / @RASC
2.4 Instruction Details

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.

1 0 1 0 0 1 0 1
A 5

4 1 3 5

0 1 0 0 0 0 0 1 0 0 1 1 0 1 0 1

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..

0 0 1 1 0 1 1 0 0 1 0 0 0 0 1 1
3 6 4 3

2 6 C

0 0 0 0 0 0 0 0 0 1 1 0 1 1 0 0

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

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

3-184 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 184 08.3.11, 0:04 PM


ROOT / @ROOT
2.4 Instruction Details

ROOT: Square Root ORL ORB Takes square root of 32-bit data (TM00:
FUN 3 6 : ROOT
higher order byte, internal register: lower
@ROOT: Square Root @ ORL ORB order byte), and inputs result back to same
#,$ FUN 3 6 : ROOT
register.

Example
0000 DM0001 TM00 DM0000 DM0100
LDA STA LDA ROOT STA

Coding

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
12
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.

TM00 Internal register Internal register


Higher order 16 bits Lower order 16 bits

Operands

Key operation
FUN
ORL ORB ENT ENT
@ 3 6 R-SRCH R-SRCH
#,$ FUN

Chapter 2 Instructions 3-185

KVNKA Chap 02_4dP.p65 185 08.3.11, 0:04 PM


2.4 Instruction Details

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 Data memory No. 1 2 3 —
CMP
➮ 3-146 $,# constant 1 2 3 —
[FUN04]
# TM 1 2 3 H
ADD Data memory No. 4 5 — —
ADD
➮ 3-150 $,# constant 4 5 — —
[FUN00]
# TM 4 5 — H
2 SUBTRACT Data memory No. 6 5 7 —
SUB
➮ 3-150 $,# constant 6 5 7 —
[FUN46]
# TM 6 5 7 H
MULTIPLY Data memory No. I 8 — —
MUL
➮ 3-150 $,# constant I 8 — —
[FUN28]
# TM I 8 — H
DIVIDE Data memory No. — 8 — 9
DIV
➮ 3-150 $,# constant — 8 — 9
[FUN11]
# TM — 8 — H9
AND A Data memory No. — 5 — —
ANDA
➮ 3-159 $,# constant — 5 — —
[FUN01]
# TM — 5 — H
—: No change in arithmetic flag
Refer to the description of each instruction for details of the operating conditions of the flag.

3-186 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 186 08.3.11, 0:04 PM


2.4 Instruction Details

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 Data memory No. — 5 — —
ORA
➮ 3-161 $,# constant — 5 — —
[FUN31]
# TM — 5 — H
EXCLUSIVE Data memory No. — 5 — —
EORA
OR A $,# constant — 5 — —
[FUN15]
➮ 3-164 # TM — 5 — H
SHIFT Number of shifts 0 5 — —
SRA
RIGHT A
[FUN41]
➮ 3-166
SHIFT Number of shift 0 5 — —
SLA
LEFT A
[FUN40]
➮ 3-166
ROTATE Number of rotations 0 5 — —
RRA
RIGHT A
[FUN37]
➮ 3-169
ROTATE Number of rotations 0 5 — —
RLA
LEFT A
[FUN40]
➮ 3-169
COMPLE- — 5 — —
COM
MENT
➮ 3-171
[FUN05] 12
INCREMENT Data memory No. A 5 — —
INC
MEMORY
[FUN19]
➮ 3-172
DECRE-
MENT DEC Data memory No. B 5 — —
MEMORY [FUN07]
➮ 3-172
MULTI- Digit No. — — — —
MPX
PLEXER
[FUN27]
➮ 3-176
DEMULTI- — — — C
DMX
PLEXER
[FUN12]
➮ 3-176
TRANSFER — — — D
TBCD
BCD
[FUN47]
➮ 3-180
TRANSFER — — — E
TBIN
BIN
[FUN48]
➮ 3-180
ASCII — — — —
ASC
CONVERT
[FUN02]
➮ 3-183
REVERSE
ASCII RASC — — — F
CONVERT [FUN32]
➮ 3-183
SQUARE — 5 — —
ROOT
ROOT
[FUN36]
➮ 3-185
TRIMMER — G — —
TMIN
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.

Chapter 2 Instructions 3-187

KVNKA Chap 02_4dP.p65 187 08.3.11, 0:04 PM


2.4 Instruction Details

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.
2 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.

3-188 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 188 08.3.11, 0:04 PM


2.5 Programming Notes

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.

A B 0500 C E B 0500

A
E

C D A E D

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.
A 1000 A 1000 0500

1000 0500 A 1000

12

3. If the same coil is used in two positions, the latter position has priority and the
coil in the former position is ignored.
A B 0500 A B 0500

C E 0500 C E

4. The circuit shown below left cannot be programmed. Modify it as shown on the
right.
A B C 0500 B C A 0500

D E D E

F F E

5. The circuit shown below left cannot be programmed. Modify it as shown on the
right.
A B 0500 C D B 0500

C D A

E 0501 C E 0501

Chapter 2 Instructions 3-189

KVNKA Chap 02_4dP.p65 189 08.3.11, 0:04 PM


2.5 Programming Notes

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.
0500 0500

#0010 2002 #0010


T000 T000

2. A contact cannot be connected to an output line.


A B D E 0500 E

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.
A B

0500

2 4. Make sure that illegal short-circuits are not generated in parallel connections.
0500

A B C

5. Circuits including output coils cannot be connected in parallel.

A B C 0500

D 0501

However, parallel connection is enabled when each circuit in parallel connection


is connected to an output line.
A B D 0500

D 0501

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.

3-190 Chapter 2 Instructions

KVNKA Chap 02_4dP.p65 190 08.3.11, 0:04 PM


Visual KV
Series
Chapter 3
Interrupts
The interrupt processing function executes an interrupt program when an external
input or request from the high-speed counter comparator (interrupt factor) is encoun-
tered during KV operation.
This chapter describes the types of interrupt factors as well as inputs and outputs
encountered during interrupt processing.

➮ For KV-10/80 Series, see Chapter 6.

3.1 Interrupt Instructions ...................................................................... 3-192


3.2 Interrupt Processing ....................................................................... 3-194
3.2.1 Interrupt Processing ............................................................................... 3-194
3.2.2 Types of Interrupts ................................................................................. 3-195
3.2.3 Interrupt Priority ...................................................................................... 3-196
3.2.4 Interrupt Program ................................................................................... 3-196
3.3 Direct Input/Output .......................................................................... 3-197
3.3.1 Direct Input ............................................................................................. 3-197
3.3.2 Direct Output .......................................................................................... 3-197
3.4 Applications of Interrupt Programs ............................................ 3-198
3.4.1 Interrupt with a Signal Converter ............................................................ 3-198
3.4.2 Interrupt with a High-speed Counter ...................................................... 3-199
3.4.3 Measuring the ON Time of High-speed Pulses ...................................... 3-200
3.4.4 Measuring the Period in which a Target Passes between
Two Points ............................................................................................. 3-201

KVNKA Chap 03.p65 191 08.3.11, 0:05 PM


3.1 Interrupt Instructions

3.1 Interrupt Instructions


This section describes the INT, RETI, DI, and EI instructions used for interrupt
processing.
Visual KV
Series

ANL RES INT Executes interrupt between INT and RETI


INT: Interrupt FUN 2 0 nnnn
instructions at rising or falling edge of input
specified by operand.
RETI
ORL LDB
RETI: Return Interrupt FUN 3 4 Represents termination of interrupts.

Example

a)
Coding for normal input
Normal 0000 #00020 Line No. Instruction Operand
input T000
0000 LD 0000
0000
0500 T000 0500 0001 OR 0500
0002 TMR 00 #00020
(Input ON time: 10 ms min.) 0003 ANB T000
0004 OUT 0500

b) Coding for interrupt input


Interrupt 2008 Line No. Instruction Operand
input EI
0000 0000 LD 2008
2002 HSP 0001 EI
0000
3 1000 #00020
0002 LD 2002
0003 HSP 0000
T000
0004 LD 1000
0500 0005 OR 0500
0006 TMR 000 #00020
T0 1000 0007 OUT 0500
(RES)
0008 LD T0
END 0009 RES 1000
0010 END
INT 0011 INT 0000
0000
0012 LD 2002
2002 1000 0013 OUT 1000
0014 RETI
RETI 0015 ENDH

ENDH

(Input ON time: 10 µs min.)


Description
• Example a) shows a normal input and is used when input relay 0000 turns ON
longer than the input time constant (10 ms).
• Example b) is used when input relay 0000 turns ON shorter than the scan time.

Operands
0000 to 0003
CTC0 to CTC3
Key operation

ANL RES ENT ENT


FUN 2 0 R-SRCH
Operand
R-SRCH

ORL LDB ENT ENT


FUN 3 4 R-SRCH R-SRCH

3-192 Chapter 3 Interrupts

KVNKA Chap 03.p65 192 08.3.11, 0:05 PM


3.1 Interrupt Instructions

RES AND Disables execution of interrupt.


DI: Interrupt Disabled FUN 0 8 DI

SET ORL
EI: Interrupt Enabled FUN 1 3 EI
Enables execution of interrupt.

Visual KV
Series
Example 1000
EI

1000
DI

Coding
Line No. Instruction Operand
0000 LD 0000
0001 EI
• •
• •
• •
0021 LDB 1000
0022 DI
• •
• •
• •

Description
• When 1000 is ON, execution of interrupt is enabled.
• When 1000 is OFF, execution of interrupt is disabled.
• Interrupts are enabled between EI instruction and DI instruction. 13
• Once an EI instruction is executed, an interrupt is enabled until a DI instruction is
executed.
• Any interrupt is disabled when the Visual KV Series starts operation.
• The DI instruction disables execution of an interrupt. Use this instruction to
temporarily disable an interrupt.
• The EI instruction enables execution of an interrupt. Use this instruction to
release an interrupt that was disabled by a DI instruction.
• To execute another interrupt during execution of the previous interrupt, include EI
instruction in this first interrupt. EI-DI instruction set can be nested to four levels.

Note 1: When any interrupt occurs between DI and EI instructions (interrupt disabled
period), the disabled interrupt is stored (to 8 levels max.). The stored interrupt is
executed as soon as an EI instruction is executed.
Note 2: If an INT CTC instruction is stored before a RES CTC instruction is ex-
ecuted, the stored INT CTC is deleted.

Operands

Key operation

RES AND
FUN 0 8 ENT ENT
R-SRCH R-SRCH
SET ORL
FUN 1 3

Chapter 3 Interrupts
3-193

KVNKA Chap 03.p65 193 08.3.11, 0:05 PM


3.2 Interrupt Processing

3.2 Interrupt Processing


This section describes interrupt processing.

3.2.1 Interrupt Processing


Visual KV
Series

Outline
Normally, a PLC processes a ladder sequence program by repeating the steps of
input processing, program execution, and output processing. Therefore, signals
which are shorter than the scan time cannot be received.
When the interrupt processing function is used, a process can be executed at the
instant of the interrupt, independent of the scan time.
When any interrupt occurs, the Visual KV series suspends the currently executed
program and executes the interrupt program in accordance with the interrupt factor.
When the interrupt program completes, the Visual KV resumes execution of the
suspended program.
➮ For more about scan time, refer to "1.1.2 Scan Time" (p. 3-3).

Input
processing

Direct input *
Interrupt input
(0000 to 0015)

Scan Program
3 time execution
Interrupt
processing

Return to the next Direct output


line of the interrupt.
Output (0500 to 0503)
processing

Direct input/output
The direct input/output functions are used during interrupt processing. Direct input
allows the KV PLC to fetch the input status of input relays 0000 through 0015 (KV-
10xx: 0000-0005, KV-16xx: 0000-0009) during execution of the interrupt program.
Direct output allows the Visual KV PLC to output the ON/OFF status of output relays
0500 through 0503 during execution of the interrupt program.
No special setting is required to use the direct input/output functions. The functions
can be used only by using the devices assigned for direct input/output within the
interrupt program.

Executing interrupts
The INT (Interrupt) instruction is used to execute an interrupt. Since an interrupt is
disabled at the start of operation, it is necessary to execute an EI (Interrupt enable)
instruction before using the INT instruction. In addition, the input time constant
should be set shorter by using the HSP instruction (to 10 µs) or by specifying the
desired value in DM1940 and turning ON special utility relay 2813.
➮ For more about the input time constant, refer to "1.4.1 Input Time Constant Change Function" (p. 3-
23).
2002
EI
2008 #00000 2813
EI DW SET or
DM1940 2002 HSP
0000

3-194 Chapter 3 Interrupts

KVNKA Chap 03.p65 194 08.3.11, 0:05 PM


3.2 Interrupt Processing

3.2.2 Types of Interrupts


Interrupts can be divided into two types: an interrupt by an external input, and an
interrupt by the high-speed counter comparator. This section describes both of these
interrupt types.

Visual KV
Series
Interrupt by an external input
This interrupt is executed by input relays 0000 through 0003. Use the special utility
relay to specify the polarity of the interrupt factor to a rising or falling edge.

Interrupt by the high-speed counter comparator


This interrupt is executed when the current value of the high-speed counter (CTH)
matches the preset value of the high-speed counter comparator (CTC).

Polarity setting for interrupts by an external input


Turn ON the appropriate special utility relay to specify the interrupt factor to a rising
or falling edge.
The interrupt polarity can be changed as follows by setting special utility relays
2402/2403 (INT0), 2404/2405 (INT1), 2410/2411 (INT2), and 2412/2413 (INT3).
Interrupt Relay Relay
Status Status Description
type No. No.
OFF OFF
Interrupt occurs at rising edge.
ON OFF
INT0 2402 2403
OFF ON Interrupt occurs at falling edge.
ON ON Interrupt occurs at both rising and falling edges.
OFF OFF
Interrupt occurs at rising edge.
13
ON OFF
INT1 2404 2405
OFF ON Interrupt occurs at falling edge.
ON ON Interrupt occurs at both rising and falling edges.
OFF OFF
Interrupt occurs at rising edge.
ON OFF
INT2 2410 2411
OFF ON Interrupt occurs at falling edge.
ON ON Interrupt occurs at both rising and falling edges.
OFF OFF
Interrupt occurs at rising edge.
ON OFF
INT3 2412 2413
OFF ON Interrupt occurs at falling edge.
ON ON Interrupt occurs at both rising and falling edges.

CAUTION Use SET-RES instructions to turn the special utility relays ON/OFF.

Input capture
Each external interrupt factor is provided with the input capture function. This is a
function which writes the value of the high-speed counter into the data memory
when an interrupt occurs. Without any particular settings, the value of the high-
speed counter is automatically transferred to DM1928 through DM1935 when an
interrupt occurs.
External interrupt factor Description
Value of CTH0 is written to DM1928 (low-order bits)
Occurrence of INT0
and DM1929 (high-order bits)
Value of CTH0 is written to DM1930 (low-order bits)
Occurrence of INT1
and DM1931 (high-order bits)
Value of CTH1 is written to DM1932 (low-order bits)
Occurrence of INT2
and DM1933 (high-order bits)
Value of CTH1 is written to DM1934 (low-order bits)
Occurrence of INT3
and DM1935 (high-order bits)

Chapter 3 Interrupts
3-195

KVNKA Chap 03.p65 195 08.3.11, 0:05 PM


3.2 Interrupt Processing

• Use SET-RES instructions to turn the special utility relays ON/OFF.


CAUTION
• The input capture function stores the high-order bit data only when the 24-
bit high-speed counter is used. The data is undefined when the 16-bit high-
speed counter is used.
➮ "4.4.1 24-bit High-speed Counter" (p. 3-221)
• Timing of the input capture execution depends on the input polarity setting
Visual KV
Series

specified with special utility relays 2402 through 2405 and 2410 through
2413.

3.2.3 Interrupt Priority


When many interrupts occur sequentially, priority is given to the interrupt which
occurs earlier.
When two or more interrupts occur simultaneously, priority is given in the order of
0000, 0001, 0002, 0003, CTC2, CTC3, CTC0, and CTC1.

Note 1: While one interrupt is being executed, other interrupts are disabled. (Multi-
level interrupts are possible by placing an EI instruction within an interrupt routine.)
Note 2: When other interrupts occur during execution of an interrupt, other interrupts
are stored up to 8 levels deep. The stored interrupts are executed after completion
of the previous interrupt, according to the priority order. However, an interrupt which
uses the same device as a previous interrupt cannot be stored.

3.2.4 Interrupt Program


The interrupt program is a program which is executed by an interrupt. It is necessary
to execute an EI (Interrupt enabled) instruction before executing an interrupt pro-
3 gram.
To temporarily disable an interrupt, execute a DI (Interrupt disabled) instruction.
When an interrupt is disabled, subsequent interrupts are not executed but stored
until the next EI instruction.
➮ "EI instruction", "DI instruction" (p. 3-193)

Example of an interrupt program


2008
EI An interrupt program is not executed unless an EI instruction is executed.
HSP Set the input time constant shorter by using the HSP instruction
0000
(to 10 µs) or by turning ON special utility relay 2813.

END

INT
0000

Write the interrupt program between the END and ENDH


instructions.
RETI

ENDH

Note 1: To shorten the input time constant, use the HSP instruction (to 10 µs) or
specify the desired value in DM1940 and turn ON special utility relay 2813.
Note 2: For more about the input time constant, refer to "1.4.1 Input Time Constant
Change Function" (p. 3-23).
Note 3: Use SET-RES instructions instead of OUT-OUTB instructions within inter-
rupt programs.

The following instructions cannot be used within interrupt programs:


TMR, TMH, TMS, DIFU, DIFD, W-ON, W-OFF, W-UE, W-DE, STG, JMP, ENDS,
HKEY, ITVL, @xxxx (differentiation type instructions), C, UDC, SFT

3-196 Chapter 3 Interrupts

KVNKA Chap 03.p65 196 08.3.11, 0:05 PM


3.3 Direct Input/Output

3.3 Direct Input/Output


This section describes direct input and output.

Visual KV
3.3.1 Direct Input

Series
The direct input function is used during interrupt processing. Direct input allows the

KV PLC to fetch the input status of the input relays during execution of the interrupt
program.

Direct input is available only with input relays 0000 through 0015 (KV-10xx: 0000-
0005, KV-16xx: 0000-0009). (KV-300: 0000-0005)

• The input time constant must be set to 10 µs by using the HSP instruction or by
turning ON special utility relay 2813.
• The direct input data is effective only within the interrupt program so that the
internal utility relay must be provided.
2008
EI

2002 HSP
0000

HSP
0005

1000 0500

END

INT
0000
13
0005 1000
SET

RETI

ENDH

3.3.2 Direct Output


Direct output allows the Visual KV PLC to output the ON/OFF status of output relays
during execution of the interrupt program. Direct output is available only with output
relays 0500 through 0503.

• Direct output is not affected by the scan time.

2008
EI

2002 HSP
0000

HSP
0001

END

INT
0000

2002 0500
SET

RETI

INT
0001

2002 0501
SET

RETI

ENDH

Chapter 3 Interrupts
3-197

KVNKA Chap 03.p65 197 08.3.11, 0:05 PM


3.4 Applications of Interrupt Programs

3.4 Applications of Interrupt Programs


This section presents program examples of interrupt processing.

3.4.1 Interrupt with a Signal Converter


Visual KV
Series

■ Outline
Converts the short pulses which are input by interrupt processing into pulses of a
constant width and then outputs them.

Scan

ON
Input 0000
OFF

ON
Output 0500 ON ON ON
OFF
1 sec. 1 sec. 1 sec.

■ Ladder diagram
• Converts the short pulses input from input relay 0000 into pulses of 1-second ON
width and then outputs them from output relay 0500.
3 • Output relay 0500 turns ON for 1 second from the rising edge of input relay 0000.

2008
EI When power is turned on, an EI
0001
instruction enables interrupts.
2002 HSP
0002 0000 Sets the input time constant of
input 0000 to 10 µs.
0500 #00010 T0000 0500
0003 T000 RES
Turns ON output 0500 for 1
END second and then turns it OFF.
0004

INT
0005 0002
When input 0000 turns
2002 0500 ON, output 0500 turns ON.
0006 SET

RETI
0007

ENDH
0008

3-198 Chapter 3 Interrupts

KVNKA Chap 03.p65 198 08.3.11, 0:05 PM


3.4 Applications of Interrupt Programs

3.4.2 Interrupt with a High-speed Counter


■ Outline
Uses the input value of a high-speed counter from one input relay and the ON/OFF
status of another input relay to control the ON/OFF status of an output relay.

Visual KV
Series
Scan

ON
Input 0004
OFF

ON
Input 0000
OFF
ON
Output 0500 ON
OFF

Example: Filling control for medicine (tablets)

Visual KV
Sensor

13

■ Ladder diagram
• Output relay 0500 turns ON when the input value of the high-speed counter from
input relay 0004 reaches "10000".
• Output relay 0500 turns OFF when input relay 0000 turns ON.

When power is turned on, an EI


2008 2103 CTH0 instruction enables interrupts.
0001 EI SET RES Sets automatic reset of CTH0.
Resets current value of CTH0.
2002 HSP
0002 0004 Sets an input time constant of
input 0004 to 10 µs.
2002 CTH0
0003 0004 Specifies CTH0 as the high-
speed counter for input 0004 and
# 10000 sets "10000" as the preset value
0004 CTC0 of CTC0.
0000 0500 Turns OFF output 0500 when
0005 RES
input 0000 turns ON.
END
0006

INT
0007 CTC0 Executes an interrupt when the
input value of CTH0 reaches
2002 0500 "10000". Turns ON output 0500.
0008 SET

RETI
0009

ENDH
0010

Chapter 3 Interrupts
3-199

KVNKA Chap 03.p65 199 08.3.11, 0:05 PM


3.4 Applications of Interrupt Programs

3.4.3 Measuring the ON Time of High-speed Pulses


■ Outline
Measures the pulse width of the pulse input to an input relay.
Visual KV
Series

ON
Sensor input 0000
OFF

Pulse width (µs)

Example: Measurement of workpiece length

Sensor
Visual KV

■ Ladder diagram
• Special utility relay 2100 is turned ON to measure the pulse width using 1-µs
units.
• The values when input relay 0000 is ON is written into temporary data memory
3 TM02, and the values when input relay 0000 is OFF is written into data memory
DM1912. The pulse width can be obtained by subtracting the value of TM02 from
the value of DM1912.
• The obtained value is written into data memory DM0000 (Unit: µs).

2008 • When power is turned ON, an EI


0001 EI
instruction enables interrupts.
2002 HSP • Sets an input time constant of
0002 0000 input 0000 to 10 µs.
• CTH0 counts pulses with a 1-µs
2002 CTH0 internal clock.
0003 2100

END
0004

INT
0005 0000 • Turns ON input 0000 to execute an
interrupt.
2403 DM1928 TM02 KEEP
0006 LDA STA SET First, an interrupt is executed at the
2403 rising edge of input 0000. The
2403 DM1928 TM02 DM0000
0007 LDA SUB STA RES current value of CTH0 stored in
DM1928 is written to TM02. Turns
RETI ON special utility relay 2403 to
0008 change the interrupt polarity to the
falling edge.
ENDH
0009 Next, an interrupt is executed at the
falling edge of input 0000. The
value stored in TM02 is subtracted
from the current value of CTH0
stored in DM1928, and the
obtained ON width of input 0000 is
written to DM0000. Turns OFF
special utility relay 2403 to change
the interrupt polarity to the rising
edge.

3-200 Chapter 3 Interrupts

KVNKA Chap 03.p65 200 08.3.11, 0:05 PM


3.4 Applications of Interrupt Programs

3.4.4 Measuring the Period in which a Target Passes between


Two Points
■ Outline
Measures the period in which two input relays turn ON.

Visual KV
Series
ON
Sensor 1 input 0002
OFF

ON
Sensor 2 input 0003
OFF

Passing time (µs)

Example: Measurement of tact time

Visual KV

Sensor 1

Sensor 2

■ Ladder diagram 13
• Measures the time from when input relay 0002 turns ON until input relay 0003
turn ON.
• The measured value is written to data memory DM0000 (Unit: µs).

• When power is turned on, an


2008 2410 2411 2412 2413 EI instruction enables inter-
EI RES RES RES RES rupts. Sets the interrupt polarity
0001 of inputs 0002 and 0003 to the
rising edge.
2002 HSP
0002 0002 • Sets the input time constant of
inputs 0002 and 0003 to 10 µs.
HSP
0003 0003

2002 CTH1
0004 2200 • CTH1 counts the pulses using
a 1-µs internal clock.
END
0005

INT
0006 0002 • When INT2 is executed, the
current value of CTH1 is
RETI automatically transferred to
0007 DM1932 and DM1933 (Input
capture).
INT
0008 0003 • When INT3 is executed, the
current value of CTH1 is
2002 DM1934 DM1932 DM0000 automatically transferred to
0009 LDA SUB STA DM1934 and DM1935 (Input
capture).
RETI
0010 Subtracts the input capture
value of INT2 from that of INT3
ENDH to obtain the time it takes for
0011 the target to pass between two
points and then writes it to
DM0000.

Chapter 3 Interrupts
3-201

KVNKA Chap 03.p65 201 08.3.11, 0:05 PM


3.4 Applications of Interrupt Programs
Visual KV
Series

3-202 Chapter 3 Interrupts

KVNKA Chap 03.p65 202 08.3.11, 0:05 PM


Visual KV
Series
Chapter 4
High-speed Counters
This chapter describes high-speed counters and high-speed counter comparators,
which allow high-speed pulse measurement and pulse output, independent of the
scan time.

➮ For KV-10/80 Series, see Chapter 6.

4.1 High-speed Counter Instructions ................................................ 3-204


4.2 Outline of High-speed Counters .................................................. 3-206
4.2.1 High-speed Counters and High-speed Counter Comparators ............... 3-206
4.2.2 Internal Clock for High-speed Counters ................................................. 3-210
4.3 Setting and Operation of High-speed Counters ...................... 3-211
4.3.1 Reading the Current Value of the High-speed Counter ......................... 3-211
4.3.2 Preset Value of the High-speed Counter Comparator ........................... 3-211
4.3.3 Comparator Output ................................................................................ 3-211
4.3.4 Count Input Method ................................................................................ 3-212
4.3.5 Resetting the High-speed Counter ......................................................... 3-214
4.3.6 Differences with the CTH Instruction between the
Conventional and Visual KV Series ....................................................... 3-216
4.3.7 Applications of High-speed Counters ..................................................... 3-217
4.4 Expanded Functions of High-speed Counters ......................... 3-221
4.4.1 24-bit High-speed Counter ..................................................................... 3-221
4.4.2 Changing the Current Value of a 24-bit High-speed Counter ................ 3-223
4.4.3 Application Example of 24-bit High-speed Counter (single-phase input) 3-224
4.4.4 Ring Counter Function ........................................................................... 3-225
4.4.5 Applications of Ring Counters ................................................................ 3-226
4.5 Special Functions Using High-speed Counters ...................... 3-228
4.5.1 Specified Frequency Pulse Output Function .......................................... 3-228
4.5.2 Applications of the Specified Frequency Pulse Output .......................... 3-229
4.5.3 Frequency Counter Function .................................................................. 3-231
4.5.4 Applications of Frequency Counters ...................................................... 3-232
4.5.5 Cam Switch Function ............................................................................. 3-233
4.5.6 Application of the Cam Switch ............................................................... 3-236
4.6 Direct Clock Pulse Output ............................................................. 3-237
4.6.1 Outline of Direct Clock Pulse Output ...................................................... 3-237
4.6.2 Pulse Output Setting with the High-speed Counter Comparator ............ 3-238
4.7 Examples of Direct Clock Pulse Output .................................... 3-242
4.7.1 Example of Outputting a Pulse with 1:1 ON/OFF Ratio ......................... 3-242
4.7.2 Example of Outputting a Pulse with Variable ON/OFF Ratio ................. 3-245
4.7.3 Example of Stopping the Pulse Output at a Specified Pulse Count ....... 3-249
4.7.4 Application of Direct Clock Pulse Output (Ramp-up/down control) ........ 3-251

KVNKA Chap 04_1.p65 203 08.3.11, 0:06 PM


4.1 High-speed Counter Instructions

4.1 High-speed Counter Instructions


This section describes the CTH0, CTH1, and CTC instructions, which are used for
high-speed counters.
Visual KV
Series

• 16-bit (0 to 65535) up/down counters for


clock pulses with a 30-kHz input 1.
CTH0: 16-Bit High- CTH0 response frequency.
RES :
speed counter CTH 0 nnnn
• Can be changed to 24-bit (0 to 16777215)
counters with the MEMSW instruction. 2.
CTH1: 16-Bit High- CTH1 • Enables 30 kHz, two-phase input through
SET :
CTH 1 nnnn two channels.1.
speed counter
• Hardware-based comparator between the
preset value and current value of the
CTC: High-speed CTC :
#ddddd
CTCn high-speed counter.
counter comparator • The current value can be changed to a
preset value by external input.

1. KV-300/Visual KV only
Example 2. Visual KV only

2008 HSP
0004
1)
2008 2103 CTH0
SET RES

0000 Input-enable relay Count input


CTH0
2)
0004

#60000
3) CTC0
4
CTC0 0500
4) SET

0500 #00030 T000 CTC0 0500


5) T000 RES RES

Coding

Line No. Instruction Operand Line No. Instruction Operand


0000 LD 2008 0009 LD CTC0
0001 HSP 0004 0010 SET 0500
0002 LD 2008 0011 LD 0500
0003 SET 2103 0012 TMR 000 #00030
0004 CON 0013 AND T000
0005 RES CTH0 0014 RES CTC0
0006 LD 0000 0015 CON
0007 CTH0 0004 0016 RES 0500
0008 CTC0 #6000

3-204 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 204 08.3.11, 0:06 PM


4.1 High-speed Counter Instructions

Operands
CTH0: 0004
2100 to 2102
CTH1: 0005
0500

Visual KV
2200 to 2202

Series
CTC0 to 3: Preset value
#00001 to #65535

Key operation
RES
0 ENT
CTH Clock input
R-SRCH
SET
1

Preset ENT
CTC Operand value R-SRCH

Description
1) Initializes the setting when power is turned on.
• The HSP instruction sets the input time constant of input relay 0004 to 10 µs.
• The current value of CTH0 is reset as soon as it matches the preset value of
CTC0 when special utility relay 2103 is ON.
2) The counting is disabled when input relay 0000 is OFF. Counting starts (at 0004)
when input relay 0000 turns ON.
3) Sets "60000" as the preset value of the high-speed counter comparator.
4) When the current value of CTH0 reaches "60000", output relay 0500 turns ON
and the current value is reset.
5) Turns OFF both CTC0 and 0500 for three seconds after output relay 0500 turns
ON.
14
Tips
Unlike software-based counters, the high-speed counter is a hardware-based,
program-independent counter. It achieves an input response frequency of 30 kHz
without being affected by the scan time.

• Input relays 0004 and 0005 can independently count the pulses with a 30 kHz
input response frequency.
• Two-phase encoder input can be captured through two channels (30 kHz).
• CTH0 uses input from relay 0004 as phase A input and input from relay 0006 as
phase B input (KV-10xx: 0000). CTH1 uses input from 0005 as phase A input
and input from 0007 as phase B input (KV-10xx: 0001).

Note: When phase differential input is used, pulses with a maximum frequency of 30
kHz can be counted, provided the pulses have a duty ratio of 1:1 (50%) and phase
difference of 90°. Inputting pulses with an irregular duty ratio or phase difference will
decrease the allowable input frequency.

Chapter 4 High-speed Counters 3-205

KVNKA Chap 04_1.p65 205 08.3.11, 0:06 PM


4.2 Outline of High-speed Counters

4.2 Outline of High-speed Counters


This section describes the outline and specifications for high-speed counters and
high-speed counter comparators featured with the Visual KV Series.
Visual KV
Series

4.2.1 High-speed Counters and High-speed Counter Compara-


tors
The high-speed counter is a hardware-based counter that can count high-speed
pulses that cannot be counted by counters written in main routines (C or UDC).
(Pulses with a maximum frequency of 30 kHz can be counted.). *
High-speed counter comparators are hardware-based comparators that compare
their preset value with the current value of one of the a high-speed counters.
Both counters and comparators perform processing with hardware rather than
software programs, enabling high-speed performance independent of the scan time.

Structure of high-speed counters and high-speed counter comparators


The Visual KV PLC has two high-speed counters, each equipped with two high-
speed counter comparators and dedicated internal clocks.

Block diagram of high-speed counters


0008 (RESET) 2.

Internal clocks* 16-bit high-speed Input capture device Special utility relay
2100 (1.0 µs) counter DM1928, DM1929(INT0) 2103 to 2114
2101 (10.0 µs) CTH0 DM1930, DM1931(INT1)
2102 (100.0 µs)
Control circuit 0500
External input high-speed high-speed
Phase A 0004 counter counter
0004/0006 comparator comparator INT CTC0
4 Phase B(0006)
CTC0 CTC1 INT CTC1

Internal clocks* 16-bit high-speed Input capture device Special utility relay
2200 (1.0 µs)
counter DM1932, DM1933(INT2) 2203 to 2214
2201 (10.0 µs) CTH1 DM1934, DM1935(INT3)
2202 (100.0µs)
0501
Internal connection
for external clock Control circuit
0500
Phase A high-speed high-speed
Phase B 0005 External input counter counter
0005/0007 comparator comparator INT CTC2
(0007)
CTC2 CTC3 INT CTC3

0009 (RESET) 2.

1. With the KV-10xx, the external input relay for CTH0 is 0004 (phase A)/0000
(phase B), and for CTH1 is 0005 (phase A)/0001 (phase B).
2. With the KV-10xx, the preset input relay for CTH0 is 0002, and for CTH1 is 0003.

For KV-10/80 user's


Max. response frequency: 10 kHz
* 2100 0.8 µs
2101 6.4 µs
2102 102.4 µs
2200 0.4 µs
2201 0.8 µs
2202 3.2 µs

3-206 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 206 08.3.11, 0:06 PM


4.2 Outline of High-speed Counters

■ List of special utility relays for high-speed counter CTH0


Relay
Function
No.
2100* Internal clock used only for CTH0 (1 µs)
2101* Internal clock used only for CTH0 (10 µs)

Visual KV
2102* Internal clock used only for CTH0 (100 µs)

Series
2103 Automatically clears CTH0 when comparator CTC0 turns ON. ON: Yes OFF: No
Disables/enables direct output from 0500 when comparator CTC0 ON: Disable
2104
turns ON. OFF: Enable
2105 Turns OFF direct output from 0500 when comparator CTC0 turns ON. ON: Yes OFF: No
2106 Turns ON direct output from 0500 when comparator CTC0 turns ON. ON: Yes OFF: No
Reverses ON/OFF status of output from 0500 each time comparator
2107 ON: Yes OFF: No
CTC0 turns ON.
Disables/enables direct output from 0500 when comparator CTC1 ON: Disable
2108
turns ON. OFF: Enable
2109 Turns OFF direct output from 0500 when comparator CTC1 turns ON. ON: Yes OFF: No
2110 Turns ON direct output from 0500 when comparator CTC1 turns ON. ON: Yes OFF: No
Reverses ON/OFF status of output from 0500 each time comparator
2111 ON: Yes OFF: No
CTC1 turns ON.
2112 Automatically clears CTH0 when comparator CTC1 turns ON. ON: Yes OFF: No
2113 Selects multiplication mode for CTH0.
OFF/OFF: No multiplication (1 pulse) ON/OFF: x2 OFF/ON: x4
2114 ON/ON: 2 pulses
* Read-only relay.

Multiplication No multiplication
x2 x4 2 pulses
mode (1 pulse)
2113 OFF ON OFF ON
2114 OFF OFF ON ON

■ List of special utility relays for high-speed counter CTH1


Relay
No.
Function 14
2200* Internal clock used only for CTH1 (1 µs)
2201* Internal clock used only for CTH1 (10 µs)
2202* Internal clock used only for CTH1 (100 µs)
2203 Automatically clears CTH1 when comparator CTC2 turns ON. ON: Yes OFF: No
Disables/enables direct output from 0501 when comparator CTC2 ON: Disable
2204
turns ON. OFF: Enable
2205 Turns OFF direct output from 0501 when comparator CTC2 turns ON. ON: Yes OFF: No
2206 Turns ON direct output from 0501 when comparator CTC2 turns ON. ON: Yes OFF: No
Reverses ON/OFF status of output from 0501 each time comparator
2207 ON: Yes OFF: No
CTC2 turns ON.
Disables/enables direct output from 0501 when comparator CTC3 ON: Disable
2208
turns ON. OFF: Enable
2209 Turns OFF direct output from 0501 when comparator CTC3 turns ON. ON: Yes OFF: No
2210 Turns ON direct output from 0501 when comparator CTC3 turns ON. ON: Yes OFF: No
Reverses ON/OFF status of output from 0501 each time comparator
2211 ON: Yes OFF: No
CTC3 turns ON.
2212 Automatically clears CTH1 when comparator CTC3 turns ON. ON: Yes OFF: No
2213 Selects multiplication mode for CTH1.
2214 O F F / O F F: N o m u lt i p l i c at i o n ( 1 p u l s e ) O N / O F F: x 2 O F F/ O N : x 4 O N / O N : 2 pulses
* Read-only relay.

Multiplication No multiplication
x2 x4 2 pulses
mode (1 pulse)
2213 OFF ON OFF ON
2214 OFF OFF ON ON

Chapter 4 High-speed Counters 3-207

KVNKA Chap 04_1.p65 207 08.3.11, 0:06 PM


4.2 Outline of High-speed Counters

■ Other special utility relays


Relay
Function
No.
2400 Changes current value of CTH0 to preset value by external signal
2401 OFF/OFF: Not used ON/OFF: At rising edge OFF/ON: At falling edge ON/ON: Level
Visual KV

2406 Sets CTH0 as ring counter. ON: Yes OFF: No


Series

Ignores phase B input when no multiplication mode is used for CTH0.


2407
ON: Ignore phase B input and always count up. OFF: Use phase B input as usual.
2408 Changes current value of CTH1 to preset value by external signal
2409 OFF/OFF: Not used ON/OFF: At rising edge OFF/ON: At falling edge ON/ON: Level
2414 Sets CTH1 as ring counter. ON: Yes OFF: No
Ignores phase B input when no multiplication mode is used for CTH1.
2415
ON: Ignore phase B input and always count up. OFF: Use phase B input as usual.

■ Data memory
DM No. Description
DM1900/DM1901 Current value of 24-bit CTH0 (low-order bits/high-order bits) is read.
DM1902/DM1903 Current value of 24-bit CTH1 (low-order bits/high-order bits) is read.
DM1904/DM1905 Current value of 24-bit CTC0 (low-order bits/high-order bits) is read.
DM1906/DM1907 Current value of 24-bit CTC1 (low-order bits/high-order bits) is read.
DM1908/DM1909 Current value of 24-bit CTC2 (low-order bits/high-order bits) is read.
DM1910/DM1911 Current value of 24-bit CTC3 (low-order bits/high-order bits) is read.
DM1912/DM1913 Current value of 24-bit CTH0 (low-order bits/high-order bits) is written.
DM1914/DM1915 Current value of 24-bit CTH1 (low-order bits/high-order bits) is written.
DM1916/DM1917 Preset value of 24-bit CTC0 (low-order bits/high-order bits) is written.
DM1918/DM1919 Preset value of 24-bit CTC1 (low-order bits/high-order bits) is written.
DM1920/DM1921 Preset value of 24-bit CTC2 (low-order bits/high-order bits) is written.
DM1922/DM1923 Preset value of 24-bit CTC3 (low-order bits/high-order bits) is written.
DM1924/DM1925 Preset value of CTH0 (low-order bits/high-order bits) is written.
DM1926/DM1927 Preset value of CTH1 (low-order bits/high-order bits) is written.
4
Note 1: As with the internal register, the contents of data memory are stored as 16-
bit binary data.
Note 2: The contents of data memory are stored even when the Visual KV is turned
off or "ALL DATA MEMORY CLEAR" is executed. It is stored more than 20 days
with the KV-10xx, and more than two months with other models.

Specifications of high-speed counters


• The high-speed counter is a hardware-based up/down counter that counts from 0
to 65535 with an auto-reset function.
• The following operands can be specified for count inputs.
High-speed counter Operand Measurement range
CTH0 2100 to 2102, 0004
#00000 to 65535
CTH1 2200 to 2202, 0005, 0500

• High-speed counters CTH0 and CTH1 store current values only.


• When input relays 0004 and 0005 are selected as operands, they can be used as
high-speed counters with a response frequency of 30 kHz.
• When special utility relays 2100 through 2102 and 2200 through 2202 are se-
lected as operands, the high-speed counters can be used as high-speed timers.
• When relay 0500 is selected as an operand for CTH1, CTH1 can count the clock
pulses produced by CTH0.
• CTH0 and CTH1 can be used as 24-bit high-speed counters when the MEMSW
instruction is set.
➮ "MEMSW instruction" (p. 3-92), "4.4.1 24-bit High-speed Counter" (p. 3-221), "4.3.4 Count Input
Method" (p. 3-212), "When using comparator output from other counters as count input" (p. 3-213).

3-208 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 208 08.3.11, 0:06 PM


4.2 Outline of High-speed Counters

Note 1: CTH instructions cannot be duplicated in a program. A maximum of two


counters, CTH0 and CTH1, can be used in one program.
Note 2: The operands for a high-speed counter cannot be changed during program
execution.
Note 3: When using a high-speed counter with external inputs, the input time con-

Visual KV
stant must be set to 10 µs with the HSP instruction or with special utility relay 2813.

Series
(Pulses with a maximum frequency of 30 kHz can be counted.)
Note 4: When using input 0004 as an operand, use input 0006 (KV-10xx: 0000) for
phase B input. Therefore, do not use input 0006 (KV-10xx: 0000) other than for the
high-speed counter.
Note 5: When selecting no multiplication mode, and you do not want to use input
0006 (KV-10xx: 0000) as phase B input, turn ON special utility relay 2407.
Note 6: When using input 0005 as an operand, use input 0007 (KV-10xx: 0001) for
phase B input. Therefore, do not use input 0007 (KV-10xx: 0000) other than for the
high-speed counter.
Note 7: When selecting no multiplication mode, and you do not want to use input
0007 (KV-10xx: 0001) as phase B input, turn ON special utility relay 2415.
Note 8: When using the high-speed counter internal connection relay 0500, only
single-phase input is available. In this case, external input relays 0005 and 0007 for
CTH1 can be used as normal input relays.
Note 9: When using phase differential input, pulses with a maximum frequency of 30
kHz can be counted, provided the pulses have a duty ratio of 1:1 (50%) and phase
difference of 90°. Inputting pulses with an irregular duty ratio or phase difference will
decrease the allowable input frequency.
Note 10: The current value of the high-speed counter is stored with a built-in,
electrical double-layer capacitor for more than two months at 25°C (KV-10xx: more
than 20 days). The value can also be stored in EEPROM.
➮ "3.5 System Mode" (p.1-94).
14
High-speed counter comparators
• The high-speed counter comparator (CTC) compares its preset value with the
value of the high-speed counter (CTH).
• The CTC contact turns ON when the current value of the CTH matches the
preset value of the CTC.
• Among CTC contacts, the ON/OFF status of output relays 0500 and 0501 can be
changed with hardware (direct output) or can be used to execute an interrupt. Set
special utility relays (2103 to 2112, 2203 to 2212) to change the ON/OFF status
of output relays 0500 and 0501.
• The following table shows the relationship between the high-speed counters and
high-speed counter comparators.
High-speed High-speed counter Preset value Direct
Interrupts
counter comparator range output
CTH0 CTC0, CTC1 0500 INT CTC0, INT CTC1
#1 to 65535
CTH1 CTC2, CTC3 0501 INT CTC2, INT CTC3

Note 1: Once the high-speed counter comparator turns ON, it remains ON until a
RES instruction is encountered.
Note 2: When a high-speed counter comparator is used as an interrupt, the interrupt
is executed as soon as the current value of the high-speed counter reaches the
preset value of the comparator. At the same time, the contact for the high-speed
counter comparator automatically turns OFF.
Note 3: CTC2 or CTC3 cannot be used as comparators for CTH0; CTC0 or CTC1
cannot be used as comparators for CTH1.
Note 4: Do not specify "#00000" as the preset value for CTC0 through CTC3.

Chapter 4 High-speed Counters 3-209

KVNKA Chap 04_1.p65 209 08.3.11, 0:06 PM


4.2 Outline of High-speed Counters

4.2.2 Internal Clock for High-speed Counters


• Each high-speed counter (CTH) is equipped with a dedicated internal clock.
• To use the internal clock, specify the appropriate relay No. as an operand for the
CTH instruction.
• The internal clock or external pulses cannot be changed during program execu-
Visual KV

tion.
Series

• Each clock has the following count period:


High-speed counter CTH0 CTH1 Period
2100 2200 1.0 µs
Relay No. 2101 2201 10.0 µs
2102 2202 100.0 µs

High-speed counter internal clock error


• Absolute error: ± 200 ppm
• Temperature coefficient: 00
• Relative error between CTH0 and CTH1: ± 0

3-210 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 210 08.3.11, 0:06 PM


4.3 Setting and Operation of High-speed Counters

4.3 Setting and Operation of High-speed


Counters
The high-speed counters and high-speed counter comparators operate using data

Visual KV
Series
specified with special utility relays.

4.3.1 Reading the Current Value of the High-speed Counter


The current value of a high-speed counter is normally written as 16-bit data (0 to
65535).
The range of the current value for high-speed counters is as follows:
High-speed counter Current value
CTH0
0 to 65535
CTH1
➮ Refer to "4.4.1 24-bit High-speed Counter" (p. 3-221) when using the 24-bit high-speed counter.

4.3.2 Preset Value of the High-speed Counter Comparator


The preset value of a high-speed counter comparator is written as 16-bit data (0 to
65535).
The relationship between high-speed counters and high-speed counter comparators
is as follows:
High-speed counter
High-speed counter
comparator
CTC0
CTH0
CTC1 14
CTC2
CTH1
CTC3

➮ Refer to "4.4.1 24-bit High-speed Counter" (p. 3-221) when using the 24-bit high-speed counter.

4.3.3 Comparator Output


The high-speed counter comparator provides the comparator output function, which
turns ON outputs as soon as the comparator turns ON, without being affected by the
scan time.
Comparator output is controlled by setting special utility relays. The relationships
among the high-speed counters, high-speed counter comparators, and special utility
relays are as follows:

High-speed
High-speed Special utility
counter Setting of special utility relay
counter relay
comparator
CTC0 2104 Turns output relay 0500 ON/OFF. OFF: Yes ON: No
CTH0
CTC1 2108 Turns output relay 0500 ON/OFF. OFF: Yes ON: No
CTC2 2204 Turns output relay 0501 ON/OFF. OFF: Yes ON: No
CTH1
CTC3 2208 Turns output relay 0501 ON/OFF. OFF: Yes ON: No

Chapter 4 High-speed Counters 3-211

KVNKA Chap 04_1.p65 211 08.3.11, 0:06 PM


4.3 Setting and Operation of High-speed Counters

4.3.4 Count Input Method


Select the input source for the high-speed counter.

When using an internal clock as input


Visual KV

Three types of internal clocks are provided: 1 µs, 10 µs, and 100 µs.
Series

Set the desired internal clock with a special utility relay.

When using external inputs as count inputs


Set special utility relays as follows:
CTH0 CTH1
Operation mode
2113 2114 2407 2213 2214 2415
With direction judgement
(Count up when phase B input
OFF OFF OFF OFF OFF OFF
No multiplication 0006 [0007] is OFF, count down
(single-phase when ON)
input) Without direction judgement
(Always count up by ignoring OFF OFF ON OFF OFF ON
phase B input 0006 [0007])

x2 ON OFF — ON OFF —
Phase differential
input
x4 OFF ON — OFF ON —

2-pulse method
ON ON — ON ON —
(Phase A: count up, phase B: count down)

0500 (CTH1) input — — — — — —

4 ■ Operation mode
The counting method can be selected from the following when external inputs are
used.
The ring counter function is available for each counting method.
➮ For more about the ring counter, refer to "4.4.4 Ring Counter Function" (p. 3-225).

■ Types of operation modes


No multiplication mode (single-phase input)
Counts up at the rising edge of phase A while phase B is OFF.
Counts down at the rising edge of phase A while phase B is ON.

• With direction judgement (Special utility relay 2407: OFF)


(Phase A) ON

0004 OFF
(Phase B) ON
0006 OFF
(Counter value)
CTH0 0 1 2 3 2 1 0

• Without direction judgement (Special utility relay 2407: ON)

(Phase A) ON

0004 OFF
(Phase B) ON
0006 OFF

(Counter value)
CTH0 0 1 2 3 4 5 6

Phase B input can be ignored by turning ON special utility relay 2407 (for CTH0) or
2415 (for CTH1).

3-212 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 212 08.3.11, 0:06 PM


4.3 Setting and Operation of High-speed Counters

Double (x2) mode: Counts up/down based on the phase difference


between two-phase pulse inputs (phase A and
phase B).
ON
(Phase A)
0004 OFF

Visual KV
(Phase B) ON

Series
0006 OFF

(Counter value)
CTH0
0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0

Quadruple (x4) mode: Counts up/down based on the phase difference


between two-phase pulse inputs (phase A and
phase B).
ON
(Phase A)
0004 OFF

(Phase B) ON
0006 OFF

(Counter value)
CTH0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

2-pulse method mode: Counts up at the rising edge of phase A and


counts down at the rising edge of phase B.
14
(Phase A) ON
0004 OFF
(Phase B) ON
0006
OFF
(Counter value)
CTH0

0 1 2 3 4 5 6 5 4 3 2 1 0

Count up: Rising edge of phase A


Count down: Rising edge of phase B

Note 1: Use SET-RES instructions to set the special utility relays.


Note 2: When using phase differential input, pulses with a maximum frequency of 30
kHz can be counted, provided the pulses have a duty ratio of 1:1 (50%) and phase
difference of 90°. Inputting pulses with an irregular duty ratio or phase difference will
decrease the allowable input frequency.

When using comparator output from other counters as count input


When relay 0500 is specified as the operand for CTH1, the pulses produced by
CTH0 can be directly output from 0500 to CTH1.
In this case, input relays 0005 (phase A) and 0007 (phase B) for CTH1 can be used
as normal input relays.
ON
0500
OFF

(Counter value)
CTH1 0 1 2 3 4 5 6

Chapter 4 High-speed Counters 3-213

KVNKA Chap 04_1.p65 213 08.3.11, 0:06 PM


4.3 Setting and Operation of High-speed Counters

4.3.5 Resetting the High-speed Counter


Reset is an operation used to set the current value of a high-speed counter to "0".
Four types of reset operations are available: reset with input-enable relay, reset with
external input, reset automatically after counting up, and reset with the RES CTH
instruction.
Visual KV
Series

Automatic reset after counting up


Resets the counter value as soon as the preset value matches the current value
(CTC = CTH).
This reset operation is independent of the scan time.
High-speed
High-speed
counter Relay No. Operation
counter
comparator

CTC0 2103 When special utility relays 2103 and 2112 are
turned ON, the current CTH0 value is reset as
CTH0
soon as it matches the CTC0 or CTC1 preset
CTC1 2112 value.

CTC2 2203 When special utility relays 2203 and 2212 are
turned ON, the current CTH1 value is reset as
CTH1
soon as it matches the CTC2 or CTC3 preset
CTC3 2212 value.

Note: Do not specify the same values for CTC0 and 1 (2 and 3) to automatically
reset the counter with both comparators.
Scan

CTH

4 CTH = CTC
CTH is reset when CTH value equals CTC value.

Reset with the RES CTH instruction


Resets the counter by writing a RES CTH instruction to the program.
This reset operation is dependent on the scan time.
Scan

CTH

Execution of RES CTH instruction

* CTH is reset by the output process of the scan which executes the RES CTH
instruction.

Reset with the input-enable relay


Resets the counter at execution of CTH instruction during the scan after the input-
enable relay is turned OFF.
This reset operation is dependent on the scan time.

Scan
Input-enable relay
for CTH instruction

CTH

Execution of CTH instruction

* CTH is reset at execution of the CTH instruction during the scan after the input-
enable relay turns OFF.

3-214 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 214 08.3.11, 0:06 PM


4.3 Setting and Operation of High-speed Counters

Reset with external input


Resets the counter at the instant the external reset input relay turns ON.
The external reset is assigned to input relay 0008 (KV-10xx: 0002) for CTH0, and
input relay 0009 (KV-10xx: 0003) for CTH1.
The timing of the reset can be changed by setting relays 2400 and 2401 (for CTH0)

Visual KV
or 2408 and 2409 (for CTH1) as follows.

Series
This reset operation is independent of the scan time.

High-speed
Relay No. Status Relay No. Status Operation
counter
OFF OFF Disables external reset operation.
Resets counter at rising edge of input
ON OFF
0008 (KV-10xx: 0002).
CTH0 2400 2401 Resets counter at falling edge of input
OFF ON
0008 (KV-10xx: 0002).
Resets counter when input 0008
ON ON
(KV-10xx: 0002) is ON.
OFF OFF Disables external reset operation.
Resets counter at rising edge of input
ON OFF
0009 (KV-10xx: 0003).
CTH1 2408 2409 Resets counter at falling edge of input
OFF ON
0009 (KV-10xx: 0003).
Resets counter when input 0009
ON ON
(KV-10xx: 0003) is ON.

Scan
External
reset input

CTH
14

* CTH is reset at the instant the external reset input relay turns ON.

Preset function
The current value of CTH can be changed to any desired value by using the external
reset function of input relays 0008 (KV-10xx: 0002) (for CTH0) or 0009 (KV-10xx:
0003) (for CTH1) specified with special utility relays 2400 and 2401 (for CTH0) or
2408 and 2409 (for CTH1). (The external reset function sets the value to "0".)
Write the desired value of the preset input into the following data memories:
DM No. Description
DM1924 (low-order bits), DM1925 (high-order bits) Preset value for CTH0
DM1926 (low-order bits), DM1927 (high-order bits) Preset value for CTH1

Use the STA or DW instruction to write data to the data memory.

Note 1: The preset function is available only with the external reset input. The CTH
value is reset to "0" with other resetting methods.
Note 2: Use the SET, RES instruction pair to set the special utility relays.
Note 3: When 16-bit high-speed counter is used, write the preset values into
DM1924 and DM1926 only.

Chapter 4 High-speed Counters 3-215

KVNKA Chap 04_1.p65 215 08.3.11, 0:06 PM


4.3 Setting and Operation of High-speed Counters

4.3.6 Differences with the CTH Instruction between the


Conventional and Visual KV Series
The Visual KV Series has some different high-speed counter operations from the
conventional KV Series [KV-10/16/24/80R(W)/T(W)].
Visual KV
Series

Input-enable relay

0001 CTH0
0004

Input-enable relay Count input

• With the conventional KV Series, the current value of the high-speed counter is
reset when the CTH instruction is executed while the input-enable relay is OFF.
However, the counter continues counting until the end of the scan time. As a
result, when the input-enable relay starts counting again, the counter may al-
ready be incremented by the length of the scan time.
• With the Visual KV Series, the current value of the high-speed counter is reset at
the falling edge of the input-enable relay, so that the counter does not continue
counting.

High-speed counter (CTH)


• The conventional KV Series includes high-speed counter CTH0, which is an 8-bit
counter. The period of the internal clock is different from that in the new KV
Series.
• The Visual KV Series allows you to reset a high-speed counter with external
inputs. Its high-speed counter CTH0 is a 16-bit counter (can also be used as 24-
bit counter).
• With the Visual KV Series, when using the high-speed counter, the input time
constant must be set shorter by using the HSP instruction or by turning ON
4 special utility relay 2813.

Phase differential input


The Visual KV Series allows phase differential input for the high-speed counter.

Response frequency
The Visual KV Series provides a response frequency of 30 kHz.

High-speed counter comparator


• The high-speed counter comparator turns ON the contact when its preset value
matches the current value of the high-speed counter. Consequently, the contact
may turn ON during the scan time.
Be careful when using the contact for one comparator in several points in a
program.

Special utility relay


A portion of the special utility relay assignment is different from that of the conven-
tional KV Series.

3-216 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 216 08.3.11, 0:06 PM


4.3 Setting and Operation of High-speed Counters

4.3.7 Applications of High-speed Counters


Comparing encoder values
Uses two encoders to input phase differential signals to input relays 0004 and 0006,
and 0005 and 0007. Turns ON output relay 0500 if the count value of 0005 and 0007

Visual KV
is greater than that of 0004 and 0006 when 0004 and 0006 count "60000".

Series
Initial setting
2008 2113 2114 2213 2214 CTH0 SET 2113
EI SET RES SET RES RES Setting for CTH0
RES 2114
2002 HSP SET 2213
Setting for CTH1
0004 RES 2214
HSP
0005

HSP
0006 Sets input time constant of inputs 0004,
0005, 0006, and 0007 to 10 µs.
HSP
0007

0000 CTH0
0004 Phase differential input to inputs 0004 and
0006
#60000
CTC0 Specifies preset value of CTC0 to "#60000".
CTH1
0005 Phase differential input to inputs 0005 and
0007
END

INT
CTC0

2002 CTH1 #60000 2009 0500


LDA CMP RES

2009 0500
SET Compares current value of CTH1 with

2002 CTH0 CTH1


"#60000". Turns ON 0500 when value is 14
RES RES
greater than "#60000". Turns OFF 0500
when value is smaller.
RETI

ENDH

Setting multi-level high-speed counters


Sets the preset value of the high-speed counter comparator for the high-speed
counter for input relay 0005 as follows:
#01000 ➞ DM0000
#02000 ➞ DM0001
#03000 ➞ DM0002
When the current counter value reaches one of the preset values, the respective
output turns ON as follows:
DM0000 ➞ 0500 turns ON.
DM0001 ➞ 0501 turns ON.
DM0002 ➞ 0502 turns ON.

2008 #01000 DM0000 #02000 DM0001 #03000 DM0002


LDA STA LDA STA LDA STA

2002 HSP
0005
0001 CTH1
0005
2002 CTH1 DM0000 2009 0500
LDA CMP

DM0001 2009 0501


CMP

DM0002 2009 0502


CMP

Chapter 4 High-speed Counters 3-217

KVNKA Chap 04_1.p65 217 08.3.11, 0:06 PM


4.3 Setting and Operation of High-speed Counters

Cording

Line No. Instruction Operand Line No. Instruction Operand


0000 LD 2008 0015 CTH1 0005
0001 LDA #01000 0016 LD 2002
0002 CON 0017 LDA CTH1
Visual KV

0003 STA DM0000 0018 MPS


Series

0004 CON 0019 CMP DM0000


0005 LDA #02000 0020 ANB 2009
0006 CON 0021 OUT 0500
0007 STA DM0001 0022 MRD
0008 CON 0023 CMP DM001
0009 LDA #03000 0024 ANB 2009
0010 CON 0025 OUT 0501
0011 STA DM0002 0026 MPP
0012 LD 2002 0027 CMP DM0002
0013 HSP 0005 0028 ANB 2009
0014 LDB 0001 0029 OUT 0502

Clearing the current value of the high-speed counter


Counts pulses at input relay 0005. When the current value reaches the preset value
"60000", clears the current value of high-speed counter CTH1 and turns ON output
relay 0502 for 3 seconds.

Cording
2008 2203 CTH1 Line No. Instruction Operand
SET RES
0000 LD 2008
2002 HSP 0001 SET 2203
0005
4 0002 CON
2002 CTH1
0003 RES CTH
0005
0004 LD 2002
#60000
CTC2 0005 HSP 0005
0006 LD 2002
CTC2 0502 #00030 T001 CTC2
T001 RES 0007 CTH1 0005
0008 CTC2 #60000
0009 LD CTC2
0010 OUT 0502
0011 CON
0012 TMR 001 #00030
0013 CON
0015 AND T001
0016 RES CTC2

3-218 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 218 08.3.11, 0:06 PM


4.3 Setting and Operation of High-speed Counters

Phase differential input


• Inputs phase differential signals from input relays 0004 and 0006 and counts
pulses at CTH0.
• The count value is written to DM0000.
• When the current value of CTH0 reaches "60000", clears the value, turns ON

Visual KV
output 0500, and stops counting at CTH0.

Series
• Input relay 0008 is used as an external reset.

2008 2103 2113 2114 2400 2401 CTH0


EI SET SET RES SET RES RES Initial setting
2002 HSP
0004
HSP
0006
HSP
0008

0500 CTH0
0004
#60000
CTC0

2002 CTH0 DM0000


LDA STA

END

INT
CTC0
2002 0500
SET

RETI

ENDH

Cording
Line No. Instruction Operand Line No. Instruction Operand 14
0000 LD 2008 0016 HSP 0006
0001 EI 0017 HSP 0008
0002 CON 0018 LDB 0500
0003 SET 2103 0019 CTH 0 0004
0004 CON 0020 CTC 0 #60000
0005 SET 2113 0021 LD 2002
0006 CON 0022 LDA CTH0
0007 RES 2114 0023 CON
0008 CON 0024 STA DM0000
0009 SET 2400 0025 END
0010 CON 0026 INT CTC0
0011 RES 2401 0027 LD 2002
0012 CON 0028 SET 0500
0013 RES CTH0 0029 RETI
0014 LD 2002 0030 ENDH
0015 HSP 0004

● Initial setting
Special utility relays
• Turn ON 2013 to reset the current value of CTH0 when CTC0 turns ON.
• Turn ON 2113 and turn OFF 2114 to set the high-speed counter to double (x2)
multiplication mode.
• Turn ON 2400 and turn OFF 2401 to enable the external reset.

The counter is reset at the rising edge of input 0008.

Note : External reset input 0008 is set with hardware. Programming is not necessary
except for setting the external reset enable relays (2400 to ON and 2401 to OFF).

Chapter 4 High-speed Counters 3-219

KVNKA Chap 04_1.p65 219 08.3.11, 0:06 PM


4.3 Setting and Operation of High-speed Counters

Fetching counts from encoder


Uses the double (x2) multiplication mode to fetch phase differential input from the
encoder.
The fetched data is output as BCD data. Phase differential input: 0004, 0006 BCD
output: 0600 to 0615 (4 digits)
Visual KV
Series

2008 2103 2113 2114 CTH0 2400


SET SET RES RES SET Initial setting

2002 HSP
0004
HSP
0006
HSP
0008
0000 CTH0
0004
2002 #00000 TM00 CTH0 #00002 0600
LDA STA LDA DIV TBCD STA

END

ENDH

Cording

Line No. Instruction Operand Line No. Instruction Operand


0000 LD 2008 0015 CTH 0 0004
4 0001 SET 2103 0016 LD 2002
0002 CON 0017 LDA #0000
0003 SET 2113 0018 CON
0004 CON 0019 STA TM00
0005 RES 2114 0020 CON
0006 CON 0021 LDA CTH0
0007 RES CTH0 0022 CON
0008 CON 0023 DIV #00002
0009 SET 2400 0024 CON
0010 LD 2002 0025 TBCD
0011 HSP 0004 0026 CON
0012 HSP 0006 0027 STA 0600
0013 HSP 0008 0028 END
0014 LD 0000 0029 ENDH

● Initial setting
Special utility relays
• Turn ON 2013 to reset the current value of CTH0 when CTC0 turns ON.
• Turn ON 2113 and turn OFF 2114 to set the high-speed counter to double (x2)
multiplication mode.
• Turn ON 2400 to enable the external reset.

The counter is reset at the rising edge of input 0008.

Note : The external reset input 0008 is set with hardware. Programming is not
necessary except for setting the external reset enable relay (2400 to ON).

3-220 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 220 08.3.11, 0:06 PM


4.4 Expanded Functions of High-speed Counters

4.4 Extended Functions of High-speed


Counters Visual KV Series Only
This section describes the 24-bit high-speed counter and ring counter functions.

Visual KV
Series
4.4.1 24-bit High-speed Counter
Normally, the high-speed counter operates with 16 bits. You can operate the counter
with 24 bits (0 to 16777215) using special utility relays.
Set the 24-bit operation with the MEMSW instruction.
➮ "MEMSW instruction" (p. 3-92)

MEMSW instruction: SW3


No. Function of switch ON OFF

Setting 24-bit/16-bit counter


3 24-bit 16-bit
comparator for CTH0

MEMSW instruction: SW4


No. Function of switch ON OFF

Setting 24-bit/16-bit counter


0 24-bit 16-bit
comparator for CTH1

The following data memories are used for 24-bit operation.


Read areas
DM No. Description DM No. Description 14
Low-order bits of current Low-order bits of preset
DM1900 DM1906
CTH0 value CTC1 value
High-order bits of current High-order bits of preset
DM1901 DM1907
CTH0 value CTC1 value
Low-order bits of current Low-order bits of preset
DM1902 DM1908
CTH1 value CTC2 value
High-order bits of current High-order bits of preset
DM1903 DM1909
CTH1 value CTC2 value
Low-order bits of preset CTC0 Low-order bits of preset
DM1904 DM1910
value CTC3 value
High-order bits of preset High-order bits of preset
DM1905 DM1911
CTC0 value CTC3 value

Write areas
DM No. Description DM No. Description
Low-order bits of current Low-order bits of preset
DM1912 DM1918
CTH0 value CTC1 value
High-order bits of current High-order bits of preset
DM1913 DM1919
CTH0 value CTC1 value
Low-order bits of current Low-order bits of preset
DM1914 DM1920
CTH1 value CTC2 value
High-order bits of current High-order bits of preset
DM1915 DM1921
CTH1 value CTC2 value
Low-order bits of preset Low-order bits of preset
DM1916 DM1922
CTC0 value CTC3 value
High-order bits of preset High-order bits of preset
DM1917 DM1923
CTC0 value CTC3 value

Chapter 4 High-speed Counters 3-221

KVNKA Chap 04_1.p65 221 08.3.11, 0:06 PM


4.4 Expanded Functions of High-speed Counters

The high-speed counter and high-speed counter comparator update the contents of
the read area of data memory each scan time.
At the start of an interrupt routine, the current value is updated. The contents of the
write area of data memory is updated with the data write operation.
➮ "Setting the 24-bit high-speed counter comparator" (below) and "4.4.2 Changing the Current Value of
a 24-bit High-speed Counter" (p. 3-223)
Visual KV
Series

Note 1: Use the SET, RES instruction pair to set the special utility relays.
Note 2: The 16-bit/24-bit high-speed counter setting with the MEMSW instruction is
effective when the Visual KV is in RUN mode.
You must change the program to change between 16-bit and 24-bit settings.

Setting the 24-bit high-speed counter comparator


To specify the preset value for the 24-bit high-speed counter comparator, write the
value into the write area DM1916 to DM1923 and execute the STA and CTC instruc-
tions to specify or change the preset value.
When the setting or change is properly performed, the CTC read areas DM1904
through DM1911 are updated with the new values after one scan.

■ Changing the preset value


Change the preset value for the 24-bit high-speed counter comparator using the
Access Window, programming support software, handheld programmer, or operator
panel with the following procedure.

1. Write the desired preset value into data memory.


Write the desired preset value to the CTC preset value write areas DM1916
through DM1923.

2. Change the preset value of CTC. (See the notes on the next page.)
4 • With the Access Window
Call CTC in device mode and change the value.
• With the "KV IncrediWare (DOS)" programming support software
Change the preset value of CTC with the "Edit Device CTC" [F2] option.
• With the "LADDER BUILDER for KV" programming support software
Change the preset value of CTC in the dialog box.
• With the KV-P3E(01) handheld programmer
Change the preset value of CTC with the "TIMER COUNTER SETTING
CHANGE" function.
➮ For more about detailed operation, refer to "Chapter 3 Access Window" (p. 1-79), "Chapter 6
Handheld Programmer" (p. 1-195) and "Chapter 2 Instructions" (p. 3-33).

Note 1: When the preset value of a 24-bit CTC is changed with an instruction such
as STA CTC0, the value entered as an operand is ignored but the value written in
DM1916 through DM1923 is referred to and used as the preset value.
Note 2: Be sure to write the desired value to the write area of the high-speed
counter comparator preset value (DM1916 through DM1923) before executing the
change operation (e.g., STA instruction).

3-222 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 222 08.3.11, 0:06 PM


4.4 Expanded Functions of High-speed Counters

4.4.2 Changing the Current Value of a 24-bit High-speed


Counter
Change the current value of the 24-bit high-speed counter with the Access Window,
programming support software, handheld programmer, or operator panel with the

Visual KV
following procedure.

Series
1. Write the desired current value into data memory.
Write the desired current value to the CTH current value write areas DM1912
through DM1915.

2. Change the current value of CTH. (See notes below.)


• With the Access Window
Call CTH in device mode and change the value.
• With the "KV IncrediWare (DOS)" programming support software
Change the preset value of CTH with the "Edit Device CTH" [F2] option.
• With the "LADDER BUILDER for KV" programming support software
Change the preset value of CTH in the dialog box.
• With the KV-P3E(01) handheld programmer
Change the preset value of CTH with the "TIMER COUNTER CURRENT VALUE
CHANGE" function.
➮ For more about detailed operation, refer to "Chapter 3 Access Window" (p.1-79), "Chapter 6
Handheld Programmer" (p.1-195) and "Chapter 2 Instructions" (p.3-33).

Note 1: The current value of the high-speed counter cannot be changed in the
ladder program.
Note 2: DM1900 to DM1923, the data memories for 24-bit high-speed counters, can
be used only when a 24-bit high-speed counter is specified with the MEMSW in-
14
struction.

Chapter 4 High-speed Counters 3-223

KVNKA Chap 04_1.p65 223 08.3.11, 0:06 PM


4.4 Expanded Functions of High-speed Counters

4.4.3 Application Example of 24-bit High-speed Counter


(single-phase input)
The following is a ladder program using a 24-bit high-speed counter and high-speed
counter comparator with a preset value of "1000000".
Visual KV
Series

MEMSW
0001 $0800 1)

2008 #00015 DM1917 #16960 DM1916 CTC0 CTH0


0002 LDA STA LDA STA STA RES 2)
High-order 16 bits of Low-order 16 bits of Writes preset value of
high-speed counter high-speed counter high-speed counter
2002 comparator comparator comparator HSP
0003 0004 3)

2002 CTH0
0004 0004 4)

#65535
0005 CTC0 5)

2002 DM1901 DM0001 DM1900 DM0000


0006 LDA STA LDA STA 6)
High-order 16 bits of Low-order 16 bits of
current value of high- current value of high-
speed counter speed counter END
0007

ENDH
0008

1) Sets CTH0 as the 24-bit high-speed counter with the MEWSW instruction. (Turn
on 3 of SW3.)
2) When power is turned on, writes the preset value "1000000" of the high-speed
4 counter comparator (CTC0) and sets the value with the STA CTC0 instruction.
3) Sets the input time constant of input relay 0004 to 10 µs.
4) Counts pulses at input relay 0004 with high-speed counter CTH0.
5) Defines a dummy high-speed counter comparator.
6) Reads the current value of CTH0 into data memory DM0000 (low-order bits) and
DM0001 (high-order bits) each scan time.

3-224 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 224 08.3.11, 0:06 PM


4.4 Expanded Functions of High-speed Counters

4.4.4 Ring Counter Function


Normally, the counter reads "#65535 ($FFFF)" by counting down from "0" by one.
The ring counter function is an additional function of the automatic clear function. It
reads "preset value - 1" when it counts down from "0" by one.

Visual KV
■ Operation of the ring counter function

Series
Normal counter
0 65535

Ring counter
0 CTC1 -1 65535
( CTC3 -1)

Not used

■ Setting procedure
• When setting the ring counter, use CTC1 for CTH0 and CTC3 for CTH1.
• Set the upper limit (preset value) to CTC1 or CTC3 and turn ON special utility
relay 2406 (for CTH0) or 2414 (for CTH1). The ring counter is set to read "CTC1/
CTC3 preset value - 1" when it counts down from "0" by one.
• To use the ring counter for both counting up/down operations, turn ON special
utility relay 2112 (for CTH0) or 2212 (for CTH1).

High-speed counter High-speed counter comparator Special utility relay

When CTH0 is used Set "upper limit value + 1" to CTC1. Turn ON 2406.
14
When CTH1 is used Set "upper limit value + 1" to CTC3. Turn ON 2414.

Note 1: Use the SET-RES instruction pair to set the special utility relays.
Note 2: The flag or the count-up interrupt for each CTC is effective in counting up
operations, but is disabled in counting down operations.
Example: When CTC = 100
Count
up

Count
down
Turns ON.
CTC Does not turn ON.

CTH

0 1 2 97 98 99 0 1 2 2 1 0 99 98 97

Chapter 4 High-speed Counters 3-225

KVNKA Chap 04_1.p65 225 08.3.11, 0:06 PM


4.4 Expanded Functions of High-speed Counters

4.4.5 Applications of Ring Counters


When using a 16-bit high-speed counter
The following is a ladder program that uses the ring counter of a 16-bit high-speed
counter with the preset value of "10000".
Visual KV
Series

0 9999

2008 2113 2114 2406 2112 CTH0


0001 EI SET RES SET SET RES 1)
Sets ring Automatic reset
Sets high-speed counter in counter. of high-speed
2002 double (x2) multiplication mode.
counter HSP
0002 0004
2)
HSP
0003 0006

2002 CTH0
0004 0004 3)

#10000
0005 CTC1 4)

0500 #00010 T000 0500


0006 T000 RES 5)

END
0007

4 0008
INT
CTC1

2002 0500
0009 SET 6)

RETI
0010

ENDH
0011

1) When the power is turned on, an EI instruction enables interrupts. Sets high-
speed counter CTH0 in double (x2) multiplication mode, CTH0 as a ring counter,
and the high-speed counter automatic reset function at counting up. Resets the
high-speed counter.
2) Sets the input time constant for input relays 0004 and 0006 to 10 µs.
3) Counts 2-phase pulses of input relays 0004 and 0006 at CTH0.
4) Sets the preset value of high-speed counter comparator CTC1 to "10000".
5) Output relay 0500 turns ON for 1 second and then turns OFF.
6) When CTC1 turns ON, an interrupt is executed. Output relay 0500 turns ON.

3-226 Chapter 4 High-speed Counters

KVNKA Chap 04_1.p65 226 08.3.11, 0:06 PM


4.4 Expanded Functions of High-speed Counters

When using a 24-bit high-speed counter


The following is a ladder program that uses the ring counter of a 24-bit high-speed
counter with the preset value of "100000".

Visual KV
Series
0 99999

MEMSW
0001 $0800 1)

2008 2113 2114 2406 2112 CTH0


0002 EI SET RES SET SET RES 2)
Sets high-speed Sets ring Automatic reset of
counter in double (x2) counter. high-speed counter
multiplication mode.
#00001 DM1919 #34464 DM1918 CTC1
0003 LDA STA LDA STA STA 3)
High-order 16 Low-order 16 Writes preset
bits of high- value of high-
bits of high- speed counter
speed counter speed counter
comparator.
comparator comparator
2002 HSP
0004 0004
4)
HSP
0005 0006

2002 CTH0
0006 0004 5)

#65535
0007 CTC1 6)

0008
0500 #00010
T000
T000 0500
RES 7)
14
END
0009

INT
0010 CTC1
8)
2002 0500
0011 SET

RETI
0012

ENDH
0013

1) Sets CTH0 as a 24-bit high-speed counter using the MEMSW instruction (Turn
on 3 of SW3.).
2) When the power is turned on, an EI instruction enables interrupts. Sets high-
speed counter CTH0 in double (x2) multiplication mode, CTH0 as a ring counter,
and high-speed counter automatic reset function at counting up. Resets the high-
speed counter.
3) Writes the preset value "100000" of high-speed counter comparator (CTC1) for
the 24-bit high-speed counter (CTH0). Sets the preset value with the STA CTC0
instruction.
4) Sets the input time constant for input relays 0004 and 0006 to 10 µs.
5) Counts 2-phase pulses of input relays 0004 and 0006 at CTH0.
6) Describes a dummy high-speed counter comparator.
7) Output relay 0500 turns ON for 1 second and then turns OFF.
8) When CTC1 turns ON, an interrupt is executed. Output relay 0500 turns ON.

Chapter 4 High-speed Counters 3-227

KVNKA Chap 04_1.p65 227 08.3.11, 0:06 PM


4.5 Special Functions Using High-speed Counters

4.5 Special Functions Using High-speed


Counters Visual KV Series Only
This section describes the specified frequency pulse output function, frequency
Visual KV
Series

counter function, and cam switch function.

4.5.1 Specified Frequency Pulse Output Function


With high-speed counter CTH1, output pulses from output relay 0501 with the
frequency (Hz) specified in data memory DM1936. To activate this function, write the
desired value into DM1936 and turn ON special utility relay 2306.

The internal clock of the high-speed counter is automatically set to 1 µs. Pulses with
duty ratio of 1:1 are output at the preset frequency obtained with the calculation
"1,000,000/2/Output frequency".

The KV performs the following operations after each scan time during the specified
frequency pulse output function.

• Stops pulse output when special utility relay 2306 is turned OFF.
• Sets the preset value so that pulses are output at the frequency specified with
the DM. (Pulse duty ratio: fixed to 50%)
• Starts pulse output.

Pulse duty
Pulse duty is the ratio of the pulse widths between ON time and OFF time. A pulse
duty of 50% means that the pulse widths between ON time and OFF time are the
same, as follows.
4 ON

OFF

The ratio between ON and OFF time is 1:1.

■ Device used for specified frequency pulse output


Special utility relays
Relay No. Description
Use specified frequency pulse output. ON: Yes, OFF: No Function
2306
is forced OFF when error relay 2307 turns ON.
Error flag for specified frequency pulse output function.
2307
Turns ON when contents of DM1936 is other than 16 to 50000.

Data memory
DM No. Description
DM1936 Preset value for specified frequency pulse output is written.

3-228 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 228 08.3.11, 0:08 PM


4.5 Special Functions Using High-speed Counters

■ Setting method
• Set the desired output frequency (Hz) into DM1936. The available range is 16 Hz
to 50 kHz (16 to 50000).
• Pulses are output when special utility relay 2306 is ON. The output is stopped
when the relay is turned OFF.

Visual KV
• If an unacceptable frequency is specified, special utility relay 2307 (error relay)

Series
turns ON. Special utility relay 2306 is turned OFF and pulse output is stopped.

Note 1: The available minimum frequency specified in DM1936 is 16 Hz.


Note 2: The output is stopped when a value of 15 or less is specified in DM1936.
Note 3: Starts and stops of pulse output or frequency changes are executed after
each scan.
Note 4: It takes a maximum of 200 µs from when the output command is issued until
pulses are output.
Note 5: CTH1 and special utility relays 2200 through 2215 cannot be used when the
specified frequency pulse output function is used.

4.5.2 Applications of the Specified Frequency Pulse Output


■ Program using a digital trimmer
The following ladder program illustrates how to use a digital trimmer to output pulses
at a desired frequency (16 Hz to 10 kHz).
Pulse output is stopped when the value of the digital trimmer decreases to 15 or
less.

2008 #10000 DM1938 2306


0001 LDA STA SET 1)

2002 0 DM1936 14
0002 TMIN STA 2)

2307 0500
0003 3)

END
0004

ENDH
0005

1) Sets the upper limit of the digital trimmer to "10000" and turns ON special utility
relay 2306 to start the specified frequency pulse output.
2) Sets the input value of the digital trimmer as the output frequency value.
3) Output relay 0500 turns ON when a setting error occurs.

Chapter 4 High-speed Counters 3-229

KVNKA Chap 04_2.p65 229 08.3.11, 0:08 PM


4.5 Special Functions Using High-speed Counters

■ Program for speed control


The following ladder program illustrates speed control using the specified frequency
pulse output function.
Control is started when input relay 0000 turns ON. The operation is slowed down
and then stopped when input relay 0001 turns ON.
By specifying the speed (Hz) in data memory DM0000, the program controls the
Visual KV
Series

speed with a start-up speed of 16 Hz and an acceleration speed of 100 Hz/100 ms.

0000 1000 1000 #00016 DM1936 2306 1100


0001 DIFU LDA STA SET SET 1)

0001 1001 1001 1101


0002 DIFU SET 2)

1101 #00016 DM0000 DM1936 2010 2306 1100 1101


0003 LDA STA CMP RES RES RES 3)

1100 T000 #00100


T
0004 S 000 4)

T000 DM1936 DM0000 2009 00


0005 LDA CMP CALL 5)

2011 01
0006 CALL

2307 0500
0007 6)

0008 END

SBN
0009 00 7)

2002 DM0000 DM1936 #00100 2011 TM02 DM1936 TM02 DM1936


0010 LDA SUB CMP STA LDA ADD STA

2011 DM1936 #00100 DM1936


0011 LDA ADD STA

4 RET
0012

SBN 8)
0013 01

2002 DM1936 DM0000 #00100 2011 TM02 DM1936 TM02 DM1936


0014 LDA SUB CMP STA LDA SUB STA

2011 DM1936 #00100 DM1936


0015 LDA SUB STA

RET
0016

ENDH
0017

1) Sets "16" as the preset speed at the rising edge of input relay 0000. Turns ON
special utility relay 2306 to start the specified frequency pulse output. Then, turns
ON the operating flag.
2) Turns ON slow-down-stop flag 1101 at the rising edge of input 0001.
3) When the slow-down-stop flag turns ON, sets the preset speed to "16". When the
output frequency reaches "16", turns OFF the operation start flag, operating flag,
and slow-down-stop flag.
4) Activates a 100-ms flicker circuit while the operating flag turns ON.
5) Compares the current speed and preset speed every 100 ms. Executes subrou-
tine 0 when the preset speed is faster, and executes subroutine 1 when the
preset speed is slower.
6) Output relay 0500 turns ON when a setting error occurs.
7) Acceleration process. When the current speed is slower than the preset speed by
less than "100", the speed is accelerated by the difference. When the difference
is "100" or more, the speed is accelerated by "100".
8) Deceleration process. When the current speed is faster than the preset speed by
less than "100", the speed is decelerated by the difference. When the difference
is "100" or more, the speed is decelerated by "100".

3-230 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 230 08.3.11, 0:08 PM


4.5 Special Functions Using High-speed Counters

4.5.3 Frequency Counter Function


High-speed counter CTH0 is used. Write the interval (ms) of frequency measure-
ment into data memory DM1404 and turn ON special utility relay 2305. The mea-
surement result (Hz) is written into DM1405.
Input relay 0004 is for pulse input (single-phase input). Input relay 0006 (phase B

Visual KV
Series
input) is ignored.

■ Devices used with the frequency counter


Special utility relays

Relay No. Description


2305 Use frequency counter. ON: Yes, OFF: No

Data memory

DM No. Description
DM1404 Measurement cycle (ms) of frequency counter [1 to 1000]

DM1405 Result of frequency count (Hz) of frequency counter

■ Operation flow
1. Set the high-speed counter with external input. Use the END instruction and
measure how much time has elapsed since the last measurement in units of 10
µs. After each scan, pulses are counted within the time specified with the data
memory. The frequency is calculated from the count value and written into data
memory.

2. When the time specified with DM1404 elapses from the last measurement, the
current value of CTH0 is fetched and divided by the elapsed time (Unit: 10 µs).
The frequency is obtained with the following calculation.
14
Frequency (Hz) = (100,000 x Pulse count)/Elapsed time (Unit: 10 µs)

3. The calculation result (Hz) is written into DM1405.

■ Setting method
1. Specify the counting period for the frequency counter (the interval of frequency
measurement [Unit: ms]) in data memory DM1404.

2. The preset value must be greater than the scan time. When a value smaller than
the scan time is specified, the frequency is measured each scan time.

Note 1: To use the frequency counter function, set the input time constant to 10 µs
with the HSP instruction or the special utility relay. (A maximum frequency of 30 kHz
can be measured.).
Note 2: The counting start/stop or measurement result is updated after each scan.
Therefore, the counting period includes some scan time errors for the time specified
with DM1404. Set the counting period so that overflow does not occur at CTH.
Note 3: Specify the counting period so that the number of pulse inputs in one period
is between 2 and 65535, inclusive.
Note 4: Measurement may fail when the pulse period is 5000 ms or more.
Note 5: The frequency counter cannot be used when CTH0 is used in the ladder
program.
Note 6: Special utility relays concerning CTH0, CTC0/1, and the cam switch cannot
be used.
Note 7: CTH0 and the cam switch function cannot be used when the frequency
counter is used.

Chapter 4 High-speed Counters 3-231

KVNKA Chap 04_2.p65 231 08.3.11, 0:08 PM


4.5 Special Functions Using High-speed Counters

4.5.4 Applications of Frequency Counters


Program for basic operation of the frequency counter
Stores the frequency of pulses at input relay 0004 to DM0000 every second (1000
ms). (Unit: Hz)
Visual KV
Series

2008 #01000 DM1404 2305


0001 LDA STA SET 1)

2002 HSP
0002 0004 2)

2002 DM1405 DM0000


0003 LDA STA 3)

END
0004

ENDH
0005

1) Sets the counting period to "1000 ms (1 second)" and turns ON special utility
relay 2305 to start the frequency counter function.
2) Sets the input time constant for input relay 0004 to 10 µs.
3) Stores the measured frequency (Hz) into data memory DM0000.

Program for synchronous control


The following ladder program illustrates synchronous control using the frequency
counter and pulse output functions.
Measures the frequency of pulses at input relay 0004 every 100 ms and outputs
pulses of the same frequency from output relay 0501.

4 2008 #00100 DM1404 2305 2306


0001 LDA STA SET SET 1)

2002 HSP
0002 0004 2)

2002 DM1405 DM1936


0003 LDA STA 3)

2307 0500
0004 4)

END
0005

ENDH
0006

1) Sets the counting period to "100 ms" and turns ON special utility relays 2305 and
2306 to start the frequency counter and the specified frequency pulse output
functions.
2) Sets the input time constant for input relay 0004 to 10 µs.
3) Uses the measured frequency (Hz) as the preset value for the output frequency
(Hz).
4) Turns on output relay 0500 when an error occurs in the setting of the specified
frequency pulse output.

3-232 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 232 08.3.11, 0:08 PM


4.5 Special Functions Using High-speed Counters

4.5.5 Cam Switch Function


The cam switch function has two modes: cam switch mode, which simulates cam
operation; and multi-step comparator mode, which compares the value written in
DM1401 with multiple values.

Visual KV
■ Devices used with the cam switch function

Series
Special utility relays
Relay No. Description
2314 Start relay
2315 Error relay
2715 In-operation relay
The preset value in the data memory is registered at the rising edge of the start
relay. When the preset value is changed, turn OFF special utility relay 2314 once
and then turn it ON again to register the new value.

■ Timing diagram of cam switch function


Start relay
2314

In-operation
relay
2715

Cam switch
Stopped Executed Stopped
function
▲ ▲
: Operation with the ladder program.
▲ ▲
: Operation automatically executed by the Visual KV.
Description: When start relay 2314 is turned ON, the Visual KV automatically turns OFF
start relay 2314 and turns ON in-operation relay 2715 to activate the cam
switch function. 14
When in-operation relay 2715 is turned OFF, the cam switch function is
stopped.

Cam switch mode


Simulates a cam operation.
Connect an encoder to CTH0 to count pulses in double multiplication mode.
CTH0 uses input relays 0004 (phase A), 0006 (phase B) (KV-10xx: 0000), and 0008
(phase Z) (KV-10xx: 0002).
Relays are turned ON/OFF when the pulse count reaches the specified angle.
The cam switch function controls a maximum of 32 successive relays. Specify relay
Nos. with the data memory (DM1400). Each relay is turned ON/OFF once every
rotation. To turn relays ON/OFF several times in one rotation, use the OR instruction
in the ladder program.

■ Devices used in cam switch mode


Data memory
DM No. Description
Stores initial address of output relays (Values other than 1900
DM1400
through 2900 whose last two digits are 00.).
Twice the pulse numbers for one rotation of the device connected to
DM1402
CTH0 (1 to 65534)
Angle at which first output relay turns ON/OFF (Unit: 0.1 deg.)
DM1406/DM1407
(0 to 65534)
Angle at which second relay turns ON/OFF (Unit: 0.1 deg.)
DM1408/• DM1409 (0 to 65534) •
• •
• •

DM1468/DM1469 Angle at which 32nd relay turns ON/OFF (Unit: 0.1 deg.)
(0 to 65534)
DM1470 Reserved for system use

Chapter 4 High-speed Counters 3-233

KVNKA Chap 04_2.p65 233 08.3.11, 0:08 PM


4.5 Special Functions Using High-speed Counters

Multi-step comparator mode


Even a single phase incoder can be used by changing a part of the cam switch
function.
To activate the multi-step comparator mode, write the value to be compared into
data memory DM1401 to replace the CTH0 value. This value determines the resolu-
Visual KV

tion. If 360 is written in DM1401, and 60 is written in DM1406, the 1st relay is turned
Series

ON at 60/360 i.e. 60°.

■ Devices used in multi-step comparator mode


Data memory
DM No. Description
Stores initial address of output relays (Values other than 1900
DM1400
through 2900 whose last two digits are 00.).
DM1401 Value to be compared (0 to 65534)
DM1402 Enter "65535" to use multi-stage comparator mode.
DM1406/DM1407 Preset value at which first output relay turns ON/OFF (0 to 65534)
DM1408/• DM1409 Preset value at which second relay• turns ON/OFF (0 to 65534)
• •
• •

DM1468/DM1469 Preset value at which 32nd relay turns ON/OFF (0 to 65534)


DM1470 Reserved for system use

Setting method
■ In cam switch mode
1. Write the initial number of output relays to be used into DM1400.
Be sure to write the initial relay number of each channel.
4 Example 0500, 0600: Acceptable, 0501, 0610: Unacceptable

2. Write the number of pulses in two pulse-periods of the encoder connected to


CTH0 into DM1402. (Twice the number of pulses for one rotation.)
3. Specify the angle at which the first relay turns ON (Unit: 0.1 deg.) into
DM1406. Use units of 0.1 deg. to specify the preset angle for the cam switch
mode. (Write the value of [Desired angle x 10] into data memory.)
4. Specify the angle at which the first relay turns OFF (Unit: 0.1 deg.) into
DM1407.
5. Specify the angle at which the second relay turns ON (Unit: 0.1 deg.) into
DM1408.
6. Specify the angle at which the second relay turns OFF (Unit: 0.1 deg.) into
DM1409.
7. Repeat steps 3 through 6 as many times as the number of relays to be used (32
relays max.).
8. Turn ON special utility relay 2314.
This relay automatically turns OFF when the cam switch function is activated.
9. Turn OFF special utility relay 2715 to stop the operation.

■ In multi-step comparator mode


1. Write the initial number of output relays to be used into DM1400.
Be sure to write the initial relay number of each channel.
Example 0500, 0600: Acceptable, 0501, 0610: Unacceptable
2. Write the value to be compared into DM1401, and write "65535" into DM1402.
3. Specify the preset value at which the first relay turns ON into DM1406.
4. Specify the preset value at which the first relay turns OFF into DM1407.

3-234 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 234 08.3.11, 0:08 PM


4.5 Special Functions Using High-speed Counters

5. Specify the preset value at which the second relay turns ON into DM1408.
6. Specify the preset value at which the second relay turns OFF into DM1409.
7. Repeat steps 3 through 6 as many times as the number of relays to be used (32
relays max.).
8. Turn ON special utility relay 2314.

Visual KV
This relay automatically turns OFF when the cam switch function is activated.

Series
9. Turn OFF special utility relay 2715 to stop the operation.

Note 1: When the cam switch function is used, 32 relays from the relay No. speci-
fied with DM1400 is occupied for the function regardless of whether they are used or
not. As a result, these relays cannot be used for any other purpose.
Note 2: To use the cam switch mode, set the input time constant to 10 µs with the
HSP instruction or the special utility relay. (A maximum frequency of 30 kHz can be
measured.)
Note 3: When any improper value is set in data memory, the setting error occurs
and special utility relay 2315 turns ON.
Note 4: CTH0 and the frequency counter function cannot be used while the cam
switch function is being used.
Note 5: The cam switch function cannot be used when CTH0 is used in the ladder
program.
Note 6: Special utility relays concerning CHT0, CTC0/1, and the frequency counter
function cannot be used.
Note 7: The scan time is extended by a maximum of 16 ms when the cam switch
function is activated.
Note 8: The in-operation relay of the cam switch function (2715) remains ON even
when the mode is changed or the power is turned OFF.
Note 9: Use the END instruction to change relays or turn them ON/OFF.
Note 10: When the encoder is ON in cam switch mode while the KV is OFF, the
14
count may be shifted for the time between the start-up and phase Z input.
Note 11: The encoder count is stopped in cam switch mode while the Visual KV is
OFF. (While the Visual KV is ON, the count is continued even in PROGRAM mode.)
Note 12: When a value of 360° or more is specified as the preset angle for the cam
switch function, the value is converted into one within the range of 0 to 360° before
the control.
Example: When 500° is specified, it is converted to 140°.

Chapter 4 High-speed Counters 3-235

KVNKA Chap 04_2.p65 235 08.3.11, 0:08 PM


4.5 Special Functions Using High-speed Counters

4.5.6 Application of the Cam Switch (Cam Switch Mode)


The following ladder program illustrates the basic setting of the cam switch function.
Connect the encoder with a resolution of 360 pulses.
Use output relays 0600 through 0603.
Output relay 0600: Turns ON within the range 30° to 90°
Visual KV

Output relay 0601: Turns ON within the range 45° to 80°


Series

Output relay 0602: Turns ON within the range 70° to 150°


Output relay 0603: Turns ON within the range 120° to 270°
2008 #00600 DM1400 #00720 DM1402
0001 LDA STA LDA STA 1)

#00300 #00900 #00450 #00800 #00700 #01500 #01200 #02700


0002 DW DW DW DW DW DW DW DW 2)
DM1406 DM1407 DM1408 DM1409 DM1410 DM1411 DM1412 DM1413
2002 HSP
0003 0004 3)

HSP
0004 0006 4)

HSP
0005 0008 5)

0000 1000 1000 2314


0006 DIFU SET 6)

0001 1001 1001 2715


0007 DIFU RES 7)

END
0008

ENDH
0009

4 1) Sets "0600", which is the initial number of relays used for the cam switch function, to
DM1400 and sets twice the number of pulses for one encoder rotation (360 x 2 = 720) to
DM1402.
2) Specifies the preset angles at which output relays 0600 through 0603 turn ON/OFF.
3) Sets the input time constant for input relay 0004 to 10 µs.
4) Sets the input time constant for input relay 0006 to 10 µs.
5) Sets the input time constant for input relay 0008 to 10 µs.
6) The cam switch operation starts when input relay 0000 turns ON.
7) The cam switch operation stops when input relay 0001 turns ON.
3600
(360°)
30° DM1406
45° DM1408
70° DM1410
80° DM1409
270° 90° DM1407
DM1413

120° DM1412

150° DM1412

Timing Diagram
DM1406 DM1407
ON
1st relay 0600 OFF
DM1408 DM1409
2nd relay 0601 ON
OFF
DM1410 DM1411
3rd relay 0602 ON
OFF
DM1412 DM1413
4th relay 0603 ON
OFF

0 90 180 270 360


Rotation (°)

3-236 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 236 08.3.11, 0:08 PM


4.6 Direct Clock Pulse Output

4.6 Direct Clock Pulse Output Visual KV Series Only

This section describes the outline and setting method for direct clock pulse output.

Visual KV
4.6.1 Outline of Direct Clock Pulse Output

Series
Using the high-speed counter (CTH) and high-speed counter comparator (CTC), the
KV PLC can output clock pulses directly through output relays 0500 and/or 0501
without any delays caused by the scan time.

The period (frequency) and width of the pulses are determined by the period of the
internal clock used for the high-speed counter (CTH) and high-speed counter com-
parator (CTC).

The period of the clock pulse (frequency) can be changed with the program within
the following ranges.

Output Internal clock Range of pulse period (Frequency)


2100 (1.0 µs) 20 µs (50 kHz) to 65.5 ms (15 Hz)
0500 2101 (10.0 µs) 20 µs (50 kHz) to 655.3 ms (1.5 Hz)
2102 (100.0 µs) 200 µs (5 kHz) to 6553.5 ms (0.15 Hz)
2200 (1.0 µs) 20 µs (50 kHz) to 65.5 ms (15 Hz)
0501 2201 (10.0 µs) 20 µs (50 kHz) to 655.3 ms (1.5 Hz)
2202 (100.0 µs) 200 µs (5 kHz) to 6553.5 ms (0.15 Hz)

Pulses of the internal clock are counted with the high-speed counter (CTH). When
the number of current pulses reaches the preset value of the high-speed counter
comparator (CTC), the ON/OFF status of output relays 0500 and/or 0501 is toggled 14
to output direct clock pulses.

Count value

CTC

ON ON

Note 1: The operation of output relays 0500 and 0501 are determined by setting the
special utility relays.
Note 2: For more about setting special utility relays, refer to "4.2 Outline of High-
speed Counters" on page 3-206.
Note 3: The ON/OFF status when the direct clock pulse output is started is the
same as when the last direct clock pulse output is stopped. (Initial status: OFF)
Note 4: Output relays 0500 and 0501 cannot be used in a normal program during
direct clock pulse output.

Chapter 4 High-speed Counters 3-237

KVNKA Chap 04_2.p65 237 08.3.11, 0:08 PM


4.6 Direct Clock Pulse Output

4.6.2 Pulse Output Setting with the High-speed Counter


Comparator
Changing the pulse period and width
Visual KV

By using two high-speed counter comparators, you can change only the pulse width
Series

while keeping the pulse period constant, or change only the pulse period while
keeping the pulse width constant.
The following examples illustrate how the pulse width and period can be selected
with the high-speed counter comparator.

■ ON-OFF ratio of 1:1

ON/OFF status is set by special utility relays.

ON

OFF
Pulse width

Pulse period

Pulse width (µs) = CTC0 preset value x internal clock (µs)


Pulse period (µs) = CTC0 preset value x 2 x internal clock (µs)

Use the following calculation to obtain the pulse period from the frequency:

Pulse period (µs) = 1,000,000/Frequency (Hz)

Example: To output 10-kHz pulses


4 Pulse period = 1,000,000 ÷ 10,000 = 100 µs
Preset value for CTC0 = 10 ÷ 2 ÷ 1 = 50

■ Variable pulse width


The period and width of the pulse can be changed by changing the preset values of
CTC0 and CTC1.
ON/OFF status is set by special utility relays.

ON

OFF Pulse
width

Pulse period

Pulse width (µs) = CTC1 preset value x internal clock (µs)


Pulse period (µs) = CTC0 preset value x internal clock (µs)

• Change CTC1 preset value to change the pulse width.


• Change CTC0 preset value to change the pulse period.

Note: The pulse width determined above is the pulse width produced inside the
Visual KV PLC. In reality, the output pulse width may vary depending on the re-
sponse delay of the output circuit and the load connected to this circuit. Be sure to
determine the pulse width after monitoring the actual output waveform with an
oscilloscope. (Monitor the pulses of variable pulse width.)

3-238 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 238 08.3.11, 0:08 PM


4.6 Direct Clock Pulse Output

Calculating the pulse period and comparator preset value


The Visual KV PLC can output a maximum clock pulse of 50 kHz.
Use the following calculations to obtain the pulse period and preset value of the
high-speed counter comparator used to output the clock pulse.

Visual KV
■ Pulse period

Series
Pulse period (µs) = 1,000,000 ÷ Frequency (Hz)

■ CTC preset value for pulses with 1:1 ON/OFF ratio (using one comparator)
CTC preset value = Pulse period (µs) ÷ Internal clock (µs) ÷ 2
ON

OFF Pulse
width

Pulse period

■ CTC preset value for pulses with variable pulse width


CTC preset value for pulse width = Pulse width (µs) ÷ Internal clock (µs)
CTC preset value for pulse period = Pulse period (µs) ÷ Internal clock (µs)
ON

OFF Pulse
width

Pulse period

■ Range of CTC preset value with the internal clock

Special utility relay (internal clock) Period Range of CTC preset value
14
2100 2200 1.0 µs 10 to 65535
2101 2201 10.0 µs 1 to 65535
2102 2202 100.0 µs 1 to 65535

Note 1: Set the CTC preset value to 10 or more when the operands for the high-
speed counter (CTH) is 2100 and 2200. The clock pulse output may be improper
when the preset value is set to less than 10.
Note 2: The pulse width may vary depending on the load connected to the circuit.
Be sure to determine the pulse width after monitoring actual output waveform with
an oscilloscope.
Note 3: When CTC0 and CTC1, or CTC2 and CTC3, are used to output the clock
pulse, do not specify the same value for the preset values of CTC0 and CTC1, or of
CTC2 and CTC3.

Operation with special utility relays


■ Operation with special utility relays for high-speed counter CTH0
The following table shows the ON/OFF status of output relay 0500 which can be
changed by setting special utility relays (2103 through 2112) at the start of opera-
tion, or by changing them during clock pulse output.
You can set desired values for the pulse period and pulse width, and can enable or
disable the direct output.
Operation of output relay 0500 when special utility relays are ON/OFF

Chapter 4 High-speed Counters 3-239

KVNKA Chap 04_2.p65 239 08.3.11, 0:08 PM


4.6 Direct Clock Pulse Output

High-speed Special
Operation when CTH0 (current value)
counter utility
reaches CTC (preset value)
comparator relay
Automatically clears current value of
2103 ON: Yes OFF: No
CTH0
Visual KV

ON: OFF:
Series

2104 Disables/enables control of 0500.


Disable Enable

CTC0 2105 Turns OFF direct output through 0500. ON: Yes OFF: No

2106 Turns ON direct output through 0500. ON: Yes OFF: No

2107 Reverses ON/OFF status of 0500. ON: Yes OFF: No

ON: OFF:
2108 Disables/enables control of 0500.
Disable Enable

2109 Turns OFF direct output through 0500. ON: Yes OFF: No

CTC1 211 Turns ON direct output through 0500. ON: Yes OFF: No

2111 Reverses ON/OFF status of 0500. ON: Yes OFF: No

Automatically clears current value of


2112 ON: Yes OFF: No
CTH0

Setting the special utility relay


The special utility relay must be set to output the clock pulse. Set the relays in the
following manner.
• Only one relay for each group can be turned ON from relays 2104 through 2107
4 and 2108 through 2111.
• Use the SET-RES pair or STA instruction to turn relays 2103 through 2112 ON/
OFF.
• Turning OFF relays 2104 or 2108 enables control of output relay 0500.
• To change the pulse width, be sure to first turn ON relays 2103 or 2112 to auto-
matically clear the current value of CTH0. You cannot change the pulse period
unless you turn ON relays 2103 or 2112.
• Turning ON/OFF relay 2105 stops/outputs the clock pulse.

Note: If two or more relays of special utility relays 2104 through 2107 or 2108
through 2111 are turned ON, priority is given to the relay with the smaller number.

Operation of output 0500 by setting special utility relays


Outputting a pulse with 1:1 ON/OFF ratio Outputting a pulse with variable pulse width
Special utility relay settings Special utility relay settings
2103 ON 2108 OFF 2103 ON 2108 OFF
2104 OFF 2109 OFF 2104 OFF 2109 ON
2105 OFF 2110 OFF 2105 OFF 2110 OFF
2106 OFF 2111 OFF 2106 ON 2111 OFF
2107 ON 2112 OFF 2107 OFF 2112 OFF

Count value Count value

CTC0 CTC0
CTC1

ON ON ON ON ON ON

3-240 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 240 08.3.11, 0:08 PM


4.6 Direct Clock Pulse Output

■ Operation with special utility relays for high-speed counter CTH1


The following table shows the ON/OFF status of output relay 0501 which can be
changed by setting special utility relays (2203 through 2212) at the start of opera-
tion, or by changing them during clock pulse output.
You can set desired values for the pulse period and pulse width, and can enable or

Visual KV
disable the direct output.

Series
Operation of output relay 0501 when special utility relays are ON/OFF
High-speed Special Operation when CTH0 (current value)
counter
comparator utility relay reaches CTC (preset value)
Automatically clears current value
2203 of CTH1 ON: Yes OFF: No

2204 Disables/enables control of 0501. ON: OFF:


Disable Enable
CTC2 2205 Turns OFF direct output through ON: Yes OFF: No
0501.
2206 Turns ON direct output through ON: Yes OFF: No
0501.
2207 Reverses ON/OFF status of 0501. ON: Yes OFF: No
ON: OFF:
2208 Disables/enables control of 0501. Disable Enable
Turns OFF direct output through
2209 0501. ON: Yes OFF: No
CTC3 Turns ON direct output through
2210 0501. ON: Yes OFF: No
2211 Reverses ON/OFF status of 0501. ON: Yes OFF: No
2212 Automatically clears current value ON: Yes OFF: No
of CTH1

Setting the special utility relay


The special utility relay must be set to output the clock pulse. Set the relays in the
following manner. 14
• Only one relay for each group can be turned ON from relays 2204 through 2207
and 2208 through 2211.
• Use the SET-RES pair or STA instruction to turn relays 2203 through 2212 ON/
OFF.
• Turning OFF relays 2204 or 2208 enables control of output relay 0501.
• To change the pulse width, be sure to first turn ON relays 2203 or 2212 to auto-
matically clear the current value of CTH1. You cannot change the pulse period
unless you turn ON relays 2203 or 2212.
• Turning ON/OFF relay 2205 stops/outputs the clock pulse.

Note: If two or more relays of special utility relays 2204 through 2207 or 2208
through 2211 are turned ON, priority is given to the relay with the smaller number.

Operation of output 0501 by setting special utility relays


Outputting a pulse with 1:1 ON/OFF ratio Outputting a pulse with variable pulse width

Special utility relay settings Special utility relay settings


2203 ON 2208 ON 2203 ON 2208 OFF
2204 OFF 2209 OFF 2204 OFF 2209 ON
2205 OFF 2210 OFF 2205 OFF 2210 OFF
2206 OFF 2211 OFF 2206 ON 2211 OFF
2207 ON 2212 OFF 2207 OFF 2212 OFF

Count value Count value

CTC2 CTC2
CTC3

ON ON ON ON ON ON

Chapter 4 High-speed Counters 3-241

KVNKA Chap 04_2.p65 241 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

4.7 Examples of Direct Clock Pulse Output


This section describes programming examples of the direct clock pulse output.

4.7.1 Example of Outputting a Pulse with 1:1 ON/OFF Ratio


Visual KV
Series

To output a clock pulse of 1 ms (1 kHz)-period from output relay 0500


This section describes a programming example that will output a clock pulse with 1:1
ON/OFF ratio from output relay 0500 by using the high-speed counter (CTH0) and
high-speed counter comparator (CTC0).

■ Special utility relay setting


Set the special utility relay (2103 through 2112) according to the following table.
When outputting a pulse with 1:1 ON/OFF ratio, you can simplify the program by
using the reverse (toggle) output (2107: ON).

Relay No. Setting


2103 ON
2104 OFF
2105 OFF
2106 OFF
2107 ON

■ Internal clock and CTC0 preset value


Specify the internal clock and calculate the preset value of CTC0 for the clock.

CTC0 preset value = Pulse period (µs) ÷ Internal clock (µs) ÷ 2


4 Obtain the preset value of CTC0 by substituting 1 ms for the pulse period and 10 µs
for the internal clock (special utility relay 2101).
In this case, the preset value of CTC0 is "50".
Refer to the following table for the preset value of CTC0 with other internal clocks.

Special utility relay Internal clock CTC0 preset value


2100 1.0 µs 500
2101 10.0 µs 50
2102 100.0 µs 5

■ Example
Count value
2008 2103 2104 2105 2106 2107 CTH0
0001 SET RES RES RES SET RES
CTC0
2002 CTH0
0002 2101
#00050
0003 CTC0 ON ON

• Sets the pulse output from output relay 0500 with special utility relays 2104 through 2107.
In this example, turns OFF 2104 to enable direct output from 0500 and turns ON 2107 to
reverse the output each time the CTH0 value reaches the CTC0 value.
• Turns ON 2103 to set CTH0 to be cleared when its value reaches the CTC0 value.
• With this setting, the operation which clears the CTH0 current value when it reaches the
CTC0 preset value is repeated.
• The RES CTH0 instruction resets the CTH0 current value when operation starts. This
ensures that the first clock pulse is output at the proper pulse width.
Turn ON the input enable relay for CTH0 all the time when CTH0 is used to output the
clock pulse.

3-242 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 242 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

Cording
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0008 CON
0001 SET 2103 0009 SET 2107
0002 CON 0010 CON

Visual KV
0003 RES 2104 0011 RES CTH0

Series
0004 CON 0012 LD 2002
0005 RES 2105 0013 CTH 0 2101
0006 CON 0014 CTC 0 #00050
0007 RES 2106

Note :When the input enable relay for the high-speed counter is used to start/stop
the clock pulse, the response is delayed by a maximum of one scan when output
starts. Moreover, if the response is delayed by one scan when output stops, the
clock pulse stops but the output may remain ON.

■ Tips
• Use special utility relay 2105 to control (enable/disable) the clock pulse output by
external inputs.
• Use the SET-RES pair or KEEP instruction to turn special utility relay 2105 ON/
OFF.
• With this setting, the clock pulse is always turned OFF when it starts as well as
stops.
• When either of the following programs is added to the example on the previous
page, the clock pulse is output from 0500 only when 0000 is ON.

When SET-RES instructions are used When KEEP instruction is used

0000 2105 0000 KEEP


SET SET
2105 14
0000 2105 0000
RES RES

To output a clock pulse of 1 ms (1 kHz)-period from output relay 0501


This section describes a programming example that will output a clock pulse with 1:1
ON/OFF ratio from output relay 0501 by using the high-speed counter (CTH1) and
high-speed counter comparator (CTC2).

■ Special utility relay setting


Set the special utility relay (2203 through 2212) according to the following table.
When outputting a pulse with 1:1 ON/OFF ratio, you can simplify the program by
using the reverse (toggle) output (2207: ON).
Relay No. Setting
2203 ON
2204 OFF
2205 OFF
2206 OFF
2207 ON

■ Internal clock and CTC2 preset value


Specify the internal clock and calculate the preset value of CTC2 for the clock.
CTC2 preset value = Pulse period (µs) ÷ Internal clock (µs) ÷ 2
Obtain the preset value of CTC2 by substituting 1 ms for the pulse period and 10 µs
for the internal clock (special utility relay 2201).
In this case, the preset value of CTC2 is "50".
Refer to the following table for the CTC2 preset value with other internal clocks.

Chapter 4 High-speed Counters 3-243

KVNKA Chap 04_2.p65 243 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

Special utility relay Internal clock CTC2 preset value


2200 1.0 µs 500
2201 10.0 µs 50
2202 100.0 µs 5
Visual KV

■ Example
Series

Count value
2008 2203 2204 2205 2206 2207 CTH1
0001 SET RES RES RES SET RES
CTC2
2002 CTH1
0002 2201
#00050
0003 CTC2 ON ON

• Sets the pulse output from output relay 0501 with special utility relays 2204 through 2207.
In this example, turns OFF 2204 to enable direct output from 0501 and turns ON 2207 to
reverse the output each time the CTH1 value reaches the CTC2 value.
• Turns ON 2203 to set CTH1 to be cleared when its value reaches the CTC2 value.
With this setting, the operation which clears the CTH1 current value when it reaches the
CTC2 preset value is repeated.
• The RES CTH1 instruction resets the CTH1 current value when operation starts. This
ensures that the first clock pulse is output at the proper pulse width.
Turn ON the input enable relay for CTH1 all the time when CTH1 is used to output the
clock pulse.

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0008 CON
0001 SET 2203 0009 SET 2207
0002 CON 0010 CON
0003 RES 2204 0011 RES CTH1
4 0004 CON 0012 LD 2002
0005 RES 2205 0013 CTH 1 2201
0006 CON 0014 CTC 2 #00050
0007 RES 2206

Note :When the input enable relay for the high-speed counter is used to start/stop
the clock pulse, the response is delayed by a maximum of one scan when output
starts. Moreover, if the response is delayed by one scan when output stops, the
clock pulse stops but the output may remain ON.

■ Tips
• Use special utility relay 2205 to control (enable/disable) the clock pulse output by
external inputs.
• Use the SET-RES pair or KEEP instruction to turn special utility relay 2205 ON/
OFF.
• With this setting, the clock pulse is always turned OFF when it starts as well as
stops.
• When either of the following programs is added to the example on the previous
page, the clock pulse is output from 0501 only when 0000 is ON.

When SET-RES instructions are used When KEEP instruction is used

0000 2205 0000 KEEP


SET SET
2205
0000 2205 0000
RES RES

3-244 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 244 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

4.7.2 Example of Outputting a Pulse with Variable ON/OFF


Ratio
To output a clock pulse of 500 µ s (2 kHz)-period and 200 µ s-width from output relay 0500

Visual KV
This section describes a programming example that will output a clock pulse with

Series
variable ON/OFF ratio from output relay 0500 by using the high-speed counter
(CTH0) and high-speed counter comparator (CTC0 and CTC1).

■ Special utility relay setting


Set the special utility relay (2103 through 2112) according to the following table.

Relay No. Setting Relay No. Setting


2103 ON 2108 OFF
2104 OFF 2109 ON
2105 OFF 2110 OFF
2106 ON 2111 OFF
2107 OFF 2112 OFF

■ Internal clock and CTC0/CTC1 preset values


Specify the internal clock and calculate the preset values of CTC0 and CTC1 for the
clock.

CTC1 preset value = Pulse width (µs) ÷ Internal clock (µs)


CTC0 preset value = Pulse period (µs) ÷ Internal clock (µs)

Obtain the preset values of CTC0 and CTC1 by substituting 200 µs for the pulse
width, 500 µs for the pulse period, and 10 µs for the internal clock (special utility
relay 2101).
In this case, the preset value of CTC1 is "20", and that of CTC0 is "50". 14
Refer to the following table for the CTC preset values with other internal clocks.

Special utility relay Internal clock CTC0 preset value CTC1 preset value
2100 1.0 µs 500 200
2101 10.0 µs 50 20
2102 100.0µs 5 2

■ Example
Count value
2008 2103 2104 2105 2106 2107
0001 SET RES RES SET RES

2108 2109 2110 2111 CTH0 CTC0


0002 RES SET RES RES RES CTC1
2002 CTH0
0003 2101
ON ON ON ON
#00050
0004 CTC0

#00020
0005 CTC1

• Sets the pulse output from output relay 0500 with special utility relays 2104 through 2107
and 2108 through 2111.
In this example, turns OFF 2104 to enable direct output from 0500. Turns ON 2106 to turn
ON the output from 0500 when the CTH0 value reaches the CTC0 value, and turns ON
2109 to turn OFF the output when the CTH0 value reaches the CTC1 value.
• Turns ON 2103 to set CTH0 to be cleared when its value reaches the CTC0 value. This
ensures that the first clock pulse is output at the proper pulse width.
• Turn ON the input enable relay for CTH0 all the time when CTH0 is used to output the
clock pulse.

Chapter 4 High-speed Counters 3-245

KVNKA Chap 04_2.p65 245 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0013 CON
0001 MPS 0014 SET 2109
0002 SET 2103 0015 CON
Visual KV
Series

0003 CON 0016 RES 2110


0004 RES 2104 0017 CON
0005 CON 0018 RES 2111
0006 RES 2105 0019 CON
0007 CON 0020 RES CTH0
0008 RES 2106 0021 LD 2002
0009 CON 0022 CTH 0 2101
0010 RES 2107 0023 CTC 0 #00050
0011 MPP 0024 CTC 1 #00020
0012 RES 2108

Note 1: When the input enable relay for the high-speed counter is used to start/stop
the clock pulse, the response is delayed by a maximum of one scan when output
starts. The response is also delayed by a maximum of one scan when output stops.
Note 2: Refer to the following "Tips" to start and stop the clock pulse.

■ Tips
• Use special utility relay 2105 to control (enable/disable) the clock pulse output by
external inputs.
• Use the SET-RES pair or KEEP instruction to turn special utility relay 2105 ON/
OFF.
With this setting, the clock pulse is always turned OFF when it starts as well as
stops.
4 • When either of the following program is added to the example on the previous
page, the clock pulse is output from 0500 only when 0000 is ON.

When SET-RES instructions are used When KEEP instruction is used

0000 2105 0000 KEEP


SET SET
2105
0000 2105 0000
RES RES

• You can change the period (frequency) of the clock pulse by changing the CTC0
preset value using the LDA and STA instructions.
To change the period of the clock pulse, refer to "4.3.4 Count Input Method" (p.3-
212).

3-246 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 246 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

To output a clock pulse of 500 µ s (2 kHz)-period and 200 µ s-width from output relay 0501
This section describes a programming example that will output a clock pulse with
variable ON/OFF ratio from output relay 0501 by using the high-speed counter
(CTH1) and high-speed counter comparator (CTC2 and CTC3).

Visual KV
■ Special utility relay setting

Series
Set the special utility relay (2203 through 2212) according to the following table.

Relay No. Setting Relay No. Setting


2203 ON 2208 ON
2204 OFF 2209 OFF
2205 OFF 2210 OFF
2206 ON 2211 OFF
2207 OFF 2212 OFF

■ Internal clock and CTC2/CTC3 preset values


Specify the internal clock and calculate the preset values of CTC2 and CTC3 for the
clock.

CTC2 preset value = Pulse width (µs) ÷ Internal clock (µs)


CTC3 preset value = Pulse period (µs) ÷ Internal clock (µs)

Obtain the preset values of CTC2 and CTC3 by substituting 200 µs for the pulse
width, 500 µs for the pulse period, and 10 µs for the internal clock (special utility
relay 2201).
In this case, the preset value of CTC3 is "20", and that of CTC2 is "50".
Refer to the following table for the CTC preset values with other internal clocks.

Special utility relay Internal clock CTC2 preset value CTC3 preset value 14
2200 1.0 µs 500 200
2201 10.0 µs 50 20
2202 100.0 µs 5 2

■ Example
Count value
2008 2203 2204 2206 2207
0001 SET RES SET RES

2208 2209 2210 2211 CTH1 CTC2


0002 RES SET RES RES RES
CTC3
2002 CTH1
0003 2201
ON ON ON ON
#00050
0004 CTC2

#00020
0005 CTC3

• Sets the pulse output from output relay 0501 with special utility relays 2204 through 2207
and 2208 through 2211.
In this example, turns OFF 2204 to enable direct output from 0501. Turns ON 2206 to turn
ON the output from 0501 when the CTH1 value reaches the CTC2 value and turns ON
2209 to turn OFF the output when the CTH1 value reaches the CTC3 value.
• Turns ON 2203 to set CTH1 to be cleared when its value reaches the CTC2 value. This
ensures that the first clock pulse is output at the proper pulse width.
• Turn ON the input enable relay for CTH1 all the time when CTH1 is used to output the
clock pulse.

Chapter 4 High-speed Counters 3-247

KVNKA Chap 04_2.p65 247 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0012 SET 2209
0001 MPS 0013 CON
0002 SET 2203 0014 RES 2210
Visual KV

0003 CON 0015 CON


Series

0004 RES 2204 0016 RES 2211


0005 CON 0017 CON
0006 SET 2205 0018 RES CTH1
0007 CON 0019 LD 2002
0008 RES 2207 0020 CTH 1 2201
0009 MPP 0021 CTC 2 #00050
0010 RES 2208 0022 CTC 3 #00020
0011 CON

Note :When the input enable relay for the high-speed counter is used to start/stop
the clock pulse, the response is delayed by a maximum of one scan when output
starts. The response is also delayed by a maximum of one scan when the output
stops.

■ Tips
• Use special utility relay 2205 to control (enable/disable) the clock pulse output by
external inputs.
• Use the SET-RES pair or KEEP instruction to turn special utility relay 2205 ON/
OFF.
With this setting, the clock pulse is always turned OFF when it starts as well as
stops.
• When either of the following programs is added to the example on the previous
page, the clock pulse is output from 0501 only when 0000 is ON.
4
When SET-RES instructions are used When KEEP instruction is used

0000 2205 0000 KEEP


SET SET
2205
0000 2205 0000
RES RES

• You can change the period (frequency) of the clock pulse by changing CTC2
preset value using LDA and STA instructions.
To change the period of the clock pulse, refer to "4.3.4 Count Input Method" on
page 3-212.

3-248 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 248 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

4.7.3 Example of Stopping the Pulse Output at a Specified


Pulse Count
This section describes a programming example that will output a clock pulse of 500
µs (2 kHz)-period and 200 µs-width from output relay 0500 and then stop it after

Visual KV
10000 pulses are output.

Series
■ Special utility relay, internal clock, and CTC settings
Set the special utility relay according to the following table.
Relay No. Setting Relay No. Setting
2103 ON 2108 OFF
2104 OFF 2109 ON
2105 OFF 2110 OFF
2106 ON 2111 OFF
2107 OFF 2112 OFF

Specify the internal clock and CTC0/CTC1 preset values according to the following
table.
Special utility relay Internal clock CTC0 preset value CTC1 preset value
2100 1.0 µs 500 200
2101 10.0 µs 50 20
2102 100.0 µs 5 2

■ Example
2008 2103 2104 2105 2106 2107
0001 EI SET RES SET SET RES

2108 2109 2110 2111 CTH0


0002 RES SET RES RES RES

2203 #00000 2813 CTH1


0003 SET DW SET RES

0000
DM1940
1000 1000 2105
14
0004 DIFU RES

2002 CTH0
0005 2101
#00050
0006 CTC0

#00020
0007 CTC1

2002 CTH1
0008 0500
#10000
0009 CTC2

END
0010

INT
0011 CTC2
2002 2105
0012 SET

RETI
0013

ENDH
0014

• Sets the pulse output from output relay 0500 with special utility relays 2104 through 2107
and 2108 through 2111.
In this example, turns OFF 2104 to enable direct output from 0500. Turns ON 2106 to turn
ON the output from 0500 when the CTH0 value reaches the CTC0 value and turns ON
2109 to turn OFF the output when the CTH0 value reaches the CTC1 value.
• Turns ON 2103 to set CTH0 to be cleared when its value reaches the CTC0 value. This
ensures that the first clock pulse is output at the proper pulse width.
• Uses an EI instruction to enable interrupts.
The interrupt program (INT CTC2) stops the clock pulse when the CTH1 current value
reaches the CTC2 preset value (when 10000 pulses are output).
• Turns ON 2203 to set CTH1 to be cleared when its value reaches the CTC2 value. This
forces the operation to repeat by the specified pulses (10000).
• Relay 2813 must be turned ON when counting pulses with CTH1.

Chapter 4 High-speed Counters 3-249

KVNKA Chap 04_2.p65 249 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

• The input enable relay for CTH0 must be ON all the time when CTH0 is used to output the
clock pulse.
• The input enable relay for CTH1 must be ON all the time when CTH1 is used to count the
clock pulse.
• Specifies the internal clock (2101) as the clock input for CTH0. Specifies 0500 as the
clock input for CTH1. With this setting, CTH0 is used to output the clock pulse, and CTH1
Visual KV

is used to count the clock pulse.


Series

• Specifies the number of clock pulses to the CTC2 preset value.


• The clock pulse output starts when input 0000 is turned ON.
To restart the clock pulse output after it stops, turn ON input 0000 again.

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0024 SET 2203
0001 EI 0025 CON
0002 CON 0026 DW #00000 DM1940
0003 MPS 0027 CON
0004 SET 2103 0028 SET 2813
0005 CON 0029 CON
0006 RES 2104 0030 RES CTH1
0007 CON 0031 LD 0000
0008 SET 2105 0032 DIFU 1000
0009 CON 0033 CON
0010 SET 2106 0034 AND 1000
0011 CON 0035 RES 2105
0012 RES 2107 0036 LD 2002
0013 MRD 0037 CTH 0 2101
0014 RES 2108 0038 CTC 0 #00050
0015 CON 0039 CTC 1 #00020
0016 SET 2109 0040 LD 2002
0017 CON 0041 CTH 1 0500
0018 RES 2110 0042 CTC 2 #10000
4 0019 CON 0043 END
0020 RES 2111 0044 INT CTC2
0021 CON 0045 LD 2002
0022 RES CTH0 0046 SET 2105
0023 MPP 0047 RET1
0048 ENDH

■ Tips
Special utility relays 2103 through 2111 can be turned ON/OFF by using the LDA
and STA instructions instead of the SET-RES instructions.
The example program below can be changed as follows by using the LDA and STA
instructions. The number of lines and steps can be reduced.
2008 2103 2104 2105 2106 2107 2008 $0268 2100 CTH0 2203 2813 CTH1
EI SET RES SET SET RES EI LDA STA RES SET SET RES

2108 2109 2110 2111 CTH0


RES SET RES RES RES

2203 2813 CTH1


SET SET RES

• LDA $0268
When LDA $0268 is executed, the value specified by the operand is written into
the internal register as follows.
[0] [2] [6] [8]
Internal register
0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0

When STA 2100 is executed, the value in the internal register is assigned to
special utility relays 2100 through 2115.
xx 15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
Special utility
relay 21xx 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0

3-250 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 250 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

4.7.4 Application of Direct Clock Pulse Output


(Ramp-up/down control)
The following ramp-up/down control is available by setting four parameters (DM0000
to DM0003)

Visual KV
y

Series
nc
tpu e

sto erge
ou vers
t
rt

Em
Re
Sta

p
24 VDC

+
Stepping motor driver

Twisted-pair cable
+
– CW (Pulse)
COM 0001 0003
0000 0002
+
KV – CCW (Rotation
0500 0502 direction)
COM 0501 0503

5 VDC
– + FG Stepping motor

■ Setting parameters
Specify values in the range from 153 Hz to
DM0000: fH [Hz] (Running frequency)
➞ 50000 Hz. The fH value must be greater
DM0001: fL [Hz] (Start-up frequency) than the fL value.
DM0002: Acceleration rate [Hz/10 ms] ➞ (fH - fL) / (Acceleration time / 10 ms)
DM0003: No. of pulses for positioning ➞ Must be 65534 pulses or less.

Note 1: A smaller acceleration rate allows smoother control but extends the accel- 14
eration time.
Note 2: Be sure to turn OFF input 0007 (phase B input).

■ Operation
In the example on the next page, each parameter is set as follows:
DM0000: 8000 [Hz]
DM0001: 700 [Hz]
DM0002: 400 [Hz/10 ms]
DM0003: 4000 pulses
When start switch 0000 is pressed, ramp-up/down control is performed as shown
below. Control is stopped when the pulse count reaches "4000".
Pressing the start switch restarts the operation. The operation is reversed while
reverse switch 0001 is ON.

■ Connection example
The above diagram shows a connection example between the KV PLC and a
stepping motor driver.
Refer to the instruction manual for your stepping motor driver for details.
Set the pulse input method of the stepping motor driver to "1-pulse input method".
Frequency (Hz)

H
(DM0000) Total pulses
Acceleration for positioning
rate (DM0003)
(DM0002)

L 10ms
(DM0001) (Acceleration
change period)
0 Time (ms)
Acceleration Constant Deceleration
time speed time time

Chapter 4 High-speed Counters 3-251

KVNKA Chap 04_2.p65 251 08.3.11, 0:08 PM


4.7 Examples of Direct Clock Pulse Output

■ Example
Specifies high-speed
0001 counters and comparators
2002 #00010 #65535 CTH0
0002 CTC1 CTC0 2100
• CTC0 generates a clock pulse.
#65535 #65535 CTH1
0003 CTC2 CTC3 0500 • CTH1 counts the number of
Visual KV

2008 #08000 #00700 #00400 #04000 2813 2105 clock pulses.


Series

0004 DW DW DW DW SET SET


DM0000 DM0001 DM0002 DM0003
CTC0:Pulse period
CTC1: Pulse width
0005 Starts positioning CTC2:Frequency change point
CTC3:Total No. of pulses for positioning
0003 0000 1001 1001
0006 DIFU
• Sets parameters (DM0000 to
0007 DM0003).
$0268 2100 01 1200 CTH1 CTH0 2105
0008 LDA STA CALL SET RES RES EI RES

0001 0502
0009 • Sets reverse output.

0010 Emergency stop


0003 2105
0011 SET • Sets emergency stop.
END
0012

0013
Calculation routine for
CTC0, CTC2, and DM0011
SBN
0014
• Specifies the CTC0 preset value.
02
CTC0 preset value =
2002 #01000 #10000 DM0012 #00005 #00010 CTC0 DM0010 1 ÷ DM0012 x 103 x 103
0015 LDA MUL DIV ADD DIV STA STA

#00010 #10000 DM0010 #00005 #00010 DM0011 CTC2 DM0011


0016 LDA MUL DIV ADD DIV ADD STA STA • Specifies the CTC2 preset
value.
RET
0017 DM0010: Pulse period T (µs)
DM0011: No. of accumulated pulses
0018 Initialization routine DM0012: Current frequency (Hz)
1200: Acceleration flag
SBN
0019 01
2002 DM0003 CTC3 #00002 DM0004 DM0001 DM0012 #00000 02
0020 LDA STA DIV STA LDA STA DW CALL
DM0011
4 0021
RET

0022 Triangle drive check routine


SBN
0023 03
2002 DM0012 #00100 DM0011 DM0004
0024 LDA DIV ADD CMP

RET
0025

Interrupt routine for


0026
acceleration/deceleration
INT
0027 CTC2

0028 Acceleration process


1200 DM0012 DM0002 DM0012 DM0000 2011 03 2011 02 • Acceleration ratio is added to the
0029 LDA ADD STA CMP CALL CALL
current frequency to change it each
2011 1201 time CTC2 turns ON while
0030
acceleration flag 1200 is ON.
2011 DM0003 DM0011 CTC2 DM0011 Acceleration stops when the
0031 LDA SUB STA STA
current frequency reaches fH. Sets
1201 1200 No. of pulses for the deceleration
0032 RES point.

0033 Deceleration process


1200 DM0012 DM0002 DM0012 DM0001 2011 02
0034 LDA SUB STA CMP CALL • Acceleration ratio is subtracted
from the current frequency to
2011 02 #65535 CTC2
0035 CALL LDA STA change it each time CTC2 turns
ON while acceleration flag 1200 is
RETI
0036 ON. Deceleration stops when the
current frequency reaches fL. The
0037 Interrupt for pulse stop setting is initialized.

INT
0038 • Clock pulse output is stopped when
CTC3
the No. of pulses equals the CTC3
2002 2105 preset value.
0039 SET

RETI
0040

ENDH
0041

3-252 Chapter 4 High-speed Counters

KVNKA Chap 04_2.p65 252 08.3.11, 0:08 PM


Visual KV
Series
Chapter 5
Positioning Control Visual KV Series Only

This chapter describes ramp-up/down control of stepping motors and servo motors.

➮ For KV-10/80 Series, see Chapter 6.


5.1 Outline of Positioning Control ..................................................... 3-254
5.1.1 Ramp-up/down Control .......................................................................... 3-254
5.2 Parameter Setting and Operating Procedures ......................... 3-255
5.2.1 Parameter Setting Procedure ................................................................. 3-255
5.2.2 Operating Procedure .............................................................................. 3-257
5.3 Examples of Using the Positioning Control Function ........... 3-258
5.3.1 Connection Example .............................................................................. 3-258
5.3.2 Tips ........................................................................................................ 3-258
5.3.3 Application Examples of the Positioning Control Function ..................... 3-259

KVNKA Chap 05.p65 253 08.3.11, 0:09 PM


5.1 Outline of Positioning Control

5.1 Outline of Positioning Control


This section describes the outline of positioning control.

5.1.1 Ramp-up/down Control


Visual KV
Series

The Visual KV Series can directly output clock pulses not affected by the scan time
to output relay 0502.
If the frequency, the number of output pulses, and the acceleration time of the clock
pulses have been preliminarily set to data memories, the Visual KV Series automati-
cally performs ramp-up/down control.
The ramp-up/down control output function offers ramp-up/down timing charts of the
startup frequency, operating frequency, acceleration time, and deceleration time as
shown below.
The output frequency can be set within the range of 200 to 50,000 Hz.

Number of output DM1485 and DM1484


Frequency (Hz) pulses (pulses) Upper digit Lower digit

Operating
frequency
DM1481

Startup
frequency
DM1480

Time (ms)
5 Acceleration
time DM1482
Deceleration
time DM1482

By using the ramp-up/down control output function, ramp-up/down control of step-


ping motors and AC servo motors (pulse input types) is possible.

Clock pulse

Rotation direction
Lo: CW
0502 Hi: CCW

Stepping motor
NEW KV 0503 Servo motor

Motor driver

3-254 Chapter 5 Positioning Control

KVNKA Chap 05.p65 254 08.3.11, 0:09 PM


5.2 Parameter Setting and Operating Procedures

5.2 Parameter Setting and Operating


Procedures
This section describes the parameter setting and operating procedures for position-

Visual KV
Series
ing control.

5.2.1 Parameter Setting Procedure


Preliminarily set each parameter for positioning control to a corresponding data
memory. To operate, special utility relays must be set.
➮ For more about special utility relays, refer to "5.2.2 Operating Procedure" (p. 3-257).
The table below shows the relationship between parameters and data memories.

Data memories for ramp-up/down control


Data memory Setting contents Setting range
Ramp-up/down control startup
DM1480 200 to 50,000
frequency (Hz)
Ramp-up/down control operating 200 to 50,000
DM1481
frequency (Hz) (value larger than startup frequency)
Ramp-up/down control
DM1482 acceleration/deceleration time 0 to 4000
(ms)
Number of output pulses 0 to 65,535
DM1484
(lower 16 bits) (2 or more when DM1485 is 0)
Number of output pulses
DM1485 0 to 65,535
(upper 16 bits)
When an error occurs, a correspond-
DM1486 Set value error code
ing error code 11 to 17 is stored.

Note: When pulse output is started, the scan time is extended by 10 ms maximum
(if the acceleration/deceleration time is set to 4 s). 15
Set value error code (DM1486)
If there is an error in the preset parameters when starting operation, a corresponding
error code (11 to 17) is automatically written to DM1486.

Code Description Countermeasures


11 Startup frequency value is smaller than Set starting frequency within setting
allowable setting range. range (200 to 50,000).
12 Operating frequency value is smaller Set operating frequency within setting
than allowable setting range. range (200 to 50,000).
13 Operating (or startup) frequency value is Set operating (or startup) frequency
larger than allowable setting range. within setting range (200 to 50,000).
14 Startup frequency value is larger than Set them appropriately so that startup
operating frequency value. frequency is smaller than operating
frequency.
15 Acceleration/deceleration time is larger Set acceleration/deceleration time within
than allowable setting range. setting range (0 to 4,000).
16 System error Contact our sales office.
17 Number of pulses output within Set number of output pulses to 2 or
acceleration/deceleration time is too more.
small.

Startup frequency (Hz) (DM1480)


Set the frequency (speed) of the motor at startup in positioning control so that motor
rotations start up smoothly.
At the set frequency, the Visual KV Series will output clock pulses.

Chapter 5 Positioning Control 3-255

KVNKA Chap 05.p65 255 08.3.11, 0:09 PM


5.2 Parameter Setting and Operating Procedures

Operating frequency (Hz) (DM1481)


Set the frequency (speed) of the motor during operation in positioning control.
At the set frequency, the Visual KV Series will output clock pulses.

Note: If the startup frequency is the same as the operating frequency, the timing
Visual KV

chart becomes as shown below.


Series

Operating (startup)
frequency

In this case, the acceleration/deceleration time is ignored.

Acceleration/deceleration time (ms) (DM1482)


Set the time to accelerate from the starting frequency to the operating frequency
after operation is started.
When operation is stopped, the deceleration time is equivalent to the acceleration
time.
In the set time, the Visual KV Series varies the clock pulse frequency from the
startup frequency to the operating frequency (in the case of acceleration time).
The clock pulse frequency change cycle within the acceleration time is fixed to 5 ms.

Operating frequency

Startup frequency 5ms

Acceleration/deceleration time
5
Number of output pulses (DM1484 and DM1485)
Set the angle of rotation (movement quantity) in positioning control as the number of
pulses. The Visual KV Series outputs as many clock pulses as the set value.
If the number of output pulses is larger than 65,535, divide it into the upper 16-bit
value and the lower 16-bit value using the following equation.
The minimum value is 2, and maximum value is 4,294,967,295.

(Number of output pulses) ÷ 65,536 = A (answer) . . . B (remainder)


A = Number of output pulses (upper 16-bit) ➞ DM1485
B = Number of output pulses (upper 16-bit) ➞ DM1484

Note 1: When the set number of pulses is too small and the target value cannot be
achieved, triangular control is performed as shown below.

Operating frequency

Startup frequency
0

Note 2: The current value of pulse output cannot be obtained.

3-256 Chapter 5 Positioning Control

KVNKA Chap 05.p65 256 08.3.11, 0:09 PM


5.2 Parameter Setting and Operating Procedures

5.2.2 Operating Procedure


In positioning control, operation is started up, stopped normally, and stopped in
emergencies by the ON/OFF status of special utility relays.
The table below shows the relationship between operations and the special utility
relays used.

Visual KV
Series
Special utility
R/W* Function Description
relay No.
Performs deceleration at rising edge, then stops
2308 W Stop
operation.
Remains ON while pulses are output.
R Run
2309 Stops operation immediately when being reset in an
W RESET
interrupt program.
2310 W Start Starts up operation at rising edge.
* R: Read W: Write
■ Operation chart

DM1481 DM1480: Startup frequency (Hz)


DM1481: Operating frequency (Hz)
DM1480 DM1482: Acceleration time (ms)
DM1485 DM1485: Number of output pulses (upper 16 bits)
DM1484 DM1484: Number of output pulses (lower 16 bits)
0
DM1482 DM1482

When relay 2310 turns ON, clock pulses are


2310
output (detection at rising edge).
(START)
While clock pulses are output, relay 2309
2309 remains ON. While clock pulses are not
(RUN) output, relay 2309 remains OFF.
2308 When relay 2308 turns ON, clock pulses are
(STOP) decelerated and stopped (detection at rising
edge). 15
Note 1: If there is no error in the parameter setting when special utility relay 2310
turns ON at startup of the clock pulses, special utility relay 2309 turns ON and clock
pulses are output.
Note 2: If there is an error in the parameter setting, special utility relay 2309 does
not turn ON but a corresponding error code is written to DM1486.
Confirm the error code, and change the erroneously set parameter.
Note 3: By setting special utility relay 2309 to OFF in an interrupt program, clock
pulses can be immediately stopped.
Note 4: Rising of special utility relay 2310, falling of special utility relay 2309, and
rising of special utility relay 2308 are performed by end processing and RETI.
(Special utility relay 2309 turns ON at that time.)
Note 5: It takes a maximum of 10 ms from when special utility relay 2310 turns ON
until pulses are output.
Note 6: Even if special utility relay 2310 is set to ON while special utility relay 2308
or 2309 is ON, it is ignored.
Note 7: When pulse output has finished, special utility relay 2309 is immediately set
to OFF (without regard to the scan time).

Chapter 5 Positioning Control 3-257

KVNKA Chap 05.p65 257 08.3.11, 0:09 PM


5.3 Examples of Using the Positioning Control Function

5.3 Examples of Using the Positioning


Control Function
This section describes examples of connecting a stepping motor driver and perform-
Visual KV
Series

ing ramp-up/down control using the positioning control function of the Visual KV
Series.

5.3.1 Connection Example


Connect the Visual KV Series and stepping motor driver as shown below.
This example is only for reference. For details, refer to the instruction manual for the
stepping motor driver.
Set the pulse input type of the stepping motor driver to "1 pulse input type".
top
ys
enc
erg

p
rt
Sto
Em

Sta

24 VDC

+ Stepping motor driver

Twisted pair cable


+
– CW (pulse)
COM 0001
0000 0002
+
Visual KV – CCW
R0502 (rotation
COM R0503 direction)

5 5 VDC*
– + FG Stepping motor

• When using a 24 VDC power supply, be sure to use the outputs with current limiting
resistors (R500, R501, and R502) or use the normal outputs with external current limiting
resistors.

5.3.2 Tips
When using a servo motor, also refer to the connection example above. However,
I/O control dedicated to a servo motor such as servo ON is also required.

3-258 Chapter 5 Positioning Control

KVNKA Chap 05.p65 258 08.3.11, 0:09 PM


5.3 Examples of Using the Positioning Control Function

5.3.3 Application Examples of the Positioning Control


Function
Ladder example of ramp-up/down control

Visual KV
When start switch 0000 is set to ON, output 0502 starts to output 100,000 pulses

Series
with a startup frequency of 500 Hz, operating frequency of 10 kHz, and acceleration/
deceleration time of 3 seconds.
When input 0001 is set to ON, pulse output is decelerated and stopped.
When input 0002 is set to ON, pulse output is immediately stopped.

Speed (Hz)

1000

500

0 100000 Coordinate (pulses)

■ Program example
2008 Permit interrupts when operation is
0001 EI started (so that emergency stop
operations are available).
2002 HSP
0002 0002 Set the input time constant of input
0002 to 10 µs.
0000 #00500 #10000 #03000 #00001 #34464 2310
0003 DW DW DW DW DW Set each parameter, and start pulse
DM1480 DM1481 DM1482 DM1485 DM1484 output at the same time.
0001 2308
0004 Decelerate and stop pulse output.

END
0005

INT
15
0006 0002 Perform emergency stop processing
by using an interrupt program.
2002 2309
0007 RES

RETI
0008

ENDH
0009

Chapter 5 Positioning Control 3-259

KVNKA Chap 05.p65 259 08.3.11, 0:09 PM


5.3 Examples of Using the Positioning Control Function

Ladder example of the jog operation


The jog operation is performed.

Speed (Hz)
CW direction CCW direction
Visual KV

1000
Series

500

Coordinate (pulses)

Input 0000
(CW direction)

Input 0001
(CCW direction)

• While input 0000 is ON, the machine continues to move in the CW direction.
When input 0000 turns OFF, the machine decelerates and stops.
• While input 0001 is ON, the machine continues to move in the CCW direction.
When input 0001 turns OFF, the machine decelerates and stops.

■ Program example

0000 0001 2309 0503 1000


0001 SET DIFU

0001 0000 2309 0503 1001


5 0002 RES DIFU

1000 #00500 #02000 #01000 #65535 #65535 2310


0003 DW DW DW DW DW
DM1480 DM1481 DM1482 DM1485 DM1484
1001
0004

0000 0001 1100 1100 2308


0005 DIFU

END
0006

ENDH
0007

3-260 Chapter 5 Positioning Control

KVNKA Chap 05.p65 260 08.3.11, 0:09 PM


5.3 Examples of Using the Positioning Control Function

Ladder example of automatic operation (palletizing operation)


A palletizing operation is automatically performed.
The machine moves to a target coordinate, then returns to the start position. Next,
the machine moves to a position further away than the target coordinate, then again
returns to the start position. Such an operation is realized using repetitious and

Visual KV
return movements. This type of operation is suitable for, for example, a job where

Series
workpieces to be supplied are located in one position and a moving body picks up
the workpieces and positions them little by little at a certain interval.

Speed (Hz)

5000

500 Point 3: 14,000

0 Coordinate (pulses)
Point 1: 10,000
500 Point 2: 12,000

5000

When start signal 0000 is set to ON, a moving body moves to point 1, returns to the
start position, moves to point 2, and then returns to the start position again. After-
wards, the moving body moves to point 3, then returns to the start position, output
05000 remains ON for 3 seconds, and then the operation is finished.

■ Program example

0001 Ladder for automatic operation

0002 Point 1: 10,000 Point 2: 12,000 Point 3: 14,000

0000 #00500 #05000 #03000 #00000 1000


0003 DW DW DW DW SET
DM1480 DM1481 DM1482 DM1485

0004 Moves to point 1.

1000 0503 #10000 2310 2309 1200 1001


15
0005 STG SET DW JMP
DM1484 1200

0006 Returns from point 1.

1001 2309 1100 0503 2310 2309 1201 1002


0007 STG RES JMP
1100 1201

0008 Moves to point 2.

1002 2309 1101 0503 #12000 2310 2309 1202 1003


0009 STG SET DW JMP
1101 DM1484 1202

0010 Returns from point 2

1003 2309 1102 0503 2310 2309 1203 1004


0011 STG RES JMP
1102 1203

0012 Moves to point 3.

1004 2309 1103 0503 #14000 2310 2309 1204 1005


0013 STG SET DW JMP
1103 DM1484 1204

0014 Returns from point 3.

1005 2309 1104 0503 2310 1006


0015 STG RES JMP
1104

0016 When operation has completed, output 500 remains ON for 3 seconds.

1006 2309 1105 0500 #00030 T000


0017 STG T000 ENDS
1105
END
0018

ENDH
0019

Chapter 5 Positioning Control 3-261

KVNKA Chap 05.p65 261 08.3.11, 0:09 PM


5.3 Examples of Using the Positioning Control Function

Ladder example of a return to the zero point


A return to the zero point is performed.

Range detected by
zero point sensor
Visual KV
Series

Low speed Start


Forced stop

Deceleration
and stop High-speed

When start signal 0000 turns ON, the machine moves at a high speed in the CCW
direction. When the zero point sensor turns ON, the machine decelerates, moves at
a low speed in the CW direction, then stops in the position at which the zero point
sensor turns OFF (at the end of the CW direction).

■ Program example

0001 Return to zero point

0002
Zero point sensor: 0003 Start signal: 0000 Pulse output: 0502
Rotation direction: 0503

0003 Initial setting

2008
0004 EI

2002 HSP
0005 0003

0006 Moves at high speed in the CCW direction.


0000 1000 1000 2309 #00500 #10000 #00500 #00000 #65535 1005
0007 DIFU DW DW DW DW DW SET
DM1480 DM1481 DM1482 DM1485 DM1484
5 0008
2413
RES
0503
RES

0009 When the zero point sensor turns ON, moves at low speed in the CW direction.

1006 2309 2308 #00200 #10200 #00500 #00000 #65535 2413 0503
0010 RES DW DW DW DW DW SET SET
DM1480 DM1481 DM1482 DM1485 DM1484
1005 2309 1007 1007 2310
0011 DIFU

1006
0012

END
0013

Detects the rising/falling edge of the zero point sensor (003), stops, and
0014
then changes direction.
INT
0015 0003

1006 2309 1006


0016 RES RES

1005 2308 1006 1005


0017 SET SET RES

RETI
0018

ENDH
0019

3-262 Chapter 5 Positioning Control

KVNKA Chap 05.p65 262 08.3.11, 0:09 PM


5.3 Examples of Using the Positioning Control Function

Ladder example of an automatic operation (continuous operation with wait status)


In automatic operation, wait status is realized at each point.

Speed (Hz)
10000

Visual KV
7000

Series
5000
500
0 250000 320000 460000 Coordinate
(pulses)
Wait Wait

When start signal 0000 turns ON, the machine moves to point 1 and stops there. At
the rising edge of wait status reset switch 1, the machine automatically moves to
point 2 and stops there. At the rising edge of waiting status reset switch 1, the
machine automatically moves to point 3. When the machine reaches point 3, output
0500 remains ON for 3 seconds and the operation is finished.

■ Program example

0001 Ladder for automatic operation (continuous operation with wait status)

0002 Start signal: 0000 Pulse output: 0508 Rotation direction: 0503

0003 Wait reset switch: 0001

0000 #00500 1000


0004 DW SET
DM1480
Moves to point 1 at speed of 10 kHz. Acceleration/deceleration time: 1 second
0005
Moving quantity: 250,000 pulses
1000 0503 #01000 #01000 #00003 #53392 2310 2309 1300 1001
0006 STG SET DW DW DW DW JMP
DM1481 DM1482 DM1485 DM1484 1300

0007
Moves to point 2 at speed of 5 kHz. Acceleration/deceleration time: 1 second
Moving quantity: 70,000 pulses
1001 2309 1400 0001 1301
0008 STG
1400 1301 15
0009

0503 #05000 #01000 #00001 #04464 2310 2309 1302 1002


0010 SET DW DW DW DW JMP
DM1481 DM1482 DM1485 DM1484 1302

0011
Moves to point 3 at speed of 7 kHz. Acceleration/deceleration time: 1 second

1002 2309 1401 0001 1303


0012 STG
1401 1303

0013

0503 #07000 #01000 #00002 #08928 2310 2309 1304 1003


0014 SET DW DW DW DW JMP
DM1481 DM1482 DM1485 DM1484 1304

0015 Moving quantity: 140,000 pulses


When operation has completed, output 500 remains ON for 3 seconds.
1003 2309 1305 0500 #00030 T000
0016 STG T000 ENDS
1305
END
0017

ENDH
0018

Chapter 5 Positioning Control 3-263

KVNKA Chap 05.p65 263 08.3.11, 0:09 PM


5.3 Examples of Using the Positioning Control Function

Ladder example of a pulse motor application circuit


This is a program example which offers control using both automatic and manual
operations.
In automatic operation, when input 000 is set to ON, the following operation is
performed.
Visual KV
Series

Speed (Hz)
8000
2000
300
0 15000 17500 Coordinate
(pulses)

15000

In manual operation, the machine moves forward while input 0008 is ON, and moves
backward while input 0009 is ON. When input 0007 is set to ON, the machine
returns to the zero point.
Output 0502 outputs pulses. The rotation direction is changed by an ON/OFF of
0503.
This machine is equipped with a zero-point sensor (0002), a forward limit switch
(0006), and a backward limit switch (0004).

■ Program example

0001 Pulse motor application circuit (with zero point sensor, forward
limit switch, and backward limit switch)
0002 Specifications

Pulse output: 0502 Rotation direction: 0503


0003
5 Forward limit switch: 0006 Backward limit switch: 0004

0004 Manual switch: Forward = 0008, backward = 0009 Zero point switch:

0005 0007

0006

0007 Automatic operation start: 0000

2008 1200
0008 RES EI

2002 HSP
0009 0000

HSP
0010 0002

Resets interrupt permission & zero point detection flag.


0011 Manual switch (0008: Forward, 0009: Backward) Set the startup frequency,
0008 0009 2309 0503 0006 1100 operating frequency, and
0012 RES DIFU acceleration/deceleration
0008 0009 2309 0503 0004 1101 time for manual operation.
0013 SET DIFU
• Startup frequency: 600 Hz
1100 #00600 #04000 #00100 #00001 #00000 1103 • Operating frequency: 4 kHz
0014 DW DW DW DW DW DIFU • Acceleration/
DM1480 DM1481 DM1482 DM1485 DM1484
deceleration: 100 ms
1101
0015 • Number of output pulses:
65,536
0008 0009 1105
0016 DIFU

3-264 Chapter 5 Positioning Control

KVNKA Chap 05.p65 264 08.3.11, 0:09 PM


5.3 Examples of Using the Positioning Control Function

Return to zero point


In a zero-point-return
0015
operation, the machine
moves forward once, and
0016 Limit switch
then backward. When the
0007 1205 zero point limit switch
0017 DIFU
(0002) turns ON, the
machine stops.

Visual KV
0018 Move forward.
Settings for forward

Series
1205 0503 #00300 #03000 #00250 #00000 #03500 1300 1200 movement
0019 SET DW DW DW DW DW DIFU SET
DM1480 DM1481 DM1482 DM1485 DM1484 • Startup frequency: 300 Hz
• Operating frequency: 3 kHz
0020 Trigger end of forward movement • Acceleration time: 250 ms
• Number of output pulses:
1200 2309 1201 2309 1202 1203
0021 ON OFF DIFU 3,500
1201 1202 Settings for backward
0022 While moving backward at low speed, return to zero point. movement
• Drive frequency: 500 Hz
1203 0503 #00500 #00500 #00000 #00000 #65535 1301 1200 • Operating frequency: 500 Hz
0023 RES DW DW DW DW DW DIFU RES
DM1480 DM1481 DM1482 DM1485 DM1484 • Acceleration time: 0 ms
• Number of output pulses:
0024 Start up motor. 65,535
1300 0006 2310
0025 Give instructions to start up
and decelerate/stop the
1301 0004
0026 motor.
1103
0027

1506 2308
0028

0029 Decelerate and stop (in manual/automatic operation).

0006 0009 2308


0030

0004 0008
0031

1105
0032

0033 Automatic operation

0034 Trigger for stage instruction

0035
2008 1400
SET 15
2308 1408 1408 1401 1402 1403 1400
0036 DIFU RES RES RES SET

0037 Automatic start (while 0000 is ON)

1400 0000 2308 2309 1401


0038 STG JMP Create each operation
program using the STG
0039 When motor operation has finished, moves stage forward. instruction, and let each
program be executed in
1401 1407 #00010 T001 1500 2309 1405 1402
0040 STG RES T001 DIFU JMP turn.
1405
1402 1405 #00005 T002 1501 2309 1406 1403
0041 STG RES T002 DIFU JMP
1406
1403 1406 #00005 T003 1502 2309 1407 1400
0042 STG RES T003 DIFU JMP
1407

Chapter 5 Positioning Control 3-265

KVNKA Chap 05.p65 265 08.3.11, 0:09 PM


5.3 Examples of Using the Positioning Control Function

Set parameters for auto-


0043 Set automatic operation parameters.
matic operation.
1500 0503 #00300 #08000 #00150 #00000 #15000 1503 1. Startup frequency: 300 Hz
0044 SET DW DW DW DW DW DIFU Operating frequency: 8 kHz
DM1480 DM1481 DM1482 DM1485 DM1484
1501 0503 #00300 #02000 #00250 #00000 #02500 1504
Acceleration time: 150 ms
0045 SET DW DW DW DW DW DIFU Number of output pulses:
DM1480 DM1481 DM1482 DM1485 DM1484 15,000
1502 0503 #00300 #15000 #00250 #00000 #17500 1505 2. Startup frequency: 300 Hz
Visual KV

0046 RES DW DW DW DW DW DIFU


DM1480 DM1481 DM1482 DM1485 DM1484 Operating frequency: 2 kHz
Series

Acceleration time: 250 ms


0047 Start up motor.
Number of output pulses:
1503 1506 25000
0048 3. Startup frequency: 300 Hz
Operating frequency: 15 kHz
1504
0049 Acceleration time: 250 ms
Number of output pulses:
1505 17,500
0050

END
0051

0052 Interrupt for instantaneous stop (to return to zero point)


Stop pulse output at the
INT zero point by using an
0053 0002
interrupt program.
1200 0008 0009 0000 2309
0054 RES

RETI
0055

ENDH
0056

3-266 Chapter 5 Positioning Control

KVNKA Chap 05.p65 266 08.3.11, 0:09 PM


KV-300
KV-10/80
Chapter 6
Interrupts, High-speed Counters,
Positioning Control KV-300, KV-10/80 Series Only
This chapter describes ramp-up/down control of stepping motors and servo motors.

6.1 Interrupt Instructions .............................................................. 3-268


6.1.1 Description of Interrupts ......................................................................... 3-268
6.1.2 Interrupt Instructions .............................................................................. 3-271
6.2 Direct Clock Pulse ................................................................... 3-276
6.2.1 Output of Direct Clock Pulse .................................................................. 3-276
6.3 Positioning Control ................................................................. 3-296
6.3.1 Positioning Control (Ramp-up/down Control) ......................................... 3-296

KVNKA Chap 06.p65 267 08.3.11, 0:10 PM


6.1 Interrupt Instructions

6.1 Interrupt Instructions


6.1.1 Description of Interrupts
Input processing for routine program and interrupt routine

Input processing
KV-300
KV-10/80

t
rup Processing of
inter
direct inputs
Scan time

of
ion
rat (00000 to 00005)
ne
Ge
Routine program Interrupt routine
execution Re execution
tu
at rns
the to
po sus Processing of
int pe
of nd direct outputs
su ed
sp pr (00500 to 00503)
en og
sio ram
n.
Output processing

Fig. 1

Routine program flow is shown by the thick arrow on the left of Fig.1. In this case,
input signals can be received only during input processing.
Although input time constant can be made shorter by using HSP or by turning ON
special utility relay 2813, input signals can be received only if they are longer than
the duration of one scan time.
When an interrupt initiation input turns ON, the currently running program is sus-
pended to immediately execute the interrupt routine.
6 During execution of interrupt routine, input signals shorter than one scan time can be
received by the PLC.

Note: To execute INT (interrupt initiation instruction), execute EI first to enable


interrupt, then use HSP (time constant: 25 µs) or turn ON special utility relay 2813
(time constant: 10 µs) to reduce the input time constant.
2008 2813 2002
EI SET or EI

2002 HSP
0000

Types of interrupt
High speed counter comparators

CTC0, CTC1, CTC2, CTC3

Input relays

0000, 0001, 0002, 0003


(rising/falling edge selectable)

Interrupt by CTC can be generated when the CTC preset value and CTH current
value are equal.

A signal received through any of inputs 0000 to 0003 can generate an interrupt.

3-268 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 268 08.3.11, 0:10 PM


6.1 Interrupt Instructions

Interrupt priority
If two or more interrupts are generated at different timings, interrupt routines are
executed in the order that interrupts are generated.
If two or more interrupts are generated simultaneously, interrupt routines are
executed according to the priority shown below.
CTC0 > CTC1 > CTC2 > CTC3 > 0000 > 0001 > 0002 > 0003

* Note that the above priority differs from that for other KV PLCs (KV-10/16/24/40/
80).
The priority is: 0000 > 0001 > 0002 > 0003 > CTC2 > CTC3 > CTC0 > CTC1.

KV-300
KV-10/80
Note 1: During execution of one interrupt routine, execution of other interrupt rou-
tines is inhibited. (One interrupt routine can be executed inside another interrupt
routine by inserting EI.)
Note 2: If other interrupts are generated during execution of one interrupt routine,
the routines of these interrupts are executed after completion of the first interrupt
routine in the order that they are generated. Note that generation of up to 8 levels of
interrupt nesting or up to 8 individual interrupts can be stored during execution of
interrupt routine. However, generation of an interrupt is ignored if generation of the
same interrupt has already been stored.

Interrupt routine
2008 2813
EI SET

END

INT
XXXXX

RETI

ENDH

16
• Execute EI to enable interrupt.
• Be sure to insert INT between END and ENDH.
• Be sure to shorten the input time constant by using HSP or by turning ON special
utility relay 2813.

Instructions that cannot be used in the INT-RETI block


TMR, TMH, TMS, DIFU, DIFD, W-ON, W-OFF, W-UE, W-DE, STG, JMP, ENDS,
HKEY, ITVL, @xxxx (instruction), C, UDC, SFT

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-269

KVNKA Chap 06.p65 269 08.3.11, 0:10 PM


6.1 Interrupt Instructions

Direct output
2008 2813
EI SET

END

INT
0000
2002 0500
( SET )

RETI
KV-300

INT
KV-10/80

0001
2002 0500
( SET )

ENDH

Direct output is enabled only through output relays 0500, 0501, 0502, and 0503.
This function allows ON/OFF status of any of output relays 0500, 0501, 0502, and
0503 to be output during execution of interrupt routine.
This function allows immediate ON/OFF status output without delay caused by scan
time.

Note: Be sure to turn ON special utility relay 2813 to shorten the input time constant.

Direct input
2008 2813
SET
1000 0500

END

6 INT
0000
0005 1000

RETI

ENDH

Direct input is enabled only through input relays 0000 to 0005.


This function allows ON/OFF status of any of input relays 0000 to 0005 to be input
during execution of interrupt routine.

Note 1: Be sure to turn ON special utility relay 2813 to shorten the input time
constant.
Note 2: Input status read using direct input function is valid only in the interrupt
routine. Be sure to insert an internal utility relay after the direct input relay.

3-270 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 270 08.3.11, 0:10 PM


DI / EI
6.1 Interrupt Instructions

6.1.2 Interrupt Instructions

DI: Interrupt Disabled FNC RES AND


0 8 : DI Disables execution of interrupt.

EI: Interrupt Enabled FNC SET


1
ORL
3 : EI Enables execution of interrupt.

Key operations

FNC RES AND


0 8 ENT ENT
SET ORL R-SRCH R-SRCH

KV-300
FNC

KV-10/80
1 3

Operand

Example
1000
EI

1000
DI

Coding
Line No. Instruction Operand
0000 LD 1000
0001 EI
: :
0021 LDB 1000
0022 DI
: :

Description 16
When 1000 is ON, execution of interrupt is enabled. When 1000 is OFF, execution
of interrupt is disabled. Interrupts are enabled between EI instruction and DI instruc-
tion.
Therefore, once EI is executed, interrupt is enabled until it is disabled by DI.

With the KV, any interrupt is disabled when the operation is started.
DI instruction disables execution of interrupt. Use this instruction to temporarily
disable interrupt.
EI instruction enables the execution of interrupt. Use this instruction to release
interrupt disabled by DI instruction.
During execution of an interrupt, any other interrupt is disabled.To execute another
interrupt during execution of the previous interrupt, include EI instruction in this first
interrupt. Interrupts can be nested up to 8 levels by executing EI in each interrupt
routine.

Note 1: Generation of up to 8 levels of interrupt nesting or up to 8 individual inter-


rupts can be stored while interrupt is disabled. These interrupts are executed after EI
has been executed.
Note 2: Generation of INT CTC is erased from the storage when RES CTC is
executed.

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-271

KVNKA Chap 06.p65 271 08.3.11, 0:10 PM


INT / RETI
6.1 Interrupt Instructions

INT Executes interrupt between INT and RETI


INT: Interrupt FNC ANL
2
RES
0 : nnnn
instructions at rising edge of input specified
by operand. When 0003 is specified by
operand, the rising or falling edge can be
RETI selected for execution of interrupts.
RETI: Return Interrupt FNC ORL LDB
:
3 4
Represents termination of interrupts.

Key Operations
FNC ANL RES ENT Operand ENT
2 0 R-SRCH R-SRCH
KV-300

FNC ORL LDB ENT ENT


KV-10/80

3 4 R-SRCH R-SRCH

Operand
0000 to 0003
CTC0 to CTC3

Example 1
Input pulse width shorter than one scan time (eg. one-shot circuit)
(a) 0000 #00020
Input for T000
routine
program 0500 T000 0500
0000

(Input remains ON for 1 ms or more.)

(b) 2008
2813
Input for
interrupt EI SET
routine 1000 #00020
0000 T000
0500 T000 0500

END
6
INT
0000
2002 1000

RETI

ENDH

(Input remains ON for 10 µs or more.)

Program (a) can be used when input 0000 remains ON longer than the input time constant (8
to 12 ms).
Program (b) is used when input 0000 remains ON shorter than one scan time.

Routine program coding


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

3-272 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 272 08.3.11, 0:10 PM


INT / RETI
6.1 Interrupt Instructions

Interrupt routine coding


Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0008 OUT 0500
0001 EI 0009 END
0002 CON 0010 INT 0000
0003 SET 2813 0011 LD 2002
0004 LD 1000 0012 OUT 1000
0005 OR 0500 0013 RETI
0006 TMR 000 #00020 0014 ENDH
0007 ANB T000

Example 2

KV-300
KV-10/80
Features of INT0003
Upon generation of interrupt by INT0003, the CTH1 current value is automatically
transferred to TM30.
Interrupt generated by any of INT0000 to INT0002 is executed at the rising edge of
the input signal. Interrupt generated by INT0003 can be executed either at the rising
or falling edge of the input signal.
Relay No. ON OFF
2206 Executes interrupts at falling edge of Executes interrupts at rising edge of
input pulse to 0003. input pulse to 0003.

In the example program below, pulse width of input 0003 is measured.


2206(OFF) 2206(ON) 2008 $0000 2200 DM0000
ON 1 EI LDA STA STA
0003
OFF Pulse width 2002 CTH1
2 2200

END

INT
3 0003

2206 TM30
LDA
TM02
STA
KEEP
SET (a)
16
2206
4 2206 TM30 TM02 DM0000
LDA SUB STA RES (b)

RETI

ENDH

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0014 CON
0001 EI 0015 STA TM02
0002 CON 0016 CON
0003 LDA $0000 0017 LD 2206
0004 CON 0018 LDA TM30
0005 STA 2200 0019 CON
0006 CON 0020 SUB TM02
0007 STA DM0000 0021 CON
0008 LD 2002 0022 STA DM0000
0009 CTH 1 2200 0023 CON
0010 END 0024 KEEP 2206
0011 INT 0003 0025 RETI
0012 LDB 2206 0026 ENDH
0013 LDA TM30

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-273

KVNKA Chap 06.p65 273 08.3.11, 0:10 PM


INT / RETI
6.1 Interrupt Instructions

■ Initial setting
• When the operation is started, EI instruction enables interrupts.
• Special utility relays No. 2200 through 2215 are turned OFF. Turning OFF 2203
disables CTC2 from resetting the CTH1 current value to 0.
• Turning OFF 2206 allows interrupt to be generated at the rising edge of INT0003.
• The value of DM0000 is reset to "0".
• Turning ON special utility relay 2813 changes the input time constant to 10 µs.
• 1.0-µs internal clock pulses are counted using CTH1.
• INT instruction with 0003 as the operand allows interrupts to be executed.
KV-300
KV-10/80

• When interrupt is generated for the first time, 2206 is OFF. Therefore, program in
rung (a) is executed. Then, KEEP turns 2206 ON.
• When interrupt is generated for the second time, 2206 is ON. Therefore, program
in rung (b) is executed to calculate the following:
(TM30 at 2nd execution) - (TM30 at 1st execution) = pulse width (unit: 1.0 µs)
The result is stored in DM0000.
Example 3
Interrupt by CTC
Pulses input to 0005 are counted. 0501 is turned ON when the number of pulses
reaches 5,000.
2008 2203 CTH1 #05000 2813
1 EI SET RES CTC2 SET

2002 CTH1
2 0005

0000 0501
3 RES

END

6 INT
CTC2
4

2002 0501
5 SET

RETI

ENDH

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0010 LD 2002
0001 EI 0011 CTH 1 0005
0002 CON 0012 LD 0000
0003 SET 2203 0013 RES 0501
0004 CON 0014 END
0005 RES CTH1 0015 INT CTC2
0006 CON 0016 LD 2002
0007 CTC 2 #05000 0017 SET 0501
0008 CON 0018 RETI
0009 SET 2813 0019 ENDH

3-274 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 274 08.3.11, 0:10 PM


INT / RETI
6.1 Interrupt Instructions

■ Initial setting
• When the operation is started, EI instruction enables interrupts.
• Turning ON special utility relay 2203 allows CTC2 to reset the CTH1 current
value to 0.
• The CTH1 current value is reset to 0.
• The CTC2 preset value is set to 5000.
• Turning ON special utility relay 2813 changes the input time constant to 10 µs.
• Pulses input to 0005 are counted using CTH1.
• When input 0000 turns ON, output 0501 is reset.

KV-300
KV-10/80
• INT CTC2 is used to execute the interrupt. (Interrupt routine is executed when
the CTH1 current value and CTC2 preset value are equal.)
• Immediate output to 0501 is performed.

Note 1: When the interrupt is executed, the contact of CTC2 is automatically reset.
Note 2: The operand used for INT instruction is not allowed for use with other INT
instructions.

16

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-275

KVNKA Chap 06.p65 275 08.3.11, 0:10 PM


6.2 High-speed Counters

6.2 Direct Clock Pulse


6.2.1 Output of Direct Clock Pulse
Outline of High-Speed Counters
Basic Architecture
The KV-300 CPU has two 16-bit (CTH0, CTH1) double-phase counter, each
equipped with two high-speed counter comparators (CTC0, 1, 2, 3). These counters
can be used as a stepping motor controller or are used to measure pulse width.
KV-300
KV-10/80

Block diagram of high-speed counters

0008 (RESET)

16-bit Special utility relay


Internal clocks high-speed counter (2103 to 2115)
2100(1.0 µs) CTH0
2101(10.0 µs)
Control circuit 0500
2102(100.0 µs)
Phase A 0004 External pulse High-speed
Phase B (0006) 0004/0006 counter comparator INT CTC0
CTC0, CTC1 INT CTC1

Internal clocks 16-bit high- Special utility relay


speed counter TM30 (2203 to 2215)
2200(1.0 µs)
2201(10.0 µs) CTH1
2202(100.0 µs) Control circuit 0501
External pulse High-speed
Phase A 0005 0005/0007 counter comparator INT CTC2
Phase B (0007) 0500 CTC2, CTC3 INT CTC3
0009 (RESET)

■ Lists of special utility relays for high-speed counters


Utility relays for high-speed counter CTH0
2100 Internal clock (1.0 µs) for CTH0
2101 Internal clock (10.0 µs) for CTH0
2102 Internal clock (100.0 µs) for CTH0
6 2103 When comparator CTC0 is ON, automatically clears CTH0.
1: Yes 0: No
2104 Direct output to 0500 Direct output level to 0500 through comparator
1: Disable 0: Enable CTC1 (any one of these is ON)
2105 Turns OFF output to 0500.
1: Yes 0: No
2106 Turns ON output to 0500.
1: Yes 0: No
2107 Reverses output (toggle) to 0500.
1: Yes 0: No
2108 Direct output to 0500 Direct output level to 0500 through comparator
1: Disable 0: Enable CTC1 (any one of these is ON)
2109 Turns OFF output to 0500.
1: Yes 0: No
2110 Turns ON output to 0500.
1: Yes 0: No
2111 Reverses output to 0500 (toggle).
1: Yes 0: No
2112 When comparator CTC1 is ON, automatically clears CTH0.
1: Yes 0: No
2113 Uses CTH0 in magnification mode.
1: Yes 0: No
2114 Selection of magnification mode for CTH0
1: x 4 0: x 2
2115 Enables external reset for CTH0.
1: Yes 0: No

3-276 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 276 08.3.11, 0:10 PM


6.2 High-speed Counters

Utility relays for high-speed counter CTH1


2200 Internal clock (1.0 µs) for CTH1
2201 Internal clock (10.0 µs) for CTH1
2202 Internal clock (100.0 µs) for CTH1
2203 When comparator CTC2 is ON, automatically clears CTH1.
1: Yes 0: No
2204 Direct output to 0501 through comparator CTC2
1: Enable 0: Disable
2205 Direct output level to 0501 through comparator CTC2
1: ON 0: OFF
2206 Selection of INT3 edge

KV-300
KV-10/80
0: UP edge 1: DOWN edge
2207 Reverse output (toggle) level
1: ON 0: OFF
2208 Direct output to 0501 Direct output level to 0501 through comparator
1: Disable 0: Enable CTC3 (any one of these is ON)
2209 Turns OFF output to 0501.
1: Yes 0: No
2210 Turns ON output to 0501.
1: Yes 0: No
2211 Reverses output (toggle) to 0501.
1: Yes 0: No
2212 When comparator CTC3 is ON, automatically clears CTH1.
1: Yes 0: No
2213 Uses CTH1 in magnification mode.
1: Yes 0: No
2214 Selection of magnification mode for CTH1
1: x 4 0: x 2
2215 Enables external reset for CTH1.
1: Yes 0: No

For KV-10/80 users


1. KV-10/80 has one 8-bit (CTH0) and one 16-bit (CTH1) single phase counter.
16
2. Internal clocks are as follows:
2100 0.8 µs 2200 0.4 µs
2101 6.4 µs 2201 0.8 µs
2102 102.4 µs 2202 3.2 µs

3. Special utility relays of 2112, 2113, 2114, 2115, 2212, 2213, 2214, and 2215
are not available.

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-277

KVNKA Chap 06.p65 277 08.3.11, 0:10 PM


6.2 High-speed Counters

■ High-speed counter and counter comparators


High-speed counter (CTH1)
CTH1 is a 16-bit hardware counter that counts from 0 to 65535.
• You can specify the operands listed in the table below as the count input.
• You can specify one operand from the table below.
• Operand cannot be modified externally during execution of the program.
• When the external pulse (0004, 0005) is selected, CTH1 is used as a High-speed
counter with a response frequency of 30 kHz.*
• When one of the internal clocks (2100 to 2102, 2200 to 2202) is selected, CTH1
is used as a High-speed timer.
• When the external pulse 0500 is selected as input to CTH1, CTH1 can count
KV-300

direct clock pulses generated by CTH0.


KV-10/80

High-speed counter CTH0 CTH1


Operand 2100 2200
2101 2201
2102 2202
0004 0005
0500
Countable range 0 to 65535
* KV-10/80: 10 kHz

■ High-speed counter comparator (CTC)


High-speed counter comparators (CTC) is used only for High-speed counters (CTH).
When the current value of CTH reaches the preset value of one of the comparators
(CTC), the comparator turns ON.
At the contact of High-speed counter comparator (CTC), the level of output (0500,
0501) can be changed (directly output) through hardware or an interrupt can be
generated. To change the level of output 0500 and 0501, set the desired value (ON/
OFF) to special utility relays 2103 to 2112, 2203 to 2205, and 2207 to 2212.

The High-speed counters correspond to the High-speed counter comparators as


shown in the table below.

6 High-speed
counter
High-speed
counter
Range of
setting value
Output Interrupt

comparator
CTH0 CTC0 0 TO 65535 0500 INT CTC0
CTC1 INT CTC1
CTH1 CTC2 0501 INT CTC2
CTC3 INT CTC3

Internal Clocks for CTH0 and CTH1


• Each High-speed counter (CTH) has its own internal clock.
• The desired clock can be selected by specifying the relay No. as operand for
CTH instruction.
• You cannot change the internal clock or external pulse during execution of the
program.
• Each clock has the following period:

High-speed counter CTH0 CTH1 Period


Relay No. 2100 2200 1.0 µs
2101 2201 10.0 µs
2102 2202 100.0 µs

3-278 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 278 08.3.11, 0:10 PM


6.2 High-speed Counters

• You cannot change operands of the high-speed counters (CTH) during


CAUTION execution of the program. The input time constant of the high-speed
counters is usually set to 25 ms. (The HSP instruction is not required.)

• High-speed pulses can be counted at up to 30 kHz through external inputs


(0004 to 0007) by turning ON special utility relay 2813. (Internal pulses can
be counted at up to 50 kHz by turning ON 2813.)*

* KV-10/80 : 10 kHz

Outline of Pulse Output

KV-300
The KV PLC can output clock pulses through 0500 and/or 0501 without any delays

KV-10/80
caused by scan time. (Through CPU only)
Direct clock pulses, used with the high-speed counters, are applicable for various
types of production control such as for controlling target positions at desired speed.
To perform ramp-up/down control, see "Controlling stepping motors" in Chapter 5.
A setting of the clock pulse cycle (frequency) can be changed by the program within
the allowable range as shown in the table below.

Outline of pulse output

Output Internal clock Range of pulse cycle (frequency)


0500 2100 20 µs (50 kHz) to 65.5 ms (15 Hz)
2101 20 µs (50 kHz) to 655.3 ms (1.5 Hz)
2102 200 µs (5 kHz) to 6553.5 ms (0.1 Hz)
0501 2200 20 µs (50 kHz) to 65.5 ms (15 Hz)
2201 20 µs (50 kHz) to 655.3 ms (1.5 Hz)
2202 200 µs (5 kHz) to 6553.5 ms (0.1 Hz)

Direct clock pulses are output through 0500 and/or 0501 according to the settings on
the special utility relays when the number of internal clock pulses counted by the
high-speed counter reaches the preset value of the comparator.

Output example
16
CTH current value (count value)

CTC preset value

0500 ON
0501

OFF

ON/OFF of output relay 0500/0501 depends on the setting of the special utility
CAUTION relay. ➮ Refer to page 3-281.

For KV-10/80 users

Model Output Range of pulse cycle


KV-10, 16, 24, 40 500 500 ms to 52.2 ms
(2 kHz to 19 Hz)
501 666 ms to 419.4 ms
(1.5 kHz to 2.4 Hz)
KV-80 500 50 ms to 52.2 ms
(20 kHz to 19 Hz)
501 666 ms to 419.4 ms
(1.5 kHz to 2.4 Hz)

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-279

KVNKA Chap 06.p65 279 08.3.11, 0:10 PM


6.2 High-speed Counters

Pulse period and width


Period and width of the pulse is determined by the period of the internal clock (CTH)
used and the preset value of the comparator (CTC).
When two counter comparators are used, only the pulse width can be changed while
a constant period is maintained.
The following examples illustrate how pulse width and period can be selected:

■ ON/OFF ratio of 1:1


Pulse width (ms) = CTC0 preset value x internal clock (ms)
Pulse period (ms) = CTC0 preset value x 2 x internal clock (ms)
KV-300

• ON/OFF ratio of pulse is 1:1.


KV-10/80

• Change CTC0 preset value to change the pulse width and period.

ON/OFF status is set special utility relays


ON
OFF
Pulse
width
Pulse period

■ Variable pulse width


ON/OFF status is set by special utility relays.
Pulse width (ms) = CTC1 preset value x internal clock (ms)
Pulse period (ms) = CTC0 preset value x internal clock (ms)

• Change CTC1 preset value to change the pulse width.


• Change CTC0 preset value to change the pulse period.
ON/ OFF status is set by special utility relays
ON
OFF
Pulse
width

6 Pulse period

The pulse width determined as above is used to pulses generated from the
CAUTION
KV-300 CPU.
Pulses are output through the output circuit. The pulse width varies depend-
ing on the response delay from the output circuit and influence of the con-
nected load. Before setting the pulse width, you should measure the actual
waveform using an oscilloscope. (Use pulses with variable pulse width.)

• To obtain the pulse cycle from frequency, use the following expression:
Pulse cycle (µs) = 1000 ÷ Frequency (kHz)

3-280 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 280 08.3.11, 0:10 PM


6.2 High-speed Counters

Special utility relay settings and output statuses


■ 16-bit high-speed counter (CTH0) and special utility relays (2103 to 2112)
By setting the special utility relays 2104 to 2112 at startup or changing these relays
during generation of clock pulse, you can select ON/OFF of output relay 0500 as
listed below.
These special utility relays also allow you to set the pulse cycle and pulse width
and enable or disable the direct output.
Pulse status at CTH0 (current value) = CTC (preset value)
Comparator No. Relay No. Pulse status at ON.
CTC0 2103 Automatically clears current value of CTH0.

KV-300
2104 Disables output to 0500.

KV-10/80
2105 Outputs OFF to 0500
2106 Outputs ON to 0500.
2107 Inverts output to 0500.
CTC1 2112 Automatically clears current value of CTH0.
2108 Disables output to 0500.
2109 Outputs OFF to 0500
2110 Outputs ON to 0500.
2111 Inverts output to 0500.

• Special utility relay must be ON when clock pulse is generated.


CAUTION
• Only one of relays 2104 to 2107 and one of relays 2108 to 2111 can be
turned ON. When two or more of the relays among each group are ON,
priority is given to the relay with the smallest No.
• Turning OFF special utility relays 2104 and 2108 enable direct output.
Because these relays are factory-set to ON, be sure to set them to OFF.
• ON/OFF status of special utility relays 2104 to 2112 is set using SET and
RES instructions or STA instruction.
• Be sure to turn the special utility relay 2103 or 2112 ON to change the
pulse width. Turn ON 2103 or 2112 to change the pulse cycle.
16
• Turn OFF 2105 to start clock pulse output. Turn ON 2105 to stop pulse
output.
• When special utility relays 2104 and 2108 are turned ON while the direct
clock pulses are being output, the status of the output relay 0500 is output
and the pulses will be stopped.

■ Timing diagram of 0500 with special utility relay settings


• ON-OFF ratio of 1:1 • Variable pulse width
Settings of special utility relays Settings of special utility relays
2103 ON 2112 OFF 2103 ON 2112 OFF
2104 OFF 2108 OFF 2104 OFF 2108 OFF
2105 OFF 2109 OFF 2105 OFF 2109 ON
2106 OFF 2110 OFF 2106 ON 2110 OFF
2107 ON 2111 OFF 2107 OFF 2111 OFF

CTH0 value CTH0 value


CTC0 CTC0
CTC1
ON ON
OFF OFF

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-281

KVNKA Chap 06.p65 281 08.3.11, 0:10 PM


6.2 High-speed Counters

■ 16-bit high-speed counter (CTH1) and special utility relays (2203 to 2205,
2208 to 2212)
By setting the special utility relays 2204 to 2205 and 2208 to 2212 at startup or
changing these relays during generation of clock pulse, you can select ON/OFF of
output relay 0501 as listed below.
These special utility relays also allow you to set the pulse cycle
Pulse status at CTH1 (current value) = CTC (preset value)
Comparator No. Relay No. Pulse status at ON.
CTC2 2203 Automatically clears current value of CTH0.
2204 Disables output to 0501.
2205 Outputs OFF to 0501
KV-300
KV-10/80

2207 Inverts output to 0501.


CTC3 2212 Automatically clears current value of CTH0.
2208 Disables output to 0501.
2209 Outputs OFF to 0501
2210 Outputs ON to 0501.
2211 Inverts output to 0501.

• Special utility relay must be ON when clock pulse is generated.


CAUTION
• Only one of relays 2208 to 2211 can be turned ON. When two or more of the
relays among each group are ON, priority is given to the relay with the
smallest No.
• Turning ON special utility relay 2204 and turning OFF special utility relay
2208 enable direct output.
• ON/OFF status of special utility relays 2204 to 2212 is set using SET and
RES instructions or STA instruction.
• Be sure to turn the special utility relay 2203 or 2212 ON to change the pulse
width.
• Turn ON 2203 or 2212 to change the pulse cycle.
Turn OFF 2205 to start clock pulse output. Turn ON 2205 to stop pulse
output.
6
• When special utility relays 2204 and 2208 are turned ON while the direct
clock pulses are being output, the status of the output relay 0501 which is
used in the program is output and the pulses will be stopped.

Timing diagram of 0501 with special utility relay settings


• Variable pulse width • ON-OFF ratio of 1:1
Settings of special utility relays Settings of special utility relays

2203 ON 2212 OFF 2203 ON 2212 OFF


2204 ON 2208 OFF 2204 ON 2208 OFF
2205 OFF 2209 OFF 2205 ON 2209 ON
2206 OFF 2210 OFF 2206 OFF 2210 OFF
2207 ON 2211 OFF 2207 OFF 2211 OFF

CTH1 value CTH1 value


CTC2 CTC2
CTC3
ON ON
OFF OFF

3-282 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 282 08.3.11, 0:10 PM


6.2 High-speed Counters

Calculating the pulse cycle and comparator setting value


The KV-300 CPU supports clock pulse output at maximum frequency of 50 kHz.
Obtain the pulse cycle for clock pulse output and comparator setting value from the
following expressions:
• Pulse cycle
Pulse cycle (µs) = 1000 ÷ Frequency (kHz)
• For pulse with 1:1 ON/OFF ratio (using one comparator)
CTC setting value = Pulse cycle (µs) ÷ Internal clock (µs) ÷ 2

ON

OFF

KV-300
Pulse

KV-10/80
width
Pulse cycle

• For pulse with variable pulse width (using two comparators)


CTC setting value for pulse width = Pulse width (µs) ÷ Internal clock (µs)
CTC setting value for pulse cycle = Pulse cycle (µs) ÷ Internal clock (µs)

ON

OFF
Pulse
width

Pulse cycle

Range of CTC setting based on internal clock


Special utility relay (Internal clock) Cycle * CTC setting range
2100 2200 1.0 µs 10 to 65535
2101 2201 10.0 µs 1 to 65535
2102 2202 100.0 µs 1 to 65535

• When setting 2100 or 2200 for the operand of High-speed counter CTH, set
CAUTION 10 or greater value to CTC. Otherwise, clock pulse is not correctly output.
• The pulse width varies depending on the influence of the connected load. 16
Before setting the pulse width, you should measure the actual waveform
using an oscilloscope.
• When generating clock pulse using CTC0 and CTC1, or CTC2 and CTC3,
do not set the same value to CTC0 and CTC1, or CTC2 and CTC3. If setting
the same value, clock pulse is output at the double clock cycle.
➮ * Refer to page 3-276.

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-283

KVNKA Chap 06.p65 283 08.3.11, 0:10 PM


6.2 High-speed Counters

Examples of Pulse Output


The following sample explains how to program the pulse output.

Example of clock pulse with 1:1 ON/OFF ratio


■ When outputting clock pulse with cycle 1 ms (1 kHz) from 0500
This program example shows how to output clock pulse with 1:1 ON/OFF ratio from
0500, through High-speed counter CTH0 and High-speed counter comparator
CTC0.

Setting special utility relays


KV-300

Special utility relays 2103 to 2112 are set as shown on the right table.
KV-10/80

The program can be simplified using reverse output (toggle) for pulse with 1:1 ON/
OFF ratio.
Relay No. Setting Relay No. Setting
2103 ON 2112 OFF
2104 OFF 2108 OFF
2105 OFF 2109 OFF
2106 OFF 2110 OFF
2107 ON 2111 OFF

Values set to the internal clock and CTC0


After the internal clock is determined, the CTC0 setting value is calculated from the
following expression.

CTC0 setting value = Pulse cycle (µs) ÷ Internal clock (µs) ÷ 2


Assign 1 ms to pulse cycle and 10 µs (2101: special utility relay) to internal clock
and calculate the CTC0 setting value.
The calculated result is "50".
CTC0 values calculated based on other internal clocks are listed below for your
reference.
Special utility relay Internal clock* CTC0 value
6 2100 1.0 µs 500
2101 10.0 µs 50
2102 100.0 µs 5

Programming example
2008 2103 2104 2105 2106 2107 CTH0
CTH0 value
0001 SET RES RES RES SET RES
CTC0
2002
CTH0
0002 2101
ON
#00050
0003 OFF
CTC0

• The status of output 0500 is set by turning ON one of the relays 2104 to 2107 at
the beginning of the program. In Example, output of direct clock pulses to 0500 is
enabled, and the status of output 0500 is inverted each time CTH0 = CTC0.
• Turns ON special utility relay 2103 and specifies to clear CTH0 using CTC0. The
program repeats clearing the CTH0 current value with the value set to CTC0.
• Resetting the current value of CTH0 at the beginning of the program allows direct
clock pulses of specified width to be output starting from the 1st pulse.
• Input relay which enables CTH0 remains ON during clock pulse output.
➮ * Refer to page 3-276.

3-284 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 284 08.3.11, 0:10 PM


6.2 High-speed Counters

Coding
Line No. Instruction Operand
0000 LD 2008
0001 SET 2103
0002 CON
0003 RES 2104
0004 CON
0005 RES 2105
0006 CON
0007 RES 2106

KV-300
0008 CON

KV-10/80
0009 SET 2107
0010 CON
0011 RES CTH0
0012 LD 2002
0013 CTH 0 2101
0014 CTC 0 #00050

When start/stop of clock pulse is controlled by the input relay which enables/
CAUTION disables the high-speed counter, response relay of up to 1 scan is generated
at start. Also, the same response relay is generated at stop, which may stop
clock pulse output while the output relay is still ON.

This controls clock pulse so that it always starts and stops when 2105 turns OFF.
Turn ON/OFF special utility relay 2105 as required to enable or disable output of
direct clock pulses using one of the external clocks. Use SET and RES instructions
together or only KEEP instruction to turn ON/OFF this relay.
The diagram below can be added to the sample diagram so that direct clock pulses
are output through 0500 only when 0000 is ON.
SET/RES Instructions KEEP Instructions

0000 2105 0000


SET
KEEP
SET 16
2105
0000 2105 0000
RES RES

■ When outputting clock pulse with cycle 1 ms (1 kHz) from 0501


This program example shows how to output clock pulse with 1:1 ON/OFF ratio from
0501, through high-speed counter CTH1 and high-speed counter comparator CTC2.

Setting special utility relays


Special utility relays 2203 to 2212 are set as shown on the right table.
The program can be simplified using reverse output (toggle) for pulse with 1:1 ON/
OFF ratio.

Relay No. Setting Relay No. Setting


2203 ON 2212 OFF
2204 OFF 2208 OFF
2205 OFF 2209 OFF
2206 OFF 2210 OFF
2207 ON 2211 OFF

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-285

KVNKA Chap 06.p65 285 08.3.11, 0:10 PM


6.2 High-speed Counters

Values set to the internal clock and CTC2


After the internal clock is determined, the CTC2 setting value is calculated from the
following expression.
CTC2 setting value = Pulse cycle (µs) ÷ Internal clock (µs) ÷ 2
Assign 1 ms to pulse cycle and 10 µs (2201: special utility relay) to internal clock
and calculate the CTC2 setting value.
The calculated result is "50".
CTC2 values calculated based on other internal clocks are listed below for your
reference.

Special utility relay Internal clock* CTC0 value


2200 1.0 µs 500
KV-300
KV-10/80

2201 10.0 µs 50
2202 100.0 µs 5

➮ * Refer to page 3-276.

Programming example
2008 2203 2204 2205 2207 CTH1 CTH1 value
0001 SET SET RES SET RES CTC2
2002
CTH1
0002 2201 ON
#00050 OFF
0003 CTC2

• The status of output 0501 is set by turning ON one of the relays 2204 to 2207 at
the beginning of the program. In Example, output of direct clock pulses to 0501 is
enabled, and the status of output 0501 is inverted each time CTH1 = CTC2.
• Turns ON special utility relay 2203 and specifies to clear CTH1 using CTC2. The
program repeats clearing the CTH1 current value with the value set to CTC2.
• Resetting the current value of CTH1 at the beginning of the program allows direct
clock pulses of specified width to be output starting from the 1st pulse.
• Input relay which enables CTH1 remains ON during clock pulse output.
6
Coding
Line No. Instruction Operand
0000 LD 2008
0001 SET 2203
0002 CON
0003 SET 2204
0004 CON
0005 RES 2205
0006 CON
0007 SET 2207
0008 CON
0009 RES CTH1
0010 LD 2002
0011 CTH 1 2201
0012 CTC 2 #00050

3-286 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 286 08.3.11, 0:10 PM


6.2 High-speed Counters

When start/stop of clock pulse is controlled by the input relay which enables/
CAUTION disables the high-speed counter, response relay of up to 1 scan is generated
at start. Also, the same response relay is generated at stop, which may stop
clock pulse output while the output relay is still ON.

This controls clock pulse so that it always starts and stops when 2204 turns OFF.
Turn ON/OFF special utility relay 2204 as required to enable or disable output of
direct clock pulses using one of the external clocks. Use SET and RES instructions
together or only KEEP instruction to turn ON/OFF this relay.
The diagram below can be added to the sample diagram so that direct clock pulses
are output through 0501 only when 0000 is ON.
SET/RES Instructions KEEP Instructions

KV-300
KV-10/80
0000 2204 0000
KEEP
SET SET
2204
0000 2204 0000
RES RES

Example of clock pulse with variable ON/OFF ratio


■ When outputting clock pulse with cycle 500 µs (2 kHz) and pulse width
200 µs from 0500
This program example shows how to output clock pulse varies ON/OFF ratio from
0500, through high-speed counter CTH0 and high-speed counter comparator
CTC0 and CTC1.

Setting special utility relays


Special utility relays 2103 to 2112 are set as shown in the table below.

Relay No. Setting Relay No. Setting


2103 ON 2112 OFF
2104 OFF 2108 OFF
2105 OFF 2109 ON
2106 ON 2110 OFF
2107 OFF 2111 OFF
16

Values set to the internal clock, CTC0 and CTC1


After the internal clock is determined, the CTC0 and CTC1 setting value is calcu-
lated from the following expression.
CTC1 setting value = Pulse width (µs) ÷ Internal clock (µs)
CTC0 setting value = Pulse cycle (µs) ÷ Internal clock (µs)
Assign 200 µs to pulse width, 500 µs to pulse cycle and 10 µs (2101: special utility
relay) to internal clock and calculate the CTC0 and CTC1 setting value.
The calculated results of CTC1 and CTC0 are "20" and "50", respectively.
Values calculated based on other internal clocks are listed below for your reference.

Special utility relay Internal clock* CTC0 value CTC1 value


2100 1.0 µs 500 200
2101 10.0 µs 50 20
2102 100.0 µs 5 2
➮ * Refer to page 3-276.

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-287

KVNKA Chap 06.p65 287 08.3.11, 0:10 PM


6.2 High-speed Counters

Programming example
2008 2103 2104 2105 2106 2107
0001 SET RES RES SET RES
CTH0 value
2108 2109 2110 2111 CTH0
0002 CTC0
RES SET RES RES RES
2002 CTC1
CTH0
0003 ON
2101
OFF
#00050
0004 CTC0
#00020
0005 CTC1

• The status of output 0500 is set by turning ON one of the relays 2104 to 2107
KV-300
KV-10/80

and 2108 to 2111 at the beginning of the program. In Example, output of direct
clock pulses to 0500 is enabled, and the status of output 0500 is turned ON at
CTC0 and is turned OFF at CTC1.
• Turns ON special utility relay 2103 and specifies to clear CTH0 using CTC0. The
program repeats clearing the CTH0 current value with the value set to CTC0.
• Input relay which enables CTH0 remains ON during clock pulse output.

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0013 CON
0001 MPS 0014 SET 2109
0002 SET 2103 0015 CON
0003 CON 0016 RES 2110
0004 RES 2104 0017 CON
0005 CON 0018 RES 2111
0006 RES 2105 0019 CON
0007 CON 0020 RES CTH0
0008 SET 2106 0021 LD 2002
0009 CON 0022 CTH 0 2101
0010 RES 2107 0023 CTC 0 #00050
0011 MPP 0024 CTC 1 #00020
6 0012 RES 2108

When start/stop of clock pulse is controlled by the input relay which enables/
CAUTION disables the high-speed counter, response relay of up to 1 scan is generated
at start. Also, the same response relay is generated at stop, which may stop
clock pulse output while the output relay is still ON.

This controls clock pulse so that it always starts and stops when 2105 turns OFF.
Turn ON/OFF special utility relay 2105 as required to enable or disable output of
direct clock pulses using one of the external clocks. Use SET and RES instructions
together or only KEEP instruction to turn ON/OFF this relay.
The diagram below can be added to the sample diagram so that direct clock pulses
are output through 0500 only when 0000 is ON.
SET/RES Instructions KEEP Instructions

0000 2105 0000


KEEP
SET SET
2105
0000 2105 0000
RES RES

By overwriting the setting value of high-speed counter comparator CTC0 using the
LDA and STA instructions, you can change the clock pulse cycle (frequency).
➮ Refer to "Example of pulse output "on page 3-293.

3-288 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 288 08.3.11, 0:10 PM


6.2 High-speed Counters

■ When outputting clock pulse with cycle 500 µs (2 kHz) and pulse width 200
µs from 0501
This program example shows how to output clock pulse with variable ON/OFF ratio
from 0501, through High-speed counter CTH1 and High-speed counter comparator
CTC2 and CTC3.

Setting special utility relays


Special utility relays 2203 to 2212 are set as shown on the right table.
Relay No. Setting Relay No. Setting
2203 ON 2212 OFF
2204 ON 2208 OFF

KV-300
KV-10/80
2205 ON 2209 ON
2206 OFF 2210 OFF
2207 OFF 2211 OFF

Values set to the internal clock and CTC2 and CTC3


After the internal clock is determined, the CTC2 and CTC3 setting value is calcu-
lated from the following expression.
CTC3 setting value = Pulse width (µs) ÷ Internal clock (µs)
CTC2 setting value = Pulse cycle (µs) ÷ Internal clock (µs)
Assign 200 µs to pulse width, 500 µs to pulse cycle and 10 µs (2201: special utility
relay) to internal clock and calculate the CTC2 and CTC3 setting value.
The calculated results of CTC3 and CTC2 are "20" and "50", respectively.
Values calculated based on other internal clocks are listed below for your refer-
ence.
Special utility relay Internal clock* CTC2 value CTC3 value
2100 1.0 µs 500 200
2101 10.0 µs 50 20
2102 100.0 µs 5 2
➮ *Refer to page 3-276.

Programming example
16
2008 2203 2204 2205 2207
0001 SET SET SET RES CTH1 value
2208 2209 2210 2211 CTH1 CTC2
0002 RES SET RES RES RES CTC3
2002
CTH1 ON
0003 2201 OFF
#00050
0004 CTC2
#00020
0005 CTC3

• The status of output 0501 is set by turning ON one of the relays 2204 to 2207
and 2208 to 2211 at the beginning of the program. In Example, output of direct
clock pulses to 0501 is enabled, and the status of output 0501 is turned ON at
CTC2 and is turned OFF at CTC3.
• Turns ON special utility relay 2203 and specifies to clear CTH1 using CTC2.
The program repeats clearing the CTH1 current value with the value set to
CTC2.
• Input relay which enables CTH1 remains ON during clock pulse output.

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-289

KVNKA Chap 06.p65 289 08.3.11, 0:10 PM


6.2 High-speed Counters

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0012 SET 2209
0001 MPS 0013 CON
0002 SET 2203 0014 RES 2210
0003 CON 0015 CON
0004 SET 2204 0016 RES 2211
0005 CON 0017 CON
0006 SET 2205 0018 RES CTH1
0007 CON 0019 LD 2002
0008 RES 2207 0020 CTH 1 2201
KV-300

0009 MPP 0021 CTC 2 #00050


KV-10/80

0010 RES 2208 0022 CTC 3 #00020


0011 CON

When start/stop of clock pulse is controlled by the input relay which enables/
CAUTION disables the high-speed counter, response relay of up to 1 scan is generated
at start. Also, the same response relay is generated at stop, which may stop
clock pulse output while the output relay is still ON.

This controls the clock pulse so that it always starts and stops when 2205 turns
OFF.

Turn ON/OFF special utility relay 2205 as required to enable or disable output of
direct clock pulses using one of the external clocks. Use SET and RES instructions
together or only KEEP instruction to turn ON/OFF this relay.
The diagram below can be added to the sample diagram so that direct clock pulses
are output through 0501 only when 0000 is ON.
SET/RES Instructions KEEP Instructions

0000 2204 0000


KEEP
SET SET
2204
0000 2204 0000
RES RES

6
By overwriting the setting value of high-speed counter comparator CTC2 using the
LDA and STA instructions, you can change the clock pulse cycle (frequency).

Example of stopping clock pulse after reaching the specified output pulse count
The following example stops clock pulse having the pulse width of 200 µs which is
output from 0500 at cycle of 500 µs (2 kHz) after reaching the pulse count value of
10000.

■ Setting special utility relay, internal clock, and CTC


Settings of the special utility relays, internal clock, CTC0, and CTC1 are listed
below.
Relay No. Setting Relay No. Setting
2103 ON 2112 OFF
2104 OFF 2108 OFF
2105 OFF 2109 ON
2106 ON 2110 OFF
2107 OFF 2111 OFF

Special utility relay Internal clock* CTC0 value CTC1 value


2100 1.0 µs 500 200
2101 10.0 µs 50 20
2102 100.0 µs 5 2
➮ *Refer to page 3-276.

3-290 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 290 08.3.11, 0:10 PM


6.2 High-speed Counters

Programming example
2008 2103 2104 2105 2106 2107
0001 EI SET RES SET SET RES
2108 2109 2110 2111 CTH0
0002 RES SET RES RES RES
2203 2813 CTH1
0003 SET SET RES
0000 1000 1000 2105
0004 DIFU RES
2002
CTH0
0005 2101
#00050
0006 CTC0
#00020

KV-300
KV-10/80
0007 CTC1
2002
CTH1
0008 0500
#10000
0009 CTC2

END
0010

INT
0011 CTC2
2002 2105
0012 SET
RET1
0013

ENDH
0014

• Sets pulse output to 0500 using special utility relays 2104 to 2107 and 2108 to
2111.
The example on the left sets special utility relays to enable direct output to 0500
(2104: OFF), and turn 0500 output ON at CTC0 (2106: ON) and OFF at CTC1
(2109: ON).
• Turns ON special utility relay 2103 to clear CTH0 using CTC0. This allows output
with correct clock pulse width starting from the 1st pulse.
• Enables interrupt using the EI instruction.
Stops clock pulse using interrupt program (INT CTC2) when the current value of 16
High-speed counter CTH1 reaches the setting value of high-speed counter
comparator CTC2 (when 10000 pulses are output).
• Turns ON special utility relay 2203 to clear CTH1 using CTC2. This allows
program to operate repeatedly at the specified pulse count (10000 pulses).
• Always turns ON 2813 when counting pulses using high-speed counter CTH1.
• Input relay which enables CTH0 remains ON during clock pulse output.
• Input relay which enables CTH1 remains ON during clock pulse counting.
• Specifies internal clock (2101) for clock input of high-speed counter CTH0.
Specifies 0500 for clock input of high-speed counter CTH1. Then, CTH0 is used
for clock pulse output and CTH1 is used for clock pulse counting.
• Sets the clock pulse count using the setting value of high-speed counter com-
parator CTC2.
• Turns ON input relay 0000 to start clock pulse output.
To restart clock pulse output after once stopped, turns ON input relay 0000
again.

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-291

KVNKA Chap 06.p65 291 08.3.11, 0:10 PM


6.2 High-speed Counters

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0024 SET 2203
0001 EI 0025 CON
0002 CON 0026 SET 2813
0003 MPS 0027 CON
0004 SET 2103 0028 RES CTH1
0005 CON 0029 LD 0000
0006 RES 2104 0030 DIFU 1000
0007 CON 0031 CON
KV-300

0008 SET 2105 0032 AND 1000


KV-10/80

0009 CON 0033 RES 2105


0010 SET 2106 0034 LD 2002
0011 CON 0035 CTH 0 2101
0012 RES 2107 0036 CTC 0 #00050
0013 MRD 0037 CTC 1 #00020
0014 RES 2108 0038 LD 2002
0015 CON 0039 CTH 1 0500
0016 SET 2109 0040 CTC 2 #10000
0017 CON 0041 END
0018 RES 2110 0042 INT CTC2
0019 CON 0043 LD 2002
0020 RES 2111 0044 SET 2105
0021 CON 0045 RETI
0022 RES CTH0 0046 ENDH
0023 MPP

Special utility relays 2103 to 2111 can be set to turn ON or OFF using LDA and STA
instructions as well as SET and RES instructions. Example below illustrates how
one program can be made shorter using LDA and STA instructions.

6 2008
EI
2103
SET
2104
RES
2105
SET
2106
SET
2107
RES
2008
EI
$0268 $2100
LDA STA
CTH0
RES
2203
SET
2813
SET
CTH1
RES
2108 2109 2110 2111 CTH0
RES SET RES RES RES
2203 2813 CTH1
SET SET RES

• LDA $0268
When LDA $0268 is executed, the following data is input to the internal register.

[0] [2] [6] [8]


Internal
register 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0

Internal register
When STA 2100 is executed, the data in the internal register is assigned to 16
special utility relays starting from 2100 to 2115.
15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
Special utility
relays 21** 0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0

Thus, 2103, 2105, 2106, and 2109 are ON.

3-292 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 292 08.3.11, 0:10 PM


6.2 High-speed Counters

Example of pulse output (Ramp-up/down control)


The following example performs ramp-up/down control as shown below by setting 4
parameters (DM0000 to DM0003).

Connection example
The following chart shows an operation example when the KV-300 CPU is con-
nected to the stepping motor driver. See the stepping motor driver instruction
manual for details.
Set the pulse input mode of the stepping motor driver to "1 pulse input mode".

ers
rt

ve

KV-300
Sta

KV-10/80
Re

KV-300 24 VDC Stepping motor driver
+

Twisted pair cable


COM 1
CW (pulse)
0000 11
0001 2
CCW
(rotating
0500 7 direction)
0501 8
0502 9 Stepping motor
0503 10 24 VDC
COM 20
– +
FG

Frequency (Hz)

fH
(DM0000) Positioning
pulse total
Acceleration count
rate (DM0003)
(DM0002)

fL 10 ms
(DM0001) Acceleration
change time
0 Time (ms)
Acceleration time Constant
rate time
Deceleration time 16

Setting parameters
DM0000: fH [Hz] (Run frequency) ➞153 Hz to 50000 Hz fH must be greater than
fL.
DM0001: fH [Hz] (Start frequency)
DM0002: Acceleration rate [Hz/10 ms] ➞ (fH-fL) ÷ (Acceleration time ÷ 10 ms)
DM0003: Positioning pulse count ➞ 65534 pulses max.

• Although smoother trapezoidal control can be obtained by setting a smaller


CAUTION acceleration rate, the acceleration time is extended.
• Be sure to turn OFF input relay 0007 (phase B input).

Operation
This program sets the parameters as below:
DM0000 = 8000 [Hz], DM0001 = 700 [Hz], DM0002 = 400 [Hz/10 ms], DM0003 =
4000 pulses
The program performs trapezoidal control as shown above when start switch 0000 is
pressed, and stops control when pulse count reaches 4000.
The program restarts operation by re-pressing the start switch. It performs reverse
operation while reverse switch 0001 is ON.

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-293

KVNKA Chap 06.p65 293 08.3.11, 0:10 PM


6.2 High-speed Counters

Programming exmaple

0001 INITIAL SETUP FOR HIGH-SPEED COUNTER/COMPARATOR

2002 #00010 #65535 CTH0


0002 CTC1 CTC0 2100 Generates clock pulse through high-
speed counter CTH0.
#65535 #65535 CTH1
0003 CTC2 CTC3 0500 Counts clock pulese through high-
speed counter CTH1.
2008 #08000 #00700 #00400 #04000 2813 2105 • CTC0: Pulse cycle
0004 DW DW DW DW (SET ) (SET ) CTC1: Pulse width
DM0000 DM0001 DM0002 DM0003 • CTC2: Frequency change point
0005
CTC3: Positioning pulse total
STARTS POSITIONING
count
KV-300
KV-10/80

0003 0000 1001 1001


0006 DIFU Sets parameters (DM0000 to
DM0003).
0007

$0268 2100 01 1200 CTH1 CTH0 2105


0008 LDA STA CALL (SET ) (RES ) (RES ) EI (RES )

0001 0502
0009 ( ) Reverse output

0010 EMERGENCY STOP

0003 2105
0011 (SET)

END
0012

0013 CTC0,CTC2,DM0011, CALCULATION SUBROUTINE

SBN Emergency stop


0014 02 Sets CTC0.
Setting value of CTC0 =
2002 #01000 #10000 DM0012 #00005 #00010 CTC0 DM0010 1 ÷ DM0012 x 103 x 103 ÷ 6.4
0015 LDA MUL DIV ADD DIV STA STA

#00010 #10000 DM0010 #00005 #00010 DM0011 CTC2 DM0011


0016 LDA MUL DIV ADD DIV ADD STA STA Sets CTC2.
6 RET
• DM0010: Pulse cycle T (µs) x 10
• DM0011: Accumulated pulse count
0017 • DM0012: Current frequency f [Hz]
• 1200: Acceleration flag
0018 INITIALIZING SUBROUTINE

SBN
0019 01

2002 DM0003 CTC3 #00002 DM0004 DM0001 DM0012 #00000 02


0020 LDA STA DIV STA LDA STA DW CALL
DM0011
RET
0021

0022 RAMP UP/DOWN CHECK ROUTINE

SBN
0023 03

2002 DM0012 #00100 DM0011 DM0004


0024 LDA DIV ADD CMP

3-294 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 294 08.3.11, 0:10 PM


6.2 High-speed Counters

RET
0025

0026 INTERRUPT ROUTINE FOR SPEED-UP/SLOW-DOWN

INT
0027 CTC2

0028 SPEED-UP

1200 DM0012 DM0002 DM0012 DM0000 2011 03 2011 02


Adds the acceleration rate to the
0029 LDA ADD STA CMP CALL CALL
current frequency to change
2011 1201 frequency whenever CTC2 turns
0030 ( ) ON while acceleration flag 1200 is

KV-300
KV-10/80
2011 DM0003 DM0011
ON. When the current frequency
CTC2 DM0011
0031 LDA SUB STA STA
reaches fH, stops acceleration and
sets the deceleration pulse count.
1201 1200
0032 (RES )

0033 SPEED-UP
1200 DM0012 DM0002 DM0012 DM0001 2011 02
0034 LDA SUB STA CMP CALL Subtracts the acceleration rate from
2011 02
the current frequency to change
#65535 CTC2
0035 CALL LDA STA
frequency whenever CTC2 turns
ON while acceleration flag 1200 is
RETI OFF. When the current frequency
0036 reaches fL, stops deceleration and
initializes the settings.
0037 INTERRUPT FOR PULSE STOP

INT
When pulse count of clock pulses
0038 CTC3
equals the setting value of CTC3,
2002 2105 stops clock pulse output.
0039 (SET )

RETI
0040
ENDH
0041

16

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-295

KVNKA Chap 06.p65 295 08.3.11, 0:10 PM


6.3 Positioning Control

6.3 Positioning Control


6.3.1 Positioning Control (Ramp-up/down Control)
Outline of positioning control
The KV-300 CPU outputs clock pulses, independent of scan time, directly through
output relay 0500 or 0501. When the clock pulse frequency, output pulse count, and
acceleration/deceleration time are set to the data memory addresses in advance,
the KV-300 CPU automatically performs ramp-up/down control. Output frequency
can be set within the range of 153 Hz to 50000 Hz.
KV-300
KV-10/80

Frequency (Hz)

Operation

Start
Output pulse count

Acceleration time Deceleration time Time (ms)

With this function, ramp-up/down control over stepper motors and AC servo motors
(pulse input type) becomes possible.
The following section describes setting and application of positioning control
parameters.

Clock pulse

6 Rotation direction
0500
0501 Lo : CW
Hi : CCW
0502
0503 Stepping motor
/servo motor

KV-300 Motor driver

3-296 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 296 08.3.11, 0:10 PM


6.3 Positioning Control

Setting and application of parameters


This section describes how to set and apply parameters for positioning control.

Setting parameters
Set the parameters to the assigned data memory addresses. To operate the
positioning control function, the special utility relays must be set. ➮ Refer to page 3-299.
The following table shows the parameters and assigned DM Nos.
DMNo. Parameter Allowable setting range
DM9407 Set value error code Code 11 to 17 or FFFF (-1)
is entered when error occurs

KV-300
KV-10/80
X-axis DM9408 0500 Start frequency (Hz) 153 to 50000
(0500) DM9409 0500 Run frequency (Hz) 153 to 50000
DM9410 0500 Acceleration/deceleration 0 to 4096
time (ms)
DM9411 0500 Output pulse count 0 to 65535
(high-order 16 bits)
DM9412 0500 Output pulse count 0 to 65535
(low-order 16 bits)
Y-axis DM9413 0501 Start frequency (Hz) 153 to 50000
(0501) DM9414 0501 Run frequency (Hz) 153 to 50000
DM9415 0501 Acceleration/deceleration 0 to 4096
time (ms)
DM9416 0501 Output pulse count 0 to 65535
(high-order 16 bits)
DM9417 0501 Output pulse count 0 to 65535
(low-order 16 bits)

Note: Refer to the following expression to determine the output pulse count.

Output pulse count < (65535 x pulse change cycle [ms]) ÷ (1000 x run frequency
[Hz])

■ Pulse change cycle (∆t)


16
The pulse change cycle is the cycle in which the output clock pulse frequency is
changed for acceleration or deceleration. The pulse change cycle is obtained from
one of the following expressions, whichever produces the smaller solution. However,
when the start pulse is less than 500 Hz, the pulse change cycle becomes 14 ms or
more.

Pulse change cycle (∆t) [ms] = (acceleration time [ms] + 199) ÷ 200 x 4
or
Pulse change cycle (∆t) [ms] = 1000 ÷ (run frequency [Hz] ÷ 1000)

Run

Start ∆t

Acceleration/ deceleration time

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-297

KVNKA Chap 06.p65 297 08.3.11, 0:10 PM


6.3 Positioning Control

■ Set value error code


Automatically writes an error code (11 to 17) into DM9407 when a parameter setting
error is found at startup.

Code Error description Corrective action


11 Start frequency is below allowable Adjust start frequency to within allow-
range. able range (153 to 50000).
12 Run frequency is below allowable Adjust run frequency to within allow-
range. able range (153 to 50000).
13 Run/start frequency exceeds allow- Adjust run/start frequency to within
able range. allowable range (153 to 50000).
14 Start frequency is greater than run Reduce start frequency to less than
KV-300
KV-10/80

frequency. run frequency.


15 Acceleration/deceleration time Adjust acceleration/deceleration time
exceeds allowable range. to within allowable range (0 to 4096).
16 Too many pulses are output during Change the parameters.
acceleration/deceleration time.
17 Too few pulses are output during Set 2 or more as value for output
acceleration/deceleration time. pulse count.
FFFF Other calculation error Change the parameters.

■ Corrective action for error code 16


Error code 16 is issued when the output pulse count during acceleration/decelera-
tion time exceeds other values calculated from the preset parameters.
To recover from the error, the following corrective actions are available.
• Change the run frequency and/ or the acceleration/ deceleration time according
to the following expression.
Run frequency
65535 x Pulse change cycle x 65535
1000
Corrective action for error code FFFF (-1)
• Reduce run frequency and start frequency.
• Reduce accelleration/ deccelleration time.
6 ■ Start frequency (Hz)
Sets a start frequency (speed) to start the motor rotation smoothly during positioning
control.
The KV-300 CPU outputs clock pulses at the specified frequency.

■ Run frequency (Hz)


Sets the motor frequency (speed) during positioning control. The KV-300 CPU
outputs clock pulses at the specified frequency.

Note: When the start frequency equals the run frequency, the system operates as
shown in the following chart.
Preset frequency

0
Here, the acceleration/deceleration time is ignored. The output count should be less
than 65535.

3-298 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 298 08.3.11, 0:10 PM


6.3 Positioning Control

■ Acceleration/deceleration time (ms)


Sets the time required when the start frequency accelerates to the run frequency at
startup. In the same manner, sets the deceleration time required at stop. The KV-
300 CPU controls the clock pulse frequency from the start frequency to the run
frequency within the specified time. The pulse change cycle within the acceleration
time is obtained from one of the following expressions, whichever produces the
smaller solution. However, the pulse change cycle when the start pulse is less than
500 Hz becomes 14 ms or more.

Pulse change cycle (∆t) ms = (acceleration time ms + 199) ÷ 200 x 4


or
Pulse change cycle (∆t) ms = 1000 ÷ (run frequency Hz ÷ 1000)

KV-300
KV-10/80
■ Output pulse count
Sets the positioning control rotation angle (moving distance) with the pulse count.
The KV-300 CPU outputs as many clock pulses as specified. If the output pulse
count is greater than 65535, set the pulse count separately for high-order 16 bits
and low-order 16 bits based on the following expressions.

(Output pulse count) ÷ 65536 = A (solution) … B (remainder)

A = Output pulse count (high-order 16 bits)


B = Output pulse count (low-order 16 bits)

Note: When the specified output pulse count is insufficient and does not reach the
target value, the KV-300 CPU performs triangular control.
Run frequency

Start frequency
0

The current pulse output value cannot be checked.

Procedure
When the positioning control function is used, the KV-300 CPU controls start, stop,
16
and emergency stop by turning ON/OFF the utility relays. The table below shows the
operations and assigned utility relays.

Relay No. R/W Function Description


0500 0501
2308 2311 W STOP Decelerates at rising (UP) edge and stops.
2309 2312 R RUN Turns ON during pulse output.
W RESET Immediately stops when turning ON during
interrupt program.
2310 2313 W START Starts at rising (UP) edge.

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-299

KVNKA Chap 06.p65 299 08.3.11, 0:10 PM


6.3 Positioning Control

■ Operation chart (when 0500 is used)

DM9409
DM9408: Start frequency (Hz)
DM9409: Run frequency (Hz)
DM9408 DM9411 DM9410: Acceleration time (ms)
DM9412 DM9411: Output pulse count
0 (high-order 16 bits)
DM9410 DM9410
DM9412: Output pulse count
(low-order 16 bits)
When 2310 turns ON, clock pulse is output.
2310 (rising [UP] edge is detected.)
(START) 2309 is ON during clock pulse output. When
KV-300

pulse output is stopped, 2309 turns OFF.


KV-10/80

2309 When turning ON 2308, clock pulse


(RUN) decelerates and stops (rising [UP] edge is
detected.)
2308
(STOP)

Note 1: When special utility relay 2310 (2313) is turned ON at start of clock pulse,
2309 (2312) turns ON and the clock pulse is output, assuming parameter settings
are correct.
Note 2: If a parameter setting for the X-axis or Y-axis is incorrect, 2309 (2312) does
not turn ON and an error code is written into DM9407. Check the error code and
adjust the parameter setting.
Note 3: By resetting 2309 (2312) within the interrupt program, you can stop the
clock pulse immediately. You must reset 2309 within the interrupt program; other-
wise, the clock pulse is not stopped.
Note 4: Because the clock pulse is output under software control, the pulse width is
extended by 10 µs to 20 µs in the pulse change cycle. Test the clock pulse output on
the KV-300 system before using it in practical applications.

Examples of stepping motor control


■ Connection example
6 The following reference example shows how to connect the KV-300 CPU to a
stepping motor driver. Refer to the stepping motor driver instruction manual for
details.
Set the pulse input mode for the stepping motor driver to "Pulse input mode 1".
top
s
ncy
rge

p
e

rt
Sto
Em

Sta


24 VDC
+
KV-300 Stepping motor driver

Twisted pair cable


COM 1 + CW (pulse)
0000 11 –
0001 2 + CCW
0002 12 – (rotation
direction)

0500 7
0501 8
0502 9 Stepping motor
0503 10 24 VDC
COM 20
– +
FG

3-300 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 300 08.3.11, 0:10 PM


6.3 Positioning Control

Ramp-up/down control
When start switch 0002 is turned ON, 0500 outputs 100000 pulses under the
following conditions: start frequency 1 kHz, run frequency 5 kHz, and acceleration/
deceleration time 3 s.
Turn ON 0001 to decelerate and stop pulse output. When 0000 is turned ON, pulse
output is immediately stopped.
Enables interrupt when starting operation.
2008
0001 This is required to allow emergency stop
EI
operation.
0002 #01000 #05000 #03000 #00001 #34464 2310
0002 DW DW DW DW DW Sets parameters and simultaneously
0001 DM9408 DM9409 DM9410 DM9411 DM9412 2308 starts pulse.
0003 Decelerates and stops pulse.

KV-300
KV-10/80
END
0004
INT Executes emergency stop sequence with
0005 0000
interrupt progaram.
2002 2309
0006 RES
RET1
0007
ENDH
0008

Application example of stepping motor control


Assume a program that can be controlled both automatically and manually.
In automatic mode, the system runs as shown in the chart below after 0000 is turned
ON.

8000
2000
300
0 15000 17500

16
15000

In manual mode, the system goes forward while 0008 is ON and rearward while
0009 is ON. It returns to the origin when 0007 turns ON.
A pulse is output from 0500. Reverse the rotation direction by turning ON/OFF 0502.
The system is equipped with an origin sensor (0002), forward end limit (0006), and
rearward end limit (0004).

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-301

KVNKA Chap 06.p65 301 08.3.11, 0:10 PM


6.3 Positioning Control

Program example

0001 STEPPING MOTOR CONTROL PROGRAM (ORIGIN, FORWARD, REVERSE LIMITS)

0002 SPECIFICATION

0003 PULUSE OUT==500 FOR/REV=502 ORIGIN=0002 FOR/END=0006 FOR/END=0004

0004 MANUAL SW: FORWARD=0008 REVERSE=0009 ORIGIN SW=0007

0005 AUTO OPERATION START=0000


KV-300
KV-10/80

0006

0007 ENABLES INTERRUPT & RESETS ORIGIN POSITIONING FRAG

2008 1200 Sets start frequency, run frequency,


0008 (RES) < EI > and acceleration/deceleration time.
Start frequency: 600 Hz
Run frequency: 4 kHz
0009 MANUAL SWITCHES: FORWARD=0008 REVERSE=0009 Acceleration/deceleration time:
0008 0009 2309 0502 0006 1100 100 ms
0010 (SET) DIFU Output pulse count: 65536

0009 0008 2309 0502 0004 1101


0011 (RES) DIFU

1100 #00600 #04000 #00100 #00001 #00000 1103


0012 < DW > < DW > < DW > < DW > < DW > DIFU
DM9408 DM9409 DM9410 DM9411 DM9412
1101
0013
To return to the origin, first goes
0008 0009 1105
forward and then rearward. Stops
0014 DIFU
when origin limit (0002) turns ON.

* * * * * * * * * * * * * * * * * * * * * * * * * * ORIGIN * * * * * * * * * * * * * * * * * * * * * * * * * * * *
For forward operation, the following
0015
parameters are set:
Start frequency: 300 Hz,
0016 LIMIT SWITCHES Run frequency: 3 kHz,
0007 1205 Acceleration/decekeratuib time: 250 ms,
0017 DIFU Output pulse count: 3500.

6 For rearward operation, the following


0018 FORWARD IN ADVANCE parameters are set:
Start frequency: 50 Hz
1205 0502 #00300 #03000 #00250 #00000 #03500 1300 1200
(SET)
Run frequency: 500 Hz
0019 < DW > < DW > < DW > < DW > < DW > DIFU (SET)
DM9408 DM9409 DM9410 DM9411 DM9412 Acceleration/deceleration time: 0 ms
Output pulse count: 65536
0020 STOP FORWARDING

1200 2309 1201 2309 1202 1203


0021 ON OFF DIFU
1201 1202

0022 POSITIONING ORIGIN WHILE REVERSING SLOWLY

1203 0502 #00500 #05000 #00000 #00001 #00000 1301 1200


0023 (RES) < DW > < DW > < DW > < DW > < DW > DIFU (RES)
DM9408 DM9409 DM9410 DM9411 DM9412

3-302 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 302 08.3.11, 0:10 PM


6.3 Positioning Control

0024 STARTS MOTOR

1300 0006 2310


0025 ( ) Instructs motor start and acceleration/
deceleration stop.
1301 0004
0026

1103
0027

1506 2308
0028

0029 SLOW DOWN & STOP (MANUAL/AUTO)

0006 0009 2308


( )

KV-300
0030

KV-10/80
0004 0008
0031

1105
0032

0033 * * * * * * * * * * * * * * * * * * * * * * * * AUTO OPERATION CH0 * * * * * * * * * * * * * * * * * * * *

0034 STAGE INSTRUCTION START

2008 1400
0035 (SET)

2308 1408 1408 1401 1402 1403 1400


0036 DIFU (RES) (RES) (RES) (SET)

0037 AUTO START (OPERATES DURING 0000 IS TURNED ON)

1400 0000 1401 Creates each of the operation programs


0038 STG JMP
with the STG instruction and makes the
programs ready in the specified order.
0039 MOVES TO NEXT STAGE AFTER MOTOR STOPS

1407 T001 1500 1405 1402


Sets the parameters for automatic mode.
1401 #00010 2309
0040 STG (RES) T001 DIFU JMP (1) Start frequency: 300 Hz
1405 Run frequency: 8 kHz
1402 1405 #00005 T002 1501 2309 1406 1403 Acceleration/deceleration time: 150 ms
0041 STG (RES) T002 DIFU JMP
1406
Output pulse count: 15000
1403 1406 #00005 T003 1502 2309 1407 1400 (2) Start frequency: 300 Hz
0042 STG (RES) T003 DIFU JMP Run frequency: 2 kHz
1407 Acceleration/deceleration time: 250 ms
Output pulse count: 2500
16
0043 AUTO OPERATION PARAMETER SET
(3) Start frequency: 300 Hz
1500 0502 1503
#00300 #08000 #00150 #00000 #15000 Run frequency: 15 kHz
0044 (SET) < DW > < DW > < DW > < DW > < DW > DIFU
DM9408 DM9409 DM9410 DM9411 DM9412 Acceleration/deceleration time: 250 ms
1501 0502 #00300 #02000 #00250 #00000 #02500 1504 Output pulse count: 17500
0045 (SET) < DW > < DW > < DW > < DW > < DW > DIFU
DM9408 DM9409 DM9410 DM9411 DM9412
1502 0502 1505 Stops pulse at the origin with the interrupt
#00300 #15000 #00250 #00000 #17500
0046 (RES) < DW > < DW > < DW > < DW > < DW > DIFU program.
DM9408 DM9409 DM9410 DM9411 DM9412

0047 STARTS MOTOR

1503 1506
0048 ( )

1504
0049

1505
0050

END
0051

0052 INTERRUPT FOR EMERGENCY STOP (POSITIONING ORIGIN)

INT
0053 0002

1200 0008 0009 0000 2309


0054 ( RES )

RETI
0055

ENDH
0056

Chapter 6 Interrupts, High-speed Counters, Positioning Control


3-303

KVNKA Chap 06.p65 303 08.3.11, 0:10 PM


6.3 Positioning Control
KV-300
KV-10/80

3-304 Chapter 6 Interrupts, High-speed Counters, Positioning Control

KVNKA Chap 06.p65 304 08.3.11, 0:10 PM


Chapter 7
Serial Communication
The KV Series can be connected to an external device with an RS-232C interface
to establish communication.
This chapter describes communications specifications, how to connect the KV
Series to external devices, and how to perform communication.

7.1 Communications Specifications ............................................ 3-306


7.1.1 Communications Specification ............................................................... 3-306
7.1.2 Connection with the KV Unit .................................................................. 3-306
7.1.3 Connecting the KV-300 CPU to a Personal Computer .......................... 3-307
7.2 Serial Communication ............................................................. 3-308
7.2.1 Command Transmission Procedure ....................................................... 3-308
7.2.2 Format of Commands/Responses ......................................................... 3-309
7.2.3 Communication Command/Response List ............................................. 3-310
7.2.4 Setting Communication Commands and Responses to Commands ..... 3-311
7.2.5 Other Response Codes .......................................................................... 3-315
7.2.6 Error Code List ....................................................................................... 3-316
7.2.7 Example Program .................................................................................. 3-317
7.3 Loading Text Data .................................................................... 3-318
7.3.1 Receiving Text Data ............................................................................... 3-318
7.3.2 Transmitting Text Data ........................................................................... 3-319
7.3.3 Sample Program .................................................................................... 3-320
7.4 ASCII Code List ........................................................................ 3-321

KVNKA Chap 07.p65 305 08.3.11, 0:11 PM


7.1 Communications Specifications

7.1 Communications Specifications


This section describes the specifications for the RS-232C interface and the connec-
tion between the KV and external devices.

7.1.1 Communications Specification


The communications specification of the KV is summarized in the table. Set the
communications parameters of the personal computer by referring to the table.

Communications parameters
Duplex Full
Synchronization Start/stop
Data format ASCII
Baud rate 9,600 bps
Data length 8 bits
Parity check Even
Stop bit length 1 bit
Delimiter CR

Note 1: Be sure to specify the same communication parameters for the KV and any
external devices to be connected. Communication will fail if different parameters are
used.
Note 2: Refer to the instruction manual supplied with each device when setting
communications parameters on the device.

7.1.2 Connection with the KV Unit


Use the special connection cable (Straight cable: OP-26487, Reverse cable: OP-
96607) and a 25-pin D-sub connector (OP-26485) to connect the KV to the RS-232C
connector of the external device.

7 Communication port B
Communication port A

External device with RS-232C connector


KV

Note: The KV-10xx and KV-10/80 Series include only communication port A.

Wiring diagram
The following is the wiring diagram for the RS-232C cable. Be sure to use the
special connection cable to connect the KV with each device.
Device desig- Device designated
KV nated as modem KV as terminal
SD 3 2 SD SD 3 2 SD
RD 5 3 RD RD 5 3 RD
SG 4 7 SG SG 4 7 SG
4 RS 4 RS
Connection Connection
5 CS 5 CS
cable 6 DR cable 6 DR
(Reverse: 20 ER (Straight: 20 ER
1 2 3 4 5 6
OP-96607) OP-26487)
Pin assignment for 25-pin D-sub 25-pin D-sub
the KV connector connector
(OP-26485) (OP-26485)

3-306 Chapter 7 Serial Communication

KVNKA Chap 07.p65 306 08.3.11, 0:11 PM


7.1 Communications Specifications

7.1.3 Connecting the KV-300 CPU to a Personal Computer


Connect the KV-300 CPU to the RS-232C port of the personal computer with the
supplied connecting cable (OP-226486/OP-26487).

Connecting cable 9-pin D-SUB female


connector: OP-26487 Personal computer with an
Standard cable:OP-26486
RS-232C port
KV-300

Recommended pin assignments for the RS-232C communication cable are shown
below. When connecting the KV-300 CPU, use only the connecting cable supplied.
KV-300 DCE KV-300 DTE
SD 3 2 SD SD 3 2 SD
RD 5 3 RD RD 5 3 RD
4 RS 4 RS
5 CS 5 CS
6 DR 6 DR
20 ER 20 ER
23 45 SG 4 7 SG SG 4 7 SG

Pin assignments for


the KV-300 CPU

Standard cable (OP-26486 + OP-26487)

SD 3 2
RD 5 3
4
SG 4 5
6
Modular 7
Connector 8
9-pin D-sub connector

17

Chapter 7 Serial Communication


3-307

KVNKA Chap 07.p65 307 08.3.11, 0:11 PM


7.2 Serial Communication

7.2 Serial Communication


When the KV is connected to a personal computer, the current value or preset value
of timers/counters or contents of data memories in the KV can be loaded to and
modified on the computer.

7.2.1 Command Transmission Procedure


Commands are transmitted from a personal computer to the KV base unit as follows:

Initialize the communication buffer and


Transmits a break signal baud rate setting of the KV.

Transmits communications Start communications with the KV.


start command (CR)

Transmit a command which instructs the


Transmits a command
KV to perform the required operation.

Receiving a response Receive and check the response to the


transmitted command.

Transmits communications End communications with the KV.


end command (CQ)

■ Transmitting a break signal


A break signal is used to initialize the communication buffer and baud rate setting of
the KV. It is necessary to transmit a break signal of 100 ms or longer to the KV
before starting communication. Another break signal is unnecessary once the
communication is established.
A break signal must have the waveform shown below.
7 100 ms or longer
+V
SD
-V
10 ms or longer

Note 1: For the first serial communication with a personal computer after the KV-
P3E(01) handheld programmer is connected to the KV, or after the "KV IncrediWare
(DOS)" or "LADDER BUILDER for KV" programming support software is evoked, be
sure to transmit a break signal. A break signal is unnecessary at other times.
Note 2: If you cannot transmit a break signal, turn OFF the KV once to initialize the
communication program. After that, restart communication between the KV and the
personal computer.
Note 3: Be sure to stop the communication for 10 ms or longer after transmitting a
break signal.

3-308 Chapter 7 Serial Communication

KVNKA Chap 07.p65 308 08.3.11, 0:11 PM


7.2 Serial Communication

■ Command/response format
"Command" and "response" in communications between the KV and a personal
computer are defined as follows:

Command: Message transmitted from personal computer to KV

Response: Answer to the command (message from KV to personal computer)

When a personal computer transmits a command to the KV Series basic unit, the KV
sends back a response to the personal computer.
When creating a program to control the KV using a personal computer, create it so
that the response is checked before the next command is transmitted.

7.2.2 Format of Commands/Responses


The formats of commands and responses are as follows:

Command format
Use the following format to transmit commands from the personal computer to the
KV. [CR] is a delimiter. The KV ignores [LF] and recognizes the next character after
[LF] as the next command.

Command C
R

Or Command C L
R F

Response format
The KV sends back a response to the received command in the following format.
When creating a program using a personal computer, create it so that the personal
computer can process the response in this format.

Response C L
R F

17

Chapter 7 Serial Communication


3-309

KVNKA Chap 07.p65 309 08.3.11, 0:11 PM


7.2 Serial Communication

7.2.3 Communication Command/Response List


The following list shows the commands and responses used in serial communica-
tion. "_" in the list represents a space.

Function Command Response Description


Starts communication. CR CC
Ends communication. CQ CF
n= 0: PROGRAM mode
Changes mode. Mn OK
1: RUN mode
Clears error. ER OK
Checks PLC error. ?E dd dd= Error code (00: No error)
f= 0: PROGRAM mode
Checks current PLC mode. ?M f
1: RUN mode
Counter RD_Cnnn
High-speed f, ddddd, ddddd f= 0: Contact OFF, 1: Contact ON
RD_CTHn
counter CTH ↑ ↑ dddddd= 00000 to 65535 (in decimal)
High-speed (Current value) (Preset value) n/nnn= Counter No.
counter RD_CTCn
comparator CTC

f, ddddd, ddddd f= 0: Contact OFF 1: Contact ON


Reads Timer RD_Tnnn ↑ ↑ dddddd= 00000 to 65535 (in decimal)
(Current value) (Preset value) nnn= Timer No.

ddddd_ddddd_00000_00000
dddddd= 00000 to 65535 (in decimal)
Digital trimmer RD_AT ↑ ↑
Reads preset values of trimmer 0 and 1.
(Trimmer 0) (Trimmer 1)

Relay contact RD_nnnnn f f= 0: Contact OFF, 1: Contact ON


Data memory RD_DMnnnn
dddddd= 00000 to 65535 (in decimal)
Temporary data ddddd
RD_TMnn nnnn= DM No.
memory
Counter current
WR_Cnnn_ddddd
value
Timer current n/nnn= Timer/counter
WR_Tnnn_ddddd OK
value No. dddddd= 00000 to 65535 (in decimal)
CTH current
WR_CTHn_ddddd
value
Counter preset
Writes WS_Cnnn_ddddd
value 2.
Timer preset n/nnn= Timer/counter
WS_Tnnn_ddddd OK
value 2. No. dddddd= 00000 to 65535 (in decimal)
7 CTC preset
WS_CTCn_ddddd
value 2.
Data memory WR_DMnnnn_ddddd
dddddd= 00000 to 65535 (in decimal)
Temporary data OK
WR_TMnn_ddddd nn,nnnn= DM No.
memory
Relay ST_nnnnn
nnnn= Relay No.
Forces ON Counter contact ST_Cnnn OK
nnn= Timer/counter No.
Timer contact ST_Tnnn
Relay RS_nnnnn
Counter contact RS_Cnnn
Forces OFF Timer contact RS_Tnnn nnnn= Relay No.
OK nnn= Timer/counter No.
High-speed n= CTC No.
counter RS_CTCn
comparator CTC
contact

Note 1: Temporary data memories TM28, TM30, and TM31 are read-only. Values cannot be written into
these memories. However, these memories can be used when special functions are not used.
Note 2: Visual KV Series: When the preset values of timers and counters are changed using "WS", the
ladder program in EEPROM is updated the next time the KV is turned on.
KV-300, 10/80 Series: The "WS" command changes the content of the program stored in the
PLC’s EEPROM.
➮ Contact Keyence if you need to change it frequently.

3-310 Chapter 7 Serial Communication

KVNKA Chap 07.p65 310 08.3.11, 0:11 PM


7.2 Serial Communication

7.2.4 Setting Communication Commands and Responses to


Commands
This section describes the command settings and responses when a command is
properly processed.
"_" represents a space.
Refer to "7.2.5 Other Response Codes" (p. 3-315) for responses under abnormal
conditions.

■ Communications start command


Transmit a communications start command to start communication with the KV.
Other commands can be transmitted after the proper response is sent back from the
KV.

Note: Other commands cannot be used unless a [CR] (communications start)


command is transmitted first.

Starts communications between the KV and a personal computer.


Command: CR
Response: CC

■ Communications end command


Ends communications between the KV and a personal computer.
Command: CQ
Response: CF

■ Mode change command


Selects the mode between PROGRAM and RUN.
Command: Mn [n=0; PROGRAM mode, n=1; RUN mode]
Response: OK

■ Error clear command


Clears error messages on KV.
Command: ER
Response: OK 17
■ Checking KV PLC error
Checks errors or faults in the KV. The description of the error is indicated with the
error code.
➮ "7.2.6 Error Code List" (p. 3-316).
Command: ?E
Response: dd
Error code (2- or 3-digit number)

■ Checking current mode


The KV responds with 0 or 1 indicating a current mode.
Command: ?M
Response: f
0: PROGRAM mode 1: RUN mode

Chapter 7 Serial Communication


3-311

KVNKA Chap 07.p65 311 08.3.11, 0:11 PM


7.2 Serial Communication

■ Reading counter
Reads the contact ON/OFF status, or the current and preset values of the specified
counter/up-down counter.
Command: RD_Cnnn
Counter No.
Response: f,ddddd,ddddd
[Preset value of the counter (00000 to 65535: in
decimal)]
[Current value of the counter (00000 to 65535: in
decimal)]
0: Contact is OFF., 1: Contact is ON.

■ Reading high-speed counter CTH


Reads the contact ON/OFF status, or the current and preset values of the specified
high-speed counter CTH.
Command: RD_CTHn
High-speed counter No. (0 or 1)
Response: f,ddddd,ddddd
Preset value of CTH (00000 to 65535: in decimal)
Current value of CTH (00000 to 65535: in decimal)
0: Contact is OFF., 1: Contact is ON.

■ Reading high-speed counter comparator CTC


Reads the contact ON/OFF status, or the current and preset values of the specified
high-speed counter comparator CTC.
Command: RD_CTCn
High-speed counter comparator No.
Response: f,ddddd,ddddd
Preset value of CTC (00000 to 65535: in decimal)
Current value of CTC (00000 to 65535: in decimal)
0: Contact is OFF., 1: Contact is ON.

■ Reading timer
Reads the contact ON/OFF status, or the current and preset values of the specified
timer.
Command: RD_Tnnn
7 Timer No.
Response: f,ddddd,ddddd
Preset value of timer (00000 to 65535: in decimal)
Current value of timer (00000 to 65535: in decimal)
0: Contact is OFF., 1: Contact is ON.

■ Reading digital trimmer


Reads the preset values of the digital trimmers.
Command: RD_AT
Response: ddddd_ddddd_00000_00000
Value of trimmer 1 (00000 to 65535: in decimal)
Value of trimmer 0 (00000 to 65535: in decimal)

■ Reading relay contact


Reads the contact ON/OFF status of the specified relay.
Command: RD_nnnn
Relay No.
Response: f
0: Contact is OFF., 1: Contact is ON.

3-312 Chapter 7 Serial Communication

KVNKA Chap 07.p65 312 08.3.11, 0:11 PM


7.2 Serial Communication

■ Reading DM
Reads the contents of the specified data memory.
Command: RD_DMnnnn
Data memory No.
Response: ddddd
Data in the specified data memory. (00000 to
65535: in decimal)
■ Reading TM
Reads the contents of the specified temporary data memory.
Command: RD_TMnn
Temporary data memory No. (00 to 31)
Response: ddddd
Data in the specified temporary data memory.
(00000 to 65535: in decimal)
■ Writing current value of counter
Changes the current value of the specified counter or up-down counter.
Command: WR_Cnn_ddddd
New current value (00000 to 65535: in decimal)
Counter No.
Response: OK
■ Writing current value of timer
Changes the current value of the specified timer.
Command: WR_Tnnn_ddddd
New current value (00000 to 65535: in decimal)
Timer No.
Response: OK
■ Writing current value of high-speed counter CTH
Changes the current value of the specified high-speed counter CTH.
Command: WR_CTHn_ddddd
New current value (00000 to 65535: in decimal)
High-speed counter No.
Response: OK
■ Writing preset value of counter
Changes the preset value of the specified counter or up-down counter.
17
Command: WS_Cnnn_ddddd
New preset value (00000 to 65535: in decimal)
Counter No.
Response: OK

Note: Executing this command changes the program in the KV. The program in EEPROM is
automatically updated the next time the KV is turned ON.

■ Writing preset value of timer


Changes the preset value of the specified timer.
Command: WS_Tnnn_ddddd
New preset value (00000 to 65535: in decimal)
Timer No.
Response: OK

Note: Visual KV Series: Executing this command changes the program in the KV. The
program in EEPROM is automatically updated the next time the KV
is turned ON.
KV-300, 10/80 Series: The "WS" command changes the content of the program
stored in the PLC’s EEPROM.
➮ Contact Keyence if you need to change it frequently.

Chapter 7 Serial Communication


3-313

KVNKA Chap 07.p65 313 08.3.11, 0:11 PM


7.2 Serial Communication

■ Writing preset value of high-speed counter comparator CTC


Changes the preset value of the specified high-speed counter comparator CTC.
Command: WS_CTCn_ddddd
New preset value (00000 to 65535: in decimal)
High-speed counter comparator No.
Response: OK

■ Writing into DM
Writes data into the specified data memory.
Command: WR_DMnnnn_ddddd
New current value (00000 to 65535: in decimal)
Data memory No.
Response: OK

■ Writing into TM
Writes data into the specified temporary data memory. TM30 and TM31 are read-
only memories, so values cannot be written to them.
Command: WR_TMnn_ddddd
New current value (00000 to 65535: in decimal)
Temporary data memory No. (00 to 29)
Response: OK

■ Forcing relay ON
Forces the contact of the specified relay to ON.
Command: ST_nnnnn
Relay No.
Response: OK

■ Forcing counter contact ON


Forces the contact of the specified counter to ON.
Command: ST_Cnnn
Counter No.
Response: OK

■ Forcing timer contact ON


7 Forces the contact of the specified timer to ON.
Command: ST_Tnnn
Timer No.
Response: OK

■ Forcing relay OFF


Forces the contact of the specified relay to OFF.
Command: RS_nnnnn
Relay No.
Response: OK

■ Forcing counter contact OFF


Forces the contact of the specified counter to OFF.
Command: RS_Cnnn
Counter No.
Response: OK

■ Forcing timer contact OFF


Forces the contact of the specified timer to OFF.
Command: RS_Tnnn
Timer No.
Response: OK

3-314 Chapter 7 Serial Communication

KVNKA Chap 07.p65 314 08.3.11, 0:11 PM


7.2 Serial Communication

■ Forcing CTC contact OFF


Forces the contact of the specified high-speed counter comparator to OFF.
Command: RS_CTCn
High-speed counter comparator No.
Response: OK

Note 1: Input relays cannot be forced ON/OFF. (Except when special utility relay
2301 is ON.)
Note 2: "_" in commands and responses represents a space.

7.2.5 Other Response Codes


If the command from a computer is an unspecified one, or an error occurs in the KV,
the KV sends back an appropriate response code for the status.

Response
Description Cause Remedy
code
E0 Relay No. • Undefined relay, counter, • Specify a number that is
error timer, DM, CTH, or CTC defined in the KV being
number was specified. used.
• Counter, timer, CTH, or • Check a program, and
CTC number, unused in a specify a number used in
program was specified. the program.

E1 Command • Undefined command was • Check a command.


error transmitted.
• Incorrect command was
specified.
• Command other than "CR" • Transmit "CR" to start
was transmitted before the communications, and then
communications path was transmit a command.
established.
E2 Program When the KV has no program • Register a program into the
unregistered stored, "M1" was transmitted KV.
or reading of timer/counter • Check a program and
content was attempted. specify the number used in
the program.

E3 Base unit Hardware error was detected Turn off the power for the KV, 17
fault in a KV base unit. and then turn it on again. If
the cause of the error is not
removed, the KV may be
faulty. Contact your nearest
KEYENCE office.

E4 Write- Attempt was made to change Write-enable the program,


protected the preset value of a counter, and change the preset value.
timer, or CTC in a write-
protected program.

E5 Base unit "M1" was transmitted before Clear the error message from
error cleaning an error message the KV, and remove the cause
from the KV. of the error.

Chapter 7 Serial Communication


3-315

KVNKA Chap 07.p65 315 08.3.11, 0:11 PM


7.2 Serial Communication

7.2.6 Error Code List


When a "Checking KV PLC error" command (?E) is transmitted, the KV sends back
the error code. The following list shows the description, cause, and remedy for each
error code.

Error code Description Cause Remedy


00 No error
10 CALL nest error Subroutines are nested to four levels These errors may occur when a
or more. program is executed.
11 FOR nest error FOR/NEXT instructions are nested to Check the program while paying
eight levels or more. particular attention to usage of
12 INT nest error Five levels or more of interrupts subroutines and the INT instruction,
occurred simultaneously. and restore the program accordingly.
13 MPS nest error MPS/MPP instructions are nested to
eight levels or more.
Content in RAM was erased. All data Turn the KV off once and turn it on.
20 Memory error in data memory and current values of Register data from the beginning.
counters in the KV were cleared.
Scan time exceeds 300 ms. Check the program again.
• Be sure that there is no excessive
30 Scan timer error repetition using the FOR/NEXT loop.
• Be sure that an interrupt is not
executed at a higher rate.
Attempt was made to operate a KV Write a program into KV.
40 NO PROGRAM base unit which has no programs
stored.
50 SND/RTN failure Hardware error was detected in a KV Turn off the power for the KV, and
51 Division by zero base unit. then turn it on again. If the cause of
the error is not removed, the KV may
52 Address error
be faulty. Contact your nearest
53 Invalid instruction KEYENCE office.
54 Watchdog timer error

3-316 Chapter 7 Serial Communication

KVNKA Chap 07.p65 316 08.3.11, 0:11 PM


7.2 Serial Communication

7.2.7 Example Program


Typical program for communications between the KV and a personal computer (For
IBM PC-AT & compatible computers using BASIC)


‘Language Microsoft BASIC Version 7.0

‘ *****I/OAddress (RS-232C Port-1)*****
‘Port-1&H3F*
‘Port-2&H2F*

PortCtrl%=&H3FB’COM1
Port1Modem%=&H3FC’MODEMCtrl
PortBpsLow%=&H3F8’BitrateLow
PortBpsHigh%=&H3F9’BitrateHigh
‘*****ControlCode*****
Port1CtrlCode1%=&H5B’Break&8bitEven1Stopbit
Port1CtrlCode2%=&H1B’8bitEven1Stopbit
‘*****InitializesRS-232C***** Note: No parity check is specified due to the
OPEN"COM1:9600,N,8,1"FORRANDOMAS#1' limitations of the version of BASIC being used.
‘*****RS-232CPortInit*****
OUTPortCtrl %,Port1CtrlCode1%’Start transmitting a break signal
SLEEP1’wait 1 sec.
OUTPortCtrl%,Port1CtrlCode2%’Ends transmitting a break signal

‘-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
‘’’’’’’’’’’’*****DebugPrint*****
‘’’’’’’’’’’status=INP(&H3FE):PRINT"ModemStatus1";status
‘’’’’’’’’’’status=INP(&H3FD):PRINT"LineStatus1";status
‘’’’’’’’’’’’
‘’’’’’’’’’’’*****SelfInit.*****
‘’’’’’’’’’’linectrl=INP(PortCtrl%)’ReadLine-Control-Register
‘’’’’’’’’’’linectrl=linectrlOR&H80'
‘’’’’’’’’’’OUTPortCtrl%,linectrl’DLAB=ON
‘’’’’’’’’’’
‘’’’’’’’’’’OUTPortBpsLow%,12’SetBitRate(9600BPS)
‘’’’’’’’’’’OUTPortBpsHigh%,0'
‘’’’’’’’’’’
‘’’’’’’’’’’linectrl=linectrlAND&H7F’DLAB=OFF
‘’’’’’’’’’’OUTPortCtrl%,linectrl
‘’’’’’’’’’’’
‘’’’’’’’’’’’*****CtrlLine*****
‘’’’’’’’’’’OUTPort1Modem%,&HB’RTS,DTRON !!
‘’’’’’’’’’’’
‘’’’’’’’’’’’*****DebugPrint*****
‘’’’’’’’’’’status=INP(&H3FE):PRINT"ModemStatus2";status
‘’’’’’’’’’’status=INP(&H3FD):PRINT"LineStatus2";status
‘-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
‘*********************************************************
17
‘*****Transmitting a command/receiving a response*****
‘*********************************************************
a$=""
WHILEa $>"END"
PRINT"Command>>":
INPUTa$
PRINT#1,a $
b$=""
LINEINPUT#1,b$
PRINT"RsP[";b$;"]"
PRINT
WEND
PRINT"GoodBy!!"
CLOSE#1
END

• Change value in "SLEEP" timer according to your personal computer’s clock


frequency so that value I exceeds 100 ms.
• Set the baud rate of your personal computer to 9600 bits/s.
• Enter END to terminate programming.

Note 1: MS-DOS executable files (KVCOM.EXE) and BASIC source code files
(KVCOM.BAS) are included in the KV Incrediware (DOS) Software (KV-H4E,
version 2.00 or higher).
Note 2: Type in "KVCOM" and press ENTER to call the MS-DOS command line.

Chapter 7 Serial Communication


3-317

KVNKA Chap 07.p65 317 08.3.11, 0:11 PM


7.3 Loading Text Data

7.3 Loading Text Data


The KV can be connected to equipment having an RS-232C port to load consecutive
text data (less than 100 bytes) as a batch into its data memories.
Loaded data can be modified and incorporated into a program.

7.3.1 Receiving Text Data


The KV can write up to 100 bytes of text data sandwiched between STX and ETX,
into internal data memories (DM1000 to DM1099 with communication port A,
DM1200 to DM1299 with communication port B), one byte per data memory in
ASCII code.

Communications data format


Note that each text data must include STX (02H) in the 1st byte followed by the text
(100 bytes max.) and end with ETX (03H) in the last byte as shown below.

1st byte Last byte

STX Text data (less than 100 bytes) ETX

Internal data memory


The KV writes received text data into its data memories (DM1000 to DM1099 with
communication port A, DM1200 to 1299 with communication port B), one byte per
data memory in ASCII code.

NEW PO RT A DM1000 DM1001 DM1002 DM1003 to DM1098 DM1099


Dat a KV PO RT B DM1200 DM1201 DM1202 DM1203 to DM1298 DM1299
memory
KV- 300
DM9200 DM9201 DM9202 DM9203 to DM9298 DM9299
KV- 10/ 80
Dat a No. Byte count Data 1 Data 2 Data 3 to Data 98 Data 99

The KV writes "00" into the high-order 8 bits and text data in ASCII code into the
low-order 8 bits of the data memory.
7
Byte count of data

Received data STX Data 1 Data 2 Data 3 Data 99 ETX

1st DM
Data memory (Byte count of data) 2nd DM 3rd DM 4th DM 100th DM

15 00

Bits in 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1
data memory
High-order 8 bits (00) Low-order 8 bits (ASCII code)

Note: The KV-10xx includes only communication port A.

Special utility relay operation


Three special utility relays assigned for each channel turn on for one scan to
indicate that text data has been received or that data reception has failed.

3-318 Chapter 7 Serial Communication

KVNKA Chap 07.p65 318 08.3.11, 0:11 PM


7.3 Loading Text Data

Relay No. Relay No. Relay No.


Descript ion
( PO RT A) ( PO RT B) ( KV- 300/ 10/ 80)
Turns ON for one scan when text data
2801 2806 2804
has been received.
Turns ON for one scan when text data
2802 2807 2805 has been received while 2801 is ON,
or when 2803 is ON.
Turns ON for one scan when text data
2803 2808 2806
reception has failed.

Note 1: Be sure to transmit a break signal for the first serial communication with a
personal computer after the KV-P3E(01) handheld programmer is connected to the
KV, or after the "KV IncrediWare (DOS)" or "LADDER BUILDER for KV" program-
ming support software is evoked.
A break signal initializes the communication setting for the KV. If you cannot transmit
a break signal, turn the KV OFF once to initialize the communication setting. The KV
will not receive text data unless its communication setting has been initialized.
Note 2: If [ETX] exists at some point in the text data, the KV writes the data before
[ETX] into the data memory. The data after [ETX] is not written.
Note 3: If KV receives text data while special utility relay 2804 (2809)*1 is ON, the
received data is not written into the data memory. In this case, special utility relay
2802 (2807)*2 turns ON for one scan.
Note 4: When parity errors or other errors occur during text data reception, the
received data is not written into the data memory. In this case, special utility relays
2802 (2807) and 2803 (2808)*3 turn ON for one scan.
Note 5: The KV-10xx includes only communication port A.
*1: 2804 with KV-300/10/80 *2: 2805 with KV-300/10/80 *3: 2806 with KV-300/10/80

7.3.2 Transmitting Text Data


The KV transmits text data written into its data memories (DM1100 to DM1199 for
communication port A, DM1300 to DM1399 for communication port B), one byte per
data memory in ASCII code.

Transmission data format and internal data memories


When transmitting data from the KV, write the data into the data memory in the
following format. 17
PO R T A DM1100 DM1101 DM1102 DM1103 to DM1198 DM1199
Dat a PO R T B DM1300 DM1301 DM1302 DM1303 to DM1398 DM1399
memory
KV- 300/
DM9300 DM9301 DM9302 DM9303 to DM9398 DM9399
10/ 80
Dat a No. Byte count Data 1 Data 2 Data 3 to Data 98 Data 99

The KV writes "00" into the high-order 8 bits and text data in ASCII code into the
low-order 8 bits of the data memory.

High-order 8 bits (00) Low-order 8 bits (ASCII code)

15 00

Data memory bits 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1

Data memory 1st DM


(Byte count of data) 2nd DM 3rd DM 4th DM 100th DM

Transmitted data Data 1 Data 2 Data 3 Data 99

Note: The KV-10xx includes only communication port A.

Chapter 7 Serial Communication


3-319

KVNKA Chap 07.p65 319 08.3.11, 0:11 PM


7.3 Loading Text Data

Special utility relay operation


Two special utility relays are assigned for each channel for data transmission. Text
data or a break signal is transmitted when the respective relay is turned ON/OFF.
Relay No. Relay No. Relay No.
Description
(Port A) (Port B) (KV-300/10/80)
Starts/stops transmitting text data.
2804 2809 2807
ON: Start, OFF: Stop
Starts/stops transmitting break signal.
2800 2805 2803
ON: Start, OFF: Stop

Note 1: Be sure to transmit a break signal for the first serial communication with a
personal computer after the KV-P3E(01) handheld programmer is connected to the
KV, or after the "KV IncrediWare (DOS)" or "LADDER BUILDER for KV" program-
ming support software is evoked.
A break signal initializes the communication setting for the KV. If you cannot transmit
a break signal, turn the KV OFF once to initialize the communication setting.
The KV will not transmit/receive text data unless its communication setting has been
initialized.
Note 2: Turn ON special utility relay 2804 (2809) (SET 2804 [2809])*1 to transmit text
data. Special utility relay 2804 (2809)*1 remains ON during text data transmission,
and automatically turns OFF when the transmission completes.
To forcefully stop the text data transmission, turn OFF special utility relay 2804
(2809) (RES 2804 [2809])*1.
Note 3: A break signal is transmitted while special utility relay 2808*2 is turned ON.
Use the SET-RES instruction pair or OUT-OUB instruction pair to control a break
signal. The communication program of the destination KV is initialized after a break
signal has been transmitted.
*1: 2807 with KV-300/10/80 *2: 2803 with KV-300/10/80

7.3.3 Sample Program


The following is the sample program to transmit/receive text data using communica-
tion port A on the KV basic unit.
Data to be transmitted: KEYENCE
Transmission header: STX
Transmission delimiter: ETX
7 Length of received data: Fixed to 7 bytes

0001 Sends break signal (1 sec.).


2008 T000 2800 When power is turned ON,
0002
One scan ON transmits a break signal for
2800 #00010 one second during the first
0003 T000
Break signal scan.
0004 Transmits text data ("STX KEYENCE ETX").
0000 1001 1001 #00009 $0002 $004B $0045 $0059 $0045 Transmits text data when
0005 DIFU DW DW DW DW DW DW
Transmission DM1100 DM1101 DM1102 DM1103 DM1104 DM1105 input relay 0000 turns ON.
start relay No. of STX K E Y E
0006 transmitted
data
$004E $0043 $0045 $0003 2804
0007 DW DW DW DW SET
DM1106 DM1107 DM1108 DM1109 Trans-
N C E ETX mission
0008 Receives text data. relay

2801 DM1000 DM1001 DM1002 DM1003 DM1004 DM1005 DM1006 DM1007


0009 LDA LDA LDA LDA LDA LDA LDA LDA Receives text data.
Reception relay No. of Received Received Received Received Received Received Received data
2803 T001 received data. data data data data data data 0500
0010 Turns ON output relay 0500
Reception error for 3 seconds when
0500 #00030
0011 T001 reception error occurs.

END
0012

ENDH
0013

3-320 Chapter 7 Serial Communication

KVNKA Chap 07.p65 320 08.3.11, 0:11 PM


7.4 ASCII Code List

7.4 ASCII Code List


The following are the ASCII code characters used for data transmission.

High-order 4 bits

0 1 2 3 4 5 6 7 8 9
0
1
2
3
4
5
Low-order 4 bits

6
7
8
9
A
B
C
D
17
E
F

Characters in the shaded area can be used for data transmission with the KV.
[STX], [ETX], [LF], and [CR] are used as data delimiters.
Only use characters in the shaded area because the other characters are used for
control purposes.

Chapter 7 Serial Communication


3-321

KVNKA Chap 07.p65 321 08.3.11, 0:11 PM


7.4 ASCII Code List

3-322 Chapter 7 Serial Communication

KVNKA Chap 07.p65 322 08.3.11, 0:11 PM


Chapter 8
Programming Examples
This chapter describes the typical programming examples for KV-300, KV-10/80
Series. These programs can be used for Visual KV Series. However, pay attention
to the I/O addressing compatibility before use.

8.1 List ....................................................................................................... 3-324


8.2 Details ................................................................................................. 3-326
8.2.1 Reference Program Examples ............................................................... 3-326

KVNKA Chap 08.p65 323 08.3.11, 0:12 PM


8.1 List

8.1 List
Instruction Program title Reference
Page
TMR, TMH, TMS [Timers] One-shot circuit 3-326
Off-delay circuit 3-326
On-delay circuit 3-327
Flicker circuit 3-327
C [Counter] Accumulator timer 3-327
Large capacity counter 3-328
Multi-level Up/Down counter 3-328
Counter multi-level setting 3-328
DIFU, DIFD One-shot circuit 3-329
KEEP Detection of packs on conveyor 3-329
SFT Alternating circuit 3-330
Repeat shift circuit 3-331
Asynchronous shift register 3-331
Resetting internal utility relays 3-332
HSP High-speed fetching of input data 3-332
MC-MCR Emergency stop circuit 3-333
W-UE Input sequence check 3-334
Fork lift truck IN/OUT judgement 3-334
STG-JMP Enabling double coil 3-335
Conditional branching 3-335
STP-STE Process progression 3-336
ITVL Pulse interval measurement 3-336
Fetching data from KV-AN6 3-337
CTH [High-speed counter] High-speed counter multi-level setting 3-338
High-speed counter current value clear 3-339
Input of phase differential signal 3-339
SBN [Sub-routine] DM shift 3-340
FOR-NEXT Transfer of a block of DM data 3-341
HKEY Fetching 16-key input 3-342
TMIN [Analog timer] Changing timer setting value 3-343

8 Changing setting values of multiple timers 3-343


LDA/STA First-in first-out (FIFO) 3-343
Changing the counter setting value 3-345
Changing the timer setting value 3-345
CMP Comparing values with no specific range 3-345
Setting the upper/lower limit 3-345
Changing the CMP setting value 3-346
Multi-level comparator 3-346
ADD Adding BCD and BIN(binary) values 3-347
Total count 3-348
SUB Comparison of absolute values 3-348
MUL Multiplying the counter current value by DM value 3-349
DIV Total count average 3-349
ANDA BCD (1-digit) input 3-350
Fetches input data separately 3-350
ORA Output of 2-digit BCD data 3-351
Separate input of 2-digit BCD 3-351

3-324 Chapter 8 Programming Examples

KVNKA Chap 08.p65 324 08.3.11, 0:12 PM


8.1 List

Instruction Program title Reference


Page
EORA Judgement of matcing data 3-352
SRA/SLA Separate input of BCD 3-352
RRA/RLA Error input count 3-353
INC/DEC Total count 3-353
Up/Down count 3-354
MPX Display of 7-segment LED 3-355
DMX Output of error input No. in BCD 3-356
TBCD Output of 4-digit BCD data 3-356
Output of 8-digit BCD data 3-356
TBIN Output of 4-digit BCD data 3-357

18

Chapter 8 Programming Examples 3-325

KVNKA Chap 08.p65 325 08.3.11, 0:12 PM


8.2 Details

8.2 Details
8.2.1 Reference Program Examples
Basic Instructions
Applications of TMR, TMH, and TMS Instructions ➮ Refer to p. 3-67 to p. 3-71.
■ One-shot circuit
When input relay 0000 turns ON, output relay 0500 turns ON and remains ON for a
specified time.

Timing diagram

0000

0500 2s 2s

Ladder diagram Coding


2-s timer
0000 #00020
Line No. Instruction Operand
T000 0000 LD 0000
0001 OR 0500
0500 T000 00500
0002 TMR 000#00020
0003 ANB T000
0004 OUT 0500

■ 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

0000

8 0500 2s

Ladder diagram Coding


0000 T000 0500 Line No. Instruction Operand
0000 LD 0000
0500 00000 #00020 0001 OR 0500
T000 0002 ANB T000
2-s timer 0003 OUT 0500
0004 ANB 0000
0005 TMR 000 #00020

3-326 Chapter 8 Programming Examples

KVNKA Chap 08.p65 326 08.3.11, 0:12 PM


8.2 Details

■ 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

0000

0500
2s 1s

Ladder diagram Coding

2-s timer Line No. Instruction Operand


0000 #00020 0000 LD 0000
T000 0001 TMR 000 #00020
T000 0500 0002 LD T000
0003 OUT 0500

■ Flicker circuit
Output relay 0500 turns ON and OFF repeatedly while input relay 0000 is ON.

Timing diagram

0000 1s 1s

0500
2s 2s

Ladder diagram Coding


2-s timer
Line No. Instruction Operand
0000 T001 #00020
T000 0000 LD 0000
T000 1-s timer
#00010 0001 ANB T001
T001 0002 TMR 000 #00020
0500 0003 LD T000
0004 TMR 001 #00010
0005 OUT 0500 18
■ Accumulator timer (Remains ON in case of power failure)
Counts special utility relay 2006 (1-s clock pulse) for 3600 s at C001 and inputs the
count value to C002. Accumulates the count for 10000 hours and retains the current
count value even when power failure occurs or power is OFF.
Input relay 0000
Reset relay 0001
(Resolution is 1 s at 2006.)

Ladder diagram Coding


0000 C001 3600-s counter Line No. Instruction Operand
#03600
C001 0000 LD 0000
2006 0001 ANB C001
C001 1-s pulse 1000
0002 C 001 #03600 2006
0001 10000-s counter 0003 LD C001
#10000
C002
0004 OUT 1000
1000
0005 LDB 0001
0006 C 002 #10000 1000

Chapter 8 Programming Examples 3-327

KVNKA Chap 08.p65 327 08.3.11, 0:12 PM


8.2 Details

■ Large capacity counter


Accumulates 1 count to C001 for every 10000 counts by C000. This example can
count up to 655350000.
Count input relay 0000
Reset relay 0001

Ladder diagram Coding


0001 C000 #10000 Line No. Instruction Operand
C000 0000 LDB 0001
0000
C000 1000 0001 ANB C000
0002 C 000 #10000 0000
0001 #65535 0003 LD C000
C001
1000 0004 OUT 1000
0005 LDB 0001
0006 C 001 #65535 1000

■ Multi-level UP/DOWN counter


UP/DOWN counter which allows the count setting value up to 99,990,000.
• UP input relay: 0001
• DOWN input relay: 0002
• Reset input relay: 0003

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.
0004 C000 8500
LDA TBCD STA Low-order
4 digits
C001 8600
LDA TBCD STA High-order
4 digits
Ladder diagram Coding
0001 UDC000
Line No. Instruction Operand
UP BCD:
0002 #09999 Low-order 0000 LD 0001
4 digits
DW 0001 LD 0002
0003 0002 LD 0003
RES
0003 UDC 000 #09999
C000 0001 UDC001 0004 LD C000
UP BCD:
High-order 0005 AND 0001
C000 0002 #09999
4 digits 0006 LD C000
8 DW
0007 AND 0002
0003
RES 0008 LD 0003
0009 UDC 001 #09999

■ Counter multi-level setting


Outputs in 3 different levels according to the counter current value.
• 00000 to 00999 —> 0500 turns ON.
• 01000 to 01999 —> 0501 turns ON.
• 02000 to 02999 —> 0502 turns ON.

Ladder diagram
0001 #09999
C000
0000
2002 C000 #00999 2011 0500
LDA CMP 00000 to
00999
#01999 2011 0500 0501
CMP 01000 to
01999
#02999 2011 0500 0501 0512
02000 to
CMP
02999

3-328 Chapter 8 Programming Examples

KVNKA Chap 08.p65 328 08.3.11, 0:12 PM


8.2 Details

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB 0001 0012 CON
0001 C 000 #09999 0000 0013 ANB 2011
0002 LD 2002 0014 ANB 0500
0003 LDA C000 0015 OUT 0501
0004 CON 0016 MPP
0005 MPS 0017 CMP #02999
0006 CMP #00999 0018 CON
0007 CON 0019 ANB 2011
0008 ANB 2011 0020 ANB 0500
0009 OUT 0500 0021 ANB 0501
0010 MRD 0022 OUT 0502
0011 CMP #01999

Application of DIFU, DIFD Instructions


■ One-shot circuit using differentiate instruction
When input relay 0000 turns ON/OFF, output relay 0500 and 0501 turns ON one-
shot (1 second).

Timing diagram
0000
1000
1001
0500 1S
0501 1S
Ladder diagram Coding
0000 1000 Line No. Instruction Operand
DIFU 0000 LD 0000
1001 0001 DIFU 1000
DIFD 0002 DIFD 1001
1000 T001 0500 0003 LD 1000
0004 OR 0500
0500 #00010
0005 ANB T001
T001
0006 OUT 0500
1001 T002 0501
0007 TMR 001 #00010
0008 LD 1001
0501 #00010
T002 0009 OR 0501 18
0010 ANB T002
➮ Refer to p. 3-78. 0011 OUT 0501
0012 TMR 002 #00010

Application of KEEP instruction


■ 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).
Reflector (R-2)
ing ck
ew
Ch m pa
gu
ing ck
ew
Ch m pa Proximity Switch ES Series
gu

ON OFF ON

ES Series
Gum Gum
Gum Gum Gum
Gum Gum Gum
PZ2-61

Chapter 8 Programming Examples 3-329

KVNKA Chap 08.p65 329 08.3.11, 0:12 PM


8.2 Details

Timing diagram

0000

0001

0002

0003

0500 1s

Ladder diagram
0000 0001 0002 0003 KEEP
Excecutes SET when
SE T all input relays 0000 to
1000 0003 are ON.
1001
RES
0000 1001 Detects presence/absence
DIFD of chewing gum packs at
DOWN edge of 0000.
1001 1000 T001 0500

Outputs 1-s one-shot pulse


0500 #00010 from output relay 0500
when 1000 is OFF.
T001

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
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
➮ Refer to p. 3-80.

8 Applications of SFT instruction


■ Alternating circuit
Every time input relay No. 0000 turns ON, 0500 turns alternately ON and OFF.

Timing diagram

0000

0500

Ladder diagram Coding


1000 SFT Line No. Instruction Operand
D
1000 0000 LDB 1000
0000
CLK 0001 LD 0000
2003 1000 0002 LD 2003
RES
0003 SFT 1000 1000
1000 0500
0004 LD 1000
0005 OUT 0500
➮ Refer to p. 3-82.

3-330 Chapter 8 Programming Examples

KVNKA Chap 08.p65 330 08.3.11, 0:12 PM


8.2 Details

■ 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 7500 to 7504 every second at T001.
When 1005 turns ON, 1000 is set and the same sequence as above repeats.

Ladder diagram Coding


2008 1000 Line No. Instruction Operand
SET
#00010 0000 LD 2008
T001
T001 0001 SET 1000
2003 SFT 0002 LDB T001
D
0003 T001 #00010
1000
T001
CLK
0004 LD 2003
2003 1005 0005 LD T001
RES 0006 LD 2003
1000 7500 0007 SFT 1000 1005
0008 LD 1000
1001 7501
0009 OUT 7500
1002 7502 0010 LD 1001
0011 OUT 7501
1003 7503
0012 LD 1002
1004 7504 0013 OUT 7502
0014 LD 1003
1005 1000
SET 0015 OUT 7503
0016 LD 1004
0017 OUT 7504
0018 LD 1005
0019 SET 1000
■ Synchronous 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.

Timing diagram

0001
0000
1000
1001 18
1002
.
.
.
Ladder diagram Coding
0000 1100 Line No. Instruction Operand
DIFU
0000 LD 0000
1100 1000
SET 0001 DIFU 1100
2003 SFT 0002 LD 1100
D
1000 0003 SET 100
0001
CLK 0004 LD 2003
0002 1010 0005 LD 0001
RES
0006 LD 0002
0007 SFT 1000 1010

Chapter 8 Programming Examples 3-331

KVNKA Chap 08.p65 331 08.3.11, 0:12 PM


8.2 Details

■ 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.

Ladder diagram Coding


2003 SFT
D Line No. Instruction Operand
2003 1000 0000 LD 2003
CLK 0001 LD 2003
0000 1915
RES
0002 LD 0000
0003 SFT 1000 1915

Applications of HSP instruction


■ High-speed fetching of input data
When the input signal at 0000 has pulses of 5-ms interval 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.

Timing diagram
0000

0001

0500 1s

Ladder diagram Coding


0001
HSP
Line No. Instruction Operand
0000 0000 LD 0001
1-s timer
0000 #00010 0001 HSP 0000
T000 Outputs 0002 LD 0000
1-s one-shot
0500 T000 0500 pulse from 0003 OR 0500
output relay 0004 TMR 000 #00010
0500.
0005 ANB T000
0006 OUT 0500

* To input a signal having pulse interval shorter than the scan time, use the inter-
8 rupt instruction. ➮ Refer to p. 3-192.

■ When using the interrupt instruction


Ladder diagram
Turn ON for 1st scan only at startup.
2008
EI Interrupt enabled
Initial settings
2813
Input time constant
SET 10 µs
0500 #00010
Turns ON timer for
T000 1s when 0500 is ON.
T000 0500
RES Resets 0500 when
T000 turns ON.
END

I NT Sets interrupt input


0000 at 0000.
2002 0500 Sets 0500 when
SET 0000 turns ON.

RET I

ENDH

3-332 Chapter 8 Programming Examples

KVNKA Chap 08.p65 332 08.3.11, 0:12 PM


8.2 Details

Coding
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 RETI
0005 LD T000 0012 ENDH
0006 RES 0500
➮ Refer to p. 3-86.

Application of MC-MCR instruction


■ 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


Line No. Instruction Operand
0000 0000 LD 0000
0001 OUT 1000
0001 0002 CON
0002
0003 OUB 1001
0004 LD 0000
0003 0005 DIFU 1002
0006 CON
0500
0007 AND 1002
0501 0008 SET 1100
0009 CON
0502 0010 RES 1101
0011 CON
Ladder diagram 0012 RES 1102
0000 1000 1001 0013 LD 1000
0001 0014 MC
0000 1002 1002
0015 STG 1100
1100 1101 1102
0002 DIFU SET RES RES 0016 OUT 1200
0017 CON
1000 MC 0018 TMR 000 #00010
0003
0019 CON
1100 1200 #00010 T000 1101 0020 AND T000
0004 STG T000 JMP
0021 JMP 1101
1101 1201 #00020 T001 1102 0022 STG 1101
0005 STG T001 JMP
0023 OUT 1201
1102 1202 #00030 T002 1100 0024 CON
0006 STG T002 JMP 0025 TMR 001 #00020
MCR 0026 CON
0007 0027
0028
AND
JMP
T001
1102
18
1001 MC
0008 0029 STG 1102
0030 OUT 1202
0001 1203
0009 0031 CON
0032 TMR 002 #00030
0002 1204 0033 CON
0010
0034 AND T002
0003 1205 0035 JMP 1100
0011
0036 MCR
MCR 0037 LD 1001
0012 0038 MC
1200 0500 0039 LD 0001
0013 0040 OUT 1203
1203 0041 LD 0002
0014 0042 OUT 1204
1201
0043 LD 0003
0501
0015 0044 OUT 1205
0045 MCR
1204
0016
0046 LD 1200
0047 OR 1203
1202 0502 0048 OUT 0500
0017
0049 LD 1201
1205 0050 OR 1204
0018 0051 OUT 0501
END 0052 LD 1202
0019 0053 OR 1205
ENDH 0054 OUT 0502
0020 0055 END
0056 ENDH

Chapter 8 Programming Examples 3-333

KVNKA Chap 08.p65 333 08.3.11, 0:12 PM


8.2 Details

Application Instructions
Application of W-UE instruction
■ 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.

Timing diagram
0000
0001
0002
0003
0500

Ladder diagram Coding


0000 0001
Line No. Instruction Operand
1000 0000 LD 0000
1000 0002
0001 W-UE 0001 1000
1001 0002 LD 1000
1001 0003
0003 W-UE 0002 1001
1002 0004 LD 1001
1002 0500
0005 W-UE 0003 1002
0006 LD 1002
0007 OUT 0500

■ 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.

Timing diagram

0000
0001
0500
0501
8
Ladder diagram Coding

0000 0001 1000 0500 Line No. Instruction Operand


Leave 0000 LD 0000
1000 warehouse
0001 W-UE 0001 1000
0001 0000 1001 0501
Enter 0002 CON
1001 warehouse
0003 AND 1000
0004 OUT 0500
0005 LD 0001
0006 W-UE 0000 1001
0007 CON
0008 AND 1001
0009 OUT 0501

3-334 Chapter 8 Programming Examples

KVNKA Chap 08.p65 334 08.3.11, 0:12 PM


8.2 Details

Application of STG-JMP instruction


■ Enabling double coil
When start SW 0000 is pressed, output relay 0500 turns ON for 1 s, then output
relays 0500 and 0501 turn ON for 2 s, and then output relays 0500, 0501, and 0502
turn ON for 3 s. The above sequence repeats.

Ladder diagram
0000 1100 1100 1000
DIFU SET Turns ON 1000 when input relay 0000 turns ON.

1000 0500 #00010 T000 1001


STG T000 JMP Output relay 0500 turns ON for 1 s.

1001 0500 0501 #00020 T001 1002


STG T001 JMP Output relays 0500 and 0501 turn ON for 2 s.

1002 0500 0501 0502 #00030 T002 1000


STG T002 JMP Output relays 0500, 0501 and 0502 turn ON for 3 s.

Coding
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

The double coil operates normally through different STG instructions. If


CAUTION different STG instructions turn ON simultaneously, the latter programmed
instruction has the priority. 18
■ Conditional branching
When input relay 0000 (start SW) turns ON, output relay 0500 turns ON. Then, as
programmed for conditional branching, output 0501 turns ON for 1 s when 0001
turns ON or 0502 turns ON for 2 s when 0002 turns ON. After either one of the
processes is completed, the program returns to the conditional branching and
repeats the same steps.

Ladder diagram
0000 1100 1100 1000
DIFU SET
1000 0500 0001 1001
STG JMP
0002 1002
JMP
1001 0501 #00010 T000 1000
STG T000 JMP
1002 0502 #00020 T001 1000
STG T001 JMP

Chapter 8 Programming Examples 3-335

KVNKA Chap 08.p65 335 08.3.11, 0:12 PM


8.2 Details

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0000 0014 OUT 0501
0001 DIFU 1100 0015 CON
0002 CON 0016 TMR 000 #00010
0003 AND 1100 0017 CON
0004 SET 1000 0018 AND T000
0005 STG 1000 0019 JMP 1000
0006 OUT 0500 0020 STG 1002
0007 MPS 0021 OUT 0502
0008 AND 0001 0022 CON
0009 JMP 1001 0023 TMR 001 #00020
0010 MPP 0024 CON
0011 AND 0002 0025 AND T001
0012 JMP 1002 0026 JMP 1000
0013 STG 1001

Application of STP-STE instruction


■ Process progression
When input relay 0000 turns ON, output relay 0500 automatically turns ON for 2 s,
and then 0501 turns ON for 3 s.

Ladder diagram Coding


0000 1000 1000 1001
0001 DIFU SET Line No. Instruction Operand
STP 0000 LD 0000
0002 1001
T000
0001 DIFU 1000
1001
0003 RES 0002 CON
T000 0500
0004
0003 AND 1000
1001 #00020 0004 SET 1001
0005 T000
0005 STP 1001
T000 1002
0006 SET 0006 LD T000
STE 0007 RES 1001
0007

STP
0008 LDB T000
0008 1002
0009 OUT 0500
T001 1002
0009 RES 0010 LD 1001
T001 0501 0011 TMR 000 #00020
0010
1002 #00030
0012 LD T000
0011 T001 0013 SET 1002
8 0012
STE
0014 STE
END 0015 STP 1002
0013
0016 LD T001
ENDH
0014 0017 RES 1002
0018 LDB T001
0019 OUT 0501
0020 LD 1002
* The double coil operates normally 0021 TMR 001 #00030
across different STP instructions. 0022 STE
➮ Refer to p. 3-114. 0023 END
0024 ENDH

Application of ITVL instruction


■ Pulse interval measurement
Measures the pulse interval of input relay 0000 and writes the measured data into
DM0100 (in units of 10 ms).
• Mode No. ➞ 1 (DM0000)
• MAX. setting value ➞ 51 (DM0001)
• MIN. setting value ➞ 49 (DM0002)
• Average number of measurements ➞ 10 (DM0003)

3-336 Chapter 8 Programming Examples

KVNKA Chap 08.p65 336 08.3.11, 0:12 PM


8.2 Details

Reset input relay 0002


Output relay 0500 turns ON
when the pulse interval is not within the range from 490 to 510 mm.
Measure the pulse interval

ON
OFF 500ms

Ladder diagram
2008 #00001 DM0000
LDA STA Sets mode 1 in DM0000.

2008 #00051 DM0001


LDA STA Sets MAX. setting value (510 ms) in DM0001.

2008 #00049 DM0002


LDA STA Sets MIN. setting value (490 ms) in DM0002.

2008 #00010 DM0003


LDA STA Sets the average number of measurements (10) in
DM0003.
0000 ITVL
Measures the pulse interval when input relay 0000
PLS
turns ON.
DM0000
0001 Pauses measurement when input relay 0001 turns
PAUSE
ON.
0002 1000
Resets measurement when input relay 0002 turns
RES ON.

1002 DM0007 DM0100 0500 Writes the average measurement value into
LDA STA RES DM0100 and resets 0500 after every time a
measurement is completed.
1000 0500
SET Turns On output relay 0500 when the pulse
interval is not within the range from 490 to 510
mm.
1001

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0015 STA DM0003
0001 LDA #00001 0016 LD 0000
0002 CON 0017 LD 0001 18
0003 STA DM0000 0018 LD 0002
0004 LD 2008 0019 ITVL DM0000 1000
0005 LDA #00051 0020 LD 1002
0006 CON 0021 LDA DM0007
0007 STA DM0001 0022 CON
0008 LD 2008 0023 STA DM0100
0009 LDA #00049 0024 CON
0010 CON 0025 RES 0500
0011 STA DM0002 0026 LD 1000
0012 LD 2008 0027 OR 1001
0013 LDA #00010 0028 SET 0500
0014 CON

■ Fetching data from the KV-AN6 (For KV-300 PLC only)


Fetches data from Ch 1 of the KV-AN6. Writes this data value into DM0100.
• Mode No. ➞ 9000 (DM0000) from Ch 1 of KV-AN6
• MAX. setting value ➞ 2000 (DM0001)
• MIN. setting value ➞ 00900 (DM0002)
• Average number of measurements ➞ 10 (DM0003)
Reset input relay 0002

Chapter 8 Programming Examples 3-337

KVNKA Chap 08.p65 337 08.3.11, 0:12 PM


8.2 Details

Ladder diagram Coding


2008 #09000 DM0000 Line No. Instruction Operand
LDA STA 0000 LD 2008
0001 LDA #09000
2008 #02000 DM0001 0002 CON
LDA STA 0003 STA DM0000
0004 LD 2008
2008 #00900 DM0002 0005 LDA #02000
LDA STA 0006 CON
0007 STA DM0001
2008 #00010 DM0003 0008 LD 2008
LDA STA 0009 LDA #00900
0010 CON
2003 ITVL 0011 STA DM0002
PLS
0012 LD 2008
DM0000
0001 0013 LDA #00010
PAUSE 0014 CON
1000 0015 STA DM0003
0002
RES 0016 LD 2003
0017 LD 0001
DM0007 DM0100 0018 LD 0002
1003
LDA STA 0019 ITVL DM0000 1000
0020 LD 1003
0021 LDA DM0007
➮ Refer to p. 3-117. 0022 CON
0023 STA DM0100
Applications of High-speed counter
■ High-speed counter multi-level setting
Sets the high speed counter comparator value of the input relay 0005 as below:
• #0100 ➞ DM0000
• #0200 ➞ DM0001
• #0300 ➞ DM0002
When a comparator value is greater than the setting value:
• DM0000 ➞ 0500 turns ON.
• DM0001 ➞ 0501 turns ON.
• DM0002 ➞ 0502 turns ON.
Ladder diagram Coding
2008 2813 #01000 DM0000 #02000 DM0001 #03000 DM0002 Line No. Instruction Operand
SET LDA STA LDA STA LDA STA 0000 LD 2008
0001 SET 2813
0001 CTH1 0002 CON
8 00005 0003
0004
LDA
CON
#01000
2002 CTH1 DM0000 2009 0500
0005 STA DM0000
LDA CMP
0006 CON
DM0001 2009 0501 0007 LDA #02000
CMP 0008 CON
0009 STA DM0001
DM0002 2009 0502 0010 CON
CMP 0011 LDA #03000
0012 CON
0013 STA DM0002
0014 LDB 0001
0015 CTH1 0005
0016 LD 2002
0017 LDA CTH1
0018 MPS
0019 CMP DM0000
0020 ANB 2009
0021 OUT 0500
0022 MRD
0023 CMP DM0001
0024 ANB 2009
0025 OUT 0501
0026 MPP
0027 CMP DM0002
0028 ANB 2009
0029 OUT 0502

3-338 Chapter 8 Programming Examples

KVNKA Chap 08.p65 338 08.3.11, 0:12 PM


8.2 Details

■ High-speed counter current value clear


Counts pulses at input relay 0005. When the count value reaches setting value
60000, clears the current value of high speed counter CTH1 and turns ON output
relay 0502 for 3 s.

Ladder diagram Coding


2008 2813 2203 CTH1 Line No. Instruction Operand
SET SET RES 0000 LD 2008
2002 CTH1
0001 SET 2813
0005 0002 CON
#60000 0003 SET 2203
CTC2 0004 CON
0005 RES CTH1
CTC2 0502 #00030 T001 CTC2 0502
T001 RES RES
0006 LD 2002
0007 CTH1 0005
0008 CTC2 #60000
0009 LD CTC2
0010 OUT 0502
0011 CON
0012 TMR 001 #00030
0013 CON
0015 AND T001
0016 RES CTC2
0017 CON
0018 RES 0502
■ Input of phase differential signal
Inputs phase differential signals to input relays 0004 and 0006 and counts pulses at
CTH0.
Writes the count value into DM0000.
When high speed counter CTH0 reaches 60000, clears the current value of CTH0,
sets output relay 0500, and stops fetching count value to CTH0.
Sets 0008 as external reset.

Ladder diagram
2008 2813 2103 2113 2114 2115 CTH0
EI SET SET SET RES SET RES Initial settings*Note
0500 CTH0
00004
#60000
2002 CTH0 DM0000 CTC0
18
LDA STA
END

INT
CTC0
2002 0500
SET
RETI

ENDH

Note: Initial settings for special utility relays


• Sets input time constant of input relays 0000 to 0009 to 10 µs when 2813 turns
ON.
• Clears the current value of CTH0 when 2103 turns ON and CTC0 is ON.
• Sets CTH0 in the X 2 mode when 2113 is ON and 2114 is OFF.
• Enables external reset (input relay 0008) when 2115 turns ON.

Chapter 8 Programming Examples 3-339

KVNKA Chap 08.p65 339 08.3.11, 0:12 PM


8.2 Details

External reset 0008 is predetermined on hardware even if you do not specify in


CAUTION the program. However, you have to set external reset enable relay 2115 to ON.

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0014 LDB 0500
0001 EI 0015 CTH 1 0004
0002 CON 0016 CTC 0 #60000
0003 SET 2813 0017 LD 2002
0004 CON 0018 LDA CTH0
0005 SET 2103 0019 CON
0006 CON 0020 STA DM0000
0007 SET 2113 0021 END
0008 CON 0022 INT CTC0
0009 RES 2114 0023 LD 2002
0010 CON 0024 SET 0500
0011 SET 2115 0025 RETI
0012 CON 0026 ENDH
0013 RES CTH0

Application of Subroutine CALL


■ DM shift
Shifts the data from current DM to the next DM at UP edge of the synchronous
signal (timing).
As the number of DMs to be shifted increases, the required scan time becomes
longer.

Ladder diagram
0000 1000 1000 #00010 TM02 #00030 TM03 00 Shifts data from
DIFU LDA STA LDA STA CALL DM0010 to DM0030.
Synchoronous Designates the Designates the
signal shift start shift end
DM No. (DM0010). DM No. (DM0030). END

SBN
00
2002 TM03 #00001 TM04 TM02 TM05
LDA ADD STA SUB STA
Shift level FOR
8 TM05
2002 TM03 TM04 #TM03 #TM04
DEC DEC LDA STA The program lines which
Uses the indirect addressing execute the data shift
function to designate DM Nos. are groped as the subroutine.
NEXT

2002 #00000 #TM02


LDA STA
Clears the start DM to #0000
after the data is shifted.
RET

ENDH

3-340 Chapter 8 Programming Examples

KVNKA Chap 08.p65 340 08.3.11, 0:12 PM


8.2 Details

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0000 0021 CON
0001 DIFU 1000 0022 SUB TM02
0002 CON 0023 CON
0003 AND 1000 0024 STA TM05
0004 LDA #00010 0025 FOR TM05
0005 CON 0026 LD 2002
0006 STA TM02 0027 DEC TM03
0007 CON 0028 CON
0008 LDA #00030 0029 DEC TM04
0009 CON 0030 CON
0010 STA TM03 0031 LDA #TM03
0011 CON 0032 CON
0012 CALL 00 0033 STA #TM04
0013 END 0034 NEXT
0014 SBN 00 0035 LD 2002
0015 LD 2002 0036 LDA #00000
0016 LDA TM03 0037 CON
0017 CON 0038 STA #TM02
0018 ADD #00001 0039 RET
0019 CON 0040 ENDH
0020 STA TM04
➮ Refer to p. 3-122.

Application of FOR-NEXT
■ Transfer of a block of DM data
Uses the indirect addressing function to transfer a block of data from DM0000 -
DM0099 to DM0100 - DM0199.

Ladder diagram Coding


SBN Line No. Instruction Operand
01
0000 SBN 01
2002 #0000 TMO2 #00100 TMO3
LDA STA LDA STA 0010 LD 2002
0001 LD 2002
1st DM No. of 1st DM No. of
transfer source transfer destination FOR 0011 LDA #TM02
#00100
Number of DMs to be Transferred. 0002 LDA #0000
2002 #TM02 #TM03 TM02 TM03 0012 CON
LDA STA INC INC
0003 CON 18
NEXT 0013 STA #TM03
0004 STA TM02
RET
0014 CON
0005 CON
Data memory 0015 INC TM02
DM0000 0006 LDA #00100
0016 CON
0007 CON
0017 INC TM03
0008 STA TM03
0018 NEXT
DM0099 Transfer
a block of data 0009 FOR #00100
DM0100
0019 RET

DM0199

➮ Refer to p. 3-125.

Chapter 8 Programming Examples 3-341

KVNKA Chap 08.p65 341 08.3.11, 0:12 PM


8.2 Details

Application of HKEY instruction


■ Fetching 16-key input
Writes the following 16-key input value into DM0000 in 4-digit BCD.
Pressing the keys in the lower line clear the input numerical value.
Wires the 16-key input terminals using 4 outputs and 4 inputs as shown below.

24 VDC COM 000 001 002 003


KV
COM 500 501 502 503 0 1 2 3
4 5 6 7
8 9 A B
C D E F

Ladder diagram
2008 2814
SET
2002 HKEY KEY IN
0000
0500
2815 2900 2010 $03FF TM05 2010 TM05 TM06
LDA ANDA CMP STA DMX STA
2815 2900 2010 $03FF TM05 2010 TM05
LDA ANDA CMP STA

DM0000 #04 TM06 DM0000


Input value
LDA SLA ORA STA (BCD)
2815 2915 #00000
DW Input value
(BCD)
DM0000
END

ENDH

Coding
Line No. Instruction Operand Line No. Instruction Operand
8 0000 LD 2008 0021 AND 2010
0001 SET 2814 0022 ANDA $03FF
0002 LD 2002 0023 CON
0003 HKEY 0000 0500 0024 CMP TM05
0004 LD 2815 0025 CON
0005 LDA 2900 0026 ANB 2010
0006 CON 0027 STA TM05
0007 ANB 2010 0028 CON
0008 ANDA $03FF 0029 LDA DM0000
0009 CON 0030 CON
0010 CMP TM05 0031 SLA #04
0011 CON 0032 CON
0012 ANB 2010 0033 ORA TM06
0013 STA TM05 0034 CON
0014 CON 0035 STA DM0000
0015 DMX 0036 LD 2815
0016 CON 0037 AND 2915
0017 STA TM06 0038 DW #0000 DM0000
0018 LD 2815 0039 END
0019 LDA 2900 0040 ENDH
0020 CON
➮ Refer to p. 3-131.

3-342 Chapter 8 Programming Examples

KVNKA Chap 08.p65 342 08.3.11, 0:12 PM


8.2 Details

Arithmetic Instructions
Applications of TMIN (Analog timer) instruction
■ Changing timer setting value
Uses analog timer (TMIN0) to change the timer setting value (0 to 24.9 s).

Ladder diagram Coding


2002 0 T000 Line No. Instruction Operand
TMIN STA
0000 LD 2002
0000 #00010 0001 TMIN 0
T000
0002 CON
0500 T000 0500
0003 STA T000
0004 LD 0000
0005 OR 0500
0006 TMR 000 #00010
0007 ANB T000
0008 OUT 0500

■ Changing setting values of multiple timers


Uses analog timer (TMIN0) to change setting values of multiple timers (0 to 24.9 s).

Ladder diagram Coding


2002 0 T000 T001 T002 Line No. Instruction Operand
TMIN STA STA STA
0000 LD 2002
0000 #00010 0001 TMIN 0
T000
0002 CON
0500 T000 0500
0003 STA T000
0001
0004 CON
#00010
T001 0005 STA T001
0501 T001 0501 0006 CON
0007 STA T002
0002 #00010 0008 LD 0000
T002 0010 TMR 000 #00010
0502 T002 0502 0011 ANB T000
0012 OUT 0500
0013 LD 0001
0014 OR 0501
0015 TMR 001 #00010 18
0016 ANB T001
0017 OUT 0501
* In the above example, T000, T001, 0018 LD 0002
and T002 have the same setting value. 0019 OR 0502
➮ Refer to p. 3-138. 0020 TMR 002 #00010
0009 OR 0500
0021 ANB T002
0022 OUT 0502

Applications of LDA/STA instruction


■ First-in first-out (FIFO)
DM data flow
OK/NG judgement
DM0000

DM0001

Data shift DM0002

DM0003

DM0004
Unloading timing

Chapter 8 Programming Examples 3-343

KVNKA Chap 08.p65 343 08.3.11, 0:12 PM


8.2 Details

The data once fetched is written into DM0004, DM0003, ..., DM0000 in this order. At
the unloading timing, unload the data from DM0004 and shifts the data value to the
next DM.

The ON/NG judgement and unloading timings can be used in asynchronous pro-
grams.

Ladder diagram
0000 1000 1000 0001 $1111 DM0000
DIFU LDA STA
Transfers $1111 to DM0000.
OK/NG judgement timing OK/NG judgement
0001 $5555 DM0000
LDA STA
Transfers $5555 to DM0000.
2002 DM0004 $0000 2010 DM0003 DM0004 $0000 DM0003
LDA CMP LDA STA LDA STA
2002 DM0003 $0000 2010 DM0002 DM0003 $0000 DM0002
LDA CMP LDA STA LDA STA Compares the DM value to $0000.
If it is equal to $0000, transfers the
2002 DM0002 $0000 2010 DM0001 DM0002 $0000 DM0001 value of the previous DM No. and
then writes $0000 into the current DM No.
LDA CMP LDA STA LDA STA
2002 DM0001 $0000 2010 DM0000 DM0001 $0000 DM0000
LDA CMP LDA STA LDA STA
0002 $0000 DM0004
LDA STA
Unloading timing Transfers $0000 to DM at unloading timing.

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0000 0035 STA DM0003
0001 DIFU 1000 0036 CON
0002 CON 0037 LDA $0000
0003 AND 1000 0038 CON
0004 MPS 0039 STA DM0002
0005 AND 0001 0040 LD 2002
0006 LDA $1111 0041 LDA DM0002
0007 CON 0042 CON
0008 STA DM0000 0043 CMP $0000
0009 MPP 0044 CON
0010 ANB 0001 0045 AND 2010
0011 LDA $5555 0046 LDA DM0001
8 0012 CON 0047 CON
0013 STA DM0000 0048 STA DM0002
0014 LD 2002 0049 CON
0015 LDA DM0004 0050 LDA $0000
0016 CON 0051 CON
0017 CMP $0000 0052 STA DM0001
0018 CON 0053 LD 2002
0019 AND 2010 0054 LDA DM0001
0020 LDA DM0003 0055 CON
0021 CON 0056 CMP $0000
0022 STA DM0004 0057 CON
0023 CON 0058 AND 2010
0024 LDA $0000 0059 LDA DM0000
0025 CON 0060 CON
0026 STA DM0003 0061 STA DM0001
0027 LD 2002 0062 CON
0028 LDA DM0003 0063 LDA $0000
0029 CON 0064 CON
0030 CMP $0000 0065 STA DM0000
0031 CON 0066 LD 0002
0032 AND 2010 0067 @LDA $0000
0033 LDA DM0002 0068 CON
0034 CON 0069 @STA DM0004

3-344 Chapter 8 Programming Examples

KVNKA Chap 08.p65 344 08.3.11, 0:12 PM


8.2 Details

■ Changing the counter setting value


Sets the setting value of counter C000 to DM0000. Reset input is 0005.

Ladder diagram Coding


2002 DM0000 C000 Line No. Instruction Operand
LDA STA 0000 LD 2002
0005 #9999 0001 LDA DM0000
C000
0002 CON
0001
0003 STA C000
0004 LDB 0005
0005 C 000 #9999 0001
■ Changing the timer setting value
Sets the setting value of timer T000 to DM0000. Reset input is 0005.

Ladder diagram Coding


2002 DM0000 T000 Line No. Instruction Operand
LDA STA 0000 LD 2002
0005 #9999 0001 LDA DM0000
T000
0002 CON
0003 STA T000
0004 LDB 0005
0005 T 0000 #9999
➮ Refer to p. 3-140.

Application of CMP (compare) instruction


■ 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.

Ladder diagram Coding


2002 DM000 #01000 2009 0500 Line No. Instruction Operand
LDA CMP DM0000
<#01000 0000 LD 2002
2010 0501
0001 LDA DM0000
DM0000
2011
=#01000 0002 CON
0502
DM0000 0003 CMP #01000
>#01000 0004 MPS 18
0005 AND 2009
0006 OUT 0500
0007 MRD
0008 AND 2010
0009 OUT 0501
0010 MPP
0011 AND 2011
0012 OUT 0502
■ 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.

Ladder diagram
0001 #09999
C001
0000
2002 C001 #01000 2011 0500
LDA CMP C001 ≤ #1000
2002 C001 #02000 2009 0501
LDA CMP C001 ≥ #02000

Chapter 8 Programming Examples 3-345

KVNKA Chap 08.p65 345 08.3.11, 0:12 PM


8.2 Details

Coding
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

■ Changing the CMP setting value


Compares the current value of C000 to the CMP setting value. Sets the CMP setting
value to analog timer TMIN0.
The following example changes the setting value within the range from 0 to 100.
Turns ON 0500 when the C000 value is smaller than the CMP setting value.
Turns ON 0501 when the C000 value is greater than the CMP setting value.

Ladder diagram
2002 0 #00001 #00004 #00010 DM0000
Sets the TMIN setting
TMIN ADD MUL DIV STA range from 0 to 100.
0001 #09999
C000
00000
2002 C000 DM0000 2009 0500
LDA CMP
2009 0501

Coding
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
8 0007 DIV #00010 0018 OUT 0500
0008 CON 0019 MPP
0009 STA DM0000 0020 ANB 2009
0010 LDB 0001 0021 OUT 0501

■ Multi-level comparator
Compares the counter current value according to the following range:
• 0 to 999 → 0500 turns ON.
• 1000 to 1999 → 0501 turns ON.
• 2000 to 2999 → 0502 turns ON.
Counter reset relay 0001
Counter input relay 0000

3-346 Chapter 8 Programming Examples

KVNKA Chap 08.p65 346 08.3.11, 0:12 PM


8.2 Details

Ladder diagram

0001 #09999
C000
0000
2002 C000 #00999 2011 0500
LDA CMP C000 ≤ 00999

#01999 2011 0500 0501


CMP 00999 < C000 ≤ 01999

#02999 2011 0500 0501 0502


01999 < C000 ≤ 02999
CMP

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB 0001 0012 CON
0001 C 000 #09999 0000 0013 ANB 2011
0002 LD 2002 0014 ANB 0500
0003 LDA C000 0015 OUT 0501
0004 CON 0016 MPP
0005 MPS 0017 CMP #02999
0006 CMP #00999 0018 CON
0007 CON 0019 ANB 2011
0008 ANB 2011 0020 ANB 0500
0009 OUT 0500 0021 ANB 0501
0010 MRD 0022 OUT 0502
0011 CMP #01999
➮ Refer to p. 3-146.

Application of ADD instruction


■ Adding BCD and BIN values
Adds a 4-digit BCD input value (7000 to 7015) to the counter current value and
writes the sum into DM0100.

Ladder diagram
2002 7000 DM0000
LDA TBIN STA Converts BCD input value to BIN.
2002 C001 DM0000 DM0100
18
LDA ADD STA Adds converted BIN value to the current value of
C001 and writes the sum into DM0100.
0001 #09999
C001
0000

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0007 LDA C001
0001 LDA 7000 0008 CON
0002 CON 0009 ADD DM0000
0003 TBIN 0010 CON
0004 CON 0011 STA DM0100
0005 STA DM0000 0012 LDB 0001
0006 LD 2002 0013 C 001 #09999 0000

Chapter 8 Programming Examples 3-347

KVNKA Chap 08.p65 347 08.3.11, 0:12 PM


8.2 Details

■ Total count
Writes total count of counters C001 to C003 into DM0100. The total count must be
within 65535.

Ladder diagram
0000 #09999 C001 DM0001
C001 LDA STA Writes C001 current value into DM0001.
0001
0000 #09999 C002 DM0002
C002 LDA STA Writes C002 current value into DM0002.
0002
0000 #09999 C003 DM0003
C003 LDA STA Writes C003 current value into DM0003.
0003
2002 DM0001 DM0002 DM0003 DM0100
LDA ADD ADD STA Writes total count (DM0001 + CM0002 + DM0003) into
DM100.

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB 0000 0013 C 003 #09999 0003
0001 C 001 #09999 0001 0014 CON
0002 CON 0015 LDA C003
0003 LDA C001 0016 CON
0004 CON 0017 STA DM0003
0005 STA DM0001 0018 LD 2002
0006 LDB 0000 0019 LDA DM0001
0007 C 002 #09999 0002 0020 CON
0008 CON 0021 ADD DM0002
0009 LDA C002 0022 CON
0010 CON 0023 ADD DM0003
0011 STA DM0002 0024 CON
0012 LDB 0000 0025 STA DM0100
➮ Refer to p. 3-150.

Application of SUB instruction


■ Comparison of absolute values
Compares the DM0000 value to the DM0001 value and turns ON 0500 when the
difference of the two absolute values is greater than 5.

Ladder diagram
8 2002 DM0000 DM0001 2009 #0005 2009 1000
LDA SUB CMP
2009 DM0001 DM0000 #0005 2009 1001
LDA SUB CMP
1000 0500

1001

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0012 LDA DM0001
0001 LDA DM0000 0013 CON
0002 CON 0014 SUB DM0000
0003 SUB DM0001 0015 CON
0004 MPS 0016 CMP #00005
0005 ANB 2009 0017 CON
0006 CMP #00005 0018 ANB 2009
0007 CON 0019 OUT 1001
0008 ANB 2009 0020 LD 1000
0009 OUT 1000 0021 OR 1001
0010 MPP 0022 OUT 0500
0011 AND 2009
➮ Refer to p. 3-150.

3-348 Chapter 8 Programming Examples

KVNKA Chap 08.p65 348 08.3.11, 0:12 PM


8.2 Details

Application of MUL instruction


■ Multiplying the counter current value by 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.

Ladder diagram Coding


0001 #09999 Line No. Instruction Operand
C001
0000 LDB 0001
0000
2002 C001 DM0000 DM0100 TM00 DM0101 0001 C 001 #09999 0000
LDA MUL STA LDA STA 0002 LD 2002
0003 LDA C001
0005 MUL DM0000
0004 CON
0006 CON
0007 STA DM0100
0008 CON
0009 LDA TM00
0010 CON
0011 STA DM0101
➮ Refer to p. 3-150.

Application of DIV instruction


■ 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 7500 to 7515.

Ladder diagram
0000 #09999 C001 DM0001
Writes the C001 current
C001 LDA STA value into DM0001.
00001
0000 #09999 C002 DM0002
Writes the C002 current
C002 LDA STA value into DM0002.
00002
0000 #09999 C003 DM0003
Writes the C003 current
C003 LDA STA value into DM0003.
00003
2002 DM0001
LDA
DM0002 DM0003
ADD ADD DM0001 DM0002 DM0003
18
2002 #00003 07500 ÷3 → Output to 07500
DIV TBCD STA to 07515 in 4-digit BCD.

Coding

Line No. Instruction Operand Line No. Instruction Operand


0000 LDB 0000 0015 LDA C003
0001 C 001 #09999 0001 0016 CON
0002 CON 0017 STA DM0003
0003 LDA C001 0018 LD 2002
0004 CON 0019 LDA DM0001
0005 STA DM0001 0020 CON
0006 LDB 0000 0021 ADD DM0002
0007 C 002 #09999 0002 0022 CON
0008 CON 0023 ADD DM0003
0009 LDA C002 0024 LD 2002
0010 CON 0025 DIV #00003
0011 STA DM0002 0026 CON
0012 LDB 0000 0027 TBCD
0013 C 003 #09999 0003 0028 CON
0014 CON 0029 STA 7500
➮ Refer to p. 3-150.

Chapter 8 Programming Examples 3-349

KVNKA Chap 08.p65 349 08.3.11, 0:12 PM


8.2 Details

Application of ANDA instruction


■ BCD (1-digit) input
Sets a 1-digit BCD value, which is input to 0000 to 0003, in C000.

Ladder diagram
2002 0000 $000F
Fetches data of 0000 to 0015 and retains data of 0000
LDA ANDA
to 0003 only.
2002 C000
TBIN STA Converts data to BIN and writes it into C000.

7000 #09999
C000 Sets C000.
7001

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0005 TBIN
0001 LDA 0000 0006 CON
0002 CON 0007 STA C000
0003 ANDA $000F 0008 LDB 7000
0004 LD 2002 0009 C 000 #09999 7001

■ Fetches 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 to timer T001.

Ladder diagram
2002 7000 $00FF C000
LDA ANDA TBIN STA Converts data of 7000 to 7007 to BIN and
writes it into C000.
2002 7000 $FF00 #08 T001
LDA ANDA SRA TBIN STA Shifts data to right by 8 bits, converts it to
BIN, and writes it into T001.
0001 #09999
C000 Sets C000.
0000
0001 #09999
T001 Sets T001.

Coding
8
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0011 ANDA $FF00
0001 LDA 7000 0012 CON
0002 CON 0013 SRA #08
0003 ANDA $00FF 0014 CON
0004 CON 0015 TBIN
0005 TBIN 0016 CON
0006 CON 0017 STA T001
0007 STA C000 0018 LDB 0001
0008 LD 2002 0019 C 000 #09999 0000
0009 LDA 7000 0020 LDB 0001
0010 CON 0021 T 001 #09999
➮ Refer to p. 3-159.

3-350 Chapter 8 Programming Examples

KVNKA Chap 08.p65 350 08.3.11, 0:12 PM


8.2 Details

Application of ORA instruction


■ 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 7500 to 7507.
However, retain ON/OFF of 7508 to 7515 which are loaded.

Ladder diagram

0000 #00099
C000 Sets C000.
0001
2002 7500 $FF00 DM0000
LDA ANDA STA Writes data of 7008 to 7015 into DM0000.

2002 C000 $00FF Converts the current value of C000 to BCD and
LDA TBCD ANDA retains the low-order 2 digits of BCD in the
internal register.
2002 DM0000 7500 ORs the data in the internal register and the
ORA STA DM0000 data and sends the ORed data to 7500
to 7515.

Coding

Line No. Instruction Operand Line No. Instruction Operand


0000 LDB 0000 0009 LDA C000
0001 C 000 #00099 0001 0010 CON
0002 LD 2002 0011 TBCD
0003 LDA 7500 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 7500
■ Separate input of 2-digit BCD
Fetches only 2 digits of the BCD digital switch (7000 to 7003 for the 1st digit, 8000 to
8003 for the 2nd digit) and sets it as the counter value.

Ladder diagram
0000 #00099
C001
0001
2002 7000 $000F DM0000
18
LDA ANDA STA

2002 8000 $000F


LDA ANDA

2002 #04 DM0000 C001


SLA ORA TBIN STA

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB 0000 0010 CON
0001 C 001 #00099 0001 0011 ANDA $000F
0002 LD 2002 0012 LD 2002
0003 LDA 7000 0013 SLA #04
0004 CON 0014 CON
0005 ANDA $000F 0015 ORA DM0000
0006 CON 0016 CON
0007 STA DM0000 0017 TBIN
0008 LD 2002 0018 CON
0009 LDA 8000 0019 STA C001
➮ Refer to p. 3-161.

Chapter 8 Programming Examples 3-351

KVNKA Chap 08.p65 351 08.3.11, 0:12 PM


8.2 Details

Application of EORA instruction


■ Judgement of matching data
Turns ON 0500 (“OK” output) when the ON/OFF statuses of input relays 7000 to
7007 match the DM0000 setting value.

Ladder diagram Coding


2008 $00AA DM0000 Line No. Instruction Operand
LDA STA
0000 LD 2008
0001 LDA $00AA
2002 7000 $00FF DM0000 2010 0500
LDA ANDA EORA
0002 CON
0003 STA DM0000
0004 LD 2002
0005 LDA 7000
0006 CON
0007 ANDA $00FF
0008 CON
0009 EORA DM0000
0010 CON
0011 AND 2010
0012 OUT 0500

For easy comprehension, the following data is set temporarily.


D15 D14 D13 D12 D11 D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
$BBBB 1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1 7000 to 7015
ANDA
$00FF 0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1 Operand

$00BB 0 0 0 0 0 0 0 0 1 0 1 1 1 0 1 1 Internal register


EORA
$00AA 0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0 DM0000

$0011 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1 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 7000 to 7015.
When 2010 is ON, the two values match.
When 2010 is OFF, the two values do not match.
➮ Refer to p. 3-164.

Application of SRA/SLA instructions


8 ■ Separate input of BCD
Fetches only 2 digits of the BCD digital switch (7012 to 7015 for the 1st digit, 8000 to
8003 for the 2nd digit) and sets it as the counter value.

Ladder diagram
0001 #00099
C001 Sets C001.
0000
2002 7000 $F000 Sends the data of 7012 to 7015 to internal
LDA ANDA register.

2002 #12 DM0000 Shifts the value of internal register to right by


SRA STA 12 bits and writes it into DM0000.

2002 08000 $000F Sends the data of 8000 to 8003 to internal


LDA ANDA register.
Shifts the data of internal register to left by 4
2002 #04 DM0000
bits, ORs the internal register data and the
SLA ORA
data of DM0000, and sends the ORed data to
internal register.
2002 C001
TBIN STA Converts the data of internal register to BIN
data and writes it into C001.

3-352 Chapter 8 Programming Examples

KVNKA Chap 08.p65 352 08.3.11, 0:12 PM


8.2 Details

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 0001 0011 LDA 8000
0001 C 001 #00099 0000 0012 CON
0002 LD 2002 0013 ANDA $000F
0003 LDA 7000 0014 LD 2002
0004 CON 0015 SLA #04
0005 ANDA $F000 0016 CON
0006 LD 2002 0017 ORA DM0000
0007 SRA #12 0018 LD 2002
0008 CON 0019 TBIN
0009 STA DM0000 0020 CON
0010 LD 2002 0021 STA C001
➮ Refer to p. 3-166.

Application of RRA/RLA instructions


■ Error input count
Writes the number of error detection sensors, which are connected to input relays
(7000 to 7015) and turn ON, into DM0000.

Ladder diagram
2002 7000
LDA Writes the data of 7000 to
7015 into internal register.
FOR
#00016 Executes FOR-NEXT instruction for 16 times.
2002 #01 2009 TM10
RRA INC Shifts the data including carry (2009) to right,
and increments TM10 by 1 when 2009 is ON.
NEXT

2002 TM10 DM0000 #00000 TM10 Writes the TM10 data into DM0000, and then writes
LDA STA LDA STA #00000 to TM10.

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0009 LD 2002
0001 LDA 7000 0010 LDA TM10
0002 FOR #00016 0011 CON
0003 LD 02002 0012 STA DM0000 18
0004 RRA #01 0013 CON
0005 CON 0014 LDA #00000
0006 AND 2009 0015 CON
0007 INC TM10 0016 STA TM10
0008 NEXT
➮ Refer to p. 3-169.

Applications of INC/DEC instructions


■ Total count
Writes the total count of 4 lines (0000 to 0003) into DM0000.
Reset input relay is 0005.

Chapter 8 Programming Examples 3-353

KVNKA Chap 08.p65 353 08.3.11, 0:12 PM


8.2 Details

Ladder diagram
2008 #00000 DM0000
LDA STA Sets #00000 to DM0000 at startup.

0000 DM0000
INC Increments DM0000 by 1 at UP
edge of input relay 0000.
0001 DM0000
INC
Increments DM0000 by 1 at UP
edge of input relay 0001.
0002 DM0000
INC Increments DM0000 by 1 at UP
edge of input relay 0002.
0003 DM0000
INC Increments DM0000 by 1 at UP
edge of input relay 0003.
0005 #00000
DW Clears DM0000 to #00000 when
DM0000 0005 turns ON.

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0007 @INC DM0000
0001 LDA #00000 0008 LD 0002
0002 CON 0009 @INC DM0000
0003 STA DM0000 0010 LD 0003
0004 LD 0000 0011 @INC DM0000
0005 @INC DM0000 0012 LD 0005
0006 LD 0001 0013 DW #00000 DM0000

■ UP/DOWN count
Performs UP count when input relay 0000 turns ON.
Performs DOWN count when input relay 0001 turns ON.
Writes the count value into DM0000.
Reset input relay is 0005.

Ladder diagram
2008 #00000 DM0000
LDA STA Sets #00000 to DM0000 at startup.

0000 DM0000
Increments DM0000 by 1 at UP edge
INC
of input relay 0000.

0001 DM0000
Decrements DM0000 by 1 at UP edge
8 DEC
of input relay 0001.

0005 #00000
DW Clears DM0000 to #00000 when 0005
turns ON.
DM0000

Coding
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

➮ Refer to p. 3-172.

3-354 Chapter 8 Programming Examples

KVNKA Chap 08.p65 354 08.3.11, 0:12 PM


8.2 Details

Application of MPX instruction


■ Display of 7-segment LED
Displays the current value of counter C000 to the 7-segment LED.
Outputs from 7500 to 7571.
Connection of 7 segments
Connect each of 7 segments to output relays as shown below:
a a. 7500
b. 7501
f b
g c. 7502
d. 7503
e c e. 7504
d f. 7505
g. 7506

Ladder diagram Coding


Converts the counter value to 16-bit
Auto reset counter data using the MPX instruction. Line No. Instruction Operand
0000 LDB C000
C000 #00009 C000 #0 1000 0024 LD 1004
C000 LDA MPX STA
0001 C 000 #00009 0000
0000 Sends internal register data to 0025 LDA $0066
output relays starting from 7500.
0002 CON
0026 CON
1000 $003F 7500
LDA STA 0 0003 LDA C000
0027 STA 7500
1001 $0006 7500 0004 CON
LDA STA 1 0028 LD 1005
1002 $005B 7500 0005 MPX #0
LDA STA 2 0029 LDA $006D
0006 CON
1003 $004F 7500
0030 CON
LDA STA 3
0007 STA 1000
1004 $0066 7500 0031 STA 7500
LDA STA 4 0008 LD 1000
1005
0032 LD 1006
$006D 7500
LDA STA 5 0009 LDA $003F
0033 LDA $007D
1006 $007D 7500 0010 CON
LDA STA 6
0034 CON
1007 $0007 7500 0011 STA 7500
LDA STA 7 0035 STA 7500
1008 $007F 7500
0012
0036
LD
LD
1001
1007
18
LDA STA 8
0013 LDA $0006
1009 $006F 7500 0037 LDA $0007
LDA STA 9 0014 CON
0038 CON
0015 STA 7500
7-segment display
0039 STA 7500
0016 LD 1002
0040 LD 1008
0017 LDA $005B
0041 LDA $007F
0018 CON
0042 CON
0019 STA 7500
0043 STA 7500
0020 LD 1003
0044 LD 1009
0021 LDA $004F
0045 LDA $006F
0022 CON
0046 CON
0023 STA 7500
0047 STA 7500
➮ Refer to p. 3-176.

Chapter 8 Programming Examples 3-355

KVNKA Chap 08.p65 355 08.3.11, 0:12 PM


8.2 Details

Application of DMX instruction


■ Output of error input No. in BCD
Outputs the error sensor No. from input relay 7000 to 7015 to output relays 8500 to
8507 in 2-digit BCD.

Ladder diagram
2002 07000 Converts the most significant bit of 16-bit data
LDA DMX (7000 to 7015) to 4-bit BIN data and sends it to
internal register.
2002 $00FF 8000 Converts internal register data to BCD data,
TBCD ANDA STA executes ANDA instruction, and outputs the data
to 8000 to 8015.

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0005 TBCD
0001 LDA 7000 0006 CON
0002 CON 0007 ANDA $00FF
0003 DMX 0008 CON
0004 LD 2002 0009 STA 8000
➮ Refer to p. 3-176.

Applications of TBCD instruction


■ Output of 4-digit BCD data
Outputs the current value of counter C001 to 7500 to 7515 in 4-digit BCD data.

Ladder diagram
0001 #09999
C001
0000
2002 C001 7500
LDA TBCD STA

Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB 0001 0004 CON
8 0001 C 001 #09999 0000 0005 TBCD
0002 LD 2002 0006 CON
0003 LDA C001 0007 STA 7500

■ 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 8500 to 8515
Low-order 4-digit BCD data ➞ To 7500 to 7515

DM0000 x DM0001 = TM00 Internal register


(High-order 4 digits) (Low-order 4 digits)

DM00 Internal register ÷ #10000 = TM00 Internal register --- TM01


(High-order 4 digits) (Low-order 4 digits) (Remainder)

(Display)

8500 to 8515 7500 to 7515


(High-order 4 digits) (Low-order 4 digits)

3-356 Chapter 8 Programming Examples

KVNKA Chap 08.p65 356 08.3.11, 0:12 PM


8.2 Details

Ladder diagram

2002 DM0000 DM0001 #10000 DM0101 TM01 7500


LDA MUL DIV STA LDA TBCD STA

DM0101 8500
LDA TBCD STA

Coding
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 750
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 8500
➮ Refer to p. 3-180.

Application of TBIN instruction


■ Output of 4-digit BCD data
Sets 4 digits of the BCD digital switch (7000 to 7015) as the counter C001 value.

Ladder diagram

2002 7000 C001


LDA TBIN STA Converts data of 7000 to 7015 to BIN
data and writes it into C001.
0001 #09999
C001 Sets C001.
0000

Coding

Line No. Instruction Operand Line No. Instruction Operand 18


0000 LD 2002 0004 CON
0001 LDA 7000 0005 STA C001
0002 CON 0006 LDB 0001
0003 TBIN 0007 C 001 #09999 0000
➮ Refer to p. 3-183.

Chapter 8 Programming Examples 3-357

KVNKA Chap 08.p65 357 08.3.11, 0:12 PM


8.2 Details

3-358 Chapter 8 Programming Examples

KVNKA Chap 08.p65 358 08.3.11, 0:12 PM


Index

KVNKA Index_Pro.p65 359 08.3.11, 0:14 PM


Index — For Visual KV User’s Only

Index — For Visual KV User’s Only


The following is the index with some descriptions for your reference.

Purpose Title Page


A
Access Window, changing device value in Device mode 1-87
Access Window, changing modes in Selecting modes and setting/resetting key lock 1-82
Access Window, displaying directions in User messages 1-97
Access Window, displaying errors in Error messages and error status 1-97
Access Window, error display in Error List 1-372
Access Window, increasing device selection speed in Turbo function 1-83
Access window, part names functions of Part names and functions of the Access Window 1-82
Access Window, switching the KV PLC between RUN and
System Mode 1-94
PROGRAM (stop) modes in
Access Window, using digital trimmer in Digital Trimmer Mode 1-84
Application instructions, learning about Application instructions 3-36
Arithmetic instructions, learning about Arithmetic instructions 3-38
B
Basic instructions, learning about Basic instructions 3-34
C
Cam switch function, setting item for Device used for cam switch function 3-233
Cam switch, using KV as Cam switch function 3-233
CE marking, acquiring Restriction on acquiring the CE marking (2)
Command transmission between KV and personal computer Communication command/response list 3-310
Command transmission, when error occurs during Error code list 3-316
Communication port, specifications of Communications Specification 3-306
Contact comments, transmitting them to KV PLC Contact comment save function 3-27
Contacts, protecting Contact protection 1-69
Conventional KV series, differences with Compatibility with conventional KV peripheral units (4)
Current consumption General specifications 1-4
D
Data memory, functions assigned to Data memories 3-19
Direct clock pulse, outline of Outline of direct clock pulse output 3-237
Direct clock pulse, outputting pulses with 1:1 ON/OFF ratio
ON/OFF ratio of 1:1 3-238
using
Direct clock pulse, outputting pulses with variable pulse
Variable pulse width 3-238
Index

width
Pulse output setting with the high-speed counter
Direct clock pulse, setting item for 3-238
comparator
E
Expansion unit, checking operation of Connection information for expansion units 1-75
Expansion unit, connecting Connecting Visual KV Series expansion units 1-71
Expansion unit, maximum number to be connected to Number of connectable units 1-73
Expansion unit, setting its height flush with AC-type basic unit Expansion unit spacer 1-66
External output, disabling Output prohibition function 3-26
F
Forcing input ON/OFF without switch Input refresh disabled function 3-26
Frequency counter function, setting item for Devices used with the frequency counter 3-231
High-speed counter, increasing measurement range of 24-bit high-speed counter 3-221
High-speed counter, measuring frequency with Frequency counter function 3-231
High-speed counter, outputting pulses using Direct Clock Pulse Output 3-237
Reading the current value of the high-speed
High-speed counter, reading current value of 3-211
counter
High-speed counter, resetting the value to other than "0" Preset function 3-215

3-360 Index

KVNKA Index_Pro.p65 360 08.3.11, 0:14 PM


Index — For Visual KV User’s Only

Purpose Title Page


High-speed counter, resetting the value to "0" Resetting the high-speed counter 3-214
High-speed counter, selecting input source for Count input method 3-212
High-speed counter, specifications of Specifications of high-speed counters 3-208
Preset value of the high-speed counter
High-speed counter, specifying the preset value of 3-211
comparator
High-speed counter, using, as ring counter Ring counter function 3-225
I
Input time constant of basic unit, changing Input time constant change function 3-23
Input time constant of expansion unit, setting Input time constant for expansion units 1-76
Interrupt instruction, outputting relay status independent of
Direct Input/Output 3-197
scan time
Interrupt instructions, learning about Interrupt instruction 3-41
Interrupt programs, instructions that cannot be used within Instructions that cannot be used 3-196
Interrupt, reading current value of high-speed counter by Input capture 3-195
Interrupt, setting input condition for Polarity setting for interrupts by an external input 3-195
Interrupt: when several interrupts are executed Interrupt priority 3-196
K
Cautions when using the previous version of ladder
KV IncrediWare (DOS)/LADDER BUILDER for KV, using (5)
support software
KV-P3E(01), entering instructions using Function No. list (alphabetical order) 3-41
KV-P3E(01), functions available with Function Nos. list 1-216
KV-P3E(01), operating Basic programming operation 1-200
M
Memory card, capacity of Storage capacity 1-230
Memory card, replacing battery of To replace battery 1-238
Multi-step comparator operation of DM, executing Multi-step comparator mode 3-234
O
Output, disabling output from KV Output disabled function 3-26
P
Panel mounting of KV Attaching a unit directly to a panel 1-66
Personal computer, receiving data from Receiving text data 3-318
Personal computer, transmitting data from KV to Transmitting text data 3-319
Program capacity, calculation of Calculating the byte count used 3-4
Program capacity, learning about Program capacity 3-4
Programs, saving into memory card Functions [used with KV-P3E(01)] 1-230
Index

Pulse motor, driving Parameter setting procedure 3-255


Pulse output at desired frequency Specified frequency pulse output function 3-228
Relay Nos. assigned to basic unit Relay list 3-5
Relay Nos. assigned to expansion unit List of relays in expansion units 3-6
Relay Nos., assigning Assigning relay Nos. 3-8
S
Saving current value of counter/DM into ROM LOAD and SAVE modes 1-96
Scan time Scan time 3-3
Sensors or other devices, connecting to KV Wiring procedures for basic units 1-67
Special utility relays, change in status of, when arithmetic Change in status of special utility relays
3-186
instruction is used (arithmetic flags) by arithmetic instructions
Special utility relays, functions assigned to Special utility relay list 3-86
Specified frequency pulse output function, setting item for Device used for specified frequency pulse output 3-228
T
Temporary data memory, functions assigned to Temporary data memory 3-21
Timers/counters, maximum number of Timer/Counter list 3-18

Index 3-361

KVNKA Index_Pro.p65 361 08.3.11, 0:14 PM


Index — For KV-300, KV-10/80 User’s Only

Index — For KV-300, KV-10/80 User’s Only


A F
A/D converter ........................... 1-312 [AN6], 1-334 [AD4] FOR: Repeat Start ................................................ 3-125
A/D conversion table ................ 1-408 [AN6], 1-357 [AD4]
ADD/@ADD: Add .................................................. 3-150 H
AND: And ................................................................ 3-58
ANB: And Bar ......................................................... 3-58 High-Speed Counters .......................................... 3-276
ANDA/@ANDA: And A ......................................... 3-159 HKEY: 16 Key Input .............................................. 3-131
ANL: And Load ....................................................... 3-61 HSP: High Speed .................................................... 3-86
Application Instructions ...................... 3-36, 3-45, 3-95
Arithmetic Instructions ...................... 3-38, 3-48, 3-134 I
ASC/@ASC: ASCII Convert ................................ 3-183
Assignment of Data Memory ................................. 3-19 INC/@INC: Increment Memory ............................ 3-172
Assignment of I/O relay numbers ......................... 3-22 Indirect Addressing of Data Memory or Relay .. 3-127
Input Relays .............................................................. 3-9
B Instruction List .............................................. 3-34, 3-42
INT: Interrupt ........................................................ 3-192
Basic Instructions ................................ 3-34, 3-42, 3-56 Interface [RS-232C] .............................................. 3-306
Baud rate ......................................... 2-136, 1-247 [KV-L2] Internal register .................................................... 3-135
Break signal .......................................................... 3-308 Internal Utility Relays ............................................. 3-11
Internal Clocks for CTH0 and CTH1 ................... 3-278
C Interrupt Instructions ........................................... 3-268
I/O distribution ......................................................... 1-187
C: Counter .............................................................. 3-72 ITVL: Interval Timer .............................................. 3-117
CALL: Subroutine Call ......................................... 3-122
CMP/@CMP: Compare ......................................... 3-146 J
COM/@COM: Complement .................................. 3-171
Commands [Serial communication] ................... 3-310 JMP: Jump ............................................................ 3-106
Communications ....................................... 2-135, 3-306
CON: Connect ....................................................... 3-102 K
Connector wiring ....................................................... 1-72
CTC: Counter Comparator .................................. 3-204 KEEP: Keep ............................................................ 3-80
CTH1: 16-Bit Counters ......................................... 3-204 KV-10/16/24/40/80 ............................ 1-167, 1-175, 1-177
KV-300 ......................................................... 1-166, 1-170
D KV-AD4 ................................................................... 1-334
KV-AN6 ................................................................... 1-312
Data Memory ........................................................... 3-19 KV-B16R/B16S/C32T .............................................. 1-172
D/A converter ........................... 1-312 [AN6], 1-334 [AD4] KV-C16X/C32X ....................................................... 1-171
D/A conversion table ................ 1-408 [AN6], 1-357 [DA4] KV-DA4 ................................................................... 1-334
DEC/@DEC: Decrement Memory ........................ 3-172 KV-L2 ...................................................................... 1-240
DI: Interrupt Disabled ........................................... 3-193 KV-R1A/R16X/R16R/R16T/R8X/R8R/R8T .. 1-173, 1-174
DIFD: Differentiate Down ....................................... 3-78 KV-U4/U5 ..................................................... 1-168, 1-169
DIFU: Differentiate Up ........................................... 3-78 KV mode [KV-L2] .................................................... 1-253
Index

Dimensions ............................................................. 1-404


DIN rail (mounting) .................................................. 1-180 L
Direct Clock Pulse ................................................ 3-276
Display Interface Mode [KV-L2] .............................. 1-244 LD: Load .................................................................. 3-57
DIV/@DIV: Divide .................................................. 3-150 LDA/@LDA: Load A .............................................. 3-140
DMX/@DMX: Demultiplexer ................................. 3-176 LDB: Load Bar ........................................................ 3-57
DW: Data Memory Write ...................................... 3-136
M
E
Macros ...................................................................... 2-72
EI: Interrupt Enabled ............................................ 3-193 MC: Master Control ................................................ 3-89
END: End ................................................................. 3-94 MCR: Master Control Reset ................................... 3-89
ENDH: End Hi ......................................................... 3-94 Memory Card .......................................................... 1-230
ENDS: End Stage ................................................. 3-106 MEMSW: Memory Switch ...................................... 3-92
Environment requirements ........................................ 1-64 Module names ......................................................... 1-175
EORA/@EORA: Exclusive Or A .......................... 3-164 Mounting Environment .............................................. 1-64
Error code list .......................................................... 1-372 MPP: Pop .............................................................. 3-103
Extended Ladder Diagrams ................................... 3-29 MPS: Push ............................................................ 3-103

3-362 Index

KVNKA Index_Pro.p65 362 08.3.11, 0:14 PM


Index — For KV-300, KV-10/80 User’s Only

MPX/@MPX: Multiplexer ...................................... 3-176 System Configuration (Memory Card) ..................... 1-196
MRD: Read ............................................................ 3-103 System specifications [Visual KV Series] ................ 1-382
MUL/@MUL: Multiply ........................................... 3-150 System specifications [KV-300 Series] ................... 1-392

N T
NEXT: Repeat End ................................................ 3-125 TBCD/@TBCD: Transfer BCD ............................. 3-180
Non-procedure mode [KV-L2] ................................. 1-292 TBIN/@TBIN: Transfer BIN .................................. 3-180
NOP: No Operation ................................................ 3-94 Temporary Memory ...................................... 2-172, 2-176
Timers and Counters ............................................... 2-169
TMH: 0.01-s Timer .................................................. 3-68
O
TMIN: Trimmer In .................................................. 3-138
OR: Or ..................................................................... 3-60 @TMIN: Trimmer Setting ..................................... 3-138
ORA/@ORA: Or A ................................................. 3-161 TMR: 0.1-s Timer .................................................... 3-67
ORB: Or Bar ............................................................ 3-60 TMS: 1-ms Timer .................................................... 3-69
ORL: Or Load .......................................................... 3-63 Transmitting text data .......................................... 3-319
OUB: Out Bar .......................................................... 3-65 Troubleshooting ...................................................... 1-372
OUT: Out ................................................................. 3-65
Output Relays ......................................................... 3-10 U
UDC: Up-Down Counter ......................................... 3-76
P
Peripheral equipments ............................................ 1-176 W
Port1/Port2 [KV-L2] ................................................. 1-245
Positionning control ............................................ 3-296 W-DE: Wait Down Edge ......................................... 3-98
Programming examples ...................................... 3-324 W-OFF: Wait OFF ................................................... 3-96
W-ON: Wait ON ....................................................... 3-96
W-UE: Wait Up Edge .............................................. 3-98
R
RASC/@RASC: Reverse ASCII Convert ............. 3-183 X
Receiving text data .............................................. 3-318
Relay/Memory/Memory Switch Lists ....................... 2-167 @xxxx: Differentiation ......................................... 3-137
Relay/Memory Nos. ................................................. 2-167
Relay No. List .......................................................... 2-167
Relay Nos. and Functions ....................................... 2-167
RES: Reset .............................................................. 3-66
RET: Subroutine Return ...................................... 3-122
RETI: Return Interrupt ......................................... 3-192
RLA/@RLA: Rotate Left A ................................... 3-169
ROOT/@ROOT: Square Root .............................. 3-185
RRA/@RRA: Rotate Right .................................... 3-169
RS-232C cable connection .................................. 3-307
RS-232C Protocol ................................................. 3-306
Index

RS-422A [KV-L2] ..................................................... 1-248

S
SBN: Subroutine Entry ........................................ 3-122
Serial Communication ......................................... 3-306
SET: Set .................................................................. 3-66
SFT: Shift ................................................................ 3-82
SLA/@SLA: Shift Left A ....................................... 3-166
Special Utility Relays ............................................... 2-174
SRA/@SRA: Shift Right A .................................... 3-166
STA/@STA: Store A ............................................. 3-140
Station No. [KV-L2] ................................................. 1-246
STE: Step End ...................................................... 3-114
STG: Stage ............................................................ 3-106
STP: Step .............................................................. 3-114
SUB/@SUB: Subtract ........................................... 3-150
System configuration ............................................... 1-166

Index 3-363

KVNKA Index_Pro.p65 363 08.3.11, 0:14 PM


Index — Software/P3E (handheld programmer)

Index — Software/P3E (handheld programmer)


A MULTI-MONITOR [P3E] ......................................... 1-212

ACCS ...................................................................... 1-234


ALL CLEAR [FNC60] [P3E] ..................................... 1-217
O
ALL DATA MEMORY CLEAR OFFLINE EDITOR START (OFFLINE EDITOR):
(DM ALL CLEAR): [FNC64] [P3E] ...................... 1-219 [FNC67] [P3E] .................................................... 1-221
ALL LATCHING RELAYS RESET OFFLINE EDITOR STOP (QUIT OFF-L EDIT):
(L-RELAY ALL RST): [FNC65] [P3E] ................... 1-219 [FNC68] [P3E] .................................................... 1-221
ON/OFF MONITOR [P3E] ....................................... 1-215
B
Break signal .......................................................... 3-308
P
Printer Setting, Defining Environment Strings .......... 2-77
C Printing examples ...................................................... 2-81
PROGRAM CAPACITY CHECK (PROGRAM SIZE):
CLEAR [P3E] .......................................................... 1-232
[FNC75] [P3E] .................................................... 1-229
Comments (Relay comment, Line comment) ............ 2-46
PROGRAM SENT OR RECEIVED
Compile ..................................................................... 2-75
(COMMUNICATION—): [FNC66] [P3E] ............. 1-220
Converting N.O./N.C. ................................................ 2-65
Copy, move and delete ............................................. 2-69
COUNTER CLEAR (CTR CLEAR): [FNC62] [P3E] 1-218
Q
Customizing KV-LADDER , Quitting software ....................................................... 2-16
Defining Environment Strings ................................ 2-19
Copy, move and delete operation ............................. 2-52 R
D READ TRIMMER SETTING (TRIMMER MONITOR):
[FNC73] [P3E] .................................................... 1-228
Data Communications between KV Registration of cursor position and
and Personal Computer .................................... 3-306 jump to registered position ................................... 2-59
Display mode ........................................................... 2-19 RELAY ON/OFF (FORCED SET/RESET):
Double coil check ...................................................... 2-76 [FNC71] [P3E] .................................................... 1-226
Replacing relays ........................................................ 2-64
E RS-232C cable connection ......................................... 2-7
RS-232C Protocol ....................................................... 2-3
Edit screen ................................................................ 2-27
Entering symbols ....................................................... 2-37
Environment requirements .......................................... 2-3
S
Error message list ................................................... 2-156 SCAN TIME MONITOR [P3E] ................................. 1-212
SCROLL [P3E] ........................................................ 1-202
H Search ....................................................................... 2-58
Searching Program [P3E] ....................................... 1-207
HANDHELD PROGRAMMER CLEAR (P3E CLEAR):
Selecting display mode ............................................. 2-19
[FNC61] .............................................................. 1-217
Setting print range ..................................................... 2-77
Handheld Programmer KV-P3E .............................. 1-196
Simulator Mode ......................................................... 2-84
HIGH-SPEED COUNTER CLEAR
Index

Simulator screen ....................................................... 2-86


(HIGH SPEED CTR CLR): [FNC63] [P3E] .......... 1-218
Starting and quitting software ................................... 2-16
I Starting edit mode .................................................... 2-29
Starting the Monitor Function .................................. 2-139
Installing Ladder Builder .............................................. 2-9 Starting the Simulator ................................................ 2-86
SYNTAX CHECK (PROGRAM CHECK):
J [FNC74] [P3E] .................................................... 1-228
Jump ......................................................................... 2-58 T
L Temporary Memory ................................................ 3-21
Time Chart Monitor ................................................. 2-157
Ladder Monitor ........................................................ 2-134 Time Chart Viewer ....................................... 2-148, 2-167
Ladder Simulator ....................................................... 2-84 TIMER/COUNTER SETTING CHANGE
Line comment ........................................................... 2-46 (CHG: T/C SET-V): [FNC70] [P3E] .................... 1-224
TIMER/COUNTER CURRENT VALUE CHANGE
M (CHG: T/C CURT-V): [FNC69] [P3E] ................. 1-222
Macros ...................................................................... 2-72
Memory Card [P3E] ................................................. 1-230 W
Monitor Mode .......................................................... 2-134
Monitor screen ........................................................ 2-143 WRITE INTO DATA MEMORY (DM WRITE):
MOVE CURSOR [P3E] ........................................... 1-202 [FNC72] [P3E] .................................................... 1-227

3-364 Index

KVNKA Index_Pro.p65 364 08.3.11, 0:14 PM


Index

Index 3-365

KVNKA Index_Pro.p65 365 08.3.11, 0:14 PM


Index

3-366 Index

KVNKA Index_Pro.p65 366 08.3.11, 0:14 PM


Safety Precautions WARRANTIES AND DISCLAIMERS:
This instruction manual describes the operation and function of the KV Series PLC. (1) KEYENCE warrants the Products to be free of defects in materials and workmanship for a period of
Read this manual carefully to ensure safe use and maximum performance from your one (1) year from the date of shipment. If any models or samples were shown to Buyer, such models or
KV Series PLC. samples were used merely to illustrate the general type and quality of the Products and not to represent
that the Products would necessarily conform to said models or samples. Any Products found to be defec-
tive must be shipped to KEYENCE with all shipping costs paid by Buyer or offered to KEYENCE for in-
Symbols spection and examination. Upon examination by KEYENCE, KEYENCE, at its sole option, will refund the
purchase price of, or repair or replace at no charge any Products found to be defective. This warranty
The following symbols alert you to important messages. Be sure to read these does not apply to any defects resulting from any action of Buyer, including but not limited to improper
messages carefully. installation, improper interfacing, improper repair, unauthorized modification, misapplication and mishan-
dling, such as exposure to excessive current, heat, coldness, moisture, vibration or outdoors air. Compo-
Failure to follow instructions may lead to injury. (electric nents which wear are not warranted.
WARNING shock, burn, etc.)
(2) KEYENCE is pleased to offer suggestions on the use of its various Products. They are only sugges-
tions, and it is Buyer’s responsibility to ascertain the fitness of the Products for Buyer’s intended use.
KEYENCE will not be responsible for any damages that may result from the use of the Products.
Failure to follow instructions may lead to product damage. (3) The Products and any samples (“Products/Samples”) supplied to Buyer are not to be used internally
CAUTION
in humans, for human transportation, as safety devices or fail-safe systems, unless their written specifica-
tions state otherwise. Should any Products/Samples be used in such a manner or misused in any way,
Note: Provides additional information on proper operation. KEYENCE assumes no responsibility, and additionally Buyer will indemnify KEYENCE and hold
KEYENCE harmless from any liability or damage whatsoever arising out of any misuse of the Products/
Samples.
Conventions (4) OTHER THAN AS STATED HEREIN, THE PRODUCTS/SAMPLES ARE PROVIDED WITH NO
OTHER WARRANTIES WHATSOEVER. ALL EXPRESS, IMPLIED, AND STATUTORY WARRANTIES,
This manual describes the operation/function of all Keyence KV Series PLC.
INCLUDING, WITHOUT LIMITATION, THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
Note following conventions when you use.
PARTICULAR PURPOSE, AND NON-INFRINGEMENT OF PROPRIETARY RIGHTS, ARE EXPRESSLY
Visual KV (Series) KV-10AR/AT/DR/DT KV-16AR/AT/DR/DT DISCLAIMED. IN NO EVENT SHALL KEYENCE AND ITS AFFILIATED ENTITIES BE LIABLE TO ANY
KV-10xx, 16xx, 24xx, 40xx KV-24AR/AT/DR/DT KV-40AR/AT/DR/DT PERSON OR ENTITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, PUNITIVE, SPECIAL OR CONSE-
Conventional KV (Series) KV-10R(W)/T(W) KV-16R(W)/T(W) QUENTIAL DAMAGES (INCLUDING, WITHOUT LIMITATION, ANY DAMAGES RESULTING FROM
KV-300 (Series) KV-24R(W)/T(W) KV-40R(W)/T(W) LOSS OF USE, BUSINESS INTERRUPTION, LOSS OF INFORMATION, LOSS OR INACCURACY OF
KV-10/80 (Series) KV-80R(W)/T(W) DATA, LOSS OF PROFITS, LOSS OF SAVINGS, THE COST OF PROCUREMENT OF SUBSTITUTED
KV-300 GOODS, SERVICES OR TECHNOLOGIES, OR FOR ANY MATTER ARISING OUT OF OR IN CONNEC-
TION WITH THE USE OR INABILITY TO USE THE PRODUCTS, EVEN IF KEYENCE OR ONE OF ITS
AFFILIATED ENTITIES WAS ADVISED OF A POSSIBLE THIRD PARTY’S CLAIM FOR DAMAGES OR
General Precautions ANY OTHER CLAIM AGAINST BUYER. In some jurisdictions, some of the foregoing warranty disclaimers
• At startup and during operation, be sure to monitor the functions and perfor- or damage limitations may not apply.
mance of the KV Sereis PLC.
BUYER’S TRANSFER OBLIGATIONS: If the Products/Samples purchased by Buyer are to be resold or
• We recommend that you take substantial safety measures to avoid any damage delivered to a third party, Buyer must provide such third party with a copy of this document, all specifica-
in the event a problem occurs. tions, manuals, catalogs, leaflets and written information provided to Buyer pertaining to the Products/
Samples.
• Do not open or modify the KV Series PLC or use it in any way other than de-
scribed in the specifications.

• When the KV Series PLC is used in combination with other instruments, func-
tions and performance may be degraded, depending on operating conditions and
the surrounding environment.

• Do not use the KV Series PLC for the purpose of protecting the human body.

Note: The built-in display may show the error message "Error 40" blinking the very
first time you turn on the power supply to the Visual KV Series. Press any key
around the display to cancel this message.
The Visual KV Series shows this message when no program is loaded.

(1) 3-367
Visual KV Series
96M0366
INDEX

1 2 3
Installation Support Programming
1. Configuration and Software 1. Programming

3
Specifications 1. Introduction 2. Instructions
User’s Manual

Programming
2. System Installation
2. Editor 3. Interrupts
3. Access Window
3. Simulator 4. High-speed Counters
4. KV-D20 Operator
Interface Panel 4. Monitor 5. Positioning Control Visual KV Series
5. Appendices 6. Interrupts, High-speed
5. KV-10/80 Hardware
Counters, Positioning
6. Handheld Program-
mer
Control 3
7. Serial Communication

Programming

User’s Manual
7. KV-L2 Serial Interface
8. Programming
Module
Examples
8. KV-AN6 Analog I/O
Module
9. KV-AD4/DA4 Analog
I/O Unit
10. Troubleshooting
11. Appendices

Specifications are subject to change without notice.

KEYENCE CORPORATION
1-3-14, Higashi-Nakajima, Higashi-Yodogawa-ku, Osaka, 533-8555, Japan PHONE: +81-6-6379-2211

AUSTRIA GERMANY MALAYSIA SWITZERLAND


Phone: +43-2236-378266-0 Phone: +49-6102-36 89-0 Phone: +60-3-2092-2211 Phone: +41 43 455 77 30
BELGIUM HONG KONG MEXICO TAIWAN
Phone: +32 2 716 40 63 Phone: +852-3104-1010 Phone: +52-81-8220-7900 Phone: +886-2-2718-8700
CANADA HUNGARY NETHERLANDS THAILAND
Phone: +1-905-696-9970 Phone: +36 14 748 313 Phone: +31 40 20 66 100 Phone: +66-2-369-2777 How this manual is organized:
CHINA ITALY POLAND UK & IRELAND The Visual KV Series User’s Manual is composed of 3 separate
Phone: +86-21-68757500 Phone: +39-2-6688220 Phone: +48 71 36861 60 Phone: +44-1908-696900
manuals; 1-Installation, 2-Support Software, 3-Programming.
CZECH REPUBLIC JAPAN SINGAPORE USA
Phone: +420 222 191 483 Phone: +81-6-6379-2211 Phone: +65-6392-1011 Phone: +1-201-930-0100 Please read each manual relevant to your purpose.
FRANCE KOREA SLOVAKIA
Phone: +33 1 56 37 78 00 Phone: +82-31-642-1270 Phone: +421 2 5939 6461
A5WW1-MAN-0069

Copyright (c) 1999 KEYENCE CORPORATION. All rights reserved.


084024E-3 0109-5 96M0366 Printed in Japan

You might also like