temperature sensing/monitoring using lm35 & atmega8

9
TEMPERATURE MONITORING USING LM35 & ATMEGA8 This is a major sub-part of our project. We need to sense the temperature continuously and display it on LCD. LM35: 1) What is LM35? The LM35 is an integrated circuit sensor that can be used to measure temperature with an electrical output proportional to the temperature (in o C). 2) How does LM35 look? 3) How does it work? It has an output voltage that is proportional to the Celsius temperature. 4) Features an LM35: Linear + 10.0 mV/˚C scale factor 0.5˚C accuracy guarantee (at +25˚C) Rated for full −55˚ to +150˚C range 5) Relationship between voltage and temperature: The general equation used to convert output voltage to temperature is: Temperature ( o C) = Vout * (100 o C/Vcc) Thus we now have appropriate relation between voltage and temperature. What we need now is to give the output of LM35 to

Upload: suket

Post on 28-Apr-2015

1.106 views

Category:

Documents


1 download

DESCRIPTION

Temperature Monitoring Using Lm35 & Atmega8

TRANSCRIPT

Page 1: Temperature Sensing/Monitoring Using Lm35 & Atmega8

TEMPERATURE MONITORING USING LM35 & ATMEGA8

This is a major sub-part of our project. We need to sense the temperature continuously and display it on LCD.

LM35:

1) What is LM35?

The LM35 is an integrated circuit sensor that can be used to measure temperature with an electrical output proportional to the temperature (in oC).

2) How does LM35 look?

3) How does it work?It has an output voltage that is proportional to the Celsius temperature.

4) Features an LM35: 

Linear + 10.0 mV/˚C scale factor 0.5˚C accuracy guarantee (at +25˚C) Rated for full −55˚ to +150˚C range

5) Relationship between voltage and temperature:

The general equation used to convert output voltage to temperature is: Temperature ( o C) = Vout * (100 o C/Vcc)

Thus we now have appropriate relation between voltage and temperature. What we need now is to give the output of LM35 to ADC pin of Atmega8. So, next we need to interface in built ADC of Atmega8.

Page 2: Temperature Sensing/Monitoring Using Lm35 & Atmega8

Interfacing ADC:

In simple words, Analog to Digital converter is an electronic device which converts analog signal from our real world into a machine readable or binary or digital format.

Atmega8 has internal ADC. These are some features:

10-bit Resolution ±2 LSB Absolute Accuracy Optional Left Adjustment for ADC Result Readout Selectable 2.56V ADC Reference Voltage 13μs - 260μs Conversion Time 6 Multiplexed Single Ended Input Channels

Analog to Digital Converter Block Schematic operation:

Page 3: Temperature Sensing/Monitoring Using Lm35 & Atmega8

Explanation of ADC operation:

The ATmega8 features a 10-bit successive approximation ADC. The ADC is connected to a 6-channel Analog Multiplexer which allows six single-ended voltage inputs constructed from the pins of Port C.

The ADC converts an analog input voltage to a 10-bit digital value through successive approximation.

The minimum value represents GND and the maximum value represents the voltage onthe AREF pin minus 1 LSB. Optionally, AVCC or an internal 2.56V reference voltage may be connected to the AREF pin by writing to the REFSn bits in the ADMUX Register. The internal voltage reference may thus be decoupled by an external capacitor at the AREF pin to improve noise immunity.

The analog input channel is selected by writing to the MUX bits in ADMUX. Any of the ADC input pins can be selected as single ended inputs to the ADC.

The ADC is enabled by setting the ADC Enable bit, ADEN in ADCSRA. Voltagereference and input channel selections will not go into effect until ADEN is set. The ADCdoes not consume power when ADEN is cleared, so it is recommended to switch off the ADCbefore entering power saving sleep modes.

The ADC generates a 10-bit result which is presented in the ADC Data Registers, ADCH andADCL. By default, the result is presented right adjusted, but can optionally be presented leftadjusted by setting the ADLAR bit in ADMUX.

If the result is left adjusted and no more than 8-bit precision is required, it is sufficient to readADCH. Otherwise, ADCL must be read first, then ADCH, to ensure that the content of the Data Registers belongs to the same conversion. Once ADCL is read, ADC access to Data Registers is blocked. This means that if ADCL has been read, and a conversion completes before ADCH is read, neither register is updated and the result from the conversion is lost. When ADCH is read, ADC access to the ADCH and ADCL Registers is re-enabled.

Okay good, but how does it convert voltage into its equivalent ADCW value?

Suppose the input voltage is 3.6 Volts (X) and is checked over a 10 bit ADC. Controller

voltage is 0V (Vmin) to 5V (Vmax). DAC is set to midscale which means, reference voltage =

5/2 = 2.5 Volts. Now the procedure follows as given below; the comparator checks if X >=

reference voltage; If yes, then retain else discard and move on to next bit.

Page 4: Temperature Sensing/Monitoring Using Lm35 & Atmega8

Condition ValueBit Status

Result

Is X >= 2.5 Yes 1 Retain -> 2.5

Is X >= 2.5+2.5/2 = 3.75 No 0 Discard -> 1.25

Is X >= 2.5+0.625 = 3.125 Yes 1 Retain -> 0.625

Is X>= 3.125 + 0.3125 = 3.4375 Yes 1 Retain -> 0.3125

Is X>= 3.4375 + 0.15625  = 3.59375 Yes 1 Retain -> 0.15625

Is X>= 3.59375 + 0.078125 = 3.671875

No 0 Discard -> 0.078125

Is X>= 3.59375 + 0.0390625 = 3.6328125

No 0 Discard -> 0.0390625

Is X>= 3.59375 + 0.01953125 = 3.61328125

No 0 Discard -> 0.01953125

Is X>= 3.59375 + 0.009765625 = 3.603515625

No 0Discard -> 0.009765625

Is X>= 3.59375 + 0.0048828125 = 3.5986328125

Yes 1Retain -> 3.5986328125

The digital equivalent of analog input from SAR is 1011100001(2). Suppose we require an 8 bit resolution, then the digital equivalent is 10111000(2).

Resolution in context of ADC:

Maximum Voltage: VHigh = 5 VoltsMinimum Voltage: VLow = 0 VoltsFull measurement voltage (EFSR) = VHigh - VLow= 5V– 0 V = 5VADC resolution (N) = 10 bits= 2^10 = 1024 levelsTherefore, ADC voltage resolution (Q) = EFSR/ N = 5 / 1024 = 0.00488 V or 4.88 mV.

Now we can say that the resolution of 10 bit ADC over a range of 5 volts is 4.88 mV. When we refer to Atmega8 datasheet, it says that absolute accuracy in AD conversion can be ± 2 LSB, meaning the accuracy after conversion can be over or under 2 levels. Since ADC voltage resolution derived above is 4.88 mV, it can be considered that the absolute accuracy after conversion can be 4.88 * 2 = +/-9.77mV of the derived value.

Circuit diagram of temperature monitoring:

Page 5: Temperature Sensing/Monitoring Using Lm35 & Atmega8

LM35 is connected to PC5(ADC5) pin of Atmega8.

AVcc & Aref are set to 5V.

Flowchart of code:

Explanation of flowchart:

Page 6: Temperature Sensing/Monitoring Using Lm35 & Atmega8

The appropriate ports are first initialized as an output port to write on them. Then the LCD is initialized in 4-bit mode as explained in LCD section before. Now, the ADC registers are initialized.

Set ADCSRA Register to Enable ADC (ADEN) & to set division factor 8 (ADPS1,ADPS0) since we’re using internal 1MHz. Set ADMUX Register for Channel no.5 ,right shifted result & Vcc(5V) given to Aref & AVcc.

Start Conversion by setting ADCSC bit of ADCSRA Register.

Wait until conversion completes. ADSC=0 means Complete.

After the conversion completes, convert the result of ADC to temperature by using below formula:

From the datasheet ADC, ADCW = Vin * 1024 / Vref ----- (1)

Also, from datasheet of LM35, Temperature = 100*Vin / Vcc ----- (2)

By combining (1) & (2),

Temperature = 100*(ADCW * Vref) / (Vcc*1024)

Putting Vcc=Vref=5V, ADCW = adc_value.

Temperature = ( adc_value * 500) / 1024

Display the Temperature, 0xDF(for degree symbol) & ‘C’ on LCD.

Wait for few seconds before starting conversion. (e.g. 3 seconds)

Then again start conversion and do the above task repeatedly.

Thank You,

Suket & Mayur

B.Tech. EC (Dharmsinh Desai University, Nadiad, Gujarat)

Internship At Einfoworks, Ahmedabad, Gujarat