Next Tutorial >>>
There are totally four registers for A2d conversion in PIC16f877 and PIC16f877A .They are the following .
(NOTE : Almost all the PIC series of IC's have this same register configuration .So knowing this is enough to program all the PIC series IC's )
Name | Bit 7 | Bit 6 | Bit 5 | Bit 4 | Bit 3 | Bit 2 | Bit 1 | Bit 0 |
ADRESH | A2D Result Register - High Byte | |||||||
ADRESL | A2D Result Register - Low Byte | |||||||
ADCON0 | ADCS1 | ADCS0 | CHS2 | CHS1 | CHS0 | GO/DONE | - | ADON |
ADCON1 | ADFM | - | - | - | PCFG3 | PCFG2 | PCFG1 | PCFG0 |
ADCON0 Configuration
Since PIC has 10 bit A2D and its a 8 bit microcontroller it needs an extra register to store the extra 2 bits resulting in the A2D conversion .Thats the job the first two registers ADRESH and ADRESL name itself is self explanatory .ADRESH:Stores the higher 8 bits .
ADRESL:Stores the lower 8 bits .
So now we are done with the first two registers .
The next register that we are gonna see in PIC16F877A is ADCONO .
The first two bits ADCS1 and ADCS0 is required to select the A2D clock .The table for clock selection is given below .If I am using 5 MHZ I will select 01 thats fosc/8 .
ADCS1 | ADCS0 | A/D Conversion Clock Select bits. | Max. Clock Freq. |
0 | 0 | Fosc/2 | 1.25MHz |
0 | 1 | Fosc/8 | 5MHz |
1 | 0 | FOsc/32 | 20MHz |
1 | 1 | Frc (Internal A2D RC Osc.) | Typ. 4uS |
The next set of bits are channel select .YOu can select the appropriate channels by selecting the appropriate bits .So now I am using 5 MHZ and selecting RA2 for example , now bit selection will be 01010xxx .The bits that are named as X are still to be selected .
The next bit is GO/DONE .Setting this bit high starts A2D conversion and it is automatically cleared when it is complete .So monitoring the status of this bit can tell us about the status of Analog to digital conversion .So we have to set it high to start conversion .So now our bit configuration will be 010101xx .
If you look at the first table you will see bit1 is useless .So put a zero there .So now our bit configuration becomes 0101010x .
The last bit is ADON .When the bit is set it turns on the A2D when cleared it turns off .So we are setting 1 there .Now it becomes
01010101 .This is the bit configuration to select 5 MHZ clock channel AN2 .The next three bits are useless .
CHS2 | CHS1 | CHS0 | Channel | Pin |
0 | 0 | 0 | Channel0 | RA0/AN0 |
0 | 0 | 1 | Channel1 | RA1/AN1 |
0 | 1 | 0 | Channel2 | RA2/AN2 |
0 | 1 | 1 | Channel3 | RA3/AN3 |
1 | 0 | 0 | Channel4 | RA5/AN4 |
1 | 0 | 1 | Channel5 | RE0/AN5 |
1 | 1 | 0 | Channel6 | RE1/AN6 |
1 | 1 | 1 | Channel7 | RE2/AN7 |
ADCON1 Configuration
The next channel is ADCON1 . The bit7 ADFM(Analog to digital conversion format ) is used to select the format .Setting this bit high makes it 10 bit converter .And clearing it makes it 8 bit ie the result only appears in ADRESH and ADRESL is ignored .Now we are entering thre most complicated part of the register selection .Please look at the following table to select the configuration you need .
Visit WINPIC PROG to learn more in detail about the register selection .
PCFG3: PCFG0 | AN7 RE2 | AN6 RE1 | AN5 RE0 | AN4 RA5 | AN3 RA3 | AN2 RA2 | AN1 RA1 | AN0 RA0 | Vref+ | Vref- |
0000 | A | A | A | A | A | A | A | A | Vdd | Vss |
0001 | A | A | A | A | Vref+ | A | A | A | RA3 | Vss |
0010 | D | D | D | A | A | A | A | A | Vdd | Vss |
0011 | D | D | D | A | Vref+ | A | A | A | RA3 | Vss |
0100 | D | D | D | D | A | D | A | A | Vdd | Vss |
0101 | D | D | D | D | Vref+ | D | A | A | RA3 | Vss |
0110 | D | D | D | D | D | D | D | D | Vdd | Vss |
0111 | D | D | D | D | D | D | D | D | Vdd | Vss |
1000 | A | A | A | A | Vref+ | Vref- | A | A | RA3 | RA2 |
1001 | D | D | A | A | A | A | A | A | Vdd | Vss |
1010 | D | D | A | A | Vref+ | A | A | A | RA3 | Vss |
1011 | D | D | A | A | Vref+ | Vref- | A | A | RA3 | RA2 |
1100 | D | D | D | A | Vref+ | Vref- | A | A | RA3 | RA2 |
1101 | D | D | D | D | Vref+ | Vref- | A | A | RA3 | RA2 |
1110 | D | D | D | D | D | D | D | A | Vdd | Vss |
1111 | D | D | D | D | Vref+ | Vref- | D | A | RA3 | RA2 |
in the next tutorial we are going to kick start with PIC16F877A programming in C .I am gonna use mikroc compiler .
7 comments:
a good resource for robotics. And the tutorial of PIC is also good to see and learn for us
Thank you Aman. I will try to come up with more good ones in the future .
thank you for the information. i need help in programming PIC 16F877A can i talk to you using mail? my email is sirc4526@yahoo.com thankz in advance
huh...very good tutorial...
it helps a lot in my final year project....=)
hy arun.. nice tutorial.. can u give tutorial on 10 bit adc for pic18f4550.. i'm stuck.. plss help
can anyone help me out to solve a analog to digital converter program coding
Hi actually i have an doubt it might be stupid but im confused please help me
0 0 Fosc/2 1.25MHz
0 1 Fosc/8 5MHz
1 0 FOsc/32 20MHz
what if im using a 12MHz crystal in my board..which one should i use.
Post a Comment