RTD电阻转换成对应温度的代码,支持-200~+850摄氏度
- //RTD分度表,1 degree Celsius (-200C to +850C)
- //单位ohm
- const double RTD_Table[] = {
- 18.52 , 18.952 , 19.384 , 19.815 , 20.247 , 20.677 , 21.108 , 21.538 , 21.967 , 22.397 ,
- 22.825 , 23.254 , 23.682 , 24.11 , 24.538 , 24.965 , 25.392 , 25.819 , 26.245 , 26.671 ,
- 27.096 , 27.522 , 27.947 , 28.371 , 28.796 , 29.22 , 29.643 , 30.067 , 30.49 , 30.913 ,
- 31.335 , 31.757 , 32.179 , 32.601 , 33.022 , 33.443 , 33.864 , 34.284 , 34.704 , 35.124 ,
- 35.543 , 35.963 , 36.382 , 36.8 , 37.219 , 37.637 , 38.055 , 38.472 , 38.889 , 39.306 ,
- 39.723 , 40.14 , 40.556 , 40.972 , 41.388 , 41.803 , 42.218 , 42.633 , 43.048 , 43.462 ,
- 43.876 , 44.29 , 44.704 , 45.117 , 45.531 , 45.944 , 46.356 , 46.769 , 47.181 , 47.593 ,
- 48.005 , 48.416 , 48.828 , 49.239 , 49.649 , 50.06 , 50.47 , 50.881 , 51.291 , 51.7 ,
- 52.11 , 52.519 , 52.928 , 53.337 , 53.746 , 54.154 , 54.562 , 54.97 , 55.378 , 55.786 ,
- 56.193 , 56.6 , 57.007 , 57.414 , 57.821 , 58.227 , 58.633 , 59.039 , 59.445 , 59.85 ,
- 60.256 , 60.661 , 61.066 , 61.471 , 61.876 , 62.28 , 62.684 , 63.088 , 63.492 , 63.896 ,
- 64.3 , 64.703 , 65.106 , 65.509 , 65.912 , 66.315 , 66.717 , 67.12 , 67.522 , 67.924 ,
- 68.325 , 68.727 , 69.129 , 69.53 , 69.931 , 70.332 , 70.733 , 71.134 , 71.534 , 71.934 ,
- 72.335 , 72.735 , 73.134 , 73.534 , 73.934 , 74.333 , 74.732 , 75.131 , 75.53 , 75.929 ,
- 76.328 , 76.726 , 77.125 , 77.523 , 77.921 , 78.319 , 78.717 , 79.114 , 79.512 , 79.909 ,
- 80.306 , 80.703 , 81.1 , 81.497 , 81.894 , 82.29 , 82.687 , 83.083 , 83.479 , 83.875 ,
- 84.271 , 84.666 , 85.062 , 85.457 , 85.853 , 86.248 , 86.643 , 87.038 , 87.432 , 87.827 ,
- 88.222 , 88.616 , 89.01 , 89.404 , 89.798 , 90.192 , 90.586 , 90.98 , 91.373 , 91.767 ,
- 92.16 , 92.553 , 92.946 , 93.339 , 93.732 , 94.124 , 94.517 , 94.909 , 95.302 , 95.694 ,
- 96.086 , 96.478 , 96.87 , 97.261 , 97.653 , 98.044 , 98.436 , 98.827 , 99.218 , 99.609 ,
- 100 , 100.391 , 100.781 , 101.172 , 101.562 , 101.953 , 102.343 , 102.733 , 103.123 , 103.513 ,
- 103.903 , 104.292 , 104.682 , 105.071 , 105.46 , 105.849 , 106.238 , 106.627 , 107.016 , 107.405 ,
- 107.794 , 108.182 , 108.57 , 108.959 , 109.347 , 109.735 , 110.123 , 110.51 , 110.898 , 111.286 ,
- 111.673 , 112.06 , 112.447 , 112.835 , 113.221 , 113.608 , 113.995 , 114.382 , 114.768 , 115.155 ,
- 115.541 , 115.927 , 116.313 , 116.699 , 117.085 , 117.47 , 117.856 , 118.241 , 118.627 , 119.012 ,
- 119.397 , 119.782 , 120.167 , 120.552 , 120.936 , 121.321 , 121.705 , 122.09 , 122.474 , 122.858 ,
- 123.242 , 123.626 , 124.009 , 124.393 , 124.777 , 125.16 , 125.543 , 125.926 , 126.309 , 126.692 ,
- 127.075 , 127.458 , 127.84 , 128.223 , 128.605 , 128.987 , 129.37 , 129.752 , 130.133 , 130.515 ,
- 130.897 , 131.278 , 131.66 , 132.041 , 132.422 , 132.803 , 133.184 , 133.565 , 133.946 , 134.326 ,
- 134.707 , 135.087 , 135.468 , 135.848 , 136.228 , 136.608 , 136.987 , 137.367 , 137.747 , 138.126 ,
- 138.506 , 138.885 , 139.264 , 139.643 , 140.022 , 140.4 , 140.779 , 141.158 , 141.536 , 141.914 ,
- 142.293 , 142.671 , 143.049 , 143.426 , 143.804 , 144.182 , 144.559 , 144.937 , 145.314 , 145.691 ,
- 146.068 , 146.445 , 146.822 , 147.198 , 147.575 , 147.951 , 148.328 , 148.704 , 149.08 , 149.456 ,
- 149.832 , 150.208 , 150.583 , 150.959 , 151.334 , 151.71 , 152.085 , 152.46 , 152.835 , 153.21 ,
- 153.584 , 153.959 , 154.333 , 154.708 , 155.082 , 155.456 , 155.83 , 156.204 , 156.578 , 156.952 ,
- 157.325 , 157.699 , 158.072 , 158.445 , 158.818 , 159.191 , 159.564 , 159.937 , 160.309 , 160.682 ,
- 161.054 , 161.427 , 161.799 , 162.171 , 162.543 , 162.915 , 163.286 , 163.658 , 164.03 , 164.401 ,
- 164.772 , 165.143 , 165.514 , 165.885 , 166.256 , 166.627 , 166.997 , 167.368 , 167.738 , 168.108 ,
- 168.478 , 168.848 , 169.218 , 169.588 , 169.958 , 170.327 , 170.696 , 171.066 , 171.435 , 171.804 ,
- 172.173 , 172.542 , 172.91 , 173.279 , 173.648 , 174.016 , 174.384 , 174.752 , 175.12 , 175.488 ,
- 175.856 , 176.224 , 176.591 , 176.959 , 177.326 , 177.693 , 178.06 , 178.427 , 178.794 , 179.161 ,
- 179.528 , 179.894 , 180.26 , 180.627 , 180.993 , 181.359 , 181.725 , 182.091 , 182.456 , 182.822 ,
- 183.188 , 183.553 , 183.918 , 184.283 , 184.648 , 185.013 , 185.378 , 185.743 , 186.107 , 186.472 ,
- 186.836 , 187.2 , 187.564 , 187.928 , 188.292 , 188.656 , 189.019 , 189.383 , 189.746 , 190.11 ,
- 190.473 , 190.836 , 191.199 , 191.562 , 191.924 , 192.287 , 192.649 , 193.012 , 193.374 , 193.736 ,
- 194.098 , 194.46 , 194.822 , 195.183 , 195.545 , 195.906 , 196.268 , 196.629 , 196.99 , 197.351 ,
- 197.712 , 198.073 , 198.433 , 198.794 , 199.154 , 199.514 , 199.875 , 200.235 , 200.595 , 200.954 ,
- 201.314 , 201.674 , 202.033 , 202.393 , 202.752 , 203.111 , 203.47 , 203.829 , 204.188 , 204.546 ,
- 204.905 , 205.263 , 205.622 , 205.98 , 206.338 , 206.696 , 207.054 , 207.411 , 207.769 , 208.127 ,
- 208.484 , 208.841 , 209.198 , 209.555 , 209.912 , 210.269 , 210.626 , 210.982 , 211.339 , 211.695 ,
- 212.052 , 212.408 , 212.764 , 213.12 , 213.475 , 213.831 , 214.187 , 214.542 , 214.897 , 215.252 ,
- 215.608 , 215.962 , 216.317 , 216.672 , 217.027 , 217.381 , 217.736 , 218.09 , 218.444 , 218.798 ,
- 219.152 , 219.506 , 219.86 , 220.213 , 220.567 , 220.92 , 221.273 , 221.626 , 221.979 , 222.332 ,
- 222.685 , 223.038 , 223.39 , 223.743 , 224.095 , 224.447 , 224.799 , 225.151 , 225.503 , 225.855 ,
- 226.206 , 226.558 , 226.909 , 227.26 , 227.612 , 227.963 , 228.314 , 228.664 , 229.015 , 229.366 ,
- 229.716 , 230.066 , 230.417 , 230.767 , 231.117 , 231.467 , 231.816 , 232.166 , 232.516 , 232.865 ,
- 233.214 , 233.564 , 233.913 , 234.262 , 234.61 , 234.959 , 235.308 , 235.656 , 236.005 , 236.353 ,
- 236.701 , 237.049 , 237.397 , 237.745 , 238.093 , 238.44 , 238.788 , 239.135 , 239.482 , 239.829 ,
- 240.176 , 240.523 , 240.87 , 241.217 , 241.563 , 241.91 , 242.256 , 242.602 , 242.948 , 243.294 ,
- 243.64 , 243.986 , 244.331 , 244.677 , 245.022 , 245.367 , 245.713 , 246.058 , 246.403 , 246.747 ,
- 247.092 , 247.437 , 247.781 , 248.125 , 248.47 , 248.814 , 249.158 , 249.502 , 249.845 , 250.189 ,
- 250.533 , 250.876 , 251.219 , 251.562 , 251.906 , 252.248 , 252.591 , 252.934 , 253.277 , 253.619 ,
- 253.962 , 254.304 , 254.646 , 254.988 , 255.33 , 255.672 , 256.013 , 256.355 , 256.696 , 257.038 ,
- 257.379 , 257.72 , 258.061 , 258.402 , 258.743 , 259.083 , 259.424 , 259.764 , 260.105 , 260.445 ,
- 260.785 , 261.125 , 261.465 , 261.804 , 262.144 , 262.483 , 262.823 , 263.162 , 263.501 , 263.84 ,
- 264.179 , 264.518 , 264.857 , 265.195 , 265.534 , 265.872 , 266.21 , 266.548 , 266.886 , 267.224 ,
- 267.562 , 267.9 , 268.237 , 268.574 , 268.912 , 269.249 , 269.586 , 269.923 , 270.26 , 270.597 ,
- 270.933 , 271.27 , 271.606 , 271.942 , 272.278 , 272.614 , 272.95 , 273.286 , 273.622 , 273.957 ,
- 274.293 , 274.628 , 274.963 , 275.298 , 275.633 , 275.968 , 276.303 , 276.638 , 276.972 , 277.307 ,
- 277.641 , 277.975 , 278.309 , 278.643 , 278.977 , 279.311 , 279.644 , 279.978 , 280.311 , 280.644 ,
- 280.978 , 281.311 , 281.643 , 281.976 , 282.309 , 282.641 , 282.974 , 283.306 , 283.638 , 283.971 ,
- 284.303 , 284.634 , 284.966 , 285.298 , 285.629 , 285.961 , 286.292 , 286.623 , 286.954 , 287.285 ,
- 287.616 , 287.947 , 288.277 , 288.608 , 288.938 , 289.268 , 289.599 , 289.929 , 290.258 , 290.588 ,
- 290.918 , 291.247 , 291.577 , 291.906 , 292.235 , 292.565 , 292.894 , 293.222 , 293.551 , 293.88 ,
- 294.208 , 294.537 , 294.865 , 295.193 , 295.521 , 295.849 , 296.177 , 296.505 , 296.832 , 297.16 ,
- 297.487 , 297.814 , 298.142 , 298.469 , 298.795 , 299.122 , 299.449 , 299.775 , 300.102 , 300.428 ,
- 300.754 , 301.08 , 301.406 , 301.732 , 302.058 , 302.384 , 302.709 , 303.035 , 303.36 , 303.685 ,
- 304.01 , 304.335 , 304.66 , 304.985 , 305.309 , 305.634 , 305.958 , 306.282 , 306.606 , 306.93 ,
- 307.254 , 307.578 , 307.902 , 308.225 , 308.549 , 308.872 , 309.195 , 309.518 , 309.841 , 310.164 ,
- 310.487 , 310.81 , 311.132 , 311.454 , 311.777 , 312.099 , 312.421 , 312.743 , 313.065 , 313.386 ,
- 313.708 , 314.029 , 314.351 , 314.672 , 314.993 , 315.314 , 315.635 , 315.956 , 316.277 , 316.597 ,
- 316.918 , 317.238 , 317.558 , 317.878 , 318.198 , 318.518 , 318.838 , 319.157 , 319.477 , 319.796 ,
- 320.116 , 320.435 , 320.754 , 321.073 , 321.391 , 321.71 , 322.029 , 322.347 , 322.666 , 322.984 ,
- 323.302 , 323.62 , 323.938 , 324.256 , 324.573 , 324.891 , 325.208 , 325.526 , 325.843 , 326.16 ,
- 326.477 , 326.794 , 327.11 , 327.427 , 327.744 , 328.06 , 328.376 , 328.692 , 329.008 , 329.324 ,
- 329.64 , 329.956 , 330.271 , 330.587 , 330.902 , 331.217 , 331.533 , 331.848 , 332.162 , 332.477 ,
- 332.792 , 333.106 , 333.421 , 333.735 , 334.049 , 334.363 , 334.677 , 334.991 , 335.305 , 335.619 ,
- 335.932 , 336.246 , 336.559 , 336.872 , 337.185 , 337.498 , 337.811 , 338.123 , 338.436 , 338.748 ,
- 339.061 , 339.373 , 339.685 , 339.997 , 340.309 , 340.621 , 340.932 , 341.244 , 341.555 , 341.867 ,
- 342.178 , 342.489 , 342.8 , 343.111 , 343.422 , 343.732 , 344.043 , 344.353 , 344.663 , 344.973 ,
- 345.284 , 345.593 , 345.903 , 346.213 , 346.522 , 346.832 , 347.141 , 347.451 , 347.76 , 348.069 ,
- 348.378 , 348.686 , 348.995 , 349.303 , 349.612 , 349.92 , 350.228 , 350.536 , 350.844 , 351.152 ,
- 351.46 , 351.768 , 352.075 , 352.382 , 352.69 , 352.997 , 353.304 , 353.611 , 353.918 , 354.224 ,
- 354.531 , 354.837 , 355.144 , 355.45 , 355.756 , 356.062 , 356.368 , 356.674 , 356.979 , 357.285 ,
- 357.59 , 357.896 , 358.201 , 358.506 , 358.811 , 359.116 , 359.42 , 359.725 , 360.029 , 360.334 ,
- 360.638 , 360.942 , 361.246 , 361.55 , 361.854 , 362.158 , 362.461 , 362.765 , 363.068 , 363.371 ,
- 363.674 , 363.977 , 364.28 , 364.583 , 364.886 , 365.188 , 365.491 , 365.793 , 366.095 , 366.397 ,
- 366.699 , 367.001 , 367.303 , 367.604 , 367.906 , 368.207 , 368.508 , 368.81 , 369.111 , 369.412 ,
- 369.712 , 370.013 , 370.314 , 370.614 , 370.914 , 371.215 , 371.515 , 371.815 , 372.115 , 372.414 ,
- 372.714 , 373.013 , 373.313 , 373.612 , 373.911 , 374.21 , 374.509 , 374.808 , 375.107 , 375.406 ,
- 375.704 , 376.002 , 376.301 , 376.599 , 376.897 , 377.195 , 377.493 , 377.79 , 378.088 , 378.385 ,
- 378.683 , 378.98 , 379.277 , 379.574 , 379.871 , 380.167 , 380.464 , 380.761 , 381.057 , 381.353 ,
- 381.65 , 381.946 , 382.242 , 382.537 , 382.833 , 383.129 , 383.424 , 383.72 , 384.015 , 384.31 ,
- 384.605 , 384.9 , 385.195 , 385.489 , 385.784 , 386.078 , 386.373 , 386.667 , 386.961 , 387.255 ,
- 387.549 , 387.843 , 388.136 , 388.43 , 388.723 , 389.016 , 389.31 , 389.603 , 389.896 , 390.188 ,
- };
复制代码
- //查找索引
- short findRTDInterpolationIndex (double ohm)
- {
- unsigned short i;
- unsigned short RTD_TableCount = sizeof(RTD_Table)/sizeof(RTD_Table[0]);
- for (i=0; i< RTD_TableCount; i++)
- {
- if (RTD_Table[i] > ohm)
- return (i-1);
- }
- return (RTD_TableCount);
- }
- //通过电压查找分度表计算对应温度
- double ConverRTD2Temperature(double ohm)
- {
- unsigned short index;
- double temperature;
- //查找当前电阻在分度表中的位置索引
- index = findRTDInterpolationIndex(ohm);
- //举例
- //RTDTable[] = {1,3,8,10,20};//ohm
- //如果输入数据是4.3ohm
- //查找到索引得到对应的电阻为3
- //用当前电压减索引电阻4.3-3=1.3
- //再用上一个刻度减去当前刻度8-3 = 5
- //每个刻度为1摄氏度间隔
- //1.3/5=0.26 * 1度,得到当前刻度中对应的小数温度
- //再用计算后的小数温度+当前索引=1+0.26 = 1.26
- //因为索引不是从零度开始,假设从-1开始,那索引1则对应0度
- //用1.26+分度表里的最低温度-1即得到0.26为当前计算后的温度
- temperature = (ohm - RTD_Table[index]) / (RTD_Table[index + 1]- RTD_Table[index]) + index + RTD_TABLE_TEMP_MIN;
- return temperature;
- }
复制代码
附上MSP430的测试工程
|