Stable ADC readings


Closed Thread
Results 1 to 40 of 91

Hybrid View

  1. #1
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    Hi, Sayzer

    I am testing it using a simple voltage divider with two resistors of the same value so that I get a value around 512 (ADC in 10 bit mode).
    That means he works in ratiometric mode and supply changes do not interfere here ...
    so, problem is elsewhere ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi, Sayzer



    That means he works in ratiometric mode and supply changes do not interfere here ...
    so, problem is elsewhere ...

    Alain
    Yes Alain, I missed that.

    Then, may be he should pause ~2ms after each read.

    Also, for example, reading lower voltages and reading higher voltages may behave differently.
    If reading higher voltages are accurate, but lower voltages are not, then there is something else, too.




    ---------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Sep 2004
    Location
    montreal, canada
    Posts
    6,898


    Did you find this post helpful? Yes | No

    Default

    Input impedance too high, too short of ADC aquisition time, noisy PSU, unstable PSU, no averaging routine, multiplexed function on the ADC pin, loose/dirty bread board contacts, poor wiring, poor oscillator, poor decoupling, etc... quite a few possibilities...
    Steve

    It's not a bug, it's a random feature.
    There's no problem, only learning opportunities.

  4. #4
    Join Date
    Jul 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    As mentioned I am decoupling, using averaging, and testing the ratio of two resistors hooked up to the same battery after the regulator.

    Let me draw the schematic and I will post.

    But before that, let me say that I switched from ADCIN to doing a manual ADCON0.1 = 1 reading, and now I get a stable value. So my problem is an erroneous use of the ADCIN command or a problem in the logic of my routine.

    BEFORE:
    Code:
    DEFINE ADC_BITS 10 ' Set number of bits in result (8, 10 or 12)
    DEFINE ADC_CLOCK 3 ' Set clock source (rc = 3)
    DEFINE ADC_SAMPLEUS 50 ' Set sampling time in microseconds
    ...
    WSum = 0
    Pause 100
    
    For i = 0 to 49
    ADCIn PinProbe, W0
    Pause 10
    WSum = WSum + W0
    Next i
    
    W0 = WSum / 50
    NOW:
    Code:
    Pauseus 50 'Stabilize
    ADCON0.1 = 1  'start the ADC
    WHILE ADCON0.1 : WEND
      
    W0.HighByte = ADRESH
    W0.LowByte = ADRESL
    It works, now the reading stays fixed and it is much faster. (I even didn't have to do any averaging)

  5. #5
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    Hi,

    What about reinitialising your Wsum value to 0 @ each 50 samples batch ??? don't you run this loop in another continuous loop ... ??? " par hasard " ...

    BTW " PinProbe " is the alias for which pin ???

    Alain
    Last edited by Acetronics2; - 22nd January 2011 at 18:10.
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  6. #6
    Join Date
    Jul 2010
    Posts
    19


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by Acetronics View Post
    Hi,

    What about reinitialise your Wsum value to 0 @ each 50 samples batch ??? don't you run this loop in another continuous loop ... ???

    Alain
    Oh I do. I left that part out of the code I pasted, but it is indeed running in an outside continuous loop.

    Code:
    PinProbe VAR PORTA.2
    ...
    myLoop:
    
    WSum = 0
    Pause 100
    
    For i = 0 to 49
    ADCIn PinProbe, W0
    Pause 10
    WSum = WSum + W0
    Next i
    
    W0 = WSum / 50
    ...
    LCDout $fe, 1 'Clear Screen
    Lcdout $fe, $80
    Lcdout "Reading: ", DEC W0
    
    Goto myLoop
    The readings I get with the ADCIN method are in the ballpark but move around too much. With the "manual" ADC method I get a stable value.
    Last edited by dream-; - 22nd January 2011 at 18:15.

  7. #7
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Default

    ADCIN also polls for the ADCON0.1 bit ...

    sooo .... aheum, how to tell it ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

Members who have read this thread : 2

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts