## 0-2V Input to ADC using ATmega8

7 posts / 0 new
Author
Message

I have a 0 to 2V input on one channel of ATmega8.
Can any one help me by explaining the AVCC, GND and AREF conenctions as well as register values. I am using internal 1MHz clock.
And most important is I want to avoid the use of "L-C" circuit (inductor coil) with ATmega8's ADC.

Yellowboy_75

yellowboy_75 wrote:
I have a 0 to 2V input on one channel of ATmega8.
Can any one help me by explaining the AVCC, GND and AREF conenctions as well as register values. I am using internal 1MHz clock.
And most important is I want to avoid the use of "L-C" circuit (inductor coil) with ATmega8Is there any one to help me around?

Have you read the Atmel application note "AVR042: AVR Hardware Design Considerations"???
You'll find it here: http://www.atmel.com/dyn/products/app_notes.asp?family_id=607

I don't use a LC circuit anyway. I just connect a RC to AVCC where R = 1Ohm and C = 100nF.
I always connect a 100nF capacitor to the AREF pin.
I wire the analog GND directly to the voltage regulator which is placed only a few cm away
from the AVR chip.
A RC circuit at each analog input is recommend. Generally I chose R = 4.7kOhm or higher
since this resistor protects the input pin from voltages greater than VCC of ATmega8
The value of C depends on the max. sample rate you need.

To set up the ADC you must first determine the ADC clock:

Quote:
By default, the successive approximation circuitry requires an input clock frequency
between 50 kHz and 200 kHz to get maximum resolution. If a lower resolution than 10
bits is needed, the input clock frequency to the ADC can be higher than 200 kHz to get a
higher sample rate.
(See datasheet page 195)

Since your ATmega8 is running at 1MHz there are 2 valid ADC clock frequencies you can select:
125KHz and 62.5kHz

If you want to run the ADC at 125kHz you can initialize it this way:
This expression is similar to
and

The next step is to select the reference voltage.

If 10% accuracy is enough for you I suggest that you use the internal reference voltage
which can differ from device to device from 2.3V to 2.7V. (See datasheet page 243).

If you need a higher absolut accuracy you have to connect an external reference voltage to
the AREF pin.

Note that the reference voltage determines the maximum input voltage for an analog
input pin. If your reference voltage is 2.048V a voltage of 2.046V at an analog input pin will
give the max result of 1023 (0x3FF). In this example the ADC resolution is 2mV.
(See datasheet page 194)

The next step is to determine the input channel. If your ATmega8 comes in DIP package
you can chose one pin of PC0 to PC5 as analog input. This done in the ADMUX register
which handles the reference voltage selection, too. (See datasheet page 204)

If you want to measure a voltage at PC5 (ADC5) and you use the internal reference set
ADMUX = _BV(REFS1) | _BV(REFS0) | _BV(MUX2) | _BV(MUX0);

If you want to measure a voltage at PC5 (ADC5) and you use an external reference set

Now you have initialized the ADC
To start the conversation type

The ADSC flag is automatically cleared when the ADC has finished the conversation
(see datasheet page 204)

To do just a simple wait on the ADC result type
which is similar to the expression

Then you can read the conversation result from the ADC register (datasheet page 205):
uint16_t value;

Regards
Sebastian

I have set the bit required for this (ADLAR)

How about the connections of AVCC and GND. OD i need to conenct them too when using external AREF. What is the use of AVCC?

Yellowboy

Quote:
I have set the bit required for this (ADLAR)

This requires only a single byte read:
uint8_t value;

Quote:
How about the connections of AVCC and GND. OD i need to conenct them too when using external AREF. What is the use of AVCC?

I recommend you read the application note which I suggested before.
You find details in the datasheet chapter "Pin description", too.

Regards
Sebastian
Sebastian

I am opting for internal ref. this will solve my problem.
Thanks
Its working now and I learn a lot from your posts.
I have checked the URL you mentioed in last post, its showing many PDFs. i was confused which you are talking about.

Yellowboy