The short answer
How to Create a PID Loop in a PLC
To create a PID loop, scale the process variable into engineering units and the output into the range the final element expects, set the controller action so an increase in output moves the process variable the right way, execute the instruction at a fixed interval matched to the process, set output limits with anti-windup, initialize in manual with bumpless transfer, then tune starting with proportional only and add integral slowly.
Key points
- Scale first. A PID loop on raw counts has gains nobody can interpret.
- Get the action right before anything else. A loop with the wrong action runs to a limit.
- Execute at a fixed interval, in a periodic task, not in the main scan.
- Set output limits and anti-windup, or integral will wind up during every start.
- Start in manual. Tune proportional first, then integral. Leave derivative off unless there is a reason.
What you need
- The control narrative or a one-line description of what the loop holds and with what
- The transmitter calibrated range and the final element range (drive speed, valve position)
- Programming software with online monitoring and a trend
- A simulated PV or a process that can be run safely in manual
- The platform PID instruction manual, for its gain units and equation form
Procedure
- 1
Define the loop on paper
Write one sentence: hold X at setpoint by moving Y. Wet well level at 4.0 ft by pump speed. Discharge pressure at 65 psi by pump speed. Chlorine residual at 1.5 mg/L by feeder stroke. If the sentence is hard to write, the loop is not ready to be built.
- 2
Scale the process variable
Convert the analog input to engineering units before it reaches the PID instruction, using the transmitter calibrated range. Record the range in the instruction comments. Some platforms expect the PV in engineering units; others expect it in percent of range. Check which, and match it.
- 3
Scale the output
Decide the CV range: 0 to 100 percent is conventional. Map it to the final element in a separate scaling instruction: percent to drive speed reference counts, or percent to valve position. Keep the PID output in percent so that gains are meaningful across loops.
- 4
Set the controller action
Direct action: output increases when PV rises above setpoint. Reverse action: output decreases when PV rises. Level control with a pump that empties the well is direct: level up, speed up. Pressure control with a pump that raises pressure is reverse: pressure up, speed down. Get this right before tuning; a wrong action cannot be tuned.
- 5
Choose the execution interval
Run the instruction in a periodic task at a fixed interval, typically 100 to 500 ms for pressure and flow, 1 to 5 s for level and residual. The interval must be consistent, because the integral and derivative terms depend on it. Do not run PID in the continuous task where scan time varies.
- 6
Set output limits and anti-windup
Clamp the CV between the minimum and maximum the final element can use: a drive minimum speed of 40 percent, a valve minimum of 5 percent. Enable the instruction anti-reset-windup so integral stops accumulating at a limit. Without this the loop overshoots badly after every period at a limit.
- 7
Configure manual mode and bumpless transfer
Provide a manual mode where the operator sets the CV directly. When the loop switches to auto, the instruction initializes its integral so that the output does not jump. Most instructions do this if the manual CV is written to the instruction output while in manual; confirm it in the manual.
- 8
Handle a bad PV
If the PV signal fails, the loop must not chase it. Use the signal validation flags: on bad PV, force the loop to manual at the last good output or a safe fixed output, and alarm. Test this by pulling the input wire on the bench.
- 9
Set initial tuning
Start with proportional only: a gain that produces a visible but modest response, often 1.0 in dimensionless units or its equivalent in the platform gain units. Integral off, or a very long reset time. Derivative off.
- 10
Test in manual
With the loop in manual, step the output and watch the PV. Confirm the direction, note the dead time and how long the PV takes to settle. Those two numbers guide the tuning: integral time roughly equal to the process time constant, and a gain that does not amplify the dead time into oscillation.
- 11
Switch to auto and tune
Switch to auto at a setpoint near the current PV. Make a small setpoint change. Raise gain until the response is brisk without sustained oscillation, then back off by a third. Add integral until offset is removed in a reasonable time without overshoot. Trend PV, SP, and CV together throughout.
- 12
Document
Record the final gains, the action, the execution interval, the limits, and the date, in the program and on the loop sheet. The next person will need the reasons, not just the numbers.
Gain units differ by platform
Every platform expresses PID tuning differently. Some use proportional gain, some proportional band, which is 100 divided by gain. Integral may be in repeats per minute, minutes per repeat, or seconds. Some instructions use the independent equation, where each term has its own gain; others use the dependent, or ISA, form, where the controller gain multiplies all three terms. Moving tuning values between platforms without converting them is a common way to build a loop that oscillates or never moves.
| Parameter | Common forms | Conversion |
|---|---|---|
| Proportional | Gain Kc; proportional band PB in percent | Kc = 100 / PB |
| Integral | Reset time Ti in minutes or seconds per repeat; reset rate in repeats per minute | Repeats per minute = 1 / Ti in minutes |
| Derivative | Rate time Td in minutes or seconds | Usually zero |
| Equation | Dependent (ISA): CV = Kc × (e + (1/Ti) ∫e dt + Td de/dt). Independent: CV = Kp e + Ki ∫e dt + Kd de/dt | Ki = Kc / Ti and Kd = Kc × Td |
Verification
- A setpoint step in either direction is followed without sustained oscillation and settles within a few process time constants.
- Switching between manual and auto does not bump the output.
- Holding the output at a limit for a minute and then releasing does not produce a large overshoot.
- Pulling the PV signal forces the loop to the defined safe state and raises the alarm.
- The tuning and configuration are recorded in the program and on the loop sheet.
Frequently asked questions
- Should the PID run in the PLC or in the drive?
- Most drives include a PID controller, and for a single pump on a single pressure or level loop it can work well. Running it in the PLC keeps the tuning, the limits, the failure handling, and the alarming in one place, visible on SCADA, and consistent across loops. Use the drive PID for a standalone application; use the PLC for anything with more than one pump or any interaction with the rest of the process.
- How do I know whether my loop is direct or reverse acting?
- Ask what happens to the process variable when the output increases. If PV rises, the loop must reduce output when PV is above setpoint: reverse acting. If PV falls when output increases, as with a pump emptying a wet well, the loop must increase output when PV is above setpoint: direct acting. Platforms name these differently; test in manual to be certain.
- What execution rate should I use?
- Fast enough that the loop sees changes as they happen and slow enough that noise does not dominate. Ten to twenty executions per process time constant is a reasonable rule. A wet well that takes ten minutes to move a foot does not need a 50 ms loop, and running it that fast only amplifies noise through the derivative and integral terms.
- The loop oscillates slowly. What is wrong?
- Slow oscillation with a period of several process time constants is usually too much integral, or gain too high on a loop with long dead time. Reduce integral first. Fast oscillation is usually gain. A loop that oscillates in manual is not a tuning problem at all; it is the process or a valve with stiction.
Related topics
- PID Control for Pumps and ValvesWhat each term actually does, how to tune a loop on a real pump station, and the handful of mistakes that cause most of the oscillation people blame on tuning.
- Analog Scaling: Raw Counts to Engineering UnitsThe arithmetic that turns an analog card reading into feet, psi, or gallons per minute — plus the range mismatches that silently corrupt it.
- Signal ValidationCatching a failed analog input in logic before it runs a pump on a dead transmitter: range checks, module status bits, frozen-value detection, rate checks, and what the program does with a bad value.
- Tasks and Execution PriorityHow a controller schedules its work: the continuous task, periodic tasks at a fixed rate, event tasks triggered by something happening, how priority preempts, and where each kind of logic belongs.
- Distribution Pressure ControlHow a booster or high service pump station holds discharge pressure with variable speed pumps, how pumps are staged, and what stops the system hunting.
- How to Scale a 4-20 mA Input in a PLCTurn raw analog counts into engineering units, verify at three points, and add the validity checks that stop a failed transmitter from producing a believable number.
Direct contact
Have a controls question?
Reach Eric Sullivan directly about anything on this site, a controls or automation topic, or one of his personal projects.