【问题标题】:Need explanation for InvenSenses Motion DriverInvenSenses Motion Driver 需要解释
【发布时间】:2018-03-15 08:30:28
【问题描述】:

我正在使用 InvenSense 的 Motion Driver API 从 MPU-6050 读取值的项目。作为开始,我正在尝试测量温度。

阅读注册文件里面有下面这句话。

对于给定的寄存器值,以摄氏度为单位的温度可能是 计算为: 以摄氏度为单位的温度 = (TEMP_OUT 寄存器值作为 签约数量)/340 + 36.53

在这个API的源码中有如下函数

int mpu_get_temperature(long *data, unsigned long *timestamp)
{
    unsigned char tmp[2];
    short raw;

    if (!(st.chip_cfg.sensors))
        return -1;

    if (i2c_read(st.hw->addr, st.reg->temp, 2, tmp))
        return -1;
    raw = (tmp[0] << 8) | tmp[1];
    if (timestamp)
        get_ms(timestamp);

    data[0] = (long)((35 + ((raw - (float)st.hw->temp_offset) / st.hw->temp_sens)) * 65536L);
    return 0;
}

当我搜索互联网时,我通常会遇到这个似乎有效的 sn-p

uint8_t buf[2];
mpu_read_reg(0x41, &buf[0]);
mpu_read_reg(0x42, &buf[1]);
uint16_t raw = (((uint16_t) buf[0]) << 8) | buf[1];
float temperature = raw / 340.0f + 36.53f;

有人可以向我解释一下(long)((35 + ((raw - (float)st.hw-&gt;temp_offset) / st.hw-&gt;temp_sens)) * 65536L) 吗? 这是某种类型的转换还是我有什么问题?

【问题讨论】:

    标签: c microcontroller mpu6050


    【解决方案1】:

    这其实是一样的。

    1. 65536 转换为Q-format
    2. 文档和来源都说:.temp_sens = 340, .temp_offset = -521
    3. 现在我们有:35 + (R - -521) / 340 == 35 + R / 340 + 521 / 340 == 35 + 1.53 + R/340

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-02-23
      • 2022-01-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多