在做温度控制时都会遇到热电偶电势转换到温度、温度转换到电势,如果查表编程比较麻烦。我根据热电偶的正函数和反函数编了2个转换函数,个人认为比较方便,而且网上也很少有热电偶的正函数和反函数的资料,所以我show给大家看看,也许各位会用到。这2个函数是针对K型热电偶的。
注:之前的VtoTemp()函数没有包含负电压的转换,而且还有错误,现在已经做了修改。
‘温度转换为电压值
Private Function TempToV(t As Double)
Dim C(9) As Double
Dim a1 As Double
Dim a0 As Double
C(0) = -0.017600413686
C(1) = 0.038921204975
C(2) = 0.000018558770032
C(3) = -9.9457592874E-08
C(4) = 3.1840945719E-10
C(5) = -5.6072844889E-13
C(6) = 5.6075059059E-16
C(7) = -3.2020720003E-19
C(8) = 9.7151147152E-23
C(9) = -1.2104721275E-26
a0 = 0.1185976
a1 = -0.0001183432
V = 0
If t = 0 Then
TempToV = 0
Else
For I = 0 To 9
V = V + C(I) * t ^ I
Next
TempToV = V + a0 * Exp(a1 * (t - 126.9686) ^ 2)
End If
End Function
’电压值转温度 K型热电偶反函数
Function VtoTemp(V As Double) As Double ‘V为mV单位
’Dim V As Double
‘-5.891mV~0(-200℃~0℃)
Dim C2(10) As Double
C2(0) = 0
C2(1) = 25.173462
C2(2) = -1.1662878
C2(3) = -1.0833638
C2(4) = -0.8977354
C2(5) = -0.37342377
C2(6) = -0.086632643
C2(7) = -0.010450598
C2(8) = -0.00051920577
’0.~20.644mV(0℃~500℃)
Dim C0(9) As Double
C0(0) = 0
C0(1) = 25.08355
C0(2) = 0.07860106
C0(3) = -0.2503131
C0(4) = 0.0831527
C0(5) = -0.01228034
C0(6) = 0.0009804036
C0(7) = -0.0000441303
C0(8) = 0.000001057734
C0(9) = -0.00000001052755
‘20.644~54.886(500℃~1372℃)
Dim C1(6) As Double
C1(0) = -131.8058
C1(1) = 48.30222
C1(2) = -1.646031
C1(3) = 0.05464731
C1(4) = -0.0009650715
C1(5) = 0.000008802193
C1(6) = -0.0000000311081
Dim Temp As Double
If V 《 0 Then ’-5.891mV(-200)
For i = 0 To 8
Temp = Temp + C2(i) * V ^ i
Next
ElseIf V 》= 0 And V 《 20.644 Then
For i = 0 To 9
Temp = Temp + C0(i) * V ^ i
Next
ElseIf V 》= 20.644 Then ‘54.866(1372)
For i = 0 To 6
Temp = Temp + C1(i) * V ^ i
Next
End If
VtoTemp = Temp
End Function
-
热电偶
+关注
关注
5文章
939浏览量
75575 -
代码
+关注
关注
30文章
4788浏览量
68625
发布评论请先 登录
相关推荐
评论