Scale the process value in the input mapping, call PID_Compact from a cyclic interrupt OB such as OB30 so the sample time is constant, set output and process value limits before tuning, run pretuning then fine tuning, and give the HMI setpoint, process value, output, mode and manual value.
- PID belongs in a cyclic interrupt OB, not OB1.
- Set limits before tuning.
- Manual and automatic must switch bumplessly.
Where PID_Compact Fits in a Control Loop
The loop is sensor → scaled process value → PID → output → actuator → process. PID_Compact compares setpoint and process value and calculates the output from proportional, integral and derivative parts. It contains its own commissioning tools: pretuning finds the first parameters from a step response, fine tuning refines them around the setpoint.
Lab Flow: From Temperature Sensor to a Tuned Loop
Every lesson in the Softwell PLC lab manual series follows the same six stages and the same address rule, so the code you write here plugs straight into the HMI lessons.
Stage 1Field Signals and PLC Tags
| PLC tag | Address | Type | Device / comment |
|---|---|---|---|
TT70_Raw | %IW106 | Int | Oven thermocouple transmitter 4–20 mA = 0 – 300 °C |
SCR70_Ref | %QW86 | Int | Thyristor power controller 0 – 10 V = 0 – 100 % |
Stage 2Input Mapping and Scaling
// FC_InputMapping "DB_IO".TT70_degC := SCALE_X(MIN := 0.0, MAX := 300.0, VALUE := NORM_X(MIN := 0, VALUE := "TT70_Raw", MAX := 27648));
Scaling options and plausibility checks: PLC analog input scaling.
Stage 3Logic: PID_Compact in a Cyclic Interrupt OB
// OB30 "Cyclic interrupt", cycle 100 ms
"PID_Oven"(Setpoint := "DB_Oven2".SP,
Input := "DB_IO".TT70_degC, // already scaled → use Input, not Input_PER
ManualEnable := "DB_Oven2".Manual,
ManualValue := "DB_Oven2".ManualValue,
Output => "DB_Oven2".Out_pct);
// FC_OutputMapping
"SCR70_Ref" := REAL_TO_INT("DB_Oven2".Out_pct * 276.48); // 0–100 % → 0–27648| Setting (PID_Compact configuration) | Value | Why |
|---|---|---|
| Controller type | Temperature, °C | Units on the commissioning screen |
| Process value limits | 0 – 300 °C | Error if the sensor leaves the range |
| Output limits | 0 – 100 % | Actuator range |
| Sample time | from OB30 (100 ms) | Constant time base for I and D |
The constant time base is explained in the scan cycle lesson.
Stage 4Link PLC Tags to the HMI
| HMI tag | PLC member | Used by |
|---|---|---|
DB_Oven2_SP | "DB_Oven2".SP | Setpoint input, limits |
DB_IO_TT70_degC | "DB_IO".TT70_degC | PV field and trend |
DB_Oven2_Out_pct | "DB_Oven2".Out_pct | Output field and trend |
DB_Oven2_Manual / _ManualValue | "DB_Oven2".Manual / ManualValue | Mode button, manual input |
Stage 5Link the Graphics
| # | Object | Properties | Tag / event |
|---|---|---|---|
| ① | Trend view | PV, SP (dashed) and output on two axes | Logged or real-time curves |
| ② | I/O field setpoint | Limits; authorisation Operator | DB_Oven2_SP |
| ③ | Button MANUAL/AUTO | InvertBit; authorisation Maintenance | DB_Oven2_Manual |
| ④ | I/O field manual value | Visible only in manual | DB_Oven2_ManualValue |
Trend configuration: HMI trends and data logs; setpoint entry: HMI I/O fields.
Stage 6Perform and Test: Oven Temperature Loop
A PID controls an oven heater. Change setpoint and gains, apply the pretuning result, switch to manual and back (bumpless), and move the PID from the cyclic interrupt OB into OB1 to see why the sample time must be constant. Time runs 10× faster.
Troubleshooting
| Symptom | Likely cause | First check |
|---|---|---|
| Loop oscillates | Gain too high or Ti too short | Retune; check actuator |
| Output stuck at limit | Limits wrong or wind-up | Output limits, PV range |
| Erratic behaviour | PID called in OB1 | Move to OB30 |
| Pretuning error | Process not stable or actuator not moving | Wait for steady state; test the actuator |
Hands-On Lab: Build and Tune a Temperature Loop with PID_Compact
Hands-on- TIA Portal with an S7-1200/1500 or PLCSIM with a simulated process
- Estimated time: 90 minutes
Wire and declare the loop signals
Declare TT70_Raw and the SCR heater reference SCR70_Ref.
Scale into DB_IO
Scale TT70 to °C in FC_InputMapping.
Call PID_Compact in OB30
Create OB30 (100 ms), call PID_Oven with Setpoint, Input and Output; set limits.
Link HMI tags
Publish setpoint, PV, output, mode and manual value.
Build the PID faceplate
Trend with PV, SP and output, input fields and a MANUAL/AUTO button.
Tune and test
Pretune, fine tune, step the setpoint and test manual/auto switching.
The loop runs at a constant sample time, within its limits, tuned by pretuning and fine tuning, and the operator can see and take control of it from the panel.
Frequently asked questions
Can PID_Compact be called in OB1?
It is technically possible but not recommended. The controller needs a constant sampling time, and OB1 cycle time varies with load, which distorts the integral and derivative calculation.
What is the difference between PID_Compact and PID_3Step?
PID_Compact drives a continuous actuator such as a control valve, drive reference or PWM heater output. PID_3Step drives a motorised valve using open and close pulses with optional position feedback.
Do I need derivative action?
Many industrial loops run as PI only. Derivative reacts to the rate of change and amplifies measurement noise, so it is used only on slow processes with a clean signal.
Why does pretuning fail with an error?
Pretuning needs a stable process before it starts and a measurable response to its test step. A noisy signal, an actuator that is not moving, or a process still settling usually causes the failure.
Should the process value be scaled before PID_Compact?
Use Input with a value already scaled in the input mapping, or Input_PER with the raw value and the scaling configured in the PID. Doing both scales twice.
How does the operator switch PID to manual?
Through the PID mode and a manual value from the HMI, written into the instance DB or an interface DB. PID_Compact switches bumplessly when configured correctly.