Analog to Digital Converter (ADC)
Analog to Digital Converters Microcontroller understands only digital language. To convert the analog output from the sensors to digital we need ADC. In AVR family of microcontroller we have inbuilt ADC on PORTA. Each pin in PORTA has a ADC circuit connected behind it. Thus we have 8 channels of ADC. The resolution of ADC output is 10 bit i.e. the output from the ADC is any number between 0 to 1023, where 0 corresponds to 0V and 1023 corresponds to 5 V. The reference voltage of the ADC is fixed with the help of REFS bits in ADMUX register.
ADC It is a device that converts an analog input into a digital value ( a number). A ‘n’ bit ADC can covert the i/p to a value between 0 to 2 n -1 For ex. For a 8 bit ADC, with the dynamic range of 5 V gives the following O/p.
Process of A-D Conversion The conversion is 3 step process SamplingQuantizationCoding
ADC Vout is ANALOG But uC being digital can only read it as 0 or 1. 0 if Vout < 2.5 V 1 if Vout > 2.5 V However most applications require much higher resolution & multiple levels.
ADC In general O/p = ( V in / V ref ) * 2 n V ref is the max value of i/p that is expected
Analog to Digital Convertor (ADC) ATmega16 has an inbuilt 10 bit ADC (1024 Levels) 8 Multiplexed Single Ended Input Channels 7 Differential Input Channels
Registers of ADC Registers used in the ADC ADMUX – ADC Multiplexer Selection Register ADCW – ADC Word ADCSRA – ADC Control and Status Register A
Using ADC (WinAVR) #include #include “adc.h” #include “lcd.h” void main( ) { int x; DDRA=0b ; ADCinit();// initializes ADC LCDinit( ); LCDclr( ); while(1) { x= ADCread(7);// converts analog i/p at pin 7 to digital LCDgotoXY(0,5); LCDWriteInt(x,5); _delay_ms(300); }
Check point !!!!! Make sure you include adc.h and adc.c in ur folder In make-file, add the.c file to the src list SRC= $(TARGET).c lcd.c adc.c