Skip to content

Commit 0deb6b3

Browse files
authored
fix(bmp388): correct timestamp_sample to integration midpoint (#26920)
The BMP388 pressure measurement is integrated over a configurable window (e.g. 37ms at 16x oversampling). The previous code used the read time as timestamp_sample, which is the end of the integration window. Correct to the midpoint by subtracting half the measurement time, with a guard against unsigned underflow.
1 parent 0e63f41 commit 0deb6b3

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

src/drivers/barometer/bmp388/bmp388.cpp

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,8 +171,12 @@ BMP388::collect()
171171

172172
perf_begin(_sample_perf);
173173

174-
/* this should be fairly close to the end of the conversion, so the best approximation of the time */
175-
const hrt_abstime timestamp_sample = hrt_absolute_time();
174+
/* Correct for measurement integration delay: the pressure was
175+
* integrated over the preceding measurement_time window, so the
176+
* effective sample midpoint is half the measurement time before now. */
177+
const hrt_abstime now = hrt_absolute_time();
178+
const hrt_abstime half_meas = get_measurement_time() / 2;
179+
const hrt_abstime timestamp_sample = (now > half_meas) ? (now - half_meas) : now;
176180

177181
if (!get_sensor_data(sensor_comp, &data)) {
178182
perf_count(_comms_errors);

0 commit comments

Comments
 (0)