plc programming course1

55
Super-small Programmable Logic Controller with Built-in Display Visual KV Series Advanced Programming Course

Upload: danielrcaldwell

Post on 15-May-2015

720 views

Category:

Documents


20 download

TRANSCRIPT

Page 1: Plc programming course1

Super-small Programmable Logic Controllerwith Built-in Display

Visual KV SeriesAdvancedProgramming Course

Page 2: Plc programming course1

ContentsVOL.1 Counting total number of products ...................................................................... 4

Example: Totaling the number of products on multiple production lines

VOL.2 Shift register ........................................................................................................... 6

Example: Ejecting rejects

VOL.3 BCD data output (to BCD display) ........................................................................ 8

Example: Indicating the number of products

VOL.4 Setting of multi-level output with high-speed counter ..................................... 10

Example: Cutting a sheet of cloth to specified length

VOL.5 BCD data input (4 digits) ..................................................................................... 12

Example: Inputting BCD data with a digital switch

VOL.6 BCD data input (2 digits) ..................................................................................... 14

Example: Inputting BCD data from the digital switch

VOL.7 Measurement of high-speed pulse period ......................................................... 16

Example: Checking rotation pulse period of engine

VOL.8 Phase differential input ........................................................................................ 18

Example: Input from rotary encoder

VOL.9 Position control using a stepping motor ........................................................... 20

Example: Stop/counterclockwise rotation of a stepping motor at a specified number of pulses

VOL.10 The specified frequency pulse output function ................................................. 22

Example: Speed control of a pulse motor with the specified frequency pulse output function

VOL.11 Word shifting ......................................................................................................... 24

Example: Storing the stop duration of equipment in memory as history

VOL.12 Fine adjustment with a digital trimmer ............................................................... 26

Example: Fine adjustment of the air discharge time of a parts feeder

VOL.13 Receiving multiple pulses and outputting them as a batch ............................. 28

Example: Displaying total number of products travelling on multiple lines on a counter

VOL.14 Converting high speed pulses into low speed pulses ...................................... 30

Example: Converting pulse frequency

VOL.15 Bit counting (Bit checking) .................................................................................. 32

Example: Checking how many error detection signals are input to input relays of channel

2

Page 3: Plc programming course1

3

VOL.16 Shift register simulation in an asynchronous production line ......................... 34

Example: Ejecting rejects without a constant synchronous signal

VOL.17 Emergency stop circuit ........................................................................................ 36

Example: Emergency stop for cutting work

VOL.18 Selection of operation mode ............................................................................... 38

Example: Selecting fully-automatic or individual operation mode

VOL.19 Step-progress operation (sequential control) ................................................... 40

Example: Step progress of material handling machine

VOL.20 Frequency counter function ................................................................................ 42

Example: Counting the number of rotations using the frequency counter

VOL.21 Sorting ................................................................................................................... 44

Example: Sorting machines in the ascending order of production

VOL.22 High-speed interrupt input function ................................................................... 46

Example: Measurement of passing time between two points using high-speed interrupt input

VOL.23 Synchronous control function ............................................................................ 48

Example: Synchronous control of a pulse motor

VOL.24 High-speed counter .............................................................................................. 50

Example: Multi-step comparator operation with high-speed counter

Page 4: Plc programming course1

VOL.Example

4

Counting total number of products1Totaling the number of products on multiple production lines

Line 1

Line 2

Line 3

Line 4

Line 5

The number of products travelling on each of 5 lines iscounted simultaneously. When the total number of productson the 5 lines reaches 100 the KV outputs.An FS Series fiberoptic sensor counts the number ofproducts on each line. When the total number equals thepreset value, the KV outputs.

Input 0000: Counting products on line 1Input 0001: Counting products on line 2Input relay 0002: Counting products on line 3Input relay 0003: Counting products on line 4Input relay 0004: Counting products on line 5Input relay 0005: Resetting

0000

0001

0002

0003

0004

0 1 2 3 4 5 6 7, 8Products counted

■ Programming TechniqueThe following 2 instructions can be used for counting.

(1) Counter instruction(2) Increment Memory instruction

The programs created using instruction (1) and (2) are as follows:

Using instruction (1) Using instruction (2)

For the same control as shown here, using instruction (2) simplifies programming.

Time and labor for debugging is saved.

To obtain comparator output, the CMP instruction can be used.

C001LDA

DM0001STA

C002LDA

DM0002STA

C003LDA

DM0003STA

C004LDA

DM0004STA

C005LDA

#09999C005

#09999C004

#09999C003

#09999C002

#09999C001

DM0005STA

DM0005ADD

DM0000STA

DM0003ADD

DM0004ADD

DM0001LDA

DM0002ADD

0005

2002

DM0000INC

DM0000INC

DM0000INC

DM0000INC

DM0000INC

0004

0003

0002

0001

0000

0000

0001

0002

0003

0004

0005 $0000DW

DM0000

Visual KV Series

Outline

FS Series Fiberoptic Sensor

Output relay 0500: Comparator output

Page 5: Plc programming course1

5

VOL. 1 Counting total number of products

Programming Example

0000

0001

0002

0003

0004

0005

2002

0001

0002

0003

0004

0005

0006

0007

0008

0009

END

ENDH

DM0000INC

DM0000INC

DM0000INC

DM0000INC

DM0000INC

$0000DW

DM00002009#00100

CMPDM0000

LDA0500

When Input 0000 (line 1) turns ON, DM0000 isincremented by 1.

When Input 0001 (line 2) turns ON, DM0000 isincremented by 1.

When input relay 0002 (line 3) turns ON, DM0000 isincremented by 1.

When input relay 0003 (line 4) turns ON, DM0000 isincremented by 1.

When input relay 0004 (line 5) turns ON, DM0000 isincremented by 1.

When input relay 0005 (reset input) turns ON, DM0000 isreset to 0.

When DM0000 equals 100 or more, output relay 500 turnsON.When the reset input (0005) turns ON, output 0500 turnsOFF.

0000

0001

0002

0003

0004

0000

0001

0002

0003

0004

DM0000INC

DM0000INC

DM0000INC

DM0000INC

DM0000INC

DM0000INC

(2)(1)

Tips ORing Differentiation instructions• Compare the following 2 programs.

In program (1), counting is performed for each input even when input relays 0000 to 0004turn ON simultaneously.In program (2), simultaneous inputs are ignored when input relays 0000 to 0004 turn ONsimultaneously.

Referring to the above, program according to your purpose.

Set the input time constant to 10 µs using HSP instruction when the line speed is very high.

Page 6: Plc programming course1

VOL.Example

6

2 Shift registerEjecting rejects

Detecting rejectsSensor Input 0001

Position 1 Position 2 Position 3 Position 4 Position 5

Compressed air ejection0500

Clock inputSensor Input 0002

CamDetection position Ejection position

■ Programming TechniqueThe SHIFT instruction allows the sensor reject input to turn ON each specified internal utility relay sequentially.Each utility relay turns ON synchronously when the reject reaches a specific stage on the conveyor. This reject willbe ejected from the conveyor when the eject output and final utility relay turn ON.

Each time the clock input sensor is activated, a workpiece travels from position 1 to 5 sequentially. Acceptance orrejection values for the workpieces in position 1 to 5 are stored in internal relays 1000 to 1004, with a reject beingejected, using compressed air, in position 5.

0002

0000

0500

1000

1001

1002

1003

1004

Position 5Position 4Position 3Position 2Position 1

(Clock input)

1 sec

Position of reject

(Ejection output)

(Detection of rejects)

Outline

At position 1, the fiberoptic sensor checks whether the workpiece is acceptable or not. If the workpiece is rejected,it is ejected at position 5.When the detection position is different from the ejection position as shown in the figure, using the Shift instructionis convenient.

Page 7: Plc programming course1

7

VOL. 2 Shift register

Programming Example0001 1100

2003

0002

2003

1004 0002

0500

1000SET

1100DIFU

SFT

D 1000

CLK

1004RES

#00010T000

T0000006

0005

0004

0003

0002

0001

0500

Internal Input relay 1000 is turned ON by a signal fromthe fiberoptic sensor when it detects a reject.

Each time clock input relay 0002 turns ON, acceptanceor rejection of workpieces in position 1 to 5 is stored ininternal relays 1000 to 1004.

SFTD 1000

CLK

1004RES

0001

0002

20031000

1001

1002

0002

0001(1)

(Detection of rejects)

(Clock input)

SFTD 1000

CLK

1004RES

0001 1100

2003

0002

2003

1000

1001

1002

0002

00011000SET

1100DIFU

(2)

Then, program as follows:

A one-shot ejection signal is sent.

Tips Using shift registerThere are 2 ways to input data into the shift register:

In circuit 1 shown above, reject detection signals cannot be transferred to the internal registerif the reject detection output relay is not turned ON while the clock input pulse is ON (if theyare not synchronized).

In circuit 2 shown above, the reject detection signal is guaranteed to be sent to the internalregister.

➮ For details, refer to the KV User’s Manual.

Page 8: Plc programming course1

VOL.Example

8

BCD data output (to BCD display)Indicating the number of products

The number of products is counted by the internal counter of the KV, and the number is indicated on the BCDdisplay.

Without using an externally-mounted counter, the internal counter of the KV can indicate the count result on theexternal BCD display. This enables centralized control of the system by the KV.

■ Programming Technique1. TBCD instruction: In the KV, data is in binary format to convert binary data into BCD data.

2. STA instruction: Use this instruction to transfer BCD data obtained by the TBCD instruction to external equip-ment.

4-digit BCD display connection diagram and programming example are shown below.

Type I: 4-digit individual input

Connect the output of the KV to each input of the 4 digits of the BCD display.

Programming Example (Using the KV-40)

Though 16 outputs from the KV are required, program length can be decreased.

BCD displayVisual KV Series

Count inputPZ2 Series

1 2 4 8 1 2 4 8 1 2 4 8 1 2 4 8

4th-digit BCD data(512 to 515)

1st digit

1st-digit BCD data(500 to 503)

2nd-digit BCD data(504 to 507)

2nd digit

3rd-digit BCD data(508 to 511)

3rd digit4th digit

2002

C0000001

0002

00000500STA

C000LDA TBCD

#00100C000 Counter (count input: 0000, preset value: 100)

The value of the internal counter is converted into BCD data and isoutput to the display.

3

Outline

Page 9: Plc programming course1

9

Type II: Digit designation input

Data of 1st to 4th digits is indicated sequentially in a high speed cycle.

Programming Example (The ladder program may vary depending on the KV model to be used.)

Though longer programming is required, only 8 outputs from the KV are required.

The KV-D20 Operator Interface Panel is convenient for displaying several values.

VOL. 3 BCD data output (to BCD display)

1 2 4 8

BCD data of each digit(0500 to 0503)

4th digit 3rd digit 2nd digit 1st digit

1st digit2nd digit3rd digit4th digit

Each-digit designation(0504 to 0507)

0001

0002

2008

C000

T001

2003

T001

2003

1008

1000

1002

1004

1006

1001

1003

1005

1007

0003

0004

0005

0006

0007

0008

0009

0010

0011

0012

0013

0014

0015

0500STA

DM0000STATBCD

C000LDA

DM0000LDA

DM0000LDA

DM0000LDA

#04SRA

#08SRA

#12SRA

0500STA

0500STA

0500STA

0504

0505

0506

0507

$000FANDA

$000FANDA

$000FANDA

$000FANDA

SFTD 1000

CLK

1008RES

1000SET

1000SET

#00100C0000000

#00050 001ST

7 6 5 4 3 2 1 0

The start relay of the Shift instruction is turned ON when operationbegins.

Counter (count input: 0000, preset value: 100)

50-ms clock pulses are output. (Display updating)

Internal relays 1000 to 1008 are turned ON sequentially.(BCD display updating)

Internal relays 1000 to 1008 are sequential and repeatedly turnedON/OFF.

Units digit data in the internal register is output through 0500.

Tens digit in the internal register is output through 0500.

Hundreds digit data in the internal register is output through 0500.

Thousands digit data in the internal register is output through 0500.

Digit designation of 1st digit (units digit) is output through 0504.

Digit designation of 2nd digit (tens digit) is output through 0505.

Digit designation of 3rd digit (hundreds digit) is output through 0506.

Digit designation of 4th digit (thousands digit) is output through 0507.

Page 10: Plc programming course1

VOL.Example

10

Setting of multi-level output withhigh-speed counterCutting a sheet of cloth to specified length

4

Winding process

■ Programming TechniqueFor this control, 3 values (the number of pulses) must be preset respectively to decrease winding speed, stopwinding, and alarm overrunning. Preset the number of pulses of the high-speed counter to 3 levels using the CMPinstruction.

➮ For details on the instructions, refer to the KV Users Manual.

Cutter

Rotary encoder

Decrease inwinding speed

Input the preset value for each point.

AlarmOverrunning

Cutting

Stop ofwinding

Start of winding

20092002

2009

DM0000CMP

CTH0LDA

DM0001CMP

0500

0501

0502DM0002CMP

2009Alarm for overrunning

Signal for decreasing winding speed

Signal for stopping winding

Outline

By using pulses fed from the encoder, the KV controls winding speed of a sheet of cloth to cut the cloth to thespecified length.High speed pulses from the encoder are entered to the high-speed counter of the KV. Output signals are issuedrespectively to decrease winding speed, to stop winding and for overrunning alarm, the preset values (the numberof pulses) are previously input into the data memory of the KV.

Page 11: Plc programming course1

11

VOL. 4 Setting of multi-level output with high-speed counter

0001

0002

0003

0004

0005

0006

0007

0008

2008

2002

0001

2002

HSP

HSP

CTH0

2009

2009

2009

0500

0501

0502

#02000DW

DM0002

#01500DW

DM0001

#01000DW

DM0000

2113SET

0004

0006

0004

2114RES

DM0000CMP

CTH0LDA

DM0001CMP

DM0002CMP

2002

2002

2002

2009

2009

2009 0502

0501

0500

CTH0LDA

DM0000CMP

DM0000CMP

DM0002CMP

2002 CTH0LDA

DM0000CMP

05002009

DM0001CMP

05012009

DM0002CMP

05022009

There are a large number of lines,making it difficult to understand the flow.

There are few lines, making it easier tounderstand the flow.

Programming Example

20092009

When the power is turned ON, preset the initial values for decelera-tion point, stop point, and overrunning point respectively to 1000,1500, and 2000.

When the number of pulses from the encoder exceeds the presetvalue for overrunning point in DM0002, output is sent through outputrelay 0502.

When the number of pulses from the encoder exceeds the preset valuefor stop point in DM0001, output is sent through output relay 0501.

When the number of pulses from the encoder exceeds the presetvalue for the deceleration point in DM0000, output is sent throughoutput relay 0500.

The pulses from the encoder are received with high-speed counterCTH0 through inputs 0004 and 0006.

The input time constants of inputs 0004 and 0006 are changed to10 µs.

CTH0 is set to the double multiplication mode.

CMP instruction1. To obtain comparator output using the CMP instruction, create an expanded ladder

diagram program. This makes it easier to understand sequential processing flow.

Conventional ladder diagram Expanded ladder diagram

2. When or is used as compar ison condition:

When the value in the internal register is smaller than the operand value, internal relay2009 turns ON. By applying this, program as , the desired condition(value in the internal register oper and value) can be set.

* The same process can be used for comparison condition .

Tips

Fromencoder

Page 12: Plc programming course1

VOL.Example

12

BCD data input (4 digits)5Inputting BCD data with a digital switch

The preset value for the KVs counter is input using an external digital switch.

■ Programming Technique

To input 4-digit BCD data, it is convenient to use the HKEY instruction.

Advantage: To input 4-digit BCD data, 16 input terminals are normally required. With the HKEY instruction,however, only 4 inputs and 4 outputs are required.

4-digit BCD data is stored in special utility relays 2900 to 2915.

Example of utility relay status: When the BCD data is 1234:

1

+

2

+

3

+

4

+

4-digit BCD digital switch Visual KV Series

COM 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012 0013 0014 0015

100 101 102 103

DC24V

+–

DC24V

+–

COM 0000 0001 0002 0003

COM 0500 0501 0502 0503

100 101 102 103

Digitalswitch

Digitalswitch

24 V DC

24 V DC

2 9 1 5 2 9 1 4 2 9 1 3 2 9 1 2 2 9 1 1 2 9 1 0 2 9 0 9 2 9 0 8 2 9 0 7 2 9 0 6 2 9 0 5 2 9 0 4 2 9 0 3 2 9 0 2 2 9 0 1 2 9 0 0

0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0

“1”

103

“2”

102

“3”

101

“4”

100

Outline

Diode

Page 13: Plc programming course1

13

Programming ExampleTo set the preset value of counter C000 using a 4-digit digital switch:

0001

0002

0003

HKEY

C000

0005

2815 2900LDA

C000STATBIN

00000500

#09999

0004C000 Input to counter C000 is received through input

0004.

When input 0005 is turned ON, the preset value ofthe digital switch is determined.

4-digit BCD data from the digital switch is readfrom special utility relays 2900 to 2915, andconverted into a binary number, which is used asthe preset value of counter C000.

VOL. 5 BCD data input (4 digits)

If the HKEY instruction is not used, the above programming example is written in ladderdiagram notation as follows. You soon discover how simple programming can be using HKEY.

The time constant is set to 10 µs using the HSPinstruction, and data is received through inputs0000 to 0003.

2002

2003

T001

0005 1000

T001

2003

1001

1003

1005

1007

0500

0501

0502

0503

1009

C000

0503

0502

0501

0500

SFTD 1001

CLK

1009RES

1001SET

#00020 001ST

HSP0000

HSP0001

HSP0002

HSP0003

1000DIFU

$000FANDA

$000FANDA

$000FANDA

$000FANDA

DM0004ORA

0000LDA

0000LDA

0000LDA

0000LDA

DM0003ORA

DM0002ORA

DM0001LDA

#04SLA

DM0001STA

DM0002STA

#08SLA

DM0003STA

#12SLA

DM0004STA

TBINC000STA

#09999C0000004

Obtaining the preset value from the digital switchWhen 0500 is ON: Receiving 100 data to store inDM0000When 0501 is ON: Receiving 101 data to store inDM0001When 0502 is ON: Receiving 102 data to store inDM0002When 0503 is ON: Receiving 103 data to store inDM0003

Combine each digit and convert the result intobinary data. This data is used as the preset valueof the counter.

Output relays 0500 to 0503 are turned ONsequentially and the equivalent data for each digitis sent to the special utility relays.

Tips

Using the HKEY instruction shortens programming to only 3 lines.

Page 14: Plc programming course1

VOL.Example

14

BCD data input (2 digits)6 Inputting BCD data from the digital switch

The product type No. is input to the KV using the external digital switch. At this time, the ANDA instruction ignoresinput data from the operation switch or sensor.

■ Programming Technique

To input 2-digit BCD data, it is convenient to use the LDA instruction.

When 2-digit BCD data is entered to inputs 0000 to 0007 of the KV-40 Series:

When the LDA instruction is used, the ON/OFF status of inputs 0000 to 0015 are received normally. When sensorsor operation switches are connected to inputs 0008 to 0015, therefore, their ON/OFF status is entered as BCDdata.Use the ANDA instruction to ignore the ON/OFF status of inputs 0008 to 0015.

As shown above, only 2-digit BCD data can be received, regardless of whether these sensors or operation switchesturn ON/OF.

3

+

4

+

2-digit BCD digital switch Visual KV Series

COM 0000 0001 0002 0003 0004 0005 0006 0007 0008 0009 0010 0011 0012

100 101

DC24V

+

Operation switch, sensor, etc.Digitalswitch

24 V DC

0015 0014 0013 0012 0011 0010 0009 0008 0007 0006 0005 0004 0003 0002 0001 0000

0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0

0015 0014 0013 0012 0011 0010 0009 0008 0007 0006 0005 0004 0003 0002 0001 0000

0 0 0 0 0 0 0 0 1 1 1 1 1 1 1 1

0015 0014 0013 0012 0011 0010 0009 0008 0007 0006 0005 0004 0003 0002 0001 0000

0 1 1 0 0 1 0 1 0 0 1 1 0 1 0 0

$OOFFANDA

Input

BCD data “4”BCD data “3”BCD data “0”BCD data “0”

BCD data “4”BCD data “3”ON/OFF status of sensor or operation switch

Outline

Page 15: Plc programming course1

15

Programming Example2002 0000 $00FF

LDADM0000

STAANDA0001The ON/OFF status of inputs 0000 to 0015 is received,but only the data from inputs 0000 to 0007 is selectedand entered into data memory DM0000.

2002 $0FFF

2002 0000 $000FLDA

DM0000STAANDA

0000LDA

DM0000STAANDA

Input0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8

– – – – 0 0 1 1

0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1

0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1

Internal register#04SLA

$000FANDA

0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0

(*1)

(*2) 0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0

0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 0

0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0010 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0

DM0002ORA

Tens digit of BCD data

VOL. 6 BCD data input (2 digits)

1. ANDA instructionIn the above programming example, $00FF is specified as the operand for the ANDAinstruction to ignore the ON/OFF status of inputs 0008 to 0015.Referring to the above programming, specify the operand as follows to receive 1-digit dataor 3-digit data.

2. 2-digit BCD dataExample: When inputs 0004 to 0007 cannot be used because the high-speed counter of

the KV-40 is used, receive 2-digit BCD data through inputs 0000 to 0003 and0008 to 0011. At this time, use the SLA instruction and ORA instruction conven-iently.

In (*1) and (*2) shown above, contents in the internal register are changed as follows:

Tips

To receive 1-digit BCD data:

To receive 3-digit BCD data:

2002 #04SLA

DM0001STA

0008LDA

$000FANDA

DM0002TBINORA

0000 $000F DM0002STAANDA

DM0000STA

LDA

DM0001LDA

(*2)

(*1)

COM 0000 0001 0002 0003 0004 0005 0008 0009 0010 0011

100 101

24 V DC+

3

+

4

+Digital switch

Set value = 34

Used for high-speed counter.

Tens and units digits are stored in DM0000.

Units digit of BCD data is stored in DM0002.

Tens digit of BCD data is stored in DM0001.

Page 16: Plc programming course1

VOL.Example

16

Measurement of high-speed pulseperiod7Checking rotation pulse period of engine

The sensor detects the mark on the jig for the engine and emits a pulse each rotation. Using these pulses, thepulse period during engine rotation at high speed is measured.

■ Programming Technique

Step 1: The rotation pulse period is obtained by counting the number of internal clockpulses emitted by the KV.

To obtain the rotation pulse period, internal clock pulses (example: 100µs period) emitted during each rotation pulseperiod are counted using the high-speed counter.

Step 2: Use the INT instruction for programming the first step operation.Rotation pulses are received by the KV through input 0003, and the pulse period is measured using the Interruptinstruction.

When an interrupt is executed, the current value of the high-speed counter is automatically transferred to the datamemory (DM1934) at the rising edge of the pulse received at input 0003.

When this function is used, the clock pulse count equals the difference between the value of the high-speed coun-ter obtained at the rising edge of the first rotation pulse and that of the second rotation pulse.

FS Series

Visual KV Series

Rotation pulse period = internal clock pulse period: 100 µs x clock pulse count

Internal clock pulse count

Rotation pulse

Internal clockpulse (100 µs)

INT

0003

Clock pulse count = DM1934 (2) - DM1934 (1)

DM1934(1) DM1934(2)

Pulse period

Rotation pulse

Internal clockpulse (100 µs)

Outline

Pulse period

Page 17: Plc programming course1

17

VOL. 7 Measurement of high-speed pulse period

Programming Example

Note: Since the countable range of CTH1 is 00000 to 65535 in the above program example, measurablerotation pulse period is between approx. 100 µs and approx. 6553 ms.

An interrupt is declared, and initialization isperformed. The interrupt polarity of input0003 is set to the rising edge.

2008

2002

2002

2002

2002

2002

2412RES

1000RES

2413RES

1000SET

1000

0006

0007

0008

0009

0010

0011

0005

0004

0003

0002

0001DM0002

STADM0000

STA2200STA

#00000LDAEI

DM0001STA

DM0000STA

DM1934LDA

#10000DIV

DM0002STA

DM0001LDA

#00100MUL

DM0001STA

DM0000SUB

DM1934LDA

CTH12202

HSP0003

END

INT0003

RETI

ENDH

The difference between the current valueof CTH1 obtained at the rising edge of thefirst rotation pulse and that obtained at therising edge of the second rotation pulse isentered into DM0001.

The rotation pulses are received using theINT instruction.

The rotation pulse period measured isentered into DM0002 in milliseconds.

Internal clock pulses (100 µs) of the KV areinput into high-speed counter CTH1, andcounted.

Input time constant for input 0003 is set to10 µs.

Higher accuracy for this measurement can be obtained by using special utility relay 2200 or2201 which enables the use of the 1 µs or 10 µs internal clock pulse of the KV. The countableranges are as follows.

• 1 µs: Approx. 1 µs to approx. 65 ms• 10 µs: Approx. 10 µs to approx. 655 ms

When the clock pulses exceeds 65535 (maximum countable value by CTH1), use CTH0.Then, up to 56 minutes (approx.) can be measured accurately.

Example:1. Count internal clock pulses (100 µs) at the rising edge of the rotation pulse using CTH0,

and set the preset value to 50.

2. When the CHT0 count exceeds 50 (preset value), a direct clock pulse (period: 10 ms) isoutput through output relay 500.

3. The rotation pulse period can be obtained by counting the number of direct clock pulsesemitted between the rising edge of the first rotation pulse and that of the second.

100 µs

10 ms

50 50 50

Direct clockpulse

Internal clockpulse (100 µs)

Rotation pulse Pulse period

Tips

Page 18: Plc programming course1

VOL.Example

18

■ Programming TechniqueWhen using the phase differential input, set the high-speed counter to the double or quadruple multiplication mode.

CTH0 Phase A: Input 0004 Phase B: Input 0006CTH1 Phase A: Input 0005 Phase B: Input 0007

Special utility relay setting for phase differential input

8

Visual KV Series

Phase A

Phase B

0HTC 1HTC

3112 4112 3122 4122

edomelbuoD NO FFO NO FFO

edomelpurdauQ FFO NO FFO NO

1 2 3 4ONOFFONOFF

0 1 2 3 4 5 6 7 8 7 6 5 4 3 2 1 0

Counter value

Phase B

Phase A

Counter value

Phase B

Phase A

Phase differential inputExample: Input from rotary encoder

Outline

Rotary encoder

ONOFFONOFF

1 2 3

3

4

4

0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 15 14 13 12 11 10 9 8 7 6 5 4 3 2 1 0

1 2

Phase differential input in double multiplication mode(2113: ON, 2114: OFF)

Phase differential input in quadruple multiplication mode(2113: OFF, 2114: ON)

Page 19: Plc programming course1

19

Programming Example (In double multiplication mode)Pulses up to 30-kHz frequency can be input.

VOL. 8 Phase differential input

2008

2002

0000

2002

2113SET

2114RES

CTH0RES

0003

0004

0005

0002

0001

HSP0004

CTH00004

HSP0006

High-speed counter CTH0 is set to the doublemode.

Turning ON input 0000 resets high-speedcounter CTH0.

The pulses from the encoder are counted withhigh-speed counter CTH0.

The input time constants of inputs 0004 and0006 are set to 10 µs.

MEMSW$0800

MEMSW$1000

To use 24-bit high-speed counterThe 24-bit high-speed counter can be used to count the pulses from the encoder bysetting the special utility relays. It allows reliable counting of the pulses that cannot becounted with the 16-bit high-speed counter.

Setting methodSpecify the 24-bit high-speed counter with the MEMSW instruction.

To set high-speed counter CTH0 To set high-speed counter CTH1

The counter value is read at every scan and is stored in the following data memories.DM1900: Low-order bits of current CTH0 valueDM1901: High-order bits of current CTH0 valueDM1902: Low-order bits of current CTH1 valueDM1903: High-order bits of current CTH1 value

By using the KV-D20 operator interface panel, you can display the current value of the 24-bit high-speed counter in real time.

Tips

Page 20: Plc programming course1

VOL.Example

20

Stop/counterclockwise rotation of a stepping motor at a specified number of pulses

■ Programming TechniqueFor positioning control, set each parameter in the specified data memory in advance.Turning on the special utility relay starts the operation. The KV Series starts ramp up/down control automatically.Pulses are output from output 0502.The output frequency can be specified within the range of 200 Hz to 50 kHz.

Parameter setting

Control relays

➮ Refer to “12.3 Positioning Control” on page 690 in the Visual KV Series User’s Manual for details.

Operating procedure

Input 0000: ON

Clockwise rotationfor 1000 pulses

Input 0001: ON

Clockwise rotationfor 2000 pulses

Input 0002: ON

Counterclockwiserotation for 3000pulses (Return to thestarting position)

➞➞

➞➞

➞ Visual KV Series

Stepping motor and motor driver

➮ For wiring, refer to “11.3 Examples of Using the Positioning ControlFunction” on page 652 in the Visual KV Series User’s Manual.

DM1481

DM1480

9 Position control using a stepping motor

Outline

Frequency (Hz)

Operating frequency

Startup frequency

Number of outputpulses (pulses)

DM1485 and DM 1484Upper digit Lower digit

Accelerationtime DM1482

Decelerationtime DM1482

yromemataD stnetnocgnitteS egnargnitteS0841MD )zH(ycneuqerfputratslortnocnwod/pu-pmaR 000,05ot0021841MD )zH(ycneuqerfgnitarepolortnocnwod/pu-pmaR )ycneuqerfputratsnahtregraleulav(000,05ot0022841MD )sm(emitnoitareleced/noitareleccalortnocnwod/pu-pmaR 0004ot04841MD )stib61rewol(sesluptuptuoforebmuN )0si5841MDnehweromro2(535,56ot05841MD )stib61reppu(sesluptuptuoforebmuN 53556ot0

.oNyalerytilitulaicepS noitpircseD8032 .noitarepospotsneht,egdegnisirtanoitarelecedsmrofreP9032 .margorptpurretninanitesergniebnehwyletaidemminoitarepospotS.tuptuoeraseslupelihwNOsniameR0132 .egdegnisirtanoitarepopustratS

Page 21: Plc programming course1

21

VOL. 9 Position control using a stepping motor

Programming Example

The interrupt for emergency-stop opera-tion is enabled.

ENDH

RETI

INT

END

HSP0003

0001

0002

2008

2002

0000

0001

1002

0004

2002

0003

0004

0005

0006

0007

0008

0009

0010

0011

0012

0013

0014

0002

1000

1001

EI

2309RES

#00000DW

DM1485

#01000DW

DM1484

#00200DW

DM1482

#05000DW

DM1481

#00500DW

DM1480

0503RES

#00000DW

DM1485

#02000DW

DM1484

#00200DW

DM1482

#05000DW

DM1481

#00500DW

DM1480

0503RES

#00000DW

DM1485

#03000DW

DM1484

#00200DW

DM1482

#05000DW

DM1481

#00500DW

DM1480

0503SET

2413RES

2412RES

2310

1002

1001

1000

2308

0003

The input time constant for input 0003(emergency stop) is set to10 µs.

The parameters for clockwise rotation for1000 pulses are set.

The parameters for clockwise rotation for2000 pulses are set.

The parameters for counterclockwiserotation for 3000 pulses are set.

When each parameter is set, pulse outputis started.

The operation is slowed down andstopped.

The interrupt program for emergency stopis executed.

0004 2308

RETI

2002 2309RES

INT0003

Slow-down stop and emergency stopTurn ON relay 2308 for the slow-down stop operation.

Reset relay 2309 in the interrupt program for the emergency-stop operation.

Tips

Page 22: Plc programming course1

VOL.Example

22

Speed control of a pulse motor with the specified frequency pulse output function

10

Use the specified frequency pulse output function to control the speed of a pulse motor.Turning on input 0000 starts the operation. The operation is slowed down and stopped when input 0001 turns on.The operation frequency is set in DM0000.

Applications: Tension adjustment of hoop material, Timeadjustment for sheet material remaining inthe processing bath

■ Programming TechniqueThe Visual KV Series features the specified frequency pulse output function as standard. This function is convenientespecially for the applications above. When the specified frequency pulse output function is set, the pulses of thefrequency (Hz) specified in DM1936 is produced from output 0501. Turning ON special utility relay 2306 starts thepulse output. Turning OFF special utility relay 2306 stops the pulse output.

Device used for specified frequency pulse output

Special utility relays

Data memory

Pulse duty ratio: fixed to 50%

The frequency is increased/decreased by 100 Hz and updated every 20 ms in the program.The current speed is compared with the preset speed. If the current speed is less than preset speed, the currentspeed is increased. If the current speed is more than the preset speed, the current speed is decreased.

OHZ OHZ

30kHZ

50kHZ

5kHZ

20kHZ

Visual KV Series Pulse motor and motor driver

The specified frequency pulse outputfunction

Outline

.oNyaleR noitpircseD

6032noitcnuFoN:FFO,seY:NO.tuptuoeslupycneuqerfdeificepsesU

.NOsnrut7032yalerrorrenehwFFOdecrofsi

7032.noitcnuftuptuoeslupycneuqerfdeificepsrofgalfrorrE

).FFOdenrutsituptuoeslupeht,NOdenrutnehW(

.oNMD noitpircseD6391MD )]zH:stinU[00005ot61(.nettirwsituptuoeslupycneuqerfdeificepsrofeulavteserP

ON

OFF

The ratio between ON and OFF time is 1:1.

Page 23: Plc programming course1

23

VOL. 10 The specified frequency pulse output function

Programming ExampleThe operation starts when input 0000 turns ON. The operation is slowed down and stopped when input 0001turns ON. The output frequency is changed every time when input 0002 turns ON.When the output frequency (Hz) is specified in DM0000, the operation is controlled at the start-up speed of 16Hz and the acceleration of 100 Hz/20 ms.

The preset speed is set to “16” at the rising edge of input0000. The specified frequency pulse output start relay isturned ON.0001

1204

1101

0002

2003

1002

2008

1206

1200

1201

1202

1203

1100

T000 2009

2011

2307

2002

2002

ENDH

RET

SBN01

RET

SBN00

END

0000 1200SET

1101SET

1100SET

1101RES

1100RES

2306RES

2010

2306SET

1206

0500

SFTD 1200

CLK

1204RES

1002DIFU

00CALL

01CALL

1001DIFU

#00016DW

DM1936

#30000DW

DM0000#50000

DWDM0000#05000

DWDM0000#20000

DWDM0000

DM1936STA

TM02ADD

DM1936LDA

TM02STA

DM0000LDA

DM1936SUB

DM1936LDA

DM0000CMP

#00100CMP

DM1936STA

TM02SUB

DM1936LDA

DM1936STA

#00100ADD

DM1936LDA

DM1936STA

#00100SUB

DM1936LDA

TM02STA

2306 10001000DIFU

1001

1003DIFU

1003

1004DIFU

1004

1005DIFU

1005

1006DIFU

#00100CMP

1006

#00020 000ST

2011

2011

T000

2011

2011

LDA#00016 DM0000

STADM1936

CMP

DM1936LDA

DM0000SUB

The operation is slowed down and stopped at the risingedge of input 0001 or at the end of the operation pattern.When the slowdown-stop relay is turned ON, the presetspeed is set to 16 Hz. When the output frequency reaches16 Hz, the operation is stopped.

The output frequency is changed in the specified order atthe rising edge of the output frequency change input.

The 1st frequency is set. (30 kHz)

The 2nd frequency is set. (50 kHz)

The 3rd frequency is set. (5 kHz)

The 4th frequency is set. (20 kHz)

The 20-ms flicker circuit is activated during the pulseoutput.The current speed is compared with the preset speed every20 ms. The current speed is accelerated (SBN00) when thepreset speed is faster. The current speed is decelerated(SBN01) when the preset speed is slower.

Output 0500 turns ON when a setting error occurs.

Acceleration processWhen the difference between the current speed and presetspeed is less than “100,” the speed is accelerated by thedifference. When the difference is “100” or more, the speedis accelerated by “100.”

Deceleration processWhen the difference between the current speedand preset speed is less than “100,” the speedis decelerated by the difference. When thedifference is “100” or more, the speed isdecelerated by “100.”

Page 24: Plc programming course1

VOL.Example

24

Word shifting11Storing the stop duration of equipment in memory as history

The stop duration of equipment is measured using the internal timer of the KV, and is stored into data memoryDM0000. When the equipment stops again, the previous stop duration is transferred to DM0001 and the currentstop duration is written into DM0000. The last 5 stop durations are stored.

Example:

When stop 1 (1 min), stop 2 (2 min and 28 sec), and stop 3 (51 sec) are input sequentially, the contents of eachdata memory is changed, as follows, each time a new stop duration is input.

■ Programming Technique

Use the FOR-NEXT instructions and indirect addressing of data memory.

Use the LDA instruction and STA instruction to shift words in the data memory. The content of each data memory istransferred as follows:

(1): Content of DM0003 is transferred to DM0004.(2): Content of DM0002 is transferred to DM0003.(3): Content of DM0001 is transferred to DM0002.(4): Content of DM0000 is transferred to DM0001.(5): Latest stop duration is transferred to DM0000.

Indirect addressing of the data memory (format: #TMxx) can be performed using tempo-rary data memory (such as TM10 and TM11).

When word shifting (1) is performed, for example, #00003 and #0004 are specified respectively for TM10 and TM11to transfer data from #TM10 to #TM11 using the LDA instruction and STA instruction.

Word shifting of (1) to (4): Transfer from #TM10 to #TM11 is repeated using the FOR-NEXT instructions.

➮ To use the FOR-NEXT instructions in combination with indirect addressing of data memory, refer to examples 1 and 2 ofFOR-NEXT applications of the visual KV Series Users Manual, “Indirect addressing” on page 521.

DM0000:

DM0001:

DM0002

DM0004

#00060 #00148

#00060

#00051

#00148

#00060

Stop 1 (1 min) Stop 2 (2 min and 28 sec) Stop 3 (51 sec)

(5)

DM0000

(4)

DM0001

(3)

DM0002

(2)

DM0003 DM0004

(1)

Latest stop duration

gnitfihsdroW 01MTfoeulaVyltceridninoitanitseD01MT#ybdesserdda

01MTfoeulaVyltceridninoitanitseD11MT#ybdesserdda

)1( 30000# 3000MD 40000# 4000MD

)2( 20000# 2000MD 30000# 3000MD

)3( 10000# 1000MD 20000# 2000MD

)4( 00000# 0000MD 10000# 1000MD

Outline

Page 25: Plc programming course1

25

VOL. 11 Word shifting

ON duration of input 0000 is stored intotemporary data memory TM05.

NEXT

RET

END

SBN00

FOR#00004

0001

0002

0000

1001

1000

1000

2002

2002

0003

0004

0005

0006

0007

0008

0009

0010

0011

0012

2002

TM05STA

TM04SUB

#65535LDA

TM04STA

T000LDA

TM03DEC

TM02DEC

#TM03STA

#TM02LDA

TM03STA

#00004LDA

TM02STA

#00003LDA

#TM03STA

TM05LDA

1001SET

1001RES

00CALL

#65535T000

1000DIFD

0000

1001

1000

1000

DM0000STA

TM05LDA

DM0001STA

DM0000LDA

DM0002STA

DM0001LDA

DM0003STA

DM0002LDA

DM0004STA

DM0003LDA

TM05STA

TM04SUB

#65535LDA

TM04STA

T000LDA

1001SET

1001RES

#65535T000

1000DIFD

FOR#00004

At the rising edge of input to 0000, subroutineprogram is called.

Subroutine for executing word shifting

To execute word shifting (1) first, DM0003 andDM0004 are specified using TM02 and TM03.

Program between FOR and NEXT is repeated4 times.

Content of the data memory indirectly-addressed by TM02 is transferred to the datamemory indirectly-addressed by TM03. Then,the value of TM02 and that of TM03 aredecremented respectively by one, and datamemory No. for the next word shifting isspecified.

After execution of program between FORand NEXT is terminated, the latest stopduration is transferred to the data memory(DM0000) indirectly-addressed by TM03.

Tips

Word shifting (1) is executed.

Word shifting (2) is executed.

Word shifting (3) is executed.

Word shifting (4) is executed.

Word shifting (5) is executed.

When indirect addressing is used, what you haveto do is just to change the value of operand for theFOR instruction. The program does not becomelonger.

Just change this value!

Programming Example

If indirect addressing of data memory using temporary data memory is not used for theabove programming, program for word shifting (for which LDA instruction and STA instructionare used) is shown below.

If word shifting is executed 20times using the LDA instructionand STA instruction, programbecomes longer as frequencyof execution increases.

Page 26: Plc programming course1

VOL.Example

26

12

Line 1Defective productinput: 0003Air discharge: 0500

Line 2Defective productinput: 0004Air discharge: 0501

Line 3Defective product input: 0005Air discharge: 0502

Setting

Digital trimmer

Digital trimmer

#00000to #65535

Internal register Input 0000: When turned ON, it updates thepreset value of the timer for line 1.

Input 0001: When turned ON, it updates thepreset value of the timer for line 2.

Input 0002: When turned ON, it updates thepreset value of the timer for line 3.

Outline

Fine adjustment with a digital trimmerFine adjustment of the air discharge time of a parts feeder

In a factory with several lines, defective products are discharged by air. The digital trimmer of the Visual KV Seriescan be used to adjust the air discharge time for each line according to the size and interval of products.

The digital trimmer mode of the Access Window enables the adjustment of the air discharge without the handheldprogrammer or an external input device.

■ Programming Technique

Use the TMIN instruction to set the digital trimmer.Store the preset value of the Visual KV series’ digital trimmer in the internal register. The value is set in the KV’sinternal timer as the air discharge time for each line.Enter the preset value for each line by changing the preset input respectively.

Visual KV Series

Page 27: Plc programming course1

27

VOL. 12 Fine adjustment with a digital trimmer

0001

0002

0003

0004

0005

0006

0007

0008

0009

0010

0011

00120502

0005

0501

0004

0500

0003

2002

0000

0000

0000 0001

0001

T000

0001 0002

0002

0002 1002

0500

T001 0501

T002 0502

1001

1000

0TMIN

1000 T000STA

1001 T001STA

1002 T002STA

#00080 000ST

#00150 001ST

#00230 002ST

2008 #01000DW

DM1938

Interlock circuit of input relays 0000 to 0002When 0000 turns ON, compressed air releasetime for line 1 is updated.When 0001 turns ON, compressed air releasetime for line 2 is updated.When 0002 turns ON, compressed air releasetime for line 3 is updated.

The preset values of the digital trimmer arechanged to the preset values of timers T000 toT002.

T000: Compressed air release time for line 1T001: Compressed air release time for line 2T002: Compressed air release time for line 3

When input of detecting defective for line 1(0003) turns ON, one-shot output is sentthrough 0500.

When input of detecting defective for line 2(0004) turns ON, one-shot output is sentthrough 0501.

When input of detecting defective for line 3(0005) turns ON, one-shot output is sentthrough 502.

Tips

Programming Example

To set the range for the digital trimmer adjustment, specify the upper limitvalue in data memory.

Digital trimmer 0 Upper limit value: DM1938Digital trimmer 1 Upper limit value: DM1939

Set the upper limit value by specifying it in the device mode of the Access Window or bywriting it in the program.

Example:

To set the range of 0 to 1000:

Page 28: Plc programming course1

VOL.Example

28

13

6 5 4RST 3 2 1

Line 1

Line 2

Line 3

Line 4

Line 5

Pulse

This is repeated until the value of thedata memory is 0.

The CMP instruction checkswhether the value of the data memory is 0.

Each time a pulse is output, the value ofthe data memory is decremented by one.

Outline

Visual KV Series

Receiving multiple pulses andoutputting them as a batchDisplaying total number of products travelling on multiple lines on a coun-

terThe total number of products on all lines is counted. Then, the same number of pulses as counted products areoutput to the RC Series high speed counter to display the total number on the counter.

■ Programming Technique

Create an up-down counter using the INC instruction and DEC instruction.

• To count the total number of products on the line, the INC instruction is used.➮ Refer to No. 1 “Counting total number of products”.

• Since the total count is stored in the data memory, the same number of pulses as the stored value are output tothe RC Series.

In the example from No.1 “Counting total number of products”, the data memory is used. When the temporary datamemory is used instead of the data memory, the value of the memory is reset to 0 automatically when power isturned OFF.

Note 1: If the pulse period of the count input is very short, the RC’s display will not follow the flow of products.Note 2: Use the KV with transistor or MOS-FET type outputs.

RC Series Counter

FS Series Fiberoptic Sensor

Page 29: Plc programming course1

29

VOL. 13 Receiving multiple pulses and outputting them as a batch

2002

0000

0001

0002

0003

0004

2002

T000

0001

0002

0003

0004

0005

0006

0007

0008

0009

0010

0011

0012

TM02INC

TM02INC

TM02INC

TM02INC

TM02INC

TM02DEC

2010 T000#00000CMP

TM02LDA

0500

#00010 000HT

HSP0000

HSP0001

HSP0002

HSP0003

HSP0004

The time constant of input relays 0000 to 0004 isset to 10 µs so that high speed inputs can bereceived.(If you use an input device that chatters, such asa limit switch, do not use the HSP instruction.)

Each time one of input relays 0000 to 0004 turnsON, the value of temporary data memory TM02 isincremented by one.

When the value of temporary data memory TM02is not #00000, timer T000 cycles ON and OFFeach 0.1 sec.

Each time timer T000 turns ON, the value ofTM02 is decremented by one and output is sentthrough 0500.

Tips

2002 2011

1000

0500

0500 TM02DEC

KEEPSET 0500

RES

0500

1000#00000CMP

TM02LDA

Programming Example

To minimize the response delay of the counter display, the following cir-cuit is recommended.

When this circuit is replaced with that on the 11th and 12th lines of the above program, 0500turn ON every two scans. Accordingly, the RC counts once in two scans.

When the scan time is 0.3 ms, for example, the RC counts every 0.6 ms. Higher speedresponse can be obtained by using the above circuit than by using the 1-ms timer.

Page 30: Plc programming course1

VOL.Example

30

Converting high speed pulses intolow speed pulses14Converting pulse frequency

High speed pulses emitted from the high speed response fiberoptic sensor FS-M1H are converted into low speedpulses, and the same number of low speed pulses are output to an electromagnetic counter or host controller.

■ Programming TechniqueThe number of high speed pulses are counted using CTH0, and low speed pulses are output until the high speedpulse count is the same as that of low speed pulses.

High speed pulses are counted using CTH0. Low speed pulses are uniformly output to control the internal timer.The value of the temporary data memory is incremented by one each time a pulse is sent. The pulses continue tobe output until the value of the temporary data memory equals the count value of CTH0.

The width and period of pulses to be output through 0500 can be set as required using timers T000 and T001.

Pulse width =preset value of T001 - preset value of T000Pulse period = preset value of T001

Note: Frequency of low speed pulses depends on error margin of timers T000 and T001.

➮ To count the number of cyclic outputs using the temporary data memory, refer to No. 13 “Receiving Multiple Pulses thenOutputting Them as A Batch”.

Electromagnetic counterLarge host controller

Low speed pulseHigh speed pulse

Visual KV Series

2002

T000

T001

2010 T001TM02CMP

CTH0LDA

0500

#00100 000ST

#00200 001ST

TM02INC

TM02: Used for counting the number of low speed pulses

Outline

Page 31: Plc programming course1

31

Programming Example

VOL. 14 Converting high speed pulses into low speed pulses

2002

0001

0002

#00000LDA

2100STA

CTH0RES

0003

0004CTH0LDA

TM02CMP

2002

2002

0005T000

0006T001

2010 T001

TM02INC

0500

2008

HSP0004

CTH00004

#00200 001ST

#00100 000ST

When the operation is started, reset high-speed counter CTH0 to the initial setting.

The input time constant for input 0004 is setto 10 µs.

High speed pulses are input through 0004.

Pulses whose width is 100 ms and whoseperiod is 200 ms are cyclic-output through0500 until the count value of high speed pulsesbecomes same as that of low speed pulses.

Each time T001 turns ON, the value of TM02is incremented by one.

In the above program, up to 65,535 (maximum number that high speed counter can count)high speed pulses can be converted into low speed pulses. (When 24 bit mode is used, themaximum count is 16,777,215.) When more than 65,535 pulses need be counted, a pro-gram should be created so that the following conditions are satisfied:

Overflow frequency of high speed pulses = overflow frequency of lowspeed pulsesCount value of high speed pulses is same as that of low speed pulsesThe programming example is shown below.

Number of low speed pulses that are output:

Overflow frequency of high speed pulses x 65,535 + count value of high speed pulses.

Pulses whose width is 100 ms and whose period is200 ms are cyclic-output through 0500 until thecount value of high speed pulses becomes same asthat of low speed pulses.

20080001

20020002

2002

20020003

0004

0005

0006

0007

0008

0009

0010

0011

0012

0013

0014

EICTH0RES

2103SET

0004HSP

0004CTH0

END

CTC0INT

RETI

ENDH

#65535CTC0

CTH0LDA

TM02CMP

2010 1000

T001

2002

2010 #00000LDA

TM02STA

TM03INC

TM10INC

TM02INC

TM02LDA

#65535CMP

T000

TM10LDA

TM03CMP

2010

T000

1001

0500

1000

1001

#00100000S

T#00200

001ST

When CTH0 counts up to 65,535 (overflow occurs),the overflow frequency is stored in TM10.TM02: Used for counting the number of low speed

pulsesTM03: Used for counting the overflow frequency of

low speed pulsesTM10: Used for counting the overflow frequency of

high speed pulses

Tips

When the value of TM02 exceeds 65,535 (overflowoccurs), the overflow frequency is stored in TM03.

Page 32: Plc programming course1

VOL.Example

32

Bit counting (Bit checking)15Checking how many error detection signals are input to input relays of channel

The KV checks how many sensors for detecting errors (that are connected to input relays 0000 to 0015 of channel0) are currently turned ON, allowing you to confirm the total number of errors.

■ Programming TechniqueThe KV checks whether each input relay is ON, and the number of relays that are ON are counted.

Use the RRA instruction to check the status of input relays.

Procedures1. The status of the input relays of channel 0 are entered into the internal register using the LDA instruction.

2. Contents of the internal register are shifted right by one bit using the RRA instruction.

3. Contents of the rightmost bit is entered into special utility relay 2009. When the contents of 2009 is 1 (ON), 1 isadded to the number of errors.

The above operation is repeated 16 times (number of bits of channel 0).

The SRA instruction can be used in the same way.

➮ Refer to KV Series Users Manual, “Change in status of special utility relays by arithmetic instruction” on page 580 to 582.

0 0 1 5

OFF0 0 1 4 0 0 1 3

OFF OFF OFF OFF OFF OFF OFF OFF OFF OFF OFF0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

ONONONON

Visual KV Series

Errordetection

input

Four errors are detected.

0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

11 0 0 0 0 1 0 0 1 0 0 0 0 00

0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

02 0 0 9

10 1 0 0 0 0 1 0 0 1 0 0 0 00

0000LDA

#01RRA

When content of 2009 is 1 (ON), 1 is added to the number of errors.When content of 2009 is 0 (OFF), no action is performed.

Repeated16 times.

Outline

Page 33: Plc programming course1

33

VOL. 15 Bit counting (Bit checking)

Programming Example

FOR

NEXT

0000LDA

TM10INC

#01RRA

TM10STA

#00000LDA

TM10LDA

DM0000STA

#00016

20022002 2009

2002

20020001

0002

0003

0004

0005

The ON/OFF status of the input relays of channel0 are always entered into the internal register.

16 bits of the internal register are checked.

Bits are shifted right one by one each time the bitof 2009 is checked, and the value of TM10 isincremented by one when 2009 turns ON.

After the 16 bits are checked, the value of TM10 istransferred to DM0000 and the value of TM10 isreset to 0. The value entered into DM0000 is thenumber of inputs that turns ON.

When some of the input relays of channel 0 are used for purposes other than error detection,the ON/OFF status of those input relays should not be subjected to bit checking.

Immediately after status of the input relays of channel 0 are read using the LDA instruc-tion, fetch only status of the desired inputs using the ANDA instruction.

Example

When input 0006 is not used for error detection input:

As shown above, the status of error detection input relays only can be read, allowing thenumber of errors to be counted.When the input relays of another channel, in addition to channel 0, are also used for errordetection input, specify the desired channel for LDA and create the same program as theabove, then combine it with the above program.

➮ The number of error detection inputs can be counted using the INC instruction more easily thanusing the C (Counter) instruction. For details, refer to No. 1 “Counting total number of products”.

Tips

$FFBFANDA

0000LDA

20020001

0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

0 0 1 0 0 0 0 1 0 0 0 0 0 0 0 0

0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

0 1 0 0 0 0 1 0 0 0 0 0 0 0 0 1

$FFBFANDA

#01RRA

0000LDA

0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 00 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8

0 1 0 0 0 0 1 0 0 1 0 0 0 0 0 1

0 0 1 5 0 0 1 4 0 0 1 3 0 0 1 2 0 0 1 1 0 0 1 0 0 0 0 9 0 0 0 8 0 0 0 7 0 0 0 6 0 0 0 5 0 0 0 4 0 0 0 3 0 0 0 2 0 0 0 1 0 0 0 0

1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 1

2 0 0 9

1

Page 34: Plc programming course1

VOL.Example

34

O K

O K

O K

N G

N G

DM0004

DM0002

DM0001

DM0003

DM0000

O K

N G

N G

DM0004

DM0002

DM0001

DM0003

DM0000

O K

O K

Blank

Shift register simulation in an asyn-chronous production line16Ejecting rejects without a constant synchronous signal

When interval between workpieces on the production line varies, rejects are correctly ejected only by using sensorsfor detecting rejects and for confirming a workpiece in the ejection position.

• Inputting clock pulses (synchronous signal) for a timing cam is not required.

■ Programming TechniqueSince the clock pulse input to control the position of a reject on the line is not used, the SFT instruction cannot beused. ➮ Refer to No. 2 “Shift register”.

Then, use the data memory to eject rejects.Information whether each workpiece is acceptable or not is stored sequentially into the data memory. When eachworkpiece reaches the ejection position, the workpiece is accepted or ejected according to the stored information.

First-in first-out (FIFO) queuing is used to store and read data.

Ejection process

Box forreceivingrejects

Sensor for synchronizationINPUT 0000

Even if interval between workpieces is not constant,rejects can still be correctly ejected.

Sensor for confirmingworkpiece in ejectionposition INPUT 0002

Sensor fordetecting rejectsINPUT 0001

Inspection process

Reject detection input: 0001

Ejection

When input from theworkpiece confirmationsensor at the ejection position(0002) turns ON

Outline

Page 35: Plc programming course1

35

0001

0002

2008

0000

0002 1001

0500

0003

0004

0005

0006

0007

0008

0009

0010

0011

1000

$1111CMP

DM0000LDA

DM0000STA

$FFFFLDA

$FFFF

DM0001DW

DM0000STA

DM0001LDA

$FFFFCMP

DM0000LDA

2002 2010

$FFFF

DM0002DW

DM0001STA

DM0002LDA

$FFFFCMP

DM0001LDA

2002 2010

$FFFF

DM0003DW

DM0002STA

DM0003LDA

$FFFFCMP

DM0002LDA

2002 2010

$FFFF

DM0004DW

DM0003STA

DM0004LDA

$FFFFCMP

DM0003LDA

2002 2010

STADMOOO2

STADMOOO4

STADMOOO3

STADMOOO1

STADMOOO0

LDA$FFFF

STADMOOO4

LDA$1111

STADMOOO4

LDA$00000001

0001

100020101001DIFU

#00010T000

0500T000

Programming Example

The important point is that the blank data is entered into the contents ofthe data memory after a defective workpiece is ejected.

On the 8th to 11th lines of the above program, the contents of data memory DM0000 ismade blank after a reject is ejected. To perform the next ejection, the contents of the nextdata memory (DM0001) must be transferred to DM0000. Blank data memory is expressed as$FFFF, and the contents of data memories DM0001 to DM0004 is transferred sequentially tothe previous data memory to fill the data memory where $FFFF is written.

By changing content of the data memory, product types can be differentiated.In addition to acceptable ($0000) and defective ($1111), other information can be digitalizedand entered into the data memories. This allows differentiation between product types.

Example

Product type 1 ($0100), product type 2 ($0200), product type 3 ($0300), etc.

When power is turned ON, $FFFF is written intoDM0000 to DM0004. $FFFF assumes that content ofthe data memories is blank.

When input 0000 (input from sensor for synchroniza-tion) turns ON, detection of rejects is performed (0001).

Acceptable workpiece: $0000 is entered into DM0004.Defective workpiece: $1111 is entered into DM0004.

When the workpiece in ejection position is defective($1111), output is sent through 1000.After workpiece acceptability has been determined,the contents of DM0000 is erased.

When the contents of DM0000 to DM0004 isblank, the contents of each data memory istransferred to the previous data memory.

O K

O K

N G

DM0002

DM0001

DM0003

DM0000

O K

N G

N G O K

N G

O K

O K

Blank

Blank

Blank

VOL. 16 Shift register simulation in an asynchronous production line

When the workpiece is defective, a one-shot output issent through 0500.

Contents of data

$FFFF: No data (blank)$0000: Acceptable$1111: Defective

Tips

Page 36: Plc programming course1

VOL.Example

36

Emergency stop circuit17Emergency stop for cutting work

■ Programming Technique

Use the MC-MCR instructions for performing an emergency stop.

Put the cutting program between the MC and MCR instructions and create the program so that the MC instructionis set to OFF when an emergency stop signal is input. Then the cutting process, which was interrupted by anemergency stop signal, is stored and can resume when the emergency stop is canceled.

Configure program as follows:

Control circuit and emergency stop circuit can be programmed as 2 independent steps.

Operation procedures

Visual KV Series

➞➞

➞➞

Releasing chuck

Retreatingcutting tool

Advancing cuttingtool and machiningworkpiece

Rotating workpiece

Closing chuck Emergency stop

?????

?????

????? ????? ?????RST

?????

?????

SET

?????

????? ?????SET

????? ????? ?????RES

MC

MCR

?????

?????

Emergency stop input

Outline

Emergency stop

An emergency stop is performed in the cutting process shown below.

Page 37: Plc programming course1

37

VOL. 17 Emergency stop circuit

Programming Example

* When operation resumes, after the emergency stop is canceled(0005: OFF), all relays except for output relays* are reactivated in thesame status (ON/OFF) as before the emergency stop was performed.The timer, however, operates from its initial status.

* Outputs are set to OFF when an emergency stop is performed.

When 0000 turns ON, STG 1000 turns ON andthe cutting operation starts.

1000STG

1001JMP

1002JMP

1003JMP

1000JMP

1001STG

1002STG

#00030T000

1003STG

0001

0002

0003

0004

0005

0006

0007

MC

0501SET

0500

0502

0504

0002

0003

0000

0001

0503

0000 1000SET

MCR

0005

0501RES

T000

When 0005 turns ON, an emergency stop isperformed. (All outputs between MC and MCRinstructions are turned OFF.)The chuck closes and execution is transferred toSTG 1001 when chuck confirmation input is setto ON.The motor starts and the cutting tool advances.When the cutting tool reaches the other end,execution is transferred to STG 1002.The motor stops after 3 sec and the cutting toolis retracted. When the cutting tool reaches itsorigin, execution is transferred to STG 1003.The chuck is released and the system waits fora restart.

ENDS0005

2003

2003

0005

SFTD 1000

CLK

1003RES

0000: Start0001: Confirming chuck closing0002: Confirming advance end0003: Confirming retreat end0500: Closing chuck0501: Rotating motor0502: Advancing cutting tool0503: Retreating cutting tool

For users who need a complete reset when the emergency stop is per-formedTo perform a complete reset when the emergency stop is performed, add the following stepto the above program as the 8th line.

By adding the above step, execution of all STG instructions is stopped. The above is effectivefor resetting all relays when the STG instruction and JMP instruction are used in a sequentialprocess.

Even when processes other than a sequential process are controlled, the SFT instructioncan be used conveniently to reset all the specified internal relays.

➮ When input 0005 turns ON, internal relays 1000 to 1003 can be reset.

Tips

Page 38: Plc programming course1

VOL.Example

38

Selection of operation mode18Selecting fully-automatic or individual operation mode

On a production line with multiple processing machines, the fully-automatic or individual operation mode is se-lected. (fully-automatic operation mode allows workpieces to be transferred sequentially to each machine, whileindividual operation mode allows each machine to be operated by pressing a pushbutton.)

■ Programming TechniquePoints are as follows:

1. Sequential processing is controlled.2. Because one process is controlled using two inputs (fully-automatic and individual), a double-input coil is ap-

plied.

The STG instruction and JMP instruction are optimal for controlling the process shownabove.

For the STG instruction, one coil can be used as the output for 2 relays as shown below.

By programming internal relays 1000 and 1001 not to turn ON simultaneously, the ON/OFF of 0500 can be control-led using the STG instruction for internal relays 1000 and 1001.

0007 0008 0009

Con

firm

ing

wor

kpie

ce s

ettin

gP

roce

ssin

g 2

Eje

ctin

g w

orkp

iece

Con

firm

ing

wor

kpie

ce s

ettin

gP

roce

ssin

g 3

Pushbutton forindividual operation

Fully-automatic

Individual

Selector switch0000

Eje

ctin

g w

orkp

iece

Eje

ctin

g w

orkp

iece

Pro

cess

ing

1

Con

firm

ing

wor

kpie

ce s

ettin

g

Processingmachine 1

Processingmachine 2

Processingmachine 3

0001

0002

1001

1000

0500

0500

1000STG

1001STG

Outline

Page 39: Plc programming course1

39

Programming Example

000020080001

0002

0003

0004

0005

0006

0007

0008

0009

0010

0011

0012

0013

0014

0001 0002

1201

1000STG

1001JMP

ENDS0003

1201

1001STG

0005

1201

1002STG

0500

0501

0502

0004

0006

0007

1200

1100STG

05000001

05020005

0008

0009

05010003

0000 1200

1201

1002JMP

1000JMP

ENDS

ENDS

ENDS1200DIFU1201DIFU

1000SET

1100SET

1000SET1100SET

C000

0000

When power is turned ON, STG 1000 (fully-automatic operationmode) is selected when the input for the selector switch turns ON.At this time, STG 1100 (individual operation mode) is selectedwhen the input for the selector switch turns OFF.

Fully-automatic operation modeControl of processing machine 1:After confirmation of workpiece setting, processing, andconfirmation of workpiece ejection are completed, execution istransferred to STG 1001 (processing machine 2).

The STG instruction for the fully-automatic operation mode iscanceled.

Control of processing machine 2:After confirmation of workpiece setting, processing, andconfirmation of workpiece ejection are completed, execution istransferred to STG 1002 (processing machine 3).

The STG instruction for the fully-automatic operation mode iscanceled.

Control of processing machine 3:After confirmation of workpiece setting, processing, andconfirmation of workpiece ejection are completed, execution istransferred to STG 1000 (processing machine 1).

The STG instruction for the fully-automatic operation mode iscanceled.

Individual operation modeControl of processing machine 1: After workpiece setting isconfirmed, each workpiece is processed by pressing thepushbutton switch.Control of processing machine 2: After workpiece setting isconfirmed, each workpiece is processed by pressing thepushbutton switch.Control of processing machine 3: After workpiece setting isconfirmed, each workpiece is processed by pressing thepushbutton switch.

The STG instruction for the individual operation mode iscanceled.

The STG instruction for the individual operation mode iscanceled, and the fully-automatic operation mode is selected.

The STG instruction for the fully-automatic operation mode iscanceled and the individual operation mode is selected.

ENDSC000#00005

0006C000

C000

Description of terminals0000: Mode selector switch0001: Confirming workpiece setting (processing machine 1)0002: Confirming workpiece ejection (processing machine 1)0003: Confirming workpiece setting (processing machine 2)0004: Confirming workpiece ejection (processing machine 2)0005: Confirming workpiece setting (processing machine 3)0006: Confirming workpiece ejection (processing machine 3)0007: Pushbutton switch for individual operation (processing machine 1)0008: Pushbutton switch for individual operation (processing machine 2)0009: Pushbutton switch for individual operation (processing machine 3)0500: Processing output (processing machine 1)0501: Processing output (processing machine 2)0502: Processing output (processing machine 3)

VOL. 18 Selection of operation mode

To repeat a cycle of fully-automatic operation several times, add the following step to theabove program as the 11th line of the program.Example

To repeat a cycle of fully-automatic operation 5 times:

The number of times that input 0006 turns on, indicating the completion of one cycle opera-tion (completion of machine 3 process), is counted. When the count value reaches thepreset value, the entire process operation is terminated. (To restart operation, turn ON input0000 again.)

Tips

Page 40: Plc programming course1

VOL.Example

40

Step-progress operation(sequential control)19

When the step-progress operation is specified, pressing the start button changes the operation process one by one.

■ Programming Technique

W-UE (wait up edge) instruction is useful for step-progress operation.When the W-UE instruction is used with the STG and JMP instructions, one start button allows the step-progressoperation (sequential control) of every process.

12

4

56

7

8

3

Parts feeder

StageStart

Step

Auto

Operation panel

Origin point

1. Lowering the arm

2. Clamping

3. Raising the arm

4. Forwarding the arm

5. Lowering the arm

6. Unclamping

7. Raising the arm

8. Returning the arm

STG1001

JMP100211010000

1101

0500

STG1002

JMP100311020000

1102

0501

STG1003

JMP100411030000

1103

0502

Start button

DIFU1101

0500

0000

JMP1002

STG1001 1101

DIFU1102

0501

0000

JMP1003

STG1002 1102

DIFU1103

0502

0000

JMP1004

STG1003 1103

Start button: 0000

When the STG and JMP instructions are used for the control of each process, the program can be created inde-pendently. This allows for easy programming.

Without W-UE instruction: Complicated

Outline

With W-UE instruction: Simple

Step progress of material handling machine

Page 41: Plc programming course1

41

VOL. 19 Step-progress operation (sequential control)

Programming Example

00050001

00021100

1000SET

1000STG

10010000

1100JMP

000311011001 0500

STG10020000

1101JMP

000411021002 0501

STG10030000JMP

000511031003 0502

STG10040000

1103JMP

000611041004 0503

STG10050000

1104JMP

000711051005 0501

STG10060000

1105JMP

000811061006 0504

STG10070000

1106JMP

000911071007 0502

STG10080000

1107JMP

001011081008 0505

STG10000000

1108JMP

1102

When 0005 turns ON, the step-progress operationis enabled.

When 0000 turns ON, the arm is lowered.

When 0000 turns ON, the product is clamped.

When 0000 turns ON, the arm is raised.

When 0000 turns ON, the arm is forwarded.

When 0000 turns ON, the arm is lowered.

When 0000 turns ON, the product is unclamped.

When 0000 turns ON, the arm is raised.

When 0000 turns ON, the arm returns.

When 0000 turns ON, the arm goes back to theorigin point.

0000: Start button0005: Step-progress operation setting0500: Lowering the arm

0501: Clamping0502: Raising the arm0503: Forwarding the arm

0504: Unclamping0505: Returning the arm

0005

2002

1000 1100

SET

STG JMP

1000

RES1100

1001 1100STG JMPRES

1100

1002 1100STG JMPRES

1100

0000

1100

0500

0501

1001

1002

1003

Save the internal relay by setting the step-progress operation using the W-UE instruction.

Since the W-UE instruction does not allow for the duplication of the second operand, theprogramming example above requires several internal relays.

However, the following program requires only the one point of an internal relay.

The point is that the internal relay 1100 used for the W-UEinstruction resets itself.

0000

????

Tips

Page 42: Plc programming course1

VOL.Example

42

Frequency counter function20Counting the number of rotations using the frequency counter

With the frequency counter function, which the Visual KV Series features as standard, measure the time for theoutput pulse of a rotating object received through input 0004 with the high-speed counter and convert it into afrequency (Hz). The measured frequency is used for the calculation of the number of rotations (rpm).

Applications: Detecting the reduction in the number of rotations of a magnet, detecting the reduction in the numberof rotations of an agitator, and measuring the frequency of a rotating object

■ Programming TechniqueThe frequency counter function of high-speed counter CTH0 enables the measurement of the frequency of 30 kHzat maximum.Input the pulses for the frequency measurement to 0004. (In this case, phase B input 0006 is ignored.)

Devices used for the frequency counter functionSpecial utility relay2305: Enable/disable the frequency counter function ON: Enable, OFF: Disable

Data memoriesDM1404: Measurement cycle of frequency count (1 to 9999 [ms])DM1405: Result of frequency count (Hz)

Turning ON special utility relay 2305 starts the frequency counter function. The measurement result (Hz) is stored inDM1405.To set the interval of the frequency measurement (ms), specify the value larger than the scanning time in DM1404in the unit of ms.The number of rotations can be obtained from the measured frequency with the following calculation:

No. of rotations (rpm) = Frequency (Hz) x 60 (sec.) / (No. of pulses for one rotation)

Note: When setting the measurement cycle, limit the number of pulses that are input during one measurementcycle within the range of 2 to 65535.The frequency counter function and high-speed counter CTH0 cannot be used at the same time.

Proximity sensor

Pulse

Visual KV Series

Outline

Page 43: Plc programming course1

43

Programming ExampleCount the number of rotations of the gear which requires 10 pulses for one rotation.Count the frequency of the pulses received through input 0004 every second (1000 ms). Store the result inDM0000 and store the calculated number of rotations in DM0001.

VOL.20 Frequency counter function

2008

2002

DM1404STA

#01000LDA

DM1405LDA

DM0000STA

#00010DIV

DM0001STA

DM0000LDA

#00060MUL

2002

END

ENDH

HSP0004

2305SET

DM0001 > DM0010: Lo output2002 2009

2002 2009

2009 1002

1001

1000DM0010CMP

DM0001LDA

DM0011CMP DM0010 DM0001 < DM0011: Go output

DM0011 DM0001: Hi output

After the measurement cycle of the pulses is set to 1000 ms(1 sec.). The frequency counter start relay 2305 is turned ON.

The input time constant for input 0004 is set to 10 µs.

The measured frequency (Hz) is stored in DM0000.

The number of rotations (rpm) is calculated with the meas-ured frequency and is stored in DM0001.

To obtain the signals of Hi, Go, and Lo using the number of rotations, use the COMPARE(CMP) instruction in the program.

Tips

Page 44: Plc programming course1

VOL.Example

44

Sorting21Sorting machines in the ascending order of production

In the production site with multiple-injection molding machines, the Visual KV Series counts the number of moldedproducts of each machine. The resulting with count can be used to determine the machine of low production.

* This example uses 5 machines for simplification. This application is more effective with a greater number ofmachines.

■ Programming TechniquePrepare data memories for each machine to register the machine No. and the count value. (Example: Machine 1:DM0011 for machine No., DM0001 for count value)The sorting uses these data memories.

The large/small comparison of all target data memories is repeated and the data memo-ries are sorted.

Flow chart of large/small comparison

It is convenient to use the indirect addressing with temporary data memory in order to specify the data memorynumber (*).

C001=#2500

C002=#2200

C003=#2400

C004=#2100

C005=#2300

DM0012=#0002: DM0002=#2200

DM0013=#0005: DM0003=#2300

DM0014=#0003: DM0004=#2400

DM0015=#0001: DM0005=#2500

DM0011=#0004: DM0001=#2100

<Before sorting> <After sorting>

Machine No. Count value

Machine 1

Machine 2

Machine 3

Machine 4

Machine 5 High

Low

DM(*)>DM(*+1) DM(*)≤DM(*+1)

DM(*): DM0001 to DM0005

(*+1)≤5

(*+1)>5

Start

Compares the data of DM (*) with DM (*+1)

Switches the data and machine Nos. in DM(*) and DM (*+1).

Compares the new data in DM (*) with thedata in DM (*-1). Repeats the comparisonuntil the data memory number (*) becomesthe initial number (0001).

End

Repeats the comparison until the data memorynumber (*+1) becomes the last number (0005).

Outline

Page 45: Plc programming course1

45

VOL. 21 Sorting

Programming Example

Sorting busy relay 1000 is set at therising edge of 0000. The data memoryand temporary data memory are set tothe initial settings.

#00001LDA

TM10STA

#00002LDA

TM11STA

#00011LDA

TM12STA

#00005CMP

#00012LDA

TM13STA

#TM11LDA

#TM10STA

TM20STA

#TM10LDA

TM20LDA

#TM11STA

0000

1000

1000

0001

0002

0003

0004

0005

0006

0007

0008

0009

0010

0011

0012

0013

0014

0015

0016

0017

0018

0019

0020

0021

0022

0023

10011001DIFU

03CALL

00CALL

1000SET

1000

TM11LDA

2011

END

01SBN

RET

02SBN

2002

C003LDA

DM0003STA

DM0002STA

C002LDA

DM0001STA

C001LDA

C004LDA

DM0004STA

DM0005STA

C005LDA

#00003DW

DM0013

#00004DW

DM0014

#00002DW

DM0012

#00001DW

DM0011

#00005

DM0015DW

2002

2002

ENDH

#TM11CMP

#TM10LDA

TM11INC

TM12INC

TM13INC

TM10INC

#00005CMP

TM11LDA

2011

CMP#00000

LDATM10 TM11

DECTM10DEC

TM13DEC

TM12DEC

2011

RES

02CALL

01CALL

2010

#TM13LDA

#TM12STA

TM20STA

#TM12LDA

TM20LDA

#TM13STA

RET

00SBN

RET

RET

SBN03

2011

If the value in TM11 is less than “5,” thesubroutine of the sorting is called.

Subroutine for switching the count values.

The data in DM0001 to DM0005 areswitched by using the indirect addressing.

Subroutine for switching the machineNos.The data in DM0011 to DM0015 areswitched by using the indirect addressing.

Subroutine for sorting

To sort values in ascending order, “1” isadded to the data memory No. (*) until“*+1” exceeds the last number “5.” Whenit exceeds “5,” relay 1000 is reset and theoperation finishes.

To sort values other than in ascendingorder, the count values and the machineNos. in data memories are switched. Tocheck the previous comparison, “1” issubtracted from the data memory No. (*)until the number returns to the initialnumber (0).

Subroutine for initial setting of sorting.

The machine Nos. and count values aretemporarily copied in data memories.

* The count inputs for C001 to C005should be prepared separately.

Page 46: Plc programming course1

VOL.Example

46

High-speed interrupt input function22

Measure the time during which the target passes two points A and B and calculate the passing speed.The FS-M1H high-speed response photoelectric sensor is used as the sensor. The passing time is measured withthe internal clock of the high-speed counter in the unit of µs.

Applications: Measurement of the swing speed of a golf club head.

■ Programming Technique

Point 1: Measure the passing time with the internal clock of the KV.• Use the KV’s internal clock (1-µs cycle) and the high-speed counter to measure the passing time.

(Passing time) = (Cycle of internal clock: 1 µs) x (No. of clock counts)

Point 2 The interrupt (INT) instruction is the best for the program.• When the sensor detects the target, the interrupt is executed. Store the current value of the high-speed counter

in the data memory.When the interrupt is executed, the current value of the high-speed counter is automatically stored in the datamemory (Input capture function).By using this function, the passing time is obtained as the difference between the stored counter values ofsensor 1 and sensor 2.

(Passing time) = [yyyyy (DM1934) - xxxxx (DM1932)] x (Cycle of internal clock: 1 µs)

ONOFF

ONOFF

Sensor 2INPUT 0003

Sensor 1INPUT 0002

Sensor 1

Sensor 2

Sensor 1

Sensor 2

Internal clock(1 µs) No. of clock

counts

Passingtime

DM1934DM1932

No. of clockcounts

Sensor 1(Interrupt 0002)

Passingtime

Sensor 2(Interrupt 0003)

Internal clock(1 µs)

No. of pulses = xxxxx No. of pulses = yyyyy

(Value stored by the input capture of 0003)(Value stored by the input capture of 0002)

Measurement of passing time between two points using high-speed interrupt input

Outline

Visual KV Series

Passing time (µs)

Page 47: Plc programming course1

47

VOL. 22 High-speed interrupt input function

Programming Example• Measures the time from when input relay 0002 turns ON until input relay 0003 turn ON.• The measured value is written to data memory DM0000 (Unit: µs).• Writes the calculated speed into DM0010 (unit: m/ms).

(This program sets the distance between sensor 1 and sensor 2 to 1 m.)

2008

2002

2002

2412RES

2413RES

2410RES

2411RES

HSP0002

CTH12200

END

0002

RETI

RETI

ENDH

HSP0003

2002 DM0000STA

DM1932SUB

DM1934LDA

DM0010STA

DM0000DIV

#01000MUL

#00001LDA(1) (2)

EI

INT

0003INT

#00100MUL

#00100LDA

DM0000DIV

DM0010STA

#01000MUL

When power is turned on, an EL instruction enablesinterrupts. Sets the interrupt polarity of inputs 0002 and0003 to the rising edge.

Sets the input time constant of inputs 0002 and 0003 to10 µs.

CTH1 counts the pulses using a 1-µs internal clock.

When INT0002 is executed, the current value of CTH1 isautomatically transferred to DM1932 and DM1933 (Inputcapture).

When INT0003 is executed, the current value of CTH1 isautomatically transferred to DM1934 and DM1935 (Inputcapture).

Subtracts the input capture value of INT0002 from thatof INT0003 to obtain the time it takes for the target topass between two points and then writes it to DM0000.(Unit: 1µs)

The passing speed is obtained through calculating (2)the passing time and (1) the distance between the twopoints (unit: m/ms). It is stored in DM0010.

Calculation of passing speedThe passing speed is calculated with the following expression:

Passing speed (m/ms) = ((1) Distance between two points [Unit: m]) / ((2) Passing time [Unit: ms])

In the program above, the passing time is measured in the unit of µs. Therefore, the meas-ured value is multiplied by the factor of 1000 (2) to be converted into the value in the unit ofms. The calculation uses 1 m (1) as the distance between the two points.

To set the distance between the two points in the unit of cm, multiply it by the factor of 100 asthe underlined section in the following program. The unit of speed is set to cm/ms.

To convert the unit of time from µs to s (second), multiply values by the factor of 1,000,000(execute 1,000x twice in a program).

Tips

Page 48: Plc programming course1

VOL.Example

48

Synchronous control functionSynchronous control of a pulse motor

23

Synchronize and control the roller speed at the feeding side and the ejecting side of a device.Control is easy when using the frequency counter function and specified frequency pulse output function featuredas standard with the Visual KV Series.

Application: Time adjustment for sheet material remaining in the processing bath.

■ Programming TechniqueUse the frequency counter function of high-speed counter CTH0 to measure the frequency of the pulses (Hz) sentthrough input 0004. Then, use the specified frequency pulse output function to output the pulse of the same fre-quency as the measured input pulse from 0501.

The pulses are output after the frequency is changed according to the measurement result. The response is de-layed by the length of the measurement.

Devices used with the frequency counterSpecial utility relays

Data memory

Devices used with the specified frequency pulse outputSpecial utility relays

Data memory

Pulse input

Pulse output

Pulse input0004

Pulse output0501

(Specified frequency pulse output function)2306: Starts pulse output when turned ON.DM1936: Frequency of output pulse

Pulse output

Datatransfer

(Frequency counter function)CTH0: high-speed counter (Measurement ofpulse period)2305: Enables operation when turned ON.DM1404: Measurement timingDM1405: Measured frequency

Frequency measurement

Outline

.oNyaleR noitpircseD5032 oN:FFO,seY:NO.retnuocycneuqerfesU

.oNMD noitpircseD4041MD )]sm:stinU[9999ot1(.retnuocycneuqerffo)sm(elcyctnemerusaeM

5041MD .retnuocycneuqerffo)zH(tnuocycneuqerffotluseR

.oNyaleR noitpircseD

6032noitcnuFoN:FFO,seY:NO.tuptuoeslupycneuqerfdeificepsesU

.NOsnrut7032yalerrorrenehwFFOdecrofsi

7032.noitcnuftuptuoeslupycneuqerfdeificepsrofgalfrorrE

).FFOdenrutsituptuoeslupeht,NOdenrutnehW(

.oNMD noitpircseD6391MD )]zH:stinU[00005ot61(.nettirwsituptuoeslupycneuqerfdeificepsrofeulavteserP

Page 49: Plc programming course1

49

VOL. 23 Synchronous control function

Programming ExampleThe frequency of the pulse sent through input 0004 is measured every 100 ms. Then, the pulses of the samefrequency are output from 0501. The pulse output is disabled when the measured frequency is less than 16 Hz.

The measurement cycle is set to 100 ms. The frequency counterstart relay (2305) turns ON.

END

HSP

ENDH

0500

#00100LDA

DM1404STA

DM1405LDA

DM1936STA

00042002

2002

2307

2008

2306SET

2305SET

DM1936STA

#00002DIV

DM1405LDA

2002 2306SET

The input time constant of input 0004 is set to 10 µs.

The specified frequency pulse output start relay (2306) is turnedON. The measured frequency (DM1405, Unit: Hz) is used as theoutput frequency (DM1936, Unit: Hz).Output 0500 turns ON when an error occurs in the setting of thespecified frequency pulse output.

• The pulses of the frequency up to 30 kHz can be measured with the frequency counterfunction.

• The pulses of the frequency up to 50 kHz can be output with the specified frequencypulse output function. (Duty cycle of the pulses is 50%.)

• It is also possible to multiply the measured frequency by the factor of 2 or 1/2 for theoutput.

Example

Output pulses of half frequency of the measured frequency. The pulse output is disabledwhen the measured frequency is less than 16 Hz.

Tips

Page 50: Plc programming course1

VOL.Example

50

High-speed counter24Multi-step comparator operation with high-speed counter

By counting the pulses from the encoder, control the feeding amount of cloth and cut it at a specified length.The high-speed counter is used to count the high-speed pulses from the encoder.The number of pulses for the deceleration point, stopping point, and overrunning point are preset in data memories.

Application: Cutting products at a specified length

■ Programming TechniqueThis control requires three preset values of the number of pulses to determine deceleration, stopping, andoverrunning points.The program of multi-step comparator operation can be simplified by using the multi-step comparator mode of thehigh-speed counter’s cam switch function.In the multi-step comparator mode, the value in DM1401 is compared with each preset value (DM 1406 toDM1469). When the value in DM1401 is larger than the preset value, the corresponding relay is turned ON/OFF.Up to 32 points can be set as the preset values.

High-speed counter CTH1 counts the pulses from the encoder received through inputs 0005 and 0007. The currentvalue of CTH1 is transferred to DM1401 as the value for comparison.Set the preset values (comparator values) in DM1406 to DM1469 before the operation.To enable the multi-step comparator operation, turn ON special utility relay 2314.To stop the operation, turn OFF special utility relay 2715.

Devices used in multi-step comparator modeSpecial utility relays2314: Operation start relay (Operation starts when turned ON)2315: Error relay (Turns ON during an error.)2715: In-operation relay (Turns ON during operation.)

Data memoriesDM1400: The initial No. of output relaysDM1401: The value to be compared. (0 to 65535)DM1402: Enter “65535” in the multi-step comparator mode.DM1406: Preset value to turn ON output relay “initial No. + 0” (0 to 65534)DM1407: Preset value to turn OFF output relay “initial No. + 0” (0 to 65534)DM1408: Preset value to turn ON output relay “initial No. + 1” (0 to 65534)DM1409: Preset value to turn OFF output relay “initial No. + 1” (0 to 65534)

: :DM1468: Preset value to turn ON output relay “initial No. + 31” (0 to 65534)DM1469: Preset value to turn OFF output relay “initial No. + 31” (0 to 65534)

Film

Encoder

Pulley fordetection

Cuttingmachine

End of winding

Enter the presetvalue of the numberof pulses for eachpoint.

Alarm

OverrunningCutting

Start of winding

Decrease inwinding speed

Outline

Page 51: Plc programming course1

51

VOL. 24 High-speed counter

High-speed counter CTH1 is set to the double multiplication mode.2008 CTH1

RES

2314SET

2213SET

2214RES

END

ENDH

HSP0005

HSP0007

CTH10005

0000

2002

0001

1000

1001

DM1401STA

CTH1LDA

#65535

DM1402DW

#00500

DM1400DW

#10000

DM1406DW

#15000

DM1408DW

#20000

DM1410DW

#16000

DM1409DW

#21000

DM1411DW

#11000

DM1407DW

2715RES

1000DIFU

1001DIFU

2002

Relay 0500 is set as the initial relay to be used in the multi-stepcomparator mode. The multi-step comparator mode is specified.

The positions where relays 0500 to 0502 turn ON/OFF arespecified.

The input time constants for inputs 0005 and 0007 are set to 10 µs.

High-speed counter CTH1 counts the pulses from the encoder.The current value of CTH1 is transferred to DM1401. This value isused for the comparison.

When input 0000 turns ON, the multi-step comparator mode isactivated.

When input 0001 turns ON, The multi-step comparator mode isstopped.

Tips

Programming ExampleWhen input 0001 turns ON, the multi-step comparator mode is enabled.When input 0002 turns ON, the multi-step comparator mode is disabled.Outputs are assigned as follows:Deceleration: 0500, Stopping: 0501, Overrunning: 0502

The multi-step comparator mode compares values with the value stored in DM1401.Therefore, not only the high-speed counter values but also the current values of a timer orcounter can be used for the multi-step comparator operation.

Page 52: Plc programming course1

52

Page 53: Plc programming course1

53

Page 54: Plc programming course1

54

Page 55: Plc programming course1

©KEYENCE CORPORATION,1999 NKV-KA-APC-1-0024 Printed in Japan

Specifications are subject to change without notice.

Visit our website for other Keyence products at

KEYENCE CORPORATION OF AMERICACorporate Office50 Tice Blvd., Woodcliff Lake, NJ 07677Phone:201-930-0100 Fax:201-930-0099E-mail:[email protected]

PennsylvaniaPhone:610-382-1310Fax: 610-382-1320

VirginiaPhone:804-327-9522Fax: 804-327-9180

New JerseyPhone:201-474-1480Fax: 201-474-1481

ClevelandPhone:216-464-7530Fax: 216-464-7540

AtlantaPhone:770-951-1222Fax: 770-951-1958

BostonPhone:781-453-2244Fax: 781-453-2255

ChicagoPhone:847-969-0001Fax: 847-969-0453

ColumbusPhone:614-799-3400Fax: 614-799-3401

St. LouisPhone:314-275-9174Fax: 314-275-9175

CharlottePhone:704-423-0070Fax: 704-423-0066

IndianapolisPhone:317-843-2616Fax: 317-843-2647

CincinnatiPhone:513-554-1227Fax: 513-554-1229

TexasPhone:972-733-6790Fax: 972-733-6791

PortlandPhone:503-699-0500Fax: 503-699-8400

MinneapolisPhone:952-924-9779Fax: 952-249-9143

PhoenixPhone:602-225-2400Fax: 602-225-2425

DenverPhone:303-756-5242Fax: 303-756-8301

Los AngelesPhone:562-552-9980Fax: 562-552-9981

Northern CaliforniaPhone:925-225-1550Fax: 925-225-1440

TampaPhone:813-998-9886Fax: 813-998-9887

NashvillePhone:615-986-0113Fax: 615-986-0114

MichiganPhone:734-591-9922Fax: 734-591-1722