먼저 온도 측정을 위한 NTC 저항 관련 계산 방법은 하기 참고 문서를 참조한다.

NTC에서 온도에 따른 저항값의 변화는 리니어하지 않으므로 NTC 판매 업체의

β정수를 이용하여 계산하여야 한다.

하기 코드의 200~201번 라인을 참조하여 계산하면 된다.


/**   ******************************************************************************   * @file    main.c   * @author  MCD Application Team   * @version V1.0.0   * @date    18-April-2011   * @brief   Main program body   ******************************************************************************   * @attention   *   * THE PRESENT FIRMWARE WHICH IS FOR GUIDANCE ONLY AIMS AT PROVIDING CUSTOMERS   * WITH CODING INFORMATION REGARDING THEIR PRODUCTS IN ORDER FOR THEM TO SAVE   * TIME. AS A RESULT, STMICROELECTRONICS SHALL NOT BE HELD LIABLE FOR ANY   * DIRECT, INDIRECT OR CONSEQUENTIAL DAMAGES WITH RESPECT TO ANY CLAIMS ARISING   * FROM THE CONTENT OF SUCH FIRMWARE AND/OR THE USE MADE BY CUSTOMERS OF THE   * CODING INFORMATION CONTAINED HEREIN IN CONNECTION WITH THEIR PRODUCTS.   *   * <h2><center>&copy; COPYRIGHT 2011 STMicroelectronics</center></h2>   ******************************************************************************     */ /* Includes ------------------------------------------------------------------*/ #include "stm32f2xx.h" #include "usart.h" #include "JOYState.h" #include "LCD/LCD.h" #include <math.h> #define ADC3_DR_ADDRESS    ((uint32_t)0x4001224C) #define AVCC_mv 3300.0 #define NTC_Resistor 1000 //1Kohm __IO uint16_t ADC3ConvertedValue = 0; __IO uint32_t ADC3ConvertedVoltage = 0; void  Delay (uint32_t nCount) {   for(; nCount != 0; nCount--); } void ADC3_CH7_DMA_Config(void); void Display(void); /**   * @brief  Main program   * @param  None   * @retval None   */ GPIO_InitTypeDef t_Gpio_init; int main(void) {   /*!< At this stage the microcontroller clock setting is already configured,        this is done through SystemInit() function which is called from startup        file (startup_stm32f2xx.s) before to branch to application main.        To reconfigure the default setting of SystemInit() function, refer to         system_stm32f2xx.c file      */     SystemInit();   SystemCoreClockUpdate(); USART_Configuration(); USART_NVIC_Config(); //JOYState_LED_GPIO_Init(); LCD_Initializtion(); ADC3_CH7_DMA_Config(); ADC_SoftwareStartConv(ADC3); LCD_Clear(Red); GUI_Text(132,104,"Open207Z",White,Red); //GUI_Text(76,120,"Development Board V1.0",0xFFEF,Red); Delay(0xffffff); LCD_Clear(Red); GUI_Text(76,120,"Development Board V1.0",White,Red); Delay(0xffffff); LCD_Clear(Red); printf("\r\nBoot Success\r\n"); while (1) { ADC3ConvertedVoltage = ADC3ConvertedValue *3300/0xFFF; Display(); Led_Toggle(Read_JOYState()); } } void ADC3_CH7_DMA_Config() { ADC_InitTypeDef  ADC_InitStructure; ADC_CommonInitTypeDef ADC_CommonInitStructure; DMA_InitTypeDef  DMA_InitStructure; GPIO_InitTypeDef  GPIO_InitStructure;   /* Enable ADC3, DMA2 and GPIO clocks ****************************************/ RCC_AHB1PeriphClockCmd(RCC_AHB1Periph_DMA2 | RCC_AHB1Periph_GPIOF, ENABLE); RCC_APB2PeriphClockCmd(RCC_APB2Periph_ADC3, ENABLE); /* DMA2 Stream0 channel2 configuration **************************************/ DMA_InitStructure.DMA_Channel = DMA_Channel_2; DMA_InitStructure.DMA_PeripheralBaseAddr = (uint32_t)ADC3_DR_ADDRESS; DMA_InitStructure.DMA_Memory0BaseAddr = (uint32_t)&ADC3ConvertedValue; DMA_InitStructure.DMA_DIR = DMA_DIR_PeripheralToMemory; DMA_InitStructure.DMA_BufferSize = 1; DMA_InitStructure.DMA_PeripheralInc = DMA_PeripheralInc_Disable; DMA_InitStructure.DMA_MemoryInc = DMA_MemoryInc_Disable; DMA_InitStructure.DMA_PeripheralDataSize = DMA_PeripheralDataSize_HalfWord; DMA_InitStructure.DMA_MemoryDataSize = DMA_MemoryDataSize_HalfWord; DMA_InitStructure.DMA_Mode = DMA_Mode_Circular; DMA_InitStructure.DMA_Priority = DMA_Priority_High; DMA_InitStructure.DMA_FIFOMode = DMA_FIFOMode_Disable;   DMA_InitStructure.DMA_FIFOThreshold = DMA_FIFOThreshold_HalfFull; DMA_InitStructure.DMA_MemoryBurst = DMA_MemoryBurst_Single; DMA_InitStructure.DMA_PeripheralBurst = DMA_PeripheralBurst_Single; DMA_Init(DMA2_Stream0, &DMA_InitStructure); DMA_Cmd(DMA2_Stream0, ENABLE); /* Configure ADC3 Channel7 pin as analog input ******************************/ GPIO_InitStructure.GPIO_Pin = GPIO_Pin_9; GPIO_InitStructure.GPIO_Mode = GPIO_Mode_AN; GPIO_InitStructure.GPIO_PuPd = GPIO_PuPd_NOPULL ; GPIO_Init(GPIOF, &GPIO_InitStructure); /* ADC Common Init **********************************************************/ ADC_CommonInitStructure.ADC_Mode = ADC_Mode_Independent; ADC_CommonInitStructure.ADC_Prescaler = ADC_Prescaler_Div2; ADC_CommonInitStructure.ADC_DMAAccessMode = ADC_DMAAccessMode_Disabled; ADC_CommonInitStructure.ADC_TwoSamplingDelay = ADC_TwoSamplingDelay_5Cycles; ADC_CommonInit(&ADC_CommonInitStructure); /* ADC3 Init ****************************************************************/ ADC_InitStructure.ADC_Resolution = ADC_Resolution_12b; ADC_InitStructure.ADC_ScanConvMode = DISABLE; ADC_InitStructure.ADC_ContinuousConvMode = ENABLE; ADC_InitStructure.ADC_ExternalTrigConvEdge = ADC_ExternalTrigConvEdge_None; ADC_InitStructure.ADC_ExternalTrigConv = ADC_ExternalTrigConv_T1_CC1; ADC_InitStructure.ADC_DataAlign = ADC_DataAlign_Right; ADC_InitStructure.ADC_NbrOfConversion = 1; ADC_Init(ADC3, &ADC_InitStructure); /* ADC3 regular channel7 configuration *************************************/ ADC_RegularChannelConfig(ADC3, ADC_Channel_7, 1, ADC_SampleTime_3Cycles); /* Enable DMA request after last transfer (Single-ADC mode) */ ADC_DMARequestAfterLastTransferCmd(ADC3, ENABLE); /* Enable ADC3 DMA */ ADC_DMACmd(ADC3, ENABLE); /* Enable ADC3 */ ADC_Cmd(ADC3, ENABLE); } void Display(void) {     /*       resistance value of NTC:       r(25)=500 Ohm       r(t)=r(25)*e^(3300*(1/(t+273)-1/(25+273)))       etc,       r(-20)=3.58 KOhm       r(-3)=1576 KOhm       r(60)=156 Ohm       r(100)=54 Ohm       ...       if R1=5.6KOhm, then:       V_in(t)=AVCC*(r(t)/(r(t)+R1))       etc,       V_in(-3)=1098 mv       V_in(100)=47.7 mv       ...             when V_in is known,       r=R1/((AVCC/V_in)-1)       because of B=3300K, r(25)=500 Ohm:       t=(1/((ln(r/500)/3300)+(1/(25+273))))-273     */ unsigned long v=0,mv=0,temp1=0,temp2=0,temp=0; float r,t; unsigned char i=0,temp_buf[3]; v=(ADC3ConvertedVoltage)/1000; mv = (ADC3ConvertedVoltage%1000)/100; temp1 = (3300 - ADC3ConvertedVoltage);  //1K Resister ADC Value temp2 = temp1 / 100; // Amp temp = (ADC3ConvertedVoltage*10) / temp2; //NTC Resister Value printf("1K Resister Voltage:%d\r\n",temp1); printf("1K Resister AMP    :%d\r\n",temp2); printf("NTC Resister Value :%d\r\n",temp); printf("Voltage = %d,%d V   \r\n",v,mv); printf("ADC = %d   \r\n",ADC3ConvertedValue); r= NTC_Resistor /((AVCC_mv/ADC3ConvertedVoltage)-1.0); t=1.0/(log(r/1000)/3950+(1.0/(25.0+273.0))) - 273; printf("Temperature = %3f   \r\n",t); i = (unsigned char)t; temp_buf[0] = (t/10)+48; temp_buf[1] = ((char)t%10)+48; GUI_Text(50,137,"ADC Temperature Senising",White,Red); GUI_Text(76,120,&temp_buf[0],White,Red); GUI_Text(92,120,"C",White,Red); Delay(0xffffff); } #ifdef  USE_FULL_ASSERT /**   * @brief  Reports the name of the source file and the source line number   *         where the assert_param error has occurred.   * @param  file: pointer to the source file name   * @param  line: assert_param error line source number   * @retval None   */ void assert_failed(uint8_t* file, uint32_t line) {   /* User can add his own implementation to report the file name and line number,      ex: printf("Wrong parameters value: file %s on line %d\r\n", file, line) */   /* Infinite loop */   while (1)   {   } } #endif /**   * @}   */ /**   * @}   */ /******************* (C) COPYRIGHT 2011 STMicroelectronics *****END OF FILE****/
크리에이티브 커먼즈 라이센스
Creative Commons License
2014/11/23 20:10 2014/11/23 20:10

Trackback Address >> 이 글에는 트랙백을 보낼 수 없습니다

댓글을 달아 주세요

  1. Livali Ageless Moisturizer Review 2018/06/23 09:41  address  modify / delete  reply

    I hardly drop comments, but i did a few searching and wound up here S.Jung
    :: [Cortex-M3] DMA를 이용한 ADC 측정으로 NTC
    저항값 잀어들이기. And I actually do have a
    few questions for you if you usually do not mind.
    Is it simply me or does it look like a few of these remarks come across like they are written by brain dead individuals?
    :-P And, if you are posting on additional places, I would
    like to keep up with everything fresh you have to post.
    Would you list of every one of your public pages like your Facebook page,
    twitter feed, or linkedin profile?

  2. Livali Skin Care 2018/07/03 11:06  address  modify / delete  reply

    I almost never comment, but i did a few searching and wound up here S.Jung :: [Cortex-M3] DMA를 이용한 ADC 측정으로 NTC 저항값 잀어들이기.
    And I do have a couple of questions for you if it's allright.

    Could it be only me or does it look like some of the
    comments come across like written by brain dead individuals?
    :-P And, if you are posting on additional places, I'd like to follow anything fresh you have to post.
    Would you make a list of every one of all your shared
    sites like your Facebook page, twitter feed, or linkedin profile?

  3. Ultra Shave Forskolin 2019/03/13 09:42  address  modify / delete  reply

    I hardly comment, however i did some searching and wound up here S.Jung :
    : [Cortex-M3] DMA를 이용한 ADC 측정으로 NTC 저항값 잀어들이기.
    And I do have a couple of questions for you if you tend not to mind.

    Is it just me or does it look like some of the responses come across like coming from brain dead visitors?
    :-P And, if you are posting on additional online social sites, I'd like to follow anything
    fresh you have to post. Could you make a list of every one of your shared pages like your Facebook page, twitter feed, or linkedin profile?