Monday, 10 June 2013

INTERFACING MULTIPLE TEMPERATURE SENSORS TO AVR – LM35 ATMEGA8


             Here is a simple example to interface multiple temperature sensors to AVR (Atmega8) microcontroller.  Atmega8 is a High-performance, Low-power Atmel®AVR® 8-bit Microcontroller Advanced RISC Architecture with 8KB ISP flash, 1KB RAM, 512B EEPROM, Two 8-bit Timer/Counters with Separate Prescaler, one Compare Mode, One 16-bit Timer/Counter with Separate Prescaler, Compare Mode, and Capture Mode, Real Time Counter with Separate Oscillator, Three PWM Channels, 6 multiplexed ADC channels with 10-bit resolution. We have used 2 channels to connect 2 LM35 linear temperature sensors to it.



About LM35:
            The LM35 series are precision integrated-circuit temperature sensors, whose output voltage is linearly proportional to the Celsius (Centigrade) temperature. The LM35 thus has an advantage over linear temperature sensors calibrated in °Kelvin.
·         Calibrated directly in ° Celsius (Centigrade)
·         Linear + 10.0 mV/°C scale factor
·         0.5°C accuracy guaranteeable (at +25°C)
·         Rated for full −55° to +150°C range
·         Suitable for remote applications
·         Low cost due to wafer-level trimming
·         Operates from 4 to 30 volts
·         Less than 60 μA current drain
·         Low self-heating, 0.08°C in still air
·         Nonlinearity only ±1⁄4°C typical
·         Low impedance output, 0.1 W for 1 mA load



AVR AMTEGA8 ADC Registers:

BIT
7
6
5
4
3
2
1
0
ADMUX
REFS1
REFS0
ADLAR
MUX3
MUX2
MUX1
MUX0

BIT
7
6
5
4
3
2
1
0
ADCSRA
ADEN
ADSC
ADFR
ADIF
ADIE
ADPS2
ADPS1
ADPS0

 Functions used:
   ADC_init();
                        To initialize the ADC with reference voltage, adc clock prescalar, interrupts,,,

   ADC_readch(ch_no);
         To start conversion in the specified channel & return the values.
     int ADC_readch(unsigned char chn)         
     {
       ADMUX= (ADMUX & 0xF0) | (chn & 0x0F);
       ADC_CLEAR_ADIF(); //Clear ADC Interrupt Flag
       ADC_START_CONV(); //Start ADC Conversion.
       while(!(CHECKBIT(ADCSRA,ADIF)));
             //wait for conversion complete
       return(ADC_read());//----read values & return
     }

   ADC_calcvolt(long int ADCval);
           To convert the ADCvalue into equ. voltage value (float).

  updatedisp();
           To display the temperature in LCD in required format.

 To get the Celsius value, the ADC_Value is divided by 2 to convert 5mV/'C to 10mV/'C

Main Program:

unsigned char d1[]="T1=    . 'C",d2[]="T2=    . 'C";unsigned int t1,t2;
void updatedisp1(){  unsigned int i=t1/2; //convert 5mV/'C to 10mV/'C (directly into Celcius) d1[6]= (i%10) | 0x30; //1s i/=10;  d1[5]= (i%10) | 0x30; //10s i/=10;  d1[4]= (i%10) | 0x30; //100s d1[8]= (t1%2 ? 5:0) | 0x30;//decimal LCD_putsXY(0,0,d1);}void updatedisp2(){  unsigned int i=t2/2; //convert 5mV/'C to 10mV/'C (directly into Celcius) d2[6]= (i%10) | 0x30; //1s i/=10;  d2[5]= (i%10) | 0x30; //10s i/=10;  d2[4]= (i%10) | 0x30; //100s d2[8]= (t2%2 ? 5:0) | 0x30;//decimal LCD_putsXY(0,1,d2);}
int main(){
  CLEARBIT(DDRC,4)//set as i/p for adc CLEARBIT(DDRC,5) DDRD=0xF8;//enable PD as i/p & en pull ups PORTD=0x07; _delay_ms(10); LCD_init(COFF); _delay_ms(100); LCD_putsXY(0,0,"Welcome"); WaitMs(1000);//wait for some time ADC_init();
LCD_putsXY(0,0,d1); LCD_putsXY(0,1,d2);
while(1) {// t=t2/2;//convert 5mV/'C to 10mV/'C (directly into Celcius) t1=ADC_readch(4); t2=ADC_readch(5); updatedisp1(); updatedisp2(); WaitMs(300); }//end of while  return 0;}


Circuit Diagram:

OUTPUT Snapshots:








If you have any queries mail us to admin@elecdude.com
Viewers comments are encouraged.
It helps us to do better.
Thank you.



Reactions:

1 comments:

Post a Comment

Search Here...