Author Topic: Looking in-depth at microcontroller ADCs  (Read 3686 times)

0 Members and 1 Guest are viewing this topic.

Offline muxTopic starter

  • Regular Contributor
  • *
  • Posts: 119
Looking in-depth at microcontroller ADCs
« on: July 07, 2017, 04:51:29 pm »
I'm involved in a dozen or so projects that rely on the AVR XMEGA ADC, and I'm using it in all kinds of weird and wonderful ways - from massively oversampling to get more resolution out of it to doing very fast precision measurements. I found out a lot of interesting things that are probably of great use to other people using highly configurable ADC peripherals. So I made a video and did some quantitative measurements as well. Video first:



The cool thing about MCU ADCs is that you can change many, many settings. But what effect do these settings have? Specifically, on the XMEGA ADC you can change:
  • The ADC can be free-running (immediately continue with a new conversion when the previous one completes)
     or single-shot
  • The ADC clock speed can be changed (to at most the CPU frequency / 4)
  • It can run in signed or unsigned mode
  • You can limit the current usage of the ADC peripheral
  • You can change the voltage reference
  • You can increase the sampling time (in increments of 1/2 of the ADC frequency)
  • You can run it as single-ended, differential or differential with gain, with 1/2x to 64x gain

Now, the datasheet says very little about how each of these settings affect the accuracy, precision, hell, even the input impedance. And you can do back of the envelope calculations, but nothing beats some serious experimentation. So I built a test set-up, which you can see in the video. This allows me to read out the ADCs from a powerbank project via USB and visualize the results. Each measurement is 1024 samples, which I bin into a histogram (top-left) and do a time series plot on (bottom).



Using this, I tried to figure out what works and what doesn't, basically. And it's mighty interesting.

Some things I found:
  • The ADC is a true differential design, as it says in the datasheet. It doesn't matter one bit whether you run the ADC single-ended, differential or differential with x1 gain, you get the exact same noise, accuracy, it's like you haven't changed anything at all. But you do get an extra bit of resolution in unsigned mode, so single-ended is pretty much always better for positive signals.
  • The gain stage is really good. Like, you get exactly twice the signal and twice the noise. It's not a digital multiplier, you can measure tiny signals reliably. If you're accumulating and decimating anyway, this is a great way to do current measurements, even with very low voltage drops over the shunt.
  • Every ADC needs a sampling time adjustment. I'm measuring a ~20kohm impedance signal, but simply increasing the sample time (and thus letting the sample capacitor charge over a longer period of time) allows you to basically decouple input impedance from ADC speed (up to a point of course).
  • The datasheet isn't messing around when it says the maximum sample rate is 350kS/s. The ADC does really funny stuff (read: bogus results) when you crank it up to 8MHz (=~1MS/s).
  • The 1/2x in the gain stage is a true analog divider. So you can measure 3.3V inputs with a 2.048V reference!
  • The internal bandgap reference is pretty noisy. Also not very accurate or stable, even over short time periods. It's bordering on useless for precision measurements.
  • If you do it right, these ADCs can easily compete with discrete ADCs. Not at the same sample rate per se, you'll have to put a bit more care into the frontend, but it's way more than serviceable. I mean, Fluke puts TMS320s in their meters, those just use the built-in ADC peripheral.

Some of these things contradict 'common knowledge' about the XMEGA, SAM and UC3 ADCs, for instance that you have to run them differential signed to get the best results (e.g. https://blog.frankvh.com/2010/01/03/atmel-xmega-adc-problems-solutions/).

I went into some more detail in the video, and I got a whole bunch more measurements done. If anyone's interested, I can expand more on some points or talk about my experiences with other microcontrollers, although this is all pretty universal across the board.
 
The following users thanked this post: hans, diyaudio, ajb, Svuppe, alm, colorado.rob

Offline danadak

  • Super Contributor
  • ***
  • Posts: 1875
  • Country: us
  • Reactor Operator SSN-583, Retired EE
Re: Looking in-depth at microcontroller ADCs
« Reply #1 on: July 10, 2017, 10:13:01 am »
Some processors have ability to bypass reference. See discussion here on PSOC -


http://origin-www.cypress.com/knowledge-base-article/choice-reference-voltage-accurate-adc-measurements-psoc-3-psoc-4-and-psoc-5lp


Regards, Dana.
Love Cypress PSOC, ATTiny, Bit Slice, OpAmps, Oscilloscopes, and Analog Gurus like Pease, Miller, Widlar, Dobkin, obsessed with being an engineer
 
The following users thanked this post: splin

Offline JPortici

  • Super Contributor
  • ***
  • Posts: 3925
  • Country: it
Re: Looking in-depth at microcontroller ADCs
« Reply #2 on: July 10, 2017, 11:10:06 am »
excellent  :clap: your pc application and your analysis is something i wanted to do many times but never actually bothered to
strange that this topic hasn't had more attention, maybe you should have posted in the voltnut section  >:D
 

Offline muxTopic starter

  • Regular Contributor
  • *
  • Posts: 119
Re: Looking in-depth at microcontroller ADCs
« Reply #3 on: July 14, 2017, 02:04:00 pm »
Yes, all XMEGA (and Atmel SAM) MCUs can also use an external reference directly, but in this application I happened not to include one, so I was relegated to the internal references.
 

Offline ajb

  • Super Contributor
  • ***
  • Posts: 2867
  • Country: us
Re: Looking in-depth at microcontroller ADCs
« Reply #4 on: July 14, 2017, 03:04:06 pm »
Will definitely watch the video later, but based on your writeup: :-+


The ADC is a true differential design, as it says in the datasheet. It doesn't matter one bit whether you run the ADC single-ended, differential or differential with x1 gain, you get the exact same noise, accuracy, it's like you haven't changed anything at all. But you do get an extra bit of resolution in unsigned mode, so single-ended is pretty much always better for positive signals.
At least in the SAMD series, you also still have to explicitly configure the negative mux in single-ended mode--It defaults to something like AIN0 on reset, which will cause some head scratching if assume that single ended means ground referenced.  They should really just call the "DIFFMODE" bit "SIGNED", since that's all it really does AFAICT.
 


Share me

Digg  Facebook  SlashDot  Delicious  Technorati  Twitter  Google  Yahoo
Smf

 

- - -
-->