NerdKits - electronics education for a digital generation

You are not logged in. [log in]

NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.

Microcontroller Programming » ADMUX=0

February 18, 2016
by Javy
Javy's Avatar

I'm totally new to micro-controller programming, so forgive the unforgivable questions.

How does ADMUX=0 (in the temp sensor project) do anything? I thought ADMUX was a 8

bit register, controlled with REFS1 through MUX0. The datasheet is supposed to have

all necessary info, I just don't see where ADMUX=0 sets anything (though, I'm sure it

does). Is ADMUX a variable in one of the "include" files?

Any cool help will be deeply appreciated.

February 18, 2016
by Javy
Javy's Avatar

If my question makes zero sense, let me know too.

Thanks.

February 19, 2016
by BobaMosfet
BobaMosfet's Avatar

Javy-

Your question is perfectly fine.

'ADMUX' is defined in the compiler header files that get included (usually another header file included by io.h). This identifies which -channel- of the MUX you want to use. The 'channel' corresponds to the pin you want to use. The ATMEGA168 has multi-purpose pins. This means you can use them for one thing or another, depending on the capabilities that Atmel has designed for each respective pin.

In the datasheet, if you look at 'Pin Configurations', you will see that pins 23-28 may be used for ADC purposes. In other words, the ATMEGA168 has 5 ADC pins (or 5 channels), labeled as 'ADC0' through 'ADC5'. 'AD' = analog to digital. 'C' = Port C, and '5' = channel. So, in the datasheet, for more information about using the ADC, look under 'Alternate Functions of Port C'.

So, if you say 'ADMUX = 0', you're choosing channel 0 (aka pin ADC0) and telling the ADC to watch that pin for an analog voltage level. Once it registers that voltage level, it converts that to an 8-it digital value, which is what you get when you combine and read the high and low ADC registers.

BM

February 19, 2016
by BobaMosfet
BobaMosfet's Avatar

Javy-

The section 'Analog to Digital converter' (section 23 in my datasheet) has the detail information about programming for the ADC.

Note that AVREF is used by the MCU to determine the upper-end of the ADC range, and GND the lower reference.

BM

February 19, 2016
by Javy
Javy's Avatar

BM,

Thank you for the excellent response. I will be going through all your valuable info within 48

hrs. I can't wait to build my foundation in micro-controller programming.

Also, If you do one-on-one tutoring and live within 200 miles of San Francisco, please let me

know.

Respectfully,

Javy

February 19, 2016
by BobaMosfet
BobaMosfet's Avatar

Javy,

Thank you, you are too kind. Unfortunately, I'm on the other side of the country or I'd be happy to help you-- but for any questions you have-- please feel free to post them here in this forum, or in the forum that Rick has created (in case this board goes down for good).

http://www.rs-micro.com/forums/

Any of us here are more than happy to help.

BM

February 19, 2016
by Javy
Javy's Avatar

Sounds good!

Javy

Post a Reply

Please log in to post a reply.

Did you know that you can make a capacitive proximity sensor with some aluminum foil and paperclips? Learn more...