Society of Robots - Robot Forum

Software => Software => Topic started by: malex on June 20, 2008, 01:01:36 PM

Title: How does the a2dConvert8bit function work?
Post by: malex on June 20, 2008, 01:01:36 PM
I'm trying to dissect the code for the 50$ robot and I'm not sure how exactly does a2dConvert8bit work.  Eg a2dConvert8bit(5)

Judging from the name, I suppose it means analog to digital converted with 8 bits.  This returned an 8 bit integer right?

From using my voltmeter I can observe the voltage change at the analog pin on the microcontroller and it basically drops from about 5 volts (when bright) to .5 volts(when dark)

My questions are:
How does the voltage relate to the digital value returned by the function?  Is higher voltage = higher integer?

Also, what does the 5 in a2dConvert8bit(5) supposed to mean?

Thank you in advance.
Title: Re: How does the a2dConvert8bit function work?
Post by: bens on June 20, 2008, 01:24:53 PM
The ADC returns 255 when the input voltage is AREF and 0 when it is 0 V.  Usually AREF is Vcc (your logic voltage), which is usually 5 V.  The conversion value varies linearly with voltage.  The 5 in a2dConvert8Bit(5) is probably the ADC channel on which to perform the conversion (there are multiple ADC channels, each corresponding to an analog input pin, but only one converter).

- Ben
Title: Re: How does the a2dConvert8bit function work?
Post by: izua on June 20, 2008, 03:46:28 PM
it depends on how you make the sensor. if the transistor is the higher side resistance, you'll get + when it's open (hit by light).
if it is the lower side (ground connected) resistance, when it will open, you'll get ground (0 V). In theory at least.

The function calls the Atmega's onboard ADC. This device transforms the analog voltage into a digital value which is then returned to your function, which in turn, does something with it.
Title: Re: How does the a2dConvert8bit function work?
Post by: Razor Concepts on January 22, 2009, 09:20:29 PM
Digging up old thread -

So say AREF is at 5v and the input voltage is at 2.5, the ADC should return a 128 since it's linear?
Title: Re: How does the a2dConvert8bit function work?
Post by: Admin on January 22, 2009, 09:36:37 PM
The equation is:

8_bit_value/255=voltage/AREF