diff --git a/src/drivers/barometer/ms5611/MS5611.hpp b/src/drivers/barometer/ms5611/MS5611.hpp index 6f297e86b4..ff360b795f 100644 --- a/src/drivers/barometer/ms5611/MS5611.hpp +++ b/src/drivers/barometer/ms5611/MS5611.hpp @@ -83,6 +83,7 @@ enum MS56XX_DEVICE_TYPES { * conversion finished */ #define MS5611_CONVERSION_INTERVAL 10000 /* microseconds */ +#define MS5611_OSR1024_CONVERSION_TIME 2280 /* max ADC conversion time at OSR 1024, microseconds */ #define MS5611_MEASUREMENT_RATIO 3 /* pressure measurements per temperature measurement */ class MS5611 : public I2CSPIDriver diff --git a/src/drivers/barometer/ms5611/ms5611.cpp b/src/drivers/barometer/ms5611/ms5611.cpp index 871316a0fd..d925a30af8 100644 --- a/src/drivers/barometer/ms5611/ms5611.cpp +++ b/src/drivers/barometer/ms5611/ms5611.cpp @@ -243,8 +243,13 @@ MS5611::collect() perf_begin(_sample_perf); - /* read the most recent measurement - read offset/size are hardcoded in the interface */ - const hrt_abstime timestamp_sample = hrt_absolute_time(); + /* Correct for measurement integration delay: the conversion was + * started CONVERSION_INTERVAL ago and took OSR1024_CONVERSION_TIME + * to integrate, so the effective sample midpoint is + * (CONVERSION_INTERVAL - OSR1024_CONVERSION_TIME/2) before now. */ + const hrt_abstime now = hrt_absolute_time(); + static constexpr hrt_abstime correction = MS5611_CONVERSION_INTERVAL - MS5611_OSR1024_CONVERSION_TIME / 2; + const hrt_abstime timestamp_sample = (now > correction) ? (now - correction) : now; int ret = _interface->read(0, (void *)&raw, 0); if (ret < 0) {