1. Overview: The Over-Engineering Problem in Industrial Automation
Special-machine automation routinely produces programs that double the estimated engineering time, tax the controller CPU, and become unmaintainable the moment the original author moves on. The pattern repeats across OEMs, system integrators, and in-house automation groups: a competent programmer invests in custom function blocks (FBs), intricate monitoring, and optimization paths that solve problems the production line does not have. The result is a "Swiss clock" that the maintenance electricians cannot read, the project manager cannot accept, and a replacement CPU cannot accommodate without a re-spec.
This reference documents the field-proven boundaries between disciplined engineering and self-indulgent programming on the SIMATIC S7-1200 platform. It pairs the soft skills of program ownership (tag naming, structure, documentation) with the hard numbers (work memory percentage, cycle time, OB priority) that determine whether a CPU swap or a re-write is needed.
2. CPU and Memory Impact: Quantifying the Damage on S7-1200
The S7-1200 family is structured around a fixed work-memory budget and a deterministic OB1 scan. Both are easy to overrun when scope creeps. Three S7-1200 data points matter most for this discussion:
| Resource | S7-1211C (DC/DC/DC) | S7-1214C (DC/DC/DC) | S7-1215C (DC/DC/DC) |
|---|---|---|---|
| Work memory (program + data) | 30 KB | 100 KB | 125 KB (code) / 4 MB (data, firmware 4.x) |
| Load memory | 1 MB | 4 MB | 4 MB |
| Bit execution time | 0.1 µs | 0.08 µs | 0.08 µs |
| Typical OB1 minimum scan | 1 ms baseline; rises linearly with active logic | ||
Source: S7-1200 Programmable Controller System Manual (09/2023).
The figure quoted in the field case (a built-in FTP client consuming 50% of the S7-1200 work memory) is realistic. The FTP_CMD / FTP_CONNECT blocks in the Siemens "Communication with FTP" library pull a TLS stack, a TCP/IP state machine, and a sizeable buffer for file transfer. On an S7-1211C, that single library can take a 30 KB program budget to ~18 KB free, which is the boundary below which TIA Portal will refuse to compile new logic without flagging the resource exhaustion.
2.1 When to move FTP off the PLC
If the only requirement is to move a CSV or trace file from the machine to a network share, the PLC should not be the FTP server. Replace the in-PLC FTP with one of the following patterns, ordered by preference:
- PC-side script: A small VB.NET, PowerShell, or Python service on the HMI IPC reads the S7-1200 tags over S7 communication (PUT/GET or OPC UA) and writes the file via the OS FTP client. PLC memory impact: 0 KB. Cycle impact: 0 µs.
- WinCC Comfort/Advanced script: Use the HMI's built-in VBScript to dump tag values to a USB or network share. The script runs on the panel, not the CPU.
- SIMATIC IOT2050 / IPC227G: A node at the cell level that polls the PLC and handles file transfer, MQTT, and email independently.
3. Standard Library Blocks vs Custom Function Blocks
Every S7-1200 project pulls from the same global library set under Project > Libraries > Global Libraries > Standard Library. The temptation to re-invent these is the most common over-engineering vector.
| Re-invented feature | Standard block | Why the standard wins |
|---|---|---|
| Edge detection |
FP / FN operators, or R_TRIG / F_TRIG FBs from Standard Library |
Single instruction, vendor-tested, no instance DB overhead |
| On-delay / off-delay |
TP, TON, TOF IEC timers |
Same behavior as a custom counter-based timer; no risk of drift |
| Counter |
CTU, CTD, CTUD IEC counters |
Retentive variants available; no risk of overflow mishandling |
| PID control |
PID_Compact (S7-1200 V4+) |
Auto-tuning, anti-windup, bumpless transfer included; field-proven |
| Scale / unscale analog |
SCALE / UNSCALE in Basic Instructions |
Handles integer overflow and rounding correctly |
| Sequencer |
SCL_Sequencer in Standard Library (SCL) or step chains in GRAPH |
Inspector in TIA Portal shows active step; debug without breakpoints |
| File operations on S7-1200 |
FileReadC / FileWriteC (card-based, NOT FTP) |
Uses only the load memory; no TLS stack required |
The standard block is not just shorter code; it is also shorter time-to-diagnose. When a maintenance electrician sees TON with a 5 s PT input, they recognize it. When they see a custom FB named MySmartDelay_V3_DoNotUse, the diagnostic clock starts.
4. Ladder Logic for Maintainability: The 75-Rung vs 50-Rung Trade
A consistent finding across OEM programs is that a maintainable ladder program will use 50% more rungs than a "clever" sequencer, SFC, or function-block implementation of the same machine. The cost is in rung count; the benefit is in mean time to repair (MTTR).
4.1 The maintenance-driven write style
Three rules keep ladder diagnostic-friendly:
- One rung, one decision. A rung that sets three outputs makes a hunting fault impossible to trace. Split it.
-
Tag names describe the asset, not the function.
Conveyor_3_RunbeatsBit_M45_0. Maintainers talk about the conveyor, not about M45.0. - Sequential order matches physical order. Power flow runs left-to-right, top-to-bottom. Align the scan with the process flow so the maintenance technician can read the program in the same order as the machine layout.
4.2 When SFC / GRAPH is justified
Use SFC (or S7-GRAPH) only when the machine has ≥ 30 sequential steps and the step transitions are the primary diagnostic indicator. A typical 3-station rotary indexer is better in ladder; a 12-station assembly dial with 80 steps, alternate paths, and manual mode belongs in SFC. Reference: S7-GRAPH V5.5 / TIA Portal Programming Manual.
5. PC-Based Alternatives for Non-Control Functions
The 50% work-memory figure for the S7-1200 FTP case is not a bug; it is the correct cost of fitting a general-purpose TLS/TCP stack on a controller without a memory management unit. The PLC has higher-value work to do. Push non-deterministic tasks off the controller.
5.1 VB.NET data logger against an S7-1200
A minimal VB.NET example using the Sharp7 library (open-source, MIT-licensed) reads tags over ISO-on-TCP and writes to a CSV. This is the recommended replacement for the in-PLC FTP scenario.
' Add NuGet package: Sharp7
Imports Sharp7
Module PlcDataLogger
Sub Main()
Dim client As New S7Client()
Dim result = client.ConnectTo("192.168.0.1", 0, 1, 0)
If result <> 0 Then
Console.WriteLine($"Connect failed: {result}")
Return
End If
Dim buffer(19) As Byte
Dim tagNames = {"DB1.DBD0", "DB1.DBD4", "DB1.DBD8"}
Dim sw = IO.StreamWriter("C:\Logs\S71200_data.csv", True)
sw.WriteLine("Timestamp,Pressure_kPa,Flow_Lpm,Temp_C")
While True
client.DBRead(1, 0, 20, buffer)
Dim pressure = BitConverter.ToSingle(buffer, 0)
Dim flow = BitConverter.ToSingle(buffer, 4)
Dim temp = BitConverter.ToSingle(buffer, 8)
sw.WriteLine($"{DateTime.Now:o},{pressure:F2},{flow:F2},{temp:F2}")
Threading.Thread.Sleep(1000)
End While
End Sub
End Module
The PLC side requires PUT/GET to be enabled under CPU Properties > Protection > Permit access with PUT/GET or, for production, an explicit OPC UA server on the S7-1215C with firmware 4.4+. Either way, the in-PLC work memory cost is zero.
6. Standards and Code Consistency: OEM Templates vs One-Off Style
Automotive-tier OEMs run a separate "standard control" function that audits every program in PLCSIM before it is allowed near the line. The audit checks tag naming, FB structure, and approved material lists. Smaller OEMs and system integrators cannot afford that headcount, but they can adopt the same artifacts.
6.1 A minimal project standard for S7-1200
| Element | Convention | Example |
|---|---|---|
| Tag prefix | Asset code from the P&ID |
CV3 for control valve on line 3 |
| Digital input | DI_<asset>_<descriptor> |
DI_CV3_LS_OK (limit switch OK) |
| Digital output | DO_<asset>_<action> |
DO_CV3_OPEN |
| Analog input | AI_<asset>_<eng unit> |
AI_TK1_LEVEL_PCT |
| FB instance DB | Same name as the FB instance | iBeltStarter |
| HMI tag mirror | Same as PLC tag, no prefix | HMI reads DI_CV3_LS_OK directly |
Document the standard in a single Engineering Standard.docx checked into the project folder. Two pages is enough. Reference: TIA Portal Programming and Operating Manual.
6.2 Code review checklist before release
- Every FB has a single, documented purpose in its header comment.
- No magic numbers; constants live in a
ConstantsDB. - No unused instance DBs (TIA Portal will not warn; you have to look).
- No
ANYpointers unless the team has signed off on the dereferencing. - All alarms are in a single
HMI_AlarmsDB with consistent structure. - Cross-references generated and saved to PDF with the project archive.
7. Cycle Time Optimization: Reading the Diagnostic Buffer
Cycle time is the silent killer. A clean S7-1200 program on a 1214C runs OB1 in 5-10 ms. A program that "monitors every possible event" with high-frequency tasks, alarms on every transition, and trace blocks can push OB1 to 30-50 ms. For a machine with a 200 ms cycle budget, that 30 ms overhead is a 15% throughput loss.
7.1 Where to look in TIA Portal
- Open the online project and the device view of the CPU.
- Navigate to Online & Diagnostics > Diagnostic buffer. Cycle time overruns show as
Time error OB80entries. - Right-click the CPU in the project tree and select Online & Diagnostics > Cycle time / Memory. The current, minimum, and maximum OB1 time are displayed.
7.2 Reduction patterns
- Move slow logic out of OB1. Anything with a 100 ms+ period belongs in a cyclic OB (e.g., OB30 at 100 ms) or a hardware interrupt (OB40).
-
Replace index-based loops with explicit copy. A
FORloop over 200 array elements adds scan overhead per element. If the array is fixed, copy the operations as explicit rungs. -
Eliminate the
ANYvariant. Block moves withBLK_MOV/MOVE_BLKare faster than generic pointer copies. - Profile with the S7-1200 trace. Use Traces > Configuration > Trigger on OB1.start to capture the longest single-scan time over 1000 cycles.
8. CPU Sizing: Avoid the "Throw Hardware at It" Anti-Pattern
A common budgetary anti-pattern is to step up to a higher-CPU tier (e.g., S7-1215C to S7-1511) because the engineer cannot get OB1 under the cycle budget. The hardware is more expensive (often 2,000 EUR and up for the controller alone) and the symptom persists because the program is the bottleneck, not the silicon.
8.1 Sizing formula
For a deterministic cell with OB1 scan T_scan, IO count N_io, and target cycle time T_cycle:
T_scan_max = 0.5 * T_cycle # leave 50% headroom for diagnostics, alarms
T_scan_max >= N_io * t_bit # where t_bit is bit-instruction time (0.08 µs on 1214C)
For a 1,000-bit program on a 1214C, N_io * t_bit = 80 µs, well under any reasonable T_scan. The CPU has headroom; the program is the problem.
8.2 Decision matrix
| Symptom | First action | Escalate to CPU change? |
|---|---|---|
| OB1 scan > budget, work memory < 50% used | Refactor: move slow logic to cyclic OB, remove unused FBs | No |
| OB1 scan OK, work memory > 80% used | Replace custom code with library blocks; push FTP/HTTP off the PLC | Only if physical I/O count exceeds CPU channel limit |
| OB1 scan OK, work memory OK, but communication errors | Check PROFINET topology and update intervals | No |
| OB80 time-error entries under load | Lower OB1 priority work; consider S7-1511 if refactor fails | Yes, as a last resort |
9. Maintenance Handoff: Designing for the Aftermarket
A program that the original author finds readable is not the same as a program that a maintenance technician finds readable. The benchmark is not "can I read it"; it is "can a Level-2 electrician with no TIA Portal access on the line troubleshoot it in 30 minutes."
9.1 The 30-minute diagnostic target
Field data from OEMs that have moved from custom SFC to plain ladder shows downtime dropping from ~20 hours per week to ~2.5 hours per week on machines of similar complexity. The reduction is not because the ladder is more capable; it is because the technician can locate the failed step on a printout without launching TIA Portal.
9.2 Handoff artifacts
- Cross-reference printout: Project tree > Program blocks > right-click > Cross-references > Print to PDF.
- Bit-mapped HMI alarm screen: a single screen listing every active input, output, and tag in a 30-cell grid that the technician can read at a glance.
- Tag-name legend: a laminated legend at the panel mapping every tag prefix to the asset it represents.
- Backup archive: Project > Archive > Save As > .zap14 on the cabinet-mounted USB drive, dated.
10. Team Workflow: When to Go Rogue, When to Follow
The healthy boundary for an individual contributor is:
- Follow the standard when the standard exists, the requirement fits, and the project is on a deadline.
- Propose a change when the standard has measurable friction (e.g., tag prefix collision, OB1 scan growth). Bring numbers, not opinions.
- Build a proof of concept when the team needs data to choose. A 2-day spike that demonstrates a 30% scan-time reduction is a legitimate team investment; a 3-day deep-dive on FTP alternatives is not, when the production line does not have an FTP requirement.
- Never ship custom code that only you understand. The maintainability test is: can a colleague debug this on a Saturday at 2 AM?
11. Verification Procedure Before Release
Run this checklist on every program before it ships to commissioning:
- Compile clean. TIA Portal > Compile > Software (rebuild all). No warnings, no errors.
- Resource check. Online > CPU > Properties > Resource. Work memory used < 70% of total. Load memory < 80%.
- Cycle check. Run for 1 hour in PLCSIM with simulated I/O. Verify OB1 max scan < 50% of cycle budget. Zero OB80 entries in diagnostic buffer.
- Fault injection. Force each E-stop, light curtain, and safety gate; verify HMI alarm and proper shutdown state.
- Power-cycle test. Cycle power 3 times. Verify retentive tags recover, non-retentive reset, and the program returns to the same step as before power loss.
- Maintenance dry run. Hand the HMI and the ladder printout to a maintenance technician unfamiliar with the project. Time the diagnostic for a forced fault. Target: < 30 minutes to identify the root cause and reset.
- Cross-reference diff. Compare the shipped program against the last archived version. Every block change must have a code-review comment.
12. Failure Modes and Field Symptoms
| Symptom | Likely root cause | Corrective action |
|---|---|---|
| OB1 scan creeping up over months | Cumulative scope creep: added alarms, traces, hand-shake bits that were never removed | Run a quarterly audit; remove dead code |
| Work memory > 80% with no new features | Instance DBs not reused, custom FBs with deep nesting | Consolidate FBs; use multi-instance DBs |
| Diagnostic buffer full of OB80 time errors during peak demand | Synchronous communication (PUT/GET) or file operations on OB1 | Move to asynchronous via RDREC/WRREC or move to a cyclic OB |
| Maintenance calls the OEM weekly for the same line | Program not ladder-first; custom FBs and SFC not intuitive for the local skill set | Refactor critical diagnostic paths back to explicit ladder |
| HMI shows wrong units after a tag rename | Tag-name standard not enforced; HMI tags drifted from PLC tags | Use PLC tag as the single source of truth; remove HMI tag mirror |
| CPU swap required because cycle time exceeded | Over-engineered monitoring on OB1, not cycle-critical logic | Refactor: move monitoring to OB30 or to a PC-side script |
13. References Used in This Article
- SIMATIC S7-1200 Programmable Controller System Manual
- S7-1200 Module Data Manual (09/2023)
- STEP 7 / TIA Portal Programming and Operating Manual
- S7-GRAPH V5.5 / TIA Portal Programming Manual
- S7 Communication (PUT/GET) Application Examples
How much work memory does the S7-1200 FTP client actually consume?
On a CPU 1214C, the "Communication with FTP" library (FTP_CONNECT, FTP_OPEN, FTP_READ, etc.) typically consumes 40-60 KB of work memory, which is 40-60% of the 100 KB budget on that CPU. This single feature is often the trigger for stepping up to a 1215C or higher; the proper fix is to move file transfer to a PC-side application using S7 communication or OPC UA.
What is the maximum acceptable OB1 cycle time on an S7-1214C for a 200 ms machine cycle?
OB1 scan should stay below 100 ms (50% of the machine cycle), with a design target of 20-30 ms. Anything above 50 ms requires refactoring: move non-critical logic to cyclic OBs (OB30 at 100 ms), remove redundant monitoring, and replace generic pointer copies with explicit BLK_MOV operations.
Should I use SFC/S7-GRAPH or ladder logic for a 10-station assembly machine?
Use SFC/S7-GRAPH when the machine has 30+ sequential steps, alternate paths, and the step transitions are the primary diagnostic. For a 10-station machine with linear flow, plain ladder with one rung per physical step is faster to commission and easier for the maintenance team to diagnose. Reference the S7-GRAPH programming manual for the threshold guidance.
Can I disable PUT/GET on the S7-1200 and still move data to a PC?
Yes. Use the OPC UA server on the S7-1215C with firmware 4.4 or later. OPC UA provides authenticated, encrypted access without the security exposure of legacy PUT/GET, and it is the recommended path for new installations. Reference: TIA Portal OPC UA configuration manual.
What is the quickest way to identify which FB is consuming the most OB1 scan time on the S7-1200?
Use the S7-1200 trace: configure a trigger on OB1.start, capture the time stamp and a unique marker bit at the start of each candidate FB, and read the trace over 1000 cycles. The FB with the largest delta between its entry marker and exit marker is the bottleneck. Pair this with the diagnostic buffer for OB80 (time error) entries to confirm the priority.