Skip to content

Commit aa61da1

Browse files
marknolanclaude
andcommitted
DEV-958: correct the rationale - 0.061 mg/LSB is real, not a rounding
My previous comment claimed ST's accel figures were just 32768/FS rounded to three significant figures, and that the old derived values were therefore the more accurate of the two. That was wrong, and the datasheet settles it. AN5922 Table 27 (FS_XL = +-2 g) gives worked register contents: 1 g reads 0x4009 = 16393 LSB and 350 mg reads 0x1669 = 5737 LSB. 0.061 mg/LSB predicts 16393.4 and 5737.7; a 32768/FS derivation predicts 16384 and 5734.4. The accelerometer does not map its nominal full scale onto exactly 2^15 counts - it has a small margin, the same phenomenon as the gyro, just far smaller. So the old values were wrong by 0.0576%, and this is a correctness fix rather than a consistency trade-off. The constants themselves are unchanged from the previous commit; only the reasoning recorded beside them. Corroborated four ways: the datasheet worked example, ST's upstream driver (STMicroelectronics/lsm6dsv-pid, byte-identical to the copy this firmware vendors), every example in STMems_Standard_C_drivers/lsm6dsv_STdC/examples, and lsm6dsv_self_test.c in particular - its pass/fail limits are specified in mg, so ST's own self-test only produces correct results if 0.122 mg/LSB is right. Comment-only; 51 driver tests still pass. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
1 parent fe367a5 commit aa61da1

1 file changed

Lines changed: 20 additions & 16 deletions

File tree

ShimmerDriver/src/main/java/com/shimmerresearch/verisense/sensors/SensorLSM6DSV.java

Lines changed: 20 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -288,23 +288,27 @@ public static final class DatabaseConfigHandle {
288288
// Accel sensitivity (LSB per m/s^2) from the ST datasheet linear-acceleration
289289
// sensitivity: 0.061 / 0.122 / 0.244 / 0.488 mg/LSB, i.e. 1/(mg_per_LSB/1000)/9.80665.
290290
//
291-
// These were previously derived as 32768/(FS_g*9.80665), which is the exact form:
292-
// unlike the gyro (see below) the accel really does span the full 16-bit range at
293-
// its nominal full scale, so ST's printed figures are just 32768/FS rounded to
294-
// three significant figures (2/32768 g = 0.06103516 mg/LSB -> "0.061"). The exact
295-
// derivation is therefore 0.0576% larger and, on its own terms, slightly more
296-
// accurate.
291+
// These were previously derived as 32768/(FS_g*9.80665), on the assumption that
292+
// the accel spans exactly the full 16-bit range at nominal full scale and that
293+
// ST's printed figures were just that quantity rounded to three significant
294+
// figures. They are not. The datasheet's own worked example (AN5922 Table 27,
295+
// FS_XL = +-2 g) settles it: 1 g reads 0x4009 = 16393 LSB and 350 mg reads
296+
// 0x1669 = 5737 LSB. 0.061 mg/LSB predicts 16393.4 and 5737.7; the 32768/FS
297+
// derivation predicts 16384 and 5734.4. So the sensor really is 0.061 mg/LSB -
298+
// full scale sits a little inside +-2 g - and the old derivation was wrong by
299+
// 0.0576%, not merely a rounding apart from the datasheet.
297300
//
298-
// We use the datasheet figures anyway, for agreement rather than precision. The
299-
// firmware seeds these exact values into the on-device calibration blob
300-
// (SC_ACCEL_SENS in asm_calibration.c), so they are what the device itself
301-
// reports and what becomes the source of truth once per-unit calibration is
302-
// loaded; the web SDK catalog and the gen-1 SensorLSM6DS3/SensorLIS2DW12 classes
303-
// use them too, as does ST's own reference driver (lsm6dsv_from_fs2_to_mg
304-
// multiplies by 0.061f). Keeping the exact form here would leave a 0.0576% step
305-
// change in calibrated output waiting to appear the day the device blob is
306-
// honoured. 0.0576% is far inside per-unit sensitivity variation, so consistency
307-
// is worth more than the last digit.
301+
// Same story as the gyro below, just with a much smaller margin: neither part
302+
// maps its nominal full scale onto exactly 2^15 counts, so for both of them the
303+
// ST mg/LSB and mdps/LSB figures are the authority and a 32768/FS derivation is
304+
// simply incorrect. These values also match the firmware calibration seed
305+
// (SC_ACCEL_SENS in asm_calibration.c), the web SDK catalog, the gen-1
306+
// SensorLSM6DS3/SensorLIS2DW12 classes and ST's own reference driver
307+
// (lsm6dsv_from_fs2_to_mg multiplies by 0.061f). Every example in
308+
// STMems_Standard_C_drivers/lsm6dsv_STdC/examples converts through those
309+
// helpers and none derives 32768/FS - including lsm6dsv_self_test.c, whose
310+
// pass/fail limits are specified in mg, so ST's own self-test only comes out
311+
// right if 0.122 mg/LSB is the true sensitivity.
308312
public static final double[][] SENS_ACCEL_2G = {{1671.665922915,0,0},{0,1671.665922915,0},{0,0,1671.665922915}};
309313
public static final double[][] SENS_ACCEL_4G = {{835.832961457,0,0},{0,835.832961457,0},{0,0,835.832961457}};
310314
public static final double[][] SENS_ACCEL_8G = {{417.916480729,0,0},{0,417.916480729,0},{0,0,417.916480729}};

0 commit comments

Comments
 (0)