lis3l06al.h File Reference


Detailed Description

Accelerometer example header for AVR32 UC3.

This file provides an example for the ADC + Accelerometer on AVR32 UC3 devices.

Author:
Atmel Corporation: http://www.atmel.com
Support and FAQ: http://support.atmel.no/

Definition in file lis3l06al.h.

Go to the source code of this file.

Data Structures

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

Defines

#define ACC_SHIFT   2
Nominal values out of lis3l06al accelerometer spec
#define ACC_1G   (205 >> ACC_SHIFT)
#define ACC_MAX   ( ACC_ZERO + ACC_1G )
#define ACC_MIN   ( ACC_ZERO - ACC_1G )
#define ACC_ZERO   (512 >> ACC_SHIFT)
Axis calibration correction
#define ACC_CALIB_X   0
#define ACC_CALIB_Y   0
#define ACC_CALIB_Z   0
Sudden acceleration thresholds
#define ACC_QUIET_HI   (int) ( 1.4 * ACC_1G * ACC_1G )
#define ACC_QUIET_LO   (int) ( 0.6 * ACC_1G * ACC_1G )
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_BOT   (int) ( ACC_ZERO_Z + SIN60 * ACC_1G )
#define ACC_TRIG_Z_TOP   (int) ( ACC_ZERO_Z - SIN75 * ACC_1G )
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 )
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
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

Functions

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


Define Documentation

#define ACC_1G   (205 >> ACC_SHIFT)

Definition at line 63 of file lis3l06al.h.

Referenced by is_acc_abs_angle_x(), and is_acc_abs_angle_y().

#define ACC_CALIB_X   0

Definition at line 83 of file lis3l06al.h.

#define ACC_CALIB_Y   0

Definition at line 84 of file lis3l06al.h.

#define ACC_CALIB_Z   0

Definition at line 85 of file lis3l06al.h.

#define ACC_MAX   ( ACC_ZERO + ACC_1G )

Definition at line 65 of file lis3l06al.h.

#define ACC_MIN   ( ACC_ZERO - ACC_1G )

Definition at line 64 of file lis3l06al.h.

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

Definition at line 111 of file lis3l06al.h.

Referenced by is_acc_slow().

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

Definition at line 110 of file lis3l06al.h.

Referenced by is_acc_slow().

#define ACC_SHIFT   2

Definition at line 57 of file lis3l06al.h.

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

Definition at line 99 of file lis3l06al.h.

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

Definition at line 100 of file lis3l06al.h.

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

Definition at line 101 of file lis3l06al.h.

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

Definition at line 102 of file lis3l06al.h.

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

Definition at line 104 of file lis3l06al.h.

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

Definition at line 103 of file lis3l06al.h.

#define ACC_ZERO   (512 >> ACC_SHIFT)

Definition at line 62 of file lis3l06al.h.

#define ACC_ZERO_X   ( ACC_ZERO + ACC_CALIB_X )

Definition at line 91 of file lis3l06al.h.

Referenced by print_mouse().

#define ACC_ZERO_Y   ( ACC_ZERO + ACC_CALIB_Y )

Definition at line 92 of file lis3l06al.h.

Referenced by print_mouse().

#define ACC_ZERO_Z   ( ACC_ZERO + ACC_CALIB_Z )

Definition at line 93 of file lis3l06al.h.

#define ADC_CHANNEL_X   ADC_ACC_X_CHANNEL

Definition at line 118 of file lis3l06al.h.

#define ADC_CHANNEL_Y   ADC_ACC_Y_CHANNEL

Definition at line 119 of file lis3l06al.h.

#define ADC_CHANNEL_Z   ADC_ACC_Z_CHANNEL

Definition at line 120 of file lis3l06al.h.

#define SIN0   0

Definition at line 71 of file lis3l06al.h.

#define SIN15   0.26

Definition at line 72 of file lis3l06al.h.

#define SIN30   0.5

Definition at line 73 of file lis3l06al.h.

#define SIN45   0.71

Definition at line 74 of file lis3l06al.h.

#define SIN60   0.87

Definition at line 75 of file lis3l06al.h.

#define SIN75   0.97

Definition at line 76 of file lis3l06al.h.

#define SIN90   1

Definition at line 77 of file lis3l06al.h.


Function Documentation

unsigned long acc_get_m_x ( void   ) 

Return measured value of X sensor.

Returns:
measured value of X sensor.

Definition at line 285 of file lis3l06al.c.

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

Referenced by print_mouse().

00286 {
00287    return acc.m.x;
00288 }

unsigned long acc_get_m_y ( void   ) 

Return measured value of Y sensor.

Returns:
measured value of Y sensor.

Definition at line 290 of file lis3l06al.c.

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

Referenced by print_mouse().

00291 {
00292    return acc.m.y;
00293 }

unsigned long acc_get_m_z ( void   ) 

Return measured value of Z sensor.

Returns:
measured value of Z sensor.

Definition at line 295 of file lis3l06al.c.

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

Referenced by print_mouse().

00296 {
00297    return acc.m.z;
00298 }

void acc_init ( void   ) 

Initialise Accelerometer driver. Mandatory to call.

Definition at line 213 of file lis3l06al.c.

Referenced by main().

00214 {
00215   volatile avr32_adc_t *adc = &AVR32_ADC;
00216   static const gpio_map_t ADC_GPIO_MAP =
00217   {
00218     {AVR32_ADC_AD_3_PIN,  AVR32_ADC_AD_3_FUNCTION}, // ADC channel 3
00219     {AVR32_ADC_AD_1_PIN,  AVR32_ADC_AD_1_FUNCTION}, // ADC channel 1
00220     {AVR32_ADC_AD_2_PIN,  AVR32_ADC_AD_2_FUNCTION}  // ADC channel 2
00221   };
00222 
00223   // enable GPIO pins for ADC
00224   gpio_enable_module(ADC_GPIO_MAP,
00225                      sizeof(ADC_GPIO_MAP) / sizeof(ADC_GPIO_MAP[0]));
00226 
00227   // configure ADC
00228   adc_configure(adc);
00229 }

void acc_update ( void   ) 

Get accelerometer measure (3x) and process results.

Definition at line 231 of file lis3l06al.c.

References avr32_acc_t::ag, avr32_acc_t::ak, avr32_acc_t::ak2, avr32_acc_t::g, is_acc_slow(), avr32_acc_t::k, avr32_acc_t::m, avr32_acc_t::s, xyz_t::x, xyz_t::y, and xyz_t::z.

Referenced by main().

00232 {
00233   volatile avr32_adc_t *adc = &AVR32_ADC;
00234 
00235   // start + get from adc
00236   acc_get_value(adc, &acc.m) ;
00237 
00238   // ak  = acceleration = m - k
00239   xyz_diff( acc.m , acc.k, &acc.ak ) ;
00240   acc.ak2 = xyz_sumsq( acc.ak ) ;
00241 
00242   if ( is_acc_slow() ) {
00243      // update g for next move
00244      acc.g.x = acc.m.x ;
00245      acc.g.y = acc.m.y ;
00246      acc.g.z = acc.m.z ;
00247   }
00248   else {
00249      xyz_diff( acc.m , acc.g, &acc.ag ) ;
00250      xyz_round0( acc.ag , 16, &acc.ag ) ;
00251      xyz_add( acc.s , acc.ag, &acc.s ) ;
00252      //xyz_round0( acc.s , 256, &acc.s ) ;
00253      //print_dbg("m = "); print_xyz( acc.m ) ;
00254      //print_dbg("k = "); print_xyz( acc.k ) ;
00255      //print_dbg("g = "); print_xyz( acc.g ) ;
00256      //print_dbg("ag = "); print_xyz( acc.ag ) ;
00257      //print_dbg("s = "); print_xyz( acc.s ) ;
00258      //print_dbg("\r\n");
00260      //print_dbg("s2 = 0x"); print_dbg_hex(acc.s2); print_dbg("\r\n");
00261   }
00262 }

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.

Definition at line 265 of file lis3l06al.c.

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

Referenced by print_angles().

00266 {
00267   if( abs(acc.ak.x) > (int)(sin(DEG_2_RAD(abs_ang)) * ACC_1G) )
00268   {
00269      if ( acc.ak.x > 0 ) return 1;
00270      else                return -1;
00271   }
00272   return 0;
00273 }

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.

Definition at line 275 of file lis3l06al.c.

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

Referenced by print_angles().

00276 {
00277   if( abs(acc.ak.y) > (int)(sin(DEG_2_RAD(abs_ang)) * ACC_1G) )
00278   {
00279      if ( acc.ak.y > 0 ) return 1;
00280      else                return -1;
00281   }
00282   return 0;
00283 }

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.

Definition at line 189 of file lis3l06al.c.

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

Referenced by print_mouse().

00190 {
00191   if      ( (acc.pos.down==0) && (acc.m.y > (int)(1.01*ACC_TRIG_Y1)) ) acc.pos.down = 1 ;
00192   else if ( (acc.pos.down==1) && (acc.m.y < (int)(0.99*ACC_TRIG_Y1)) ) acc.pos.down = 0 ;
00193   return acc.pos.down ;
00194 }

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.

Definition at line 170 of file lis3l06al.c.

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

Referenced by print_mouse().

00171 {
00172   if      ( (acc.pos.left==0) && (acc.m.x > (int)(1.01*ACC_TRIG_X1)) ) acc.pos.left = 1 ;
00173   else if ( (acc.pos.left==1) && (acc.m.x < (int)(0.99*ACC_TRIG_X1)) ) acc.pos.left = 0 ;
00174   return acc.pos.left ;
00175 }

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.

Definition at line 203 of file lis3l06al.c.

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

Referenced by main(), and print_mouse().

00204 {
00205   static char topdown = 0 ;
00206   static char meuh = 0 ;
00207   if ( stop )  meuh = 0 ;
00208   if      ( (topdown==0) && (acc.m.z > ACC_TRIG_Z_BOT) ) topdown = 1 ;
00209   else if ( (topdown==1) && (acc.m.z < ACC_TRIG_Z_TOP) ) { topdown = 0 ; meuh = 1 ; }
00210   return meuh ;
00211 }

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.

Definition at line 176 of file lis3l06al.c.

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

Referenced by print_mouse().

00177 {
00178   if      ( (acc.pos.right==0) && (acc.m.x < (int)(0.99*ACC_TRIG_X0)) ) acc.pos.right = 1 ;
00179   else if ( (acc.pos.right==1) && (acc.m.x > (int)(1.01*ACC_TRIG_X0)) ) acc.pos.right = 0 ;
00180   return acc.pos.right ;
00181 }

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.

Definition at line 147 of file lis3l06al.c.

References ACC_QUIET_HI, ACC_QUIET_LO, and avr32_acc_t::ak2.

Referenced by acc_update(), and main().

00148 {
00149   return ( (acc.ak2 > ACC_QUIET_LO) && (acc.ak2 < ACC_QUIET_HI) ) ;
00150 }

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.

Definition at line 196 of file lis3l06al.c.

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

Referenced by print_mouse().

00197 {
00198   if      ( (acc.pos.topdown==0) && (acc.m.z > (int)(1.01*ACC_TRIG_Z_BOT)) ) acc.pos.topdown = 1 ;
00199   else if ( (acc.pos.topdown==1) && (acc.m.z < (int)(0.99*ACC_TRIG_Z_BOT)) ) acc.pos.topdown = 0 ;
00200   return acc.pos.topdown ;
00201 }

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.

Definition at line 183 of file lis3l06al.c.

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

Referenced by print_mouse().

00184 {
00185   if      ( (acc.pos.up==0) && (acc.m.y < (int)(0.99*ACC_TRIG_Y0)) ) acc.pos.up = 1 ;
00186   else if ( (acc.pos.up==1) && (acc.m.y > (int)(1.01*ACC_TRIG_Y0)) ) acc.pos.up = 0 ;
00187   return acc.pos.up ;
00188 }


Generated on Fri Feb 19 02:23:25 2010 for AVR32 UC3 - lis3l06al accelerometer driver by  doxygen 1.5.5