PID_Compact must be called from a cyclic interrupt OB (for example OB30 or OB35) so it runs at a fixed sampling time. Connect Setpoint, the scaled process value at Input or the raw analog value at Input_PER, and take the manipulated variable from Output, Output_PER or Output_PWM. Set output limits and process value limits first, then run pretuning followed by fine tuning.
- A PID loop only behaves consistently when its sampling time is fixed, so it belongs in a cyclic interrupt OB, never in OB1.
- Scaling, output limits and process value limits are configured before tuning; tuning a badly scaled loop wastes commissioning time.
- Pretuning finds a starting parameter set, fine tuning refines it at the working setpoint, and both need a stable, disturbance-free process.
Where PID_Compact Fits in a Control Loop
Open-loop control switches an output on and off. Closed-loop control measures the result and keeps correcting it. A heater that is simply switched on when temperature is low will overshoot; a PID controller continuously calculates how much heating is needed to hold the setpoint.
Every closed loop has the same four elements, and PID_Compact sits in the middle of them:
- Setpoint: the value the process should reach, entered by the operator or supplied by a recipe.
- Process value: the measurement from a transmitter, scaled into engineering units.
- Manipulated variable: the controller output that drives a valve, drive or heater.
- Error and correction: proportional, integral and derivative action applied to the difference between the two.
Proportional action reacts to the size of the present error, integral action removes the remaining steady-state offset, and derivative action responds to how fast the error is changing. Many industrial loops run well as PI only, with derivative left out because it amplifies measurement noise.
Before writing any PID code, confirm the measurement itself is trustworthy. If the analog input is not correctly scaled, no amount of tuning will produce stable control. Work through analog input scaling in TIA Portal first.
Calling PID_Compact in a Cyclic Interrupt OB
PID_Compact is a technology object with its own instance data block. Drag it from the Technology instructions into a cyclic interrupt organisation block so that it executes at a fixed interval. OB30 or OB35 with a 100 ms cycle is a common starting point for temperature loops; fast pressure and flow loops may need 20 to 50 ms.
The sampling time of the controller must match the OB cycle time. If the block is called from OB1 instead, the interval changes with program load and the integral and derivative calculations drift.
| Parameter | Purpose | Typical source |
|---|---|---|
| Setpoint | Target value in engineering units | HMI setpoint tag or recipe DB |
| Input | Process value already scaled in the program | REAL from SCALE_X |
| Input_PER | Raw peripheral value from the analog card | IW address of the input channel |
| Output | Manipulated variable 0.0 to 100.0 percent | To valve position or drive reference |
| Output_PER | Manipulated variable as a peripheral value | QW address of the analog output |
| Output_PWM | Pulse width modulated digital output | Heater contactor or SSR |
| ManualEnable / ManualValue | Switch to manual and set output directly | Operator command from HMI |
| State / Error / ErrorBits | Operating mode and diagnostics | Displayed on HMI faceplate |
Use either Input or Input_PER, not both, and the same rule applies on the output side. Mixing them is one of the most common causes of a loop that never leaves its start-up state.
Configuring Setpoint, Scaling and Limits
Open the configuration editor of the technology object and work through it top to bottom before you attempt any tuning.
Controller type and units
Select the physical quantity and unit, for example temperature in degrees Celsius. This affects only display, but it makes the faceplate and trends readable for maintenance staff later.
Process value scaling
If you use Input_PER, enter the low and high scaled values that correspond to the raw range of the transmitter. A 0 to 400 degree thermocouple input and a 4 to 20 mA pressure transmitter are scaled differently, so check the instrument datasheet rather than assuming a default.
Process value monitoring
Set warning and error limits on the process value. When the measurement leaves the valid band, the controller reports an error and can switch to a substitute output value instead of driving the actuator with meaningless data.
Output limits
Restrict the manipulated variable to the range the actuator can actually use, for example 0 to 100 percent, or 20 to 90 percent for a control valve that should never fully close. Output limiting is also what protects the loop from integral windup during long start-up ramps.
Want to practise a live PID loop on hardware?
Softwell runs Siemens sessions with real temperature and flow trainers, online, in the Pune classroom or in-plant.
Pretuning, Fine Tuning and Manual Mode
Tuning is done online with the commissioning editor of the technology object. Open it, start measurement, and watch the setpoint, process value and output on the built-in trend.
- Pretuning: run it with the process stable and away from the setpoint. The controller applies a step, measures the response and calculates a starting parameter set.
- Fine tuning: run it once the process is near the setpoint. It produces a controlled oscillation to refine the parameters for normal operating conditions.
- Upload the parameters: transfer the tuned values into the project so they survive the next download.
Manual mode is not only a tuning aid. During commissioning it lets you drive the actuator to a fixed percentage and confirm the mechanical response before closing the loop. Wire ManualEnable and ManualValue to HMI controls so a maintenance engineer can take a loop to manual safely.
Common problems and what they usually mean
| Symptom | Likely cause |
|---|---|
| Output stuck at 0 or 100 percent | Reversed control action, or setpoint outside the scaled process value range |
| Continuous oscillation | Proportional gain too high or sampling time too slow for the process |
| Very slow approach to setpoint | Integral time too long, or output limits too narrow |
| Pretuning aborts with an error | Process not stable at start, or the process value is not changing when the output changes |
| Noisy output with derivative enabled | Measurement noise amplified; filter the input or use PI only |
Log the tuned parameters, the date and the operating conditions in your handover documentation. A loop tuned for an empty tank rarely stays optimal for a full one.
Hands-On Lab: Build and Tune a Temperature Loop with PID_Compact
Hands-on- TIA Portal V16 or later with an S7-1200 or S7-1500 CPU, or PLCSIM with a simulated process
- One analog input for the process value and one analog output or PWM output for the actuator
- A test loop only; never tune a live production heater without permission
- Estimated time: 45 minutes
Create the cyclic interrupt OB
Add OB30 with a cycle time of 100 ms and call PID_Compact inside it. Confirm the instance data block is created automatically.
Wire the interface
Connect Setpoint to an HMI tag, the transmitter to Input_PER and the actuator to Output_PER. Leave Input and Output unconnected.
Configure scaling and limits
Set the process value range to match the transmitter, add warning and error limits, and restrict the output to a safe range.
Run pretuning
Open the commissioning editor, start measurement, set a setpoint well away from the current value and start pretuning.
Fine tune and save
With the process near setpoint, run fine tuning, then upload the parameters into the project and download the project again.
The loop holds setpoint under a small load change, manual mode works from the HMI, output limits are respected, and the tuned parameters are saved in the offline project.
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 program load, which makes the integral and derivative calculation inconsistent.
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 normally 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 recovering from a previous change will all cause it to abort.
