In this article we will use a
simple, proven tuning procedure to find effective values for
proportional, integral, and derivative gain.
Supporting Information
 This project makes use of a customdesigned PCB; please refer to Custom PCB Design with an EFM8 Microcontroller for guidance on incorporating EFM8 devices into your custom hardware.
 You can find a brief overview of thermocouples along with some general information about the MAX31855 in Make an EFM8Based System for Monitoring and Analyzing Thermocouple Measurements.
 An Introduction to Control Systems: Designing a PID Controller Using MATLAB’s SISO Tool
 Negative Feedback, Part 1: General Structure and Essential Concepts
 This article introduces Scilab.
 Two previous articles provide information on incorporating USB communication into an EFM8 project: Communicating with an EFM8 Microcontroller via USB and EFM8 Sound Synthesizer: Playing Melodies via USB.
Before we get started, here is the PID control system diagram presented previously:
And here are PIDrelated portions of the schematic:
The Limitations of GuessandCheck
In the previous article we employed some basic system analysis followed by crude experimentation to determine workable PID gain parameters. The resulting performance was quite good—but then again, we only tested the system with one specific control task, so we don’t know much about what the controller might do under different operating conditions. We also don’t know how much better the performance could be. It’s all well and good to be satisfied when you see adequate performance, but what if the system could be significantly improved simply by changing the gain values? The guessandcheck approach is also rather impractical, or at least tiresome. The process was timeconsuming even with this little experimental temperature controller—what would you do if each control run took an hour instead of a few minutes? My point here is that efficient, effective PID tuning is an essential part of controlsystem design.It should come as no surprise that the people designing jet fighters and Mars rovers need something way better than guessandcheck. Sophisticated PID software packages or simulation environments are probably the method of choice for most modern control systems; we, on the other hand, will use a simple, timetested technique known as the Ziegler–Nichols method.
Ziegler–Nichols
This procedure was first described in a paper published in 1942—credit to Ziegler and Nichols for coming up with a tuning method that has survived almost 75 years of overwhelming technological development. The process starts with a proportionalgainonly system. You increase the P gain until the system exhibits oscillations that are sustained (i.e., stable in terms of amplitude) and regular (i.e., stable in terms of period); the oscillation does not need to be centered around the setpoint. This is the only tiresome part of the Ziegler–Nichols method. The rest is just math.Once you have sustained, regular oscillation, you record the proportional gain and measure the oscillation period. These values are referred to as the ultimate gain (K_{U}) and the ultimate period (P_{U}), respectively. Now you calculate K_{P}, K_{I}, and K_{D} according to the following table:

K_{P}

T_{I}

T_{D}

Ponly control

K_{U}/2



PI control

K_{U}/2.2

P_{U}/1.2


PID control

K_{U}/1.7

P_{U}/2

P_{U}/8

Seeking Oscillation
So first we need to find the ultimate gain and period. Feedback systems often burden engineers with the problem of preventing oscillation; there is something relaxing about encouraging oscillation and even feeling a sense of satisfaction when it occurs with sufficient regularity.In the previous article we saw that a Ponly system with K_{P} = 70 does not produce stable oscillation:
So let’s increase K_{P} to 90 and see what happens.
This is looking better, but the amplitude of the oscillations clearly decreases over time. Let’s try K_{P} = 100:
I would consider this borderline. The oscillations are regular but not quite sustained (the decreasing amplitude is not really apparent until the last three cycles). Here’s K_{P} = 110:
This looks good to me. I don’t notice any significant irregularity or reduction in amplitude. So we will say that the ultimate gain is 110.
Calculations
The first table shows the Ziegler–Nichols values for the proportional gain, integral time constant, and derivative time constant assuming K_{U} = 110 and T_{U} = 55 seconds. The second table has gain values instead of time constants for the integral and derivative terms, assuming that the PID interval is 2 seconds. All values in the second table are rounded to the nearest integer; these are the values that we will actually use in the system, which does not support noninteger gains.

K_{P}

T_{I}

T_{D}

Ponly control

55



PI control

50

45.8


PID control

64.7

27.5

6.9


K_{P}

K_{I}

K_{D}

Ponly control

55



PI control

50

2


PID control

65

5

223

Results
We will compare the performance of different system configurations based on convergence time, which we will define as follows: the interval between the time at which the measured temperature first reaches the setpoint and the time at which the measured temperature remains directly on top of or immediately adjacent to the setpoint line. (This convergence criterion corresponds to a range of about 1°C above or below the setpoint temperature.) We want the interval to begin when the measured temperature first reaches the setpoint (rather than at the beginning of the control run) because this should minimize errors associated with variations in the initial system state (the dominant concern being variations in the measured temperature at the beginning of the control run).First let’s look at the Ziegler–Nichols Ponly system:
Unsurprisingly, this system doesn’t even converge. There’s only so much you can do with a Ponly system.
Here is the Ziegler–Nichols PI system:
This is good—probably about the best we can do without any derivative gain. Actually, after all the time I have spent experimenting with this system, I cannot remember a better PI control run. As marked in the plot, the convergence time was 198 seconds. Note also the reasonable amount of overshoot. It’s important to keep in mind that the Ziegler–Nichols method includes a tuning procedure specifically for PI control because in many situations it is acceptable or even preferable to use only proportional and integral gain. Derivative action can be problematic when the system is susceptible to major disturbances or noise in the measured variable.
Now we’re ready for the full PID:
Nicely done, Ziegler and Nichols. This far surpasses any control run I’ve seen so far. The convergence time has decreased from 198 seconds to 43 seconds, and the overshoot has increased by only about 1°C. Despite what I said above about the dangers of derivative gain, it is clearly beneficial in this system. I suppose this is not too surprising—we have no major disturbances, and there is not much noise in the measured temperature (in part because the temperature measurements are effectively filtered by the limited resolution of the MAX31855 and the relatively long PID interval).
One weakness with the standard Ziegler–Nichols approach is the overshoot. In our system, and many other systems, this amount of overshoot is no problem. But there are situations in which overshoot is unacceptable—an extreme example is a substance that will ignite if the temperature goes too far above the setpoint. So before we finish up, we’ll look at tuning parameters that are intended to minimize overshoot. This article from Microstar Laboratories includes a table with the parameters for this “no overshoot” tuning method, as well as for two additional methods that differ from the standard Ziegler–Nichols technique.

K_{P}

T_{I}

T_{D}

No overshoot

K_{U}/5

T_{U}/2

T_{U}/3

The corresponding rounded gains are K_{P} = 22, K_{I} = 2, and K_{D} = 202. Here are the results:
The method succeeded in eliminating overshoot, to the serious detriment of convergence time. We can’t directly compare this run to previous runs because our convergencetime rule doesn’t work when the measured temperature never crosses the setpoint, and because this run never quite converges according to our previous criterion. But we can get a general idea from the overall time to nearconvergence. With the Ziegler–Nichols PID system, the overall time to convergence was 134 seconds, whereas the “no overshoot” PID system comes very close to convergence at 275 seconds.
Conclusion
We now understand the value of proven tuning methods. We had great success with the Ziegler–Nichols approach, but other methods are available. With this particular temperature controller, the Ziegler–Nichols procedure achieved performance that looks close to optimal. However, it’s important to understand that there is nothing magical about Ziegler–Nichols or any other method. If the system’s performance is not adequate, then the gain values generated by the method become a starting point for further observation and refinement.