Converting STL (AWL) to SCL with AI: procedure and pitfalls
Many machines with Siemens PLCs run programs written in STL (AWL in German). STL still works on the S7-1500, but fewer and fewer programmers read it fluently, and the S7-1200 does not support it at all. Converting to SCL is therefore a logical step. We describe the procedure we use, what AI can do along the way and where a human is needed.
Why convert STL to SCL
- Readability and maintenance. Anyone who knows structured text can read SCL. STL requires knowledge of accumulators and the status word.
- Moving to the S7-1200 or standardising libraries. The S7-1200 cannot run STL, but it can run SCL.
- Symbolic programming. Old STL code often relies on absolute addresses and a fixed data block layout.
Conversion does not always pay off, though. A well-tested block that nobody touches can stay in STL. Convert mainly what you are going to keep changing.
Step 1: block inventory
Before you start converting, list what the project contains: which blocks are in STL, who calls them, which global data they use and whether they contain indirect addressing or S5 timers. With TIA MCP you just ask the AI for a block list with languages, the call hierarchy and cross-references. The inventory shows which blocks to convert first and which to leave until last.
Step 2: automatic conversion
TIA MCP includes an STL → SCL converter that first translates the block deterministically, i.e. by fixed rules and without guessing. It handles:
- bit logic including brackets and AND-before-OR precedence, set and reset, and FP/FN edges,
- accumulator operations: loading and transferring values, arithmetic and data type conversions,
- comparisons, jumps and block end instructions,
- FC and FB calls with parameters.
Networks become REGION sections with their original titles. It understands both international and German mnemonics. Anything it cannot convert stays in the code as a comment with the original instruction and is listed in the warnings. The conversion itself writes nothing; you see the result first.
A short example. An STL section with a latching circuit, a comparison and an S5 timer:
A(
O "Start"
O "Motor"
)
AN "Stop"
= "Motor"
L "Speed"
L 1500
>I
= "Overspeed"
A "Motor"
L S5T#5S
SE T 5
The converter turns it into:
"Motor" := ("Start" OR "Motor") AND NOT "Stop";
"Overspeed" := ("Speed" > 1500);
// STL: SE T 5
The converter deliberately does not convert the S5 timer in the last three lines. It leaves it as a comment with a warning, because deciding what to replace it with is the programmer's call.
Only now does the AI step in. It goes through the warnings, fills in the missing parts, replaces jumps with structured code, checks that the instructions used exist on the given CPU and creates the new block under a new name. The original STL block stays in the project for comparison.
Step 3: comparing behaviour
A block that compiles is not yet a correct block. What matters is whether the new SCL block behaves the same as the original STL one. This is how we proceed:
- We prepare test cases for the block: inputs and expected outputs, including edge cases.
- TIA MCP generates a test block from them, downloads the program to the PLCSIM Advanced simulator and runs the unit tests.
- We run the same cases against both the original STL block and the new SCL block and compare the results.
- For sequences and control loops we record tag values over time and compare the traces of both versions.
Nothing is downloaded to a real PLC in the process. Tests do not replace trials on the machine, but they reveal most logic errors before you get to the machine.
Pitfalls of converting STL to SCL
Precedence of logic operations
Written without brackets, A Start, O Motor, AN Stop means Start OR (Motor AND NOT Stop) in STL, because AND takes precedence over OR. The converter respects this precedence. In a manual rewrite or a general chat it is easy to overlook.
Indirect addressing
The converter does not translate pointers, ANY parameters or memory-indirect addressing. In SCL the right solution is usually an array with an index, or alternatively Variant or PEEK and POKE. That requires understanding what the code does, not just rewriting instructions.
Address registers AR1 and AR2
Instructions such as LAR1 and +AR1 work with address registers that have no equivalent in SCL. Such code has to be rewritten by hand, usually into array or structure access. Watch out for older FBs that modify AR2: this is a common source of hidden bugs.
Status word
SCL has no status word. The converter therefore rewrites SAVE as ENO := RLO, and conditions and jumps on result bits (==0, >0, JZ, JM…) as a comparison of the last result in the accumulator with zero. The OV, OS and BR bits cannot be converted mechanically: the converter marks them with the variables #STL_OV, #STL_BR… and a warning, so the block will not compile until it is fixed. The logic has to be expressed differently, for example with a range check before the calculation or by evaluating ENO. It pays to find such blocks during the inventory.
S5 timers and counters
The converter does not translate S5 timers and counters. In SCL, replace them with IEC timers (TON, TOF, TP) and CTU and CTD counters. An S5 timer is a global operand; an IEC timer needs an instance, ideally a multi-instance in the FB. Also watch the mnemonics: SE is an on-delay in German mnemonics but an extended pulse in international ones.
Jumps
Jumps are converted to GOTO so that the behaviour stays the same. It works, but it reads poorly. Turn them into structured code only once you have tests that confirm the behaviour has not changed.
Frequently asked questions
Does TIA Portal convert STL to SCL on its own?
No. TIA Portal can switch between LAD and FBD, but it does not offer automatic STL to SCL conversion. It has to be done by hand or with a tool, such as the converter in TIA MCP.
Can ChatGPT convert STL to SCL?
A short section, yes, but without checks it easily overlooks logic precedence, accumulator behaviour or jumps, and it does not know your tags. More reliable is a deterministic conversion, AI for completing and checking it, and above all testing the result.
How do I verify that the converted block does the same thing?
With the same test cases for the original and the new block in the PLCSIM Advanced simulator. TIA MCP generates a test block from the cases, runs it and reports which cases passed.
Do I have to convert STL when moving to the S7-1500?
No, the S7-1500 supports STL. Conversion pays off for blocks you will keep changing, and it is necessary when moving to the S7-1200, which does not support STL.
Related articles
- ChatGPT and Siemens PLCs: what AI can and cannot do in TIA Portal
- AI review of a PLC program before FAT: code review in TIA Portal
Got a project in STL?
TIA MCP converts STL to SCL, the AI completes the rest and tests verify the behaviour in the simulator. Try it free for 7 days on your own project in TIA Portal V17–V21.