Author Topic: Understanding Atmega8: ADC and Bit precision  (Read 3836 times)

0 Members and 1 Guest are viewing this topic.

Offline GophermofurTopic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
Understanding Atmega8: ADC and Bit precision
« on: March 04, 2010, 11:46:28 AM »
Hey Guys,

Alright, I'm fairly new to electronics in general but I'm slowly working my way through as much material as I can find, however, I've hit a stumbling block.

What I *think* i know, as in pertains to the Atmega8, please correct me if I'm wrong:
1. A port is made up of several pins.
2. Each pin can only have a value of 0 or 1 (0V or 5V)

Now for the question:

After reading the Fuzzy Logic tutorial, I got confused because it mentions that you can have values 0 - 255 coming from a photoresistor. I understand the ADC converts an analog signal into digital, but how can it convert it to a value between 0 - 255 if the pin can only handle 0/1? Do ADC pins have special properties that allow for more bits? I did read somewhere on the Atmel guide for the Atmega8 that the ADC can handle 10-bit's, but I'm not sure why or how?

Thanks in advance!

Offline chelmi

  • Supreme Robot
  • *****
  • Posts: 496
  • Helpful? 15
Re: Understanding Atmega8: ADC and Bit precision
« Reply #1 on: March 04, 2010, 01:40:32 PM »
Hi,

All of the pins can be used as General Purpose Input/Ouput (GPIO). These can be set high (5V) or low (0V) if used as output, or read high or low (another name for 0 or 1) when set as input.
These pins are grouped into ports, but this is not relevant now. Some pins can also be configured for specific purpose, analog to digital conversion being one of them.

When a pin is set to ADC input, it is rerouted internally to a specific device called ... ADC :)
This device takes an analog voltage as input, between 0 and 5V (the max value can be configured) and outputs a 10 bits value. 10 bits means that you will get a number between 0 and 1024 (2^10),
0 for 0V and 1024 for 5V. So each step between 0 and 1024 will represent around 5mV (5V / 1024). For instance a value of 512 represent 512 * 5mv = 2,5V. This value can then be scalled to be between 0 and 255 (8 bits), but you loos precision.

I hope this helps,

Chelmi

Offline waltr

  • Supreme Robot
  • *****
  • Posts: 1,930
  • Helpful? 98
Re: Understanding Atmega8: ADC and Bit precision
« Reply #2 on: March 04, 2010, 01:42:53 PM »
Ok, confusion understood.

Many micro-controllers, not just the Atmega, have pins that can be digital or analog.

A digital pin can only have logic levels of 1 or 0, but these logic levels are actually a voltage on the port's pin. The voltage needs to below a certain voltage to be a legitimate logic low (0) and above  a certain voltage to be a  legitimate logic high (1). The voltages for a processor power from 5V is near 5V when high and less than about 0.4V when low.

For a port pin that is an analog input, the voltage on the pin can be anywhere within the voltage range allowed by the processor, usually between 0 and +5V (see processor data sheet for the specifics). This input pin is then connected to an ADC (Analog to Digital Converter) that produces a digital value depending on the input voltage. Common micro-controller have an ADC with 10 bits of resolution. 10 bits can express a value from 0 to 1023 or for an 8bit ADC the output value can be from 0 to 255.

The difference is the the port pin can be connected to two very different types of circuits within the processor, a digital circuit or an analog circuit.

That is the short answer to your question and hopefully enough information for you to look up the details.

Offline GophermofurTopic starter

  • Jr. Member
  • **
  • Posts: 9
  • Helpful? 0
Re: Understanding Atmega8: ADC and Bit precision
« Reply #3 on: March 05, 2010, 05:57:02 PM »
Thanks guys, you guys cleared up a lot!


 


Get Your Ad Here