Migrating Legacy SIMATIC S5 Statement List (STL) Logic and Jumps into SIMATIC PCS 7
Direct line-by-line conversion of SIMATIC S5 Statement List jumps (SPB/SPA) into PCS 7 CFC is an anti-pattern because CFC is an graphical signal-flow language that does not support arbitrary jumps. To migrate S5 code effectively into PCS 7, encapsulate complex jump structures and mathematical algorithms inside Structured Control Language (SCL) Function Blocks (IF...THEN, CASE), or replace the logic entirely with standard Advanced Process Library (APL) technological blocks.
Table of Contents
- The Architectural Divide: S5 Step Programming vs. PCS 7 CFC
- Dissecting S5 Jump Mechanics and Data Formats
- Recommended Migration Strategies: SCL Encapsulation vs. APL
- S5 Instruction Conversion to PCS 7 SCL Matrix
- Verification
- Limitations and Operational Precautions
- Engineer FAQ
- Technical References
- Related Articles
- Related Tags
The Architectural Divide: S5 Step Programming vs. PCS 7 CFC
When modernizing legacy manufacturing plants controlled by SIMATIC S5 (e.g. S5-115U, S5-135U, or S5-155U) into modern SIMATIC PCS 7, engineers face the task of converting decades-old Statement List (STL) logic into the PCS 7 engineering environment.
Engineers frequently attempt direct transliteration of raw S5 assembly code:
L DW 3
L KF +11
!=F
SPB =M004
SPA =M003
M004:
L KF +1
T DW 3
UN E 15.1
SPB =M005
L DD 15
L KG +19500
+GT
T DD 15
SPA =M003
M005:
ON E 15.2
SPB =M003
L DD 15
L KG +19500
-GT
T DD 15
M003: ***
When importing this into PCS 7, engineers discover that:
1. CFC Does Not Support Jump Instructions: The Continuous Function Chart (CFC) editor is a graphical signal-flow engine based on interconnected blocks. It has no native concept of labels, jumps (SPA, SPB), or conditional skipping.
2. S5 Converter Limitations: The automated 'S5 to S7 Converter' utility translates S5 STL into standard S7 Classic STL. However, raw STL blocks cannot be directly interconnected or visualized inside PCS 7 without violating module driver generation and APL faceplate standards.
Dissecting S5 Jump Mechanics and Data Formats
To translate S5 code successfully, one must analyze the underlying control intent rather than individual assembly instructions:
-
S5 Jump Instructions:
*SPB(Springe bedingt): Jump if RLO (Result of Logic Operation) is1.
*SPA(Springe absolut): Unconditional Jump to a label.
* In the example logic, jumps are utilized to implement standard if-else branching and state selection. -
Legacy S5 Data Types vs. Modern IEEE Standards:
*KF(Festpunktzahl): 16-bit signed integer (equivalent to S7INT).
*KG(Gleitpunktzahl): Proprietary S5 floating-point format (32-bit floating point, non-IEEE 754). S7 uses standard 32-bit IEEE 754 floating point (REAL).
*+GT/-GT: S5 floating-point addition and subtraction (equivalent to S7+Rand-R).
*DW 3/DD 15: Data Word 3 (16-bit word) and Data Double Word 15 (32-bit dword) inside the active open data block. -
Technological Intent of the S5 Snippet:
* The logic checks whether a mode word (DW 3) equals 11. If not, it initializesDW 3to 1.
* If digital inputE 15.1is low (0), it increments process accumulatorDD 15by19500.0.
* If digital inputE 15.2is low, it decrements the accumulator by19500.0.
* In modern terms, this is an incremental ramp / accumulator function with direction control.
Recommended Migration Strategies: SCL Encapsulation vs. APL
Strategy 1: Encapsulating Logic in Structured Control Language (SCL - Recommended)
The cleanest method to migrate complex jump structures into PCS 7 is authoring a custom Function Block (FB) using Structured Control Language (SCL):
1. SCL natively expresses jumps through structured control statements: IF...THEN...ELSE and CASE...OF.
2. Cleanly defines formal inputs and outputs, eliminating absolute memory accesses.
Example SCL Implementation:
FUNCTION_BLOCK FB1200
TITLE = 'Accumulator Controller'
{ S7_m_c := 'true' }
VAR_INPUT
ModeSelect : INT;
DecrInput : BOOL; // Corresponds to E 15.1
IncrInput : BOOL; // Corresponds to E 15.2
StepValue : REAL := 19500.0;
END_VAR
VAR_OUTPUT
AccumulatorValue { S7_m_c := 'true' } : REAL;
ModeStatus : INT;
END_VAR
BEGIN
// Replaces: L DW 3 / L KF 11 / !=F / SPB M004
IF ModeSelect <> 11 THEN
ModeStatus := 1;
ELSE
ModeStatus := ModeSelect;
END_IF;
// Replaces conditional increments and decrements
IF NOT DecrInput THEN
AccumulatorValue := AccumulatorValue + StepValue;
ELSIF NOT IncrInput THEN
AccumulatorValue := AccumulatorValue - StepValue;
END_IF;
END_FUNCTION_BLOCK
- Compile the SCL block into an FB, place it onto a CFC chart, and wire its inputs directly to channel drivers (
Pcs7DiIn).
Strategy 2: Replacing with Standard APL Technological Blocks
In many cases, legacy S5 custom code was written because S5 lacked standard process libraries. In PCS 7, this entire routine can often be replaced by standard Advanced Process Library blocks:
* Use Ramp (FB1886) for rate-of-change control.
* Use TotalL (FB1906) for accumulated totalization.
* Use SelA16In (FB1888) for mode selection.
S5 Instruction Conversion to PCS 7 SCL Matrix
L KF +11L 11ModeSelect := 11;L KG +19500L 19500.0 (IEEE 754)StepValue := 19500.0;SPB =LabelJC Label (STL)IF Condition THEN ... END_IF;SPA =LabelJU Label (STL)GOTO Label; (or structured loop)!=F<>IIF Var1 <> Var2 THEN+GT / -GT+R / -RResult := Val1 + Val2;Verification
- Compile the custom SCL block in SIMATIC Manager; confirm 0 Errors.
- Open a test CFC chart and insert the compiled FB.
- In S7-PLCSIM, set
ModeSelect = 5,DecrInput = 0; verifyAccumulatorValueincrements by19500.0every execution cycle. - Set
DecrInput = 1,IncrInput = 0; verifyAccumulatorValuedecrements by19500.0. - Set
ModeSelect = 11; verifyModeStatusreports11. - Confirm the block executes deterministically inside cyclic interrupt OB35 with zero cycle overruns.
Limitations and Operational Precautions
- Sampling Time Sensitivity: In the legacy S5 program, the code may have executed once per OB1 scan. In PCS 7, placing the block into OB35 executes it at a fixed interval (e.g. 100 ms). Ensure the increment rate accounts for the exact cyclic interrupt sample time.
- Avoid GOTO in SCL: While SCL supports the
GOTOstatement, its use is considered poor engineering practice in PCS 7. Always use structuredIF,CASE, orWHILEconstructs. - Signal Inversion Nuances: Note that in S5,
UN(Und Nicht) checks for a0signal state. In SCL, this translates toIF NOT Signal THEN.
Engineer FAQ
Why did the S5 to S7 Converter produce code that won't run in CFC?
The Siemens S5-S7 Converter generates linear STL code designed for standard S7-300/400 Classic controllers. It does not generate CFC block types or PCS 7 driver structures.
What is the difference between S5 floating point (KG) and S7 REAL?
S5 used a proprietary 32-bit floating-point format with a different exponent bias and mantissa sign bit. S7 adheres strictly to standard IEEE 754 floating-point encoding.
Can I compile STL code directly into a CFC block?
Yes, you can write a Function Block in STL with formal input/output parameters and place it into CFC, but SCL is far superior for maintaining readable mathematical and branching logic.
Technical References
- SIMATIC S5 to S7 Converter Manual (Siemens AG)
- SIMATIC S7-SCL V5.3 for S7-300/400 Programming Manual
- SIMATIC Process Control System PCS 7 Advanced Process Library (APL) Function Manual
- Siemens Industry Online Support: Migrating from S5 to PCS 7 Guidelines (SIOS Entry ID 109780813)
Related Articles
- Calling Functions (FC) in SIMATIC PCS 7 CFC Charts
- Understanding 'Generate Module Drivers' in SIMATIC PCS 7
- APL Signal Status Propagation and Quality Code Architecture
Related Tags
- S5 Migration
- SCL
- CFC
- STL Jumps
- SPB
- PCS 7 Engineering