adc - analog to digital conversion on avr microcontroller atmega16
TRANSCRIPT
![Page 1: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/1.jpg)
ROBO INDIAhttp://roboindia.com
![Page 2: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/2.jpg)
![Page 3: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/3.jpg)
![Page 6: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/6.jpg)
• Are all CONTINUOUS time signals ANALOG ?
• All continuous time signals are analog but all analog signals are not continuous time
ROBO INDIA
![Page 8: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/8.jpg)
• The ADC converts an analog input voltage to a 10-bit digital value through successive approximation.
• The minimum value represents GND and the maximum value represents the voltage on the AREF pin minus 1 LSB
ROBO INDIA
![Page 11: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/11.jpg)
• What's wrong with totally analog ?• Ans – Two arrows in a Quiver is always
better than one
ROBO INDIA
![Page 12: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/12.jpg)
A digital signal is superior to an analogsignal because it is more robust to noiseand can easily be recovered, correctedand amplified. For this reason, thetendency today is to change an analogsignal to digital data
ROBO INDIA
![Page 15: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/15.jpg)
ReadADCX() {
ADMUX=0x4X;ADCSRA=0x86;SETBIT(ADCSRA,BIT(6));
while(!(ADCSRA & (1<<ADIF)));s=ADC;
return(s);}
NOTE: X can take value from 0 to 7
ROBO INDIA
![Page 16: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/16.jpg)
• ADMUX = 0x4X
• Let x = 1
⇒ ADMUX = 0x41 ⇒ ADMUX = 01000001
0 1 0 0 0 0 0 1
ROBO INDIA
![Page 18: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/18.jpg)
The ADLAR bit affects the presentation of the ADC conversion result in the ADC Data Register.
• ADLAR = 0 ⇒ LEFT ADJUST
• ADLAR = 1 ⇒ RIGHT ADJUST
0 1 0 0 0 0 0 1
ROBO INDIA
![Page 20: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/20.jpg)
ReadADCX() {
ADMUX=0x4X; // DONEADCSRA=0x86;SETBIT(ADCSRA,BIT(6));
while(!(ADCSRA & (1<<ADIF)));s=ADC;
return(s);}
NOTE: X can take value from 0 to 7
ROBO INDIA
![Page 21: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/21.jpg)
• ADCSRA = 0x86
• Let x = 1
⇒ ADCSRA = 0x41 ⇒ ADCSRA = 10000110
1 0 0 0 0 1 1 0
ROBO INDIA
![Page 22: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/22.jpg)
• BIT 7
• ADEN ⇒ ADC Enable bit
• ADEN = 1 ⇒ Enable ADC
• ADEN = 0 ⇒ Disable ADC
1 0 0 0 0 1 1 0
ROBO INDIA
![Page 23: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/23.jpg)
• BIT 6
• ADSC - Write this bit to one to start each conversion
1 0 0 0 0 1 1 0
ROBO INDIA
![Page 24: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/24.jpg)
• BIT 4
• ADIF - This bit is set when an ADC conversion completes
1 0 0 0 0 1 1 0
ROBO INDIA
![Page 26: ADC - Analog to Digital Conversion on AVR microcontroller Atmega16](https://reader036.vdocuments.mx/reader036/viewer/2022082206/55a6bee81a28ab41688b465f/html5/thumbnails/26.jpg)
ReadADCX() {
ADMUX=0x4X; // DONEADCSRA=0x86; // DONESETBIT(ADCSRA,BIT(6)); // DONE
while(!(ADCSRA & (1<<ADIF)));s=ADC;
return(s);}
NOTE: X can take value from 0 to 7
ROBO INDIA