BMP085 Calcs
BMP085 Calcs
Here’s a set of equations for computing pressure with the Bosch BMP085
pressure sensor that use floating point math instead of the integer math pub-
lished by Bosch. There are two advantages over the integer math.
2 The Constants
There were a couple of places in the integer math where a constant was added
to an expression before right-shifting to provide a rounding behavior instead of
truncation. These constants have been removed from the floating point equa-
tions.
1
All references to the BMP085 calibration values (e.g. AC4 or MC ) use the
integer values of these constants. As mentioned above, be sure to interpret
values as unsigned where necessary.
These floating point formulas start with a new set of floating point calibra-
tion factors. These are derived from the EEPROM integer calibration data,
which is described on the Bosch data sheet. The first three values are only used
in computing the final constants below and can be discarded afterwards.
2−15
c5 = · AC5
160
c6 = AC6
211
mc = · MC
1602
MD
md =
160
Three second order polynomials are used to compute pressure, and they
require another nine constants (three for each polynomial).
x0 = AC1
x1 = 160 · 2−13 · AC2
x2 = 1602 · 2−25 · B2
y0 = c4 · 215
y1 = c4 · c3
y2 = c 4 · b1
3791 − 8
p0 =
1600
p1 = 1 − 7357 · 2−20
p2 = 3038 · 100 · 2−36
2
is wrong, there will be a small offset in the result of 0.005mb. However, since
the device will almost always have an initial offset error much greater than this
it is not of much concern.
The coefficients above have been scaled so that the final results will be
temperature (T ) in degrees Celsius, and pressure (P ) in millibars (a.k.a hecto-
Pascals).
This wraps up the calculation of floating point constants that are used for
converting the raw, integer temperature and pressure data into degrees Celsius
and millibars.
3 The Formulas
The raw real-time data from the BMP085 will be represented by tu for temper-
ature and pu for pressure. The temperature value is just equal to the integer
value that is read from the barometer. The pressure reading is formatted a bit
different however; it is treated like a fixed point fraction with the radix point just
to the right of the LSB. After these integer values are acquired, all remaining
calculations below are floating point. These first two formulas treat the integer
register values as unsigned quantities.
s = T − 25
x = x2 s2 + x1 s + x0
y = y2 s2 + y1 s + y0
These two factors are now used to compute an initial pressure value, z:
3
Figure 1: Comparison of Pressure Computations
pu − x
z=
y
A polynomial in z gives the final corrected pressure value.
P = p2 z 2 + p1 z + p0
4 Verification
These results were compared the published Bosch integer code, over a large
grid of temperature and pressure values. The difference varies over a range
of approximately ±0.05mb and the average offset is around 0.02mb. Figure 1
shows a 3-dimensional plot of the difference between integer and floating point
values. The x/y axes cover different values of temperature and un-corrected
pressure input values. The vertical scale is in millibars, and is color coded as
shown by the bar on the right. The jagged appearance of this plot is entirely
due to round-off errors in the integer math.
These formulas therefore accurately express the proper corrections over a
large range of inputs, without the stair-step, jumpy nature of corrections from
integer math.
4
5 Usefulness
To keep this in perspective, it is worthwhile to take a look at the Bosch specifi-
cations:
Absolute accuracy ±2.5mb
Relative accuracy ±0.2mb
The improved floating point algorithm gives an improvement on the order
of 0.05mb, which is about one-fourth of the relative accuracy specification.
So, the improvements are of limited value – but still may be of interest to
some folks. These equations are also much simpler to implement and may be
preferable if the floating point resources are available on the hardware used to
make the conversion.
6 An Example
Here is an example of the calculations to dispel any questions about the equa-
tions above.
First, the values of the calibration coefficients. The values AC4 , AC5 , AC6
are unsigned 16-bit integers. All other values are signed (two’s complement)
16-bit quantities.
This data remains constant for any given sensor and need not be read and
computed every time the sensor is powered on. Once all values are computed,
it is not necessary to retain the values of c3 , c4 , b1 .
5
Given a hexadecimal temperature reading of 0x69EC and a pressure reading
of 0x982FC0, the calculations are as follows:
7 Resolution
In the above example, it is easy to verify that one LSB in temperature data is
equivalent to roughly 0.006 degC.
The value of y is approximately equal to the number of integer pu counts per
millibar of pressure. In this example, the OSS was 3, so the actual resolution of
pu is 2−3 or 0.125. From this, the resolution of the raw readings is approximately
31.65 · 8 ≈ 253 counts per millibar. One LSB in the data is then equal to about
0.004mb or 0.4Pa. This corresponds to about 1.5 inches of altitude change at
sea level.
8 Performance
To demonstrate the improvement in using floating point math, two plots were
generated using a fixed pressure reading of 0x980000. The temperature reading
was incremented from 0x6800 to 0x68FF (roughly, from 20.6 to 22.3 degC).
Pressure computations were performed with these inputs using both the Bosch
integer code and the floating point formulas developed above.
The figure 2 shows the two results plotted on top of one another. There
is not a lot of difference, although the blue line (integer math) is noticeably
noisier.
To make the differences easier to see, each of the lines was “flattened” by
subtracting a best-fit straight line from each result. The next two graphs show
this result. In the case of integer math (figure 3), the only thing clearly visible
is the jumpy, staircase behavior resulting from integer rounding. Notice that
the magnitude of these jumps is typically on the order of 0.03 to 0.04mb which
is about 10 times larger than the resolution of 0.004mb with OSS=3.
6
The data computed with floating point math (figure 4) shows a completely
different picture. First, the y-axis scale is 10 times smaller than in the preceding
graph. The parabolic behavior of the corrections (due to the various second-
order polynomials in the math) is clearly visible with almost no apparent noise.
Over this temperature range, the corrections only change by a little more than
1-bit of resolution (0.004mb), but the corrections are not going to add 10 or
more LSB counts of noise to the data as in the case with integer math.
Figure 5 shows a similar comparison of corrections over a wider temperature
range. Here, the parabolic nature of corrections is just barely visible in the
integer data. The floating point results are striking in comparison.
Again, keeping this in perspective, the correction jumps of about 0.04mb seen
with integer math correspond to about one foot of altitude change at sea level.
Can the sensor really detect these small changes in level, especially superimposed
upon local changes in barometric pressure?
7
Figure 3: Deviation of integer math from straight line.
8
Figure 5: Comparison over a wider temperature range.