Update of /cvsroot/firebug/mts400/apps/TestADXL
In directory sc8-pr-cvs1:/tmp/cvs-serv12319
Added Files:
Makefile adxl.nc adxlM.nc
Log Message:
Test application for adxl.
--- NEW FILE: Makefile ---
COMPONENT=adxl
SENSORBOARD=adxl
include ../Makelocal
include $(TOSROOT)/apps/Makerules
--- NEW FILE: adxl.nc ---
/* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */
configuration adxl {
}
implementation {
components Main,
adxlM,
MicaWbSwitch,
TimerC,
NoLeds,
LedsC,
Accel;
adxlM.Leds -> LedsC;
adxlM.Timer -> TimerC.Timer[unique("Timer")];
Main.StdControl -> adxlM;
Main.StdControl -> TimerC;
adxlM.AccelControl -> Accel.StdControl;
adxlM.AccelCmd -> Accel.AccelCmd;
adxlM.AccelX -> Accel.AccelX;
adxlM.AccelY -> Accel.AccelY;
}
--- NEW FILE: adxlM.nc ---
/* -*- Mode: C; c-basic-indent: 3; indent-tabs-mode: nil -*- */
/**
* Displays ADXL output.
*
* Output results through mica2 uart port.
* Connect serial cable from programming
* board to PC to monitor ouput. Use any
* terminal monitoring program set for
* 57600, N,8,1
*
* NOTE:
* No real power strategy; just turns sensors on sequentially.
* Should add BusArbitration routines, like mica2dotwb
* for better power control
*/
module adxlM {
provides interface StdControl;
uses {
interface Timer;
interface Leds;
interface StdControl as AccelControl;
interface I2CSwitchCmds as AccelCmd;
interface ADC as AccelX;
interface ADC as AccelY;
}
}
implementation {
#include "SODebug.h"
#define ACCEL_POWER_OFF 0
#define ACCEL_POWER_ON 1
enum {START, BUSY};
uint16_t AccelData;
command result_t StdControl.init() {
init_debug();
call Leds.init();
call AccelControl.init();
return SUCCESS;
}
command result_t StdControl.start() {
call Leds.redOn();
call Leds.yellowOn();
call Leds.greenOn();
call Timer.start(TIMER_REPEAT, 500);
return SUCCESS;
}
command result_t StdControl.stop() {
return SUCCESS;
}
event result_t Timer.fired() {
call Leds.redOff();
call Leds.yellowOff();
call Leds.greenOff();
call AccelCmd.PowerSwitch(ACCEL_POWER_ON);
return SUCCESS;
}
/******************************************************************************
* ADXL202E Accelerometer
* At 3.0 supply this sensor's sensitivty is ~167mv/g
* 0 g is at ~1.5V or ~VCC/2 - this varies alot.
* For an accurate calibration measure each axis at +/- 1 g and
* compute the center point (0 g level) as 1/2 of difference.
* Note: this app doesn't measure the battery voltage, it assumes 3.2 volts
* To getter better accuracy measure the battery voltage as this effects the
* full scale of the Atmega128 ADC.
* bits/mv = 1024/(1000*VBATT)
* bits/g = 1024/(1000*VBATT)(bits/mv) * 167(mv/g)
* = 171/VBATT (bits/g)
* C = 0.171/VBATT (bits/mg)
* Accel(mg) ~ (ADC DATA - 512) /C
*****************************************************************************/
async event result_t AccelY.dataReady(uint16_t data){
float Accel, C;
float VBATT = 3.2;
C = 0.171/VBATT;
atomic {
Accel = ((float)AccelData - 512.0)/C;
SODbg(DBG_BOOT, "AccelX data %i AcceX(mg) %i \n",AccelData, (int)Accel);
}
Accel = ((float)data - 512.0)/C;
SODbg(DBG_BOOT, "AccelY data %i AcceY(mg) %i \n",data, (int)Accel);
call AccelCmd.PowerSwitch(ACCEL_POWER_OFF);
return SUCCESS;
}
async event result_t AccelX.dataReady(uint16_t data){
atomic {
AccelData = data;
}
call AccelY.getData();
return SUCCESS;
}
event result_t AccelCmd.SwitchesSet(uint8_t PowerState) {
call Leds.greenToggle();
if (PowerState) {
call AccelX.getData();
}
return SUCCESS;
}
}
|