Spread the love

Analog to Digital Conversion( adc )

___________________________________________________________________________________________________

  • What is ADC ? – An analog-to-digital converter (abbreviated ADC, A/D or A to D) is a device that converts a continuous physical quantity (usually voltage) to a digital number that represents the quantity’s amplitude.

 graphics1

  • How ADC work – Most real world data is in analog form. Whether it be temperature, pressure, voltage, etc, their variation is always analog in nature. So we have to convert this analog data into digital format so that computer or microcontroller can understand it and process on it. Sensor gives analog data in form of variation in current and voltage, ADC read this variation and process a digital data according to analog input and send to microcontroller to process it further.
  • Terms used in ADC
  • Resolution – The resolution of the converter indicates the number of discrete values it can produce over the range of analog values. A computer is a digital machine that stores a number in binary. If you are storing a digital 2-bit number you can store 4 different values: 00, 01, 10, or 11. Now, you can say ADC have 2-bit resolution and you have a device which converts an analog voltage between 0 and 10 volts into a 2-bit digital value for storage in a computer. This device will give digital values as follows :

Voltage

 

2-Bit Digital Representation

0 to 2.5

00

2.5 to 5

01

5 to 7.5

10

7.5 to 10

11

 

Higher the resolution smaller the step size Smaller the step size better accuracy

  • Step size – smaller amount of change in analog input that can understand

For example 8-bit ADC, step size=Vref/2^8 = Vref/256Vref – used to detect step size

  • Conversion –

Dout=Vinput/(step size) Dout – decimal output digital data Vinput – analog input voltage For example – for 8 bit ADC, Vref = 2.56 V, calculate digital output for 1.7 V input. step size=(2.56 V)/256=10 mV Dout=(1.7 V)/(10 mV)=170=10101010

  • Feature of ADC in ATmega32
  • 10bit ADC inbuilt
  • 8 analog input channel (ADC0 to ADC7 = PORTA)
  • 7 differential channel input
  • 2 different input channel with gain of 10X and 200X
  • 3 option of Vref 1). internal 2.56 V 2). AVcc (pin 30) 3). AREFF (pin 32)

 

2_19_6_1_eng

  • Applications– used to read analog input data from sensor in our application.

Click Here : Program point of view understanding of ADC

 

 1. CIRCUIT  DIAGRAM OF ADC OF ATMEGA16

CIRCUIT  DIAGRAM OF ADC OF ATMEGA16

 

________________________________________________________________________________________________

1. Program of ADC (Analog to Digital Converter)     Of  ATmega16 

In this program ADC data is appeared on the LCD connected to the controller

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- ADC DATA OF VARIABLE RESISTANCE IS DISPLAYED ON LCD USING ATMEGA16
******************************************************/

#include<avr/io.h>

#include<util/delay.h>

#include<stdlib.h>

#include "lcd.h"

int adc_re();
int lcd_pos(int x,int y);

unsigned int rec;

void main()
  {
      unsigned char a[5];
      DDRA=0X00;
      DDRB=0XFF;
      DDRC=0XFF;
      lcd_ini();
      ADCSRA=0XCC;
      lcd_str("VALUE OF ADC IS");
      while(1)
        { 
           adc_re();
           sprintf(a,"%d",rec);
           lcd_pos(1,0);
           lcd_str("    ");
           lcd_pos(1,0);
           lcd_str(a);
           _delay_ms(300);
 
       }
  }

int adc_re()
   {
       DDRA=0x00;//make channel 0 as input....
       ADMUX=0X40;
       ADCSRA|=(1<<ADSC);
       while((ADCSRA & (1<<4)==0));
       rec=ADC;
       ADCSRA|=(0<<ADSC);
       return rec;
   }



int lcd_pos(int x,int y)
   {
      if(x==0)
         cmd(0x80+y);
      else if(x==1)
         cmd(0xc0+y);
   }

LCD.H HEADER FILE

/* LCD.H HEADER FILE USED IN ABOVE PROGRAM*/

#define lcd PORTC

void cmd(unsigned char x)
  {
    lcd=x;
    PORTB &=~(1<<0);
    PORTB &=~(1<<1);
    PORTB |=(1<<2);
    _delay_ms(1);
    PORTB &=~(1<<2);
  }

void lcd_display(unsigned char x)
  {
     lcd=x;
     PORTB |=(1<<0);
     PORTB &=~(1<<1);
     PORTB |=(1<<2);
     _delay_ms(1);
     PORTB &=~(1<<2);
  }

void lcd_ini()
   {
      cmd(0x38);
      cmd(0x0e);
      cmd(0x01);
      cmd(0x06);
      cmd(0x80);
   }

void lcd_str(unsigned char *str)
   {
      while(*str!='\0')
        {
            lcd_display(*str);
            str++;
        }
   }

PROTEUS File for SIMULATION(Password Of RAR file is :-firmcodes.com)

download (1) _______________________________________________________________________________________________________

 

Content for the tab VIDEO