2017-06-28 03:38 AM
Hi,
I'm having some problem using the LSM9DS1 FIFO...
My objective is to continuously acquire, without loosing samples, the Gyro and Accelleration data. (The magnetometer is turned off)
This is what I do:
- I set the watermark threshold to 21 samples (IMU_FIFO_samples = 21
(IMU_FIFO_samples = FlashBuffer_Initialize(IMU_6);)
- I configure the interrupt to be sent to pin INT1_A/G
(LSM9DS1_configInt(XG_INT1, INT_FTH, INT_ACTIVE_HIGH, INT_PUSH_PULL);)
- I configure the FIFO in Bypass Mode (LSM9DS1_setFIFO(FIFO_OFF, IMU_FIFO_samples);)
-
- In order to start the data acquisition I configure the FIFO in Continous Mode (LSM9DS1_setFIFO(FIFO_CONT, IMU_FIFO_samples);)
(I did try to set the IMU_SAMPLE_RATE to 14Hz and 900+Hz but the results are the same)
void IMU_Initialize(void)
{
uint16_t tst;
IMU_FIFO_samples = FlashBuffer_Initialize(IMU_6);
LSM9DS1_LSM9DS1(IMU_MODE_SPI, XGADDR, MADDR);
settings.accel.sampleRate = IMU_SAMPLE_RATE;
settings.gyro.sampleRate = IMU_SAMPLE_RATE;
settings.mag.operatingMode = 0x03; // Disabled
tst = LSM9DS1_begin();
LSM9DS1_enableBLE(true); // Big Little Indian
LSM9DS1_enableBDU(true); // Block Data Update
LSM9DS1_configInt(XG_INT1, INT_FTH, INT_ACTIVE_HIGH, INT_PUSH_PULL);
//LSM9DS1_setFIFO(FIFO_CONT, IMU_FIFO_samples);
LSM9DS1_enableFIFO(true);
__delay_ms(50);
LSM9DS1_setFIFO(FIFO_OFF, IMU_FIFO_samples);
}
uint8_t Acquisition_Start(void)
{ EX_INT2_InterruptFlagClear(); EX_INT2_InterruptEnable(); LSM9DS1_setFIFO(FIFO_CONT, IMU_FIFO_samples); return BT_OK;}When the Interrupt is generated the following ISR is called
void Data_Acquisition_IMU(void)
{
...// Read Data From IMU
//n5 = LSM9DS1_getFIFOSamples();
//n4 = LSM9DS1_getFIFOSamples();
//n3 = LSM9DS1_getFIFOSamples();
n = LSM9DS1_getFIFOSamples();
LSM9DS1_readAccelGyro_nAll(&FlashBufferIMU[ptr], IMU_FIFO_samples);
n1 = LSM9DS1_getFIFOSamples();
if(n1 > 31)
{
LSM9DS1_setFIFO(FIFO_OFF, IMU_FIFO_samples);
n3 = IMU_INT1_AG_GetValue();
n2 = LSM9DS1_getFIFOSamples();
EX_INT2_InterruptFlagClear();
n4 = LSM9DS1_getFIFOSamples();
LSM9DS1_setFIFO(FIFO_CONT, IMU_FIFO_samples);
}
...
}
++++ PROBLEMS ++++
Once in a while (quite often but not always) the block of data read from the FIFO is wrong (See attached picture)
LSM9DS1_readAccelGyro_nAll(&FlashBufferIMU[ptr], IMU_FIFO_samples);
void LSM9DS1_readAccelGyro_nAll(uint8_t *data, uint8_t n)
{
LSM9DS1_xgReadBytes(OUT_X_L_G, data, 12*n);
}
I read 12*21 = 252 bytes blocks from the FIFO and sometime the data look wrong (see attached picture)
The data should be always 0 but for az.
In order to debug the program I have been reading the number of data samples available in the FIFO when the ISR is called.
// Read Data From IMU
//n5 = LSM9DS1_getFIFOSamples(); //n4 = LSM9DS1_getFIFOSamples(); //n3 = LSM9DS1_getFIFOSamples(); n = LSM9DS1_getFIFOSamples();Reading n5, n4, n3 and n I read inconsistent values
uint8_t LSM9DS1_getFIFOSamples(void)
{return (LSM9DS1_xgReadByte(FIFO_SRC) & 0x3F);}Sometime n5 = 0 (even if the ISR should be called when in the FIFO there should be 21 samples) and immediately after I read n4 = 21 (the expected value)
--> WHY I READ n5 = 0 ???
Sometime n5 = 21 but then I get n4 = 0x3F
--> The reported number of samples in the FIFO changes abruptly ???
Sometime n5 = n4 = n3 = n = 21 and I read the FIFO data
LSM9DS1_readAccelGyro_nAll(&FlashBufferIMU[ptr], IMU_FIFO_samples);
Sometime when I read the remaining samples in the FIFO, instead of reading 0, or at most a small number, I get 0x3F
Once I get 0x3F, in order to read meaningful number samples in the FIFO is to reset the FIFO setting the FIFO_OFF and the re-enabling it by setting FIFO_CONT
Any clue on how to fix it?
Thank you
#fifo #lsm9ds12017-06-28 07:34 AM
Solved...
There was an interrupt conflict while communicating with the LSM9DS1