Tags:
create new tag
view all tags

# Examination on the MMA8452 accelerometer

### Introduction

The mma8452 accelerometer is a 3 axis electro-mechanical device measuring acceleration on the X,Y,Z axis. Control an readout is done through the I2C bus.
The device is described in its data sheet and in the application note AN4072.
Acceleration is measured by measuring the force exerted on a mass during acceleration. The physical formula is
F = m * a ; with F: force, m: mass, a:acceleration.
When an object is a rest and the z-axis points to the center of the earth, then you will measure:
 ax = 0
 ay = 0
 az = 1
All values are given in units of g the gravitational constant.

## Exercise 1:

Where are accelerometers used?

### Exercise 2:

The mma8452 uses an ADC to convert analogue acceleration measurements into digit values.
a) How many bits does this ADC use?
b) The raw value is a left aligned 16 bit number, what does this mean?

c) the mma8452 has 3 different dynamic ranges:
 2g: (+-1g)
 4g: (+-2g)
 8g: (+- 4g)

In 2g mode the integer part can take the values -1, 0 +1. How many bits do you need to encode this?
How many bits do you need to encode the integer part of the value in 4g and 8g mode?
What is the resolution of the device in units of g for each of the modes?

### Exercise 3:

Write a program to read out the 3 raw acceleration values in the default dynamic range.
Which is the default dynamic range?
You must
 initialize the pigpio library and connect to the pigpiod daemon
 you must open the I2C bus
 you must find out on which I2C address the device works
 you must set the mma8452 to active mode in order to enable measurements
The C code for the main program as well as a Makefile to build the application is needed.

### Exercise 4:

Write a function

 void mma8452SetActive(void) to put the device to active mode void mma8452SetStandby(void) to put it into standby mode in which you can program the configuration registers bool mma8452IsActive(void) which returns true if the device is in active mode(#include which defines bool, true and false

### Exercise 5:

Write the functions;

 int mma8452SetRange(int16_t range) setting the dynamic range. #include defining theinteger data types like int8_t int16_t int32_t and their unsigned counter parts uint8_t, uint16_t and uint32_tCheck the if the parameter is valid and return MMA8452_SUCCESS (you define the value) if successfulMMA8452_FAILURE otherwise int16_t mma8452GetRange() return the dynamic range currently set

Add calls into you main program from exercise 3.

This one is for the most clever ones! Dont be nervous if you cannot answer:
How do the raw values change when you change the dynamic range and why?

### Exercise 6:

Convert the raw values to values in units of g. Raw values are binary integers while values in units of g are floating point values.
Write a function float mma8452RawToG(int16_t rawValue) which takes a raw value from dynamic range 2g and converts it into units of g.
This exercise can we done outside of the lab as it does not use any hardware. You can produce raw value by hand!

--    