From 0bf587b8bb49f279aeff175139701ec8e4a25e81 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mario=20H=C3=BCttel?= Date: Thu, 15 Jul 2021 00:21:14 +0200 Subject: [PATCH] Add documentation in rst for PID --- doc/source/firmware/pid-controller.rst | 42 ++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/doc/source/firmware/pid-controller.rst b/doc/source/firmware/pid-controller.rst index e6b034e..7054e54 100644 --- a/doc/source/firmware/pid-controller.rst +++ b/doc/source/firmware/pid-controller.rst @@ -26,6 +26,48 @@ reflow oven's solid state relais output is saturated by software to a limit of 0 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}`. +Time Continuous Transfer Function +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The time continous transfer function of the PID controller is + +.. math:: H_c(s) = \frac{Y_c(s)}{X_c(s)} = k_p + \frac{k_i}{s} + \frac{k_ds}{1+sk_{d\tau}} + + +Time Discrete Transfer Function +~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +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: + +.. math:: H_d(z) = H_c(s)\bigg|_{s=\frac{2}{T_s}\cdot \frac{z-1}{z+1}} = k_p + \frac{k_i T_s (z+1)}{2(z-1)} + \frac{\frac{2}{T_s}k_d(z-1)}{\left(1+\frac{2k_{d\tau}}{T_s}\right)z+\left(1-\frac{2k_{d\tau}}{T_s}\right)}. + +Converted to an implementable form: + +.. math:: H_d(z) = k_p + \frac{k_iT_s(1+ z^{-1})}{2(1-z^{-1})} + \frac{\frac{2}{T_s}k_d(1-z^{-1})}{(1+2k_{d\tau}T_s^{-1})+(1-2k_{d\tau}T_s^{-1})z^{-1}} + +This function can be splitted in the three individual parts of the PID controller: + +.. math:: H_{d1}(z) = k_p +.. math:: H_{d2}(z) = \frac{k_iT_s(1+ z^{-1})}{2(1-z^{-1})} +.. math:: H_{d3}(z) = \frac{\frac{2}{T_s}k_d(1-z^{-1})}{(1+2k_{d\tau}T_s^{-1})+(1-2k_{d\tau}T_s^{-1})z^{-1}} + +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: + +.. math:: y_1[n] = k_p x[n] +.. math:: y_2[n] = \underbrace{\frac{k_iT_s}{2}}_{k_{i_t}} \left( x[n] + x[n-1]\right) + y_2[n-1] +.. math:: y_3[n] = \underbrace{\frac{2k_{d}}{2k_{d\tau} + T_s}}_{k_{d_t}}\left( x[n] - x[n-1] \right) + \underbrace{\frac{2k_{d\tau} - T_s}{2k_{d\tau} + T_s}}_{\overline{k_{d_t}}} y_3[n-1] + +The final output value is the sum of all three terms: + +.. math:: y[n] = \sum_{i=1}^{3} y_i[n] .. _pid_code_api: