生成 温度-AD 对照表
来源:互联网 发布:php bin2hex 编辑:程序博客网 时间:2024/05/01 12:15
// Test.cpp : Defines the entry point for the console application.
//
#include "stdafx.h"
#include <stdio.h>
#include <memory.h>
#include <iostream>
#include <math.h>
#include "SystemParameter.h"
#define Bn 3380 //热敏电阻的B值
#define K 273.15
#define T_10k (K + 25)//25度开尔文温度
#define R_10k 10000.0//the Resistance of the thermistor when Temperature is 25 degree
//the parameter of the amplifier circuit
#define AMPLIFY_REF_VOLT 2.5//2.5V
#define AMPLIFY_REF_DEVIDE_RESI 68100.0//
#define AMPLIFY_REF_RESI 15000.0//
#define AMPLIFY_NEGATIVE_INPUT_VOLT ((AMPLIFY_REF_VOLT*AMPLIFY_REF_RESI)/(AMPLIFY_REF_DEVIDE_RESI+AMPLIFY_REF_RESI))
#define AMPLIFY_FACTOR_RESI 10000.0//10ko
#define AMPLIFY_FEEDBACK_RESI 20000.0//21ko
//#define AMPLIFY_FEEDBACK_RESI 60000.0//21ko
//the parameter of the therm
#define THERM_REF_VOLT 2.5//2.5V
//#define THERM_DIVIDED_RESI 6980.0//the Resistance of the Therm Divided Resistor
#define THERM_DIVIDED_RESI 7680.0//the Resistance of the Therm Divided Resistor
//the parameter of the mcu
#define MCU_VOLT_REF 2.5//the reference voltage for the arm
#define AD_RESOLUTION (1023)//the resolution of the ARM's AD
#define OUTPUT_MAGNIFIED_10_TIMES 10//magnify the temperature 10 times when write to the TempTable file
void WriteTempTable(FILE *TempTable, int AD_Resolution);
int WriteTempLine(FILE *fpTable, double Tc, int Magnified, UINT16 Comment);
double ConvRtToTemp(double Resi);
double ConvAD_RegToResi(double Rd, UINT16 AD_Reg);
int _tmain(int argc, _TCHAR* argv[])
{
FILE *TempTable;
TempTable=fopen("./TempTable.txt","w");
WriteTempTable(TempTable, AD_RESOLUTION + 1);
fclose(TempTable);
system("pause");
return 0;
}
void WriteTempTable(FILE *TempTable, int AD_Resolution)
{
UINT16 AD_Reg;
double Rt;
double Temp;
for(AD_Reg = 0; AD_Reg < AD_Resolution;AD_Reg++)
{
Rt = ConvAD_RegToResi(THERM_DIVIDED_RESI, AD_Reg);
Temp = ConvRtToTemp(Rt);
WriteTempLine(TempTable, Temp,OUTPUT_MAGNIFIED_10_TIMES, AD_Reg);
}
}
int WriteTempLine(FILE *fpTable, double Tc, int Magnified, UINT16 Comment)
{
char TempLine[20] = {0};
if(fpTable == NULL)
return -1;
Tc *= Magnified;
sprintf(TempLine, "%-4.0lf, //%d\n", Tc, Comment);
printf("%s",TempLine);
printf("the sizeof TempLine is %d \n",strlen(TempLine));
fwrite(TempLine, strlen(TempLine), 1, fpTable);
return 0;
}
double ConvRtToTemp(double Rt)
{
double Tmp=0;
double T;
double Tc;
Tmp=log((Rt/R_10k));
T=1/(Tmp/Bn + 1.0/T_10k);
Tc = T - K;
//printf("TMP= %lf \n",Tc);
return Tc;
}
double ConvAD_RegToResi(double Rd, UINT16 AD_Reg)
{
//Rh=(Rd*((2/3)*(AD*2.5/1023)+0.45))/(2.05-(2/3)*(AD*2.5/1023))
double Rt;
double AD_Volt;
double Deno;
double Nume;
AD_Volt = MCU_VOLT_REF*AD_Reg/AD_RESOLUTION;
Deno = Rd*(( (AMPLIFY_FACTOR_RESI/AMPLIFY_FEEDBACK_RESI) *AD_Volt) + AMPLIFY_NEGATIVE_INPUT_VOLT);
Nume = THERM_REF_VOLT -AMPLIFY_NEGATIVE_INPUT_VOLT - (AMPLIFY_FACTOR_RESI/AMPLIFY_FEEDBACK_RESI)*AD_Volt;
Rt = Deno / Nume;
//printf("the Rt is %lf \n ", Rt);
return Rt;
}
//
#include "stdafx.h"
#include <stdio.h>
#include <memory.h>
#include <iostream>
#include <math.h>
#include "SystemParameter.h"
#define Bn 3380 //热敏电阻的B值
#define K 273.15
#define T_10k (K + 25)//25度开尔文温度
#define R_10k 10000.0//the Resistance of the thermistor when Temperature is 25 degree
//the parameter of the amplifier circuit
#define AMPLIFY_REF_VOLT 2.5//2.5V
#define AMPLIFY_REF_DEVIDE_RESI 68100.0//
#define AMPLIFY_REF_RESI 15000.0//
#define AMPLIFY_NEGATIVE_INPUT_VOLT ((AMPLIFY_REF_VOLT*AMPLIFY_REF_RESI)/(AMPLIFY_REF_DEVIDE_RESI+AMPLIFY_REF_RESI))
#define AMPLIFY_FACTOR_RESI 10000.0//10ko
#define AMPLIFY_FEEDBACK_RESI 20000.0//21ko
//#define AMPLIFY_FEEDBACK_RESI 60000.0//21ko
//the parameter of the therm
#define THERM_REF_VOLT 2.5//2.5V
//#define THERM_DIVIDED_RESI 6980.0//the Resistance of the Therm Divided Resistor
#define THERM_DIVIDED_RESI 7680.0//the Resistance of the Therm Divided Resistor
//the parameter of the mcu
#define MCU_VOLT_REF 2.5//the reference voltage for the arm
#define AD_RESOLUTION (1023)//the resolution of the ARM's AD
#define OUTPUT_MAGNIFIED_10_TIMES 10//magnify the temperature 10 times when write to the TempTable file
void WriteTempTable(FILE *TempTable, int AD_Resolution);
int WriteTempLine(FILE *fpTable, double Tc, int Magnified, UINT16 Comment);
double ConvRtToTemp(double Resi);
double ConvAD_RegToResi(double Rd, UINT16 AD_Reg);
int _tmain(int argc, _TCHAR* argv[])
{
FILE *TempTable;
TempTable=fopen("./TempTable.txt","w");
WriteTempTable(TempTable, AD_RESOLUTION + 1);
fclose(TempTable);
system("pause");
return 0;
}
void WriteTempTable(FILE *TempTable, int AD_Resolution)
{
UINT16 AD_Reg;
double Rt;
double Temp;
for(AD_Reg = 0; AD_Reg < AD_Resolution;AD_Reg++)
{
Rt = ConvAD_RegToResi(THERM_DIVIDED_RESI, AD_Reg);
Temp = ConvRtToTemp(Rt);
WriteTempLine(TempTable, Temp,OUTPUT_MAGNIFIED_10_TIMES, AD_Reg);
}
}
int WriteTempLine(FILE *fpTable, double Tc, int Magnified, UINT16 Comment)
{
char TempLine[20] = {0};
if(fpTable == NULL)
return -1;
Tc *= Magnified;
sprintf(TempLine, "%-4.0lf, //%d\n", Tc, Comment);
printf("%s",TempLine);
printf("the sizeof TempLine is %d \n",strlen(TempLine));
fwrite(TempLine, strlen(TempLine), 1, fpTable);
return 0;
}
double ConvRtToTemp(double Rt)
{
double Tmp=0;
double T;
double Tc;
Tmp=log((Rt/R_10k));
T=1/(Tmp/Bn + 1.0/T_10k);
Tc = T - K;
//printf("TMP= %lf \n",Tc);
return Tc;
}
double ConvAD_RegToResi(double Rd, UINT16 AD_Reg)
{
//Rh=(Rd*((2/3)*(AD*2.5/1023)+0.45))/(2.05-(2/3)*(AD*2.5/1023))
double Rt;
double AD_Volt;
double Deno;
double Nume;
AD_Volt = MCU_VOLT_REF*AD_Reg/AD_RESOLUTION;
Deno = Rd*(( (AMPLIFY_FACTOR_RESI/AMPLIFY_FEEDBACK_RESI) *AD_Volt) + AMPLIFY_NEGATIVE_INPUT_VOLT);
Nume = THERM_REF_VOLT -AMPLIFY_NEGATIVE_INPUT_VOLT - (AMPLIFY_FACTOR_RESI/AMPLIFY_FEEDBACK_RESI)*AD_Volt;
Rt = Deno / Nume;
//printf("the Rt is %lf \n ", Rt);
return Rt;
}
0 0
- 生成 温度-AD 对照表
- 温度对照表1
- AD属性对照表
- AD属性对照表
- AD属性对照表
- AD属性对照表[AD域][DirectoryEntry]
- AD用户帐户属性对照表
- AD用户帐户属性对照表
- AD域用户账户属性对照表
- AD元件简写中英文对照表
- 算法:输出华氏和摄氏的温度对照表
- 活动目录用户属性与AD字段对照表
- AD属性对照表 LDAP以及简单示例
- Windows AD域用户属性对照表(综合整理)
- zigbee cc2530 AD 转换温度 学习总结
- 发一个NTC 阻值温度对照公式
- GBK与Unicode对照表的生成
- AD生成Gerber
- 线程安全与并发编程探究(七)--volatile java内存模型及线程知识小结
- HTML5应用localStorage保存数据
- C语言基础知识
- hdoj---Rescue
- IP地址CString和DWORD转换
- 生成 温度-AD 对照表
- SIOCADDRT: No such process
- CSS3选择器
- TableLayout的使用来制作表格
- 如何高效地使用Launcher,如果你还没删的话
- HDOJ 1728 逃离迷宫(BFS)
- 【转载】cocos2d-x 2.1下使用CCLabelTTF显示汉字的问题
- 使用jquery跳转a标签
- nexus配置方法说明