Merging Two DWORD Energy Registers into REAL and LREAL Values in SIMATIC PCS 7
In SIMATIC PCS 7 systems reading electrical energy totalizers from Sentron PAC power meters (such as PAC3200 via the PAC32DRV block), energy values are transmitted across two 32-bit double words (High DWORD and Low DWORD) representing a 64-bit integer. Converting these registers into a standard 32-bit REAL value in CFC introduces precision truncation once energy exceeds 16,777,216 counts; engineers resolve this by calculating scaled energy in custom SCL blocks or partitioning values into MWh and fractional kWh.
Table of Contents
- Data Structure of Energy Registers in Sentron PAC Meters
- The 32-Bit Floating-Point Precision Trap in S7-400 Controllers
- Method 1: Direct 64-Bit Integer Math and REAL Conversion in SCL
- Method 2: Dual-Variable Partitioning (MWh Integer and kWh Fraction)
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Data Structure of Energy Registers in Sentron PAC Meters
Multifunction power meters (such as the Siemens Sentron PAC3200 and PAC4200) communicate electrical telemetry via PROFIBUS DP or PROFINET using the PAC32DRV driver block:
* Instantaneous values (voltage, current, power factor) are transmitted as standard 32-bit IEEE 754 floating-point values (REAL).
* Total active energy ($E_{ ext{act}}$) and reactive energy ($E_{ ext{react}}$) continuously accumulate over years of operation. To prevent rollover, the meter stores energy as a 64-bit unsigned integer (measuring in Watt-hours or tenths of a Watt-hour).
* The driver block delivers this value as two separate 32-bit words:
* DWORD_HIGH (High Word): Most Significant 32 bits ($2^{32} ext{ multiplier}$).
* DWORD_LOW (Low Word): Least Significant 32 bits ($0 ext{ to } 4,294,967,295$).
The 32-Bit Floating-Point Precision Trap in S7-400 Controllers
In classical S7-300, S7-400, and WinCC environments, floating-point math standardizes on 32-bit REAL (IEEE 754 single precision):
* A 32-bit REAL allocates 1 sign bit, 8 exponent bits, and 23 mantissa bits (yielding approximately 7 decimal digits of precision, or integer values up to $2^{24} = 16,777,216$).
* If you merge two DWORDs into a 64-bit number and convert directly to a 32-bit REAL:
* As soon as cumulative energy exceeds $16,777,216 ext{ Wh}$ ($16.7 ext{ MWh}$), the least significant bits cannot be represented in the 23-bit mantissa.
* Adding smaller increments (e.g., $10 ext{ Wh}$) to a large REAL value results in mathematical truncation ($16,777,216 + 10 = 16,777,216$).
* The totalizer permanently "freezes" in the controller logic, even though the physical meter continues accumulating energy.
Method 1: Direct 64-Bit Integer Math and REAL Conversion in SCL
To merge the two DWORDs in an SCL block without overflow:
FUNCTION_BLOCK FB_PAC_MergeEnergy
VAR_INPUT
dwHigh : DWORD; // High 32 bits from PAC32DRV
dwLow : DWORD; // Low 32 bits from PAC32DRV
END_VAR
VAR_OUTPUT
rEnergy_MWh : REAL; // Energy scaled in Megawatt-hours
rEnergy_kWh : REAL; // Energy scaled in Kilowatt-hours
END_VAR
VAR_TEMP
rHighPart : REAL;
rLowPart : REAL;
END_VAR
// Convert High DWORD: each count represents 2^32 = 4,294,967,296 Wh
// 2^32 Wh = 4,294,967.296 kWh = 4,294.967296 MWh
rHighPart := DWORD_TO_REAL(dwHigh) * 4294.967296;
// Convert Low DWORD: direct Wh to MWh (divide by 1,000,000)
rLowPart := DWORD_TO_REAL(dwLow) / 1000000.0;
// Combine into MWh to preserve precision across plant lifetime
rEnergy_MWh := rHighPart + rLowPart;
rEnergy_kWh := rEnergy_MWh * 1000.0;
END_FUNCTION_BLOCK
By scaling the high and low components directly into Megawatt-hours ($ ext{MWh}$) before summing, the values remain well within the 7-digit precision range of standard REAL variables.
Method 2: Dual-Variable Partitioning (MWh Integer and kWh Fraction)
For absolute zero-loss precision on WinCC faceplates and accounting reports:
1. Maintain two separate process variables:
* Energy_MWh (DINT): Whole integer Megawatt-hours.
* Energy_Remainder_kWh (REAL): Remaining energy within the current MWh ($0.0 ext{ to } 999.9 ext{ kWh}$).
2. The SCL block calculates total Watt-hours using modular arithmetic, passing the whole MWh as an integer to WinCC and the fractional remainder as a float.
3. In the WinCC Graphics Designer faceplate, display the combined reading as:
$$ ext{Display} = ext{Energy_MWh} imes 1000 + ext{Energy_Remainder_kWh}$$
This preserves 100% mathematical accuracy across billions of kilowatt-hours without floating-point truncation.
Verification
- In CFC dynamic test mode, force test values into the inputs:
- Set
dwHigh = 16#00000000anddwLow = 16#000F4240($1,000,000 ext{ Wh} = 1.0 ext{ MWh}$). - Verify that
rEnergy_MWhoutputs exactly1.0. - Test high-range accumulation:
- Set
dwHigh = 16#00000001anddwLow = 16#00000000($4,294,967,296 ext{ Wh}$). - Verify that
rEnergy_MWhoutputs4294.967. - In WinCC OS runtime, verify that the energy readout advances steadily and matches the Sentron PAC3200 front-panel LCD display.
Limitations and Operational Precautions
- Standard S7-300 and S7-400 CPUs do not natively support 64-bit IEEE 754 double-precision floats (
LREAL) in CFC math blocks;LREALis native to S7-1500 and CPU 410 (firmware V8.2+). - Never use standard addition blocks (
Add04) in CFC to add small energy pulses to a largeREALaccumulator; always use dedicated totalizer blocks (TotalLfrom APL). - Ensure meter scaling (Watt-hours vs. Kilowatt-hours vs. Megawatt-hours) matches the pulse resolution setting configured in the Sentron PAC hardware menu.
Engineer FAQ
- Why does the PAC32DRV block output two DWORDs for energy?
Because cumulative energy over years exceeds the 32-bit integer limit ($4.29 imes 10^9$), requiring a 64-bit counter split into high and low words. - Why does a 32-bit REAL variable freeze when energy reaches 16.7 MWh?
A 32-bit float has only 23 mantissa bits (maximum integer precision 16,777,216); adding small numbers to values above this limit results in truncation. - Can I use the SCL block in SIMATIC PCS 7 V8.0 SP2?
Yes, SCL is a standard component of STEP 7 / PCS 7 V8.0 and compiles directly into executable function blocks (FBs). - Does the APL library provide a standard block for totalizing energy?
Yes, theTotalLblock (FB1886) in the APL provides high-accuracy trapezoidal and pulse totalization with internal double-precision buffers. - What is the multiplier for the high DWORD when measuring in Watt-hours?
Each count in the high DWORD represents $2^{32} = 4,294,967,296 ext{ Watt-hours}$ (or approximately $4,294.967 ext{ MWh}$). - Can WinCC display 64-bit integers directly?
Yes, WinCC Tag Management supports 64-bit unsigned integer tags (Unsigned 64-bit value). - Does CPU 410-5H support 64-bit floating point (LREAL)?
Yes, CPU 410-5H with firmware V8.2 or higher supports native 64-bitLREALinstructions in SCL. - How do I prevent integer overflow when converting DWORD to DINT?
In S7,DWORDis bit-pattern oriented; ensure the value does not exceed $2,147,483,647$ when treating it as a signedDINT, or handle it as an unsigned real. - What happens if the Sentron PAC meter is replaced?
The new meter begins counting from zero; totalizer offset logic in the AS can add the historical baseline to maintain plant continuity. - Can I log the 64-bit energy reading into Process Historian?
Yes, archive the scaledMWhreal tag or 64-bit integer tag in WinCC Tag Logging, which exports seamlessly to Process Historian.
Technical References
- Siemens Sentron PAC3200 Multifunction Meter Manual
- SIMATIC PCS 7 Advanced Process Library (APL) Function Manual (TotalL / FB1886)
- Siemens Industry Online Support Entry: Converting Sentron PAC 64-bit Energy (Entry ID 298998)
- SIMATIC S7-SCL V5.6 for S7-300/400 Programming Manual
Related Articles
- Extracting Substring Characters and Linking Dynamic Text Signals Between WinCC OS and AS
- Integrating Socomec DIRIS A30 Power Meters into SIMATIC PCS 7 via PROFIBUS DP
Related Tags
PCS 7, Sentron, PAC3200, PAC32DRV, DWORD, Energy Totalizer, SCL, Float Precision, REAL, LREAL