## MicroHTR (Part 4)

Part 1, 2, 3, 4, 5, 6, 7, 8, 9

In the PI mode, the P term cares about the real time changes while the I term cares about the history of changes. Athough the PI mode is very effective in most situations, it fails to cover waht we could call the prediction of changes. No glass ball in sight, just a well known math function: the derivative. Computing the derivative of the signal slope gives a very good indication about the trend of the sigal. In the PID context, the D term helps anticipating the changes driven by the controller.

In its simplest expression, PID code may now look like:

double PID(double processVariable) /* Compute output signal */ { /* Timing stuff */ uint32_t now = millis(); double timeInterval = (now - _lastTime) / 1000.0; /* Compute error */ double error = (_computedSetpoint - processVariable); /* Compute error derivative */ double dError = (error - _lastError) / timeInterval; /* Compute error integral */ _integralError += ((error + _lastError ) * timeInterval) / 2.0; /* Compute output */ double outputValue = (_Kp * error) + (_Ki * _integralError) + (_Kd * dError); /* Save last values in volatile variables */ _lastTime = now; _lastError = error; return(outputValue); };

Next plots show the power applied to the heating element along with the temperature setpoint and the read temperatures.

Compared to the same plot in PI mode, one can observe the “noiser” plot of power command which is due to the higher reactivity of the PID function. On the other hand, the temperature profile is very much constrained in narrow band.

From this temeprature plot, we can extract the frequecny spectrum which shows a limited beat pattern over the time:

The probability match function gives a typical thermal noise pattern (gaussian shape)

The noisy power command may be an issue, and several methods exist to overcome this problem. It is firstly advised to address the noise related to the temperature sensing system. Then, filtering the temperature readings will greatly help in defining its function over the time. Applying a Kalmann filter might be the ultimate solution but this functions requires much more computing time than just calculation a slope between two points.