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

Problem with ADC
Goto page Previous  1, 2
 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
asmboy



Joined: 20 Nov 2007
Posts: 2128
Location: albany ny

View user's profile Send private message AIM Address

PostPosted: Mon Oct 17, 2011 4:22 pm     Reply with quote

Quote:

It shows zero for an input of .01 volts.


based on HOW you get that ".01" v i am not surprised.

a single raw ADC count could deliver that!!!

how do YOU know that you don't have a raw count of 1 ???

here is a TIP:

walk before you run.

just output the RAW converter count as a decimal 0-255 or
0-1023 for 10 bit and see what going on at low level

THEN do your volt calcs

Razz Razz
temtronic



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

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 4:33 pm     Reply with quote

...from your code snippet..

int8 adc = 0;

...

You'll have to change the type of adc to allow all 10 bits of data.


As it stands, you're dumping a 10 bit value into 8 bits, and you'll never see the correct readings.

hint... make it an int16.
haronraziq



Joined: 25 Aug 2011
Posts: 17

View user's profile Send private message

PostPosted: Mon Oct 17, 2011 5:20 pm     Reply with quote

I actually caught that mistake shortly after my last post and changing it did make it accurate at higher voltages but still has the same result at the low voltages.

asmboy, I'm not exactly sure that I follow...

Code:
void displayVoltage(int16 adc)
{
   char voltage[12];
   sprintf(voltage, "%f", (float)adc * .0048875855);         // Converts adc to text
   glcd_rect(45, 18, 69, 25, YES, OFF);            // Clear the old voltage
   glcd_text57(0, 24, voltage, 1, ON);            // Write the new voltage
}


void main()
{

   int16  adc = 0;

   setup_adc_ports(AN0_AN1_AN3);
   setup_adc(ADC_CLOCK_DIV_32);
   set_adc_channel(1);

   delay_us(200);

   glcd_init(ON);

   adc = read_adc();                 // Read a value from the ADC
    displayVoltage(adc);              // Display the reading
}
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Oct 18, 2011 12:32 pm     Reply with quote

I don't see #Device ADC=10; so apparently you are using the A/D in 8 bit mode. If you are reading 5V accurately you have at least a 5V span. So 5V/256 = a resolution of 0.019V, so 0.01V will rightly read as zero.

Even if you use 10 bit mode so 1lsb = 0.0049V, considering that A/D reading are usually +/- at least 1 count for noise, you could just barely show a reading for 0.01V.
_________________
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
Goto page Previous  1, 2
Page 2 of 2

 
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