2018-05-27 09:12 AM
Hi, I'm using an LIS3DSH in a case where I want to periodically (say once every 50 milliseconds) get the most recent X,Y,Z position of the accelerometer and perform a calculation.
My current approach is to just set a timer on my MCU to interrupt every 50 milliseconds. During this interrupt routine I simply query the OUT_X, OUT_Y and OUT_Z registers of the LIS3DSH and then immediately perform my calculations.
I've configured the block data update value (in register CTRL_REG4) on the LIS3DSH to 'continuous' and I'm not using the FIFO feature either (FIFO_CTRL = 'Bypass mode: FIFO turned off'). Additionally, I've configured the output data rate (
in register CTRL_REG4) to 100 Hz.
Am I correct to believe this will result in the OUT_X, OUT_Y and OUT_Z register values continually being updated with the very latest accelerometer position data every 10 milliseconds?
If so, this would make a worst case scenario of the X, Y, Z position data being 10 milliseconds old when performing my calculation, which is within my requirements.
I'd very much appreciate any feedback on my above approach being incorrect or less than optimal in any way. Thanks.
-Terence
#lis3dshSolved! Go to Solution.
2018-05-29 02:03 AM
Yes, I agree with you.
I'm sorry, I miss that point in your first post, you should set the BDU to 1 in CTRL_REG4 to avoid the discrepancy.
You could also use the DRDY signal so the MCU you receive an interrupt when new data are available, in this case you could read actual data with minimum delay.
2018-05-27 11:33 PM
Yes, this assumption are absolutely correct.
2018-05-28 02:22 PM
Miroslav - Thank you for the feedback. One concern: Since I have
the block data update value (in register CTRL_REG4) of the LIS3DSH set to 'continuous'
I suppose it's possible when I read the OUT_X_L and OUT_X_H values they could be from two different readings right?
I read these registers immediately one after another (OUT_X_L first then OUT_H_L) and I'm using I2C 'fast mode' (400 kHz) but it's possible the following could happen in the given order:
I retrieve the value of OUT_X_L (register 0x28)
The LIS3DSH internally updates the OUT_X_L and OUT_H_L registers with new readings
I retrieve the value of OUT_X_H (register 0x29)
So, in other words, for my 16 bit X value (comprised of both OUT_X_L and OUT_X_H), I'm using the high bits from the most recent update and the low bits from the previous update.
Do you agree this is a possibility?
2018-05-29 02:03 AM
Yes, I agree with you.
I'm sorry, I miss that point in your first post, you should set the BDU to 1 in CTRL_REG4 to avoid the discrepancy.
You could also use the DRDY signal so the MCU you receive an interrupt when new data are available, in this case you could read actual data with minimum delay.