IMDHMIControls LibraryShop main store

Troubleshooting

Why a Modbus 32-bit float reads wrong after a CPW copy

Industrial networks Published 5 min read By IMDHMI controls team

Short answer

A wrong float after a CPW copy means the two 16-bit Modbus words sit in the wrong order, not that communications failed. Capture the raw pair at two different meter readings, swap the words in integer storage, copy the ordered pair into the float destination, and confirm the value tracks the meter. Test byte order only as a separate last step.

On this page
  1. What a CPW copy does and does not do
  2. Rule out the communication path first
  3. Capture the raw words at two different readings
  4. Worked example: 1234.5 kWh through both word orders
  5. The ladder: swap, then copy into the float
  6. Verify the fix without a false match
  7. When the word swap is not the whole fault
  8. Questions asked

A wrong value after a CPW copy is a word-order mismatch, not a communications fault. A 32-bit float arrives as two 16-bit Modbus registers, and the PLC has put the first received word into the opposite half of its float storage from where the meter encoded it. The fix is to swap the two words in integer storage and then copy the ordered pair into the float destination. Capture the raw pair at two different meter readings before and after, and treat byte order as a separate test only if the word swap fails.

What a CPW copy does and does not do #

CPW moves bit patterns between storage untouched. It does not scale, convert, or reinterpret anything; the interpretation changes only when the bits land in floating-point storage. A 32-bit IEEE 754 value spans two consecutive 16-bit Modbus registers, and Modbus itself transports registers without declaring which word of a multi-register value comes first. Devices differ: one vendor's documentation describes low-word-first transport and another describes high-word-first, so the meter's register map and a raw capture decide, never a habit from the last integration. When the first received word lands in the wrong half, the bit pattern stays intact and stays stable, but it decodes to a completely different number. The same two-register ordering problem shows up on other controllers, for example the even-first-word requirement when a BRX PLC reads a Modbus Float32.

Rule out the communication path first #

Work down the chain and find the first boundary where the value goes wrong. Change nothing in the ladder until this list is clean:

  • Link — the request gets a response and no communication error is active. No response points at cabling, addressing, or request configuration, not float conversion.
  • Register — the request targets the meter's documented accumulated-energy register (register 2700 in this setup) with its documented data type, a 32-bit float spanning two registers.
  • Raw words — both received integers are captured and are stable from read to read.
  • Float destination — the interpreted value is compared against the meter display or another independent reading.

Stable raw words with an implausible float is the signature of a layout mismatch. Unstable words would point back at the link instead.

Capture the raw words at two different readings #

One capture is not enough, because some bit patterns decode to a plausible-looking number even with the words reversed. Run this before touching anything:

  1. Record the meter display value, both raw integers, and the PLC's interpreted float at the same moment.
  2. Wait until the displayed accumulated energy has changed measurably.
  3. Record all three again.
  4. Check that the raw words changed in step with the display. If they did, the request and the link are healthy and the problem is ordering.

Keep the raw pair in its own integer locations throughout, so every later test compares against the same untouched data.

Worked example: 1234.5 kWh through both word orders #

Suppose the meter displays 1234.5 kWh at the first capture. The IEEE 754 bit pattern for that value works out as follows: 1234.5 in binary is 10011010010.1, which normalizes to 1.00110100101 × 2^10, so the exponent field is 10 + 127 = 137 and the stored pattern is 0x449A5000. Split into the two registers the meter sends:

Register Hex Decimal
First word received 0x449A 17562
Second word received 0x5000 20480

Check the arithmetic: 0x449A = 4 × 4096 + 4 × 256 + 9 × 16 + 10 = 16384 + 1024 + 144 + 10 = 17562, and 0x5000 = 5 × 4096 = 20480.

If the PLC copies the pair in the reversed order, it builds the pattern 0x5000449A. Decoding that: sign bit 0, exponent bits 10100000 = 160, so 160 − 127 = 33, and the mantissa works out to about 1.0084. The value becomes roughly 1.0084 × 2^33 ≈ 8.66 × 10^9 — billions where the display shows thousands. That absurd magnitude, reproduced on a stable word pair, is the confirmation that this is word order and nothing else.

The ladder: swap, then copy into the float #

Use a second integer pair as the staging area so the raw words stay untouched for comparison. The addresses below are illustrative; use locations free in your own data files:

  1. The Modbus read deposits the response into two consecutive integers, for example N7:10 and N7:11.
  2. Swap through a staging pair: MOV N7:11 into N7:20 first, then MOV N7:10 into N7:21. Never overwrite the first word before its partner is preserved, or you lose the original pair.
  3. Copy the ordered pair N7:20–N7:21 into the float destination, for example F8:0, with the project's copy instruction.
  4. Use F8:0 as the accumulated-energy value only after the two-reading comparison below passes.

Write the comment on the rung explicitly: this logic reorders the words of the float; it does not scale or numerically convert an integer measurement. Keeping that distinction in the comments prevents the next person from adding a multiply on top.

Verify the fix without a false match #

Repeat the two-reading capture with the swap in place. The PLC float must equal the display at the first capture and still equal it after the displayed energy has moved — the same measurement point and the same units on both sides. Two matches that track the meter confirm the ordering. One match followed by divergence means recapture the raw pair and retest; do not tune around it.

One safety note: if this value feeds anything beyond logging — a demand limit, a shutdown decision, a protective interlock — treat the float as bad data until the two-reading check passes on both captures.

When the word swap is not the whole fault #

If the swapped pair still decodes wrong, work in this order:

  1. Recheck the register address against the meter's register map and confirm the documented data type is a 32-bit float, not an integer or a scaled value.
  2. Confirm the addressing convention — how the map's numbering maps to the offset in the request — because a response proves only that the device answered.
  3. Only then test byte order within each word, as a separate step with the same two-reading comparison. Do not combine byte and word swaps without evidence from the raw words, because each reordering changes the decoded value again.

The same discipline generalizes beyond meters: wherever a device expects a 32-bit value assembled from two words, the words must arrive in the order that device documents, as with the ordered 32-bit assembly that SINAMICS speed words require.

Questions asked

Does a CPW copy convert an integer measurement into a float?

No. A copy instruction moves bit patterns between storage untouched. The two words stay exactly as the meter sent them; only the way the PLC interprets the 32-bit pattern changes when the words land in floating-point storage. That is why a scaling or conversion routine cannot fix a word-order problem, and why the ladder comment should say the rung reorders words rather than converts a value.

How do I know whether this device sends the low word or the high word first?

There is no universal convention. Some vendors document low-word-first transport for 32-bit values and others document high-word-first, and a device can differ from either default. Capture both raw words while the display shows a known value, decode the pair in both orders, and let the capture decide for your device. The register map tells you the format; the capture tells you the order on the wire.

Why does the value match once and then drift later?

A single capture can mislead because some 32-bit patterns decode to a plausible-looking number even with the words reversed. Confirm the fix by comparing the PLC float against the display at two different readings. If both match and track as the measured quantity changes, the ordering is right. If only the first reading matches, recapture the raw pair and retest both orders.

Does register 2700 mean I request offset 2700 in the message?

Not necessarily. Many register maps number their registers differently from the offset the protocol puts in the request, and the two can differ by one or by a fixed base. A successful response proves only that the device answered, not that you addressed the intended register. Check how the meter's documentation defines its numbering, then confirm with a capture that the returned words change when the displayed accumulated energy changes.

When should I try a byte swap instead of a word swap?

Only after the word swap fails and you have rechecked the register address and its documented data type. Byte order within each word is a separate, less common mismatch. Test it on its own with the same two-reading comparison, and do not stack a byte swap on top of a word swap without evidence from the raw words, because each additional reordering changes the decoded value again.

Keep reading

  • Troubleshooting

    Scaling Modbus floating point values to 4-20 mA outputs

    Read each gas concentration as a 32-bit float with Modbus function code 3, scale it linearly between its engineering limits onto the analog output module's documented count endpoints, clamp, convert to a 16-bit INT and write it to the channel. Put the controller and analyzer on one subnet, verify the float's word order against the register map, and drive all three outputs to an agreed fault level when the link fails.

    Industrial networks

  • Explainer

    Concept 2.6 XXMIT limits for polling many Modbus RTU slaves

    For read-only Modbus RTU polling in Concept 2.6 on a 140CPU11302, use XXMIT: one read occupies the processor for at least five PLC scans, so 36 slaves need a poll cycle of at least 180 scan times before any slave response time is added, and a 36-device RS-485 segment exceeds the 32-unit-load electrical limit unless your devices are documented as fractional loads. Declare MsgOut with the type your installed block accepts.

    Industrial networks

  • How-to

    Connect an S7-200 to a Modbus RTU sensor and read its register

    Confirm the exact S7-200 CPU and Micro/WIN library first, then call MBUS_CTRL once on every scan to initialize the Modbus RTU master and MBUS_MSG to read the sensor's holding register with matching serial settings (example: 9600 baud, even parity). Decode the returned 16-bit word with the sensor's documented scale, and use a gateway if the library is unavailable.

    Industrial networks

Quantum RIO drop trips from a mixed CRA software version