Android下ADC读取NTC电阻测定的温度值

先上code,

--------

/*  retV is located at reply_abs_off_0, but it is discarded by the jni fn
 *  android_tvmanager_native_invoke.
 *  reply_rel_off_0:    c runtime errno with negative sign such as -EINVAL
 */
static gk_s32 getMainBoardTemp(const Parcel &request, Parcel &reply)
{
    gk_s32 nRetVal = -1;
    int nCrtErrNo = -1;
    gk_u32 temperatureRawData = 0, temperatureCelsiusDegree = 0;

    do
    {
        gk_s32 gk_ret = MwDevCtrl::getLsadcInstance()->getValue(1, &temperatureRawData);
        if(GK_SUCCESS != gk_ret)
        {
            nRetVal = -1;
            nCrtErrNo = -EIO;
            break;
        }

        /* raw data => celsius degree */
        temperatureCelsiusDegree =
            1/((std::log((1/(1-(float)temperatureRawData/255)*100000-100000)/100000)/3950) + 1/298.15f) - 273.15f;

        nRetVal = 0;
        nCrtErrNo = 0;
    }while(false);

    reply.writeInt32(nCrtErrNo);
    if(0 == nCrtErrNo)
    {
        reply.writeInt32(temperatureRawData);
        reply.writeInt32(temperatureCelsiusDegree);
    }

    return nRetVal;
}

--------

这里ADC测定值temperatureRawData范围是0~255,所以计算时折成比例

temperatureRawData/255

最后计算的temperatureCelsiusDegree就是温度摄氏度。

不同硬件板子的ADC范围可能不同,需要调节上面的255 max值。

实测满足一般主板温度检测用,且成本低廉。

  • 4
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值