Вы находитесь на странице: 1из 6

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.5C accuracy guarantee (at +25C) Rated for full 55 to +150C range

5) Relationship between voltage and temperature: The general equation used to convert output voltage to temperature is: Temperature ( oC) = Vout * (100 oC/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.

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 13s - 260s Conversion Time 6 Multiplexed Single Ended Input Channels

Analog to Digital Converter Block Schematic operation:

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 on the 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. Voltage reference and input channel selections will not go into effect until ADEN is set. The ADC does not consume power when ADEN is cleared, so it is recommended to switch off the ADC before entering power saving sleep modes. The ADC generates a 10-bit result which is presented in the ADC Data Registers, ADCH and ADCL. By default, the result is presented right adjusted, but can optionally be presented left adjusted 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 read ADCH. 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.

Condition Is X >= 2.5 Is X >= 2.5+2.5/2 = 3.75 Is X >= 2.5+0.625 = 3.125 Is X>= 3.125 + 0.3125 = 3.4375 Is X>= 3.4375 + 0.15625 = 3.59375 Is X>= 3.59375 + 0.078125 = 3.671875 Is X>= 3.59375 + 0.0390625 = 3.6328125 Is X>= 3.59375 + 0.01953125 = 3.61328125 Is X>= 3.59375 + 0.009765625 = 3.603515625 Is X>= 3.59375 + 0.0048828125 = 3.5986328125

Value Yes No Yes Yes Yes No No No No Yes

Bit Result Status 1 0 1 1 1 0 0 0 0 1 Retain -> 2.5 Discard -> 1.25 Retain -> 0.625 Retain -> 0.3125 Retain -> 0.15625 Discard -> 0.078125 Discard -> 0.0390625 Discard -> 0.01953125 Discard -> 0.009765625 Retain -> 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 Volts Minimum Voltage: VLow = 0 Volts Full measurement voltage (EFSR) = VHigh - VLow= 5V 0 V = 5V ADC resolution (N) = 10 bits= 2^10 = 1024 levels Therefore, 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: LM35 is connected to PC5(ADC5) pin of Atmega8. AVcc & Aref are set to 5V.

Flowchart of code:

Explanation of flowchart: 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 were 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 Also, from datasheet of LM35, Temperature = 100*Vin / Vcc 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. ----- (1) ----- (2)

Thank You, Suket & Mayur B.Tech. EC (Dharmsinh Desai University, Nadiad, Gujarat) Internship At Einfoworks, Ahmedabad, Gujarat

Вам также может понравиться