those numbers into accurate compensated values, then
we’ll conclude by printing the results to the LCD.
The datasheet for the BMP085 is a good one and
details the computations necessary. They’re very easy to
handle if you’re just going to carry them out with pencil
and paper. I won’t lie to you, though. Creating the PIC
code to perform those calculations consumed over 100
hours of my life and was one of the most difficult
programming challenges I’ve ever faced. Here’s why.
Of the 11 calibration constants mentioned a
moment ago, some of them represent signed 16-bit
integers, while others are unsigned integers — also 16-
bits. (The signed version is called an integer in Great
Cow Basic, while an unsigned one is a word.) What’s
more, in the actual computations, some of the
intermediate subtotals are also mixed up like that. Then,
toss in the fact that when divisions occur, sometimes the
quotient should be rounded and at other times simply
truncated. It was an incredibly frustrating two weeks of
very full days sorting this all out. It pleases me to no end
that I can spare you that! With the software library
included with this article, you can start using the
BMP085 within minutes.
Here’s how I handled the mixed data types. All of
the 16-bit numbers (constants and variables alike) —
whether signed or unsigned — are promoted to 32-bit
numbers, which Great Cow Basic calls longs. No need to
worry about overflows now! Furthermore, with one
consistent data type throughout, keeping things straight is
much simpler. Figure 4 explains what’s going on behind
the curtain, should you be curious.
However, a new problem arises. In the Great Cow
compiler, 32-bit arithmetic is
always assumed to be
performed on unsigned
longs. So, I had to forge
ahead and write new
multiplication and division
routines to accommodate
signed long integers.
(Addition and subtraction
take care of themselves).
For ultimate accuracy, I also
created a division routine
which rounds things
properly when needed.
Incidentally, all of the
computations are easily
handled without recourse to
floating point arithmetic.
Why open a can of beans
with a stick of dynamite?
To see how it all shakes
out, be sure to look over
the “BMP085.H” include
file which contains the library routines and is heavily
And Finally, the Firmware
By including the file “BMP085.H” in your own
programs, you now have access to three commands — no
muss, no fuss:
August 2015 51