I am using the 10bit ADC off the 16f689 for some simple conversion and this is what i get:
actual analog voltage off mutimeter=0.65V
reading from the adc =0.5674V
if analog=0.66V,digital =0.57V
and if the anlog voltage increases the digital value goes far and far from the anlog value
this is how i interprete the voltage off the ADC code
Code:
//max adc voltage is 4.5V(MAX_VOLTAGE)
long y;
float decivolts;
delay_ms(100);
GO=1; //start conversion
while(GO)continue; //poll GO for cobversion completion
ADIF=0;
y=Read_ADC(ADC_READ_ONLY);
decivolts=(y*MAX_VOLTAGE)/1023;
also,if i take many samples,analog voltage remains the same whereas the digital value changes at times.
is the formula ok? what am i doing wrong? need help guys.
Storic
Joined: 03 Dec 2005 Posts: 182 Location: Australia SA
Posted: Fri Mar 24, 2006 5:24 am
I am also reviewing my analogue coding, I had lots of movement where I was getting different reading all the time from the same ref input. Have you considered http://www.ccsinfo.com/forum/viewtopic.php?t=19509 Filtering your analog input with code as describe.
Andrew _________________ What has been learnt if you make the same mistake?
SherpaDoug
Joined: 07 Sep 2003 Posts: 1640 Location: Cape Cod Mass USA
Posted: Fri Mar 24, 2006 8:06 am
I would first print out the A/D reading in hex and make sure that is stable and tracks the analog input. Once you know that works then you can worry about the math.
On the other hand "decivolts=(y*MAX_VOLTAGE)/1023; " looks bad to me. If y is a long int then I would expect y*MAX_VOLTAGE to do an integer multiply, effectively truncating MAX_VOLTAGE to 4. The /1023 may also be an integer division, the list file will tell you for sure. _________________ The search for better is endless. Instead simply find very good and get the job done.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum