FlexCase

IMU and Accelerometer Guide

  • Read data from on-board 3-axis accelerometer, 3-axis gyroscope, and IMU temperature
  • Configure sample time and resolution
  • Customize for your application

Prerequisites

This is a more advanced guide intented for users integrating accelerometer data into an existing application. Please complete the following prerequisites to have the best experience with this guide:

  • Complete the Quick-Start guide for a tutorial on connecting and flashing binaries
  • Complete the Simulink guide for building a model into a flashable binary
  • Complete the FreeMASTER guide for viewing MCU variables

Simulink Model

  1. Locate IMU_Accel.slx in the Simulink samples and open it. The main code area should look like the following picture.
  2. Based on your FlexCase version (1.2+ for full IMU or 1.1 for Accelerometer only), comment out the appropriate subsystems.
  3. Build the model and flash it to the FlexCase.

The IMU/Accelerometer communicates with the MCU over SPI. The first byte of the SPI message contains the relevant register address, the second byte contains commands or motion data, and any subsequent bytes contain additional motion data. For the IMU, two power-up commands are sent for the Accelerometer and Gyroscope.

FreeMASTER

If this is your first time using FreeMASTER, please see our guide on FreeMASTER basics before proceeding.

  1. Add the compiled .elf file to the FreeMASTER configuration as the symbol file
  2. Set up and establish a connection to the FlexCase
  3. Add data variables Ax, Ay, Az to the watch and to the oscilloscope
  4. If using an IMU, also add Wx, Wy, Wz, T_imu to the watch/oscilloscope
  5. Start the measurement
  6. Tilt the FlexCase to see the acceleration and rotational rate values change

If sitting on a flat surface, the FlexCase should read approximately +1G (9.81 m/s^2) in the Z direction. The start up sequence of the model sends a default sample rate and value range to the sensor before starting to poll inertial data.

Additional Information

When sending “read” commands to the accelerometer, the first bit of the address must be set to 1. For example, the Z-axis MSB address 0x2D must be changed to 0xAD to read the data.

When using “write” commands, the first bit should be set to 0. For example, when changing the update rate the addresses will remain unchanged. For example, send CTRL1_XL write with 0x10 to turn on the Accelerometer. The register mappings are different between the older and newer FlexCase versions. For example, the Accelerometer control register on the full IMU has the following format:

And the 3-axis unit uses the following format:

The IMU/Accelerometer is highly configurable. Using similar control commands, other features can be configured such as:

  • Configure hardware filters
  • Change the acceleration/rotational speed limits
  • Configure capture mode
  • Detect acceleration events (orientation change, free-fall, wake-up)
  • Generate hardware interrupts

Please review IMU (1.2+) or the Accelerometer (1.1) datasheet for a full list of features and contact us if you have additional integration questions.

If using the older Accelerometer-only models (FlexCase S or FlexBench 1.1), the model is set up to change the reading mode live. This method is outdated but may be useful for certain applications.

In FreeMASTER, you can add other variables AccCmd, transferAct, commandAct to the watch and ensure they are modifiable. AccCmd must be configured as HEX so addresses are compatible with the sensor datasheets

If sitting on a flat surface, the FlexCase should read approximately +1G (9.81 m/s^2) in the Z direction The AccCmd variable will be set to 0xa800, the lowest address of the acceleration components. The initial value of AccCmd is 0x2010 to power up the sensor.

The default behaviour of this model is to power up the accelerometer at an update rate of 1.6Hz, and at 12bit resolution. A power mode command is sent during the first MCU time step, followed by cycling through the acceleration registers.

To change the update rate and resolution, the initial value of AccCmd can be adjusted to correspond to a different configuration of the accelerometer’s CTRL1 register:

For this guide, the default value of the power-up command AccCmd is 0x2010 (address 0x20, ODR 1, OP_MODE 0, PW_MODE 0) You can open the Data Store Memory block for AccCmd to see the initial value is set to 8208 (0x2010 in decimal).

To manually change the update rate to 50Hz at 14bit resolution:

  • Start the FreeMASTER measurement
  • (Optional) Set the transferAct variable to 0 using the variable watch. This temporarily halts SPI communication to the accelerometer. Halting communication is not necessary in this guide, but it will avoid sending unintended commands when using more advanced configurations.
  • Set the commandAct variable to 1 to stop polling acceleration and accept changes to the command address.
  • Set AccCmd to 0x2043 (make sure the variable is configured in HEX).

  • Set transferAct back to 1
  • Set commandAct back to 0 to resume updating acceleration components

The above method can be used to set different power modes, or send other configuration commands to the accelerometer. The image below is an example of the data gathered by rotating the FlexCase.

The accelerometer power mode is automatically set at startup through the AccCmd initial value. You can set the AccCmd initial value and re-flash the model to have the accelerometer start in that mode. In the image below shows setting the AccCmd value to 8259 (decimal for 0x2043) to have the accelerometer start in the 50Hz, 14bit mode.

The value of 0x2043 corresponds to the following settings for ODR, OP_MODE, and PW_MODE: