comparison 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
comparison
equal deleted inserted replaced
863:0c89c6fa949c 867:3311b720a072
478 */ 478 */
479 void scheduleDiveMode(void) 479 void scheduleDiveMode(void)
480 { 480 {
481 uint32_t ticksdiff = 0; 481 uint32_t ticksdiff = 0;
482 uint32_t lasttick = 0; 482 uint32_t lasttick = 0;
483 uint32_t lastPressureTick = 0;
484 uint32_t tickPressureDiff = 0;
483 uint8_t extAdcChannel = 0; 485 uint8_t extAdcChannel = 0;
484 uint8_t counterAscentRate = 0; 486 uint8_t counterAscentRate = 0;
485 float lastPressure_bar = 0.0f; 487 float lastPressure_bar = 0.0f;
486 global.dataSendToMaster.mode = MODE_DIVE; 488 global.dataSendToMaster.mode = MODE_DIVE;
487 global.deviceDataSendToMaster.mode = MODE_DIVE; 489 global.deviceDataSendToMaster.mode = MODE_DIVE;
550 } 552 }
551 if((global.lifeData.counterSecondsShallowDepth > 1) && (global.lifeData.counterSecondsShallowDepth < (global.settings.timeoutDiveReachedZeroDepth - 10))) 553 if((global.lifeData.counterSecondsShallowDepth > 1) && (global.lifeData.counterSecondsShallowDepth < (global.settings.timeoutDiveReachedZeroDepth - 10)))
552 global.lifeData.counterSecondsShallowDepth = (global.settings.timeoutDiveReachedZeroDepth - 10); 554 global.lifeData.counterSecondsShallowDepth = (global.settings.timeoutDiveReachedZeroDepth - 10);
553 } 555 }
554 #endif 556 #endif
555 557
556 //Calc ascentrate every two second (20 * 100 ms)
557 counterAscentRate++; 558 counterAscentRate++;
558 if(counterAscentRate == 20) 559 if(counterAscentRate == 4)
559 { 560 {
560 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f; 561 tickPressureDiff = time_elapsed_ms(lastPressureTick,lasttick); /* Calculate ascent rate every 400ms use timer to take care for small time shifts */
561 if(lastPressure_bar >= 0) 562 if(tickPressureDiff != 0)
562 { 563 {
563 //2 seconds * 30 == 1 minute, bar * 10 = meter 564 global.lifeData.pressure_ambient_bar = get_pressure_mbar() / 1000.0f;
564 global.lifeData.ascent_rate_meter_per_min = (lastPressure_bar - global.lifeData.pressure_ambient_bar) * 30 * 10; 565 if(lastPressure_bar >= 0)
566 {
567 global.lifeData.ascent_rate_meter_per_min = (lastPressure_bar - global.lifeData.pressure_ambient_bar) * (60000.0 / tickPressureDiff) * 10; /* bar * 10 = meter */
568 }
565 } 569 }
566 lastPressure_bar = global.lifeData.pressure_ambient_bar; 570 lastPressure_bar = global.lifeData.pressure_ambient_bar;
571 lastPressureTick = lasttick;
567 counterAscentRate = 0; 572 counterAscentRate = 0;
568 } 573 }
569 copyPressureData(); 574 copyPressureData();
570 Scheduler.counterPressure100msec++; 575 Scheduler.counterPressure100msec++;
571 } 576 }