float temprature;
1.直接计算法
//12位adc 基准要用上拉电阻Rp供电相同(3v3)!!!
//NTC B值 Bx_sel=3950/3450/...
float Get_Temp_ad(u16 Bx_sel,u32 adc)
{
#if true
if(Bx_sel<3000||Bx_sel>5000)return -1;Bx=Bx_sel;
#else
const u16 Bxs[]={3380,3950,3980};
if(Bx_sel>sizeof(Bxs)/2)Bx_sel=0;Bx = Bxs[Bx_sel];
#endif
float Rt;
float temp;
// int ADC_MAX=2^12;
//3980;//3950.0;//B3380
// Rt = Get_TempResistor(channel_channel);Rt_/Rp+Rt_=ad/4096; 1+Rp/Rt= 40960/ad; Rt=Rp/(4096.0f/ad-1); 12位adc 基准要用Rp供电相同(3v3)!!!
Rt=Rp/(4096.0f/adc-1);//RP 10k, Rt~10k~25℃ //RP 100k, Rt~100k~25℃
//like this R=5000, T2=273.15+25,B=3470, RT=5000*EXP(3470*(1/T1-1/(273.15+25)),
temp = Rt/Rp;
temp = log(temp);//ln(Rt/Rp)
temp/=Bx;//ln(Rt/Rp)/B
temp+=(1/T2);
temp = 1/(temp);
temp-=Ka;
return temp;
}
2.精度和时间要求不高时 ,顺序查表法
s8 get_temprature_NTC10K(u16 adc)//12位adc
{
//#define countof(a) (sizeof(a)/(*a))
#define _countof(_Array) (sizeof(_Array) / sizeof(_Array[0]))
const u16 NTC10K3435_AD_10du[]={3586,3329,3006,2635,2243,1859,1507,1202,950,747,587,460,361,284};/