Analog to Discrete Value Conversion

Lib.Mervis.v1_0.AnalogToDiscrete

  • Lib.Mervis

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

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

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:

  • A module with 6 digital inputs that converts to 0-10 V voltage.

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

  • Another possibility is transmitting multiple digital contacts over just two wires using appropriately chosen resistor values for the given contacts.

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.

  • © Energocentrum Plus, s.r.o. 2017 - 2024