Open Wallacoloo opened 10 years ago
After discussing this with M.S., this appears to be a non-trivial problem. It may be sufficient to just maintain the last N samples and average them. Could do a Riemman sum of the last N samples & divide by total time.
To elaborate on my "non-trivial" remarks - there is quite a bit of literature on the topic, under search terms such as "jitter margin." This is an area of active research, with quite a few proposed solutions that might be appropriate. The good news is that we have the spare cycles and memory to implement something...
The bad news is that sample timing (and control loop) jitter is a much more pernicious issue - it not only means that the low pass filter's actual time-based frequency response keeps jumping around, but actually directly injects noise (assuming a constantly changing process variable) into the control loop and generally threatens stability.
Besides implementing a general-purpose jitter compensator, I suspect the proper engineering solution is to attack the problem in hardware and use a better ADC system. Other target boards (e.g. the beagle bone black) could use on-board ADCs, a cheap micro-controller could run the temperature control loops (and watchdogs - #17 ), or an external SPI-interfaced ADC (or thermocouple amplifier) could be added to the system. This should offer higher sample rates (and thus more effective filtering) and more precision.
But a simple ring-buffer + running Riemman sum is, of course, easiest to implement.
(also, 1/4 Hz is probably not enough control bandwidth for a properly powered hotend)
Currently, the lowpass filter implementation, which is used to smooth thermister read values, assumes that it is fed 1 sample per second. However, it is really fed data at a variable rate. As such, it is not correct to assume that each sample is 1 second apart (and right now the average thermister sample is actually 3-4 seconds apart).