changeset 984:41136649b90d GasConsumption

Improvment temperature measurent: In the previous verion no plausibility check for over temperature values was done. In addition the temperature display switches fast between e.g. 24 and 25 in case the value is 24.9 because of measurement tolerances. To avoid this a hysterese was added to the display function.
author Ideenmodellierer
date Sat, 29 Mar 2025 14:56:08 +0100 (3 days ago)
parents 7891160acde3
children aeafa631147d
files Discovery/Src/t7.c Small_CPU/Src/pressure.c
diffstat 2 files changed, 33 insertions(+), 14 deletions(-) [+]
line wrap: on
line diff
--- a/Discovery/Src/t7.c	Sun Mar 02 21:43:08 2025 +0100
+++ b/Discovery/Src/t7.c	Sat Mar 29 14:56:08 2025 +0100
@@ -171,6 +171,7 @@
 
 #define SHOW_AMBIENTE_SURFACE_DELTA		(0.02f)
 #define SHOW_AMBIENTE_DEBOUNCE			(0.003f)
+#define SHOW_TEMPERATURE_DEBOUNCE		(0.5f)
 
 #define MAX_NUM_SUMMARY_LINES 6
 
@@ -703,6 +704,7 @@
 {
 	static float debounceAmbientPressure = 0;
 	static uint8_t lastChargeStatus = 0;
+	static float lastTemperature = 100.0;
     char text[256];
     char timeSuffix;
     uint8_t hours;
@@ -1026,10 +1028,14 @@
 
         GFX_write_string(&FontT48,&t7surfaceL,text,3);
 
+        if(fabsf(stateUsed->lifeData.temperature_celsius - lastTemperature) > SHOW_TEMPERATURE_DEBOUNCE)
+        {
+        	lastTemperature = stateUsed->lifeData.temperature_celsius;
+        }
         if(settingsGetPointer()->nonMetricalSystem)
-            snprintf(text,40,"%01.0f\140\022\016\016 fahrenheit",unit_temperature_float(stateUsed->lifeData.temperature_celsius));
+        	snprintf(text,40,"%01.0f\140\022\016\016 fahrenheit",unit_temperature_float(lastTemperature));
         else
-            snprintf(text,30,"%01.0f\140\022\016\016 celsius",stateUsed->lifeData.temperature_celsius);
+        	snprintf(text,30,"%01.0f\140\022\016\016 celsius",lastTemperature);
         GFX_write_string(&FontT48,&t7surfaceL,text,4);
     }
     else
--- a/Small_CPU/Src/pressure.c	Sun Mar 02 21:43:08 2025 +0100
+++ b/Small_CPU/Src/pressure.c	Sat Mar 29 14:56:08 2025 +0100
@@ -52,7 +52,8 @@
 #define PRESSURE_SURFACE_MAX_MBAR			(1060.0f)		/* It is unlikely that pressure at surface is greater than this value => clip to it */
 
 #define PRESSURE_MINIMUM					(0.0f)
-#define TEMPERATURE_MINIMUM					(-100.0f)
+#define TEMPERATURE_MINIMUM					(-40.0f)
+#define TEMPERATURE_MAXIMUM					(80.0f)
 
 #define PRESSURE_SURFACE_QUE					(30u)			/* history buffer [minutes] for past pressure measurements */
 #define PRESSURE_SURFACE_EVA_WINDOW				(15u)			/* Number of entries evaluated during instability test. Used to avoid detection while dive enters water */
@@ -89,7 +90,7 @@
 static float pressure_offset = 0.0;		/* Offset value which may be specified by the user via PC Software */
 static float temperature_offset = 0.0;	/* Offset value which may be specified by the user via PC Software */
 
-static float ambient_temperature = 0;
+static float ambient_temperature = 20.0;
 static float ambient_pressure_mbar = 1000.0;
 static float surface_pressure_mbar = 1000.0;
 static float surface_ring_mbar[PRESSURE_SURFACE_QUE] = { 0 };
@@ -638,8 +639,12 @@
 
 static void pressure_calculation_AN520_004_mod_MS5803_30BA__09_2015(void)
 {
-	static float runningAvg = 0;
-	static uint8_t avgCnt = 0;
+	static float runningAvgPressure = 0;
+	static uint8_t avgCntPressure = 0;
+	static float runningAvgTemp = 0;
+	static uint8_t avgCntTemp = 0;
+
+	float newTemperature = 0.0;
 
 	uint32_t local_D1; // ADC value of the pressure conversion
 	uint32_t local_D2; // ADC value of the temperature conversion
@@ -703,23 +708,31 @@
 							(((int64_t)((local_D1 * local_SENS) / 2097152)) - local_OFF)
 								/  8192 );//     )) / 10; // pow(2,21), pow(2,13)
 
-	ambient_temperature = ((float)local_Tx100) / 100;
-	ambient_temperature	+= temperature_offset;
+	newTemperature = ((float)local_Tx100) / 100;
+	newTemperature += temperature_offset;
 
-	if(ambient_temperature < TEMPERATURE_MINIMUM)
+	if((newTemperature < TEMPERATURE_MINIMUM) || (newTemperature > TEMPERATURE_MAXIMUM))
 	{
 		ambient_temperature = 20.0;
 	}
 
+	runningAvgTemp = (avgCntTemp * runningAvgTemp + newTemperature) / (avgCntTemp + 1);
+	if (avgCntTemp < 10)
+	{
+		avgCntTemp++;
+	}
+	ambient_temperature = runningAvgTemp;
+
+
 	calc_pressure = ((float)local_Px10) / 10;
 	calc_pressure += pressure_offset;
 
-	runningAvg = (avgCnt * runningAvg + calc_pressure) / (avgCnt + 1);
-	if (avgCnt < 10)	/* build an average considering the last measurements to have a weight "1 of 10" */
-	{					/* Main reason for this is the jitter of up to +-10 HPa in surface mode which is caused */
-		avgCnt++;		/* by the measurement range of the sensor which is focused on under water pressure measurement */
+	runningAvgPressure = (avgCntPressure * runningAvgPressure + calc_pressure) / (avgCntPressure + 1);
+	if (avgCntPressure < 10)	/* build an average considering the last measurements to have a weight "1 of 10" */
+	{							/* Main reason for this is the jitter of up to +-10 HPa in surface mode which is caused */
+		avgCntPressure++;		/* by the measurement range of the sensor which is focused on under water pressure measurement */
 	}
-	ambient_pressure_mbar = runningAvg;
+	ambient_pressure_mbar = runningAvgPressure;
 
 	if(ambient_pressure_mbar < PRESSURE_MINIMUM)
 	{