inc/accel.h File Reference

#include "tll_config.h"

Include dependency graph for accel.h:

This graph shows which files directly or indirectly include this file:


Data Structures

struct  accel_data_t

Defines

#define ACCEL_I2C_ADDR   0x53
#define TWI_CLK   100000
#define ACCEL_REG_DEVID   0x00
#define ACCEL_REG_THRESH_TAP   0x1D
 tap_threshold: holds the threshold value for tap detection/interrupts.
#define ACCEL_REG_DUR   0x21
 tap_duration: is an unsigned time value representing the maximum time that an event must be above the tap_threshold threshold to qualify as a tap event.
#define ACCEL_REG_Latent   0x22
 s tap_latency: is an unsigned time value representing the wait time from the detection of a tap event to the opening of the time window tap_window for a possible second tap event.
#define ACCEL_REG_Window   0x23
 tap_window: is an unsigned time value representing the amount of time after the expiration of tap_latency during which a second tap can begin.
#define ACCEL_REG_OFSX   0x1E
 X,Y,Z Axis Offset: offer user offset adjustments in twoscompliment form with a scale factor of 15.6 mg/LSB (i.e.
#define ACCEL_REG_OFSY   0x1F
#define ACCEL_REG_OFSZ   0x20
#define ACCEL_REG_THRESH_ACT   0x24
 activity_threshold: holds the threshold value for activity detection.
#define ACCEL_REG_THRESH_INACT   0x25
 inactivity_threshold: holds the threshold value for inactivity detection.
#define ACCEL_REG_TIME_INACT   0x26
 inactivity_time: is an unsigned time value representing the amount of time that acceleration must be below the value in inactivity_threshold for inactivity to be declared.
#define ACCEL_REG_ACT_INACT_CTL   0x27
 act_axis_control: X/Y/Z Enable: A '1' enables X, Y, or Z participation in activity or inactivity detection.
#define ADXL_ACT_ACDC   (1 << 7)
#define ADXL_ACT_X_EN   (1 << 6)
#define ADXL_ACT_Y_EN   (1 << 5)
#define ADXL_ACT_Z_EN   (1 << 4)
#define ADXL_INACT_ACDC   (1 << 3)
#define ADXL_INACT_X_EN   (1 << 2)
#define ADXL_INACT_Y_EN   (1 << 1)
#define ADXL_INACT_Z_EN   (1 << 0)
#define ACCEL_REG_THRESH_FF   0x28
 free_fall_threshold: holds the threshold value for Free-Fall detection.
#define ACCEL_REG_TIME_FF   0x29
 free_fall_time: is an unsigned time value representing the minimum time that the RSS value of all axes must be less than free_fall_threshold to generate a Free-Fall interrupt.
#define ACCEL_REG_TAP_AXES   0x2A
 TAP_X/Y/Z Enable: Setting TAP_X, Y, or Z Enable enables X, Y, or Z participation in Tap detection.
#define ADXL_SUPPRESS   (1 << 3)
#define ADXL_TAP_X_EN   (1 << 2)
#define ADXL_TAP_Y_EN   (1 << 1)
#define ADXL_TAP_Z_EN   (1 << 0)
#define ACCEL_REG_ACT_TAP_STATUS   0x2B
#define ACCEL_REG_BW_RATE   0x2C
 data_rate: Selects device bandwidth and output data rate.
#define ACCEL_REG_POWER_CTL   0x2D
 power_mode: LINK: A '1' with both the activity and inactivity functions enabled will delay the start of the activity function until inactivity is detected.
#define ADXL_LINK   (1 << 5)
#define ADXL_AUTO_SLEEP   (1 << 4)
#define ADXL_MEASURE   (1 << 3)
#define ACCEL_REG_INT_ENABLE   0x2E
#define ACCEL_REG_INT_MAP   0x2F
#define ACCEL_REG_INT_SOURCE   0x30
#define ACCEL_REG_DATA_FORMAT   0x31
 data_range: FULL_RES: When this bit is set with the device is in Full-Resolution Mode, where the output resolution increases with RANGE to maintain a 4 mg/LSB scale factor.
#define ADXL_FULL_RES   (1 << 3)
#define ADXL_RANGE_PM_2g   0
#define ADXL_RANGE_PM_4g   1
#define ADXL_RANGE_PM_8g   2
#define ADXL_RANGE_PM_16g   3
#define ACCEL_REG_DATAX0   0x32
#define ACCEL_REG_DATAX1   0x33
#define ACCEL_REG_DATAY0   0x34
#define ACCEL_REG_DATAY1   0x35
#define ACCEL_REG_DATAZ0   0x36
#define ACCEL_REG_DATAZ1   0x37
#define ACCEL_REG_FIFO_CTL   0x38
 fifo_mode: BYPASS The FIFO is bypassed FIFO FIFO collects up to 32 values then stops collecting data STREAM FIFO holds the last 32 data values.
#define ADXL_FIFO_BYPASS   0x00
#define ADXL_FIFO_FIFO   0x40
#define ADXL_FIFO_STREAM   0x80
#define ACCEL_REG_FIFO_STATUS   0x39
 FIFO_STATUS FIFO_TRIG Bit A 1 in the FIFO_TRIG bit corresponds to a trigger event occurring, and a 0 means that a FIFO trigger event has not occurred.

Functions

int accel_init (void)
 Initialize accelerometer and setup for default operation sample at 100Hz, full resolution, no FIFO no interrupts.
int accel_calibrate (void)
 Calibrate accelerometer.
int accel_read (accel_data_t *pData)
 Accelerometer axis read function.
void accel_registerWrite (unsigned char addr, unsigned char data)

Define Documentation

#define ACCEL_I2C_ADDR   0x53

#define ACCEL_REG_ACT_INACT_CTL   0x27

act_axis_control: X/Y/Z Enable: A '1' enables X, Y, or Z participation in activity or inactivity detection.

A '0' excludes the selected axis from participation. If all of the axes are excluded, the function is disabled. AC/DC: A '0' = DC coupled operation and a '1' = AC coupled operation. In DC coupled operation, the current acceleration is compared with activity_threshold and inactivity_threshold directly to determine whether activity or inactivity is detected. In AC coupled operation for activity detection, the acceleration value at the start of activity detection is taken as a reference value. New samples of acceleration are then compared to this reference value and if the magnitude of the difference exceeds activity_threshold the device will trigger an activity interrupt. In AC coupled operation for inactivity detection, a reference value is used again for comparison and is updated whenever the device exceeds the inactivity threshold. Once the reference value is selected, the device compares the magnitude of the difference between the reference value and the current acceleration with inactivity_threshold. If the difference is below inactivity_threshold for a total of inactivity_time, the device is considered inactive and the inactivity interrupt is triggered.

#define ACCEL_REG_ACT_TAP_STATUS   0x2B

#define ACCEL_REG_BW_RATE   0x2C

data_rate: Selects device bandwidth and output data rate.

RATE = 3200 Hz / (2^(15 - x)). Default value is 0x0A, or 100 Hz Output Data Rate. An Output Data Rate should be selected that is appropriate for the communication protocol and frequency selected. Selecting too high of an Output Data Rate with a low communication speed will result in samples being discarded.

#define ACCEL_REG_DATA_FORMAT   0x31

data_range: FULL_RES: When this bit is set with the device is in Full-Resolution Mode, where the output resolution increases with RANGE to maintain a 4 mg/LSB scale factor.

When this bit is cleared the device is in 10-bit Mode and RANGE determine the maximum g-Range and scale factor.

#define ACCEL_REG_DATAX0   0x32

#define ACCEL_REG_DATAX1   0x33

#define ACCEL_REG_DATAY0   0x34

#define ACCEL_REG_DATAY1   0x35

#define ACCEL_REG_DATAZ0   0x36

#define ACCEL_REG_DATAZ1   0x37

#define ACCEL_REG_DEVID   0x00

#define ACCEL_REG_DUR   0x21

tap_duration: is an unsigned time value representing the maximum time that an event must be above the tap_threshold threshold to qualify as a tap event.

The scale factor is 625 us/LSB. A zero value will prevent Tap/Double Tap functions from working.

#define ACCEL_REG_FIFO_CTL   0x38

fifo_mode: BYPASS The FIFO is bypassed FIFO FIFO collects up to 32 values then stops collecting data STREAM FIFO holds the last 32 data values.

Once full, the FIFO's oldest data is lost as it is replaced with newer data

DEFAULT should be ADXL_FIFO_STREAM

#define ACCEL_REG_FIFO_STATUS   0x39

FIFO_STATUS FIFO_TRIG Bit A 1 in the FIFO_TRIG bit corresponds to a trigger event occurring, and a 0 means that a FIFO trigger event has not occurred.

Entries Bits These bits report how many data values are stored in FIFO. Access to collect the data from FIFO is provided through the DATAX, DATAY, and DATAZ registers. FIFO reads must be done in burst or multiple-byte mode because each FIFO level is cleared after any read (single- or multiple-byte) of FIFO. FIFO stores a maximum of 32 entries, which equates to a maximum of 33 entries available at any given time because an additional entry is available at the output filter of the device.

#define ACCEL_REG_INT_ENABLE   0x2E

#define ACCEL_REG_INT_MAP   0x2F

#define ACCEL_REG_INT_SOURCE   0x30

#define ACCEL_REG_Latent   0x22

s tap_latency: is an unsigned time value representing the wait time from the detection of a tap event to the opening of the time window tap_window for a possible second tap event.

The scale factor is 1.25 ms/LSB. A zero value will disable the Double Tap function.

#define ACCEL_REG_OFSX   0x1E

X,Y,Z Axis Offset: offer user offset adjustments in twoscompliment form with a scale factor of 15.6 mg/LSB (i.e.

0x7F = +2 g)

#define ACCEL_REG_OFSY   0x1F

#define ACCEL_REG_OFSZ   0x20

#define ACCEL_REG_POWER_CTL   0x2D

power_mode: LINK: A '1' with both the activity and inactivity functions enabled will delay the start of the activity function until inactivity is detected.

Once activity is detected, inactivity detection will begin and prevent the detection of activity. This bit serially links the activity and inactivity functions. When '0' the inactivity and activity functions are concurrent. Additional information can be found in the Application section under Link Mode. AUTO_SLEEP: A '1' sets the ADXL34x to switch to Sleep Mode when inactivity (acceleration has been below inactivity_threshold for at least inactivity_time) is detected and the LINK bit is set. A '0' disables automatic switching to Sleep Mode. See SLEEP for further description.

#define ACCEL_REG_TAP_AXES   0x2A

TAP_X/Y/Z Enable: Setting TAP_X, Y, or Z Enable enables X, Y, or Z participation in Tap detection.

A '0' excludes the selected axis from participation in Tap detection. Setting the SUPPRESS bit suppresses Double Tap detection if acceleration greater than tap_threshold is present between taps.

#define ACCEL_REG_THRESH_ACT   0x24

activity_threshold: holds the threshold value for activity detection.

The data format is unsigned. The scale factor is 62.5 mg/LSB. A zero value may result in undesirable behavior if Activity interrupt is enabled.

#define ACCEL_REG_THRESH_FF   0x28

free_fall_threshold: holds the threshold value for Free-Fall detection.

The data format is unsigned. The root-sum-square(RSS) value of all axes is calculated and compared to the value in free_fall_threshold to determine if a free fall event may be occurring. The scale factor is 62.5 mg/LSB. A zero value may result in undesirable behavior if Free-Fall interrupt is enabled. Values between 300 and 600 mg (0x05 to 0x09) are recommended.

#define ACCEL_REG_THRESH_INACT   0x25

inactivity_threshold: holds the threshold value for inactivity detection.

The data format is unsigned. The scale factor is 62.5 mg/LSB. A zero value may result in undesirable behavior if Inactivity interrupt is enabled.

#define ACCEL_REG_THRESH_TAP   0x1D

tap_threshold: holds the threshold value for tap detection/interrupts.

The data format is unsigned. The scale factor is 62.5 mg/LSB (i.e. 0xFF = +16 g). A zero value may result in undesirable behavior if Tap/Double Tap is enabled.

#define ACCEL_REG_TIME_FF   0x29

free_fall_time: is an unsigned time value representing the minimum time that the RSS value of all axes must be less than free_fall_threshold to generate a Free-Fall interrupt.

The scale factor is 5 ms/LSB. A zero value may result in undesirable behavior if Free-Fall interrupt is enabled. Values between 100 to 350 ms (0x14 to 0x46) are recommended.

#define ACCEL_REG_TIME_INACT   0x26

inactivity_time: is an unsigned time value representing the amount of time that acceleration must be below the value in inactivity_threshold for inactivity to be declared.

The scale factor is 1 second/LSB. Unlike the other interrupt functions, which operate on unfiltered data, the inactivity function operates on the filtered output data. At least one output sample must be generated for the inactivity interrupt to be triggered. This will result in the function appearing un-responsive if the inactivity_time register is set with a value less than the time constant of the Output Data Rate. A zero value will result in an interrupt when the output data is below inactivity_threshold.

#define ACCEL_REG_Window   0x23

tap_window: is an unsigned time value representing the amount of time after the expiration of tap_latency during which a second tap can begin.

The scale factor is 1.25 ms/LSB. A zero value will disable the Double Tap function.

#define ADXL_ACT_ACDC   (1 << 7)

#define ADXL_ACT_X_EN   (1 << 6)

#define ADXL_ACT_Y_EN   (1 << 5)

#define ADXL_ACT_Z_EN   (1 << 4)

#define ADXL_AUTO_SLEEP   (1 << 4)

#define ADXL_FIFO_BYPASS   0x00

#define ADXL_FIFO_FIFO   0x40

#define ADXL_FIFO_STREAM   0x80

#define ADXL_FULL_RES   (1 << 3)

#define ADXL_INACT_ACDC   (1 << 3)

#define ADXL_INACT_X_EN   (1 << 2)

#define ADXL_INACT_Y_EN   (1 << 1)

#define ADXL_INACT_Z_EN   (1 << 0)

#define ADXL_LINK   (1 << 5)

#define ADXL_MEASURE   (1 << 3)

#define ADXL_RANGE_PM_16g   3

#define ADXL_RANGE_PM_2g   0

#define ADXL_RANGE_PM_4g   1

#define ADXL_RANGE_PM_8g   2

#define ADXL_SUPPRESS   (1 << 3)

#define ADXL_TAP_X_EN   (1 << 2)

#define ADXL_TAP_Y_EN   (1 << 1)

#define ADXL_TAP_Z_EN   (1 << 0)

#define TWI_CLK   100000


Function Documentation

int accel_calibrate ( void   ) 

Calibrate accelerometer.

Note device has to be leveled on a surface and not moving. Pre-condition:

Parameters:

Returns:
Zero on success. Negative value on failure.

int accel_init ( void   ) 

Initialize accelerometer and setup for default operation sample at 100Hz, full resolution, no FIFO no interrupts.

This function configures the accel slave device via I2C.

Pre-conditions:

Post condtions:

Parameters:

Returns:
0 on success, -1 on fail

int accel_read ( accel_data_t pData  ) 

Accelerometer axis read function.

This function reads values from the configured accel slave devices via I2C.

Pre-conditions:

Post condtions:

Parameters:

Parameters:
pData struct of acceleration values as 16bit signed values
Returns:
0 on success, -1 on fail

void accel_registerWrite ( unsigned char  addr,
unsigned char  data 
)


Generated on 3 Mar 2014 for PAL bare-c Library by  doxygen 1.4.7