Пример #1
0
/**
 * Read the pressure and temperature.
 * This method use the second order temperature
 * compensation algorithm described in the datasheet.
 * @param pressure Pressure pointer.
 * @param temperature Temperature pointer.
 * @param osr Oversample rate. Optional.
 * @return Status of operation (true = success)
 */
bool MS561101BA::read(int32_t * pressure, int32_t * temperature)
{

    int32_t d1 = readD1(defaultOsr); //pressure
    int32_t d2 = readD2(defaultOsr); //temperature
    return( TemperatureCompensation(pressure,temperature, d1, d2) );
}
Пример #2
0
/**
 * Read the pressure and temperature.
 * This method use the second order temperature
 * compensation algorithm described in the datasheet.
 * @param pressure Pressure pointer. hPa
 * @param temperature Temperature pointer. ºC
 * @param osr Oversample rate. Optional.
 * @return Status of operation (true = success)
 */
bool MS561101BA::readValues(
		float * pressure,
		float * temperature,
		int8_t osr) {

	// Read the sensors
	int32_t d1 = readD1(osr);
	int32_t d2 = readD2(osr);

	// Check for errors
	if (d1 < 0 || d2 < 0) return false;

	int32_t dT = d2 - (((uint32_t) getTREF()) << 8);
	double t = 2000.0 + ((int64_t) dT) * getTEMPSENS() / POW_2_23;

	int64_t off  = (((int64_t) getOFFT1())  << 16) +
			((int64_t) dT) * getTCO() / POW_2_7;
	int64_t sens = (((int64_t) getSENST1()) << 15) +
			((int64_t) dT) * getTCS() / POW_2_8;

	// Second order temperature compensation
	if (t < 2000) {
		double square = pow (dT,2);
		double t2 = square / POW_2_31;
		square = pow (t-2000,2);
		double off2  = square * 5 / 2;
		double sens2 = square * 5 / 4;
		if (t < 15) {
			square = pow(t+1500,2);
			off2  += square * 7;
			sens2 += square * 11 / 2;
		}

		t    -= t2;
		off  -= off2;
		sens -= sens2;

	}

	double p = ((sens * d1 / POW_2_21) - off) / POW_2_15;

	*temperature = float(t/100);
	*pressure    = float(p/100);

	return true;

}