ADC (Analog-To-Digital Converter) and Sensor Interfacing
ADC (Analog-To-Digital Converter) and Sensor Interfacing
Systems
ADC (analog-to-digital converter)
and
Sensor Interfacing
Lecture 0901
1
Parallel versus Serial ADC
3
ADC in the AVR
In recent years, an increasing number of microcontrollers have had
an on-chip ADC peripheral.
5
Software Considerations in AVR
In the AVR microcontroller, four major registers are
associated with the ADC.
6
Registers Required for ADC
System clock
ADPS
Prescaler
ADCSRA
3
clock
5
10
ADC ADCH ADCL
VIN
VREF
7
ADMUX Register
MUX4-MUX0:
Analog Channel and Gain Selection
8
ADMUX Register
ADLAR:
0: right adjust the result
1: left adjust the result
ADLAR = 0
ADCH
Right Justified ADCL
- - - - - - ADC9 ADC8 ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADC1 ADC0
ADLAR = 1
Left Justified
ADCH ADCL
ADC9 ADC8 ADC7 ADC6 ADC5 ADC4 ADC3 ADC2 ADC1 ADC0 - - - - - -
9
ADMUX Register
REFS1-REFS0: clock
Vref selection
10
ADC
VIN
VREF
10
ADCSRA (Status Register)
11
ADC Prescaler (ADPS bits)
PreScaler (ADPS) bits let us change
the clock frequency of ADC (Can Set
Conversion Time)
12
Steps in programming ADC
1. Make the pin for the selected ADC channel an input pin.
2. Turn on the ADC module (ADEN in ADCSRA)
3. Select the conversion speed (ADPS2:0 in ADCSRA)
4. Select voltage reference and ADC input channels (ADMUX).
5. Activate the start conversion bit by writing a one to the
ADSC bit of ADCSRA.
6. Wait for the conversion to be completed by polling the
ADIF bit in the ADCSRA register.
7. After the ADIF bit has gone HIGH, read the ADCL and
ADCH registers to get the digital data output.
8. If you want to read the selected channel again, go back to
step 5.
9. If you want to select another Vref source or input channel,
go back to step 4.
13
Write C Program to get data from channel 0 (ADC0) of ADC and
display the result on Port B and Port D. Set Vref =2.56v
#include <avr/io.h>
while(1)
{
ADCSRA = ADCSRA | 0x40; ADCSRA
//start = ADCSRA
conversion | =(1<<ADSC);
ADSC 1
READ_ADC:
SBI ADCSRA, ADSC IN R16, ADCL
Keep_Monitoring: OUT PORTD, R16
SBIS ADCSRA, ADIF
RJMP Keep_Monitoring IN R16, ADCH
SBI ADCSRA, ADIF OUT PORTB, R16
RJMP READ_ADC
15