Skip to content
Newer
Older
100644 77 lines (67 sloc) 2.01 KB
fa906da @jcw files imported
authored Aug 29, 2011
1 // Port library interface to BMP085 sensors connected via I2C
9c0edcc @jcw get rid of svn $Id keyword & update email address
authored Aug 29, 2011
2 // 2009-02-17 <jc@wippler.nl> http://opensource.org/licenses/mit-license.php
fa906da @jcw files imported
authored Aug 29, 2011
3
4 // computation and algorithm taken from the Bosch Sensortec BMP085 data sheet
5 // (IIRC, I had to cast to an int32_t for the b3 calculation to work above 25C)
6
7 #include <Ports.h>
8 #include "PortsBMP085.h"
1d38469 Detect Arduino environment version to make library compatible with 00…
unknown authored Oct 25, 2011
9 #if ARDUINO>=100
10 #include <Arduino.h> // Arduino 1.0
11 #else
98fcac0 @CapnBry Fix compilation under Linux for Arduino < 100
CapnBry authored Apr 16, 2012
12 #include <WProgram.h> // Arduino 0022
1d38469 Detect Arduino environment version to make library compatible with 00…
unknown authored Oct 25, 2011
13 #endif
fa906da @jcw files imported
authored Aug 29, 2011
14
15 uint8_t BMP085::startMeas(uint8_t type) const {
16 send();
17 write(0xF4);
18 write(type == TEMP ? 0x2E : 0x34 | (oss << 6));
19 stop();
20 return oss == 0 ? 5 : oss == 1 ? 8 : oss == 2 ? 14 : 26;
21 }
22
23 int32_t BMP085::getResult(uint8_t type) {
24 readFromReg(0xF6);
25 if (type == TEMP)
26 meas[TEMP] = readWord(1);
27 else {
28 meas[PRES] = readWord(0);
29 meas[PRES] <<= oss;
30 meas[PRES] |= read(1) >> (8-oss);
31 }
32 return meas[type];
33 }
34
35 void BMP085::getCalibData() {
36 readFromReg(0xAA);
37 ac1 = readWord(0);
38 ac2 = readWord(0);
39 ac3 = readWord(0);
40 ac4 = readWord(0);
41 ac5 = readWord(0);
42 ac6 = readWord(0);
43 b1 = readWord(0);
44 b2 = readWord(0);
45 mb = readWord(0);
46 mc = readWord(0);
47 md = readWord(1);
48 }
49
50 void BMP085::calculate(int16_t& tval, int32_t& pval) const {
51 int32_t ut = meas[TEMP], up = meas[PRES];
52 int32_t x1, x2, x3, b3, b5, b6, p;
53 uint32_t b4, b7;
54
55 x1 = (ut - ac6) * ac5 >> 15;
56 x2 = ((int32_t) mc << 11) / (x1 + md);
57 b5 = x1 + x2;
58 tval = (b5 + 8) >> 4;
59
60 b6 = b5 - 4000;
61 x1 = (b2 * (b6 * b6 >> 12)) >> 11;
62 x2 = ac2 * b6 >> 11;
63 x3 = x1 + x2;
64 b3 = ((((int32_t) ac1 * 4 + x3) << oss) + 2) >> 2;
65 x1 = ac3 * b6 >> 13;
66 x2 = (b1 * (b6 * b6 >> 12)) >> 16;
67 x3 = ((x1 + x2) + 2) >> 2;
68 b4 = (ac4 * (uint32_t) (x3 + 32768)) >> 15;
69 b7 = ((uint32_t) up - b3) * (50000 >> oss);
70 p = b7 < 0x80000000 ? (b7 * 2) / b4 : (b7 / b4) * 2;
71
72 x1 = (p >> 8) * (p >> 8);
73 x1 = (x1 * 3038) >> 16;
74 x2 = (-7357 * p) >> 16;
75 pval = p + ((x1 + x2 + 3791) >> 4);
76 }
Something went wrong with that request. Please try again.