Um2182 Getting Started With Motionac Accelerometer Calibration Library in Xcubemems1 Expansion For Stm32cube Stmicroelectronics
Um2182 Getting Started With Motionac Accelerometer Calibration Library in Xcubemems1 Expansion For Stm32cube Stmicroelectronics
User manual
Introduction
The MotionAC is a middleware library part of X-CUBE-MEMS1 software and runs on STM32. It provides real-time
accelerometer calibration through offset and scale factor coefficients used to correct accelerometer data.
This library is intended to work with ST MEMS only.
The algorithm is provided in static library format and is designed to be used on STM32 microcontrollers based on the ARM®
Cortex®-M3, ARM® Cortex®-M33, ARM® Cortex®-M4 or ARM® Cortex®-M7 architecture.
It is built on top of STM32Cube software technology that ease portability across different STM32 microcontrollers.
The software comes with sample implementation running on an X-NUCLEO-IKS01A3, X-NUCLEO-IKS4A1 or X-NUCLEO-
IKS02A1 expansion board on a NUCLEO-F401RE, NUCLEO-L152RE or NUCLEO-U575ZI-Q development board.
Acronym Description
Start
GetLibVersion
Initialize
Update
GetCalParams
Apply Correction
#define VERSION_STR_LENG 35
#define REPORT_INTERVAL 20
[…]
[…]
/* Apply correction */
acc_cal_x = (data_in.Acc[0] - data_out.AccBias[0])* data_out.SF_Matrix[0][0];
acc_cal_y = (data_in.Acc[1] - data_out.AccBias[1])* data_out.SF_Matrix[1][1];
acc_cal_z = (data_in.Acc[2] - data_out.AccBias[2])* data_out.SF_Matrix[2][2];
}
Step 3. Rotate the device by 180° in a clockwise fashion around the XZ plane to reach position 1.
Important: Try to rotate the device along a smooth path and at a constant speed.
You can also perform standard six point calibration, holding the module stationary in six different
directions (positive and negative X,Y and Z directions).
3 Sample application
The MotionAC middleware can be easily manipulated to build user applications; a sample application is provided
in the Application folder.
It is designed to run on a NUCLEO-F401RE, NUCLEO-L152RE or NUCLEO-U575ZI-Q development board
connected to an X-NUCLEO-IKS01A3, X-NUCLEO-IKS4A1 or X-NUCLEO-IKS02A1 expansion board.
Figure 3. Sensor expansion board and adapter connected to the STM32 Nucleo
Accelerometer algorithm output data may be displayed in real-time through a specific GUI.
Step 2. Launch the MEMS-Studio application to open the main application window.
If an STM32 Nucleo board with supported firmware is connected to the PC, it is automatically detected
the appropriate COM port. Press Connect button to open this port.
Step 3. When connected to STM32 Nucleo board with supported firmware Library Evaluation tab is opened.
Step 4. Select the Accelerometer Calibration tab on the inner vertical tool bar to open the dedicated application
status view.
The window is split into one section with uncalibrated data, another with the calibrated data, another
section with offset, scale factor and quality of calibration information and the last section with radio
button to switch the desired calibration mode
Step 5. Select the Save to File tab on the inner vertical tool bar to open the data logging configuration window.
Select which sensor and activity data to save to log file. You can start or stop saving by clicking on the
corresponding Start / Stop button.
4 References
Revision history
Table 4. Document revision history
Contents
1 Acronyms and abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
2 MotionAC middleware library in X-CUBE-MEMS1 software expansion . . . . . . . . . . . . . . 3
2.1 MotionAC overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2 MotionAC library . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.1 MotionAC library description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.2 MotionAC APIs . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3
2.2.3 Storing and loading calibration parameters . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
2.2.4 API flow chart . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.5 Demo code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
2.2.6 Calibration process . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6
2.2.7 Algorithm performance . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
3 Sample application . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
3.1 MEMS Studio. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
4 References . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .11
Revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .12
List of tables
Table 1. List of acronyms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2
Table 2. Cortex-M4 and Cortex-M3: elapsed time (µs) algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 3. Cortex-M7: elapsed time (µs) algorithm. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Table 4. Document revision history . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
List of figures
Figure 1. MotionAC API logic sequence . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5
Figure 2. Calibration movement . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7
Figure 3. Sensor expansion board and adapter connected to the STM32 Nucleo . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8
Figure 4. MEMS-Studio - Connect . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 5. MEMS-Studio - Library Evaluation - Data Table. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9
Figure 6. MEMS-Studio - Library Evaluation - Accelerometer Calibration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
Figure 7. MEMS-Studio - Library Evaluation - Save to File . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10