___________________________________________________________________________________________________
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 For example 8-bit ADC, step size=Vref/2^8 = Vref/256Vref – used to detect step size 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 ________________________________________________________________________________________________ LCD.H HEADER FILE _______________________________________________________________________________________________________ Content for the tab VIDEO
Click Here : Program point of view understanding of ADC
1. 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 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)