# the value from ADC not consistence

Discussion in 'Embedded Systems and Microcontrollers' started by mermaid09, Mar 15, 2010.

1. ### mermaid09 Thread Starter New Member

Nov 21, 2009
9
0
Hello everyone,
i need some help about reading voltage that going to ADC of PIC18F252 and then display that value to LCD.my input of adc is from current sensor that produce output in term of voltage

My range input voltage should be 4.00V to 4.10v only,and the output produce at lcd also in that range but the problem here at certain time the output at lcd go outside that range (but in short time). Why its happen?. I really need precision value to calculate some formula.

And second problem,the output that display at lcd are change from one to another are to fast (about 1 second).

below is my coding

unsigned char ch;
char *text;
long tlong,;

void LCD()
{

Delay_ms(500);// need delay
Lcd_Out(2,1,text); // Write result in the second line
tlong = (long)adc_rd * 4800; // Convert the result in millivolts
tlong = (tlong / 1024)
ch = tlong / 1000; // Extract volts (thousands of millivolts)
// from result

Lcd_Chr(2,9,48+ch); // Write result in ASCII format
ch = (tlong / 100) % 10; // Extract hundreds of millivolts
Lcd_Chr_CP(48+ch); // Write result in ASCII format
Lcd_Chr_CP('.');
ch = (tlong/ 10) % 10; // Extract tens of millivolts
Lcd_Chr_CP(48+ch); // Write result in ASCII format
ch = tlong % 10; // Extract digits for millivolts
Lcd_Chr_CP(48+ch); // Write result in ASCII format

Delay_ms(1);

}

Feb 22, 2010
31
0

3. ### t06afre AAC Fanatic!

May 11, 2009
5,939
1,224
I am not sure the internal ADC in PIC MCU is made for such resolution at all. Each bit will have a bit weight equal to 98uV. I think the internal noise is much higher than this. And how about the noise in the source signal, and the reference. You could try putting the MCU to sleep during the ADC cycle. That will reduce the noise some. But to be honest I think your project specifications do not match your current hardware at all

4. ### Markd77 Senior Member

Sep 7, 2009
2,803
595
Have you considered using op amps to amplify this voltage range? I'm not sure if this would give a better result but it might be worth a try.

5. ### mermaid09 Thread Starter New Member

Nov 21, 2009
9
0
symqwerty :
my vref+=+5v and my vref- = ground,

t06afre:
what do u say my project specifications do not match with current hardware. can u give same idea how to correct my mistake?i really weak about microcontroller

Alberto:
how to take average reading?im not understand,how to implement at coding C?how the coding lool like to sort?can u give me some example either in c programming or something else that can me to understand about your suggestion?

thank u so much for your time and kind to help me.

Dec 5, 2009
5,201
315
7. ### symqwerty Member

Feb 22, 2010
31
0
i think you are using MikroC as your editor, right?

Taking average reading means you need to store every digital value, add it, and divide by n-number of value..So, you could modify your code little bit.
For example, instantiate an array of size 10. Then, after getting digital ADC value, keep it in array of index 0, and the next execution or looping, keep it in index 1,and repeat until 10...then, sums it up and divide by 10 to get the 'mean' value before displayed it on LCD.

But the best practice is to keep shifting out old data in the array every-time you get new ones or in other words, using FIFO concept.