www.eXtremeElectronics.co.in

Analog To Digital Converter

AVR ATmega8 Bases Line Follower.

Easy to make PID LFR Robot.

Most of the physical quantities around us are continuous. By continuous we mean that the quantity can take any value between two extreme. For example the atmospheric temperature can take any value (within certain range). If an electrical quantity is made to vary directly in proportion to this value (temperature etc) then what we have is Analogue signal. Now we have we have brought a physical quantity into electrical domain. The electrical quantity in most case is voltage. To bring this quantity into digital domain we have to convert this into digital form. For this a ADC or analog to digital converter is needed. Most modern MCU including AVRs has an ADC on chip. An ADC converts an input voltage into a number. An ADC has a resolution. A 10 Bit ADC has a range of 0-1023. (2^10=1024) The ADC also has a Reference voltage(ARef). When input voltage is GND the output is 0 and when input voltage is equal to ARef the output is 1023. So the input range is 0-ARef and digital output is 0-1023.

ADC Theory

Fig.1 - ADC Theory

 

Inbuilt ADC of AVR

Now you know the basics of ADC let us see how we can use the inbuilt ADC of AVR MCU. The ADC is multiplexed with PORTC that means the ADC channels are shared with PORTC. The ADC can be operated in single conversion and free running more. In single conversion mode the ADC does the conversion and then stop. While in free it is continuously converting. It does a conversion and then start next conversion immediately after that.

ADC Library.

To Easily use the AVR's ADC you can use our ADC Library. The library comes in two files :-

You can get these files from the lib folder in the DVD.

To use the ADC Library do the following :-

  1. Create a new folder lib in the project using Solution Explorer.
  2. Create a new sub folder adc inside the lib folder.
  3. Using Windows File Manager copy/paste the adc.c and adc.h files to your <project folder>/lib/adc/ from the DVD.
  4. Add both files to your projects under lib/adc.
  5. Now you are ready to use the library!

Using the ADC Library.

Our ADC library is very simple to use and has only two functions.

void InitADC(void)

This function initializes the ADC of the AVR, this must be called before the adc 
can be read.

Arguments:
NONE

Returns:
NONE



uint16_t ReadADC(uint8_t ch)

This function reads the adc channel referred by ch, and returns a value between 0-1023.

Arguments:
	Name: ch
	Type: uint8_t (8 bit unsigned integer)
	Range: 0-5

Returns:
	Type: uint16_t (16 bit unsigned integer)
	Range: 0-1023

Return to Help Index.