Scaling of INT values into REAL

Hello everyone!
I am still a beginner is B&R AS. I am currently working on a task of using a Displacement measurement sensor and Analog Input (AI4622). The sensor outputs in the form of voltage change (0~10V) or current change (4mA~20mA) in INT equivalent (for e.g. 10V corresponds to INT: 32767. My query is that I want to scale INT values from displacement measurement sensor into REAL values. Can someone please guide to achieve carry out this scaling?

Hi,

mathematically spoken this can be done by a rule of three calculation.

For example for voltage:
ValueReal = ValueInt * 10.0V / 32767

When programming it, don’t forget to cast the integer values before divison, because dividing an lower integer value by a higher one will always will always lead to zero (because they’re integers without fraction numbers :wink:).

So staying with the voltage example, you could calculate it for example like:

myRealValue := INT_TO_REAL(myIntValue) / 3276.7;

Best regards!

That was quite a help. Thanks Alex!

1 Like