Sei sulla pagina 1di 134

KV5500/5000/3000

Introduction
Manual
-

CONTENTS
[★★] indicates the level of importance.

 Chapter 1 Hardware settings


Appearance [★★] P6
Size [★★] P7
Unit Configuration [★★] P7
Installation [★★★] P8
Device Memory [★★★] P9

 Chapter 2 Software settings


Creating a new project [★] P12
Unit Editor (Setting unit configuration) [★★★] P14
Customizing shortcut keys [★★] P19
Registering device comments [★★] P22
Entering contacts/shortcut keys [★★★] P24
Programming considerations [★★★] P29
Software layout [★] P31
Transferring ladder programs for monitoring [★★★] P36
Saving ladder programs [★★★] P39

 Chapter 3 Software debugging


Debugging procedure [★★★] P41
Reading a ladder program [★★★] P42

-1- KV0475E_C
-

Mode Switching [★★] P43


Debugging a ladder program (Monitor) [★★] P41
Batch monitor [★★] P45

Registration monitor [★★] P46

Unit monitor [★] P48

Debugging a ladder program (Search) P49


Device search [★★★] P49

Jump contact  coil [★★] P50

Cross-reference [★★] P52

Consecutive search [★★] P52

Device use list [★★] P53

Display device use status [★★] P53

Debugging a ladder program (Tool) [★★★] P54


Forced set/reset register [★] P54

Derivation monitor [★] P54

Real- time chart monitor [★★★] P56

Break function [★] P64


(Device break/Calculation error break/Line break)

Debugging a ladder program (Other functions) [★★] P68


Access window [★★] P68

Error monitor [★] P71

PLC verification/synchronization [★★] P72

-2- KV0475E_C
-

 Chapter 4 Advanced programming


Modules [★★★] P74
Types of modules [★★★] P75

Examples of using the modules [★★] P75

Local device [★★] P81


Merits of using a local device [★★] P81

Example of using a local device [★★] P85

Practice re-using programs [★★] P86


Relationship between a unit device and the module library [★★] P87

Macros (Original Instruction Words) [★★] P89


Merits of using macros [★★] P90

Procedure for using macros [★★] P94

 Chapter 5 KV Script Programming


KV script [★★★] P104
KV script operations flow [★★★] P106

Monitoring scripts [★] P111

Suffix (data type) [★★★] P115

Script programs sample [★★] P119

Appendix
Installing the USB Driver [★★★] P127
Useful Functions Categorized by Situation [★] P129

-3- KV0475E_C
-

Chapter1
Hardware setting

-4- KV0475E_C
-

1. Appearance
The KV-5500/5000/3000 Series’ CPU has a built-in input/output and is equipped with a liquid crystal display, as
shown in the photo below.

CPU UNIT

Hyper access window


 CPU monitoring
 I/O checking
 Error monitoring

Built-In I/O (DI 16 / DO 8)


Position control 2axis
Highspeed counter 2ch
Interrupt input 10 point

Ethernet/EIP port

USB port

RUN/PROG Mode switch SD(HC) card slot

EXPANSION UNIT

Direct access switch


 Unit monitoring

The hyper access windows and the direct access switches appear in either green or red.
When the hyper access windows appear in red, it indicates some sort of error status (or stop mode), so the
error must be eliminated.
When the direct access switches are red and the hyper access windows are green, an error has occurred in
the unit only. The CPU is still operating.

-5- KV0475E_C
-

2 Size

3 Unit Configuration
You can connect a maximum of 48 units.
(Maximum of 16 units side by side and a maximum of 3 levels high)

-6- KV0475E_C
-

4 Installation

No base unit is required.

A 24V supply terminal is located at the bottom of the CPU. You do not need a dedicated power supply unit for the
KV-5500. (KV-U7)

The battery is located at the bottom of the CPU.

Battery life is 5 years at +25°C. The life will be shortened if the battery is used at higher temperatures.

About the battery


 Purpose of the battery
The purpose of the battery is to retain the clock data and device values.
Programs are saved in the Flash ROM within the CPU.
Programs will not be lost even if the battery goes flat.

If [CPU Error No83] is displayed in the access window, you must replace the internal lithium battery immediately.
If a battery error occurs, CR2306 turns ON.
Data can be retained for at least 1 week (at normal temperature) after a battery error occurs.

-7- KV0475E_C
-

5 Device Memory
[DEFAULT FORMAT]

Default
Item Specification Range
Format
Input relay R
Output relay R Total 16000 points 1 bit R000 to R99915
Internal auxiliary relay R
Link relay B 16384 points 1 bit B0 to B3FFF
Internal auxiliary relay MR 16000 points 1 bit MR000 to MR99915
Latch relay LR 16000 points 1 bit LR000 to LR99915
Control relay CR 640 points 1 bit CR000 to CR3915
Timer T 4000 points 32 bits T0 to T3999
Counter C 4000 points 32 bits C0 to C3999
Data memory DM 65535 points 16 bits DM0 to DM65534
Extended data memory EM 65535 points 1 bit EM0 to EM65534
Current bank mode FM FM0 to FM32767 x 4 Bank
File register Consecutive 131072 points16 bits
ZF ZF0 to ZF131071
number mode
Link register W 16384 points 16 bits W0 to W3FFF
Temporary memory TM 512 points 16 bits TM0 to TM511
High-speed counter CTH 2 points 32 bits CTH0 to CTH1
High-speed counter comparator CTC 4 points 32 bits CTC0 to CTC3
Index register Z 12 points 32 bits Z01 to Z12
Control memory CM 6000 points 16 bits CM0 to CM5999

[Bit Device]

R10000
Channel Bit

*Same for MR/LR


[Word Device]

DM0 0 0 0 0 and so on
The number is assigned serially.

*Same for EM/FM

-8- KV0475E_C
-
[XYM FORMAT]
On the KV-5500, you can switch the device memory to XYM mode.

Display
Item Specification Range
By XYM
Input relay X X0000 to X999F
Output relay Y Total 16000 points 1 bit Y0000 to Y999F
Internal auxiliary relay R R00000 to R99915
Link relay B 16384 points 1 bit B0000 to B3FFF
Internal auxiliary relay M 16000 points 1 bit M00000 to M15999
Latch relay L 16000 points 1 bit L00000 to L15999
Control relay CR 640 points 1 bit CR0000 to CR3915
Timer T 4000 points 32 bits T0 to T3999
Counter C 4000 points 32 bits C0 to C3999
Data memory D 65535 points 16 bits D0 to D65534
Extended data memory E 65535 points 1 bit E0 to E65534
Current bank mode F F0 to F32767 x 4 Bank
File register Consecutive 131072 points16 bits
ZF ZF0 to ZF131071
number mode
Link register W 16384 points 16 bits W0 to W3FFF
Temporary memory TM 512 points 16 bits TM0 to TM511
High-speed counter CTH 2 points 32 bits CTH0 to CTH1
High-speed counter comparator CTC 4 points 32 bits CTC0 to CTC3
Index register Z 12 points 32 bits Z01 to Z12
Control memory CM 6000 points 16 bits CM0 to CM5999

 The input relay is expressed as X, and the output relay is expressed as Y.


Expressed as X(Y) + channel number + 0 to F (bit position).
Example: R30015 (input) → X300F
Expressed as X(Y) + channel number + 0 to F (bit position).
Example: R30015 (input) → X300F

 MR/LR is expressed as a decimal number.


M00000 to M15999 / L00000 to L15999 (16K points each)

 DM/EM/FM is expressed as D/E/F.


Example: DM1234 → D1234

 The prefix is K for decimal numbers and H for hexadecimal numbers.

 B/W is also B0000 to B3FFF/W0000 to W3FFF in XYM notation mode.

-9- KV0475E_C
-

Chapter2
Software setting

- 10 - KV0475E_C
-

Creating a new project/Setting up a unit


The Ladder integrated software "KV STUDIO" is used in the "KV-5000/3000" Series. Start "KV STUDIO" to create a
project.

Starting KV STUDIO
1 On the desktop, double click on the icon to start "KV STUDIO".

The start title screen can be disabled so that it is not displayed.


Tip
From the menu, select "Tool (T)" -> "Option (O)". On the "System setting" tab in the
"Setup option" dialog box, uncheck the "Display start title (T)" checkbox.

Start title screen

2 The initial screen is displayed after the start title screen.

Initial screen

Creating a project
A project is a management program that collects ladder programs, unit setting information, comments and other
information.

3 Click on the toolbar icon on the Initial screen.

Other procedure  Select "File (F)" -> "New project (N)" from the menu.

Select this from the menu

- 11 - KV0475E_C
-
4 The "New project" dialog box appears. Enter the information for the project to be created.

Enter the name of the project to be saved.


Both half-width characters and full-width characters are Select the PLC model you use.
acceptable. In this seminar, KV-5000 is used.
Make sure that you have entered the project name correctly.

Determine the position where


the project should be stored.
If you want to store the project
in a non-default position,
change the default position.
A folder with the same name
as that of the project is
created in the specified
position.

Enter a comment to be
displayed in the access
window.
See the column field for
details. Enter a comment for the project to be created.
This is not required but recommended.

 If one or more units to be added to a PLC you are using are already determined, click the "Yes" button.
Once the "Unit Editor" is started, you need to set the unit configuration you use.
 If one or more units to be added to a PLC you are using are not yet determined, click the "No" button. (The
unit configuration setting can be done later.)
 If a PLC that one or more units are already added to is able to communicate with KV STUDIO Ver. 6 (PC),
click "Read unit setting" to read the unit setting information from PLC.

Unit Editor

About the access window display comments


You can enter notes about the latest version information of ladder programs, data and time,
contact names, and other information.
 How to display comments
STEP1 : Press the "M" operation key twice to set the CPU. M STEP1
STEP2 : Press the "" operation key five times to set the CPU.
STEP3 : Press the " " operation key once to set the CPU.
STEP4 : Press the " " operation key once to set the CPU. STEP3
Operation keys to
Comments are now shown in the access window. set the CPU

STEP4

- 12 - KV0475E_C
-

Unit Editor (Setting unit configuration)


An example, in the following unit configuration, is the steps for creating a new system using the Unit Editor.

 Unit configuration example

KV-U7

KV-5000

KV-AD40
KV-U7 : Power supply unit
KV-5000 : CPU unit
KV-AD40 : A/D convert unit

5 From the "Select unit" tab, drag and drop a unit to be connected to the CPU.
The units that are actually used in the project are displayed next to each other.

Other procedure  Double click on the required units.

Select unit tab

Drag & drop

- 13 - KV0475E_C
-

6 Set up the relay/DM assignment.


Added units have relay and data memory controlled by them which must be assigned with device numbers.
(Select "Auto-assign relay/DM" here)

 How to auto-assign relay/DM


Once the units to be registered are determined, relay/DM
numbers should be assigned.
Select "Convert (P)"  "Auto-assign relay/DM (A)" from
the menu.

Other procedure Click on the tool bar.

When a message box appears to confirm whether to auto-assign relay/DM, click the “OK” button.

Relay/DM numbers are automatically assigned, and numbers appear on the units in the unit configuration
area.

 Before the assignment

 After the assignment

Tip Click the appropriate icon on the toolbar to change the unit display.
Each click toggles between box/bitmap display of the unit.

- 14 - KV0475E_C
-
I/O assignment/other settings

 Manual assignment
The device numbers that are assigned to each unit should be set to any number of your choice.

Double click on the connected unit, and then Relay setting should
change the device number from the "Setup unit be set to channel
(2)" tab. numbers, not to
device numbers.

 Batch input (only for relay numbers)


The batch input method is used, for example, when the
device numbers that are assigned to each unit should all be
set manually.

Select "Edit"  "Batch input relay No." from the menu.


Any leading relay
number can be
specified.

 Changing an auto-assigned number


An auto-assigned device number can be changed to any number of your choice. To change an auto-assigned device number, do
the following:

Select "Option"  "Setup option" from the menu.



Select the "Setup device assignment" tab.

Assign numbers to the connected unit in a


sequence, starting from the specified number
(as per channel), to the connected unit.

Assign numbers to the connected unit by


specifying them respectively to the input unit,
the output unit, and the special unit.

Specify the leading number of the word


device (DM) to be assigned. Check the
"Assign DM by 100.(M)" to assign DM by 100
to each unit.

 Checking the assigned numbers


If device numbers are assigned manually, check them to make sure that the assigned numbers are correct.

 Click the icon.

 Select "Convert"  "Verify device" from the menu.


 Press the key

If the assigned numbers contain errors, error messages appear in the message area.
 If there is an error, the project cannot be transferred to PLC.

- 15 - KV0475E_C
-
7 Set up the added units.
Set up the added units other than the unit relay/DM.

Double click on the unit to be set up Setup unit tab

Click the setting item.

Click the setting value of an item that can be charged. (Grayed out items cannot be set up)
If a pull-down menu appears, select the setting item from the menu. If a pull-down menu does
not appear, enter your setting directly.

An asterisk (*) at the end of the setting value indicates that the setting is a default setting.

- 16 - KV0475E_C
-
* Skip any CH that you don't want to use.

Set CH1 to CH3 to "Channel skip => Enabled".

8 Exit the Unit Editor.


When you finish assigning relay/DM numbers, exit the "Unit Editor".
Click the "OK" button at the bottom right of the Unit Editor.

Other procedure Click the icon on the toolbar.

Save the unit setup information you have created, and


return to the Ladder Editing window.

The items that have been set


with the Unit Editor appear.

The numbers for input output relay can be set in the range of R1000 to R99900, and the numbers for data
memory in the range of DM0 to DM65534.
In the initial setting, the relay numbers have been batch assigned from R30000 (300ch) and DM
numbers from DM10000.
You can set the Unit Editor so that numbers are separately assigned to relay numbers by specifying them
respectively to the input unit, the output unit, and the special unit.

Displaying the hardware information of the units

Once the units are configured, the overall width, height, depth,
weight and current consumption of the units a linked
connection are calculated automatically and then displayed.

The hardware information is


displayed.
These values may vary depending
on the connected units.

- 17 - KV0475E_C
-

Customizing shortcut keys and switching the display (XYM format) ★★


The shortcut key settings for O-corporation/M-corporation PLC that you are familiar with can be reproduced with KV
STUDIO.

Customizing the shortcut key settings for non- KEYENCE PLC


M-corporation GPPA format/GPPQ format and O-corporation CX format are supported.

1 Select "Tool (T)"  "Customize (K)" from the menu.


The "Customize" dialog box appears.

Item Description
“Batch chg (O)…” Batch-changes shortcut keys to Default format, GPPQ format,
GPPA format and CX format.
Shortcut key “Read (R)…” Reads saved setup files (*.key) for shortcut keys.
create “Save (S)…” Saves the settings of customized shortcut keys.
“Initialize (I)” Returns shortcut key settings to their defaults.
“Reg/delete keys (A)…” Registers/deletes shortcut keys.

2 Click the "Batch chg (O)…" button.


The "Batch change keys" dialog box appears.

3 Select the appropriate key format and click the "OK" button.

Select the appropriate key format


from the pull-down menu.
Select "Default format" to return to
the default.

- 18 - KV0475E_C
-

Display formats that are common with Mitsubishi PLC


The display is also switched.
It is also transferred to the PLC.

”Default format”

”XYM format”

* Setting the XYM format may result in some parts being left unchanged.
For details, please refer to pages 6 and 7.

* The settings of the XYM format are transferred to the CPU.


The settings are read as an XYM format when the programs are read.

- 19 - KV0475E_C
-
The function that automatically adapts to I/O
After one or more ladder programs are created, and if you want to change the device
numbers of the connected units, the device numbers in the ladder programs are
automatically converted to the new numbers by changing the settings of the device
numbers with the Unit Editor.

Use the Unit Editor to change the device numbers assigned to the units.

Before the change After the change

Once you're finished, return to the Ladder Editor to make sure that the device numbers have changed automatically.

The device comments are also moved


automatically to the changed device
numbers.

The relay numbers have


been automatically changed.

A list of the devices that have been automatically converted appears in the Output window.

Right click the "Save in text


format(K)" to save the
contents of the Output
window as a text file.

Other useful functions

 Wizard to register units


Units can be configured simply following the on screen instructions to select the number of connected units.

 Printing the system structure diagram


This feature, which is useful for supplying technical data, such as specification sheets, enables you to print all the relevant system
information you have specified with the Unit Editor, including structure diagrams of connected units, settings of each unit, and relay
assignments by unit.
The following can be printed:

 Structure diagrams of connected units


Unit illustrations and relay assignments can be printed.

 Detailed settings of connected units


Settings of each unit can be printed as tables.

 Printing the KL system structure


Illustrations of the KL system, relays of each unit, and address
assignment tables can be printed.

- 20 - KV0475E_C
-

Registering device comments


We have realized that there is a close association between setting with the Unit Editor and ladder programs.
Next, enter the contact comments. This feature enables you to register comments for devices that are
uniquely controlled by special units.

Registering device comments


1 Double click on the "Device comment" in the workspace.
The "Device comment edit" appears.

Two types of comments can


be stored. Up to 32 half-width
characters can be used.

2 Select "Detail".

3 Select "Reg unit device".

- 21 - KV0475E_C
-
4 Select "Reg".
Check the appropriate unit to be registered, and select "Reg".

5 Comments for the devices uniquely controlled by the special unit are registered automatically.

The unique control device for


each unit is extracted

The device comments have


been registered.

About device comments


 The memory for device comments is available separately from the program memory.
The program capacity is never reduced if device comments are transferred to the PLC.
*Comment / the number of label save-store
KV-5500/5000: about 96,000 (Ladder 260k step, no label)
KV-3000: about 30,000 (Ladder 260k step, no label)

 Two device comments can be stored.


Click the "Tool" -> "Option" -> "Set display mode" and set one of the two device comments to appear.
* Only one of the two is transferred to the PLC.

 Device comments can be replaced.


In the "Device comment edit" window, press "ctrl + H".
You can also use copy and paste from EXCEL to
replace device comments.
 Bit comments for word devices can also be registered.

- 22 - KV0475E_C
-

Entering contacts/shortcut keys


There are many methods available to enter ladder programs with the KV STUDIO.

Directly entering commands


Directly enter the leading character of a command from the keyboard.

(Example 1) Entering "LD/OUT"

1) Enter "LD_R000" and then press the Enter key.

2) Enter "OUT_R500" and then press the Enter key.

3) Completed

- 23 - KV0475E_C
-
Entering commands
Many different ways of entering commands are supported.

One-touch switching with a


single click of the key

One-touch switching with a single


click of the + key

(Example 2) Entering an MOV operation The "Directly entering commands


using mnemonics" dialog box
appears. Suggestions for text entries
also appear at the same time.

Point the cursor over the cell where


you enter commands, and then
press the key on the keyboard.

Press the Enter key to display ladder


Enter a command, and
symbols on the "Ladder Editing" window.
then enter an operand.

You do not need to press .

- 24 - KV0475E_C
-

 Functions to assist in entering commands and operands


The following functions are available to assist in entering commands and operands when you enter them directly.

 Displaying a list of commands


When you enter the initial character of a command, the "Suggestions for command entries" dialog box appears
showing all commands that begin with the initial entered character so that an appropriate command can be
selected.

The "Suggestions for command entries" dialog


box showing all commands that begin with the
initial entered character

 Brief description of command operands


When you enter a space following the end of the command you have entered (selected), a brief description of the
target operand and suggestions for entries follow.
Suggestions for entries include a history of devices and constants that have previously been entered are shown
first. Otherwise, special relays (CRxxxx) are displayed as suggestions for entries.

Suggestions for entries are


displayed. Otherwise, without a
history, CRxxxx are displayed.

 A quick search of unused device numbers


When you enter a question mark (?) following the device type, unused devices are displayed as suggestions for
entries. This is useful when using devices with less resource consumption including timers and counters.

Unused devices are listed as suggestions for


entries

 Performing a reverse lookup of device numbers from device comments -RT EDIT-
Enter a device comment to perform a reverse lookup of device numbers.

A part of the device comment helps perform


a reverse lookup

- 25 - KV0475E_C
-
Expanded ladder mode
Multiple out coils can be entered in a rung.

OR circuits, which are regularly used for programming, help to reduce the number of rungs.
If you are not familiar with OR circuits, uncheck the "Expanded ladder mode".
Select the "Edit"  "Edit mode"  "Expanded ladder mode" to uncheck the Expanded ladder mode.

Other useful ways to enter ladder programs - Part 1 -

 Change only device numbers


Select the target device you want to change on the Simply type in
"1200” ...
Editor and type in a value. Only the number is
changed. The device type is left unchanged.

Other useful ways to enter ladder programs - Part 2 -

 Incrementing/decrementing device numbers


Select the target device whose number you want to change on the Editor. Press to increment the device
number (the number is increased by 1). Press to decrement the device number (the number is decreased
by 1).

Incremented (increased) Decremented (decreased)

Calling up commands help

Select an unknown command on the Editor, and then simply press key. The correct page of
the INSTRUCTION HELP opens.

- 26 - KV0475E_C
-
Shortcuts
 Shortcut key list
Select "Help (H)"  "Shortcut key list (K)" from the menu. The shortcut key list (PDF), which is useful when entering/editing ladder
programs, appears.

 The Shortcut key list is included in the Appendices section of the “KV STUDIO User's Manual”.

- 27 - KV0475E_C
-

Entering mnemonics
You can also use a mnemonic language to enter ladder programs. Mnemonic programs created with a text editor (including Notepad)
can be copied and pasted.

Select "Edit"  "List edit" from the menu to open the "List edit" window.

Other procedure

 Useful ways to use the mnemonics list


Useful ways to use the mnemonics list
Using this mnemonics list will make it easier to enter ladder programs.

Simply drag and copy


the whole mnemonics list

Paste the copied mnemonics


list to the List edit dialog box

You can easily enter any


sample ladder programs
introduced in manuals.

Click the "Insert" button to enter


ladder programs.

- 28 - KV0475E_C
-

Programming considerations
This section describes some considerations specific to programming.

(1) Timer
 The timers for KV-5000/3000 are all 32-bit timers.
 The settings can be specified in the range of Unsigned 32 bit (0 to 4294967295).
 The unit of measure for timers, which is specified by a command, is not dependent on timer
numbers.
T 100ms
TH 10ms
TS 1ms
TU 10μs
 A timer uses a subtract method. When the setting is 0, it is instantaneously ON.
 The current values/contacts, updated when the T/TH/TS command is run, are more precise
and sophisticated than those updated when a batch process is executed by the END
processing.
Note) Two (2) words are occupied when the timer's setting is done with one or more
devices.

(2) Counters
 The counters for KV-5000/3000 are all 32-bit counters.
 The settings can be specified in the range of Unsigned 32 bit (0 to 4294967295).
 There are two types of counters. One is counted by power rail, and the other reset by power
rail, either one of which is selectable.

OUTC Counted by power rail

C Reset by power rail


 The current values/contacts, updated when the OUTC/C command is run, are more precise
and sophisticated than those updated when a batch processing is executed by the END
processing.
Note) Two (2) words are uniquely controlled when the timer's setting is done with one or
more devices.

- 29 - KV0475E_C
-

(3) Different ways to differentiate data types


 Double words are specified with a suffix.
(Example) DMOV .U Unsigned 16 bits
is not correct .S Signed 16 bits
MOV.D .D Unsigned 32 bits
is correct. .L Signed 32 bits
.F Floating real number
 The default, specified on the toolbar .DF Double floating real number

of the KV STUDIO (above), is without a suffix.

- 30 - KV0475E_C
-

Software layout
Various windows/dialog boxes, which are set to floating by default, can be docked to the main window of the KV
STUDIO.

Docking Navigator

Click and drag


the title bar
Docking Navigator

Docking Navigator type Description

Appears in the up/down, left/right position of the edit image.


Docked to the up/down, left/right position of the edit image when the
mouse cursor is dropped onto these marks.

Displayed when the mouse cursor is held on the Ladder Editing window.
Docked to the up/down, left/right position of the Ladder Editing window
when the mouse cursor is dropped onto these marks.

Appears when the mouse cursor is held on the workspace or the output
window.
 Docked to the up/down, left/right position of the Docking target window
when the mouse cursor is dropped onto these marks.
 Appears as a tab on the Docking target window when dropped onto the
center of the Docking Navigator.

- 31 - KV0475E_C
-

 Docking assist
The docking position appears in a grid form on the image when the docking window or the dialog box is held on the
Docking Navigator.

The docking position


appears in a grid form

Drag the target window/dialog box


to be held on the Docking Navigator

Just drop it...

The docking is
completed

- 32 - KV0475E_C
-

Auto-hide function
The ladder editing pane area becomes narrower when many windows and dialog boxes are displayed to create
ladder programs.
The Auto-hide function helps to only display the workspace, the output window or the watch window as necessary,
keeping the ladder editing pane as wider as possible.
Ladder editing pane

Workspace

Device use list

Device comment
edit window

Output window

If the Auto-hide function


is used... Ladder editing pane

 Workspace device Device use list


comment edit window

Output window

Click the PIN icon located on the top right corner of the up/down and left/right workspace, output window, or watch
window so that tabs appear.
A tabbed window or dialog box will be expanded by simply holding the mouse cursor over it.
Icon Description

When clicked, the workspace, output window, or watch window stays as


displayed.

When clicked, the workspace, output window, or watch window appears as


a tab on the up/down, left/right side of the edit image. The workspace,
output window, or watch window is displayed when the mouse cursor is
pointed at to the tab or when the tab is clicked.

- 33 - KV0475E_C
-

Useful ladder commands

The KV STUDIO allows you to use an "ON/OFF delay circuit", a "One-shot circuit", or "Alternate circuit" which is often used as a timer.

Conventionally: 2 rungs 4 commands KV STUDIO: 1 rung 2 commands


ON-delay timer

Conventionally: 2 rungs 5 commands KV STUDIO: 1 rung 2 commands


One-shot timer

Conventionally: 3 rungs 7 commands KV STUDIO: 1 rung 2 commands


Alternate circuit

Conventionally: 2 rungs 6 commands KV STUDIO: 1 rung 2 commands


OFF-delay timer

Conventionally: 3 rungs 6 commands KV STUDIO: 1 rung 2 commands


Flicker circuit

Useful ladder functions

The KV STUDIO allows you to use the Script language to describe ladder programs. Script-specific functions (command), like ABS
function, are available.

Ladder: 3 rungs Script: 1 rung


ABS function

- 34 - KV0475E_C
-

Transferring ladder programs for monitoring


Created programs can be transferred to PLC to monitor their behavior.

Writing programs
Created ladder programs are written to the "KV-5000" that is connected to a PC.
Make sure that the "KV-5000's behavior selector switch" is set to the RUN mode position.

Behavior selector switch

RUN 側に
Set in RUN
します。
mode
position

Select "Monitor/Simulator (N)"  "Transfer to PLC -> Monitor mode (C)" from the menu.

Other procedure 

 Click the icon.

Select "Transfer to PLC  Monitor mode (C)…" to convert the target/transfer ladder programs to machine codes.

- 35 - KV0475E_C
-

 When the created ladder programs contain no errors


If the created ladder programs are correct, they are converted and then checked if they can connect to the
"KV-5000/3000".
Once confirmed that they can, the "Transfer program" dialog box appears.

Transfer item info


display area

Item Description
Items for which a checkbox has been selected are transferred to PLC.
Transfer items (I) Additionally, the detailed information of the selected item is displayed in the
transfer item information area on the right side of the dialog box.
Transfer item info The contents displayed may vary with different transfer items selected.
Only the item name is displayed for items for which detailed settings are not
display area necessary.
“Select all (S)” Selects the checkbox of all transferred items.
“Cancel all (D)” Deselects the checkbox of all transferred items.
Clear module/macro in If this checkbox is selected, the module/macro written into PLC is cleared before
PLC (Q) transfer, and then the project is transferred.
Transfer in If this radio button is selected, PLC is temporarily switched to the PROGRAM
PROGRAM mode (P) mode, and then the project is transferred.
If this radio button is selected, the project is transferred in RUN state.
Transfer in RUN mode
When the program is transferred in RUN state, some contents of the "Unit setting
(R)
info" and the "CPU system setting" cannot be transferred.

If the "Transfer program" dialog box appears, it means that the writing is ready to start.
Check the transfer item, and then click the "Execute" button to transfer the program.

 Once the program transfer is completed


Once the program transfer is completed, the following dialog box appears. Click "No" to switch PLC to RUN mode.

If "Yes" is selected, PLC remains in


PROGRAM mode.
If PLC is not in RUN mode, it won't run.

- 36 - KV0475E_C
-
The following message appears in the "Output window".

Message showing that the writing was successful.

Now the ladder program has been successfully written to PLC.

 When the created ladder programs contain errors


If the program is not correctly written, it is not correctly converted.

The contents of each error appear in the "Output window". Refer to them to modify the program.

 Module name
 Line number
 Column number
 Error contents
For which an error
occurred, are shown.

In addition, click the error message in the "Output window" so that the cursor moves to the head of the appropriate
rung from the "Ladder Editing window".
The cursor moves to
the ladder rung that
shows the error
message.

Double click on the


error message in the
Output window

Tip  Even if there are two or more errors in the program, or even if the whole module is not correct, all the
errors appear in the "Output window" so that the cursor can easily jump to each error.

- 37 - KV0475E_C
-

Setting disabling of rungs


When converting ladder program blocks that contain description errors (including unfinished ladders), performing the "Set disabling of
rungs" helps easily avoid conversion errors.
To set disabling of rungs, select the rung (ladder program block) to be disabled, and simply select “Edit (E)”  "Set disabling of rungs
(Q)"  "Submit (Q)" from the menu. To cancel the disabling of rungs, select “Edit (E)”  "Set disabling of rungs (Q)"  “Cancel (W)".

Other procedure To set disabling of rungs: . To cancel disabling of rungs:

Disabling of rungs

Invalid ladder program blocks prevent conversion

Saving ladder programs


Save a ladder program.

Save project as
Save a ladder program on the PC.

Save changes to the current ladder program.

Save the current ladder program with another


name. (.kpr)

Save a copy of the current ladder program in


the compressed format. (.kpz)

Save a copy of the current ladder program so


that it can be read and written correctly with a
memory card.

- 38 - KV0475E_C
-

Chapter3
Software debugging

- 39 - KV0475E_C
-

Debugging procedure
This chapter explains the general debugging procedure.

STEP 1 Check the PLC program


Read the program

Problems with the unit,


STEP 2 Search for program
errors such as program and
Use the various search tools
setting errors

STEP 3 Continue searching for


errors
Use the various debugging tools

STEP 4 Check the PLC status


visually
Check the access windows
Additional procedures
Trouble specific to the PLC
STEP 5 Check for PLC errors
Monitor for errors

- 40 - KV0475E_C
-

Reading a ladder program


Read a program stored in the PLC to a PC.

Read the program


Read the ladder program stored in the KV-5000 to a PC.

Open KV STUDIO by double-clicking the icon.

“Monitor/Simulator”→“Read from PLC ->Monitor mode”

* ”Read from PLC ->Monitor mode”…This option reads the program and then activates monitor mode.
“Read from PLC”…This option only reads the program.

【Execute】をクリックします。

- 41 - KV0475E_C
-

Mode Switching
When you access the PLC from a PC, you can switch between several modes.

 Editor mode: Mode for writing a program


■ Monitor mode: Mode for monitoring the PLC
■ Online Editor: Mode for writing a program while monitoring the PLC
■ Simulator mode: Mode for checking program operation using only a PC

When programming on the desktop, use the Editor and Simulator modes.
When debugging a program, use Monitor mode and Online Editor.

Open the sample program “Seminar01_PLC_monitor” and transfer it to the

main unit.

- 42 - KV0475E_C
-

 Monitoring the program


When program transfer is completed, the Monitor window is automatically opened.

▪Display status of various devices during monitoring

Instructions for
Input Output
timer, etc.

ON

OFF

Monitor-related shortcut keys

- 43 - KV0475E_C
-

Debugging a ladder program (Monitor)


[Batch monitor]
Batch monitor collectively monitors the current values, contact ON/OFF statuses, and registered comments for all
devices according to device type.

Features of Batch monitor


Unit monitor has the following features:
 You can monitor each device type by the serial number. This is the most suitable method when you want
to check various parameters at a glance.
 The buffer memory for each unit can be checked in a list, so it is easy to check whether data has been
stored when an abnormality occurs in a special unit.
 The display format is changed for all devices at once, so you can quickly check serial numbers
regardless of whether they were stored as hexadecimal data or ASCII data.
 There are no restrictions on overlay display.

Displaying Batch monitor


1 In a ladder program, right-click and select “Batch monitor”.
*You can also display the window by selecting “Monitor/Simulator”→”Batch monitor”.

Changes the displayed device

Values can be changed directly

The display format can be changed

Butter memory can be monitored

- 44 - KV0475E_C
-

[Registration monitor]
Registration monitor is for registering any device, and displaying and changing the current values of registered
devices. This monitor comes in handy for batch-checking different types of devices.

Features of Registration monitor


Registration monitor has the following features:
 You can display a list of just the devices you want to view, meaning you can create a dedicated monitor
window.
 You can save the Registration monitor window as “Custom monitor”, so the monitor can be viewed again
even if you shut down the PC.
 You can create a monitor window using drag & drop.
 You can display the index modifier (Z) assignment destination and timing chart.

Displaying Registration monitor


1 In a ladder program, right-click and select “Registration monitor window”.

*You can also display the window by selecting “Monitor/simulator”→”Registration monitor”.

2 Registration monitor is displayed.

* To add a device to Registration monitor, select the device you want to add and drag it to Registration
monitor.

- 45 - KV0475E_C
-

[Saving Registration monitor: Custom monitor]


Registration monitor window

2) Enter a file name.


It is helpful if you name it using the creation date or the name of the process that was being checked.

3) To view a created monitor, click “Monitor/Simulator” and then “Custom Monitor”. The created file
opens.

- 46 - KV0475E_C
-

[Unit monitor]
Unit monitor is a monitor window that is optimized for each expansion unit. Unlike Registration monitor and Batch
monitor, relay and DM values can be viewed easily thanks to the dedicated window for expansion units.

Features of Unit monitor


Unit monitor has the following features:
 DM and relays currently assigned to each unit can be displayed in the state in which they were originally
registered.
 Templates of display formats and layouts are provided for each unit for easy monitoring.
 You can monitor the selected unit simply by selecting the unit to be monitored, without having to worry
about relay or DM assignment status

Note Unit monitor can be selected from the menu only in Monitor or Online editor.

Displaying Unit monitor


1 From the menu, select “Monitor/Simulator (N)” and then “Unit monitor (U)”.
The “Select Unit Monitor” dialog box is displayed.

Other procedure  In the workspace, double-click the unit you want to


monitor.
 In the workspace, select the unit you want to monitor.
Added units are displayed
Then, select “Unit monitor” from the right-click menu.

2 Select the unit you want to monitor and click “Display”.


The “Select Unit Monitor” dialog box is displayed.

Select the unit you


want to monitor.

- 47 - KV0475E_C
-
 KV-AD40 unit monitor  KV-C32XC unit monitor

 KV-ML16V unit monitor  KV-LE21V unit monitor


 KV-L20V unit monitor

- 48 - KV0475E_C
-

Debugging a ladder program (Search)


This section explains how to debug a ladder program.
Find the reason why output R515 does not turn ON in the sample project “Seminar01Monitor&Debug”.

1 Transfer “Seminar01Monitor&Debug” to KV-5000 and switch to monitor mode.

2 Search for R515 to find ladder blocks containing OUT R515.


Press to display the “Search/replace” dialog box.

Device search ( + )
Search for the location of R515 from the device numbers.

You can change the search item.

 Range: Specify the search range.


 Width: Set the search width.
Ex) If you set Trgt “R000” Width “3”, all the numbers in the range R000 to R002 are searched.
 Output target: You can separate the search results into search1 and search2 for managing the history
of search results.

- 49 - KV0475E_C
-

If contact R15000 turns ON,


output R515 is turned ON, so
the cause of R15000 output
can be determined.

3 Place the cursor on contact R15000 (1st cell in 50th line) to jump from contact to coil.

contact coil Jump ( )


By using a contact/coil jump, you can search for a coil (output) that corresponds to a contact or a contact that
corresponds to a coil by pressing just one key ( ).

The instruction words that correspond to the contact/coil jump are as follows:
Contact instructions : LD, LDB, LDP, LDF, LDPB, LDFB, STP, STG instructions
Output instructions : OUT, OUB, SET, RES, KEEP, DIFU, DIFD, ONDL, OFDL, SHOT,
FLIK, ALT, TMR, TMS, TMH, C, CTH, RFSX, RFSY, SFT, JMP, W-ON, W-OFF,
W-UE, W-DE, FRSTM, FRLDM, PMOV, BSR, BSL, RCOM, CTC instructions

Tip If there are duplicate coils, the search is conducted in sequence from the currently selected cursor line.
Each time the key is pressed, the focus shifts to the next coil.

Select an output instruction (coil) and press to move the cursor to the corresponding contact.

Select output instruction (TMR)


and press the F12 key.

Contact instruction corresponding to “TMR


#0 #30”, cursor moves to “LD T0”.

Tip If there are multiple corresponding contact instructions, the search is conducted in sequence from the
currently selected cursor line. Each time the key is pressed, the focus shifts to the next contact.

- 50 - KV0475E_C
-
Place the cursor on contact R15000 (1st cell in 50th line) and press the key.
Use the same procedure to check the cause of output of each contact until you reach contact R10003 in the 7th
line of the ladder program.

Selecting contact R15000


and pressing the Space key
creates a cross-reference.

4 Repeat the same procedure and press the key on a contact (execution condition).

Found the reason why R15000 is not output

- 51 - KV0475E_C
-

[Other searches]

Cross reference ( )
Clicking the Space key while the cursor is placed on a contact shows you where and with
what instruction words the contact is being used.
You can also sort contacts according to the sequence in which they appear or by
instruction words.

Consecutive search (ENTER)


You can conduct consecutive searches during monitoring by pressing the ENTER key on the
device you want to search.

Select “Tool”“Option”“Setup edit/key”, and then click the “Start up direct entry by ESC key” check box.

- 52 - KV0475E_C
-

Device use list


Select “View” and then “Device use list” (Ctrl+E)
A list of devices that have been used is displayed.
You can extract data from all lists showing used devices and unused devices.

Display device use status


You can conduct consecutive searches during monitoring by pressing the ENTER key on the
device you want to search.
Click “View”“Use status display”

The display shows a device’s use count.

If a device is used multiple times by an


instruction word, e.g. BMOV, all instances are
counted.

- 53 - KV0475E_C
-

Debugging a ladder program (Tool)


The tools allow you to switch a device’s ON/OFF status manually.

Forced set/reset register


Normally, the ON/OFF status of a relay assigned to an expansion unit cannot be changed. When forced set/reset is
registered, the refresh status and ladder program are ignored and the status of a relay device is forcibly changed.

5 Register forced set for R10003, register forced reset for MR2002, and switch OUT MR3000 to ON.
Select “Forced set/reset register (X)”→“Set register (S)” from the menu that appears by right-clicking contact
R10003.
Likewise, click “Reset register (R)” for MR3001.

Forced set Forced reset

Indicates that forced


set/reset is being
executed.

You can also register forced set/reset from the “Forced set/reset register” dialog box.
From the menu, select “Debug (D)”“Forced set/reset register (X)”.

- 54 - KV0475E_C
-

Derivation monitor
Derivation monitor monitors the rising and falling count for the specified bit device.
You can monitor up to 4 devices. “Debug”“Derivation monitor”

Even if you are monitoring a ladder program, you cannot visually


perceive high-speed ON/OFF.
Derivation monitor is useful for checking high-speed ON/OFF in a
device’s status.

- 55 - KV0475E_C
-

Real time chart monitor


Real time chart monitor is a function that can monitor the statuses of bit devices and word devices at various
sampling periods such as the scan unit. This section explains the functions of Real time chart monitor.

 Features of Real time chart monitor


 Bit data/word data can be sampled per scan time or at the desired period.
 Trigger conditions and debug traps can easily be set up.
 Data that was traced using the CPU’s trace function can be read and displayed in time chart format.
 Real time chart monitor can be started when KV STUDIO is in Editor mode, Monitor mode, or Online edit mode.
Even if KV STUDIO is not started, Real time chart monitor can be started separately.

Tip  Real time chart monitor records changes in bit devices and word devices.
 Scanning of the PLC does not stop even if trigger conditions are met on Real time chart monitor.

Using Real time chart monitor


1 Transfer the sample project “Seminer02_realtime_chart_monitor” to the PLC.
Open the sample project “Seminer02_realtime_chart_monitor”. From the menu, select “Monitor simulator
(N)”“PLC transferMonitor mode (C)”.

Other procedure 

 Click the icon

- 56 - KV0475E_C
-
2 In the “Transfer program” dialog box, click “Execute”.
Click the “Execute” button without changing any of the transfer items.
In RUN mode, a dialog box is displayed to confirm overwriting.
Click “Yes”.
When program transfer is completed, KV STUDIO switches to Monitor mode.
With the 5th and 6th lines of the “KnightRider” module selected, right-click to display the menu and open
Registration monitor.

Current mode

Registration monitor

3 From the “Registration monitor” dialog box, start “Real time chart monitor”.
Select “Real time chart monitor (H)” from the menu that appears by right-clicking in the “Registration monitor”
dialog box.
Real time chart monitor starts.

Other procedure You can also start Real time chart monitor from the menu that appears by right-clicking

in the ladder edit window, from the KV STUDIO toolbar or the icon on
Real time
chart monitor

the desktop.
- 57 - KV0475E_C
-
Tip Adding a contiguous device
Confirm that the cells (blank cells) below the registration device R500
in the Devices list are selected, and press on the keyboard.

Other procedure Select “Increment registration (I)” from the menu that
appears by right-clicking the device to be incrementally
registered.

Each time you press , the device obtained by offsetting the


above registered device by +1, is additionally registered (incremental
register).

Tip You can also register a device in Real time chart monitor by selecting
the device to be registered from the ladder editing window and
dragging & dropping it.
You can register a total of 24 devices in Real time chart monitor: 16 bit
devices and 8 word devices.

4 Start monitoring (tracing).

Click the icon in the Real time chart monitor toolbar.

Other procedure 
 From the Real time chart monitor
menu, select
“Communicate (C)”  “Start
tracing (S)”.

- 58 - KV0475E_C
-
5 Stop monitoring (tracing).

Click the icon in the Real time chart monitor toolbar.

Other procedure 
  From the Real time chart monitor menu,
select
“Communication (C)” “Stop tracing (E)”.

 Changing the sampling period (trigger)


The sampling period (trigger) is set to “SCAN” by default.
To change it, open the “Trigger setting” tab and change the value in
“Sampling period”.

You can also set trigger conditions based on bit device


ON/OFF and the value of the word device.
Select the sampling period
from the pull down menu.
Example)

 Time axis (horizontal) zoom in/zoom out


Use this feature to adjust the display range of the time axis (horizontal) of a sampled (traced) waveform.

Zoom in time axis: or

Zoom out time axis: or

Zoom out Zoom in

- 59 - KV0475E_C
-

 Measuring a waveform
Use the cursor to measure a sampled (traced) waveform.

1 Display the cursor.

Click the icon in the toolbar.

2 Select cursor A and click the position where you want to start measuring the waveform.

Click the icon in the toolbar.

Fine adjustments will be made in the next step, so position cursor A by clicking near the measurement start
position.

Cursor

3 Finely adjust the position of the cursor.


Use the keys on the keyboard to finely adjust the position of the cursor.

You can also adjust the position by dragging the cursor with the mouse.
When the mouse pointer is placed over the cursor, the cursor changes to .
You can then adjust the position by dragging the cursor.
You can even zoom in/zoom out the grid.
Zoom in/zoom out horizontal grid: (horizontal zoom in) / (horizontal zoom out)
Zoom in/zoom out vertical grid: (vertical zoom in) / (vertical zoom out)

If you lose sight of the cursor


When you zoom in/zoom out the grid, you might lose sight of the cursor because it is displayed outside the display area.

If this happens, clicking the icons in the toolbar automatically adjusts the display position of the cursor so that it appears in the
center of the display area.

- 60 - KV0475E_C
-
4 Select cursor B and click the measurement end position.

Click the icon in the toolbar.

As with cursor A, click near the end position and then finely adjust it.

Cursor A Cursor B

Displays the positions (assuming data starts at 0) Displays the distance (sampling count)
and date/time of cursors A and B. and time (ms) between cursors A and B.

 Zooming in to the waveform display area


This tool zooms in to the display area of a sampled (traced) waveform.
In the time chart display area, select a device that you want to zoom in to, and use the mouse to drag the display
range memory.

- 61 - KV0475E_C
-

 Adjusting the waveform display position


This tool adjusts the display position of a sampled (traced) waveform.
Move the display position by dragging & dropping a device within the time chart display area.

To return moved waveforms to their original positions:


From the menu, select “View (V)”→ “Tile waveforms (L)”.

To display all waveforms overlapped on one another:


From the menu, select “View (V)”→“Overlap waveforms (O)”.

To change the registration sequence of registered devices:


In the device list, change the sequence of registered devices by dragging them.
If the waveforms are currently displayed, the display order of the waveforms also changes at the same time.

- 62 - KV0475E_C
-

 Saving a sampled waveform to a file


You can save a sampled (traced) waveform (data) as an “.rtc” format file.
From the menu, select “File (F)”“Save as (A)”, specify a file name and then save the file.

 Opening a saved file


You can open a waveform (data) saved by Real time chart monitor.
From the menu, select “File (F)” “Open file (O)”. In the “Open file” dialog box that appears, specify the file you
want to read.

Tip

The example here shows reading out the file “realtime_chart_monitor.rcm”.

Read out waveform (data) Start sampling (trace)

Clicking the Start trace icon starts sampling (tracing).

- 63 - KV0475E_C
-

Break function
The KV-5000/3000 has various functions that support debugging. A break is a function that momentarily stops the
KV-5000/3000 at the desired step, enabling status confirmation at intermediate steps and during ladder execution,
which has conventionally been difficult to perform.
You can use the break function only during monitoring/simulation.

Device break
A device break invokes a break when there is a change in status of the specified bit device or depending on the
value of a word device.
At any one time, you can set up to 1 condition for monitoring, and up to 16 conditions for simulation.
From the menu, select “Debug (D)”“Setup device break (B)” and set the conditions for implementing a break in
the “Setup device break” dialog box that appears.

Other procedure  From the right-click menu, select “Setup device break (K)”.
 Click the icon.

You can set only 1


condition for monitoring

Example Transfer the sample project “Seminer03_Device_break” to the PLC and switch it to the
monitor status. (Set the PLC to RUN status.)
*For details on the monitor procedure, see P.31 of this text.
The current values of the devices DM2800 to DM2808 displayed in the Registration monitor window
change in the range 0 to 15.

Change in the
range 0 to 15

- 64 - KV0475E_C
-
Next, set the device break conditions.
DM2810 is a device that increments the current value once every 2 seconds, so add a condition to
cause a device break to be invoked when the current value of DM2810 reaches 50.

KV STUDIO <monitor status>

In the “Setup device break” dialog box, click the “OK” (or “Apply”) button.
When the current value of DM2810 reaches 50, a device break is invoked and scanning stops.

KV STUDIO while a break is invoked


When a break is
invoked, a mnemonic
list is automatically
displayed.

indicates the
ladder line where the indicates the step
scan stopped where the scan
stopped

Current value during a


break. Differs from the
current value during
RUN.

Indicates what break


conditions caused the break

- 65 - KV0475E_C
-
To resume a scan, delete the break conditions from the “Setup device break” dialog box and then click the RUN
icon .

Uncheck the box or


delete the conditions.

 After a break occurs, the icons (Execute 1 step), (Execute 1 scan), and (Execute 1 block)
become available.
 To delete a break point, double-click .

Calculation error break


This function monitors CR2012, which turns ON when an illegal calculation is executed, and invokes a break when
CR2012 turns ON.
To add calculation error break conditions, simply click the “Calc error” button in the “Setup device break” dialog box.

After registering CR2012 (calculation error), click the “OK” or “Apply” button to cause the break conditions to take
effect.
Setting “MR000” to ON in the “Registration monitor” window causes a calculation error break to be invoked.

Double-click the current value


of MR000 to set it to .

- 66 - KV0475E_C
-

Line break
You can activate the break function at any location (step) in a ladder program.
Unlike a device break, scanning always stops at a specified break point.
You can specify a maximum of 4 break points at any locations within a mnemonic list.

Indicates a break point.


Double-clicking on any
mnemonic enables you to set a
maximum of 4 break points.

- 67 - KV0475E_C
-

Debugging a ladder program (Other functions)


[Access window]
The access window is a 2-color backlit LCD display on the KV-5000/3000. In addition to error messages, it displays
device values and various types of information about expansion and particular units.

Checking the color ★★


You can tell whether the PLC is operating or
has stopped depending on the color of the access
window on the CPU.
It also indicates whether the PLC is operating or
has stopped.

RUN mode (operating): green

PROGRAM mode (stopped): red

Checking error messages


Error messages appear in the access window.
 If an error message is displayed and the access
window is red, the error may be serious.
CPU Err E**
The CPU is stopped. CPU Err E57
No End Unit
Check the action to be taken on P A-2 of the CPU
User’s manual.

 If an error message is displayed and the access


window is green, the error is minor. CPU Err W128
CPU Err W*** Ladder Calc
Even though an error is displayed, the CPU is operating.

When an error occurs on KV-5500/5000/3000 and is indicated on the access window, the error remains on
the access window even if you eliminate the cause of the error. (The same applies even if the power is
momentarily turned OFF.)
If the indicated error is minor, you can resolve it by pressing a switch on the CPU.
(A prerequisite is that the error must have been resolved.)
To reset an error display by momentarily turning OFF/ON the unit, select “View”“CPU system setting” from
the KV STUDIO menu. Then, in “Operation during error” check “Eliminate CPU error when power ON”.

- 68 - KV0475E_C
-

Switching the display language

Not displaying minor errors on the access window


You can set up the KV-5500/5000/3000 so that minor errors are ignored and not displayed
on the access window. Minor errors comprise calculation errors (errors where CR2012 turns
ON) and unit errors (errors that occur in the special unit).

In KV STUDIO, select “View”. In “CPU system setting”, select “System setting”. Then, in “Operation
during error”, change CPU operation when a calculation error or unit error occurs to “Continue (ignore)”.

- 69 - KV0475E_C
-

Unit monitor mode ★★


If abnormal data appears on the PLC special unit, check the status of the unit.

You can use the access window to monitor and set up any unit by pressing the direct access switch on any
expansion unit or special unit such as an I/O unit connected to the CPU.
To return the window for an expansion unit or special unit to the original window, press the direct access switch of
the unit currently displayed on the access window again.

Press the direct


access switch of an
additional unit

The access window display


changes to the window for the
unit whose switch was pressed

The access window


display switches

The same kind of access window display is also possible for


other types of additional unit. For details, refer to the manual
for each unit.

Device mode
This mode enables you to monitor and change the values of the PLC device.

 Switching to device mode


M
STEP 1: Press the “M” CPU setting key twice.
STEP 2: Press the “ ” CPU setting key once.
CPU setting keys
The current value of the device is now displayed on the access window.

 Changing the display device type


STEP 3: Press the “ ” CPU setting key once.
STEP 4: Use “” and “” to select the device type you want to display.
STEP 5: Use “”, “” and “ ” to select the number of the device you want to display and use “ ” to set the
selected number.
The current value of the device is now displayed on the access window. In this state, you can change the device
number by pressing “” or “”. If you hold down “” or “”, the device number will change rapidly.

 Changing the display format


STEP 6: Press the “ ” CPU setting key twice.
STEP 7: Use “” and “” to select the display format you want to display and use “ ” to set the selected format.
The display format of the device displayed on the access window is now changed.

- 70 - KV0475E_C
-

[Error monitor]
The Error monitor enables you to check the error status and log of the PLC.

“Debug”“Error monitor”

This area displays the current PLC status.

This area displays current errors. If an error is not clear


when you press the “Clear” button, it becomes a regular
error and action must be taken.

This area displays a history of past errors.


The history consists of 32 serious errors and 32 minor
errors.

This area displays details of the selected error and action


to be taken.

- 71 - KV0475E_C
-

[PLC verification/synchronization]
This function verifies the data in a PC against the data stored in the PLC.

Verifying a program

Data in the PC OK/NG indicator Data in the PLC

Process the checked items by clicking “Verify”, “Write to PLC”, or “Read from PLC”.

Verification results

 Extracts and displays the verify NG rungs only


Since each mnemonic is verified individually, only the verification NG rungs are extracted and displayed.

 Can transfer and read individual modules


You can transfer or read just the modules you want to transfer or read.

 You can see “who” changed a program and “when”


You can see the latest updater of a program. This also makes version management of devices simple.

- 72 - KV0475E_C
-

Chapter4
Advanced programming

- 73 - KV0475E_C
-

Modules
Conventional PLC executed one program per project, but the KV-5000/3000 operates several programs per project.
The KV-5000/3000 does not execute an entire program at each scan, as was the case with conventional programs.
Instead, by managing a split program as independent parts (modules), it can execute just the program required in
circumstances.

<Up until now> <On KV-5000/3000>

Before you start programming, split the entire program into modules according to types that you have determined
beforehand.
Once you have completed each individual module, create a program that controls the timing at which the modules
will be started and stopped.

- 74 - KV0475E_C
-

[Types of modules]
Every-scan module
The every-scan module is a module that is executed at every scan when the KV-5000/3000 is in RUN mode.
 One every-scan module is automatically created when a new project is created.
 A project requires at least one every-scan module.
Initialize module
The initialize module is a module that is executed only at the first scan when the KV-5000/3000 starts
operating (when the power is turned on and PROG switches to RUN). (This module cannot be started at the
second or subsequent scans.)
 This module is used for initializing each unit or function.
Standby module
The standby module is a module that does not execute until a start instruction (MDSTRT instruction) is
executed by another module.
 After module startup (after the MDSTRT instruction is executed), this module is executed at every scan,
similar to the every-scan module. It continues operating until a stop instruction (MDSTOP instruction) is
executed.
Fixed period module
The program within a fixed period module is executed at a previously specified period and separately from
the usual scans. You can use only 1 fixed period module per project.
 Similar to an interrupt program, fixed period execution is permitted/prohibited by the EI/DI.
Set the period (0.2 to 6000ms), etc., in “CPU system settings”.

Examples of using the modules


There are various merits to splitting a program into modules.
For example, a module that has not started is not scanned, so scan time is reduced. If trouble arises, the unstable
module can be isolated (not started), so this approach is effective for promptly detecting the cause.

 Creating modules by work type


Modules are useful when various types of work are manufactured by a single device. If a type must be is added, you
simply have to add a module.
To switch a module, use an external
Type Amodule input such as the touch panel or
switches.
Type B module
Legend
Type C module
Module : Every-scan module
Module : Standby module

 Creating a module with input from several engineers


Modules are useful when several engineers work together to create a single project. Each engineer uses a local
device for programming, greatly reducing burdensome preparation tasks such as allocating a device to each person
in charge.

- 75 - KV0475E_C
-
 Verifying startup/stop of a module that uses the sample project
“Seminar04_Module_switch”
Switch operation (modules) using an external input such as switches or indicators.
In cases where work of various types is conveyed along a single line, operation must be changed for each type of
work. This can be accommodated by determining the type of work immediately beforehand and switching the
program for each type. If a type is added, the program can be changed easily by adding a module.

Check the module execution order using the seminar project “Seminar04_Module_switch”.

 Project configuration of the sample project “Seminar04_Module_switch”


”Seminar04_Module_switch” has the configuration shown below.

Unit configuration and unit


device number

A “module control” module is registered as the


module that must be executed at every scan

 Overview of module-to-module control


毎スキャンモジュール
Every-scan module 待機モジュール
Standby module
Startup/stop

 Description of operation of each standby module


FLICKER Turns the even numbers and odd numbers from R500 to R515 alternately ON/OFF at a
period of 0.5 second.
LEFT-ROTATE R500 to R515 blink in ascending order at a period of 0.1 second. The CPU
lamps blink in order from top to bottom.
RIGHT-ROTATE R500 to R515 blink in descending order at a period of 0.1 second. The CPU
lamps blink in order from bottom to top.

- 76 - KV0475E_C
-
 Description of a module control (every-scan module) ladder program
The following shows a ladder program with the module name “process switchover”.

At operation start, start the “FLICKER” module.

Switch the module at the rising edge of the


switchover request switch (R000).

If the “FLICKER” module has already started


at switchover, stop the “FLICKER” module and
start the “LEFT-ROTATE” module.

If the “LEFT-ROTATE” module has already


started at switchover, stop the “LEFT-ROTATE”
module and start the “RIGHT-ROTATE”
module.

If the “RIGHT-ROTATE” module has already


started at switchover, stop the “RIGHT-ROTATE”
module and start the “FLICKER” module.

 Module control instructions


MDSTRT “module-name”·····················Starts a standby (stopped) module
MDSTOP “module-name” ····················Stops an active module

Instructions operate by a rising or falling edge. An active module remains active until the stop
instruction is executed, and a stopped (standby) module remains stopped until a start instruction is executed.
However, start/stop cannot be controlled for an initialize module.

 System device
The module within a ladder indicates the active bits of a module. When a module with the contact name
“_module-name” is active, the contact is ON.
Apart from “Active bits”, the system device contains a “bit that turns ON only one scan at start of
module/macro execution (@CR2008)” and a “bit that turns OFF only one scan at start of module/macro
execution (@CR2007)”.

* For details on the system device, refer to “Module system device” (page 3-105)” in the
“KV-5000/3000 Series User’s Manual”.

Open the sample program “Seminar04_Module_switch” and transfer it to

the main unit.

- 77 - KV0475E_C
-
 Procedure for checking operation of “Seminar04_Module_switch”

When SWITCH (R000) is turned ON, the LED for R500 to R515 switch.

The LED outlined in red switch.

 Operation can also be checked on Realtime chart monitor.

FLICKER LEFT-ROTATE RIGHT-ROTATE

10 In the “Monitor” tab of Workspace, check the modules that are currently active.
Select the “Monitor” tab in Workspace.

The icon of an active module is


“ ” (appears in green)

The icon of a stopped (standby)


Select the “Monitor” tab module is
“ ” (appears in white)
The “Monitor” tab is
displayed only when KV
STUDIO is monitoring or
simulating.

Module’s startup status immediately following operation start

- 78 - KV0475E_C
-
11 Turn Switch 0 from OFF to ON, and verify that the module’s startup status changes.
The flashing of the I/O monitor lamps beside the access window enables you to check differences in the
operations of each module.

Switch 0 Switch 0
OFFON OFFON

- 79 - KV0475E_C
-

Bookmark function
The bookmark function treats a line comment as a “bookmark”. It is useful for modules that contain a large number of ladder lines or
when you want to create a program without splitting it into modules.

MODULE

BOOKMARK

You can copy, delete, and jump


to bookmarks.

+ displays the comment list.

- 80 - KV0475E_C
-

Local device
A local device is a device that can be used independently in a module or macro. Since it is treated as a separate
device, even if it uses the same device number in multiple modules or macros, it eliminates the need to manage
assignment of devices used in modules and macros.
To use a device as a local device, simply add “@” to the beginning of the device’s name.

The device number is duplicated.


The number must be changed.

 Merits of using a local device


When you split a program into multiple parts, you can prevent device contention (double coil) among the
modules so that you do not determine device assignment beforehand.*
* You must determine assignment of global devices beforehand.
 The number and range of local devices that can be used is determined
beforehand. You can set these values in “Entire assignment setting of local
devices” in “CPU system setting”.
 The timer and counter can also be used as local devices. Devices that
cannot be used as local devices are B, W, ZF, CTC, CTH, Z, CR, and CM.
If you create a program using a local device, you can re-use modules simply by changing the
global devices.
 You can easily re-use modules by registering them in the module library.
 You can even use a program created by another engineer simply by changing the global devices.

Simply add @

Direct input Direct input

The characters
are a different
color

Description when using a Description when using a


global device local device

- 81 - KV0475E_C
-

 Operating a local device


Use the sample project “Seminar05_Local_device” to check operation of a local device.
“Seminar05_Local_device” is a program that causes output R500 to light for 3 seconds at 6 seconds intervals and
output R501 to light for 1 second at 2 second intervals.

 Project configuration of the sample project “Seminar05_Local_device”


”Seminar05_Local_device” has the configuration shown below.

The “Station A” module causes R500 to light for


3 seconds at 6 second intervals.
The “Station B” module causes R501 to light for
1 second at 2 second intervals.
Both modules execute at every scan.

 Programs of the “Operation start complete” and “Operation ready” modules


They use the same timer number, but they are
local devices so there is no device conflict

“Station A” module ”Station B” module

- 82 - KV0475E_C
-
 Verifying operation of local timers using “Seminar05_Local_device”

1 Transfer the sample project “Seminar05_Local_device” to the PLC and switch to monitor
mode. (Switch the PLC to RUN status.) Check the operating status of each timer using Registration
monitor. In the Registration monitor window, register the local timer and the global device
R500 for the module name “Operation start complete”.

Operation start complete Operation ready

Details in Registration monitor


 Displaying the assignment destination of a local device
In Monitor mode and Simulator mode, you can easily display the assignment destination (global device)
of a local device.
From the menu, select “View (V)”“Display local assignment destination (W)”.

Other procedure Click the icon in the toolbar.

Displaying the assignment destinations of local devices

- 83 - KV0475E_C
-
Timechart

 Graduations on the timechart


In some cases a device’s ON/OFF timing becomes easier to see if you increase the number of graduations on the timechart.
You can change the graduations from the menu that appears by right-clicking in Registration monitor.

 Watch window
Using watch window makes it easy to display a device’s current values.
However, use the Registration monitor window if you want to display
different module/macro devices at the same time or several windows.
To display the watch window, from the right-click menu, select
“Display/hide watch window (M)”.
For details of how to use watch window, see page 101.

Other procedure  Pressing switches


between display/hide.
 From the menu, Watch window
select “Monitor/
Simulator
(N)””Display/hide
watch window (N)”.

- 84 - KV0475E_C
-

 Example of using a local device


In conventional programming, a number of program blocks borne from functions and statuses were combined to
form a single program. In many cases, the range of devices to be used was allocated (mapped) to each program
block (module) before programming was started, so prior device management was difficult.

[Programming that does not use a local device]


** assembly ** ** print** ** TEST **

▪▪▪

Device assignment Device assignment Device assignment


in the Assembly module in the Print module in the Test module ▪▪▪ Input/output relay etc.

MR000 to MR2915 MR3000 to MR5915 MR6000 to MR6915 R30000 to R40000


LR000 to LR0915 LR1000 to LR1915 LR2000 to LR2415 DM10000 to DM20000
DM0 to DM1999 DM2000 to DM2999 DM3000 to DM3999
EM0 to EM1999 EM2000 to EM2999 EM3000 to EM3999 ▪▪▪
T0 to T99 T100 to T199 T200 to T299
C0 to C99 C100 to C199 C200 to C299

[Problems of programming without a local device]


 Device numbers must be managed beforehand.
 In many cases, a margin is allowed when the range of devices is allocated, and it is highly likely that a
considerable number of devices will remain unused (wasteful use of resources).
 If the allocated range is exceeded, it is necessary to consider allocating additional devices.
 If a function (module) is added, the change cannot be accommodated flexibly. The allocated range must
be selected again.

[Programming that uses a local device]

** assembly ** ** Print** ** Test **

▪▪▪

Device assignment in Device assignment Device assignment


the Assembly module in the Print module in the Test module ▪▪▪ Input/output relay etc.

R30000 to R40000
No assignment required No assignment required No assignment required ▪▪▪ DM10000 to DM20000

[Merits of using a local device]


 There is no need to manage the devices (global devices must be managed)
 Any number of modules can be added provided that they are within the area of the local device.
 Even if there is insufficient area for local devices, it can easily be expanded.

Thus, compared with programming that uses conventional global devices only, there is virtually no need for the
burdensome process of mapping devices, thanks to the use of “split programming” and “local devices”. In
addition, “re-use of ladder programs” and “joint programming by several engineers”, previously difficult to
implement, are now possible.

- 85 - KV0475E_C
-

Practice re-using programs

Running two instances of KV STUDIO


The module library and macro library are extremely effective for capitalizing (managing and operating) programs. However, for
programs that are not likely to be re-used several times, you can save the trouble of registering them into the library by running two
instances of KV STUDIO and copying & pasting modules and macros.

 Copying & pasting modules and macros


Run two instances of KV STUDIO. You can copy & paste by dragging & dropping Workspace modules and macros to the other
instance of KV STUDIO.

Run two instances


of KV STUDIO

Drag & drop

If a unit device in the modules and macros to be copied & pasted is being used,, the device must be replaced.
If you copy & paste the “Step control” module of the seminar sample project “Seminar 03A_Save library 1”, the “Replace devices
assigned to unit” dialog box is displayed.

By registering highly versatile modules into the module library, you can easily use them any number of times. The
module library is a library managed by KV STUDIO. It is not project-dependent, so the contents registered in the
module library differ from PC to PC.

- 86 - KV0475E_C
-

■Relationship between a unit device and the module library


When you re-use or borrow a module, depending on the program you will sometimes need to change or correct it to
suit each individual device. The module library provided by KV STUDIO automatically replaces the device number
when a module is borrowed.
Up till now Using the module library
The device number of each unit device must be When you use KV STUDIO’s module library, KV
replaced manually, so STUDIO determines the unit configuration where
the module is to be used and automatically
 The process is complicated replaces the device number of the unit device (you
 Mistakes can occur during replacement can also borrow a module without replacing the
device number).
Such problems were a barrier to program
capitalization. You can now capitalize programs.

 Using the module library


Example Create a module that uses a single AD convert unit (KV-AD40) at a single inspection station and
register it in the module library.
(1) Registering in the module library
“View””Module library”
Move the data using drag & drop or copy & paste.
Unit configuration

KV-AD 40
KV-5000/3000
KV-U7

Inspection station

Since the unit configuration is different,


the device number assigned to each
unit is different
(2) Borrow from the module library

Unit configuration
KV-C6 4XC

KV-C6 4 TC

KV-AD 40

KV-AD 40
KV- MC2 0V
KV-5000/3000
KV-U7

Measuring station

Inspection station

The project that borrows the module contains two AD convert units. One is used as an inspection
station, and the other is used as a measuring station. When a module is borrowed, the device
numbers assigned to units also change, so the device numbers of units at the registration destination
must be changed (replaced). If you use the module library, KV STUDIO automatically evaluates the
differences between the unit configuration at the registration source and the unit configuration at the
registration destination. The dialog box for replacing the device numbers is displayed, so replacing
unit numbers is easy (you simply have to select a unit number).

- 87 - KV0475E_C
-
 Changing the device number assigned to a unit
If a unit device is being used in a module that is to be borrowed (that is registered in the module library), the
window shown below will always open. Select the appropriate unit from the pulldown menu.

The process shown above automatically replaces the unit device that was being used in the module with the
device number assigned to the selected unit.

- 88 - KV0475E_C
-

Macros (original instruction words)


KV-5000/3000 supports numerous exclusive instruction words, but since all the instruction words are highly versatile, dedicated
processes that are dependent on a device or system must be formed by combining several instructions. Therefore, in some cases a
program will have the same type of ladder circuit appearing several times within a single project.

 Ladder program before the import of macros

If you look back over the completed program, you


will see there are many similar ladder blocks

MACRO_A

KV-5000/3000 allows you to give any name to a ladder circuit that is repeatedly used within a project and register it as a macro.
Registering a ladder circuit as a macro makes it possible to use a user’s ladder program as an original instruction word, which facilitates
programming.

- 89 - KV0475E_C
-

Merits of using macros


 You can create an original instruction word
A macro is a function that enables you to convert a ladder program containing several lines into a single icon
(instructionalized).
A local device is defined as a device that is effective only within the described module, but when it is used within a
macro, it is defined as a device that is effective only within the described macro. This function means a macro can
be used in the same way as an original instruction word.
That is, a local device described within a macro is handled differently from a local device within a module. This
means that you can use a local device without worrying about conflict (dual use) between local devices in a module
and in a macro.
If you register a macro in KV STUDIO, you can borrow it for various other projects.

Project A Project B Project C


MACRO_A **test** **Assembly* **Transfer**

**Print** **Test** **Alignment*

**Assembly* **Bond* **Marking**


Macro program is
described using
local devices

The macro program is described using local


devices, so the device does not conflict with other
programs

With conventional programs that used subroutines, it was necessary to replace the device before a subroutine could
be used in a different program. Using a macro eliminates the need to replace the device.
In addition, a subroutine cannot contain any arguments (exchange of values between the main program and the
subroutine program), so it was necessary to set a device for accepting the values. However, macros can contain
arguments, so they can easily accept values.

- 90 - KV0475E_C
-

 The man-hours for inputting a ladder program can be reduced


If a ladder circuit that is used several times within a project is registered as a macro, you can use the registered
ladder circuit by simply using a macro call instruction.

Drag & drop

You can write a macro call instruction by simply selecting the “Macro” tab in Workspace and dragging & dropping a
registered macro.

 You can easily correct a circuit


To correct a ladder circuit that appears several times, it is necessary to correct all modules that use that circuit. This
is time-consuming.
Manual Auto Transfer ROBOT
Manual

Correct

The same correction is required in all ladder blocks.

The modification itself is not so If the same circuit is used many times, the same
difficult, but... correction must be repeated in all circuits.

Once a macro has been registered, simply correcting one of the macro’s ladder circuits corrects the same circuit in
all ladders.
Macro_A Macro_A
Correct

A correction to the macro is reflected in all ladders.

Manual Auto Transfer ROBOT

Macro_A
Macro_A Macro_A
Macro_A

Macro_A

- 91 - KV0475E_C
-

 Preventing the leakage of knowhow by setting a password


You can set a password for a macro.
To prevent the leakage of knowhow, you can create a macro that contains important knowhow and set a password
for that macro.

1) With the cursor on the target macro, right-click and then click “Module/macro property”.

2) Click “Setup password” and enter a password.

- 92 - KV0475E_C
-

 Macros use arguments


When calling a macro, specify a macro name and also the numerical values and device numbers to be processed
within the macro. These numerical values and device numbers that are passed to the macro are called “arguments”.
A macro that contains arguments has greater versatility and reusability.

Module

Execution conditions Argument 1 Argument 2

The result of macro processing


is returned to the module.

The devices and values specified when


calling the macro are used in the ladder
Within the macro
program within the macro.

Call

The role of each argument in the above example is:


 Argument 1 (#12345)...............Value passed from the “module” to the “macro”
 Argument 2 (DM0) ...................Value that stores the result of processing by the “macro” and is returned to the
“module”
The arguments operate as follows:
 The “module”, which is the call source, passes argument 1 (#12345) to the “macro”. The “macro” uses the
received argument 1 to perform processing. Then it stores the result of processing in argument 2 (DM0) and
returns argument 2 to the “module”.

 Argument settings
The macro program determines whether an argument specified when calling the macro is P (pass device) or V
(pass constant).
The devices and constants allocated to P and V are determined by the macro call instruction.

- 93 - KV0475E_C
-

Procedure for using macros

The following explains the procedure for using macros.

STEP 1 : Extract processes and functions (planned to be) used several times within a program.

STEP 2 : Decide on the macro type.

STEP 3 : Create a macro.

Create a macro. At this time, also decide on the number of arguments.

STEP 4 : Describe the program.

Describe the ladder program in the created macro.

STEP 5 : Register the arguments.

Register the type and name of each argument.

STEP 6 : Call the created macro.

The macro is now ready for use. Use the macro’s exclusive instruction to call the macro.

STEP 7 : Check macro operation.

Use Monitor and Simulator to check macro operation.

Macro setup is
now complete

- 94 - KV0475E_C
-

STEP 1 STEP 1 Extract processes and functions often used in programs.


Extract processes
and functions often Consider whether functions and processes that you are likely to use often in programs
used in a program. created in the future need to be converted to macros.

STEP 2
Decide on the STEP 2 Decide on the macro type.
macro type.
Based on the details of operation, decide whether to select “Subroutine macro” or “Self-hold
macro” for the extracted processes and functions.

STEP 3 STEP 3 Create a macro.


Create a (Read the sample project “Seminar05A_Create macro”.)
macro.

From the menu, select “Module/macro (M)””New macro (M)”.

STEP 4
Create a
program.

STEP 5
Register the
arguments.

Other procedure  Right-click in the “Ladder editing” window and select ”Edit
STEP 6 macro (M)”→”New macro (N)” from the menu that appears
Call the created  Click the toolbar icon .
macro.

The “New macro” dialog box is displayed. Enter a macro name.

STEP 7
Check macro operation.

Enter a macro name

- 95 - KV0475E_C
-
Next, select a macro type.
STEP 1
Extract processes
and functions often
used in a program.

STEP 2
Select the macro type. Decide on the
macro type.

When you have entered all values, click the “OK” button.
The “Macro argument settings” dialog box is displayed. Close it.
STEP 3
The “Macro argument settings” dialog box is explained in STEP 5.
Create a
macro.

STEP 4
Create a
program.

STEP 5
Register the
arguments.

STEP 6
Call the created
A new subroutine macro*
macro.
with the name “Macro_A”
was created

STEP 7
* You can create a self-hold macro in the same way. Check macro operation.

For details on macro types, refer to “Macro types” (page 3-112) in the
“KV-5000/3000 User’s Manual”.

- 96 - KV0475E_C
-

STEP 4 Create a macro program.


STEP 1
Extract processes
Once you have created the macro, describe the ladder program to be processed by the
and functions often macro.
used in a program.
Describe the program in the same way as an ordinary ladder program.
Try creating the ladder program shown below using a subroutine macro.
STEP 2
Decide on the Example Add 5 (constant) to argument 1 (CAL + instruction) and divide the result by 10
macro type. (CAL/instruction). Then multiply the result by 10 (CAL*instruction) and store
the result in argument 2 (word device).
Formula: (Argument 1: V0+5) x 10 ⁄ 10 = (Argument 2: P0)

STEP 3
Create a
macro.
 Sample macro ladder program (subroutine)
Argument 1

STEP 4
Create a
program.

STEP 5
Register the You can enter P0 and
arguments. V0 in the same way as Argument 2
a normal device.

STEP 6
Call the created
macro.

STEP 7
Check macro operation.

- 97 - KV0475E_C
-
About macro arguments

 Argument “P”
Specify P if the device itself is to be accepted. The value of the device passed as P can be rewritten within the macro, so P can be
used as the return value.
You can also pass table data to a macro by modifying the index of P.
Macro B
Argument pass

Main module
DM1000


・・・
・・
DM1001

Call DM1002
・・
・・

DM1003


・・・
・・
Return value
* Example of passing table data

 Argument “V”
Use V if a constant or a value stored in a device is to be passed. A device passed as V directly passes the value stored in the device,
so the contents of the device cannot be rewritten.
Therefore, use V when setting a different device as an argument before and after execution of the macro would be a problem, or
when you want to use a constant as an argument.

 Describing arguments
Specify P (P0 to P9) or V (V0 to V9) as a macro argument. You can specify a combined total of 10 P and V arguments.

Argument name Explanation Other


P0 to P9  Treats a device as an argument.  A constant cannot be described.
 Be sure to specify P for an argument that stores a result  Can also be used as a table pass.
(return value).  Index can be modified.
V0 to V9  Treats a value stored in a device or  Cannot write to V.
 a constant as an argument.  Index cannot be modified.

Argument types

Argument type is determined according to the instruction word called within a macro or the suffix of the script. P0 indicates DM1000
 Ladder program or DM1001 (32 bit
The argument type changes depending on the suffix of an instruction word described in the ladder.

Call

 Script program
When a program is described using a script, the argument type changes if a suffix is given to P or V.

Call

P0 is treated as DM1000 (16 bit unsigned),


and P1 is treated as DM2000 or DM2001 (32 bit signed)

- 98 - KV0475E_C
-

STEP 5 Register the macro arguments.


STEP 1
The arguments described within a macro only become effective once they are registered in
Extract processes
and functions often
the “Macro argument setting” dialog box.
used in a program. Try setting the arguments of the macro created in STEP 4.

From the menu, select “Module/macro (M)””Macro argument setting (Z)”.

STEP 2
Decide on the Other procedure  In the “Ladder editing” window, right-click and from the menu that
macro type. appears, select ”Edit macro (M)””Macro argument setting (Z)”.
 Click the toolbar icon .

STEP 3
Create a
macro.

STEP 4
Create a
program.
This is the argument’s display sequence.
Describe arguments in this sequence
when writing a macro call instruction.
Select the display format
If there are several macros, select for arguments displayed
STEP 5
a macro for registering arguments. on the ladder editor.
Register the
arguments.

STEP 6
Call the created
macro.
This field indicates the
argument’s use status in the
macro. It shows “unused” if a
macro program was not created.
Give a title to the argument.
STEP 7
The name set here is displayed when
Check macro operation. the macro call instruction is described.
The argument title must not exceed 12
one-byte (6 two-byte) characters.

Register (set) the arguments to be used.


P0 to P9 : Set a device as the argument.
V0 to V9 : Set a value as the argument.
UR/UM/UV0 to 9: Set a unit relay, unit memory, or unit number as the argument.

- 99 - KV0475E_C
-

Macro argument device UR/UM/UV

UR/UM/UV is a unit relay/unit memory/unit number. It refers to the leading number of a unit device or the unit number assigned to an
additional unit.
For details on UR/UM/UV, refer to “3-9 Macros” in the ”KV-5000/3000 Series User’s Manual”, included in KV STUDIO.

To call: From the menu, select “Help (H)”→“CPU Unit User’s Manual (H)”.

- 100 - KV0475E_C
-
Adding a comment to a macro
A macro can be used in the same way as an original instruction word, but like a multipurpose instruction word, it does not have any
explanations or Help. To enhance the versatility of the macro, we recommend adding an explanation of an argument in the
argument’s operand explanation column or adding a simple explanation of macro operation as a comment.

 Macro comments
Adding a comment to a macro dramatically improves its versatility and reusability. A macro comment is displayed in the macro
palette used when entering argument operands, and in the macro properties.

 Right-click a macro in Workspace to open Module/macro properties.

Other procedure Select a macro in Workspace and, from the menu, select “Modules/macros (M)”→”Module/macro

properties (H)”.

Enter a comment.
Right-click menu You could write a simple
explanation of operation

 Explanation of argument operands


In addition to its argument title, an argument has a column for writing an explanation of each operand. Whereas the explanation of an
argument is displayed on the Ladder Editor, the explanation of an operand isn't. It is instead displayed on the macro palette, which
strongly supports the input of operands.
 Right-click a macro in Workspace and select “Macro argument setting (Z)” to display the Macro argument setting dialog box.

Other procedure Activate macro programs on the Ladder Editor. From the menu, select “Modules/macros (M)” →”Macro

argument setting (Z)”.

Right-click menu

Enter an explanation of
the operand

 Macro palette following comment input


The macro palette after comments have been
entered appears as shown below. There is
more information about the macro compared
The comment about the
with a palette with no comment entered, so it
is easier to understand macro operation. selected macro is displayed

An operand explanation for the


selected argument is displayed
*You can use up to 24 (one-byte) characters
to describe the operand explanation and up to
32 (one-byte) characters to write the macro
comment.

- 101 - KV0475E_C
-

STEP 6 Call the created macro


STEP 1
Creation of the macro is now complete.
Extract processes
If you call the macro from a module using a macro call instruction, you can and functions often
use it any number of times under conditions of your choice. used in a program.

Try calling the macro you created in STEP 5 from a module.

Describe the macro execution


STEP 2
conditions. Since the created
Decide on the
macro is a subroutine, you must macro type.
not turn OFF the execution
conditions until operation of the
macro has finished.

STEP 3
Create a
macro.

Double-click in the “Ladder editing” window to open


“Instruction/macro/pack pallet”. Click the “Macro” tab.
STEP 4
Create a
program.

Click the “Macro” tab.

STEP 5
Register the
Click the macro to be arguments.
called

STEP 6
Call the created
macro.

The argument settings have been


registered.
To correct them, open the “Macro STEP 7
argument settings” dialog box. Check macro operation.

- 102 - KV0475E_C
-

 Enter the arguments.


STEP 1
Specify values and devices in the arguments.
Extract processes
and functions often Try entering #30 as the “numerical value (argument 1)” and EM1000 as the “result
used in a program. (argument 2)”.

STEP 2 Refer to the attributes column


Decide on the when entering the values of
macro type. the arguments

STEP 3
Create a
macro.

STEP 7 Check macro operation


STEP 4 The macro operates (calculates) while the ever the execution conditions (switch
Create a 0:R000) is ON.
program.

STEP 5
Register the
arguments.

STEP 6
Call the created
macro.

STEP 7
Check macro operation.

- 103 - KV0475E_C
-

Chapter5
KV Script programming

- 104 - KV0475E_C
-
This section describes how to create the following box script.

Ladder program R000


DM100 = 100
DM200 = 10
Trigger DM300 = DM100 + DM200 + 1000

R000
DM300 = DM100 + DM10100 + 1000
DM400 = (DM100 + DM10100 + 1000) / 2
Trigger

Operation description
 Once Trigger(R000) is ON, the box script on the first rung is run.
In the box script, DM100 is set to a default value 100, DM200 is set to a default value 10,
and the operation result of DM100+DM200+1000 is stored in DM300.
 Once Trigger(R000) is OFF, the box script on the second rung is run.
DM10100 is a variable analog resistance in the switch box.

The ON/OFF condition of the switch is used to check how the values of DM100, DM200, DM300, and
DM400 vary.

Point For scripts, arithmetic expressions with "+, -, *, /" can be used. Moreover, using scripts
enables you to describe arithmetic expressions more simply than ladder programs, as you
can assign values using "=".

Arithmetic operators available for use with scripts

Arithmetic operators, including the four arithmetic operators (+, -, *, /), are available for use with scripts.

 Arithmetic operators

Operator Operation Sample


^ Raising a number to a power DM500 = DM100 ^ 2
* Multiplies one numerical value with another (multiplication) DM502 = DM100 * 3
/ Divides one numerical value into another (division) DM504 = DM100 / 4
Divides one numerical value into another and returns only the DM506 = DM100 MOD 5
MOD
remainder
+ Sums two numerical values (addition) DM508 = DM100 + 6
- Subtracts one numerical value from another (subtraction) DM510 = DM100 - 7

Tip Try the following, in addition to integer arithmetic expressions:


 Decimal point arithmetic expressions
 Trigonometric functions
 IF statements
 String manipulation
 Variable programming

- 105 - KV0475E_C
-

KV script operations flow


This section describes the operations flow of creating and editing box scripts.

- 106 - KV0475E_C
-

Creating a new box script


This section describes the steps to create a new box script.

1 Open the sample project “Seminar08_KV-script”.


This is a project for which a unit has already been set up.

2 Describe execution conditions in the ladder editor, and click the cell for which the box script is to be
programmed.

Select a cell This box script will be created here.

3 Insert a box where a script is described.

Select "Script (S)"  "Insert box script (B)" from the menu.

Tip 
 Select "Edit script (X)"  "Insert box script (B)" from the right-click menu

- 107 - KV0475E_C
-

4 The box script is inserted. Now describe a program.


When you finish describing the program, press the key + keys, or press the key. Or click the
Ladder Editing window, other than the box script you are now editing, to complete your description.

Describing execution conditions later

You can describe execution conditions after you finish creating the box script.

Insert a box script first to


describe a script.

Now describe
execution Cond1
conditions.

- 108 - KV0475E_C
-

5 When you finish describing the script, convert the box script.

Select "Script (S)"  "Convert all scripts (C)" from the menu.

Other procedure  Select "Edit script (X)" -> "Convert all scripts (C)" from the right-click menu

 If conversion is successfully

Appears when the conversion is finished

An "alarm" message may appear in the Output window.

 If conversion fails
A "script conversion error" appears.
An error message appears in the Output window.

If a conversion error occurs


If a script program is invalid, including mistyped function names, invalid types specified for suffixes, control
statements incorrectly used, a dialog box appears to indicate that a "script conversion error" has occurred.

Click the "OK" button of the dialog box.


The Output window shows where the
error has occurred and what the error
is.

- 109 - KV0475E_C
-

 Errors shown in the Output window


When a script conversion error occurs, the error will be displayed as follows:

If an "error" message appears : the script cannot be converted to a ladder program.


In this state, the program cannot be transferred to PLC.
If an "alarm" message appears : the script is converted to a ladder program. The program, which is transferred
to PLC to be run, is executable.
Notice that an executed program may not produce the results you expect.

- 110 - KV0475E_C
-

Monitoring scripts
When all scripts are successfully converted, they should be transferred to "KV-5000" to be monitored.
Scripts are transferred following the same steps as the ones used to transfer regular ladder programs.

Monitoring script programs

 How to use the watch window


With the watch window, you can easily monitor the status (current values) of all the devices that are described in the
script.

Select "Display/hide the watch window (M)" from the right-click menu to toggle display of the watch window.

Other procedure 
 Select "Monitor/Simulator (N)" -> "Display/hide the watch window (N)" from the menu

Monitor all the devices in the


ladder program block at the
cursor location.

The watch window

- 111 - KV0475E_C
-

 How to use the registration monitor


With the registration monitor, you can open more than one window at a time to conveniently monitor the devices for
different module macros.

Select the script to be


monitored, and then select the
"Registration monitor window"
from the right-click menu.

* Make sure that you


launch the Registration
monitor window from the
right-click menu

 The devices that are described in the selected script appear as registered in the Registration monitor window.
 The used devices, etc., displayed when the script is expanded, do not appear in the Registration monitor window.

Switching the module macros will not close the Registration monitor window. You can also open more than one
window at a time.

- 112 - KV0475E_C
-

Using ladder programs to monitor behaviors

Expanding script programs to ladder programs may allow easier monitoring of behavior timing.
Expand this script as this script to a ladder program for monitoring.

This state prevents the possibility of


monitoring how the device is used in the
script.

Click to expand the The ladder program to which


the box script is converted
ladder program
appears

Click to collapse the


expanded ladder program

The ladder program to which the


script is expand is monitored in the
same way as other ladder programs

- 113 - KV0475E_C
-

 Script syntax rules


Operators (+, -, *, /, =) and the equal sign are used in the script, which enables you to describe arithmetic
expressions in a free and intuitive way under the rules for describing plain arithmetic expressions (However, there
are some script syntax rules that allow advanced (complex) operations).

(1) Why?! The result of the operation is not correct. The result should be 66000...
If the following arithmetic expression is described, the expected result of the operation is not stored in DM0

Example) DM0 = 660 * 100................The result of the operation, ‘660×100, is stored in DM0

As the result of the operation implemented on the right side is 66000, which is out of the range of unsigned 16
bits (0 through 65535), "464" is stored in DM0 on the left side.

(2) Why?! Negative values cannot be stored in the result of the operation.
If the following arithmetic expression is described, overflow positive values (not negative values) are stored in
DM2.

Example) DM2 = 300 - 500 ................The result of the operation, ‘300 - 500, is stored in DM2

As the result of the operation implemented on the right side is -200, which is out of the range of unsigned 16
bits (0 through 65535), "65336" is stored in DM2 on the left side.

(3) Why?! The digits after the decimal point of the result of the operation are omitted,
aren't they?
If the following arithmetic expression is described, the value is stored in DM4 with the digits after the decimal
point truncated.

Example) DM4 = 123 * 1.05...............The result of the operation, ‘123  1.05, is stored in DM4

As the result of the operation implemented on the right side is 129.15, which is out of the range of unsigned 16
bits (0 through 65535), "129" is stored in DM4 on the left side.

Point of script syntax rules

The example 3 above will enable you to easily obtain the correct result of the operation if you
learn the rules of arithmetic expressions.
The rules of arithmetic expressions are explained in more detail in the following pages. Basically
you are supposed to understand the following three points:

1. Device types -> the range of values that the device handles
2. Operation type -> the range of values that the arithmetic expression can handle
3. Assignment type -> the rules applied when the device type on the right side is
different from that on the left side

- 114 - KV0475E_C
-

Suffix (data type)


In the ladder language, the type of a command behavior is defined by attaching a suffix to each command. In the
KV script, the type of a function behavior and the meaning of a value stored in the device are defined by attaching a
suffix to the device or the constant.
(1) (2) (3)
There are 3 main points,
as follow: Device Operation Assignment
type type type
Device type
Specify a suffix to the device in the script. The range of the values that are allowed to be stored varies depending on
the specified suffix.

 Suffix types
Suffix The range of values
Type
(Sample definition) that are handled
.U
16 bits unsigned data type 0 to 65535
(DM1000.U)
.S
16 bits signed data type -32768 to +32767
(DM1100.S)
.D
32 bits unsigned data type 0 to 4294967295
(DM1200.D)
.L
32 bits signed data type -2147483648 to +2147483647
(DM1300.L)
-3.4E38≤N≤ -1.4E-45
.F
Floating-point type (32 bits) N=0
(DM1400.F)
1.4E-45≤N≤3.4E38 (valid 7 digits)
.T
Text string type Text string (Within 1999 half-width characters)
(DM2000.T)
Bit type (Boolean-value)
.B
* If a word device .B is specified, only the 1, 0, ON, OFF, TRUE, FALSE
(DM3000.B)
least significant bit is handled.
Device .....A box that stores values
Suffix .......Size, type of the box

Specify a suffix (.D, .L, .F), which handles 32-bit type data, so that "device number・device number + 1" is
automatically handled.
Example) DM1200.D = 100...........A constant "100" is stored in "DM1200・DM1201".
DM1400.F = 1.25 ..........A constant "1.25" is stored in "DM1400・DM1401".

If a suffix (.T) that handles text strings is specified, the ensured range of the device varies depending on the length of
the text strings that are handled. A text string is separated at the point where NUL(00H) is detected.
Example) DM2000.T = "KEYENCE" Starting from a text string "KEYENCE", two characters (half-width) per word
are stored.

Date storage method

Note If values that are out of the range of the type, an overflow appears.
Example) DM1000.U = 65536 ······· A constant "0" is stored in "DM1000.U" (overflow).
DM1100.S = 65535········ A constant "-1" is stored in "DM1100.S" (overflow).

- 115 - KV0475E_C
-
 About type declaration of a suffix
Declaring the type of the device at the head of a script program allows you to abbreviate a suffix.
Type
declaration Form Description
statement

TYPE DM1000.D DM1000 is handled as .D (32 bits unsigned) even if


a suffix is abbreviated.
TYPE EM1000 – EM2000.F EM1000 through EM2000 are handled as .F (32 bits
TYPE (TYPE EM1000.F – EM2000) floating-point type) even if suffixes are abbreviated.
All the device numbers that are represented with FM
TYPE FM.L are handled as .L (32 bits signed) when suffixes are
abbreviated.

Example) TYPE DM1000.D ................................‘DM1000 is handled as .D when a suffix is abbreviated.


TYPE DM2000 - DM2999.S...............‘DM2000 through DM2999 are all handled as .S type.
TYPE FM.L..........................................‘FMxxxx are all handled as .L type.

DM1000 = 123456 ..............................‘DM1000, which is .D type, stores "123456".


DM2100 = 50 - 150 .............................‘DM2100, which is .S type, stores "-100".
FM3000 = (EM2000 + 500) * 12.........‘The right side is calculated as .L type, and the result is stored in
FM3000.L.
Note  A type declaration is valid only in the scripts (blocks) where TYPE is described.
 Even if a type has been declared with a suffix, the type can be changed by specifying another
suffix to be described.
 A TYPE statement can be described only at the head of a script program.

 Default type of a device


If a suffix is abbreviated without TYPE declared, the type varies depending on the type of a device.
Device type Type with an abbreviated suffix (default type)
R, B, MR, LR, T, C, CTC, CR .B (bit type)
DM, W, EM, FM, ZF, TM, CM,
.U (16 bits unsigned data type)
Devices to be indirectly specified (*)
Z .L (32 bits signed data type)
CTH .D (32 bits unsigned data type)

Explicitly converting types of devices and constants

In scripts, arithmetic expressions are handled as .L type (32 bits signed data). Therefore, computation elements should be type-converted
whenever doing a calculation that may handle the range other than .L (including a division calculation).

Example 1) DM1000.F = DM0.S / 3 .................."DM0.S/3" is calculated in the range of .L. If DM0.S is 10000, for example, +3333 (the
digits truncated after the decimal point of the result) is stored in DM1000.F.
Example 2) DM1002.F = FLOAT(DM0.S) /3.....DM0.S is converted to .F type by means of the FLOAT function, and then calculated in
the range of .F. If DM0.S is 10000, for example, 3333.333.... is stored in DM1002.F.
Example 3) DM1004.F = DM0.S /3.0 ................3 is handled as .F type and calculated in the range of .F by describing 3 as 3.0. If DM0.S
is 10000, for example, 3333.333.... is stored in DM1004.F.

Types are converted by means of the following functions:


TOU function the data type is converted to .U (16 bits unsigned data) : Example) DM2000.U = TOU( DM1000.L) converts .L to .U
TOS function the data type is converted to .S (16 bits signed data) : Example) DM2002.S = TOS( DM1002.L) converts .L to .S
TOD function the data type is converted to .D (32 bits unsigned data) : Example) DM2004.D = TOD( DM1004.L) converts .L to .D
TOL function the data type is converted to .L (32 bits signed data) : Example) DM2006.L = TOL( DM1006.U) converts .U to .L
TOF function* the data type is converted to .F (32 bits floating real number) : Example) DM2008.F = TOF( DM1008.U) converts .U to .F
* Behaves the same as the FLOAT function.

- 116 - KV0475E_C
-

Computation types
The operation type of a computation expression varies depending on the suffix (type) of the device (constant) that is
described in the computation expression.
Computation types are separated into the following two general groups:

 If .F (floating real number) is not included in a computation expression


If a computation expression includes a suffix is configured only with ".U .S .D .L", it is computed in the range of ".L
(32 bits signed)".
Example) DM5000.L = (DM3000.L + 300)*2................ the computation expression on the right side is computed in
the range of .L, and the result of the computation on the
right side has .L type (-2147483648 through
+2147483647).

 If .F (floating real number) is included in a computation expression


If a computation expression includes a .F suffix (or a decimal point constant), the device in the expression is
computed in the range of ".F (floating real number)”.
Example) DM6000.F = DM3200.L*1.25 ....................... DM3200.L, once converted to a floating data, is then
computed. The result of the operation implemented on the
right side has a .F type (-3.4E38 through 3.4E38).

Tip If an arithmetic expression includes multiple arithmetic expressions, they are computed in the range
of .L until a computation element of .F appears.
Example) DM6100.F = (DM3300.L + 300) * 2 + (DM3310.L – 5000) * (DM3320.F + 50)
It is calculated in the range of .L until (DM3300.L + 300) * 2 + (DM3310.L - 5000), and after
that, it is calculated in the range of .F (operations within the parentheses are prioritized, in
an order from left to right).

Point

In a conventional ladder program that "multiplies the device by 1.25", the procedure described was "Multiply the
device by 125, and then divide the result by 100".
Using script programs allows you to directly describe an arithmetic expression, using constants (including a
decimal point).

 Arithmetic expressions of .T (text strings)


A script program allows string concatenation to be handled more explicitly.
Example) DM6500.T = “ABC” + STR (DM3300.U*1.25) .......... the string “ABC” and the (ASCII code) result which
has been converted to a string of "DM3300.U*1.25"
are concatenated, and stored in DM6500.T.

Computation expressions out of the range of .L

Even if it is expected that the result of the operation should fall within the range of .L, the correct value (the expected value) may not be
obtained if it is out of the range of .L (-2147483648 through +2147483647) during the operation.

* If you want to carry out an operation that is out of the range of .L, use .F (valid numbers are 23 bits).

- 117 - KV0475E_C
-

Substitution types
A computation expression that is described in a script has the type that is defined by the result of the operation (on
the right side). However, it is possible that the type of the right side and the left side that is substituted are described
differently. In this case, he result type of the operation implemented on the right side is automatically converted to
that of the left side immediately before substituted into the left side.

 The type on the left and right are the same


If the right side is a computation expression, the result of the operation is always of ".L type" or ".F type". Therefore,
the type of the left side, which stores the result of the operation, should be of ".L type" or ".F type".

Substituted

DM5000.L
Should be the same
type as the right side
= (123 + DM3100) × 1000
The result of the computation is of .L type
* If a floating type is included in the
computation expression (on the right
side), the result of the computation is
The left side The right side of .F type.

 The type on the left and right are different


The result type of the computation expression (implemented on the right side) is always of ".L type" or ".F type". If
a type other than .L or .F is specified to the device on the left side, the result type of the operation implemented on
the right side is automatically converted to that of the left side immediately before being substituted into the left
side.
As seen in the example below, if the result type of the result of the operation (implemented on the right side) is .F
and the type of the left side is other than .F, the result of the operation is substituted to the left side, with the digits
after the decimal point truncated.

Example) DM5110.L = DM3100.L * 1.25 ...................... The result of the operation implemented on the right side
is of .F type, but when substituted, it is converted to .L
type, as the type of the left side is. L.

If DM3100.L = 12345: the result of the computation on the right, 12345 × 1.25 = 15431.25.

The digits after the decimal point of the result are truncated when
substituted
Substituted
DM5110.L
15431
= DM3100.L * 1.25
12345 × 1.25 = 15431.25
(.F -> the value converted (The result of the computation
to .L is stored) is a floating type)

The left side The right side

If a type other than .L or .F is specified to the device on the left side that stores the result of the operation of the
arithmetic expression, the result type of the operation implemented on the right side is automatically converted to
that of the left side immediately before being substituted into the left side.

Example) DM5100.U = (DM3000.U + 300) * 20 ............ The result of the operation implemented on the right side
is of .L type, but the top 16 bits are truncated when
substituted since the type of the left side is .U.

DM3000.U = 40000: (40000+300) × 20 = 806000 on the right side. "19568" is stored in DM5100.U,
with the top 16 bits truncated.

- 118 - KV0475E_C
-

Script programs sample


For more information about the following program, refer to the sample project
"Seminar09_Script_sample".

(1)-1 All the arithmetic expressions in the script are calculated in the range of .L type (32 bits signed data) *.

Arithmetic expressions
DM1000.L = 100 * DM10001.U ···················································the first rung
DM1010.U = 100 * DM10001.U····················································the second rung

R0000
Box script DM1000.L = 100 * DM10001.U
DM1010.U = 100 * DM10001.U

Operation description
The operation on the right side is implemented as .L type, and the result of the operation is also
of .L type. Therefore, the type of the device on the left side that stores the result of the operation
should be of .L type (the first rung).
Where, if a device of other than .L type is specified by the type of the left side, the precision may
be reduced (the second rung: .L type -> the precision of .U type is reduced).
However, even if a type other than .L is included in an element of the arithmetic expression,
operations will be implemented regardless of the suffix if the value during the operation or the
result value of the operation is expected to fall within the range of .L.
* Except where constants, including .F type data memory and decimal points, are included

(1)-2 Constants including decimal points can be described in arithmetic expressions in the script.

Arithmetic expressions DM1100.F = DM10001.U * 1.23·································the first rung

R0000
DM1100.F = DM10001.U * 1.23
Box script

Operation description If a decimal point is included in an element of the expression (on the right side), it is calculated
as .F type since a .F type device (or constant) appears*, and the result of the operation is also
of .F type (floating real number). Therefore, the type of the device on the left side that stores the
result of the operation should be of .F type.
Where, if a device of other than .F type is specified by the type of the left side, the digits after the
decimal point of the result are truncated, as .F type is converted to an integer before being
stored.

* In the program above, 5000-DM10000.U is calculated in the range of .L, and the result ×1.25 is
stored in the left side after .F type is calculated.

- 119 - KV0475E_C
-

(1)-3 The result of the operation implemented on the right side is always of ".L type (32 bits signed data" or ".F
type (floating real number)”. Where, if the type of the left side differs from that of the right side, the result
type of the operation implemented on the right side is automatically converted to that of the left side
immediately before being substituted into the left side.

Arithmetic expressions
DM1200.L = DM10001.U * 1.23························································· the first rung
DM1210.F = DM10001.U * 1.23 ························································ the second rung

R0000
Box script DM1200.L = DM10001.U * 1.23
DM1210.F = DM10001.U * 1.23
Arithmetic
trigger

Operation description The result of the arithmetic expression implemented on the right side is of .F type (floating real
number), since a constant with a decimal point is included in an element of the expression.
In the arithmetic expression on the first rung above, the result type of the operation (.F) is
automatically converted to .L type (with the digits after the decimal point truncated) before
substituted to the left side, as the type of the device (on the left side) that stores the result of the
operation is of .L type (32bits signed data).
On the second rung, the result of the operation is stored as .F type without being converted into
an integer.

Point If the type of the right side differs from that of the left side (which is of 16 bits type), the top
16 bits may be truncated.

The result varies depending on how the arithmetic expression is described

The result of the operation may vary depending on how the expression is described.

 Where divisions are done first


"DM2 = ((1999 - 50) / 4000 × DM10000) + 50", described in the script, is calculated as DM10000 = 500 ...
Calculated in the following order: (1): 1999 – 50.................................. solution of (1) = 1949
(2): [solution of (1)] / 4000 .............. solution of (2) = 0, remainder is 1949
500
(3): [solution of (2)] × DM10000 .. solution of (3) = 0 (zero multiplied by
anything is zero)
(4): [solution of (3)] + 50 ................ solution of (4) = 50
Result of the operation: 50
 The value stored in DM2: 50 (whatever number is stored in DM10000)

 Where calculated with decimal points


“DM2 = ((1999 – 50.0) / 4000 × DM10000) + 50", described in the script, is calculated as DM10000 = 500 ...
Calculated in the following order: (1): 1999 – 50.0.............................. solution of (1) = 1949.0 (solution is of .F type since .F (floating
type) is included in an element of the expression)
(2): [solution of (1)] / 4000 .............. solution of (2) = 0.48725 (the solution of (2) is also of .F type
since the solution of (1) is of .F (floating type)
500
(3): [solution of (2)] × DM10000 .... solution of (3) = 243.625


(4): [solution of (3)] + 50.................. solution of (4) = 293.625


Result of the operation: 293.625
 The value stored in DM2: 293 (only if 500 is stored in DM10000 : since the suffix of DM2 is .U (16 bits unsigned)

- 120 - KV0475E_C
-

(2) String concatenation is described using "+" or "&" in the script.

R0000
Box script DM1300.T = “ABC” + “XYZ” + CHR($0D)
DM1350.T = “abc” + STR ( DM10000.U ) + “xyz”

In the first rung, a text string "ABC" is concatenated with another string "XYZ", and a string
Operation description
constant with DM1300 is stored at the head of the string and "CR(0DH) at the end of the
string.

In the second rung, the value stored in DM10000 is first converted to a string and
concatenated with the text string "abc", before being concatenated with another string "xyz"
and DM1350 is stored at the head of the string.
"NUL(00H)" is automatically stored at the end of the text string.

The operation, DM1350.T = "abc" + STR (DM10000.U) + "xyz", stores text strings when
DM10000.U=2345, as shown below:
bit bit
15 “abc2345xyz” 0

DM1350 a (61H) b (62H)

DM1351 c (63H) 2 (32H)

DM1352 3 (33H) 4 (34H)

DM1353 5 (35H) x (78H)

DM1354 y (79H) z (7AH)

DM1355 NUL (00H)

 ASCII code table

High-order 4bit
Low –order 4bit

- 121 - KV0475E_C
-

(3)-1 Control structures are available to control the flow of a program. A control structure allows you to
describe a "conditional branch control statement" that will branch to specific actions determined by
whether a condition is satisfied or not.

IF DM10000.U > 1000 THEN


Area scripts
DM1410.U = DM1420 .U+ 100
SET( R500 )
ELSE
DM1400.U = 0
RES( R500 )
END IF

Operation description Area scripts are of fixed scan execution types that do not require execution conditions (just like
box scripts).
If the switch box volume indicates that the value of DM10000 increases beyond 1000, the result
of the operation of "DM1420+100" is stored in DM1410, and R500 is turned ON. If the value of
DM10000 is equal or less than 1000, 0 is substituted into DM1400, and R500 is turned ON.

Point If the script is described with control structures, using area scripts may make its behavior
simpler to understand than using box scripts.

* For more information about area scripts, refer to the section, "2-3 Area scripts" of the "Script Programming
Manual".
 Conditional branch statements
Control
Control contents
statements
(1) A control statement IF conditional expression A THEN
 If the conditional expression A is true, then the
that executes the Process statement B
process statement B is executed.
process according to END IF
If the conditional expression A is false, no process
conditional
is executed.
expressions
(2) 2 branch control IF conditional expression A THEN
statements that Process statement B  If the conditional expression A is true, then the
execute separate ELSE process statement B is executed.
processes according Process statement C If the conditional expression A is false, then the
IF statements to the conditional END IF process statement C is executed.
expressions
IF condition expression A THEN
(3) Multiple branch Process statement B  If the conditional expression A is true, then the
control statements that ELSE IF conditional expression C process statement B is executed.
execute separate THEN If the conditional expression A is false, and the
processes according Process statement D conditional expression C is true, then the process
to more than 2  statement D is executed.
conditional   If the conditional expressions A, C ... are false, no
expressions  process is executed.
END IF
SELECT CASE the value to be
compared with
CASE condition A ・ if the condition A and the value to be compared
Process statement B are equal, then the process statement B is
Multiple branch control
CASE condition C executed. If the condition C and the value to be
statements that select
SELECT Process statement D compared are equal, then the process statement
processes to execute
statements  D is executed.
according to
 ・ If the value to be compared with is not equal to
conditions  the conditions A, C,..., then the process statement
CASE ELSE E is executed.
Process statement E
END SELECT
MC conditional expression A THEN ・ If the conditional expression A is true, then the
Control statements for Process statement B process statement B is executed.
MC statements MCR
the master control If the conditional expression A is false, then the
process statement B is executed OFF.

* For more information about conditional branch statements, refer to the section, "4-3 Control statements" of
the "Script Programming Manual".

- 122 - KV0475E_C
-
Arithmetic operators available for use with scripts
Various operators, including the four arithmetic operators (+, -, *, /), are available for use with scripts.
 Arithmetic operators
Operator Operation Sample
^ Raising a number to a power DM500 = DM100 ^ 2
* Multiplies one numerical value with another (multiplication) DM502 = DM100 * 3
/ Divides one numerical value into another (division) DM504 = DM100 / 4
Divides one numerical value into another and returns only the DM506 = DM100 MOD 5
MOD
remainder
+ Sums two numerical value (addition) DM508 = DM100 + 6
- Subtracts one numerical value from another (subtraction) DM510 = DM100 - 7

● Text string concatenation operators


Operator Operation Sample
&, + Concatenates 2 text strings DM600.T = "KEY" + "ENCE"

 Relational operators
Operator Operation Sample
< less than MR500 = DM100 < 10
<= less than or equal to (less-than-or-equal-to) MR501 = DM100 <= 20
> greater than MR502 = DM100 > 30
>= greater than or equal to (greater-than-or-equal-to) MR503 = DM100 >= 40
= equal (equivalent) MR504 = DM100 = 50
<> not equal (not equivalent) MR505 = DM100 <> 60

 Logical operators
Operator Operation Sample
NOT Results the logical negative value of the operand MR600 = NOT R000
Results the logical multiplication of 2 devices
AND MR601 = R000 AND R001
(2 bit devices, 2 word devices)
Results the logical addition of 2 devices
OR MR602 = R000 OR R001
(2 bit devices, 2 word devices)
Results the exclusive OR of 2 devices
XOR MR603 = R000 XOR R001
(2 bit devices, 2 word devices)

Function list and Tips on function forms


Select "Script (S)"  "Script function list (F)" from the menu.

List of script
functions

Tips on script
function forms

To insert the function at the cursor position on the Script Editor, select the function to be used, and then press the Enter key or double
click on the selected function. A hint for the script function format appears. Otherwise, press the F1 key while the function is
inserted in order to display the appropriate function help message.

Other procedure  Press Ctrl + Space key.


 Select "Script function list (F)" from the right-click menu.

- 123 - KV0475E_C
-

(3)-2 In control structures which can be described with scripts, "repetition control statements" are available as
well as conditional branch statements. Repetition control statements are useful when the same process
is repeated many times. However, they should be used carefully if a process takes a long time to
complete as they implement the process within one scan.

Area scripts FOR Z01 = 0 TO 100


DM4000:Z01 = DM10000.U + Z01 * 5
IF DM4000:Z01 > 5000 THEN
BREAK
END IF
NEXT

Operation description
Repeats until the value of Z01 is greater than 100.
Stores the value, in an order from DM4000, adding 5 to the analog input value each time.
Where, the repetition control is exited immediately if the sum total of the added values is greater
than 5000.

Point A FOR statement continues executing the repetition process statement until the last value (100
in the example) has been exceeded. In the Example, the repetition number of times is 101,
since "Z01=0 TO 100".

* For more information about repetition control statement, refer to the section, "4-3 Control statements" of
the "Script Programming Manual".

 Repetition control statements


Control
What they control
statements
A loop control statement that FOR initial value TO last value STEP
 Repeatedly executes the
repeatedly executes a loop a incremental value
FOR process statement from the
specific number of times until Process statement A
statements initial value to the last value,
the conditional expression is NEXT
adding the incremental value.
true.
An infinite loop control WHILE conditional expressions
statement that repeatedly Process statement  Repeatedly executes the
WHILE
executes the process an infinite END WHILE process statement while the
statements
number of times until the conditional expression is true.
conditional expression is true.
An infinite loop control DO
 If the conditional expression is
statement that repeatedly Process statement
false, then the process
DO statements executes the process an infinite UNTIL conditional expression
statement is executed
number of times until the
repeatedly.
conditional expression is true.
<Repetition process statement>

  When a BREAK is executed,
Exits the current loop when
 the repetition control statement
BREAK used in a repetition control
BREAK (including BREAK) is exited
statements statement, regardless of the
 immediately, regardless of the
repetition control statement  repetition control statement.

<Repetition process statement>

- 124 - KV0475E_C
-

(4) In ladder programs, only the index modification using index devices or index constants is available.
However, in script programs, there are various ways to use index modification.

When 20 is stored in Z01, it is


equivalent to DM2020=100

Script description DM2000 : Z01 = 100 'modification by index register


DM2000 : 15 = 200 'modification by index constant
DM2000 : DM2010.U = 300 'modification by word device
DM2000 : (DM2020.U + 5) = 400 ‘modification by arithmetic expression
DM2000 : LEN(DM2100.T) = 600 ‘modification by function
(with a return value)

Operation description Each value (on the right side of the expression) is stored in the modification location where
DM2000 is index modified with each value.

* For more information about index modification, refer to the section, "3-2 Index modification and indirect
assignment" of the "Script Programming Manual".127

- 125 - KV0475E_C
-

Appendix

- 126 - KV0475E_C
-

Installing the USB Driver


If you are using Windows 7/VISTA, the procedure explained below is not required because the USB driver
is installed automatically.

Connect the KV-5000/3000 to a PC running WindowsXP. You only need to install the USB driver for the
KV-5000/3000/1000/700 the first time you connect to a particular PC. The second and subsequent times you
connect, the USB driver is recognized automatically, so you need not install it.

The following pages explain the procedure to be used when you install the driver for the
KV-5000/3000/1000/700 onto Windows XP for the first time. When you install the USB driver for KV STUDIO,
the hardware must be detected.

Use the following procedure to install the USB driver.

- 127 - KV0475E_C
-

- 128 - KV0475E_C
-

Useful Functions Categorized by Situation


(1) How do I add a contact? And when doing so, how can I quickly identify free device
addresses? P25

 When entering a device number, try entering “?.”


For example, “A_M?”. Unused devices are
displayed.

(2) How do I find the usage of an instruction? P26

 Try pressing “F1” while an instruction is highlighted. F1


The manual for instructions is displayed.

(3) How can I quickly find an instruction borne from an operation?

 In “Instruction/macro/pack pallet,” try a search using an instruction for another vendor’s PLC.

The corresponding Keyence instruction is displayed.

(4) How do I find a device quickly? P49

 Press “Ctrl+F” to display the search window.

(5) How do I search for a contact→coil?


(How do I find out why the device is in that status?) P50

 Press “F12” to jump to the coil.

(6) How do I execute a batch-search for locations where the same device is used? P52
 Press “Space” to jump to a list search. (Cross-reference))

Use “F3” or “Shift+F3” to highlight the same device in turn.

- 129 - KV0475E_C
-
(7) How do I monitor I/O?

 Several methods are available.


 Access window: Pressing the lamp switch on an I/O unit displays the CPU access window
 Unit Monitor: Click “Monitor/Simulator”→“Unit Monitor” and batch-check I/O units
 Batch Monitor: Click “Monitor/Simulator”→“Batch Monitor” and batch-check devices

(8) How do I monitor a special unit? P68/47

 Several methods are available.


 Access window: Pressing the lamp switch on a special unit displays the CPU access window
 Unit Monitor: Click “Monitor/Simulator”→“Unit Monitor” and batch-check special units

(9) How do I save the Registration monitor window? P46

 Right-click on “Registration monitor” and click “Save as Custom Monitor”

(10) How do I check operation of an added program offline? P42

 You can only check operation on a PC by clicking “Monitor/Simulator”→“Simulator”

(11) How do I investigate the cause of errors that seldom occur? -/P56
 In “Logging function”, clicking “Tracing setup” saves just the data immediately before and after
a failure to an SD card
 In “Real time chart monitor,” clicking “Tracing setup” displays data immediately before and after
a failure as a waveform

- 130 - KV0475E_C
-

Data obtained by displacement


sensor (1)

Data obtained by displacement


sensor (2)

Varicam contact output signal

It is clear that the


problem is not a PLC
Data collection interval Data lost!!! program abnormality
but a loss of output data
from the displacement
sensor

(12) How do I back up or restore programs or device values? -

 You can set backup or restore in “Monitor/Simulator”→“Batch-change window”

(13) How do I detect high-speed ON/OFF? P56

 You can monitor ON/OFF at the scan period in “Monitor/Simulator”→“Real time chart monitor”

(14) What do I do if I can’t completely remember an instruction when adding a program? P25

 Enter the first few letters that you can remember of the instruction.

The instructions that begin with those first few letters are listed.

- 131 - KV0475E_C
-
(15) How do I paste from the manual’s reference program? P28

 Copy the mnemonics list next to the manual’s reference program, click “Edit”→“Edit list” and
paste the copied portion to batch-create programs.

(16) How do I collect data?

 Using “Logging function” enables you to collect the desired data at the desired timing onto a
multipurpose SD card. Its applications are infinite: automatically creating a daily report for a
single day, investigating failures, investigating the proportion of momentary stoppage time, etc.

(17) How do I skillfully convey on-site circumstances to another person (a machine manufacturer,
Keyence, etc.)?

 You can record operations on a PC using “KV STUDIO RECORDER.”

You can also play back recordings using “KV STUDIO PLAYER.”

Send the video


file by email

Manufacturing site Office

- 132 - KV0475E_C
www.keyence.com

Copyright (c) 2011 KEYENCE CORPORATION. All rights reserved. PLCSeminar-WW-OT-E 1111-1 600A26

Potrebbero piacerti anche