Number theory for INT32, REAL32
Some devices offer the possibility to transmit the data value as floating-point number ("Float"/ REAL).
Advantages:
- the data value can be read directly during commissioning
- no scaling to 0x7FFF or similar necessary in the PLC
- values (especially less than 1) can be represented with decimals, e.g. for weighing applications
Disadvantages:
- Practical: with 16-bit analog values larger data width, process image and thus EtherCAT load increases by a factor of 2 (INT16 → REAL32)
With 24-bit analog values no effect (INT32 → REAL32) - Theoretical: representation errors occur
On the subject of “representation errors”, a few remarks:
- The structure of the 32-bit data type REAL according to IEC 61131 3 / IEC 559 / IEEE754 is 1 bit sign, 8-bit exponent to base 2 with sign (-126...+127), 23-bit mantissa (0...8,388,607). The theoretical range of values is thus decimal approx. ±3.402823... ⋅ 10+38.
- There are two special effects when converting Integer → Float that have to be considered, no matter if the conversion is done in the analog device or in the PLC on the control side:
- The distance between two consecutive numbers that can be represented as REAL32 varies: as soon as the steps at a decimal place become larger than 1, these decimal places are no longer suitable for a linear (complete) representation of a number space.
- there is a loss of information due to the forced transition from decimal to binary number space (and back). If a decimal number no longer corresponds to the float representation from one decimal place, these decimal places are also no longer usable from here and downwards.
In the following some number examples are listed (incl. thousand separator, analog technically usable part highlighted): - Vendor/product specific it has to be considered with which step size data values have to be displayed at all: if a selection range of 10 V is resolved to 23 bits + sign, the step size is 10 V / 8,388,608 = 1.192... µV, in the Beckhoff extendedRange 10 V / 7,812,500 = 1.28 µV. It is therefore sufficient in the following to carry out the considerations with this fineness.
- For exemplary orientation the difference between a REAL32 (assumed to be information lossy) and a REAL64 (assumed to be ideally correct) in the common selection range 10 V of a Beckhoff ELM3xxx is simulated here, if both are calculated from the 24-bit ADC integer value (0...7,812,500, i.e. 1 digit = 1.28 µV):
- It is noteworthy that the representation error (falsification of the data value at REAL64 → REAL32) increases with the data value. For example, let's look at the data value 9.0 V (INT32 from ADC: 7,031,250). The simulation here shows a representation error of about 5.2 ⋅ 10-7 V = 0.52 µV = 0.052 ppmFSV=10V. We must check this value against
- the digital resolution: 7,812,500 = 10 V,
1 digit = 1.28 µV → the representation error is 2x smaller and not relevant - a usual ELM3xxx basic accuracy of 100 ppmFSV=10 V = 1000 µV → the representation error is absolutely negligible
- The microscopic view into the error curve is interesting, e.g. around the point 6.0 V, plotted in the step size 1.28 µV (24-bit ADC resolution):
6.0 V can be represented error-free in REAL32; in the vicinity of the value superimposed oscillations can be seen. - Since the representation error grows with the selection range, it is recommended to look at an FSV = 1000 V:
With 3.2 ⋅ 10-5 V = 35 µV it becomes quite large, but remains at 0.035 ppmFSV=1000 V and thus is not an obstacle for REAL32 transport. - Summary: in practice, a REAL32 number can therefore represent a given numerical value to approx. 7...8 decimal places ("worst case" i.e. 10-7 = 0.1 ppm). By "decimal place" is meant here a digit of value (pre and post decimal point) without leading zero.
For size comparison: ppm = 10-6 (among others used in the measurement uncertainty specification, e.g. 100 ppm) or 1/7,812,500 = 128 ⋅ 10-9 = 0.128 ppm (used as bit resolution in the Beckhoff 24-bit-extendedRange).
This means that REAL32 numbers can be used without hesitation for transporting 16-bit resolved numbers. When transporting 24-bit analog values they approach the resolution limit but can still be used. For highest demands it is recommended to transfer integer PDO via EtherCAT and to convert it in the controller. - The wish for a wide use of REAL64 (LREAL, Double Precision) in "simple" analog devices must be rejected at present (2024); the floating-point calculations require appropriate capabilities on the µC side, these are partially given for REAL32, but not yet to a large extent for REAL64. REAL64 calculations are preferably to be performed in the PLC.
- For further considerations on this, the study of IEEE-754 and practical testing with online computers (e.g. "IEEE-754 Floating Point Converter") or own simulations are recommended.
Implications when using floating-point arithmetic in the PLC The inevitable phenomena of rounding and representation errors described above can have significant and surprising result-warping effects in comprehensive floating-point calculations in control, especially when very large (e.g., > 106) and very small numbers (e.g., < 10-6) coincide. To minimize (but not eliminate!) these, LREAL calculations should preferably be performed on the control side. |