热敏电阻温度探测查表方法

Excel表格 百度云盘下载

链接: link.
R1是串联的电阻值
在这里插入图片描述
热敏电阻的线性图
在这里插入图片描述

stm32F030C8T6程序:

博客设置页面,选择一款你喜欢的代码片高亮样式,下面展示同样高亮的 代码片.


/*******************************************
ADC 温度转换
********************************************/
const u16 NTCTab[]=
{
0xF6B,//-20℃
0xF63,//-19℃
0xF5A,//-18℃
0xF51,//-17℃
0xF47,//-16℃
0xF3D,//-15℃
0xF33,//-14℃
0xF28,//-13℃
0xF1D,//-12℃
0xF11,//-11℃
0xF05,//-10℃
0xEF8,//-9℃
0xEEB,//-8℃
0xEDD,//-7℃
0xECE,//-6℃
0xEBF,//-5℃
0xEAF,//-4℃
0xE9F,//-3℃
0xE8E,//-2℃
0xE7D,//-1℃
0xE6B,//0℃
0xE58,//1℃
0xE45,//2℃
0xE31,//3℃
0xE1C,//4℃
0xE06,//5℃
0xDEF,//6℃
0xDD9,//7℃
0xDC2,//8℃
0xDA9,//9℃
0xD90,//10℃
0xD77,//11℃
0xD5C,//12℃
0xD41,//13℃
0xD25,//14℃
0xD06,//15℃
0xCE9,//16℃
0xCCA,//17℃
0xCAC,//18℃
0xC8C,//19℃
0xC6C,//20℃
0xC4C,//21℃
0xC2A,//22℃
0xC08,//23℃
0xBE6,//24℃
0xBC3,//25℃
0xB9F,//26℃
0xB7B,//27℃
0xB57,//28℃
0xB32,//29℃
0xB0D,//30℃
0xAE7,//31℃
0xAC1,//32℃
0xA9B,//33℃
0xA74,//34℃
0xA4D,//35℃
0xA26,//36℃
0x9FE,//37℃
0x9D7,//38℃
0x9AF,//39℃
0x98A,//40℃
0x962,//41℃
0x93A,//42℃
0x912,//43℃
0x8EA,//44℃
0x8C2,//45℃
0x89A,//46℃
0x872,//47℃
0x84B,//48℃
0x823,//49℃
0x7FC,//50℃
0x7D5,//51℃
0x7AE,//52℃
0x787,//53℃
0x761,//54℃
0x73B,//55℃
0x715,//56℃
0x6F0,//57℃
0x6CB,//58℃
0x6A6,//59℃
0x682,//60℃
0x65E,//61℃
0x63A,//62℃
0x617,//63℃
0x5F5,//64℃
0x5D3,//65℃
0x5B1,//66℃
0x590,//67℃
0x570,//68℃
0x550,//69℃
0x530,//70℃
0x511,//71℃
0x4F3,//72℃
0x4D5,//73℃
0x4B8,//74℃
0x498,//75℃
0x47C,//76℃
0x460,//77℃
0x445,//78℃
0x42B,//79℃
0x411,//80℃
0x3F7,//81℃
0x3DF,//82℃
0x3C6,//83℃
0x3AF,//84℃
0x398,//85℃
0x381,//86℃
0x36B,//87℃
0x355,//88℃
0x340,//89℃
0x32C,//90℃
0x318,//91℃
0x304,//92℃
0x2F1,//93℃
0x2DF,//94℃
0x2CC,//95℃
0x2BB,//96℃
0x2A9,//97℃
0x298,//98℃
0x288,//99℃
0x277,//100℃
0x268,//101℃
0x258,//102℃
0x249,//103℃
0x23B,//104℃
0x22C,//105℃
0x21E,//106℃
0x211,//107℃
0x204,//108℃
0x1F7,//109℃
0x1EA,//110℃
0x1DE,//111℃
0x1D2,//112℃
0x1C6,//113℃
0x1BB,//114℃
0x1AF,//115℃
0x1A4,//116℃
0x19A,//117℃
0x190,//118℃
0x185,//119℃
0x17C,//120℃
0x173,//121℃
0x16A,//122℃
0x161,//123℃
0x158,//124℃
0x150,//125℃
0x148,//126℃
0x140,//127℃
0x138,//128℃
0x131,//129℃
0x129,//130℃
0x122,//131℃
0x11B,//132℃
0x115,//133℃
0x10E,//134℃
0x108,//135℃
0x102,//136℃
0xFC,//137℃
0xF6,//138℃
0xF0,//139℃
0xEB,//140℃
0xE5,//141℃
0xE0,//142℃
0xDB,//143℃
0xD6,//144℃
0xD1,//145℃
0xCC,//146℃
0xC7,//147℃
0xC3,//148℃
0xBF,//149℃
0xBA,//150℃
0xB6,//151℃
0xB2,//152℃
0xAE,//153℃
0xAA,//154℃
0xA6,//155℃
0xA2,//156℃
0x9F,//157℃
0x9B,//158℃
0x98,//159℃
0x95,//160℃
0xB9,//161℃
0xB6,//162℃
0xB3,//163℃
0xB0,//164℃
0xAD,//165℃
0xAB,//166℃
0xA8,//167℃
0xA5,//168℃
0xA2,//169℃
0xA0,//170℃
0x9D,//171℃
0x9B,//172℃
0x98,//173℃
0x96,//174℃
0x93,//175℃
0x91,//176℃
0x8F,//177℃
0x8D,//178℃
0x8A,//179℃
0x88,//180℃
0x86,//181℃
0x84,//182℃
0x82,//183℃
0x80,//184℃
0x7E,//185℃
0x7C,//186℃
0x7A,//187℃
0x78,//188℃
0x76,//189℃
0x74,//190℃
0x73,//191℃
0x71,//192℃
0x6F,//193℃
0x6D,//194℃
0x6C,//195℃
0x6A,//196℃
0x68,//197℃
0x67,//198℃
0x65,//199℃
0x64,//200℃
0x62,//201℃
0x61,//202℃
0x5F,//203℃
0x5E,//204℃
0x5D,//205℃
0x5B,//206℃
0x5A,//207℃
0x58,//208℃
0x57,//209℃
0x56,//210℃
0x55,//211℃
0x53,//212℃
0x52,//213℃
0x51,//214℃
0x50,//215℃
0x4F,//216℃
0x4D,//217℃
0x4C,//218℃
0x4B,//219℃
0x4A,//220℃
0x40 //短路

};
/**
  * @brief  This function enables the peripheral clocks on GPIO ports A,B,C
  *         configures PA1, PB1 and PC0 in Analog mode.
  *         For portability, some GPIO are again enabled.
  * @param  None
  * @retval None
  */
 void  ConfigureGPIOforADC(void)
{
  /* (1) Enable the peripheral clock of GPIOA*/
  /* (2) Select analog mode for PA4 5 6 7*/
  RCC->AHBENR |= RCC_AHBENR_GPIOAEN ; /* (1) */
  GPIOA->MODER |= GPIO_MODER_MODER4 | GPIO_MODER_MODER5 | GPIO_MODER_MODER6 | GPIO_MODER_MODER7 ; /* (2) */
  GPIOB->MODER |= GPIO_MODER_MODER0; /* (2) */
}
/**
  * @brief  This function configures the ADC to convert sequentially 4 channels
  *         in continuous mode.
  *         The conversion frequency is 14MHz 
  *         The interrupt on overrun is enabled and the NVIC is configured
  * @param  None
  * @retval None
  */
 void ConfigureADC(void)
{
  /* (1) Select HSI14 by writing 00 in CKMODE (reset value) */ 
  /* (2) Select the auto off mode */
  /* (3) Select CHSEL17 for VRefInt */
  /* (4) Select a sampling mode of 111 i.e. 239.5 ADC clk to be greater than 17.1us */
  /* (5) Wake-up the VREFINT (only for VBAT, Temp sensor and VRefInt) */
  //ADC1->CFGR2 &= ~ADC_CFGR2_CKMODE; /* (1) */   
  ADC1->CFGR1 |= ADC_CFGR1_AUTOFF; /* (2) */
  ADC1->CHSELR = ADC_CHSELR_CHSEL17; /* (3) */
  ADC1->SMPR |= ADC_SMPR_SMP_0 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_2; /* (4) */
  ADC->CCR |= ADC_CCR_VREFEN; /* (5) */
}
/**
  * @brief  This function enables the ADC
  * @param  None
  * @retval None
  */
 void EnableADC(void)
{
  /* (1) Select HSI14 by writing 00 in CKMODE (reset value) */ 
  /* (2) Select the auto off mode */
  /* (3) Select CHSEL17 for VRefInt */
  /* (4) Select a sampling mode of 111 i.e. 239.5 ADC clk to be greater than 17.1us */
  /* (5) Wake-up the VREFINT (only for VBAT, Temp sensor and VRefInt) */
  //ADC1->CFGR2 &= ~ADC_CFGR2_CKMODE; /* (1) */   
  ADC1->CFGR1 |= ADC_CFGR1_AUTOFF; /* (2) */
  ADC1->CHSELR = ADC_CHSELR_CHSEL4; /* (3) */
  ADC1->SMPR |= ADC_SMPR_SMP_0 | ADC_SMPR_SMP_1 | ADC_SMPR_SMP_2; /* (4) */
  ADC->CCR |= ADC_CCR_VREFEN; /* (5) */
}
/**
  * @brief  This function disables the ADC
  * @param  None
  * @retval None
  */
 void DisableADC(void)
{
  /* (1) Ensure that no conversion on going */
  /* (2) Stop any ongoing conversion */
  /* (3) Wait until ADSTP is reset by hardware i.e. conversion is stopped */
  /* (4) Disable the ADC */
  /* (5) Wait until the ADC is fully disabled */
  if ((ADC1->CR & ADC_CR_ADSTART) != 0) /* (1) */
  {
    ADC1->CR |= ADC_CR_ADSTP; /* (2) */
  }
  while ((ADC1->CR & ADC_CR_ADSTP) != 0) /* (3) */
  {
     /* For robust implementation, add here time-out management */
  }
  ADC1->CR |= ADC_CR_ADDIS; /* (4) */
  while ((ADC1->CR & ADC_CR_ADEN) != 0) /* (5) */
  {
    /* For robust implementation, add here time-out management */
  }  
}

/**
  * @brief  This function enables the clock in the RCC for the ADC
  *         and start HSI 14MHz dedicated RC oscillator
  * @param  None
  * @retval None
  */
 void SetClockForADC(void)
{
  /* (1) Enable the peripheral clock of the ADC */
  /* (2) Start HSI14 RC oscillator */ 
  /* (3) Wait HSI14 is ready */
  RCC->APB2ENR |= RCC_APB2ENR_ADC1EN; /* (1) */
  RCC->CR2 |= RCC_CR2_HSI14ON; /* (2) */
  while ((RCC->CR2 & RCC_CR2_HSI14RDY) == 0) /* (3) */
  {
    /* For robust implementation, add here time-out management */
  }  
}
//******************************************************
//单次转换
//******************************************************
u16  adc_result(u8	ch)
{
	ADC1->CHSELR = 1<<ch;  //通道选择
    /* Performs the AD converion */
    ADC1->CR |= ADC_CR_ADSTART; /* start the ADC conversion */
    while ((ADC1->ISR & ADC_ISR_EOC) == 0); /* wait end of conversion */

    return(ADC1->DR );
}
//查表函数
u8 look_up_table(const u16 *a,u8 ArrayLong,u16 data)
{    
    u16 begin,end,middle ;  
    u8 i ;  
    begin = 0 ;  
    end = ArrayLong-1 ;  
    i = 0  ;  
    if(data >= a[begin])
      {
      
			return begin ;  
      }
    else if(data <= a[end])
				return end ;  
    while(begin < end)  
    {  
            middle = (begin+end)/2 ;  
            if(data == a[middle] )
								break ;  
            if(data < a[middle] && data > a[middle+1])
								break ;   
            if(data > a[middle])
							end = middle ;                      
            else 
							begin = middle ;      
            if(i++ > ArrayLong)
							break ;  
    }  
    if(begin > end )
			return 0 ;   
    return middle ;  
}

//******************************************************
//温度查表转换计算(33K+100K)3路
//******************************************************
uint temp_LookUp(uchar a)
{
	uchar i;
	uint dy1=0,xsd,tt;

	for(i=0;i<16;i++)
	{
		tt=adc_result(a);
		DelayMs(5);
		dy1 = dy1 + tt;
	}
	dy1 /= 16;
	i = look_up_table(NTCTab,180,dy1);


	tt = NTCTab[i] - NTCTab[i+1];
	xsd = 10-((dy1 % tt)*10/tt);   //计算小数点后的数值
	if(i>20)
		{
		tt = i -20;
		tt = tt * 10;
		tt = tt + xsd;
		}
	else
		tt = 0;

	return(tt);
}
发布了3 篇原创文章 · 获赞 0 · 访问量 937
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览