Atmel Software Framework

 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MEMS Sensors - Accelerometer LIS3L06AL

Software Driver for the Accelerometer LIS3L06AL.

This driver relies on the ADC hardware module. It provides functions to initialize the module, to read (x,y,z) coordinates and to get acceleration/orientation/angle information.

Data Structures

struct  avr32_acc_t
 Set of computed data. More...
 
struct  xyz_t
 All 3-axis values from ADC conversion. More...
 

Macros

#define ACC_SHIFT   2
 

Functions

unsigned long acc_get_m_x (void)
 Return measured value of X sensor. More...
 
unsigned long acc_get_m_y (void)
 Return measured value of Y sensor. More...
 
unsigned long acc_get_m_z (void)
 Return measured value of Z sensor. More...
 
void acc_init (void)
 Initialize Accelerometer driver. Mandatory to call. More...
 
void acc_update (void)
 Get accelerometer measure (3x) and process results. More...
 
signed long is_acc_abs_angle_x (unsigned long abs_ang)
 Test if absolute value of X angle has reached the specified limit. More...
 
signed long is_acc_abs_angle_y (unsigned long abs_ang)
 Test if absolute value of Y angle has reached the specified limit. More...
 
bool is_acc_down (void)
 Test if sensor have detected 'down' orientation. More...
 
bool is_acc_left (void)
 Test if sensor have detected 'left' orientation. More...
 
bool is_acc_meuh (char stop)
 Detect a topdown to up transition. More...
 
bool is_acc_right (void)
 Test if sensor have detected 'right' orientation. More...
 
bool is_acc_slow (void)
 Test acceleration about 1g +-10%. More...
 
bool is_acc_topdown (void)
 Test if sensor have detected 'topdown' orientation. More...
 
bool is_acc_up (void)
 Test if sensor have detected 'up' orientation. More...
 

Nominal values out of lis3l06al accelerometer spec

#define ACC_ZERO   (512 >> ACC_SHIFT)
 
#define ACC_1G   (205 >> ACC_SHIFT)
 
#define ACC_MIN   ( ACC_ZERO - ACC_1G )
 
#define ACC_MAX   ( ACC_ZERO + ACC_1G )
 

Sinus table

#define SIN0   0
 
#define SIN15   0.26
 
#define SIN30   0.5
 
#define SIN45   0.71
 
#define SIN60   0.87
 
#define SIN75   0.97
 
#define SIN90   1
 

Axis calibration correction

#define ACC_CALIB_X   0
 
#define ACC_CALIB_Y   0
 
#define ACC_CALIB_Z   0
 

Axis zero point.

#define ACC_ZERO_X   ( ACC_ZERO + ACC_CALIB_X )
 
#define ACC_ZERO_Y   ( ACC_ZERO + ACC_CALIB_Y )
 
#define ACC_ZERO_Z   ( ACC_ZERO + ACC_CALIB_Z )
 

Axis reference values for a set of predefined angles.

#define ACC_TRIG_X0   (int) ( ACC_ZERO_X - SIN15 * ACC_1G )
 
#define ACC_TRIG_X1   (int) ( ACC_ZERO_X + SIN15 * ACC_1G )
 
#define ACC_TRIG_Y0   (int) ( ACC_ZERO_Y - SIN15 * ACC_1G )
 
#define ACC_TRIG_Y1   (int) ( ACC_ZERO_Y + SIN15 * ACC_1G )
 
#define ACC_TRIG_Z_TOP   (int) ( ACC_ZERO_Z - SIN75 * ACC_1G )
 
#define ACC_TRIG_Z_BOT   (int) ( ACC_ZERO_Z + SIN60 * ACC_1G )
 

Sudden acceleration thresholds

#define ACC_QUIET_LO   (int) ( 0.6 * ACC_1G * ACC_1G )
 
#define ACC_QUIET_HI   (int) ( 1.4 * ACC_1G * ACC_1G )
 

Accelerometer ADC channel mapping

#define ADC_CHANNEL_X   ADC_ACC_X_CHANNEL
 
#define ADC_CHANNEL_Y   ADC_ACC_Y_CHANNEL
 
#define ADC_CHANNEL_Z   ADC_ACC_Z_CHANNEL
 

#define ACC_1G   (205 >> ACC_SHIFT)
#define ACC_CALIB_X   0
#define ACC_CALIB_Y   0
#define ACC_CALIB_Z   0
#define ACC_MAX   ( ACC_ZERO + ACC_1G )
#define ACC_MIN   ( ACC_ZERO - ACC_1G )
#define ACC_QUIET_HI   (int) ( 1.4 * ACC_1G * ACC_1G )

Referenced by is_acc_slow().

#define ACC_QUIET_LO   (int) ( 0.6 * ACC_1G * ACC_1G )

Referenced by is_acc_slow().

#define ACC_SHIFT   2

Referenced by acc_get_value().

#define ACC_TRIG_X0   (int) ( ACC_ZERO_X - SIN15 * ACC_1G )

Referenced by is_acc_right().

#define ACC_TRIG_X1   (int) ( ACC_ZERO_X + SIN15 * ACC_1G )

Referenced by is_acc_left().

#define ACC_TRIG_Y0   (int) ( ACC_ZERO_Y - SIN15 * ACC_1G )

Referenced by is_acc_up().

#define ACC_TRIG_Y1   (int) ( ACC_ZERO_Y + SIN15 * ACC_1G )

Referenced by is_acc_down().

#define ACC_TRIG_Z_BOT   (int) ( ACC_ZERO_Z + SIN60 * ACC_1G )

Referenced by is_acc_meuh(), and is_acc_topdown().

#define ACC_TRIG_Z_TOP   (int) ( ACC_ZERO_Z - SIN75 * ACC_1G )

Referenced by is_acc_meuh().

#define ACC_ZERO   (512 >> ACC_SHIFT)
#define ACC_ZERO_X   ( ACC_ZERO + ACC_CALIB_X )
#define ACC_ZERO_Y   ( ACC_ZERO + ACC_CALIB_Y )
#define ACC_ZERO_Z   ( ACC_ZERO + ACC_CALIB_Z )
#define ADC_CHANNEL_X   ADC_ACC_X_CHANNEL

Referenced by acc_get_value().

#define ADC_CHANNEL_Y   ADC_ACC_Y_CHANNEL

Referenced by acc_get_value().

#define ADC_CHANNEL_Z   ADC_ACC_Z_CHANNEL

Referenced by acc_get_value().

#define SIN0   0
#define SIN15   0.26
#define SIN30   0.5
#define SIN45   0.71
#define SIN60   0.87
#define SIN75   0.97
#define SIN90   1

unsigned long acc_get_m_x ( void  )

Return measured value of X sensor.

Returns
measured value of X sensor.

References avr32_acc_t::m, and xyz_t::x.

unsigned long acc_get_m_y ( void  )

Return measured value of Y sensor.

Returns
measured value of Y sensor.

References avr32_acc_t::m, and xyz_t::y.

unsigned long acc_get_m_z ( void  )

Return measured value of Z sensor.

Returns
measured value of Z sensor.

References avr32_acc_t::m, and xyz_t::z.

void acc_init ( void  )

Initialize Accelerometer driver. Mandatory to call.

References adc, adc_configure(), ADC_GPIO_MAP, and gpio_enable_module().

Referenced by device_mouse_hid_task_init().

signed long is_acc_abs_angle_x ( unsigned long  abs_ang)

Test if absolute value of X angle has reached the specified limit.

Returns
bool 1 if limit has been reached in one sens, -1 if limit has been reached in the opposite sens, 0 if limit has not been reached.

References abs, ACC_1G, avr32_acc_t::ak, DEG_2_RAD, and xyz_t::x.

Referenced by is_usb_mouse_event().

signed long is_acc_abs_angle_y ( unsigned long  abs_ang)

Test if absolute value of Y angle has reached the specified limit.

Returns
bool 1 if limit has been reached in one sens, -1 if limit has been reached in the opposite sens, 0 if limit has not been reached.

References abs, ACC_1G, avr32_acc_t::ak, DEG_2_RAD, and xyz_t::y.

Referenced by is_usb_mouse_event().

bool is_acc_down ( void  )

Test if sensor have detected 'down' orientation.

This function uses an software hysteresis.

Returns
bool true if down is detected, false if down is not detected.

References ACC_TRIG_Y1, avr32_acc_t::down, avr32_acc_t::m, avr32_acc_t::pos, and xyz_t::y.

bool is_acc_left ( void  )

Test if sensor have detected 'left' orientation.

This function uses an software hysteresis.

Returns
bool true if left is detected, false if left is not detected.

References ACC_TRIG_X1, avr32_acc_t::left, avr32_acc_t::m, avr32_acc_t::pos, and xyz_t::x.

bool is_acc_meuh ( char  stop)

Detect a topdown to up transition.

This function uses an software hysteresis.

Returns
bool true if topdown to up transition is detected, false if topdown to up transition is not detected.

References ACC_TRIG_Z_BOT, ACC_TRIG_Z_TOP, avr32_acc_t::m, and xyz_t::z.

bool is_acc_right ( void  )

Test if sensor have detected 'right' orientation.

This function uses an software hysteresis.

Returns
bool true if right is detected, false if right is not detected.

References ACC_TRIG_X0, avr32_acc_t::m, avr32_acc_t::pos, avr32_acc_t::right, and xyz_t::x.

bool is_acc_slow ( void  )

Test acceleration about 1g +-10%.

Gravity is always present! This is used to decide slow / fast behavior

Returns
bool true if slow motion is detected, false if fast motion is detected.

References ACC_QUIET_HI, ACC_QUIET_LO, and avr32_acc_t::ak2.

Referenced by acc_update().

bool is_acc_topdown ( void  )

Test if sensor have detected 'topdown' orientation.

This function uses an software hysteresis.

Returns
bool true if topdown is detected, false if topdown is not detected.

References ACC_TRIG_Z_BOT, avr32_acc_t::m, avr32_acc_t::pos, avr32_acc_t::topdown, and xyz_t::z.

bool is_acc_up ( void  )

Test if sensor have detected 'up' orientation.

This function uses an software hysteresis.

Returns
bool true if up is detected, false if up is not detected.

References ACC_TRIG_Y0, avr32_acc_t::m, avr32_acc_t::pos, avr32_acc_t::up, and xyz_t::y.