Atmega Analog two pack

Back in February, [ProtoStack] posted a pretty good tutorial on how to do Analogue to Digital Conversion on an Atmega168. Based on a bread board, the tutorial also shows the often forgotten low pass filter on the AVCC lines to ensure an extra stable reference and an analog input connection to a simple voltage divider as a study point.

Moving on into the micro controller, the registers you’re going to need to twiddle are laid out and explained in detail. Finally you’re shown how to put it all together in a software project that outputs the analog reading onto a standard character LCD.

But hold on! There is more. Just released is a follow up to that tutorial which adds on Analogue to Digital Conversion Interrupts on an Atmega168A. So if you’re sitting there looking at an Arduino and want to know more about what’s going on under the hood, these are a good place to start.

Comments

  1. Daid says:

    The 2nd tutorial contains some wrong information:
    “Because we set the prescaler to 128, it take 128 clock cycles to read the analogue input. Whilst this is occuring we could be doing other things.”
    This is wrong, the prescaler is set to 128, however, it takes 13.5 ADC cycles to get the ADC sample. So it takes 1728 clock cycles to take the ADC sample.

    He also writes the ADIF bit in ADCSRA. But the datasheet says: “ADIF is cleared by hardware when executing the corresponding interrupt Handling Vector.” so there is no need for that.

    ReadTheFuckingDatasheet.

  2. rusty says:

    why so angry?

  3. No kidding right? Well regardless, thanks for the clarification Daid.

  4. error404 says:

    @rusty:

    I’ll venture a guess that folks who actually take the time to understand this stuff are a little sick of the Arduino generation writing ‘tutorials’ when they don’t really understand what’s going on themselves. It’s the blind leading the blind.

    It’s an interesting phenomenon around blogging, actually. People learn something new to them and are excited by it, so they go off half-cocked and write a blog post explaining it to others. While those that have been doing this stuff for ages don’t find it particularly interesting or difficult enough to warrant a post. So the newbie-friendly educational material that ends up out there is fraught with error and misconception.

    At least that’s my take. If I had any idea what people needed help with on AVR I’d take a stab at writing my own blog on the topic, but alas it’s all in the datasheet so I don’t see where help is needed.

  5. Simon says:

    The (unnamed) ProtoStack guy doesn’t come off as an Arduino-generation newbie to me at all. I think it’s more likely he just made a couple of minor mistakes in reading the datasheet. His articles are well written and of a high standard in general, and I’m sure he appreciates corrections to his articles without being attacked on a personal level.

  6. Daid says:

    He comes of to me has “used the ADC once or twice, and wrote a tutorial by skimming over the datasheet”

    The datasheet has atleast 2 pages dedicated to the timing of the ADC. It’s not something you should miss.

    I’m all for tutorials to get people off the arduino and into the better programming space. But this isn’t difficult stuff, it’s quite basic.

  7. Thanks for noticing this. I’ve updated the tutorial and fixed the issue. I always appreciate feedback.

    And yes, I should be a bit more careful when reading the datasheet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 94,628 other followers