Upload
rrebollar
View
20
Download
0
Embed Size (px)
Citation preview
Chapter 6Interrupts, High-speed Counters,Positioning Control
This chapter describes ramp-up/down control of stepping motors and servo motors.
6.1 Interrupt Instructions .............................................................. 3-2686.1.1 Description of Interrupts ......................................................................... 3-2686.1.2 Interrupt Instructions .............................................................................. 3-271
6.2 Direct Clock Pulse ................................................................... 3-2766.2.1 Output of Direct Clock Pulse .................................................................. 3-276
6.3 Positioning Control ................................................................. 3-2966.3.1 Positioning Control (Ramp-up/down Control) ......................................... 3-296
KV-300, KV-10/80 Series Only
KV-3
00KV
-10/
80
6.1 Interrupt Instructions
KV-3
00KV
-10/
80
3-268
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
6.1 Interrupt Instructions
6.1.1 Description of InterruptsInput processing for routine program and interrupt routine
Routine program flow is shown by the thick arrow on the left of Fig.1. In this case,input signals can be received only during input processing.
Although input time constant can be made shorter by using HSP or by turning ONspecial utility relay 2813, input signals can be received only if they are longer thanthe duration of one scan time.
When an interrupt initiation input turns ON, the currently running program is sus-pended to immediately execute the interrupt routine.
During execution of interrupt routine, input signals shorter than one scan time can bereceived by the PLC.
Note: To execute INT (interrupt initiation instruction), execute EI first to enableinterrupt, then use HSP (time constant: 25 µs) or turn ON special utility relay 2813(time constant: 10 µs) to reduce the input time constant.
Types of interrupt
Interrupt by CTC can be generated when the CTC preset value and CTH currentvalue are equal.
A signal received through any of inputs 0000 to 0003 can generate an interrupt.
Input processing
Output processing
Routine program execution
Interrupt routineexecution
(00000 to 00005)
(00500 to 00503)
Sca
n tim
e
Generation of in
terrupt
Returns to suspended program
at the point of suspension.
Processing of direct inputs
Processing of direct outputs
2008 EI
2813 SET or
2002
HSP0000
EI
2002
Fig. 1
High speed counter comparators CTC0, CTC1, CTC2, CTC3
Input relays 0000, 0001, 0002, 0003
(rising/falling edge selectable)
→
▲▲
6.1 Interrupt Instructions
KV-3
00KV
-10/
80
3-269
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Interrupt priorityIf two or more interrupts are generated at different timings, interrupt routines areexecuted in the order that interrupts are generated.If two or more interrupts are generated simultaneously, interrupt routines areexecuted according to the priority shown below.CTC0 > CTC1 > CTC2 > CTC3 > 0000 > 0001 > 0002 > 0003
* Note that the above priority differs from that for other KV PLCs (KV-10/16/24/40/80).The priority is: 0000 > 0001 > 0002 > 0003 > CTC2 > CTC3 > CTC0 > CTC1.
Note 1: During execution of one interrupt routine, execution of other interrupt rou-tines is inhibited. (One interrupt routine can be executed inside another interruptroutine by inserting EI.)
Note 2: If other interrupts are generated during execution of one interrupt routine,the routines of these interrupts are executed after completion of the first interruptroutine in the order that they are generated. Note that generation of up to 8 levels ofinterrupt nesting or up to 8 individual interrupts can be stored during execution ofinterrupt routine. However, generation of an interrupt is ignored if generation of thesame interrupt has already been stored.
Interrupt routine
• Execute EI to enable interrupt.• Be sure to insert INT between END and ENDH.• Be sure to shorten the input time constant by using HSP or by turning ON special
utility relay 2813.
Instructions that cannot be used in the INT-RETI block
TMR, TMH, TMS, DIFU, DIFD, W-ON, W-OFF, W-UE, W-DE, STG, JMP, ENDS,HKEY, ITVL, @xxxx (instruction), C, UDC, SFT
2008 EI
2813 SET
END
INTXXXXX
RETI
ENDH
6.1 Interrupt Instructions
KV-3
00KV
-10/
80
3-270
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Direct output
Direct output is enabled only through output relays 0500, 0501, 0502, and 0503.This function allows ON/OFF status of any of output relays 0500, 0501, 0502, and0503 to be output during execution of interrupt routine.This function allows immediate ON/OFF status output without delay caused by scantime.
Note: Be sure to turn ON special utility relay 2813 to shorten the input time constant.
Direct input
Direct input is enabled only through input relays 0000 to 0005.This function allows ON/OFF status of any of input relays 0000 to 0005 to be inputduring execution of interrupt routine.
Note 1: Be sure to turn ON special utility relay 2813 to shorten the input timeconstant.
Note 2: Input status read using direct input function is valid only in the interruptroutine. Be sure to insert an internal utility relay after the direct input relay.
2008
EI
2813 SET
END
INT0000
0500
( SET )
RETI
INT0001
ENDH
0500( SET )
2002
2002
2008 2813 SET
END
RETI
ENDH
05001000
INT 0000
10000005
6.1 Interrupt Instructions
KV-3
00KV
-10/
80
3-271
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
6.1.2 Interrupt Instructions
DI: Interrupt Disabled Disables execution of interrupt.
EI: Interrupt Enabled Enables execution of interrupt.
Key operations
Operand
Example
Coding
Description
When 1000 is ON, execution of interrupt is enabled. When 1000 is OFF, executionof interrupt is disabled. Interrupts are enabled between EI instruction and DI instruc-tion.Therefore, once EI is executed, interrupt is enabled until it is disabled by DI.
With the KV, any interrupt is disabled when the operation is started.DI instruction disables execution of interrupt. Use this instruction to temporarilydisable interrupt.EI instruction enables the execution of interrupt. Use this instruction to releaseinterrupt disabled by DI instruction.During execution of an interrupt, any other interrupt is disabled.To execute anotherinterrupt during execution of the previous interrupt, include EI instruction in this firstinterrupt. Interrupts can be nested up to 8 levels by executing EI in each interruptroutine.
Note 1: Generation of up to 8 levels of interrupt nesting or up to 8 individual inter-rupts can be stored while interrupt is disabled. These interrupts are executed after EIhas been executed.
Note 2: Generation of INT CTC is erased from the storage when RES CTC isexecuted.
: DIAND8FNC RES
0
: EISET1FNC ORL
3
ORL3
AND8 ENT
R-SRCH
RES0FNC
SET1FNC
ENTR-SRCH
1000EI
1000DI
Line No. Instruction Operand
0000 LD 1000
0001 EI
: :
0021 LDB 1000
0022 DI
: :
DI / EI
6.1 Interrupt Instructions
KV-3
00KV
-10/
80
3-272
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
INT: Interrupt
RETI: Return Interrupt
Key Operations
Operand
0000 to 0003CTC0 to CTC3
Example 1
Input pulse width shorter than one scan time (eg. one-shot circuit)
Program (a) can be used when input 0000 remains ON longer than the input time constant (8to 12 ms).Program (b) is used when input 0000 remains ON shorter than one scan time.
Routine program coding
: nnnnINT
FNC RES0
ANL2
:RETI
ORL3FNC LDB
4
ENTR-SRCH
RES0
LDB4
ENTR-SRCH
Operand ENTR-SRCH
ENTR-SRCHFNC
FNC
ANL2
ORL3
0000(a)
0000
(Input remains ON for 1 ms or more.)
2008
EI2813SET
0500 0500
#00020 T000
T000
0500 0500
#00020 T000
T000
1000
END
INT0000
RETI
ENDH
10002002
(Input remains ON for 10 µs or more.)
(b)
0000
Input for routine program
Input forinterruptroutine
Executes interrupt between INT and RETIinstructions at rising edge of input specifiedby operand. When 0003 is specified byoperand, the rising or falling edge can beselected for execution of interrupts.
Represents termination of interrupts.
Line No. Instruction Operand
0000 LD 0000
0001 OR 0500
0002 TMR 000 #00020
0003 ANB T000
0004 OUT 0500
INT / RETI
6.1 Interrupt Instructions
KV-3
00KV
-10/
80
3-273
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Interrupt routine coding
Example 2
Features of INT0003
Upon generation of interrupt by INT0003, the CTH1 current value is automaticallytransferred to TM30.Interrupt generated by any of INT0000 to INT0002 is executed at the rising edge ofthe input signal. Interrupt generated by INT0003 can be executed either at the risingor falling edge of the input signal.
In the example program below, pulse width of input 0003 is measured.
Coding
0003Pulse width
ONOFF
2206(OFF) 2206(ON) 2008
1 EI$0000LDA
2200STA
DM0000STA
2002
2206
2206
TM30LDA
TM02STA
TM30LDA
TM02SUB
DM0000STA
CTH12200
END
INT0003
KEEPSET2206
RES
RETI
ENDH
2
3
4
(a)
(b)
Relay No. ON OFF
2206 Executes interrupts at falling edge of Executes interrupts at rising edge ofinput pulse to 0003. input pulse to 0003.
INT / RETI
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0008 OUT 05000001 EI 0009 END0002 CON 0010 INT 00000003 SET 2813 0011 LD 20020004 LD 1000 0012 OUT 10000005 OR 0500 0013 RETI0006 TMR 000 #00020 0014 ENDH0007 ANB T000
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0014 CON0001 EI 0015 STA TM020002 CON 0016 CON0003 LDA $0000 0017 LD 22060004 CON 0018 LDA TM300005 STA 2200 0019 CON0006 CON 0020 SUB TM020007 STA DM0000 0021 CON0008 LD 2002 0022 STA DM00000009 CTH 1 2200 0023 CON0010 END 0024 KEEP 22060011 INT 0003 0025 RETI0012 LDB 2206 0026 ENDH0013 LDA TM30
6.1 Interrupt Instructions
KV-3
00KV
-10/
80
3-274
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
INT / RETI
2008
1 EI2203
2002
2002
CTH10005
END
INTCTC2
RETI
2
4
0000
5
3
CTH1 #05000CTC2 SET
2813
0501
0501
SET RES
SET
RES
ENDH
■ Initial setting• When the operation is started, EI instruction enables interrupts.
• Special utility relays No. 2200 through 2215 are turned OFF. Turning OFF 2203disables CTC2 from resetting the CTH1 current value to 0.
• Turning OFF 2206 allows interrupt to be generated at the rising edge of INT0003.
• The value of DM0000 is reset to "0".
• Turning ON special utility relay 2813 changes the input time constant to 10 µs.
• 1.0-µs internal clock pulses are counted using CTH1.
• INT instruction with 0003 as the operand allows interrupts to be executed.
• When interrupt is generated for the first time, 2206 is OFF. Therefore, program inrung (a) is executed. Then, KEEP turns 2206 ON.
• When interrupt is generated for the second time, 2206 is ON. Therefore, programin rung (b) is executed to calculate the following:
(TM30 at 2nd execution) - (TM30 at 1st execution) = pulse width (unit: 1.0 µs)
The result is stored in DM0000.
Example 3
Interrupt by CTC
Pulses input to 0005 are counted. 0501 is turned ON when the number of pulsesreaches 5,000.
Coding
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0010 LD 20020001 EI 0011 CTH 1 00050002 CON 0012 LD 00000003 SET 2203 0013 RES 05010004 CON 0014 END0005 RES CTH1 0015 INT CTC20006 CON 0016 LD 20020007 CTC 2 #05000 0017 SET 05010008 CON 0018 RETI0009 SET 2813 0019 ENDH
6.1 Interrupt Instructions
KV-3
00KV
-10/
80
3-275
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
INT / RETI
■ Initial setting• When the operation is started, EI instruction enables interrupts.
• Turning ON special utility relay 2203 allows CTC2 to reset the CTH1 currentvalue to 0.
• The CTH1 current value is reset to 0.
• The CTC2 preset value is set to 5000.
• Turning ON special utility relay 2813 changes the input time constant to 10 µs.
• Pulses input to 0005 are counted using CTH1.
• When input 0000 turns ON, output 0501 is reset.
• INT CTC2 is used to execute the interrupt. (Interrupt routine is executed whenthe CTH1 current value and CTC2 preset value are equal.)
• Immediate output to 0501 is performed.
Note 1: When the interrupt is executed, the contact of CTC2 is automatically reset.
Note 2: The operand used for INT instruction is not allowed for use with other INTinstructions.
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-276
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Internal clocks2200(1.0 µs)2201(10.0 µs)2202(100.0 µs)External pulse0005/00070500
Internal clocks2100(1.0 µs)2101(10.0 µs)2102(100.0 µs)External pulse0004/0006
Special utility relay(2103 to 2115)
Special utility relay(2203 to 2215)
INT CTC0INT CTC1
INT CTC2INT CTC3
TM30
Phase A 0004Phase B (0006)
0009 (RESET)
0500
0501
0008 (RESET)
Phase A 0005Phase B (0007)
Control circuit
Control circuit
16-bit high-speed counterCTH0
16-bit high- speed counterCTH1
High-speed counter comparatorCTC0, CTC1
High-speed counter comparatorCTC2, CTC3
6.2 Direct Clock Pulse
6.2.1 Output of Direct Clock PulseOutline of High-Speed Counters
Basic Architecture
The KV-300 CPU has two 16-bit (CTH0, CTH1) double-phase counter, eachequipped with two high-speed counter comparators (CTC0, 1, 2, 3). These counterscan be used as a stepping motor controller or are used to measure pulse width.
Block diagram of high-speed counters
■ Lists of special utility relays for high-speed counters
Utility relays for high-speed counter CTH0
2100 Internal clock (1.0 µs) for CTH0
2101 Internal clock (10.0 µs) for CTH0
2102 Internal clock (100.0 µs) for CTH0
2103 When comparator CTC0 is ON, automatically clears CTH0.1: Yes 0: No
2104 Direct output to 0500 Direct output level to 0500 through comparator1: Disable 0: Enable CTC1 (any one of these is ON)
2105 Turns OFF output to 0500.1: Yes 0: No
2106 Turns ON output to 0500.1: Yes 0: No
2107 Reverses output (toggle) to 0500.1: Yes 0: No
2108 Direct output to 0500 Direct output level to 0500 through comparator1: Disable 0: Enable CTC1 (any one of these is ON)
2109 Turns OFF output to 0500.1: Yes 0: No
2110 Turns ON output to 0500.1: Yes 0: No
2111 Reverses output to 0500 (toggle).1: Yes 0: No
2112 When comparator CTC1 is ON, automatically clears CTH0.1: Yes 0: No
2113 Uses CTH0 in magnification mode.1: Yes 0: No
2114 Selection of magnification mode for CTH01: x 4 0: x 2
2115 Enables external reset for CTH0.1: Yes 0: No
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-277
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Utility relays for high-speed counter CTH1
2200 Internal clock (1.0 µs) for CTH1
2201 Internal clock (10.0 µs) for CTH1
2202 Internal clock (100.0 µs) for CTH1
2203 When comparator CTC2 is ON, automatically clears CTH1.1: Yes 0: No
2204 Direct output to 0501 through comparator CTC21: Enable 0: Disable
2205 Direct output level to 0501 through comparator CTC21: ON 0: OFF
2206 Selection of INT3 edge0: UP edge 1: DOWN edge
2207 Reverse output (toggle) level1: ON 0: OFF
2208 Direct output to 0501 Direct output level to 0501 through comparator1: Disable 0: Enable CTC3 (any one of these is ON)
2209 Turns OFF output to 0501.1: Yes 0: No
2210 Turns ON output to 0501.1: Yes 0: No
2211 Reverses output (toggle) to 0501.1: Yes 0: No
2212 When comparator CTC3 is ON, automatically clears CTH1.1: Yes 0: No
2213 Uses CTH1 in magnification mode.1: Yes 0: No
2214 Selection of magnification mode for CTH11: x 4 0: x 2
2215 Enables external reset for CTH1.1: Yes 0: No
For KV-10/80 users
1. KV-10/80 has one 8-bit (CTH0) and one 16-bit (CTH1) single phase counter.
2. Internal clocks are as follows:
3. Special utility relays of 2112, 2113, 2114, 2115, 2212, 2213, 2214, and 2215are not available.
2100 0.8 µs 2200 0.4 µs
2101 6.4 µs 2201 0.8 µs
2102 102.4 µs 2202 3.2 µs
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-278
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
■ High-speed counter and counter comparatorsHigh-speed counter (CTH1)CTH1 is a 16-bit hardware counter that counts from 0 to 65535.
• You can specify the operands listed in the table below as the count input.• You can specify one operand from the table below.• Operand cannot be modified externally during execution of the program.• When the external pulse (0004, 0005) is selected, CTH1 is used as a High-speed
counter with a response frequency of 30 kHz.*• When one of the internal clocks (2100 to 2102, 2200 to 2202) is selected, CTH1
is used as a High-speed timer.• When the external pulse 0500 is selected as input to CTH1, CTH1 can count
direct clock pulses generated by CTH0.
* KV-10/80: 10 kHz
■ High-speed counter comparator (CTC)
High-speed counter comparators (CTC) is used only for High-speed counters (CTH).When the current value of CTH reaches the preset value of one of the comparators(CTC), the comparator turns ON.At the contact of High-speed counter comparator (CTC), the level of output (0500,0501) can be changed (directly output) through hardware or an interrupt can begenerated. To change the level of output 0500 and 0501, set the desired value (ON/OFF) to special utility relays 2103 to 2112, 2203 to 2205, and 2207 to 2212.
The High-speed counters correspond to the High-speed counter comparators asshown in the table below.
Internal Clocks for CTH0 and CTH1
• Each High-speed counter (CTH) has its own internal clock.• The desired clock can be selected by specifying the relay No. as operand for
CTH instruction.• You cannot change the internal clock or external pulse during execution of the
program.• Each clock has the following period:
High-speed counter CTH0 CTH1
Operand 2100 22002101 22012102 22020004 0005
0500
Countable range 0 to 65535
High-speed High-speed Range of Output Interruptcounter counter setting value
comparator
CTH0 CTC0 0 TO 65535 0500 INT CTC0
CTC1 INT CTC1
CTH1 CTC2 0501 INT CTC2
CTC3 INT CTC3
High-speed counter CTH0 CTH1 Period
Relay No. 2100 2200 1.0 µs
2101 2201 10.0 µs
2102 2202 100.0 µs
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-279
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
• You cannot change operands of the high-speed counters (CTH) duringexecution of the program. The input time constant of the high-speedcounters is usually set to 25 ms. (The HSP instruction is not required.)
• High-speed pulses can be counted at up to 30 kHz through external inputs(0004 to 0007) by turning ON special utility relay 2813. (Internal pulses canbe counted at up to 50 kHz by turning ON 2813.)*
* KV-10/80 : 10 kHz
Outline of Pulse OutputThe KV PLC can output clock pulses through 0500 and/or 0501 without any delayscaused by scan time. (Through CPU only)Direct clock pulses, used with the high-speed counters, are applicable for varioustypes of production control such as for controlling target positions at desired speed.To perform ramp-up/down control, see "Controlling stepping motors" in Chapter 5.A setting of the clock pulse cycle (frequency) can be changed by the program withinthe allowable range as shown in the table below.
Outline of pulse output
Direct clock pulses are output through 0500 and/or 0501 according to the settings onthe special utility relays when the number of internal clock pulses counted by thehigh-speed counter reaches the preset value of the comparator.
Output example
ON/OFF of output relay 0500/0501 depends on the setting of the special utilityrelay. ➮ Refer to page 3-281.
For KV-10/80 users
CAUTION
Output Internal clock Range of pulse cycle (frequency)
0500 2100 20 µs (50 kHz) to 65.5 ms (15 Hz)
2101 20 µs (50 kHz) to 655.3 ms (1.5 Hz)
2102 200 µs (5 kHz) to 6553.5 ms (0.1 Hz)
0501 2200 20 µs (50 kHz) to 65.5 ms (15 Hz)
2201 20 µs (50 kHz) to 655.3 ms (1.5 Hz)
2202 200 µs (5 kHz) to 6553.5 ms (0.1 Hz)
CTH current value (count value)
CTC preset value
ON
OFF
05000501
CAUTION
Model Output Range of pulse cycle
KV-10, 16, 24, 40 500 500 ms to 52.2 ms(2 kHz to 19 Hz)
501 666 ms to 419.4 ms(1.5 kHz to 2.4 Hz)
KV-80 500 50 ms to 52.2 ms(20 kHz to 19 Hz)
501 666 ms to 419.4 ms(1.5 kHz to 2.4 Hz)
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-280
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Pulse period and width
Period and width of the pulse is determined by the period of the internal clock (CTH)used and the preset value of the comparator (CTC).When two counter comparators are used, only the pulse width can be changed whilea constant period is maintained.The following examples illustrate how pulse width and period can be selected:
■ ON/OFF ratio of 1:1Pulse width (ms) = CTC0 preset value x internal clock (ms)Pulse period (ms) = CTC0 preset value x 2 x internal clock (ms)
• ON/OFF ratio of pulse is 1:1.• Change CTC0 preset value to change the pulse width and period.
■ Variable pulse width
ON/OFF status is set by special utility relays.Pulse width (ms) = CTC1 preset value x internal clock (ms)Pulse period (ms) = CTC0 preset value x internal clock (ms)
• Change CTC1 preset value to change the pulse width.• Change CTC0 preset value to change the pulse period.
The pulse width determined as above is used to pulses generated from theKV-300 CPU.Pulses are output through the output circuit. The pulse width varies depend-ing on the response delay from the output circuit and influence of the con-nected load. Before setting the pulse width, you should measure the actualwaveform using an oscilloscope. (Use pulses with variable pulse width.)
• To obtain the pulse cycle from frequency, use the following expression:Pulse cycle (µs) = 1000 ÷ Frequency (kHz)
ON
OFFPulse width
Pulse period
ON/OFF status is set special utility relays
ON
OFF
Pulse period
ON/ OFF status is set by special utility relays
Pulse width
CAUTION
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-281
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
CTH0 value
ONOFF
CTC0
CTH0 value
ONOFF
CTC0CTC1
Special utility relay settings and output statuses
■ 16-bit high-speed counter (CTH0) and special utility relays (2103 to 2112)By setting the special utility relays 2104 to 2112 at startup or changing these relaysduring generation of clock pulse, you can select ON/OFF of output relay 0500 aslisted below.These special utility relays also allow you to set the pulse cycle and pulse widthand enable or disable the direct output.
• Special utility relay must be ON when clock pulse is generated.
• Only one of relays 2104 to 2107 and one of relays 2108 to 2111 can beturned ON. When two or more of the relays among each group are ON,priority is given to the relay with the smallest No.
• Turning OFF special utility relays 2104 and 2108 enable direct output.Because these relays are factory-set to ON, be sure to set them to OFF.
• ON/OFF status of special utility relays 2104 to 2112 is set using SET andRES instructions or STA instruction.
• Be sure to turn the special utility relay 2103 or 2112 ON to change thepulse width. Turn ON 2103 or 2112 to change the pulse cycle.
• Turn OFF 2105 to start clock pulse output. Turn ON 2105 to stop pulseoutput.
• When special utility relays 2104 and 2108 are turned ON while the directclock pulses are being output, the status of the output relay 0500 is outputand the pulses will be stopped.
■ Timing diagram of 0500 with special utility relay settings
• ON-OFF ratio of 1:1 • Variable pulse widthSettings of special utility relays Settings of special utility relays
CAUTION
2103 ON 2112 OFF
2104 OFF 2108 OFF
2105 OFF 2109 OFF
2106 OFF 2110 OFF
2107 ON 2111 OFF
2103 ON 2112 OFF
2104 OFF 2108 OFF
2105 OFF 2109 ON
2106 ON 2110 OFF
2107 OFF 2111 OFF
Pulse status at CTH0 (current value) = CTC (preset value)
Comparator No. Relay No. Pulse status at ON.
CTC0 2103 Automatically clears current value of CTH0.
2104 Disables output to 0500.
2105 Outputs OFF to 0500
2106 Outputs ON to 0500.
2107 Inverts output to 0500.
CTC1 2112 Automatically clears current value of CTH0.
2108 Disables output to 0500.
2109 Outputs OFF to 0500
2110 Outputs ON to 0500.
2111 Inverts output to 0500.
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-282
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
■ 16-bit high-speed counter (CTH1) and special utility relays (2203 to 2205,2208 to 2212)
By setting the special utility relays 2204 to 2205 and 2208 to 2212 at startup orchanging these relays during generation of clock pulse, you can select ON/OFF ofoutput relay 0501 as listed below.These special utility relays also allow you to set the pulse cycle
• Special utility relay must be ON when clock pulse is generated.
• Only one of relays 2208 to 2211 can be turned ON. When two or more of therelays among each group are ON, priority is given to the relay with thesmallest No.
• Turning ON special utility relay 2204 and turning OFF special utility relay2208 enable direct output.
• ON/OFF status of special utility relays 2204 to 2212 is set using SET andRES instructions or STA instruction.
• Be sure to turn the special utility relay 2203 or 2212 ON to change the pulsewidth.
• Turn ON 2203 or 2212 to change the pulse cycle.Turn OFF 2205 to start clock pulse output. Turn ON 2205 to stop pulseoutput.
• When special utility relays 2204 and 2208 are turned ON while the directclock pulses are being output, the status of the output relay 0501 which isused in the program is output and the pulses will be stopped.
Timing diagram of 0501 with special utility relay settings
• Variable pulse width • ON-OFF ratio of 1:1Settings of special utility relays Settings of special utility relays
CTH1 value
ONOFF
CTC2
CTH1 value
ONOFF
CTC2CTC3
CAUTION
2203 ON 2212 OFF
2204 ON 2208 OFF
2205 OFF 2209 OFF
2206 OFF 2210 OFF
2207 ON 2211 OFF
2203 ON 2212 OFF
2204 ON 2208 OFF
2205 ON 2209 ON
2206 OFF 2210 OFF
2207 OFF 2211 OFF
Pulse status at CTH1 (current value) = CTC (preset value)
Comparator No. Relay No. Pulse status at ON.
CTC2 2203 Automatically clears current value of CTH0.
2204 Disables output to 0501.
2205 Outputs OFF to 0501
2207 Inverts output to 0501.
CTC3 2212 Automatically clears current value of CTH0.
2208 Disables output to 0501.
2209 Outputs OFF to 0501
2210 Outputs ON to 0501.
2211 Inverts output to 0501.
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-283
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Calculating the pulse cycle and comparator setting value
The KV-300 CPU supports clock pulse output at maximum frequency of 50 kHz.Obtain the pulse cycle for clock pulse output and comparator setting value from thefollowing expressions:• Pulse cycle
Pulse cycle (µs) = 1000 ÷ Frequency (kHz)• For pulse with 1:1 ON/OFF ratio (using one comparator)
CTC setting value = Pulse cycle (µs) ÷ Internal clock (µs) ÷ 2
• For pulse with variable pulse width (using two comparators)CTC setting value for pulse width = Pulse width (µs) ÷ Internal clock (µs)CTC setting value for pulse cycle = Pulse cycle (µs) ÷ Internal clock (µs)
Range of CTC setting based on internal clock
• When setting 2100 or 2200 for the operand of High-speed counter CTH, set10 or greater value to CTC. Otherwise, clock pulse is not correctly output.
• The pulse width varies depending on the influence of the connected load.Before setting the pulse width, you should measure the actual waveformusing an oscilloscope.
• When generating clock pulse using CTC0 and CTC1, or CTC2 and CTC3,do not set the same value to CTC0 and CTC1, or CTC2 and CTC3. If settingthe same value, clock pulse is output at the double clock cycle.
➮ * Refer to page 3-276.
ON
OFFPulse width
Pulse cycle
ON
OFFPulse width
Pulse cycle
CAUTION
Special utility relay (Internal clock) Cycle * CTC setting range
2100 2200 1.0 µs 10 to 65535
2101 2201 10.0 µs 1 to 65535
2102 2202 100.0 µs 1 to 65535
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-284
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Examples of Pulse OutputThe following sample explains how to program the pulse output.
Example of clock pulse with 1:1 ON/OFF ratio
■ When outputting clock pulse with cycle 1 ms (1 kHz) from 0500
This program example shows how to output clock pulse with 1:1 ON/OFF ratio from0500, through High-speed counter CTH0 and High-speed counter comparatorCTC0.
Setting special utility relaysSpecial utility relays 2103 to 2112 are set as shown on the right table.The program can be simplified using reverse output (toggle) for pulse with 1:1 ON/OFF ratio.
Values set to the internal clock and CTC0
After the internal clock is determined, the CTC0 setting value is calculated from thefollowing expression.
CTC0 setting value = Pulse cycle (µs) ÷ Internal clock (µs) ÷ 2Assign 1 ms to pulse cycle and 10 µs (2101: special utility relay) to internal clockand calculate the CTC0 setting value.The calculated result is "50".CTC0 values calculated based on other internal clocks are listed below for yourreference.
Programming example
• The status of output 0500 is set by turning ON one of the relays 2104 to 2107 atthe beginning of the program. In Example, output of direct clock pulses to 0500 isenabled, and the status of output 0500 is inverted each time CTH0 = CTC0.
• Turns ON special utility relay 2103 and specifies to clear CTH0 using CTC0. Theprogram repeats clearing the CTH0 current value with the value set to CTC0.
• Resetting the current value of CTH0 at the beginning of the program allows directclock pulses of specified width to be output starting from the 1st pulse.
• Input relay which enables CTH0 remains ON during clock pulse output.
➮ * Refer to page 3-276.
Special utility relay Internal clock* CTC0 value
2100 1.0 µs 500
2101 10.0 µs 50
2102 100.0 µs 5
2008
SET
2103 2104 2105 2106 2107
2002
0001
0002
0003
CTH0
2101
RES RES RES SET RES
CTH0
CTC0#00050
CTH0 value
ONOFF
CTC0
Relay No. Setting Relay No. Setting
2103 ON 2112 OFF
2104 OFF 2108 OFF
2105 OFF 2109 OFF
2106 OFF 2110 OFF
2107 ON 2111 OFF
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-285
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
0000 2105
0000
SET
2105
RES
0000
21050000
SET
RES
KEEP
KEEP InstructionsSET/RES Instructions
Coding
Line No. Instruction Operand
0000 LD 2008
0001 SET 2103
0002 CON
0003 RES 2104
0004 CON
0005 RES 2105
0006 CON
0007 RES 2106
0008 CON
0009 SET 2107
0010 CON
0011 RES CTH0
0012 LD 2002
0013 CTH 0 2101
0014 CTC 0 #00050
When start/stop of clock pulse is controlled by the input relay which enables/disables the high-speed counter, response relay of up to 1 scan is generatedat start. Also, the same response relay is generated at stop, which may stopclock pulse output while the output relay is still ON.
This controls clock pulse so that it always starts and stops when 2105 turns OFF.Turn ON/OFF special utility relay 2105 as required to enable or disable output ofdirect clock pulses using one of the external clocks. Use SET and RES instructionstogether or only KEEP instruction to turn ON/OFF this relay.The diagram below can be added to the sample diagram so that direct clock pulsesare output through 0500 only when 0000 is ON.
CAUTION
■ When outputting clock pulse with cycle 1 ms (1 kHz) from 0501
This program example shows how to output clock pulse with 1:1 ON/OFF ratio from0501, through high-speed counter CTH1 and high-speed counter comparator CTC2.
Setting special utility relays
Special utility relays 2203 to 2212 are set as shown on the right table.The program can be simplified using reverse output (toggle) for pulse with 1:1 ON/OFF ratio.
Relay No. Setting Relay No. Setting
2203 ON 2212 OFF
2204 OFF 2208 OFF
2205 OFF 2209 OFF
2206 OFF 2210 OFF
2207 ON 2211 OFF
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-286
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Values set to the internal clock and CTC2After the internal clock is determined, the CTC2 setting value is calculated from thefollowing expression.
CTC2 setting value = Pulse cycle (µs) ÷ Internal clock (µs) ÷ 2Assign 1 ms to pulse cycle and 10 µs (2201: special utility relay) to internal clockand calculate the CTC2 setting value.The calculated result is "50".CTC2 values calculated based on other internal clocks are listed below for yourreference.
➮ * Refer to page 3-276.
Programming example
• The status of output 0501 is set by turning ON one of the relays 2204 to 2207 atthe beginning of the program. In Example, output of direct clock pulses to 0501 isenabled, and the status of output 0501 is inverted each time CTH1 = CTC2.
• Turns ON special utility relay 2203 and specifies to clear CTH1 using CTC2. Theprogram repeats clearing the CTH1 current value with the value set to CTC2.
• Resetting the current value of CTH1 at the beginning of the program allows directclock pulses of specified width to be output starting from the 1st pulse.
• Input relay which enables CTH1 remains ON during clock pulse output.
Coding
Special utility relay Internal clock* CTC0 value
2200 1.0 µs 500
2201 10.0 µs 50
2202 100.0 µs 5
2008
SET
2203 2204 2205 2207
2002
0001
0002
0003
CTH1
2201
SET RES SET RES
CTH1
CTC2#00050
CTH1 value
ONOFF
CTC2
Line No. Instruction Operand
0000 LD 2008
0001 SET 2203
0002 CON
0003 SET 2204
0004 CON
0005 RES 2205
0006 CON
0007 SET 2207
0008 CON
0009 RES CTH1
0010 LD 2002
0011 CTH 1 2201
0012 CTC 2 #00050
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-287
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
0000 2204
0000
SET
2204
RES
0000
22040000
SET
RES
KEEP
KEEP InstructionsSET/RES Instructions
When start/stop of clock pulse is controlled by the input relay which enables/disables the high-speed counter, response relay of up to 1 scan is generatedat start. Also, the same response relay is generated at stop, which may stopclock pulse output while the output relay is still ON.
This controls clock pulse so that it always starts and stops when 2204 turns OFF.Turn ON/OFF special utility relay 2204 as required to enable or disable output ofdirect clock pulses using one of the external clocks. Use SET and RES instructionstogether or only KEEP instruction to turn ON/OFF this relay.The diagram below can be added to the sample diagram so that direct clock pulsesare output through 0501 only when 0000 is ON.
CAUTION
Example of clock pulse with variable ON/OFF ratio
■ When outputting clock pulse with cycle 500 µs (2 kHz) and pulse width200 µs from 0500
This program example shows how to output clock pulse varies ON/OFF ratio from0500, through high-speed counter CTH0 and high-speed counter comparatorCTC0 and CTC1.
Setting special utility relaysSpecial utility relays 2103 to 2112 are set as shown in the table below.
Values set to the internal clock, CTC0 and CTC1
After the internal clock is determined, the CTC0 and CTC1 setting value is calcu-lated from the following expression.CTC1 setting value = Pulse width (µs) ÷ Internal clock (µs)CTC0 setting value = Pulse cycle (µs) ÷ Internal clock (µs)Assign 200 µs to pulse width, 500 µs to pulse cycle and 10 µs (2101: special utilityrelay) to internal clock and calculate the CTC0 and CTC1 setting value.The calculated results of CTC1 and CTC0 are "20" and "50", respectively.Values calculated based on other internal clocks are listed below for your reference.
Special utility relay Internal clock* CTC0 value CTC1 value
2100 1.0 µs 500 200
2101 10.0 µs 50 20
2102 100.0 µs 5 2
➮ * Refer to page 3-276.
Relay No. Setting Relay No. Setting
2103 ON 2112 OFF
2104 OFF 2108 OFF
2105 OFF 2109 ON
2106 ON 2110 OFF
2107 OFF 2111 OFF
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-288
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
When start/stop of clock pulse is controlled by the input relay which enables/disables the high-speed counter, response relay of up to 1 scan is generatedat start. Also, the same response relay is generated at stop, which may stopclock pulse output while the output relay is still ON.
This controls clock pulse so that it always starts and stops when 2105 turns OFF.Turn ON/OFF special utility relay 2105 as required to enable or disable output ofdirect clock pulses using one of the external clocks. Use SET and RES instructionstogether or only KEEP instruction to turn ON/OFF this relay.The diagram below can be added to the sample diagram so that direct clock pulsesare output through 0500 only when 0000 is ON.
By overwriting the setting value of high-speed counter comparator CTC0 using theLDA and STA instructions, you can change the clock pulse cycle (frequency).➮ Refer to "Example of pulse output "on page 3-293.
CAUTION
Programming example
2008
SET2103 2104 2105 2106
2002
0001
0002
0003 2101
RES RES SET RES
CTH0
CTC0#00050
0004
0005
RES2108 2109 2110 2111 CTH0
SET RES RES RES
2107
CTC1#00020
CTH0 value
ONOFF
CTC0CTC1
• The status of output 0500 is set by turning ON one of the relays 2104 to 2107and 2108 to 2111 at the beginning of the program. In Example, output of directclock pulses to 0500 is enabled, and the status of output 0500 is turned ON atCTC0 and is turned OFF at CTC1.
• Turns ON special utility relay 2103 and specifies to clear CTH0 using CTC0. Theprogram repeats clearing the CTH0 current value with the value set to CTC0.
• Input relay which enables CTH0 remains ON during clock pulse output.
Coding
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0013 CON0001 MPS 0014 SET 21090002 SET 2103 0015 CON0003 CON 0016 RES 21100004 RES 2104 0017 CON0005 CON 0018 RES 21110006 RES 2105 0019 CON0007 CON 0020 RES CTH00008 SET 2106 0021 LD 20020009 CON 0022 CTH 0 21010010 RES 2107 0023 CTC 0 #000500011 MPP 0024 CTC 1 #000200012 RES 2108
0000 2105
0000
SET
2105
RES
0000
21050000
SET
RES
KEEP
KEEP InstructionsSET/RES Instructions
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-289
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
■ When outputting clock pulse with cycle 500 µs (2 kHz) and pulse width 200µs from 0501
This program example shows how to output clock pulse with variable ON/OFF ratiofrom 0501, through High-speed counter CTH1 and High-speed counter comparatorCTC2 and CTC3.
Setting special utility relays
Special utility relays 2203 to 2212 are set as shown on the right table.
Relay No. Setting Relay No. Setting
2203 ON 2212 OFF
2204 ON 2208 OFF
2205 ON 2209 ON
2206 OFF 2210 OFF
2207 OFF 2211 OFF
Values set to the internal clock and CTC2 and CTC3After the internal clock is determined, the CTC2 and CTC3 setting value is calcu-lated from the following expression.CTC3 setting value = Pulse width (µs) ÷ Internal clock (µs)CTC2 setting value = Pulse cycle (µs) ÷ Internal clock (µs)Assign 200 µs to pulse width, 500 µs to pulse cycle and 10 µs (2201: special utilityrelay) to internal clock and calculate the CTC2 and CTC3 setting value.The calculated results of CTC3 and CTC2 are "20" and "50", respectively.Values calculated based on other internal clocks are listed below for your refer-ence.
Special utility relay Internal clock* CTC2 value CTC3 value
2100 1.0 µs 500 200
2101 10.0 µs 50 20
2102 100.0 µs 5 2
➮ *Refer to page 3-276.
Programming example
2008
SET2203 2204 2205
2002
0001
0002
0003 2201
SET SET RES
CTH1
CTC2#00050
0004
0005
RES2208 2209 2210 2211 CTH1
SET RES RES RES
2207
CTC3#00020
CTH1 value
ONOFF
CTC2CTC3
• The status of output 0501 is set by turning ON one of the relays 2204 to 2207and 2208 to 2211 at the beginning of the program. In Example, output of directclock pulses to 0501 is enabled, and the status of output 0501 is turned ON atCTC2 and is turned OFF at CTC3.
• Turns ON special utility relay 2203 and specifies to clear CTH1 using CTC2.The program repeats clearing the CTH1 current value with the value set toCTC2.
• Input relay which enables CTH1 remains ON during clock pulse output.
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-290
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
0000 2204
0000
SET
2204
RES
0000
22040000
SET
RES
KEEP
KEEP InstructionsSET/RES Instructions
Relay No. Setting Relay No. Setting
2103 ON 2112 OFF
2104 OFF 2108 OFF
2105 OFF 2109 ON
2106 ON 2110 OFF
2107 OFF 2111 OFF
Special utility relay Internal clock* CTC0 value CTC1 value
2100 1.0 µs 500 200
2101 10.0 µs 50 20
2102 100.0 µs 5 2
When start/stop of clock pulse is controlled by the input relay which enables/disables the high-speed counter, response relay of up to 1 scan is generatedat start. Also, the same response relay is generated at stop, which may stopclock pulse output while the output relay is still ON.
This controls the clock pulse so that it always starts and stops when 2205 turnsOFF.
Turn ON/OFF special utility relay 2205 as required to enable or disable output ofdirect clock pulses using one of the external clocks. Use SET and RES instructionstogether or only KEEP instruction to turn ON/OFF this relay.The diagram below can be added to the sample diagram so that direct clock pulsesare output through 0501 only when 0000 is ON.
By overwriting the setting value of high-speed counter comparator CTC2 using theLDA and STA instructions, you can change the clock pulse cycle (frequency).
Example of stopping clock pulse after reaching the specified output pulse count
The following example stops clock pulse having the pulse width of 200 µs which isoutput from 0500 at cycle of 500 µs (2 kHz) after reaching the pulse count value of10000.
■ Setting special utility relay, internal clock, and CTC
Settings of the special utility relays, internal clock, CTC0, and CTC1 are listedbelow.
CAUTION
Coding
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0012 SET 22090001 MPS 0013 CON0002 SET 2203 0014 RES 22100003 CON 0015 CON0004 SET 2204 0016 RES 22110005 CON 0017 CON0006 SET 2205 0018 RES CTH10007 CON 0019 LD 20020008 RES 2207 0020 CTH 1 22010009 MPP 0021 CTC 2 #000500010 RES 2208 0022 CTC 3 #000200011 CON
➮ *Refer to page 3-276.
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-291
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Programming example
2008
SET2103 2104 2105 2106
2002
0001
0002
0003
2101
RES SET SET RES
CTH0
CTC0#00050
0004
0005
RES2108 2109 2110 2111 CTH0
SET RES RES RES
2107
CTC1#00020
END
INTCTC2
2002SET2105
RET1
ENDH
SET2203 2813
SET
2105RES
CTH1RES
EI
0000 1000DIFU
1000
0006
00072002
0500CTH1
CTC2#10000
0008
0009
0010
0011
0012
0013
0014
• Sets pulse output to 0500 using special utility relays 2104 to 2107 and 2108 to2111.The example on the left sets special utility relays to enable direct output to 0500(2104: OFF), and turn 0500 output ON at CTC0 (2106: ON) and OFF at CTC1(2109: ON).
• Turns ON special utility relay 2103 to clear CTH0 using CTC0. This allows outputwith correct clock pulse width starting from the 1st pulse.
• Enables interrupt using the EI instruction.Stops clock pulse using interrupt program (INT CTC2) when the current value ofHigh-speed counter CTH1 reaches the setting value of high-speed countercomparator CTC2 (when 10000 pulses are output).
• Turns ON special utility relay 2203 to clear CTH1 using CTC2. This allowsprogram to operate repeatedly at the specified pulse count (10000 pulses).
• Always turns ON 2813 when counting pulses using high-speed counter CTH1.
• Input relay which enables CTH0 remains ON during clock pulse output.
• Input relay which enables CTH1 remains ON during clock pulse counting.
• Specifies internal clock (2101) for clock input of high-speed counter CTH0.Specifies 0500 for clock input of high-speed counter CTH1. Then, CTH0 is usedfor clock pulse output and CTH1 is used for clock pulse counting.
• Sets the clock pulse count using the setting value of high-speed counter com-parator CTC2.
• Turns ON input relay 0000 to start clock pulse output.To restart clock pulse output after once stopped, turns ON input relay 0000again.
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-292
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
2008
SET2103 2104 2105 2106
RES SET SET RES
RES2108 2109 2110 2111 CTH0
SET RES RES RES
2107
SET2203 2813
SETCTH1RES
EI
2008 2203 2813RES SET SET RES
CTH1EI LDA STA
$0268 $2100 CTH0
0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0Internal register
[0] [2] [6] [8]
15 14 13 12 11 10 09 08 07 06 05 04 03 02 01 00
0 0 0 0 0 0 1 0 0 1 1 0 1 0 0 0Special utility relays 21**
Coding
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2008 0024 SET 2203
0001 EI 0025 CON
0002 CON 0026 SET 2813
0003 MPS 0027 CON
0004 SET 2103 0028 RES CTH1
0005 CON 0029 LD 0000
0006 RES 2104 0030 DIFU 1000
0007 CON 0031 CON
0008 SET 2105 0032 AND 1000
0009 CON 0033 RES 2105
0010 SET 2106 0034 LD 2002
0011 CON 0035 CTH 0 2101
0012 RES 2107 0036 CTC 0 #00050
0013 MRD 0037 CTC 1 #00020
0014 RES 2108 0038 LD 2002
0015 CON 0039 CTH 1 0500
0016 SET 2109 0040 CTC 2 #10000
0017 CON 0041 END
0018 RES 2110 0042 INT CTC2
0019 CON 0043 LD 2002
0020 RES 2111 0044 SET 2105
0021 CON 0045 RETI
0022 RES CTH0 0046 ENDH
0023 MPP
Special utility relays 2103 to 2111 can be set to turn ON or OFF using LDA and STAinstructions as well as SET and RES instructions. Example below illustrates howone program can be made shorter using LDA and STA instructions.
• LDA $0268
When LDA $0268 is executed, the following data is input to the internal register.
Internal registerWhen STA 2100 is executed, the data in the internal register is assigned to 16special utility relays starting from 2100 to 2115.
Thus, 2103, 2105, 2106, and 2109 are ON.
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-293
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
COM00000001
0500050105020503
1112
789
10COM 20
24 VDC–
+KV-300
FG
Twisted pair cable
CW (pulse)
CCW (rotating direction)
Stepping motor driver
Stepping motor
Star
t
Rev
erse
24 VDC
– +
0
fH(DM0000)
fL(DM0001)
Frequency (Hz)
Acceleration rate
(DM0002)
10 msAcceleration change time
Positioning pulse total count (DM0003)
Acceleration time Constant rate time
Deceleration timeTime (ms)
CAUTION
Example of pulse output (Ramp-up/down control)
The following example performs ramp-up/down control as shown below by setting 4parameters (DM0000 to DM0003).
Connection exampleThe following chart shows an operation example when the KV-300 CPU is con-nected to the stepping motor driver. See the stepping motor driver instructionmanual for details.Set the pulse input mode of the stepping motor driver to "1 pulse input mode".
Setting parameters
DM0000: fH [Hz] (Run frequency) ➞ 153 Hz to 50000 Hz fH must be greater thanfL.DM0001: fH [Hz] (Start frequency)DM0002: Acceleration rate [Hz/10 ms] ➞ (fH-fL) ÷ (Acceleration time ÷ 10 ms)DM0003: Positioning pulse count ➞ 65534 pulses max.
• Although smoother trapezoidal control can be obtained by setting a smalleracceleration rate, the acceleration time is extended.
• Be sure to turn OFF input relay 0007 (phase B input).
Operation
This program sets the parameters as below:DM0000 = 8000 [Hz], DM0001 = 700 [Hz], DM0002 = 400 [Hz/10 ms], DM0003 =4000 pulsesThe program performs trapezoidal control as shown above when start switch 0000 ispressed, and stops control when pulse count reaches 4000.The program restarts operation by re-pressing the start switch. It performs reverseoperation while reverse switch 0001 is ON.
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-294
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
2002
INITIAL SETUP FOR HIGH-SPEED COUNTER/COMPARATOR
#00010CTC1
#65535CTC0
CTH02100
#65535CTC2
#65535CTC3
CTH10500
2008 #08000DW
DM0000
#00700DW
DM0001
#00400DW
DM0002
#04000DW
DM0003
(SET ) (SET )2813 2105
STARTS POSITIONING
0003 0000 1001 DIFU
1001
$0268LDA
2100STA
01 CALL (SET ) (RES )
1200 CTH1(RES )
CTH0(RES )EI2105
0001( )0502
EMERGENCY STOP
0003(SET)2105
END
CTC0,CTC2,DM0011, CALCULATION SUBROUTINE
SBN02
2002 #01000LDA
#10000MUL
DM0012DIV
#00005ADD
#00010DIV
CTC0STA
DM0010STA
#00010LDA
#10000MUL
DM0010DIV
#00005ADD
#00010DIV
DM0011ADD
CTC2STA
DM0011STA
INITIALIZING SUBROUTINE
RET
SBN01
DM0003LDA
CTC3STA
#00002DIV
DM0004STA
DM0001LDA
DM0012STA
#00000DW
DM0011
2002 02 CALL
RAMP UP/DOWN CHECK ROUTINE
SBN03
RET
DM0012LDA
#00100DIV
DM0011ADD
DM0004CMP
2002
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
0024
Generates clock pulse through high-speed counter CTH0.
Counts clock pulese through high-speed counter CTH1.• CTC0: Pulse cycle
CTC1: Pulse width• CTC2: Frequency change point
CTC3: Positioning pulse totalcount
Sets parameters (DM0000 toDM0003).
Reverse output
Emergency stopSets CTC0.Setting value of CTC0 = 1 ÷ DM0012 x 103 x 103 ÷ 6.4
Sets CTC2.• DM0010: Pulse cycle T (µs) x 10• DM0011: Accumulated pulse count• DM0012: Current frequency f [Hz]• 1200: Acceleration flag
Programming exmaple
6.2 High-speed Counters
KV-3
00KV
-10/
80
3-295
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
RET
0025
INTERRUPT ROUTINE FOR SPEED-UP/SLOW-DOWN
INTCTC2
SPEED-UP
DM0012LDA
DM0002ADD
DM0012STA
DM0000CMP
1200 2011 03 CALL
2011 02 CALL
2011( )1201
2011 DM0003LDA
DM0011SUB
CTC2STA
DM0011STA
1201(RES )1200
SPEED-UP
DM0012LDA
DM0002SUB
DM0012STA
DM0001CMP
1200 2011 02 CALL
2011 02 CALL
#65535LDA
CTC2STA
RETI
RETI
ENDH
INTERRUPT FOR PULSE STOP
INTCTC3
2002(SET )2105
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
Adds the acceleration rate to thecurrent frequency to changefrequency whenever CTC2 turnsON while acceleration flag 1200 isON. When the current frequencyreaches fH, stops acceleration andsets the deceleration pulse count.
Subtracts the acceleration rate fromthe current frequency to changefrequency whenever CTC2 turnsON while acceleration flag 1200 isOFF. When the current frequencyreaches fL, stops deceleration andinitializes the settings.
When pulse count of clock pulsesequals the setting value of CTC3,stops clock pulse output.
6.3 Positioning Control
KV-3
00KV
-10/
80
3-296
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
6.3 Positioning Control
6.3.1 Positioning Control (Ramp-up/down Control)Outline of positioning control
The KV-300 CPU outputs clock pulses, independent of scan time, directly throughoutput relay 0500 or 0501. When the clock pulse frequency, output pulse count, andacceleration/deceleration time are set to the data memory addresses in advance,the KV-300 CPU automatically performs ramp-up/down control. Output frequencycan be set within the range of 153 Hz to 50000 Hz.
With this function, ramp-up/down control over stepper motors and AC servo motors(pulse input type) becomes possible.The following section describes setting and application of positioning controlparameters.
Acceleration time Deceleration time Time (ms)
Frequency (Hz)
Operation
StartOutput pulse count
Stepping motor/servo motor
Motor driver
Clock pulse
Rotation direction
Lo : CWHi : CCW
KV-300
05000501
05020503
6.3 Positioning Control
KV-3
00KV
-10/
80
3-297
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Run
Start
Acceleration/ deceleration time
∆t
Setting and application of parametersThis section describes how to set and apply parameters for positioning control.
Setting parameters
Set the parameters to the assigned data memory addresses. To operate thepositioning control function, the special utility relays must be set. ➮ Refer to page 3-299.
The following table shows the parameters and assigned DM Nos.
Note: Refer to the following expression to determine the output pulse count.
Output pulse count < (65535 x pulse change cycle [ms]) ÷ (1000 x run frequency[Hz])
■ Pulse change cycle (∆t)
The pulse change cycle is the cycle in which the output clock pulse frequency ischanged for acceleration or deceleration. The pulse change cycle is obtained fromone of the following expressions, whichever produces the smaller solution. However,when the start pulse is less than 500 Hz, the pulse change cycle becomes 14 ms ormore.
Pulse change cycle (∆t) [ms] = (acceleration time [ms] + 199) ÷ 200 x 4orPulse change cycle (∆t) [ms] = 1000 ÷ (run frequency [Hz] ÷ 1000)
DMNo. Parameter Allowable setting range
DM9407 Set value error code Code 11 to 17 or FFFF (-1)is entered when error occurs
X-axis DM9408 0500 Start frequency (Hz) 153 to 50000
(0500) DM9409 0500 Run frequency (Hz) 153 to 50000
DM9410 0500 Acceleration/deceleration 0 to 4096time (ms)
DM9411 0500 Output pulse count 0 to 65535(high-order 16 bits)
DM9412 0500 Output pulse count 0 to 65535(low-order 16 bits)
Y-axis DM9413 0501 Start frequency (Hz) 153 to 50000
(0501) DM9414 0501 Run frequency (Hz) 153 to 50000
DM9415 0501 Acceleration/deceleration 0 to 4096time (ms)
DM9416 0501 Output pulse count 0 to 65535(high-order 16 bits)
DM9417 0501 Output pulse count 0 to 65535(low-order 16 bits)
6.3 Positioning Control
KV-3
00KV
-10/
80
3-298
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
■ Set value error code
Automatically writes an error code (11 to 17) into DM9407 when a parameter settingerror is found at startup.
■ Corrective action for error code 16Error code 16 is issued when the output pulse count during acceleration/decelera-tion time exceeds other values calculated from the preset parameters.To recover from the error, the following corrective actions are available.• Change the run frequency and/ or the acceleration/ deceleration time according
to the following expression.
Corrective action for error code FFFF (-1)• Reduce run frequency and start frequency.• Reduce accelleration/ deccelleration time.
■ Start frequency (Hz)
Sets a start frequency (speed) to start the motor rotation smoothly during positioningcontrol.
The KV-300 CPU outputs clock pulses at the specified frequency.
■ Run frequency (Hz)
Sets the motor frequency (speed) during positioning control. The KV-300 CPUoutputs clock pulses at the specified frequency.
Note: When the start frequency equals the run frequency, the system operates asshown in the following chart.
Here, the acceleration/deceleration time is ignored. The output count should be lessthan 65535.
0
Preset frequency
Code Error description Corrective action
11 Start frequency is below allowable Adjust start frequency to within allow-range. able range (153 to 50000).
12 Run frequency is below allowable Adjust run frequency to within allow-range. able range (153 to 50000).
13 Run/start frequency exceeds allow- Adjust run/start frequency to withinable range. allowable range (153 to 50000).
14 Start frequency is greater than run Reduce start frequency to less thanfrequency. run frequency.
15 Acceleration/deceleration time Adjust acceleration/deceleration timeexceeds allowable range. to within allowable range (0 to 4096).
16 Too many pulses are output during Change the parameters.acceleration/deceleration time.
17 Too few pulses are output during Set 2 or more as value for outputacceleration/deceleration time. pulse count.
FFFF Other calculation error Change the parameters.
65535Run frequency
x Pulse change cycle x 655351000
6.3 Positioning Control
KV-3
00KV
-10/
80
3-299
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
■ Acceleration/deceleration time (ms)
Sets the time required when the start frequency accelerates to the run frequency atstartup. In the same manner, sets the deceleration time required at stop. The KV-300 CPU controls the clock pulse frequency from the start frequency to the runfrequency within the specified time. The pulse change cycle within the accelerationtime is obtained from one of the following expressions, whichever produces thesmaller solution. However, the pulse change cycle when the start pulse is less than500 Hz becomes 14 ms or more.
Pulse change cycle (∆t) ms = (acceleration time ms + 199) ÷ 200 x 4orPulse change cycle (∆t) ms = 1000 ÷ (run frequency Hz ÷ 1000)
■ Output pulse count
Sets the positioning control rotation angle (moving distance) with the pulse count.The KV-300 CPU outputs as many clock pulses as specified. If the output pulsecount is greater than 65535, set the pulse count separately for high-order 16 bitsand low-order 16 bits based on the following expressions.
(Output pulse count) ÷ 65536 = A (solution) … B (remainder)
A = Output pulse count (high-order 16 bits)B = Output pulse count (low-order 16 bits)
Note: When the specified output pulse count is insufficient and does not reach thetarget value, the KV-300 CPU performs triangular control.
The current pulse output value cannot be checked.
Procedure
When the positioning control function is used, the KV-300 CPU controls start, stop,and emergency stop by turning ON/OFF the utility relays. The table below shows theoperations and assigned utility relays.
0
Run frequency
Start frequency
Relay No. R/W Function Description
0500 0501
2308 2311 W STOP Decelerates at rising (UP) edge and stops.
2309 2312 R RUN Turns ON during pulse output.W RESET Immediately stops when turning ON during
interrupt program.
2310 2313 W START Starts at rising (UP) edge.
6.3 Positioning Control
KV-3
00KV
-10/
80
3-300
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
DM9409
DM9408
0
DM9411DM9412
DM9410DM9410
2310(START)
2309(RUN)
2308(STOP)
COM000000010002
0500050105020503
1112
12
789
10COM 20
24 VDC–
+KV-300
+–+–
FG
24 VDC
– +
Twisted pair cableCW (pulse)
CCW (rotation direction)
Stepping motor driver
Stepping motor
Em
erge
ncy
stop
Sto
pS
tart
■ Operation chart (when 0500 is used)
Note 1: When special utility relay 2310 (2313) is turned ON at start of clock pulse,2309 (2312) turns ON and the clock pulse is output, assuming parameter settingsare correct.
Note 2: If a parameter setting for the X-axis or Y-axis is incorrect, 2309 (2312) doesnot turn ON and an error code is written into DM9407. Check the error code andadjust the parameter setting.
Note 3: By resetting 2309 (2312) within the interrupt program, you can stop theclock pulse immediately. You must reset 2309 within the interrupt program; other-wise, the clock pulse is not stopped.
Note 4: Because the clock pulse is output under software control, the pulse width isextended by 10 µs to 20 µs in the pulse change cycle. Test the clock pulse output onthe KV-300 system before using it in practical applications.
Examples of stepping motor control■ Connection example
The following reference example shows how to connect the KV-300 CPU to astepping motor driver. Refer to the stepping motor driver instruction manual fordetails.Set the pulse input mode for the stepping motor driver to "Pulse input mode 1".
DM9408: Start frequency (Hz)DM9409: Run frequency (Hz)DM9410: Acceleration time (ms)DM9411: Output pulse count
(high-order 16 bits)DM9412: Output pulse count
(low-order 16 bits)
When 2310 turns ON, clock pulse is output.(rising [UP] edge is detected.)2309 is ON during clock pulse output. Whenpulse output is stopped, 2309 turns OFF.When turning ON 2308, clock pulsedecelerates and stops (rising [UP] edge isdetected.)
6.3 Positioning Control
KV-3
00KV
-10/
80
3-301
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
15000 17500
80002000
3000
15000
Ramp-up/down control
When start switch 0002 is turned ON, 0500 outputs 100000 pulses under thefollowing conditions: start frequency 1 kHz, run frequency 5 kHz, and acceleration/deceleration time 3 s.Turn ON 0001 to decelerate and stop pulse output. When 0000 is turned ON, pulseoutput is immediately stopped.
Application example of stepping motor control
Assume a program that can be controlled both automatically and manually.In automatic mode, the system runs as shown in the chart below after 0000 is turnedON.
In manual mode, the system goes forward while 0008 is ON and rearward while0009 is ON. It returns to the origin when 0007 turns ON.A pulse is output from 0500. Reverse the rotation direction by turning ON/OFF 0502.The system is equipped with an origin sensor (0002), forward end limit (0006), andrearward end limit (0004).
0002DW DW DW DW DW
2008EI
#01000 #05000 #03000 #00001 #34464 2310
0001 2308
END
INT0000
2002RES2309
RET1
ENDH
DM9408 DM9409 DM9410 DM9411 DM9412
0001
0002
0003
0004
0005
0006
0007
0008
Enables interrupt when starting operation.This is required to allow emergency stopoperation.
Sets parameters and simultaneouslystarts pulse.Decelerates and stops pulse.
Executes emergency stop sequence withinterrupt progaram.
6.3 Positioning Control
KV-3
00KV
-10/
80
3-302
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023
STEPPING MOTOR CONTROL PROGRAM (ORIGIN, FORWARD, REVERSE LIMITS)
SPECIFICATION
PULUSE OUT==500 FOR/REV=502 ORIGIN=0002 FOR/END=0006 FOR/END=0004
MANUAL SW: FORWARD=0008 REVERSE=0009 ORIGIN SW=0007
AUTO OPERATION START=0000
ENABLES INTERRUPT & RESETS ORIGIN POSITIONING FRAG
MANUAL SWITCHES: FORWARD=0008 REVERSE=0009
LIMIT SWITCHES
FORWARD IN ADVANCE
STOP FORWARDING
POSITIONING ORIGIN WHILE REVERSING SLOWLY
* * * * * * * * * * * * * * * * * * * * * * * * * * ORIGIN * * * * * * * * * * * * * * * * * * * * * * * * * * * *
2008 1200(RES) < EI >
0008 0009 2309 00060502(SET) DIFU
1100
0009 0008 2309 00040502(RES) DIFU
1101
1100
1101
< DW > < DW > < DW > < DW > < DW >1103DIFU
#00600
DM9408
#04000
DM9409
#00100
DM9410
#00001
DM9411
#00000
DM9412
0008 0009 1105DIFU
0007 1205DIFU
1205< DW > < DW > < DW > < DW > < DW >
1300DIFU
#00300
DM9408
#03000
DM9409
#00250
DM9410
#00000
DM9411
#03500
DM9412
0502(SET)
1200(SET)
1203< DW > < DW > < DW > < DW > < DW >
1301DIFU
#00500
DM9408
#05000
DM9409
#00000
DM9410
#00001
DM9411
#00000
DM9412
0502(RES)
1200(RES)
1203DIFU
1200 1201 12022309ON
2309OFF
1201 1202
Program example
Sets start frequency, run frequency,and acceleration/deceleration time.Start frequency: 600 HzRun frequency: 4 kHzAcceleration/deceleration time:100 msOutput pulse count: 65536
To return to the origin, first goesforward and then rearward. Stopswhen origin limit (0002) turns ON.
For forward operation, the followingparameters are set:Start frequency: 300 Hz,Run frequency: 3 kHz,Acceleration/decekeratuib time: 250 ms,Output pulse count: 3500.
For rearward operation, the followingparameters are set:Start frequency: 50 HzRun frequency: 500 HzAcceleration/deceleration time: 0 msOutput pulse count: 65536
6.3 Positioning Control
KV-3
00KV
-10/
80
3-303
16
Chapter 6 Interrupts, High-speed Counters, Positioning Control
0025
0026
0027
0028
0029
0030
0031
0032
0033
0034
0035
0036
0037
0038
0039
0040
0041
0042
0043
0044
0045
0046
0047
SLOW DOWN & STOP (MANUAL/AUTO)
MOVES TO NEXT STAGE AFTER MOTOR STOPS
STARTS MOTOR
* * * * * * * * * * * * * * * * * * * * * * * * AUTO OPERATION CH0 * * * * * * * * * * * * * * * * * * * *
2008 1400(SET)
2308 1401(RES)
T003
1502
2309
1407
< DW > < DW > < DW > < DW > < DW >#00300
DM9408
#15000
DM9409
#00250
DM9410
#00000
DM9411
#17500
DM9412
0502(RES)
1505DIFU
1501< DW > < DW > < DW > < DW > < DW >#00300
DM9408
#02000
DM9409
#00250
DM9410
#00000
DM9411
#02500
DM9412
0502(SET)
1504DIFU
1500< DW > < DW > < DW > < DW > < DW >#00300
DM9408
#08000
DM9409
#00150
DM9410
#00000
DM9411
#15000
DM9412
0502(SET)
1503DIFU
AUTO OPERATION PARAMETER SET
1400JMP
1502DIFU
1403STG
1406(RES)
#00005T003
1407
T002 2309
1406
1403JMP
1501DIFU
1402STG
1405(RES)
#00005T002
1406
T001 2309
1405
1402JMP
1500DIFU
1401STG
1407(RES)
#00010T001
1405
0000 1401JMP
1400STG
1300 0006 2310( )
1301 0004
1103
1506 2308
0006 0009 2308( )
0004 0008
1105
DIFU1408 1402
(RES)1403(RES)
1408
STAGE INSTRUCTION START
AUTO START (OPERATES DURING 0000 IS TURNED ON)
1400(SET)
0024 STARTS MOTOR
0048
0049
0050
0051
0052
0053
0054
INTERRUPT FOR EMERGENCY STOP (POSITIONING ORIGIN)
1503 1506( )
1504
1505
2309( RES )
1200 0008
END
0055
0056ENDH
RETI
0009 0000
INT0002
Instructs motor start and acceleration/deceleration stop.
Creates each of the operation programswith the STG instruction and makes theprograms ready in the specified order.
Sets the parameters for automatic mode.(1) Start frequency: 300 HzRun frequency: 8 kHzAcceleration/deceleration time: 150 msOutput pulse count: 15000(2) Start frequency: 300 HzRun frequency: 2 kHzAcceleration/deceleration time: 250 msOutput pulse count: 2500(3) Start frequency: 300 HzRun frequency: 15 kHzAcceleration/deceleration time: 250 msOutput pulse count: 17500
Stops pulse at the origin with the interruptprogram.
6.3 Positioning Control
KV-3
00KV
-10/
80
3-304
6
Chapter 6 Interrupts, High-speed Counters, Positioning Control
Chapter 7Serial Communication
The KV Series can be connected to an external device with an RS-232C interfaceto establish communication.This chapter describes communications specifications, how to connect the KVSeries to external devices, and how to perform communication.
7.1 Communications Specifications ............................................ 3-3067.1.1 Communications Specification ............................................................... 3-3067.1.2 Connection with the KV Unit .................................................................. 3-3067.1.3 Connecting the KV-300 CPU to a Personal Computer .......................... 3-307
7.2 Serial Communication ............................................................. 3-3087.2.1 Command Transmission Procedure ....................................................... 3-3087.2.2 Format of Commands/Responses ......................................................... 3-3097.2.3 Communication Command/Response List ............................................. 3-3107.2.4 Setting Communication Commands and Responses to Commands ..... 3-3117.2.5 Other Response Codes .......................................................................... 3-3157.2.6 Error Code List ....................................................................................... 3-3167.2.7 Example Program .................................................................................. 3-317
7.3 Loading Text Data .................................................................... 3-3187.3.1 Receiving Text Data ............................................................................... 3-3187.3.2 Transmitting Text Data ........................................................................... 3-3197.3.3 Sample Program .................................................................................... 3-320
7.4 ASCII Code List ........................................................................ 3-321
7.1 Communications Specifications
3-306
7
Chapter 7 Serial Communication
7.1 Communications SpecificationsThis section describes the specifications for the RS-232C interface and the connec-tion between the KV and external devices.
7.1.1 Communications SpecificationThe communications specification of the KV is summarized in the table. Set thecommunications parameters of the personal computer by referring to the table.
Communications parameters
Note 1: Be sure to specify the same communication parameters for the KV and anyexternal devices to be connected. Communication will fail if different parameters areused.Note 2: Refer to the instruction manual supplied with each device when settingcommunications parameters on the device.
7.1.2 Connection with the KV UnitUse the special connection cable (Straight cable: OP-26487, Reverse cable: OP-96607) and a 25-pin D-sub connector (OP-26485) to connect the KV to the RS-232Cconnector of the external device.
Note: The KV-10xx and KV-10/80 Series include only communication port A.
Wiring diagram
The following is the wiring diagram for the RS-232C cable. Be sure to use thespecial connection cable to connect the KV with each device.
Duplex Full
Synchronization Start/stop
Data format ASCII
Baud rate 9,600 bps
Data length 8 bits
Parity check Even
Stop bit length 1 bit
Delimiter CR
External device with RS-232C connector
Communication port ACommunication port B
25-pin D-subconnector
(OP-26485)
Pin assignment forthe KV
KV
Connectioncable
(Reverse:OP-96607)
Device desig-nated as modem
25-pin D-subconnector
(OP-26485)
KV
Connectioncable
(Straight:OP-26487)
Device designatedas terminal
SD 3RD 5SG 4
23
45620
7
SDRD
RSCSDRER
SG
SD 3RD 5SG 4
23
45620
7
SDRD
RSCSDRER
SG
2 31 4 5 6
KV
7.1 Communications Specifications
3-307
17
Chapter 7 Serial Communication
7.1.3 Connecting the KV-300 CPU to a Personal ComputerConnect the KV-300 CPU to the RS-232C port of the personal computer with thesupplied connecting cable (OP-226486/OP-26487).
Recommended pin assignments for the RS-232C communication cable are shownbelow. When connecting the KV-300 CPU, use only the connecting cable supplied.
Standard cable (OP-26486 + OP-26487)
KV-300
Connecting cableStandard cable:OP-26486
9-pin D-SUB femaleconnector: OP-26487 Personal computer with an
RS-232C port
KV-30035
4
23456
207
SDRD
SG
SDRDRSCSDRERSG
35
4
23456
207
SDRD
SG
SDRDRSCSDRERSG5432
Pin assignments forthe KV-300 CPU
DCE KV-300 DTE
35
4
2345678
SDRD
SG
ModularConnector
9-pin D-sub connector
7.2 Serial Communication
3-308
7
Chapter 7 Serial Communication
7.2 Serial CommunicationWhen the KV is connected to a personal computer, the current value or preset valueof timers/counters or contents of data memories in the KV can be loaded to andmodified on the computer.
7.2.1 Command Transmission ProcedureCommands are transmitted from a personal computer to the KV base unit as follows:
■ Transmitting a break signalA break signal is used to initialize the communication buffer and baud rate setting ofthe KV. It is necessary to transmit a break signal of 100 ms or longer to the KVbefore starting communication. Another break signal is unnecessary once thecommunication is established.A break signal must have the waveform shown below.
Note 1: For the first serial communication with a personal computer after the KV-P3E(01) handheld programmer is connected to the KV, or after the "KV IncrediWare(DOS)" or "LADDER BUILDER for KV" programming support software is evoked, besure to transmit a break signal. A break signal is unnecessary at other times.Note 2: If you cannot transmit a break signal, turn OFF the KV once to initialize thecommunication program. After that, restart communication between the KV and thepersonal computer.Note 3: Be sure to stop the communication for 10 ms or longer after transmitting abreak signal.
10 ms or longer
Transmits a command
Transmits communicationsstart command (CR)
Initialize the communication buffer andbaud rate setting of the KV.
Start communications with the KV.
Transmit a command which instructs theKV to perform the required operation.
Transmits communicationsend command (CQ)
End communications with the KV.
▲
▲
▲
▲
Receive and check the response to thetransmitted command.
Transmits a break signal
Receiving a response
▲
▲
100 ms or longer+V
-VSD
7.2 Serial Communication
3-309
17
Chapter 7 Serial Communication
■ Command/response format
"Command" and "response" in communications between the KV and a personalcomputer are defined as follows:
Command: Message transmitted from personal computer to KV
Response: Answer to the command (message from KV to personal computer)
When a personal computer transmits a command to the KV Series basic unit, the KVsends back a response to the personal computer.When creating a program to control the KV using a personal computer, create it sothat the response is checked before the next command is transmitted.
7.2.2 Format of Commands/ResponsesThe formats of commands and responses are as follows:
Command format
Use the following format to transmit commands from the personal computer to theKV. [CR] is a delimiter. The KV ignores [LF] and recognizes the next character after[LF] as the next command.
Response format
The KV sends back a response to the received command in the following format.When creating a program using a personal computer, create it so that the personalcomputer can process the response in this format.
Command
Response
Or
CR
CR LFCommand
CR LF
7.2 Serial Communication
3-310
7
Chapter 7 Serial Communication
7.2.3 Communication Command/Response ListThe following list shows the commands and responses used in serial communica-tion. "_" in the list represents a space.
noitcnuF dnammoC esnopseR noitpircseD
.noitacinummocstratS RC CC
.noitacinummocsdnE QC FC
.edomsegnahC nM KO edomMARGORP:0=nedomNUR:1
.rorresraelC RE KO
.rorreCLPskcehC E? dd )rorreoN:00(edocrorrE=dd
.edomCLPtnerrucskcehC M? f edomMARGORP:0=fedomNUR:1
retnuoC nnnC_DR
ddddd,ddddd,f↑↑
)eulavteserP()eulavtnerruC(
NOtcatnoC:1,FFOtcatnoC:0=f)lamicedni(53556ot00000=dddddd
.oNretnuoC=nnn/n
deeps-hgiHHTCretnuoc nHTC_DR
deeps-hgiHretnuoc
CTCrotarapmocnCTC_DR
sdaeR remiT nnnT_DRddddd,ddddd,f
↑↑)eulavteserP()eulavtnerruC(
NOtcatnoC:1FFOtcatnoC:0=f)lamicedni(53556ot00000=dddddd
.oNremiT=nnn
remmirtlatigiD TA_DR00000_00000_ddddd_ddddd
↑↑)1remmirT()0remmirT(
)lamicedni(53556ot00000=dddddd.1dna0remmirtfoseulavteserpsdaeR
tcatnocyaleR nnnnn_DR f NOtcatnoC:1,FFOtcatnoC:0=f
yromemataD nnnnMD_DRddddd )lamicedni(53556ot00000=dddddd
.oNMD=nnnnatadyraropmeTyromem nnMT_DR
tnerrucretnuoCeulav ddddd_nnnC_RW
KO retnuoc/remiT=nnn/n)lamicedni(53556ot00000=dddddd.oN
tnerrucremiTeulav ddddd_nnnT_RW
tnerrucHTCeulav ddddd_nHTC_RW
setirW teserpretnuoCeulav .2 ddddd_nnnC_SW
KO retnuoc/remiT=nnn/n)lamicedni(53556ot00000=dddddd.oN
teserpremiTeulav .2 ddddd_nnnT_SW
teserpCTCeulav .2 ddddd_nCTC_SW
yromemataD ddddd_nnnnMD_RWKO )lamicedni(53556ot00000=dddddd
.oNMD=nnnn,nnatadyraropmeTyromem ddddd_nnMT_RW
yaleR nnnnn_TS
KO .oNyaleR=nnnn.oNretnuoc/remiT=nnnNOsecroF tcatnocretnuoC nnnC_TS
tcatnocremiT nnnT_TS
yaleR nnnnn_SR
KO.oNyaleR=nnnn
.oNretnuoc/remiT=nnn.oNCTC=n
tcatnocretnuoC nnnC_SR
FFOsecroF tcatnocremiT nnnT_SR
deeps-hgiHretnuoc
CTCrotarapmoctcatnoc
nCTC_SR
Note 1: Temporary data memories TM28, TM30, and TM31 are read-only. Values cannot be written intothese memories. However, these memories can be used when special functions are not used.
Note 2: Visual KV Series: When the preset values of timers and counters are changed using "WS", theladder program in EEPROM is updated the next time the KV is turned on.
KV-300, 10/80 Series: The "WS" command changes the content of the program stored in thePLC’s EEPROM.
➮ Contact Keyence if you need to change it frequently.
7.2 Serial Communication
3-311
17
Chapter 7 Serial Communication
7.2.4 Setting Communication Commands and Responses toCommands
This section describes the command settings and responses when a command isproperly processed."_" represents a space.Refer to "7.2.5 Other Response Codes" (p. 3-315) for responses under abnormalconditions.
■ Communications start command
Transmit a communications start command to start communication with the KV.Other commands can be transmitted after the proper response is sent back from theKV.
Note: Other commands cannot be used unless a [CR] (communications start)command is transmitted first.
Starts communications between the KV and a personal computer.
Command: CRResponse: CC
■ Communications end command
Ends communications between the KV and a personal computer.
Command: CQResponse: CF
■ Mode change commandSelects the mode between PROGRAM and RUN.
Command: Mn [n=0; PROGRAM mode, n=1; RUN mode]Response: OK
■ Error clear command
Clears error messages on KV.
Command: ERResponse: OK
■ Checking KV PLC error
Checks errors or faults in the KV. The description of the error is indicated with theerror code.➮ "7.2.6 Error Code List" (p. 3-316).
Command: ?EResponse: dd
Error code (2- or 3-digit number)
■ Checking current modeThe KV responds with 0 or 1 indicating a current mode.
Command: ?MResponse: f
0: PROGRAM mode 1: RUN mode
7.2 Serial Communication
3-312
7
Chapter 7 Serial Communication
■ Reading counter
Reads the contact ON/OFF status, or the current and preset values of the specifiedcounter/up-down counter.
Command: RD_CnnnCounter No.
Response: f,ddddd,ddddd[Preset value of the counter (00000 to 65535: indecimal)][Current value of the counter (00000 to 65535: indecimal)]0: Contact is OFF., 1: Contact is ON.
■ Reading high-speed counter CTH
Reads the contact ON/OFF status, or the current and preset values of the specifiedhigh-speed counter CTH.
Command: RD_CTHnHigh-speed counter No. (0 or 1)
Response: f,ddddd,dddddPreset value of CTH (00000 to 65535: in decimal)Current value of CTH (00000 to 65535: in decimal)0: Contact is OFF., 1: Contact is ON.
■ Reading high-speed counter comparator CTC
Reads the contact ON/OFF status, or the current and preset values of the specifiedhigh-speed counter comparator CTC.
Command: RD_CTCnHigh-speed counter comparator No.
Response: f,ddddd,dddddPreset value of CTC (00000 to 65535: in decimal)Current value of CTC (00000 to 65535: in decimal)0: Contact is OFF., 1: Contact is ON.
■ Reading timerReads the contact ON/OFF status, or the current and preset values of the specifiedtimer.
Command: RD_TnnnTimer No.
Response: f,ddddd,dddddPreset value of timer (00000 to 65535: in decimal)Current value of timer (00000 to 65535: in decimal)0: Contact is OFF., 1: Contact is ON.
■ Reading digital trimmer
Reads the preset values of the digital trimmers.
Command: RD_ATResponse: ddddd_ddddd_00000_00000
Value of trimmer 1 (00000 to 65535: in decimal)Value of trimmer 0 (00000 to 65535: in decimal)
■ Reading relay contactReads the contact ON/OFF status of the specified relay.
Command: RD_nnnnRelay No.
Response: f0: Contact is OFF., 1: Contact is ON.
7.2 Serial Communication
3-313
17
Chapter 7 Serial Communication
■ Reading DM
Reads the contents of the specified data memory.
Command: RD_DMnnnnData memory No.
Response: dddddData in the specified data memory. (00000 to65535: in decimal)
■ Reading TM
Reads the contents of the specified temporary data memory.
Command: RD_TMnnTemporary data memory No. (00 to 31)
Response: dddddData in the specified temporary data memory.(00000 to 65535: in decimal)
■ Writing current value of counter
Changes the current value of the specified counter or up-down counter.
Command: WR_Cnn_dddddNew current value (00000 to 65535: in decimal)Counter No.
Response: OK
■ Writing current value of timerChanges the current value of the specified timer.
Command: WR_Tnnn_dddddNew current value (00000 to 65535: in decimal)Timer No.
Response: OK
■ Writing current value of high-speed counter CTH
Changes the current value of the specified high-speed counter CTH.
Command: WR_CTHn_dddddNew current value (00000 to 65535: in decimal)High-speed counter No.
Response: OK
■ Writing preset value of counterChanges the preset value of the specified counter or up-down counter.
Command: WS_Cnnn_dddddNew preset value (00000 to 65535: in decimal)Counter No.
Response: OK
Note: Executing this command changes the program in the KV. The program in EEPROM isautomatically updated the next time the KV is turned ON.
■ Writing preset value of timer
Changes the preset value of the specified timer.
Command: WS_Tnnn_dddddNew preset value (00000 to 65535: in decimal)Timer No.
Response: OK
Note: Visual KV Series: Executing this command changes the program in the KV. Theprogram in EEPROM is automatically updated the next time the KVis turned ON.
KV-300, 10/80 Series: The "WS" command changes the content of the programstored in the PLC’s EEPROM.
➮ Contact Keyence if you need to change it frequently.
7.2 Serial Communication
3-314
7
Chapter 7 Serial Communication
■ Writing preset value of high-speed counter comparator CTC
Changes the preset value of the specified high-speed counter comparator CTC.
Command: WS_CTCn_dddddNew preset value (00000 to 65535: in decimal)High-speed counter comparator No.
Response: OK
■ Writing into DM
Writes data into the specified data memory.
Command: WR_DMnnnn_dddddNew current value (00000 to 65535: in decimal)Data memory No.
Response: OK
■ Writing into TM
Writes data into the specified temporary data memory. TM30 and TM31 are read-only memories, so values cannot be written to them.
Command: WR_TMnn_dddddNew current value (00000 to 65535: in decimal)Temporary data memory No. (00 to 29)
Response: OK
■ Forcing relay ON
Forces the contact of the specified relay to ON.
Command: ST_nnnnnRelay No.
Response: OK
■ Forcing counter contact ON
Forces the contact of the specified counter to ON.
Command: ST_CnnnCounter No.
Response: OK
■ Forcing timer contact ON
Forces the contact of the specified timer to ON.
Command: ST_TnnnTimer No.
Response: OK
■ Forcing relay OFF
Forces the contact of the specified relay to OFF.
Command: RS_nnnnnRelay No.
Response: OK
■ Forcing counter contact OFF
Forces the contact of the specified counter to OFF.
Command: RS_CnnnCounter No.
Response: OK
■ Forcing timer contact OFF
Forces the contact of the specified timer to OFF.
Command: RS_TnnnTimer No.
Response: OK
7.2 Serial Communication
3-315
17
Chapter 7 Serial Communication
■ Forcing CTC contact OFF
Forces the contact of the specified high-speed counter comparator to OFF.
Command: RS_CTCnHigh-speed counter comparator No.
Response: OK
Note 1: Input relays cannot be forced ON/OFF. (Except when special utility relay2301 is ON.)Note 2: "_" in commands and responses represents a space.
7.2.5 Other Response CodesIf the command from a computer is an unspecified one, or an error occurs in the KV,the KV sends back an appropriate response code for the status.
Base uniterror
Responsecode
Description Cause Remedy
• Undefined relay, counter,timer, DM, CTH, or CTCnumber was specified.
• Counter, timer, CTH, orCTC number, unused in aprogram was specified.
• Specify a number that isdefined in the KV beingused.
• Check a program, andspecify a number used inthe program.
• Undefined command wastransmitted.
• Incorrect command wasspecified.
• Command other than "CR"was transmitted before thecommunications path wasestablished.
• Check a command.
• Transmit "CR" to startcommunications, and thentransmit a command.
E0
E1
E2
E3
E4
E5
Relay No.error
Commanderror
Programunregistered
Base unitfault
Write-protected
When the KV has no programstored, "M1" was transmittedor reading of timer/countercontent was attempted.
• Register a program into theKV.
• Check a program andspecify the number used inthe program.
Hardware error was detectedin a KV base unit.
Turn off the power for the KV,and then turn it on again. Ifthe cause of the error is notremoved, the KV may befaulty. Contact your nearestKEYENCE office.
Attempt was made to changethe preset value of a counter,timer, or CTC in a write-protected program.
Write-enable the program,and change the preset value.
"M1" was transmitted beforecleaning an error messagefrom the KV.
Clear the error message fromthe KV, and remove the causeof the error.
7.2 Serial Communication
3-316
7
Chapter 7 Serial Communication
Subroutines are nested to four levelsor more.
FOR/NEXT instructions are nested toeight levels or more.
Five levels or more of interruptsoccurred simultaneously.
MPS/MPP instructions are nested toeight levels or more.
Content in RAM was erased. All datain data memory and current values ofcounters in the KV were cleared.
Scan time exceeds 300 ms.
Attempt was made to operate a KVbase unit which has no programsstored.
Hardware error was detected in a KVbase unit.
Error code Description Cause Remedy
00 No error
10 CALL nest error
11 FOR nest error
12 INT nest error
13 MPS nest error
20 Memory error
30 Scan timer error
40 NO PROGRAM
50 SND/RTN failure
51 Division by zero
52 Address error
53 Invalid instruction
54 Watchdog timer error
7.2.6 Error Code ListWhen a "Checking KV PLC error" command (?E) is transmitted, the KV sends backthe error code. The following list shows the description, cause, and remedy for eacherror code.
These errors may occur when aprogram is executed.
Check the program while payingparticular attention to usage ofsubroutines and the INT instruction,and restore the program accordingly.
Turn the KV off once and turn it on.Register data from the beginning.
Check the program again.• Be sure that there is no excessive
repetition using the FOR/NEXT loop.• Be sure that an interrupt is not
executed at a higher rate.
Write a program into KV.
Turn off the power for the KV, andthen turn it on again. If the cause ofthe error is not removed, the KV maybe faulty. Contact your nearestKEYENCE office.
7.2 Serial Communication
3-317
17
Chapter 7 Serial Communication
7.2.7 Example ProgramTypical program for communications between the KV and a personal computer (ForIBM PC-AT & compatible computers using BASIC)
‘‘Language Microsoft BASIC Version 7.0‘‘ *****I/OAddress (RS-232C Port-1)*****‘Port-1&H3F*‘Port-2&H2F*‘PortCtrl%=&H3FB’COM1Port1Modem%=&H3FC’MODEMCtrlPortBpsLow%=&H3F8’BitrateLowPortBpsHigh%=&H3F9’BitrateHigh‘*****ControlCode*****Port1CtrlCode1%=&H5B’Break&8bitEven1StopbitPort1CtrlCode2%=&H1B’8bitEven1Stopbit‘*****InitializesRS-232C*****OPEN"COM1:9600,N,8,1"FORRANDOMAS#1'‘*****RS-232CPortInit*****OUTPortCtrl %,Port1CtrlCode1%’Start transmitting a break signalSLEEP1’wait 1 sec.OUTPortCtrl%,Port1CtrlCode2%’Ends transmitting a break signal‘‘-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-‘’’’’’’’’’’’*****DebugPrint*****‘’’’’’’’’’’status=INP(&H3FE):PRINT"ModemStatus1";status‘’’’’’’’’’’status=INP(&H3FD):PRINT"LineStatus1";status‘’’’’’’’’’’’‘’’’’’’’’’’’*****SelfInit.*****‘’’’’’’’’’’linectrl=INP(PortCtrl%)’ReadLine-Control-Register‘’’’’’’’’’’linectrl=linectrlOR&H80'‘’’’’’’’’’’OUTPortCtrl%,linectrl’DLAB=ON‘’’’’’’’’’’‘’’’’’’’’’’OUTPortBpsLow%,12’SetBitRate(9600BPS)‘’’’’’’’’’’OUTPortBpsHigh%,0'‘’’’’’’’’’’‘’’’’’’’’’’linectrl=linectrlAND&H7F’DLAB=OFF‘’’’’’’’’’’OUTPortCtrl%,linectrl‘’’’’’’’’’’’‘’’’’’’’’’’’*****CtrlLine*****‘’’’’’’’’’’OUTPort1Modem%,&HB’RTS,DTRON !!‘’’’’’’’’’’’‘’’’’’’’’’’’*****DebugPrint*****‘’’’’’’’’’’status=INP(&H3FE):PRINT"ModemStatus2";status‘’’’’’’’’’’status=INP(&H3FD):PRINT"LineStatus2";status‘-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-‘*********************************************************‘*****Transmitting a command/receiving a response*****‘*********************************************************a$=""WHILEa $>"END"PRINT"Command>>":INPUTa$PRINT#1,a $b$=""LINEINPUT#1,b$PRINT"RsP[";b$;"]"PRINTWENDPRINT"GoodBy!!"CLOSE#1
END
Note: No parity check is specified due to thelimitations of the version of BASIC being used.
• Change value in "SLEEP" timer according to your personal computer’s clockfrequency so that value I exceeds 100 ms.
• Set the baud rate of your personal computer to 9600 bits/s.• Enter END to terminate programming.
Note 1: MS-DOS executable files (KVCOM.EXE) and BASIC source code files(KVCOM.BAS) are included in the KV Incrediware (DOS) Software (KV-H4E,version 2.00 or higher).
Note 2: Type in "KVCOM" and press ENTER to call the MS-DOS command line.
7.3 Loading Text Data
3-318
7
Chapter 7 Serial Communication
7.3 Loading Text DataThe KV can be connected to equipment having an RS-232C port to load consecutivetext data (less than 100 bytes) as a batch into its data memories.Loaded data can be modified and incorporated into a program.
7.3.1 Receiving Text DataThe KV can write up to 100 bytes of text data sandwiched between STX and ETX,into internal data memories (DM1000 to DM1099 with communication port A,DM1200 to DM1299 with communication port B), one byte per data memory inASCII code.
Communications data format
Note that each text data must include STX (02H) in the 1st byte followed by the text(100 bytes max.) and end with ETX (03H) in the last byte as shown below.
Internal data memory
The KV writes received text data into its data memories (DM1000 to DM1099 withcommunication port A, DM1200 to 1299 with communication port B), one byte perdata memory in ASCII code.
The KV writes "00" into the high-order 8 bits and text data in ASCII code into thelow-order 8 bits of the data memory.
Note: The KV-10xx includes only communication port A.
Special utility relay operationThree special utility relays assigned for each channel turn on for one scan toindicate that text data has been received or that data reception has failed.
STX
1st byte Last byte
Text data (less than 100 bytes) ETX
Low-order 8 bits (ASCII code)
Received data
Byte count of data
Data 1 Data 2 Data 3 Data 99
1st DM(Byte count of data)Data memory 2nd DM 3rd DM 4th DM 100th DM
Bits indata memory
High-order 8 bits (00)
ataDyromem
WENVK
ATROP 0001MD 1001MD 2001MD 8901MDot3001MD 9901MD
BTROP 0021MD 1021MD 2021MD 8921MDot3021MD 9921MD
003-VK08/01-VK 0029MD 1029MD 2029MD 8929MDot3029MD 9929MD
.oNataD tnuocetyB 1ataD 2ataD 89ataDot3ataD 99ataD
STX
0
15 00
0 0 0 0 0 0 0 0 0 1 1 0 0 0 1
ETX
7.3 Loading Text Data
3-319
17
Chapter 7 Serial Communication
Note 1: Be sure to transmit a break signal for the first serial communication with apersonal computer after the KV-P3E(01) handheld programmer is connected to theKV, or after the "KV IncrediWare (DOS)" or "LADDER BUILDER for KV" program-ming support software is evoked.A break signal initializes the communication setting for the KV. If you cannot transmita break signal, turn the KV OFF once to initialize the communication setting. The KVwill not receive text data unless its communication setting has been initialized.
Note 2: If [ETX] exists at some point in the text data, the KV writes the data before[ETX] into the data memory. The data after [ETX] is not written.
Note 3: If KV receives text data while special utility relay 2804 (2809)*1 is ON, thereceived data is not written into the data memory. In this case, special utility relay2802 (2807)*2 turns ON for one scan.
Note 4: When parity errors or other errors occur during text data reception, thereceived data is not written into the data memory. In this case, special utility relays2802 (2807) and 2803 (2808)*3 turn ON for one scan.
Note 5: The KV-10xx includes only communication port A.
*1: 2804 with KV-300/10/80 *2: 2805 with KV-300/10/80 *3: 2806 with KV-300/10/80
7.3.2 Transmitting Text DataThe KV transmits text data written into its data memories (DM1100 to DM1199 forcommunication port A, DM1300 to DM1399 for communication port B), one byte perdata memory in ASCII code.
Transmission data format and internal data memoriesWhen transmitting data from the KV, write the data into the data memory in thefollowing format.
The KV writes "00" into the high-order 8 bits and text data in ASCII code into thelow-order 8 bits of the data memory.
Note: The KV-10xx includes only communication port A.
Data 99
Data memory bits
High-order 8 bits (00) Low-order 8 bits (ASCII code)
Data memory 1st DM(Byte count of data) 2nd DM 3rd DM 4th DM 100th DM
Transmitted data Data 1 Data 2 Data 3
.oNyaleR)ATROP(
.oNyaleR)BTROP(
.oNyaleR)08/01/003-VK( noitpircseD
1082 6082 4082 atadtxetnehwnacsenorofNOsnruT.deviecerneebsah
2082 7082 5082atadtxetnehwnacsenorofNOsnruT
,NOsi1082elihwdeviecerneebsah.NOsi3082nehwro
3082 8082 6082 atadtxetnehwnacsenorofNOsnruT.deliafsahnoitpecer
ataDyromem
ATROP 0011MD 1011MD 2011MD 8911MDot3011MD 9911MD
BTROP 0031MD 1031MD 2031MD 8931MDot3031MD 9931MD
/003-VK08/01 0039MD 1039MD 2039MD 8939MDot3039MD 9939MD
.oNataD tnuocetyB 1ataD 2ataD 89ataDot3ataD 99ataD
0
15 00
0 0 0 0 0 0 0 0 0 1 1 0 0 0 1
7.3 Loading Text Data
3-320
7
Chapter 7 Serial Communication
T000
T0012803
0500
2801
2800
0000
2008
1001
2800
0500
DM1007LDA
DM1006LDA
DM1005LDA
DM1004LDA
DM1003LDA
DM1002LDA
DM1001LDA
DM1000LDA
1001DIFU
#00010T000
#00030T001
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
2804SET
END
ENDH
#00009DW
DM1100
$0002DW
DM1101
$004BDW
DM1102
$0045DW
DM1103
$0059DW
DM1104
$004EDW
DM1106
$0043DW
DM1107
$0045DW
DM1108
$0003DW
DM1109
$0045DW
DM1105STX K E Y E
N C E ETX
Turns ON output relay 0500for 3 seconds whenreception error occurs.
Sends break signal (1 sec.).
One scan ON
Break signal
Transmits text data ("STX KEYENCE ETX").
Transmissionstart relay No. of
transmitteddata
Trans-missionrelayReceives text data.
Reception relay No. ofreceived data.
Receiveddata
Reception error
When power is turned ON,transmits a break signal forone second during the firstscan.
Transmits text data wheninput relay 0000 turns ON.
Receives text data.Received
dataReceived
dataReceived
dataReceived
dataReceived
dataReceived data
Special utility relay operation
Two special utility relays are assigned for each channel for data transmission. Textdata or a break signal is transmitted when the respective relay is turned ON/OFF.
Note 1: Be sure to transmit a break signal for the first serial communication with apersonal computer after the KV-P3E(01) handheld programmer is connected to theKV, or after the "KV IncrediWare (DOS)" or "LADDER BUILDER for KV" program-ming support software is evoked.A break signal initializes the communication setting for the KV. If you cannot transmita break signal, turn the KV OFF once to initialize the communication setting.The KV will not transmit/receive text data unless its communication setting has beeninitialized.
Note 2: Turn ON special utility relay 2804 (2809) (SET 2804 [2809])*1 to transmit textdata. Special utility relay 2804 (2809)*1 remains ON during text data transmission,and automatically turns OFF when the transmission completes.To forcefully stop the text data transmission, turn OFF special utility relay 2804(2809) (RES 2804 [2809])*1.
Note 3: A break signal is transmitted while special utility relay 2808*2 is turned ON.Use the SET-RES instruction pair or OUT-OUB instruction pair to control a breaksignal. The communication program of the destination KV is initialized after a breaksignal has been transmitted.
*1: 2807 with KV-300/10/80 *2: 2803 with KV-300/10/80
7.3.3 Sample ProgramThe following is the sample program to transmit/receive text data using communica-tion port A on the KV basic unit.
Data to be transmitted: KEYENCETransmission header: STXTransmission delimiter: ETXLength of received data: Fixed to 7 bytes
.oNyaleR)AtroP(
.oNyaleR)BtroP(
.oNyaleR)08/01/003-VK( noitpircseD
4082 9082 7082 .atadtxetgnittimsnartspots/stratSpotS:FFO,tratS:NO
0082 5082 3082 .langiskaerbgnittimsnartspots/stratSpotS:FFO,tratS:NO
7.4 ASCII Code List
3-321
17
Chapter 7 Serial Communication
0
0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F
1 2 3 4 5 6 7 8 9
High-order 4 bits
Low
-ord
er 4
bits
7.4 ASCII Code ListThe following are the ASCII code characters used for data transmission.
Characters in the shaded area can be used for data transmission with the KV.[STX], [ETX], [LF], and [CR] are used as data delimiters.Only use characters in the shaded area because the other characters are used forcontrol purposes.
7.4 ASCII Code List
3-322
7
Chapter 7 Serial Communication
Chapter 8Programming Examples
This chapter describes the typical programming examples for KV-300, KV-10/80Series. These programs can be used for Visual KV Series. However, pay attentionto the I/O addressing compatibility before use.
8.1 List ....................................................................................................... 3-324
8.2 Details ................................................................................................. 3-3268.2.1 Reference Program Examples ............................................................... 3-326
8.1 List
3-324
8
Chapter 8 Programming Examples
8.1 List
Instruction Program title ReferencePage
TMR, TMH, TMS [Timers] One-shot circuit 3-326
Off-delay circuit 3-326
On-delay circuit 3-327
Flicker circuit 3-327
C [Counter] Accumulator timer 3-327
Large capacity counter 3-328
Multi-level Up/Down counter 3-328
Counter multi-level setting 3-328
DIFU, DIFD One-shot circuit 3-329
KEEP Detection of packs on conveyor 3-329
SFT Alternating circuit 3-330
Repeat shift circuit 3-331
Asynchronous shift register 3-331
Resetting internal utility relays 3-332
HSP High-speed fetching of input data 3-332
MC-MCR Emergency stop circuit 3-333
W-UE Input sequence check 3-334
Fork lift truck IN/OUT judgement 3-334
STG-JMP Enabling double coil 3-335
Conditional branching 3-335
STP-STE Process progression 3-336
ITVL Pulse interval measurement 3-336
Fetching data from KV-AN6 3-337
CTH [High-speed counter] High-speed counter multi-level setting 3-338
High-speed counter current value clear 3-339
Input of phase differential signal 3-339
SBN [Sub-routine] DM shift 3-340
FOR-NEXT Transfer of a block of DM data 3-341
HKEY Fetching 16-key input 3-342
TMIN [Analog timer] Changing timer setting value 3-343
Changing setting values of multiple timers 3-343
LDA/STA First-in first-out (FIFO) 3-343
Changing the counter setting value 3-345
Changing the timer setting value 3-345
CMP Comparing values with no specific range 3-345
Setting the upper/lower limit 3-345
Changing the CMP setting value 3-346
Multi-level comparator 3-346
ADD Adding BCD and BIN(binary) values 3-347
Total count 3-348
SUB Comparison of absolute values 3-348
MUL Multiplying the counter current value by DM value 3-349
DIV Total count average 3-349
ANDA BCD (1-digit) input 3-350
Fetches input data separately 3-350
ORA Output of 2-digit BCD data 3-351
Separate input of 2-digit BCD 3-351
8.1 List
3-325
18
Chapter 8 Programming Examples
Instruction Program title ReferencePage
EORA Judgement of matcing data 3-352
SRA/SLA Separate input of BCD 3-352
RRA/RLA Error input count 3-353
INC/DEC Total count 3-353
Up/Down count 3-354
MPX Display of 7-segment LED 3-355
DMX Output of error input No. in BCD 3-356
TBCD Output of 4-digit BCD data 3-356
Output of 8-digit BCD data 3-356
TBIN Output of 4-digit BCD data 3-357
8.2 Details
3-326
8
Chapter 8 Programming Examples
8.2 Details
8.2.1 Reference Program Examples
Basic Instructions
Applications of TMR, TMH, and TMS Instructions ➮ Refer to p. 3-67 to p. 3-71.
■ One-shot circuit
When input relay 0000 turns ON, output relay 0500 turns ON and remains ON for aspecified time.
Timing diagram
Ladder diagram Coding
■ Off-delay circuit
When input relay 0000 turns ON, output relay 0500 turns ON. 0500 turns OFF in aspecified time after 0000 turns OFF.
Timing diagram
Ladder diagram Coding
0500
0000
2s 2s
0000 #00020
T000
T000 005000500
2-s timer
0500
0000
2s
0000
#00020
T000
0500
000000500
2-s timer
T000
Line No. Instruction Operand0000 LD 00000001 OR 05000002 TMR 000#000200003 ANB T0000004 OUT 0500
Line No. Instruction Operand0000 LD 00000001 OR 05000002 ANB T0000003 OUT 05000004 ANB 00000005 TMR 000 #00020
8.2 Details
3-327
18
Chapter 8 Programming Examples
■ On-delay circuit
Output relay 0500 turns ON in a specified time after input relay 0000 turns ON.When input relay 0000 turns OFF, output relay 0500 also turns OFF.
Timing diagram
Ladder diagram Coding
■ Flicker circuit
Output relay 0500 turns ON and OFF repeatedly while input relay 0000 is ON.
Timing diagram
Ladder diagram Coding
■ Accumulator timer (Remains ON in case of power failure)
Counts special utility relay 2006 (1-s clock pulse) for 3600 s at C001 and inputs thecount value to C002. Accumulates the count for 10000 hours and retains the currentcount value even when power failure occurs or power is OFF.Input relay 0000Reset relay 0001(Resolution is 1 s at 2006.)
Ladder diagram Coding
0500
0000
2s 1s
0000 #00020
T000
0500T000
2-s timer
0500
0000
2s
1s 1s
2s
0000 #00020T000
T000
2-s timer
0500
#00010T001
T001
1-s timer
Line No. Instruction Operand0000 LD 00000001 TMR 000 #000200002 LD T0000003 OUT 0500
Line No. Instruction Operand
0000 LD 0000
0001 ANB T001
0002 TMR 000 #00020
0003 LD T000
0004 TMR 001 #00010
0005 OUT 0500
0000 #03600C001
C001
3600-s counterC001
1-s pulse
0001 #10000C002
10000-s counter
1000
1000
2006
Line No. Instruction Operand
0000 LD 0000
0001 ANB C001
0002 C 001 #03600 2006
0003 LD C001
0004 OUT 1000
0005 LDB 0001
0006 C 002 #10000 1000
8.2 Details
3-328
8
Chapter 8 Programming Examples
0001 #09999C000
2002 0500#0099900000 to00999
LDAC000
CMP
0501
0512
2011
#01999CMP
2011 0500
#02999CMP
2011 0500 0501
0000
01000 to 01999
02000 to 02999
0004Low-order4 digits
High-order4 digits
STATBCDLDAC000 8500
STATBCDLDAC001 8600
■ Large capacity counter
Accumulates 1 count to C001 for every 10000 counts by C000. This example cancount up to 655350000.Count input relay 0000Reset relay 0001
Ladder diagram Coding
■ Multi-level UP/DOWN counter
UP/DOWN counter which allows the count setting value up to 99,990,000.• UP input relay: 0001• DOWN input relay: 0002• Reset input relay: 0003
The example below outputs the high-order 4 digits of 8-digit BCD to UDC001 andthe low-order 4 digits of 8-digit BCD to UDC000.
Ladder diagram Coding
■ Counter multi-level setting
Outputs in 3 different levels according to the counter current value.• 00000 to 00999 —> 0500 turns ON.• 01000 to 01999 —> 0501 turns ON.• 02000 to 02999 —> 0502 turns ON.
Ladder diagram
#10000C000
C000
0001 C000
0001 #65535C001
1000
1000
0000
Line No. Instruction Operand
0000 LDB 0001
0001 ANB C000
0002 C 000 #10000 0000
0003 LD C000
0004 OUT 1000
0005 LDB 0001
0006 C 001 #65535 1000
Line No. Instruction Operand
0000 LD 00010001 LD 00020002 LD 00030003 UDC 000 #099990004 LD C0000005 AND 00010006 LD C0000007 AND 00020008 LD 00030009 UDC 001 #09999
0001
#09999UP
UDC000
0002
0003
C000
C000
0003
0002
0001
DW
RES
#09999UP
UDC001
DW
RES
BCD: Low-order 4 digits
BCD:High-order 4 digits
8.2 Details
3-329
18
Chapter 8 Programming Examples
Coding
Application of DIFU, DIFD Instructions
■ One-shot circuit using differentiate instructionWhen input relay 0000 turns ON/OFF, output relay 0500 and 0501 turns ON one-shot (1 second).
Timing diagram
Ladder diagram Coding
➮ Refer to p. 3-78.
Application of KEEP instruction
■ Detection of chewing gum packs
Detects chewing gum packs over the carton using the proximity switch ES Series(0001 to 0003). If the switch detects that one or more packs of chewing gum aremissing, output relay 0500 turns ON for 1 s.The timing clock is generated from the visible beam photoelectric switch PZ2 (0000).
Line No. Instruction Operand Line No. Instruction Operand0000 LDB 0001 0012 CON0001 C 000 #09999 0000 0013 ANB 20110002 LD 2002 0014 ANB 05000003 LDA C000 0015 OUT 05010004 CON 0016 MPP0005 MPS 0017 CMP #029990006 CMP #00999 0018 CON0007 CON 0019 ANB 20110008 ANB 2011 0020 ANB 05000009 OUT 0500 0021 ANB 05010010 MRD 0022 OUT 05020011 CMP #01999
1000
0000
1S
1001
0500
0501 1S
1001 0501
0501 #00010T002
T002
0000 1000DIFU
1001DIFD
1000 0500
0500 #00010T001
T001
Line No. Instruction Operand0000 LD 00000001 DIFU 10000002 DIFD 10010003 LD 10000004 OR 05000005 ANB T0010006 OUT 05000007 TMR 001 #000100008 LD 10010009 OR 05010010 ANB T0020011 OUT 05010012 TMR 002 #00010
Gum
Reflector (R-2)
Proximity Switch ES Series
ON OFF ON
PZ2-61
Chewing
gum pack
Chewing
gum pack
Gum
Gum
Gum
Gum
Gum
Gum
Gum
ES Series
8.2 Details
3-330
8
Chapter 8 Programming Examples
Timing diagram
Ladder diagram
Executes SET when all input relays 0000 to 0003 are ON.Detects presence/absence of chewing gum packs at DOWN edge of 0000.Outputs 1-s one-shot pulse from output relay 0500 when 1000 is OFF.
Coding
➮ Refer to p. 3-80.
Applications of SFT instruction
■ Alternating circuit
Every time input relay No. 0000 turns ON, 0500 turns alternately ON and OFF.
Timing diagram
Ladder diagram Coding
➮ Refer to p. 3-82.
0000
1s
0001
0002
0003
0500
0000
1000SETKEEP
1001RES
0000 1001DIFD
1001 0500
0500 #00010T001
T001
0001 0002 0003
1000
Excecutes SET when all input relays 0000 to 0003 are ON.
Detects presence/absence of chewing gum packs at DOWN edge of 0000.
Outputs 1-s one-shot pulse from output relay 0500 when 1000 is OFF.
0000
0500
1000
1000D
SFT
0000
2003
1000
CLK
RES
0500
1000
Line No. Instruction Operand Line No. Instruction Operand0000 LD 0000 0007 DIFD 10010001 AND 0001 0008 LD 10010002 AND 0002 0009 ANB 10000003 AND 0003 0010 OR 05000004 LD 1001 0011 ANB T0010005 KEEP 1000 0012 OUT 05000006 LD 0000 0013 TMR 001 #00010
Line No. Instruction Operand
0000 LDB 1000
0001 LD 0000
0002 LD 2003
0003 SFT 1000 1000
0004 LD 1000
0005 OUT 0500
8.2 Details
3-331
18
Chapter 8 Programming Examples
■ Repeat shift circuit
Turns ON every output for a second sequentially. Sets 1000 to 2008 (ON for 1stscan only at startup) and shifts outputs from 7500 to 7504 every second at T001.When 1005 turns ON, 1000 is set and the same sequence as above repeats.
Ladder diagram Coding
■ Synchronous shift registerTurns ON input relay 0002 to reset the shift register (1000 to 1010) when the datainput to 0000 does not synchronize with the clock input to 0001.
Timing diagram
Ladder diagram Coding
2008
T001
2003
T001
2003
1000D
SFT
1000
1001
1002
CLK
RES
7502
1005
1003 7503
#00010T001
7500
7501
1004 7504
1005 1000
SET1000
SET
0000
0001
1000
1001
1002 ...
Line No. Instruction Operand0000 LD 20080001 SET 10000002 LDB T0010003 T001 #000100004 LD 20030005 LD T0010006 LD 20030007 SFT 1000 10050008 LD 10000009 OUT 75000010 LD 1001
0011 OUT 7501
0012 LD 1002
0013 OUT 7502
0014 LD 1003
0015 OUT 7503
0016 LD 1004
0017 OUT 7504
0018 LD 1005
0019 SET 1000
0000
1100
2003
0001
0002
1000D
SFT
CLK
RES1010
1100DIFU
SET1000
Line No. Instruction Operand
0000 LD 0000
0001 DIFU 1100
0002 LD 1100
0003 SET 100
0004 LD 2003
0005 LD 0001
0006 LD 0002
0007 SFT 1000 1010
8.2 Details
3-332
8
Chapter 8 Programming Examples
2008Turn ON for 1st scan only at startup.
2813SET
EI
0500 #00010T000
T000RES
0000
2002SET
0500
0500
Interrupt enabled
Input time constant 10µs
Turns ON timer for 1s when 0500 is ON.
Resets 0500 when T000 turns ON.
Sets interrupt input at 0000.
Sets 0500 when 0000 turns ON.
END
INT
RETI
ENDH
Initial settings
■ Resetting internal utility relays
When input relay No. 0000 turns ON, all internal utility relays No. 1000 through 1915turn OFF.SFT instruction can be substituted for RES instruction. This application can be usedto reset many relays at one time.
Ladder diagram Coding
Applications of HSP instruction
■ High-speed fetching of input dataWhen the input signal at 0000 has pulses of 5-ms interval and input relay 0001 isON, fetches data from input relay 0000 at high speed and outputs 1-s one-shotpulse from output relay 0500.
Timing diagram
Ladder diagram Coding
* To input a signal having pulse interval shorter than the scan time, use the inter-rupt instruction. ➮ Refer to p. 3-192.
■ When using the interrupt instruction
Ladder diagram
2003
2003
0000
1000D
SFT
CLK
RES1915
0001
0000
0500 1s
0001
0000
0500
#00010T000
1-s timer
0500 T000
Outputs 1-s one-shot pulse from output relay0500.
0000HSP
Line No. Instruction Operand0000 LD 2003
0001 LD 2003
0002 LD 0000
0003 SFT 1000 1915
Line No. Instruction Operand0000 LD 00010001 HSP 00000002 LD 00000003 OR 05000004 TMR 000 #000100005 ANB T0000006 OUT 0500
8.2 Details
3-333
18
Chapter 8 Programming Examples
Coding
➮ Refer to p. 3-86.
Application of MC-MCR instruction
■ Emergency stop circuit
When input relay 0000 is ON, 0500 turns ON for 1 s, then 0501 turns ON for 2 s,and then 0502 turns ON for 3 s, repeatedly.Once input relay 0000 turns OFF, 0500 turns ON when 0001 is ON, 0501 turns ONwhen 0002 is ON, and 0502 turns ON when 0003 is ON.
Timing diagram Coding
Ladder diagram
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0007 END0001 EI 0008 INT 00000002 SET 2813 0009 LD 20020003 LD 0500 0010 SET 05000004 T000 #00010 0011 RETI0005 LD T000 0012 ENDH0006 RES 0500
0000
0001
0002
0500
0501
0502
0003
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0015
0014
0016
0017
0018
0019
0020
0000
0000
1000
SET RES RES1100 1101 1102
DIFU1002 1002
STG1100 1200 #00010 T000
JMP1101
T000
MC
STG1101 1201 #00020 T001
JMP1102
T001
STG1102 1202 #00030 T002
JMP1100
T002
MCR
MC1001
0001
0002
0003
MCR
1203
1204
1205
1200
1203
0500
1201
1204
1202
1205
0501
0502
END
ENDH
1000 1001
Line No. Instruction Operand0000 LD 00000001 OUT 10000002 CON0003 OUB 10010004 LD 00000005 DIFU 10020006 CON0007 AND 10020008 SET 11000009 CON0010 RES 11010011 CON0012 RES 11020013 LD 10000014 MC0015 STG 11000016 OUT 12000017 CON0018 TMR 000 #000100019 CON0020 AND T0000021 JMP 11010022 STG 11010023 OUT 12010024 CON0025 TMR 001 #000200026 CON0027 AND T0010028 JMP 11020029 STG 11020030 OUT 12020031 CON0032 TMR 002 #000300033 CON0034 AND T0020035 JMP 11000036 MCR0037 LD 10010038 MC0039 LD 00010040 OUT 12030041 LD 00020042 OUT 12040043 LD 00030044 OUT 12050045 MCR0046 LD 12000047 OR 12030048 OUT 05000049 LD 12010050 OR 12040051 OUT 05010052 LD 12020053 OR 12050054 OUT 05020055 END0056 ENDH
8.2 Details
3-334
8
Chapter 8 Programming Examples
0000
0001
0500
0501
0000
0001
0002
0003
0500
0000
1000 0002
1001 0003
0001
1002 0500
1000
1001
1002
Application Instructions
Application of W-UE instruction
■ Input sequence check
Output relay 0500 turns ON when input relay 0000 is ON and input 0001, 0002, and0003 turn ON in this sequence.Output relay 0500 turns OFF when input relay 0000 is OFF.
Timing diagram
Ladder diagram Coding
■ Fork lift truck IN/OUT judgement
Checks the input sequence. Output relay 0500 turns ON when input relay 0000 turnsON and then 0001 turns ON. Output relay 0501 turns ON when input relay 0001turns ON and then 0000 turns ON.
Timing diagram
Ladder diagram Coding
Line No. Instruction Operand
0000 LD 0000
0001 W-UE 0001 1000
0002 LD 1000
0003 W-UE 0002 1001
0004 LD 1001
0005 W-UE 0003 1002
0006 LD 1002
0007 OUT 0500
0000 0001
1000
1000 0500
0001 0000
1001
1001 0501
Leave warehouse
Enter warehouse
Line No. Instruction Operand
0000 LD 0000
0001 W-UE 0001 1000
0002 CON
0003 AND 1000
0004 OUT 0500
0005 LD 0001
0006 W-UE 0000 1001
0007 CON
0008 AND 1001
0009 OUT 0501
8.2 Details
3-335
18
Chapter 8 Programming Examples
Application of STG-JMP instruction
■ Enabling double coil
When start SW 0000 is pressed, output relay 0500 turns ON for 1 s, then outputrelays 0500 and 0501 turn ON for 2 s, and then output relays 0500, 0501, and 0502turn ON for 3 s. The above sequence repeats.
Ladder diagram
Coding
The double coil operates normally through different STG instructions. Ifdifferent STG instructions turn ON simultaneously, the latter programmedinstruction has the priority.
■ Conditional branching
When input relay 0000 (start SW) turns ON, output relay 0500 turns ON. Then, asprogrammed for conditional branching, output 0501 turns ON for 1 s when 0001turns ON or 0502 turns ON for 2 s when 0002 turns ON. After either one of theprocesses is completed, the program returns to the conditional branching andrepeats the same steps.
Ladder diagram
0000
1001JMP
SET10001100
DIFU1100
1000STG
T000#00010T000
1002JMP
1001STG
T001#00020T001
1000JMP
1002STG
T002#00030T002
0500
0501
050205010500
0500
Turns ON 1000 when input relay 0000 turns ON.
Output relay 0500 turns ON for 1 s.
Output relays 0500 and 0501 turn ON for 2 s.
Output relays 0500, 0501 and 0502 turn ON for 3 s.
Line No. Instruction Operand Line No. Instruction Operand0000 LD 0000 0016 CON0001 DIFU 1100 0017 TMR 001 #000200002 CON 0018 CON0003 AND 1100 0019 AND T0010004 SET 1000 0020 JMP 10020005 STG 1000 0021 STG 10020006 OUT 0500 0022 OUT 05000007 CON 0023 CON0008 TMR 000 #00010 0024 OUT 05010009 CON 0025 CON0010 AND T000 0026 OUT 05020011 JMP 1001 0027 CON0012 STG 1001 0028 TMR 002 #000300013 OUT 0500 0029 CON0014 CON 0030 AND T0020015 OUT 0501 0031 JMP 1000
CAUTION
0000
1001JMP
SET10001100
DIFU1100
1000STG
0001
1002JMP
0002
1000JMP
1001STG
T000#00010T000
0500
0501
1000JMP
1002STG
T001#00020T001
0502
8.2 Details
3-336
8
Chapter 8 Programming Examples
Application of STP-STE instruction
■ Process progressionWhen input relay 0000 turns ON, output relay 0500 automatically turns ON for 2 s,and then 0501 turns ON for 3 s.
Ladder diagram Coding
* The double coil operates normallyacross different STP instructions.
➮ Refer to p. 3-114.
Application of ITVL instruction
■ Pulse interval measurement
Measures the pulse interval of input relay 0000 and writes the measured data intoDM0100 (in units of 10 ms).• Mode No. ➞ 1 (DM0000)• MAX. setting value ➞ 51 (DM0001)• MIN. setting value ➞ 49 (DM0002)• Average number of measurements ➞ 10 (DM0003)
Coding
Line No. Instruction Operand Line No. Instruction Operand0000 LD 0000 0014 OUT 05010001 DIFU 1100 0015 CON0002 CON 0016 TMR 000 #000100003 AND 1100 0017 CON0004 SET 1000 0018 AND T0000005 STG 1000 0019 JMP 10000006 OUT 0500 0020 STG 10020007 MPS 0021 OUT 05020008 AND 0001 0022 CON0009 JMP 1001 0023 TMR 001 #000200010 MPP 0024 CON0011 AND 0002 0025 AND T0010012 JMP 1002 0026 JMP 10000013 STG 1001
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0000
SET1001
DIFU1000 1000
STE
T001 0501
END
ENDH
SET1002T000
1001
STE
STP
T000
1001T000
#00020
0500
RES1001T000
STP1002
RES1002T001
1002T001
#00030
Line No. Instruction Operand
0000 LD 00000001 DIFU 10000002 CON0003 AND 10000004 SET 10010005 STP 10010006 LD T0000007 RES 10010008 LDB T0000009 OUT 05000010 LD 10010011 TMR 000 #000200012 LD T0000013 SET 10020014 STE0015 STP 10020016 LD T0010017 RES 10020018 LDB T0010019 OUT 05010020 LD 10020021 TMR 001 #000300022 STE0023 END0024 ENDH
8.2 Details
3-337
18
Chapter 8 Programming Examples
ONOFF 500ms
Measure the pulse interval
Reset input relay 0002Output relay 0500 turns ONwhen the pulse interval is not within the range from 490 to 510 mm.
Ladder diagram
Coding
2008
0000
0001
0002
DM0000PLS
ITVL
PAUSE
RES1000
1000 0500
STADM0000
SET
LDA#00001
2008STA
DM0001LDA
#00051
2008STA
DM0002LDA
#00049
2008STA
DM0003LDA
#00010
1002RES0500
STADM0100
1001
LDADM0007
Sets mode 1 in DM0000.
Sets MAX. setting value (510 ms) in DM0001.
Sets MIN. setting value (490 ms) in DM0002.
Sets the average number of measurements (10) inDM0003.
Measures the pulse interval when input relay 0000turns ON.
Pauses measurement when input relay 0001 turnsON.
Resets measurement when input relay 0002 turnsON.
Writes the average measurement value intoDM0100 and resets 0500 after every time ameasurement is completed.
Turns On output relay 0500 when the pulseinterval is not within the range from 490 to 510mm.
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0015 STA DM00030001 LDA #00001 0016 LD 00000002 CON 0017 LD 00010003 STA DM0000 0018 LD 00020004 LD 2008 0019 ITVL DM0000 10000005 LDA #00051 0020 LD 10020006 CON 0021 LDA DM00070007 STA DM0001 0022 CON0008 LD 2008 0023 STA DM01000009 LDA #00049 0024 CON0010 CON 0025 RES 05000011 STA DM0002 0026 LD 10000012 LD 2008 0027 OR 10010013 LDA #00010 0028 SET 05000014 CON
■ Fetching data from the KV-AN6 (For KV-300 PLC only)
Fetches data from Ch 1 of the KV-AN6. Writes this data value into DM0100.• Mode No. ➞ 9000 (DM0000) from Ch 1 of KV-AN6• MAX. setting value ➞ 2000 (DM0001)• MIN. setting value ➞ 00900 (DM0002)• Average number of measurements ➞ 10 (DM0003)Reset input relay 0002
8.2 Details
3-338
8
Chapter 8 Programming Examples
2008
2003
0001
0002
DM0000PLS
ITVL
PAUSE
RES1000
STADM0000
LDA#09000
2008STA
DM0001LDA
#02000
2008STA
DM0002LDA
#00900
2008STA
DM0003LDA
#00010
1003STA
DM0100LDA
DM0007
2008STA
DM0002LDA
#03000
0001
2002CMP
DM0000LDA
CTH1
STADM0001
LDA#02000
STADM0000
LDA#01000
SET2813
CTH100005
2009 0500
CMPDM0001 2009 0501
CMPDM0002 2009 0502
Ladder diagram Coding
➮ Refer to p. 3-117.
Applications of High-speed counter
■ High-speed counter multi-level setting
Sets the high speed counter comparator value of the input relay 0005 as below:• #0100 ➞ DM0000• #0200 ➞ DM0001• #0300 ➞ DM0002
When a comparator value is greater than the setting value:• DM0000 ➞ 0500 turns ON.• DM0001 ➞ 0501 turns ON.• DM0002 ➞ 0502 turns ON.
Ladder diagram Coding
Line No. Instruction Operand0000 LD 20080001 LDA #090000002 CON0003 STA DM00000004 LD 20080005 LDA #020000006 CON0007 STA DM00010008 LD 20080009 LDA #009000010 CON0011 STA DM00020012 LD 20080013 LDA #000100014 CON0015 STA DM00030016 LD 20030017 LD 00010018 LD 00020019 ITVL DM0000 10000020 LD 10030021 LDA DM00070022 CON0023 STA DM0100
Line No. Instruction Operand0000 LD 20080001 SET 28130002 CON0003 LDA #010000004 CON0005 STA DM00000006 CON0007 LDA #020000008 CON0009 STA DM00010010 CON0011 LDA #030000012 CON0013 STA DM00020014 LDB 00010015 CTH1 00050016 LD 20020017 LDA CTH10018 MPS0019 CMP DM00000020 ANB 20090021 OUT 05000022 MRD0023 CMP DM00010024 ANB 20090025 OUT 05010026 MPP0027 CMP DM00020028 ANB 20090029 OUT 0502
8.2 Details
3-339
18
Chapter 8 Programming Examples
2008
2002 CTH10005
RESCTH1
SET2203
SET2813
#60000CTC2
CTC2RES0502
RESCTC2T0010502 #00030
T001
■ High-speed counter current value clear
Counts pulses at input relay 0005. When the count value reaches setting value60000, clears the current value of high speed counter CTH1 and turns ON outputrelay 0502 for 3 s.
Ladder diagram Coding
■ Input of phase differential signal
Inputs phase differential signals to input relays 0004 and 0006 and counts pulses atCTH0.Writes the count value into DM0000.When high speed counter CTH0 reaches 60000, clears the current value of CTH0,sets output relay 0500, and stops fetching count value to CTH0.Sets 0008 as external reset.
Ladder diagram
Note: Initial settings for special utility relays
• Sets input time constant of input relays 0000 to 0009 to 10 µs when 2813 turnsON.
• Clears the current value of CTH0 when 2103 turns ON and CTC0 is ON.• Sets CTH0 in the X 2 mode when 2113 is ON and 2114 is OFF.• Enables external reset (input relay 0008) when 2115 turns ON.
Line No. Instruction Operand0000 LD 20080001 SET 28130002 CON0003 SET 22030004 CON0005 RES CTH10006 LD 20020007 CTH1 00050008 CTC2 #600000009 LD CTC20010 OUT 05020011 CON0012 TMR 001 #000300013 CON0015 AND T0010016 RES CTC20017 CON0018 RES 0502
2008RES
CTH0SET2115
0500RES2114
SET2113
SET2103
SET2813
EI
CTH000004#60000CTC02002
STADM0000
LDACTH0
END
INTCTC0
2002SET0500
RETI
ENDH
Initial settings*Note
8.2 Details
3-340
8
Chapter 8 Programming Examples
0000STA
TM03LDA
#00030STA
TM02LDA
#00010
END
00CALL
2002
NEXT
RET
ENDH
SBN00
2002STA
TM05SUB
TM02STA
TM04ADD
#00001LDA
TM03
FORTM05
2002STA
#TM04LDA
#TM03DECTM04
DECTM03
STA#TM02
LDA#00000
1000DIFU
1000 Shifts data from DM0010 to DM0030.
Designates the shift start DM No. (DM0010).
Designates the shift end DM No. (DM0030).
Uses the indirect addressing function to designate DM Nos.
Clears the start DM to #0000 after the data is shifted.
The program lines which execute the data shift are groped as the subroutine.
Shift level
Synchoronous signal
External reset 0008 is predetermined on hardware even if you do not specify inthe program. However, you have to set external reset enable relay 2115 to ON.
Coding
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0014 LDB 05000001 EI 0015 CTH 1 00040002 CON 0016 CTC 0 #600000003 SET 2813 0017 LD 20020004 CON 0018 LDA CTH00005 SET 2103 0019 CON0006 CON 0020 STA DM00000007 SET 2113 0021 END0008 CON 0022 INT CTC00009 RES 2114 0023 LD 20020010 CON 0024 SET 05000011 SET 2115 0025 RETI0012 CON 0026 ENDH0013 RES CTH0
Application of Subroutine CALL
■ DM shift
Shifts the data from current DM to the next DM at UP edge of the synchronoussignal (timing).As the number of DMs to be shifted increases, the required scan time becomeslonger.
Ladder diagram
CAUTION
8.2 Details
3-341
18
Chapter 8 Programming Examples
Coding
➮ Refer to p. 3-122.
Application of FOR-NEXT
■ Transfer of a block of DM data
Uses the indirect addressing function to transfer a block of data from DM0000 -DM0099 to DM0100 - DM0199.
Ladder diagram Coding
Line No. Instruction Operand Line No. Instruction Operand0000 LD 0000 0021 CON0001 DIFU 1000 0022 SUB TM020002 CON 0023 CON0003 AND 1000 0024 STA TM050004 LDA #00010 0025 FOR TM050005 CON 0026 LD 20020006 STA TM02 0027 DEC TM030007 CON 0028 CON0008 LDA #00030 0029 DEC TM040009 CON 0030 CON0010 STA TM03 0031 LDA #TM030011 CON 0032 CON0012 CALL 00 0033 STA #TM040013 END 0034 NEXT0014 SBN 00 0035 LD 20020015 LD 2002 0036 LDA #000000016 LDA TM03 0037 CON0017 CON 0038 STA #TM020018 ADD #00001 0039 RET0019 CON 0040 ENDH0020 STA TM04
➮ Refer to p. 3-125.
FOR
NEXT
RET
SBN01
2002STA
TMO3LDA
#00100STA
TMO2LDA
#0000
2002INC
TM03INC
TM02STA
#TM03LDA
#TM02
#00100
1st DM No. of transfer source
1st DM No. of transfer destination
Number of DMs to be Transferred.
Line No. Instruction Operand0000 SBN 010010 LD 20020001 LD 20020011 LDA #TM020002 LDA #00000012 CON0003 CON0013 STA #TM030004 STA TM020014 CON0005 CON0015 INC TM020006 LDA #001000016 CON0007 CON0017 INC TM030008 STA TM030018 NEXT0009 FOR #001000019 RET
DM0000
DM0099
DM0100
DM0199
Transfer a block of data
Data memory
8.2 Details
3-342
8
Chapter 8 Programming Examples
2008SET2814
2815
END
ENDH
HKEY0000
STADM0000
ORATM06
SLA#04
LDADM0000
DW#00000
2815DMXSTA
TM05CMPTM05
ANDA$03FF2010
0500
LDA2900
KEY IN
Input value (BCD)
2010STA
TM06
2002
2815STA
TM05CMPTM05
ANDA$03FF2010
LDA2900 2010
2915
DM0000
Input value (BCD)
24 VDC COM 000 001 002 003
COM 500 501 502 503KV
0 1 2 3
4 5 6 7
8 9 A B
C D E F
Application of HKEY instruction
■ Fetching 16-key input
Writes the following 16-key input value into DM0000 in 4-digit BCD.Pressing the keys in the lower line clear the input numerical value.Wires the 16-key input terminals using 4 outputs and 4 inputs as shown below.
Ladder diagram
Coding
➮ Refer to p. 3-131.
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0021 AND 20100001 SET 2814 0022 ANDA $03FF0002 LD 2002 0023 CON0003 HKEY 0000 0500 0024 CMP TM050004 LD 2815 0025 CON0005 LDA 2900 0026 ANB 20100006 CON 0027 STA TM050007 ANB 2010 0028 CON0008 ANDA $03FF 0029 LDA DM00000009 CON 0030 CON0010 CMP TM05 0031 SLA #040011 CON 0032 CON0012 ANB 2010 0033 ORA TM060013 STA TM05 0034 CON0014 CON 0035 STA DM00000015 DMX 0036 LD 28150016 CON 0037 AND 29150017 STA TM06 0038 DW #0000 DM00000018 LD 2815 0039 END0019 LDA 2900 0040 ENDH0020 CON
8.2 Details
3-343
18
Chapter 8 Programming Examples
2002
0000
0500
#00010T000
0500 T000
STAT000
TMIN0
2002
0000
0500
#00010T000
0500 T000
STAT002
STAT001
STAT000
TMIN0
0001
0501
#00010T001
0501 T001
0002
0502
#00010T002
0502 T002
Arithmetic Instructions
Applications of TMIN (Analog timer) instruction
■ Changing timer setting value
Uses analog timer (TMIN0) to change the timer setting value (0 to 24.9 s).
Ladder diagram Coding
■ Changing setting values of multiple timers
Uses analog timer (TMIN0) to change setting values of multiple timers (0 to 24.9 s).
Ladder diagram Coding
* In the above example, T000, T001,and T002 have the same setting value.
➮ Refer to p. 3-138.
Applications of LDA/STA instruction
■ First-in first-out (FIFO)
DM data flow
Line No. Instruction Operand0000 LD 20020001 TMIN 00002 CON0003 STA T0000004 LD 00000005 OR 05000006 TMR 000 #000100007 ANB T0000008 OUT 0500
Line No. Instruction Operand0000 LD 20020001 TMIN 00002 CON0003 STA T0000004 CON0005 STA T0010006 CON0007 STA T0020008 LD 00000010 TMR 000 #000100011 ANB T0000012 OUT 05000013 LD 00010014 OR 05010015 TMR 001 #000100016 ANB T0010017 OUT 05010018 LD 00020019 OR 05020020 TMR 002 #000100009 OR 05000021 ANB T0020022 OUT 0502
D M 0 0 0 2
D M 0 0 0 0
D M 0 0 0 1
D M 0 0 0 3
D M 0 0 0 4
Data shift
OK/NG judgement
Unloading timing
8.2 Details
3-344
8
Chapter 8 Programming Examples
Line No. Instruction Operand Line No. Instruction Operand0000 LD 0000 0035 STA DM00030001 DIFU 1000 0036 CON0002 CON 0037 LDA $00000003 AND 1000 0038 CON0004 MPS 0039 STA DM00020005 AND 0001 0040 LD 20020006 LDA $1111 0041 LDA DM00020007 CON 0042 CON0008 STA DM0000 0043 CMP $00000009 MPP 0044 CON0010 ANB 0001 0045 AND 20100011 LDA $5555 0046 LDA DM00010012 CON 0047 CON0013 STA DM0000 0048 STA DM00020014 LD 2002 0049 CON0015 LDA DM0004 0050 LDA $00000016 CON 0051 CON0017 CMP $0000 0052 STA DM00010018 CON 0053 LD 20020019 AND 2010 0054 LDA DM00010020 LDA DM0003 0055 CON0021 CON 0056 CMP $00000022 STA DM0004 0057 CON0023 CON 0058 AND 20100024 LDA $0000 0059 LDA DM00000025 CON 0060 CON0026 STA DM0003 0061 STA DM00010027 LD 2002 0062 CON0028 LDA DM0003 0063 LDA $00000029 CON 0064 CON0030 CMP $0000 0065 STA DM00000031 CON 0066 LD 00020032 AND 2010 0067 @LDA $00000033 LDA DM0002 0068 CON0034 CON 0069 @STA DM0004
The data once fetched is written into DM0004, DM0003, ..., DM0000 in this order. Atthe unloading timing, unload the data from DM0004 and shifts the data value to thenext DM.
The ON/NG judgement and unloading timings can be used in asynchronous pro-grams.
Ladder diagram
Coding
2002LDA$0000
STADM0004
LDADM0003
CMP$0000 2010
LDADM0004
STADM0003
0000LDA
$11111000 0001STA
DM00001000DIFU
Transfers $1111 to DM0000.
LDA$55550001
STADM0000
Transfers $5555 to DM0000.
OK/NG judgementOK/NG judgement timing
2002LDA$0000
STADM0003
LDADM0002
CMP$0000 2010
LDADM0003
STADM0002
2002LDA$0000
STADM0002
LDADM0001
CMP$0000 2010
LDADM0002
STADM0001
2002LDA$0000
STADM0001
LDADM0000
CMP$0000 2010
LDADM0001
STADM0000
0002LDA
$0000STA
DM0004
Unloading timing Transfers $0000 to DM at unloading timing.
Compares the DM value to $0000. If it is equal to $0000, transfers the value of the previous DM No. and then writes $0000 into the current DM No.
8.2 Details
3-345
18
Chapter 8 Programming Examples
2002
0005 #9999C000
STAC000
LDADM0000
0001
■ Changing the counter setting value
Sets the setting value of counter C000 to DM0000. Reset input is 0005.
Ladder diagram Coding
■ Changing the timer setting value
Sets the setting value of timer T000 to DM0000. Reset input is 0005.
Ladder diagram Coding
➮ Refer to p. 3-140.
Application of CMP (compare) instruction
■ When comparing values with no specific rangeTurns ON 0500 when the DM0000 value is smaller than the CMP value.Turns ON 0501 when the DM0000 value is equal to the CMP value.Turns ON 0502 when the DM0000 value is greater than the CMP value.
Ladder diagram Coding
■ Setting the upper/lower limitTurns ON 0500 when the C001 value is 1000 or less.Turns ON 0501 when the C001 value is 2000 or more.
Ladder diagram
Line No. Instruction Operand0000 LD 2002
0001 LDA DM0000
0002 CON
0003 STA C0000004 LDB 0005
0005 C 000 #9999 0001
2002
0005 #9999T000
STAT000
LDADM0000 Line No. Instruction Operand
0000 LD 2002
0001 LDA DM0000
0002 CON
0003 STA T0000004 LDB 0005
0005 T 0000 #9999
2002
05022011
CMP
#01000
LDA
DM000 05002009
DM0000 <#01000
DM0000 =#01000
DM0000 >#01000
05012010
Line No. Instruction Operand0000 LD 2002
0001 LDA DM0000
0002 CON
0003 CMP #010000004 MPS
0005 AND 2009
0006 OUT 0500
0007 MRD0008 AND 2010
0009 OUT 0501
0010 MPP
0011 AND 20110012 OUT 0502
2002
0001 #09999C001
CMP
#02000
LDA
C001 05012009
C001≤#1000
C001≥#02000
2002
CMP
#01000
LDA
C001 050020110000
8.2 Details
3-346
8
Chapter 8 Programming Examples
2002
05012009
CMP
DM0000
LDA
C000 05002009
2002DIV
#00010MUL
#00004ADD
#00001TMIN
0
0001 #09999C00000000
STADM0000
Sets the TMIN setting range from 0 to 100.
Coding
Line No. Instruction Operand Line No. Instruction Operand0000 LDB 0001 0008 OUT 05000001 C 001 #09999 0000 0009 LD 20020002 LD 2002 0010 LDA C0010003 LDA C001 0011 CON0004 CON 0012 CMP #020000005 CMP #01000 0013 CON0006 CON 0014 ANB 20090007 ANB 2011 0015 OUT 0501
■ Changing the CMP setting valueCompares the current value of C000 to the CMP setting value. Sets the CMP settingvalue to analog timer TMIN0.The following example changes the setting value within the range from 0 to 100.Turns ON 0500 when the C000 value is smaller than the CMP setting value.Turns ON 0501 when the C000 value is greater than the CMP setting value.
Ladder diagram
Coding
■ Multi-level comparator
Compares the counter current value according to the following range:• 0 to 999 → 0500 turns ON.• 1000 to 1999 → 0501 turns ON.• 2000 to 2999 → 0502 turns ON.Counter reset relay 0001Counter input relay 0000
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2002 0011 C 000 #09999 00000001 TMIN 0 0012 LD 020020002 CON 0013 LDA C0000003 ADD #00001 0014 CON0004 CON 0015 CMP DM00000005 MUL #00004 0016 MPS0006 CON 0017 AND 20090007 DIV #00010 0018 OUT 05000008 CON 0019 MPP0009 STA DM0000 0020 ANB 20090010 LDB 0001 0021 OUT 0501
8.2 Details
3-347
18
Chapter 8 Programming Examples
0001 #09999C000
2002 0500#00999C000 ≤ 00999LDA
C000CMP
0501
0502
2011
#01999CMP
2011 0500
#02999CMP
2011 0500 0501
0000
00999 < C000 ≤ 01999
01999 < C000 ≤ 02999
Ladder diagram
Coding
➮ Refer to p. 3-146.
Application of ADD instruction
■ Adding BCD and BIN valuesAdds a 4-digit BCD input value (7000 to 7015) to the counter current value andwrites the sum into DM0100.
Ladder diagram
Coding
2002
0001 #09999C001
ADD
DM0000
LDA
C001
2002
TBINLDA
7000
0000
STA
DM0100
STA
DM0000Converts BCD input value to BIN.
Adds converted BIN value to the current value ofC001 and writes the sum into DM0100.
Line No. Instruction Operand Line No. Instruction Operand0000 LDB 0001 0012 CON0001 C 000 #09999 0000 0013 ANB 20110002 LD 2002 0014 ANB 05000003 LDA C000 0015 OUT 05010004 CON 0016 MPP0005 MPS 0017 CMP #029990006 CMP #00999 0018 CON0007 CON 0019 ANB 20110008 ANB 2011 0020 ANB 05000009 OUT 0500 0021 ANB 05010010 MRD 0022 OUT 05020011 CMP #01999
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2002 0007 LDA C0010001 LDA 7000 0008 CON0002 CON 0009 ADD DM00000003 TBIN 0010 CON0004 CON 0011 STA DM01000005 STA DM0000 0012 LDB 00010006 LD 2002 0013 C 001 #09999 0000
8.2 Details
3-348
8
Chapter 8 Programming Examples
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2002 0012 LDA DM00010001 LDA DM0000 0013 CON0002 CON 0014 SUB DM00000003 SUB DM0001 0015 CON0004 MPS 0016 CMP #000050005 ANB 2009 0017 CON0006 CMP #00005 0018 ANB 20090007 CON 0019 OUT 10010008 ANB 2009 0020 LD 10000009 OUT 1000 0021 OR 10010010 MPP 0022 OUT 05000011 AND 2009
0000LDAC001
STADM0001#09999
C0010001
0000LDAC002
STADM0002#09999
C0020002
0000LDAC003
STADM0003#09999
C0030003
2002ADD
DM0002LDA
DM0001STA
DM0100ADD
DM0003
2002CMP
#00052009LDA
DM0000SUB
DM0001 10002009
CMP#0005
SUBDM0000
LDADM00012009 10012009
1000 0500
1001
■ Total count
Writes total count of counters C001 to C003 into DM0100. The total count must bewithin 65535.
Ladder diagram
Coding
Line No. Instruction Operand Line No. Instruction Operand0000 LDB 0000 0013 C 003 #09999 00030001 C 001 #09999 0001 0014 CON0002 CON 0015 LDA C0030003 LDA C001 0016 CON0004 CON 0017 STA DM00030005 STA DM0001 0018 LD 20020006 LDB 0000 0019 LDA DM00010007 C 002 #09999 0002 0020 CON0008 CON 0021 ADD DM00020009 LDA C002 0022 CON0010 CON 0023 ADD DM00030011 STA DM0002 0024 CON0012 LDB 0000 0025 STA DM0100
Writes C001 current value into DM0001.
Writes C002 current value into DM0002.
Writes C003 current value into DM0003.
Writes total count (DM0001 + CM0002 + DM0003) intoDM100.
➮ Refer to p. 3-150.
Application of SUB instruction
■ Comparison of absolute values
Compares the DM0000 value to the DM0001 value and turns ON 0500 when thedifference of the two absolute values is greater than 5.
Ladder diagram
Coding
➮ Refer to p. 3-150.
8.2 Details
3-349
18
Chapter 8 Programming Examples
2002LDATM00
STADM0100
MULDM0000
LDAC001
0001 #09999C0010000
STADM0101
#09999
00001C001
0000STA
DM0001LDA
C001
2002
DM0001 DM0002 DM0003
÷3 → Output to 07500 to 07515 in 4-digit BCD.
2002
#09999C002
0000STA
DM0002LDA
C002
#09999C003
0000STA
DM0003LDA
C003
ADDLDADM0001
ADDDM0003
TBCDDIV#00003
STA07500
00002
00003DM0002
Writes the C001 current value into DM0001.
Writes the C002 current value into DM0002.
Writes the C003 current value into DM0003.
Application of MUL instruction
■ Multiplying the counter current value by DM value
Multiplies the counter current value by the DM0000 value and writes the high-order16 bits of the product into DM0101 and low-order 16 bits of the product intoDM0100.
Ladder diagram Coding
➮ Refer to p. 3-150.
Application of DIV instruction
■ Total count average
Outputs the average of 3 counter values in 4-digit BCD.(C001 + C002 + C003) ÷ 3 → BCD output valueThe BCD value is output to 7500 to 7515.
Ladder diagram
Coding
Line No. Instruction Operand0000 LDB 00010001 C 001 #09999 00000002 LD 20020003 LDA C0010005 MUL DM00000004 CON0006 CON0007 STA DM01000008 CON0009 LDA TM000010 CON0011 STA DM0101
Line No. Instruction Operand Line No. Instruction Operand0000 LDB 0000 0015 LDA C0030001 C 001 #09999 0001 0016 CON0002 CON 0017 STA DM00030003 LDA C001 0018 LD 20020004 CON 0019 LDA DM00010005 STA DM0001 0020 CON0006 LDB 0000 0021 ADD DM00020007 C 002 #09999 0002 0022 CON0008 CON 0023 ADD DM00030009 LDA C002 0024 LD 20020010 CON 0025 DIV #000030011 STA DM0002 0026 CON0012 LDB 0000 0027 TBCD0013 C 003 #09999 0003 0028 CON0014 CON 0029 STA 7500
➮ Refer to p. 3-150.
8.2 Details
3-350
8
Chapter 8 Programming Examples
➮ Refer to p. 3-159.
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2002 0011 ANDA $FF00
0001 LDA 7000 0012 CON
0002 CON 0013 SRA #08
0003 ANDA $00FF 0014 CON0004 CON 0015 TBIN
0005 TBIN 0016 CON
0006 CON 0017 STA T001
0007 STA C000 0018 LDB 00010008 LD 2002 0019 C 000 #09999 0000
0009 LDA 7000 0020 LDB 0001
0010 CON 0021 T 001 #09999
Application of ANDA instruction
■ BCD (1-digit) input
Sets a 1-digit BCD value, which is input to 0000 to 0003, in C000.
Ladder diagram
Coding
■ Fetches input data separately
Sets the low-order 2 digits of the BCD digital switch (7000 to 7007) to counter C000and the high-order 2 digits to timer T001.
Ladder diagram
Coding
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2002 0005 TBIN0001 LDA 0000 0006 CON0002 CON 0007 STA C0000003 ANDA $000F 0008 LDB 70000004 LD 2002 0009 C 000 #09999 7001
2002ANDA$000F
LDA0000
2002STAC000
TBIN
#09999C000
7000
7001
Fetches data of 0000 to 0015 and retains data of 0000to 0003 only.
Converts data to BIN and writes it into C000.
Sets C000.
2002
2002LDA
#09999C000
0001
0000
7000ANDA$FF00
TBIN#08
SRA STAT001
LDA7000
ANDA$00FF
STAC000
TBIN
#09999T001
0001
Converts data of 7000 to 7007 to BIN andwrites it into C000.
Shifts data to right by 8 bits, converts it toBIN, and writes it into T001.
Sets C000.
Sets T001.
8.2 Details
3-351
18
Chapter 8 Programming Examples
Application of ORA instruction
■ Output of BCD 2-digit data
Converts the current value of counter C000 to BCD and sends 2 digits of BCD datato output relays 7500 to 7507.However, retain ON/OFF of 7508 to 7515 which are loaded.
Ladder diagram
Coding
■ Separate input of 2-digit BCDFetches only 2 digits of the BCD digital switch (7000 to 7003 for the 1st digit, 8000 to8003 for the 2nd digit) and sets it as the counter value.
Ladder diagram
Coding
➮ Refer to p. 3-161.
#00099
0001C000
0000
2002
2002STA
DM0000ANDA$FF00
2002ANDA$00FF
TBCD
STAORADM0000 7500
LDA7500
LDAC000
Sets C000.
Writes data of 7008 to 7015 into DM0000.
ORs the data in the internal register and theDM0000 data and sends the ORed data to 7500to 7515.
Converts the current value of C000 to BCD andretains the low-order 2 digits of BCD in theinternal register.
Line No. Instruction Operand Line No. Instruction Operand0000 LDB 0000 0009 LDA C0000001 C 000 #00099 0001 0010 CON0002 LD 2002 0011 TBCD0003 LDA 7500 0012 CON0004 CON 0013 ANDA $00FF0005 ANDA $FF00 0014 LD 20020006 CON 0015 ORA DM00000007 STA DM0000 0016 CON0008 LD 2002 0017 STA 7500
#00099
0001C001
0000
2002
2002STA
DM0000ANDA$000F
2002ANDA$000F
LDA7000
LDA8000
SLA#04
ORADM0000
STAC001
TBIN
Line No. Instruction Operand Line No. Instruction Operand0000 LDB 0000 0010 CON0001 C 001 #00099 0001 0011 ANDA $000F0002 LD 2002 0012 LD 20020003 LDA 7000 0013 SLA #040004 CON 0014 CON0005 ANDA $000F 0015 ORA DM00000006 CON 0016 CON0007 STA DM0000 0017 TBIN0008 LD 2002 0018 CON0009 LDA 8000 0019 STA C001
8.2 Details
3-352
8
Chapter 8 Programming Examples
1 0 1 1 1 0 1 1 1 0 1 1 1 0 1 1D15D14D13D12D11D10 D9 D8 D7 D6 D5 D4 D3 D2 D1 D0
0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 0 1 1 1 0 1 1
0 0 0 0 0 0 0 0 1 0 1 0 1 0 1 0
0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 1
ANDA
EORA
$BBBB
$00FF
$00BB
$00AA
$0011
7000 to 7015
Operand
Internal register
DM0000
Internal register → 2010 is OFF. When the value of internal register is 0000, 2010 turns ON.
Judges match between the operand and the data of 7000 to 7015.
#00099
0000C001
0001
2002
2002ANDA$F000
2002STA
ANDALDA08000
DM0000
LDA7000
SRA#12
2002
2002ORA
STATBINC001
SLA#04
$000F
DM0000
Sets C001.
Sends the data of 7012 to 7015 to internalregister.
Shifts the value of internal register to right by12 bits and writes it into DM0000.
Sends the data of 8000 to 8003 to internalregister.
Shifts the data of internal register to left by 4bits, ORs the internal register data and thedata of DM0000, and sends the ORed data tointernal register.
Converts the data of internal register to BINdata and writes it into C001.
2008
2002LDA7000
ANDA$00FF DM0000
EORA
LDA$00AA
STADM0000
2010 0500
Application of EORA instruction
■ Judgement of matching data
Turns ON 0500 (“OK” output) when the ON/OFF statuses of input relays 7000 to7007 match the DM0000 setting value.
Ladder diagram Coding
For easy comprehension, the following data is set temporarily.
When 2010 is ON, the two values match.When 2010 is OFF, the two values do not match.➮ Refer to p. 3-164.
Application of SRA/SLA instructions
■ Separate input of BCD
Fetches only 2 digits of the BCD digital switch (7012 to 7015 for the 1st digit, 8000 to8003 for the 2nd digit) and sets it as the counter value.
Ladder diagram
Line No. Instruction Operand0000 LD 20080001 LDA $00AA0002 CON0003 STA DM00000004 LD 20020005 LDA 70000006 CON0007 ANDA $00FF0008 CON0009 EORA DM00000010 CON0011 AND 20100012 OUT 0500
8.2 Details
3-353
18
Chapter 8 Programming Examples
Coding
➮ Refer to p. 3-166.
Application of RRA/RLA instructions
■ Error input countWrites the number of error detection sensors, which are connected to input relays(7000 to 7015) and turn ON, into DM0000.
Ladder diagram
Coding
➮ Refer to p. 3-169.
Applications of INC/DEC instructions
■ Total count
Writes the total count of 4 lines (0000 to 0003) into DM0000.Reset input relay is 0005.
Line No. Instruction Operand Line No. Instruction Operand0000 LD 0001 0011 LDA 80000001 C 001 #00099 0000 0012 CON0002 LD 2002 0013 ANDA $000F0003 LDA 7000 0014 LD 20020004 CON 0015 SLA #040005 ANDA $F000 0016 CON0006 LD 2002 0017 ORA DM00000007 SRA #12 0018 LD 20020008 CON 0019 TBIN0009 STA DM0000 0020 CON0010 LD 2002 0021 STA C001
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2002 0009 LD 20020001 LDA 7000 0010 LDA TM100002 FOR #00016 0011 CON0003 LD 02002 0012 STA DM00000004 RRA #01 0013 CON0005 CON 0014 LDA #000000006 AND 2009 0015 CON0007 INC TM10 0016 STA TM100008 NEXT
Writes the TM10 data into DM0000, and then writes#00000 to TM10.
2002
RRA#01
INCTM10
LDA7000
#00016
2002
LDATM10
LDADM0000
STA STATM102002
2009
#00000
NEXT
FOR
Writes the data of 7000 to7015 into internal register.
Executes FOR-NEXT instruction for 16 times.
Shifts the data including carry (2009) to right,and increments TM10 by 1 when 2009 is ON.
8.2 Details
3-354
8
Chapter 8 Programming Examples
2008STA
DM0000LDA
#00000
0000INC
DM0000
0005DW
#00000
0001DEC
DM0000
DM0000
Sets #00000 to DM0000 at startup.
Increments DM0000 by 1 at UP edgeof input relay 0000.
Decrements DM0000 by 1 at UP edgeof input relay 0001.
Clears DM0000 to #00000 when 0005turns ON.
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0005 @INC DM00000001 LDA #00000 0006 LD 00010002 CON 0007 @DEC DM00000003 STA DM0000 0008 LD 00050004 LD 0000 0009 DW #00000 DM0000
Ladder diagram
Coding
■ UP/DOWN count
Performs UP count when input relay 0000 turns ON.Performs DOWN count when input relay 0001 turns ON.Writes the count value into DM0000.Reset input relay is 0005.
Ladder diagram
Coding
➮ Refer to p. 3-172.
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2008 0007 @INC DM00000001 LDA #00000 0008 LD 00020002 CON 0009 @INC DM00000003 STA DM0000 0010 LD 00030004 LD 0000 0011 @INC DM00000005 @INC DM0000 0012 LD 00050006 LD 0001 0013 DW #00000 DM0000
2008STA
DM0000LDA
#00000
0000INC
DM0000
0003INC
DM0000
0005DW
#00000
0001INC
DM0000
0002INC
DM0000
DM0000
Sets #00000 to DM0000 at startup.
Increments DM0000 by 1 at UPedge of input relay 0000.
Increments DM0000 by 1 at UPedge of input relay 0001.
Increments DM0000 by 1 at UPedge of input relay 0002.
Increments DM0000 by 1 at UPedge of input relay 0003.
Clears DM0000 to #00000 when0005 turns ON.
8.2 Details
3-355
18
Chapter 8 Programming Examples
a
f b
e c
g
d
a. 7500
b. 7501
c. 7502
d. 7503
e. 7504
f. 7505
g. 7506
Application of MPX instruction
■ Display of 7-segment LED
Displays the current value of counter C000 to the 7-segment LED.Outputs from 7500 to 7571.Connection of 7 segmentsConnect each of 7 segments to output relays as shown below:
Ladder diagram Coding
1000
1004
1005
1006
STA7500
LDA$003F
1001STA7500
LDA$0006
1002STA7500
LDA$005B
1003STA7500
LDA$004F
1007STA7500
LDA$0007
C000 #00009C000 STA
1000MPX#0
LDAC000
0000
Converts the counter value to 16-bit data using the MPX instruction.Auto reset counter
STA7500
LDA$0066
STA7500
LDA$006D
STA7500
LDA$007D
Sends internal register data to output relays starting from 7500.
1008STA7500
LDA$007F
1009STA7500
LDA$006F
0
1
2
3
4
5
6
7
8
9
7-segment display
Line No. Instruction Operand0000 LDB C0000024 LD 10040001 C 000 #00009 00000025 LDA $00660002 CON0026 CON0003 LDA C0000027 STA 75000004 CON0028 LD 10050005 MPX #00029 LDA $006D0006 CON0030 CON0007 STA 10000031 STA 75000008 LD 10000032 LD 10060009 LDA $003F0033 LDA $007D0010 CON0034 CON0011 STA 75000035 STA 75000012 LD 10010036 LD 10070013 LDA $00060037 LDA $00070014 CON0038 CON0015 STA 75000039 STA 75000016 LD 10020040 LD 10080017 LDA $005B0041 LDA $007F0018 CON0042 CON0019 STA 75000043 STA 75000020 LD 10030044 LD 10090021 LDA $004F0045 LDA $006F0022 CON0046 CON0023 STA 75000047 STA 7500
➮ Refer to p. 3-176.
8.2 Details
3-356
8
Chapter 8 Programming Examples
2002DMXLDA
07000
2002ANDATBCD$00FF
STA8000
STA7500
TBCDLDA
0001 #09999C001
2002 C001
0000
Converts the most significant bit of 16-bit data(7000 to 7015) to 4-bit BIN data and sends it tointernal register.Converts internal register data to BCD data,executes ANDA instruction, and outputs the datato 8000 to 8015.
Line No. Instruction Operand Line No. Instruction Operand
0000 LDB 0001 0004 CON
0001 C 001 #09999 0000 0005 TBCD
0002 LD 2002 0006 CON
0003 LDA C001 0007 STA 7500
DM0000 x DM0001 = TM00 Internal register
DM00 Internal register ÷ #10000 = TM00 Internal register --- TM01
(High-order 4 digits) (Low-order 4 digits)
(High-order 4 digits) (Low-order 4 digits) (Remainder)
8500 to 8515 7500 to 7515
(Display)
(High-order 4 digits) (Low-order 4 digits)
Application of DMX instruction
■ Output of error input No. in BCD
Outputs the error sensor No. from input relay 7000 to 7015 to output relays 8500 to8507 in 2-digit BCD.
Ladder diagram
Coding
➮ Refer to p. 3-176.
Applications of TBCD instruction
■ Output of 4-digit BCD data
Outputs the current value of counter C001 to 7500 to 7515 in 4-digit BCD data.
Ladder diagram
Coding
■ Output of 8-digit BCD data
Outputs the calculated product of DM0000 x DM0001 (0 to 99999999) in BCD of 8digits at maximum as below:
High-order 4-digit BCD data ➞ To 8500 to 8515Low-order 4-digit BCD data ➞ To 7500 to 7515
Line No. Instruction Operand Line No. Instruction Operand0000 LD 2002 0005 TBCD0001 LDA 7000 0006 CON0002 CON 0007 ANDA $00FF0003 DMX 0008 CON0004 LD 2002 0009 STA 8000
8.2 Details
3-357
18
Chapter 8 Programming Examples
MULLDA2002
LDASTADIV TBCD STADM0000 DM0001 #10000 DM0101 TM01 7500
LDA TBCD STADM0101 8500
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0010 CON
0001 LDA DM0000 0011 TBCD
0002 CON 0012 CON
0003 MUL DM0001 0013 STA 750
0004 CON 0014 CON
0005 DIV #10000 0015 LDA DM0101
0006 CON 0016 CON
0007 STA DM0101 0017 TBCD
0008 CON 0018 CON
0009 LDA TM01 0019 STA 8500
2002TBINLDA
7000STAC001
#09999
0000C001
0001
Converts data of 7000 to 7015 to BINdata and writes it into C001.
Sets C001.
Line No. Instruction Operand Line No. Instruction Operand
0000 LD 2002 0004 CON
0001 LDA 7000 0005 STA C001
0002 CON 0006 LDB 0001
0003 TBIN 0007 C 001 #09999 0000
Ladder diagram
Coding
➮ Refer to p. 3-180.
Application of TBIN instruction
■ Output of 4-digit BCD data
Sets 4 digits of the BCD digital switch (7000 to 7015) as the counter C001 value.
Ladder diagram
Coding
➮ Refer to p. 3-183.
8.2 Details
3-358
8
Chapter 8 Programming Examples
Index
Inde
x
Index3-360
Index — For Visual KV User’s OnlyThe following is the index with some descriptions for your reference.
Index — For Visual KV User’s Only
esopruP eltiT egaP
A
nieulavecivedgnignahc,wodniWsseccA edomeciveD 78-1
nisedomgnignahc,wodniWsseccA kcolyekgnitteser/gnittesdnasedomgnitceleS 28-1
nisnoitceridgniyalpsid,wodniWsseccA segassemresU 79-1
nisrorregniyalpsid,wodniWsseccA sutatsrorrednasegassemrorrE 79-1
niyalpsidrorre,wodniWsseccA tsiLrorrE 273-1
nideepsnoitcelesecivedgnisaercni,wodniWsseccA noitcnufobruT 38-1
fosnoitcnufsemantrap,wodniwsseccA wodniWsseccAehtfosnoitcnufdnasemantraP 28-1
dnaNURneewtebCLPVKehtgnihctiws,wodniWsseccAnisedom)pots(MARGORP
edoMmetsyS 49-1
niremmirtlatigidgnisu,wodniWsseccA edoMremmirTlatigiD 48-1
tuobagninrael,snoitcurtsninoitacilppA snoitcurtsninoitacilppA 63-3
tuobagninrael,snoitcurtsnicitemhtirA snoitcurtsnicitemhtirA 83-3
B
tuobagninrael,snoitcurtsnicisaB snoitcurtsnicisaB 43-3
C
rofmetignittes,noitcnufhctiwsmaC noitcnufhctiwsmacrofdesueciveD 332-3
saVKgnisu,hctiwsmaC noitcnufhctiwsmaC 332-3
gniriuqca,gnikramEC gnikramECehtgniriuqcanonoitcirtseR )2(
retupmoclanosrepdnaVKneewtebnoissimsnartdnammoC tsilesnopser/dnammocnoitacinummoC 013-3
gnirudsruccororrenehw,noissimsnartdnammoC tsiledocrorrE 613-3
fosnoitacificeps,tropnoitacinummoC noitacificepSsnoitacinummoC 603-3
CLPVKotmehtgnittimsnart,stnemmoctcatnoC noitcnufevastnemmoctcatnoC 72-3
gnitcetorp,stcatnoC noitcetorptcatnoC 96-1
htiwsecnereffid,seiresVKlanoitnevnoC stinularehpirepVKlanoitnevnochtiwytilibitapmoC )4(
noitpmusnoctnerruC snoitacificepslareneG 4-1
D
otdengissasnoitcnuf,yromemataD seiromemataD 91-3
foeniltuo,eslupkcolctceriD tuptuoeslupkcolctceridfoeniltuO 732-3
oitarFFO/NO1:1htiwseslupgnittuptuo,eslupkcolctceriDgnisu
1:1fooitarFFO/NO 832-3
eslupelbairavhtiwseslupgnittuptuo,eslupkcolctceriDhtdiw
htdiweslupelbairaV 832-3
rofmetignittes,eslupkcolctceriDretnuocdeeps-hgihehthtiwgnittestuptuoesluP
rotarapmoc832-3
E
fonoitarepognikcehc,tinunoisnapxE stinunoisnapxerofnoitamrofninoitcennoC 57-1
gnitcennoc,tinunoisnapxE stinunoisnapxeseireSVKlausiVgnitcennoC 17-1
otdetcennocebotrebmunmumixam,tinunoisnapxE stinuelbatcennocforebmuN 37-1
tinucisabepyt-CAhtiwhsulfthgiehstignittes,tinunoisnapxE recapstinunoisnapxE 66-1
gnilbasid,tuptuolanretxE noitcnufnoitibihorptuptuO 62-3
F
hctiwstuohtiwFFO/NOtupnignicroF noitcnufdelbasidhserfertupnI 62-3
rofmetignittes,noitcnufretnuocycneuqerF retnuocycneuqerfehthtiwdesuseciveD 132-3
foegnartnemerusaemgnisaercni,retnuocdeeps-hgiH retnuocdeeps-hgihtib-42 122-3
htiwycneuqerfgnirusaem,retnuocdeeps-hgiH noitcnufretnuocycneuqerF 132-3
gnisuseslupgnittuptuo,retnuocdeeps-hgiH tuptuOesluPkcolCtceriD 732-3
foeulavtnerrucgnidaer,retnuocdeeps-hgiHdeeps-hgihehtfoeulavtnerrucehtgnidaeR
retnuoc112-3
"0"nahtrehtooteulavehtgnitteser,retnuocdeeps-hgiH noitcnufteserP 512-3
Inde
x
Index 3-361
esopruP eltiT egaP
"0"oteulavehtgnitteser,retnuocdeeps-hgiH retnuocdeeps-hgihehtgnitteseR 412-3
rofecruostupnignitceles,retnuocdeeps-hgiH dohtemtupnitnuoC 212-3
fosnoitacificeps,retnuocdeeps-hgiH sretnuocdeeps-hgihfosnoitacificepS 802-3
foeulavteserpehtgniyficeps,retnuocdeeps-hgiHretnuocdeeps-hgihehtfoeulavteserP
rotarapmoc112-3
retnuocgnirsa,gnisu,retnuocdeeps-hgiH noitcnufretnuocgniR 522-3
I
gnignahc,tinucisabfotnatsnocemittupnI noitcnufegnahctnatsnocemittupnI 32-3
gnittes,tinunoisnapxefotnatsnocemittupnI stinunoisnapxeroftnatsnocemittupnI 67-1
fotnednepednisutatsyalergnittuptuo,noitcurtsnitpurretnIemitnacs
tuptuO/tupnItceriD 791-3
tuobagninrael,snoitcurtsnitpurretnI noitcurtsnitpurretnI 14-3
nihtiwdesuebtonnactahtsnoitcurtsni,smargorptpurretnI desuebtonnactahtsnoitcurtsnI 691-3
ybretnuocdeeps-hgihfoeulavtnerrucgnidaer,tpurretnI erutpactupnI 591-3
rofnoitidnoctupnignittes,tpurretnI tupnilanretxenaybstpurretnirofgnittesytiraloP 591-3
detucexeerastpurretnilarevesnehw:tpurretnI ytiroirptpurretnI 691-3
K
gnisu,VKrofREDLIUBREDDAL/)SOD(eraWidercnIVKreddalfonoisrevsuoiverpehtgnisunehwsnoituaC
erawtfostroppus)5(
gnisusnoitcurtsnigniretne,)10(E3P-VK )redrolacitebahpla(tsil.oNnoitcnuF 14-3
htiwelbaliavasnoitcnuf,)10(E3P-VK tsil.soNnoitcnuF 612-1
gnitarepo,)10(E3P-VK noitarepognimmargorpcisaB 002-1
M
foyticapac,dracyromeM yticapacegarotS 032-1
foyrettabgnicalper,dracyromeM yrettabecalperoT 832-1
gnitucexe,MDfonoitareporotarapmocpets-itluM edomrotarapmocpets-itluM 432-3
O
VKmorftuptuognilbasid,tuptuO noitcnufdelbasidtuptuO 62-3
P
VKfognitnuomlenaP lenapaotyltceridtinuagnihcattA 66-1
morfatadgniviecer,retupmoclanosreP atadtxetgnivieceR 813-3
otVKmorfatadgnittimsnart,retupmoclanosreP atadtxetgnittimsnarT 913-3
fonoitaluclac,yticapacmargorP desutnuocetybehtgnitaluclaC 4-3
tuobagninrael,yticapacmargorP yticapacmargorP 4-3
dracyromemotnignivas,smargorP ])10(E3P-VKhtiwdesu[snoitcnuF 032-1
gnivird,rotomesluP erudecorpgnittesretemaraP 552-3
ycneuqerfderisedtatuptuoesluP noitcnuftuptuoeslupycneuqerfdeificepS 822-3
tinucisabotdengissa.soNyaleR tsilyaleR 5-3
tinunoisnapxeotdengissa.soNyaleR stinunoisnapxenisyalerfotsiL 6-3
gningissa,.soNyaleR .soNyalergningissA 8-3
S
MORotniMD/retnuocfoeulavtnerrucgnivaS sedomEVASdnaDAOL 69-1
emitnacS emitnacS 3-3
VKotgnitcennoc,secivedrehtorosrosneS stinucisabrofserudecorpgniriW 76-1
citemhtiranehw,fosutatsniegnahc,syalerytilitulaicepSdesusinoitcurtsni
syalerytilitulaicepsfosutatsniegnahCsnoitcurtsnicitemhtirayb)sgalfcitemhtira(
681-3
otdengissasnoitcnuf,syalerytilitulaicepS tsilyalerytilitulaicepS 68-3
rofmetignittes,noitcnuftuptuoeslupycneuqerfdeificepS tuptuoeslupycneuqerfdeificepsrofdesueciveD 822-3
T
otdengissasnoitcnuf,yromematadyraropmeT yromematadyraropmeT 12-3
forebmunmumixam,sretnuoc/sremiT tsilretnuoC/remiT 81-3
Index — For Visual KV User’s Only
Inde
x
Index3-362
AA/D converter ........................... 1-312 [AN6], 1-334 [AD4]A/D conversion table ................ 1-408 [AN6], 1-357 [AD4]ADD/@ADD: Add .................................................. 3-150AND: And ................................................................ 3-58ANB: And Bar ......................................................... 3-58ANDA/@ANDA: And A ......................................... 3-159ANL: And Load ....................................................... 3-61Application Instructions ...................... 3-36, 3-45, 3-95Arithmetic Instructions ...................... 3-38, 3-48, 3-134ASC/@ASC: ASCII Convert ................................ 3-183Assignment of Data Memory ................................. 3-19Assignment of I/O relay numbers ......................... 3-22
BBasic Instructions ................................ 3-34, 3-42, 3-56Baud rate......................................... 2-136, 1-247 [KV-L2]Break signal .......................................................... 3-308
CC: Counter .............................................................. 3-72CALL: Subroutine Call ......................................... 3-122CMP/@CMP: Compare ......................................... 3-146COM/@COM: Complement .................................. 3-171Commands [Serial communication] ................... 3-310Communications ....................................... 2-135, 3-306CON: Connect ....................................................... 3-102Connector wiring ....................................................... 1-72CTC: Counter Comparator .................................. 3-204CTH1: 16-Bit Counters ......................................... 3-204
DData Memory ........................................................... 3-19D/A converter ........................... 1-312 [AN6], 1-334 [AD4]D/A conversion table ................ 1-408 [AN6], 1-357 [DA4]DEC/@DEC: Decrement Memory ........................ 3-172DI: Interrupt Disabled ........................................... 3-193DIFD: Differentiate Down ....................................... 3-78DIFU: Differentiate Up ........................................... 3-78Dimensions ............................................................. 1-404DIN rail (mounting) .................................................. 1-180Direct Clock Pulse ................................................ 3-276Display Interface Mode [KV-L2] .............................. 1-244DIV/@DIV: Divide .................................................. 3-150DMX/@DMX: Demultiplexer ................................. 3-176DW: Data Memory Write ...................................... 3-136
EEI: Interrupt Enabled ............................................ 3-193END: End ................................................................. 3-94ENDH: End Hi ......................................................... 3-94ENDS: End Stage ................................................. 3-106Environment requirements ........................................ 1-64EORA/@EORA: Exclusive Or A .......................... 3-164Error code list .......................................................... 1-372Extended Ladder Diagrams ................................... 3-29
Index — For KV-300, KV-10/80 User’s Only
Index — For KV-300, KV-10/80 User’s Only
FFOR: Repeat Start ................................................ 3-125
HHigh-Speed Counters .......................................... 3-276HKEY: 16 Key Input .............................................. 3-131HSP: High Speed .................................................... 3-86
IINC/@INC: Increment Memory ............................ 3-172Indirect Addressing of Data Memory or Relay .. 3-127Input Relays .............................................................. 3-9Instruction List .............................................. 3-34, 3-42INT: Interrupt ........................................................ 3-192Interface [RS-232C] .............................................. 3-306Internal register .................................................... 3-135Internal Utility Relays ............................................. 3-11Internal Clocks for CTH0 and CTH1 ................... 3-278Interrupt Instructions ........................................... 3-268I/O distribution ......................................................... 1-187ITVL: Interval Timer .............................................. 3-117
JJMP: Jump ............................................................ 3-106
KKEEP: Keep ............................................................ 3-80KV-10/16/24/40/80 ............................ 1-167, 1-175, 1-177KV-300 ......................................................... 1-166, 1-170KV-AD4 ................................................................... 1-334KV-AN6 ................................................................... 1-312KV-B16R/B16S/C32T.............................................. 1-172KV-C16X/C32X ....................................................... 1-171KV-DA4 ................................................................... 1-334KV-L2 ...................................................................... 1-240KV-R1A/R16X/R16R/R16T/R8X/R8R/R8T .. 1-173, 1-174KV-U4/U5 ..................................................... 1-168, 1-169KV mode [KV-L2] .................................................... 1-253
LLD: Load .................................................................. 3-57LDA/@LDA: Load A .............................................. 3-140LDB: Load Bar ........................................................ 3-57
MMacros ...................................................................... 2-72MC: Master Control ................................................ 3-89MCR: Master Control Reset ................................... 3-89Memory Card .......................................................... 1-230MEMSW: Memory Switch ...................................... 3-92Module names......................................................... 1-175Mounting Environment .............................................. 1-64MPP: Pop .............................................................. 3-103MPS: Push ............................................................ 3-103
Inde
x
Index 3-363
MPX/@MPX: Multiplexer ...................................... 3-176MRD: Read ............................................................ 3-103MUL/@MUL: Multiply ........................................... 3-150
NNEXT: Repeat End ................................................ 3-125Non-procedure mode [KV-L2] ................................. 1-292NOP: No Operation ................................................ 3-94
OOR: Or ..................................................................... 3-60ORA/@ORA: Or A ................................................. 3-161ORB: Or Bar ............................................................ 3-60ORL: Or Load .......................................................... 3-63OUB: Out Bar .......................................................... 3-65OUT: Out ................................................................. 3-65Output Relays ......................................................... 3-10
PPeripheral equipments ............................................ 1-176Port1/Port2 [KV-L2] ................................................. 1-245Positionning control ............................................ 3-296Programming examples ...................................... 3-324
RRASC/@RASC: Reverse ASCII Convert ............. 3-183Receiving text data .............................................. 3-318Relay/Memory/Memory Switch Lists ....................... 2-167Relay/Memory Nos.................................................. 2-167Relay No. List .......................................................... 2-167Relay Nos. and Functions ....................................... 2-167RES: Reset .............................................................. 3-66RET: Subroutine Return ...................................... 3-122RETI: Return Interrupt ......................................... 3-192RLA/@RLA: Rotate Left A ................................... 3-169ROOT/@ROOT: Square Root .............................. 3-185RRA/@RRA: Rotate Right .................................... 3-169RS-232C cable connection .................................. 3-307RS-232C Protocol ................................................. 3-306RS-422A [KV-L2] ..................................................... 1-248
SSBN: Subroutine Entry ........................................ 3-122Serial Communication ......................................... 3-306SET: Set .................................................................. 3-66SFT: Shift ................................................................ 3-82SLA/@SLA: Shift Left A ....................................... 3-166Special Utility Relays............................................... 2-174SRA/@SRA: Shift Right A .................................... 3-166STA/@STA: Store A ............................................. 3-140Station No. [KV-L2] ................................................. 1-246STE: Step End ...................................................... 3-114STG: Stage ............................................................ 3-106STP: Step .............................................................. 3-114SUB/@SUB: Subtract ........................................... 3-150System configuration............................................... 1-166
Index — For KV-300, KV-10/80 User’s Only
System Configuration (Memory Card) ..................... 1-196System specifications [Visual KV Series] ................ 1-382System specifications [KV-300 Series] ................... 1-392
TTBCD/@TBCD: Transfer BCD ............................. 3-180TBIN/@TBIN: Transfer BIN .................................. 3-180Temporary Memory ...................................... 2-172, 2-176Timers and Counters............................................... 2-169TMH: 0.01-s Timer .................................................. 3-68TMIN: Trimmer In .................................................. 3-138@TMIN: Trimmer Setting ..................................... 3-138TMR: 0.1-s Timer .................................................... 3-67TMS: 1-ms Timer .................................................... 3-69Transmitting text data .......................................... 3-319Troubleshooting ...................................................... 1-372
UUDC: Up-Down Counter ......................................... 3-76
WW-DE: Wait Down Edge ......................................... 3-98W-OFF: Wait OFF ................................................... 3-96W-ON: Wait ON ....................................................... 3-96W-UE: Wait Up Edge .............................................. 3-98
X@xxxx: Differentiation ......................................... 3-137
Inde
x
Index3-364
AACCS ...................................................................... 1-234ALL CLEAR [FNC60] [P3E] ..................................... 1-217ALL DATA MEMORY CLEAR (DM ALL CLEAR): [FNC64] [P3E] ...................... 1-219ALL LATCHING RELAYS RESET (L-RELAY ALL RST): [FNC65] [P3E] ................... 1-219
BBreak signal .......................................................... 3-308
CCLEAR [P3E] .......................................................... 1-232Comments (Relay comment, Line comment) ............ 2-46Compile ..................................................................... 2-75Converting N.O./N.C. ................................................ 2-65Copy, move and delete ............................................. 2-69COUNTER CLEAR (CTR CLEAR): [FNC62] [P3E] 1-218Customizing KV-LADDER , Defining Environment Strings................................ 2-19Copy, move and delete operation ............................. 2-52
DData Communications between KV and Personal Computer .................................... 3-306Display mode ........................................................... 2-19Double coil check ...................................................... 2-76
EEdit screen ................................................................ 2-27Entering symbols....................................................... 2-37Environment requirements .......................................... 2-3Error message list ................................................... 2-156
HHANDHELD PROGRAMMER CLEAR (P3E CLEAR): [FNC61] .............................................................. 1-217Handheld Programmer KV-P3E .............................. 1-196HIGH-SPEED COUNTER CLEAR (HIGH SPEED CTR CLR): [FNC63] [P3E] .......... 1-218
IInstalling Ladder Builder.............................................. 2-9
JJump ......................................................................... 2-58
LLadder Monitor ........................................................ 2-134Ladder Simulator ....................................................... 2-84Line comment........................................................... 2-46
MMacros ...................................................................... 2-72Memory Card [P3E] ................................................. 1-230Monitor Mode .......................................................... 2-134Monitor screen ........................................................ 2-143MOVE CURSOR [P3E] ........................................... 1-202
Index — Software/P3E (handheld programmer)MULTI-MONITOR [P3E] ......................................... 1-212
OOFFLINE EDITOR START (OFFLINE EDITOR): [FNC67] [P3E] .................................................... 1-221OFFLINE EDITOR STOP (QUIT OFF-L EDIT): [FNC68] [P3E] .................................................... 1-221ON/OFF MONITOR [P3E] ....................................... 1-215
PPrinter Setting, Defining Environment Strings .......... 2-77Printing examples...................................................... 2-81PROGRAM CAPACITY CHECK (PROGRAM SIZE): [FNC75] [P3E] .................................................... 1-229PROGRAM SENT OR RECEIVED (COMMUNICATION—): [FNC66] [P3E] ............. 1-220
QQuitting software ....................................................... 2-16
RREAD TRIMMER SETTING (TRIMMER MONITOR): [FNC73] [P3E] .................................................... 1-228Registration of cursor position and jump to registered position ................................... 2-59RELAY ON/OFF (FORCED SET/RESET): [FNC71] [P3E] .................................................... 1-226Replacing relays........................................................ 2-64RS-232C cable connection ......................................... 2-7RS-232C Protocol ....................................................... 2-3
SSCAN TIME MONITOR [P3E] ................................. 1-212SCROLL [P3E] ........................................................ 1-202Search ....................................................................... 2-58Searching Program [P3E] ....................................... 1-207Selecting display mode ............................................. 2-19Setting print range ..................................................... 2-77Simulator Mode ......................................................... 2-84Simulator screen ....................................................... 2-86Starting and quitting software ................................... 2-16Starting edit mode .................................................... 2-29Starting the Monitor Function .................................. 2-139Starting the Simulator ................................................ 2-86SYNTAX CHECK (PROGRAM CHECK): [FNC74] [P3E] .................................................... 1-228
TTemporary Memory ................................................ 3-21Time Chart Monitor ................................................. 2-157Time Chart Viewer ....................................... 2-148, 2-167TIMER/COUNTER SETTING CHANGE (CHG: T/C SET-V): [FNC70] [P3E] .................... 1-224TIMER/COUNTER CURRENT VALUE CHANGE (CHG: T/C CURT-V): [FNC69] [P3E] ................. 1-222
WWRITE INTO DATA MEMORY (DM WRITE): [FNC72] [P3E] .................................................... 1-227
Index — Software/P3E (handheld programmer)
Inde
x
Index 3-365
Inde
x
Index3-366
Inde
x
Index 3-367
WARRANTIES AND DISCLAIMERS: (1) KEYENCE warrants the Products to be free of defects in materials and workmanship for a period ofone (1) year from the date of shipment. If any models or samples were shown to Buyer, such models orsamples were used merely to illustrate the general type and quality of the Products and not to representthat the Products would necessarily conform to said models or samples. Any Products found to be defec-tive must be shipped to KEYENCE with all shipping costs paid by Buyer or offered to KEYENCE for in-spection and examination. Upon examination by KEYENCE, KEYENCE, at its sole option, will refund thepurchase price of, or repair or replace at no charge any Products found to be defective. This warrantydoes not apply to any defects resulting from any action of Buyer, including but not limited to improperinstallation, improper interfacing, improper repair, unauthorized modification, misapplication and mishan-dling, such as exposure to excessive current, heat, coldness, moisture, vibration or outdoors air. Compo-nents which wear are not warranted. (2) KEYENCE is pleased to offer suggestions on the use of its various Products. They are only sugges-tions, and it is Buyer’s responsibility to ascertain the fitness of the Products for Buyer’s intended use.KEYENCE will not be responsible for any damages that may result from the use of the Products. (3) The Products and any samples (“Products/Samples”) supplied to Buyer are not to be used internallyin humans, for human transportation, as safety devices or fail-safe systems, unless their written specifica-tions state otherwise. Should any Products/Samples be used in such a manner or misused in any way,KEYENCE assumes no responsibility, and additionally Buyer will indemnify KEYENCE and holdKEYENCE harmless from any liability or damage whatsoever arising out of any misuse of the Products/Samples. (4) OTHER THAN AS STATED HEREIN, THE PRODUCTS/SAMPLES ARE PROVIDED WITH NOOTHER WARRANTIES WHATSOEVER. ALL EXPRESS, IMPLIED, AND STATUTORY WARRANTIES,INCLUDING, WITHOUT LIMITATION, THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR APARTICULAR PURPOSE, AND NON-INFRINGEMENT OF PROPRIETARY RIGHTS, ARE EXPRESSLYDISCLAIMED. IN NO EVENT SHALL KEYENCE AND ITS AFFILIATED ENTITIES BE LIABLE TO ANYPERSON OR ENTITY FOR ANY DIRECT, INDIRECT, INCIDENTAL, PUNITIVE, SPECIAL OR CONSE-QUENTIAL DAMAGES (INCLUDING, WITHOUT LIMITATION, ANY DAMAGES RESULTING FROMLOSS OF USE, BUSINESS INTERRUPTION, LOSS OF INFORMATION, LOSS OR INACCURACY OFDATA, LOSS OF PROFITS, LOSS OF SAVINGS, THE COST OF PROCUREMENT OF SUBSTITUTEDGOODS, SERVICES OR TECHNOLOGIES, OR FOR ANY MATTER ARISING OUT OF OR IN CONNEC-TION WITH THE USE OR INABILITY TO USE THE PRODUCTS, EVEN IF KEYENCE OR ONE OF ITSAFFILIATED ENTITIES WAS ADVISED OF A POSSIBLE THIRD PARTY’S CLAIM FOR DAMAGES ORANY OTHER CLAIM AGAINST BUYER. In some jurisdictions, some of the foregoing warranty disclaimersor damage limitations may not apply.
BUYER’S TRANSFER OBLIGATIONS: If the Products/Samples purchased by Buyer are to be resold ordelivered to a third party, Buyer must provide such third party with a copy of this document, all specifica-tions, manuals, catalogs, leaflets and written information provided to Buyer pertaining to the Products/Samples.
1 2 3
Visual KV Series 3 P
rogra
mm
ing
User's ManualVisual KV Series
3Programming
© KEYENCE CORPORATION, 1999 NKVP-UM-4-1000 Printed in Japan
96M0366
How this manual is organized:
The Visual KV Series User’s Manual is composed of 3 separatemanuals; 1-Installation, 2-Support Software, 3-Programming.Please read each manual relevant to your purpose.
Installation
1. Configuration andSpecifications
2. System Installation
3. Access Window
4. KV-D20 OperatorInterface Panel
5. KV-10/80 Hardware
6. Handheld Program-mer
7. KV-L2 Serial InterfaceModule
8. KV-AN6 Analog I/OModule
9. KV-AD4/DA4 AnalogI/O Unit
10. Troubleshooting
11. Appendices
SupportSoftware
1. Introduction
2. Editor
3. Simulator
4. Monitor
5. Appendices
Programming
1. Programming
2. Instructions
3. Interrupts
4. High-speed Counters
5. Positioning Control
6. Interrupts, High-speedCounters, PositioningControl
7. Serial Communication
8. ProgrammingExamples
INDEX
Specifications are subject to change without notice.
KEYENCE CORPORATION1-3-14, Higashi-Nakajima,Higashi-Yodogawa-ku,Osaka, 533-8555, JapanPHONE: 81-6-6379-2211FAX: 81-6-6379-2131
AFFILIATED COMPANIES
KEYENCE CORPORATION OF AMERICAPHONE: 201-930-0100 FAX: 201-930-0099
KEYENCE (UK) LIMITEDPHONE: 01908-696900 FAX: 01908-696777
KEYENCE DEUTSCHLAND GmbHPHONE: 0711-79 73 71-0 FAX: 0711-797 77 99
KEYENCE FRANCE S.A.PHONE: 01 47 92 76 76 FAX: 01 47 92 76 77
KEYENCE SINGAPORE PTE LTD.PHONE: 392-1011 FAX: 392-5055
KEYENCE (MALAYSIA) SDN BHDPHONE: 03-252-2211 FAX: 03-252-2131
KEYENCE (THAILAND) CO., LTD.PHONE: 02-369-2777 FAX: 02-369-2775
KEYENCE THAIWAN CO., LTD.PHONE: 02-2627-3100 FAX: 02-2798-8925
KEYENCE KOREA CORPORATIONPHONE: 02-563-1270 FAX: 02-563-1271