This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

ADC read value sits at 255.

Hi all,

I've set up my ADC to read a rather low set of voltages (between 50-150mV). However, when I configure my ADC and have nothing connected to the ADC channel, it still reads 254/255.

I'm slightly confused with this because when I start measuring and then averaging what I've measured, I'm unsure if the average is correct due to this number sneaking through.

  • Hi James, 

    Well nothing can give you anything. The pin is floating "he does anything he wants to"

    What pin are you using in which board? 
    If you want to really test accuracy get a pot, to make a voltage divider and get a voltage between 0 and 3.3V. Measure it with a scope, voltmeter and also with your ADC to check if it is correct. Note that 12bits resolution very hopeful, check how precise it can be but you probably will have to discard the 2 least significant bits.

  • Luis Afonso said:
    you probably will have to discard the 2 least significant bits.

    Our findings - unless averaged - (usually) the 3 lsb have great tendency to "wander."     That's not unique to this vendor - simply the "blessing" provided by most any, "mixed signal device."

    Should higher accuracy be (really) needed - this vendor/others produce "serious" ADCs - designed to purpose - which avoid the "digital-analog" complex mix.

    @Luis - you may wish to set up for single channel conversion - but w/8 steps - and log that measure.      I can almost guarantee that all 3 lsb will jitter...     And - if you do this over time - you may note a "drift" from your earlier readings.     (assumes a proper analog signal level is presented)

  • Hello James,

    Is it because the pin is floating. Can you connect it to GND on the board and then see if the results still persist. If yes, then please send in your code as well.

    Regards
    Amit
  • Hi Luís, cheers for your reply!

    I figured it would be some along those lines. I tested it with a pot and it does indeed read the correct value on the ADC, the 'scope and voltmeter.

    In regards to discarding the 2/3 least significant bits, is this just a matter of reading the registers first 10 bits?

    And @cb1-, by avering, do you simply measure a bunch of values, store them in an array, and divide by the size of the array?
  • The ADC module also has the capability to do the averaging in hardware, up to 64 sequential samples. If you can afford "locking up" the ADC for that single measurement for that time, that's definitely the best way to go.

    About discarding the bits; I'd treat that more as a guideline in designing your "surrounding algorithm" - you shouldn't rely on the last bits being correct, but OTOH simply discarding them will result in rounding errors at your desired accuracy unless you account for that with the "plus half" trick. Whichever is the better approach really depends on your implementation.
  • Hi Veikko, I noticed the hardware sampling, so I've implemented that already.

    I'm a bit unclear how to even approach the discarding of the bits though, so I'll have to do some more google fu!

  • James Kent69 said:
    And @cb1-, by averaging, do you simply measure a bunch of values, store them in an array, and divide by the size of the array?

    That should work - although that suggestion stemmed from another.

    My point - while vendor's marketing "touts" 12 bits - that's not really achievable - and I did suggest an alternative means - should that be a requirement.

    Your "treatment" of the external (analog) signal - being introduced to the MCU - deserves (some) care/consideration.    Amit, Robert, Veikko (even this reporter) have "chimed in" - forum search should find/reveal...

  • James Kent69 said:
    And @cb1-, by avering, do you simply measure a bunch of values, store them in an array, and divide by the size of the array?

    Personally, I use a simple first order IIR. It can be implements with a few shifts and additions so it is fast. It doesn't require the arithmetic and space of an average and doesn't have need to manage the sample buffer of an average.

    Robert

    And as cb1 suggested, the care and feeding of an A/D is well worth at least some initial study.