陀螺仪
嗨,
我在使用LSM9DS1 FIFO时遇到了一些问题......
我的目标是在不丢失样品的情况下不断获取陀螺仪和加速数据。 (磁力计关闭)
这就是我做的:
- 我将水印阈值设置为21个样本(IMU_FIFO_samples = 21
(IMU_FIFO_samples = FlashBuffer_Initi alize(IMU_6);)
- 我将中断配置为发送到引脚INT1_A / G.
(LSM9DS1_configInt(XG_INT1,INT_FTH,INT_ACTIVE_HIGH,INT_PUSH_PULL);)
- 我在旁路模式下配置FIFO(LSM9DS1_setFIFO(FIFO_OFF,IMU_FIFO_samples);)
-
- 为了开始数据采集,我在连续模式下配置FIFO(LSM9DS1_setFIFO(FIFO_CONT,IMU_FIFO_samples);)
(我确实尝试将IMU_SAMPLE_RATE设置为14Hz和900 + Hz,但结果是一样的)
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; //已禁用
tst = LSM9DS1_begin();
LSM9DS1_enableBLE(真); //大小印第安人
LSM9DS1_enableBDU(真); //阻止数据更新
LSM9DS1_configInt(XG_INT1,INT_FTH,INT_ACTIVE_HIGH,INT_PUSH_PULL);
// LSM9DS1_setFIFO(FIFO_CONT,IMU_FIFO_samples);
LSM9DS1_enableFIFO(真);
__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);
返回BT_OK;
}
生成中断时,将调用以下ISR
void Data_Acquisition_IMU(void)
{
...
//从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);
}
...
}
++++问题++++
偶尔(经常但不总是)从FIFO读取的数据块是错误的(参见附图)
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);
}
我从FIFO中读取了12 * 21 = 252字节的块,有时数据看起来不对(参见附图)
数据应始终为0但对于az。
为了调试程序,我一直在读取调用ISR时FIFO中可用的数据样本数。
//从IMU读取数据
// n5 = LSM9DS1_getFIFOSamples();
// n4 = LSM9DS1_getFIFOSamples();
// n3 = LSM9DS1_getFIFOSamples();
n = LSM9DS1_getFIFOSamples();
读n5,n4,n3和n我读取不一致的值
uint8_t LSM9DS1_getFIFOSamples(void)
{
return(LSM9DS1_xgReadByte(FIFO_SRC)& 0x3F);
}
有时n5 = 0(即使在FIFO中应该调用ISR时应该有21个样本)并且在我读取n4 = 21(预期值)之后立即调用
- >为什么我读n5 = 0 ???
有时n5 = 21但是我得到n4 = 0x3F
- >报告的FIFO中的样本数量突然变化了?
有时n5 = n4 = n3 = n = 21并且我读取FIFO数据
LSM9DS1_readAccelGyro_nAll(& FlashBufferIMU [ptr],IMU_FIFO_samples);
有时当我读取FIFO中的剩余样本时,而不是读取0,或者最多只读取一小部分,我得到0x3F
一旦我得到0x3F,为了在FIFO中读取有意义的数字样本,重置FIFO设置FIFO_OFF并通过设置FIFO_CONT重新启用它
有关如何解决它的任何线索?
谢谢
#fifo#lsm9ds1
以上来自于谷歌翻译
以下为原文
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 #lsm9ds1
更多回帖