Fluctuation in ADC in PIC16F877

Thread Starter

ecaits

Joined Jan 6, 2014
56
Dear Sir,

I have used ADC in PIC16F877 with hi-tech C compiler. I am measuring pressure in field through pressure transmitter giving 0-100mV. I am getting constant mV from pressure transmitter but when I am giving it to my controller, its fluctuate lots. My ADC resolution is 4.88 mV (analog input range 0-5V).

How can I solve my problem???

Nirav
 
Last edited:

t06afre

Joined May 11, 2009
5,934
Any schematics to show us? That would help us a lot in helping you. But some tips anyway. You want to adapt your 0-100mV transducer signal to your full ADC span. So your signal need to be amplified. Also adding at least some low-pass filtering before the ADC stage will also be highly recommended. The filter specs need to be adjusted to your sample-rate and the signal bandwidth. I will also recommend using oversampling. Sample data with a higher rate than needed and use a average of several samples for further data processing. If you use the result of 2^n samples. You can create a very fast calculating by using a shift operator on a "raw" integer data type
 

Thread Starter

ecaits

Joined Jan 6, 2014
56
Can I show you my program code??? One more thing, when I am providing mV voltage from mV source, at that time it is not fluctuating. I have attached program code for your reference.

I am using internal ADC of PIC16F877.

How can I use oversampling???
 

Attachments

ErnieM

Joined Apr 24, 2011
8,377
If a fixed source doesn't show the same changes as the real transducer either the signal has noise or the impeadance of the transducer is too large.
 

Thread Starter

ecaits

Joined Jan 6, 2014
56
I am sure that sensor is working fine because as per range it works properly and gives accordingly same output.

If the impedance of transducer is high then how can I solve the problem???

What may be the probable reason for ADC fluctuation???
 

THE_RB

Joined Feb 11, 2008
5,438
How many ADC counts is it fluctuating?

You mention using the sensor "in the field" so it is probably picking up 1 or more ADC counts in noise. That's perfectly normal.

Your Vref of 5.0v is very large, and your sensor range (0-100mV) is very low!

Your total sensor range will read 0-20 ADC counts! So with 1-2 counts ADC noise it will definitely be "fluctuating"!
:)
 

enggricha

Joined May 17, 2014
89
if you can share your schematic that would be useful. In the past I have had situations where things connected to other ports have caused inexplicable problems with the ADC reading.

I know this makes no sense, but it has happened.
 

djsfantasi

Joined Apr 11, 2010
9,163
I am also curious as to how many ADC counts it is fluctuating.

Often, when performing an ADC measurement, it is useful to measure several times and calculate a rolling average. This evens out minor variations and in the long run, provides more consistent results. I have typically kept the last 3 - 5 measurements and averaged them. This can be done with an array of 5 elements and an index which cycles from 0 to 4 and back to 0 again.
 

Thread Starter

ecaits

Joined Jan 6, 2014
56
How many ADC counts is it fluctuating?

You mention using the sensor "in the field" so it is probably picking up 1 or more ADC counts in noise. That's perfectly normal.

Your Vref of 5.0v is very large, and your sensor range (0-100mV) is very low!

Your total sensor range will read 0-20 ADC counts! So with 1-2 counts ADC noise it will definitely be "fluctuating"!
:)
No, it fluctuate a lot. Should I use voltage amplifier??? What can be the reason of so high fluctuation???
 

THE_RB

Joined Feb 11, 2008
5,438
THE_RB said:
How many ADC counts is it fluctuating?
...
Change your code to display the actual 10bit ADC result from 0-1023.

Then please tell us what the readings are.

That is what we meant by "ADC counts". The actual 10bit reading from the ADC hardware module.
:)
 

t06afre

Joined May 11, 2009
5,934
What is a lot of fluctuations? Another thing is that the ADC type used in your PIC tend to fluctuate around the least significant bit. In your setting these fluctuations will be about 1/20 of the sensors total measurement range.
I would with no doubt have used gain to stretch the signal so 100mV is fitted to the max ADC range. And used both an analog filter and some digital filtering. That will bring us to the next question what is your planned sample rate?
 

enggricha

Joined May 17, 2014
89
Bhai,

as long us dont say how much its fluctuating or share a schematic or some information that we can work with this is not going anywhere.
 

Thread Starter

ecaits

Joined Jan 6, 2014
56
I have used 741 op-amp as amplifier with 50 Gain so I am getting 0-5 V w.r.t. 0-100mV analog input. I have also used the averaging in ADC program. I have also tried 10uF capacitor connected to adc pin and ground. Still I am getting fluctuation in reading of ADC. What may be the reason for that???
 

ErnieM

Joined Apr 24, 2011
8,377
You chose one of the nosiest op amps still in production.

A 10uF cap does little against high frequency noise, and nothing against other sources of noise.

Your fluctuation is still undefined, as are your schematic and code.
 

ErnieM

Joined Apr 24, 2011
8,377
I can see from your schematic that none of the components are powered.

Add some power, then add the appropiate bypass caps.
 

paulfjujo

Joined Mar 6, 2014
23
hello,

Probleme is in ADC software...
I tried it, but bad results with Raw adc value...and strange edge effects ..
i suppres the integer table of 20 elements ..
uses right shift instead Divide
and simplify ..and it is now OK

nota: tested with Fosc=16MHz (not 4Mhz)


very few difference of code with MikroC and MPLABX
mainly GO_bit instead of GODONE

Rich (BB code):
unsigned int ADC_Read(unsigned char channel)
{
  int i; 
  unsigned int avg_output=0,temp=0 ;
  //unsigned int digital_out[20];  // genere warning IRP_bit ........  
  if(channel > 7) return 0; 
  ADCON0 &= 0xC7;        // AND= RAZ channel selection
  ADCON0 |= channel<<3; // OR = Set  chanel selection
  Delay_ms(3);
  for(i=0;i<32;i++)
  //for(i=0;i<20;i++)
        {   
            GO_bit = 1;
            _asm NOP  //  allways one instruction after setting bit GO  (MicroChip recommandation)
            while(GO_bit);  // Wait until conversion gets over
	    Delay_ms(2);
	  //  temp=temp+digital_out;  
            temp=temp+(unsigned int) (ADRESH<<8) + ADRESL ;   // Store 10-bit output into a 16-bit variable
	    Delay_ms(5);
            
        }
Delay_ms(5);
avg_output=temp>>5;    // use SHIFT to divide by 32 to avoid use of maths.h
//avg_output=temp/20;
return(avg_output);
}



nota: same subjet in EDABOARD forum
 

THE_RB

Joined Feb 11, 2008
5,438
Averaging 32 ADC readings is a good idea. BUT you lose almost all the benefits when you integer-divide by 32 afterwards!

Also, you are recording the samples with 7mS between, so you may be getting a beat frequency with the AC mains frequency which is usually the big offender in terms of LF noise that upsets ADCs.

If you reduce that time delay from 7mS to (say) 1/16th of a mains halfcycle, you get 32 samples recorded during one mains full cycle. (so assuming France is 50Hz mains; each sample is 20mS/32, so you sample every 625uS.)

And finally, we are all still asking;
HOW MANY ADC COUNTS IS IT FLUCTUATING?

A good test is to just take one sample every second and display it (range 0-1023). Then look at the sample every second and write down what it is. Then we can see how much it is "fluctuating".
 

paulfjujo

Joined Mar 6, 2014
23
hello,

Has i said in post #18, probleme was not fluctuation
but bad software ..
here is the result i get on my terminal ..
with output on LCD and USART
One measure per 500mS...at different level..
source for ADC input is a potar between +5V and 0V .

You can see..no fluctuation.. with a stable ADC value on ADC input..
 

Attachments

Top