Example accelerometer code released.

I’ve written example TI accelerometer interface code and posted it here: http://kevin.org/frc. Here’s the readme.txt:


The source code in accelerometer.c/.h contains a driver and 
supporting software to interface the Texas Instruments 
accelerometer found in the FIRST Robotics 2005 kit of parts
to an IFI Robotics FRC or EDU robot controller. By default, 
this software is configured to sample the device's analog 
output at 200Hz, downconverting to an update rate of 50Hz by 
averaging four samples per update. These parameters can be 
changed by editing accelerometer.h.
						 ** IMPORTANT **
The cable provided in the kit of parts uses a non-standard
color coding for power. Connect the black wire to +5V and
the red wire to ground. The white wire connects to the RC's
analog input.  
This software makes the assumption that when it's running, it 
solely controls the analog to digital conversion hardware and 
that only the accelerometer, on analog input one, is being 
sampled. Calling Disable_Accelerometer() will disable the
accelerometer interface software and allow you to use the ADC 
for other purposes.
This source code will work with the Robovation (A/K/A EDU-RC) 
robot controller and the FIRST Robotics robot controller.
The included project files were built with MPLAB version 6.60.
If your version of MPLAB complains about the project version, 
the best thing to do is just create a new project with MPLAB's 
project wizard. Include every file except: FRC_alltimers.lib 
and ifi_alltimers.lib and you should be able to build the code.
****************************************************************
Here's a description of the functions in accelerometer.c:

Initialize_Accelerometer()
This function initializes the accelerometer software. It 
should be called from user_routines.c/User_Initialization().
 
Get_Acceleration()
This function returns the current calculated acceleration in
units of milligs. It's important to note that this value is
relative to the acceleration measured when the accelerometer
started taking measurements or when Calc_Accelerometer_Bias()
was last called.

Calc_Accelerometer_Bias()
This function forces a new accelerometer bias calculation 
to take place.

Get_Accelerometer_Bias()
This function returns the current calculated accelerometer
bias. For extra precision, this software internally maintains 
an accelerometer bias value that is the sum of 
ACCELEROMETER_SAMPLES_PER_UPDATE samples of the accelerometer's
analog output.

Set_Accelerometer_Bias()
This function can be called to manually set the accelerometer 
bias. For extra precision, this software internally maintains 
an accelerometer bias value that is the sum of 
ACCELEROMETER_SAMPLES_PER_UPDATE samples of the accelerometer's
analog output.

Disable_Accelerometer()
This function should be called when the accelerometer
functionality is no longer needed, thus reclaiming the time 
spent servicing the timer 2 interrupt.

Initialize_ADC()
This function initializes the analog to digital conversion
hardware. This is called by Initialize_Accelerometer() above 
and shouldn't be called directly.

Initialize_Timer_2()
This function initializes and starts timer2. This is called 
by Initialize_Accelerometer() above and shouldn't be called 
directly.

Timer_2_Int_Handler()
This function is automatically called when timer 2 causes an
interrupt and shouldn't be called directly.

****************************************************************
Four things must be done before this software will work 
correctly on the FRC-RC:
1) The accelerometers output is wired to analog input 1.
2) A #include statement for the accelerometer.h header file 
must be included at the beginning of each source file that 
calls the functions in this source file. The statement should 
look like this: #include "accelerometer.h".
3) Initialize_Accelerometer() must be called from 
user_routines.c/User_Initialization().
4) The timer 2 interrupt handler, Timer_2_Int_Handler(), must
be installed in User_Routines_Fast.c/InterruptHandlerLow().
See the accompanying copy of User_Routines_Fast.c to see how
this is done.

Six things must be done before this software will work 
correctly on the EDU-RC:
1) The accelerometer's output is wired to analog input 1.
2) IO1 must be configured as an "INPUT" in user_routines.c/
User_Initialization().
3) The call to Set_Number_of_Analog_Channels() must configure
at least one analog channel.
4) A #include statement for the accelerometer.h header file 
must be included at the beginning of each source file that 
calls the functions in this source file. The statement should 
look like this: #include "accelerometer.h".
5) Initialize_Accelerometer() must be called from 
user_routines.c/User_Initialization().
6) The timer 2 interrupt handler, Timer_2_Int_Handler(), must
be installed in User_Routines_Fast.c/InterruptHandlerLow().
See the accompanying copy of User_Routines_Fast.c to see how
this is done.

-Kevin