Converting REAL Floating-Point Values to WORD or DWORD in SIMATIC PCS 7 CFC
To convert a 32-bit floating-point REAL value (such as the output of mathematical block DIV_R) to a WORD or DWORD in SIMATIC PCS 7 CFC, engineers must select the appropriate conversion block depending on whether they require bit-pattern preservation or numerical rounding. For bit-level preservation (e.g. packing IEEE 754 float registers for Modbus RTU/TCP telemetry), use the R_DW block from the standard library (CFC Library -> ELEMENTA -> CONVERT -> R_DW) and split into words via DW_W. For numerical integer conversion (e.g. converting 123.45 to integer 123), use ROUND or TRUNC to convert REAL to DINT, followed by DI_I to obtain a 16-bit integer/word.
Table of Contents
- Data Representation: IEEE 754 Floating-Point vs Integer Bitstrings
- Bit-Pattern Preservation vs Numerical Rounding in PCS 7
- CFC Elementary Conversion Blocks Reference Matrix
- Step-by-Step Procedure to Implement REAL to WORD Conversion in CFC
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Data Representation: IEEE 754 Floating-Point vs Integer Bitstrings
In SIMATIC PCS 7 controllers (S7-400 and CPU 410-5H), data types have distinct binary memory structures:
- REAL (32-bit IEEE 754 Floating-Point): Composed of 1 sign bit, an 8-bit exponent, and a 23-bit mantissa. The mathematical output of blocks like
DIV_R(floating-point division) is always formatted as a REAL number. - DWORD (32-bit Bitstring): An untyped sequence of 32 bits, often treated as hexadecimal or raw register data.
- WORD (16-bit Bitstring): An untyped sequence of 16 bits.
- INT / DINT (16-bit / 32-bit Signed Integers): Two's complement integer numbers.
Engineers frequently need to convert REAL values into WORD or DWORD structures when transmitting process variables across fieldbus protocols (such as Modbus RTU, Modbus TCP, PROFIBUS DP, or OPC) where destination registers are restricted to 16-bit word boundaries.
Bit-Pattern Preservation vs Numerical Rounding in PCS 7
A critical engineering distinction must be made between two conversion objectives:
-
Case A: Bit-Pattern Transmission (Transmitting IEEE 754 over Modbus):
- The engineer wants to transmit the exact floating-point value (e.g.25.75) across two 16-bit Modbus registers.
- The 32 bits of the IEEE 754 representation must not be rounded or modified; they must be cast directly into a 32-bit DWORD via blockR_DW, and then divided into a High Word and Low Word using blockDW_W.
- The receiver reconstructs the exact REAL float by combining the two words. -
Case B: Numerical Value Conversion (Integer Truncation/Rounding):
- The engineer wants the numerical quantity itself converted to an integer (e.g.25.75becomes26or25).
- Passing a REAL throughR_DWin this case results in a meaningless hexadecimal bitmask. Instead, the mathematical blocksROUND(mathematical round to nearest integer) orTRUNC(truncate decimal places) must be used to produce a DINT, which is then converted to an INT/WORD.
CFC Elementary Conversion Blocks Reference Matrix
The following table summarizes the standard CFC library conversion blocks available under ELEMENTA -> CONVERT:
R_DWDW_WW1) and Low Word (W0)W_DWDW_RROUNDTRUNCDI_IStep-by-Step Procedure to Implement REAL to WORD Conversion in CFC
Follow this procedure to configure conversion in the CFC Editor:
-
Identify the Conversion Objective:
- Determine whether you need to send an IEEE 754 float across two Modbus registers (Procedure A) or convert a float to an integer word (Procedure B). -
Implementation for Procedure A (Modbus Float Transmission):
- In the CFC catalog, expandLibraries -> CFC Library -> ELEMENTA -> CONVERT.
- Drag blockR_DWinto the chart.
- Connect the outputOutof your math block (e.g.DIV_R) to the inputInofR_DW.
- Drag blockDW_Wfrom the same library folder into the chart.
- Connect the outputOutofR_DWto the inputInofDW_W.
- Connect outputsW1(High Word) andW0(Low Word) to your Modbus send data block. SwapW0andW1if the slave device uses Little-Endian word ordering. -
Implementation for Procedure B (Numerical Integer Word Conversion):
- Drag blockROUNDfromELEMENTA -> CONVERTinto the chart.
- Connect the REAL output ofDIV_RtoInofROUND.
- Drag blockDI_Iinto the chart.
- Connect outputOutofROUNDtoInofDI_I. The output ofDI_Iprovides a 16-bit integer/word reflecting the rounded numerical value. -
Compile and Download:
- SelectChart -> Compile -> Changes only.
- Download changes to the S7-400 controller in RUN mode.
Verification
Verify conversion accuracy in the CFC Editor online view:
1. Open the CFC chart containing the conversion blocks and switch to Online test mode (Test -> Watch on).
2. Apply a test input to DIV_R producing an output of 100.0.
3. For Procedure A (R_DW + DW_W), verify that R_DW outputs 16#42C80000 (hex representation of IEEE 754 100.0). Verify W1 = 16#42C8 and W0 = 16#0000.
4. For Procedure B (ROUND + DI_I), verify that DI_I outputs integer 100 (16#0064).
5. Verify that destination telemetry devices receive and interpret the registers correctly without byte-order corruption.
Limitations and Operational Precautions
- Integer Overflow During DI_I Conversion: If the REAL value converted via
ROUNDorTRUNCexceeds the 16-bit integer limits (-32,768 to +32,767),DI_Iwill saturate or trigger an arithmetic overflow exception. Always clamp values using limits prior to conversion. - Byte Swapping and Endianness in Modbus: Modbus devices differ in their expectation of register order (Big-Endian vs Little-Endian byte and word swap). If the receiving system reads
100.0asNaNor astronomical values, invert the connection order ofW0andW1. - Precision Loss in Rounding: Converting a continuous REAL process value (e.g. pressure of 14.87 bar) to an integer word loses fractional resolution unless scaled prior to rounding (e.g. multiply by 100 before rounding to retain 2 decimal places).
Engineer FAQ
Why does R_DW output a weird number like 16#42C80000 instead of 100?
R_DW does not perform mathematical integer conversion; it preserves the raw 32-bit IEEE 754 binary floating-point pattern. 16#42C80000 is the exact hexadecimal representation of single-precision float 100.0.
How do I split a REAL into two words for Modbus communication?
Connect the REAL to R_DW to obtain a DWORD. Connect the DWORD to DW_W, which outputs W1 (most significant word) and W0 (least significant word). Feed W1 and W0 into the Modbus send buffer.
What block should I use if I want 23.6 to become 24?
Use the ROUND block from CFC Library -> ELEMENTA -> CONVERT. It performs standard mathematical rounding of a REAL value to the nearest DINT integer.
Technical References
- SIMATIC PCS 7 CFC for S7 / S7-HiGraph / PCS 7 Manual (A5E41356136-AB)
- IEEE Standard for Floating-Point Arithmetic (IEEE 754-2008)
- SIMATIC S7-400 Automation System CPU Specifications Reference Manual (A5E00850741-08)
- Siemens Industry Online Support FAQ: Data type conversion in STEP 7 and CFC (Entry ID 22697857)
Related Articles
- PROFIdrive PZD 4-4 Telegram Structure and Word Assignment for Drives in PCS 7
- Integrating Third-Party IO-Link Masters and Transmitters via PROFINET into SIMATIC PCS 7
- Resolving CPU Programming Error 58 on FC2936 After Splitting CFC Runtime Groups
- Developing Custom APL Block Icons and Faceplates Linked to SCL Function Blocks in PCS 7
Related Tags
- CFC Conversion
- R_DW
- DW_W
- IEEE 754 Float
- Modbus Registers
- Data Type Conversion