Discuz! Board

 找回密码
 立即注册
搜索
热搜: 活动 交友 discuz
查看: 31|回复: 0

2.6-Air302(NB-IOT)-基础外设-AD采集,NTC温度传感器B3950

[复制链接]

56

主题

56

帖子

224

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
224
发表于 2020-10-11 16:59:53 | 显示全部楼层 |阅读模式




电路说明
模组有3个AD通道
819239-20201011122643423-1214499336.png


直接看程序
819239-20201011122813785-250303219.png



adc.open(0) -- CPU温度
adc.open(1) -- VBAT电压
adc.open(2) -- 模块上的ADC0脚, 0-1.8v,不要超过范围使用!!!


sys.taskInit(function()
    while 1 do
        ------原始值   计算后的值
        local adc0Value,temp = adc.read(0);--temp为实际温度
        local adc1Value,VBAT = adc.read(1);--VBAT为采集的实际电压(mV)
        local adc2Value,Value = adc.read(2);--Value为采集的实际电压(mV)


        log.info("adc0Value=", adc0Value,"temp=",temp,"\r\n");
        log.info("adc1Value=", adc1Value,"VBAT=",VBAT,"\r\n");
        log.info("adc2Value=", adc2Value,"Value=",Value,"\r\n");
        log.info("\r\n");


        sys.wait(500);
    end
    -- 支持close操作,按需使用,close后read的返回值无效,再次open后可以read
    -- adc.close(0)
    -- adc.close(1)
    -- adc.close(2)
end)


819239-20201011122904206-2104138861.png


①: 采集的模组的温度为 28摄氏度
②: 采集的供电电压为 3317mV
③:采集的外面的ADC0引脚的电压为 22mV


使用ADC0采集NTC温度传感器B3950(10K)
注:板子上并没有接该传感器,我是用引脚连接测试的.
因为电池供电是变动的,所以用了一个基准电压
下面的431电路产生一个 2.5V的基准电压.
819239-20201011130840425-1945834969.png



adc.open(2) -- 模块上的ADC0脚, 0-1.8v,不要超过范围使用!!!


--建表
Temp_Tab_10K=                                                            
{
    95.3370,92.6559,90.0580,87.5406,85.1009,82.7364,80.4445,78.2227,76.0689,73.9806,    ---20~-15.5
    71.9558,69.9923,68.0881,66.2412,64.4499,62.7122,61.0264,59.3908,57.8038,56.2639,    ---15~-10.5
    54.7694,53.3189,51.9111,50.5445,49.2178,47.9298,46.6792,45.4649,44.2856,43.1403,    ---10~-5.5
    42.0279,40.9447,39.8978,38.8780,37.8873,36.9246,35.9892,35.0801,34.1965,33.3378,    ---5~-0.5
    32.5030,31.6915,30.9026,30.1355,29.3896,28.6644,27.9590,27.2730,26.6058,25.9567,    --0~4.5
    25.3254,24.7111,24.1135,23.5320,22.9661,22.4154,21.8795,21.3579,20.8502,20.3559,    --5~9.5
    19.8747,19.4063,18.9502,18.5060,18.0735,17.6523,17.2421,16.8426,16.4534,16.0743,    --10~14.5
    15.7049,15.3450,14.9944,14.6528,14.3198,13.9954,13.6792,13.3710,13.0705,12.7777,    --15~19.5
    12.4922,12.2138,11.9425,11.6778,11.4198,11.1681,10.9227,10.6834,10.4499,10.2222,    --20~24.5
    10.000,9.7833,9.5718,9.3655,9.1642,8.9677,8.7760,8.5889,8.4063,8.2281,    --25~29.5
    8.0541,7.8842,7.7184,7.5565,7.3985,7.2442,7.0935,6.9463,6.8026,6.6622,    --30~34.5
    6.5251,6.3912,6.2604,6.1326,6.0077,5.8858,5.7666,5.6501,5.5363,5.4251,    --35~39.5
    5.3164,5.2102,5.1064,5.0049,4.9057,4.8088,4.7140,4.6213,4.5307,4.4421,    --40~44.5
    4.3554,4.2707,4.1878,4.1068,4.0275,3.9500,3.8742,3.8000,3.7275,3.6565,    --45~49.5
    3.5870,3.5190,3.4525,3.3875,3.3238,3.2615,3.2005,3.1408,3.0824,3.0252,    --50~54.5
    2.9692,2.9144,2.8608,2.8082,2.7568,2.7065,2.6572,2.6089,2.5616,2.5153,    --55~59.4
    2.4700,2.4255,2.3820,2.3394,2.2977,2.2568,2.2167,2.1775,2.1390,2.1013,    --60~64.5
    2.0644,2.0282,1.9928,1.9580,1.9240,1.8906,1.8579,1.8258,1.7944,1.7636,    --65~69.5
    1.7334,1.7037,1.6747,1.6462,1.6183,1.5910,1.5641,1.5378,1.5120,1.4867,    --70~74.5
    1.4619,1.4375,1.4136,1.3902,1.3672,1.3447,1.3225,1.3008,1.2795,1.2586,    --75~79.5
    1.2381,1.2180,1.1983,1.1789,1.1599,1.1412,1.1229,1.1050,1.0873,1.0700,    --80~84.5
    1.0530,1.0363,1.0199,1.0038,0.9880,0.9725,0.9573,0.9424,0.9277,0.9133,    --85~89.5
    0.8991,0.8852,0.8715,0.8581,0.8450,0.8320,0.8193,0.8068,0.7945,0.7825,    --90~94.5
    0.7707,0.7590,0.7476,0.7364,0.7253,0.7145,0.7038,0.6933,0.6831,0.6729,    --95~99.5
    0.6630    --100
}


--获取采集的温度
local function Get_Temp()
    local Temperature = 0;
    local adcval,voltval = adc.read(2)
    local value = voltval/1000;
    local Resistance = 82*(value/(2.5-value))
    for k, v in pairs(Temp_Tab_10K) do
        if Resistance> v then
            Temperature = (((k-1)-40)/2)
            break;
        end     
    end
    return  Temperature;
end




sys.taskInit(function()
    while 1 do
        log.debug("Temperature=", Get_Temp())  
        sys.wait(500);
    end
end)



819239-20201011130801926-938093327.png

警告
原先版本的底层打印浮点数有BUG
请重新下载最新版本,然后测试本节程序
819239-20201011151947040-829031070.png


首次使用最新版,记得把底层烧录进去
python air302.py lfs dlfull

copycode.gif
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|小黑屋|DiscuzX

GMT+8, 2020-10-31 15:47 , Processed in 0.084333 second(s), 21 queries .

Powered by Discuz! X3.4

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表