Author Topic: How does the a2dConvert8bit function work?  (Read 2222 times)

0 Members and 1 Guest are viewing this topic.

Offline malexTopic starter

  • Jr. Member
  • **
  • Posts: 14
  • Helpful? 0
How does the a2dConvert8bit function work?
« 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.

Offline bens

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 332
  • Helpful? 3
Re: How does the a2dConvert8bit function work?
« Reply #1 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

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: How does the a2dConvert8bit function work?
« Reply #2 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.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline Razor Concepts

  • Supreme Robot
  • *****
  • Posts: 1,856
  • Helpful? 53
Re: How does the a2dConvert8bit function work?
« Reply #3 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?

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,659
  • Helpful? 169
    • Society of Robots
Re: How does the a2dConvert8bit function work?
« Reply #4 on: January 22, 2009, 09:36:37 PM »
The equation is:

8_bit_value/255=voltage/AREF

 


Get Your Ad Here