fix(iis2mdc): data-ready flag, sensitivity, and sample rate (#28016)

* fix(iis2mdc): wait for the Zyxda flag before reading data

STATUS_REG bit 3 (Zyxda) signals that X, Y and Z all have new data. The
ready mask also covered bits 0-2, the individual per-axis flags, so a sample
could be taken when only one axis had refreshed.

* fix(iis2mdc): correct sensitivity to 1.5 mGauss/LSB

The datasheet specifies 1.5 mGauss/LSB. The previous 100/65535 assumed the
+/-50 Gauss range maps exactly onto the 16-bit output and reads about 1.7%
high.

* fix(iis2mdc): poll on a fixed interval for a steady sample rate

RunImpl rescheduled with ScheduleDelayed(10ms) after reading the sensor, so
the period was 10 ms plus the read time and the effective rate fell below the
100 Hz ODR, dropping samples. Drive it from ScheduleOnInterval(10ms) instead
so the period is independent of the read time. A not-ready poll is now
expected occasionally rather than a fault, so it no longer counts as a comms
error.
This commit is contained in:
Jacob Dahl
2026-07-23 20:28:28 -06:00
committed by GitHub
parent c90fee80b2
commit 9bb0d365c4
2 changed files with 6 additions and 6 deletions

View File

@@ -64,9 +64,11 @@ int IIS2MDC::init()
write_register(IIS2MDC_ADDR_CFG_REG_B, OFF_CANC);
write_register(IIS2MDC_ADDR_CFG_REG_C, BDU);
_px4_mag.set_scale(100.f / 65535.f); // +/- 50 Gauss, 16bit
_px4_mag.set_scale(0.0015f); // 1.5 mGauss/LSB (datasheet)
ScheduleDelayed(20_ms);
// Poll at the 100 Hz ODR on a fixed interval so the rate does not drift with
// the time spent reading the sensor.
ScheduleOnInterval(10_ms);
return PX4_OK;
}
@@ -95,11 +97,9 @@ void IIS2MDC::RunImpl()
}
} else {
// No new sample yet; expected occasionally when polling at the data rate.
PX4_DEBUG("not ready: %u", status);
perf_count(_comms_errors);
}
ScheduleDelayed(10_ms);
}
uint8_t IIS2MDC::read_register_block(SensorData *data)

View File

@@ -46,7 +46,7 @@
// IIS2MDC Definitions
#define IIS2MDC_WHO_AM_I 0b01000000
#define IIS2MDC_STATUS_REG_READY 0b00001111
#define IIS2MDC_STATUS_REG_READY 0b00001000 // Zyxda: X, Y and Z all have new data
// CFG_REG_A
#define COMP_TEMP_EN (1 << 7)
#define MD_CONTINUOUS (0 << 0)