Analog To Digital Converter
Analog To Digital Converter
Analog To Digital Converter
7 6 5 4 3 2 1
0
REFS1 REFS0 ADLAR MUX4 MUX3 MUX2 MUX1 MUX0 8
Bit
This is 8 bit register and used in :
Selection of channel
set reference voltage of ADC
And select output as left adjustment or right adjustment
Registers
ACSRA: ADC Control
ADC Enable andthis
Writing Status Register
bit to A
one enables the ADC. By writing it to zero, the ADC
is turned off. Turning the ADC off while a conversion is in progress, will terminate
this conversion.
ADC Start Conversion To start each conversion we have to write one to this bit,
ADSC will be high as long as a conversion is in progress. When the conversion
is7complete, it6returns to5zero. Writing4 zero to this3bit has no effect.
2 1
ADC auto 0 trigger enable When this bit is written to one, Auto Triggering of the8
ADEN ADSC ADATE ADIF ADIE ADPS2 ADPS1 ADPS0
ADC is enabled. The ADC will start a conversion on a positive edge of theBit
selected trigger signal. The trigger source is selected by setting the ADC Trigger
Select
This bits,register
is 8 bit ADTSused
in SFIOR.
to control the ADC and also show its status.
ADC Interrupt Flag This bit is set when an ADC conversion completes. ADIF is
cleared by hardware when executing the corresponding interrupt handling
vector. Alternatively, ADIF is cleared by writing a logical one to the flag.
ADC Interrupt Enable When this bit is written to one, the ADC Conversion
Complete Interrupt is activated.
ADC Prescaler Select Bits These bits determine the division factor between the
XTAL frequency and the input clock to the ADC.
//Program for ADC to read from channel 1 and show the 8 bit o/p
on PORTB
#include<avr/io.h>
#include<util/delay.h>
void ADC_init(void);
unsigned int ADC_read(unsigned char);
return (ADC);
}
int main(void)
{
unsigned int value;
DDRB=0xFF;
ADC_init(); // Initialization of ADC
while(1)
{
value=ADC_read(0);
PORTB=value;
_delay_ms(500);
}
}