Simulating S7-1200 Motor Speed Control in TIA Portal: Tutorial

David Krause12 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

1. Overview: Why Simulate Motor Speed on an S7-1200

The SIMATIC S7-1200 is a compact, scalable PLC that natively supports motion control through integrated technology objects (TOs). The CPU firmware exposes a configurable speed axis (TO_SpeedAxis) and positioning axis (TO_PositioningAxis) that can be wired, in real life, to PROFINET-controlled drives such as SINAMICS V90, V20, or third-party inverters speaking PROFIdrive. The same TOs, however, can be exercised in PLCSIM or PLCSIM Advanced without any physical hardware, which makes the platform an ideal training environment for engineers learning motion control, PID tuning, and HMI integration.

This reference covers a complete simulated motor-speed application built entirely around a CPU S7-1200 (tested in TIA Portal V17/V18/V19, firmware 4.4 / 4.5 / 4.6). The simulation runs in PLCSIM, so no SINAMICS, no servo drive, and no motor is required. The user can:

  • Enter a target speed (RPM) from the HMI.
  • Toggle the rotation direction (CW / CCW).
  • Start, stop, and reset the simulated motor.
  • Observe a real-time speed feedback curve on the HMI trend view.

The same project can later be re-pointed at a real SINAMICS V90 PN by simply swapping the drive in the device configuration and reassigning the TO's PROFIdrive telegram — no PLC code changes required.

Important: The S7-1200 does not drive a motor directly. In a real installation a frequency inverter (SINAMICS V20/V90, or a third-party drive on PROFINET with PROFIdrive profile 1/2/3/4) is always required between the PLC and the motor. The simulation described here replaces that drive with the PLCSIM runtime.

2. Prerequisites

Item Version / Catalog Purpose
STEP 7 (TIA Portal) V17, V18, or V19 Engineering framework
S7-1200 CPU CPU 1214C DC/DC/DC (6ES7214-1AG40-0XB0) or CPU 1215C Motion control capable target
CPU firmware V4.4 (or higher up to V4.6) Required for axis TO and PID_Compact V2
PLCSIM V17/V18/V19 (matches TIA) Hardware-free simulation runtime
HMI WinCC Comfort/Advanced on TIA Portal (simulated KTP700/1200) Operator panel
License TIA Portal Basic for S7-1200; PLCSIM is included Software activation

Before starting, install the latest HSP (Hardware Support Package) for your CPU so the device catalog reflects the current firmware. Verify the PID_Compact block is present in the Instructions tree under "Technology > PID Control" — it ships with every S7-1200 firmware V4.0 and later. Documentation for PID_Compact is published in the Siemens function manual at the S7-1200 PID Control entry.

3. S7-1200 Motion Control Fundamentals

The S7-1200 motion firmware is split into two layers:

  1. Technology objects (TOs) – software objects configured in TIA Portal that describe an axis (mechanics, limits, dynamics, encoder, drive interface).
  2. Motion control instructions – user-callable blocks in the program (for example MC_Power, MC_MoveVelocity, MC_Stop, MC_Reset) that operate on the TOs.

For a pure speed-control application the relevant TO is TO_SpeedAxis. It is a subset of the positioning axis and uses the same PROFIdrive telegram, but it does not manage position. When speed is set through MC_MoveVelocity, the TO outputs a normalized setpoint (N2 / Nset) that the drive converts to RPM. In PLCSIM, the telegram is internally emulated; the setpoint ramps in the simulation cycle and is read back as actual speed ActualVelocity on the TO's tag interface.

The base architecture looks like this:

HMI Tags        MC_xxx Instructions         TO_SpeedAxis
  (Speed_SP)  --> MC_MoveVelocity  -->  Axis.Setpoint
  (Dir)       --> MC_MoveVelocity  -->  Axis.Direction
  (Start/Stop)--> MC_Power         -->  Axis.Enable
                                   -->  ActualVelocity --> HMI

4. TIA Portal Project Setup

  1. Open TIA Portal and create a new project: Project > New > Name = "S7-1200_SpeedSim".
  2. Add a new device: Add new device > Controllers > SIMATIC S7-1200 > CPU 1214C DC/DC/DC > 6ES7214-1AG40-0XB0 > V4.4.
  3. Add an HMI: Add new device > HMI > SIMATIC HMI > KTP700 Basic PN. WinCC Comfort/Advanced is required for trend views.
  4. Create an HMI connection from the HMI to the S7-1200 (default: PROFINET, slot 1, TSAP 03.01).
  5. Save the project. The device view should show the CPU with PROFINET interface PN_1 and the HMI on the same subnet.
Network tip: Place both the CPU and HMI on subnet 192.168.0.0/24. The S7-1200 default IP is 192.168.0.1; the HMI may be set to 192.168.0.10. PLCSIM does not require any IP change.

5. Configuring the TO_SpeedAxis Technology Object

  1. In the project tree, expand CPU_1214C > Technology objects > Add new object > Motion Control > TO_SpeedAxis.
  2. Name the object Axis_Motor. Click Configuration on the toolbar.
  3. Basic parameters:
    • Axis name: Axis_Motor
    • Drive: leave as Simulation (the default for PLCSIM) — the wizard will set telegram type to Free telegram 1:1.
    • Encoder: Simulation
  4. Mechanics:
    • Load gear / motor gear: leave 1:1 for simulation purposes.
    • Maximum speed: 3000.0 RPM
    • Reference speed: 1500.0 RPM (used as the normalization base for N2 setpoint = 16384 dec)
  5. Dynamic limits:
    • Acceleration: 100.0 RPM/s
    • Deceleration: 100.0 RPM/s
    • Emergency stop deceleration: 500.0 RPM/s
  6. Limits:
    • Software limit switches: disabled (we are not using position)
    • Maximum torque / force: leave default 100%

The TO exposes a structure Axis_Motor.Config and a tag interface under Axis_Motor.<tag>. Useful tags:

Tag Data type Meaning
Axis_Motor.ActualVelocity LReal Measured speed in configured unit (RPM)
Axis_Motor.StatusWord Word Drive status word (bit 0 = enable, bit 2 = running, bit 7 = fault)
Axis_Motor.ErrorWord Word Active error code
Axis_Motor.Position LReal Position counter (rising with speed)

For background on the S7-1200 motion control architecture, see the Siemens function manual at the S7-1200 system manual entry.

6. Programming the Speed Control Logic

Open Program blocks > Main [OB1] and add the following instructions from the task card under Technology > Motion Control:

Network 1 – Enable the axis (MC_Power)


// Inputs
i_bEnable   : Bool   := "HMI".Start_Button
i_bStop     : Bool   := "HMI".Stop_Button
i_bAck      : Bool   := "HMI".Ack_Button
// Output
q_bAxisOn   : Bool
q_bError    : Bool

MC_Power_DB(
    Axis        := "Axis_Motor",
    Enable      := i_bEnable AND NOT i_bStop,
    StopMode    := MC_StopMode#EMERGENCY_STOP,
    Status      => q_bAxisOn,
    Busy        =>,
    Error       => q_bError,
    ErrorID     =>);

Network 2 – Run at commanded speed (MC_MoveVelocity)


i_lrSpeedSP   : LReal := "HMI".Speed_SP       // 0 .. 3000 RPM
i_bDirCW      : Bool  := "HMI".Direction_CW
i_bRunCmd     : Bool  := "HMI".Start_Button

MC_MoveVelocity_DB(
    Axis        := "Axis_Motor",
    Execute     := i_bRunCmd,
    Velocity    := i_lrSpeedSP,
    Direction   := i_bDirCW ? MC_DIRECTION#POSITIVE : MC_DIRECTION#NEGATIVE,
    CurrentVelocity => "HMI".Speed_PV,
    Busy        =>,
    CommandAborted =>,
    Error       =>,
    ErrorID     =>);

Network 3 – Decelerated stop (MC_Stop)


MC_Stop_DB(
    Axis        := "Axis_Motor",
    Execute     := i_bStop,
    Deceleration:= 100.0,
    Jerk        := 0.0,
    Done        =>,
    Busy        =>,
    Error       =>);

Network 4 – Reset (MC_Reset)


MC_Reset_DB(
    Axis        := "Axis_Motor",
    Execute     := i_bAck,
    Restart     := FALSE,
    Done        =>,
    Busy        =>,
    Error       =>);
Direction change procedure: Toggling the direction bit while the axis is running does not automatically reverse the motor. You must (a) call MC_Stop and wait for Done, (b) call MC_Reset if a direction-change error is flagged, then (c) re-trigger MC_MoveVelocity with the new direction. The S7-1200 firmware will not ramp through zero automatically.

7. PID_Compact for Closed-Loop Speed Regulation

To make the simulation more realistic, wrap the manual speed setpoint in a PID_Compact loop. PID_Compact is included in every S7-1200 firmware V4.0+; see the official PID_Compact V2 documentation for parameter details.

  1. Drag PID_Compact from "Technology > PID Control" into OB1 and rename the instance DB to PID_Speed.
  2. Open the configuration editor: Configure > Basic settings > Setpoint / Process value scaling:
    • Input / output scaling: 0.0 to 3000.0 RPM
    • Setpoint source: Speed_SP (HMI tag)
    • Process value: Axis_Motor.ActualVelocity
    • Output: tied to Velocity input of MC_MoveVelocity (replace the HMI speed tag in Network 2)
  3. Run the PID_Compact commissioning tool: click the eye icon in the project tree to launch the watch table and tuning panel.
  4. Select "Pretuning" (one-shot step response) — in simulation, set the output to 1500 RPM for 5 s, then back to 0. PID_Compact will compute initial P, I, D values.
  5. Switch the mode selector to "Automatic mode" and validate with a step change from 1000 to 2000 RPM.

Typical starting parameters in simulation (light inertia, friction coefficient 0.05 N·m·s):

Parameter Symbol Starting value Range
Proportional gain Gain 1.20 0.5 .. 3.0
Integral action time Ti 2.0 s 0.5 .. 10.0 s
Derivative action time Td 0.0 s 0.0 .. 1.0 s
Deadband width DeadBand 2.0 RPM 0.0 .. 20.0

An academic study on the same control topology is published in Salkić (2022) on DC motor control with the S7-1200; the paper demonstrates open-loop RPM, PID, and position control and is a useful cross-check for the closed-loop values shown above.

8. HMI Configuration for Speed and Direction

  1. Open the HMI device configuration. Add the following tags to the HMI tag table:
HMI tag PLC tag Type Use
Speed_SP DB1.Speed_SP Real Setpoint slider, 0–3000 RPM
Speed_PV Axis_Motor.ActualVelocity LReal Numeric display + trend
Start_Button DB1.Start_Button Bool Start pushbutton (latched via PLC logic)
Stop_Button DB1.Stop_Button Bool Stop pushbutton
Ack_Button DB1.Ack_Button Bool Acknowledge fault
Direction_CW DB1.Direction_CW Bool Radio button: CW = 1, CCW = 0
Axis_On DB1.Axis_On Bool Indicator lamp "Drive enabled"
Axis_Error DB1.Axis_Error Bool Indicator lamp "Fault"
  1. Build a screen named Overview with the following objects:
    • Slider (0–3000, scaling x1) bound to Speed_SP
    • Numeric I/O field bound to Speed_SP with display format 9999.9
    • Two radio buttons: CW (writes 1 to Direction_CW) and CCW (writes 0)
    • Pushbutton "Start" (write 1 to Start_Button, edge-triggered)
    • Pushbutton "Stop" (write 1 to Stop_Button)
    • Pushbutton "Ack" (write 1 to Ack_Button)
    • Trend view, two pens: Speed_SP (red) and Speed_PV (green), 30 s window
  2. Add a status bar at the bottom driven by Axis_Motor.StatusWord: bit 0 → "Drive ready", bit 2 → "Running", bit 7 → "Fault".
  3. Configure the connection — HMI > Connections > default HMI_Connection_1 must point to the S7-1200 on the same subnet.

9. PLCSIM Simulation Procedure

  1. Compile the PLC: Right-click CPU_1214C > Compile > Software (rebuild all). The result window must show "0 errors, 0 warnings".
  2. Compile the HMI: Right-click HMI_1 > Compile > Software (rebuild all).
  3. Start the PLCSIM instance: Online > Start Simulation > PLCSIM. Choose the local S7-1200 target. The PLCSIM panel opens.
  4. Download to PLCSIM: Online > Download to device. Accept the default PN/IE interface.
  5. Start the HMI runtime: Right-click HMI_1 > WinCC Runtime > Start.
  6. Test sequence:
    1. Click Start on the HMI. The "Drive enabled" lamp should turn green within 100 ms.
    2. Set slider to 1500 RPM, click Start again. Speed_PV should ramp from 0 to 1500 in ~15 s (acceleration 100 RPM/s).
    3. Toggle direction to CCW. The axis should run MC_Stop, settle to 0, then re-launch in CCW with the same setpoint.
    4. Click Stop. The motor decelerates at 100 RPM/s to 0.
PLCSIM V18+ behavior: When the drive is set to Simulation in the TO, PLCSIM fully emulates the telegram handshake. If you see error F0161 (Telegram failure) in the online diagnostics, regenerate the drive in the device view and recompile.

10. Verification and Commissioning Checklist

# Check Expected result
1 MC_Power enables the axis Axis_Motor.StatusWord.0 = 1 within 200 ms
2 Setpoint 0 → 1500 RPM ActualVelocity reaches 1498 .. 1502 RPM within 20 s
3 Direction change CW → CCW ActualVelocity crosses 0, settles to 1500 RPM, sign flips
4 Stop pushbutton ActualVelocity = 0 within 20 s, StatusWord.0 still 1
5 PID_Compact step 1000 → 2000 RPM Overshoot < 5%, settling time < 10 s, no steady-state error
6 Fault injection (set Velocity to 5000 RPM) Axis_Error = 1, StatusWord.7 = 1, axis decelerates to 0
7 Ack fault Axis_Error resets, drive is re-enabled

For a final acceptance test, use the online watch table to log Speed_SP, Speed_PV, and PID_Speed.Output at 100 ms intervals over 60 s. Export the CSV and plot in Excel/MATLAB to validate the rise time, overshoot, and steady-state error.

11. Troubleshooting Matrix

Symptom Likely cause Remedy
Axis won't enable; StatusWord.0 = 0 MC_Power not called cyclically, or StopMode mismatch Move MC_Power into OB1 (not OB100); verify StopMode is EMERGENCY_STOP
Speed stays at 0 after Start MC_MoveVelocity not re-triggered on rising edge Use a one-shot (P-trig) of Start_Button into Execute
Axis reports "Configuration error" 0x8401 Reference speed inconsistent with max speed Set Reference ≤ Maximum in TO configuration
Direction toggle does not reverse motor MC_Stop not issued before changing Direction Add interlocks: Run direction-change sequence in SCL/GRAPH
PID_Compact output saturates at 100% Gain too high, or process value not updating Verify process value wiring; reduce Gain by 50% and re-tune
HMI shows "No connection" Subnet mismatch or HMI tag DB index wrong Verify both devices on 192.168.0.0/24; re-link tags
Download to PLCSIM fails with 0xE004 PLCSIM instance already in RUN Stop the PLCSIM panel first, then re-download

12. Migrating the Simulation to Real Hardware

When the simulated behavior matches the specification, the project is migrated to a real drive by:

  1. Adding the drive in the device view (e.g., SINAMICS V90 PN, article number 6SL3210-5FE10-4UA0 for 0.4 kW).
  2. Connecting the V90 to the S7-1200 PROFINET network.
  3. In the TO configuration, changing the drive from Simulation to the real V90, telegram 1 (standard telegram 1 for PROFIdrive).
  4. Re-running the wizard — the TO will regenerate the PROFIdrive telegrams and the HMI tags stay valid.
  5. Recompiling and downloading. The MC_Power / MC_MoveVelocity / MC_Stop code in OB1 does not need to change.

The same flow works for any PROFINET drive that supports PROFIdrive profile 1, 2, 3, or 4 (Siemens, ABB, Schneider, Yaskawa GA500, etc.). For drives on other buses (EtherCAT, Modbus TCP), replace MC_MoveVelocity with a custom block that writes the RPM setpoint into a holding register — see the S7-1200 Modbus TCP function manual at the S7-1200 system manual.

Safety: Before the first real-axis test, verify the motor is decoupled from any mechanical load, the drive's STO (Safe Torque Off) inputs are wired, and the emergency-stop circuit is functional. A PLC simulation cannot validate the safety chain.

FAQ

Can an S7-1200 control a motor without any drive?

No. The S7-1200 only outputs digital or PROFINET signals. A frequency inverter (SINAMICS V20/V90, or any third-party drive on PROFINET with PROFIdrive profile) is always required between the PLC and the motor. The simulation in PLCSIM replaces that drive for training purposes only.

Which S7-1200 firmware is required for TO_SpeedAxis and PID_Compact?

TO_SpeedAxis is supported from firmware V4.0 onward. PID_Compact (V2.x) is available from V4.0 as well. For current feature parity (PROFIdrive telegram 1:1 free mapping, PID_Compact V2.3 tuning assistant) use V4.4 or later.

How do I reverse the rotation direction of the simulated motor?

Issue MC_Stop, wait for Done, then re-trigger MC_MoveVelocity with the new Direction input. The S7-1200 firmware does not ramp through zero automatically, so a structured sequence (Stop → Reset → MoveVelocity) is required.

Why does my axis stay at 0 RPM even though MC_Power returns status 1?

MC_Power only enables the drive. The actual motion is started by MC_MoveVelocity, which requires a rising edge on the Execute input. Wrap the Start pushbutton with a P_TRIG before connecting it to MC_MoveVelocity.Execute.

Can the same program be used on a real SINAMICS V90 later?

Yes. Replace the simulated drive in the device configuration with a real SINAMICS V90 PN, regenerate the technology object, and recompile. The PLC code (MC_Power, MC_MoveVelocity, MC_Stop, MC_Reset) does not change. Only the hardware address of the drive and the firmware version are updated.

Back to blog