Diagnosing Area Length Read Errors (FB506 Local Data Address 0) in SIMATIC S7-400 and CPU 410-5H

Diagnosing Area Length Read Errors (FB506 Local Data Address 0) in SIMATIC S7-400 and CPU 410-5H

In SIMATIC S7-400 and CPU 410-5H controllers, the recurring diagnostic buffer event 'Area length error when reading' pointing to FB506 at local data address 0 (Event ID 16#2522 or 16#2523) occurs when STL or SCL code attempts to access unallocated temporary local data (L stack) via an invalid or uninitialized pointer. Increasing the priority class stack size in HW Config fails because stack configuration only defines the maximum memory pool, not an individual block's declared TEMP variables. To resolve this: open the offending block (FB506) from the diagnostic buffer, locate the indirect address or ANY pointer offset reading address L 0.0 / LD 0, verify the TEMP variable declaration table, ensure all pointers are initialized before reading, and recompile the block source.

Table of Contents

Executive Summary

During plant operation or commissioning, an automation controller may flood its diagnostic buffer with continuous 'Area length error when reading' events. In SIMATIC PCS 7, this triggers recurring calls to Organization Block OB121 (Programming Error). If OB121 is absent, the CPU enters STOP mode immediately; if present, the CPU remains in RUN but incurs substantial cycle time penalties. Engineers often attempt to resolve the fault by expanding priority class local data stack allocations in HW Config, only to find the error persists unabated. This article explains why hardware stack reconfiguration fails and provides the code-level debugging procedure to eliminate pointer violations in FB506.

Architecture and Fundamental Mechanics

The SIMATIC S7 execution model manages memory across distinct address spaces: Inputs (I), Outputs (Q), Bit Memory (M), Data Blocks (DB/DI), and Temporary Local Data (L). Local data is allocated dynamically on the L-stack whenever an Organization Block (OB), Function Block (FB), or Function (FC) is invoked.

In STEP 7 HW Config, the 'Memory' tab under CPU Properties allows engineers to assign local data stack bytes per priority class (e.g., 256 or 512 bytes for OB35). This setting establishes the total memory reserve available for all nested block calls within that priority class.

However, within an individual compiled block like FB506, the block's local data frame is dictated strictly by its VAR_TEMP declaration table:
1. If FB506 declares only 8 bytes of temporary variables (LB 0 to LB 7), any instruction addressing LB 8 or higher violates the block's local data frame.
2. In indirect addressing (e.g., L L [AR1, P#0.0] or SCL pointer references), if Address Register AR1 is uninitialized or loaded with 0 while pointing to an invalid memory area, the CPU attempts to read LD 0 from an unallocated local data offset.
3. Because the error is rooted in out-of-bounds pointer arithmetic within the block logic, increasing the CPU priority class allocation in HW Config has zero effect; the CPU hardware memory protection detects that the instruction exceeds the block's declared temporary storage frame, issuing Event ID 16#2522.

Step-by-Step Implementation Procedure

  1. Analyze Diagnostic Buffer Event Details:
    a. In SIMATIC Manager, select the target CPU and click PLC -> Diagnostic Buffer.
    b. Highlight the 'Area length error when reading' event (Event ID 16#2522 or 16#2523).
    c. Note the calling block (FB506), the current block address / instruction offset, and the memory area cited (Local Data, address 0).
    d. Click the 'Open Block' button in the diagnostic buffer dialog to navigate directly to the offending instruction in the LAD/STL/FBD or SCL editor.

  2. Inspect Address Registers and Pointer Logic in FB506:
    a. Examine the instruction highlighted by the editor (e.g., L D [AR1, P#0.0], L W [AR1, P#2.0], or an SCL array index access MyArray[Index]).
    b. Trace the logic immediately preceding the instruction where Address Register 1 (AR1) or Address Register 2 (AR2) is loaded.
    c. Verify if AR1 was loaded from an uninitialized ANY pointer (LAR1 P##InputAny) or if an offset calculation yielded 0 or an out-of-bounds index.

  3. Review TEMP Variable Declaration Table:
    a. Scroll to the top of FB506 and inspect the VAR_TEMP section in the declaration table.
    b. Confirm that the total byte size of declared temporary variables accommodates all indexed local data accesses.
    c. If a structure or array is referenced via local data pointers, verify that its declaration begins at the expected boundary and matches the data types.

  4. Correct Pointer Initialization and SCL Bounds:
    a. If writing in SCL, ensure array access includes bounds checking before evaluation (e.g., IF Index >= 1 AND Index <= MaxIndex THEN ...).
    b. If using ANY pointers, verify that the pointer structure format (16#1002 for byte counts) and DB number are properly populated before dereferencing.
    c. In STL, initialize AR1 with a valid pointer target (e.g., LAR1 P##LocalVariable) before executing indexed reads.

  5. Recompile and Download Block:
    a. Save and compile the modified FB506.
    b. In SIMATIC Manager, download FB506 to the CPU online in RUN mode (Download Changes).
    c. Clear the diagnostic buffer and confirm no new programming error events appear.

Verification

  1. Open the CPU Diagnostic Buffer in SIMATIC Manager: verify that Event ID 16#2522 ceases to log.
  2. Confirm that the call count for OB121 drops to zero and the CPU cycle time stabilizes.
  3. Monitor FB506 online in CFC or test editor: confirm that processed output values calculate correctly without returning default zero or NaN values.
  4. Check the controller operating status LEDs: verify that the SF (System Fault) LED extinguishes.

Limitations and Operational Precautions

Never resolve area length errors by simply downloading an empty OB121 to mask the fault; while OB121 prevents the CPU from halting, unhandled memory read errors corrupt calculations, lead to invalid process outputs, and dramatically inflate CPU scan times. If FB506 is a protected proprietary library block (Know-How Protected), the block source must be requested from the original vendor or updated via official library hotfixes.

Engineer FAQ

Why did increasing priority class stack size in HW Config fail to fix the error?

HW Config allocates total stack space for all nested blocks, but it cannot expand an individual block's internal TEMP variable declaration table or fix invalid pointer arithmetic.

What does Event ID 16#2522 indicate in S7 CPUs?

It specifies an 'Area length error when reading', meaning an instruction attempted to read data beyond the boundary of a declared memory area (DB, I, Q, M, or L).

What happens if OB121 is deleted from the CPU?

The next time FB506 triggers the area length error, the CPU will immediately transition to STOP mode, halting the automation system.

How do I find which line of code caused the area length error?

Highlight the error event in the STEP 7 Diagnostic Buffer and click 'Open Block'; the editor opens directly to the faulty instruction line.

Can SCL code generate area length errors?

Yes. Accessing an array with an index exceeding its declared upper or lower bounds compiles into pointer offsets that violate the local or DB memory area at runtime.

Technical References

Related Articles

Related Tags

  • Area Length Error
  • Diagnostic Buffer
  • OB121
  • FB506
  • Local Data Stack
  • Pointer Addressing
20 respuestas