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 support@ccsinfo.com

Analog to Digital - values read are not stable

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







Analog to Digital - values read are not stable
PostPosted: Mon Jul 30, 2007 10:33 am     Reply with quote

I'm using a PIC16F877A uC with a pressure sensor to detect changes in water level. The pressure sensor outputs values from 0 - 5V at a 0-4kPa pressure max. However I read the values and they are not stable. The pressure values I get vary by 0.1V when the pressure is not suppose to be changing. When I measure with a volt meter the voltage remains constant. Something with the PIC is causing the pressure to vary. I was wondering if anyone else had such problems with analog to digital conversion. Is it the PIC or is there something with the code that is causing this problem for me.

Furthermore if anyone knows of a very easy way to average out 10 readings so that any values that are outside the norm would not be read. What I mean is if I have values 1.11, 1.14, 1.10, 1.09, 1.40, 1.14, I would want to remove the 1.40 and then take the average of the remaining values. I am trying to minimize code complexity.

I don't have much experience with analog to digital and was hoping someone out here who does have a lot of experience could let me know what to do with these oscillations in analog values. Thank you.
RLScott



Joined: 10 Jul 2007
Posts: 465

View user's profile Send private message

Re: Analog to Digital - values read are not stable
PostPosted: Mon Jul 30, 2007 11:40 am     Reply with quote

PICHelpNeeded wrote:
...if anyone knows of a very easy way to average out 10 readings so that any values that are outside the norm would not be read. What I mean is if I have values 1.11, 1.14, 1.10, 1.09, 1.40, 1.14, I would want to remove the 1.40 and then take the average of the remaining values. I am trying to minimize code complexity....


I don't think there is anything simpler than maintaining a sorted list of values. As each new value is read, the new value gets inserted in the list so as to keep the list sorted. That requires an array of 10 items. Then after all 10 items have been read in, throw away the first and the last elements. Sorry, it's not very efficient, but that's what you would need to do.

Robert Scott
Real-Time Specialties
Ypsilanti, Michigan
Ttelmah
Guest







PostPosted: Mon Jul 30, 2007 12:21 pm     Reply with quote

Seriously, before applying damping, find out why the values are changing so much. I'd look in particular at the stability of your Vref. Using a similar pressure sensor, with a properly stabilised Vref, and a properly selected ADC clock (be very careful on the timing of this - the internal RC clock in particular is not suitable for stable readings, unless you put the processor to sleep for the reading), I see variations of only +/- a single count...

Best Wishes
SherpaDoug



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

View user's profile Send private message

PostPosted: Mon Jul 30, 2007 1:43 pm     Reply with quote

There is a much easier way than a sorted list. You don't even have to store all the numbers. Just keep track of the maximum, the minimum, and the sum. When you are done reading just subtract the maximum and minimum from the sum then shift 3 bits to divide by 8 for the average.
_________________
The search for better is endless. Instead simply find very good and get the job done.
PICHelpNeeded
Guest







PostPosted: Mon Jul 30, 2007 10:43 pm     Reply with quote

Thanks for your help and ideas. They were very helpful. But as was mentioned the VREF has to be stable. I don't know if I did this right. I simply used the 5V supply as VREF. Is there a better way of doing this? Perhaps I did not setup my analog circuit appropriately.

The pressure sensor has three pins. Approx. 5V power (4.75min - 5.25max allowed). The third pin I connect to AN0 and that is it. The PIC uses an external 20mhz clock and is powered by the same supply as the pressure sensor.

In my code I read the analog values at 100ms. Below is the setup code I used.

setup_adc_ports(RA0_analog);
setup_adc(ADC_CLOCK_DIV_64);
set_adc_channel(0);


If there is a better way to do it, please let me know, thank you.
LEVENT



Joined: 04 May 2006
Posts: 16

View user's profile Send private message

PostPosted: Tue Jul 31, 2007 2:42 am     Reply with quote

I want to say a basic way to solve this problem.
You can connect small capacitance to your ADC pin like 100pf.This capacitance can remove ripples caused from some reasons.
SherpaDoug



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

View user's profile Send private message

PostPosted: Tue Jul 31, 2007 7:55 am     Reply with quote

I would want to know if the sensor is "ratiometric" or not. If it is not ratiometric it might put out 2.5V at half pressure. If it is ratiometric it might put out 50% of the supply voltage at half pressure. For low noise that is an important difference.

Also are there heavy loads like relays or motors that might make the +5V supply wobble? If so can you use a separate 5V regulator for just the sensor and the PIC reference?
_________________
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
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