From ddd72324c393b8cf8259b3ad0d144047a96998ce Mon Sep 17 00:00:00 2001 From: Alessio Morale Date: Fri, 20 Mar 2015 22:11:29 +0100 Subject: [PATCH] OP-1793 - Use a constant for running average smoothing factor --- flight/pios/common/pios_ms5611.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/flight/pios/common/pios_ms5611.c b/flight/pios/common/pios_ms5611.c index 8dcd7673a..6a9c70879 100644 --- a/flight/pios/common/pios_ms5611.c +++ b/flight/pios/common/pios_ms5611.c @@ -42,7 +42,9 @@ #ifndef PIOS_MS5611_SLOW_TEMP_RATE #define PIOS_MS5611_SLOW_TEMP_RATE 1 #endif - +// Running moving average smoothing factor +#define PIOS_MS5611_TEMP_SMOOTHING 10 +// /* Local Types */ typedef struct { uint16_t C[6]; @@ -248,8 +250,9 @@ int32_t PIOS_MS5611_ReadADC(void) // Actual temperature (-40…85°C with 0.01°C resolution) // TEMP = 20°C + dT * TEMPSENS = 2000 + dT * C6 / 2^23 Temperature = 2000l + ((deltaTemp * CalibData.C[5]) / POW2(23)); - if(FilteredTemperature != INT32_MIN){ - FilteredTemperature = (FilteredTemperature * 9 + Temperature) / 10; + if (FilteredTemperature != INT32_MIN) { + FilteredTemperature = (FilteredTemperature * (PIOS_MS5611_TEMP_SMOOTHING - 1) + + Temperature) / PIOS_MS5611_TEMP_SMOOTHING; } else { FilteredTemperature = Temperature; }