AnsweredAssumed Answered

The Problem about Z-axis of ADXL345,It is interesting for everyone can help find where the mistake happen?

Question asked by xlwuhai on May 23, 2013
Latest reply on May 5, 2016 by Anthony.DeSimone

1.I use FPGA(spartan6 xc6slx9 miniBoard) connect ADXL345 with 4-wire SPI. And the driver privided by ADI(ATofan) thanks first!
2.Configure Sensor:
  0x31 DATA_FORMAT 0x0B  +-16g,13-Bit Mode
  0x2C BW_RATE     0x0D  ODR:800Hz
  0x2D POWER_CTL   0x08  Start Measurement
3.When place sensor in X = 0g, Y = 0g,  Z = +1g. The data show

Device ID:E5
X Axis:-159  Y Axis:-27  Z Axis:1375
X Axis:-159  Y Axis:-20  Z Axis:1373
X Axis:-162  Y Axis:-18  Z Axis:1380
X Axis:-160  Y Axis:-19  Z Axis:1379
X Axis:-161  Y Axis:-19  Z Axis:1376
X Axis:-162  Y Axis:-19  Z Axis:1380
X Axis:-161  Y Axis:-22  Z Axis:1383
X Axis:-160  Y Axis:-19  Z Axis:1379
X Axis:-160  Y Axis:-24  Z Axis:1381
....................................

4.Question:
Z is about 1/0.0039 = 255,but here is too large
X is the same problem, anyone who met the problem, and how to solve?

5.Part Code
int main(void)
  {
      unsigned char Device_ID;
      short X_val,Y_val,Z_val;


   SPI_Init(SPI_BASEADDR, 0, 1, 1);
   ADXL345_Init();

   Device_ID= ADXL345_ReadReg(ADXL345_DEVID);

   xil_printf("Device ID:%x\n",Device_ID);

   while(1)
        {
      Acc_fixed_measure(&acc_x,&acc_y,&acc_z);

      xil_printf("X Axis:%d  Y Axis:%d  Z Axis:%d\n",acc_x,acc_y,acc_z);

       }

   return 0;
  }

void ADXL345_Init(void)
{

ADXL345_WriteReg(ADXL345_DATA_FORMAT,0x0B); //Self-Test=0 SPI=0 INT_Invert=0 0  FULL_RES = 1  Justify=0 D1=1 D0=1 16G
ADXL345_WriteReg(ADXL345_BW_RATE,0x0D);     //ODR:800Hz BandWidth:400Hz
ADXL345_WriteReg(ADXL345_POWER_CTL,0x08);
ADXL345_WriteReg(ADXL345_INT_ENABLE,0x80);
}

Outcomes