Table of Contents

Analog to Discrete Value Conversion

Full Name

Lib.Mervis.v1_0.AnalogToDiscrete

Required Project References

Description

A block used for converting continuous values (e.g., voltage or resistance) that encode binary values based on their magnitude.

Usage in ST

program test
    var
        a2d: lib.mervis.v1_0.AnalogToDiscrete;
    end_var

    a2d(Value := ..., Weights := [1, 2, 4, 8, 0, 0, 0, 0], Output0 => D0, Output1 => D1);
end_program

Inputs

Name Data Type Allowed Range Retain Mandatory Connection Meaning
Value real No Yes Input analog value
Weights array[0..7] of real Each element greater than or equal to zero No No Weights of individual inputs. Must be sorted in ascending order, zero at any position ends the calculation.
Tolerance real 0..100 % No No Tolerance for comparing the weights of individual inputs

Outputs

Name Data TypeMeaning
Output0..Output7 bool Values of individual bits (0 - lowest weight = LSB, 7 - highest weight = MSB)
CombinedOutput usint Outputs Output0..Output7 combined into one 8-bit number

Detailed Function Description

The block is used to convert a continuous variable (e.g., voltage or resistance) that encodes binary values based on its magnitude. Its main use is for utilizing analog inputs to expand the number of digital inputs or to save wiring between the sensor and the controller.

Usage Examples:

The first input has a weight of 5 V, the second 2.5 V, and so on, the last has a weight of 0.15625 V. The resulting voltage is the sum of these weights. To convert back to the states of the digital inputs, this function block can be used by filling in the weights from the smallest: Weights = [0.15625, 0.3125, 0.625, 1.25, 2.5, 5, 0, 0].

For example, choosing values of 120 Ohms, 240 Ohms, 390 Ohms, and 820 Ohms allows us to distinguish 16 different resistance values and thus 4 switching contacts.