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 values are not constant

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



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

ADC values are not constant
PostPosted: Tue Sep 07, 2010 11:29 pm     Reply with quote

hi,

I tried ADC program with a pot of 1k and it was working fine,
however I tried with different adc values but the values are not constant.
Like I tried with adc i/p from .18v to .94V but the values are not constant without any linearity. :(

Code that I tried is as follows:
Code:

#include <18F452.h>
#device ICD=TRUE ADC=10
#fuses HS,NOLVP,NOWDT
#use delay (clock=20000000)
#use rs232 (baud= 9600,xmit = PIN_C6)

const char TABLE[]={0xc0,0xf9,0xa4,0xb0,0x99,0x92,0X82,0XF8,0X80,0X98};

void display(int x)         
    {
     int  i,j,k,temp;   //define four temporary variable
     temp=x;                 //temporary keep AD convert result
     i=temp/100;         //get display hundred bit
     j=(temp%100)/10;    //get display ten bit
     k=(temp%100)%10;     //get display Entries bit
       
     output_d(TABLE[i]);   //get the display hundred bit code from table
     output_low(PIN_A5);
     delay_ms(1);                //delay some time,ensure display brightness
     output_high(PIN_A5);
     output_d(TABLE[j]);       //get the display ten bit code from table
     output_low(PIN_A4);             //RA4 OUTPUT low,light ten bit display
     delay_ms(1);                //delay some time,ensure display brightness
     output_high(PIN_A4);
     output_d(TABLE[k]);        //get the display Entries bit code from table
     output_low(PIN_A3);       //RA5 OUTPUT low,light Entries bit display
     delay_ms(1);                //delay some time,ensure display brightness
     output_high(PIN_A3);
     
 
 /* if(j>=5)
  {
  output_high(PIN_C0);
  }
  else
 
  if(i>=1)
  {
  output_high(PIN_C2);
  }
  else
  output_low(PIN_C0);
 */
 
  }
   
void main ()
{
 
 float z; 
 setup_adc_ports(AN0_AN1_AN3);
 setup_adc(ADC_CLOCK_INTERNAL);
 output_low(PIN_C2);
 output_low(PIN_C3);
 output_low(PIN_C6);
 output_low(PIN_C7);
  SET_TRIS_c(0x00);

while(1)
{
   set_adc_channel( 0 );
   z = read_adc();
   delay_ms(10);
   z=z*1000;
   display(z);
}
}
PCM programmer



Joined: 06 Sep 2003
Posts: 21708

View user's profile Send private message

PostPosted: Tue Sep 07, 2010 11:58 pm     Reply with quote

Quote:
#use delay (clock=20000000)

setup_adc(ADC_CLOCK_INTERNAL);

I tried with different adc values but the values are not constant.

We probably have discussed this topic about one million times but it still
comes up, so here's a recent thread on it:
http://www.ccsinfo.com/forum/viewtopic.php?t=43419
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Wed Sep 08, 2010 3:35 am     Reply with quote

Thanks PCM,

I tried with changing the clock by using 32Tosc for 20Mhz frequency. But still my values are fluctuating.
My circuit is simple. I'm giving voltage varying from .18v to .94v. But I'm not getting anything.
I'm trying to learn since I'm new to PIC.
Please help,

Thanks
temtronic



Joined: 01 Jul 2010
Posts: 9243
Location: Greensville,Ontario

View user's profile Send private message

PostPosted: Wed Sep 08, 2010 9:21 am     Reply with quote

You might want to just display the raw 10 bit ADC result to PC or similar.

This would show whether it's a hardware glitch or a math problem.

If your pot is in one place, the readings hould be within a couple of bits. Having a filter cap on the input will smooth the result.
Sid2286



Joined: 12 Aug 2010
Posts: 119

View user's profile Send private message

PostPosted: Thu Sep 09, 2010 5:35 am     Reply with quote

hi,

I got the bug, i was having floating ground :(
i was trying to use analog input of another circuit to the input of PIC.

Ok, i'm wondering what is the return type of read_adc() function. is it ascii or int..?
Geps



Joined: 05 Jul 2010
Posts: 129

View user's profile Send private message

PostPosted: Thu Sep 09, 2010 7:19 am     Reply with quote

Sid2286 wrote:
hi,

I got the bug, i was having floating ground :(
i was trying to use analog input of another circuit to the input of PIC.

Ok, i'm wondering what is the return type of read_adc() function. is it ascii or int..?


According to the help files:

Quote:
Returns:
Either a 8 or 16 bit int depending on #DEVICE ADC= directive.
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