This example demonstrates how to implement a basic, yet robust, PID control loop using the PID_Compact technology object, with full configuration and runtime control via a structured global data block.

Step 1: Global Data Structure Design

Create a global DB structure named autoFunction with the following elements:

Structure

Step 2: Create a PID_Compact Technology Object

Inside the project:

  • Go to Technology Objects → Add new → Select PID_Compact.
  • In the Configuration tab:
    • Set Mode to Automatic.
    • Set Process Value Limits:
      • valueUpperDeadband := machine.autoFunction.pidSetpoint + machine.autoFunction.pidConfig.deadband;

Technology Object: PID

Invert Control Logic (If Needed)

IF (machine.autoFunction.actualValue – machine.autoFunction.pidSetpoint) < 0 THEN

    autoFunction_.Config.InvertControl := TRUE;

ELSE

    autoFunction_.Config.InvertControl := FALSE; END_IF;

Apply PID Output and Global Gain

// Store raw output

machine.autoFunction.pidOut := output;

// Apply global gain and clamp to -100..100

output := LIMIT(

    MN := -100.0,

    IN := (autoFunction_.Output * machine.autoFunction.pidConfig.globalGain1) / 100,

    MX := 100.0 );

Reset PID Output If Within Deadband or Not Enabled

IF ((machine.autoFunction.actualValue < valueUpperDeadband) AND

    (machine.autoFunction.actualValue > valueLowerDeadband)) OR

    NOT machine.autoFunction.enableAutoFunction THEN

    output := 0.0;

END_IF;


 Key Benefits of This Approach

  • Fully Dynamic Configuration: No hardcoded tuning values.
  • Deadband Handling: Prevents unnecessary actuator movement.
  • Direction Awareness: Inverted control if setpoint is below process value.
  • Output Scaling: Global gain allows smooth fine-tuning.
  • Safe Fallback: Resets output automatically when PID should not act.

Basic Configuration 1

Set Process Value High and Low Limit

Set Output Value High and Low Limit

Set PID parameters

Create a Function block with basic variables

Initialize basics parameters & call technology into FB

Basic PID logic

PID Commissioning -Pretuning

PID disabled

PID enabled and locked at 86 due to  r_trig  on enable

PID enabled and locked at 86. No output due to deadband

PID enabled and locked at 86. PID reaching setpoint.

PID enabled and locked at 86. PID reaching setpoint. (Invert Control is True now)


If you found this helpful, please consider supporting with a small donation. Thank you!

Posted in

One response to “TIA Portal Tutorial: Implementing and Tuning PID Control with PID_Compact (Part 2)”

  1. […] TIA Portal Tutorial: Implementing and Tuning PID Control with PID_Compact (Part 2) […]

Leave a Reply to TIA Portal Tutorial: From Development to Optimization – PLC Steps – Your Guide to Industrial AutomationCancel reply

Discover more from PLC Steps - Your Guide to Industrial Automation

Subscribe now to keep reading and get access to the full archive.

Continue reading