beautypg.com

5 programming examples, Calculating analog data values from digital data, Kv -300 – KEYENCE Visual KV Series User Manual

Page 383

background image

9.5 Programming Examples

KV-10/80 Series Only

KV

-300

KV-10/80

Chapter 9 KV-AD4/DA4 Analog I/O Unit

1-359

1

9

9.5

Programming Examples

This section describes sample programs for the KV-AD4/DA4. Refer to this section
when making programs for the KV-AD4/DA4.

Calculating Analog Data Values from Digital Data

This sample program reads A/D-converted digital data from memory, and calculates
the value of the actual analog-input voltage.

Conditions

The analog input data from analog input V0 on the KV-AD4 is calculated.
(The digital data of data memory DM0992 is used for this operation.)

When the calculated value is a positive value, an absolute value is written to
memory DM0100, and when the calculated value is a negative value, an absolute
value is written to memory DM0101. Data is written in mV units.
For example:

When the input is +10 V, "10000" (data x 1000) will be written to DM0100.

When the input is - 10 V, "10000" (data x 1000) will be written to DM0101.

Ladder diagram

1. The data of DM0992 is calculated, and the calculation result (data x 5 mV -

10000) is written to DM0000.

2. The KV-AD4 judges that the DM0000 data is positive or negative by comparing

DM0000 with $8000. (When the MSB of DM0000 is OFF, the data is judged to
be positive, and when it is ON, the data is judged to be negative.)

3. If the data is a positive value, the calculation result is written to DM0100.
4. If the data is a negative value, the 2’s complement of the data is calculated to

change its sign to a positive sign, and the result is written to DM0101.

Note: "2007" (first scan OFF at power ON) must be set as the input condition. In
the case of analog input, an unsteady value will be input for the first scan when the
power is turned ON.

DM0000

LDA

2007

2009

2009

DM0000

LDA

DM0992

LDA

$8000

CMP

#00005

MUL

DM0000

STA

DM0000

LDA

COM

DM0100

STA

DM0101

STA

#00001

ADD

#10000

SUB

1

2

3

4

KVHKA Chap 09.p65

08.3.11, 11:20 AM

359