Resolving 'Programming Error 58: Maximum Lines Code Exceeded' in SIMATIC CFC Compilations

Resolving 'Programming Error 58: Maximum Lines Code Exceeded' in SIMATIC CFC Compilations

In SIMATIC PCS 7, the compiler error or CPU diagnostic alarm 'Programming error 58: FCxxxx / maximum lines code exceeded' occurs when the code generated for a single CFC runtime group exceeds the S7-400 CPU architectural block size limit of 64 KB (or statement count limit). To resolve this, open the CFC Run Sequence Editor (Edit -> Run Sequence), locate the overloaded cyclic interrupt OB (e.g. OB35), create new runtime groups, and distribute the block calls across multiple runtime groups to split the generated machine code into smaller executable Functions.

Table of Contents

CFC Compilation Mechanics and S7-400 Block Size Limits

In SIMATIC PCS 7, engineers program graphical control strategies in the Continuous Function Chart (CFC) editor. During CFC compilation, the compiler translates these graphical blocks and interconnections into standard STEP 7 machine code blocks:
* Function Blocks (FBs): Standard library block types (e.g. MotL, PIDConL).
* Instance Data Blocks (DBs): Data structures storing state variables and parameter values for each block instance.
* Internal Functions (FCs): Executable code containers generated automatically by the CFC compiler.

Every CFC runtime group residing within an Organization Block (e.g. OB35 for 100 ms cyclic execution, OB32 for 1 s execution) is compiled into a dedicated S7-400 Function (FC). For instance, a runtime group named OB35_Group1 compiles into FC 2936.

The Architectural Limit:
In the SIMATIC S7-400 CPU architecture (including standard CPUs 414, 416, 417 and the process automation controller CPU 410-5H), the maximum allowable size for any single compiled program block (FC, FB, DB) is strictly 64 Kilobytes (65,536 bytes). If a runtime group contains an excessive number of blocks or complex interconnects, the generated FC breaches this 64 KB threshold, triggering compilation abort or runtime CPU fault.

Root Cause of 'Programming Error 58: Maximum Lines Code Exceeded'

When an engineer places dozens or hundreds of blocks into a single CFC chart or accepts default runtime positioning without organizing runtime groups:
1. Instruction Explosion: Each block instance in a runtime group generates a sequence of parameter assignments, memory address offsets, instance DB calls (CALL FBxx, DBxx), and signal status evaluations.
2. Jump Table Overflow: Complex conditional jumps and interconnect checks accumulate thousands of statements.
3. Compiler Threshold Breach: The CFC compiler detects that the compiled S7 instruction list for the generated FC exceeds either the maximum statement count (approximately 16,000 instructions) or the 64 KB binary footprint.
4. Diagnostic Symptoms:
- During compilation: Error in FCxxxx: Maximum lines code exceeded (Error 58).
- In CPU Diagnostic Buffer (if an oversized block was downloaded): Event ID 16#2528: Programming error during block processing in FCxxxx or OB121: Programming error organization block invoked.

Runtime Group Architecture in Cyclic Interrupt OBs

The solution lies in understanding and managing the CFC Run Sequence:
* An Organization Block (such as OB35) is not limited to a single runtime group; it can contain dozens of runtime groups executed in sequential order.
* Each distinct runtime group generates its own separate FC.
* By creating multiple smaller runtime groups (e.g. OB35_Tanks, OB35_Reactors, OB35_Valves), the total processing load of the OB remains identical, but the generated machine code is partitioned across multiple individual FCs (e.g. FC 1001, FC 1002, FC 1003), each comfortably under the 64 KB threshold.

Block Size and Execution Threshold Comparison Matrix

The following matrix outlines S7-400 architectural boundaries and best-practice thresholds:

Architectural MetricS7-400 Hardware Hard LimitBest-Practice Safe LimitConsequence of ExceedingMaximum Block Size (FC / FB / DB)64 KB (65,536 bytes)< 32 KB per blockCompilation abort / CPU STOP (Error 58)Blocks per Runtime Group~100 to 150 (depends on complexity)30 to 50 blocksCode bloat; single FC exceeds statement limitsReserved FC Number Range for CFCUp to 1,000 - 8,191 (CPU dependent)Configure range in CFC settingsBlock number collisions with library FCsOB35 Execution TimeOB35 configured cycle time (e.g. 100 ms)< 60% of cycle timeCycle time overrun (OB80 invocation)Process Image Partition (PIP) UpdatePer cyclic OB executionGrouped by I/O rackMemory and bus bandwidth optimization

Step-by-Step Procedure to Partition Overloaded Runtime Groups

Follow this procedure to resolve Programming Error 58:
1. Identify the Overloaded Function and Runtime Group:
- Note the FC number reported in the compiler log (e.g. FC 2936).
- In SIMATIC Manager, open any CFC chart.
- Open the Run Sequence Editor by selecting Edit -> Run Sequence or pressing Ctrl + Shift + R.
- Expand the target cyclic OB (typically OB35). Locate the runtime group corresponding to the error.
2. Create New Runtime Groups:
- Right-click the cyclic OB folder (e.g. OB35) or an existing group and select Insert Runtime Group.
- Assign intuitive names to the new groups (e.g. OB35_Area1_Analog, OB35_Area1_Motors, OB35_Area2_Logic).
3. Move Blocks to New Runtime Groups:
- In the Run Sequence Editor, expand the overloaded runtime group.
- Select roughly half of the block instances.
- Drag and drop (or cut/paste) the selected blocks into the newly created runtime group.
- Ensure the logical execution sequence of interlocked blocks is maintained (e.g. channel drivers execute before controller blocks, controller blocks execute before actuator drivers).
4. Verify Compiler Block Number Range:
- In CFC, select Options -> Customize -> Compile/Download....
- Inspect the Installed block numbers range for FCs and DBs. Ensure the upper range is wide enough to accommodate the new functions (e.g. FC range 1 to 3000).
5. Recompile the S7 Program:
- In SIMATIC Manager, right-click the Charts folder and select Compile -> Charts as Program.
- Select Scope: Changes only (or Entire program if block numbers were adjusted).
- Verify that compilation finishes with 0 Errors.

Verification

Verify that code restructuring resolved the error:
1. Check the CFC compilation log: Confirm that the compile process completes with 0 Errors and that FC 2936 (or its split successors) compiles cleanly.
2. Open the S7 Program block folder in Component View: Check the size of the compiled FCs. Ensure each generated FC is well below the 64 KB limit (typically 10 KB to 25 KB).
3. Download the program to the S7-400 or S7-PLCSIM:
- Verify the CPU remains in RUN mode.
- Open the CPU Diagnostic Buffer (Ctrl + D): Verify zero entries for Event ID 16#2528 or OB121 programming faults.
4. Verify that cyclic scan execution time in OB35 remains stable and well within the configured cycle time.

Limitations and Operational Precautions

  • When moving blocks between runtime groups, maintain data flow causality: always keep signal reading blocks executing before data processing blocks to prevent introducing 1-cycle latency into control loops.
  • Moving blocks into a new runtime group requires downloading the program to the CPU; on running plants, execute download in RUN (Changes only), never perform a full stop download during production.
  • If user-written Step 7 functions (FCs/FBs) were placed in the reserved CFC block number range, relocate user blocks to avoid number space collisions.

Engineer FAQ

Can an S7-400 CPU block ever exceed 64 KB if memory is available?

No. The 64 KB limit is an architectural constraint of the S7-400 instruction addressing system (16-bit internal address pointers). Even on a high-end CPU 410-5H with 32 MB of load memory, no single block can exceed 64 KB.

Why does CFC create runtime groups automatically?

When a new CFC chart is created, PCS 7 automatically generates a default runtime group for that chart inside the assigned OB. However, if multiple charts share one group or if a massive chart contains hundreds of blocks, the single group becomes overloaded.

What happens if a programming error occurs in the CPU without OB121 programmed?

If the CPU encounters a programming error (such as an oversized or corrupted block call) and Organization Block OB121 is not present in the controller, the CPU immediately trips into STOP mode.

Technical References

Related Articles

Related Tags

  • SIMATIC PCS 7 V8.1
  • CFC Engineering
  • Runtime Groups
  • Error 58
  • S7-400 Architecture
6 respuestas