We are getting sporadic wrong accelerometer readings ('spikes') from ADXL345. Depending on the configuration, the wrong reading can show up after a few minutes, although sometimes it has taken up to 10 hours. Fortunately, we have found that increasing the value of the output data rate (BW_RATE register) reduces the time between 'spikes', making it easier to reproduce.
The company I work for has been using ADXL345 in several products, and we have sold thousands of units with it since 2012. In spite of that, we have never noticed this anomaly because we have always filtered the output before using the acceleration values. It was just after a recent change in the software, in which we included a more strict "out of range" detection algorithm, that we started to notice these spikes. More information about our tests and SPI configuration can be found below, but at this point I will just clarify that we have not changed the way in which we collect the data from the SPI bus, we have just added a monitor to detect "strange" raw values from the DATAX, DATAY and DATAZ registers.
We have found in the Q&A database a possible relationship with these two other unresolved cases:
ez.analog.com/.../adxl345-gives-erratic-output-data-intermittently
ez.analog.com/.../issue-at-adxl345
In all our tests, the wrong reading is always isolated (i.e. just one sample is wrong, previous and following samples seem to be OK). Additionally, we have managed to observe some "pattern" in the errors, they all show up in one of these two forms:
1. One or more axes report 0 (raw value)
2. The value of Z axis is extremely high
In order for all tests to be consistent, the ADXL345 was always placed on a desk so that we would normally read values of around -1G for the Z axis, and values very close to 0 in the X and Y axes. Knocking on the desk where the ADXL345 was placed would cause a momentary increase in the acceleration values. Such knock was noticeable in the sensor output values across several samples, whereas the spikes are completely isolated and do not respond to any external stimulus.
We first thought that maybe the unit we were testing could be damaged, so we tested also other PCBs and we managed to observe the same problem. For that, we then purchased an evaluation board "EVAL-ADXL345Z" from an authorized distributor. We got the same problem with the evaluation board, so we tried connecting different CPUs to make sure there was not a problem in the SPI controller that we were using. So far we have managed to detect the isolated spikes using 4 different SoCs from 3 different manufacturers, particularly:
- Atmel AT91SAM7X512
- Atmel SAMA5D2
- NXP LPC1768 (mbed)
- Freescale MK20DX256VLH7 (Teensy 3.2)
We have checked that the values which we are decoding from the DATAX, DATAY and DATAZ registers match the data observed in the SPI bus with an oscilloscope. Also, we have carefully checked in all cases that SPI timing constraints are compliant (with some extra margin) with the figures in the datasheet, pages 16-17. We are not having any problems to read the content of other registers (e.g. DEVID, etc), that works fine. In our product boards there are other sensors by Analog Devices attached to the same SPI bus (but of course, different chip select) and we do not get any spikes from those other sensors; this is just to say that all SPI transactions seem to be working flawlessly.
When it comes to configuration, we have carefully read the datasheet and also these two application notes to make sure we are initializing the device correctly and that we are not missing any important steps:
www.analog.com/.../AN-1025.pdf
www.analog.com/.../AN-1077.pdf
We are using SPI @4MHz and our initialization sequence is as follows:
DATA_FORMAT: 0x0E ==> 4 wire SPI, full resolution, left justify, 8G
INT_ENABLE: 0x00 ==> We don't use the interrupt pin at all.
BW_RATE: 0x0F ==> 3200 Hz sampling. We normally use 400 but 3200 is the most error-prone config.
FIFO_CTL: 0x00 ==> FIFO bypass. Also tested with FIFO and Stream modes.
PWR_CTL: 0x00 ==> Set standby mode. Suggested by datasheet when clearing Link bit (even though it has never been raised). Tests also performed without this step, no differences.
PWR_CTL: 0x08 ==> Set measuring mode.
Our test applications schedule 1 read operation every 1ms, using the multi-byte read mode, i.e. DATAX, DATAY and DATAZ registers are read in the same SPI transaction every millisecond.
Even though all the tests were done with different CPUs, they were all using the SPI bus so we decided to do a final test with the Teensy 3.2 board using I2C. This was to make sure that the spikes were not related to the communication protocol. In fact we also got spikes using I2C @400kHz with the same configuration above, except for the output data rate (BW_RATE register), which we set to 800Hz rather than 3200Hz, as this is the maximum recommended value for I2C (datasheet page 15).
We would like to understand what can be causing the observed spikes, and if there is a way to avoid getting them -thanks.