Sie sind auf Seite 1von 14

ADC

(Analog-to-Digital Converter)
Our Microcontroller is a digital electronics device.

It can respond to only two states -- either ON or OFF.

But our real world data is always in Analog form, so it has


to be converted into Digital form to work on it. ADC
Feature 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 0= 0 V
10 bit Resolution 8 bit Resolution
Resolution
The minimum value of analog quantity for which the ADC
responds…..

Let Reference Voltage = 5 Volt

In 10 bit ADC (2^10=1024)


Resolution-- 5/1024 = 4.89 mV or around 5mV

In 8 bit ADC (2^8=256)


Resolution-- 5/256 = 19.53mV or around 20mV
• In Atmega8, PORT C is Multiplexed with ADC.
• PORT C can work as both IO PORT or ADC.
• ADC can be used for interfacing analog devices like
Temperature sensor, Accelerometer etc.

A PC5 ADC5
T PC4 ADC4
M PC3 ADC3
E PC2 ADC2
G PC1 ADC1
A PC0 ADC0
8
ADC Registers
• There are three Registers which are required to control
the ADC process-

1. ADMUX (ADC Multiplexer)

2. ADCSRA (ADC Control and Status Register)

3. ADC (Digital Data Buffer)


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

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


Voltage Reference Selection for ADC

REFS1 REFS0 Voltage reference Selection

0 0 AREF, Internal Vref turned off

0 1 AVCC with external capacitor at AREF


pin
1 0 Reserved

1 1 Internal 2.56V Voltage Reference


with external capacitor at AREF pin
ADCSRA: ADC Status & Control Register

ADEN BIT : To Enable the ADC..


ADSC BIT: To start each ADC conversion…
ADATE : To start auto Triggering of the ADC …….
ADIF : This bit is set when an ADC conversion completes …
ADIE : 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 ADPS1 ADPS0 Division Factor


0 0 0 2
0 0 1 2
0 1 0 4
0 1 1 8
1 0 0 16
1 0 1 32
1 1 0 64
1 1 1 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)
{
ch=ch&0b00001111; // Select ADC Channel
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

ADCSRA|=(00010000); // Clear ADIF by writing one


to it
return(ADC);
}
AN EXAMPLE

DISPLAY ON
TEMPERATURE
SEVEN ATMEGA 8
SENSOR
SEGMENT

With the help of ADC, we can monitor the change in the


ambient temperature….
THANK YOU

Das könnte Ihnen auch gefallen