Post Go back to editing

ADXL Data Misalignment

Thread Summary

The user is experiencing axis switching in an ADXL380 accelerometer when reading FIFO data. The final answer suggests that this issue is likely due to FIFO data misalignment, which can occur if the SPI transaction is not completed before a new sample is generated. To resolve this, the user should reset the FIFO after each read and add a small delay, ensuring the SPI clock rate is sufficiently high (at least 4 MHz) to meet the timing requirements.
AI Generated Content
Category: Software
Product Number: ADXL380
Software Version: C

Hello, 

I have created a proprietary board which utilizes an ADXL380 as the accelerometer. 

THE SETUP: 

My ADXL380 is being configured with the following settings:

Register # Value Purpose
0x26
0b10000000
Enter standby mode to update registers
0x27 0b01111000 Enable X,Y,Z and FIFO
0x30 0b01100000 Enable Channel ID and FIFO Stream
0x31 0b00001100 Number of samples per watermark (we aren't using watermark so this shouldn't matter (?)
0x2B 0b00001100 Enable FIFO watermark and Overrun interrupt (again, neither being used)
0x50
0b01110000
DCF enabled + EQ_Bypass_enabled (req for LPf) + 1/16 ODR LPF + no HPF
0x26
0b10000100
running on LP mode, +-16g range

THE ISSUE: 

This project started with the best of intentions. I wanted to write code which checked the FIFO fill levels and interrupted on the watermark bit to smoothly take samples at regular intervals. The real world is unfortunately a messy place where idealistic code rarely survives. Over the course of this project, the code has evolved greatly and now I am taking data simply whenever possible.

My board receives external interrupts at 100Hz and I put out accelerometer data into the output buffer in between these moments. It works well and consistently for the most part, although I am seeing a very strange issue where the axes will simply switch. X will become Y, Y will become Z and Z will become X. I have done absolutely all I can to try to replicate this error through software to no avail.

In the documentation, I saw this warning: "Note that when retrieving data from the FIFO, each full sample, that is one set of all enabled axes, must be read in a burst (or multibyte) read operation to avoid data loss or misalignment". I always aim to do that, and am reading 19*9 samples from the FIFO register as a multibyte read operation, but I believe that this function commonly gets interrupted by UART transmissions or timing signals which are a priority to catch. 

Over ~6 months of deployment I have seen the error maybe 10 times or so making me very bearish on my chances of seeing it happen live and being able to halt everything to examine under a breakpoint. 

MY QUESTION:

Is this behaviour something which is known to occur rarely when I fail to do a full multibyte read? I cannot see anywhere in my code where this behaviour could be exhibited and I have narrowed it down (I believe) the data which is coming out of the ADXL380. The behaviour seems to persist across multiple samples and immediately after reading the ADXL I ensure the samples I am reading have the corresponding channel IDs - The only way I can see this happening is if the data gets misaligned to the channel ID. I do not believe it is the work of random noise on the HI byte of the data, since although it is somewhat likely for two of the channels to show channel ID-esque values [00 and 01] I would expect the channel under gravity to have a HI byte nowhere NEAR [02]. If this value appeared during a measurement, the behaviour would not persist. I am also seeing this behaviour on static machinery where I would not expect to see values in this range 0x02XX for any channel. 

The bedrock of my question is: 
Is this a known issue which stems from my abuse of the FIFO buffer? Or is there something I haven't thought of / discovered in my own code which could be leading to this event. If it is the former, I will cut my losses and use post-processing to address it and for the latter I will allocate more development time.

Thanks!

  • Hi ,

    Based on your description, the behaviour you are observing is consistent with FIFO data misalignment.

    To avoid sample loss or FIFO data misalignment, the SPI transaction must be completed and the CS line deasserted before a new sample becomes available. In practice, this means that all the required FIFO data must be read before the sensor generates the next sample.

    At a 2 kHz ODR (LP mode), a new sample becomes available every 500 µs. Therefore, the burst read operation must be completed within this time budget. If you are reading 19 samples (plus any additional status information), this should not be an issue with an 8 MHz SPI clock. However, at SPI clock speeds below 4 MHz, it may become more challenging to guarantee sufficient timing margin.

    If you are already operating at a high SPI clock rate, I would also recommend resetting the FIFO after each read operation and adding a small delay, as shown in the diagram below. This can be implemented, for example, by temporarily adding two extra SPI writes  before re-enabling the desired FIFO mode (you can repeat two more times Set FIFO_Mode = 0.

    With this approach, FIFO misalignment should be avoided.

    Please also note that, due to these timing constraints, the latest datasheet revision restricts the use of Stream Mode to ULP and HS operating modes. The complete FIFO contents cannot always be read within the available timing budget in the other operating modes. That said, depending on the application, SPI clock rate, and FIFO read strategy, some configurations may still operate reliably in practice.

    I hope this helps.

Before You Switch


Switching languages will make ADI Explorer unavailable. Resume your session by switching back to English and reopening ADI Explorer.