Shop OBEX P1 Docs P2 Docs Learn Events
Need Desparate Help. Altimeter (MS5607) Failing Below 20 — Parallax Forums

Need Desparate Help. Altimeter (MS5607) Failing Below 20

cbf0005cbf0005 Posts: 1
edited 2014-04-12 20:06 in Accessories
Okay, I have an Altimeter (MS5607). The only thing that I need to get going in my code is temperatures below 20 degrees Celsius. Temperatures above or at 20 degrees Celsius, it works fine.

Here is my code:

#include <Wire.h>
#define ADDRESS 0x76 //0x77
#include "IntersemaBaro.h"
Intersema::BaroPressure_MS5607B baro(true);
uint32_t D1 = 0;
uint32_t D2 = 0;
int64_t dT = 0;
int32_t TEMP = 0;
int64_t OFF = 0;
int64_t SENS = 0;
int32_t P = 0;

uint16_t C[1];
//uint16_t C[2];
//uint16_t C[3];
//uint16_t C[4];
//uint16_t C[5];
//uint16_t C[6];
//uint16_t C[7];




float Temperature;
float Pressure;


void setup() {

baro.init();
// Disable internal pullups, 10Kohms are on the breakout
PORTC |= (1 << 4);

Wire.begin();
Serial.begin(9600); //9600 changed 'cos of timing?
delay(100);
initial(ADDRESS);

}

void loop()
{

int32_t T2; //Unsigned int 32 bit for T2 (used for solving below 20 Celsius)
int64_t OFF2; //Unsigned int 64 bit for OFF2 (used for solving below 20 Celsius)
int64_t SENS2; //Unsigned int 64 bit for SENS2 (used for solving below 20 Celsius)

D2 = getVal(ADDRESS, 0x58);// raw temperature value

//dT and Temp will calculate temperature
dT = D2 - ((uint32_t)C[5] *(2*2*2*2*2*2*2*2));

//off and sens will calculate temperature compensated pressure
OFF = ( (int64_t)C[2]*131072 ) + ( (dT * C[4]) / (64));
SENS = ( (int64_t)C[1]*65536 ) + ( (dT * C[3]) / (128));
TEMP = 2000 + (dT * (int32_t)C[6] / (8388608) ); //base temperature formula

while(TEMP <2000) // FOR WHEN THE TEMPERATURE IS BELOW 20 CELSIUS
{

Serial.print("Made pass through low temp\n");
T2=(-(dT*dT)/(2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2*2));
OFF2= -(61)*((TEMP-2000)*(TEMP-2000))/(16);
SENS2 = 2*(TEMP-2000)*(TEMP-2000);
break;
}

while(TEMP>2000) //FOR WHEN THE TEMPERATURE IS ABOVE 20 CELSIUS
{

T2=0;
OFF2=0;
SENS2 =0;
break;
}

TEMP = TEMP - T2;
OFF = OFF - OFF2;
SENS = SENS - SENS2;

Serial.print(" Actual TEMP= ");
Serial.print(TEMP);
Serial.print("Temp two");
Serial.print(T2);
Serial.println();
delay(1000);

}



long getVal(int address, byte code)
{
unsigned long ret = 0;
Wire.beginTransmission(address);
Wire.write(code);
Wire.endTransmission();
delay(10);
// start read sequence
Wire.beginTransmission(address);
Wire.write((byte) 0x00);
Wire.endTransmission();
Wire.beginTransmission(address);
Wire.requestFrom(address, (int)3);
if (Wire.available() >= 3)
{
ret = Wire.read() * (unsigned long)65536 + Wire.read() * (unsigned long)256 + Wire.read();
}
else {
ret = -1;
}
Wire.endTransmission();
return ret;
}

void initial(uint8_t address)
{

Serial.println();
Serial.println("PROM COEFFICIENTS ivan");

Wire.beginTransmission(address);
Wire.write(0x1E); // reset
Wire.endTransmission();
delay(10);


for (int i=0; i<6 ; i++) {

Wire.beginTransmission(address);
Wire.write(0xA2 + (i * 2));
Wire.endTransmission();

Wire.beginTransmission(address);
Wire.requestFrom(address, (uint8_t) 6);
delay(1);
if(Wire.available())
{
C[i+1] = Wire.read() << 8 | Wire.read();
}
else {
Serial.println("Error reading PROM 1"); // error reading the PROM or communicating with the device
}
Serial.println(C[i+1]);
}
Serial.println();
}

Variable TEMP is fine until it reaches below 20 Celsius. It then produces an insanely large number. If anyone could help me get this running, I would be unspeakably appreciative.

Attached to this link is the data sheet. You will see that my code follows the variables from the data sheet almost to the tee. Did this for easaibility of reading the code ..
http://www.farnell.com/datasheets/1756127.pdf

Comments

  • FranklinFranklin Posts: 4,747
    edited 2014-04-12 20:06
    It would help if you wrapped your code in [code] tags rather than
    tags.
Sign In or Register to comment.