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

# AVR TUTORIALS ADC PROGRAMING OF ATMEGA32

Analog to digital converters are most widely used method for data acquisition. The world is consisting of physical quantities (temperature, humidity, velocity etc) which are analog signal but the microcontrollers /PC uses binary value (0, 1). The physical quantity must be converted into electrical signals (Voltage, current) by using sensors .Then these analog signals must be converted into digital by Analog to digital so that the microcontroller/pc can understand and process them
PC/MICROC ONTROLLER

DISPLAY

The selection of the ADC depends on its level of accuracy in conversion. The conversion accuracy depends on Resolution: The ADC has n bit resolution (where n can be 8, 10, 12).The n is used to find the step size along with reference voltage . The step size is the minimum voltage that ADC can measure. The resolution is decided at the time of design although the step size can be valid with help of reference voltage. Conversion Time: The conversion time depends on clock source give to the ADC and the conversion techniques used. The conversion time is the time taken by the ADC to convert the analog signal to digital number. Reference Voltage: This the voltage given to Avref pin .This voltage along with bit resolution is used to find step size Step size=
E-Dazzling Technologies

## where n is the ADC bit resolution.

Page 1

AVR TUTORIALS
ADC Programming in ATMega32 Features of ADC in ATmega32 ATMega 32 has inbuilt 8 channel ADC which uses successive approximation technique. Its features are

Successive Approximation Technique: 2.5mv The ADC of ATMega 32 is 10 bit at the reference voltage of 2.56v the step size is

For input voltage of 300mv=.3v Step 1: Step 2: Step 3 Step 4 Step 5 0b 1000000000 *2.5mv=1.28v this is greater than the input voltage, hence this one left out Ob0100000000*2.5mv=.64mv this is greater than the input voltage, hence this one will be left out. 0b0010000000*2.5mv=.32v this is greater to the input, then it will left for the next step 0b0001000000*2.5mv=.16v this is less than input, it will be held for next step. 0b0001100000*2.5mv=.24v is less than input, it will be held for next step.
Page 2

=2.5mv

E-Dazzling Technologies

AVR TUTORIALS
Step 6 Step 7 Step 8 Step 9 Step 10 0b0001110000*2.5mv=.28v is less than input, it will be held for next step. 0b0001111000*2.5mv=.3v is equal than input, it will be held for next step. 0b0001111100*2.5mv=.31v is greater than input, it will be left out for next step. 0b0001111010*2.5mv=.305v is greater than input, it will be left out for next step. 0b0001111001*2.5mv=.3025v is greater than input, it will be left out.

Thus the digital value of 300mv is 0001111000.This how the successive approximation technique works Formula for Calculating Digital value The formula for calculating the digital value manually is Dout = this can be used to check the out of the ADC

conversion. For example taking the value from the successive approximation technique 300mv input and step size is 2.5mv

## Dout = 300 2.5

=120 =0001111000

In Atmega32 the ADC process depends on the following register ADMUX ADCSRA ADCW(ADCL and ADCH) SPIOR but in this tutorial we are going to use only first three register, since we are going to only single ended conversion

E-Dazzling Technologies

Page 3

AVR TUTORIALS

E-Dazzling Technologies

Page 4

AVR TUTORIALS

REFS1:0

## These two bits are used to select the reference voltage

MUX4:0

These bits are used to select the ADC channel. For single ended output the values are

E-Dazzling Technologies

Page 5

AVR TUTORIALS

ADC Data Register (ADCH and ADCL) This is the register which holds the digital data after the completion of the ADC. The data is arranged based on the value of ADLAR

This bit is used to enable the ADC by writing one to it. This bit is used to start the conversion by writing one to this bit. Auto triggering of ADC is enabled by setting this bit. This bit is set when ADC conversion is complete and data is updated in ADCW (ADCL and ADCH). This bit is used to enable ADC interrupt when conversion gets completed These bits are used to select the division factor for XTAL for ADC clock source

E-Dazzling Technologies

Page 6

AVR TUTORIALS

Now we write a program for converting signal connected to the signal to the pin ADC0.

E-Dazzling Technologies

Page 7

AVR TUTORIALS

E-Dazzling Technologies

Page 8

AVR TUTORIALS

E-Dazzling Technologies

Page 9