Resolving Negative Value Display in APL CntOhSc Operating Hours Counter

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

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), allowing OldDay values 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:

  1. 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.
  2. Zero the OldDay Parameter:
    - In the CFC chart hosting CntOhSc, set input parameter OldDay = 0.
  3. Assign Value to OldHours (REAL):
    - The OldHours parameter is defined as data type REAL (floating point), which supports values up to $+3.4028 \times 10^{38}$.
    - Set input parameter OldHours = 48010.0.
  4. Trigger Re-Initialization:
    - Pulse the block input parameter Init = 1 for one CPU cycle (or trigger CPU restart OB100).
    - The block recalculates total runtime without passing through the defective 16-bit integer multiplication routine.
  5. 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):

Parameter NameData TypeDefault ValueInternal Handling in V8.xSafe Operational Range in V8.xOldDayDINT / INT0Multiplied by 24 via 16-bit math0 to 1365 days maximum (Exceeding flips negative)OldHoursREAL0.0Direct floating-point addition0.0 to 100,000.0+ hours (Recommended)OldMinREAL0.0Divided by 60.0 via REAL math0.0 to 59.0 minutesOldCyclesDINT0Direct 32-bit integer transfer0 to 2,147,483,647 cyclesInitBOOL0Command to load Old valuesPulse 0 -> 1 -> 0 to re-initialize

[!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:

  1. CFC Online Test: In CFC, activate Test -> Test Mode. Verify that output pin Hours displays the correct positive floating-point value (e.g. 48010.0) instead of a negative number.
  2. Counting Operation Test: Force the input condition Run = 1. Verify that output pin Sec increments cyclically and that Hours accumulates upward continuously.
  3. 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:

  1. Single Execution of Init: Ensure the Init command is not permanently tied to 1. Once initialization completes, Init must be reset to 0, otherwise the counter will reset to old values on every scan.
  2. 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.
  3. Long-Term Floating Point Resolution: In single-precision REAL arithmetic, 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

Related Articles

Related Tags

  • CntOhSc
  • APL
  • Operating Hours
  • Integer Overflow
  • OldDay
  • FB1864
6 respuestas