Fluctuation in ADC in PIC16F877

Discussion in 'Embedded Systems and Microcontrollers' started by ecaits, May 23, 2014.

  1. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0
    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: May 23, 2014
  2. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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
     
  3. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0
    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???
     
  4. wmodavis

    Well-Known Member

    Oct 23, 2010
    737
    150
    Are you sure the sensor is not defective? Try substituting a spare sensor and see if results are same.
     
  5. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
  6. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0
    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???
     
  7. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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"!
    :)
     
  8. enggricha

    Member

    May 17, 2014
    62
    1
    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.
     
  9. djsfantasi

    AAC Fanatic!

    Apr 11, 2010
    2,795
    830
    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.
     
  10. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0
    No, it fluctuate a lot. Should I use voltage amplifier??? What can be the reason of so high fluctuation???
     
  11. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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.
    :)
     
  12. t06afre

    AAC Fanatic!

    May 11, 2009
    5,939
    1,222
    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?
     
  13. enggricha

    Member

    May 17, 2014
    62
    1
    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.
     
  14. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0
    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???
     
  15. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    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.
     
  16. ecaits

    Thread Starter Member

    Jan 6, 2014
    52
    0

    Dear Sir,

    Plz find the schematic and code for reference.

    Nirav
     
  17. ErnieM

    AAC Fanatic!

    Apr 24, 2011
    7,386
    1,605
    I can see from your schematic that none of the components are powered.

    Add some power, then add the appropiate bypass caps.
     
  18. paulfjujo

    New Member

    Mar 6, 2014
    20
    3
    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

    Code ( (Unknown Language)):
    1.  
    2.  
    3. unsigned int ADC_Read(unsigned char channel)
    4. {
    5.   int i;
    6.   unsigned int avg_output=0,temp=0 ;
    7.   //unsigned int digital_out[20];  // genere warning IRP_bit ........  
    8.   if(channel > 7) return 0;
    9.   ADCON0 &= 0xC7;        // AND= RAZ channel selection
    10.   ADCON0 |= channel<<3; // OR = Set  chanel selection
    11.   Delay_ms(3);
    12.   for(i=0;i<32;i++)
    13.   //for(i=0;i<20;i++)
    14.         {  
    15.             GO_bit = 1;
    16.             _asm NOP  //  allways one instruction after setting bit GO  (MicroChip recommandation)
    17.             while(GO_bit);  // Wait until conversion gets over
    18.         Delay_ms(2);
    19.       //  temp=temp+digital_out[i];  
    20.             temp=temp+(unsigned int) (ADRESH<<8) + ADRESL ;   // Store 10-bit output into a 16-bit variable
    21.         Delay_ms(5);
    22.            
    23.         }
    24. Delay_ms(5);
    25. avg_output=temp>>5;    // use SHIFT to divide by 32 to avoid use of maths.h
    26. //avg_output=temp/20;
    27. return(avg_output);
    28. }
    29.  
    30. [/i]


    nota: same subjet in EDABOARD forum
     
  19. THE_RB

    AAC Fanatic!

    Feb 11, 2008
    5,435
    1,305
    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".
     
  20. paulfjujo

    New Member

    Mar 6, 2014
    20
    3
    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..
     
Loading...