完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
嗨,
我正在研究LIS3DH加速计传感器,我已经使用SPI接口将该传感器与STM32F103系列微控制器连接。当我读取X,Y和Z加速度值时,我会得到一些随机读数,而且它的波动很大。传感器水平放置在PCB上,平行于X,Y轴并垂直于Z轴。所有三个轴的读数都在0.01到-0.15左右波动。在初始化中,所有三个轴都已启用。 由于我对加速度计传感器很陌生,我的理解是,在上面提到的位置,我应该得到0和0左右的g和0左右的g值和1左右的Z轴是否正确? 或者它只是在传感器有一些运动时显示X,Y和Z轴值的波动,并且当传感器静止时它再次获得稳定值? 以上来自于谷歌翻译 以下为原文 Hi, I am working on LIS3DH accelerometer sensor, I have interfaced this sensor with STM32F103 series micro controller using SPI interface. When I read X, Y and Z acceleration values, I get some random readings and it too fluctuate lot. The sensor is placed horizontal on PCB, parallel to X , Y axis and perpendicular to Z axis. The reading for all three axes is fluctuate around 0.01 to -0.15. In initialization, all three axes has been enabled. As I am very new to accelerometer sensor, is my understanding that in the position mentioned above should I get g value for X and Y axis around 0g and for Z axis around 1g correct? OR it just shows fluctuations in X,Y and Z axis value when there is some movement of sensor and again it get stable value when the sensor is stationary? |
|
相关推荐
8个回答
|
|
非常感谢你的回复。请参考以下详细信息。
/ *加速度计寄存器地址定义* / #define Status_Reg1((u8)0x07) #define Who_Am_I((u8)0x0F) #define Ctrl_Reg1((u8)0x20) #define Ctrl_Reg2((u8)0x21) #define Ctrl_Reg3((u8)0x22) #define Ctrl_Reg4((u8)0x23) #define Ctrl_Reg5((u8)0x24) #define Ctrl_Reg6((u8)0x25) #define Status_Reg2((u8)0x27) #define Out_X_L((u8)0x28) #define Out_X_H((u8)0x29) #define Out_Y_L((u8)0x2A) #define Out_Y_H((u8)0x2B) #define Out_Z_L((u8)0x2C) #define Out_Z_H((u8)0x2D) #define INT1_CFG((u8)0x30) #define INT1_SRC((u8)0x31) #define INT1_THS((u8)0x32) #define INT1_DURATION((u8)0x33) #define CLICK_CFG((u8)0x38) #define CLICK_SRC((u8)0x39) #define CLICK_THS((u8)0x3A) #define TIME_LIMIT((u8)0x3B) #define TIME_LATENCY((u8)0x3C) #define TIME_WINDOW((u8)0x3D)以下是加电时的传感器配置。 / *问我是谁来确认硬件状态* / retCode = ACCELEROMETER_Read(Who_Am_I,&amp; tmp); if((tmp == 0x33)&amp;&amp;(retCode == 0)) { MEMS_DEVICE.HardWareSta = DEF_MEMS_NONE_ERR; retCode = 0; #if(DEF_ADDINFO_OUTPUTEN&gt; 0) 的printf( '[ACC]:OK! r n'); #万一 } 其他 { MEMS_DEVICE.HardWareSta = DEF_MEMS_DEVICE_ERR; retCode = -1; #if(DEF_ADDINFO_OUTPUTEN&gt; 0) 的printf( '[ACC]:错误! r n'); #万一 if(MEMS_DEVICE.HardWareSta!= DEF_MEMS_DEVICE_ERR) { ACCELEROMETER_Write(Ctrl_Reg1,0x57); // 0101:正常/低功耗模式(100Hz),0:正常模式,111:XYZ使能。 // ACCELEROMETER_Read(CTRL_REG1,&安培; TMP); ACCELEROMETER_Write(Ctrl_Reg2,0x89); //高通过滤器启用 // ACCELEROMETER_Read(Ctrl_Reg2,&安培; TMP); ACCELEROMETER_Write(Ctrl_Reg3,0x00); //禁用INT // ACCELEROMETER_Read(Ctrl_Reg3,&安培; TMP); ACCELEROMETER_Write(Ctrl_Reg4,0x08); // 2:满量程选择+/- 2G高分辨率启用 // ACCELEROMETER_Read(Ctrl_Reg4,&安培; TMP); ACCELEROMETER_Write(Ctrl_Reg5,0x00); //未锁存INT1 IO // ACCELEROMETER_Read(Ctrl_Reg5,&安培; TMP); ACCELEROMETER_Write(Ctrl_Reg6,0x02); // INT1 IO低电平有效(??) // ACCELEROMETER_Read(Ctrl_Reg6,&安培; TMP); ACCELEROMETER_Write(INT1_DURATION,0x00); //设置INT1模式OR,高事件 // ACCELEROMETER_Read(INT1_DURATION,&安培; TMP); ACCELEROMETER_Write(INT1_CFG,0x2A); //设置INT1模式OR,高低事件0X3F // ACCELEROMETER_Read(INT1_CFG,&安培; TMP); 以下是根据存储在非易失性存储器中的用户配置的INT1阈值。 BSP_ACCELEROMETER_SetInt1Threshold(s_Cfg.accMThreshold,2000); BSP_ACCELEROMETER_SetInt1Duration(s_Cfg.accMDuration,2000); g值计算功能。 s8 BSP_ACCELEROMETER_ReadXYZ(MEMS_data_Typedef * MEMS_data,u16超时) { s8 retCode = 0; u8 X_data_h = 0,X_data_l = 0,Y_data_h = 0,Y_data_l = 0,Z_data_h = 0,Z_data_l = 0,tmp = 0; s16 tmpdata = 0; double x_acc = 0,y_acc = 0,z_acc = 0; ACCELEROMETER_Read(Out_X_L,&安培; X_data_l); ACCELEROMETER_Read(Out_X_H,&安培; X_data_h); //读取Y数据 ACCELEROMETER_Read(Out_Y_L,&安培; Y_data_l); ACCELEROMETER_Read(Out_Y_H,&安培; Y_data_h); //读取Z数据 ACCELEROMETER_Read(Out_Z_L,&安培; Z_data_l); ACCELEROMETER_Read(Out_Z_H,&amp; Z_data_h); / *计算数据* / tmpdata = X_data_l; tmpdata | =(X_data_h&lt;&lt; 8); MEMS_data-&gt; X_data = tmpdata; tmpdata = Y_data_l; tmpdata | =(Y_data_h&lt;&lt; 8); MEMS_data-&gt; Y_data = tmpdata; tmpdata = Z_data_l; tmpdata | =(Z_data_h&lt;&lt; 8); MEMS_data-&gt; Z_data = tmpdata; x_acc =((double)MEMS_data-&gt; X_data)/ 16380; y_acc =((double)MEMS_data-&gt; Y_data)/ 16380; z_acc =((double)MEMS_data-&gt; Z_data)/ 16380; printf(' r n [ACC]:X =%lf,Y =%lf,Z =%lf',x_acc,y_acc,z_acc); return retCode; } 以上来自于谷歌翻译 以下为原文 Thank you so much for your response. Please refer below details. /* accelerometer register address define */ #define Status_Reg1 ((u8)0x07) #define Who_Am_I ((u8)0x0F) #define Ctrl_Reg1 ((u8)0x20) #define Ctrl_Reg2 ((u8)0x21) #define Ctrl_Reg3 ((u8)0x22) #define Ctrl_Reg4 ((u8)0x23) #define Ctrl_Reg5 ((u8)0x24) #define Ctrl_Reg6 ((u8)0x25) #define Status_Reg2 ((u8)0x27) #define Out_X_L ((u8)0x28) #define Out_X_H ((u8)0x29) #define Out_Y_L ((u8)0x2A) #define Out_Y_H ((u8)0x2B) #define Out_Z_L ((u8)0x2C) #define Out_Z_H ((u8)0x2D) #define INT1_CFG ((u8)0x30) #define INT1_SRC ((u8)0x31) #define INT1_THS ((u8)0x32) #define INT1_DURATION ((u8)0x33) #define CLICK_CFG ((u8)0x38) #define CLICK_SRC ((u8)0x39) #define CLICK_THS ((u8)0x3A) #define TIME_LIMIT ((u8)0x3B) #define TIME_LATENCY ((u8)0x3C) #define TIME_WINDOW ((u8)0x3D)Below is the sensor configuration at power up. /* Ask who am I to comfirm the hardware status */ retCode =ACCELEROMETER_Read(Who_Am_I,&tmp); if((tmp == 0x33) && (retCode == 0)) { MEMS_DEVICE.HardWareSta = DEF_MEMS_NONE_ERR; retCode =0; #if(DEF_ADDINFO_OUTPUTEN > 0) printf('[ACC]:OK!rn'); #endif } else { MEMS_DEVICE.HardWareSta = DEF_MEMS_DEVICE_ERR; retCode =-1; #if(DEF_ADDINFO_OUTPUTEN > 0) printf('[ACC]:Error!rn'); #endif }if(MEMS_DEVICE.HardWareSta != DEF_MEMS_DEVICE_ERR) { ACCELEROMETER_Write(Ctrl_Reg1,0x57);//0101:normal/low power mode (100Hz),0:normal mode,111:XYZ enable. //ACCELEROMETER_Read(Ctrl_Reg1,&tmp); ACCELEROMETER_Write(Ctrl_Reg2,0x89);//high pass filter enable //ACCELEROMETER_Read(Ctrl_Reg2,&tmp); ACCELEROMETER_Write(Ctrl_Reg3,0x00);//disable INT //ACCELEROMETER_Read(Ctrl_Reg3,&tmp); ACCELEROMETER_Write(Ctrl_Reg4,0x08);//2: Full scale selection +/- 2G High resolution enable //ACCELEROMETER_Read(Ctrl_Reg4,&tmp); ACCELEROMETER_Write(Ctrl_Reg5,0x00);//INT1 IO not latched //ACCELEROMETER_Read(Ctrl_Reg5,&tmp); ACCELEROMETER_Write(Ctrl_Reg6,0x02);//INT1 IO active low(??) //ACCELEROMETER_Read(Ctrl_Reg6,&tmp); ACCELEROMETER_Write(INT1_DURATION,0x00);//set INT1 mode OR, high event //ACCELEROMETER_Read(INT1_DURATION,&tmp); ACCELEROMETER_Write(INT1_CFG,0x2A);//set INT1 mode OR, high and low event 0X3F //ACCELEROMETER_Read(INT1_CFG,&tmp); }Below is are INT1 threshold value as per user configuration stored in non volatile memory. BSP_ACCELEROMETER_SetInt1Threshold(s_Cfg.accMThreshold, 2000); BSP_ACCELEROMETER_SetInt1Duration(s_Cfg.accMDuration, 2000); g value calculation function. s8 BSP_ACCELEROMETER_ReadXYZ(MEMS_data_Typedef *MEMS_data,u16 timeout) { s8 retCode=0; u8 X_data_h=0,X_data_l=0,Y_data_h=0,Y_data_l=0,Z_data_h=0,Z_data_l=0,tmp=0; s16 tmpdata=0;double x_acc = 0, y_acc = 0,z_acc = 0; ACCELEROMETER_Read(Out_X_L,&X_data_l); ACCELEROMETER_Read(Out_X_H,&X_data_h); // read Y data ACCELEROMETER_Read(Out_Y_L,&Y_data_l); ACCELEROMETER_Read(Out_Y_H,&Y_data_h); // read Z data ACCELEROMETER_Read(Out_Z_L,&Z_data_l); ACCELEROMETER_Read(Out_Z_H,&Z_data_h);/* calculate the data */ tmpdata = X_data_l; tmpdata |= (X_data_h << 8); MEMS_data->X_data = tmpdata;tmpdata = Y_data_l; tmpdata |= (Y_data_h << 8); MEMS_data->Y_data = tmpdata;tmpdata = Z_data_l; tmpdata |= (Z_data_h << 8); MEMS_data->Z_data = tmpdata;x_acc = ((double)MEMS_data->X_data)/16380; y_acc = ((double)MEMS_data->Y_data)/16380; z_acc = ((double)MEMS_data->Z_data)/16380; printf('rn[ACC]:X=%lf, Y=%lf, Z=%lf', x_acc,y_acc,z_acc); return retCode; } |
|
|
|
好,
你启用了高通过滤器 在这种情况下,您将只看到加速度的变化,换句话说,它将删除任何DC值,如1g重力。 以上来自于谷歌翻译 以下为原文 OK, you enabled the High pass filter In this case you will see only changes in the acceleration, in other words, it will remove any DC value like 1g gravity. |
|
|
|
禁用高通滤波器后,我能够按预期获得g值。
非常感谢你的解决方案。 以上来自于谷歌翻译 以下为原文 After disabling high pass filter, I am able to get g value as expected. Thank you so much for your solution. |
|
|
|
您好Vishal,您能分享如何将原始数据转换为g值吗?寄存器设置的配置是什么?谢谢你的时间。
以上来自于谷歌翻译 以下为原文 Hi Vishal, Can you share how you convert raw data into g value? And what is the configuration of registers settings? Thanks for your time. |
|
|
|
将有符号整数转换为浮点数并根据所选的满刻度偏转模式进行缩放。
根据您希望测量的内容选择一个范围,以便获得最精细的粒度测量。 以上来自于谷歌翻译 以下为原文 Cast the signed integer to a float and scale based on the full-scale-deflection mode selected. Pick a range based on what you expect to be measuring so you get the finest granularity measurements. |
|
|
|
嗨Clive,我的控制器没有FPU(浮点单元)所以只有整数支持。您能否将原始数据的等式提供为+ -2g等级的g值?谢谢。
以上来自于谷歌翻译 以下为原文 Hi Clive, my controller is not having FPU(Floating point unit) so only integer support. Could you provide the equation for raw data into g value for +-2g scale? Thanks. |
|
|
|
你不需要一个FPU来做浮点数学,你说你想要G中的单位,而不是mG
float x =(float)X * 0.001f; //在G中12位带符号样本和+/- 2G范围 http://www.st.com/content/ccc/resource/technical/document/datasheet/3c/ae/50/85/d6/b1/46/fe/CD00274221.pdf/files/CD00274221.pdf/jcr:内容/翻译/ en.CD00274221.pdf 以上来自于谷歌翻译 以下为原文 You don't need an FPU to do floating point math, and you say you want units in G, not mG float x = (float)X * 0.001f; // in G where 12-bit signed sample, and +/-2G range http://www.st.com/content/ccc/resource/technical/document/datasheet/3c/ae/50/85/d6/b1/46/fe/CD00274221.pdf/files/CD00274221.pdf/jcr:content/translations/en.CD00274221.pdf |
|
|
|
谢谢克莱夫。所以,根据你的回答。我必须将原始值放入等式中以将数据输入G单位。我对吗?或者如果我想使用8位或10位输出样本,而不是根据数据表中的Mechanical特性表值,我必须将0.001值替换为其各自的值。我对吗?
注意:原始帖子包含大量线程对话,只能迁移到第9级 以上来自于谷歌翻译 以下为原文 Thank you Clive. So, as per your response. I have to put raw value into the equation to get the data into G unit. Am I right? or If I want to use 8-bit or 10-bit output sample than according to Mechanical characteristic table value from datasheet I have to replace 0.001 value to its respective value. Am I right? Note: the original post contained a large number of threaded conversations and was only able to be migrated to the 9th level |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2578 浏览 1 评论
3194 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1763 浏览 1 评论
3589 浏览 6 评论
5967 浏览 21 评论
924浏览 4评论
1300浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
563浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1286浏览 3评论
1338浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-5 21:26 , Processed in 1.632897 second(s), Total 91, Slave 74 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号