Microcontroller - PID Control
Microcontroller - PID Control
MICROCONTROLLER TECHNOLOGY
PID CONTROL
Introduction
Everyone uses control loops. Anytime you adjust how you do something based on previous results,
you are forming your own control loop.
For example, when you want to drive your car at 65 mph, you depress the accelerator until the
speedometer reports the target speed — simple. But what happens when you start driving up a hill?
The car slows because the torque to move a car at 65 mph on flat road is no longer enough — so you
respond by pressing the accelerator further down. Your foot, the speedometer, and your brain have
formed a control loop. American cars have offered automated speed control loops — also known as
cruise control — since 1958.
Similarly, modern industrial controls are often required to regulate processes as part of a control
loop. The controller receives a setpoint request from the programmer and compares it to a
measured feedback. The setpoint can be thought of as where I want to be and feedback can be
thought of as where I really am. The difference between the setpoint and feedback is called the error
ε. The job of the controller is to eliminate the error — so where I am is where I want to be.
PID is an acronym for the mathematical terms Proportional, Integral, and Derivative. Proportional
means a constant multiple. A number is said to be a proportion to another if there exists a
constant n such that y = nx. This n can be positive or negative, greater or less than one. To make the
formula more accurate by PID controller standards, proportion is given by KP and the x term is
the control loop error ε: So, y = KP (ε) or P = KP (ε).
The term Integral means the summation of a function over a given interval. In the case of controller
PID that is the sum of error over time: So, y = ∫f (ε)dt or P = ∫f (ε)dt
Finally, Derivative is the rate of change during a given interval. Interpreted by a PID controller:
rate of change of the error Δε
Although the PID controller has only three parameters, it is not easy, without a systematic procedure,
to find good values (tunings) for them. In fact, a visit to a process plant will usually show that a large
number of the PID controllers are poorly tuned.
All three of these PID controller components create output based on measured error of the process
being regulated. If a control loop functions properly, any changes in error caused by setpoint changes
or process disturbances are quickly eliminated by the combination of the three factors P, I, and D. Let
us now analyze how each contributes to performance.
Proportional factor
The proportional factor is easiest to understand: The output of the proportional factor is the product of
gain and measured error ε. Hence, larger proportional gain or error makes for greater output
from the proportional factor. Setting the proportional gain too high causes a controller to
repeatedly overshoot the setpoint, leading to oscillation.
The downside (the negative aspect) to a proportional-only loop (P-only) is that when error becomes too
small, loop output becomes negligible. The larger the proportional gain, the smaller the steady
state error — but the larger the proportional gain, the more likely the loop is to become unstable.
This dilemma leads to inevitable steady-state error called offset. Steady-state Error is the difference
between the steady state output and the desired output.
When the integral factor functions properly in the control loop, the basket is nearly empty. Even when
error is so small that the proportional factor is no longer effective, the integral is still hard at work,
collecting error until it is large enough to matter — as part of the integral's function is to eliminate steady-
state offset i.e it removes the dilemma poised by the P-only controller.
In fact, most control loop action at steady state is due to the integral factor. Controllers that feature
integral reset prove it: Resetting the integral when a loop is in steady state causes controller output to
momentarily drop to zero as the integral “basket” is emptied.
The downside to the integral factor is that it strongly contributes to controller output overshoot
past the target setpoint. The shorter the integral time, the more aggressively the integral works.
Derivative factor
The derivative factor is the least understood and used of the three factors. In fact, a majority of PID
loops in the real world are really just PI loops. That does not negate the fact that there are certain
applications in which the derivative plays a very important role. The proportional corrects instances of
error, the integral corrects accumulation of error, and the derivative corrects present error versus
error the last time it was checked.
The effect of the derivative is to counteract the overshoot caused by P and I. When the error is
large, the P and the I will push the controller output. This controller response makes error change
quickly, which in turn causes the derivative to more aggressively counteract the P and the I.
A properly used derivative allows for more aggressive proportional and integral factors. Larger
derivative time makes the derivative more aggressively dampen (make less strong or intense) P and I.
Remember that there are four major characteristics of the closed-loop step response.
1. Rise Time: the time it takes for the plant output to rise beyond 90% of the desired level for the
first time.
2. Overshoot: how much the peak level is higher than the steady state, normalized against
the steady state.
3. Settling Time: the time it takes for the system to converge to its steady state.
4. Steady-state Error: the difference between the steady state output and the desired output.
Where Kp, KI and KD , all non-negative, denote the coefficients for the proportional, integral,
and derivative terms respectively (sometimes denoted P, I, and D).
In the standard form of the equation, KI and KD are respectively replaced by Kp and KpTd the
Ti
advantage of this being that Ti and Td have some understandable physical meaning, as they represent
the integration time and the derivative time respectively.
The controller continues to apply the correction until change is seen on the feedback. Depending on the
error calculation update rate (which in turn may depend on how often the loop feedback is read) the
corrective action can be adjusted at a fast rate — for instance, the analog feedback on some variable
frequency drives is updated every 10 msec.
The job of a PID controller is to force feedback to match a setpoint. Sometimes error between
feedback and setpoint is caused by a setpoint change, but in most applications the setpoint is not
adjusted much. More often, error in a loop is caused by disturbances in measured feedback.
Tuning is part of loop design, usually required if the system oscillates too much, responds too slowly,
has steady-state error, or is unstable.
One must be careful when determining whether a PID needs tuning or not: Always check hardware
first, as it could be the problem and not the controller that needs tuning.
On the other hand, problems may have nothing to do with the PID loop tuning if a control valve sticks,
measurement taps are plugged, sensors are disconnected, or if a control valve is stripped out from high-
pressure flow.
Some systems have interactions of widely varied strengths — and there is no single definition of “best
tuned” that applies to all loops, so no single method optimizes all loops.
The optimum behavior in a process or setpoint change depends on the application. Some processes
must not allow overshoot of a process variable, while others must minimize energy expended in
reaching a new setpoint.
Generally, response must be stable and systems must not oscillate for any combination of conditions
and setpoints. Tuning of loops is further complicated by process response time, as it may take minutes
or hours for a setpoint change to produce a stable effect. Some processes also exhibit nonlinearity, so
parameters that work well at full-load conditions don't work when starting from no-load.
AketchescoBenz A TVET Trainer Kenya Coast National Polytechnic 11/10/2019 6|Page
Several methods are available for tuning a PID loop; the choice of method largely depends on whether
or not the loop can be taken offline for tuning, and the system response speed. If the system can be
taken offline, the best tuning method often involves subjecting the system to a step change in input,
measuring output as a function of time, and using this response to determine control parameters.
If the system must remain online, one tuning method is to first set I and D values to zero and increase P
until loop output oscillates — then increase I until oscillation stops, and increase D until the loop is
acceptably quick in reaching its reference. A fast PID loop tuning usually overshoots slightly to reach
the setpoint more quickly.
Another is known as the Ziegler-Nichols method, introduced by John G. Ziegler and Nathaniel B.
Nichols of Taylor Instruments in 1942. This technique also involves setting I and D gains to zero and
then increasing P gain until the loop output starts to oscillate.
Most industrial facilities no longer tune loops with manual calculation, but use tuning and loop
optimization software. These software packages gather data, develop process models, suggest optimal
tuning, and even develop tuning by gathering data from reference changes. This can be done both on
and offline. It may also include valve and sensor analysis, and simulation before downloading. The
only drawbacks: Software is somewhat costly and involves some training.
The analytical approach involves mathematics. PID loop tuning induces an impulse in the system, and
then uses the controlled system's frequency response to design PID loop values. In loops with response
times of several minutes, mathematical loop tuning is recommended because trial and error can
literally take days just to find a stable set of loop values. Optimal values are harder to find, but can
save a company huge amounts of money. Commercial software is available from several sources, and
can easily pay for itself if a PID loop runs large or expensive processes. Some digital controllers even
feature self tuning, in which small setpoint changes are sent to the process, allowing the controller
itself to calculate optimal values.
One can also tune by feel, which is an online method that doesn't require math. The main problem with
this method is that it is erratic, not repeatable, and can be inefficient.
The final method of tuning is a quality process model called the Cohen-Coon, which is a modified
version of the Ziegler-Nichols approach. This offline method involves some math, but is only good for
the first-order process. Under manual mode, wait until the process is at a steady state before
introducing a step change in the input. From the measurements based on the step test, evaluate the
process parameters. Based on these, formulas should prescribe controller settings.
Ziegler-Nichols tuning
How can a control engineer designing a PID loop determine the values for P, T I, and TD that will work
best for a particular application?
John G. Ziegler and Nathaniel B. Nichols of Taylor Instruments addressed that question in 1942 when
they published two loop tuning techniques that remain popular to this day.
Ziegler and Nichols derived the following control parameters based on this model:
It should be noted that the response curve of Figure 4 is also typical of overdamped second order
systems.
Second Method
Note: This is just like the Routh-Hurwitz stability range problems we studied.
The second method targets plants that can be rendered unstable under proportional control. The
technique is designed to result in a closed loop system with 25% overshoot. This is rarely achieved as
Ziegler and Nichols determined the adjustments based on a specific plant model.
The steps for tuning the PID controller via the 2nd method are as follows:
Example 1
Solution
PID loops provide technicians and engineers with a customizable way to control a variety of
conditions, from temperature to speed and everything in between. The loop's control is used to modify
application behavior to keep output at stable and improve response rates. What's particularly exciting is
that special software and computers can perform calculations to make PID design easier.