Chinaunix首页 | 论坛 | 博客
  • 博客访问: 288702
  • 博文数量: 38
  • 博客积分: 3010
  • 博客等级: 中校
  • 技术积分: 392
  • 用 户 组: 普通用户
  • 注册时间: 2007-01-22 19:12
文章分类

全部博文(38)

文章存档

2009年(1)

2008年(4)

2007年(33)

我的朋友

分类: C/C++

2007-01-25 10:41:36

设计热电偶/热电阻式温度采集电路,将采集值转换成温度值是件麻烦事,因为其温度关系曲线不是线性的,可以近似看作高次方程曲线,而一般采集得到的数据都是用单片机来做温度值转换,让单片机去求解高次方程显然不现实,所以一般都是采用分段线性化的方法来计算温度值,这个分段方法技巧就不去介绍了,这里主要来探讨分段线性化对应表(分度表)的生成,网络上有不少这种表格,但是这种表格一般精度不高,而且不一定符合我们的分段要求,所以这里介绍程序生成分度表.B型热电偶为例:
其温度-电压关系曲线方程为:

t90=c0+c1E+c2E+2+c3E+3…ciE+i(注,+i表示E的i次方)

其中t90是温度值(计算所得),E是热电偶产生的电动势(采集所得),c是常量,下面是c的取值表:

温度范围:
250 to 700°C
700 to 1,820°C
电压范围:
291 to 2,431 m V
2,431 to 13,820 m V
c0
=
9.842 332 1 x 10+1
2.131 507 1 x 10+2
c1
=
6.997 150 0 x 10-1
2.851 050 4 x 10-1
c2
=
-8.476 530 4 x 10-4
-5.274 288 7 x 10-5
c3
=
1.005 264 4 x 10-6
9.916 080 4 x 10-9
c4
=
-8.334 595 2 x 10-10
-1.296 530 3 x 10-12
c5
=
4.550 854 2 x 10-13
1.119 587 0 x 10-16
c6
=
-1.552 303 7 x 10-16
-6.062 519 9 x 10-21
c7
=
2.988 675 0 x 10-20
1.866 169 6 x 10-25
c8
=
-2.474 286 0 x 10-24
-2.487 858 5 x 10-30
错误范围:
0.03 to -0.02°C
0.02 to -0.01°C

(表中如-2.474 286 0 x 10-24后面可是-24次方, -2.131 507 1 x 10+2后面是2次方)
下面是根据温度求电动势的逆方程:
 

E=c0+c1t90+c2t90+2….cit90+i

常量取值表如下:

温度范围:
0 to 630.615°C
630.615 to 1,820°C
c0=
 c1=
 c2=
 c3=
 c4=
 c5=
 c6=
 c7=
 c8=
0.000 000 000 0 ....
 -2.465 081 834 6 x10-1 5.904 042 117 1 x 10-3 -1.325 793 163 6 x 10-6 1.566 829 190 1 x 10-9 -1.694 452 924 0 x 10-12 6.229 034 709 4 x 10-16
-3.893 816 862 1 x 103
2.857 174 747 0 x 101
 -8.488 510 478 5 x 10-2
1.578 528 016 4 x 10-4
-1.683 534 486 4 x 10-7
 1.110 979 401 3 x 10-10
 -4.451 543 103 3 x 10-14
 9.897 564 082 1 x 10-18
-9.379 133 028 9 x 10-22

根据公式可以设计程序来完成计算,下面是一个计算分段为1摄氏度和1uV的小程序:

#include <math.h>
#include <stdio.h>
#define C00 0.0000
//0-630.615

#define C10 -2.4650818346e-1
#define C20 5.9040421171e-3
#define C30 -1.3257931636e-6
#define C40 1.5668291901e-9
#define C50 -1.6944529240e-12
#define C60 6.2290347094e-16
//630.615-1820

#define C01 -3893.8168621
#define C11 28.571747470
#define C21 -8.4885104785e-2
#define C31 1.5785280164e-4
#define C41 -1.6835344864e-7
#define C51 1.1109794013e-10
#define C61 -4.4515431033e-14
#define C71    9.8975640821e-18
#define C81 -9.3791330289e-22
//291-2431uV;250-700

#define C02 98.423321
#define C12 6.9971500e-1
#define C22 -8.4765304e-4
#define C32 1.0052644e-6
#define C42 -8.3345952e-10
#define C52 4.5508542e-13
#define C62 -1.5523037e-16
#define C72 2.9886750e-20
#define C82 -2.4742860e-24
//2431-13820uV;700-1820

#define C03 213.15071
#define C13 2.8510504e-1
#define C23 -5.2742887e-5
#define C33 9.9160804e-9
#define C43 -1.2965303e-12
#define C53 1.1195870e-16
#define C63 -6.0625199e-21
#define C73 1.8661696e-25
#define C83 -2.4878585e-30
int main(void)
{
    double t,e;//t=temperature e = electronictive force

    int i,j;
    for(i=0;i<631;i++)
    {
        t = (double)i;
        e = C00+C10*t+C20*t*t+C30*t*t*t+C40*t*t*t*t+C50*t*t*t*t*t+C60*t*t*t*t*t*t;
        printf("t = %g, e = %g\n",t,e);

    }
    printf("t from 0-630 ended!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");    
for(i=631;i<1821;i++)
        {
                t = (double)i;
                e = C01+C11*t+C21*t*t+C31*t*t*t+C41*t*t*t*t+C51*t*t*t*t*t+C61*t*t*t*t*t*t+C71*t*t*t*t*t*t*t+C81*t*t*t*t*t*t*t*t;
                printf("t = %g, e = %g\n",t,e);
        }
        printf("t from 631-1820 ended!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
        for(j=291;j<2432;j++)
        {
                e = (double)j;
                t = C02+C12*e+C22*e*e+C32*e*e*e+C42*e*e*e*e+C52*e*e*e*e*e+C62*e*e*e*e*e*e+C72*e*e*e*e*e*e*e+C82*e*e*e*e*e*e*e*e;
                printf("e = %g, t = %g\n",e,t);
        }
          printf("t from 291- 2431 ended!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
        for(j=2432;j<13821;j++)
        {
                e = (double)j;
                t = C03+C13*e+C23*e*e+C33*e*e*e+C43*e*e*e*e+C53*e*e*e*e*e+C63*e*e*e*e*e*e+C73*e*e*e*e*e*e*e+C83*e*e*e*e*e*e*e*e;
                printf("e = %g, t = %g\n",e,t);
        }
           printf("t from 291- 2431 ended!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!\n");
}

对于热电阻,方法一样,公式为(PT100):

R=R0(1+AT+BT+2+CT+3(T-100))

 

R是采集的阻值,T是求得的温度值,R0=100, A = 3.90830 x 10 -3. B = -5.775 x 10 -7. C = 0 如果 T > 0 否则C= -4.183 x 10 -12.(,那个-3-3次方)

程序实现就略了,通过该公式开可以计算分段误差.

上面的程序在Linux下编译运行通过.其他类型的那些个公式可以在网上找到,曾经想做个小软件,Qt写个界面,计算8种热电偶和几种热电阻的分度表,可以设置精度自动分段,可惜没时间.

(上面的公式太难看,没办法)

阅读(7486) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-04-13 19:02:54

我也在写这个,其他的都好说,就是K型大于0度的公式没看懂e是什么?