IMDTouchKnowledge BaseShop main store

Troubleshooting

Scaling a 32-bit float Modbus value in an HMI script

HMI and touchscreens Published 5 min read

Short answer

The divide returns zero because a w32s script operand is signed 32-bit integer arithmetic: it divides the raw bit pattern, not the float those bits encode. Define the pressure as a float variable with Bit Length 32 mapped to the two-word register pair, and run the division by 100 in the ladder logic program, where floating-point math is supported.

On this page
  1. Why the script returns zero
  2. How the 32-bit value reaches the panel
  3. The fix: float variables and a ladder divide
  4. Worked example: 101325 Pa in both paths
  5. Quick diagnosis
  6. Questions asked

The script is the wrong tool, not the syntax. The expression [w32s:[#INTERNAL]USR00018]=[w32s:[#INTERNAL]USR00016]/100 returns 0 because w32s declares a signed 32-bit integer operand: D-Script divides the raw bit pattern as an integer, never the pressure those bits encode as an IEEE-754 float, and the script engine offers no floating-point arithmetic to repair it with. Define the pressure as a float variable with Bit Length 32 mapped to the two-word internal pair and run the divide by 100 in the ladder logic program, where floating-point math does exist. On the ET6400-WA terminal programmed with GP-Pro EX V04.09.600 where this failed, that combination produced the hectopascals the script could not.

Why the script returns zero #

w32s selects a signed 32-bit word operand. Written against [#INTERNAL]USR00016, it reads that word together with USR00017 as one signed integer. The pair actually holds a 32-bit IEEE-754 floating-point pressure in pascals. Thirty-two bits is a storage width, not a number format: the same bits are a pressure under the float rule and a large integer under the integer rule.

Integer division keeps only the whole-number part of the quotient, so two outcomes are possible and both are wrong. When the interpreted integer is smaller than the divisor, the truncated quotient is 0 — the reported behavior for every divisor above 1. When the interpreted integer is large, the quotient is meaningless, orders of magnitude from the pressure; the worked example below yields 12,041,519 where 1013.25 is correct. The zero adds one clue: the bits the script read interpreted to an integer below 100, so check what the pair really contains. No syntax fixes either outcome. The prefix fixes the arithmetic type, and the decision is to stop doing this math in the script.

How the 32-bit value reaches the panel #

A Modbus register is 16 bits, so the 32-bit pressure occupies two consecutive registers. The editor listing only word addresses is normal and not the fault: the address selects the first word, and a 32-bit operand or display reads that word together with the next. There is no separate double-word address class to hunt for.

Three things about the pair must be verified:

  • Transfer width — the move from the Modbus registers into internal memory must be 32 bits. A 16-bit copy carries half the float and leaves the other word stale or zero.
  • Word order and byte order — match them against the sender's register map; the settings are the ones covered in displaying a PLC real value over Modbus on an HMI.
  • Exclusive use — keep 32-bit internal operands two words apart. The pressure at USR00016 occupies USR00016 and USR00017, and USR00018 with USR00019 is a clean destination. No other object, transfer or script may write either word of either pair.

The fix: float variables and a ladder divide #

GP-Pro EX gives the panel two places to compute: D-Script, whose operands are typed integer words, and the logic program, a ladder environment that supports floating-point arithmetic. The workaround splits the job along that line — bits move in the script, math happens in ladder.

  1. Read the sender's register map and confirm the pair is an IEEE-754 single-precision float in pascals. If it is an integer count with a documented scale, take the integer route described in scaling a PLC integer into an HMI display value instead.
  2. Confirm the 32-bit transfer into the internal pair, with the second word reserved against other writers.
  3. Define two float variables, one for the raw pressure and one for the result. Set Bit Length to 32 in each — a 16-bit setting reads only one word of the pair — and map the raw variable to the internal address.
  4. In D-Script, assign the raw float variable from the internal address. An assignment copies bits and does no arithmetic, so the integer-only engine is no obstacle.
  5. In the logic program, divide the raw float variable by 100 into the result variable, and run the comparison against the second value there as well, in float.
  6. Point the numeric display at the result variable with two decimal places for hectopascals.

If the comparison output acts on the machine — holds an alarm, stops a pump — prove the ladder result against a calibrated pressure at two points before release; a scaling fault can suppress an alarm as readily as raise one.

If you would rather divide in the controller, it must have floating-point instructions of its own; configuring Delta PLC floating-point decimal arithmetic walks through that setup for one controller family.

Worked example: 101325 Pa in both paths #

Take a standard-atmosphere reading of 101325 Pa, transmitted as an IEEE-754 single-precision value with the high word first. The two registers hold 0x47C5 and 0xE680 — the 32-bit pattern 0x47C5E680.

Float path: 101325 ÷ 100 = 1013.25. One hectopascal is 100 pascals, so the display reads 1013.25 hPa.

Script path, same bits: 0x47C5E680 read as a signed integer is 1,204,151,936. Then 1,204,151,936 ÷ 100 = 12,041,519 remainder 36, and truncation keeps 12,041,519.

Path Operation on 0x47C5E680 Displayed value
Float variable, ladder divide 101325.0 ÷ 100 1013.25 hPa
w32s script divide 1,204,151,936 ÷ 100, truncated 12,041,519
w32s on an all-zero pair 0 ÷ 100 0

The reported zero sits in the third row's territory: the integer the script saw was below the divisor, which is worth a transfer check on its own. Rows two and three agree on the decision, though — integer arithmetic on float bits is rejected in every case, and 1013.25 hPa is the number that reaches the operator.

Quick diagnosis #

  • Display correct, script wrong — the display object and the script operand type the same bits independently; move the math to a float divide in ladder.
  • Only word addresses offered — expected; a 32-bit operand spans the addressed word and the one after it.
  • Script returns 0 for any divisor above 1 — the pair's integer interpretation is below the divisor; verify the transfer width and the pair's contents.
  • Value right at one pressure, wrong at another — word order; confirm both words against the sender's map before touching arithmetic.
  • Result changes when another object updates — something writes the second word of a pair; move the next 32-bit operand two words away.

Questions asked

Why does the address list show only word addresses when I need a double word?

An address names the first word, and the operand's bit length decides that the next word is read with it, so there is no separate double-word address class. Keep 32-bit operands two words apart: a value at USR00016 occupies USR00016 and USR00017, and the next free 32-bit slot starts at USR00018. Let nothing else write either word of either pair.

The display shows the pressure correctly, so why does the script disagree?

The display object and the script operand interpret the same bits independently. A display set to present the pair as a floating-point value reads the identical storage that a w32s operand reads as a signed integer. A correct display proves the transfer and the word order only; it says nothing about the arithmetic type the script applied.

When is w32s the right operand to use?

When the storage genuinely holds a signed 32-bit integer, such as a counter total or an offset added to an analog reading. Adding an offset to a fast counter that climbs to 380,000 is a legitimate w32s operation. It turns wrong the moment the bits are an IEEE-754 float, because the prefix fixes the arithmetic, not just the width.

How do I prove the pair holds a float before building the ladder logic?

Apply two known pressures and read both words each time. At 101325 Pa the registers hold 0x47C5 and 0xE680; at half that pressure a float changes in the exponent bits of the high word, while an integer count halves across the whole pattern. Whichever interpretation reproduces the sender's numeric value at both points is the encoding you have.

Do the float variables survive a panel restart?

Only if the variable is marked retentive in its settings; otherwise variables are initialized at startup. The ladder divide refreshes the result on the first scan after the controller data arrives, so retention matters chiefly for values an operator could read before that first exchange completes, or for results kept as a running history.

Keep reading

  • Troubleshooting

    Displaying a PLC Real Value Over Modbus on an HMI

    An INTEGER display that reads the register proves the link, station and address, so a blank REAL display is a 32-bit mapping fault. Declare the HMI variable as a 32-bit float on the register pair (40064/40065), set the device double-word order to Low Word First to match the PLC, and give the numeric field six integer digits for 628402.0.

    HMI and touchscreens

  • How-to

    How to Scale a PLC Integer Into an HMI Display Value

    Divide the raw integer by 100 in an expression on the HMI variable and set the numeric field format to two decimal places: a register value of 4998 then displays as 49.98. The scaling tab rounds because its result stays an integer, which cannot carry a fraction; the expression evaluates the division as a real value before the field renders it.

    HMI and touchscreens

  • Troubleshooting

    Displaying Negative Drive Values and Script Writes in Vijeo Designer

    The reverse readings failed because the Vijeo Designer variables were typed UINT, which cannot show a value below zero; set them to INT and the same drive words display negative. The script write is a separate fault: point the script's write at the setpoint variable the keypad uses, clamp the result to the drive's documented setpoint range, and verify the write on the connected panel, not in the simulator.

    HMI and touchscreens