Blue Robotics Bar02 Pressure Sensor sample MS5837-02BA Pressure Sensor
Dependents: Bar02_MS5837-02BA OCE360_Project
Fork of MS5837 by
Diff: MS5837.cpp
- Revision:
- 1:ee71a13b8e68
- Parent:
- 0:0c2c06ab8e72
- Child:
- 2:365c8caabc0e
--- a/MS5837.cpp Mon Jul 25 00:19:52 2016 +0000 +++ b/MS5837.cpp Tue Jul 17 16:11:48 2018 +0000 @@ -78,6 +78,15 @@ { int32_t dT, temp; int64_t OFF, SENS, press; + + //int32_t dT = 0; + //int64_t SENS = 0; + //int64_t OFF = 0; + int32_t SENSi = 0; + int32_t OFFi = 0; + int32_t Ti = 0; + int64_t OFF2 = 0; + int64_t SENS2 = 0; //no need to do this everytime! @@ -88,21 +97,38 @@ D2 = MS5837ReadADC(); // read the temperature value //printf("D1 = %d\n", D1); /* calculation according MS5837-01BA data sheet DA5837-01BA_006 */ - dT = D2 - (C[5]* 256); - OFF = (int64_t)C[2] * (1<<16) + ((int64_t)dT * (int64_t)C[4]) / (1<<7); - SENS = (int64_t)C[1] * (1<<15) + ((int64_t)dT * (int64_t)C[3]) / (1<<8); + dT = D2 - ((uint32_t)C[5]* 256); + OFF = (int64_t)C[2] * (1<<17) + ((int64_t)dT * (int64_t)C[4]) / (1<<6); + SENS = (int64_t)C[1] * (1<<16) + ((int64_t)dT * (int64_t)C[3]) / (1<<7); - temp = 2000 + (dT * C[6]) / (1<<23); + temp = 2000 + ((int64_t)dT * C[6]) / (1<<23); + press = (((int64_t)D1 * SENS) / (1<<21) - OFF) / (1<<15); + if((temp/100)<20){ //Low temp + //Serial.println("here"); + Ti = (11*int64_t(dT)*int64_t(dT))/(34359738368LL); + OFFi = (31*(temp-2000)*(temp-2000))/8; + SENSi = (63*(temp-2000)*(temp-2000))/32; + } + + OFF2 = OFF-OFFi; //Calculate pressure and temp second order + SENS2 = SENS-SENSi; + + temp = (temp-Ti); + press = (((D1*SENS2)/2097152l-OFF2)/32768l)/100; + T_MS5837 = (float) temp / 100.0f; // result of temperature in deg C in this var - press = (((int64_t)D1 * SENS) / (1<<21) - OFF) / (1<<13); - P_MS5837 = (float) press / 10.0f; // result of pressure in mBar in this var + P_MS5837 = (float) press / 1.00f; // result of pressure in mBar in this var - if (P_MS5837 < 900 || P_MS5837 > 3000) { - MS5837Reset(); // reset the sensor - MS5837ReadProm(); // read the calibration values - } } float MS5837::depth(void) { - return (P_MS5837/100)*1.019716; + //return (P_MS5837/100)*1.019716; + return ((P_MS5837*100)-101300)/(fluidDensity*9.80665); + +} + +float MS5837::altitude(void) { + //return (P_MS5837/100)*1.019716; + return (1-pow((P_MS5837/1013.25),0.190284))*145366.45*0.3048; + } \ No newline at end of file