PID_Compact is the Siemens software PID controller for S7-1200 and S7-1500 CPUs. It is a technology object plus an instruction that runs a PIDT1 algorithm with anti-windup and adjustable weighting of the proportional and derivative actions. It also has two built-in self-tuning routines, pretuning and fine tuning. You configure it in TIA Portal and call it from a cyclic interrupt OB. Its output can go to an analog channel, a REAL tag or a PWM digital output.
This guide covers V2, the version running on most machines in service. On S7-1200 it needs PID_Compact V2.2 or later and CPU firmware 4.0 or later. The reference is the free function manual SIMATIC S7-1200, S7-1500 PID control (A5E35300227) on Siemens Industry Online Support, entry 108210036. Download the newest edition. Recent TIA Portal releases also document PID_Compact V3 and the S7-1200 G2, and details can differ between versions.
In particolar modo vedremo:
Step-by-step procedure: setup, pretuning, fine tuning
- Create a cyclic interrupt OB (OB30 or another) and choose its interval. The time between calls is the controller’s base sampling time and PID_Compact monitors it, so never call the block from OB1. A slow oven tolerates a long interval, while pressure and flow loops need a short one. If the
Warningtag shows 16#0020 after tuning, the OB is too slow for the process. Shorten the interval and tune again. - Drag PID_Compact into the OB. TIA Portal creates the technology object and its instance DB. The instance DB will also hold the tuned parameters.
- Basic settings. Pick the physical quantity. If a higher output lowers the process value (cooling, a drain valve), tick Invert control logic. The block rejects negative gain, so this checkbox is the only way to get reverse action. Choose
Input(a REAL you scaled yourself) orInput_PER(the raw analog word), then the output type. Last, decide whether the controller resumes its savedModeafter a CPU restart. - Scaling and limits. With
Input_PER, enter the scaling pairs or press Automatic setting to copy them from the hardware configuration. Set realistic absolute limits for the process value: crossing either limit raises 16#0001 and aborts any tuning. - Output limits and reaction to error. The output limits must match the control logic, or pretuning stops with 16#0080. Minimum ON and OFF times apply only to PWM; with other outputs leave them at 0.0. Then choose the error reaction: zero and inactive, hold the current value, or output a substitute value. The default keeps the loop running in many cases, even with the process value beyond its limits. Make this choice deliberately for any heater or dosing pump.
- Check the loop by hand. Download, go online, open Commissioning, press Start and switch to manual mode. Apply a modest output and confirm that the process value moves the right way. Tuning a loop with a stuck valve or a reversed sign only produces error codes.
- Pretuning. With the process steady and well away from the setpoint, select Pretuning and click Start. The block steps the output and finds the inflection point of the response. It computes the parameters from the steepest slope and the dead time, then switches to automatic mode.
- Fine tuning. Once the process value has settled at the setpoint, select Fine tuning and click Start. Keep disturbances away: no load changes, no open doors, no setpoint writes from the HMI.
- Upload and save. Click Upload PID parameters, then save the project. Tuning changes only the instance DB in the CPU. If you skip this step, the next full download restores the old values.
Pretuning vs fine tuning: comparison
| Pretuning | Fine tuning | |
|---|---|---|
| Excitation | A single output step | A steady oscillation of limited size around the setpoint |
| What it measures | Maximum rate of rise and dead time | Amplitude and frequency of the oscillation |
| Process value at start | Far from the setpoint | Settled at the setpoint |
| Noise | Tolerated if the rise is much larger than the noise | Little effect: the block makes the oscillation larger than the noise |
| Result | A usable first set | Usually better setpoint tracking and disturbance rejection |
| Typical messages | 16#0008, 16#0080, Warning 16#0001 (no inflection point) | 16#0004, 16#0100 |
| Use it for | First commissioning, process at rest | Refining at the real operating point |
Both routines can start from inactive, manual or automatic mode. Both save the previous parameters first, and LoadBackUp = TRUE restores them. If you start fine tuning from inactive or manual mode and the pretuning conditions are met, pretuning runs first. If the process value is already too close to the setpoint, the block drives the output to a limit to reach the setpoint, and the overshoot can be large.
The pretuning distance rule, worked out
Pretuning starts only if both conditions are true:
|Setpoint − Input| > 0.3 × |InputUpperLimit − InputLowerLimit||Setpoint − Input| > 0.5 × |Setpoint|
Take an invented plant: a curing oven on a fictional panel line, with limits from 0 to 200 °C and a setpoint of 150 °C. The range rule needs a gap above 60 °C. The setpoint rule needs a gap above 75 °C. The second rule is the stricter one, so pretuning works only below 75 °C. On a Monday morning at 20 °C it starts without problems. After a short stop with the chamber still at 90 °C, it fails at once with 16#0008. Either let the oven cool, or go straight to fine tuning.
On a range that starts at zero, the setpoint rule becomes the stricter one once the setpoint exceeds 60% of the span. The setpoint is also frozen when tuning begins. Moving it by more than CancelTuningLevel cancels the run with 16#0010, often because an HMI ramp keeps writing to it.
Reading ErrorBits
ErrorBits is a DWORD. Error is TRUE only while a fault is active. ErrorBits is retentive and keeps the record until a rising edge on ErrorAck or Reset. ErrorAck clears it without restarting the controller; Reset also sends the controller to inactive. When several errors are active, their codes add up: 16#0000_0801 means a sampling time error plus a process value out of limits. The table lists the V2 codes you will meet most often.
| Code (16#) | Meaning | Check first |
|---|---|---|
| 0001 | Process value beyond the absolute limits | Limits too tight, sensor fault, broken wire |
| 0002 | Invalid value at Input_PER |
Analog module diagnostics |
| 0004 | Fine tuning lost the oscillation | Disturbances, saturated or slow actuator |
| 0008 | Pretuning refused: process value too close to setpoint | Distance rule; use fine tuning |
| 0010 | Setpoint changed during tuning | HMI or ramp writes, CancelTuningLevel |
| 0020 | Pretuning requested during fine tuning | Logic writing the wrong Mode |
| 0080 | Output limits do not match the control logic | Invert control logic, sign of the limits |
| 0100 | Fine tuning produced invalid parameters | Repeat with a steadier process |
| 0400 | Output value calculation failed | Manually entered PID parameters |
| 0800 | Block not called within the OB sampling time | CPU overload, simulator timing |
| 0200, 1000, 10000, 20000, 40000 | Invalid REAL at Input, Setpoint, ManualValue, SubstituteOutput, Disturbance |
Uninitialised tags, NaN |
The ActivateRecoverMode tag sets how the block reacts. With FALSE, any error makes the controller inactive until a falling edge on Reset or a rising edge on ModeActivate. With TRUE in automatic mode, the block keeps controlling through 0001, 0800 and 40000. For 0002, 0200, 0400 and 1000 it moves to State 5 (substitute output value with error monitoring) and returns to automatic when the cause clears. During tuning, TRUE cancels the run and goes back to the mode tuning started from. The exception is 0020, where fine tuning simply carries on.
In PLCSIM the OB timing jitters more than on real hardware, so 16#0800 can abort a tuning test. In the simulator only, set CycleTime.EnEstimation and CycleTime.EnMonitoring to FALSE. Then write the OB interval, in seconds, to CycleTime.Value.
Frequently asked questions (FAQ)
Can I start tuning from the HMI without TIA Portal?
Yes. With ManualEnable and Reset at FALSE, write 1 (pretuning) or 2 (fine tuning) to Mode and give a rising edge on ModeActivate. State shows 1 or 2 while the routine runs and 3 once it has succeeded.
Why did my tuned parameters disappear?
A full download replaced them with the values stored in the project. Upload and save after every successful tuning. If a new tuning made things worse, LoadBackUp brings back the previous set.
Which output should I use?
Use Output_PER for a 4–20 mA or 0–10 V actuator. Use Output when your own code must linearise or split the signal. Use Output_PWM for heaters on solid-state relays. With PWM, the PID algorithm sampling time is the pulse period, and every pulse lasts a whole number of OB cycles. A period ten times the OB interval therefore gives 10% steps.
Is pretuning alone enough?
For a slow, non-critical loop it often is. When overshoot or disturbance rejection matters, also run fine tuning at the real operating point. Pretuning followed by fine tuning gives the best parameters PID_Compact can find by itself.

Alessandro Strongoli has been programming PLCs and commissioning machines and plants for many years: S7-1200/S7-1500 with TIA Portal, WinCC panels, SINAMICS drives. Writing here since 2021. About the author
Parti gratis, poi i corsi passo-passo per installarlo e programmarlo.
Corso GRATIS su UdemyCorso completo: Come installare e aggiornare il TIA Portal
Libri: PLC S7-1200 Guida Completa · PLC per Principianti
Percorso: Infarinatura PLC Siemens


