From 66f06d20a28c0a12671df7de4ff27632be131eb7 Mon Sep 17 00:00:00 2001 From: wurstnase Date: Thu, 23 Jun 2016 19:03:05 +0200 Subject: [PATCH] Temp: change TEMP_EWMA to integer. This allows to use EWMA_ALPHA in an #if clause, which is needed for the next commit. Review changes by Traumflug: made changes to comments more complete, added rounding ("+ 500") and also adjusted Configtool for the change. --- config/printer.mendel.h | 9 +++++---- config/printer.mendel90.h | 9 +++++---- config/printer.tronxy.h | 9 +++++---- config/printer.wolfstrap.h | 9 +++++---- configtool/miscellaneouspage.py | 29 +---------------------------- configtool/printer.generic.h | 9 +++++---- temp.c | 8 ++++---- testcases/config.h.Profiling | 12 ++++++------ 8 files changed, 36 insertions(+), 58 deletions(-) diff --git a/config/printer.mendel.h b/config/printer.mendel.h index cf819f6..7f6484b 100644 --- a/config/printer.mendel.h +++ b/config/printer.mendel.h @@ -208,17 +208,18 @@ #define TEMP_RESIDENCY_TIME 60 /** \def 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). + 1000 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 + 50 to 100 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 + Valid range: 1 to 1000 */ -#define TEMP_EWMA 1.0 +#define TEMP_EWMA 1000 /** \def REPORT_TARGET_TEMPS With this enabled, M105 commands will return the current temperatures along diff --git a/config/printer.mendel90.h b/config/printer.mendel90.h index 0f9469c..aba73f6 100644 --- a/config/printer.mendel90.h +++ b/config/printer.mendel90.h @@ -208,17 +208,18 @@ #define TEMP_RESIDENCY_TIME 60 /** \def 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). + 1000 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 + 50 to 100 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 + Valid range: 1 to 1000 */ -#define TEMP_EWMA 1.0 +#define TEMP_EWMA 1000 /** \def REPORT_TARGET_TEMPS With this enabled, M105 commands will return the current temperatures along diff --git a/config/printer.tronxy.h b/config/printer.tronxy.h index c6b4889..ede7c91 100644 --- a/config/printer.tronxy.h +++ b/config/printer.tronxy.h @@ -208,17 +208,18 @@ #define TEMP_RESIDENCY_TIME 60 /** \def 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). + 1000 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 + 50 to 100 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 + Valid range: 1 to 1000 */ -#define TEMP_EWMA 1.0 +#define TEMP_EWMA 1000 /** \def REPORT_TARGET_TEMPS With this enabled, M105 commands will return the current temperatures along diff --git a/config/printer.wolfstrap.h b/config/printer.wolfstrap.h index 2753ec8..002cb8f 100644 --- a/config/printer.wolfstrap.h +++ b/config/printer.wolfstrap.h @@ -208,17 +208,18 @@ #define TEMP_RESIDENCY_TIME 60 /** \def 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). + 1000 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 + 50 to 100 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 + Valid range: 1 to 1000 */ -#define TEMP_EWMA 1.0 +#define TEMP_EWMA 1000 /** \def REPORT_TARGET_TEMPS With this enabled, M105 commands will return the current temperatures along diff --git a/configtool/miscellaneouspage.py b/configtool/miscellaneouspage.py index 545a161..c9e6e9e 100644 --- a/configtool/miscellaneouspage.py +++ b/configtool/miscellaneouspage.py @@ -145,39 +145,12 @@ class MiscellaneousPage(wx.Panel, Page): sz.Add(tc, pos = (7, 5)) k = 'TEMP_EWMA' - tc = self.addTextCtrl(k, labelWidth, self.onTextCtrlEWMA) + tc = self.addTextCtrl(k, labelWidth, self.onTextCtrlInteger) sz.Add(tc, pos = (8, 5)) self.SetSizer(sz) self.enableAll(False) - def onTextCtrlEWMA(self, evt): - self.assertModified(True) - tc = evt.GetEventObject() - name = tc.GetName() - w = tc.GetValue().strip() - if w == "": - valid = True - else: - m = reFloat.match(w) - if m: - v = float(w) - if v < 0.1 or v > 1.0: - valid = False - else: - valid = True - else: - valid = False - - self.setFieldValidity(name, valid) - - if valid: - tc.SetBackgroundColour(wx.SystemSettings_GetColour(wx.SYS_COLOUR_WINDOW)) - else: - tc.SetBackgroundColour("pink") - tc.Refresh() - evt.Skip() - def setHeaters(self, hlist): k = 'DC_EXTRUDER' v = self.choices[k].GetSelection() diff --git a/configtool/printer.generic.h b/configtool/printer.generic.h index 3bbddb8..1813f14 100644 --- a/configtool/printer.generic.h +++ b/configtool/printer.generic.h @@ -208,17 +208,18 @@ #define TEMP_RESIDENCY_TIME 60 /** \def 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). + 1000 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 + 50 to 100 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 + Valid range: 1 to 1000 */ -#define TEMP_EWMA 1.0 +#define TEMP_EWMA 1000 /** \def REPORT_TARGET_TEMPS With this enabled, M105 commands will return the current temperatures along diff --git a/temp.c b/temp.c index c5f5940..4f7a9bf 100644 --- a/temp.c +++ b/temp.c @@ -86,16 +86,16 @@ static struct { Default alpha constant for the Exponentially Weighted Moving Average (EWMA) for smoothing noisy sensors. Instrument Engineer's Handbook, 4th ed, - Vol 2 p126 says values of 0.05 to 0.1 are typical. + Vol 2 p126 says values of 50 to 100 are typical. - Setting it to 1.0 turns EWMA off. + This is scaled by factor 1000. Setting it to 1000 turns EWMA off. */ #ifndef TEMP_EWMA - #define TEMP_EWMA 1.0 + #define TEMP_EWMA 1000 #endif #define EWMA_SCALE 1024L -#define EWMA_ALPHA ((uint32_t)(TEMP_EWMA * EWMA_SCALE)) +#define EWMA_ALPHA ((TEMP_EWMA * EWMA_SCALE + 500) / 1000) // If EWMA is used, continuously update analog reading for more data points. #define TEMP_READ_CONTINUOUS (EWMA_ALPHA < EWMA_SCALE) diff --git a/testcases/config.h.Profiling b/testcases/config.h.Profiling index 1e1d78e..79cf289 100644 --- a/testcases/config.h.Profiling +++ b/testcases/config.h.Profiling @@ -405,18 +405,18 @@ */ #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). +/** \def TEMP_EWMA + Smooth noisy temperature sensors. Good hardware shouldn't be noisy. Set to + 1000 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 + 50 to 100 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 + Valid range: 1 to 1000 */ -#define TEMP_EWMA 1.0 +#define TEMP_EWMA 1000 /** \def TEMP_MAX6675 TEMP_THERMISTOR TEMP_AD595 TEMP_PT100 TEMP_INTERCOM \def TEMP_MCP3008