General > Frequently Asked Questions

Managing IEEE Floating Point Numbers

(1/2) > >>

support:
Although the Nano-10, FMD and F-series as well as the older T100M+ PLCs do not directly support floating point computation, there may be situation when it become necessary to deal with numbers that it obtains that is formatted as a floating point number.  For example the PLC could interface to a Modbus power meter that only presents data in floating point format via Modbus registers. The retrieved floating point data needs to be converted into fixed point integer for computation.

In other occasions, the PLC may need to present its result as a floating point number for other devices that only accepts data in floating point format. This enables the PLC to be programmed as an instrument, a smart sensor gateway, or act as a data concentrator, data translator or protocol converters between incompatible industrial devices.

We have written and tested two TBASIC custom functions to enable translation of floating-point to fixed-point data and vice versa. The .PC6 files containing the two functions can be downloaded from the following link. These two functions are written to be easily copied into your application programs. Please refer to the comments in the functions for details.

http://www.tri-plc.com/trilogi/Float2Integer-RevA.zip

If you wish to check the conversion result of the function, the following website is a good calculator:

http://www.h-schmidt.net/FloatApplet/IEEE754.html

More information about IEEE Single Precision Floating point format can be found at:

http://en.wikipedia.org/wiki/Single-precision_floating-point_format

support:
The Fx1616-BA, Fx2424 and SmartTILE-Fx board now all natively support floating point numbers and it is very easy for these PLCs to read from MODBUS registers that contain numbers in floating point format.

The i-TRiLOGI version 7 supports the commands:

A = FLOAT2BITS (x#)   ' convert floating point number into IEEE 32-bit single precision hex number
X# = BITS2FLOAT(n)   ' convert a 32-bit number in IEEE single precision format into a floating point number.

Hence you can use the standard READMB2 command to read two consecutive Modbus registers and then convert the 32-bit number into internal floating point numbers for computation.

BC SYSTEMS:
Hi,

I'm using a fx PLC and reading data from a power meter in the IEEE format. When I look at the variable A# in the online viewer the value is correct "240.5". If I copy this to the LCD I get "+240.50000" but really all I want is "240.50".

I have copied the data from A# to A, multiplied by 10 then used the MOD function to get " 240.50" but this seems a little long winded and uses up the 32 bit variable.

I was wondering if I could truncate the A# string?   Have tried A# = MID$(A#),2,6) but this fails to compile  :'(

support:
try this:

SETLCD 1,1, STR$(A#, -2)

BC SYSTEMS:
Hello,

Thanks that helped but you still have the signed bit representing a + or - depending on your value.   Can I remove this also without moving the data into the 16/32 bit memory?  Appreciate IEEE is for both positive and negative number representation but the value I'm reading will always be positive.

Cheers

Navigation

[0] Message Index

[#] Next page

Go to full version