Offline
God Member
Karma: 10
Posts: 871
|
 |
« on: March 21, 2012, 03:11:26 am » |
straight from this component out of a PDF .... http://www.bosch-sensortec.com/content/language1/downloads/BMP085_DataSheet_Rev.1.0_01July2008.pdf now here's the code I have in Arduino's IDE. void bmp085_read_temperature_and_pressure(int* temperature, long* pressure, long* alti) { long tmp; long x1, x2, x3, b3, b5, b6, p, b7; unsigned long b4; long t; //calculate the temperature
long up = bmp085_read_up(); long ut= bmp085_read_ut(); x1 = ((long)ut - ac6) * ac5 >> 15; x2 = ((long) mc << 11) / (x1 + md); b5 = x1 + x2; t =((b5 + 8) )>> 4; *temperature = t;
Either the sensor is faulty or the code is, but I don't see a Divide by 2 like it requires in the arduino just a bit shift operator >>
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19066
I don't think you connected the grounds, Dave.
|
 |
« Reply #1 on: March 21, 2012, 03:17:36 am » |
but I don't see a Divide by 2 like it requires in the arduino just a bit shift operator >> Shift right by one place is a divide by two.
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Global Moderator
Melbourne, Australia
Offline
Shannon Member
Karma: 218
Posts: 13897
Lua rocks!
|
 |
« Reply #2 on: March 21, 2012, 03:18:56 am » |
2^4 is 16.
x >> 4 is effectively a divide by 16.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
God Member
Karma: 10
Posts: 871
|
 |
« Reply #3 on: March 21, 2012, 03:19:25 am » |
x1 = ((long)ut - ac6) * ac5 >> 15; >>15 is not divide by 15 though
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19066
I don't think you connected the grounds, Dave.
|
 |
« Reply #4 on: March 21, 2012, 03:20:31 am » |
>>15 is not divide by 15 though Who said it was? x1 = (UT - AC6) * AC5 / 2 15
|
|
|
|
« Last Edit: March 21, 2012, 03:22:49 am by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
God Member
Karma: 10
Posts: 871
|
 |
« Reply #5 on: March 21, 2012, 03:28:35 am » |
I'm just trying to translate that 2(15) value my math is crap >> bit shit / = divide 3^3 = 3*3*3 (power of?) so would that not mean x1 = (long)ut - ac6) * ac5/215; (from PDF from bosh) becomes x1 = ((((long)ut - ac6) * ac5/2)^15; ?? really am clueless here lol
sorry my newb status with Arduino and C is really not helping... i'm trying to convert this line (x1=......) to something Arduino will compile so i can use it to correct my other code... thanks, unless the example i posted is actually correct in which case i may have to return this sensor as it's not giving a correct reading.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19066
I don't think you connected the grounds, Dave.
|
 |
« Reply #6 on: March 21, 2012, 03:33:36 am » |
"x >> 1" divides x by 2, so it follows that "x >> 2" divides x by four, and "x >> 3" divides x by eight. Now, 2 = 21, 4 = 22 and 8 = 23. You could write "x >> 3" as " ((x >> 1) >> 1) >> 1", with each successive operator halving thing previous result Can you see where this is going?
(This isn't an "Arduino" operator, it's a C/C++ operator)
|
|
|
|
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
God Member
Karma: 10
Posts: 871
|
 |
« Reply #7 on: March 21, 2012, 03:36:55 am » |
cool i get it... but i don't need to use >> so what is the operator? ^ or pow?
|
|
|
|
|
Logged
|
|
|
|
|
Gosport, UK
Offline
Faraday Member
Karma: 19
Posts: 3118
|
 |
« Reply #8 on: March 21, 2012, 03:41:49 am » |
Why don't you need to use >>?
|
|
|
|
|
Logged
|
|
|
|
|
Manchester (England England)
Offline
Brattain Member
Karma: 277
Posts: 25501
Solder is electric glue
|
 |
« Reply #9 on: March 21, 2012, 03:55:03 am » |
^ or pow? ^ is a bitwise exclusive OR opperation pow( ) is for taking the power of a number.
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19066
I don't think you connected the grounds, Dave.
|
 |
« Reply #10 on: March 21, 2012, 04:04:01 am » |
but i don't need to use >> so what is the operator I don't understand you. You can divide by 32768L, or you can shift right fifteen places - the result will be the same.
|
|
|
|
« Last Edit: March 21, 2012, 04:07:25 am by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
Offline
God Member
Karma: 10
Posts: 871
|
 |
« Reply #11 on: March 21, 2012, 04:06:24 am » |
ok ok, just take this code here long up = bmp085_read_up(); long ut= bmp085_read_ut(); x1 = ((long)ut - ac6) * ac5 >> 15; *temperature = x1; //my code outputs 6157 x2 = ((long) mc << 11) / (x1 + md); b5 = x1 + x2; t =((b5 + 8) )>> 4; // *temperature = p;
6157, is what i get, but the PDF says 4743 So which is it, the code or the sensor?
|
|
|
|
|
Logged
|
|
|
|
|
Global Moderator
UK
Offline
Brattain Member
Karma: 138
Posts: 19066
I don't think you connected the grounds, Dave.
|
 |
« Reply #12 on: March 21, 2012, 04:10:05 am » |
Perhaps it is a bit warmer where you are. What are your values of ac5, ac6 and ut? Here's the example code with the values from the example (uncompiled, untested) void setup () { Serial.begin (9600); unsigned int ac5 = 32757; // these numbers all from the example unsigned int ac6 = 23153; // these numbers all from the example int mc = -8711; // these numbers all from the example int md = 2868; // these numbers all from the example long ut= 27898; // these numbers all from the example - you will read this from the device.
long x1 = ((long)ut - ac6) * ac5 >> 15; long x2 = ((long) mc << 11) / (x1 + md); long b5 = x1 + x2; long t =((b5 + 8) )>> 4; Serial.print ("x1 "); Serial.println (x1); Serial.print ("t "); Serial.println (t); }
void loop () {}
|
|
|
|
« Last Edit: March 21, 2012, 04:40:49 am by AWOL »
|
Logged
|
Pete, it's a fool looks for logic in the chambers of the human heart.
|
|
|
|
|