Configuring PID Autotuning from HMI in TIA Portal V14 SP1

David Krause14 min read
SiemensTIA PortalTutorial / 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

Configuring PID Autotuning from HMI in TIA Portal V14 SP1 on S7-1200

1. Overview

Pressure-control loops drift as process gain, dead time, and load profile change. A controller tuned once at commissioning rarely stays optimal for the life of the line, so the operator must be able to re-trigger PID autotuning from the HMI without a programmer present. On a SIMATIC S7-1200 CPU 1212C running TIA Portal V14 SP1 Update 8 with a TP900 Comfort panel, the closed-loop regulator block PID_Compact (FB 1139, DB 1139 instance) ships with an integrated pretuning and fine-tuning routine that can be started from a single mode-select input. Wiring that input to a tag and exposing the tag to a TP900 button is the cleanest, most supportable path.

The official Siemens sample project "PID Control with PID_Compact V13 SP1" (entry ID 100746401) demonstrates exactly this HMI-driven autotuning flow. The V13 SP1 project is the lowest revision that will upgrade into V14, so it remains a useful starting template even when the active engineering station is V14 SP1 Update 8.

2. Prerequisites

Item Specification Notes
CPU SIMATIC S7-1200 CPU 1212C DC/DC/DC or DC/DC/RLY (6ES7212-1xxxxx-0XB0) Firmware V4.x supports PID_Compact autotuning
HMI SIMATIC TP900 Comfort (6AV2124-1JC01-0AX0) Comfort panels ship with WinCC Comfort V14 SP1
Engineering SW STEP 7 Basic V14 SP1 Update 8 (6ES7822-0AA04-0YA5 or current) Update 8 is the last V14 SP1 release
Analog input SM 1231 AI4 or onboard AI0 of CPU 1212C (0-10 V or 4-20 mA) Pressure transmitter wired to AI
Analog output SM 1232 AQ2 or onboard AQ0 (0-10 V / 4-20 mA) Drives proportional valve or VFD reference
Sensor supply 24 V DC stabilized, 0.5 A minimum headroom Common-mode isolation required for 4-20 mA loops

Confirm the TIA Portal installation includes the optional package "STEP 7 Basic" and that the device catalog under Controllers > SIMATIC S7-1200 > CPU > CPU 1212C resolves a hardware version that matches the actual PLC. Mismatched firmware warnings will block download.

3. Converting the V13 SP1 Sample Project to V14 SP1

The 100746401 sample is published as a TIA Portal V13 SP1 archive. TIA Portal performs forward conversion on open. The conversion path is unambiguous: there is no need to obtain a re-archived copy from a third party.

  1. Launch TIA Portal V14 SP1 Update 8.
  2. Click Open existing project on the start page or use Project > Open (Ctrl+O).
  3. Browse to the unzipped .ap13 / .ap13_1 project file. TIA Portal recognizes the V13 SP1 archive by its file version header.
  4. Click Open. A dialog asks whether to upgrade the project. Confirm with Upgrade.
  5. TIA Portal rewrites the project database in place. A conversion report is appended to the project tree under Common data > Logs.
  6. After upgrade, recompile the project (Project tree > CPU_1 > Compile > Software (rebuild all)). Watch for unresolved device versions; pin the device versions to those available on the engineering station if the catalog is missing the original revision.
Common error: If the message "The project must be at least V13 SP1 to be upgraded" appears, the project is actually V13 (without SP1) or V12. In that case obtain a V13 SP1 source archive from Siemens Support, or rebuild the HMI screens in V14 SP1 from scratch. The error text does not indicate a defect in the destination version.

Once compiled cleanly, save the project as a TIA Portal V14 SP1 archive (Project > Archive > Name.iap14) to lock in the new format.

4. PID_Compact Block Architecture

PID_Compact is the standard closed-loop controller for S7-1200. The block combines continuous PID, output scaling, and an integrated identification routine. The interface relevant to HMI-triggered autotuning is summarized below.

Input Type Meaning Operator action
Setpoint REAL Process setpoint in engineering units IO field on HMI
Input REAL Process value (PV) in engineering units Read-only display
Input_PER INT Analog input raw value (0-27648) Hard-wired from AI
ManualEnable BOOL Switch to manual mode Button tag
ManualValue REAL Manual output 0-100 % IO field, gated by ManualEnable
Retain.CtrlParams STRUCT Holds Gain, TI, TD, dead band Auto-populated after tuning
Mode / Retain.Mode INT Operating mode selector Mode buttons on HMI

The Mode input is the HMI trigger. Valid values:

  • 0 – Inactive (block executes but does not control)
  • 1 – Manual (operator drives output via ManualValue)
  • 2 – Automatic (closed-loop control with current PID parameters)
  • 3 – Automatic with pretuning request
  • 4 – Automatic with fine-tuning request
  • 5 – Automatic with fine-tuning request, then closed-loop
Mode 3 vs 4: Pretuning (mode 3) injects a step on the output and identifies process gain and dead time. Fine-tuning (mode 4) tunes around the current setpoint and is preferred when the loop is already in automatic and the operator only wants incremental refinement. For a pressure loop where setpoint varies widely, fine-tuning is usually sufficient and faster.

5. PLC Program Skeleton for HMI-Triggered Tuning

Wrap the mode change in a one-shot so a button press does not repeatedly request tuning while held.

// FB instance: "PID_Pressure" of type PID_Compact (DB1139)
// HMI tags (HMI side): "bStartPretune", "bStartFinetune", "iMode", "bManual", "rManVal", "rSP", "rPV", "rOutput"

// Edge detection for tuning buttons
"bStartPretune_Old" := "bStartPretune";
IF "bStartPretune" AND NOT "bStartPretune_Old" THEN
    "PID_Pressure".Retain.Mode := 3;  // Pretuning request
END_IF;

"bStartFinetune_Old" := "bStartFinetune";
IF "bStartFinetune" AND NOT "bStartFinetune_Old" THEN
    "PID_Pressure".Retain.Mode := 4;  // Fine-tuning request
END_IF;

// Mode = 2 holds the loop in automatic after tuning completes
IF "bAutoMode" THEN
    "PID_Pressure".Mode := 2;
END_IF;

// Manual / automatic toggle
IF "bManual" THEN
    "PID_Pressure".ManualEnable := TRUE;
    "PID_Pressure".ManualValue  := "rManVal";
ELSE
    "PID_Pressure".ManualEnable := FALSE;
END_IF;

// Wire analog IO
"PID_Pressure".Input     := "rPV_scaled";   // scaled via NORM_X / SCALE_X
"PID_Pressure".Input_PER := "iwAI_Pressure"; // raw 0-27648
"PID_Pressure".Setpoint  := "rSP";

6. TP900 HMI Screen Design

On the TP900 Comfort, build a faceplate with five controls and four readouts.

Control Tag Range / Configuration
IO field – Setpoint rSP 0.0 to 100.0 bar, 1 decimal
IO field – ManualValue rManVal 0.0 to 100.0 %, visible only when bManual = TRUE
Button – Manual / Auto toggle bManual Toggle, text labels via Text list
Button – Start Pretuning bStartPretune Momentary, confirms via dialog
Button – Start Fine Tuning bStartFinetune Momentary, confirms via dialog
Bar – Process value rPV Color changes on deviation > 5 %
Bar – Output rOutput 0-100 %
Display – Active mode iMode Text list (Inactive / Manual / Auto / Tuning)

Define a tag table HMI_Tags_PID on the TP900 with the data type of each tag matching the PLC tag exactly. Use the TP900 connection "HMI_1 > Connections > S7_1200_1" pointing to the CPU 1212C. Tags must be configured with acquisition mode Cyclic in operation for the mode state and Cyclic continuous for PV / SP / output, with a 1 s update cycle. Mode-toggle tags use On demand acquisition to avoid PLC-side floods.

7. Step-by-Step Commissioning Procedure

  1. Wire the pressure transmitter to AI0 of the CPU 1212C. Calibrate the transmitter zero and span against a reference gauge. Verify the engineering-unit conversion in a watch table: PEW96 should read 0 at 0 bar and 27648 at full scale.
  2. Download the hardware configuration to the CPU. The CPU reports the configured AI range back in the online diagnostics; confirm "Measuring range: 0-10 V" or "4-20 mA" matches the wiring.
  3. Add a PID_Compact instance (DB) to the program blocks. Open the configuration editor and assign Input_PER to %IW96, Setpoint to a default of 0 bar, and Output_PER to %QW96 if the actuator is on the onboard AQ.
  4. In the PID_Compact commissioning window (called from the block properties or by right-clicking the DB), open the online preview. Set the controller to Manual with output = 0 % and verify the actuator responds (valve closes, pump idles).
  5. Establish a stable manual baseline. Drive the output to the expected operating point (e.g., 50 % valve opening) and let PV settle. Note the steady-state PV value.
  6. Switch the controller to Automatic. Tune the loop using the operator HMI: tap Start Fine Tuning. The TP900 should display "Tuning" in the mode field. PID_Compact will perturb the setpoint by a small step and identify the process response.
  7. When the mode returns to "Auto" and the block reports Retain.CtrlParams.Gain, TI, and TD are non-zero, the loop is tuned. Verify disturbance response by injecting a small setpoint step from the HMI IO field.
  8. Save the project. Back up the tuned parameters by reading the DB online and writing the values to a recipe on the TP900 (Recipe view > Recipe_1) so the parameters can be reloaded after a CPU stop / restart with retain cleared.

8. Verification Checks

After tuning completes, perform the following quantitative checks before releasing the loop to production:

  • Closed-loop error: Steady-state deviation between Setpoint and Process value should be < 1 % of sensor span.
  • Overshoot: Step response from 0 to 50 % SP should overshoot by no more than 10 % of the step. PID_Compact fine-tuning aims for a damping factor of 0.8 by default; reduce Retain.CtrlParams.Gain by 10 % if overshoot is excessive.
  • Integral windup: With output saturated at 100 %, verify that the integral component does not grow indefinitely. PID_Compact implements anti-windup internally; confirm by reducing SP and watching the loop recover within the expected time constant.
  • Mode tag sync: Press the HMI Manual button. The PLC Retain.Mode should read 1, and the HMI mode display should show "Manual". If only one side updates, the tag acquisition cycle is mismatched.
  • Retain behavior: Power-cycle the CPU. The loop should resume in the tuned state (not as defaults). If not, the DB was generated as non-retain; right-click the DB instance and toggle Retain for the CtrlParams and Mode structures.

9. Using the TIA Portal Openness API for Diagnostic Automation

For installations that retune many loops, manually driving the HMI is impractical. TIA Portal exposes a public scripting interface, the TIA Portal Openness API, that can read controller state, trigger a project build, and compare the running configuration against the offline project. Diagnostic information from a live TIA Portal instance – including currently opened projects, active sessions, and log-level events – can be retrieved through a static method on the diagnostic interface. The reference page is in the official TIA Portal Openness documentation at Diagnostic interfaces on TIA Portal.

A minimal C# snippet (Visual Studio, .NET 4.8, references Siemens.Engineering.dll and Siemens.Engineering.Hmi.dll) that reads the TIA Portal session diagnostics to confirm the V14 SP1 Update 8 project is open and unmodified looks like this:

using Siemens.Engineering;
using TiaPortal.Openness.Diagnostics;   // public static accessor

class Program
{
    static void Main()
    {
        var tia = TiaPortal.GetFromLocalProcess();
        var diag = TiaPortalDiagnostic.GetDiagnostics(tia);

        foreach (var entry in diag)
        {
            System.Console.WriteLine($"{entry.Timestamp} {entry.Severity} {entry.Source} {entry.Message}");
        }

        // Walk every PID_Compact instance and dump tuning state
        var project = tia.Projects[0];
        foreach (var device in project.Devices)
        {
            foreach (var blockGroup in device.DeviceItems[0].Software.PlcSoftware.BlockGroups)
            {
                foreach (var block in blockGroup.Blocks)
                {
                    if (block.Type == BlockType.FB && block.Name.StartsWith("PID_"))
                    {
                        System.Console.WriteLine($"Found {block.Name} on {device.Name}");
                    }
                }
            }
        }
    }
}

Note that the Openness API is read-only with respect to online PID values – it cannot write to the live controller. For online writes, the engineering station must use a connected TIA Portal in TIA Portal mode, or the HMI path described above. Openness is most useful for documentation, audit logs, and verifying that the offline project matches the deployed controller configuration after a tuning campaign.

10. PID Lean as an Open-Source Alternative

The standard PID_Compact block is general-purpose. When the process is dominated by first-order lag with measurable dead time (typical for pressure loops with long pipe runs), a lighter controller is often adequate. Siemens' community-published "PID Lean" library provides a smaller code footprint, an explicit auto-tuning step, and a quicker commissioning dialog. PID Lean is distributed as a global library for TIA Portal and can be imported into a V14 SP1 project via Options > Global libraries > Open library.

Verify the version: Before importing, confirm the library revision explicitly lists TIA Portal V14 SP1 as a compatible target. Earlier revisions may not load the Comfort panel faceplates. PID Lean does not replace PID_Compact; it provides a parallel alternative for installations where the engineer prefers a thinner regulator. Plan to validate the HMI tags against the new block's interface after import, because tag names and structures differ from PID_Compact.

11. Troubleshooting Matrix

Symptom Likely root cause Corrective action
Mode stays 0 after tapping Start Pretuning Mode assigned to Retain.Mode was written by a tuning cycle that was interrupted Force Mode := 2 in the watch table, then retry; also verify the DB is generated as retentive
Tuning aborts within 1 second Process value is noisy or out of configured measuring range Filter the analog input (SM 1231 hardware filter, 50/60 Hz rejection) and confirm PV is within the configured Input scaling
Project will not upgrade from V13 to V14 Source project is V12 or earlier Obtain a V13 SP1 source from Siemens Support, or rebuild screens in V14 SP1
HMI button updates PLC but PLC does not echo back to HMI Tag direction configured as "read only" on TP900, or wrong connection partner Open HMI tag properties, set direction to Read/Write; verify the HMI_1 connection points to the same CPU
Tuning parameters zero after CPU restart DB not generated as retain; tuning parameters held in non-retain area Right-click PID_Compact DB instance, select Properties > Attributes, enable Retain for the instance
Openness script returns "TIA Portal is not running" Script executed from a process that is not the engineering station, or TIA Portal not in interactive mode Run script from a custom UI on the engineering PC; confirm the TIA Portal instance is in interactive (non-headless) state
Pretuning never completes (mode stays 3) Output_PER is not wired, or actuator is in manual / disabled Verify Output_PER connection, switch the field device to remote / auto, then retry

12. Field-Proven Caveats

  • The CPU 1212C has only two onboard analog inputs and two onboard analog outputs. If the pressure loop is one of several on the same PLC, plan to add an SM 1231 AI4 and SM 1232 AQ2 to avoid contention.
  • TP900 Comfort panel projects compiled with TIA Portal V14 SP1 Update 8 cannot be opened on an older V14 SP1 Update 5 or earlier runtime image on the panel. Keep HMI images and engineering versions aligned.
  • Comfort panel faceplates can be re-used across multiple S7-1200 controllers, but each instance must have its own tag-prefix space. A single global PID faceplate with a tag prefix interface is more maintainable than per-loop copies.
  • PID_Compact autotuning assumes the process is stable at the current operating point. If the loop is in manual with output saturated, switch to automatic with a realistic setpoint first, then trigger fine tuning.
  • Retain behavior in S7-1200 is byte-granular and only applies to bit memory (M), DBs, and some I/O. If the DB instance containing PID_Compact is not flagged as retain, all tuning parameters are lost on power cycle.

13. HMI-to-PLC Tag Reference Summary

PLC tag Data type HMI control Direction
rSP REAL IO field HMI → PLC
rPV REAL Numeric display / bar PLC → HMI
rOutput REAL Numeric display / bar PLC → HMI
rManVal REAL IO field (gated) HMI → PLC
bManual BOOL Toggle button HMI → PLC
bStartPretune BOOL Momentary button HMI → PLC
bStartFinetune BOOL Momentary button HMI → PLC
iMode INT Symbolic IO field with text list PLC → HMI
bTuningActive BOOL Indicator (e.g., yellow lamp) PLC → HMI
rGain, rTI, rTD REAL Read-only display PLC → HMI

Can a TIA Portal V13 SP1 project be opened directly in V14 SP1 Update 8?

Yes. TIA Portal performs an in-place forward conversion when a V13 SP1 archive is opened in V14 SP1. If the message "project must be at least V13 SP1" appears, the source archive is V12 or earlier, not V14. Obtain a true V13 SP1 archive or rebuild the screens in V14 SP1.

Which PID block on the S7-1200 supports HMI-triggered autotuning?

The standard block is PID_Compact (FB 1139, instance DB 1139). Writing Mode := 3 starts pretuning; Mode := 4 starts fine tuning; Mode := 2 returns the loop to closed-loop automatic with the new parameters.

Why do tuned parameters reset to defaults after power cycling the CPU?

The PID_Compact instance DB must be generated as retain. In the DB properties, enable the Retain attribute. If only some parameters are retained, the integral action will re-initialize and the loop will bump on restart.

Can the TIA Portal Openness API start autotuning remotely?

No. The Openness API in TIA Portal V14 SP1 is read-only with respect to online controller state; it can list blocks, read parameters, and run diagnostics, but it cannot write to a running controller. Use the HMI to trigger tuning, or implement the request from a third-party SCADA via the S7-1200's PUT/GET or Modbus TCP server interface.

Is PID Lean a drop-in replacement for PID_Compact?

No. PID Lean is a separate global library with its own block interface, tag names, and faceplate logic. It is lighter and well-suited to first-order processes, but the HMI tags and program wiring must be rebuilt to match its interface. Confirm the imported library revision explicitly supports TIA Portal V14 SP1 before adopting it.

Back to blog