UrabnBadger
New Member
Hi, I'm pretty new to this lark.
I'm tryin to do a simple adc on a 12F675 and then built on the program from there.
The Circuit:
5V (5.5V MAX) regulator connected to Vdd & Vss
5V LED connected over Vdd & Vss
0.1 microfarad decoupling cap over the Vdd & Vss pins
GP0/AN0 connected to a 500K Potentiometer (Also connected to Vss and Vdd)
GP1 connected to 5V LED (red)
GP2 connected to 5V LED (green)
10bit adc so 0V = 0 & 5.5V = 1023
Very simple!
I am writing in assembly using MPLAB IDE,
I went through my program and narrowed the problem down to the adc results. I setup a little test to blink out the results held in each bit of the ADRESL and ADRESH files
When ADCON0,ADFM is set (results right justified) my test revealed
bits 2-7 of ADRESH are always clear (as expected) so you would expect that bits 0 & 1 of ADRESH and bits 0-7 of ADRESL would contain the results
Instead I got the following:
V@AN0 ARESH ADRESL DEC RESULT EXPECTED DEC RESULT
0.0V 00000000 00000000 0 0
0.5V 00000000 00000000 0 93
1.0V 00000000 00000000 0 186
1.5V 00000001 00000001 257 279
2.0V 00000001 00000001 257 372
2.5V 00000001 00000001 257 465
3.0V 00000010 00000010 514 558
3.5V 00000010 00000010 514 651
4.0V 00000010 00000010 514 744
4.5V 00000011 00000011 771 837
5.0V 00000011 00000011 771 930
5.5V 00000011 00000011 771 1023
It seem odd that ARESH is the same as ADRESL, also the relusts aren't waht I expected, can anyone make any sense of these results?
So next I changed to ADCON0,ADFM clear (results left justified) my test revealed bits 0-5 of ADRESL aren't always clear as you would expect
(Note that on the data sheet P42 it says for ADFM=0 bits 0-5 of ADRESL read as 0)
My results are below:
V@AN0 ARESH ADRESL DEC RESULT EXPECTED DEC RESULT
0.0V 00000100 00000100 1028 0
0.5V 00011100 00011100 7196 93
1.0V 00110000 00110000 12336 186
1.5V 01001000 01001000 18504 279
2.0V 01011100 01011100 23644 372
2.5V 01111100 01111100 31868 465
3.0V 10001100 10001100 35980 558
3.5V 10100110 10100110 42662 651
4.0V 10111001 10111001 47545 744
4.5V 11001100 11001100 52428 837
5.0V 11100100 11100100 58596 930
5.5V 11110001 11110001 61937 1023
Again ARESH is the same as ADRESL, is this correct? shouldn't bits 0-5 of ADRESL always be 0?
If only bits 0-7 of ADRESH and bits 6 & 7 of ADRESL are used the following decimal equivalents are obtained:
V@AN0 ARESH ADRESL DEC RESULT EXPECTED DEC RESULT
0.0V 00000100 00 16 0
0.5V 00011100 00 112 93
1.0V 00110000 00 192 186
1.5V 01001000 01 289 279
2.0V 01011100 01 369 372
2.5V 01111100 01 497 465
3.0V 10001100 10 562 558
3.5V 10100110 10 666 651
4.0V 10111001 10 742 744
4.5V 11001100 11 819 837
5.0V 11100100 11 915 930
5.5V 11110001 11 967 1023
This would apper to be correct! but to summarise:
What is happening with the results for ADFM = 1 incorrect
Why are the results of ADRESH and ADRESL the same for ADFM = 1 of 0
Why aren't the bits 0-5 of ADRESL 0 when ADFM = 0
Hope someone can shed some light as I'm tearing my hair out!
Cheers
I'm tryin to do a simple adc on a 12F675 and then built on the program from there.
The Circuit:
5V (5.5V MAX) regulator connected to Vdd & Vss
5V LED connected over Vdd & Vss
0.1 microfarad decoupling cap over the Vdd & Vss pins
GP0/AN0 connected to a 500K Potentiometer (Also connected to Vss and Vdd)
GP1 connected to 5V LED (red)
GP2 connected to 5V LED (green)
10bit adc so 0V = 0 & 5.5V = 1023
Very simple!
I am writing in assembly using MPLAB IDE,
I went through my program and narrowed the problem down to the adc results. I setup a little test to blink out the results held in each bit of the ADRESL and ADRESH files
When ADCON0,ADFM is set (results right justified) my test revealed
bits 2-7 of ADRESH are always clear (as expected) so you would expect that bits 0 & 1 of ADRESH and bits 0-7 of ADRESL would contain the results
Instead I got the following:
V@AN0 ARESH ADRESL DEC RESULT EXPECTED DEC RESULT
0.0V 00000000 00000000 0 0
0.5V 00000000 00000000 0 93
1.0V 00000000 00000000 0 186
1.5V 00000001 00000001 257 279
2.0V 00000001 00000001 257 372
2.5V 00000001 00000001 257 465
3.0V 00000010 00000010 514 558
3.5V 00000010 00000010 514 651
4.0V 00000010 00000010 514 744
4.5V 00000011 00000011 771 837
5.0V 00000011 00000011 771 930
5.5V 00000011 00000011 771 1023
It seem odd that ARESH is the same as ADRESL, also the relusts aren't waht I expected, can anyone make any sense of these results?
So next I changed to ADCON0,ADFM clear (results left justified) my test revealed bits 0-5 of ADRESL aren't always clear as you would expect
(Note that on the data sheet P42 it says for ADFM=0 bits 0-5 of ADRESL read as 0)
My results are below:
V@AN0 ARESH ADRESL DEC RESULT EXPECTED DEC RESULT
0.0V 00000100 00000100 1028 0
0.5V 00011100 00011100 7196 93
1.0V 00110000 00110000 12336 186
1.5V 01001000 01001000 18504 279
2.0V 01011100 01011100 23644 372
2.5V 01111100 01111100 31868 465
3.0V 10001100 10001100 35980 558
3.5V 10100110 10100110 42662 651
4.0V 10111001 10111001 47545 744
4.5V 11001100 11001100 52428 837
5.0V 11100100 11100100 58596 930
5.5V 11110001 11110001 61937 1023
Again ARESH is the same as ADRESL, is this correct? shouldn't bits 0-5 of ADRESL always be 0?
If only bits 0-7 of ADRESH and bits 6 & 7 of ADRESL are used the following decimal equivalents are obtained:
V@AN0 ARESH ADRESL DEC RESULT EXPECTED DEC RESULT
0.0V 00000100 00 16 0
0.5V 00011100 00 112 93
1.0V 00110000 00 192 186
1.5V 01001000 01 289 279
2.0V 01011100 01 369 372
2.5V 01111100 01 497 465
3.0V 10001100 10 562 558
3.5V 10100110 10 666 651
4.0V 10111001 10 742 744
4.5V 11001100 11 819 837
5.0V 11100100 11 915 930
5.5V 11110001 11 967 1023
This would apper to be correct! but to summarise:
What is happening with the results for ADFM = 1 incorrect
Why are the results of ADRESH and ADRESL the same for ADFM = 1 of 0
Why aren't the bits 0-5 of ADRESL 0 when ADFM = 0
Hope someone can shed some light as I'm tearing my hair out!
Cheers