본문 바로가기
코스웨어/15년 스마트컨트롤러

20150903 - 21번 홍준모

by 알 수 없는 사용자 2015. 9. 3.
728x90
반응형

[원래 소스]

#include <avr/io.h>
#include <util/delay.h>
#include <math.h>

#define BCOEFFICIENT 3950    // The beta coefficient of the thermistor (usually 3000-4000)
#define THERMISTORNOMINAL 10000  // resistance at 25 degrees C
#define TEMPERATURENOMINAL 25  // temp. for nominal resistance (almost always 25 C)
#define SERIESRESISTOR 10000  // the value of the 'other' resistor


void ADC_ONE(void)
{
 ADCSRA = 0x00// 일종의 초기화 전 ... 상태 안정하게.. INIT VALUE
 ADCSRA = 0x85//Enable adc, 500kHz 101 32분주 (( `
 ADCSRB = 0x00
 ADMUX = 0x40//avcc를 기준전압으로, select ADC0
}

int main(void)
{
  unsigned char i;
  volatile int sum;
  unsigned int tsum ;
  double Ther_Total = 0
  float steinhart;
  
  DDRF = 0xFE;   // F0 : input
  ADC_ONE();    // ADC 단일 입력 모드
   while(1)
  {
    sum = 0;
    tsum = 0;
    Ther_Total = 0;
    for(i=0; i<100; i++)  // ADC Data 100개를 수집하여 합을 구함
    { 
      ADCSRA = 0b11010101;       
              
      while((ADCSRA & 0x10) != 0x10); 
 
      sum = ADC; 
      tsum += sum;
       
 
      _delay_ms(10); 
    }// End of for 
    
    tsum /= 100;      // 수집한 데이터의 합을 100으로 나누어서 평균을 구함.

    // convert the value to resistance
    tsum = 1023 / tsum - 1;
    tsum = SERIESRESISTOR  / tsum;
    // Thermistor resistance = tsum
     
    steinhart = tsum / THERMISTORNOMINAL;           // (R/Ro)
    steinhart = log(steinhart);                      // ln(R/Ro)
    steinhart /= BCOEFFICIENT;                       // 1/B * ln(R/Ro)
    steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15);   // + (1/To)
    steinhart = 1.0 / steinhart;                     // Invert
    steinhart -= 273.15;                             // convert to C
  }// End of while
}


[바뀐 소스]

#include <avr/io.h>
#include <util/delay.h>
#include <math.h>

#define BCOEFFICIENT 3950    // The beta coefficient of the thermistor (usually 3000-4000)
#define THERMISTORNOMINAL 10000  // resistance at 25 degrees C
#define TEMPERATURENOMINAL 25  // temp. for nominal resistance (almost always 25 C)
#define SERIESRESISTOR 10000  // the value of the 'other' resistor

// calculate resistor value
float fCalcNtc(short wADCVal)  // from ADC

  float fRntc;

    fRntc = 10000 *  (float) wADCVal / ( 1023.0  - (float) wADCVal);  // 10000 = pullup resistor
  return(fRntc);
}


// calculate temperature from resistorvalue
float fCalcTemp( float fRntc)
{
  float fTemp;

    fTemp = (1.0 / ( (log(fRntc/THERMISTORNOMINAL))/BCOEFFICIENT  + 1.0/298.0)) - 273.0//log = ln 
  return( fTemp);
}
void ADC_ONE(void)
{
 ADCSRA = 0x00// 일종의 초기화 전 ... 상태 안정하게.. INIT VALUE
 ADCSRA = 0x85//Enable adc, 500kHz 101 32분주 (( `
 ADCSRB = 0x00
 ADMUX = 0x40//avcc를 기준전압으로, select ADC0
}

int main(void)
{
  unsigned char i;
  volatile int sum;
  unsigned int tsum ;
  double Ther_Total = 0
  float steinhart, Res, Temp;
  
  DDRF = 0xFE;   // F0 : input
  ADC_ONE();    // ADC 단일 입력 모드
   while(1)
  {
    sum = 0;
    tsum = 0;
    Ther_Total = 0;
    for(i=0; i<100; i++)  // ADC Data 100개를 수집하여 합을 구함
    { 
      ADCSRA = 0b11010101;       
              
      while((ADCSRA & 0x10) != 0x10); 
 
      sum = ADC; 
      tsum += sum;
       
 
      _delay_ms(10); 
    }// End of for 
    
    tsum /= 100;      // 수집한 데이터의 합을 100으로 나누어서 평균을 구함.
#if 0
    // convert the value to resistance
    tsum = 1023 / tsum - 1;
    tsum = SERIESRESISTOR  / tsum;
    // Thermistor resistance = tsum
     
    steinhart = tsum / THERMISTORNOMINAL;           // (R/Ro)
    steinhart = log(steinhart);                      // ln(R/Ro)
    steinhart /= BCOEFFICIENT;                       // 1/B * ln(R/Ro)
    steinhart += 1.0 / (TEMPERATURENOMINAL + 273.15);   // + (1/To)
    steinhart = 1.0 / steinhart;                     // Invert
    steinhart -= 273.15;                             // convert to C
#endif
    Res = fCalcNtc(tsum);      // calculate temperature from resistorvalue 
    Temp = fCalcTemp(Res);      // calculate temperature from resistorvalue
  }// End of while
}




<MTW 부분>

- $ --> 뒤에 오는 -- 는 아무거나 와도 된다. ex) -+, -y, ty, xc ...

- MTW -> 매니저먼트 템퍼러쳐 워터 로 인식

- X.X -> 실제 측정된 온도 값

- C*hh -> 센시어스(섭씨), [f 는 화씨]

            hh는 체크 섬


그 다음 ui로 온도값을 디스플레이 해주는 프로그램 코딩 해주면 끝



죄송합니다.. 제 차례인지 모르고 있다가 ㅜㅜ 급하게 듣고 작성했네요..ㅎㅎ

728x90