Version modifié Polytech Paris Sud correction erreur de calcul sur la lib initiale
Diff: MS5607Base.h
- Revision:
- 1:b7fffbf481e2
- Parent:
- 0:5760862143d1
diff -r 5760862143d1 -r b7fffbf481e2 MS5607Base.h --- a/MS5607Base.h Tue Jul 03 08:57:57 2012 +0000 +++ b/MS5607Base.h Wed Dec 25 15:12:21 2019 +0000 @@ -25,6 +25,18 @@ class MS5607Base { public: + void init(float itemp=0,float ipress=0) { + writeCommand(RESET, 3); + c1 = readPROM(1); + c2 = readPROM(2); + c3 = readPROM(3); + c4 = readPROM(4); + c5 = readPROM(5); + c6 = readPROM(6); + inittemp = itemp; + initpress= ipress; + } + void printCoefficients() { printf("%d, %d, %d, %d, %d, %d\n", c1, c2, c3, c4, c5, c6); } @@ -38,12 +50,12 @@ } float getTemperature() { - int dT = getRawTemperature() - (c5 << 8); - int temp = 2000 + ((dT * c6) >> 23); + int dT = getRawTemperature() - ((0x0FFFF&c5) << 8); + int temp = 2000 + (((int64_t)dT * (0x0FFFF&c6)) >> 23); // 2nd order temperature compensation if (temp < 2000) { - int t2 = (int64_t) dT * dT >> 31; + int t2 = ((int64_t) dT * dT )>> 31; temp -= t2; } @@ -77,7 +89,7 @@ protected: int32_t c1, c2, c3, c4, c5, c6; - + float inittemp, initpress; enum { RESET = 0x1E, ADC_READ = 0x00, @@ -96,23 +108,17 @@ virtual int readPROM(int address) = 0; virtual int readADC(int command) = 0; - void init() { - writeCommand(RESET, 3); - c1 = readPROM(1); - c2 = readPROM(2); - c3 = readPROM(3); - c4 = readPROM(4); - c5 = readPROM(5); - c6 = readPROM(6); - } + float toAltitude(int pressure) { // Ref. 29124-AltimeterAppNote1.pdf const float R = 287.052; // specific gas constant R*/M0 const float g = 9.80665; // standard gravity const float t_grad = 0.0065; // gradient of temperature - const float t0 = 273.15 + 15; // temperature at 0 altitude - const float p0 = 101325; // pressure at 0 altitude + if(inittemp==0) inittemp=15; + if(initpress==0) initpress=101325; + float t0 = 273.15 + inittemp; // temperature at 0 altitude + float p0 = initpress;// 101700; // pressure at 0 altitude return t0 / t_grad * (1 - exp((t_grad * R / g) * log(pressure / p0))); }