View previous topic :: View next topic |
Author |
Message |
asmboy
Joined: 20 Nov 2007 Posts: 2128 Location: albany ny
|
|
Posted: Mon Oct 17, 2011 4:22 pm |
|
|
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
|
|
|
temtronic
Joined: 01 Jul 2010 Posts: 9246 Location: Greensville,Ontario
|
|
Posted: Mon Oct 17, 2011 4:33 pm |
|
|
...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
|
|
Posted: Mon Oct 17, 2011 5:20 pm |
|
|
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
|
|
Posted: Tue Oct 18, 2011 12:32 pm |
|
|
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. |
|
|
|