You are on page 1of 2

Top

Contact Us

Back

VOL. 22

High-speed interrupt input function

Example

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

Outline
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 with
the internal clock of the high-speed counter in the unit of s.
Sensor 1
INPUT 0002

ON
OFF

Sensor 1
Sensor 2
INPUT 0003

Visual KV Series

ON
OFF

Sensor 2
Passing time (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 KVs internal clock (1-s cycle) and the high-speed counter to measure the passing time.
Passing
time
Sensor 1

Sensor 2

Internal clock
(1 s)

No. of clock
counts

(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 data
memory (Input capture function).
By using this function, the passing time is obtained as the difference between the stored counter values of
sensor 1 and sensor 2.
Passing
time
Sensor 1
(Interrupt 0002)
Sensor 2
(Interrupt 0003)

No. of pulses = yyyyy

No. of pulses = xxxxx

Internal clock
(1 s)
DM1932

No. of clock
counts

(Value stored by the input capture of 0002)

DM1934

(Value stored by the input capture of 0003)

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

Top

Back

Contact Us

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
EI

2410
RES

2411
RES

2412
RES

2002

2413
RES
HSP
0002
HSP
0003

2002

CTH1
2200

When power is turned on, an EL instruction enables


interrupts. Sets the interrupt polarity of inputs 0002 and
0003 to the rising edge.
Sets the input time constant of inputs 0002 and 0003 to
10 s.

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

END
INT
0002
RETI
INT
0003
DM1934
LDA

DM1932
SUB

DM0000
STA

#00001
LDA

#01000
MUL

DM0000
DIV

DM0010
STA

(1)

(2)

2002

RETI

When INT0002 is executed, the current value of CTH1 is


automatically transferred to DM1932 and DM1933 (Input
capture).
When INT0003 is executed, the current value of CTH1 is
automatically transferred to DM1934 and DM1935 (Input
capture).
Subtracts the input capture value of INT0002 from that
of INT0003 to obtain the time it takes for the target to
pass between two points and then writes it to DM0000.
(Unit: 1s)
The passing speed is obtained through calculating (2)
the passing time and (1) the distance between the two
points (unit: m/ms). It is stored in DM0010.

ENDH

Tips

Calculation of passing speed


The 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 measured value is multiplied by the factor of 1000 (2) to be converted into the value in the unit of
ms. 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 as
the underlined section in the following program. The unit of speed is set to cm/ms.
#00100
LDA

#00100
MUL

#01000 DM0000 DM0010


MUL
DIV
STA

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

You might also like