==========================================================================================

센서

==========================================================================================

<AVR2560>


=온도센서(NTC) 10k






전압분배의 법칙


V2 = R2/(R1+R2)*V





#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
}


'2015 스마트 콘트롤러 > 업무일지' 카테고리의 다른 글

20150903  (2) 2015.09.04
20150901  (0) 2015.09.01
20150831  (0) 2015.08.31
20150828  (0) 2015.08.30
20150828  (0) 2015.08.28
Posted by ahj333
,