Analog To Digital Convertor: PIC18f452
Analog To Digital Convertor: PIC18f452
DIGITAL
CONVERTOR
PIC18f452
INTRO
8 ADC’s (ANO-AN7) in PIC16f877a with 10-bit resolution
The A/D module has four registers. These registers are:
Used to configure
• 8- bit A/D Control Register 0 (ADCON0) settings of ADC
• 8- bit A/D Control Register 1 (ADCON1)
• 8- bit A/D Result High Register (ADRESH)
Hold binary result of
• 8- bit A/D Result Low Register (ADRESL) converted analog
signal
bit 7-6 ADCS1:ADCS0: A/D Conversion Clock Select bits (ADCON0 bits in bold , ADCS2 bit is in
ADCON1 reg)
<ADCS2:ADCS1:ADCS0> Clock Conversion
0 00 FOSC/2
0 01 FOSC/8
0 10 FOSC/32
0 11 FRC (clock derived from the internal A/D RC oscillator)
1 00 FOSC/4
1 01 FOSC/16
1 10 FOSC/64
1 11 FRC (clock derived from the internal A/D RC oscillator)
bit 2 GO/DONE’: A/D Conversion Status bit indicates whether conversion completed or not?
When ADON = 1:
1 = A/D conversion in progress (setting this bit starts the A/D conversion which is automatically
cleared by hardware when the A/D conversion is complete)
0 = A/D conversion not in progress
A = Analog input
D = Digital I/O
C/R =
# of analog input channels /
# of ADC voltage references
PIC ADC INTERNAL BLOCK
DIAGRAM
ADC CODING STEPS
Load ADCON0 reg Load ADCON1 reg
Set Analog Channel Give Some delay of
as i/p • Result format? about 1ms to
• Channel?
• Pin settings? capture i/p
• Clk Source?
completely
• ADON bit?
unsigned Adc_Read(char channel);
It returns 10-bit unsigned digitized number
of the specified analog channel. NOTE:
1. Don’t forget to do TRIS settings of analog
channel being used!!!
2. Also call function Adc_init() function to initialize
ADC module with RC internal clock.