Skip to content

Question about AIS2IH PID acceleration raw data alignment and mg conversion #1

Description

@CoreMaker-lab

Hi ST Team,
I am currently evaluating AIS2IH with STM32C542CCT6 and STM32CubeMX2 / HAL2. I am using the ST official platform-independent driver from GitHub:
STMicroelectronics/ais2ih-pid
According to the repository README, this driver is a platform-independent C driver, and the user only needs to provide the platform-specific I2C/SPI read and write functions.
The I2C communication works correctly in my test. I can read the WHO_AM_I register successfully, and the returned value matches AIS2IH_ID = 0x44.
My configuration is as follows:
ais2ih_block_data_update_set(&dev_ctx, PROPERTY_ENABLE);
ais2ih_full_scale_set(&dev_ctx, AIS2IH_2g);
ais2ih_filter_path_set(&dev_ctx, AIS2IH_LPF_ON_OUT);
ais2ih_filter_bandwidth_set(&dev_ctx, AIS2IH_ODR_DIV_4);
ais2ih_power_mode_set(&dev_ctx, AIS2IH_HIGH_PERFORMANCE);
ais2ih_data_rate_set(&dev_ctx, AIS2IH_XL_ODR_25Hz);
Then I read the acceleration raw data and convert it to mg:
ais2ih_acceleration_raw_get(&dev_ctx, data_raw_acceleration);

acceleration_mg[0] = ais2ih_from_fs2_to_mg(data_raw_acceleration[0]);
acceleration_mg[1] = ais2ih_from_fs2_to_mg(data_raw_acceleration[1]);
acceleration_mg[2] = ais2ih_from_fs2_to_mg(data_raw_acceleration[2]);
However, the output values are about 4 times larger than expected.
For example, when the board is placed flat:
Acceleration [mg]: -482.14    92.72    3956.70
When the board is flipped over:
Acceleration [mg]: 152.26    -4.88    -4001.60
Since the board is static, one axis should be close to ±1000 mg. The AIS2IH datasheet also mentions that, on a horizontal surface, X and Y should measure around 0 g while Z should measure around 1 g.
From the datasheet, the nominal sensitivity for FS ±2 g in High-Performance mode is 0.244 mg/digit. The driver conversion function also uses this coefficient:
float_t ais2ih_from_fs2_to_mg(int16_t lsb)
{
 return ((float_t)lsb) * 0.244f;
}
But according to the datasheet, the acceleration output registers appear to be left-aligned. For example, OUT_X_L / OUT_Y_L / OUT_Z_L show bit1 and bit0 as fixed 0, while OUT_X_H / OUT_Y_H / OUT_Z_H contain the most significant bits.
After I modified the conversion functions by shifting the raw value before applying the sensitivity coefficient, the results became correct:
float_t ais2ih_from_fs2_to_mg(int16_t lsb)
{
 return ((float_t)(lsb >> 2)) * 0.244f;
}

float_t ais2ih_from_fs4_to_mg(int16_t lsb)
{
 return ((float_t)(lsb >> 2)) * 0.488f;
}

float_t ais2ih_from_fs8_to_mg(int16_t lsb)
{
 return ((float_t)(lsb >> 2)) * 0.976f;
}

float_t ais2ih_from_fs16_to_mg(int16_t lsb)
{
 return ((float_t)(lsb >> 2)) * 1.952f;
}
For Low-Power Mode 1, I also adjusted the conversion functions with a 4-bit shift:
float_t ais2ih_from_fs2_lp1_to_mg(int16_t lsb)
{
 return ((float_t)(lsb >> 4)) * 0.976f;
}

Image

After this modification, the Z-axis output is close to +1000 mg when the board is placed flat, and close to -1000 mg when it is flipped over.
Could you please help confirm the following points?

For AIS2IH High-Performance / 14-bit mode, should the raw acceleration data be shifted right by 2 bits before applying the mg/digit sensitivity?

For Low-Power Mode 1 / 12-bit mode, should the raw acceleration data be shifted right by 4 bits before conversion?

Is the current ais2ih_from_fs*_to_mg() implementation in the PID driver intended to receive already right-aligned raw data, or should the conversion function handle the alignment internally?

Thank you for your support.

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Fields

No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions