You are on page 1of 1

Back to the Top of the Page


about this implementation:
This function is called once every TS seconds, with Ts being set to 5 seconds in my brewing program. It means that a new value for the PID controller output is
calculated every 5 seconds.
 The actual temperatures are read in every second. These temperatures are filtered and then passed to this function (as xk).
 The values of Kc, Ti, Td and Ts can be adjusted by the brewer (see the GUI section on the software page).
 The extension _1 to several variables (e.g. xk_1, lpf_1) indicates the previous version of that variable. For example: xk_1 means the value of xk during the
previous call to this function (5 seconds ago). Same with the extension _2 (which was the value 2 * 5 seconds ago).
Please let me know if you find this listing easy or difficult to read. I would be interested to hear about it.

Before the first call to this function, it should be initialised. For this reason, I created a pid_init() function, that calculates the value of the necessary constants. If
you observe the PID controller closely, you can see various improvements. For example: the I-term calculates the value of Kc * Ts / Ti every time again. This is
not necessary, because you can calculate this once in the pid_init() function and then use it in the PID controller function (saves computing time).

You might also like