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 problem with 16F88

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







ADC problem with 16F88
PostPosted: Tue Jul 29, 2008 2:07 am     Reply with quote

Hi,

I have a problem with read_adc().

I try reading the chanel AN0. In the input I have 1.05 V(VDD = 3) and the function return 3C --> 0.175 V.


Code:


#include <16F88.h>
#device adc=10
#use delay(clock=8000000,RESTART_WDT)
#fuses HS,MCLR,WDT,PUT,NOBROWNOUT,NOLVP


void main(){

   setup_adc_ports(sAN0|VSS_VDD);
   setup_adc(ADC_CLOCK_INTERNAL);
   set_adc_channel(0);


   while(TRUE){

      delay_us(20);
      vbat = read_adc();
      vbat = (vbat*0.0293+0.6).001+vbat_old*0.999;
      vbat_old = vbat;
   }
}




Thanks!
Ttelmah
Guest







PostPosted: Tue Jul 29, 2008 4:10 am     Reply with quote

First, give us some code that can actually work.
What you post, has no definitions for vbat, or vbat_old, and the arithmetic as posted can't work. Makes it impossible to really 'comment'...
The code should be similar in length, but able to be compiled, and work to show the problem.
Second, what compiler version?. On a few of the older compilers, there are problems with some of the setup values for things like the ADC port.
Consider some other way of doing the damping. floating point arithmetic is _slow_, and bulky. There are simpler ways of getting a similar result.
Third, though it won't cause this problem, and the data sheet for the F88, is one of a number that doesn't 'warn' about this, the internal ADC oscillator, should only really be used in conjunction with 'sleep' sampling, otherwise the processor noise, which is asynchronous to this RC clock, can lead to poor result accuracy.

Best Wishes
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