Building S7-1200 Motor, Valve, and Analog Blocks in TIA Portal

David Krause17 min read
S7-1200SiemensTutorial / How-to
Licensed PE Working through this on a live machine? A Maine-licensed engineer can take it from here — included with IMD hardware, by the hour for everything else. Book an engineer

Building S7-1200 Motor, Valve, and Analog Blocks in TIA Portal V14

This technical reference walks through the design of three reusable standard blocks for the SIMATIC S7-1200 CPU programmed in TIA Portal V14: a motor block, a solenoid/pneumatic valve block, and an analog I/O processing block. All logic is implemented in Ladder Diagram (LAD). The reference addresses a common field question: STL (Statement List) is not supported on the S7-1200 family, so engineers migrating from S7-300/400 must restructure their block libraries to use LAD or Function Block Diagram (FBD) on Siemens Industry Online Support.

STL is not available on S7-1200 CPUs. Firmware from V1.0 onward exposes only LAD and FBD as the IEC 61131-3 textual/graphical editors in TIA Portal. SCL (Structured Control Language) is available as an optional package and can be used for math-heavy code, but the bulk of standard I/O blocks should remain in LAD for maintenance visibility.

1. Block Architecture on S7-1200

Before writing any logic, define the block hierarchy. The S7-1200 supports the standard SIMATIC block set: Organization Blocks (OB), Function Blocks (FB), Functions (FC), and Data Blocks (DB). Background OB and time-of-day OB interrupt classes are inherited from the S7-300/400 model and behave identically from the engineer's perspective. The official programming reference defines how called blocks are invoked and how their local data is exchanged through an Instance DB for each FB call. See Calling blocks from within your program in the S7-1200 manual collection.

Block Type Retains memory Typical role on S7-1200
OB1 (Main) Organization Block No Cyclic main sweep; calls FB instances
OB82 / OB83 / OB86 Organization Block No Diagnostic, module pull, rack fault
FB_Motor, FB_Valve, FB_Analog Function Block Yes (Instance DB) Standard library functions with state
FC_Scale, FC_Debounce Function No Stateless math/utility
DB_Global Global Data Block Yes (configurable) Project-wide tags, recipes, setpoints
iDB per call Instance Data Block Yes One per FB invocation

Use FBs with Instance DBs for any block that must remember state across scans: latched motor starters, valve open requests, last-good analog values, fault latches. Use FCs for pure functions: scaling, debounce, moving data. Mixing the two keeps each block's retentivity behavior predictable and minimizes the global tag namespace.

2. Prerequisites

  1. STEP 7 Basic/Professional V14 (TIA Portal V14) with the S7-1200 CPU support package installed.
  2. S7-1200 CPU with firmware V4.0 or later recommended for full TIA V14 feature set (LAD/FBD instruction set is identical from V1.0, but the LGF requires V4.x for some blocks).
  3. Signal modules: SM 1223 DI16/DQ16 for digital motor/valve I/O, SM 1231 AI4/AI8 or SM 1232 AQ2/AQ4 for analog channels.
  4. Library of General Functions (LGF) for SIMATIC STEP 7 (TIA Portal) and S7-1200/S7-1500 imported as a global library. The LGF is a Siemens-shipped set of reusable FBs/FCs covering motor, valve, analog, and PID primitives.
If a project migrates from an S7-300 STL library, do not attempt to import the STL sources. Re-implement the same control philosophy in LAD so maintenance technicians can read the logic on the Web server of the CPU or from the HMI backup.

3. State Machine for Motor and Valve Blocks

Field equipment rarely operates as a simple on/off. Real-world control requires an equipment module to switch between four operator intent states plus two running states. The standard model used in IEC 61131-3 packaging and ISA-88 batch terminology is:

Mode Source of commands Typical use
Local Hard-wired pushbutton at the MCC Maintenance, commissioning, override of all software
Manual HMI/SCADA start-stop, no sequence Operator-driven single equipment module
Auto Sequencer / recipe from the PLC Production, interlocking, batch logic
Remote Plant SCADA via S7 communication Supervisory control from a higher-level system

The state machine is implemented in FB_Motor and FB_Valve as a flat 4-way selector. The selected mode routes Start/Stop/Close/Open requests to the actuator. Local mode always wins, even if the HMI is in Auto. This protects the technician at the cabinet from being overridden by software.

4. FB_Motor Block Design

The motor block is the workhorse of the standard library. It is reused for conveyors, pumps, fans, and mixers with only the I/O mapping changing. The block exposes a clean Input/Output/InOut/Static/Const interface so the HMI can be wired once and reused across the plant.

4.1 Block Interface

Section Name Type Direction Initial / Meaning
Input iStart_Cmd Bool IN Start request from selected mode
Input iStop_Cmd Bool IN Stop request (always honored)
Input iAux_OK Bool IN Permissive: overload healthy, MCC door closed
Input iRun_Fdbk Bool IN Contactor or VFD ready signal
Input iLocal_Mode Bool IN Local/Off selector at the cabinet
Input iManual_Mode Bool IN HMI manual selector
Input iAuto_Mode Bool IN Auto request from sequencer
Output oMotor_Cmd Bool OUT Coil driver to the contactor
Output oRunning Bool OUT True when iRun_Fdbk is on
Output oFault Bool OUT Latched fault
Output oMode_Active Int OUT 0=Off, 1=Local, 2=Manual, 3=Auto
InOut ioHMI_Ctrl Struct IN_OUT HMI tag cluster (start PB, stop PB, reset, mode)
Static sFault_Latch Bool STAT Retentive fault bit
Static sStart_Latch Bool STAT Run seal-in
Static sRun_Timer TIME STAT Elapsed run time, accumulated
Const kStart_Delay TIME CONST 2 s max to receive Run feedback

4.2 Network-by-Network LAD Logic

Each network is a short segment of ladder. The actual editor view is graphical; the text below describes each rung for engineers who need to read the logic in plain language or reproduce it in another LAD editor.

  1. Network 1: Mode arbitration. A priority encoder selects the active mode. Local wins over Manual, which wins over Auto. Wire iLocal_Mode in series with the start request through a normally-closed iStop_Cmd. Manual is selected only when iManual_Mode is true and iLocal_Mode is false. Auto fills the remaining case. The result is latched in a static sMode_Word and mirrored to oMode_Active for the HMI faceplate.
  2. Network 2: Start seal-in. When the active mode is Local, Manual, or Auto and iStart_Cmd is true and iStop_Cmd is false and iAux_OK is true, set sStart_Latch. The latch holds itself through an OR contact parallel to the start path. sStart_Latch drops when iStop_Cmd, the trip from iAux_OK, or the fault clear is asserted.
  3. Network 3: Coil output. oMotor_Cmd := sStart_Latch AND NOT oFault. The fault gate is critical: a latched fault must drop the coil instantly, even if the operator is still pressing start.
  4. Network 4: Feedback watchdog. When oMotor_Cmd goes high, start a TON with PT = kStart_Delay. If iRun_Fdbk fails to arrive within the preset, set oFault and latch sFault_Latch. The same timer resets when the command drops.
  5. Network 5: Stop seal-out. When oMotor_Cmd is high and iRun_Fdbk stays high after a TOF of 1 s, generate a "stuck contactor" fault. This catches welded contactor contacts on the field side.
  6. Network 6: Fault reset. A rising edge on ioHMI_Ctrl.Reset clears sFault_Latch only when iAux_OK and the stop request are both present. Never allow a reset while the start command is held.
  7. Network 7: Running flag and runtime accumulator. oRunning := iRun_Fdbk AND NOT oFault. Add the OB1 cycle time (typically 10 ms to 100 ms) to sRun_Timer while oRunning is true. This gives a maintenance-visible runtime in seconds without a separate counter DB.

4.3 Calling FB_Motor from OB1

Each physical motor is one instance. Drag FB_Motor from the program blocks tree into Network 1 of OB1, then assign a unique Instance DB (e.g., iDB_Motor_101). Wire the inputs from the I/O symbols and HMI tags. Reuse the same block for every motor in the project. The HMI faceplate is bound to ioHMI_Ctrl, so the same WinCC Comfort/Advanced faceplate works for all instances.

Multi-instance tip. If the project is large, declare a parent FB (e.g., FB_Area_100) and place all motors in that area as multi-instances inside the parent's Instance DB. This consolidates the DB count and lets a single area-level fault propagate up the hierarchy.

5. FB_Valve Block Design

The valve block is structurally similar to the motor block but with two stable states (Open, Closed) and two feedback inputs (Open limit switch, Closed limit switch). The same Auto/Manual/Local arbitration applies. The differences are in the fault logic: a valve that fails to reach its commanded position within a configurable travel time is a "position fault," distinct from the motor's "failed to start" fault.

5.1 Block Interface (delta from FB_Motor)

Name Type Meaning
iOpen_Cmd / iClose_Cmd Bool Position request from selected mode
iOpen_Fdbk / iClose_Fdbk Bool Limit switch feedback (mechanical or prox)
oOpen_Cmd / oClose_Cmd Bool Solenoid coil drivers
oPosition Int 0=Unknown, 1=Open, 2=Closed, 3=Transit
kOpen_Time, kClose_Time TIME Maximum travel time for that valve

5.2 Travel Time Watchdog

Each direction uses an independent TON. When oOpen_Cmd rises, start TON_Open with PT = kOpen_Time. If iOpen_Fdbk does not rise before PT expires, latch a position fault. The same logic applies on close. The two timers are mutually exclusive: only one command can be active at a time, enforced by an interlock in the output network.

5.3 Inferred Position

When feedback is healthy, oPosition equals the commanded position after a 200 ms debounce. If both limit switches are off (mid-travel), oPosition = 3 (Transit). If both are on (fault condition, indicates bad wiring or a stuck limit), latch oFault immediately. The valve faceplate on the HMI reflects the inferred position rather than the raw command, which is what the operator expects.

6. FB_Analog Block Design

The analog block converts the raw integer from the SM 1231 AI module into engineering units (EU) and back into the integer for the SM 1232 AQ module. TIA Portal V14 already includes the NORM_X and SCALE_X instructions, but they expect normalized real values; the FB handles the full 0..27648 range used by S7-1200 analog modules and the optional bipolar -27648..27648 range for ±10 V or ±20 mA signals.

6.1 Scaling Formula

The standard linear mapping is:

EU = ((Raw - Raw_min) / (Raw_max - Raw_min)) * (EU_max - EU_min) + EU_min

For unipolar 0..27648 with EU_min = 0 and EU_max = 100, this reduces to EU = Raw / 276.48. For a 4..20 mA input mapped to 0..100 °C, Raw_min = 5530 (4 mA) and Raw_max = 27648 (20 mA), so the formula becomes EU = ((Raw - 5530) / 22118) * 100.

6.2 Wire-Break and Overflow Detection

The SM 1231 sets specific raw values for diagnostic events. The block checks for these explicitly:

Raw value (unipolar) Meaning Action
32767 (0x7FFF) Overflow / overrange Set oHigh_Fault
-32768 (0x8000) Underflow / underrange Set oLow_Fault
32512 (0x7F00) Wire break on 4..20 mA / RTD open Set oWireBreak

These constants are documented in the SM 1231 / SM 1232 chapters of the S7-1200 system manual. The block must debounce the diagnostic value for at least two OB1 cycles to avoid nuisance trips during module startup.

6.3 Block Interface

Name Type Direction Meaning
iRaw Int IN Channel value from SM 1231
iRaw_Min / iRaw_Max Int IN Calibration endpoints
iEU_Min / iEU_Max Real IN Engineering unit endpoints
iBipolar Bool IN True for ±10 V / ±20 mA
oEU Real OUT Scaled engineering unit
oHigh_Fault / oLow_Fault / oWireBreak Bool OUT Diagnostic flags
sLast_Good Real STAT Retentive last good value

6.4 Network Sequence in LAD

  1. Network 1: Range check. Compare iRaw against 32512, 32767, and -32768. Output the appropriate diagnostic bit. The diagnostic value (>= 32512) must be debounced with a TON of 0.5 s to reject module startup pulses.
  2. Network 2: Bipolar guard. If iBipolar is true, swap iRaw_Min to -27648 and iRaw_Max to +27648 internally. Otherwise default to 0..27648.
  3. Network 3: Conversion guard. Block any division by zero: if (iRaw_Max - iRaw_Min) = 0, set oEU to sLast_Good and a config fault. This catches engineering errors in the instance DB at runtime rather than letting the CPU go to STOP.
  4. Network 4: Subtract and divide. Use SUB (Real) and DIV (Real) instructions to compute ((iRaw - iRaw_Min) / (iRaw_Max - iRaw_Min)). The intermediate result is a Real between 0.0 and 1.0.
  5. Network 5: Scale to EU. Use MUL and ADD to apply EU range. Clamp the final value to [iEU_Min, iEU_Max] using MIN and MAX instructions to defend against out-of-range raw values that pass the diagnostic filter.
  6. Network 6: Update last-good. When no diagnostic is active, copy oEU to sLast_Good. The retentive tag survives CPU restart so the HMI can display a sane value immediately after power-up.

7. Library of General Functions (LGF) Reference

Before writing any block from scratch, install the Siemens-shipped Library of General Functions (LGF) for SIMATIC STEP 7 (TIA Portal) and S7-1200 / S7-1500. The LGF provides vetted versions of motor, valve, analog, and PID primitives, all written in LAD/FBD/SCL. The library is distributed via Siemens Industry Online Support and can be opened as a global library in TIA Portal. The LGF is the recommended starting point because:

  • The blocks have been bench-tested and field-validated across hundreds of installations.
  • They expose a consistent tag interface across the motor, valve, and analog categories, so HMI faceplates can be generic.
  • Siemens maintains the library across TIA Portal versions, so a project upgrade from V14 to V15/V16/V17 requires only re-compilation, not rewriting.
  • The license terms permit modification for in-house use, so the standard blocks can be extended with project-specific interlocks while keeping the proven core intact.

Use the LGF blocks as a template: copy the LGF block into your project master copy library, rename it (e.g., LGF_Motor -> S7_1200_Motor), and modify the additional features you need. This avoids reinventing the watchdog, debounce, and fault-latch logic and keeps your custom code reviewable against the Siemens reference.

8. HMI Faceplate Integration

All three blocks share the same HMI control cluster concept. Define a UDT_HMI_Ctrl in the PLC with a fixed layout: Start PB, Stop PB, Reset PB, Mode selector, Mode_Local bit, Mode_Manual bit, Mode_Auto bit, Fault, Warning, Running, Mode_Active (Int). Create a WinCC Comfort/Advanced faceplate bound to the UDT. Then the faceplate can be instanced against any motor, valve, or analog channel simply by changing the tag prefix. This is the same pattern used in the LGF faceplates.

Faceplate element Tag binding (PLC side) Animation
Start button ioHMI_Ctrl.Start_PB Visible only when Mode = Manual or Auto
Stop button ioHMI_Ctrl.Stop_PB Always visible
Mode selector ioHMI_Ctrl.Mode_Sel Local locked by key switch in PLC
Running indicator oRunning Color change on state
Fault banner oFault Visible only when true

9. Calling Blocks from Your Program

The S7-1200 programming manual describes how the CPU enters OB1 on every cycle, evaluates Network 1 to Network N in order, and when it encounters a call to an FB or FC, it pushes the current program counter onto the call stack, opens the called block, executes its networks, and returns to the next network of the caller. Each call to an FB requires an Instance DB; each call to an FC uses the caller's local stack. The official reference is the chapter Calling blocks from within your program in the S7-1200 manual collection, which contains the canonical call-stack diagram and the difference between single-instance and multi-instance FBs.

Two practical rules follow from that reference:

  1. Order your OB1 networks so that safety-related FBs (E-Stop, guard interlock) are called before motor FBs that depend on them. Ladder evaluates networks sequentially; a downstream motor block cannot see a permissive computed in a later network within the same cycle.
  2. Never call an FB conditionally with a jump or skip. The Instance DB is only updated when the call executes, so a motor that is "skipped" will retain stale state and may behave unpredictably when the call returns. Use the mode arbitration inside the FB instead.

10. Verification and Commissioning

After the blocks are compiled, follow this sequence in the TIA Portal V14 online view:

  1. Compile all blocks. Resolve any "tag not declared" or "type mismatch" warnings before downloading. Warnings on the LGF blocks usually indicate a missing Instance DB or a TIA Portal version mismatch.
  2. Download to the CPU. Use a consistent STOP/RUN download if the program structure changed. Hot reload of new FB types is not supported on S7-1200.
  3. Go ONLINE in OB1. Confirm the motor, valve, and analog FBs are called in the expected order and that each Instance DB exists with the expected static tags.
  4. Force-test each mode. From the watch table, set iLocal_Mode, iManual_Mode, and iAuto_Mode one at a time. Verify that the start command in the corresponding mode reaches oMotor_Cmd and that mode arbitration prevents two modes from being active simultaneously.
  5. Fault injection. Force iRun_Fdbk low while the motor is commanded; verify that the start watchdog trips within kStart_Delay. For valves, force iOpen_Fdbk low during a commanded open; verify the position fault latches. For analog, force iRaw to 32512; verify the wire-break flag and that sLast_Good retains the previous good value.
  6. HMI faceplate check. Open the HMI project in WinCC Comfort/Advanced runtime. Verify the faceplate starts in Off mode, responds to local selector, and that the fault banner appears and clears only on reset with permissive.

11. Troubleshooting Matrix

Symptom Likely root cause Block to inspect Remediation
Motor does not start, no fault, coil not energized Mode arbitration returning Off FB_Motor Network 1 Verify iLocal_Mode, iManual_Mode, iAuto_Mode wiring; check selector on HMI faceplate
Motor starts in PLC, contactor pulls, no Run feedback Wiring error on aux contact or VFD ready FB_Motor Network 4 Check iRun_Fdbk terminal; increase kStart_Delay if VFD ramp is slow
Fault latches immediately on every start Reset held while start is asserted FB_Motor Network 6 Reset must pulse; ensure ioHMI_Ctrl.Reset is edge-triggered
Valve reports Transit forever Both limit switches wired normally-open vs. normally-closed swapped FB_Valve Network for inferred position Confirm limit switch polarity; the block expects NC for safe state
Analog reading sticks at last value Wire-break or overflow; sLast_Good is updating the display FB_Analog Network 1 and 6 Check iRaw for 32512 / 32767; inspect the SM 1231 channel diagnostics in the device view
CPU goes to STOP on first cycle after download OB1 has a call to an FB without a valid Instance DB OB1 call site Right-click the call, choose "Call options > Instance DB > New"; recompile
Edit fails: "STL not supported" Residual STL source from an S7-300 import Source file Re-implement the block in LAD or FBD; do not paste STL into S7-1200 sources
Multi-instance DB does not appear in project tree Parent FB has no STAT declarations of the child FB Parent FB interface Declare a STAT of the child FB type, e.g., STAT Motor_101 : FB_Motor

12. Performance and Cycle Time Considerations

On an S7-1200 CPU 1214C DC/DC/DC with 50 motor instances, 30 valve instances, and 20 analog instances, the typical OB1 execution time is in the 8 ms to 15 ms range. The dominant cost is the Instance DB access for the static tags of the FB calls. Two optimizations help when the count grows:

  • Group equipment that is always operated together into a single area FB with multi-instances. The compiler can hoist the call overhead.
  • Use cyclic interrupt OB (OB30 to OB38) at a slower phase, say 100 ms, for non-critical interlocks. The default OB1 stays at 10 ms for fast protection logic.
Never run the motor and valve FBs in OB1 if their cycle time can be longer than 100 ms. Watchdogs with 1 s to 2 s presets tolerate this, but faster safety paths (E-Stop, guard door) must remain on the main OB.

Can I use STL statements inside an S7-1200 FB?

No. STL is not part of the S7-1200 instruction set in TIA Portal V14. Re-implement the block in LAD or FBD, or use SCL for the math-heavy sections. STL sources from S7-300 projects must be converted before they will compile on an S7-1200.

Do I need a separate Instance DB for every motor, or can I share one?

Each FB call must have its own Instance DB. Sharing a single Instance DB across calls would cause one motor's state to overwrite another's. Use a multi-instance parent FB to consolidate many FB instances into a single DB at the project level.

What raw value indicates a wire break on the SM 1231 4..20 mA input?

32767 (0x7FFF) is the overrange / overflow value, -32768 (0x8000) is the underrange value, and 32512 (0x7F00) is the wire-break / open-circuit value. The FB_Analog block checks all three and latches the corresponding fault flag.

How do I prevent Local mode from being switched to Auto by the HMI?

Treat the local selector at the cabinet as the highest-priority input. In the mode arbitration network of FB_Motor, evaluate iLocal_Mode before any other mode. The HMI should only display the active mode, not control it, when the cabinet selector is in Local. Add a key switch or supervisor tag in the HMI to allow software override of the cabinet selector only with an explicit authentication step.

Where can I download a vetted starting-point implementation of these blocks?

Use the Library of General Functions (LGF) for SIMATIC STEP 7 (TIA Portal) and S7-1200/S7-1500 from Siemens Industry Online Support. Copy the LGF blocks into a project master copy library, rename them to your naming convention, and add the project-specific interlocks on top. The LGF blocks include the watchdog, debounce, and fault-latch logic described in this article, so you do not need to re-validate it from scratch.

Back to blog