Updating PID_Compact Parameters from HMI on S7-1200/1500

David Krause12 min read
PID ControlSiemensTutorial / 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: PID_Compact and HMI Parameterization

PID_Compact is the standard PID controller instruction supplied with the S7-1200, S7-1500, and S7-1200 G2 CPU families. The instruction is part of the PID Control technology object family and is included in every TIA Portal installation without additional licensing. PID_Compact delivers continuous, pulse, or mixed output behavior from a single FB and provides built-in pretuning and fine tuning routines.

When commissioning a temperature, level, flow, or pressure loop, the integrator or operator frequently needs to adjust controller parameters (Gain, Integral time TI, Derivative time TD) after the loop is running. Three valid parameterization paths exist in TIA Portal:

  1. Inspector window of the PID_Compact block (offline configuration download).
  2. Online/offline edit of the instance DB (DBedit) from the project tree.
  3. HMI write access to the retentive structure of the instance DB during runtime.

Only the third path lets the operator change Gain, TI, and TD from a Comfort Panel, Unified Comfort Panel, Basic Panel, WinCC Runtime, or any third-party HMI that speaks S7 communication. The configuration question is therefore: which of the two PID_Compact parameter source modes (Instance DB or Instruction) exposes the values in a way the HMI can write?

Reference: Technology object PID_Compact (S7-1200, S7-1500, S7-1200 G2).

2. Prerequisites and Compatibility

Component Minimum Version Notes
TIA Portal V15.0 or later V17 / V18 / V19 / V20 / V21 recommended for current G2 CPUs.
S7-1200 firmware V4.2 or later PID_Compact is in the global library; not firmware-licensed.
S7-1500 firmware V2.0 or later Technology objects in TIA Portal project tree.
S7-1200 G2 firmware V1.0 or later Updated PID_Compact V3.x is auto-installed with the device package.
HMI platform Comfort / Basic / Unified Comfort / WinCC RT Any panel that can hold a typed PLC tag connection.
Connection type Integrated HMI connection or S7 PUT/GET PUT/GET must be enabled in the CPU protection settings.
The PID_Compact instruction version in the project must match the firmware family. A V2 PID_Compact cannot be downloaded into an S7-1200 G2 without first updating the instruction to the current major version. Use the project tree entry Technology objects > PID_Compact > Update to align versions.

3. PID_Compact Source Modes: Instance DB vs. Instruction

PID_Compact exposes two paths for the Setpoint, Input (process value), and Output tags. The selected path determines whether the HMI can write to the value. This is documented in the SIMATIC S7-1200, S7-1500 PID control function manual (page 73 in the V21 PDF edition).

Source Setting Data Location Update Mechanism HMI Write Allowed?
Instance DB Stored in the PID_Compact instance DB (Retain or non-retain). User program must copy the desired value into the instance DB tag; the instruction reads it from the DB each cycle. Yes, when the tag is exposed as an HMI tag with read/write access.
Instruction Connected to the input pin of the PID_Compact box call. The instruction overwrites the instance DB value with the pin value on every call. No. HMI writes are immediately overwritten on the next call.

For tuning, the operator is changing controller parameters (Gain, TI, TD) and not the Setpoint, so the relevant tags live in the retentive structure of the instance DB regardless of the source mode setting. However, choosing Instance DB for Setpoint/Input/Output is the safer convention for two reasons:

  1. It keeps all operator-changeable values in one DB address range, simplifying HMI tag generation.
  2. It prevents the program from inadvertently overwriting an operator entry on the next OB1 cycle.

To select the source mode, open PID_Compact in the project tree, switch to the Configuration tab, and set Input / Setpoint / Output source to Instance DB. Apply and download the project to the CPU.

4. Identifying HMI-Accessible Parameters

PID_Compact is delivered as a FB 1130 (S7-1500) or FB within the global library (S7-1200). Each call creates an instance DB that holds three groups of tags:

Structure Path Purpose HMI Write Safe? Typical Use
Input, Setpoint, Output Cyclic I/O (volatile) Yes, if source = Instance DB Operator setpoint and read-back
Static > Config.* Loop configuration No (re-init on restart) Limit values, alarm thresholds
Static > Retain.CtrlParams.* Retentive controller tuning Yes Gain, TI, TD, DerivativeDelay, PWeighting, DWeighting, Cycle
Static > Retain.IdentifyParams.* Tuning response thresholds Yes Noise, step size, average time
Static > sRet Status / warning bits Read-only InputWarning, SetpointWarning, OutputWarning

For the common requirement of changing Gain, TI, and TD from the HMI, the absolute tag addresses inside the instance DB are:

Tag (Symbolic) Data Type Retain Engineering Range
<PID_DB>.Retain.CtrlParams.Gain REAL Yes 0.0 to 1e+10 (unit depends on process)
<PID_DB>.Retain.CtrlParams.Ti REAL Yes 0.0 to 1e+10 s (0 disables integral action)
<PID_DB>.Retain.CtrlParams.Td REAL Yes 0.0 to 1e+10 s (0 disables derivative action)
<PID_DB>.Retain.CtrlParams.TdFilt REAL Yes 0.0 to 1e+10 s (derivative filter)
<PID_DB>.Retain.CtrlParams.PWeighting REAL Yes 0.0 to 1.0 (P share weighting)
<PID_DB>.Retain.CtrlParams.DWeighting REAL Yes 0.0 to 1.0 (D share weighting)
<PID_DB>.Retain.CtrlParams.Cycle REAL Yes 0.1 to 60.0 s (sampling time)
Setting Ti = 0.0 disables the I action, producing a PD controller. Setting Td = 0.0 disables the D action, producing a PI controller. Both are valid operating modes; do not interpret the zero as a tuning error.

5. Step-by-Step: Enabling HMI Writes to PID Parameters

5.1 Confirm the Instance DB Source Mode

  1. Open the project in TIA Portal.
  2. Expand Technology objects > PID_Compact_x [DBx].
  3. Open Configuration > Basic settings.
  4. Set Input, Setpoint, and Output to Instance DB.
  5. Compile and download the hardware and software to the CPU.

5.2 Verify the Retain Structure Exists

  1. Open the instance DB in the project tree (double-click PID_Compact_x [DBx]).
  2. Confirm the path Retain.CtrlParams.Gain is visible.
  3. If only the cyclic I/O is shown, the FB version is older than V2. Replace the block using Technology objects > PID_Compact > Update.

5.3 Configure the HMI Connection

  1. Add an HMI device to the project (Comfort Panel, Unified Comfort Panel, or WinCC RT Professional).
  2. Open Devices & Networks and connect the HMI to the S7-1200/1500 CPU. An integrated S7 connection is created automatically.
  3. Right-click the CPU in the device view, choose Properties > Protection & Security, and confirm Permit access with PUT/GET from remote partner if you intend to use absolute addressing from a third-party HMI.

5.4 Create HMI Tags Pointing to the Retain Structure

  1. In the HMI project tree, open HMI tags.
  2. Add a new tag with these properties:
Property Value for Gain Value for TI Value for TD
Name PID_Gain PID_Ti PID_Td
Connection HMI_Connection_1 HMI_Connection_1 HMI_Connection_1
PLC tag (symbolic) DBx.Retain.CtrlParams.Gain DBx.Retain.CtrlParams.Ti DBx.Retain.CtrlParams.Td
Data type Real (32-bit float) Real Real
Length 4 bytes 4 bytes 4 bytes
Access Read / Write Read / Write Read / Write
Acquisition Cyclic, 1 s Cyclic, 1 s Cyclic, 1 s

The PLC tag field accepts the symbolic address of the instance DB tag. This eliminates the need to type absolute byte offsets. TIA Portal resolves the symbol during HMI compile.

5.5 Bind the Tags to HMI Objects

  1. Open the screen that should host the parameter entry.
  2. Insert an I/O field and configure:
  • Tag: PID_Gain (or the appropriate variable).
  • Mode: Input/output.
  • Format pattern: 0.000 for Gain, 0.0 s for TI/TD.
  • Limits: 0.0 to 1000.0 (adjust to the process).
  1. Repeat for TI and TD.
  2. Add three numeric read-only displays that bind to <PID_DB>.Retain.CtrlParams.Gain, .Ti, and .Td as confirmation of the active value after the CPU accepts the write.

5.6 Compile and Download

  1. Compile the HMI first (Compile > Software (rebuild all)).
  2. Compile the PLC software to refresh tag consistency.
  3. Download both to the target devices.
  4. Switch the HMI to runtime and test the write cycle.

6. Program-Side Best Practices for Safe HMI Writes

HMI writes land directly in the retentive area of the instance DB. Without guard code, the operator can enter negative values, NaN, or values outside the actuator range. Add a validation block in OB1 or a cyclic OB before PID_Compact is called:

// ST (SCL) snippet - parameter guard
IF "PID_DB".Retain.CtrlParams.Gain < 0.0 OR
   "PID_DB".Retain.CtrlParams.Gain > 1000.0 THEN
    "PID_DB".Retain.CtrlParams.Gain := "iGain_LastValid";
END_IF;

IF "PID_DB".Retain.CtrlParams.Ti < 0.0 OR
   "PID_DB".Retain.CtrlParams.Ti > 10000.0 THEN
    "PID_DB".Retain.CtrlParams.Ti := "iTi_LastValid";
END_IF;

IF "PID_DB".Retain.CtrlParams.Td < 0.0 OR
   "PID_DB".Retain.CtrlParams.Td > 10000.0 THEN
    "PID_DB".Retain.CtrlParams.Td := "iTd_LastValid";
END_IF;

Store the last-valid values in a separate, non-retentive global DB. Update them on every cycle in which the new value passes validation. This pattern prevents a stuck actuator if the operator enters an out-of-range Gain or a negative TI.

7. Verifying the HMI Write Reached the CPU

Perform the following checks after commissioning. Each step has a pass/fail criterion.

Step Action Pass Criterion
1 Go online with the PLC in TIA Portal. Online identifier is green; PID_DB shows current values.
2 Open Watch table and force PID_DB.Retain.CtrlParams.Gain to 1.5. Value remains 1.5 after CPU restart (retentive).
3 From the HMI, enter Gain = 2.0 in the I/O field. Watch table value changes to 2.0 within one acquisition cycle.
4 Force a step change in setpoint and observe control response. Output responds with the new Gain; no watchdog or fault light on PID_Compact.
5 Read PID_DB.sRet.InputWarning and .SetpointWarning. Both remain FALSE during the test.
6 Cycle power on the CPU. New Gain, TI, TD are still active; Setpoint returns to the last operator value if also in the Retain structure.

8. Edge Cases and Field Tips

8.1 HMI Writes are Overwritten by the Program

Symptom: Operator changes Gain from 1.0 to 2.0, the value reverts within a second. Cause: a section of the user program (often a startup or HMI image handler FB) writes PID_DB.Retain.CtrlParams.Gain := 1.0 on every cycle. Move the assignment to a one-shot logic (use a rising edge from a first-cycle flag such as FirstScan in OB100).

8.2 Tag Not Visible in the HMI Tag Dialog

If the symbolic tag DBx.Retain.CtrlParams.Gain is grayed out, the HMI device is not connected to the CPU as an HMI partner. Open Devices & Networks, drag a line between the HMI and CPU ports, and recompile.

8.3 TIA Portal V15 vs. V21 HMI Behavior

Older TIA Portal versions (V15, V15.1) do not expose Retain.CtrlParams.Gain as a selectable symbolic tag. Either update TIA Portal or use the absolute address. The instance DB byte offset for Gain (REAL) is fixed at DBx.DBD64 in the V1 instruction layout. Verify the offset by inspecting the Offset column of the instance DB editor.

8.4 Pretuning Resets Operator Values

Running pretuning (Mode = 1) overwrites Gain, TI, and TD with the result of the identification step. After pretuning completes, the operator values from the HMI are lost. Save the current values to the HMI recipe before triggering pretuning if the operator must be able to roll back.

8.5 PUT/GET Blocked by CPU Protection

If a third-party HMI writes by absolute address, the CPU must allow remote PUT/GET. Navigate to CPU properties > Protection > Connection mechanisms and enable Permit access with PUT/GET from remote partner. With integrated HMI connections, this is not required.

8.6 Hot-Restart of the S7-1500

On S7-1500, the retentive data of PID_Compact is loaded from the load memory at STOP-to-RUN transition. HMI writes made while the CPU is in STOP are visible in the online DB but do not take effect on the controller until the CPU returns to RUN. This is a common confusion in commissioning.

9. PID_Compact Runtime Mode Word Reference

To let the operator switch between manual and automatic from the HMI, expose the Mode input. The valid values are:

Mode Value Meaning Safe to Switch from HMI?
0 Inactive Yes, but disables output.
1 Pretuning Yes; required to start identification.
2 Automatic Yes; standard operator mode.
3 Manual Yes; operator drives Output via ManualValue.

For bump-less transfer between manual and automatic, set the manual value to the current process output before switching back to automatic:

"PID_DB".ManualValue := "PID_DB".Output;
"PID_DB".ManualEnable := TRUE;
"PID_DB".Mode := 2;  // automatic

10. SVG: Data Flow from HMI to PID_Compact

HMI I/O Field HMI Tag Table PID_Gain / PID_Ti / PID_Td S7 Connection PID_Compact Instance DB Retain.CtrlParams.* Cyclic OB / OB1 PID_Compact FB 1130

The arrow order is: HMI I/O field → HMI tag → S7 connection (PUT/GET or integrated) → Instance DB Retain.CtrlParams → PID_Compact block on the next call. The CPU only accepts the new Gain, TI, or TD at the boundary of the next PID_Compact call cycle.

11. Troubleshooting Matrix

Symptom Likely Cause Diagnostic Step Resolution
HMI field shows value but cannot be changed. HMI tag configured read-only. Check tag properties → Access = Read/Write. Set access to Read/Write; recompile HMI; redownload.
Value writes, then reverts within 1 s. User program overwrites the DB tag. Search project for assignment to Retain.CtrlParams.*. Move write to one-shot initialization logic.
Symbolic tag is not offered in the HMI tag dialog. HMI not connected in Devices & Networks. Open topology, check the HMI-CPU link. Drag a connection line; recompile both projects.
Watch table shows different value than HMI. Acquisition cycle slower than expected. Reduce HMI acquisition to 500 ms. Operator can also press Enter to force update.
Write succeeds, but PID output does not change. PID_Compact is in Mode 0 (inactive) or pretuning. Read PID_DB.Mode in a watch table. Set Mode = 2 (automatic) from the HMI or program.
Pretuning resets the operator's Gain. Expected behavior of the identification routine. Save Gain/TI/TD to an HMI recipe before pretuning. Restore from recipe after pretuning completes.
Third-party HMI cannot write at all. PUT/GET disabled in CPU protection. CPU properties → Protection → Connection mechanisms. Enable Permit access with PUT/GET from remote partner.
Gain reverts to original on CPU restart. Retain area is too small; parameter not stored retentively. Open DB, check Retain column for Gain/Ti/Td. Mark the tag as retentive; download the new DB initialization.

12. Frequently Asked Questions

Can I change Gain, TI, and TD of PID_Compact from any Siemens HMI?

Yes. Expose <PID_DB>.Retain.CtrlParams.Gain, .Ti, and .Td as HMI tags with read/write access on a Comfort, Basic, Unified Comfort, or WinCC Runtime panel, and bind them to numeric I/O fields. The tags are retentive, so the values survive a CPU restart.

Why does the HMI show the new Gain but the controller ignores it?

Either the HMI tag is set to read-only, the CPU is in STOP, or the user program is overwriting the DB tag on every cycle. Force the value in a watch table to confirm CPU-side acceptance, then audit the user program for redundant assignments to Retain.CtrlParams.*.

Do I need PID_Compact V2 or V3 for HMI access?

You need at least the V2 layout (TIA Portal V15.1 onward) to see the symbolic Retain.CtrlParams structure. Older V1 layouts work with absolute addressing using DBx.DBD64 for Gain, DBx.DBD68 for TI, and DBx.DBD72 for TD, but the symbolic path is strongly preferred.

Is the setpoint changeable from the HMI as well?

Yes, if you set the Setpoint source to Instance DB in the PID_Compact configuration. The HMI then writes to <PID_DB>.Setpoint. If the source is Instruction, the HMI write is overwritten by the connected program tag on the next call, and changes appear to have no effect.

Does pretuning erase the operator's tuning values?

Yes. Pretuning (Mode = 1) re-identifies the process and overwrites Gain, TI, TD, and several auxiliary tuning parameters. Save the active values to an HMI recipe before triggering pretuning so the operator can restore them if the identification result is unsatisfactory.

Back to blog