acc_example.c File Reference


Detailed Description

Accelerometer example driver 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 acc_example.c.

#include "stdio.h"
#include "board.h"
#include "print_funcs.h"
#include "gpio.h"
#include "pm.h"
#include "intc.h"
#include "lis3l06al.h"
#include "nlao_cpu.h"
#include "nlao_usart.h"

Go to the source code of this file.

Defines

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 )

Functions

int _init_startup (void)
 Low-level initialization routine called during startup, before the main function.
int main (void)
 This is an example demonstrating the accelerometer functionalities using the accelerometer driver.
void print_angles ()
 Detect 30 and 60 angles.
void print_mouse ()
 Detect board orientation.
void print_move ()
 Display the tilt. !! this is harder and certainly needs calibration + tuning !!

Variables

volatile char meuh_en = 0
volatile char meuh_stop = 1


Define Documentation

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

Definition at line 107 of file acc_example.c.

Referenced by is_acc_right(), and print_mouse().

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

Definition at line 108 of file acc_example.c.

Referenced by is_acc_left(), and print_mouse().

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

Definition at line 109 of file acc_example.c.

Referenced by is_acc_up(), and print_mouse().

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

Definition at line 110 of file acc_example.c.

Referenced by is_acc_down(), and print_mouse().

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

Definition at line 112 of file acc_example.c.

Referenced by is_acc_meuh(), and is_acc_topdown().

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

Definition at line 111 of file acc_example.c.

Referenced by is_acc_meuh().


Function Documentation

int _init_startup ( void   ) 

Low-level initialization routine called during startup, before the main function.

This version comes in replacement to the default one provided by the Newlib add-ons library. Newlib add-ons' _init_startup only calls init_exceptions, but Newlib add-ons' exception and interrupt vectors are defined in the same section and Newlib add-ons' interrupt vectors are not compatible with the interrupt management of the INTC module. More low-level initializations are besides added here.

Definition at line 210 of file acc_example.c.

00211 {
00212   // Import the Exception Vector Base Address.
00213   extern void _evba;
00214 
00215   // Load the Exception Vector Base Address in the corresponding system register.
00216   Set_system_register(AVR32_EVBA, (int)&_evba);
00217 
00218   // Enable exceptions.
00219   Enable_global_exception();
00220 
00221   // Initialize interrupt handling.
00222   INTC_init_interrupts();
00223 
00224   // init debug serial line
00225   init_dbg_rs232(FOSC0);
00226 
00227   // Give the used CPU clock frequency to Newlib, so it can work properly.
00228   set_cpu_hz(FOSC0);
00229 
00230   // Initialize the USART used for the debug trace with the configured parameters.
00231   set_usart_base( ( void * ) DBG_USART );
00232 
00233   // Don't-care value for GCC.
00234   return 1;
00235 }

int main ( void   ) 

This is an example demonstrating the accelerometer functionalities using the accelerometer driver.

Definition at line 266 of file acc_example.c.

References acc_init(), acc_update(), is_acc_meuh(), is_acc_slow(), meuh_en, meuh_stop, print_angles(), print_mouse(), and print_move().

00267 {
00268   volatile unsigned long i;
00269 
00270   // switch to oscillator 0
00271   pm_switch_to_osc0(&AVR32_PM, FOSC0, OSC0_STARTUP);
00272 
00273   acc_init();
00274 
00275   // do a loop
00276   for (;;)
00277   {
00278     // slow down operations
00279     for ( i=0 ; i < 50000 ; i++);
00280 
00281     // display a header to user
00282     print_dbg("\x1B[2J\x1B[H\r\n\r\nAccelerometer Example\r\n\r\n");
00283 
00284     // Get accelerometer acquisition and process datas
00285     acc_update();
00286 
00287     // test for fast or slow changes
00288     // depending on that, play with angles or moves
00289     if ( is_acc_slow() )
00290     {
00291       print_mouse() ;
00292       print_angles() ;
00293     }
00294     else
00295       print_move() ;
00296 
00297     // MEUH
00298     // only text here , needs to be combined with PWM
00299     // meuh_stop is the "end" signal from PWM
00300     meuh_en = is_acc_meuh( meuh_stop ) ;
00301   }
00302 }

void print_angles (  ) 

Detect 30 and 60 angles.

Definition at line 141 of file acc_example.c.

References is_acc_abs_angle_x(), is_acc_abs_angle_y(), xyz_t::x, and xyz_t::y.

Referenced by main().

00142 {
00143   signed int res;
00144   static xyz_t angle ;
00145 
00146 //  if ( ! is_acc_slow() ) { return }
00147 
00148   if(      0!=(res=is_acc_abs_angle_x(60)) ) angle.x = 60;
00149   else if( 0!=(res=is_acc_abs_angle_x(30)) ) angle.x = 30;
00150   else                                       angle.x = 0 ;
00151 
00152   if ( angle.x > 0 )
00153   {
00154      if(      res>0 ) print_dbg("LEFT ") ;
00155      else if( res<0 ) print_dbg("RIGHT ") ;
00156 
00157      print_dbg_ulong(angle.x) ;
00158      print_dbg("\r\n") ;
00159   }
00160 
00161   if(      0!=(res=is_acc_abs_angle_y(60)) ) angle.y = 60;
00162   else if( 0!=(res=is_acc_abs_angle_y(30)) ) angle.y = 30;
00163   else                                       angle.y = 0 ;
00164 
00165   if ( angle.y > 0 )
00166   {
00167      if(      res>0 ) print_dbg("DOWN ") ;
00168      else if( res<0 ) print_dbg("UP ") ;
00169 
00170      print_dbg_ulong(angle.y) ;
00171      print_dbg("\r\n") ;
00172   }
00173 }

void print_mouse (  ) 

Detect board orientation.

Definition at line 117 of file acc_example.c.

References acc_get_m_x(), acc_get_m_y(), acc_get_m_z(), ACC_TRIG_X0, ACC_TRIG_X1, ACC_TRIG_Y0, ACC_TRIG_Y1, ACC_ZERO_X, ACC_ZERO_Y, is_acc_down(), is_acc_left(), is_acc_meuh(), is_acc_right(), is_acc_topdown(), and is_acc_up().

Referenced by main().

00118 {
00119   print_dbg("HEX Value for Channel x : 0x");
00120   print_dbg_hex(acc_get_m_x());
00121   if      ( is_acc_left()  ) { print_dbg(" < 0x") ; print_dbg_hex(ACC_TRIG_X0) ; print_dbg(" ... left") ; }
00122   else if ( is_acc_right() ) { print_dbg(" > 0x") ; print_dbg_hex(ACC_TRIG_X1) ; print_dbg(" ... right") ; }
00123   else                       { print_dbg(" = 0x") ; print_dbg_hex(ACC_ZERO_X) ; }
00124   print_dbg("\r\n");
00125   print_dbg("HEX Value for Channel y : 0x");
00126   print_dbg_hex(acc_get_m_y());
00127   if      ( is_acc_up()   ) { print_dbg(" < 0x") ; print_dbg_hex(ACC_TRIG_Y0) ; print_dbg(" ... up") ; }
00128   else if ( is_acc_down() ) { print_dbg(" > 0x") ; print_dbg_hex(ACC_TRIG_Y1) ; print_dbg(" ... down") ; }
00129   else                      { print_dbg(" = 0x") ; print_dbg_hex(ACC_ZERO_Y) ; }
00130   print_dbg("\r\n");
00131   print_dbg("HEX Value for Channel z : 0x");
00132   print_dbg_hex(acc_get_m_z());
00133   if ( is_acc_topdown() ) { print_dbg(" ... TOPDOWN") ; }
00134   if ( is_acc_meuh(1)   ) { print_dbg(" ... MEUH !!") ; }
00135   print_dbg("\r\n\r\n");
00136 }

void print_move (  ) 

Display the tilt. !! this is harder and certainly needs calibration + tuning !!

Definition at line 180 of file acc_example.c.

Referenced by main().

00181 {
00182   volatile U32 i;
00183   print_dbg("... T I L T !!!") ;
00184   print_dbg("\r\n");
00185   for ( i=0 ; i < 1000000 ; i++);
00186 }


Variable Documentation

volatile char meuh_en = 0

Definition at line 190 of file acc_example.c.

Referenced by main().

volatile char meuh_stop = 1

Definition at line 191 of file acc_example.c.

Referenced by main().


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