Author Topic: ATMega328 ADC accuracy graph  (Read 21883 times)

0 Members and 1 Guest are viewing this topic.

Offline miceuz

  • Frequent Contributor
  • **
  • Posts: 387
  • Country: lt
    • chirp - a soil moisture meter / plant watering alarm
Re: ATMega328 ADC accuracy graph
« Reply #25 on: October 29, 2013, 07:03:09 am »
Hi,

Nice coinscidence, I was making ATmega ADC measurements of my own a couple of weeks ago. I've used AD5045 voltage reference and DAC8411 DAC for my test setup. This is the graph I got, light grey value is uncompensated error, dark grey is offset compensated error and red is offset and gain compensated error:


As you can see, it's pretty nonlinear, but somewhat close to datasheet specs. On another run, I've added some noise to a DAC signal (5LSB peak to peak triangle wave) and oversampled the ATmega ADC input up to 14 bits:



As you can see, quantization noise is gone, but the nonlinearity can be clearly seen. Note that LSBs on the second graph are 14 bit LSBs, so the nonlinearity we get is somewhat 0.8 LSB (on 10 bit scale) which is pretty close to datasheet specifications.

Lessons learned - never use internal avr adc if you want to achieve any decent accuracy :)

« Last Edit: October 29, 2013, 07:12:19 am by miceuz »
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: ATMega328 ADC accuracy graph
« Reply #26 on: August 08, 2014, 08:06:30 am »
Your results are good. The integral non-linearity is specified as 0.5 LSB. With your 5V reference voltage this would be 2.5mV (5V / 1024). You measured less than 1mV error.

Has this been resolved? Inevitable quantization error is 0.5 LSB in any case, even a perfect, perfect ADC will be "wrong" by 0.5 LSB (2.5mV in this case) simply because if the input voltage is, say, 2.49mV, the ADC has to commit to output = 0 LSB (0mV, 2.49mV error) or output = 1 LSB (5 mV, 2.51mV error). Getting an error of only 0.7mV is like, impossible for many values of analog input  :-// ? How is the graph that good? I must be missing something, like results are being averaged or some 12-bit mode is being used or something.
 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3439
  • Country: us
Re: ATMega328 ADC accuracy graph
« Reply #27 on: August 08, 2014, 04:21:27 pm »
Your results are good. The integral non-linearity is specified as 0.5 LSB. With your 5V reference voltage this would be 2.5mV (5V / 1024). You measured less than 1mV error.

Has this been resolved? Inevitable quantization error is 0.5 LSB in any case, even a perfect, perfect ADC will be "wrong" by 0.5 LSB (2.5mV in this case) simply because if the input voltage is, say, 2.49mV, the ADC has to commit to output = 0 LSB (0mV, 2.49mV error) or output = 1 LSB (5 mV, 2.51mV error). Getting an error of only 0.7mV is like, impossible for many values of analog input  :-// ? How is the graph that good? I must be missing something, like results are being averaged or some 12-bit mode is being used or something.

There is no 12bit mode with the ATMEGA328 - 10 bit only.  The sampling is averaged so it could filter out random fluctuation.  Averaging may give the impression of higher resolution, but more digits in the math doesn't change the resolution of the ADC.  I did however found that as it averages, (with luck) one could discern is LSB closer to X-1, X, or X+1 with a higher degree of confidence.

Since you already expressed your dislike of "reading+-%error" format in another thread, you will not like this graph.  Not your cup of tea.

There really isn't anything to resolve from my perspective.  I took some data, posted it in "Reading +- % Error" format, and think others may find it useful.  One person's experience of one ATMEGA328 only.  It is just another data point.  Just like doing a tear down on a single DDM of a model line.  With a sample size of one, it can't even begin to tell you how a "typical" DDM of that model would behave.  Just another data point.

Rick
 

Offline Carrington

  • Super Contributor
  • ***
  • Posts: 1202
  • Country: es
Re: ATMega328 ADC accuracy graph
« Reply #28 on: August 08, 2014, 10:43:41 pm »
@ miceuz:

I used your code (k-thermocouple-lib) here:

https://www.eevblog.com/forum/reviews/youyue-858d-some-reverse-engineering-custom-firmware/msg484155/#msg484155

Thanks for sharing.  :-+

Note: I have not corrected the ADC offset, and I use only the 328 internal reference.



Yes, 10 bit only, with the following tool is easy to calculate ENOB (ENOB-PROGRAM-PACKAGE).
http://www.maximintegrated.com/en/design/tools/calculators/hp50g/?=1



Damn, I always have to edit and re-edit my posts, because I wrote something wrong.  :palm:
« Last Edit: August 08, 2014, 11:01:18 pm by Carrington »
My English can be pretty bad, so suggestions are welcome. ;)
Space Weather.
Lightning & Thunderstorms in Real Time.
 

Offline rs20

  • Super Contributor
  • ***
  • Posts: 2318
  • Country: au
Re: ATMega328 ADC accuracy graph
« Reply #29 on: August 09, 2014, 06:34:01 am »
Has this been resolved? Inevitable quantization error is 0.5 LSB in any case, even a perfect, perfect ADC will be "wrong" by 0.5 LSB (2.5mV in this case) simply because if the input voltage is, say, 2.49mV, the ADC has to commit to output = 0 LSB (0mV, 2.49mV error) or output = 1 LSB (5 mV, 2.51mV error). Getting an error of only 0.7mV is like, impossible for many values of analog input  :-// ? How is the graph that good? I must be missing something, like results are being averaged or some 12-bit mode is being used or something.

There is no 12bit mode with the ATMEGA328 - 10 bit only.  The sampling is averaged so it could filter out random fluctuation.  Averaging may give the impression of higher resolution, but more digits in the math doesn't change the resolution of the ADC.

The fact that you were averaging does resolve this dilemma, sorry if you mentioned this earlier in the thread. Believe it or not, averaging many samples can improve noise below one LSB, and more importantly removes quantization noise as a fundamental obstacle. This is the basis of the "Hi-res" modes on many oscilloscopes that give better resolution than the native 8 bits of the ADC by heavily oversampling and averaging. It's a real gain, not mathematical smoke and mirrors. 1-bit delta-sigma ADCs are the ultimate example of this (loosely).

Since you already expressed your dislike of "reading+-%error" format in another thread, you will not like this graph.  Not your cup of tea.

I'm sorry about the other thread, I know I was going on about it a bit. However, in this thread I was just trying to understand how you were seemingly getting better results that physically possible (averaging explains it). BTW, the graph that I'm commenting on is the absolute one, without that division I "dislike" so much :). The datasheet says 0.5 LSB of non-linearity, you're getting 0.2 LSB, other people should assume 0.5 LSB to be safe but it's good to see that your sample is behaving well within the datasheet limits. Few applications (basically, only ones that average or integrate, such as that current measuring one in the other thread) can even theoretically benefit from a non-linearity better than 0.5 LSB.

Thanks!
 

Offline Rick LawTopic starter

  • Super Contributor
  • ***
  • Posts: 3439
  • Country: us
Re: ATMega328 ADC accuracy graph
« Reply #30 on: August 09, 2014, 05:45:15 pm »
...I'm sorry about the other thread...

No sweat.  No harm done.  We just increased understanding between us.

I am not an EE guy.  While I understood the (%FS+%Rd+n_digits) and realize it make perfect technology sense, and is the accurate way of saying exactly how-much and where potential errors are, but I found it hard to immediately visualize.  After making this (%Rd+%error) graph to give me a visual, I thought others may find it useful.

Rick
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf