Bird
Raised Fist0
PLC Programmingscripting~10 mins

PID temperature control system in PLC Programming - Step-by-Step Execution

Choose your learning style10 modes available
Concept Flow - PID temperature control system
Read Temperature Sensor
↓
Calculate Error = Setpoint - Measured
↓
Compute P, I, D terms
↓
Sum PID Output
↓
Adjust Heater Power
↓
Wait for next cycle
↩Back to Read Temperature Sensor
The system reads the temperature, calculates the error from the setpoint, computes PID terms, adjusts heater power, and repeats continuously.
Execution Sample
PLC Programming
SETPOINT := 75.0;
MEASURED := 70.0;
ERROR := SETPOINT - MEASURED;
P_TERM := KP * ERROR;
OUTPUT := P_TERM;
HEATER_POWER := OUTPUT;
This code calculates the proportional term of PID and sets heater power accordingly.
Execution Table
StepVariableValueCalculation/ActionOutput/Effect
1SETPOINT75.0Set desired temperature-
2MEASURED70.0Read current temperature-
3ERROR5.075.0 - 70.0-
4P_TERM10.0KP(2.0) * ERROR(5.0)-
5OUTPUT10.0Sum of PID terms (only P here)-
6HEATER_POWER10.0Set heater power to outputHeater power adjusted
7MEASURED72.0Next cycle: temperature rises-
8ERROR3.075.0 - 72.0-
9P_TERM6.02.0 * 3.0-
10OUTPUT6.0Updated PID output-
11HEATER_POWER6.0Adjust heater power downHeater power adjusted
12MEASURED75.0Next cycle: temperature reached-
13ERROR0.075.0 - 75.0-
14P_TERM0.02.0 * 0.0-
15OUTPUT0.0PID output zero-
16HEATER_POWER0.0Turn off heaterHeater power off
17--Temperature stable at setpointSystem steady
💡 Temperature reached setpoint; error zero; heater power off; system stable
Variable Tracker
VariableStartAfter Step 3After Step 6After Step 9After Step 11After Step 13After Step 16Final
SETPOINT75.075.075.075.075.075.075.075.0
MEASURED70.070.070.072.072.075.075.075.0
ERROR-5.05.03.03.00.00.00.0
P_TERM--10.06.06.00.00.00.0
OUTPUT--10.06.06.00.00.00.0
HEATER_POWER--10.010.06.06.00.00.0
Key Moments - 3 Insights
Why does the heater power decrease when the temperature rises?
Because the error (setpoint - measured) gets smaller as temperature approaches setpoint, reducing the proportional term and thus heater power, as shown in steps 8-11.
Why is the heater power zero when the temperature equals the setpoint?
At step 13, error is zero, so the proportional term and output become zero, turning off the heater (step 16). This prevents overheating.
What happens if the measured temperature is higher than the setpoint?
The error becomes negative, which would reduce heater power or turn it off to cool down. This is implied by the error calculation in step 3 and output adjustment.
Visual Quiz - 3 Questions
Test your understanding
Look at the execution table, what is the ERROR value at step 8?
A5.0
B0.0
C3.0
D2.0
💡 Hint
Check the ERROR column at step 8 in the execution_table rows.
At which step does the HEATER_POWER first become zero?
AStep 11
BStep 16
CStep 13
DStep 6
💡 Hint
Look at HEATER_POWER values in execution_table rows for when it changes to 0.0.
If the KP value doubled, how would the P_TERM at step 4 change?
AIt would double from 10.0 to 20.0
BIt would stay 10.0
CIt would halve to 5.0
DIt would become zero
💡 Hint
P_TERM = KP * ERROR; doubling KP doubles P_TERM as seen in step 4.
Concept Snapshot
PID Temperature Control System:
- Reads temperature sensor
- Calculates error = setpoint - measured
- Computes PID terms (P, I, D)
- Adjusts heater power based on PID output
- Repeats continuously to maintain setpoint
Full Transcript
This visual execution trace shows a PID temperature control system in a PLC program. The system reads the current temperature, calculates the error from the desired setpoint, computes the proportional term (P_TERM) by multiplying error by KP, and sets the heater power accordingly. As the temperature rises closer to the setpoint, the error and heater power decrease. When the temperature reaches the setpoint, the error and heater power become zero, turning off the heater to maintain stability. The trace follows variable changes step-by-step, showing how the system adjusts heater power to control temperature effectively.

Practice

(1/5)
1. What is the main purpose of a PID controller in a temperature control system?
easy
A. To increase the temperature without feedback
B. To keep the temperature steady by adjusting the output based on error
C. To turn the heater on and off randomly
D. To measure the temperature only

Solution

  1. Step 1: Understand PID controller role

    A PID controller adjusts output to reduce the difference between desired and actual temperature.
  2. Step 2: Identify correct purpose

    Only To keep the temperature steady by adjusting the output based on error describes this feedback control to keep temperature steady.
  3. Final Answer:

    To keep the temperature steady by adjusting the output based on error -> Option B
  4. Quick Check:

    PID controls temperature by error adjustment = D [OK]
Hint: PID controls by error correction, not just measuring [OK]
Common Mistakes:
  • Confusing measurement with control
  • Thinking PID turns heater randomly
  • Ignoring feedback in control
2. Which of the following is the correct way to represent the proportional term in a PID control formula in PLC programming?
easy
A. P = error / Kp
B. P = Kp - error
C. P = Kp + error
D. P = Kp * error

Solution

  1. Step 1: Recall proportional term formula

    The proportional term multiplies the proportional gain (Kp) by the error value.
  2. Step 2: Match formula to options

    Only P = Kp * error correctly shows multiplication of Kp and error.
  3. Final Answer:

    P = Kp * error -> Option D
  4. Quick Check:

    Proportional term = Kp * error [OK]
Hint: Proportional term multiplies gain by error [OK]
Common Mistakes:
  • Dividing error by gain instead of multiplying
  • Adding or subtracting gain and error
  • Confusing proportional with integral or derivative
3. Given the following PLC code snippet for a PID controller output calculation:
error = setpoint - temperature
P = Kp * error
I = I + Ki * error
D = Kd * (error - last_error)
output = P + I + D
last_error = error
print(output)

If setpoint=100, temperature=90, Kp=2, Ki=0.5, Kd=1, I=5, and last_error=8, what will be printed?
medium
A. 32.0
B. 30.0
C. 20.0
D. 15.5

Solution

  1. Step 1: Calculate error and PID terms

    error = 100 - 90 = 10
    P = 2 * 10 = 20
    I = 5 + 0.5 * 10 = 10
    D = 1 * (10 - 8) = 2
  2. Step 2: Calculate output and print

    output = P + I + D = 20 + 10 + 2 = 32
    print(output) will print 32.0
  3. Final Answer:

    32.0 -> Option A
  4. Quick Check:

    20 + 10 + 2 = 32.0 [OK]
Hint: Calculate each PID term stepwise, then sum [OK]
Common Mistakes:
  • Mixing up error and last_error
  • Forgetting to update integral term
  • Adding terms incorrectly
4. Identify the error in this PLC PID control snippet:
error = setpoint - temperature
I = I + Ki * error
D = Kd * (error - last_error)
output = Kp * error + I + D
last_error = error
if output < 0:
    output = 0
print(output)

Assuming all variables are initialized, what is the main problem?
medium
A. Integral term I is not initialized before use
B. Derivative term D uses wrong error difference
C. Output is not limited to maximum value
D. last_error is updated before output calculation

Solution

  1. Step 1: Review output limiting logic

    The code limits output only if it is less than 0, setting output to 0. But it does not limit output above a maximum safe value.
  2. Step 2: Check other parts for errors

    Integral term I is updated correctly assuming initialized.
    Derivative term uses (error - last_error), which is correct.
    last_error is updated after output calculation, which is correct.
  3. Final Answer:

    Output is not limited to maximum value -> Option C
  4. Quick Check:

    Output upper limit missing = A [OK]
Hint: Check if output has both lower and upper limits [OK]
Common Mistakes:
  • Assuming only lower limit is enough
  • Updating last_error too early
  • Confusing derivative calculation
5. You want to improve the stability of a PID temperature control system that oscillates around the setpoint. Which tuning change is most likely to reduce oscillations?
hard
A. Increase the derivative gain (Kd)
B. Increase the integral gain (Ki)
C. Decrease the proportional gain (Kp)
D. Remove the derivative term

Solution

  1. Step 1: Understand causes of oscillation

    High proportional gain can cause oscillations. Integral gain affects steady-state error. Derivative gain helps dampen oscillations.
  2. Step 2: Choose tuning to reduce oscillations

    Increasing derivative gain adds damping, reducing oscillations and improving stability.
  3. Final Answer:

    Increase the derivative gain (Kd) -> Option A
  4. Quick Check:

    More derivative gain reduces oscillations = A [OK]
Hint: Increase derivative gain to damp oscillations [OK]
Common Mistakes:
  • Decreasing Kp too much causing slow response
  • Increasing Ki causing more oscillations
  • Removing derivative term losing damping effect
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