adc - analog to digital conversion on avr microcontroller atmega16
TRANSCRIPT
ROBO INDIAhttp://roboindia.com
ROBO INDIA
• Are all CONTINUOUS time signals ANALOG ?
• All continuous time signals are analog but all analog signals are not continuous time
ROBO INDIA
• 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
• What's wrong with totally analog ?• Ans – Two arrows in a Quiver is always
better than one
ROBO INDIA
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
ROBO INDIA
ROBO INDIA
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
• ADMUX = 0x4X
• Let x = 1
⇒ ADMUX = 0x41 ⇒ ADMUX = 01000001
0 1 0 0 0 0 0 1
ROBO INDIA
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
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
• ADCSRA = 0x86
• Let x = 1
⇒ ADCSRA = 0x41 ⇒ ADCSRA = 10000110
1 0 0 0 0 1 1 0
ROBO INDIA
• BIT 7
• ADEN ⇒ ADC Enable bit
• ADEN = 1 ⇒ Enable ADC
• ADEN = 0 ⇒ Disable ADC
1 0 0 0 0 1 1 0
ROBO INDIA
• BIT 6
• ADSC - Write this bit to one to start each conversion
1 0 0 0 0 1 1 0
ROBO INDIA
• BIT 4
• ADIF - This bit is set when an ADC conversion completes
1 0 0 0 0 1 1 0
ROBO INDIA
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