Mercurial > public > ostc4
comparison Small_CPU/Src/pressure.c @ 688:8c92f7743e14 Betatest
Added sanity check for temperature and pressure values:
It happens from time to time at the debug hardware (electronic without housing) that pressure or temperature are in an invalid range . To avoid side effects a sanity check has been added.
author | Ideenmodellierer |
---|---|
date | Fri, 05 Aug 2022 15:13:29 +0200 |
parents | 4644891d2f51 |
children | 2ace67231c49 |
comparison
equal
deleted
inserted
replaced
687:5e9973957318 | 688:8c92f7743e14 |
---|---|
47 #define CMD_PROM_RD 0xA0 // Prom read command | 47 #define CMD_PROM_RD 0xA0 // Prom read command |
48 | 48 |
49 /* remove comment to use a predefined profile for pressure changes instead of real world data */ | 49 /* remove comment to use a predefined profile for pressure changes instead of real world data */ |
50 /* #define SIMULATE_PRESSURE */ | 50 /* #define SIMULATE_PRESSURE */ |
51 | 51 |
52 | |
52 #define PRESSURE_SURFACE_MAX_MBAR (1060.0f) /* It is unlikely that pressure at surface is greater than this value => clip to it */ | 53 #define PRESSURE_SURFACE_MAX_MBAR (1060.0f) /* It is unlikely that pressure at surface is greater than this value => clip to it */ |
54 | |
55 #define PRESSURE_MINIMUM (0.0f) | |
56 #define TEMPERATURE_MINIMUM (-100.0f) | |
53 | 57 |
54 #define PRESSURE_SURFACE_QUE (30u) /* history buffer [minutes] for past pressure measurements */ | 58 #define PRESSURE_SURFACE_QUE (30u) /* history buffer [minutes] for past pressure measurements */ |
55 #define PRESSURE_SURFACE_EVA_WINDOW (15u) /* Number of entries evaluated during instability test. Used to avoid detection while dive enters water */ | 59 #define PRESSURE_SURFACE_EVA_WINDOW (15u) /* Number of entries evaluated during instability test. Used to avoid detection while dive enters water */ |
56 #define PRESSURE_SURFACE_STABLE_LIMIT (10u) /* Define pressure as stable if delta (mBar) is below this value */ | 60 #define PRESSURE_SURFACE_STABLE_LIMIT (10u) /* Define pressure as stable if delta (mBar) is below this value */ |
57 #define PRESSURE_SURFACE_DETECT_STABLE_CNT (5u) /* Event count to detect stable condition */ | 61 #define PRESSURE_SURFACE_DETECT_STABLE_CNT (5u) /* Event count to detect stable condition */ |
662 / 8192 );// )) / 10; // pow(2,21), pow(2,13) | 666 / 8192 );// )) / 10; // pow(2,21), pow(2,13) |
663 | 667 |
664 ambient_temperature = ((float)local_Tx100) / 100; | 668 ambient_temperature = ((float)local_Tx100) / 100; |
665 ambient_temperature += temperature_offset; | 669 ambient_temperature += temperature_offset; |
666 | 670 |
671 if(ambient_temperature < TEMPERATURE_MINIMUM) | |
672 { | |
673 ambient_temperature = 20.0; | |
674 } | |
675 | |
667 calc_pressure = ((float)local_Px10) / 10; | 676 calc_pressure = ((float)local_Px10) / 10; |
668 calc_pressure += pressure_offset; | 677 calc_pressure += pressure_offset; |
669 | 678 |
670 runningAvg = (avgCnt * runningAvg + calc_pressure) / (avgCnt + 1); | 679 runningAvg = (avgCnt * runningAvg + calc_pressure) / (avgCnt + 1); |
671 if (avgCnt < 10) /* build an average considering the last measurements to have a weight "1 of 10" */ | 680 if (avgCnt < 10) /* build an average considering the last measurements to have a weight "1 of 10" */ |
672 { /* Main reason for this is the jitter of up to +-10 HPa in surface mode which is caused */ | 681 { /* Main reason for this is the jitter of up to +-10 HPa in surface mode which is caused */ |
673 avgCnt++; /* by the measurement range of the sensor which is focused on under water pressure measurement */ | 682 avgCnt++; /* by the measurement range of the sensor which is focused on under water pressure measurement */ |
674 } | 683 } |
675 ambient_pressure_mbar = runningAvg; | 684 ambient_pressure_mbar = runningAvg; |
685 | |
686 if(ambient_pressure_mbar < PRESSURE_MINIMUM) | |
687 { | |
688 ambient_pressure_mbar = 1000.0; | |
689 } | |
676 } | 690 } |
677 | 691 |
678 | 692 |
679 /* taken from AN520 by meas-spec.com dated 9. Aug. 2011 | 693 /* taken from AN520 by meas-spec.com dated 9. Aug. 2011 |
680 * short and int are both 16bit according to AVR/GCC google results | 694 * short and int are both 16bit according to AVR/GCC google results |