Developing the auto-tuning function

The auto-tuning method implemented in the PID controller is a "relay test" as published by Karl Åström and Tore Hägglund of the Lund (Sweden) Institute of Technology in 1984. It works by forcing the process to oscillation by first applying a step on the output (i.e. the power to the heating element). When the process value (i.e. the temperature) passes the setpoint (i.e. the desired temperature), a negative step is put on the output, as shown in the figure below.
 

 
When the process value drops below the setpoint, a postive output step is applied again. This procedure is repeated to force the process to oscillate.

The time required to complete a single oscillation is known as the process' ultimate period (Tu), and the relative amplitude of the two oscillations multiplied by 4/π gives the ultimate gain (Ku).

The values of Ku and Tu can then be used to determine the optimum PID parameters according to the following tuning rule table:
 

Rule   PID Parameters
Ziegler-Nichols   Kc = 0.6 Ku; Ti = 0.5 Tu; Td = 0.125 Tu
Pessen Integral Rule   Kc = 0.7 Ku; Ti = 0.4 Tu; Td = 0.15 Tu

 
In the PID controller developed here, the procedure is repeated until the result is stable, i.e. Tu and Ku differs less than 3% between two consecutive tests. Typically it takes between 3-5 minutes to get a reliable result from the auto-tuning function.

In the prototype set-up, it seems like the Pessen Integral Rule works somewhat better, i.e. less overshoot and stabilizes faster than the Ziegler-Nichols rule, see the diagram below (green=PIR, red=ZN):