Resolving Negative Value Display in APL CntOhSc Operating Hours Counter
A negative operating hours display on the PCS 7 Advanced Process Library (APL) block CntOhSc (FB1864) occurs when the block is initialized with an initial days value (OldDay) greater than 1365. In APL V8.0 (AdvLib80 v2.1) and V8.2 (AdvLib82 v4.0), the internal calculation converting days into hours uses signed 16-bit integer multiplication (1366 days * 24 hours = 32,784 hours), which exceeds the maximum positive 16-bit limit (+32,767) and overflows into negative values (-32,752). Resolve the issue by initializing high operating hours directly using the OldHours parameter (bypassing OldDay) or updating to APL V9.0+ where 32-bit DINT arithmetic is enforced.
Table of Contents
- Integer Arithmetic Overflow Mechanism in CntOhSc OldDay Conversion
- Behavior Across APL Versions: AdvLib 8.0, 8.2, and 9.0+
- Step-by-Step Procedure to Initialize High Operating Hours Safely
- CntOhSc Initialization Parameter Reference and Data Types
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
Integer Arithmetic Overflow Mechanism in CntOhSc OldDay Conversion
The APL block CntOhSc (FB1864, Operating Hours and Switching Cycles Counter) is widely deployed to track cumulative equipment run-times and maintenance intervals for pumps, motors, and agitators. To facilitate equipment replacement or migration from legacy systems, the block provides initialization inputs to preload existing operating history:
OldDay: Number of accumulated operating days.OldHours: Number of accumulated operating hours.OldMin: Number of accumulated operating minutes.
When the block initializes (typically triggered via OB100 restart or pulsing input Init = 1), it aggregates these values into total operating hours. In APL V8.0 and V8.2, the internal SCL code executes intermediate conversion using signed 16-bit integers (INT):
$$\text{Total Hours} = (\text{OldDay} \times 24) + \text{OldHours}$$
In 16-bit signed integer mathematics, the valid positive range is 0 to +32,767 (16#7FFF):
- For
OldDay = 1365: $1365 \times 24 = 32,760$ (Valid; fits within 16-bit range). - For
OldDay = 1366: $1366 \times 24 = 32,784$ (16#8010). In signed 16-bit representation, bit 15 represents the negative sign, causing the value to evaluate to $-32,752$!
As soon as the counter starts counting cyclically, the block begins accumulating seconds from this negative base value, displaying negative operating hours on the WinCC operator faceplate.
Behavior Across APL Versions: AdvLib 8.0, 8.2, and 9.0+
The arithmetic overflow behavior differs by library version:
- AdvLib80 (APL V8.0, Block Version 2.1): Affected by 16-bit overflow when
OldDay > 1365. - AdvLib82 (APL V8.2, Block Version 4.0): Affected by 16-bit overflow when
OldDay > 1365. - AdvLib90 / AdvLib91 (APL V9.0 / V9.1+, Block Version 5.0+): Siemens refactored internal multiplication routines to use 32-bit double integers (
DINT) and floating-point mathematics (REAL), allowingOldDayvalues up to standard REAL limits without overflow.
Step-by-Step Procedure to Initialize High Operating Hours Safely
If operating on PCS 7 V8.0 or V8.2 systems where library upgrade is not immediately feasible, execute this workaround:
- Convert Cumulative Days to Hours Offline:
- Calculate total hours manually: $\text{Hours} = (\text{Days} \times 24) + \text{Existing Hours}$.
- Example: 2000 days and 10 hours = $(2000 \times 24) + 10 = 48,010$ hours. - Zero the OldDay Parameter:
- In the CFC chart hostingCntOhSc, set input parameterOldDay = 0. - Assign Value to OldHours (REAL):
- TheOldHoursparameter is defined as data typeREAL(floating point), which supports values up to $+3.4028 \times 10^{38}$.
- Set input parameterOldHours = 48010.0. - Trigger Re-Initialization:
- Pulse the block input parameterInit = 1for one CPU cycle (or trigger CPU restart OB100).
- The block recalculates total runtime without passing through the defective 16-bit integer multiplication routine. - Delta Download: Download CFC changes in RUN.
CntOhSc Initialization Parameter Reference and Data Types
The following table details the initialization interface for APL block CntOhSc (FB1864):
OldDayDINT / INTOldHoursREALOldMinREALOldCyclesDINTInitBOOL[!NOTE]
Commercial Accuracy Notice: The Advanced Process Library block CntOhSc is included within the standard PCS 7 APL package > (6ES7658-1EX58-0YA5). Utilizing CntOhSc instances consumes standard AS and OS Process Objects, but correcting block > initialization parameters consumes no additional licenses.
Verification
Verify that the operating hours counter displays positive, accurate runtime values:
- CFC Online Test: In CFC, activate Test -> Test Mode. Verify that output pin
Hoursdisplays the correct positive floating-point value (e.g.48010.0) instead of a negative number. - Counting Operation Test: Force the input condition
Run = 1. Verify that output pinSecincrements cyclically and thatHoursaccumulates upward continuously. - WinCC Faceplate Inspection: Open the CntOhSc faceplate in WinCC Runtime. Confirm that the total operating hours field renders cleanly without minus signs or format faults.
Limitations and Operational Precautions
Observe these guidelines when managing runtime counters:
- Single Execution of Init: Ensure the
Initcommand is not permanently tied to1. Once initialization completes,Initmust be reset to0, otherwise the counter will reset to old values on every scan. - Maintenance Interval Synchronization: Check the configured maintenance alarm threshold (
ExtSetHours). Ensure the limit exceeds the newly initialized operating hours value to prevent nuisance maintenance alarms. - Long-Term Floating Point Resolution: In single-precision
REALarithmetic, accumulating small fractions of hours over very large totals (>1,000,000 hours) can encounter floating-point resolution limits. Reset counters during major overhauls.
Engineer FAQ
Why does CntOhSc turn negative only when OldDay is greater than 1365?
Because 1365 * 24 = 32,760, which is just below the 16-bit integer limit (+32,767). At 1366 days, 1366 * 24 = 32,784, which overflows the 16-bit signed integer boundary and evaluates to -32,752.
How do I enter an operating history of 5 years (1825 days) into CntOhSc?
Leave OldDay = 0 and convert the entire time to hours: 1825 days * 24 hours = 43,800 hours. Enter 43800.0 into the OldHours parameter and trigger Init = 1.
Has this bug been resolved in newer PCS 7 versions?
Yes. In PCS 7 V9.0 and V9.1 (AdvLib90 / AdvLib91), the internal conversion arithmetic was updated to 32-bit DINT mathematics, eliminating the 1365-day overflow limit.
Does CntOhSc retain its counted value across a CPU power failure?
Yes. The internal accumulation variables are stored in the block's retentive instance DB, preserving values through CPU restarts.
Technical References
- SIMATIC PCS 7 Advanced Process Library (APL) Function Manual (Entry ID 109781589)
- SIMATIC S7-400 S7-SCL Data Types and Arithmetic Conversion Guide (Entry ID 109751826)
- SIMATIC PCS 7 Maintenance Station Operating Instructions (Entry ID 109754984)
- Siemens Industry Online Support FAQ on APL CntOhSc Calculation Limits (Entry ID 109756827)
Related Articles
- Customizing Motor State Colors and Icons in PCS 7 APL Block Icons
- Configuring Local Mode Operation and Interlock Bypassing in CEMAT and APL
- Retaining APL Out of Service Operating Mode Across CPU Downloads
- Resolving FbDrive Bad Output and ErrorNum 1 with SINAMICS G120C in PCS 7
Related Tags
- CntOhSc
- APL
- Operating Hours
- Integer Overflow
- OldDay
- FB1864