Siemens S7 STL (AWL) Programming Skill
Overview
Generate Siemens S7-300 / S7-400 / S7-1500 Statement List (STL / AWL) programs compatible with Step7 Classic and TIA Portal.
Core model knowledge:
- Accumulator-based execution (ACCU1 / ACCU2)
- RLO (Result of Logic Operation) for boolean logic
- S5 timers, IEC timers (TON/TOF/TP), counters, INT and REAL arithmetic
- OB / FB / FC / DB block hierarchy
- Standard scan cycle model (Read → Execute → Write)
For full instruction syntax, see references/STL_Core_Instructions.md.
Critical Rule: Omit Block Number (NAME) Line
Always omit the NAME : '<number>' line unless the user specifically requests a fixed block number. TIA Portal automatically assigns the next available unused block number on import.
Block Structure
Organization Block (OB)
ORGANIZATION_BLOCK "OB1"
TITLE = Main Program Cycle
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_TEMP
TempVar : Int;
END_VAR
BEGIN
NETWORK
TITLE = Example Network
L PIW256;
T #TempVar;
END_ORGANIZATION_BLOCK
Function (FC) — Stateless
FUNCTION "FC_Name" : Void
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
IN : Int;
END_VAR
VAR_OUTPUT
OUT : Real;
END_VAR
BEGIN
NETWORK
TITLE = Convert and Scale
L #IN;
ITD;
DTR;
T #OUT;
END_FUNCTION
Function Block (FB) — Stateful
FUNCTION_BLOCK "FB_Name"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
VAR_INPUT
StartPB : BOOL;
StopPB : BOOL;
END_VAR
VAR_OUTPUT
MotorOut : BOOL;
END_VAR
VAR
RunLatch : BOOL;
Delay : TON;
END_VAR
BEGIN
NETWORK
TITLE = Start Latch
A #StartPB;
AN #StopPB;
S #RunLatch;
NETWORK
TITLE = Output
A #RunLatch;
= #MotorOut;
END_FUNCTION_BLOCK
Data Block (DB)
DATA_BLOCK "DB_Name"
{ S7_Optimized_Access := 'TRUE' }
VERSION : 0.1
NON_RETAIN
VAR
Value : Int;
END_VAR
BEGIN
END_DATA_BLOCK
Key Formatting Rules
- Always include
{ S7_Optimized_Access := 'TRUE' } after block keyword
- Use symbolic quoted names (
"BlockName") — never numeric references
- Prefix local variables with
# (e.g., #StartPB)
- Each instruction ends with
;
- Use
NETWORK + TITLE = ... + // comment for each logical group
Timer Selection:
- Inside FC: Use S5 timers (
SE, SP, SD, SA, SS)
- Inside FB: Use IEC timers (
TON, TOF, TP)
Code Generation Constraints
MUST:
- Use symbolic quoted names for all block references
- Generate complete, compilable blocks
- Separate logical groups into individual NETWORKs
- Use uppercase STL mnemonics (A, AN, O, =, S, R, L, T, FP, ITD, DTR, etc.)
- Generate matching instance DB when generating an FB
MUST NOT:
- Mix LAD, SCL, or non-STL syntax
- Use numeric-only block references unless user explicitly requests
- Include
NAME : '<number>' in generated blocks
When to Consult Documentation
If the user's request involves instructions or patterns not covered here, consult:
- TIA Portal STL Reference:
https://docs.tia.siemens.cloud/r/en-us/v21/creating-stl-programs-s7-300-s7-400-s7-1500
- Full instruction reference: references/STL_Core_Instructions.md
- Block templates: references/REFERENCE.md
- Formatting rules: references/FORMATTING.md
Typical cases requiring documentation lookup:
- Interrupt OBs (OB35, OB40, OB80) and their startup VAR_TEMP
- System function calls (SFC, SFB) such as
CALL SFC14
- String handling, DATE_AND_TIME types
BLKMOV, FILL, UBLKMOV block move instructions
- Less common accumulator operations (
CAD, CAW, TAK, PUSH, POP)
1---2name: siemens-awl-stl-programmer3description: Generate Siemens S7-300/S7-400/S7-1500 Statement List (STL/AWL) programs compatible with Step7 Classic and TIA Portal. Use this skill whenever the user asks to write, generate, create, or modify any PLC logic, function blocks, organization blocks, data blocks, or control programs in STL/AWL format. Also trigger for any questions about Siemens S7 memory addressing, timers, counters, accumulators, block structure, or Step7/TIA Portal imports. Always use this skill even if the user just mentions "STL", "AWL", "Step7", "TIA Portal", "S7-300", "S7-400", "S7-1500", "PLC block", "OB", "FB", "FC", or "DB".4---56# Siemens S7 STL (AWL) Programming Skill78## Overview910Generate **Siemens S7-300 / S7-400 / S7-1500 Statement List (STL / AWL)** programs compatible with **Step7 Classic** and **TIA Portal**.1112Core model knowledge:13- Accumulator-based execution (ACCU1 / ACCU2)14- RLO (Result of Logic Operation) for boolean logic15- S5 timers, IEC timers (TON/TOF/TP), counters, INT and REAL arithmetic16- OB / FB / FC / DB block hierarchy17- Standard scan cycle model (Read → Execute → Write)1819For full instruction syntax, see [references/STL_Core_Instructions.md](references/STL_Core_Instructions.md).2021---2223## Critical Rule: Omit Block Number (`NAME`) Line2425**Always omit the `NAME : '<number>'` line** unless the user specifically requests a fixed block number. TIA Portal automatically assigns the next available unused block number on import.2627---2829## Block Structure3031### Organization Block (OB)3233```34ORGANIZATION_BLOCK "OB1"35TITLE = Main Program Cycle36{ S7_Optimized_Access := 'TRUE' }37VERSION : 0.13839VAR_TEMP40 TempVar : Int;41END_VAR4243BEGIN44NETWORK45TITLE = Example Network46 L PIW256;47 T #TempVar;48END_ORGANIZATION_BLOCK49```5051### Function (FC) — Stateless5253```54FUNCTION "FC_Name" : Void55{ S7_Optimized_Access := 'TRUE' }56VERSION : 0.15758VAR_INPUT59 IN : Int;60END_VAR6162VAR_OUTPUT63 OUT : Real;64END_VAR6566BEGIN67NETWORK68TITLE = Convert and Scale69 L #IN;70 ITD;71 DTR;72 T #OUT;73END_FUNCTION74```7576### Function Block (FB) — Stateful7778```79FUNCTION_BLOCK "FB_Name"80{ S7_Optimized_Access := 'TRUE' }81VERSION : 0.18283VAR_INPUT84 StartPB : BOOL;85 StopPB : BOOL;86END_VAR8788VAR_OUTPUT89 MotorOut : BOOL;90END_VAR9192VAR93 RunLatch : BOOL;94 Delay : TON;95END_VAR9697BEGIN98NETWORK99TITLE = Start Latch100 A #StartPB;101 AN #StopPB;102 S #RunLatch;103104NETWORK105TITLE = Output106 A #RunLatch;107 = #MotorOut;108END_FUNCTION_BLOCK109```110111### Data Block (DB)112113```114DATA_BLOCK "DB_Name"115{ S7_Optimized_Access := 'TRUE' }116VERSION : 0.1117NON_RETAIN118119VAR120 Value : Int;121END_VAR122123BEGIN124END_DATA_BLOCK125```126127---128129## Key Formatting Rules130131- Always include `{ S7_Optimized_Access := 'TRUE' }` after block keyword132- Use symbolic quoted names (`"BlockName"`) — never numeric references133- Prefix local variables with `#` (e.g., `#StartPB`)134- Each instruction ends with `;`135- Use `NETWORK` + `TITLE = ...` + `// comment` for each logical group136137**Timer Selection:**138- Inside FC: Use S5 timers (`SE`, `SP`, `SD`, `SA`, `SS`)139- Inside FB: Use IEC timers (`TON`, `TOF`, `TP`)140141---142143## Code Generation Constraints144145**MUST:**146- Use symbolic quoted names for all block references147- Generate complete, compilable blocks148- Separate logical groups into individual NETWORKs149- Use uppercase STL mnemonics (A, AN, O, =, S, R, L, T, FP, ITD, DTR, etc.)150- Generate matching instance DB when generating an FB151152**MUST NOT:**153- Mix LAD, SCL, or non-STL syntax154- Use numeric-only block references unless user explicitly requests155- Include `NAME : '<number>'` in generated blocks156157---158159## When to Consult Documentation160161If the user's request involves instructions or patterns **not covered here**, consult:162163- **TIA Portal STL Reference:** `https://docs.tia.siemens.cloud/r/en-us/v21/creating-stl-programs-s7-300-s7-400-s7-1500`164- **Full instruction reference:** [references/STL_Core_Instructions.md](references/STL_Core_Instructions.md)165- **Block templates:** [references/REFERENCE.md](references/REFERENCE.md)166- **Formatting rules:** [references/FORMATTING.md](references/FORMATTING.md)167168Typical cases requiring documentation lookup:169- Interrupt OBs (OB35, OB40, OB80) and their startup VAR_TEMP170- System function calls (SFC, SFB) such as `CALL SFC14`171- String handling, DATE_AND_TIME types172- `BLKMOV`, `FILL`, `UBLKMOV` block move instructions173- Less common accumulator operations (`CAD`, `CAW`, `TAK`, `PUSH`, `POP`)