Bird
Raised Fist0
PLC Programmingscripting~5 mins

PID function block for process control in PLC Programming

Choose your learning style10 modes available
Introduction
A PID function block helps control machines by adjusting outputs to keep things like temperature or speed steady and close to a target.
Keeping the temperature of an oven steady while baking.
Controlling the speed of a motor to stay constant despite load changes.
Maintaining the level of liquid in a tank at a set point.
Adjusting the pressure in a pipe to a desired value.
Balancing the flow rate of a pump to match demand.
Syntax
PLC Programming
PID(
  IN: REAL;       // Process variable (measured value)
  SP: REAL;       // Set point (desired value)
  Kp: REAL;       // Proportional gain
  Ki: REAL;       // Integral gain
  Kd: REAL;       // Derivative gain
  OUT: REAL;      // Control output
  RESET: BOOL;    // Reset integral term
  TIME: TIME;     // Sample time
);
IN is the current value you measure from the process.
SP is the target value you want to reach and keep.
Examples
Controls heater power to keep temperature at 100 degrees.
PLC Programming
TempPID(
  IN := Temperature,
  SP := 100.0,
  Kp := 2.0,
  Ki := 0.5,
  Kd := 1.0,
  OUT => HeaterPower,
  RESET := FALSE,
  TIME := T#1s
);
Adjusts motor voltage to maintain speed at 1500 RPM.
PLC Programming
MotorPID(
  IN := MotorSpeed,
  SP := 1500.0,
  Kp := 1.5,
  Ki := 0.3,
  Kd := 0.2,
  OUT => MotorVoltage,
  RESET := ResetSignal,
  TIME := T#100ms
);
Sample Program
This program uses a PID function block to control heater power and keep temperature near 100 degrees. It simulates temperature rising based on heater power.
PLC Programming
PROGRAM PID_Control
VAR
  Temperature : REAL := 90.0;
  SetPoint : REAL := 100.0;
  HeaterPower : REAL := 0.0;
  ResetPID : BOOL := FALSE;
  SampleTime : TIME := T#1s;
  Kp : REAL := 2.0;
  Ki : REAL := 0.5;
  Kd : REAL := 1.0;
  PID_FB : PID;
END_VAR

// Call PID function block
PID_FB(
  IN := Temperature,
  SP := SetPoint,
  Kp := Kp,
  Ki := Ki,
  Kd := Kd,
  OUT => HeaterPower,
  RESET := ResetPID,
  TIME := SampleTime
);

// Simulate temperature increase
Temperature := Temperature + HeaterPower * 0.1;

// Output heater power
END_PROGRAM
OutputSuccess
Important Notes
The PID block needs regular calls at fixed intervals for best control.
Tuning Kp, Ki, and Kd values is important to avoid overshoot or slow response.
Resetting the integral term can help when starting or after big changes.
Summary
PID function blocks help keep a process variable close to a target.
You set gains (Kp, Ki, Kd) to control how the output reacts.
Use PID blocks in loops that run regularly to adjust outputs smoothly.

Practice

(1/5)
1. What is the main purpose of a PID function block in process control?
easy
A. To keep a process variable close to a desired target value
B. To store data for later analysis
C. To display process values on a screen
D. To manually adjust valves and switches

Solution

  1. Step 1: Understand the role of PID blocks

    PID blocks automatically adjust outputs to keep a process variable near a setpoint.
  2. Step 2: Compare options to this role

    Only To keep a process variable close to a desired target value describes this automatic control function; others describe unrelated tasks.
  3. Final Answer:

    To keep a process variable close to a desired target value -> Option A
  4. Quick Check:

    PID controls process variable = keep near target [OK]
Hint: PID blocks control variables automatically, not manually [OK]
Common Mistakes:
  • Thinking PID stores data instead of controlling
  • Confusing PID with display or manual control
  • Assuming PID only measures values
2. Which of the following is the correct way to declare a PID function block instance named pid1 in a PLC program?
easy
A. pid1 : PID;
B. pid1 = PID();
C. PID pid1;
D. pid1 -> PID();

Solution

  1. Step 1: Recall PLC function block declaration syntax

    In PLC languages like Structured Text, function blocks are declared with name : Type;.
  2. Step 2: Match options to this syntax

    pid1 : PID; matches the correct syntax; others use incorrect assignment or C-like syntax.
  3. Final Answer:

    pid1 : PID; -> Option A
  4. Quick Check:

    Function block declaration uses colon and semicolon [OK]
Hint: Use colon and semicolon to declare function blocks [OK]
Common Mistakes:
  • Using equal sign instead of colon
  • Using C or Java style declarations
  • Using arrow operator incorrectly
3. Given the following PLC code snippet using a PID block:
pid1.Kp := 2.0;
pid1.Ki := 0.5;
pid1.Kd := 0.1;
pid1.SetPoint := 100;
pid1.ProcessVariable := 90;
pid1();
Output := pid1.ControlOutput;

What is the expected behavior of Output after this code runs once?
medium
A. Output will be negative to decrease the process variable
B. Output will be zero because PID needs multiple cycles
C. Output will be a positive value to increase the process variable
D. Output will equal the SetPoint value

Solution

  1. Step 1: Analyze PID inputs and error

    The error is SetPoint (100) minus ProcessVariable (90) = 10, positive error.
  2. Step 2: Understand PID output direction

    Positive error means output should increase to raise the process variable, so output is positive.
  3. Final Answer:

    Output will be a positive value to increase the process variable -> Option C
  4. Quick Check:

    Positive error -> positive output to correct [OK]
Hint: Positive error means output pushes variable up [OK]
Common Mistakes:
  • Assuming output is zero on first run
  • Confusing output direction with error sign
  • Thinking output equals setpoint directly
4. Identify the error in this PID block usage snippet:
pid1.Kp := 1.5;
pid1.Ki := 0.3;
pid1.Kd := 0.05;
pid1.SetPoint := 50;
pid1.ProcessVariable := 55;
Output := pid1.ControlOutput;
pid1();
medium
A. Assigning ProcessVariable before SetPoint
B. Setting Kp, Ki, Kd values too low
C. Missing declaration of pid1
D. Calling the PID block function pid1() after reading output

Solution

  1. Step 1: Check order of function call and output read

    The PID block must be called (executed) before reading ControlOutput to update output.
  2. Step 2: Identify the mistake in code order

    Here, Output is assigned before pid1() is called, so output is stale or invalid.
  3. Final Answer:

    Calling the PID block function pid1() after reading output -> Option D
  4. Quick Check:

    Call PID block before reading output [OK]
Hint: Always call PID block before reading output [OK]
Common Mistakes:
  • Reading output before calling PID block
  • Confusing parameter order
  • Ignoring function block declaration
5. You want to tune a PID block to control temperature in a tank. The temperature rises too slowly and overshoots the target. Which tuning change should you make to reduce overshoot and improve response?
hard
A. Decrease Kp and increase Ki
B. Decrease Kp and increase Kd
C. Increase Kp and decrease Kd
D. Increase Ki and Kd equally

Solution

  1. Step 1: Understand overshoot and slow rise causes

    High Kp causes overshoot; low Kd means less damping; slow rise means Kp might be too low.
  2. Step 2: Choose tuning to reduce overshoot and improve speed

    Decreasing Kp reduces overshoot; increasing Kd adds damping to reduce oscillations and overshoot.
  3. Final Answer:

    Decrease Kp and increase Kd -> Option B
  4. Quick Check:

    Lower Kp + higher Kd = less overshoot, better control [OK]
Hint: Lower Kp and raise Kd to reduce overshoot [OK]
Common Mistakes:
  • Increasing Kp causes more overshoot
  • Ignoring derivative gain effect
  • Changing Ki without addressing overshoot
Recommended

Ready to prove it?

Pass the test and this pattern moves unknown strong while earning +1 Grip toward your certificate.

10 questions~5 mineasy hard