概述
一.硬件
STC15W408AS单片机 10KNTC热敏电阻
二.资料
热敏电阻阻值温度对应表 -30摄氏度~240摄氏度对应的阻值 每个温度对应一个阻值
三.计算方法
根据需求,我这测试只用选取0~100度区间就OK了.也就是100个点 , 用表格绘制曲线图.Y轴是温度,X轴是电阻值,单位KΩ.这是一个非线性曲线,所以我们很难求解. 所以不如把它划分成多个区间,每个区间都是一小段直线.
0~100度划分了17个区间 ,当然划分的区间越多结果就越精确,这样就能得到16个线段了,然后求出16个一元一次方程的解,把ADC测出的阻值带入到对应的方程里,就能求出对应的温度.
四.求温度代码
#include <stdio.h>
/*10K NTC 温度与阻值对应表 X轴代表温度
Y轴代表阻值*/
uint16_t X_Temp[17] = {0,6,12,18,25,31,37,45,50,57,63,70,76,83,89,94,100};
uint16_t Y_Res[17] = {31908,23698,17794,13498,9900,7625,5925,4288,3529,2709,2177,1701,1386,1101,909,778,649};
/*************************************************
*函数名称:OneDimensionalEquation
*功
能:解一元一次方程
给出两点坐标和第三点的x值或y值
得出第三点y值或x值
*参
数:
*返 回 值:
*************************************************/
float OneDimensionalEquation(uint16_t x1,uint16_t y1,uint16_t x2,uint16_t y2,uint16_t Unkown_x,uint16_t Unkown_y)
{
float k = 0;
float b = 0;
k = (((int32_t)y1-(int32_t)y2)/((int32_t)x1-(int32_t)x2));
b = y1-x1*k;
if(0 == Unkown_x)
//如果unknown_x设为0 就是求x的值 否则求y值
return ((float)Unkown_y-b)/k;
else
return ((float)Unkown_x*k+b);
}
/*************************************************
*函数名称:uint8_t Res_To_Temperature(uint16_t NTC_Res)
*功
能:计算真实温度
*参
数:NTC当前阻值
*返 回 值:温度值
*************************************************/
float Res_To_Temperature(uint16_t NTC_Res)
{
uint8_t Loop = 0;
uint8_t StartPoint = 0;
float RealTemp = 0;
/*查找阻值所对应的区间*/
for(Loop = 0;Loop < 17;Loop++)
{
if(NTC_Res > Y_Res[Loop+1])
{
StartPoint = Loop;
break;
}
}
RealTemp = (float)OneDimensionalEquation(X_Temp[StartPoint],Y_Res[StartPoint],X_Temp[StartPoint+1],Y_Res[StartPoint+1],0,NTC_Res);
return RealTemp;
}
五.阻值表
区间采样阻值表
Temp. | Rmin |
(deg. C) | ( Ohms) |
0 | 31908 |
6 | 23698 |
12 | 17794 |
18 | 13498 |
25 | 9900 |
31 | 7625 |
37 | 5925 |
45 | 4288 |
50 | 3529 |
57 | 2709 |
63 | 2177 |
70 | 1701 |
76 | 1386 |
83 | 1101 |
89 | 909 |
94 | 778 |
100 | 649 |
详细组织表
Temp. | Rmax | Rnor | Rmin |
(deg. C) | (k Ohms) | (k Ohms) | (k Ohms) |
-30 | 184.3727 | 177.3726 | 170.6211 |
-29 | 173.1351 | 166.6654 | 160.4213 |
-28 | 162.6553 | 156.674 | 150.8976 |
-27 | 152.8776 | 147.3463 | 142.0008 |
-26 | 143.7506 | 138.6339 | 133.686 |
-25 | 135.227 | 130.4927 | 125.9115 |
-24 | 127.2633 | 122.8816 | 118.6389 |
-23 | 119.8193 | 115.763 | 111.8328 |
-22 | 112.8579 | 109.1019 | 105.4603 |
-21 | 106.345 | 102.8663 | 99.4914 |
-20 | 100.249 | 97.0264 | 93.8979 |
-19 | 94.5407 | 91.5547 | 88.6541 |
-18 | 89.1931 | 86.4258 | 83.736 |
-17 | 84.1813 | 81.6163 | 79.1214 |
-16 | 79.4823 | 77.1043 | 74.7899 |
-15 | 75.0747 | 72.8697 | 70.7223 |
-14 | 70.9387 | 68.8937 | 66.9011 |
-13 | 67.0559 | 65.1592 | 63.3099 |
-12 | 63.4095 | 61.65 | 59.9334 |
-11 | 59.9836 | 58.3513 | 56.7577 |
-10 | 56.7636 | 55.2491 | 53.7697 |
-9 | 53.736 | 52.3307 | 50.9571 |
-8 | 50.8882 | 49.5841 | 48.3086 |
-7 | 48.2085 | 46.9982 | 45.8137 |
-6 | 45.686 | 44.5627 | 43.4627 |
-5 | 43.3105 | 42.268 | 41.2465 |
-4 | 41.0727 | 40.1052 | 39.1565 |
-3 | 38.9639 | 38.0658 | 37.1848 |
-2 | 36.9758 | 36.1423 | 35.3241 |
-1 | 35.1009 | 34.3274 | 33.5675 |
0 | 33.3321 | 32.6142 | 31.9086 |
1 | 31.6628 | 30.9966 | 30.3415 |
2 | 30.0869 | 29.4688 | 28.8605 |
3 | 28.5986 | 28.0251 | 27.4604 |
4 | 27.1925 | 26.6606 | 26.1364 |
5 | 25.8638 | 25.3704 | 24.8839 |
6 | 24.6076 | 24.1501 | 23.6987 |
7 | 23.4197 | 22.9955 | 22.5768 |
8 | 22.2959 | 21.9028 | 21.5144 |
9 | 21.2325 | 20.8682 | 20.5081 |
10 | 20.2259 | 19.8884 | 19.5546 |
11 | 19.2727 | 18.9602 | 18.6509 |
12 | 18.3699 | 18.0806 | 17.7941 |
13 | 17.5144 | 17.2467 | 16.9815 |
14 | 16.7036 | 16.4561 | 16.2106 |
15 | 15.9349 | 15.7061 | 15.479 |
16 | 15.2059 | 14.9945 | 14.7845 |
17 | 14.5143 | 14.3191 | 14.1251 |
18 | 13.858 | 13.6779 | 13.4988 |
19 | 13.235 | 13.069 | 12.9037 |
20 | 12.6435 | 12.4905 | 12.3381 |
21 | 12.0817 | 11.9409 | 11.8005 |
22 | 11.5479 | 11.4184 | 11.2893 |
23 | 11.0407 | 10.9217 | 10.803 |
24 | 10.5585 | 10.4494 | 10.3403 |
25 | 10.1 | 10 | 9.9 |
26 | 9.6724 | 9.5724 | 9.4725 |
27 | 9.2651 | 9.1654 | 9.0659 |
28 | 8.8773 | 8.7779 | 8.6788 |
29 | 8.5078 | 8.4089 | 8.3104 |
30 | 8.1556 | 8.0574 | 7.9597 |
31 | 7.8199 | 7.7225 | 7.6256 |
32 | 7.4999 | 7.4033 | 7.3073 |
33 | 7.1946 | 7.099 | 7.004 |
34 | 6.9034 | 6.8088 | 6.7149 |
35 | 6.6255 | 6.5321 | 6.4393 |
36 | 6.3603 | 6.268 | 6.1764 |
37 | 6.1071 | 6.016 | 5.9257 |
38 | 5.8654 | 5.7755 | 5.6865 |
39 | 5.6344 | 5.5459 | 5.4581 |
40 | 5.4138 | 5.3266 | 5.2402 |
41 | 5.203 | 5.1171 | 5.0321 |
42 | 5.0015 | 4.9169 | 4.8333 |
43 | 4.8088 | 4.7257 | 4.6435 |
44 | 4.6246 | 4.5428 | 4.462 |
45 | 4.4484 | 4.368 | 4.2886 |
46 | 4.2798 | 4.2008 | 4.1229 |
47 | 4.1184 | 4.0409 | 3.9644 |
48 | 3.964 | 3.8878 | 3.8128 |
49 | 3.8162 | 3.7414 | 3.6678 |
50 | 3.6746 | 3.6012 | 3.529 |
51 | 3.539 | 3.467 | 3.3962 |
52 | 3.4091 | 3.3385 | 3.2691 |
53 | 3.2846 | 3.2154 | 3.1474 |
54 | 3.1653 | 3.0975 | 3.0308 |
55 | 3.051 | 2.9845 | 2.9191 |
56 | 2.9413 | 2.8762 | 2.8121 |
57 | 2.8362 | 2.7723 | 2.7096 |
58 | 2.7353 | 2.6727 | 2.6113 |
59 | 2.6385 | 2.5772 | 2.5171 |
60 | 2.5457 | 2.4856 | 2.4268 |
61 | 2.4566 | 2.3977 | 2.3401 |
62 | 2.371 | 2.3134 | 2.257 |
63 | 2.2888 | 2.2324 | 2.1772 |
64 | 2.2099 | 2.1547 | 2.1007 |
65 | 2.1341 | 2.0801 | 2.0272 |
66 | 2.0613 | 2.0084 | 1.9567 |
67 | 1.9913 | 1.9396 | 1.8889 |
68 | 1.9241 | 1.8734 | 1.8239 |
69 | 1.8594 | 1.8098 | 1.7614 |
70 | 1.7973 | 1.7487 | 1.7013 |
71 | 1.7375 | 1.69 | 1.6436 |
72 | 1.68 | 1.6335 | 1.5881 |
73 | 1.6247 | 1.5792 | 1.5348 |
74 | 1.5715 | 1.5269 | 1.4835 |
75 | 1.5202 | 1.4767 | 1.4342 |
76 | 1.4709 | 1.4283 | 1.3868 |
77 | 1.4235 | 1.3818 | 1.3411 |
78 | 1.3778 | 1.3369 | 1.2972 |
79 | 1.3337 | 1.2938 | 1.2549 |
80 | 1.2913 | 1.2523 | 1.2143 |
81 | 1.2505 | 1.2123 | 1.1751 |
82 | 1.2111 | 1.1737 | 1.1374 |
83 | 1.1732 | 1.1366 | 1.101 |
84 | 1.1366 | 1.1008 | 1.066 |
85 | 1.1014 | 1.0663 | 1.0323 |
86 | 1.0674 | 1.0331 | 0.9998 |
87 | 1.0346 | 1.0011 | 0.9685 |
88 | 1.003 | 0.9702 | 0.9383 |
89 | 0.9725 | 0.9404 | 0.9092 |
90 | 0.9431 | 0.9116 | 0.8812 |
91 | 0.9147 | 0.8839 | 0.8541 |
92 | 0.8873 | 0.8572 | 0.828 |
93 | 0.8608 | 0.8314 | 0.8028 |
94 | 0.8353 | 0.8064 | 0.7785 |
95 | 0.8106 | 0.7824 | 0.7551 |
96 | 0.7868 | 0.7592 | 0.7324 |
97 | 0.7638 | 0.7367 | 0.7106 |
98 | 0.7415 | 0.7151 | 0.6895 |
99 | 0.7201 | 0.6942 | 0.6691 |
100 | 0.6993 | 0.6739 | 0.6495 |
101 | 0.6792 | 0.6544 | 0.6304 |
102 | 0.6598 | 0.6355 | 0.6121 |
103 | 0.6411 | 0.6173 | 0.5943 |
104 | 0.623 | 0.5997 | 0.5772 |
105 | 0.6054 | 0.5826 | 0.5606 |
106 | 0.5885 | 0.5661 | 0.5446 |
107 | 0.5721 | 0.5502 | 0.5291 |
108 | 0.5562 | 0.5348 | 0.5142 |
109 | 0.5408 | 0.5199 | 0.4997 |
110 | 0.526 | 0.5054 | 0.4857 |
111 | 0.5116 | 0.4915 | 0.4721 |
112 | 0.4976 | 0.478 | 0.459 |
113 | 0.4842 | 0.4649 | 0.4463 |
114 | 0.4711 | 0.4522 | 0.434 |
115 | 0.4584 | 0.4399 | 0.4222 |
116 | 0.4462 | 0.4281 | 0.4107 |
117 | 0.4343 | 0.4166 | 0.3995 |
118 | 0.4228 | 0.4054 | 0.3887 |
119 | 0.4117 | 0.3947 | 0.3783 |
120 | 0.4009 | 0.3842 | 0.3682 |
121 | 0.3904 | 0.3741 | 0.3584 |
122 | 0.3803 | 0.3643 | 0.3489 |
123 | 0.3705 | 0.3547 | 0.3397 |
124 | 0.3609 | 0.3455 | 0.3307 |
125 | 0.3517 | 0.3366 | 0.3221 |
126 | 0.3427 | 0.3279 | 0.3137 |
127 | 0.334 | 0.3195 | 0.3056 |
128 | 0.3256 | 0.3114 | 0.2977 |
129 | 0.3174 | 0.3034 | 0.2901 |
130 | 0.3094 | 0.2958 | 0.2827 |
131 | 0.3017 | 0.2883 | 0.2755 |
132 | 0.2942 | 0.2811 | 0.2685 |
133 | 0.287 | 0.2741 | 0.2618 |
134 | 0.2799 | 0.2673 | 0.2552 |
135 | 0.2731 | 0.2607 | 0.2488 |
136 | 0.2664 | 0.2543 | 0.2427 |
137 | 0.26 | 0.248 | 0.2367 |
138 | 0.2537 | 0.242 | 0.2308 |
139 | 0.2476 | 0.2361 | 0.2252 |
140 | 0.2417 | 0.2304 | 0.2197 |
141 | 0.2359 | 0.2249 | 0.2144 |
142 | 0.2303 | 0.2195 | 0.2092 |
143 | 0.2249 | 0.2143 | 0.2041 |
144 | 0.2196 | 0.2092 | 0.1993 |
145 | 0.2145 | 0.2043 | 0.1945 |
146 | 0.2095 | 0.1995 | 0.1899 |
147 | 0.2046 | 0.1948 | 0.1854 |
148 | 0.1999 | 0.1903 | 0.181 |
149 | 0.1953 | 0.1859 | 0.1768 |
150 | 0.1909 | 0.1816 | 0.1727 |
151 | 0.1865 | 0.1774 | 0.1687 |
152 | 0.1823 | 0.1733 | 0.1648 |
153 | 0.1782 | 0.1694 | 0.161 |
154 | 0.1742 | 0.1656 | 0.1573 |
155 | 0.1703 | 0.1618 | 0.1537 |
156 | 0.1665 | 0.1582 | 0.1502 |
157 | 0.1628 | 0.1547 | 0.1469 |
158 | 0.1593 | 0.1512 | 0.1436 |
159 | 0.1558 | 0.1479 | 0.1403 |
160 | 0.1524 | 0.1446 | 0.1372 |
161 | 0.1491 | 0.1414 | 0.1342 |
162 | 0.1458 | 0.1383 | 0.1312 |
163 | 0.1427 | 0.1353 | 0.1283 |
164 | 0.1396 | 0.1324 | 0.1255 |
165 | 0.1366 | 0.1295 | 0.1228 |
166 | 0.1337 | 0.1268 | 0.1201 |
167 | 0.1309 | 0.1241 | 0.1175 |
168 | 0.1282 | 0.1214 | 0.115 |
169 | 0.1255 | 0.1188 | 0.1126 |
170 | 0.1228 | 0.1163 | 0.1102 |
171 | 0.1203 | 0.1139 | 0.1078 |
172 | 0.1178 | 0.1115 | 0.1055 |
173 | 0.1154 | 0.1092 | 0.1033 |
174 | 0.113 | 0.1069 | 0.1012 |
175 | 0.1107 | 0.1047 | 0.0991 |
176 | 0.1085 | 0.1026 | 0.097 |
177 | 0.1063 | 0.1005 | 0.095 |
178 | 0.1041 | 0.0984 | 0.0931 |
179 | 0.102 | 0.0964 | 0.0912 |
180 | 0.1 | 0.0945 | 0.0893 |
181 | 0.098 | 0.0926 | 0.0875 |
182 | 0.0961 | 0.0908 | 0.0857 |
183 | 0.0942 | 0.089 | 0.084 |
184 | 0.0923 | 0.0872 | 0.0823 |
185 | 0.0905 | 0.0855 | 0.0807 |
186 | 0.0888 | 0.0838 | 0.0791 |
187 | 0.0871 | 0.0822 | 0.0775 |
188 | 0.0854 | 0.0806 | 0.076 |
189 | 0.0837 | 0.079 | 0.0745 |
190 | 0.0822 | 0.0775 | 0.0731 |
191 | 0.0806 | 0.076 | 0.0716 |
192 | 0.0791 | 0.0745 | 0.0703 |
193 | 0.0776 | 0.0731 | 0.0689 |
194 | 0.0761 | 0.0717 | 0.0676 |
195 | 0.0747 | 0.0704 | 0.0663 |
196 | 0.0733 | 0.0691 | 0.0651 |
197 | 0.072 | 0.0678 | 0.0638 |
198 | 0.0706 | 0.0665 | 0.0626 |
199 | 0.0693 | 0.0653 | 0.0615 |
200 | 0.0681 | 0.0641 | 0.0603 |
201 | 0.0668 | 0.0629 | 0.0592 |
202 | 0.0656 | 0.0618 | 0.0581 |
203 | 0.0644 | 0.0606 | 0.057 |
204 | 0.0633 | 0.0595 | 0.056 |
205 | 0.0622 | 0.0585 | 0.055 |
206 | 0.0611 | 0.0574 | 0.054 |
207 | 0.06 | 0.0564 | 0.053 |
208 | 0.0589 | 0.0554 | 0.0521 |
209 | 0.0579 | 0.0544 | 0.0511 |
210 | 0.0569 | 0.0535 | 0.0502 |
211 | 0.0559 | 0.0525 | 0.0493 |
212 | 0.0549 | 0.0516 | 0.0485 |
213 | 0.054 | 0.0507 | 0.0476 |
214 | 0.0531 | 0.0498 | 0.0468 |
215 | 0.0522 | 0.049 | 0.046 |
216 | 0.0513 | 0.0481 | 0.0452 |
217 | 0.0504 | 0.0473 | 0.0444 |
218 | 0.0496 | 0.0465 | 0.0436 |
219 | 0.0487 | 0.0457 | 0.0429 |
220 | 0.0479 | 0.0449 | 0.0422 |
221 | 0.0471 | 0.0442 | 0.0414 |
222 | 0.0463 | 0.0435 | 0.0407 |
223 | 0.0456 | 0.0427 | 0.0401 |
224 | 0.0448 | 0.042 | 0.0394 |
225 | 0.0441 | 0.0413 | 0.0387 |
226 | 0.0434 | 0.0407 | 0.0381 |
227 | 0.0427 | 0.04 | 0.0375 |
228 | 0.042 | 0.0393 | 0.0369 |
229 | 0.0413 | 0.0387 | 0.0362 |
230 | 0.0407 | 0.0381 | 0.0357 |
231 | 0.04 | 0.0375 | 0.0351 |
232 | 0.0394 | 0.0369 | 0.0345 |
233 | 0.0388 | 0.0363 | 0.034 |
234 | 0.0382 | 0.0357 | 0.0334 |
235 | 0.0376 | 0.0352 | 0.0329 |
236 | 0.037 | 0.0346 | 0.0324 |
237 | 0.0364 | 0.0341 | 0.0319 |
238 | 0.0359 | 0.0335 | 0.0314 |
239 | 0.0353 | 0.033 | 0.0309 |
240 | 0.0348 | 0.0325 | 0.0304 |
最后
以上就是寒冷裙子为你收集整理的方法一 NTC热敏电阻转换温度的计算方式(分段法)的全部内容,希望文章能够帮你解决方法一 NTC热敏电阻转换温度的计算方式(分段法)所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复