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

AVR ATMega 8 uC

ADC

ANALOG TO DIGITAL CONVERTOR (ADC)


Physical Quantities are analog means they varies continuously with time.

Our Microcontroller is digital electronics device It can respond to only two states -- either ON or OFF Here Comes ADC Feature which converts continuous variation into discrete levels represented by a sequence of digit 0 or digit 1.

ADC uses a Reference Voltage to convert the analog input. 1023 = 5V 255= 5V

512= 2.5 V

127= 2.5 V

0=0V 10 bit Resolution

0= 0 V 8 bit Resolution

Resolution: The minimum value of analog quantity for which the ADC responds.
Let Reference Voltage= 5 Volt Thus In 10 bit ADC Resolution-- 5/1024 = 4.89 mV or around 5mV In 8 bit ADC Resolution-- 5/256 = 19.53mV or around 20mV

A
T M

E G
A 8

ADC5 ADC4 ADC3 ADC2 ADC1 ADC0

In Atmega8 PORTC is Multiplexed with ADC. PORTC can work as both IO PORT or ADC .

Three Registers are used to operate the ADC. ADC can be used for interfacing analog devices like temperature sensors etc. to the microcontroller.

ADMUX REGISTER
This register is used to select the reference voltage for conversion.

ADC input pins are selected by using MUX3 to MUX0 bits.

Voltage Reference Selection for ADC


REFS1 0 0 1 1 REFS0 0 1 0 1 Voltage reference Selection AREF, Internal Vref turned off AVCC with external capacitor at AREF pin Reserved Internal 2.56V Voltage Reference with external capacitor at AREF pin

ADCSRA: ADC status & control register

ADEN BIT ADSC BIT ADFR ADIF ADIE

To Enable the ADC. To start each ADC conversion. To operate ADC in Free Running mode. This bit is set when an ADC conversion completes When this bit is written to one and the I-bit in SREG is set, the ADC Conversion Complete Interrupt is activated. Bits 2:0 ADPS2:0 :- ADC Prescaler Select To provide ADC Clock

:::::-

ADC PRESCALER
ADPS2 0 0 ADPS1 0 0 ADPS0 0 1 Division Factor 2 2

0
0 1 1

1
1 0 0

0
1 0 1

4
8 16 32

1
1

1
1

0
1

64
128

ADC DATA REGISTER


This register stores the value after ADC conversion. It is a 16 bit register divided in ADCL(8bit) & ADCH(8bit).
The ADLAR bit in ADMUX register defines how converted data is stored.

ReadADC()
This Function is used read the selected ADC input pin passed as a parameter.
uint16_t ReadADC(uint8_t ch) { //Select ADC Channel ch must be 0-7 ch=ch&0b00000111; ADMUX|=ch; //Start Single conversion ADCSRA|=(0b01000000); //set ADSC //Wait for conversion to complete while(!(ADCSRA & (0b00010000))); // wait for ADIF bit of ADCSRA to be enabled //Clear ADIF by writing one to it ADCSRA|=(00010000); return(ADC); }

EXAMPLE

DISPLAY ON LCD ATMEGA 8

TEMPERATURE SENSOR

With the help of ADC, we can monitor the change in the ambient temperature.

THANK YOU!!!

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