介绍

LMT86是精密的CMOS温度传感器,它的大致参数如下:

  • 精度:±0.4误差
  • 范围:0°C 至 150°C
  • 封装:TO-92S
  • 引脚:VDD、GND、OUT
  • 价格:4RMB
  • 厂商:德州仪器
  • 供电:2.2V 至 5.5V

模块外观大概长这么样

img

硬件

VDD、GND、OUT引脚连线参考,电源端(VDD)加去耦电容、输出端(OUT)加滤波电容

img

连接ADC采集模拟量

img

关系表

温度和VOUT的对应关系

温度(°C) VOUT(mV) 温度(°C) VOUT(mV) 温度(°C) VOUT(mV) 温度(°C) VOUT(mV) 温度(°C) VOUT(mV)
-50 2616 -10 2207 30 1777 70 1335 110 883
-49 2607 -9 2197 31 1766 71 1324 111 872
-48 2598 -8 2186 32 1756 72 1313 112 860
-47 2589 -7 2175 33 1745 73 1301 113 849
-46 2580 -6 2164 34 1734 74 1290 114 837
-45 2571 -5 2154 35 1723 75 1279 115 826
-44 2562 -4 2143 36 1712 76 1268 116 814
-43 2553 -3 2132 37 1701 77 1257 117 803
-42 2543 -2 2122 38 1690 78 1245 118 791
-41 2533 -1 2111 39 1679 79 1234 119 780
-40 2522 0 2100 40 1668 80 1223 120 769
-39 2512 1 2089 41 1657 81 1212 121 757
-38 2501 2 2079 42 1646 82 1201 122 745
-37 2491 3 2068 43 1635 83 1189 123 734
-36 2481 4 2057 44 1624 84 1178 124 722
-35 2470 5 2047 45 1613 85 1167 125 711
-34 2460 6 2036 46 1602 86 1155 126 699
-33 2449 7 2025 47 1591 87 1144 127 688
-32 2439 8 2014 48 1580 88 1133 128 676
-31 2429 9 2004 49 1569 89 1122 129 665
-30 2418 10 1993 50 1558 90 1110 130 653
-29 2408 11 1982 51 1547 91 1099 131 642
-28 2397 12 1971 52 1536 92 1088 132 630
-27 2387 13 1961 53 1525 93 1076 133 618
-26 2376 14 1950 54 1514 94 1065 134 607
-25 2366 15 1939 55 1503 95 1054 135 595
-24 2355 16 1928 56 1492 96 1042 136 584
-23 2345 17 1918 57 1481 97 1031 137 572
-22 2334 18 1907 58 1470 98 1020 138 560
-21 2324 19 1896 59 1459 99 1008 139 549
-20 2313 20 1885 60 1448 100 997 140 537
-19 2302 21 1874 61 1436 101 986 141 525
-18 2292 22 1864 62 1425 102 974 142 514
-17 2281 23 1853 63 1414 103 963 143 502
-16 2271 24 1842 64 1403 104 951 144 490
-15 2260 25 1831 65 1391 105 940 145 479
-14 2250 26 1820 66 1380 106 929 146 467
-13 2239 27 1810 67 1369 107 917 147 455
-12 2228 28 1799 68 1358 108 906 148 443
-11 2218 29 1788 69 1346 109 895 149 432

驱动

ADC配置:初始化ADC2用于温度传感器读取

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
void InitAdc2(void)
{
extern void DSP28x_usDelay(Uint32 Count);

// To powerup the ADC2 the ADC2ENCLK bit should be set first to enable
// clocks, followed by powering up the bandgap, reference circuitry, and
// ADC2 core.
// Before the first conversion is performed a 5ms delay must be observed
// after power up to give all analog circuits time to power up and settle

// Please note that for the delay function below to operate correctly the
// CPU_RATE define statement in the F28M35x_Examples.h file must
// contain the correct CPU clock period in nanoseconds.
EALLOW;
Adc2Regs.ADCCTL1.bit.ADCBGPWD = 1; // Power ADC2 BG
Adc2Regs.ADCCTL1.bit.ADCREFPWD = 1; // Power reference
Adc2Regs.ADCCTL1.bit.ADCPWDN = 1; // Power ADC2
Adc2Regs.ADCCTL1.bit.ADCENABLE = 1; // Enable ADC2
Adc2Regs.ADCCTL1.bit.ADCREFSEL = 0; // Select interal BG
EDIS;

DELAY_US(ADC_usDELAY); // Delay before converting ADC2 channels
}

void TempSensor_Init(void)
{
EALLOW;

// 初始化ADC2(假设已有InitAdc2()函数)
InitAdc2();

// 配置ADC2
Adc2Regs.ADCCTL2.bit.ADCNONOVERLAP = 1; // 启用非重叠模式
Adc2Regs.ADCCTL1.bit.INTPULSEPOS = 1; // 中断在结果锁存后触发
Adc2Regs.INTSEL1N2.bit.INT1E = 1; // 启用ADCINT1
Adc2Regs.INTSEL1N2.bit.INT1CONT = 0; // 禁用连续模式
Adc2Regs.INTSEL1N2.bit.INT1SEL = 0; // EOC0触发ADCINT1

// 配置SOC0
Adc2Regs.ADCSOC0CTL.bit.CHSEL = 0; // ADC2A0通道
Adc2Regs.ADCSOC0CTL.bit.TRIGSEL = 0; // 软件触发
Adc2Regs.ADCSOC0CTL.bit.ACQPS = 6; // 采样窗口7个ADC时钟周期

EDIS;
}

温度电压映射关系数组

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
static const LMT86_LUT_Entry lmt86_lut[] = {
// 负温度区 (-50°C 到 -1°C)
{-50, 2616}, {-49, 2607}, {-48, 2598}, {-47, 2589}, {-46, 2580},
{-45, 2571}, {-44, 2562}, {-43, 2553}, {-42, 2543}, {-41, 2533},
{-40, 2522}, {-39, 2512}, {-38, 2501}, {-37, 2491}, {-36, 2481},
{-35, 2470}, {-34, 2460}, {-33, 2449}, {-32, 2439}, {-31, 2429},
{-30, 2418}, {-29, 2408}, {-28, 2397}, {-27, 2387}, {-26, 2376},
{-25, 2366}, {-24, 2355}, {-23, 2345}, {-22, 2334}, {-21, 2324},
{-20, 2313}, {-19, 2302}, {-18, 2292}, {-17, 2281}, {-16, 2271},
{-15, 2260}, {-14, 2250}, {-13, 2239}, {-12, 2228}, {-11, 2218},
{-10, 2207}, {-9, 2197}, {-8, 2186}, {-7, 2175}, {-6, 2164},
{-5, 2154}, {-4, 2143}, {-3, 2132}, {-2, 2122}, {-1, 2111},

// 正温度区 (0°C 到 150°C)
{0, 2100}, {1, 2089}, {2, 2079}, {3, 2068}, {4, 2057},
{5, 2047}, {6, 2036}, {7, 2025}, {8, 2014}, {9, 2004},
{10, 1993}, {11, 1982}, {12, 1971}, {13, 1961}, {14, 1950},
{15, 1939}, {16, 1928}, {17, 1918}, {18, 1907}, {19, 1896},
{20, 1885}, {21, 1874}, {22, 1864}, {23, 1853}, {24, 1842},
{25, 1831}, {26, 1820}, {27, 1810}, {28, 1799}, {29, 1788},
{30, 1777}, {31, 1766}, {32, 1756}, {33, 1745}, {34, 1734},
{35, 1723}, {36, 1712}, {37, 1701}, {38, 1690}, {39, 1679},
{40, 1668}, {41, 1657}, {42, 1646}, {43, 1635}, {44, 1624},
{45, 1613}, {46, 1602}, {47, 1591}, {48, 1580}, {49, 1569},
{50, 1558}, {51, 1547}, {52, 1536}, {53, 1525}, {54, 1514},
{55, 1503}, {56, 1492}, {57, 1481}, {58, 1470}, {59, 1459},
{60, 1448}, {61, 1436}, {62, 1425}, {63, 1414}, {64, 1403},
{65, 1391}, {66, 1380}, {67, 1369}, {68, 1358}, {69, 1346},
{70, 1335}, {71, 1324}, {72, 1313}, {73, 1301}, {74, 1290},
{75, 1279}, {76, 1268}, {77, 1257}, {78, 1245}, {79, 1234},
{80, 1223}, {81, 1212}, {82, 1201}, {83, 1189}, {84, 1178},
{85, 1167}, {86, 1155}, {87, 1144}, {88, 1133}, {89, 1122},
{90, 1110}, {91, 1099}, {92, 1088}, {93, 1076}, {94, 1065},
{95, 1054}, {96, 1042}, {97, 1031}, {98, 1020}, {99, 1008},
{100, 997}, {101, 986}, {102, 974}, {103, 963}, {104, 951},
{105, 940}, {106, 929}, {107, 917}, {108, 906}, {109, 895},
{110, 883}, {111, 872}, {112, 860}, {113, 849}, {114, 837},
{115, 826}, {116, 814}, {117, 803}, {118, 791}, {119, 780},
{120, 769}, {121, 757}, {122, 745}, {123, 734}, {124, 722},
{125, 711}, {126, 699}, {127, 688}, {128, 676}, {129, 665},
{130, 653}, {131, 642}, {132, 630}, {133, 618}, {134, 607},
{135, 595}, {136, 584}, {137, 572}, {138, 560}, {139, 549},
{140, 537}, {141, 525}, {142, 514}, {143, 502}, {144, 490},
{145, 479}, {146, 467}, {147, 455}, {148, 443}, {149, 432},
{150, 420}
};

使用线性插值计算温度

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
// 使用线性插值计算温度
static float VoltageToTemperature(float voltage_mV)
{
Uint16 i;
float slope;
// 边界检查
if (voltage_mV >= lmt86_lut[0].voltage) return lmt86_lut[0].temp;
if (voltage_mV <= lmt86_lut[LMT86_LUT_SIZE-1].voltage) return lmt86_lut[LMT86_LUT_SIZE-1].temp;

// 线性搜索(实际使用时建议改为二分查找)
for (i=0; i<LMT86_LUT_SIZE-1; i++) {
if (voltage_mV <= lmt86_lut[i].voltage && voltage_mV >= lmt86_lut[i+1].voltage) {
// 线性插值
slope = (lmt86_lut[i+1].temp - lmt86_lut[i].temp) / (float)(lmt86_lut[i+1].voltage - lmt86_lut[i].voltage);
return lmt86_lut[i].temp + slope * (voltage_mV - lmt86_lut[i].voltage);
}
}
return 0.0f; // 不应执行到此处
}

读取当前温度(°C)

1
2
3
4
5
6
// 读取当前温度(°C)
float TempSensor_ReadTemperature(Uint16 adcValue)
{
float voltage_mV = ADC_ToVoltage(adcValue);
return VoltageToTemperature(voltage_mV);
}

© 2025 hywing 使用 Stellar 创建
总访问 113701 次 | 本页访问 326