DE0-Nano FPGA Tilt Sensing

The Acceleromter Theory
           First let's take a look at how we view the world with the picture below. Our world is 3-dimensional. This means that when we want to measure distance, velocity or acceleration there is a maximum of 3 values (axis) for each. For the accelerometer we are interested in measuring acceleration and though it can exist in any direction X, Y or Z we will only measure it in 1.

Motion On 3-Axis

           There are two ways to use the Accelerometer. The first way is to measure the acceleration of whatever obeject the sensor is attached to, or it can measure the tilt of the object it is attached to. Below is a picture that illustrates the measuring of tilt.

A Tilt Sensor

           When the sensor is tilted the effect of the earth's gravity upon it changes and so does the sensor's output. This feature is what we'll demonstrate in both the following code and video. The acceleration aspect of what we'll build can also be seen if you put it in a car and slow very quickly or speed up very quickly. (Drive safely on the roads!)

Communicating With The Accelerometer
           The ADXL uses a standard digital communication called SPI or Serial Peripheral Interface. SPI has a loose set of standards but for communicating with this device you will use SPI commands with the following bit length:

ADXL345 SPI Write/Read Timing

           Reads and writes are the same command bit-length, it's just a matter of whether you're receiving data on the MISO line or outputing data to the addressed register on the MOSI lines. The microcontroller SPI interface article has more information of how to use SPI and the theory behind it.