High resolution barometer and altimeter using i2c mode
Fork of ms5611 by
Diff: ms5611.cpp
- Revision:
- 3:c2d1b0d432ad
- Parent:
- 2:05804ed70748
- Child:
- 5:0d7b229474c6
diff -r 05804ed70748 -r c2d1b0d432ad ms5611.cpp --- a/ms5611.cpp Thu May 09 16:34:52 2013 +0000 +++ b/ms5611.cpp Mon May 13 20:12:15 2013 +0000 @@ -18,6 +18,7 @@ double P; // compensated pressure value double T; // compensated temperature value +double A; // altitude uint32_t C[8]; //coefficient storage @@ -253,7 +254,7 @@ void ms5611::calcPT() { int32_t D2 = cmd_adc(MS5611_CMD_ADC_D2 + MS5611_CMD_ADC_4096); // read D2 int32_t D1 = cmd_adc(MS5611_CMD_ADC_D1 + MS5611_CMD_ADC_4096); // read D1 - int32_t dT = D2 - ((uint32_t)C[5] << 8); + int64_t dT = D2 - ((uint64_t)C[5] << 8); int64_t OFF = ((uint32_t)C[2] << 16) + ((dT * (C[4]) >> 7)); //was OFF = (C[2] << 17) + dT * C[4] / (1 << 6); int64_t SENS = ((uint32_t)C[1] << 15) + ((dT * (C[3]) >> 8)); //was SENS = (C[1] << 16) + dT * C[3] / (1 << 7); T = (2000 + (((uint64_t)dT * C[6]) / (float)(1 << 23))) / 100; @@ -289,7 +290,7 @@ } //******************************************************** -//! @brief calculate prssure +//! @brief calculate pressure //! //! @return double barometric pressure millibar //******************************************************** @@ -298,3 +299,26 @@ calcPT(); return(P); } + +//******************************************************** +//! @brief get pressure, no calculation +//! +//! @return double barometric pressure millibar +//******************************************************** + +double ms5611::getPressure() { + calcPT(); + return(P); +} + +//******************************************************** +//! @brief get pressure, no calculation +//! +//! @enter float sea level barometer +//! @return float altitude in feet +//******************************************************** + +float ms5611::getAltitudeFT(float sea_pressure) { + A = (1 - (pow((P / (double)sea_pressure), 0.190284))) * 145366.45; + return((float)A); +}