PI, PD and PID controllers: how they work and when to use each

PI, PD and PID controllers: how they work and when to use each

In this guide we build PI, PD and PID controllers one term at a time, with simple diagrams and a live step-response demo.

SetpointSP +− error e PID controller PKp · eIKi · ∫e dtDKd · de/dt u Actuatorheater, drive Processoven, motor,generator PV Sensor measured value (PV) 1 · Measure PV 2 · Compare: e = SP − PV 3 · Calculate P + I + D 4 · Act
One feedback loop, about eight seconds per lap. The sensor measures the process value. The controller compares it with the setpoint, calculates the P, I and D terms, and sends a new output to the actuator.

Quick answer: PI, PD and PID controllers are feedback controllers. They compare a measured value with a setpoint and act on the difference, the error. The P term reacts to the error now. The I term adds up past error, so it removes the steady offset. The D term reacts to how fast things change, so it adds damping. PI is the most common choice in industry. PD suits position control. Full PID suits slow processes with lags, such as temperature.

Why we need feedback control

Many machines must hold a value steady. An oven must hold a temperature. A motor must hold a speed. A generator must hold its voltage. But the world keeps pushing these values away. The oven door opens. The motor load changes. The grid load changes.

So we use feedback control. We measure the value and correct it again and again. A few words help here:

  • The setpoint (SP) is the value we want, for example 100 °C.
  • The process variable (PV) is the value we measure, for example 92 °C.
  • The error, e, is the difference: e = SP − PV.
  • The controller output, u, is the command to the actuator, the part that acts, such as a heater, a valve or a motor drive.

The animation at the top of the page shows one loop. The sensor measures. The controller compares and calculates. The actuator acts. Then the loop starts again. So the real question is this: how hard should the controller push for a given error?

The PID controller is the classic answer. Its ideas go back to 1922, when Nicolas Minorsky described them for automatic ship steering. His system was tested on the battleship USS New Mexico. Today PI and PID loops run in almost every factory, drive and power plant.

The three terms: P, I and D

PID stands for proportional, integral, derivative. Each word names one way of looking at the error. We add the three results to get the controller output. A simple way to remember them: P looks at the present error, I looks at the past, and D looks at the trend.

P: proportional to the error now

The P term is the error times a number called the proportional gain, Kp: P = Kp × e. A big error gives a big push. A small error gives a small push. In our oven, the further the temperature is below the setpoint, the more power the heater gets.

But P alone has a weakness. It needs some error to give any output. The oven needs some heater power to stay hot, so some error must remain. This leftover gap is the steady-state error, or offset. For a process with gain K, the offset after a step is 1 ÷ (1 + Kp × K). With K = 1 and Kp = 3, that is 1 ÷ 4, or 25%. The figure below shows it.

0.250.50.7511.2505101520Time (minutes)Oven temperature (fraction of the step) setpoint 1.0 steady-state error 25% settles at 0.75 P only, Kp = 3
P-only control of our oven model with Kp = 3. The brown curve stops at 0.75 of the step. The red gap is the steady-state error. The heater only gets power while some error is left.

A higher Kp shrinks the offset. But it never removes it. And too high a Kp makes the loop swing, or even become unstable.

I: the sum of past error

The I term adds up the error over time. In maths this sum is the integral, the area under the error curve. We multiply it by the integral gain, Ki: I = Ki × ∫e dt. So the I term grows with both the size of the error and how long it lasts.

While any error remains, the I term keeps growing. It stops only when the error is zero. At that point it holds exactly the output the process needs. So a controller with an I term removes the steady-state error. The figure below shows this for our oven.

1Error e = SP − PV 1205101520Controller terms Time (minutes) area builds up I term settles at 1.0: the power the oven needs P term = Kp · e P term fades to 0
A PI controller on the oven (Kp = 2, Ki = 0.6). The I term is Ki times the shaded area under the error. As the error disappears, the blue P term fades to zero. The brown I term stays at 1.0 and holds the heater on, so no offset is left.

The price is speed and stability. The I term reacts slowly, and too much of it causes overshoot and swinging. It can also wind up when the actuator hits its limit. We look at that problem later.

D: the rate of change

The D term looks at how fast the error changes. In maths this rate is the derivative, de/dt. We multiply it by the derivative gain, Kd: D = Kd × de/dt. If the temperature rises fast towards the setpoint, the error shrinks fast. So the D term is negative, and it cuts the heater power early. This reduces overshoot.

0.51Process value PV -1-0.5024681012D term = −Kd · dPV/dt Time (minutes) PV rising fastest: D pulls the output down most PV flat: D term ≈ 0
The D term watches the slope. Where the black PV curve rises fastest, the green D term is most negative and holds the heater back. Where the curve is flat, the D term is zero. (Kp = 2, Ki = 0.6, Kd = 1.5.)

The D term does not see the future. It only sees the slope now and acts as if the slope will continue. So it adds damping, a braking effect against swings. It does nothing when the error is constant, so it cannot remove an offset. Its weak points are noise and sudden setpoint steps.

Analogy

Think of cruise control in a car. P presses the pedal more when the car is further below the set speed. I notices that a long hill keeps the car slow, so it slowly presses further until the speed is right. D sees the speed climbing quickly and eases off a little early, so the car does not overshoot.

The PID equation, step by step

We add the three terms to get the full controller. The most direct way to write it is the parallel form, with three independent gains:

u(t) = Kp·e(t) + Ki·∫e(t) dt + Kd·de(t)/dt

Here u(t) is the controller output, e(t) is the error at time t, and Kp, Ki and Kd are the gains. A PI controller is the same with Kd = 0. A PD controller has Ki = 0.

Many industrial controllers use the standard form instead. It is also called the ideal or ISA form. Kp multiplies all three terms, and the I and D actions are set by times:

u(t) = Kp·[e(t) + (1/Ti)·∫e(t) dt + Td·de(t)/dt]

Ti is the integral time, also called reset time. Td is the derivative time. The two forms are the same controller when Ki = Kp ÷ Ti and Kd = Kp × Td. The standard form is handy for tuning, because Ti and Td are in seconds or minutes, like the process itself.

Common mistake

Copying PID numbers from one controller to another without checking the form and units. One device may ask for Ki, another for Ti in seconds, and another for "repeats per minute" (1/Ti). The names for the forms also vary between makers. The same number can mean a very different controller.

A real controller is digital. It does not solve the equation all at once. It runs a short cycle again and again, every sample time Δt, for example every 0.1 min for an oven or every 100 µs for an inverter. The four cards below follow one cycle of an oven controller.

SP = 100 °CPV = 92 °Ce = 8 °C

1Measure and find the error

The controller reads the sensor. The oven is at 92 °C and the setpoint is 100 °C. So the error is 8 °C.

P = Kp × e = 2 × 816%P0%40%

2Work out the P term

Kp is 2% of heater power per °C. So the P term is 2 × 8 = 16%.

sum = 40% + Ki × e × Δt= 40 + 0.6 × 8 × 0.1I40.5%the sum is kept for the next cycle

3Update the I term

The I term is a running sum. Each cycle adds Ki × e × Δt. With Ki = 0.6 per minute and Δt = 0.1 min, the sum grows from 40% to 40.5%.

D = −Kd × ΔPV ÷ Δt = −4.5%PI−Du = 16 + 40.5 − 4.5 = 52%limit to 0–100%, send to heater

4Add the D term, limit, send

PV rose 0.3 °C since the last cycle. With Kd = 1.5 min, D = −1.5 × 0.3 ÷ 0.1 = −4.5%. The total is 52%, inside the 0–100% limits.

Notice two details in step 4. The D term here uses the change in PV, not in error. And the output is limited to what the heater can really give. Both details matter, as we see later.

How each gain changes the response

To compare controllers, we look at the step response: how the PV moves after the setpoint jumps. Four numbers describe it:

  • Rise time: how long the PV takes to climb close to the final value, often from 10% to 90%.
  • Overshoot: how far the PV goes past the final value, in percent.
  • Settling time: how long until the PV stays within a small band, often ±2%, of the final value.
  • Steady-state error: the gap that remains at the end.

The figure below raises one gain at a time on our oven model. Each panel keeps the other gains fixed.

Raise KpP only0.511.501020Kp:124Raise KiKp 2, Kd 1.501020Ki:0.611.5Raise KdKp 3, Ki 101020Kd:012 time (minutes)
Raising one gain at a time on our oven model. Grey is the lowest value, blue the middle, brown the highest. Compare these curves with the table below.

The table gives the classic rule of thumb. It matches the curves above.

ChangeRise timeOvershootSettling timeSteady-state error
Raise KpDecreasesIncreasesSmall changeDecreases (never zero)
Raise KiDecreasesIncreasesIncreasesEliminates
Raise KdSmall changeDecreasesDecreasesNo effect in theory

Treat the table as a guide, not a law. The gains act together, so changing one changes the effect of the others. For example, in the left panel a higher Kp also made the settling time longer. And too much Kd can make the response slow and noisy again.

P, PI, PD or PID: when to use each

We do not always need all three terms. Each extra term adds something useful, but also something to tune. Here is how the four common types compare.

  • P only. Simple and fast. But it leaves an offset. It suits loops where a small offset is fine, such as a level in a buffer tank. It also suits the outer position loop of a servo, because the motor itself turns speed into position.
  • PI controller. P plus I. It removes the offset and has no noisy D term. This makes it the most common controller in industry. Typical uses are flow, pressure, motor speed, inverter current and many temperature loops. The trade-off is more overshoot than P alone, unless it is tuned carefully.
  • PD controller. P plus D. It is fast and well damped, but it leaves an offset unless the process itself integrates. So PD suits position control: servo axes, robot arms and disk-drive heads. Here the process turns speed into position, which acts like a built-in I term.
  • PID controller. All three. It removes the offset, and D lets us use more gain without large swings. It suits slow processes with lags and a clean signal, such as temperature in ovens and furnaces. It is the hardest to tune, and the D term needs a filter.
Common mistake

Using a PD controller for motor speed. Without an I term, the speed sags a little every time the load rises, and it never fully recovers. Speed loops in drives use PI, so the speed returns exactly to the setpoint.

Most loops start as PI. We add D only when the process is slow, has several lags, and gives a clean measurement.

Worked example and a note on tuning

Let us test the three types on one process. Our model oven has three lags of about one minute each: the heater element, the oven air and the sensor. Its gain is 1. We step the setpoint by 1.0, which we can think of as 100 °C.

  • P only, Kp = 3. The offset is 1 ÷ (1 + 3) = 25%. So the oven stops about 25 °C short. The simulation agrees: the PV settles at 0.75.
  • PI, Kp = 3 and Ki = 1 per minute. The offset is gone. But the overshoot is about 46%, and the PV takes about 22 minutes to settle within ±2%.
  • PID, Kp = 3, Ki = 1 and Kd = 1.5 min. The D term damps the swing. Overshoot falls to about 20%, and settling time to about 8 minutes.
  • Gentler PID, Kp = 2, Ki = 0.6 and Kd = 1.5. Overshoot is only about 2%, and the PV settles in about 5.2 minutes.

The demo below lets us move the three gains and watch the result. Try P only and raise Kp: the offset shrinks, but above Kp = 8 the loop never settles. Then add a little Ki to remove the offset, and some Kd to calm the swing.

Try it · tune the oven
0.511.520510152025Time (minutes)Oven temperature (fraction of the step) P only (Kp 3): stops at 0.75 PI (Kp 3, Ki 1): 46% overshoot PID (Kp 3, Ki 1, Kd 1.5): 20% overshoot
Overshoot: 19.5% Settling time (±2%): 7.9 min Steady-state error: 0% Stable

Oven model: three 1-minute lags, gain 1, setpoint step of 1.0 at time zero. Overshoot and settling time are measured against the final value. The D term acts on the measurement with a 0.1 min filter. The heater has no power limit here.

How do we find good gains on a real plant? The classic answer is the Ziegler–Nichols method from 1942. We switch off I and D and raise Kp until the loop swings steadily. That gain is the ultimate gain Ku, and the swing period is Tu. The classic PID settings are then Kp = 0.6 Ku, Ti = Tu ÷ 2 and Td = Tu ÷ 8. For our oven, Ku = 8 and Tu ≈ 3.6 min, so Kp = 4.8, Ki ≈ 2.65 per minute and Kd ≈ 2.2 min. The result is fast but aggressive: about 51% overshoot, because the method aims for each swing to be a quarter of the one before. So engineers often treat it as a starting point and then soften the gains. Many modern controllers also have an auto-tune function. For other methods, see our guide Mastering PID: 6 tuning methods beyond Z-N.

Two practical problems: windup and derivative kick

The equation looks clean. But real actuators have limits, and real sensors have noise. Two problems come up again and again.

Integral windup. Every actuator has a limit. A heater cannot give more than 100% power, and a valve cannot open more than fully. During a large change, the output sits at its limit for a while. But the error is still there, so the I term keeps growing. When the PV finally reaches the setpoint, the I term is far too large. It takes a long time to unwind, so the PV overshoots badly. The figure below shows this.

0.510510152025Oven temperature (fraction of the step) Time (minutes) no anti-windup: 20% overshoot with clamping: 2% overshoot Time the heater sits at its limit: brown: no anti-windupblue: clamping
Integral windup. The heater can give at most 1.2 times the power the oven needs at setpoint (Kp = 2, Ki = 1). Without anti-windup (brown) the integral keeps growing while the heater is at its limit, so the temperature overshoots. With clamping (blue) the integral pauses at the limit.

In this example, anti-windup cuts the overshoot from about 20% to about 2%, and the settling time from about 19 to about 9 minutes. There are two common fixes:

  • Clamping, also called conditional integration. The controller stops adding to the I term while the output is at its limit and the error would push it further.
  • Back-calculation. The controller compares its wanted output with the limited output. It feeds the difference back to shrink the I term.
Analogy

Think of a person who keeps turning a tap after it is fully open, counting every extra turn. When the water is finally hot enough, they must undo all those useless turns before the tap starts to close. Anti-windup simply stops counting once the tap is fully open.

Derivative kick and noise. When the setpoint jumps, the error jumps too. Its slope is huge for one sample, so the D term gives a sharp spike to the actuator. This is derivative kick. The D term also turns small, fast sensor noise into large swings in the output. The figure below shows both effects.

Derivative kickcontroller output after a setpoint step 0240246Time (minutes) spike ≈ 16, off scale red: D on error blue: D on measurement NoiseD term with a noisy sensor -2020246Time (minutes) grey: no filterblue: filtered
Two problems with the D term. Left: on a setpoint step, D on error gives a huge spike (red), while D on measurement does not (blue). Right: sensor noise of only about 0.4% makes an unfiltered D term (grey) jump around. A small filter (blue) calms it.
  • Derivative on measurement. Use −Kd × dPV/dt instead of Kd × de/dt. When the setpoint is steady, the two are equal. But a setpoint step no longer causes a kick.
  • Filter the D term. A small low-pass filter removes the fast noise. A common choice is a filter time of Td ÷ N, with N often between about 5 and 20.
  • Ramp the setpoint. A smooth setpoint change is kinder to the actuator than a sudden step.
  • Switch D off when the signal is very noisy. This is one reason why so many loops are PI.

Where PID control is used

PI and PID loops are everywhere in electrical engineering. The figure below shows four common homes for them.

Motor drive (VFD)outer loop sets speed,inner loop sets current;both usually PIPI + PI cascade Oven, furnaceslow heat with lags;D helps if the sensorsignal is cleanPID or PI Generatorgovernor holds speed;AVR holds theterminal voltagePI or PID Grid inverterfast current loops,often in the d-q frame(DC-like quantities)PI VFDmotordrivespeed loop → current loop180 °CsensorturbineGOVAVRspeedvoltageDC→ACinvertergrid current
Where these loops live on the power side. Motor drives use PI loops in a cascade. Ovens often use full PID. Generators use a governor and an AVR. Grid inverters use fast PI current loops.
  • Motor speed control. A DC drive or servo drive usually runs two loops in a cascade, one loop inside another. The outer PI loop compares the speed with the set speed and asks for a current, which sets the torque. The inner PI loop makes the real current follow that request. The inner loop is much faster than the outer one.
  • Variable frequency drives (VFDs). A VFD, a drive that changes motor speed by changing the supply frequency, uses the same cascade in vector control. The d- and q-axis currents each have their own PI loop. Many VFDs also have a built-in process PID. It can hold a pump pressure or a fan airflow by changing the motor speed.
  • Temperature control. Ovens, furnaces, plastic extruders and HVAC systems use PID or PI loops. These processes are slow and have several lags, so the D term helps when the sensor signal is clean.
  • Generator AVR and governor. The automatic voltage regulator (AVR) holds the generator terminal voltage by adjusting the field current. Many modern digital AVRs use a PID or PI regulator, and the IEEE 421.5 standard models include PID-type regulators. The governor controls the turbine to hold speed and share load. Many hydro governors use PID control.
  • Inverter current loops. A grid-connected inverter, for solar, batteries or wind, must shape its output current very precisely. It often converts the AC currents into a rotating d-q frame, where they look like DC values. Then simple PI loops can control them, often thousands of times per second.

Flow, pressure and level loops in water, chemical and food plants are also mostly PI. The ideas are the same in every case: measure, compare, calculate, act.

Key takeaways

  • A feedback controller acts on the error, e = SP − PV. P reacts to the error now, I to the sum of past error, and D to its rate of change.
  • P alone always leaves an offset. The I term removes it by holding the output the process needs.
  • The parallel form is u = Kp·e + Ki∫e dt + Kd·de/dt. The standard form uses Ti and Td, with Ki = Kp ÷ Ti and Kd = Kp × Td.
  • Raising Kp or Ki speeds up the response but adds overshoot. Raising Kd cuts overshoot. The gains interact, so the table is only a guide.
  • PI is the industrial default. PD suits position control. Full PID suits slow, lagging processes with clean signals.
  • Real loops need anti-windup and a filtered D term on the measurement. Ziegler–Nichols gives a fast but aggressive starting point.

Next, we suggest looking at tuning methods in more depth, and at how these loops work inside motor drives and generators. The guides below go deeper.

Leave a Comment