diff --git a/config.default.h b/config.default.h index 84ec516..c45d2fd 100644 --- a/config.default.h +++ b/config.default.h @@ -251,6 +251,19 @@ */ #define TEMP_RESIDENCY_TIME 60 +/** + TEMP_EWMA: Smooth noisy temperature sensors. Good hardware shouldn't be + noisy. Set to 1.0 for unfiltered data (and a 140 bytes smaller binary). + + Instrument Engineer's Handbook, 4th ed, Vol 2 p126 says values of + 0.05 to 0.1 are typical. Smaller is smoother but slower adjusting, larger is + quicker but rougher. If you need to use this, set the PID parameter to zero + (M132 S0) to make the PID loop insensitive to noise. + + Valid range: 0.001 to 1.0 +*/ +#define TEMP_EWMA 1.0 + /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board. // #define TEMP_MAX6675 #define TEMP_THERMISTOR diff --git a/config.gen3.h b/config.gen3.h index 440ed36..880fecd 100644 --- a/config.gen3.h +++ b/config.gen3.h @@ -256,6 +256,19 @@ */ #define TEMP_RESIDENCY_TIME 60 +/** + TEMP_EWMA: Smooth noisy temperature sensors. Good hardware shouldn't be + noisy. Set to 1.0 for unfiltered data (and a 140 bytes smaller binary). + + Instrument Engineer's Handbook, 4th ed, Vol 2 p126 says values of + 0.05 to 0.1 are typical. Smaller is smoother but slower adjusting, larger is + quicker but rougher. If you need to use this, set the PID parameter to zero + (M132 S0) to make the PID loop insensitive to noise. + + Valid range: 0.001 to 1.0 +*/ +#define TEMP_EWMA 0.1 + /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board. // #define TEMP_MAX6675 // #define TEMP_THERMISTOR diff --git a/config.gen6.h b/config.gen6.h index 361d134..7e9ceee 100644 --- a/config.gen6.h +++ b/config.gen6.h @@ -251,6 +251,19 @@ */ #define TEMP_RESIDENCY_TIME 60 +/** + TEMP_EWMA: Smooth noisy temperature sensors. Good hardware shouldn't be + noisy. Set to 1.0 for unfiltered data (and a 140 bytes smaller binary). + + Instrument Engineer's Handbook, 4th ed, Vol 2 p126 says values of + 0.05 to 0.1 are typical. Smaller is smoother but slower adjusting, larger is + quicker but rougher. If you need to use this, set the PID parameter to zero + (M132 S0) to make the PID loop insensitive to noise. + + Valid range: 0.001 to 1.0 +*/ +#define TEMP_EWMA 0.1 + /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board. // #define TEMP_MAX6675 #define TEMP_THERMISTOR diff --git a/config.gen7-v1.1-v1.3.h b/config.gen7-v1.1-v1.3.h index 22e0a65..edc3cad 100644 --- a/config.gen7-v1.1-v1.3.h +++ b/config.gen7-v1.1-v1.3.h @@ -259,6 +259,19 @@ */ #define TEMP_RESIDENCY_TIME 60 +/** + TEMP_EWMA: Smooth noisy temperature sensors. Good hardware shouldn't be + noisy. Set to 1.0 for unfiltered data (and a 140 bytes smaller binary). + + Instrument Engineer's Handbook, 4th ed, Vol 2 p126 says values of + 0.05 to 0.1 are typical. Smaller is smoother but slower adjusting, larger is + quicker but rougher. If you need to use this, set the PID parameter to zero + (M132 S0) to make the PID loop insensitive to noise. + + Valid range: 0.001 to 1.0 +*/ +#define TEMP_EWMA 1.0 + /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board. // #define TEMP_MAX6675 #define TEMP_THERMISTOR diff --git a/config.gen7-v1.4.h b/config.gen7-v1.4.h index c414d6c..7e7e434 100644 --- a/config.gen7-v1.4.h +++ b/config.gen7-v1.4.h @@ -259,6 +259,19 @@ */ #define TEMP_RESIDENCY_TIME 60 +/** + TEMP_EWMA: Smooth noisy temperature sensors. Good hardware shouldn't be + noisy. Set to 1.0 for unfiltered data (and a 140 bytes smaller binary). + + Instrument Engineer's Handbook, 4th ed, Vol 2 p126 says values of + 0.05 to 0.1 are typical. Smaller is smoother but slower adjusting, larger is + quicker but rougher. If you need to use this, set the PID parameter to zero + (M132 S0) to make the PID loop insensitive to noise. + + Valid range: 0.001 to 1.0 +*/ +#define TEMP_EWMA 1.0 + /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board. // #define TEMP_MAX6675 #define TEMP_THERMISTOR diff --git a/config.ramps-v1.2.h b/config.ramps-v1.2.h index 3aeb09a..dffea7f 100644 --- a/config.ramps-v1.2.h +++ b/config.ramps-v1.2.h @@ -254,6 +254,19 @@ */ #define TEMP_RESIDENCY_TIME 60 +/** + TEMP_EWMA: Smooth noisy temperature sensors. Good hardware shouldn't be + noisy. Set to 1.0 for unfiltered data (and a 140 bytes smaller binary). + + Instrument Engineer's Handbook, 4th ed, Vol 2 p126 says values of + 0.05 to 0.1 are typical. Smaller is smoother but slower adjusting, larger is + quicker but rougher. If you need to use this, set the PID parameter to zero + (M132 S0) to make the PID loop insensitive to noise. + + Valid range: 0.001 to 1.0 +*/ +#define TEMP_EWMA 0.1 + /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board. // #define TEMP_MAX6675 #define TEMP_THERMISTOR diff --git a/config.ramps-v1.3.h b/config.ramps-v1.3.h index fec2715..f3af468 100644 --- a/config.ramps-v1.3.h +++ b/config.ramps-v1.3.h @@ -258,6 +258,19 @@ */ #define TEMP_RESIDENCY_TIME 60 +/** + TEMP_EWMA: Smooth noisy temperature sensors. Good hardware shouldn't be + noisy. Set to 1.0 for unfiltered data (and a 140 bytes smaller binary). + + Instrument Engineer's Handbook, 4th ed, Vol 2 p126 says values of + 0.05 to 0.1 are typical. Smaller is smoother but slower adjusting, larger is + quicker but rougher. If you need to use this, set the PID parameter to zero + (M132 S0) to make the PID loop insensitive to noise. + + Valid range: 0.001 to 1.0 +*/ +#define TEMP_EWMA 0.1 + /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board. // #define TEMP_MAX6675 #define TEMP_THERMISTOR diff --git a/config.sanguinololu-v1.1.h b/config.sanguinololu-v1.1.h index 93ffba0..631027b 100644 --- a/config.sanguinololu-v1.1.h +++ b/config.sanguinololu-v1.1.h @@ -255,6 +255,19 @@ */ #define TEMP_RESIDENCY_TIME 60 +/** + TEMP_EWMA: Smooth noisy temperature sensors. Good hardware shouldn't be + noisy. Set to 1.0 for unfiltered data (and a 140 bytes smaller binary). + + Instrument Engineer's Handbook, 4th ed, Vol 2 p126 says values of + 0.05 to 0.1 are typical. Smaller is smoother but slower adjusting, larger is + quicker but rougher. If you need to use this, set the PID parameter to zero + (M132 S0) to make the PID loop insensitive to noise. + + Valid range: 0.001 to 1.0 +*/ +#define TEMP_EWMA 0.1 + /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board. // #define TEMP_MAX6675 #define TEMP_THERMISTOR diff --git a/config.sanguinololu-v1.2.h b/config.sanguinololu-v1.2.h index fc4f759..5130c07 100644 --- a/config.sanguinololu-v1.2.h +++ b/config.sanguinololu-v1.2.h @@ -255,6 +255,19 @@ */ #define TEMP_RESIDENCY_TIME 60 +/** + TEMP_EWMA: Smooth noisy temperature sensors. Good hardware shouldn't be + noisy. Set to 1.0 for unfiltered data (and a 140 bytes smaller binary). + + Instrument Engineer's Handbook, 4th ed, Vol 2 p126 says values of + 0.05 to 0.1 are typical. Smaller is smoother but slower adjusting, larger is + quicker but rougher. If you need to use this, set the PID parameter to zero + (M132 S0) to make the PID loop insensitive to noise. + + Valid range: 0.001 to 1.0 +*/ +#define TEMP_EWMA 0.1 + /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board. // #define TEMP_MAX6675 #define TEMP_THERMISTOR diff --git a/config.teensy.h b/config.teensy.h index 8e8448f..d048fda 100644 --- a/config.teensy.h +++ b/config.teensy.h @@ -339,6 +339,19 @@ New plan: */ #define TEMP_RESIDENCY_TIME 60 +/** + TEMP_EWMA: Smooth noisy temperature sensors. Good hardware shouldn't be + noisy. Set to 1.0 for unfiltered data (and a 140 bytes smaller binary). + + Instrument Engineer's Handbook, 4th ed, Vol 2 p126 says values of + 0.05 to 0.1 are typical. Smaller is smoother but slower adjusting, larger is + quicker but rougher. If you need to use this, set the PID parameter to zero + (M132 S0) to make the PID loop insensitive to noise. + + Valid range: 0.001 to 1.0 +*/ +#define TEMP_EWMA 0.1 + /// which temperature sensors are you using? List every type of sensor you use here once, to enable the appropriate code. Intercom is the gen3-style separate extruder board. // #define TEMP_MAX6675 #define TEMP_THERMISTOR diff --git a/temp.c b/temp.c index b53e295..7f348d7 100644 --- a/temp.c +++ b/temp.c @@ -289,7 +289,17 @@ void temp_sensor_tick() { default: /* prevent compiler warning */ break; } - temp_sensors_runtime[i].last_read_temp = temp; + /* Exponentially Weighted Moving Average alpha constant for smoothing + noisy sensors. Instrument Engineer's Handbook, 4th ed, Vol 2 p126 + says values of 0.05 to 0.1 for TEMP_EWMA are typical. */ + #ifndef TEMP_EWMA + #define TEMP_EWMA 1.0 + #endif + #define EWMA_SCALE 1024L + #define EWMA_ALPHA ((long) (TEMP_EWMA * EWMA_SCALE)) + temp_sensors_runtime[i].last_read_temp = (EWMA_ALPHA * temp + + (EWMA_SCALE-EWMA_ALPHA) * temp_sensors_runtime[i].last_read_temp + ) / EWMA_SCALE; } if (labs((int16_t)(temp_sensors_runtime[i].last_read_temp - temp_sensors_runtime[i].target_temp)) < (TEMP_HYSTERESIS*4)) { if (temp_sensors_runtime[i].temp_residency < (TEMP_RESIDENCY_TIME*120))