// 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;
}