Main Content

Triple-Axis Tilt Calculation Using LIS3DH FIFO Data Ready Interrupt

This example shows how to use the FIFO data ready interrupt of LIS3DH linear accelerometer connected to an TI's™ C2000-based hardware to sense the tilt of the sensor. This is done using a downstream function-call subsystem that reads acceleration values from FIFO buffer sensor.

The sensor block is placed inside the downstream function-call subsystem. The output of the sensor block is sent to a MATLAB Function block where the data is averaged, and tilt is calculated.

For more information on tilt sensing using accelerometer values, see Using an Accelerometer for Inclination Sensing.

Supported Hardware

To run this example, you can use any TI C2000 hardware. For your convenience, the following hardware is preconfigured to execute the example:

  • TI Delfino F28379D

Prerequisites

Before you start this example, complete the Getting Started with Texas Instruments C2000 Microcontroller Blockset.

Required Hardware

  • Supported TI C2000 hardware

  • LIS3DH sensor

  • USB cable

  • Breadboard wires

Hardware Connection

  • Connect the INT1 pin of the LIS3DH sensor to pin 60 on the TI C2000 hardware.

  • Connect the SDA, SCL, 3.3V, and GND pin of the TI C2000 hardware to the respective pins on the LIS3DH sensor.

Hardware Configuration in the Model

Open the c28xlis3dhtiltdetection model.

The model is preconfigured to work with TI Delfino F28379D LaunchPad hardware. If you are using a different C2000 hardware, change the hardware board by performing the following steps:

1. Navigate to Modeling > Model Settings to open the Configuration Parameters dialog box.

2. Open the Hardware Implementation pane, and from the Hardware board list, select the type of TI 2000 hardware that you are using.

3. Click Apply. Click OK to close the dialog box.

Configure the GPIO Pin for External Interrupt

1. Navigate to Modeling > Model Settings > Hardware Implementation > Target hardware resources.

2. Click Input X-BAR and assign the pin to configure as interrupt.

3. The pin selected is reflected in External interrupt tab. Select the polarity of the interrupt pin in this tab.

4. Click Apply. Click OK to close the dialog box.

5. In the C28x Interupt Block parameters, specify the values for CPU interrupt numbers, PIE interrupt numbers, and Simulink task priorities, and Preemption flags.

Configure the FIFO Data Ready Interrupt on LIS3DH for Interrupt Service Routine (ISR)

1. The LIS3DH sensor block is placed in the downstream function-call subsystem. The output of the block is connected to MATLAB function block. The FIFO data acquired by the MATLAB function is averaged, and tilt of each axis is calculated.

2. Ensure that the Generate data ready interrupt on INT1 pin parameter is selected, and also ensure that FIFO is enabled and Number of samples to read from FIFO (1-32) is provided. In this example, data update is expected at 100 Hz (the specified ODR) and Number of samples to read from FIFO is 10.

3. Connect the INT1 pin to GPIO 60 of TI C2000 hardware.

Initiate Monitor and Tune Action for the Model

During Monitor and Tune action, the model is deployed as a C code on the hardware. The code obtains real-time data from the hardware. The data acquisition and parameter tuning are done while the application is running on the hardware.

Note: Ensure that the TI 2000 hardware you are using has sufficient memory to run the application on hardware.

1. On the Hardware tab, in the Mode section, select Run on board (External Mode) and then click Monitor & Tune.

The lower-left corner of the model window displays status while Simulink prepares, downloads, and runs the Simulink model on the hardware. During simulation, the pin 60 on TI C2000 hardware generates an interrupt on every rising edge of the signal, which triggers the function-call subsystem.

2. Move the sensor and verify the changing values at each time step by double-clicking the Display blocks in the Display data area of the model.