(Complete list of all blog entries in this series)
After getting the ADXL375 to run, I needed to work on storing the acceleration history. In my test project I configured the accelerometer to use a 12.5Hz data rate since that allowed to write the measured data directly to the LCD. But for my use case I need a much better resolution (the head injury criterion integrates the acceleration over a period about about 15ms, so I need at least 1ms resolution).
So I set the data rate to 1600Hz - this gives good time resolution, and even uses less power than the 800Hz data rate (but it reduces the resolution since the LSB is always 0 now). The FIFO is 32 values deep, and the notification watermark (which generates an interrupt signal) is set to 24. This way I can always read 24 values in one go and process them - that's data for exactly 15ms (which is the recommended time period).
Each time the ADXL375 triggers a high watermark interrupt, the PSoC4 reads 24 values (which are guaranteed to be there) and calculates the length of the acceleration vector. Since the ADXL needs some time to prepare the next values to be read from the FIFO, it can be used for calculation.
Together with the last 24 calculated acceleration values, the PSoC now can calculate the 24 integrals (by just summing up the values). From these integrals it calculates the maximum. It also calculates the average acceleration value, and sums it up.
Once per second another interrupt is triggered, which takes the data from the last elapsed second, and stores it away (maximum of the integrated values, maximum measured acceleration, average acceleration). If values for 60 seconds have been collected, they are aggregated again and stored per minute. This RRD structure allows to get historical data while still having.
Right now I'm just using the collected values to show average and maximum acceleration for the last second the the last minute on the LCD.
Next steps
Since the RRD storage code now works fine, I can move it to the BLE project and use it to transfer it to the Android app. I also got another LiIon battery. Its much smaller than the one I have now, even though it still has 380mAh capacity. But this is something for the next hardware update.