mirror of
https://git.intern.spaceteamaachen.de/ALPAKA/driver-ms56xx.git
synced 2025-06-11 02:26:00 +00:00
Changes to make use of previous temperature measurements
This commit is contained in:
parent
e96fae6f97
commit
7505f04558
@ -119,9 +119,10 @@ namespace sta
|
|||||||
* @brief Reads the current pressure value from the sensor. Obtains the temperature value from the interal sensor.
|
* @brief Reads the current pressure value from the sensor. Obtains the temperature value from the interal sensor.
|
||||||
*
|
*
|
||||||
* @param unit Specifies the unit for the pressure measurement. Default is hPa.
|
* @param unit Specifies the unit for the pressure measurement. Default is hPa.
|
||||||
|
* @param cachedTemp Specifies if a cached temperature value should be used.
|
||||||
* @return int32_t The measured value in the specified unit.
|
* @return int32_t The measured value in the specified unit.
|
||||||
*/
|
*/
|
||||||
float getPressure(Unit unit = Unit::hPa);
|
float getPressure(Unit unit = Unit::hPa, bool cachedTemp = false);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Reads the current temperature value from the sensor.
|
* @brief Reads the current temperature value from the sensor.
|
||||||
@ -129,7 +130,7 @@ namespace sta
|
|||||||
* @return int32_t The measured temperature.
|
* @return int32_t The measured temperature.
|
||||||
* @note There are better sensors for temperature measurements than the MS56xx.
|
* @note There are better sensors for temperature measurements than the MS56xx.
|
||||||
*/
|
*/
|
||||||
int32_t getTemperature();
|
float getTemperature();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Provide a reference pressure value at a reference altitude in order to estimate the sealevel pressure.
|
* @brief Provide a reference pressure value at a reference altitude in order to estimate the sealevel pressure.
|
||||||
@ -216,6 +217,8 @@ namespace sta
|
|||||||
OsrLevel osr_;
|
OsrLevel osr_;
|
||||||
Intf intf_;
|
Intf intf_;
|
||||||
|
|
||||||
|
float dT_;
|
||||||
|
|
||||||
// Pressure at sealevel. Use the standard atmosphere per default.
|
// Pressure at sealevel. Use the standard atmosphere per default.
|
||||||
float sealevel_ = 1013.25;
|
float sealevel_ = 1013.25;
|
||||||
|
|
||||||
@ -227,4 +230,4 @@ namespace sta
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // ifndef STA_SENSORS_MS5607_HPP
|
#endif // ifndef STA_SENSORS_MS5607_HPP
|
||||||
|
@ -53,7 +53,7 @@ namespace sta
|
|||||||
delay_(MS56xx::RESET_DELAY);
|
delay_(MS56xx::RESET_DELAY);
|
||||||
}
|
}
|
||||||
|
|
||||||
float MS56xx::getPressure(Unit unit /* = Unit::hPa */)
|
float MS56xx::getPressure(Unit unit /* = Unit::hPa */, bool cachedTemp /* = false */)
|
||||||
{
|
{
|
||||||
// Request the ADC to read pressure values.
|
// Request the ADC to read pressure values.
|
||||||
busCommand(MS56xx::Operations::D1_CONVERSION + 2*this->osr_);
|
busCommand(MS56xx::Operations::D1_CONVERSION + 2*this->osr_);
|
||||||
@ -66,39 +66,23 @@ namespace sta
|
|||||||
|
|
||||||
uint32_t D1 = 0x00 | buffer[0] << 16 | buffer[1] << 8 | buffer[2];
|
uint32_t D1 = 0x00 | buffer[0] << 16 | buffer[1] << 8 | buffer[2];
|
||||||
|
|
||||||
// Request the ADC to read temperature values.
|
if (!cachedTemp)
|
||||||
busCommand(MS56xx::Operations::D2_CONVERSION + 2*this->osr_);
|
|
||||||
|
|
||||||
// 8.22 ms conversion according to the datasheet.
|
|
||||||
delay_(osrDelay());
|
|
||||||
|
|
||||||
busRead(MS56xx::Operations::ADC_RESULT, buffer, 3);
|
|
||||||
|
|
||||||
uint32_t D2 = buffer[0] << 16 | buffer[1] << 8 | buffer[2];
|
|
||||||
|
|
||||||
float dT = D2 - C_[5];
|
|
||||||
float offset = C_[2] + dT * C_[4];
|
|
||||||
float sens = C_[1] + dT * C_[3];
|
|
||||||
|
|
||||||
/*
|
|
||||||
if (temperature < 2000)
|
|
||||||
{
|
{
|
||||||
float T2 = dT * dT * 4.6566128731E-10;
|
// Request the ADC to read temperature values.
|
||||||
float t = (temperature - 2000) * (temperature - 2000);
|
busCommand(MS56xx::Operations::D2_CONVERSION + 2*this->osr_);
|
||||||
float offset2 = 2.5 * t;
|
|
||||||
float sens2 = 1.25 * t;
|
// 8.22 ms conversion according to the datasheet.
|
||||||
// COMMENT OUT < -1500 CORRECTION IF NOT NEEDED
|
delay_(osrDelay());
|
||||||
if (temperature < -1500)
|
|
||||||
{
|
busRead(MS56xx::Operations::ADC_RESULT, buffer, 3);
|
||||||
t = (temperature + 1500) * (temperature + 1500);
|
|
||||||
offset2 += 7 * t;
|
uint32_t D2 = buffer[0] << 16 | buffer[1] << 8 | buffer[2];
|
||||||
sens2 += 5.5 * t;
|
|
||||||
}
|
dT_ = D2 - C_[5];
|
||||||
temperature -= T2;
|
|
||||||
offset -= offset2;
|
|
||||||
sens -= sens2;
|
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
|
float offset = C_[2] + dT_ * C_[4];
|
||||||
|
float sens = C_[1] + dT_ * C_[3];
|
||||||
|
|
||||||
// The pressure in Pa.
|
// The pressure in Pa.
|
||||||
float pressure = (D1 * sens * 4.76837158205E-7 - offset) * 3.051757813E-5;
|
float pressure = (D1 * sens * 4.76837158205E-7 - offset) * 3.051757813E-5;
|
||||||
@ -107,7 +91,7 @@ namespace sta
|
|||||||
return pressure * 0.01;
|
return pressure * 0.01;
|
||||||
}
|
}
|
||||||
|
|
||||||
int32_t MS56xx::getTemperature()
|
float MS56xx::getTemperature()
|
||||||
{
|
{
|
||||||
// Request the ADC to read temperature values.
|
// Request the ADC to read temperature values.
|
||||||
busCommand(MS56xx::Operations::D2_CONVERSION + 2*this->osr_);
|
busCommand(MS56xx::Operations::D2_CONVERSION + 2*this->osr_);
|
||||||
@ -120,8 +104,8 @@ namespace sta
|
|||||||
|
|
||||||
uint32_t D2 = buffer[0] << 16 | buffer[1] << 8 | buffer[2];
|
uint32_t D2 = buffer[0] << 16 | buffer[1] << 8 | buffer[2];
|
||||||
|
|
||||||
float dT = D2 - C_[5];
|
dT_ = D2 - C_[5];
|
||||||
float temperature = 2000 + dT * C_[6];
|
float temperature = 2000 + dT_ * C_[6];
|
||||||
|
|
||||||
return temperature * 0.01;
|
return temperature * 0.01;
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user