We will be closed on November 25, 2021 and November 26, 2021 in observance of the Thanksgiving holiday. We will resume normal operations on November 29, 2021. Wishing you a safe and happy holiday from all your friends at SparkFun!


Receive a free SparkFun USB Thumb Drive with every order this weekend. Details.

According to Pete - Analog to Digital Conversion

Check out this month's episode of "According to Pete."

Favorited Favorite 0

In today's episode of "According to Pete," Pete Dokter, SparkFun's Director of Engineering/electronics guru extraordinaire/all-around swell guy, guides you through one of the mysteries of hobbyist electronics - analog to digital conversions.



Give it a look and let us know what you think - leave any questions, comments, or suggestions below. We hope you enjoyed this edition of "According to Pete" and we'll see you next month!

Interested in learning more foundational topics?

See our Engineering Essentials page for a full list of cornerstone topics surrounding electrical engineering.

Take me there!

Comments 25 comments

  • I think AtP is in a dead tie with Robert's "New Products" (don't head back to Chernobyl just yet). That's one of the first things I check for every Friday morning, and I'm disappointed if it's not there right away. It makes my day.

    Actually, all the SF newsreels are great. Keep them coming!

  • hello, as per your tutorial adc = (vol/5)1023. but i have one document adc = 1023-(vol/5)1023. could you please explain why its minus again with 1023.

  • Pete, you had it right the first time it's 1023 (i.e. 1111111111) not 1024! Common mistake.

  • You totally lost me on the part where the ADC starts setting bits in the output register. Do you know any place that has more detailed information on how that part is done?

  • Pete-O...

    I enjoy your "According to Pete" posts, good refresher and gets the memory moving. My question is how long, typically, does your posts take to make?

    • Maybe a day (spread over several days) to write it and verify that I'm not going to tell any lies, then a couple of hours for me and Gregg to shoot.

  • Oh, Pete. For such a strong engineer, you should know that Nyquist said you must sample at GREATER THAN 2f. Equal to is not sufficient.

    See the comment from TheRegnirps for more info.

    • Eh... that's not really what I meant to say, and certainly not what I meant to imply. The message I was really trying to convey is that it will all go wonky if you're sampling at less.

      • I'm pretty sure everyone knows what you meant :-) I see that Nyquist thing everywhere from text books to technical papers so, must.....write....posting! It is a personality flaw. In the real world I filter pre-conversion with op-amp active filters, oversample, then digital filter or correlate. It is curious that one of the few places where it all comes together and works wonderfully is the Sigma-Delta converter. I have some 26 bit and they really work solid. It's a miracle on a chip. You could probably explain it in a 6 hour video. Or, GPS, which is a mathematical and physics nightmare. But buried in each ground unit is a Kalmann Filter, another of those things that can bring the math and hardware together and really work, though need the math to get it set up and tuned in right.

        By the way, a discrete sigma-delta with an AVR in the center would be a great project.

  • Nyquist says in order to recorver any signal you must sample it 2 times de frequency of the signal. So when you aply the Fourier transform to a periodic signal, will be non periodic and discrete in frequencies,and if you obey the Nyquist law you will not have aliasing, so you can apply a filter like a Chebyshev filter and make the inverse Fourier and obtain only the desired frequency, thats the base of tecomunications,greetings from Portugal

    • Must have been someone else. Nyquist says sample at > 2f, not =2f. Try it on paper. Sample a sin(wt) at 2f. You will get a constant value somewhere between -1 and 1 depending only on the phase of your sampling clock. Wait, I'll do it for you: sin(pi)=0, sin(2pi)=0, sin(3pi)=0, sin(4pi)=0, etc. You can reconstruct from a long list of zeroes? Or phase is 45 degrees and you get steady 0.707. Sampling at 2f aliases to a constant. Funny everyone thinks it is the right thing to do, isn't it?

  • Great Video! Quick (hopefully) question. I'm trying to sample a DC motor voltage, and it's really noisy (brush noise, etc.). Is there a good way to do this with a standard arduino ADC (maybe an RC filter)? I've seen some stand alone ADC chips, are these worthwile, or should Arduino ADC function basically the same way? Thanks a ton!

    • Yes, filters are the way to get rid of the noise. Consider the frequency range you're interested in measuring, and make sure the filter you design falls well above that frequency range.

      You can use RC filters, or even better, an active filter (opamp filter). Like Pete showed in his diagram, ADCs have sampling capacitors that need to charge quickly to the voltage you're measuring. If you have too much resistance from your source (like, through the resistor in your RC network), the capacitor may not charge up all the way during the acquisition time, which results in some measurement error. On the other hand, if you're feeding the ADC with the (low impedance) output of an opmap, you don't have to worry about that.

      There are also ways of filtering in software. As long as you've applied enough hardware filtering to avoid aliasing, you can use a digital filter as well. Look up IIR filters, to get some ideas.

      Stand alone ADCs will usually have much better specs than integrated ADCs. Higher precision (number of bits), better internal voltage references (accuracy), and faster sampling rates. See what you can get the Arduino to do for you, and if you end up bumping your head on these limitations, you can always add the external ADC later.

    • The Atmega ADC on the Arduino should suffice, and since DC motors are very noisy, always a good idea to do a LPF of any sort. The standalone ADC chips are very nice if you need to use more than a couple channels for sampling, and will always provide more accurate results because all it does is the conversion. The Atmega ADC is nice, but if you're doing anything in realtime you'll have to figure out if you need to use an interrupt system or go with the good ol' polling.

      Either way should work just fine.

  • A small nit, so common that it must have worked its way into the EE text books. If you sample exactly at Nyquist, you will get a straight line. Of course you are reading the signal at exactly the same point in its cycle every time. The Nyquist criteria is that you must sample at GREATER THAN twice the frequency of the signal of interest. And how long you need to sample is related to how much greater the sampling rate. If you need quick results, over sample, and not at an harmonic of the signal of interest (well sometimes a harmonic, if you know what you are looking for. Optimal filters, blah blah...).

    It is like over-tipping. It can pay off if you forget your new hat and the waitress runs out into the parking lot to give it to you, instead of going home with her nice new hat.

  • According to Pete is by far the best thing you create all month. I like all the other things, but I do not get near as excited about them as when I see AtP pop up on my YouTube feed. It's seriously the only reason I subscribe to your channel.

    That being said, Sparkfun is defiantly one of my more favorite web pages due to all your content and it's a great way to trick me into buying your stuff. Keep it up!

    • I'll see myself out :-(

      • Hey Robert, I'm so sorry you had ti find this out this way. One can only have one thing be their favorite.

        That said I always watch the new product posts and also enjoy them on my lunch break, and in all honesty there is no bad content here. Thanks for everything you guys do.

    • Aw, shucks. Thanks much.

      • I should be thanking you. After two years of upper level electrical engineering courses I have retained more from your videos than my previous lectures. If you are ever in the Orlando area, or we end up crossing paths, you will be having a beer on me.

        • Must be the heapin' helpin' of stupid I bring to electronics. In any case, glad to be of service.

          BTW boys and girls, if you haven't already noticed, we've got not one, but TWO engineering positions available. Wanna get "bossed" by me? ahem Well, check out the jobs section if'n you're interested.

          • ...you're kidding me.

            I am applying tonight. Fly me out there for an interview and then I'll get you that beer, and I promise it won't be a bribe or anything.

          • Are you kidding? Being one of Pete's Minions is my dream!

Related Posts

Recent Posts

All About Surveyors


All Tags