View previous topic :: View next topic |
Author |
Message |
oxxyfx
Joined: 24 May 2007 Posts: 97
|
Adc in Pic 16F88 |
Posted: Wed Aug 22, 2007 4:18 pm |
|
|
Hello,
this may be a stupid beginner question, but I can't figure this out. The datasheet says that the above PIC has 7 x 10Bit ADC pins.
However all I am reading back from the ADC is 8 bit values. Is there a way to change this to 10 bit resolution? I could use the extra resolution in my program...
Thanks,
Ox. |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Wed Aug 22, 2007 4:24 pm |
|
|
look to the help file for #device ADC
Quote: | Relevant Preprocessor:
#DEVICE ADC=xx Configures the read_adc return size. For example, using a PIC with a 10bit A/D you can use 8 or 10 for xx- 8 will return the most significant byte, 10 will return the full A/D reading of 10 bits |
Remember to store this in a variable that can hold 10 bits,... int16 or bigger. |
|
![](templates/subSilver/images/spacer.gif) |
oxxyfx
Joined: 24 May 2007 Posts: 97
|
|
Posted: Wed Aug 22, 2007 6:21 pm |
|
|
Thank you, I found that as the second line in my .h file.
Now, if I change the
#Devide ADC =10
and then the original code:
Code: |
int8 adc_conversion(Int8 adc_value);
int8 value;
int8 y;
...
Void main() {
...
y = adc_conversion(value);
...
}
Int8 adc_conversion(int8 adc_value) {
value = read_adc();
delay_us(10);
}
|
to 16 bit integers:
Code: |
int16 adc_conversion(Int16 adc_value);
int16 value;
int16 y;
...
Void main() {
...
y = adc_conversion(value);
...
}
Int16 adc_conversion(in16 adc_value) {
value = read_adc();
delay_us(10);
}
|
Then the compiler reports back with an error:
y=adc_conversion(value) used but not defined.
The compiler version is 4.023
If I change it back to 8 bit values, it compiles without error - even if the #device adc is left on 10. |
|
![](templates/subSilver/images/spacer.gif) |
treitmey
Joined: 23 Jan 2004 Posts: 1094 Location: Appleton,WI USA
|
|
Posted: Thu Aug 23, 2007 8:15 am |
|
|
Did you also change the adc_conversion(); function itself?
So it returns an int16?
Go ahead and post a small complete test case showing the error. |
|
![](templates/subSilver/images/spacer.gif) |
oxxyfx
Joined: 24 May 2007 Posts: 97
|
|
Posted: Thu Aug 23, 2007 5:08 pm |
|
|
I did it today again just now, and it worked. Thanks for your help. Last night I might have been too tired and possibly misstyped something.
Thanks again for your help. |
|
![](templates/subSilver/images/spacer.gif) |
|