Whereas the bang-bang control works as expected (fan turns on when measured temp is > reference temp), the ControlPID as designed doesn't have the same behavior and the duty cycle is max_speed - PID value, which is not the expected behavior.
The correction allows the PID to work correctly.
As the minimum fan speed is generally about 20%, a 1° C tolerance has been programmed to avoid that the fan oscillate near the reference value.
The temp_err variable is < 0 when the fan should power-on and if the value is lower, the fan must speed up, so all PID coefficients must be negative. (or the temp_err should be inverted).
I'm using this to control the fan of a water-cooling system, and it is suitable to have it silent most of the time. A 80 mm radiator & fan is more than sufficient to cool the head and motors to 3-4° above ambient temp.
Whereas the bang-bang control works as expected (fan turns on when measured temp is > reference temp), the ControlPID as designed doesn't have the same behavior and the duty cycle is max_speed - PID value, which is not the expected behavior.
The correction allows the PID to work correctly.
As the minimum fan speed is generally about 20%, a 1° C tolerance has been programmed to avoid that the fan oscillate near the reference value.
The temp_err variable is < 0 when the fan should power-on and if the value is lower, the fan must speed up, so all PID coefficients must be negative. (or the temp_err should be inverted).
I'm using this to control the fan of a water-cooling system, and it is suitable to have it silent most of the time. A 80 mm radiator & fan is more than sufficient to cool the head and motors to 3-4° above ambient temp.