You are on page 1of 76

Chapter 3

Interrupts
The interrupt processing function executes an interrupt program when an external
input or request from the high-speed counter comparator (interrupt factor) is encoun-
tered during KV operation.
This chapter describes the types of interrupt factors as well as inputs and outputs
encountered during interrupt processing.
For KV-10/80 Series, see Chapter 6.
3.1 Interrupt Instructions ...................................................................... 3-192
3.2 Interrupt Processing ....................................................................... 3-194
3.2.1 Interrupt Processing ............................................................................... 3-194
3.2.2 Types of Interrupts ................................................................................. 3-195
3.2.3 Interrupt Priority...................................................................................... 3-196
3.2.4 Interrupt Program................................................................................... 3-196
3.3 Direct Input/Output .......................................................................... 3-197
3.3.1 Direct Input ............................................................................................. 3-197
3.3.2 Direct Output .......................................................................................... 3-197
3.4 Applications of Interrupt Programs ............................................ 3-198
3.4.1 Interrupt with a Signal Converter ............................................................ 3-198
3.4.2 Interrupt with a High-speed Counter ...................................................... 3-199
3.4.3 Measuring the ON Time of High-speed Pulses ...................................... 3-200
3.4.4 Measuring the Period in which a Target Passes between
Two Points ............................................................................................. 3-201
V
i
s
u
a
l

K
V
S
e
r
i
e
s
3.1 Interrupt Instructions
3-192
V
i
s
u
a
l

K
V
S
e
r
i
e
s
3
Chapter 3 Interrupts
FUN
FUN
LDB
4
RES
0
ENT
Operand
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ENT
R-SRCH
ANL
2
ORL
3
3.1 Interrupt Instruc tions
This section describes the INT, RETI, DI, and EI instructions used for interrupt
processing.
INT: Interrupt
RETI: Return Interrupt
Executes interrupt between INT and RETI
instructions at rising or falling edge of input
specified by operand.
Represents termination of interrupts.
FUN
FUN
LDB
4
RES
0
ANL
2
ORL
3
RETI
INT
nnnn
0500
0000
T000 0500
#00020
T000
a)
0000
Normal
input
Example
Coding for normal input
Coding for interrupt input
Description
Example a) shows a normal input and is used when input relay 0000 turns ON
longer than the input time constant (10 ms).
Example b) is used when input relay 0000 turns ON shorter than the scan time.
Operands
0000 to 0003
CTC0 to CTC3
Key operation
(Input ON time: 10 s min.)
(Input ON time: 10 ms min.)
Interrupt
input
Line No. Instruction Operand
0000 LD 0000
0001 OR 0500
0002 TMR 00 #00020
0003 ANB T000
0004 OUT 0500
Line No. Instruction Operand
0000 LD 2008
0001 EI
0002 LD 2002
0003 HSP 0000
0004 LD 1000
0005 OR 0500
0006 TMR 000 #00020
0007 OUT 0500
0008 LD T0
0009 RES 1000
0010 END
0011 INT 0000
0012 LD 2002
0013 OUT 1000
0014 RETI
0015 ENDH
1000
0500
#00020
T000
1000
2002
b)
0000
2008
EI
END
INT
0000
HSP
0000
RETI
ENDH
2002
T0 1000
(RES)
3.1 Interrupt Instructions
3-193
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
3
Chapter 3 Interrupts
DI: Interrupt Disabled
EI: Interrupt Enabled
Disables execution of interrupt.
Enables execution of interrupt.
Example
Coding
Description
When 1000 is ON, execution of interrupt is enabled.
When 1000 is OFF, execution of interrupt is disabled.
Interrupts are enabled between EI instruction and DI instruction.
Once an EI instruction is executed, an interrupt is enabled until a DI instruction is
executed.
Any interrupt is disabled when the Visual KV Series starts operation.
The DI instruction disables execution of an interrupt. Use this instruction to
temporarily disable an interrupt.
The EI instruction enables execution of an interrupt. Use this instruction to
release an interrupt that was disabled by a DI instruction.
To execute another interrupt during execution of the previous interrupt, include EI
instruction in this first interrupt. EI-DI instruction set can be nested to four levels.
Note 1: When any interrupt occurs between DI and EI instructions (interrupt disabled
period), the disabled interrupt is stored (to 8 levels max.). The stored interrupt is
executed as soon as an EI instruction is executed.
Note 2: If an INT CTC instruction is stored before a RES CTC instruction is ex-
ecuted, the stored INT CTC is deleted.
Operands
Key operation
FUN
FUN
RES
0
ORL
3
DI
EI
SET
1
AND
8
1000
EI
DI
1000
FUN
FUN
SET
1
RES
0
AND
8
ORL
3
ENT
R-SRCH
ENT
R-SRCH
Line No. Instruction Operand
0000 LD 0000
0001 EI



0021 LDB 1000
0022 DI



3.2 Interrupt Processing
3-194
V
i
s
u
a
l

K
V
S
e
r
i
e
s
3
Chapter 3 Interrupts
2008
SET or
2813
EI
#00000
DW
DM1940
2002
2002
EI
HSP
0000
(0000 to 0015)
(0500 to 0503)
3.2 Interrupt Proc essing
This section describes interrupt processing.
3.2.1 Interrupt Processing
Outline
Normally, a PLC processes a ladder sequence program by repeating the steps of
input processing, program execution, and output processing. Therefore, signals
which are shorter than the scan time cannot be received.
When the interrupt processing function is used, a process can be executed at the
instant of the interrupt, independent of the scan time.
When any interrupt occurs, the Visual KV series suspends the currently executed
program and executes the interrupt program in accordance with the interrupt factor.
When the interrupt program completes, the Visual KV resumes execution of the
suspended program.
For more about scan time, refer to "1.1.2 Scan Time" (p. 3-3).
Direct input/output
The direct input/output functions are used during interrupt processing. Direct input
allows the KV PLC to fetch the input status of input relays 0000 through 0015 (KV-
10xx: 0000-0005, KV-16xx: 0000-0009) during execution of the interrupt program.
Direct output allows the Visual KV PLC to output the ON/OFF status of output relays
0500 through 0503 during execution of the interrupt program.
No special setting is required to use the direct input/output functions. The functions
can be used only by using the devices assigned for direct input/output within the
interrupt program.
Executing interrupts
The INT (Interrupt) instruction is used to execute an interrupt. Since an interrupt is
disabled at the start of operation, it is necessary to execute an EI (Interrupt enable)
instruction before using the INT instruction. In addition, the input time constant
should be set shorter by using the HSP instruction (to 10 s) or by specifying the
desired value in DM1940 and turning ON special utility relay 2813.
For more about the input time constant, refer to "1.4.1 Input Time Constant Change Function" (p. 3-
23).
Direct output
Input
processing
Program
execution
Output
processing
Scan
time
Interrupt input
Return to the next
line of the interrupt.
Interrupt
processing
Direct input *
3.2 Interrupt Processing
3-195
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
3
Chapter 3 Interrupts
3.2.2 Types of Interrupts
Interrupts can be divided into two types: an interrupt by an external input, and an
interrupt by the high-speed counter comparator. This section describes both of these
interrupt types.
Interrupt by an external input
This interrupt is executed by input relays 0000 through 0003. Use the special utility
relay to specify the polarity of the interrupt factor to a rising or falling edge.
Interrupt by the high-speed counter comparator
This interrupt is executed when the current value of the high-speed counter (CTH)
matches the preset value of the high-speed counter comparator (CTC).
Polarity setting for interrupts by an external input
Turn ON the appropriate special utility relay to specify the interrupt factor to a rising
or falling edge.
The interrupt polarity can be changed as follows by setting special utility relays
2402/2403 (INT0), 2404/2405 (INT1), 2410/2411 (INT2), and 2412/2413 (INT3).
Use SET-RES instructions to turn the special utility relays ON/OFF.
Input capture
Each external interrupt factor is provided with the input capture function. This is a
function which writes the value of the high-speed counter into the data memory
when an interrupt occurs. Without any particular settings, the value of the high-
speed counter is automatically transferred to DM1928 through DM1935 when an
interrupt occurs.
CAUTION
t p u r r e t n I
e p y t
y a l e R
. o N
s u t a t S
y a l e R
. o N
s u t a t S n o i t p i r c s e D
0 T N I 2 0 4 2
F F O
3 0 4 2
F F O
. e g d e g n i s i r t a s r u c c o t p u r r e t n I
N O F F O
F F O N O . e g d e g n i l l a f t a s r u c c o t p u r r e t n I
N O N O . s e g d e g n i l l a f d n a g n i s i r h t o b t a s r u c c o t p u r r e t n I
1 T N I 4 0 4 2
F F O
5 0 4 2
F F O
. e g d e g n i s i r t a s r u c c o t p u r r e t n I
N O F F O
F F O N O . e g d e g n i l l a f t a s r u c c o t p u r r e t n I
N O N O . s e g d e g n i l l a f d n a g n i s i r h t o b t a s r u c c o t p u r r e t n I
2 T N I 0 1 4 2
F F O
1 1 4 2
F F O
. e g d e g n i s i r t a s r u c c o t p u r r e t n I
N O F F O
F F O N O . e g d e g n i l l a f t a s r u c c o t p u r r e t n I
N O N O . s e g d e g n i l l a f d n a g n i s i r h t o b t a s r u c c o t p u r r e t n I
3 T N I 2 1 4 2
F F O
3 1 4 2
F F O
. e g d e g n i s i r t a s r u c c o t p u r r e t n I
N O F F O
F F O N O . e g d e g n i l l a f t a s r u c c o t p u r r e t n I
N O N O . s e g d e g n i l l a f d n a g n i s i r h t o b t a s r u c c o t p u r r e t n I
r o t c a f t p u r r e t n i l a n r e t x E n o i t p i r c s e D
0 T N I f o e c n e r r u c c O
) s t i b r e d r o - w o l ( 8 2 9 1 M D o t n e t t i r w s i 0 H T C f o e u l a V
) s t i b r e d r o - h g i h ( 9 2 9 1 M D d n a
1 T N I f o e c n e r r u c c O
) s t i b r e d r o - w o l ( 0 3 9 1 M D o t n e t t i r w s i 0 H T C f o e u l a V
) s t i b r e d r o - h g i h ( 1 3 9 1 M D d n a
2 T N I f o e c n e r r u c c O
) s t i b r e d r o - w o l ( 2 3 9 1 M D o t n e t t i r w s i 1 H T C f o e u l a V
) s t i b r e d r o - h g i h ( 3 3 9 1 M D d n a
3 T N I f o e c n e r r u c c O
) s t i b r e d r o - w o l ( 4 3 9 1 M D o t n e t t i r w s i 1 H T C f o e u l a V
) s t i b r e d r o - h g i h ( 5 3 9 1 M D d n a
3.2 Interrupt Processing
3-196
V
i
s
u
a
l

K
V
S
e
r
i
e
s
3
Chapter 3 Interrupts
Use SET-RES instructions to turn the special utility relays ON/OFF.
The input capture function stores the high-order bit data only when the 24-
bit high-speed counter is used. The data is undefined when the 16-bit high-
speed counter is used.
"4.4.1 24-bit High-speed Counter" (p. 3-221)
Timing of the input capture execution depends on the input polarity setting
specified with special utility relays 2402 through 2405 and 2410 through
2413.
3.2.3 Interrupt Priority
When many interrupts occur sequentially, priority is given to the interrupt which
occurs earlier.
When two or more interrupts occur simultaneously, priority is given in the order of
0000, 0001, 0002, 0003, CTC2, CTC3, CTC0, and CTC1.
Note 1: While one interrupt is being executed, other interrupts are disabled. (Multi-
level interrupts are possible by placing an EI instruction within an interrupt routine.)
Note 2: When other interrupts occur during execution of an interrupt, other interrupts
are stored up to 8 levels deep. The stored interrupts are executed after completion
of the previous interrupt, according to the priority order. However, an interrupt which
uses the same device as a previous interrupt cannot be stored.
3.2.4 Interrupt Program
The interrupt program is a program which is executed by an interrupt. It is necessary
to execute an EI (Interrupt enabled) instruction before executing an interrupt pro-
gram.
To temporarily disable an interrupt, execute a DI (Interrupt disabled) instruction.
When an interrupt is disabled, subsequent interrupts are not executed but stored
until the next EI instruction.
"EI instruction", "DI instruction" (p. 3-193)
Example of an interrupt program
Note 1: To shorten the input time constant, use the HSP instruction (to 10 s) or
specify the desired value in DM1940 and turn ON special utility relay 2813.
Note 2: For more about the input time constant, refer to "1.4.1 Input Time Constant
Change Function" (p. 3-23).
Note 3: Use SET-RES instructions instead of OUT-OUTB instructions within inter-
rupt programs.
The following instructions cannot be used within interrupt programs:
TMR, TMH, TMS, DIFU, DIFD, W-ON, W-OFF, W-UE, W-DE, STG, JMP, ENDS,
HKEY, ITVL, @xxxx (differentiation type instructions), C, UDC, SFT
CAUTION
2008
EI
HSP
0000
END
RETI
ENDH
INT
0000
An interrupt program is not executed unless an EI instruction is executed.
Set the input time constant shorter by using the HSP instruction
(to 10 s) or by turning ON special utility relay 2813.
Write the interrupt program between the END and ENDH
instructions.
3.3 Direct Input/Output
3-197
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
3
Chapter 3 Interrupts
2002
2008
END
INT
0000
1000
0005
RETI
ENDH
0500
HSP
0000
HSP
0005
EI
1000
SET
2002
2008
EI
END
INT
0000
HSP
0001
HSP
0000
2002
RETI
INT
0001
2002
RETI
ENDH
0500
SET
0501
SET
3.3 Direc t Input/Output
This section describes direct input and output.
3.3.1 Direct Input
The direct input function is used during interrupt processing. Direct input allows the
KV PLC to fetch the input status of the input relays during execution of the interrupt
program.
Direct input is available only with input relays 0000 through 0015 (KV-10xx: 0000-
0005, KV-16xx: 0000-0009). (KV-300: 0000-0005)
The input time constant must be set to 10 s by using the HSP instruction or by
turning ON special utility relay 2813.
The direct input data is effective only within the interrupt program so that the
internal utility relay must be provided.
3.3.2 Direct Output
Direct output allows the Visual KV PLC to output the ON/OFF status of output relays
during execution of the interrupt program. Direct output is available only with output
relays 0500 through 0503.
Direct output is not affected by the scan time.
3.4 Applications of Interrupt Programs
3-198
V
i
s
u
a
l

K
V
S
e
r
i
e
s
3
Chapter 3 Interrupts
0001
0002
0003
0004
0005
0006
0007
0008
2008
EI
2002
2002
T0000 0500
HSP
0000
END
INT
0002
RETI
ENDH
#00010
T000
0500
RES
0500
SET
3.4 Applic ations of Interrupt Programs
This section presents program examples of interrupt processing.
3.4.1 Interrupt with a Signal Converter
I Outline
Converts the short pulses which are input by interrupt processing into pulses of a
constant width and then outputs them.
I Ladder diagram
Converts the short pulses input from input relay 0000 into pulses of 1-second ON
width and then outputs them from output relay 0500.
Output relay 0500 turns ON for 1 second from the rising edge of input relay 0000.
OFF
ON
OFF
ON
ON ON ON
1 sec.
Scan
Input 0000
Output 0500
1 sec. 1 sec.
When input 0000 turns
ON, output 0500 turns ON.
When power is turned on, an EI
instruction enables interrupts.
Sets the input time constant of
input 0000 to 10 s.
Turns ON output 0500 for 1
second and then turns it OFF.
3.4 Applications of Interrupt Programs
3-199
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
3
Chapter 3 Interrupts
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
2008
EI
2002 HSP
0004
2002 CTH0
0004
#10000
CTC0
CTH0
RES
0500
SET
2103
SET
2002
0500
RES
0000
END
INT
CTC0
RETI
ENDH
3.4.2 Interrupt with a High-speed Counter
I Outline
Uses the input value of a high-speed counter from one input relay and the ON/OFF
status of another input relay to control the ON/OFF status of an output relay.
Example: Filling control for medicine (tablets)
I Ladder diagram
Output relay 0500 turns ON when the input value of the high-speed counter from
input relay 0004 reaches "10000".
Output relay 0500 turns OFF when input relay 0000 turns ON.
Sensor
When power is turned on, an EI
instruction enables interrupts.
Sets automatic reset of CTH0.
Resets current value of CTH0.
ON
OFF
ON
OFF
ON
OFF
ON
Output 0500
Scan
Input 0004
Input 0000
Sets an input time constant of
input 0004 to 10 s.
Turns OFF output 0500 when
input 0000 turns ON.
Executes an interrupt when the
input value of CTH0 reaches
"10000". Turns ON output 0500.
Specifies CTH0 as the high-
speed counter for input 0004 and
sets "10000" as the preset value
of CTC0.
Visual KV
3.4 Applications of Interrupt Programs
3-200
V
i
s
u
a
l

K
V
S
e
r
i
e
s
3
Chapter 3 Interrupts
0001
0002
0003
0004
0005
0006
0007
0008
0009
2008
EI
2002 HSP
0000
2002 CTH0
2100
2403
END
INT
0000
RETI
ENDH
KEEP
2403
RES
SET
TM02
STA
DM1928
LDA
DM0000
STA
TM02
SUB
DM1928
LDA
2403
3.4.3 Measuring the ON Time of High-speed Pulses
I Outline
Measures the pulse width of the pulse input to an input relay.
Example: Measurement of workpiece length
I Ladder diagram
Special utility relay 2100 is turned ON to measure the pulse width using 1-s
units.
The values when input relay 0000 is ON is written into temporary data memory
TM02, and the values when input relay 0000 is OFF is written into data memory
DM1912. The pulse width can be obtained by subtracting the value of TM02 from
the value of DM1912.
The obtained value is written into data memory DM0000 (Unit: s).
Turns ON input 0000 to execute an
interrupt.
First, an interrupt is executed at the
rising edge of input 0000. The
current value of CTH0 stored in
DM1928 is written to TM02. Turns
ON special utility relay 2403 to
change the interrupt polarity to the
falling edge.
Next, an interrupt is executed at the
falling edge of input 0000. The
value stored in TM02 is subtracted
from the current value of CTH0
stored in DM1928, and the
obtained ON width of input 0000 is
written to DM0000. Turns OFF
special utility relay 2403 to change
the interrupt polarity to the rising
edge.
When power is turned ON, an EI
instruction enables interrupts.
Sets an input time constant of
input 0000 to 10 s.
CTH0 counts pulses with a 1-s
internal clock.
OFF
ON
Sensor input 0000
Pulse width (s)
Visual KV
Sensor
3.4 Applications of Interrupt Programs
3-201
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
3
Chapter 3 Interrupts
3.4.4 Measuring the Period in which a Target Passes between
Two Points
I Outline
Measures the period in which two input relays turn ON.
Example: Measurement of tact time
I Ladder diagram
Measures the time from when input relay 0002 turns ON until input relay 0003
turn ON.
The measured value is written to data memory DM0000 (Unit: s).
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
2008
EI
2002 HSP
0002
HSP
0003
2002 CTH1
2200
2411
RES
2412
RES
2413
RES
2410
RES
END
INT
0002
RETI
RETI
ENDH
INT
0003
DM0000
STA
DM1932
SUB
DM1934
LDA
2002
When power is turned on, an
EI instruction enables inter-
rupts. Sets the interrupt polarity
of inputs 0002 and 0003 to the
rising edge.
Sets the input time constant of
inputs 0002 and 0003 to 10 s.
CTH1 counts the pulses using
a 1-s internal clock.
When INT2 is executed, the
current value of CTH1 is
automatically transferred to
DM1932 and DM1933 (Input
capture).
When INT3 is executed, the
current value of CTH1 is
automatically transferred to
DM1934 and DM1935 (Input
capture).
Subtracts the input capture
value of INT2 from that of INT3
to obtain the time it takes for
the target to pass between two
points and then writes it to
DM0000.
OFF
ON
OFF
ON
Sensor 1 input 0002
Sensor 2 input 0003
Passing time (s)
Sensor 1
Sensor 2
Visual KV
3.4 Applications of Interrupt Programs
3-202
V
i
s
u
a
l

K
V
S
e
r
i
e
s
3
Chapter 3 Interrupts
Chapter 4
High-speed Counters
This chapter describes high-speed counters and high-speed counter comparators,
which allow high-speed pulse measurement and pulse output, independent of the
scan time.
For KV-10/80 Series, see Chapter 6.
4.1 High-speed Counter Instructions ................................................ 3-204
4.2 Outline of High-speed Counters .................................................. 3-206
4.2.1 High-speed Counters and High-speed Counter Comparators ............... 3-206
4.2.2 Internal Clock for High-speed Counters ................................................. 3-210
4.3 Setting and Operation of High-speed Counters ...................... 3-211
4.3.1 Reading the Current Value of the High-speed Counter ......................... 3-211
4.3.2 Preset Value of the High-speed Counter Comparator ........................... 3-211
4.3.3 Comparator Output ................................................................................ 3-211
4.3.4 Count Input Method................................................................................ 3-212
4.3.5 Resetting the High-speed Counter ......................................................... 3-214
4.3.6 Differences with the CTH Instruction between the
Conventional and Visual KV Series ....................................................... 3-216
4.3.7 Applications of High-speed Counters ..................................................... 3-217
4.4 Expanded Functions of High-speed Counters ......................... 3-221
4.4.1 24-bit High-speed Counter ..................................................................... 3-221
4.4.2 Changing the Current Value of a 24-bit High-speed Counter ................ 3-223
4.4.3 Application Example of 24-bit High-speed Counter (single-phase input) 3-224
4.4.4 Ring Counter Function ........................................................................... 3-225
4.4.5 Applications of Ring Counters ................................................................ 3-226
4.5 Special Functions Using High-speed Counters ...................... 3-228
4.5.1 Specified Frequency Pulse Output Function .......................................... 3-228
4.5.2 Applications of the Specified Frequency Pulse Output .......................... 3-229
4.5.3 Frequency Counter Function.................................................................. 3-231
4.5.4 Applications of Frequency Counters ...................................................... 3-232
4.5.5 Cam Switch Function ............................................................................. 3-233
4.5.6 Application of the Cam Switch ............................................................... 3-236
4.6 Direct Clock Pulse Output ............................................................. 3-237
4.6.1 Outline of Direct Clock Pulse Output ...................................................... 3-237
4.6.2 Pulse Output Setting with the High-speed Counter Comparator ............ 3-238
4.7 Examples of Direct Clock Pulse Output .................................... 3-242
4.7.1 Example of Outputting a Pulse with 1:1 ON/OFF Ratio ......................... 3-242
4.7.2 Example of Outputting a Pulse with Variable ON/OFF Ratio ................. 3-245
4.7.3 Example of Stopping the Pulse Output at a Specified Pulse Count ....... 3-249
4.7.4 Application of Direct Clock Pulse Output (Ramp-up/down control) ........ 3-251
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4.1 High-speed Counter Instructions
3-204
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
CTH0: 16-Bit High-
speed counter
CTH1: 16-Bit High-
speed counter
CTC: High-speed
counter comparator
16-bit (0 to 65535) up/down counters for
clock pulses with a 30-kHz input
1.
response frequency.
Can be changed to 24-bit (0 to 16777215)
counters with the MEMSW instruction.
2.
Enables 30 kHz, two-phase input through
two channels.
1.
Hardware-based comparator between the
preset value and current value of the
high-speed counter.
The current value can be changed to a
preset value by external input.
SET
1
CTC
CTH
CTH
RES
0
CTH1
nnnn
CTCn
#ddddd
CTH0
nnnn
2008
0000
CTH0
RES
0500
SET
2103
SET
CTC0
RES
2008
0500
RES
CTC0
0500 T000
#60000
CTC0
#00030
T000
CTH0
0004
HSP
0004
1)
2)
3)
4)
5)
Input-enable relay
4.1 High-speed Counter Instruc tions
This section describes the CTH0, CTH1, and CTC instructions, which are used for
high-speed counters.
Count input
Example
Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0009 LD CTC0
0001 HSP 0004 0010 SET 0500
0002 LD 2008 0011 LD 0500
0003 SET 2103 0012 TMR 000 #00030
0004 CON 0013 AND T000
0005 RES CTH0 0014 RES CTC0
0006 LD 0000 0015 CON
0007 CTH0 0004 0016 RES 0500
0008 CTC0 #6000
:
:
:
1. KV-300/Visual KV only
2. Visual KV only
4.1 High-speed Counter Instructions
3-205
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
Operands
CTH0: 0004
2100 to 2102
CTH1: 0005
0500
2200 to 2202
CTC0 to 3: Preset value
#00001 to #65535
Key operation
Description
1) Initializes the setting when power is turned on.
The HSP instruction sets the input time constant of input relay 0004 to 10 s.
The current value of CTH0 is reset as soon as it matches the preset value of
CTC0 when special utility relay 2103 is ON.
2) The counting is disabled when input relay 0000 is OFF. Counting starts (at 0004)
when input relay 0000 turns ON.
3) Sets "60000" as the preset value of the high-speed counter comparator.
4) When the current value of CTH0 reaches "60000", output relay 0500 turns ON
and the current value is reset.
5) Turns OFF both CTC0 and 0500 for three seconds after output relay 0500 turns
ON.
Tips
Unlike software-based counters, the high-speed counter is a hardware-based,
program-independent counter. It achieves an input response frequency of 30 kHz
without being affected by the scan time.
Input relays 0004 and 0005 can independently count the pulses with a 30 kHz
input response frequency.
Two-phase encoder input can be captured through two channels (30 kHz).
CTH0 uses input from relay 0004 as phase A input and input from relay 0006 as
phase B input (KV-10xx: 0000). CTH1 uses input from 0005 as phase A input
and input from 0007 as phase B input (KV-10xx: 0001).
Note: When phase differential input is used, pulses with a maximum frequency of 30
kHz can be counted, provided the pulses have a duty ratio of 1:1 (50%) and phase
difference of 90. Inputting pulses with an irregular duty ratio or phase difference will
decrease the allowable input frequency.
SET
1
RES
0
CTC
CTH
Operand
Clock input
Preset
value
ENT
R-SRCH
ENT
R-SRCH
4.2 Outline of High-speed Counters
3-206
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
4.2 Outline of High-speed Counters
This section describes the outline and specifications for high-speed counters and
high-speed counter comparators featured with the Visual KV Series.
4.2.1 High-speed Counters and High-speed Counter Compara-
tors
The high-speed counter is a hardware-based counter that can count high-speed
pulses that cannot be counted by counters written in main routines (C or UDC).
(Pulses with a maximum frequency of 30 kHz can be counted.). *
High-speed counter comparators are hardware-based comparators that compare
their preset value with the current value of one of the a high-speed counters.
Both counters and comparators perform processing with hardware rather than
software programs, enabling high-speed performance independent of the scan time.
Structure of high-speed counters and high-speed counter comparators
The Visual KV PLC has two high-speed counters, each equipped with two high-
speed counter comparators and dedicated internal clocks.
Block diagram of high-speed counters
1. With the KV-10xx, the external input relay for CTH0 is 0004 (phase A)/0000
(phase B), and for CTH1 is 0005 (phase A)/0001 (phase B).
2. With the KV-10xx, the preset input relay for CTH0 is 0002, and for CTH1 is 0003.
For KV-10/80 user's
Max. response frequency: 10 kHz
* 2100 0.8 s
2101 6.4 s
2102 102.4 s
2200 0.4 s
2201 0.8 s
2202 3.2 s
CTC2
CTH1
CTC3
DM1932, DM1933(INT2)
DM1934, DM1935(INT3)
2203 to 2214
INT CTC2
INT CTC3
2200 (1.0 s)
2201 (10.0 s)
2202 (100.0s)

0500
0005/0007
CTC0
CTH0
CTC1
DM1928, DM1929(INT0)
DM1930, DM1931(INT1)
2103 to 2114
INT CTC0
INT CTC1
2100 (1.0 s)
2101 (10.0 s)
2102 (100.0 s)
0004/0006
0005
(0007)
0004
(0006)
0008 (RESET)
2.
0009 (RESET)
2.
0500
0501
Phase A
Phase B
Internal clocks*
External input
16-bit high-speed
counter
high-speed
counter
comparator
high-speed
counter
comparator
Input capture device Special utility relay
Control circuit
Input capture device Internal clocks*
External input
16-bit high-speed
counter
high-speed
counter
comparator
high-speed
counter
comparator
Special utility relay
Control circuit
Phase A
Phase B
Internal connection
for external clock
4.2 Outline of High-speed Counters
3-207
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
I List of special utility relays for high-speed counter CTH0
* Read-only relay.
I List of special utility relays for high-speed counter CTH1
* Read-only relay.
y a l e R
. o N
n o i t c n u F
* 0 0 1 2 1 ( 0 H T C r o f y l n o d e s u k c o l c l a n r e t n I ) s
* 1 0 1 2 0 1 ( 0 H T C r o f y l n o d e s u k c o l c l a n r e t n I ) s
* 2 0 1 2 0 0 1 ( 0 H T C r o f y l n o d e s u k c o l c l a n r e t n I ) s
3 0 1 2 . N O s n r u t 0 C T C r o t a r a p m o c n e h w 0 H T C s r a e l c y l l a c i t a m o t u A o N : F F O s e Y : N O
4 0 1 2
0 C T C r o t a r a p m o c n e h w 0 0 5 0 m o r f t u p t u o t c e r i d s e l b a n e / s e l b a s i D
. N O s n r u t
e l b a s i D : N O
e l b a n E : F F O
5 0 1 2 . N O s n r u t 0 C T C r o t a r a p m o c n e h w 0 0 5 0 m o r f t u p t u o t c e r i d F F O s n r u T o N : F F O s e Y : N O
6 0 1 2 . N O s n r u t 0 C T C r o t a r a p m o c n e h w 0 0 5 0 m o r f t u p t u o t c e r i d N O s n r u T o N : F F O s e Y : N O
7 0 1 2
r o t a r a p m o c e m i t h c a e 0 0 5 0 m o r f t u p t u o f o s u t a t s F F O / N O s e s r e v e R
. N O s n r u t 0 C T C
o N : F F O s e Y : N O
8 0 1 2
1 C T C r o t a r a p m o c n e h w 0 0 5 0 m o r f t u p t u o t c e r i d s e l b a n e / s e l b a s i D
. N O s n r u t
e l b a s i D : N O
e l b a n E : F F O
9 0 1 2 . N O s n r u t 1 C T C r o t a r a p m o c n e h w 0 0 5 0 m o r f t u p t u o t c e r i d F F O s n r u T o N : F F O s e Y : N O
0 1 1 2 . N O s n r u t 1 C T C r o t a r a p m o c n e h w 0 0 5 0 m o r f t u p t u o t c e r i d N O s n r u T o N : F F O s e Y : N O
1 1 1 2
r o t a r a p m o c e m i t h c a e 0 0 5 0 m o r f t u p t u o f o s u t a t s F F O / N O s e s r e v e R
. N O s n r u t 1 C T C
o N : F F O s e Y : N O
2 1 1 2 . N O s n r u t 1 C T C r o t a r a p m o c n e h w 0 H T C s r a e l c y l l a c i t a m o t u A o N : F F O s e Y : N O
3 1 1 2
. 0 H T C r o f e d o m n o i t a c i l p i t l u m s t c e l e S
4 x : N O / F F O 2 x : F F O / N O ) e s l u p 1 ( n o i t a c i l p i t l u m o N : F F O / F F O
s e s l u p 2 : N O / N O
4 1 1 2
n o i t a c i l p i t l u M
e d o m
n o i t a c i l p i t l u m o N
) e s l u p 1 (
2 x 4 x s e s l u p 2
3 1 1 2 F F O N O F F O N O
4 1 1 2 F F O F F O N O N O
y a l e R
. o N
n o i t c n u F
* 0 0 2 2 1 ( 1 H T C r o f y l n o d e s u k c o l c l a n r e t n I ) s
* 1 0 2 2 0 1 ( 1 H T C r o f y l n o d e s u k c o l c l a n r e t n I ) s
* 2 0 2 2 0 0 1 ( 1 H T C r o f y l n o d e s u k c o l c l a n r e t n I ) s
3 0 2 2 . N O s n r u t 2 C T C r o t a r a p m o c n e h w 1 H T C s r a e l c y l l a c i t a m o t u A o N : F F O s e Y : N O
4 0 2 2
2 C T C r o t a r a p m o c n e h w 1 0 5 0 m o r f t u p t u o t c e r i d s e l b a n e / s e l b a s i D
. N O s n r u t
e l b a s i D : N O
e l b a n E : F F O
5 0 2 2 . N O s n r u t 2 C T C r o t a r a p m o c n e h w 1 0 5 0 m o r f t u p t u o t c e r i d F F O s n r u T o N : F F O s e Y : N O
6 0 2 2 . N O s n r u t 2 C T C r o t a r a p m o c n e h w 1 0 5 0 m o r f t u p t u o t c e r i d N O s n r u T o N : F F O s e Y : N O
7 0 2 2
r o t a r a p m o c e m i t h c a e 1 0 5 0 m o r f t u p t u o f o s u t a t s F F O / N O s e s r e v e R
. N O s n r u t 2 C T C
o N : F F O s e Y : N O
8 0 2 2
3 C T C r o t a r a p m o c n e h w 1 0 5 0 m o r f t u p t u o t c e r i d s e l b a n e / s e l b a s i D
. N O s n r u t
e l b a s i D : N O
e l b a n E : F F O
9 0 2 2 . N O s n r u t 3 C T C r o t a r a p m o c n e h w 1 0 5 0 m o r f t u p t u o t c e r i d F F O s n r u T o N : F F O s e Y : N O
0 1 2 2 . N O s n r u t 3 C T C r o t a r a p m o c n e h w 1 0 5 0 m o r f t u p t u o t c e r i d N O s n r u T o N : F F O s e Y : N O
1 1 2 2
r o t a r a p m o c e m i t h c a e 1 0 5 0 m o r f t u p t u o f o s u t a t s F F O / N O s e s r e v e R
. N O s n r u t 3 C T C
o N : F F O s e Y : N O
2 1 2 2 . N O s n r u t 3 C T C r o t a r a p m o c n e h w 1 H T C s r a e l c y l l a c i t a m o t u A o N : F F O s e Y : N O
3 1 2 2
. 1 H T C r o f e d o m n o i t a c i l p i t l u m s t c e l e S
s e s l u p 2 : N O / N O 4 x : N O / F F O 2 x : F F O / N O ) e s l u p 1 ( n o i t a c i l p i t l u m o N : F F O / F F O
4 1 2 2
n o i t a c i l p i t l u M
e d o m
n o i t a c i l p i t l u m o N
) e s l u p 1 (
2 x 4 x s e s l u p 2
3 1 2 2 F F O N O F F O N O
4 1 2 2 F F O F F O N O N O
4.2 Outline of High-speed Counters
3-208
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
I Other special utility relays
I Data memory
Note 1: As with the internal register, the contents of data memory are stored as 16-
bit binary data.
Note 2: The contents of data memory are stored even when the Visual KV is turned
off or "ALL DATA MEMORY CLEAR" is executed. It is stored more than 20 days
with the KV-10xx, and more than two months with other models.
Specifications of high-speed counters
The high-speed counter is a hardware-based up/down counter that counts from 0
to 65535 with an auto-reset function.
The following operands can be specified for count inputs.
High-speed counters CTH0 and CTH1 store current values only.
When input relays 0004 and 0005 are selected as operands, they can be used as
high-speed counters with a response frequency of 30 kHz.
When special utility relays 2100 through 2102 and 2200 through 2202 are se-
lected as operands, the high-speed counters can be used as high-speed timers.
When relay 0500 is selected as an operand for CTH1, CTH1 can count the clock
pulses produced by CTH0.
CTH0 and CTH1 can be used as 24-bit high-speed counters when the MEMSW
instruction is set.
"MEMSW instruction" (p. 3-92), "4.4.1 24-bit High-speed Counter" (p. 3-221), "4.3.4 Count Input
Method" (p. 3-212), "When using comparator output from other counters as count input" (p. 3-213).
y a l e R
. o N
n o i t c n u F
0 0 4 2
l a n g i s l a n r e t x e y b e u l a v t e s e r p o t 0 H T C f o e u l a v t n e r r u c s e g n a h C
l e v e L : N O / N O e g d e g n i l l a f t A : N O / F F O e g d e g n i s i r t A : F F O / N O d e s u t o N : F F O / F F O
1 0 4 2
6 0 4 2 o N : F F O s e Y : N O . r e t n u o c g n i r s a 0 H T C s t e S
7 0 4 2
. 0 H T C r o f d e s u s i e d o m n o i t a c i l p i t l u m o n n e h w t u p n i B e s a h p s e r o n g I
. l a u s u s a t u p n i B e s a h p e s U : F F O . p u t n u o c s y a w l a d n a t u p n i B e s a h p e r o n g I : N O
8 0 4 2
l a n g i s l a n r e t x e y b e u l a v t e s e r p o t 1 H T C f o e u l a v t n e r r u c s e g n a h C
l e v e L : N O / N O e g d e g n i l l a f t A : N O / F F O e g d e g n i s i r t A : F F O / N O d e s u t o N : F F O / F F O
9 0 4 2
4 1 4 2 o N : F F O s e Y : N O . r e t n u o c g n i r s a 1 H T C s t e S
5 1 4 2
. 1 H T C r o f d e s u s i e d o m n o i t a c i l p i t l u m o n n e h w t u p n i B e s a h p s e r o n g I
. l a u s u s a t u p n i B e s a h p e s U : F F O . p u t n u o c s y a w l a d n a t u p n i B e s a h p e r o n g I : N O
. o N M D n o i t p i r c s e D
1 0 9 1 M D / 0 0 9 1 M D . d a e r s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 0 H T C t i b - 4 2 f o e u l a v t n e r r u C
3 0 9 1 M D / 2 0 9 1 M D . d a e r s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 1 H T C t i b - 4 2 f o e u l a v t n e r r u C
5 0 9 1 M D / 4 0 9 1 M D . d a e r s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 0 C T C t i b - 4 2 f o e u l a v t n e r r u C
7 0 9 1 M D / 6 0 9 1 M D . d a e r s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 1 C T C t i b - 4 2 f o e u l a v t n e r r u C
9 0 9 1 M D / 8 0 9 1 M D . d a e r s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 2 C T C t i b - 4 2 f o e u l a v t n e r r u C
1 1 9 1 M D / 0 1 9 1 M D . d a e r s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 3 C T C t i b - 4 2 f o e u l a v t n e r r u C
3 1 9 1 M D / 2 1 9 1 M D . n e t t i r w s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 0 H T C t i b - 4 2 f o e u l a v t n e r r u C
5 1 9 1 M D / 4 1 9 1 M D . n e t t i r w s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 1 H T C t i b - 4 2 f o e u l a v t n e r r u C
7 1 9 1 M D / 6 1 9 1 M D . n e t t i r w s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 0 C T C t i b - 4 2 f o e u l a v t e s e r P
9 1 9 1 M D / 8 1 9 1 M D . n e t t i r w s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 1 C T C t i b - 4 2 f o e u l a v t e s e r P
1 2 9 1 M D / 0 2 9 1 M D . n e t t i r w s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 2 C T C t i b - 4 2 f o e u l a v t e s e r P
3 2 9 1 M D / 2 2 9 1 M D . n e t t i r w s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 3 C T C t i b - 4 2 f o e u l a v t e s e r P
5 2 9 1 M D / 4 2 9 1 M D . n e t t i r w s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 0 H T C f o e u l a v t e s e r P
7 2 9 1 M D / 6 2 9 1 M D . n e t t i r w s i ) s t i b r e d r o - h g i h / s t i b r e d r o - w o l ( 1 H T C f o e u l a v t e s e r P
r e t n u o c d e e p s - h g i H d n a r e p O e g n a r t n e m e r u s a e M
0 H T C 4 0 0 0 , 2 0 1 2 o t 0 0 1 2
5 3 5 5 6 o t 0 0 0 0 0 #
1 H T C 0 0 5 0 , 5 0 0 0 , 2 0 2 2 o t 0 0 2 2
4.2 Outline of High-speed Counters
3-209
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
Note 1: CTH instructions cannot be duplicated in a program. A maximum of two
counters, CTH0 and CTH1, can be used in one program.
Note 2: The operands for a high-speed counter cannot be changed during program
execution.
Note 3: When using a high-speed counter with external inputs, the input time con-
stant must be set to 10 s with the HSP instruction or with special utility relay 2813.
(Pulses with a maximum frequency of 30 kHz can be counted.)
Note 4: When using input 0004 as an operand, use input 0006 (KV-10xx: 0000) for
phase B input. Therefore, do not use input 0006 (KV-10xx: 0000) other than for the
high-speed counter.
Note 5: When selecting no multiplication mode, and you do not want to use input
0006 (KV-10xx: 0000) as phase B input, turn ON special utility relay 2407.
Note 6: When using input 0005 as an operand, use input 0007 (KV-10xx: 0001) for
phase B input. Therefore, do not use input 0007 (KV-10xx: 0000) other than for the
high-speed counter.
Note 7: When selecting no multiplication mode, and you do not want to use input
0007 (KV-10xx: 0001) as phase B input, turn ON special utility relay 2415.
Note 8: When using the high-speed counter internal connection relay 0500, only
single-phase input is available. In this case, external input relays 0005 and 0007 for
CTH1 can be used as normal input relays.
Note 9: When using phase differential input, pulses with a maximum frequency of 30
kHz can be counted, provided the pulses have a duty ratio of 1:1 (50%) and phase
difference of 90. Inputting pulses with an irregular duty ratio or phase difference will
decrease the allowable input frequency.
Note 10: The current value of the high-speed counter is stored with a built-in,
electrical double-layer capacitor for more than two months at 25C (KV-10xx: more
than 20 days). The value can also be stored in EEPROM.
"3.5 System Mode" (p.1-94).
High-speed counter comparators
The high-speed counter comparator (CTC) compares its preset value with the
value of the high-speed counter (CTH).
The CTC contact turns ON when the current value of the CTH matches the
preset value of the CTC.
Among CTC contacts, the ON/OFF status of output relays 0500 and 0501 can be
changed with hardware (direct output) or can be used to execute an interrupt. Set
special utility relays (2103 to 2112, 2203 to 2212) to change the ON/OFF status
of output relays 0500 and 0501.
The following table shows the relationship between the high-speed counters and
high-speed counter comparators.
Note 1: Once the high-speed counter comparator turns ON, it remains ON until a
RES instruction is encountered.
Note 2: When a high-speed counter comparator is used as an interrupt, the interrupt
is executed as soon as the current value of the high-speed counter reaches the
preset value of the comparator. At the same time, the contact for the high-speed
counter comparator automatically turns OFF.
Note 3: CTC2 or CTC3 cannot be used as comparators for CTH0; CTC0 or CTC1
cannot be used as comparators for CTH1.
Note 4: Do not specify "#00000" as the preset value for CTC0 through CTC3.
d e e p s - h g i H
r e t n u o c
r e t n u o c d e e p s - h g i H
r o t a r a p m o c
e u l a v t e s e r P
e g n a r
t c e r i D
t u p t u o
s t p u r r e t n I
0 H T C 1 C T C , 0 C T C
5 3 5 5 6 o t 1 #
0 0 5 0 1 C T C T N I , 0 C T C T N I
1 H T C 3 C T C , 2 C T C 1 0 5 0 3 C T C T N I , 2 C T C T N I
4.2 Outline of High-speed Counters
3-210
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
4.2.2 Internal Clock for High-speed Counters
Each high-speed counter (CTH) is equipped with a dedicated internal clock.
To use the internal clock, specify the appropriate relay No. as an operand for the
CTH instruction.
The internal clock or external pulses cannot be changed during program execu-
tion.
Each clock has the following count period:
High-speed counter internal clock error
Absolute error: 200 ppm
Temperature coefficient: 00
Relative error between CTH0 and CTH1: 0
r e t n u o c d e e p s - h g i H 0 H T C 1 H T C d o i r e P
. o N y a l e R
0 0 1 2 0 0 2 2 0 . 1 s
1 0 1 2 1 0 2 2 0 . 0 1 s
2 0 1 2 2 0 2 2 0 . 0 0 1 s
4.3 Setting and Operation of High-speed Counters
3-211
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
r e t n u o c d e e p s - h g i H e u l a v t n e r r u C
0 H T C
5 3 5 5 6 o t 0
1 H T C
r e t n u o c d e e p s - h g i H
r e t n u o c d e e p s - h g i H
r o t a r a p m o c
0 H T C
0 C T C
1 C T C
1 H T C
2 C T C
3 C T C
d e e p s - h g i H
r e t n u o c
d e e p s - h g i H
r e t n u o c
r o t a r a p m o c
y t i l i t u l a i c e p S
y a l e r
y a l e r y t i l i t u l a i c e p s f o g n i t t e S
0 H T C
0 C T C 4 0 1 2 o N : N O s e Y : F F O . F F O / N O 0 0 5 0 y a l e r t u p t u o s n r u T
1 C T C 8 0 1 2 o N : N O s e Y : F F O . F F O / N O 0 0 5 0 y a l e r t u p t u o s n r u T
1 H T C
2 C T C 4 0 2 2 o N : N O s e Y : F F O . F F O / N O 1 0 5 0 y a l e r t u p t u o s n r u T
3 C T C 8 0 2 2 o N : N O s e Y : F F O . F F O / N O 1 0 5 0 y a l e r t u p t u o s n r u T
4.3 Setting and Operation of High-speed
Counters
The high-speed counters and high-speed counter comparators operate using data
specified with special utility relays.
4.3.1 Reading the Current Value of the High-speed Counter
The current value of a high-speed counter is normally written as 16-bit data (0 to
65535).
The range of the current value for high-speed counters is as follows:
Refer to "4.4.1 24-bit High-speed Counter" (p. 3-221) when using the 24-bit high-speed counter.
4.3.2 Preset Value of the High-speed Counter Comparator
The preset value of a high-speed counter comparator is written as 16-bit data (0 to
65535).
The relationship between high-speed counters and high-speed counter comparators
is as follows:
Refer to "4.4.1 24-bit High-speed Counter" (p. 3-221) when using the 24-bit high-speed counter.
4.3.3 Comparator Output
The high-speed counter comparator provides the comparator output function, which
turns ON outputs as soon as the comparator turns ON, without being affected by the
scan time.
Comparator output is controlled by setting special utility relays. The relationships
among the high-speed counters, high-speed counter comparators, and special utility
relays are as follows:
4.3 Setting and Operation of High-speed Counters
3-212
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
4.3.4 Count Input Method
Select the input source for the high-speed counter.
When using an internal clock as input
Three types of internal clocks are provided: 1 s, 10 s, and 100 s.
Set the desired internal clock with a special utility relay.
When using external inputs as count inputs
Set special utility relays as follows:
I Operation mode
The counting method can be selected from the following when external inputs are
used.
The ring counter function is available for each counting method.
For more about the ring counter, refer to "4.4.4 Ring Counter Function" (p. 3-225).
I Types of operation modes
No multiplication mode (single-phase input)
Counts up at the rising edge of phase A while phase B is OFF.
Counts down at the rising edge of phase A while phase B is ON.
With direction judgement (Special utility relay 2407: OFF)
Without direction judgement (Special utility relay 2407: ON)
Phase B input can be ignored by turning ON special utility relay 2407 (for CTH0) or
2415 (for CTH1).
0006
0004
CTH0 0 1 2 3 2 1 0
OFF
ON
OFF
ON
(Counter value)
(Phase A)
(Phase B)
e d o m n o i t a r e p O
0 H T C 1 H T C
3 1 1 2 4 1 1 2 7 0 4 2 3 1 2 2 4 1 2 2 5 1 4 2
n o i t a c i l p i t l u m o N
e s a h p - e l g n i s (
) t u p n i
t n e m e g d u j n o i t c e r i d h t i W
t u p n i B e s a h p n e h w p u t n u o C (
n w o d t n u o c , F F O s i ] 7 0 0 0 [ 6 0 0 0
) N O n e h w
F F O F F O F F O F F O F F O F F O
t n e m e g d u j n o i t c e r i d t u o h t i W
g n i r o n g i y b p u t n u o c s y a w l A (
) ] 7 0 0 0 [ 6 0 0 0 t u p n i B e s a h p
F F O F F O N O F F O F F O N O
l a i t n e r e f f i d e s a h P
t u p n i
2 x N O F F O N O F F O
4 x F F O N O F F O N O
d o h t e m e s l u p - 2
) n w o d t n u o c : B e s a h p , p u t n u o c : A e s a h P (
N O N O N O N O
t u p n i ) 1 H T C ( 0 0 5 0
0006
0004
CTH0 0 1 2 3 4 5 6
OFF
ON
OFF
ON
(Counter value)
(Phase A)
(Phase B)
4.3 Setting and Operation of High-speed Counters
3-213
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
Double (x2) mode: Counts up/down based on the phase difference
between two-phase pulse inputs (phase A and
phase B).
Quadruple (x4) mode: Counts up/down based on the phase difference
between two-phase pulse inputs (phase A and
phase B).
2-pulse method mode: Counts up at the rising edge of phase A and
counts down at the rising edge of phase B.
Count up: Rising edge of phase A
Count down: Rising edge of phase B
Note 1: Use SET-RES instructions to set the special utility relays.
Note 2: When using phase differential input, pulses with a maximum frequency of 30
kHz can be counted, provided the pulses have a duty ratio of 1:1 (50%) and phase
difference of 90. Inputting pulses with an irregular duty ratio or phase difference will
decrease the allowable input frequency.
When using comparator output from other counters as count input
When relay 0500 is specified as the operand for CTH1, the pulses produced by
CTH0 can be directly output from 0500 to CTH1.
In this case, input relays 0005 (phase A) and 0007 (phase B) for CTH1 can be used
as normal input relays.
3 2 1 0 7 6 5 4
0006
0004
CTH0
0 1 2 3 4 5 6 7 8
OFF
ON
OFF
ON
7 6 5 4 3 2 1 0 15 14 13 12 11 10 9 8
0006
0004
CTH0
0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
OFF
ON
OFF
ON
0006
0004
CTH0
0 1 2 3 4 5 6 5 4 3 2 1 0
OFF
ON
OFF
ON
(Counter value)
(Phase A)
(Phase B)
(Counter value)
(Phase A)
(Phase B)
(Counter value)
(Phase A)
(Phase B)
0500
CTH1
0 1 2 3 4 5 6
OFF
ON
(Counter value)
4.3 Setting and Operation of High-speed Counters
3-214
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
4.3.5 Resetting the High-speed Counter
Reset is an operation used to set the current value of a high-speed counter to "0".
Four types of reset operations are available: reset with input-enable relay, reset with
external input, reset automatically after counting up, and reset with the RES CTH
instruction.
Automatic reset after counting up
Resets the counter value as soon as the preset value matches the current value
(CTC = CTH).
This reset operation is independent of the scan time.
Note: Do not specify the same values for CTC0 and 1 (2 and 3) to automatically
reset the counter with both comparators.
Reset with the RES CTH instruction
Resets the counter by writing a RES CTH instruction to the program.
This reset operation is dependent on the scan time.
* CTH is reset by the output process of the scan which executes the RES CTH
instruction.
Reset with the input-enable relay
Resets the counter at execution of CTH instruction during the scan after the input-
enable relay is turned OFF.
This reset operation is dependent on the scan time.
* CTH is reset at execution of the CTH instruction during the scan after the input-
enable relay turns OFF.
CTH
Scan
Execution of CTH instruction
Input-enable relay
for CTH instruction
d e e p s - h g i H
r e t n u o c
d e e p s - h g i H
r e t n u o c
r o t a r a p m o c
. o N y a l e R n o i t a r e p O
0 H T C
0 C T C 3 0 1 2
e r a 2 1 1 2 d n a 3 0 1 2 s y a l e r y t i l i t u l a i c e p s n e h W
s a t e s e r s i e u l a v 0 H T C t n e r r u c e h t , N O d e n r u t
t e s e r p 1 C T C r o 0 C T C e h t s e h c t a m t i s a n o o s
. e u l a v
1 C T C 2 1 1 2
1 H T C
2 C T C 3 0 2 2
e r a 2 1 2 2 d n a 3 0 2 2 s y a l e r y t i l i t u l a i c e p s n e h W
s a t e s e r s i e u l a v 1 H T C t n e r r u c e h t , N O d e n r u t
t e s e r p 3 C T C r o 2 C T C e h t s e h c t a m t i s a n o o s
. e u l a v
3 C T C 2 1 2 2
CTH
CTH = CTC
CTH is reset when CTH value equals CTC value.
Scan
CTH
Execution of RES CTH instruction
Scan
4.3 Setting and Operation of High-speed Counters
3-215
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
Reset with external input
Resets the counter at the instant the external reset input relay turns ON.
The external reset is assigned to input relay 0008 (KV-10xx: 0002) for CTH0, and
input relay 0009 (KV-10xx: 0003) for CTH1.
The timing of the reset can be changed by setting relays 2400 and 2401 (for CTH0)
or 2408 and 2409 (for CTH1) as follows.
This reset operation is independent of the scan time.
* CTH is reset at the instant the external reset input relay turns ON.
Preset function
The current value of CTH can be changed to any desired value by using the external
reset function of input relays 0008 (KV-10xx: 0002) (for CTH0) or 0009 (KV-10xx:
0003) (for CTH1) specified with special utility relays 2400 and 2401 (for CTH0) or
2408 and 2409 (for CTH1). (The external reset function sets the value to "0".)
Write the desired value of the preset input into the following data memories:
Use the STA or DW instruction to write data to the data memory.
Note 1: The preset function is available only with the external reset input. The CTH
value is reset to "0" with other resetting methods.
Note 2: Use the SET, RES instruction pair to set the special utility relays.
Note 3: When 16-bit high-speed counter is used, write the preset values into
DM1924 and DM1926 only.
Scan
External
reset input
CTH
d e e p s - h g i H
r e t n u o c
. o N y a l e R s u t a t S . o N y a l e R s u t a t S n o i t a r e p O
0 H T C 0 0 4 2
F F O
1 0 4 2
F F O . n o i t a r e p o t e s e r l a n r e t x e s e l b a s i D
N O F F O
t u p n i f o e g d e g n i s i r t a r e t n u o c s t e s e R
. ) 2 0 0 0 : x x 0 1 - V K ( 8 0 0 0
F F O N O
t u p n i f o e g d e g n i l l a f t a r e t n u o c s t e s e R
. ) 2 0 0 0 : x x 0 1 - V K ( 8 0 0 0
N O N O
8 0 0 0 t u p n i n e h w r e t n u o c s t e s e R
. N O s i ) 2 0 0 0 : x x 0 1 - V K (
1 H T C 8 0 4 2
F F O
9 0 4 2
F F O . n o i t a r e p o t e s e r l a n r e t x e s e l b a s i D
N O F F O
t u p n i f o e g d e g n i s i r t a r e t n u o c s t e s e R
. ) 3 0 0 0 : x x 0 1 - V K ( 9 0 0 0
F F O N O
t u p n i f o e g d e g n i l l a f t a r e t n u o c s t e s e R
. ) 3 0 0 0 : x x 0 1 - V K ( 9 0 0 0
N O N O
9 0 0 0 t u p n i n e h w r e t n u o c s t e s e R
. N O s i ) 3 0 0 0 : x x 0 1 - V K (
. o N M D n o i t p i r c s e D
) s t i b r e d r o - h g i h ( 5 2 9 1 M D , ) s t i b r e d r o - w o l ( 4 2 9 1 M D 0 H T C r o f e u l a v t e s e r P
) s t i b r e d r o - h g i h ( 7 2 9 1 M D , ) s t i b r e d r o - w o l ( 6 2 9 1 M D 1 H T C r o f e u l a v t e s e r P
4.3 Setting and Operation of High-speed Counters
3-216
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
4.3.6 Differences with the CTH Instruction between the
Conventional and Visual KV Series
The Visual KV Series has some different high-speed counter operations from the
conventional KV Series [KV-10/16/24/80R(W)/T(W)].
Input-enable relay
With the conventional KV Series, the current value of the high-speed counter is
reset when the CTH instruction is executed while the input-enable relay is OFF.
However, the counter continues counting until the end of the scan time. As a
result, when the input-enable relay starts counting again, the counter may al-
ready be incremented by the length of the scan time.
With the Visual KV Series, the current value of the high-speed counter is reset at
the falling edge of the input-enable relay, so that the counter does not continue
counting.
High-speed counter (CTH)
The conventional KV Series includes high-speed counter CTH0, which is an 8-bit
counter. The period of the internal clock is different from that in the new KV
Series.
The Visual KV Series allows you to reset a high-speed counter with external
inputs. Its high-speed counter CTH0 is a 16-bit counter (can also be used as 24-
bit counter).
With the Visual KV Series, when using the high-speed counter, the input time
constant must be set shorter by using the HSP instruction or by turning ON
special utility relay 2813.
Phase differential input
The Visual KV Series allows phase differential input for the high-speed counter.
Response frequency
The Visual KV Series provides a response frequency of 30 kHz.
High-speed counter comparator
The high-speed counter comparator turns ON the contact when its preset value
matches the current value of the high-speed counter. Consequently, the contact
may turn ON during the scan time.
Be careful when using the contact for one comparator in several points in a
program.
Special utility relay
A portion of the special utility relay assignment is different from that of the conven-
tional KV Series.
0001
CTH0
0004
Count input Input-enable relay
4.3 Setting and Operation of High-speed Counters
3-217
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
2008
2002
0000
2214
RES
2213
SET
2114
RES
2113
SET EI
#60000

CTC0
CTH0
RES
0500
RES
CTH0
0004
CTH1
0005

HSP
0005
HSP
0006
HSP
0004
HSP
0007
INT
CTC0
2002 2009
2009
2002
ENDH
RETI
END
0500
SET
CTH0
RES
CTH1
RES
CTH1
LDA
#60000
CMP
4.3.7 Applications of High-speed Counters
Comparing encoder values
Uses two encoders to input phase differential signals to input relays 0004 and 0006,
and 0005 and 0007. Turns ON output relay 0500 if the count value of 0005 and 0007
is greater than that of 0004 and 0006 when 0004 and 0006 count "60000".
Compares current value of CTH1 with
"#60000". Turns ON 0500 when value is
greater than "#60000". Turns OFF 0500
when value is smaller.
Initial setting
SET 2113
RES 2114
SET 2213
RES 2214
Setting for CTH0
Setting for CTH1
Sets input time constant of inputs 0004,
0005, 0006, and 0007 to 10 s.
Phase differential input to inputs 0004 and
0006
Specifies preset value of CTC0 to "#60000".
Phase differential input to inputs 0005 and
0007
Setting multi-level high-speed counters
Sets the preset value of the high-speed counter comparator for the high-speed
counter for input relay 0005 as follows:
#01000 DM0000
#02000 DM0001
#03000 DM0002
When the current counter value reaches one of the preset values, the respective
output turns ON as follows:
DM0000 0500 turns ON.
DM0001 0501 turns ON.
DM0002 0502 turns ON.
DM0000
STA
#01000
LDA
#02000
LDA
DM0001
STA
DM0000
CMP
CTH1
LDA
DM0001
CMP
DM0002
CMP
#03000
LDA
DM0002
STA
2008
0001
2009
2009
2009
2002
CTH1
0005
2002 HSP
0005
0500
0501
0502
4.3 Setting and Operation of High-speed Counters
3-218
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
2203
SET
CTH1
RES
CTC2
RES
CTC2 T001
2008
2002
#60000
CTC2
CTH1
0005
2002 HSP
0005
0502 #00030
T001
Clearing the current value of the high-speed counter
Counts pulses at input relay 0005. When the current value reaches the preset value
"60000", clears the current value of high-speed counter CTH1 and turns ON output
relay 0502 for 3 seconds.
Cording
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0015 CTH1 0005
0001 LDA #01000 0016 LD 2002
0002 CON 0017 LDA CTH1
0003 STA DM0000 0018 MPS
0004 CON 0019 CMP DM0000
0005 LDA #02000 0020 ANB 2009
0006 CON 0021 OUT 0500
0007 STA DM0001 0022 MRD
0008 CON 0023 CMP DM001
0009 LDA #03000 0024 ANB 2009
0010 CON 0025 OUT 0501
0011 STA DM0002 0026 MPP
0012 LD 2002 0027 CMP DM0002
0013 HSP 0005 0028 ANB 2009
0014 LDB 0001 0029 OUT 0502
Line No. Instruction Operand
0000 LD 2008
0001 SET 2203
0002 CON
0003 RES CTH
0004 LD 2002
0005 HSP 0005
0006 LD 2002
0007 CTH1 0005
0008 CTC2 #60000
0009 LD CTC2
0010 OUT 0502
0011 CON
0012 TMR 001 #00030
0013 CON
0015 AND T001
0016 RES CTC2
Cording
4.3 Setting and Operation of High-speed Counters
3-219
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
Phase differential input
Inputs phase differential signals from input relays 0004 and 0006 and counts
pulses at CTH0.
The count value is written to DM0000.
When the current value of CTH0 reaches "60000", clears the value, turns ON
output 0500, and stops counting at CTH0.
Input relay 0008 is used as an external reset.
Cording
G Initial setting
Special utility relays
Turn ON 2013 to reset the current value of CTH0 when CTC0 turns ON.
Turn ON 2113 and turn OFF 2114 to set the high-speed counter to double (x2)
multiplication mode.
Turn ON 2400 and turn OFF 2401 to enable the external reset.
The counter is reset at the rising edge of input 0008.
Note : External reset input 0008 is set with hardware. Programming is not necessary
except for setting the external reset enable relays (2400 to ON and 2401 to OFF).
2103
SET EI
2113
SET
2114
RES
2401
RES
CTH0
RES
0500
2008
0500
2002
CTH0
0004
2002
END
INT
CTC0
RETI
ENDH
#60000
CTC0
2002 HSP
0004
HSP
0006
HSP
0008
CTH0
LDA
DM0000
STA
SET
2400
SET
Initial setting
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0016 HSP 0006
0001 EI 0017 HSP 0008
0002 CON 0018 LDB 0500
0003 SET 2103 0019 CTH 0 0004
0004 CON 0020 CTC 0 #60000
0005 SET 2113 0021 LD 2002
0006 CON 0022 LDA CTH0
0007 RES 2114 0023 CON
0008 CON 0024 STA DM0000
0009 SET 2400 0025 END
0010 CON 0026 INT CTC0
0011 RES 2401 0027 LD 2002
0012 CON 0028 SET 0500
0013 RES CTH0 0029 RETI
0014 LD 2002 0030 ENDH
0015 HSP 0004

4.3 Setting and Operation of High-speed Counters


3-220
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
Fetching counts from encoder
Uses the double (x2) multiplication mode to fetch phase differential input from the
encoder.
The fetched data is output as BCD data. Phase differential input: 0004, 0006 BCD
output: 0600 to 0615 (4 digits)
Cording
G Initial setting
Special utility relays
Turn ON 2013 to reset the current value of CTH0 when CTC0 turns ON.
Turn ON 2113 and turn OFF 2114 to set the high-speed counter to double (x2)
multiplication mode.
Turn ON 2400 to enable the external reset.
The counter is reset at the rising edge of input 0008.
Note : The external reset input 0008 is set with hardware. Programming is not
necessary except for setting the external reset enable relay (2400 to ON).
2103
SET
2113
SET
2114
RES
CTH0
RES
2400
SET
2008
CTH0
LDA
TM00
STA
#00002
DIV LDA TBCD
0600
STA
2002 #00000
0000 CTH0
0004
2002 HSP
0004
HSP
0006
HSP
0008
END
ENDH
Initial setting
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0015 CTH 0 0004
0001 SET 2103 0016 LD 2002
0002 CON 0017 LDA #0000
0003 SET 2113 0018 CON
0004 CON 0019 STA TM00
0005 RES 2114 0020 CON
0006 CON 0021 LDA CTH0
0007 RES CTH0 0022 CON
0008 CON 0023 DIV #00002
0009 SET 2400 0024 CON
0010 LD 2002 0025 TBCD
0011 HSP 0004 0026 CON
0012 HSP 0006 0027 STA 0600
0013 HSP 0008 0028 END
0014 LD 0000 0029 ENDH

4.4 Expanded Functions of High-speed Counters


3-221
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
4.4 Extended Func tions of High-speed
Counters
This section describes the 24-bit high-speed counter and ring counter functions.
4.4.1 24-bit High-speed Counter
Normally, the high-speed counter operates with 16 bits. You can operate the counter
with 24 bits (0 to 16777215) using special utility relays.
Set the 24-bit operation with the MEMSW instruction.
"MEMSW instruction" (p. 3-92)
MEMSW instruction: SW3
MEMSW instruction: SW4
The following data memories are used for 24-bit operation.
Read areas
Write areas
. o N h c t i w s f o n o i t c n u F N O F F O
3
r e t n u o c t i b - 6 1 / t i b - 4 2 g n i t t e S
0 H T C r o f r o t a r a p m o c
t i b - 4 2 t i b - 6 1
. o N M D n o i t p i r c s e D . o N M D n o i t p i r c s e D
0 0 9 1 M D
t n e r r u c f o s t i b r e d r o - w o L
e u l a v 0 H T C
6 0 9 1 M D
t e s e r p f o s t i b r e d r o - w o L
e u l a v 1 C T C
1 0 9 1 M D
t n e r r u c f o s t i b r e d r o - h g i H
e u l a v 0 H T C
7 0 9 1 M D
t e s e r p f o s t i b r e d r o - h g i H
e u l a v 1 C T C
2 0 9 1 M D
t n e r r u c f o s t i b r e d r o - w o L
e u l a v 1 H T C
8 0 9 1 M D
t e s e r p f o s t i b r e d r o - w o L
e u l a v 2 C T C
3 0 9 1 M D
t n e r r u c f o s t i b r e d r o - h g i H
e u l a v 1 H T C
9 0 9 1 M D
t e s e r p f o s t i b r e d r o - h g i H
e u l a v 2 C T C
4 0 9 1 M D
0 C T C t e s e r p f o s t i b r e d r o - w o L
e u l a v
0 1 9 1 M D
t e s e r p f o s t i b r e d r o - w o L
e u l a v 3 C T C
5 0 9 1 M D
t e s e r p f o s t i b r e d r o - h g i H
e u l a v 0 C T C
1 1 9 1 M D
t e s e r p f o s t i b r e d r o - h g i H
e u l a v 3 C T C
. o N h c t i w s f o n o i t c n u F N O F F O
0
r e t n u o c t i b - 6 1 / t i b - 4 2 g n i t t e S
1 H T C r o f r o t a r a p m o c
t i b - 4 2 t i b - 6 1
. o N M D n o i t p i r c s e D . o N M D n o i t p i r c s e D
2 1 9 1 M D
t n e r r u c f o s t i b r e d r o - w o L
e u l a v 0 H T C
8 1 9 1 M D
t e s e r p f o s t i b r e d r o - w o L
e u l a v 1 C T C
3 1 9 1 M D
t n e r r u c f o s t i b r e d r o - h g i H
e u l a v 0 H T C
9 1 9 1 M D
t e s e r p f o s t i b r e d r o - h g i H
e u l a v 1 C T C
4 1 9 1 M D
t n e r r u c f o s t i b r e d r o - w o L
e u l a v 1 H T C
0 2 9 1 M D
t e s e r p f o s t i b r e d r o - w o L
e u l a v 2 C T C
5 1 9 1 M D
t n e r r u c f o s t i b r e d r o - h g i H
e u l a v 1 H T C
1 2 9 1 M D
t e s e r p f o s t i b r e d r o - h g i H
e u l a v 2 C T C
6 1 9 1 M D
t e s e r p f o s t i b r e d r o - w o L
e u l a v 0 C T C
2 2 9 1 M D
t e s e r p f o s t i b r e d r o - w o L
e u l a v 3 C T C
7 1 9 1 M D
t e s e r p f o s t i b r e d r o - h g i H
e u l a v 0 C T C
3 2 9 1 M D
t e s e r p f o s t i b r e d r o - h g i H
e u l a v 3 C T C
Visual KV Series Only
4.4 Expanded Functions of High-speed Counters
3-222
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
The high-speed counter and high-speed counter comparator update the contents of
the read area of data memory each scan time.
At the start of an interrupt routine, the current value is updated. The contents of the
write area of data memory is updated with the data write operation.
"Setting the 24-bit high-speed counter comparator" (below) and "4.4.2 Changing the Current Value of
a 24-bit High-speed Counter" (p. 3-223)
Note 1: Use the SET, RES instruction pair to set the special utility relays.
Note 2: The 16-bit/24-bit high-speed counter setting with the MEMSW instruction is
effective when the Visual KV is in RUN mode.
You must change the program to change between 16-bit and 24-bit settings.
Setting the 24-bit high-speed counter comparator
To specify the preset value for the 24-bit high-speed counter comparator, write the
value into the write area DM1916 to DM1923 and execute the STA and CTC instruc-
tions to specify or change the preset value.
When the setting or change is properly performed, the CTC read areas DM1904
through DM1911 are updated with the new values after one scan.
I Changing the preset value
Change the preset value for the 24-bit high-speed counter comparator using the
Access Window, programming support software, handheld programmer, or operator
panel with the following procedure.
1. Write the desired preset value into data memory.
Write the desired preset value to the CTC preset value write areas DM1916
through DM1923.
2. Change the preset value of CTC. (See the notes on the next page.)
With the Access Window
Call CTC in device mode and change the value.
With the "KV IncrediWare (DOS)" programming support software
Change the preset value of CTC with the "Edit Device CTC" [F2] option.
With the "LADDER BUILDER for KV" programming support software
Change the preset value of CTC in the dialog box.
With the KV-P3E(01) handheld programmer
Change the preset value of CTC with the "TIMER COUNTER SETTING
CHANGE" function.
For more about detailed operation, refer to "Chapter 3 Access Window" (p. 1-79), "Chapter 6
Handheld Programmer" (p. 1-195) and "Chapter 2 Instructions" (p. 3-33).
Note 1: When the preset value of a 24-bit CTC is changed with an instruction such
as STA CTC0, the value entered as an operand is ignored but the value written in
DM1916 through DM1923 is referred to and used as the preset value.
Note 2: Be sure to write the desired value to the write area of the high-speed
counter comparator preset value (DM1916 through DM1923) before executing the
change operation (e.g., STA instruction).
4.4 Expanded Functions of High-speed Counters
3-223
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
4.4.2 Changing the Current Value of a 24-bit High-speed
Counter
Change the current value of the 24-bit high-speed counter with the Access Window,
programming support software, handheld programmer, or operator panel with the
following procedure.
1. Write the desired current value into data memory.
Write the desired current value to the CTH current value write areas DM1912
through DM1915.
2. Change the current value of CTH. (See notes below.)
With the Access Window
Call CTH in device mode and change the value.
With the "KV IncrediWare (DOS)" programming support software
Change the preset value of CTH with the "Edit Device CTH" [F2] option.
With the "LADDER BUILDER for KV" programming support software
Change the preset value of CTH in the dialog box.
With the KV-P3E(01) handheld programmer
Change the preset value of CTH with the "TIMER COUNTER CURRENT VALUE
CHANGE" function.
For more about detailed operation, refer to "Chapter 3 Access Window" (p.1-79), "Chapter 6
Handheld Programmer" (p.1-195) and "Chapter 2 Instructions" (p.3-33).
Note 1: The current value of the high-speed counter cannot be changed in the
ladder program.
Note 2: DM1900 to DM1923, the data memories for 24-bit high-speed counters, can
be used only when a 24-bit high-speed counter is specified with the MEMSW in-
struction.
4.4 Expanded Functions of High-speed Counters
3-224
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
4.4.3 Application Example of 24-bit High-speed Counter
(single-phase input)
The following is a ladder program using a 24-bit high-speed counter and high-speed
counter comparator with a preset value of "1000000".
1) Sets CTH0 as the 24-bit high-speed counter with the MEWSW instruction. (Turn
on 3 of SW3.)
2) When power is turned on, writes the preset value "1000000" of the high-speed
counter comparator (CTC0) and sets the value with the STA CTC0 instruction.
3) Sets the input time constant of input relay 0004 to 10 s.
4) Counts pulses at input relay 0004 with high-speed counter CTH0.
5) Defines a dummy high-speed counter comparator.
6) Reads the current value of CTH0 into data memory DM0000 (low-order bits) and
DM0001 (high-order bits) each scan time.
2008 CTH0
RES
0008
CTC0
STA
DM1916
STA
#16960
LDA
DM1917
STA
#00015
LDA
2002 DM0000
STA
DM1900
LDA
DM0001
STA
DM1901
LDA
2002
0002
0001
HSP
0004
2002
0003
0004
CTH0
0004
0006
END
0007
0005
ENDH
#65535
CTC0
2)
1)
3)
4)
5)
6)
MEMSW
$0800
Low-order 16 bits of
current value of high-
speed counter
High-order 16 bits of
high-speed counter
comparator
Low-order 16 bits of
high-speed counter
comparator
Writes preset value of
high-speed counter
comparator
High-order 16 bits of
current value of high-
speed counter
4.4 Expanded Functions of High-speed Counters
3-225
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
4.4.4 Ring Counter Function
Normally, the counter reads "#65535 ($FFFF)" by counting down from "0" by one.
The ring counter function is an additional function of the automatic clear function. It
reads "preset value - 1" when it counts down from "0" by one.
I Operation of the ring counter function
I Setting procedure
When setting the ring counter, use CTC1 for CTH0 and CTC3 for CTH1.
Set the upper limit (preset value) to CTC1 or CTC3 and turn ON special utility
relay 2406 (for CTH0) or 2414 (for CTH1). The ring counter is set to read "CTC1/
CTC3 preset value - 1" when it counts down from "0" by one.
To use the ring counter for both counting up/down operations, turn ON special
utility relay 2112 (for CTH0) or 2212 (for CTH1).
Note 1: Use the SET-RES instruction pair to set the special utility relays.
Note 2: The flag or the count-up interrupt for each CTC is effective in counting up
operations, but is disabled in counting down operations.
Example: When CTC = 100
0 65535
0 CTC1 -1
( CTC3 -1)
65535
Not used
Normal counter
Ring counter
CTH
0 1 2 97 98 99 0 1 2
CTC
97 98 99 2 1 0
Count
up
Count
down
Turns ON.
Does not turn ON.
r e t n u o c d e e p s - h g i H r o t a r a p m o c r e t n u o c d e e p s - h g i H y a l e r y t i l i t u l a i c e p S
d e s u s i 0 H T C n e h W . 1 C T C o t " 1 + e u l a v t i m i l r e p p u " t e S . 6 0 4 2 N O n r u T
d e s u s i 1 H T C n e h W . 3 C T C o t " 1 + e u l a v t i m i l r e p p u " t e S . 4 1 4 2 N O n r u T
4.4 Expanded Functions of High-speed Counters
3-226
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
0 9999
2008
0003
0005
CTH0
RES
0007
EI
2406
SET
2112
SET
2114
RES
2113
SET
2002
0001
HSP
0004
0002
END
0006
INT
CTC1
0010
0011
RETI
0009
ENDH
#00010
T000
1)
0500
RES 5)
2)
HSP
0006
2002
CTH0
0004
0004
0500 T000
3)
0500
SET 6)
2002
0008
#10000
CTC1 4)
Sets high-speed counter in
double (x2) multiplication mode.
Sets ring
counter.
Automatic reset
of high-speed
counter
4.4.5 Applications of Ring Counters
When using a 16-bit high-speed counter
The following is a ladder program that uses the ring counter of a 16-bit high-speed
counter with the preset value of "10000".
1) When the power is turned on, an EI instruction enables interrupts. Sets high-
speed counter CTH0 in double (x2) multiplication mode, CTH0 as a ring counter,
and the high-speed counter automatic reset function at counting up. Resets the
high-speed counter.
2) Sets the input time constant for input relays 0004 and 0006 to 10 s.
3) Counts 2-phase pulses of input relays 0004 and 0006 at CTH0.
4) Sets the preset value of high-speed counter comparator CTC1 to "10000".
5) Output relay 0500 turns ON for 1 second and then turns OFF.
6) When CTC1 turns ON, an interrupt is executed. Output relay 0500 turns ON.
4.4 Expanded Functions of High-speed Counters
3-227
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
0 99999
0013
2008
0004
0006
CTH0
RES
0008
EI
2406
SET
2114
RES
2113
SET
2002
0002
#00001
LDA
DM1919
STA
#34464
LDA
DM1918
STA
CTC1
STA
HSP
0004
0003
0012
END
0007
INT
CTC1
0011
RETI
0010
ENDH
#00010
T000
2)
1)
3)
0500
RES
6)
HSP
0006
2002
CTH0
0004
0005
0500 T000
4)
0500
SET
2002
0009
7)
#65535
CTC1
5)
8)
2112
SET
0001
MEMSW
$0800
Writes preset
value of high-
speed counter
comparator.
Sets high-speed
counter in double (x2)
multiplication mode.
Sets ring
counter.
Automatic reset of
high-speed counter
High-order 16
bits of high-
speed counter
comparator
Low-order 16
bits of high-
speed counter
comparator
When using a 24-bit high-speed counter
The following is a ladder program that uses the ring counter of a 24-bit high-speed
counter with the preset value of "100000".
1) Sets CTH0 as a 24-bit high-speed counter using the MEMSW instruction (Turn
on 3 of SW3.).
2) When the power is turned on, an EI instruction enables interrupts. Sets high-
speed counter CTH0 in double (x2) multiplication mode, CTH0 as a ring counter,
and high-speed counter automatic reset function at counting up. Resets the high-
speed counter.
3) Writes the preset value "100000" of high-speed counter comparator (CTC1) for
the 24-bit high-speed counter (CTH0). Sets the preset value with the STA CTC0
instruction.
4) Sets the input time constant for input relays 0004 and 0006 to 10 s.
5) Counts 2-phase pulses of input relays 0004 and 0006 at CTH0.
6) Describes a dummy high-speed counter comparator.
7) Output relay 0500 turns ON for 1 second and then turns OFF.
8) When CTC1 turns ON, an interrupt is executed. Output relay 0500 turns ON.
4.5 Special Functions Using High-speed Counters
3-228
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
OFF
ON
4.5 Spec ial Func tions Using High-speed
Counters
This section describes the specified frequency pulse output function, frequency
counter function, and cam switch function.
4.5.1 Specified Frequency Pulse Output Function
With high-speed counter CTH1, output pulses from output relay 0501 with the
frequency (Hz) specified in data memory DM1936. To activate this function, write the
desired value into DM1936 and turn ON special utility relay 2306.
The internal clock of the high-speed counter is automatically set to 1 s. Pulses with
duty ratio of 1:1 are output at the preset frequency obtained with the calculation
"1,000,000/2/Output frequency".
The KV performs the following operations after each scan time during the specified
frequency pulse output function.
Stops pulse output when special utility relay 2306 is turned OFF.
Sets the preset value so that pulses are output at the frequency specified with
the DM. (Pulse duty ratio: fixed to 50%)
Starts pulse output.
Pulse duty
Pulse duty is the ratio of the pulse widths between ON time and OFF time. A pulse
duty of 50% means that the pulse widths between ON time and OFF time are the
same, as follows.
The ratio between ON and OFF time is 1:1.
I Device used for specified frequency pulse output
Special utility relays
Data memory
. o N y a l e R n o i t p i r c s e D
6 0 3 2
n o i t c n u F o N : F F O , s e Y : N O . t u p t u o e s l u p y c n e u q e r f d e i f i c e p s e s U
. N O s n r u t 7 0 3 2 y a l e r r o r r e n e h w F F O d e c r o f s i
7 0 3 2
. n o i t c n u f t u p t u o e s l u p y c n e u q e r f d e i f i c e p s r o f g a l f r o r r E
. 0 0 0 0 5 o t 6 1 n a h t r e h t o s i 6 3 9 1 M D f o s t n e t n o c n e h w N O s n r u T
. o N M D n o i t p i r c s e D
6 3 9 1 M D . n e t t i r w s i t u p t u o e s l u p y c n e u q e r f d e i f i c e p s r o f e u l a v t e s e r P
Visual KV Series Only
4.5 Special Functions Using High-speed Counters
3-229
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
I Setting method
Set the desired output frequency (Hz) into DM1936. The available range is 16 Hz
to 50 kHz (16 to 50000).
Pulses are output when special utility relay 2306 is ON. The output is stopped
when the relay is turned OFF.
If an unacceptable frequency is specified, special utility relay 2307 (error relay)
turns ON. Special utility relay 2306 is turned OFF and pulse output is stopped.
Note 1: The available minimum frequency specified in DM1936 is 16 Hz.
Note 2: The output is stopped when a value of 15 or less is specified in DM1936.
Note 3: Starts and stops of pulse output or frequency changes are executed after
each scan.
Note 4: It takes a maximum of 200 s from when the output command is issued until
pulses are output.
Note 5: CTH1 and special utility relays 2200 through 2215 cannot be used when the
specified frequency pulse output function is used.
4.5.2 Applications of the Specified Frequency Pulse Output
I Program using a digital trimmer
The following ladder program illustrates how to use a digital trimmer to output pulses
at a desired frequency (16 Hz to 10 kHz).
Pulse output is stopped when the value of the digital trimmer decreases to 15 or
less.
1) Sets the upper limit of the digital trimmer to "10000" and turns ON special utility
relay 2306 to start the specified frequency pulse output.
2) Sets the input value of the digital trimmer as the output frequency value.
3) Output relay 0500 turns ON when a setting error occurs.
2008
0003
0005
#10000
LDA
DM1938
STA
0
TMIN
DM1936
STA
2002
0001
2307
0002
END
ENDH
0004
0500
2306
SET
1)
2)
3)
4.5 Special Functions Using High-speed Counters
3-230
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
I Program for speed control
The following ladder program illustrates speed control using the specified frequency
pulse output function.
Control is started when input relay 0000 turns ON. The operation is slowed down
and then stopped when input relay 0001 turns ON.
By specifying the speed (Hz) in data memory DM0000, the program controls the
speed with a start-up speed of 16 Hz and an acceleration speed of 100 Hz/100 ms.
1) Sets "16" as the preset speed at the rising edge of input relay 0000. Turns ON
special utility relay 2306 to start the specified frequency pulse output. Then, turns
ON the operating flag.
2) Turns ON slow-down-stop flag 1101 at the rising edge of input 0001.
3) When the slow-down-stop flag turns ON, sets the preset speed to "16". When the
output frequency reaches "16", turns OFF the operation start flag, operating flag,
and slow-down-stop flag.
4) Activates a 100-ms flicker circuit while the operating flag turns ON.
5) Compares the current speed and preset speed every 100 ms. Executes subrou-
tine 0 when the preset speed is faster, and executes subroutine 1 when the
preset speed is slower.
6) Output relay 0500 turns ON when a setting error occurs.
7) Acceleration process. When the current speed is slower than the preset speed by
less than "100", the speed is accelerated by the difference. When the difference
is "100" or more, the speed is accelerated by "100".
8) Deceleration process. When the current speed is faster than the preset speed by
less than "100", the speed is decelerated by the difference. When the difference
is "100" or more, the speed is decelerated by "100".
0003
0005
TM02
ADD
#00016
LDA
DM1936
LDA
DM0000
CMP
DM0000
STA
DM1936
CMP
DM1936
STA
TM02
STA
DM1936
LDA
0001
2010
2307
0002
0006
END
SBN
00
SBN
01
RET
0004
0500
1000
DIFU
0000 1000 1100
SET
1001
DIFU
#00100
T
000 S

0001 1001 1101
SET
1101
DM0000
LDA
DM1936
SUB
#00100
CMP
2011
#00100
ADD
DM1936
STA
DM1936
LDA
2011
2002
TM02
SUB
DM1936
STA
TM02
STA
DM1936
LDA
RET
ENDH
DM1936
LDA
DM0000
SUB
#00100
CMP
2011
#00100
SUB
DM1936
STA
DM1936
LDA
2011
2002
1100
00
CALL
T000
0007
0008
0011
0013
0009
0010
0014
0012
0015
0016
0017
2009
01
CALL
2011
T000
1101
RES
1100
RES
2306
RES
2306
SET
1)
2)
3)
4)
5)
6)
7)
8)
#00016
LDA
DM1936
STA
4.5 Special Functions Using High-speed Counters
3-231
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
4.5.3 Frequency Counter Function
High-speed counter CTH0 is used. Write the interval (ms) of frequency measure-
ment into data memory DM1404 and turn ON special utility relay 2305. The mea-
surement result (Hz) is written into DM1405.
Input relay 0004 is for pulse input (single-phase input). Input relay 0006 (phase B
input) is ignored.
I Devices used with the frequency counter
Special utility relays
Data memory
I Operation flow
1. Set the high-speed counter with external input. Use the END instruction and
measure how much time has elapsed since the last measurement in units of 10
s. After each scan, pulses are counted within the time specified with the data
memory. The frequency is calculated from the count value and written into data
memory.
2. When the time specified with DM1404 elapses from the last measurement, the
current value of CTH0 is fetched and divided by the elapsed time (Unit: 10 s).
The frequency is obtained with the following calculation.
Frequency (Hz) = (100,000 x Pulse count)/Elapsed time (Unit: 10 s)
3. The calculation result (Hz) is written into DM1405.
I Setting method
1. Specify the counting period for the frequency counter (the interval of frequency
measurement [Unit: ms]) in data memory DM1404.
2. The preset value must be greater than the scan time. When a value smaller than
the scan time is specified, the frequency is measured each scan time.
Note 1: To use the frequency counter function, set the input time constant to 10 s
with the HSP instruction or the special utility relay. (A maximum frequency of 30 kHz
can be measured.).
Note 2: The counting start/stop or measurement result is updated after each scan.
Therefore, the counting period includes some scan time errors for the time specified
with DM1404. Set the counting period so that overflow does not occur at CTH.
Note 3: Specify the counting period so that the number of pulse inputs in one period
is between 2 and 65535, inclusive.
Note 4: Measurement may fail when the pulse period is 5000 ms or more.
Note 5: The frequency counter cannot be used when CTH0 is used in the ladder
program.
Note 6: Special utility relays concerning CTH0, CTC0/1, and the cam switch cannot
be used.
Note 7: CTH0 and the cam switch function cannot be used when the frequency
counter is used.
. o N y a l e R n o i t p i r c s e D
5 0 3 2 o N : F F O , s e Y : N O . r e t n u o c y c n e u q e r f e s U
. o N M D n o i t p i r c s e D
4 0 4 1 M D ] 0 0 0 1 o t 1 [ r e t n u o c y c n e u q e r f f o ) s m ( e l c y c t n e m e r u s a e M
5 0 4 1 M D r e t n u o c y c n e u q e r f f o ) z H ( t n u o c y c n e u q e r f f o t l u s e R
4.5 Special Functions Using High-speed Counters
3-232
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
4.5.4 Applications of Frequency Counters
Program for basic operation of the frequency counter
Stores the frequency of pulses at input relay 0004 to DM0000 every second (1000
ms). (Unit: Hz)
1) Sets the counting period to "1000 ms (1 second)" and turns ON special utility
relay 2305 to start the frequency counter function.
2) Sets the input time constant for input relay 0004 to 10 s.
3) Stores the measured frequency (Hz) into data memory DM0000.
Program for synchronous control
The following ladder program illustrates synchronous control using the frequency
counter and pulse output functions.
Measures the frequency of pulses at input relay 0004 every 100 ms and outputs
pulses of the same frequency from output relay 0501.
1) Sets the counting period to "100 ms" and turns ON special utility relays 2305 and
2306 to start the frequency counter and the specified frequency pulse output
functions.
2) Sets the input time constant for input relay 0004 to 10 s.
3) Uses the measured frequency (Hz) as the preset value for the output frequency
(Hz).
4) Turns on output relay 0500 when an error occurs in the setting of the specified
frequency pulse output.
0001
2008
0003
2002
2002
0004
0002
#01000
LDA
DM1404
STA
END
0005
ENDH
2305
SET
DM1405
LDA
DM0000
STA
HSP
0004
1)
2)
3)
0001
2008
0003
2002
2002
0004
0002
#00100
LDA
DM1404
STA
2307
END
0005
0006
ENDH
2305
SET
2306
SET
DM1405
LDA
DM1936
STA
HSP
0004
0500
1)
2)
3)
4)
4.5 Special Functions Using High-speed Counters
3-233
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
4.5.5 Cam Switch Function
The cam switch function has two modes: cam switch mode, which simulates cam
operation; and multi-step comparator mode, which compares the value written in
DM1401 with multiple values.
I Devices used with the cam switch function
Special utility relays
The preset value in the data memory is registered at the rising edge of the start
relay. When the preset value is changed, turn OFF special utility relay 2314 once
and then turn it ON again to register the new value.
I Timing diagram of cam switch function
: Operation with the ladder program.
: Operation automatically executed by the Visual KV.
Description: When start relay 2314 is turned ON, the Visual KV automatically turns OFF
start relay 2314 and turns ON in-operation relay 2715 to activate the cam
switch function.
When in-operation relay 2715 is turned OFF, the cam switch function is
stopped.
Cam switch mode
Simulates a cam operation.
Connect an encoder to CTH0 to count pulses in double multiplication mode.
CTH0 uses input relays 0004 (phase A), 0006 (phase B) (KV-10xx: 0000), and 0008
(phase Z) (KV-10xx: 0002).
Relays are turned ON/OFF when the pulse count reaches the specified angle.
The cam switch function controls a maximum of 32 successive relays. Specify relay
Nos. with the data memory (DM1400). Each relay is turned ON/OFF once every
rotation. To turn relays ON/OFF several times in one rotation, use the OR instruction
in the ladder program.
I Devices used in cam switch mode
Data memory
. o N y a l e R n o i t p i r c s e D
4 1 3 2 y a l e r t r a t S
5 1 3 2 y a l e r r o r r E
5 1 7 2 y a l e r n o i t a r e p o - n I
. o N M D n o i t p i r c s e D
0 0 4 1 M D
0 0 9 1 n a h t r e h t o s e u l a V ( s y a l e r t u p t u o f o s s e r d d a l a i t i n i s e r o t S
. ) . 0 0 e r a s t i g i d o w t t s a l e s o h w 0 0 9 2 h g u o r h t
2 0 4 1 M D
o t d e t c e n n o c e c i v e d e h t f o n o i t a t o r e n o r o f s r e b m u n e s l u p e h t e c i w T
) 4 3 5 5 6 o t 1 ( 0 H T C
7 0 4 1 M D / 6 0 4 1 M D
) . g e d 1 . 0 : t i n U ( F F O / N O s n r u t y a l e r t u p t u o t s r i f h c i h w t a e l g n A
) 4 3 5 5 6 o t 0 (
9 0 4 1 M D / 8 0 4 1 M D

9 6 4 1 M D / 8 6 4 1 M D
) . g e d 1 . 0 : t i n U ( F F O / N O s n r u t y a l e r d n o c e s h c i h w t a e l g n A
) 4 3 5 5 6 o t 0 (

) . g e d 1 . 0 : t i n U ( F F O / N O s n r u t y a l e r d n 2 3 h c i h w t a e l g n A
) 4 3 5 5 6 o t 0 (
0 7 4 1 M D e s u m e t s y s r o f d e v r e s e R
2715
2314
Executed
Start relay
In-operation
relay
Cam switch
function
Stopped Stopped
L
L
L
L
4.5 Special Functions Using High-speed Counters
3-234
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
Multi-step comparator mode
Even a single phase incoder can be used by changing a part of the cam switch
function.
To activate the multi-step comparator mode, write the value to be compared into
data memory DM1401 to replace the CTH0 value. This value determines the resolu-
tion. If 360 is written in DM1401, and 60 is written in DM1406, the 1st relay is turned
ON at 60/360 i.e. 60.
I Devices used in multi-step comparator mode
Data memory
Setting method
I In cam switch mode
1. Write the initial number of output relays to be used into DM1400.
Be sure to write the initial relay number of each channel.
Example 0500, 0600: Acceptable, 0501, 0610: Unacceptable
2. Write the number of pulses in two pulse-periods of the encoder connected to
CTH0 into DM1402. (Twice the number of pulses for one rotation.)
3. Specify the angle at which the first relay turns ON (Unit: 0.1 deg.) into
DM1406. Use units of 0.1 deg. to specify the preset angle for the cam switch
mode. (Write the value of [Desired angle x 10] into data memory.)
4. Specify the angle at which the first relay turns OFF (Unit: 0.1 deg.) into
DM1407.
5. Specify the angle at which the second relay turns ON (Unit: 0.1 deg.) into
DM1408.
6. Specify the angle at which the second relay turns OFF (Unit: 0.1 deg.) into
DM1409.
7. Repeat steps 3 through 6 as many times as the number of relays to be used (32
relays max.).
8. Turn ON special utility relay 2314.
This relay automatically turns OFF when the cam switch function is activated.
9. Turn OFF special utility relay 2715 to stop the operation.
I In multi-step comparator mode
1. Write the initial number of output relays to be used into DM1400.
Be sure to write the initial relay number of each channel.
Example 0500, 0600: Acceptable, 0501, 0610: Unacceptable
2. Write the value to be compared into DM1401, and write "65535" into DM1402.
3. Specify the preset value at which the first relay turns ON into DM1406.
4. Specify the preset value at which the first relay turns OFF into DM1407.
. o N M D n o i t p i r c s e D
0 0 4 1 M D
0 0 9 1 n a h t r e h t o s e u l a V ( s y a l e r t u p t u o f o s s e r d d a l a i t i n i s e r o t S
. ) . 0 0 e r a s t i g i d o w t t s a l e s o h w 0 0 9 2 h g u o r h t
1 0 4 1 M D ) 4 3 5 5 6 o t 0 ( d e r a p m o c e b o t e u l a V
2 0 4 1 M D . e d o m r o t a r a p m o c e g a t s - i t l u m e s u o t " 5 3 5 5 6 " r e t n E
7 0 4 1 M D / 6 0 4 1 M D ) 4 3 5 5 6 o t 0 ( F F O / N O s n r u t y a l e r t u p t u o t s r i f h c i h w t a e u l a v t e s e r P
9 0 4 1 M D / 8 0 4 1 M D

9 6 4 1 M D / 8 6 4 1 M D
) 4 3 5 5 6 o t 0 ( F F O / N O s n r u t y a l e r d n o c e s h c i h w t a e u l a v t e s e r P

) 4 3 5 5 6 o t 0 ( F F O / N O s n r u t y a l e r d n 2 3 h c i h w t a e u l a v t e s e r P
0 7 4 1 M D e s u m e t s y s r o f d e v r e s e R
4.5 Special Functions Using High-speed Counters
3-235
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
5. Specify the preset value at which the second relay turns ON into DM1408.
6. Specify the preset value at which the second relay turns OFF into DM1409.
7. Repeat steps 3 through 6 as many times as the number of relays to be used (32
relays max.).
8. Turn ON special utility relay 2314.
This relay automatically turns OFF when the cam switch function is activated.
9. Turn OFF special utility relay 2715 to stop the operation.
Note 1: When the cam switch function is used, 32 relays from the relay No. speci-
fied with DM1400 is occupied for the function regardless of whether they are used or
not. As a result, these relays cannot be used for any other purpose.
Note 2: To use the cam switch mode, set the input time constant to 10 s with the
HSP instruction or the special utility relay. (A maximum frequency of 30 kHz can be
measured.)
Note 3: When any improper value is set in data memory, the setting error occurs
and special utility relay 2315 turns ON.
Note 4: CTH0 and the frequency counter function cannot be used while the cam
switch function is being used.
Note 5: The cam switch function cannot be used when CTH0 is used in the ladder
program.
Note 6: Special utility relays concerning CHT0, CTC0/1, and the frequency counter
function cannot be used.
Note 7: The scan time is extended by a maximum of 16 ms when the cam switch
function is activated.
Note 8: The in-operation relay of the cam switch function (2715) remains ON even
when the mode is changed or the power is turned OFF.
Note 9: Use the END instruction to change relays or turn them ON/OFF.
Note 10: When the encoder is ON in cam switch mode while the KV is OFF, the
count may be shifted for the time between the start-up and phase Z input.
Note 11: The encoder count is stopped in cam switch mode while the Visual KV is
OFF. (While the Visual KV is ON, the count is continued even in PROGRAM mode.)
Note 12: When a value of 360 or more is specified as the preset angle for the cam
switch function, the value is converted into one within the range of 0 to 360 before
the control.
Example: When 500 is specified, it is converted to 140.
4.5 Special Functions Using High-speed Counters
3-236
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
4.5.6 Application of the Cam Switch (Cam Switch Mode)
The following ladder program illustrates the basic setting of the cam switch function.
Connect the encoder with a resolution of 360 pulses.
Use output relays 0600 through 0603.
Output relay 0600: Turns ON within the range 30 to 90
Output relay 0601: Turns ON within the range 45 to 80
Output relay 0602: Turns ON within the range 70 to 150
Output relay 0603: Turns ON within the range 120 to 270
1) Sets "0600", which is the initial number of relays used for the cam switch function, to
DM1400 and sets twice the number of pulses for one encoder rotation (360 x 2 = 720) to
DM1402.
2) Specifies the preset angles at which output relays 0600 through 0603 turn ON/OFF.
3) Sets the input time constant for input relay 0004 to 10 s.
4) Sets the input time constant for input relay 0006 to 10 s.
5) Sets the input time constant for input relay 0008 to 10 s.
6) The cam switch operation starts when input relay 0000 turns ON.
7) The cam switch operation stops when input relay 0001 turns ON.
#00720
LDA
DM1402
STA
#00600
LDA
DM1400
STA
2008
2002
0001
0000
HSP
0004
HSP
0006
HSP
0008
ENDH
END
0001
0002
0005
0007
0003
0004
0008
0006
0009
#02700
DW
DM1413
#01200
DW
DM1412
#01500
DW
DM1411
#00700
DW
DM1410
#00800
DW
DM1409
#00450
DW
DM1408
#00900
DW
DM1407
#00300
DW
DM1406
1000
1001
DIFU
1000
DIFU
1001
2314
SET
2715
RES
1)
2)
5)
3)
6)
4)
7)
3600
(360)
30 DM1406
45 DM1408
70 DM1410
80 DM1409
90 DM1407
120 DM1412
150 DM1412
90 180 270 360 0
ON
OFF
ON
OFF
ON
OFF
ON
OFF
Timing Diagram
Rotation ()
1st relay 0600
2nd relay 0601
3rd relay 0602
4th relay 0603
DM1406 DM1407
DM1408 DM1409
DM1410 DM1411
DM1412 DM1413
270
DM1413
4.6 Direct Clock Pulse Output
3-237
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
4.6 Direc t Cloc k Pulse Output
This section describes the outline and setting method for direct clock pulse output.
4.6.1 Outline of Direct Clock Pulse Output
Using the high-speed counter (CTH) and high-speed counter comparator (CTC), the
KV PLC can output clock pulses directly through output relays 0500 and/or 0501
without any delays caused by the scan time.
The period (frequency) and width of the pulses are determined by the period of the
internal clock used for the high-speed counter (CTH) and high-speed counter com-
parator (CTC).
The period of the clock pulse (frequency) can be changed with the program within
the following ranges.
Pulses of the internal clock are counted with the high-speed counter (CTH). When
the number of current pulses reaches the preset value of the high-speed counter
comparator (CTC), the ON/OFF status of output relays 0500 and/or 0501 is toggled
to output direct clock pulses.
Count value
Note 1: The operation of output relays 0500 and 0501 are determined by setting the
special utility relays.
Note 2: For more about setting special utility relays, refer to "4.2 Outline of High-
speed Counters" on page 3-206.
Note 3: The ON/OFF status when the direct clock pulse output is started is the
same as when the last direct clock pulse output is stopped. (Initial status: OFF)
Note 4: Output relays 0500 and 0501 cannot be used in a normal program during
direct clock pulse output.
CTC
ON ON
t u p t u O k c o l c l a n r e t n I ) y c n e u q e r F ( d o i r e p e s l u p f o e g n a R
0 0 5 0
0 . 1 ( 0 0 1 2 ) s 0 2 ) z H 5 1 ( s m 5 . 5 6 o t ) z H k 0 5 ( s
0 . 0 1 ( 1 0 1 2 ) s 0 2 ) z H 5 . 1 ( s m 3 . 5 5 6 o t ) z H k 0 5 ( s
0 . 0 0 1 ( 2 0 1 2 ) s 0 0 2 ) z H 5 1 . 0 ( s m 5 . 3 5 5 6 o t ) z H k 5 ( s
1 0 5 0
0 . 1 ( 0 0 2 2 ) s 0 2 ) z H 5 1 ( s m 5 . 5 6 o t ) z H k 0 5 ( s
0 . 0 1 ( 1 0 2 2 ) s 0 2 ) z H 5 . 1 ( s m 3 . 5 5 6 o t ) z H k 0 5 ( s
0 . 0 0 1 ( 2 0 2 2 ) s 0 0 2 ) z H 5 1 . 0 ( s m 5 . 3 5 5 6 o t ) z H k 5 ( s
Visual KV Series Only
4.6 Direct Clock Pulse Output
3-238
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
4.6.2 Pulse Output Setting with the High-speed Counter
Comparator
Changing the pulse period and width
By using two high-speed counter comparators, you can change only the pulse width
while keeping the pulse period constant, or change only the pulse period while
keeping the pulse width constant.
The following examples illustrate how the pulse width and period can be selected
with the high-speed counter comparator.
I ON-OFF ratio of 1:1
Pulse width (s) = CTC0 preset value x internal clock (s)
Pulse period (s) = CTC0 preset value x 2 x internal clock (s)
Use the following calculation to obtain the pulse period from the frequency:
Pulse period (s) = 1,000,000/Frequency (Hz)
Example: To output 10-kHz pulses
Pulse period = 1,000,000 10,000 = 100 s
Preset value for CTC0 = 10 2 1 = 50
I Variable pulse width
The period and width of the pulse can be changed by changing the preset values of
CTC0 and CTC1.
Pulse width (s) = CTC1 preset value x internal clock (s)
Pulse period (s) = CTC0 preset value x internal clock (s)
Change CTC1 preset value to change the pulse width.
Change CTC0 preset value to change the pulse period.
Note: The pulse width determined above is the pulse width produced inside the
Visual KV PLC. In reality, the output pulse width may vary depending on the re-
sponse delay of the output circuit and the load connected to this circuit. Be sure to
determine the pulse width after monitoring the actual output waveform with an
oscilloscope. (Monitor the pulses of variable pulse width.)
OFF
ON
Pulse period
ON/OFF status is set by special utility relays.
Pulse width
OFF
ON
Pulse period
ON/OFF status is set by special utility relays.
Pulse
width
4.6 Direct Clock Pulse Output
3-239
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
Calculating the pulse period and comparator preset value
The Visual KV PLC can output a maximum clock pulse of 50 kHz.
Use the following calculations to obtain the pulse period and preset value of the
high-speed counter comparator used to output the clock pulse.
I Pulse period
Pulse period (s) = 1,000,000 Frequency (Hz)
I CTC preset value for pulses with 1:1 ON/OFF ratio (using one comparator)
CTC preset value = Pulse period (s) Internal clock (s) 2
I CTC preset value for pulses with variable pulse width
CTC preset value for pulse width = Pulse width (s) Internal clock (s)
CTC preset value for pulse period = Pulse period (s) Internal clock (s)
I Range of CTC preset value with the internal clock
Note 1: Set the CTC preset value to 10 or more when the operands for the high-
speed counter (CTH) is 2100 and 2200. The clock pulse output may be improper
when the preset value is set to less than 10.
Note 2: The pulse width may vary depending on the load connected to the circuit.
Be sure to determine the pulse width after monitoring actual output waveform with
an oscilloscope.
Note 3: When CTC0 and CTC1, or CTC2 and CTC3, are used to output the clock
pulse, do not specify the same value for the preset values of CTC0 and CTC1, or of
CTC2 and CTC3.
Operation with special utility relays
I Operation with special utility relays for high-speed counter CTH0
The following table shows the ON/OFF status of output relay 0500 which can be
changed by setting special utility relays (2103 through 2112) at the start of opera-
tion, or by changing them during clock pulse output.
You can set desired values for the pulse period and pulse width, and can enable or
disable the direct output.
Operation of output relay 0500 when special utility relays are ON/OFF
OFF
ON
Pulse
width
Pulse period
OFF
ON
Pulse
width
Pulse period
) k c o l c l a n r e t n i ( y a l e r y t i l i t u l a i c e p S d o i r e P e u l a v t e s e r p C T C f o e g n a R
0 0 1 2 0 0 2 2 0 . 1 s 5 3 5 5 6 o t 0 1
1 0 1 2 1 0 2 2 0 . 0 1 s 5 3 5 5 6 o t 1
2 0 1 2 2 0 2 2 0 . 0 0 1 s 5 3 5 5 6 o t 1
4.6 Direct Clock Pulse Output
3-240
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
CTC0
ON ON
CTC1
CTC0
ON ON ON ON
s g n i t t e s y a l e r y t i l i t u l a i c e p S
N O 3 0 1 2 F F O 8 0 1 2
F F O 4 0 1 2 F F O 9 0 1 2
F F O 5 0 1 2 F F O 0 1 1 2
F F O 6 0 1 2 F F O 1 1 1 2
N O 7 0 1 2 F F O 2 1 1 2
s g n i t t e s y a l e r y t i l i t u l a i c e p S
N O 3 0 1 2 F F O 8 0 1 2
F F O 4 0 1 2 N O 9 0 1 2
F F O 5 0 1 2 F F O 0 1 1 2
N O 6 0 1 2 F F O 1 1 1 2
F F O 7 0 1 2 F F O 2 1 1 2
Setting the special utility relay
The special utility relay must be set to output the clock pulse. Set the relays in the
following manner.
Only one relay for each group can be turned ON from relays 2104 through 2107
and 2108 through 2111.
Use the SET-RES pair or STA instruction to turn relays 2103 through 2112 ON/
OFF.
Turning OFF relays 2104 or 2108 enables control of output relay 0500.
To change the pulse width, be sure to first turn ON relays 2103 or 2112 to auto-
matically clear the current value of CTH0. You cannot change the pulse period
unless you turn ON relays 2103 or 2112.
Turning ON/OFF relay 2105 stops/outputs the clock pulse.
Note: If two or more relays of special utility relays 2104 through 2107 or 2108
through 2111 are turned ON, priority is given to the relay with the smaller number.
Operation of output 0500 by setting special utility relays
Outputting a pulse with 1:1 ON/OFF ratio Outputting a pulse with variable pulse width
Count value Count value
d e e p s - h g i H
r e t n u o c
r o t a r a p m o c
l a i c e p S
y t i l i t u
y a l e r
) e u l a v t n e r r u c ( 0 H T C n e h w n o i t a r e p O
) e u l a v t e s e r p ( C T C s e h c a e r
0 C T C
3 0 1 2
f o e u l a v t n e r r u c s r a e l c y l l a c i t a m o t u A
0 H T C
s e Y : N O o N : F F O
4 0 1 2 . 0 0 5 0 f o l o r t n o c s e l b a n e / s e l b a s i D
: N O
e l b a s i D
: F F O
e l b a n E
5 0 1 2 . 0 0 5 0 h g u o r h t t u p t u o t c e r i d F F O s n r u T s e Y : N O o N : F F O
6 0 1 2 . 0 0 5 0 h g u o r h t t u p t u o t c e r i d N O s n r u T s e Y : N O o N : F F O
7 0 1 2 . 0 0 5 0 f o s u t a t s F F O / N O s e s r e v e R s e Y : N O o N : F F O
1 C T C
8 0 1 2 . 0 0 5 0 f o l o r t n o c s e l b a n e / s e l b a s i D
: N O
e l b a s i D
: F F O
e l b a n E
9 0 1 2 . 0 0 5 0 h g u o r h t t u p t u o t c e r i d F F O s n r u T s e Y : N O o N : F F O
1 1 2 . 0 0 5 0 h g u o r h t t u p t u o t c e r i d N O s n r u T s e Y : N O o N : F F O
1 1 1 2 . 0 0 5 0 f o s u t a t s F F O / N O s e s r e v e R s e Y : N O o N : F F O
2 1 1 2
f o e u l a v t n e r r u c s r a e l c y l l a c i t a m o t u A
0 H T C
s e Y : N O o N : F F O
4.6 Direct Clock Pulse Output
3-241
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
I Operation with special utility relays for high-speed counter CTH1
The following table shows the ON/OFF status of output relay 0501 which can be
changed by setting special utility relays (2203 through 2212) at the start of opera-
tion, or by changing them during clock pulse output.
You can set desired values for the pulse period and pulse width, and can enable or
disable the direct output.
Operation of output relay 0501 when special utility relays are ON/OFF
Setting the special utility relay
The special utility relay must be set to output the clock pulse. Set the relays in the
following manner.
Only one relay for each group can be turned ON from relays 2204 through 2207
and 2208 through 2211.
Use the SET-RES pair or STA instruction to turn relays 2203 through 2212 ON/
OFF.
Turning OFF relays 2204 or 2208 enables control of output relay 0501.
To change the pulse width, be sure to first turn ON relays 2203 or 2212 to auto-
matically clear the current value of CTH1. You cannot change the pulse period
unless you turn ON relays 2203 or 2212.
Turning ON/OFF relay 2205 stops/outputs the clock pulse.
Note: If two or more relays of special utility relays 2204 through 2207 or 2208
through 2211 are turned ON, priority is given to the relay with the smaller number.
Operation of output 0501 by setting special utility relays
Outputting a pulse with 1:1 ON/OFF ratio Outputting a pulse with variable pulse width
Count value Count value
d e e p s - h g i H
r e t n u o c
r o t a r a p m o c
l a i c e p S
y a l e r y t i l i t u
) e u l a v t n e r r u c ( 0 H T C n e h w n o i t a r e p O
) e u l a v t e s e r p ( C T C s e h c a e r
2 C T C
3 0 2 2
e u l a v t n e r r u c s r a e l c y l l a c i t a m o t u A
1 H T C f o
s e Y : N O o N : F F O
4 0 2 2 . 1 0 5 0 f o l o r t n o c s e l b a n e / s e l b a s i D
: N O
e l b a s i D
: F F O
e l b a n E
5 0 2 2
h g u o r h t t u p t u o t c e r i d F F O s n r u T
. 1 0 5 0
s e Y : N O o N : F F O
6 0 2 2
h g u o r h t t u p t u o t c e r i d N O s n r u T
. 1 0 5 0
s e Y : N O o N : F F O
7 0 2 2 . 1 0 5 0 f o s u t a t s F F O / N O s e s r e v e R s e Y : N O o N : F F O
3 C T C
8 0 2 2 . 1 0 5 0 f o l o r t n o c s e l b a n e / s e l b a s i D
: N O
e l b a s i D
: F F O
e l b a n E
9 0 2 2
h g u o r h t t u p t u o t c e r i d F F O s n r u T
. 1 0 5 0
s e Y : N O o N : F F O
0 1 2 2
h g u o r h t t u p t u o t c e r i d N O s n r u T
. 1 0 5 0
s e Y : N O o N : F F O
1 1 2 2 . 1 0 5 0 f o s u t a t s F F O / N O s e s r e v e R s e Y : N O o N : F F O
2 1 2 2
e u l a v t n e r r u c s r a e l c y l l a c i t a m o t u A
1 H T C f o
s e Y : N O o N : F F O
CTC2
ON ON
CTC3
CTC2
ON ON ON ON
s g n i t t e s y a l e r y t i l i t u l a i c e p S
N O 3 0 2 2 N O 8 0 2 2
F F O 4 0 2 2 F F O 9 0 2 2
F F O 5 0 2 2 F F O 0 1 2 2
F F O 6 0 2 2 F F O 1 1 2 2
N O 7 0 2 2 F F O 2 1 2 2
s g n i t t e s y a l e r y t i l i t u l a i c e p S
N O 3 0 2 2 F F O 8 0 2 2
F F O 4 0 2 2 N O 9 0 2 2
F F O 5 0 2 2 F F O 0 1 2 2
N O 6 0 2 2 F F O 1 1 2 2
F F O 7 0 2 2 F F O 2 1 2 2
4.7 Examples of Direct Clock Pulse Output
3-242
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
CTC0
ON ON
4.7 Examples of Direc t Cloc k Pulse Output
This section describes programming examples of the direct clock pulse output.
4.7.1 Example of Outputting a Pulse with 1:1 ON/OFF Ratio
To output a clock pulse of 1 ms (1 kHz)-period from output relay 0500
This section describes a programming example that will output a clock pulse with 1:1
ON/OFF ratio from output relay 0500 by using the high-speed counter (CTH0) and
high-speed counter comparator (CTC0).
I Special utility relay setting
Set the special utility relay (2103 through 2112) according to the following table.
When outputting a pulse with 1:1 ON/OFF ratio, you can simplify the program by
using the reverse (toggle) output (2107: ON).
I Internal clock and CTC0 preset value
Specify the internal clock and calculate the preset value of CTC0 for the clock.
CTC0 preset value = Pulse period (s) Internal clock (s) 2
Obtain the preset value of CTC0 by substituting 1 ms for the pulse period and 10 s
for the internal clock (special utility relay 2101).
In this case, the preset value of CTC0 is "50".
Refer to the following table for the preset value of CTC0 with other internal clocks.
I Example
Count value
Sets the pulse output from output relay 0500 with special utility relays 2104 through 2107.
In this example, turns OFF 2104 to enable direct output from 0500 and turns ON 2107 to
reverse the output each time the CTH0 value reaches the CTC0 value.
Turns ON 2103 to set CTH0 to be cleared when its value reaches the CTC0 value.
With this setting, the operation which clears the CTH0 current value when it reaches the
CTC0 preset value is repeated.
The RES CTH0 instruction resets the CTH0 current value when operation starts. This
ensures that the first clock pulse is output at the proper pulse width.
Turn ON the input enable relay for CTH0 all the time when CTH0 is used to output the
clock pulse.
. o N y a l e R g n i t t e S
3 0 1 2 N O
4 0 1 2 F F O
5 0 1 2 F F O
6 0 1 2 F F O
7 0 1 2 N O
y a l e r y t i l i t u l a i c e p S k c o l c l a n r e t n I e u l a v t e s e r p 0 C T C
0 0 1 2 0 . 1 s 0 0 5
1 0 1 2 0 . 0 1 s 0 5
2 0 1 2 0 . 0 0 1 s 5
2103
SET
2104
RES
2105
RES
2106
RES
2107
SET
CTH0
RES
2008
2002
#00050
CTC0
CTH0
2101
0001
0002
0003
4.7 Examples of Direct Clock Pulse Output
3-243
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
0000
0000 2105
RES
2105
SET
0000
0000
RES
KEEP
2105
SET
Cording
Note :When the input enable relay for the high-speed counter is used to start/stop
the clock pulse, the response is delayed by a maximum of one scan when output
starts. Moreover, if the response is delayed by one scan when output stops, the
clock pulse stops but the output may remain ON.
I Tips
Use special utility relay 2105 to control (enable/disable) the clock pulse output by
external inputs.
Use the SET-RES pair or KEEP instruction to turn special utility relay 2105 ON/
OFF.
With this setting, the clock pulse is always turned OFF when it starts as well as
stops.
When either of the following programs is added to the example on the previous
page, the clock pulse is output from 0500 only when 0000 is ON.
When SET-RES instructions are used When KEEP instruction is used
To output a clock pulse of 1 ms (1 kHz)-period from output relay 0501
This section describes a programming example that will output a clock pulse with 1:1
ON/OFF ratio from output relay 0501 by using the high-speed counter (CTH1) and
high-speed counter comparator (CTC2).
I Special utility relay setting
Set the special utility relay (2203 through 2212) according to the following table.
When outputting a pulse with 1:1 ON/OFF ratio, you can simplify the program by
using the reverse (toggle) output (2207: ON).
I Internal clock and CTC2 preset value
Specify the internal clock and calculate the preset value of CTC2 for the clock.
CTC2 preset value = Pulse period (s) Internal clock (s) 2
Obtain the preset value of CTC2 by substituting 1 ms for the pulse period and 10 s
for the internal clock (special utility relay 2201).
In this case, the preset value of CTC2 is "50".
Refer to the following table for the CTC2 preset value with other internal clocks.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0008 CON
0001 SET 2103 0009 SET 2107
0002 CON 0010 CON
0003 RES 2104 0011 RES CTH0
0004 CON 0012 LD 2002
0005 RES 2105 0013 CTH 0 2101
0006 CON 0014 CTC 0 #00050
0007 RES 2106
. o N y a l e R g n i t t e S
3 0 2 2 N O
4 0 2 2 F F O
5 0 2 2 F F O
6 0 2 2 F F O
7 0 2 2 N O
4.7 Examples of Direct Clock Pulse Output
3-244
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
I Example
Count value
Sets the pulse output from output relay 0501 with special utility relays 2204 through 2207.
In this example, turns OFF 2204 to enable direct output from 0501 and turns ON 2207 to
reverse the output each time the CTH1 value reaches the CTC2 value.
Turns ON 2203 to set CTH1 to be cleared when its value reaches the CTC2 value.
With this setting, the operation which clears the CTH1 current value when it reaches the
CTC2 preset value is repeated.
The RES CTH1 instruction resets the CTH1 current value when operation starts. This
ensures that the first clock pulse is output at the proper pulse width.
Turn ON the input enable relay for CTH1 all the time when CTH1 is used to output the
clock pulse.
Coding
Note :When the input enable relay for the high-speed counter is used to start/stop
the clock pulse, the response is delayed by a maximum of one scan when output
starts. Moreover, if the response is delayed by one scan when output stops, the
clock pulse stops but the output may remain ON.
I Tips
Use special utility relay 2205 to control (enable/disable) the clock pulse output by
external inputs.
Use the SET-RES pair or KEEP instruction to turn special utility relay 2205 ON/
OFF.
With this setting, the clock pulse is always turned OFF when it starts as well as
stops.
When either of the following programs is added to the example on the previous
page, the clock pulse is output from 0501 only when 0000 is ON.
When SET-RES instructions are used When KEEP instruction is used
0000
0000 2205
RES
2205
SET
0000
0000
RES
KEEP
2205
SET
CTC2
ON ON
y a l e r y t i l i t u l a i c e p S k c o l c l a n r e t n I e u l a v t e s e r p 2 C T C
0 0 2 2 0 . 1 s 0 0 5
1 0 2 2 0 . 0 1 s 0 5
2 0 2 2 0 . 0 0 1 s 5
2203
SET
2204
RES
2205
RES
2206
RES
CTH1
RES
2008
2002
#00050
CTC2
CTH1
2201
0001
0002
0003
2207
SET
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0008 CON
0001 SET 2203 0009 SET 2207
0002 CON 0010 CON
0003 RES 2204 0011 RES CTH1
0004 CON 0012 LD 2002
0005 RES 2205 0013 CTH 1 2201
0006 CON 0014 CTC 2 #00050
0007 RES 2206
4.7 Examples of Direct Clock Pulse Output
3-245
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
2103
SET
2104
RES
2105
RES
2106
SET
2107
RES
2108
RES
2109
SET
2110
RES
2111
RES
CTH0
RES
2008
2002
#00050
CTC0
#00020
CTC1
CTH0
2101
0001
0002
0003
0004
0005
CTC0
CTC1
ON ON ON ON
4.7.2 Example of Outputting a Pulse with Variable ON/OFF
Ratio
To output a clock pulse of 500 s (2 kHz)-period and 200 s-width from output relay 0500
This section describes a programming example that will output a clock pulse with
variable ON/OFF ratio from output relay 0500 by using the high-speed counter
(CTH0) and high-speed counter comparator (CTC0 and CTC1).
I Special utility relay setting
Set the special utility relay (2103 through 2112) according to the following table.
I Internal clock and CTC0/CTC1 preset values
Specify the internal clock and calculate the preset values of CTC0 and CTC1 for the
clock.
CTC1 preset value = Pulse width (s) Internal clock (s)
CTC0 preset value = Pulse period (s) Internal clock (s)
Obtain the preset values of CTC0 and CTC1 by substituting 200 s for the pulse
width, 500 s for the pulse period, and 10 s for the internal clock (special utility
relay 2101).
In this case, the preset value of CTC1 is "20", and that of CTC0 is "50".
Refer to the following table for the CTC preset values with other internal clocks.
I Example
Count value
Sets the pulse output from output relay 0500 with special utility relays 2104 through 2107
and 2108 through 2111.
In this example, turns OFF 2104 to enable direct output from 0500. Turns ON 2106 to turn
ON the output from 0500 when the CTH0 value reaches the CTC0 value, and turns ON
2109 to turn OFF the output when the CTH0 value reaches the CTC1 value.
Turns ON 2103 to set CTH0 to be cleared when its value reaches the CTC0 value. This
ensures that the first clock pulse is output at the proper pulse width.
Turn ON the input enable relay for CTH0 all the time when CTH0 is used to output the
clock pulse.
. o N y a l e R g n i t t e S . o N y a l e R g n i t t e S
3 0 1 2 N O 8 0 1 2 F F O
4 0 1 2 F F O 9 0 1 2 N O
5 0 1 2 F F O 0 1 1 2 F F O
6 0 1 2 N O 1 1 1 2 F F O
7 0 1 2 F F O 2 1 1 2 F F O
y a l e r y t i l i t u l a i c e p S k c o l c l a n r e t n I e u l a v t e s e r p 0 C T C e u l a v t e s e r p 1 C T C
0 0 1 2 0 . 1 s 0 0 5 0 0 2
1 0 1 2 0 . 0 1 s 0 5 0 2
2 0 1 2 0 . 0 0 1 s 5 2
4.7 Examples of Direct Clock Pulse Output
3-246
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
0000
0000 2105
RES
2105
SET
0000
0000
RES
KEEP
2105
SET
Coding
Note 1: When the input enable relay for the high-speed counter is used to start/stop
the clock pulse, the response is delayed by a maximum of one scan when output
starts. The response is also delayed by a maximum of one scan when output stops.
Note 2: Refer to the following "Tips" to start and stop the clock pulse.
I Tips
Use special utility relay 2105 to control (enable/disable) the clock pulse output by
external inputs.
Use the SET-RES pair or KEEP instruction to turn special utility relay 2105 ON/
OFF.
With this setting, the clock pulse is always turned OFF when it starts as well as
stops.
When either of the following program is added to the example on the previous
page, the clock pulse is output from 0500 only when 0000 is ON.
When SET-RES instructions are used When KEEP instruction is used
You can change the period (frequency) of the clock pulse by changing the CTC0
preset value using the LDA and STA instructions.
To change the period of the clock pulse, refer to "4.3.4 Count Input Method" (p.3-
212).
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0013 CON
0001 MPS 0014 SET 2109
0002 SET 2103 0015 CON
0003 CON 0016 RES 2110
0004 RES 2104 0017 CON
0005 CON 0018 RES 2111
0006 RES 2105 0019 CON
0007 CON 0020 RES CTH0
0008 RES 2106 0021 LD 2002
0009 CON 0022 CTH 0 2101
0010 RES 2107 0023 CTC 0 #00050
0011 MPP 0024 CTC 1 #00020
0012 RES 2108
4.7 Examples of Direct Clock Pulse Output
3-247
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
2203
SET
2204
RES
2206
SET
2207
RES
2208
RES
2209
SET
2210
RES
2211
RES
CTH1
RES
2008
2002
#00050
CTC2
#00020
CTC3
CTH1
2201
0001
0002
0003
0004
0005
CTC2
CTC3
ON ON ON ON
To output a clock pulse of 500 s (2 kHz)-period and 200 s-width from output relay 0501
This section describes a programming example that will output a clock pulse with
variable ON/OFF ratio from output relay 0501 by using the high-speed counter
(CTH1) and high-speed counter comparator (CTC2 and CTC3).
I Special utility relay setting
Set the special utility relay (2203 through 2212) according to the following table.
I Internal clock and CTC2/CTC3 preset values
Specify the internal clock and calculate the preset values of CTC2 and CTC3 for the
clock.
CTC2 preset value = Pulse width (s) Internal clock (s)
CTC3 preset value = Pulse period (s) Internal clock (s)
Obtain the preset values of CTC2 and CTC3 by substituting 200 s for the pulse
width, 500 s for the pulse period, and 10 s for the internal clock (special utility
relay 2201).
In this case, the preset value of CTC3 is "20", and that of CTC2 is "50".
Refer to the following table for the CTC preset values with other internal clocks.
I Example
Count value
Sets the pulse output from output relay 0501 with special utility relays 2204 through 2207
and 2208 through 2211.
In this example, turns OFF 2204 to enable direct output from 0501. Turns ON 2206 to turn
ON the output from 0501 when the CTH1 value reaches the CTC2 value and turns ON
2209 to turn OFF the output when the CTH1 value reaches the CTC3 value.
Turns ON 2203 to set CTH1 to be cleared when its value reaches the CTC2 value. This
ensures that the first clock pulse is output at the proper pulse width.
Turn ON the input enable relay for CTH1 all the time when CTH1 is used to output the
clock pulse.
. o N y a l e R g n i t t e S . o N y a l e R g n i t t e S
3 0 2 2 N O 8 0 2 2 N O
4 0 2 2 F F O 9 0 2 2 F F O
5 0 2 2 F F O 0 1 2 2 F F O
6 0 2 2 N O 1 1 2 2 F F O
7 0 2 2 F F O 2 1 2 2 F F O
y a l e r y t i l i t u l a i c e p S k c o l c l a n r e t n I e u l a v t e s e r p 2 C T C e u l a v t e s e r p 3 C T C
0 0 2 2 0 . 1 s 0 0 5 0 0 2
1 0 2 2 0 . 0 1 s 0 5 0 2
2 0 2 2 0 . 0 0 1 s 5 2
4.7 Examples of Direct Clock Pulse Output
3-248
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
0000
0000 2205
RES
2205
SET
0000
0000
RES
KEEP
2205
SET
Coding
Note :When the input enable relay for the high-speed counter is used to start/stop
the clock pulse, the response is delayed by a maximum of one scan when output
starts. The response is also delayed by a maximum of one scan when the output
stops.
I Tips
Use special utility relay 2205 to control (enable/disable) the clock pulse output by
external inputs.
Use the SET-RES pair or KEEP instruction to turn special utility relay 2205 ON/
OFF.
With this setting, the clock pulse is always turned OFF when it starts as well as
stops.
When either of the following programs is added to the example on the previous
page, the clock pulse is output from 0501 only when 0000 is ON.
When SET-RES instructions are used When KEEP instruction is used
You can change the period (frequency) of the clock pulse by changing CTC2
preset value using LDA and STA instructions.
To change the period of the clock pulse, refer to "4.3.4 Count Input Method" on
page 3-212.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0012 SET 2209
0001 MPS 0013 CON
0002 SET 2203 0014 RES 2210
0003 CON 0015 CON
0004 RES 2204 0016 RES 2211
0005 CON 0017 CON
0006 SET 2205 0018 RES CTH1
0007 CON 0019 LD 2002
0008 RES 2207 0020 CTH 1 2201
0009 MPP 0021 CTC 2 #00050
0010 RES 2208 0022 CTC 3 #00020
0011 CON
4.7 Examples of Direct Clock Pulse Output
3-249
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
2109
SET
2110
RES
2111
RES
CTH0
RES
2105
RES
2105
SET
2203
SET
2813
SET
CTH1
RES
2002
#00050
CTC0
1000
DIFU
#00020
CTC1
CTH0
2101
0002
2104
RES
2105
SET
2106
SET
2107
RES
2108
RES
2103
SET EI
2008
1000
0001
0003
0005
2002
0012
2002
#10000
CTC2
CTH1
0500
0008
END
0010
RETI
0013
ENDH
0014
INT
CTC2
0011
0000
0004
0006
0009
0007
#00000
DW
DM1940
4.7.3 Example of Stopping the Pulse Output at a Specified
Pulse Count
This section describes a programming example that will output a clock pulse of 500
s (2 kHz)-period and 200 s-width from output relay 0500 and then stop it after
10000 pulses are output.
I Special utility relay, internal clock, and CTC settings
Set the special utility relay according to the following table.
Specify the internal clock and CTC0/CTC1 preset values according to the following
table.
I Example
Sets the pulse output from output relay 0500 with special utility relays 2104 through 2107
and 2108 through 2111.
In this example, turns OFF 2104 to enable direct output from 0500. Turns ON 2106 to turn
ON the output from 0500 when the CTH0 value reaches the CTC0 value and turns ON
2109 to turn OFF the output when the CTH0 value reaches the CTC1 value.
Turns ON 2103 to set CTH0 to be cleared when its value reaches the CTC0 value. This
ensures that the first clock pulse is output at the proper pulse width.
Uses an EI instruction to enable interrupts.
The interrupt program (INT CTC2) stops the clock pulse when the CTH1 current value
reaches the CTC2 preset value (when 10000 pulses are output).
Turns ON 2203 to set CTH1 to be cleared when its value reaches the CTC2 value. This
forces the operation to repeat by the specified pulses (10000).
Relay 2813 must be turned ON when counting pulses with CTH1.
. o N y a l e R g n i t t e S . o N y a l e R g n i t t e S
3 0 1 2 N O 8 0 1 2 F F O
4 0 1 2 F F O 9 0 1 2 N O
5 0 1 2 F F O 0 1 1 2 F F O
6 0 1 2 N O 1 1 1 2 F F O
7 0 1 2 F F O 2 1 1 2 F F O
y a l e r y t i l i t u l a i c e p S k c o l c l a n r e t n I e u l a v t e s e r p 0 C T C e u l a v t e s e r p 1 C T C
0 0 1 2 0 . 1 s 0 0 5 0 0 2
1 0 1 2 0 . 0 1 s 0 5 0 2
2 0 1 2 0 . 0 0 1 s 5 2
4.7 Examples of Direct Clock Pulse Output
3-250
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
The input enable relay for CTH0 must be ON all the time when CTH0 is used to output the
clock pulse.
The input enable relay for CTH1 must be ON all the time when CTH1 is used to count the
clock pulse.
Specifies the internal clock (2101) as the clock input for CTH0. Specifies 0500 as the
clock input for CTH1. With this setting, CTH0 is used to output the clock pulse, and CTH1
is used to count the clock pulse.
Specifies the number of clock pulses to the CTC2 preset value.
The clock pulse output starts when input 0000 is turned ON.
To restart the clock pulse output after it stops, turn ON input 0000 again.
Coding
I Tips
Special utility relays 2103 through 2111 can be turned ON/OFF by using the LDA
and STA instructions instead of the SET-RES instructions.
The example program below can be changed as follows by using the LDA and STA
instructions. The number of lines and steps can be reduced.
LDA $0268
When LDA $0268 is executed, the value specified by the operand is written into
the internal register as follows.
When STA 2100 is executed, the value in the internal register is assigned to
special utility relays 2100 through 2115.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0024 SET 2203
0001 EI 0025 CON
0002 CON 0026 DW #00000 DM1940
0003 MPS 0027 CON
0004 SET 2103 0028 SET 2813
0005 CON 0029 CON
0006 RES 2104 0030 RES CTH1
0007 CON 0031 LD 0000
0008 SET 2105 0032 DIFU 1000
0009 CON 0033 CON
0010 SET 2106 0034 AND 1000
0011 CON 0035 RES 2105
0012 RES 2107 0036 LD 2002
0013 MRD 0037 CTH 0 2101
0014 RES 2108 0038 CTC 0 #00050
0015 CON 0039 CTC 1 #00020
0016 SET 2109 0040 LD 2002
0017 CON 0041 CTH 1 0500
0018 RES 2110 0042 CTC 2 #10000
0019 CON 0043 END
0020 RES 2111 0044 INT CTC2
0021 CON 0045 LD 2002
0022 RES CTH0 0046 SET 2105
0023 MPP 0047 RET1
0048 ENDH
0 0
[0] [2] [6] [8]
0 0 0 0 1 0 0 1 1 0 1 0 0 0
Internal register
0
15 xx 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
0 0 0 0 0 1 0 0 1 1 0 1 0 0 0
Special utility
relay 21xx
2109
SET
2110
RES
2111
RES
CTH0
RES
2203
SET
2813
SET
CTH1
RES
2104
RES
2105
SET
2106
SET
2107
RES
2108
RES
2103
SET EI
2008 2100
STA
CTH0
RES
2203
SET
2813
SET
CTH1
RES
$0268
LDA EI
2008
4.7 Examples of Direct Clock Pulse Output
3-251
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
4
Chapter 4 High-speed Counters
4.7.4 Application of Direct Clock Pulse Output
(Ramp-up/down control)
The following ramp-up/down control is available by setting four parameters (DM0000
to DM0003)
I Setting parameters
DM0000: fH [Hz] (Running frequency)
DM0001: fL [Hz] (Start-up frequency)
DM0002: Acceleration rate [Hz/10 ms]
DM0003: No. of pulses for positioning
Note 1: A smaller acceleration rate allows smoother control but extends the accel-
eration time.
Note 2: Be sure to turn OFF input 0007 (phase B input).
I Operation
In the example on the next page, each parameter is set as follows:
DM0000: 8000 [Hz]
DM0001: 700 [Hz]
DM0002: 400 [Hz/10 ms]
DM0003: 4000 pulses
When start switch 0000 is pressed, ramp-up/down control is performed as shown
below. Control is stopped when the pulse count reaches "4000".
Pressing the start switch restarts the operation. The operation is reversed while
reverse switch 0001 is ON.
I Connection example
The above diagram shows a connection example between the KV PLC and a
stepping motor driver.
Refer to the instruction manual for your stepping motor driver for details.
Set the pulse input method of the stepping motor driver to "1-pulse input method".
CW
KV
24 VDC
FG

+
5 VDC
+
CCW
0002
0001
0000
0502 0500
COM 0003
0501 COM 0503
Stepping motor
S
t
a
r
t
R
e
v
e
r
s
e
o
u
t
p
u
t
E
m
e
r
g
e
n
c
y
s
t
o
p
Stepping motor driver
Twisted-pair cable
(Pulse)
(Rotation
direction)
Specify values in the range from 153 Hz to
50000 Hz. The fH value must be greater
than the fL value.
(fH - fL) / (Acceleration time / 10 ms)
Must be 65534 pulses or less.
L
(DM0001)
H
(DM0000)
10ms
(DM0003)
(DM0002)
0
Frequency (Hz)
Acceleration
rate
(Acceleration
change period)
Total pulses
for positioning
Acceleration
time
Constant
speed time
Time (ms)
Deceleration
time

4.7 Examples of Direct Clock Pulse Output


3-252
V
i
s
u
a
l

K
V
S
e
r
i
e
s
4
Chapter 4 High-speed Counters
Interrupt routine for
acceleration/deceleration
Acceleration process
Deceleration process
Interrupt for pulse stop
Clock pulse output is stopped when
the No. of pulses equals the CTC3
preset value.
Acceleration ratio is added to the
current frequency to change it each
time CTC2 turns ON while
acceleration flag 1200 is ON.
Acceleration stops when the
current frequency reaches fH. Sets
No. of pulses for the deceleration
point.
Acceleration ratio is subtracted
from the current frequency to
change it each time CTC2 turns
ON while acceleration flag 1200 is
ON. Deceleration stops when the
current frequency reaches fL. The
setting is initialized.
#08000
DW
#00700
DW
$0268
LDA
#01000
LDA
#10000
MUL
DM0012
DIV
#00005
ADD
#00010
DIV
CTC0
STA
DM0010
STA
2100
STA
1200
SET
CTH1
RES
CTH0
RES EI
2105
RES
#00400
DW
#04000
DM0000 DM0001 DM0002 DM0003
DW
2813
SET
2105
SET
2002
2008
0003
0001
2002
0000 1001
#00010
CTC1
1001
DIFU
#65535
CTC0
CTH0
2100
0003 2105
SET
#65535
CTC2
#65535
CTC3
01
CALL
02
CALL
CTH1
0500
END
RET
SBN
01
RET
SBN
03
RET
DM0003
LDA
CTC3
STA
#00002
DIV
DM0004
STA
DM0001
LDA
DM0012
STA
#00000
DM0011
DW
2002
DM0012
LDA
#00100
DIV
DM0011
ADD
DM0004
CMP
2002
#00010
LDA
#10000
MUL
DM0010
DIV
#00005
ADD
#00010
DIV
DM0011
ADD
CTC2
STA
DM0011
STA
SBN
02
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0502
DM0012
LDA
DM0002
ADD
DM0011
STA
2105
SET
CTC2
STA
DM0011
SUB
DM0003
LDA
DM0012
STA
DM0000
CMP
1200 2011
2011
1200
RES
#65535
LDA
CTC2
STA
1201
INT
CTC2
RETI
INT
CTC3
RETI
ENDH
03
CALL
DM0012
LDA
DM0002
SUB
DM0012
STA
DM0001
CMP
1200
2002
2011 02
CALL
2011 02
CALL
2011
2011
02
CALL
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
1201
Specifies high-speed
counters and comparators
Starts positioning
Emergency stop
Calculation routine for
CTC0, CTC2, and DM0011
Initialization routine
Triangle drive check routine
CTC0 generates a clock pulse.
CTH1 counts the number of
clock pulses.
CTC0:Pulse period
CTC1: Pulse width
CTC2:Frequency change point
CTC3:Total No. of pulses for positioning
Sets parameters (DM0000 to
DM0003).
Sets reverse output.
Sets emergency stop.
Specifies the CTC2 preset
value.
DM0010: Pulse period T (s)
DM0011: No. of accumulated pulses
DM0012: Current frequency (Hz)
1200: Acceleration flag
Specifies the CTC0 preset value.
CTC0 preset value =
1 DM0012 x 10
3
x 10
3
I Example
Chapter 5
Positioning Control
This chapter describes ramp-up/down control of stepping motors and servo motors.
For KV-10/80 Series, see Chapter 6.
5.1 Outline of Positioning Control ..................................................... 3-254
5.1.1 Ramp-up/down Control .......................................................................... 3-254
5.2 Parameter Setting and Operating Procedures ......................... 3-255
5.2.1 Parameter Setting Procedure................................................................. 3-255
5.2.2 Operating Procedure .............................................................................. 3-257
5.3 Examples of Using the Positioning Control Function ........... 3-258
5.3.1 Connection Example .............................................................................. 3-258
5.3.2 Tips ........................................................................................................ 3-258
5.3.3 Application Examples of the Positioning Control Function ..................... 3-259
Visual KV Series Only
V
i
s
u
a
l

K
V
S
e
r
i
e
s
5.1 Outline of Positioning Control
3-254
V
i
s
u
a
l

K
V
S
e
r
i
e
s
5
Chapter 5 Positioning Control
5.1 Outline of Positioning Control
This section describes the outline of positioning control.
5.1.1 Ramp-up/down Control
The Visual KV Series can directly output clock pulses not affected by the scan time
to output relay 0502.
If the frequency, the number of output pulses, and the acceleration time of the clock
pulses have been preliminarily set to data memories, the Visual KV Series automati-
cally performs ramp-up/down control.
The ramp-up/down control output function offers ramp-up/down timing charts of the
startup frequency, operating frequency, acceleration time, and deceleration time as
shown below.
The output frequency can be set within the range of 200 to 50,000 Hz.
By using the ramp-up/down control output function, ramp-up/down control of step-
ping motors and AC servo motors (pulse input types) is possible.
Frequency (Hz)
Number of output
pulses (pulses)
DM1485 and DM1484
Operating
frequency
DM1481
Upper digit Lower digit
Startup
frequency
DM1480
Acceleration
time DM1482
Deceleration
time DM1482
Time (ms)
NEW KV
Lo: CW
Hi: CCW
0502
0503
Clock pulse
Rotation direction
Motor driver
Stepping motor
Servo motor
5.2 Parameter Setting and Operating Procedures
3-255
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
5
Chapter 5 Positioning Control
5.2 Parameter Setting and Operating
Proc edures
This section describes the parameter setting and operating procedures for position-
ing control.
5.2.1 Parameter Setting Procedure
Preliminarily set each parameter for positioning control to a corresponding data
memory. To operate, special utility relays must be set.
For more about special utility relays, refer to "5.2.2 Operating Procedure" (p. 3-257).
The table below shows the relationship between parameters and data memories.
Data memories for ramp-up/down control
Note: When pulse output is started, the scan time is extended by 10 ms maximum
(if the acceleration/deceleration time is set to 4 s).
Set value error code (DM1486)
If there is an error in the preset parameters when starting operation, a corresponding
error code (11 to 17) is automatically written to DM1486.
Startup frequency (Hz) (DM1480)
Set the frequency (speed) of the motor at startup in positioning control so that motor
rotations start up smoothly.
At the set frequency, the Visual KV Series will output clock pulses.
y r o m e m a t a D s t n e t n o c g n i t t e S e g n a r g n i t t e S
0 8 4 1 M D
p u t r a t s l o r t n o c n w o d / p u - p m a R
) z H ( y c n e u q e r f
0 0 0 , 0 5 o t 0 0 2
1 8 4 1 M D
g n i t a r e p o l o r t n o c n w o d / p u - p m a R
) z H ( y c n e u q e r f
0 0 0 , 0 5 o t 0 0 2
) y c n e u q e r f p u t r a t s n a h t r e g r a l e u l a v (
2 8 4 1 M D
l o r t n o c n w o d / p u - p m a R
e m i t n o i t a r e l e c e d / n o i t a r e l e c c a
) s m (
0 0 0 4 o t 0
4 8 4 1 M D
s e s l u p t u p t u o f o r e b m u N
) s t i b 6 1 r e w o l (
5 3 5 , 5 6 o t 0
) 0 s i 5 8 4 1 M D n e h w e r o m r o 2 (
5 8 4 1 M D
s e s l u p t u p t u o f o r e b m u N
) s t i b 6 1 r e p p u (
5 3 5 , 5 6 o t 0
6 8 4 1 M D e d o c r o r r e e u l a v t e S
- d n o p s e r r o c a , s r u c c o r o r r e n a n e h W
. d e r o t s s i 7 1 o t 1 1 e d o c r o r r e g n i
e d o C n o i t p i r c s e D s e r u s a e m r e t n u o C
1 1 n a h t r e l l a m s s i e u l a v y c n e u q e r f p u t r a t S
. e g n a r g n i t t e s e l b a w o l l a
g n i t t e s n i h t i w y c n e u q e r f g n i t r a t s t e S
. ) 0 0 0 , 0 5 o t 0 0 2 ( e g n a r
2 1 r e l l a m s s i e u l a v y c n e u q e r f g n i t a r e p O
. e g n a r g n i t t e s e l b a w o l l a n a h t
g n i t t e s n i h t i w y c n e u q e r f g n i t a r e p o t e S
. ) 0 0 0 , 0 5 o t 0 0 2 ( e g n a r
3 1 s i e u l a v y c n e u q e r f ) p u t r a t s r o ( g n i t a r e p O
. e g n a r g n i t t e s e l b a w o l l a n a h t r e g r a l
y c n e u q e r f ) p u t r a t s r o ( g n i t a r e p o t e S
. ) 0 0 0 , 0 5 o t 0 0 2 ( e g n a r g n i t t e s n i h t i w
4 1 n a h t r e g r a l s i e u l a v y c n e u q e r f p u t r a t S
. e u l a v y c n e u q e r f g n i t a r e p o
p u t r a t s t a h t o s y l e t a i r p o r p p a m e h t t e S
g n i t a r e p o n a h t r e l l a m s s i y c n e u q e r f
. y c n e u q e r f
5 1 r e g r a l s i e m i t n o i t a r e l e c e d / n o i t a r e l e c c A
. e g n a r g n i t t e s e l b a w o l l a n a h t
n i h t i w e m i t n o i t a r e l e c e d / n o i t a r e l e c c a t e S
. ) 0 0 0 , 4 o t 0 ( e g n a r g n i t t e s
6 1 r o r r e m e t s y S . e c i f f o s e l a s r u o t c a t n o C
7 1 n i h t i w t u p t u o s e s l u p f o r e b m u N
o o t s i e m i t n o i t a r e l e c e d / n o i t a r e l e c c a
. l l a m s
r o 2 o t s e s l u p t u p t u o f o r e b m u n t e S
. e r o m
5.2 Parameter Setting and Operating Procedures
3-256
V
i
s
u
a
l

K
V
S
e
r
i
e
s
5
Chapter 5 Positioning Control
Operating frequency (Hz) (DM1481)
Set the frequency (speed) of the motor during operation in positioning control.
At the set frequency, the Visual KV Series will output clock pulses.
Note: If the startup frequency is the same as the operating frequency, the timing
chart becomes as shown below.
In this case, the acceleration/deceleration time is ignored.
Acceleration/deceleration time (ms) (DM1482)
Set the time to accelerate from the starting frequency to the operating frequency
after operation is started.
When operation is stopped, the deceleration time is equivalent to the acceleration
time.
In the set time, the Visual KV Series varies the clock pulse frequency from the
startup frequency to the operating frequency (in the case of acceleration time).
The clock pulse frequency change cycle within the acceleration time is fixed to 5 ms.
Number of output pulses (DM1484 and DM1485)
Set the angle of rotation (movement quantity) in positioning control as the number of
pulses. The Visual KV Series outputs as many clock pulses as the set value.
If the number of output pulses is larger than 65,535, divide it into the upper 16-bit
value and the lower 16-bit value using the following equation.
The minimum value is 2, and maximum value is 4,294,967,295.
(Number of output pulses) 65,536 = A (answer) . . . B (remainder)
A = Number of output pulses (upper 16-bit) DM1485
B = Number of output pulses (upper 16-bit) DM1484
Note 1: When the set number of pulses is too small and the target value cannot be
achieved, triangular control is performed as shown below.
Note 2: The current value of pulse output cannot be obtained.
0
Operating (startup)
frequency
5ms
Operating frequency
Startup frequency
Acceleration/deceleration time
0
Operating frequency
Startup frequency
5.2 Parameter Setting and Operating Procedures
3-257
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
5
Chapter 5 Positioning Control
5.2.2 Operating Procedure
In positioning control, operation is started up, stopped normally, and stopped in
emergencies by the ON/OFF status of special utility relays.
The table below shows the relationship between operations and the special utility
relays used.
* R: Read W: Write
I Operation chart
Note 1: If there is no error in the parameter setting when special utility relay 2310
turns ON at startup of the clock pulses, special utility relay 2309 turns ON and clock
pulses are output.
Note 2: If there is an error in the parameter setting, special utility relay 2309 does
not turn ON but a corresponding error code is written to DM1486.
Confirm the error code, and change the erroneously set parameter.
Note 3: By setting special utility relay 2309 to OFF in an interrupt program, clock
pulses can be immediately stopped.
Note 4: Rising of special utility relay 2310, falling of special utility relay 2309, and
rising of special utility relay 2308 are performed by end processing and RETI.
(Special utility relay 2309 turns ON at that time.)
Note 5: It takes a maximum of 10 ms from when special utility relay 2310 turns ON
until pulses are output.
Note 6: Even if special utility relay 2310 is set to ON while special utility relay 2308
or 2309 is ON, it is ignored.
Note 7: When pulse output has finished, special utility relay 2309 is immediately set
to OFF (without regard to the scan time).
y t i l i t u l a i c e p S
. o N y a l e r
* W / R n o i t c n u F n o i t p i r c s e D
8 0 3 2 W p o t S
s p o t s n e h t , e g d e g n i s i r t a n o i t a r e l e c e d s m r o f r e P
. n o i t a r e p o
9 0 3 2
R
W
n u R
T E S E R
. t u p t u o e r a s e s l u p e l i h w N O s n i a m e R
n a n i t e s e r g n i e b n e h w y l e t a i d e m m i n o i t a r e p o s p o t S
. m a r g o r p t p u r r e t n i
0 1 3 2 W t r a t S . e g d e g n i s i r t a n o i t a r e p o p u s t r a t S
DM1480: Startup frequency (Hz)
DM1481: Operating frequency (Hz)
DM1482: Acceleration time (ms)
DM1485: Number of output pulses (upper 16 bits)
DM1484: Number of output pulses (lower 16 bits)
DM1481
DM1480
2310
(START)
2309
(RUN)
2308
(STOP)
0
DM1485
DM1484
DM1482 DM1482
When relay 2310 turns ON, clock pulses are
output (detection at rising edge).
While clock pulses are output, relay 2309
remains ON. While clock pulses are not
output, relay 2309 remains OFF.
When relay 2308 turns ON, clock pulses are
decelerated and stopped (detection at rising
edge).
5.3 Examples of Using the Positioning Control Function
V
i
s
u
a
l

K
V
S
e
r
i
e
s
5
Chapter 5 Positioning Control
3-258
5.3 Examples of Using the Positioning
Control Func tion
This section describes examples of connecting a stepping motor driver and perform-
ing ramp-up/down control using the positioning control function of the Visual KV
Series.
5.3.1 Connection Example
Connect the Visual KV Series and stepping motor driver as shown below.
This example is only for reference. For details, refer to the instruction manual for the
stepping motor driver.
Set the pulse input type of the stepping motor driver to "1 pulse input type".
When using a 24 VDC power supply, be sure to use the outputs with current limiting
resistors (R500, R501, and R502) or use the normal outputs with external current limiting
resistors.
5.3.2 Tips
When using a servo motor, also refer to the connection example above. However,
I/O control dedicated to a servo motor such as servo ON is also required.
CW
Visual KV
24 VDC
FG

+
+

5 VDC*
+
CCW
0002
0001
0000
R0502
COM
COM R0503
E
m
e
r
g
e
n
c
y

s
t
o
p
S
t
o
p
S
t
a
r
t
Stepping motor driver
Twisted pair cable
(pulse)
(rotation
direction)
Stepping motor
5.3 Examples of Using the Positioning Control Function
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
5
Chapter 5 Positioning Control
3-259
5.3.3 Application Examples of the Positioning Control
Function
Ladder example of ramp-up/down control
When start switch 0000 is set to ON, output 0502 starts to output 100,000 pulses
with a startup frequency of 500 Hz, operating frequency of 10 kHz, and acceleration/
deceleration time of 3 seconds.
When input 0001 is set to ON, pulse output is decelerated and stopped.
When input 0002 is set to ON, pulse output is immediately stopped.
I Program example
0
100000
500
1000
Speed (Hz)
Coordinate (pulses)
Permit interrupts when operation is
started (so that emergency stop
operations are available).
2008
2002
EI 0001
0002
0003
0004
0005
0006
0007
0008
0009
#34464
DW
#00001
DW
#03000
DW
#10000
DW
#00500
DM1484 DM1485 DM1482 DM1481 DM1480
DW
0000
2309
RES
2310
0001 2308
RETI
ENDH
END
INT
0002
HSP
0002
2002
Set the input time constant of input
0002 to 10 s.
Set each parameter, and start pulse
output at the same time.
Decelerate and stop pulse output.
Perform emergency stop processing
by using an interrupt program.
5.3 Examples of Using the Positioning Control Function
V
i
s
u
a
l

K
V
S
e
r
i
e
s
5
Chapter 5 Positioning Control
3-260
Ladder example of the jog operation
The jog operation is performed.
While input 0000 is ON, the machine continues to move in the CW direction.
When input 0000 turns OFF, the machine decelerates and stops.
While input 0001 is ON, the machine continues to move in the CCW direction.
When input 0001 turns OFF, the machine decelerates and stops.
I Program example
1000
500
Speed (Hz)
CW direction CCW direction
Coordinate (pulses)
Input 0000
(CW direction)
Input 0001
(CCW direction)
1000
DIFU
0000 0001
#65535
DW
#65535
DW
#01000
DW
#02000
DW
#00500
DM1484 DM1485 DM1482 DM1481 DM1480
DW
1000
1100
1001
0503
SET
2310
2308
END
ENDH
0001 2309 0000
1001
DIFU
1100
DIFU
0503
RES
0000 2309 0001
0001
0002
0003
0004
0005
0006
0007
5.3 Examples of Using the Positioning Control Function
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
5
Chapter 5 Positioning Control
3-261
Ladder example of automatic operation (palletizing operation)
A palletizing operation is automatically performed.
The machine moves to a target coordinate, then returns to the start position. Next,
the machine moves to a position further away than the target coordinate, then again
returns to the start position. Such an operation is realized using repetitious and
return movements. This type of operation is suitable for, for example, a job where
workpieces to be supplied are located in one position and a moving body picks up
the workpieces and positions them little by little at a certain interval.
When start signal 0000 is set to ON, a moving body moves to point 1, returns to the
start position, moves to point 2, and then returns to the start position again. After-
wards, the moving body moves to point 3, then returns to the start position, output
05000 remains ON for 3 seconds, and then the operation is finished.
I Program example
5000
0
5000
500
500
Speed (Hz)
Point 3: 14,000
Point 1: 10,000
Coordinate (pulses)
Point 2: 12,000
#00000
DW
#03000
DW
#05000
DW
#00500
DW
DM1485 DM1482 DM1481 DM1480
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
1000
SET
0000
#10000
DM1484
DW
2310 1001
J MP
1000
STG
0503
SET
#12000
DM1484
DW
2310 1003
J MP
1002
STG
0503
SET
1100 2310 1002
J MP
1001
STG
2309
1100
1102 2310 1004
J MP
1003
STG
0503
RES
2309
1102
1104 2310 1006
J MP
1005
STG
0503
RES
2309
1104
1101 2309
1101
2310 1005
J MP
1004
STG
0503
SET
1103 2309
1103
1201 2309
1201
1200 2309
1200
1203 2309
1203
1202 2309
1202
1204 2309
1204
END
ENDH
0500 #00030
T000
T000 1105
ENDS
1006
STG
2309
1105
#14000
DM1484
DW
0503
RES
Ladder for automatic operation
Point 1: 10,000 Point 2: 12,000 Point 3: 14,000
Moves to point 1.
Returns from point 1.
Moves to point 2.
Returns from point 2
Moves to point 3.
Returns from point 3.
When operation has completed, output 500 remains ON for 3 seconds.
5.3 Examples of Using the Positioning Control Function
V
i
s
u
a
l

K
V
S
e
r
i
e
s
5
Chapter 5 Positioning Control
3-262
Ladder example of a return to the zero point
A return to the zero point is performed.
When start signal 0000 turns ON, the machine moves at a high speed in the CCW
direction. When the zero point sensor turns ON, the machine decelerates, moves at
a low speed in the CW direction, then stops in the position at which the zero point
sensor turns OFF (at the end of the CW direction).
I Program example
Range detected by
zero point sensor
Low speed
Forced stop
Start
Deceleration
and stop
High-speed
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
2008
2002
EI
1005
SET
HSP
0003
#65535
DW
#00000
DW
#00500
DW
#10000
DW
#00500
DM1484 DM1485 DM1482 DM1481 DM1480
DW
0503
RES
2413
RES
1006
RES
2309
RES
1000
DIFU
0000 1000 2309
1007
DIFU
1005 1007 2309
0503
SET
2413
SET
#65535
DW
#00000
DW
#00500
DW
#10200
DW
#00200
DM1484 DM1485 DM1482 DM1481 DM1480
DW
1006
1006
2309
2310
1006
END
INT
0003
1005
RES
1006
SET
2308
SET
1005
RETI
ENDH
2308
RES
Return to zero point
Zero point sensor: 0003 Start signal: 0000 Pulse output: 0502
Rotation direction: 0503
Initial setting
Moves at high speed in the CCW direction.
When the zero point sensor turns ON, moves at low speed in the CW direction.
Detects the rising/falling edge of the zero point sensor (003), stops, and
then changes direction.
5.3 Examples of Using the Positioning Control Function
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
5
Chapter 5 Positioning Control
3-263
Ladder example of an automatic operation (continuous operation with wait status)
In automatic operation, wait status is realized at each point.
When start signal 0000 turns ON, the machine moves to point 1 and stops there. At
the rising edge of wait status reset switch 1, the machine automatically moves to
point 2 and stops there. At the rising edge of waiting status reset switch 1, the
machine automatically moves to point 3. When the machine reaches point 3, output
0500 remains ON for 3 seconds and the operation is finished.
I Program example
0 250000 460000 320000
500
5000
10000
7000
Speed (Hz)
Wait Wait
Coordinate
(pulses)
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
1000
SET
0000
1400
#00500
DM1480
DW
#01000
DM1481
DW
#01000
DM1482
DW
#00003
DM1485
DW
#53392
DM1484
DW
2310 1001
J MP
#05000
DM1481
DW
#01000
DM1482
DW
#00001
DM1485
DW
#04464
DM1484
DW
2310 1002
J MP
1000
STG
0503
SET
0503
SET
#07000
DM1481
DW
0503
SET
1001
STG
2309
1400
1301 0001
1301
1401
#01000
DM1482
DW
#00002
DM1485
DW
#08928
DM1484
DW
0500
2310 1003
J MP
#00030
T000
1002
STG
2309
1401
1303
T000
0001
1303
1305
ENDS
1003
STG
2309
1305
END
ENDH
1300 2309
1300
1302 2309
1302
1304 2309
1304
Ladder for automatic operation (continuous operation with wait status)
Start signal: 0000 Pulse output: 0508 Rotation direction: 0503
Wait reset switch: 0001
Moves to point 1 at speed of 10 kHz. Acceleration/deceleration time: 1 second
Moving quantity: 250,000 pulses
Moves to point 2 at speed of 5 kHz. Acceleration/deceleration time: 1 second
Moving quantity: 70,000 pulses
Moves to point 3 at speed of 7 kHz. Acceleration/deceleration time: 1 second
Moving quantity: 140,000 pulses
When operation has completed, output 500 remains ON for 3 seconds.
5.3 Examples of Using the Positioning Control Function
V
i
s
u
a
l

K
V
S
e
r
i
e
s
5
Chapter 5 Positioning Control
3-264
2008
EI
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
1100
DIFU
1101
DIFU
#00000
DW
#00001
DW
#00100
DW
#04000
DW
#00600
DM1484 DM1485 DM1482 DM1481 DM1480
DW
1200
RES
0503
RES
0008 0009
0008
2309 0006
1103
DIFU
1105
DIFU
0503
SET
0009
1100
0008 0009
2309 0004
1101
2002 HSP
0000
HSP
0002
Ladder example of a pulse motor application circuit
This is a program example which offers control using both automatic and manual
operations.
In automatic operation, when input 000 is set to ON, the following operation is
performed.
In manual operation, the machine moves forward while input 0008 is ON, and moves
backward while input 0009 is ON. When input 0007 is set to ON, the machine
returns to the zero point.
Output 0502 outputs pulses. The rotation direction is changed by an ON/OFF of
0503.
This machine is equipped with a zero-point sensor (0002), a forward limit switch
(0006), and a backward limit switch (0004).
I Program example
0 15000 17500
300
15000
2000
8000
Speed (Hz)
Coordinate
(pulses)
Pulse motor application circuit (with zero point sensor, forward
limit switch, and backward limit switch)
Set the startup frequency,
operating frequency, and
acceleration/deceleration
time for manual operation.
Startup frequency: 600 Hz
Operating frequency: 4 kHz
Acceleration/
deceleration: 100 ms
Number of output pulses:
65,536
Specifications
Pulse output: 0502 Rotation direction: 0503
Forward limit switch: 0006 Backward limit switch: 0004
Manual switch: Forward = 0008, backward = 0009 Zero point switch:
0007
Automatic operation start: 0000
Resets interrupt permission & zero point detection flag.
Manual switch (0008: Forward, 0009: Backward)
5.3 Examples of Using the Positioning Control Function
V
i
s
u
a
l

K
V
S
e
r
i
e
s
1
5
Chapter 5 Positioning Control
3-265
2309
1405
2310
2308
2008 1400
SET
1205
DIFU
0007
#03500
DW
#00000
DW
#00250
DW
#03000
DW
#00300
DM1484 DM1485 DM1482 DM1481 DM1480
DW
1300
DIFU
1205
0006
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
1203
DIFU
#65535
DW
#00000
DW
#00000
DW
#00500
DW
#00500
DM1484 DM1485 DM1482 DM1481 DM1480
DW
0503
SET
1200
SET
1200
1301
DIFU
0503
RES
1200
RES
1203
1408
DIFU
1402
RES
1403
RES
1400
SET
1401
RES
2308
1400
STG
1401
STG
#00010
T001
1500
DIFU
1401
J MP
1402
J MP
0000
1408
1300
1301 0004
1506 2308
1103
1407
RES
T001 1405
2309
1406
1402
STG
#00005
T002
1501
DIFU
1403
J MP
1405
RES
T002 1406
2309
1407
1403
STG
#00005
T003
1502
DIFU
1400
J MP
1406
RES
T003 1407
0009 0006
0004 0008
1105
2309
ON
1201
1201 1202 2309
OFF
1202
2308 2309
Return to zero point
Limit switch
Move forward.
Trigger end of forward movement
While moving backward at low speed, return to zero point.
Start up motor.
Decelerate and stop (in manual/automatic operation).
Automatic operation
Trigger for stage instruction
Automatic start (while 0000 is ON)
When motor operation has finished, moves stage forward.
In a zero-point-return
operation, the machine
moves forward once, and
then backward. When the
zero point limit switch
(0002) turns ON, the
machine stops.
Settings for forward
movement
Startup frequency: 300 Hz
Operating frequency: 3 kHz
Acceleration time: 250 ms
Number of output pulses:
3,500
Settings for backward
movement
Drive frequency: 500 Hz
Operating frequency: 500 Hz
Acceleration time: 0 ms
Number of output pulses:
65,535
Create each operation
program using the STG
instruction, and let each
program be executed in
turn.
Give instructions to start up
and decelerate/stop the
motor.
5.3 Examples of Using the Positioning Control Function
V
i
s
u
a
l

K
V
S
e
r
i
e
s
5
Chapter 5 Positioning Control
3-266
2309
RES
#17500
DW
#00000
DW
#00250
DW
#15000
DW
#00300
DM1484 DM1485 DM1482 DM1481 DM1480
DW
1505
DIFU
0503
RES
1502
1200 0008 0009 0000
1506 1503
END
RETI
ENDH
INT
0002
1504
1505
#15000
DW
#00000
DW
#00150
DW
#08000
DW
#00300
DM1484 DM1485 DM1482 DM1481 DM1480
DW
1503
DIFU
0503
SET
1500
#02500
DW
#00000
DW
#00250
DW
#02000
DW
#00300
DM1484 DM1485 DM1482 DM1481 DM1480
DW
1504
DIFU
0503
SET
1501
0043
0044
0045
0046
0047
0048
0049
0050
0051
0052
0053
0054
0055
0056
Set automatic operation parameters.
Set parameters for auto-
matic operation.
1. Startup frequency: 300 Hz
Operating frequency: 8 kHz
Acceleration time: 150 ms
Number of output pulses:
15,000
2. Startup frequency: 300 Hz
Operating frequency: 2 kHz
Acceleration time: 250 ms
Number of output pulses:
25000
3. Startup frequency: 300 Hz
Operating frequency: 15 kHz
Acceleration time: 250 ms
Number of output pulses:
17,500
Start up motor.
Interrupt for instantaneous stop (to return to zero point)
Stop pulse output at the
zero point by using an
interrupt program.

You might also like