CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

ADC conversion question

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
wolverine_349



Joined: 07 Dec 2005
Posts: 6

View user's profile Send private message

ADC conversion question
PostPosted: Fri Mar 24, 2006 5:05 am     Reply with quote

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

View user's profile Send private message Send e-mail

PostPosted: Fri Mar 24, 2006 5:24 am     Reply with quote

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? Wink
SherpaDoug



Joined: 07 Sep 2003
Posts: 1640
Location: Cape Cod Mass USA

View user's profile Send private message

PostPosted: Fri Mar 24, 2006 8:06 am     Reply with quote

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.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group