diff Small_CPU/Src/scheduler.c @ 867:3311b720a072 Evo_2_23

Decrease calculation interval for ascend speed: In the previous version the ascend speed was calculated every 2 seconds. To improve the visualization the interval has been reduced to 400ms. The average function of the depth calculation ensures a smooth dynamic transition of the values. For testing a simulation profile, which changes between several speeds, may be acivated using the compile switch.
author Ideenmodellierer
date Mon, 12 Aug 2024 14:30:22 +0200
parents d32901746950
children 5b675077ccfb
line wrap: on
line diff
--- a/Small_CPU/Src/scheduler.c	Tue Jul 02 20:05:08 2024 +0200
+++ b/Small_CPU/Src/scheduler.c	Mon Aug 12 14:30:22 2024 +0200
@@ -480,6 +480,8 @@
 {
 	uint32_t ticksdiff = 0; 
 	uint32_t lasttick = 0;
+	uint32_t lastPressureTick = 0;
+	uint32_t tickPressureDiff = 0;
 	uint8_t extAdcChannel = 0;
 	uint8_t counterAscentRate = 0;
 	float lastPressure_bar = 0.0f;
@@ -552,18 +554,21 @@
 						global.lifeData.counterSecondsShallowDepth = (global.settings.timeoutDiveReachedZeroDepth - 10);
 				}
 #endif
-				
-				//Calc ascentrate every two second (20 * 100 ms)
+
 				counterAscentRate++;
-				if(counterAscentRate == 20)
+				if(counterAscentRate == 4)
 				{
-					global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f;
-					if(lastPressure_bar >= 0)
+					tickPressureDiff = time_elapsed_ms(lastPressureTick,lasttick); /* Calculate ascent rate every 400ms use timer to take care for small time shifts */
+					if(tickPressureDiff != 0)
 					{
-							//2 seconds * 30 == 1 minute, bar * 10 = meter
-							global.lifeData.ascent_rate_meter_per_min = (lastPressure_bar - global.lifeData.pressure_ambient_bar)  * 30 * 10;
+						global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f;
+						if(lastPressure_bar >= 0)
+						{
+							global.lifeData.ascent_rate_meter_per_min = (lastPressure_bar - global.lifeData.pressure_ambient_bar)  * (60000.0 / tickPressureDiff) * 10; /* bar * 10 = meter */
+						}
 					}
 					lastPressure_bar = global.lifeData.pressure_ambient_bar;
+					lastPressureTick = lasttick;
 					counterAscentRate = 0;
 				}
 				copyPressureData();