我在其它论坛看到一段不错的程序,希望对各位有用
热电阻PT10 PT100 Cu50 Cu100电阻转温度程序
/*******************************************************************************
*函数描述:PT10&PT100 Cu50&Cu100 热阻转温度
*输入变量:R 热阻阻值
type热电阻类型 0 PT10
1 PT100
2 Cu50
3 Cu100
*返回变量:float T 温度
*******************************************************************************/
float RtoT(float R, uchar type)
{
uchar R0; // 热电阻0度时阻值
float T, tmp, min, mid, max;
float x, y, z;
float d = 3.9083/1e3, b = -5.775/1e7, c = -4.183/1e12;
if(type <= 1)
{
if(type == 0)
{
R0 = 10; min = 1.852; mid = 10; max = 39.049; // Pt10
}
else
{
R0 = 100; min = 18.52; mid = 100; max = 390.49; // Pt100
}
if(R>=mid && R<=max)
{
y = sqrt(d*d - 4*b*(1-R/R0));
T = (y-d) / (2*b); // 得出温度
}
else if(R<mid && R>=min)
{
x = 0; y = -100; z = -201;
tmp = R0*(1 + d*y + b*y*y + c*(y-100)*y*y*y);
while(fabs(tmp-R)>=0.007)
{
if(R > tmp)
{
x = x; z = y;
y = (x+y)/2;
}
else
{
x = y; z = z;
y = (y+z)/2;
}
tmp = R0*(1 + d*y + b*y*y + c*(y-100)*y*y*y);
}
T = y; // 得出温度
}
}
else
{
if(type == 2) // Cu50
R0 = 50;
else // Cu100
R0 = 100;
x = 150; y = 50; z = -50;
tmp = R0*(1 + 4.289/1e3*y - 2.133/1e7*y*y + 1.233/1e9*y*y*y);
while(fabs(tmp-R)>=0.007)
{
if(R > tmp)
{
x = x; z = y;
y = (x+y)/2;
}
else
{
x = y; z = z;
y = (y+z)/2;
}
tmp = R0*(1 + 4.28899/1e3*y - 2.133/1e7*y*y + 1.233/1e9*y*y*y);
}
T = y;
}
return T;
}
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
一周热门 更多>