Professional Documents
Culture Documents
Al-AZHAR UNIVERSITY
Microcontrollers:
Programming and Applications
(ITME 4336 )
Chapter 6
Analog to Digital Conversion
Lecturer: Dr. Eng. Mohammad Aqel
First Semester 2022/2023
5V 7
2.5V X
X= 3.5 3 or 4
• The variations consist in the resolution and interfacing of the different ICs.
• The input range of the 0831 is 0 to 5 volts, which matches the TTL voltage
levels used in PIC circuits.
• The converter uses a sample and hold capacitor to store the analog
charge and performs a successive approximation algorithm to
produce the digital result.
• The time required for the holding capacitor on the ADC to charge is
called the acquisition time.
• The exact acquisition time can be determined from the device’s data
sheet.
• The A/D module has high- and low-voltage reference inputs that are
selected by software.
• Where Tad is A/D conversion time, Fosc is the oscillator clock frequency in
MHz, and Tdiv is the divisor determined by bits ADSC1 and ADSC0 of the
ADCON0 register.
• Bits CHS2 to CHS0 in the ADCON0 register determine which of the analog
channels is selected.
• Code can test the status of the GO/DONE bit in order to determine if
conversion has concluded.
• Bit 0 of the ADCON0 register turns the A/D module on and off.
Alazhar University Dr. Mohammad Aqel 17
GAZA First Semester 2022/2023
The ADCON1 Register
• Bit 7 of the ADCON1 register is used to determine the bit justification of
the digital result.
• This is possible because the 10-bit result is returned in two 8-bit registers;
therefore, the six unused bits can be placed either on the left- or the right-
hand side of the 16-bit result.
void main() {
ADC_Init();
while (1) {
adc_value = ADC_Read(0); // Get 10-bit results of AD conversion
if (adc_value>= 511) //If A/D value is less than 511 (less than 2.5 Volt)
portb = 1; //then turn on LED0 only [(2.5V / 5V)* 1023 = 511.5 ]
else //5v --------> 1023
portb = 0; //2.5v -------> x
// x= (1023 *2.5v) / 5v = 511.5 =511
}
void main() {
TRISA = 0xFF; // PORTA is input
TRISB = 0; // PORTB is output
TRISC = 0; // PORTC is output
ADC_Init();
while (1) {
adc_value = ADC_Read(0); // Get 10-bit results of AD conversion
PORTB = adc_value; // Send lower 8 bits to PORTB
PORTC = adc_value >> 8; // Send 2 most significant bits to RC1, RC0
}