go_away

Author Topic: Analog Input Atmega48  (Read 1854 times)

0 Members and 1 Guest are viewing this topic.

Offline robokiTopic starter

  • Beginner
  • *
  • Posts: 5
  • Helpful? 0
Analog Input Atmega48
« on: May 10, 2008, 08:01:01 PM »
Hi...
I am a novice student, who's just gotten use to using digital I/O for Atmega MCU series.
I am using Atmega48, and I can use basic digital sensors (Ultrasonic,touch).
I have a pretty strong background in programming, but I am new to hardware stuff.
So here is my question...
I know that Atmega48 has A/D input pins. If I want to use analog sensors (IRsharp), do I have to get an external A/D converter?
From the 50$ robot code, it seems like you connect the sensor directly to the MCU...
Does this mean the MCU is able to read analog data?
Also, how can a MCU "read" analog data with just one pin?
From the source code,
"IR_value = analogRead(0);//use pin 0 for analog"
If I type this, does it read analog value from the sensor?
From my understandings, analogRead () is not a command known in C language...o.O
Can someone explain to me the logic behind A/D in MCU?
« Last Edit: May 10, 2008, 08:35:32 PM by roboki »

Offline izua

  • Supreme Robot
  • *****
  • Posts: 682
  • Helpful? 0
Re: Analog Input Atmega48
« Reply #1 on: May 10, 2008, 10:59:21 PM »
well, it's not a standard function. you'll have to include a library. C doesn't have any functions by itself.
the MCU is able to read analog data with one pin, or more (if required).

The A/D is a simple hardware. A sample-and-hold capacitor charges (to be able to sample the right signal, for instance, or to integrate fast pwm signals). Comparing the cap value is done in a lot of ways nowdays, the most common beeing a succesive aproximation. A comparator "iterates" through a range of voltages, fed by a DAC read from the previous value.
Check out my homepage for in depth tutorials on microcontrollers and electronics.

Offline superchiku

  • Supreme Robot
  • *****
  • Posts: 953
  • Helpful? 5
  • cooll
Re: Analog Input Atmega48
« Reply #2 on: May 11, 2008, 12:48:16 AM »
there are mainly two types of ADC THEY ARE COUNTER TYPE AND REGISTER TYPE, I WOULDNT GO INTO THE DETAILS ABT IT..

AN ADC is a analog signal to a digital signal converter it basically takes a known or unknown voltage and converts into its equivalent digital value i.e in plain numbers according to the reference volrage given . LIKE ur reference voltage is 5v then an analog input of 5v will read as 255 if it is an 8 bit adc . similarly what would be 4v it would be (4/5)*255 ==== 204 so you can calculate accordingly .

Now in ur atmega ull find many pins which take and analog input and convert them to its digital output if there are 7 analog input pins then you can connect 7 analog voltages and can use their digital values but in ur programming each conversion has to be done one by one, you select each pin get the digital value of the analog voltage inputed to that pin store it or use it somewhere and move on to the next pin...

Hope this clears ur doubt
JAYDEEP ...

IT AND ROBOTICS ENGINEER

"IN THE END IT DOESNT EVEN MATTER"

Offline Admin

  • Administrator
  • Supreme Robot
  • *****
  • Posts: 11,632
  • Helpful? 169
    • Society of Robots
Re: Analog Input Atmega48
« Reply #3 on: May 23, 2008, 09:31:05 PM »
I used the adc.c and adc.h functions in AVRlib when I programmed the $50 Robot, which is where those functions came from.

If you use my code (modified easily for the ATmega48), it will work as you say.

 


Get Your Ad Here

data_list