AnsweredAssumed Answered

Understand ADXL345 output

Question asked by memphile on Nov 27, 2014
Latest reply on Dec 1, 2014 by Achim

Hi Folks,

I am newbie in MEMS domain. In order to learn MEMS motion sensors (for few undecided projects) I borrowed an RL78/ADXL345 board from friend and started playing with it. I am attempting to derive simple velocity/distance in X direction via integration.

 

 

1. I have put the board on horizontal table. At this time I expect ax to be zero, after being compensated for 0g. I see that ADXL345, does give zero values for ax, when I push the board in x direction gently, I see non-zero accel in x dir. However, after 25 sec or so, the velocity seems to drift. Could someone help me understand this, please ? I do expect velocity to become inaccurate, due to integration, but not as early as 25 sec. My code is given below.

 

 

2. Init - ADXL345 like this -

 

   /* accelerometer data format                     */

   /* range +/- 16g                                        */

   /* right justified with sign extension           */

   /* Full resolution mode                              */

    WriteIIC(ADXL345_ADDR, DATA_FORMAT_REG, 0x3);

 

   /* put FIFO into FIFO mode                     */

    WriteIIC(ADXL345_ADDR, FIFO_CTRL, 0x40);

 

    /* set x offset register                         */

    /* this value is determined by just turning on adxl345, and observing x-axis accel from DATAX0 */

    WriteIIC(ADXL345_ADDR, OFSX, 0xFF);

 

     /* set Sample rate              400 Hz       */

    WriteIIC(ADXL345_ADDR, BW_RATE, 0x0c);

 

   /* take accelerometer out of standby mode        */

    WriteIIC(ADXL345_ADDR, POWER_CTRL, 0x08);



3. Here is how I determine velocity/distance. I am averaging acceleration in X dir with previous sample.


  while (1U)

  {

   

    if ((fifo_lvl = ADXL345_GetFifoLevel()) > 0)

    {

      sprintf(buff, "Fifo Lvl: %d      ", fifo_lvl);

      DisplayLCD(LCD_LINE3, (uint8_t *) buff);

      ADXL345_ReadFifo(fifo_data);     

     

      /* scale factor for +/- 16g range */

      ax = ((float)((fifo_data[1] << 8) | fifo_data[0])*31.0/1000.0);

      sprintf(buff, "X axis: %f      ", ax);      

      DisplayLCD(LCD_LINE4, (uint8_t *) buff);     

 

       /* velocity by inregration */

      /* value of delay = 1/ sample freq = 2.5 ms /*

      new_velocityx = old_velocityx + (((ax+old_ax)*(float)delay)/2.0)/1000.0;

      sprintf(buff, "velx: %f      ", new_velocityx);       

      DisplayLCD(LCD_LINE5, (uint8_t *) buff);

 

      old_velocityx = new_velocityx;

      old_ax = ax;

}

Outcomes