PLC Programming · Technical Blog

PID Controller in Siemens PLC: PID_Compact Instruction and Tuning Guide

Close the loop on temperature, pressure, flow or level control. This lesson shows how PID_Compact is called, configured, scaled, tuned and commissioned in TIA Portal, and how the loop is presented to the operator on HMI and SCADA.

2,500+ engineers trained 4.9/5 Google rating 21+ years, Chinchwad, Pune Next batch: contact for dates
Quick answer

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.

ParameterPurposeTypical source
SetpointTarget value in engineering unitsHMI setpoint tag or recipe DB
InputProcess value already scaled in the programREAL from SCALE_X
Input_PERRaw peripheral value from the analog cardIW address of the input channel
OutputManipulated variable 0.0 to 100.0 percentTo valve position or drive reference
Output_PERManipulated variable as a peripheral valueQW address of the analog output
Output_PWMPulse width modulated digital outputHeater contactor or SSR
ManualEnable / ManualValueSwitch to manual and set output directlyOperator command from HMI
State / Error / ErrorBitsOperating mode and diagnosticsDisplayed 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.

Book a Free Demo Class

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.

  1. 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.
  2. Fine tuning: run it once the process is near the setpoint. It produces a controlled oscillation to refine the parameters for normal operating conditions.
  3. 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

SymptomLikely cause
Output stuck at 0 or 100 percentReversed control action, or setpoint outside the scaled process value range
Continuous oscillationProportional gain too high or sampling time too slow for the process
Very slow approach to setpointIntegral time too long, or output limits too narrow
Pretuning aborts with an errorProcess not stable at start, or the process value is not changing when the output changes
Noisy output with derivative enabledMeasurement 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
Before you start
  • 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
1

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.

The block compiles and the cyclic interrupt appears in the program blocks folder.
2

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.

No compile warnings about duplicate or missing input and output assignments.
3

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.

The configuration editor shows no red error markers on any screen.
4

Run pretuning

Open the commissioning editor, start measurement, set a setpoint well away from the current value and start pretuning.

Pretuning completes and calculated parameters appear in the parameter list.
5

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 process value settles at setpoint with minimal overshoot and the parameters persist after download.
Checkpoint—how to know you did it right

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.

Reviewed by Bhawesh Kumar SinghIndustrial Automation Trainer and Industry 4.0 Consultant · Softwell Automation · 21+ years industry experience

Get the full syllabus + free demo class

Share your details—a Softwell training advisor will contact you with batch dates, fees and hardware-practice options.

No spam. Used only to share course details for this enquiry.

Learn with practical industrial examples

Join live online, Pune classroom or corporate in-plant automation training.

Request Course Details
Verified learning pathway

Discuss PID Controller in Siemens PLC

Explore practical curriculum, software, hardware and batch options for this technology.

Content reviewed: 09 September 2026

Siemens PLC & TIA Portal Learning Path

Continue with the related Siemens PLC tutorials in this practical learning series.

  1. SCL vs Ladder Logic
  2. Upload PLC Program
  3. TIA Selection Tool
  4. Analog Input Scaling
  5. PLC Counters
  6. PLC Timers
  7. Addressing & Data Types
  8. Hardware & PLC Tags
  9. OB, FB, FC & DB
☎ Call WhatsApp ✉ Email Enquire Now