The PID controller is the main element of the oven. It controls the output of the solid state relais in order to achieve the desired temperature.
The PID controller is implemented in the ``pid-controller.c`` file. See the :ref:`pid_code_api` for details.
Functional Description
----------------------
The following figure shows the PID controller's structure.
..drawio-image:: pid.drawio
The controller is composed of 3 paths. The proportional, the derivate, and the integrator path.
Compared to a textbook PID controller, this version contains a few additional features.
The integrator has a configurable maximum limit of :c:var:`pid_controller.integral_max`. Once this value is reached (plus or minus), the integrator freezes.
The integrator is also frozen in case the output value is in saturation. This serves as an anti-windup protection.
The output value saturates at configurable high and low limits (:c:var:`pid_controller.output_sat_max` and :c:var:`pid_controller.output_sat_min`). The controller instance used for the
reflow oven's solid state relais output is saturated by software to a limit of 0 to 100.
In addition to the above features, the derivate term contains an additional first order low pass filter in order to prevent coupling of high frequency noise amplified by the derivate term.
The low pass filter is charcterized by its time constant :math:`k_{d\tau}`.
The time descrete transfer function which is implemented in the code is derived by converting the time continuous transfer function
with the bilinear transformation:
..math:: s = \frac{2}{T_s}\cdot \frac{z-1}{z+1}
The frequency warping of the bilinear transform can be considered negligible because the PID controller is targetted for low frequency temperature signal data with a maximum far below the nyquist freqency.
In this area, the mapping of the continuous frequencies to the time descrete can be considered linear.
The time discrete transfer function after inserting the bilinear transform is:
The individual time domain difference equations :math:`y_i[n] = \mathcal{Z}^{-1}\left\lbrace H_{di} * X(z)\right\rbrace` that are implemented in software are: