|
楼主 |
发表于 2011-3-30 14:46:01
|
显示全部楼层
热电偶Thermistor (十七)
(原文件名:1连接原理图.jpg)
(原文件名:测量热电偶.jpg)
(原文件名:触摸后.jpg)
(原文件名:未触摸.jpg)
主要代码:
/* Look up table temperature from -40 to +125 degree C */
const uint32 Thermistor_TempTable[] =
{
328996,307906,288311,270096,253153,
237386,222670,208964,196194,184288,
173184,162822,153148,144112,135667,
127773,120404,113506,107048,100997,
95326,89988,84983,80288,75882,
71745,67874,64235,60812,57593,
54563,51698,49000,46460,44068,
41813,39690,37687,35798,34014,
32330,30737,29232,27810,26465,
25193,23990,22851,21773,20752,
19785,18868,17998,17174,16392,
15650,14946,14278,13644,13041,
12468,11923,11406,10913,10445,
10000,9575,9172,8787,8421,
8072,7739,7422,7119,6831,
6555,6293,6042,5803,5574,
5356,5147,4948,4757,4575,
4400,4233,4074,3921,3775,
3635,3501,3372,3249,3131,
3018,2910,2807,2707,2612,
2520,2432,2348,2267,2189,
2114,2042,1973,1906,1842,
1781,1722,1665,1611,1559,
1509,1460,1413,1368,1325,
1283,1243,1204,1167,1131,
1096,1063,1030,999,969,
940,912,885,859,834,
810,786,764,742,720,
700,680,661,643,625,
607,591,575,559,544,
529,515,501,488,475,
463,451,439,427,416,
406,395,385,376,366,
357
};
void main()
{
uint16 Vpower=0,Vsense=0;
uint8 temp=0;
int Count=0;
//uint8 outputStr[8]={'0'};
int32 ThermistorResistance; /* Thermistor resistance variable */
long Thermistor_Temperature; /* compter thermistor temperature * 10 */
long TempTable_UpperLimit, TempTable_LowerLimit; /* Linear Interpolation variables */
long TempTable_Decimal; /* Fractional portion of temperature */
/* Place your initialization/startup code here (e.g. MyInst_Start()) */
LCD_1602_Start();//启动LCD1602
LCD_1602_Position(0,0);
LCD_1602_PrintString("Thermistor");
LCD_1602_Position(1,0);
LCD_1602_PrintString("WEN DU: C");
/* CYGlobalIntEnable; */ /* Uncomment this line to enable global interrupts. */
VDAC8_1_Start();
ADC1_Start();
//ADC1_StartConvert();//开始转换
AMux_1_Start();
for(;;)
{
/* Place your application code here. */
/* Set Amux channel0 and read voltage across reference resistor */
AMux_1_Select(0);
ADC1_Stop();
ADC1_Start();
ADC1_StartConvert();
ADC1_IsEndConversion(ADC1_WAIT_FOR_RESULT);
Vsense = ADC1_GetResult16();//测量sense处电压
AMux_1_Select(1);
ADC1_Stop();
ADC1_Start();
ADC1_StartConvert();
ADC1_IsEndConversion(ADC1_WAIT_FOR_RESULT);
Vpower = ADC1_GetResult16();//测量power处电压
ThermistorResistance = ((int32)(Vsense * (int32)THERM_RREF) / ((int32)(Vpower - Vsense)));
for(Count = 0; Thermistor_TempTable[Count] >= ThermistorResistance; Count++);//查表
/* Piece-wise linear approximation to find fractional value between 1C increments to
* calculate temperature to 1 decimal place */
TempTable_Decimal = 0;
TempTable_LowerLimit = Thermistor_TempTable[Count];
TempTable_UpperLimit = Thermistor_TempTable[Count-1];
//根据表中两个点之间接近线性,估计小数点一位
TempTable_Decimal = ((TempTable_UpperLimit - ThermistorResistance) * 10) / (TempTable_UpperLimit - TempTable_LowerLimit);
Thermistor_Temperature = (Count - 40 - 1) * 10 + (TempTable_Decimal);
//sprintf(outputStr, "%d", Thermistor_Temperature);
LCD_1602_Position(1,7);//温度显示
//LCD_1602_PrintString(outputStr);
temp=Thermistor_Temperature/100+0x30;
LCD_1602_PutChar(temp);
temp=Thermistor_Temperature/10%10+0x30;
LCD_1602_PutChar(temp);
LCD_1602_PutChar('.');
temp=Thermistor_Temperature%10+0x30;
LCD_1602_PutChar(temp);
delay(100000);
}
} |
|