Bosch BMP085 Barometer Floating Point Pressure Calculations

Similar documents
Data byte 0 Data byte 1 Data byte 2 Data byte 3 Data byte 4. 0xA Register Address MSB data byte Data byte Data byte LSB data byte

ECE260: Fundamentals of Computer Engineering

Binary addition example worked out

Hakim Weatherspoon CS 3410 Computer Science Cornell University

Chapter 1 CSCI

14:332:231 DIGITAL LOGIC DESIGN. Why Binary Number System?

EE260: Digital Design, Spring n Digital Computers. n Number Systems. n Representations. n Conversions. n Arithmetic Operations.

Numbers and Arithmetic

Numbers and Arithmetic

Differential Pressure Sensor

Number Representation and Waveform Quantization

Experiment 0 ~ Introduction to Statistics and Excel Tutorial. Introduction to Statistics, Error and Measurement


Menu. Review of Number Systems EEL3701 EEL3701. Math. Review of number systems >Binary math >Signed number systems

Name Period Date L.O: students will be able to describe air temperature and air pressure

Math Lecture 18 Notes

Mark Redekopp, All rights reserved. Lecture 1 Slides. Intro Number Systems Logic Functions

ENGIN 112 Intro to Electrical and Computer Engineering

Four Important Number Systems

Combinational Logic Design Arithmetic Functions and Circuits

Chapter 4 Number Representations

Multiplication of signed-operands

Complement Arithmetic

UNSIGNED BINARY NUMBERS DIGITAL ELECTRONICS SYSTEM DESIGN WHAT ABOUT NEGATIVE NUMBERS? BINARY ADDITION 11/9/2018

CHAPTER 2 NUMBER SYSTEMS

CH 42 TEMPERATURE FORMULAS

In other words, we are interested in what is happening to the y values as we get really large x values and as we get really small x values.

Digital Systems Roberto Muscedere Images 2013 Pearson Education Inc. 1

Logic and Computer Design Fundamentals. Chapter 5 Arithmetic Functions and Circuits

CprE 281: Digital Logic

QUADRATIC PROGRAMMING?

The Gram-Schmidt Process

O P E R A T I N G M A N U A L

General Least Squares Fitting

Appendix B: Skills Handbook

9. Datapath Design. Jacob Abraham. Department of Electrical and Computer Engineering The University of Texas at Austin VLSI Design Fall 2017

Binary addition by hand. Adding two bits

DSP Design Lecture 2. Fredrik Edman.

Section 20: Arrow Diagrams on the Integers

Fundamentals of data, graphical, and error analysis

Exponents and Polynomials. (5) Page 459 #15 43 Second Column; Page 466 #6 30 Fourth Column

Solving Quadratic & Higher Degree Equations

Representing signed numbers in Two s Complement notation

06MAR THU 12: User Manual

Engineering Fundamentals and Problem Solving, 6e. Chapter 6 Engineering Measurements

Math 175 Common Exam 2A Spring 2018

Mathematical Induction. Part Two

Numbering Systems. Computational Platforms. Scaling and Round-off Noise. Special Purpose. here that is dedicated architecture

The grade on this summer packet will count as your first journal grade and points will be deducted for late submissions.

What s the Deal? MULTIPLICATION. Time to multiply

Basic Instruments 2 - Altimeters Nigel Page -

Algebra II Polynomials: Operations and Functions

Keywords: sensor compensation, integrated circuit, ic, compensation algorithm, piezoresistive, prt, pressure sensors, temperature

22 Approximations - the method of least squares (1)

convert a two s complement number back into a recognizable magnitude.

Solving Quadratic & Higher Degree Equations

ACCESS TO SCIENCE, ENGINEERING AND AGRICULTURE: MATHEMATICS 1 MATH00030 SEMESTER / Lines and Their Equations

Data Converter Fundamentals

ECE380 Digital Logic. Positional representation

Possible Prelab Questions.

CPE100: Digital Logic Design I

7.7. Factoring Special Products. Essential Question How can you recognize and factor special products?

Integrals. D. DeTurck. January 1, University of Pennsylvania. D. DeTurck Math A: Integrals 1 / 61

Solving Quadratic & Higher Degree Equations

Week No. 06: Numbering Systems

What Every Programmer Should Know About Floating-Point Arithmetic DRAFT. Last updated: November 3, Abstract

Unit 1: Introduction Measurement and Scientific Notation. Measurements in physics are carried out in SI units, aka the.

Homework 2 Foundations of Computational Math 1 Fall 2018

CS1800: Hex & Logic. Professor Kevin Gold

Contents. Introduction... 5

General Least Squares Fitting

CpE358/CS381. Switching Theory and Logical Design. Summer

Chapter 1: January 26 January 30

Using Scientific Measurements

NOVALYNX CORPORATION ELEVATION CORRECTION TABLES FOR BAROMETRIC PRESSURE SENSORS

Wheels Radius / Distance Traveled

High School Math Contest

Archdiocese of Washington Catholic Schools Academic Standards Mathematics

6.4 Division of Polynomials. (Long Division and Synthetic Division)

NUMBERS AND CODES CHAPTER Numbers

Introduction to Digital Logic Missouri S&T University CPE 2210 Number Systems

Ex code

Answers of the MATH97 Practice Test Form A

experiment3 Introduction to Data Analysis

2 Systems of Linear Equations

0,..., r 1 = digits in radix r number system, that is 0 d i r 1 where m i n 1

Section 4.7 Scientific Notation

Math 10b Ch. 8 Reading 1: Introduction to Taylor Polynomials

Elementary Algebra Study Guide Some Basic Facts This section will cover the following topics

Chapter 6. Systems of Equations and Inequalities

Software implementation of ECC

Measurement and Instrumentation. Sampling, Digital Devices, and Data Acquisition

Math101, Sections 2 and 3, Spring 2008 Review Sheet for Exam #2:

1. Definition of a Polynomial

Secondary Math 2H Unit 3 Notes: Factoring and Solving Quadratics

Finite Mathematics : A Business Approach

A video College Algebra course & 6 Enrichment videos

ENEL Digital Circuit Design. Final Examination

A. 16 B. 16 C. 4 D What is the solution set of 4x + 8 > 16?

Transcription:

Bosch BMP085 Barometer Floating Point Pressure Calculations...and some analysis... January 30, 2013 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 published by Bosch. There are two advantages over the integer math. Integer math results in stair-step, jumpy corrections as the input values vary smoothly. This is due to round-off errors in the integer calculations. The floating point math does not suffer from this problem and corrections vary smoothly with changes in input values. The equations are much simpler and easier to implement without error. Some new calibration values have been defined in terms of the Bosch calibration constants. Temperature and pressure calculations have been reduced to some simple ratios and three second-order polynomials. 1 The Elusive Header File It is relatively easy to find the C-language reference file bmp085.c (which contains an example of the integer math) on the internet. It is not easy to find the accompanying header file (bmp085.h) which contains some very important details. This file has finally been located and reveals that not all of the 16- bit calibration constants contained in the BMP085 s non-volatile memory are signed values. In fact, the values AC 4, AC 5, AC 6 are all unsigned 16-bit integers. At least one BMP085 unit has been seen which has an AC 4 value higher than 32,767 so this distinction is indeed important. 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 equations. 1

All references to the BMP085 calibration values (e.g. AC 4 or M C ) 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 calibration 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. c 3 = 160 2 15 AC 3 c 4 = 10 3 2 15 AC 4 b 1 = 160 2 2 30 B 1 The next four constants are used in the computation of temperature. c 5 = 2 15 160 AC 5 c 6 = AC 6 m c = 211 160 2 M C m d = M D 160 Three second order polynomials are used to compute pressure, and they require another nine constants (three for each polynomial). x 0 = AC 1 x 1 = 160 2 13 AC 2 x 2 = 160 2 2 25 B 2 y 0 = c 4 2 15 y 1 = c 4 c 3 y 2 = c 4 b 1 p 0 = 3791 8 1600 p 1 = 1 7357 2 20 p 2 = 3038 100 2 36 In subtracting 8 in the numerator of the equation for p 0, it is assumed the original value was offset for the purpose of integer rounding. If this assumption 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 t u for temperature and p u 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. t u = 256 MSB + LSB p u = 256 MSB + LSB + XLSB 256 Defining p u in this way alleviates the need to make any further adjustments for the over-sampling ratio (OSS). If OSS is zero, it is not necessary to read the XLSB register and its value can be set to zero. The temperature computation is quite simple. First we define a new value, α and then compute temperature in terms of this new variable: m c α = c 5 (t u c 6 ) ; T = α + α + m d Computing pressure requires the temperature (T ) computed above, and uses three second-order polynomials. The first two generate offset (x) and scaling factors (y) which are functions of the difference between the current temperature and 25C (which we ll call s). s = T 25 x = x 2 s 2 + x 1 s + x 0 y = y 2 s 2 + y 1 s + y 0 These two factors are now used to compute an initial pressure value, z: 3

Figure 1: Comparison of Pressure Computations z = p u x y A polynomial in z gives the final corrected pressure value. 4 Verification P = p 2 z 2 + p 1 z + p 0 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 specifications: Absolute accuracy Relative accuracy ±2.5mb ±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 equations above. First, the values of the calibration coefficients. The values AC 4, AC 5, AC 6 are unsigned 16-bit integers. All other values are signed (two s complement) 16-bit quantities. BMP085 Calibration Data AC 1 7911 B 1 5498 AC 2-934 B 2 46 AC 3-14306 M B -32768 AC 4 31567 M C -11075 AC 5 25671 M D 2432 AC 6 18974 Next, the derived values not given to a great deal of precision: Derived Calibration Data c 3-69.8535 x 0 7911 p 0 2.3644 c 4 0.000963 x 1-18.2422 p 1 0.993 c 5 0.0049 x 2 0.0351 p 2 0.00000442 c 6 18974 y 0 31.567 b 1 0.1311 y 1-0.0673 m c -886 y 2 0.000126 m d 15.2 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 c 3, c 4, b 1. 5

Given a hexadecimal temperature reading of 0x69EC and a pressure reading of 0x982FC0, the calculations are as follows: t u = 256 0x69 + 0xEC = 27116 p u = 256 0x98 + 0x2F + 0xC0 256 = 38959.75 T = 23.7764 s = 1.2236 x = 7933.4 y = 31.6495 z = 980.3108 P = 980.0456 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 p u counts per millibar of pressure. In this example, the OSS was 3, so the actual resolution of p u 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 secondorder 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? 974.5 974 973.5 Computed Pressure, mb 973 972.5 972 971.5 971 970.5 20.8 21 21.2 21.4 21.6 21.8 22 22.2 Temperature, degc Figure 2: Comparison of Pressure Computations 7

0.1 0.08 0.06 0.04 Pressure deviation, mb 0.02 0-0.02-0.04-0.06-0.08-0.1 20.8 21 21.2 21.4 21.6 21.8 22 22.2 Temperature, degc Figure 3: Deviation of integer math from straight line. 0.01 0.008 0.006 0.004 Pressure deviation, mb 0.002 0-0.002-0.004-0.006-0.008-0.01 20.8 21 21.2 21.4 21.6 21.8 22 22.2 Temperature, degc Figure 4: Deviation of floating point math from straight line. 8

0.1 0.08 0.06 0.04 Pressure deviation, mb 0.02 0-0.02-0.04-0.06-0.08-0.1 16 17 18 19 20 21 22 Temperature, degc Figure 5: Comparison over a wider temperature range. 9 Changes and Errata The January 30, 2013 version fixes an error in the value of p 2 of the example. The original value was listed as 0.000442 but it should be 0.00000442. 9