Anda di halaman 1dari 3

18912 - Converting Floating Point or REAL Datatypes into Integers

Access Level: TechConnect Date Created: 09/20/2000 10:09 AM Last Updated: 02/18/2013 11:14 PM

How do I convert floating-point or REAL datatypes into integers and then back again with PLC5, SLC, ControlLogix, FlexLogix and CompactLogix?

I. Subject
IEEE single precision floating point specification for the PLC5, SLC, ControlLogix, FlexLogix, and CompactLogix platforms and the important differences when manipulating this data type. (F8:0 and REAL datatypes).

II. Discussion of Format


The 32-bit (single precision) IEEE floating-point representation is laid out as: s eeeeeeee fffffff ffffffffffffffff in the IEEE 754 standard. There are Ne = 8 bits in the exponent field and Nf = 23 bits for the fractional part of the mantissa. Ns is the sign bit. We store bias+p in the exponent field; the bias is 01111111 binary) = 7F (hex) = 127 (decimal). To allow for the representation of special values (0,Inf, NaN) two-bit patterns are reserved thus limiting the range of the exponent to [-126 to +127]. Since the mantissa has a total of 24-bits (when you count the hidden bit) and is rounded, the magnitude of the relative error in a number is bounded by 2^{-24} = 5.96... x 10^{-8}. This means we get a bit more than 7-decimal digit precision. (The largest possible mantissa is M = 2^{24} = 16777216, which has 7+ digits of precision.) The largest positive number that can be stored is: 1.11111111111111111111111 (binary) x 2^{127} = 3.402823... x 10^{38}. Notice that 1.11111111111111111111111 (binary) = 2 - 2^{-23}. Also note that log_{10}(largest) = 38.531839... The smallest positive number is: 1.00000000000000000000000 (binary) x 2^{-126} = 1.175494... x 10^{-38}. Note that log_{10}(smallest) = -37.929779...

III. RAW Data in a PLC5 or SLC


If we take a floating point address, such as F8:0, and use the following rung:

The PLC5 or SLC will take the 32-bits and place the raw bit pattern into two consecutive integers. In the above rung, the data arrives in N9:0 and N9:1. N9:0 contains the sign bit. Note: The first word has the sign bit. Conversely, if we use the following rung:

The PLC5 or SLC will reassemble the raw bit pattern back into a floating point element for use. The PLC5 and SLC both perform this function in the same manner. For example, you can convert to integers, send these integers to the SLC, then convert them back in the SLC and get the correct starting value. This is NOT true when sending this data to devices based on the ControlLogix platform.

IV. Differences When Using ControlLogix, FlexLogix or CompactLogix


The processor used in these Logix platforms organizes the memory different than a PLC5 or SLC does. Specifically, the high word and low word are swapped. If one were to convert to integers in a PLC5 or SLC, and then send these integers to a ControlLogix based product, this person would be required to change the order of these two words before executing the

COP command. (If you stay with ControlLogix,

then everything is swapped and no extra action is required). Note: The second word has the sign bit.

V. Possible Issues
Based on item IV above, one can run into problems when exchanging the Raw data between a PLC5-SLC system, and the ControlLogix-based products. For normal operations, just exchange floating point data and REAL data directly and do not convert into the Raw data first. The problem may arise for those products that only provide this Raw data back to the processor. This includes, but is not limited to some motion products, PowerMonitors, and all Remote I/O PanelViews sending float data. The PowerMonitors provide Raw data formatted for PLC-SLCs.

VI. Solutions
When using a device such as a PowerMonitor in a ControlLogix, FlexLogix or CompactLogix system, it is necessary to swap the two integers for each parameter before executing the the data back into a REAL data type.

COP command to convert

Anda mungkin juga menyukai