Interfacing with ADXL345 at 3200 hz

Hello arduino community,

I have a Duemilanove and I'm planing to work on a project that requires vibration measurements.

I looked at the different types of accelerometers, and only the ADXL345 have a high bandwidth (sampling rate), I will most likely be measuring vibration at about 1kHz, therefore at least 3kHz sampling is required.

My question is, will Duemilanove be capable of handling 3.2kHz sampling time? I know that the it's running at 16MHz, but will that be capable of doing all the calculations at the same time as reading the input at 3.2kHz? If not, what are the alternatives?

Thanks in advance.

Sorry I posted in the wrong section, please move it to hardware interfacing...

'all the calculations' ?

You haven't specified what calculations need to be performed.

For example taking the average G's over 10 seconds

High bandwidth and averaging for 10 seconds just make a lot of sense in my head

What dataformat is spit out by the ADXL345 ? 8 bit, float string? analog voltage?
What is its interface? a serial line? I2C?
do you have a link to a datasheet?

suppose serial , 1 byte per dimension
1000 samples of 3 bytes => 3000 bytes => 30.000 baud ; can be handled easily.

Calculating the average is simple, add up all values over 10 seconds and divide by the amount. then reset all counters.
10 seconds x 1000 samples per second x 1 byte per sample = 10.000 bytes => max value is 2.560.000 => implies you need a long
note : you need 3 average counters?

If you have the 3G's, do you calculate the absolute acceleration of the three combined ? (pythagoras in 3 dimensions) and calc an average too?

Rob

Here's a link to the data sheet:
http://www.analog.com/static/imported-files/data_sheets/ADXL345.pdf

10 bit resolution, SPI or I2C (most likely will be using SPI)

Yes, I do need an average counter on all three axis, but probably wont need an absolute value.

About the datarate:
10 bit resolution and 3000 samples => 6000 bytes per second => 60.000 bit. WestFw states in http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1230552568 that SPI could run at 100Mhz so it should be possible and still have some time to do some math.

About the Average:
If you want an exact average over 10 seconds you need to add up 10.000 values of a 10 bit number (0-1023) and divide that by 10.000.
Worst cast it sums up to 1023* 10.000 = 10.230.000 which fits very well in the long data type.

in pseudocode the main loop could like

byte buffer[6];      // to hold the registers 32-37 XXYYZZ

long X;
long Y;
long Z;           
long S;   // total Spatial acceleration 

long AvgX= 0;
long AvgY= 0;
long AvgZ= 0;
long AvgS= 0;

#define COUNT  10000

void loop()
{

  // do the 10.000 samples
  for (int i= 0; i< COUNT  ; i++)
  {
     GetRegisterADXL345(buffer, 32, 6);  // fetch the 6 relevant bytes from the register in one read operation - to be written
    X = word(buffer[1], buffer[0]) ;
    Y = word(buffer[3], buffer[2]) ;
    Z = word(buffer[5], buffer[4]);

    S = sqrt(X*X + Y*Y + Z*Z);

    AvgX += X;
    AvgY += Y;
    AvgZ += Z;
    AvgS += S;
  }

  AvgX /= COUNT;
  AvgY /= COUNT;
  AvgZ /= COUNT;
  AvgS /= COUNT;

  // display data or so.

}

This pseudocode just shows the main structure could be, you probably need to add some timing to sample every millisec.

Please note page 26 about the XYZ -registers It is recommended that a multiple-byte read of all registers be performed to prevent a change in data between reads of sequential registers.

succes,
Rob