Track My Order
Frequently Asked Questions
International Shipping Info
Mon-Fri, 9am to 12pm and
1pm to 5pm U.S. Mountain Time:
Chat With Us
December 15, 2010
about 8 years ago
I believe that there is a calculation error in this code which gets worse as sensor oversampling increases.
It occurs in the lines where it is setting b3:
if (oversampling_setting == 3) b3 = ((int32_t) ac1 * 4 + x3 + 2) >> 1;
if (oversampling_setting == 2) b3 = ((int32_t) ac1 * 4 + x3 + 2);
if (oversampling_setting == 1) b3 = ((int32_t) ac1 * 4 + x3 + 2) >> 1;
if (oversampling_setting == 0) b3 = ((int32_t) ac1 * 4 + x3 + 2) >> 2;
These lines should be replaced by the datasheet and API formula:
b3 = ((((int32_t)ac1 * 4 + x3) ## oversampling_setting) + 2) >> 2;
where ## is meant to be the shift-left operator (sparkfun strips ‘less-than’ characters out of posts)
With a raw temperature reading of 31908 and a raw pressure reading of 320701 at ultra high resolution, the first code snippet gives me a true pressure of 118662. However, when using the second code snippet (which I believe to be correct) I get 100296 - which is within 1hPa of my local weather station.
No public wish lists :(
Forgot your password?
No account? Register one!