完善资料让更多小伙伴认识你,还能领取20积分哦, 立即完善>
当我尝试从传感器获取数据时,我遇到了一些问题。我可以读取寄存器并获取一些数据,但我不知道我应该怎么做才能获得真正的价值。
我正在使用arduino,我发现了一些库。这些库倾向于使用这种格式: x =((int8_t)sensorData [1])* 256 + sensorData [0]; y =((int8_t)sensorData [3])* 256 + sensorData [2]; z =((int8_t)sensorData [5])* 256 + sensorData [4];其中sensorData的位置0在OUT_X_L(28h)处开始并且向上。 这是正确的吗?我已经阅读了关于LSB左对齐的内容,我认为它应该是这样的: 它是一样的吗? 除此之外,他们使用公式从x,y和z值中获取mg值: x =(int32_t)x * 1000 /(1024 * mgScaleVel); //将数据转换为毫克,2g刻度轴* 1000 /(1024 * 16), y =(int32_t)y * 1000 /(1024 * mgScaleVel); //对于4g刻度轴* 1000 /(1024 * 8), z =(int32_t)z * 1000 /(1024 * mgScaleVel); //对于8g刻度轴* 1000 /(1024 * 4)这是关于什么的?这个公式出现在哪里?这是对的吗?我该如何解析数据? #lis2dh12 以上来自于谷歌翻译 以下为原文 I am having some problems when I try to get data from my sensor. I can read registers and get some data but I don't know how I should do the covnersion to get a real value. I am using an arduino and I found some libraries. Those libraries tend to use this format: x = ((int8_t)sensorData[1])*256+sensorData[0]; y = ((int8_t)sensorData[3])*256+sensorData[2]; z = ((int8_t)sensorData[5])*256+sensorData[4];Where position 0 of sensorData starts at OUT_X_L (28h) and goes up. Is this right? I have read something about left justified of LSB and I think it should be like: Is it the same? Apart from that, they use a formula to get mg values from the x,y and z values: x = (int32_t)x*1000/(1024*mgScaleVel); //transform data to millig, for 2g scale axis*1000/(1024*16), y = (int32_t)y*1000/(1024*mgScaleVel); //for 4g scale axis*1000/(1024*8), z = (int32_t)z*1000/(1024*mgScaleVel); //for 8g scale axis*1000/(1024*4)What is this about? where does this formula appear? Is it correct? How should I parse the data? #lis2dh12 |
|
相关推荐
10个回答
|
|
我无法编辑我的帖子。我忘了把它添加到我放的地方:'... LSB,我认为它应该是这样的:'
x =(int16_t)x_h&lt;&lt; 8; x | = x_l; y =(int16_t)y_h&lt;&lt; 8; y | = x_l; z =(int16_t)z_h&lt;&lt; 8; z | = x_l; 以上来自于谷歌翻译 以下为原文 I can't edit my post. I forgot to add this where I put: '...LSB and I think it should be like:' x = (int16_t)x_h<<8; x |= x_l; y = (int16_t)y_h<<8; y |= x_l; z = (int16_t)z_h<<8; z |= x_l; |
|
|
|
有很多方法可以做,但让我们使用典型的方法。
你需要先做一个号码 您从传感器读取的高字节和低字节: x_raw =((int16_t)OUT_X_H&lt;&lt;&lt; 8)+ OUT_X_L; 2.然后,您需要根据您使用的模式调整数字(数据在输出寄存器中左对齐): - 高分辨率模式(12位数据输出)x_raw = x_raw&gt;&gt; 4; - 正常模式(10位数据输出) x_raw = x_raw&gt;&gt; 6; - 低功率模式(8位数据输出)x_raw = x_raw&gt;&gt; 8; (对于此模式,您可以跳过第一步和第二步,仅使用OUT_X_H) 3.使用所选模式和满量程的灵敏度将原始数据转换为g单位值。灵敏度值可以在数据表的表4中找到。 x = x_raw *灵敏度...值以mg(毫克)为单位 以上来自于谷歌翻译 以下为原文 There is many ways how to do it, but lets use typical approach. 1. You need to first make one number from High and Low bytes which you read from the sensor: x_raw = ((int16_t)OUT_X_H<<8) + OUT_X_L; 2. Then you need to adjust the number according to the mode which you use (the data are left justified in the output registers): - High-resolution mode (12-bit data output) x_raw = x_raw>>4; - Normal mode (10-bit data output) x_raw = x_raw>>6; - Low-power mode (8-bit data output) x_raw = x_raw>>8; (For this mode you can skip first and second step and use only the OUT_X_H) 3. Convert the raw data into g unit value using sensitivity for selected mode and full scale. The sensitivy value can be found in Table 4 in datasheet. x = x_raw * sensitivity ... value will be in mg (milli g) |
|
|
|
谢谢Miroslav,我现在看到了。
我现在正在使用中断1。但我想稍微改变一下。 我的问题是我不知道如何将电路板设置在一个表面上(头部,尾部在边缘上......)所以我想修改轴,这样当我第一次启动它时,它会得到那个位置为0,0,0然后在阈值传递时中断触发。 现在,我的桌子上有开发板,根据位置,中断会一直闪烁。是否可以修改此行为?我怎么修改它? 以上来自于谷歌翻译 以下为原文 Thank you Miroslav, I see it now. I have the interrupt 1 working right now. But I would want to change it a bit. My problem is that I don't know how the board will be set on a surface (head, tail on a edge...) So I would want to modify axis so the first time I power it up, it will get that position as 0,0,0 and then interrupt fires when the threshold is passed over. Right now, I have the devel board on my table and depending on the position, interrupt fires all the time. Is it possible to modify this behaviour? How can I modify it? |
|
|
|
对于这种情况,您可以使用高通滤波器。您可以为输出值和/或中断发生器启用高通滤波器。
在普通模式下读取REFERENCE寄存器,您可以设置''0,0,0''位置,然后仅评估差异。 以上来自于谷歌翻译 以下为原文 For that case you can use high pass filter. You can enable high pass filter for output values and/or for interrupt generator. Reading REFERENCE register in Normal mode you can set the ''0,0,0'' position and then evaluate only the differences. |
|
|
|
如果要在高通滤波器之后查看输出,则必须将位FDS设置为'1'。
要通过读取参考寄存器来重置高通滤波器,必须进行设置 HPM [1:0] = '00',但我认为在您的情况下是正常模式 HPM [1:0] ='10'也可以使用。 以上来自于谷歌翻译 以下为原文 If you want to see the output after the high-pass filter you have to set the bit FDS = '1'. To reset the high-pass filter by reading reference register you have to set HPM[1:0] = '00', but I think in your case the normal mode HPM[1:0] = '10' is also possible to use. |
|
|
|
然后,我应该在CTRL_REG2上写一个0x81
HPM中的正常模式[1:0] FDS 0 HPCLICK 0 HP_IA2 0 HP_IA1 1 然后,读REFERENCE(0x26)寄存器设置0,0,0,不应该吗? 它是否正确?因为我试过,我仍然像以前一样得到x,y,z值。这个可以吗? 以上来自于谷歌翻译 以下为原文 Then, I should write on CTRL_REG2 a 0x81 NORMAL MODE IN HPM[1:0] FDS 0 HPCLICK 0 HP_IA2 0 HP_IA1 1 And then, read REFERENCE(0x26) register to set up 0,0,0, shouldn't I? Is this correct? Because I tried and I still get x,y,z values as before. Is this ok? |
|
|
|
好的,我想我明白了。
关于中断被解雇我有一个问题。 我正在尝试INT1。如果我将INT1_CF设置为0010 1010.它被配置为在Z,Y或X事件变为高电平时触发中断。这是工作。 但是,我想将Z,Y或X事件设置为HIGH或LOW。我不介意签名,我只想在每个方向上加速。好吧,我设置0011 1111,它不起作用。中断从未被解雇过。 这是我目前的配置: #define ACCL_CTRL_REG1 0x3F #define ACCL_CTRL_REG2 0x01 #define ACCL_CTRL_REG3 0x40 #define ACCL_CTRL_REG4 0x80 #define ACCL_CTRL_REG5 0x00 #define ACCL_CTRL_REG6 0x00 // Int1配置 #define ACCL_INT1_CFG 0x2E #define ACCL_INT1_THS 0x32 #define ACCL_INT1_DUR 0x02 #define ACCL_INT1_TIME 0x01我想尝试低功耗。但是如果我在CTRL_REG1中设置1Hz,那就更糟了。我想这是因为1Hz而不是25Hz ...... 在这种情况下我该怎么办?激活6d?每个z,y,x事件都设置为0?我不完全理解6d如何工作.... 以上来自于谷歌翻译 以下为原文 Ok, I think I got it. I have a problem about the interrupt getting fired. I am trying INT1. If I set INT1_CF to be 0010 1010. It is configured to fire interrupt when a Z,Y or X event goes HIGH. It is working. But, I want to set Z,Y or X event to go HIGH or LOW. I don't mind sign, I just want to get accel in every direction. Well, I set 0011 1111 and it doesn't work. Interrupt never got fired then. This is my current configuration: #define ACCL_CTRL_REG1 0x3F #define ACCL_CTRL_REG2 0x01 #define ACCL_CTRL_REG3 0x40 #define ACCL_CTRL_REG4 0x80 #define ACCL_CTRL_REG5 0x00 #define ACCL_CTRL_REG6 0x00 //Int1 config #define ACCL_INT1_CFG 0x2E #define ACCL_INT1_THS 0x32 #define ACCL_INT1_DUR 0x02 #define ACCL_INT1_TIME 0x01I want to try low power. but if I set 1Hz in CTRL_REG1, it is even worst. I guess it is because the 1Hz instead of 25Hz... What should I do in this case? activate 6d? set to 0 every z,y,x event? I don't fully understand how 6d works.... |
|
|
|
中断阈值是绝对值。如果将阈值设置为例如1g,则将触发中断,例如+ 1.2g或-1.2g。
持续时间设置与ODR设置相关联,基本上它表示加速度必须超过触发中断阈值的ODR周期数。因此,在ODR = 25Hz的情况下,持续时间为1/25 * 2 = 0.08s,对于ODR = 1Hz,持续时间为1/1 * 2 = 2s,这很难达到。 以上来自于谷歌翻译 以下为原文 The interrupt threshold is absolute value. If you set the threshold to for example 1g, the interrupt will be triggered for example by +1.2g or -1.2g. The duration settings is linked with the ODR settings, basically it means number of ODR periods for which the acceleration must exceed the threshold to trigger the interrupt. So in your case for ODR = 25Hz the duration will be 1/25 * 2 = 0.08s, for ODR = 1Hz the duration is 1/1 * 2 = 2s which can be difficult to reach. |
|
|
|
我看到了阈值,我没看到的是,如果我激活ZH和ZL,我的中断永远不会触发。如果我只是设置了Zh或ZL,它就会在必要时触发。
另外,在1Hz的情况下,持续时间的最短时间是1秒,不是吗? 以上来自于谷歌翻译 以下为原文 I see about threshold, what I do not see is that if I activate ZH and ZL, my interrupt never triggers. If I just set Zh or ZL, it triggers when it has to. Also, In case of 1Hz, the lowest time of duration is 1 second, isn't it? |
|
|
|
同时激活ZH和ZL是没有意义的,如果使用OR组合,中断将始终被触发(加速度总是高于或低于阈值),如果使用AND组合则不会被触发(加速度不能同时高于和低于阈值)。
您可以将持续时间设置为0,这意味着在达到阈值时立即触发中断。 以上来自于谷歌翻译 以下为原文 To activate ZH and ZL at the same time doesn't make sense, if you use OR combination the interrupt will be always triggered (acceleration is always higher or lower than threshold), if you use AND combination it won't be never triggered (acceleration cannot be higher and lower than threshold at the same time). You can set the duration to 0, it means the interrupt is triggered immediately when the threshold is reached. |
|
|
|
只有小组成员才能发言,加入小组>>
请教:在使用UDE STK时,单片机使用SPC560D30L1,在配置文件怎么设置或选择?里面只有SPC560D40的选项
2642 浏览 1 评论
3208 浏览 1 评论
请问是否有通过UART连接的两个微处理器之间实现双向值交换的方法?
1783 浏览 1 评论
3611 浏览 6 评论
5989 浏览 21 评论
940浏览 4评论
1317浏览 4评论
在Linux上安装Atollic TRUEStudio的步骤有哪些呢?
585浏览 3评论
使用DMA激活某些外设会以导致外设无法工作的方式生成代码是怎么回事
1304浏览 3评论
1362浏览 3评论
小黑屋| 手机版| Archiver| 电子发烧友 ( 湘ICP备2023018690号 )
GMT+8, 2024-11-25 11:19 , Processed in 1.621543 second(s), Total 95, Slave 78 queries .
Powered by 电子发烧友网
© 2015 bbs.elecfans.com
关注我们的微信
下载发烧友APP
电子发烧友观察
版权所有 © 湖南华秋数字科技有限公司
电子发烧友 (电路图) 湘公网安备 43011202000918 号 电信与信息服务业务经营许可证:合字B2-20210191 工商网监 湘ICP备2023018690号