Skip to main content
Print

PID loop using the Start/Continue PID block: maintaining the air at 30°C by controlling a damper

 

This tutorial walks you through a complete, working PID loop using the PID Start/Continue block. We use one real example from start to finish: keeping water at 30 °C by driving a valve. Follow the same steps for your own application and replace the values with yours.

The example in one sentence: a temperature sensor is read on an analog input, the PID compares it with a 30 °C target and opens or closes a valve through a PWM output.

The example setup

Item In our example
Measurement Temperature sensor on analog input InI16A1 (0–4095)
Target 30 °C
Actuator Valve driven by PWM, 17200 = closed, 19200 = fully open
Direction Opening the valve raises the temperature

Check the direction first.
The PID opens the valve when the measurement is below the target. That is only correct if opening the valve raises the measurement (hot water, heating). If it lowers it (cold water, cooling), the loop will run away instead of settling.

Convert the analog input into a real unit

Work in a unit people understand. Here we convert the raw input into temperature × 100 (so 30.00 °C = 3000) with a linear scaling block.

We measured two real points (41 °C read 1414, 44 °C read 1581), then extended the line to both ends of the input scale:

Raw input (InI16A1) Temperature × 100 (Temperature)
0 1560 (15.60 °C)
1414 4100 (41.00 °C) – measured
1581 4400 (44.00 °C) – measured
4095 8916 (89.16 °C)
Tip: calibrate with two points that surround your working temperature. Points far from the set point give a less accurate reading at the set point.

Set the target in the same unit

Copy the target into ConsigneTemp: 30 °C × 100 = 3000. The target and the measurement must always use the same unit.

Convert the PID output into the actuator signal

The PID works with a simple 0–100 % valve opening (ClapetPourCent). A second scaling block converts it into the PWM value the valve needs:

Valve opening (ClapetPourCent) PWM value (positionclapet)
0 % 17200
100 % 19200

The PWM period (20000 µs here) is set once at startup.

Finer control: with 0–100 the valve moves in 1 % steps (20 PWM points each). Use 0–1000 on both the PID output and the scaling block for steps of 2 PWM points.

Fill in the PID block

Field Value Why
Output ClapetPourCent Valve opening calculated by the PID. Nothing else in the program may write to it.
Output Max / Min 100 / 0 Fully open / fully closed. On start, the output begins at Output Min.
Process Variable Temperature The scaled measurement from step 1.
Set Point ConsigneTemp The target from step 2, in the same unit.
Input Max / Min 8916 / 1560 The full range of the scaled measurement. The measurement can never leave this range.
Sample Rate 50 ms How often the PID recalculates.
Proportional (Gain) 7 Reaction strength. Here, 1 °C of error opens the valve about 10 %.
Integral (Reset) 0.1 Removes the remaining error over time. Higher = faster.
Derivative (Rate) 0 Not needed to start.
Most common mistake: Input Min / Max. They must be in the same unit as the Process Variable, and the measurement must always stay between them. If it goes outside, the PID stops responding and the output stays stuck at a limit. Using the full range of the scaled input (step 1) guarantees this.

How to read the gain

The PID works in percentages. The error is divided by the input range, multiplied by the gain, and applied to the output range.

Gain Valve opening per 1 °C of error Error for a full valve stroke
4 about 5.4 % about 18 °C
7 about 10 % about 10 °C

Our input range is 8916 − 1560 = 7356, i.e. 73.56 °C. With a gain of 7: 1 / 73.56 × 7 ≈ 9.5 %, so about 10 % per °C. If you change Input Min / Max, the same gain gives a different reaction: halving the range doubles the effect.

How to read the integral

Integral (Reset) works as a gain: a higher value gives a faster correction. A value that is too low makes the output look stuck for minutes before it moves on its own. A value that is too high causes overshoot and slow oscillations. Temperature reacts slowly, so start low (0.1) and increase gradually.

Start the PID once

The PID Start/Continue block is a background task. Start it once, and it keeps calculating on its own. Do not call it on every PLC scan.

Rung A:  ──┤/├ StartBit ──────────────── [ PID Start/Continue ]
Rung B:  ──┤/├ StartBit ──────────────── ( SET StartBit )

At startup StartBit is 0, so the PID starts, then StartBit goes to 1 and the block is not called again.

After changing any setting (gain, integral, set point, ranges), restart the block: reload the program or reset StartBit to 0. Otherwise the PID keeps running with its old settings.

The complete program

1. PWM period         StartBit (NC) → Set Period 20000 µs
2. Measurement        InI16A1 0–4095 → scaling → Temperature (°C × 100)
3. Actuator           ClapetPourCent 0–100 → scaling → positionclapet 17200–19200
4. Target             Copy 3000 → ConsigneTemp (30 °C)
5. PID                StartBit (NC) → PID Start/Continue
6. Start once         StartBit (NC) → SET StartBit

Tune on the real process

Let the temperature move to the target on its own, without touching the input, and watch it. Change one setting at a time and restart the block after each change.

What you see What to do
Temperature overshoots the target, then oscillates Lower the integral (0.1 → 0.05). Still oscillating: lower the gain.
Temperature settles, but too slowly Raise the integral (0.1 → 0.2 → 0.3) until it first overshoots, then back off a little.
Temperature settles on the target Done. Keep these settings.
Don’t judge the tuning by moving the input sharply by hand. That is far more violent than a real process and makes a good tuning look bad.

Troubleshooting

Symptom Likely cause Fix
Output stuck at 0 or 100 even when the measurement changes Measurement outside Input Min / Max Set Input Min / Max to the full scaled range, then restart the block
Output frozen after a program download Block not restarted Check that StartBit returns to 0 at startup
Output barely moves Gain too low for the input range Increase the gain (see “How to read the gain”)
Output seems stuck for minutes, then moves on its own Integral too low Increase Integral (Reset)
A new setting has no effect Block not restarted Restart the block after each change
Output goes the wrong way and the loop runs away Direction does not match the process Check that opening the actuator raises the measurement

Still stuck? Note the raw input, the measurement, the set point, the output and all PID settings at the moment of the problem, and send them to our support team.