Spread the love

ADC of ARM7 ( LPC2148 )

___________________________________________________________________________________________________


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 – small amount of change in analog input that can understand
    for example 8-bit ADC, step size=Vref/2^8 = Vref/256
    Vref – 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 ARM7 (LPC2148)

 IRCUIT IAGRAM OF ADC OF ARM7 (LPC2148)

________________________________________________________________________________________________

1. Program Of ADC Of  ARM7 (LPC2148) 

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

/******************************************************
www.firmcodes.com
DEVELOPED BY:- FIRMWARE DEVELOPER
WHAT PROGRAM DO:- TEMPERATURE OF LM35 IS DISPLAYED ON LCD CONNECTED WITH ARM7(LPC21XX)
******************************************************/

#include<lpc213x.h>

#define LCD (0xff<<16)
#define RS (1<<13)
#define RW (1<<14)
#define EN (1<<15)

void delay_fv(unsigned int x,int y);

void lcd_display(unsigned int x);
void cmd(unsigned char m);
void lcd_ini();
void lcd_pos(int line, int pos);
void lcd_str(unsigned char *x);

void pll();

void adc_ini();
unsigned long int adc_data();

int main()
  {
		unsigned long temp;
		unsigned char first,second,third,fourth,fifth;
		PINSEL0=0X00000000;
		IO0DIR=0XFFFFFFFF;
		pll();
		adc_ini();
		lcd_ini();
		lcd_str("TEMP VALUE IS");
		lcd_pos(2,6);
		lcd_display('C');
		while(1)
	    {
					temp=adc_data();
					temp=temp*3300;
					temp=temp/1023;
					first=temp%10+'0';
					temp=temp/10;
					second=temp%10+'0';
					temp=temp/10;
					third=temp%10+'0';
					temp=temp/10;
					fourth=temp%10+'0';
					temp=temp/10;
					lcd_pos(2,0);
					lcd_display(fourth);
					lcd_display(third);
					lcd_display(second);
					lcd_display('.');
					lcd_display(first);
		
	    }
  }

void delay_fv(unsigned int x,int y)
  {
			 unsigned int i,j;
			 for(i=0;i<x;i++)
			 for(j=0;j<y;j++);
  }
void lcd_display(unsigned int x)
   {
			 IO0CLR|=(RS|RW|EN|LCD);
			 IO0SET|=(x<<16);
			 IO0SET|=RS;
			 IO0CLR|=RW;
			 IO0SET|=EN;
			 delay_fv(100,200);
			 IO0CLR|=EN;
			 delay_fv(10,10);
   }

void cmd(unsigned char m)
   {
			 IO0CLR|=(RS|RW|EN|LCD);
			 IO0SET|=(m<<16);
			 IO0CLR|=RS;
			 IO0CLR|=RW;
			 IO0SET|=EN;
			 delay_fv(100,10);
			 IO0CLR|=EN;
			 delay_fv(100,10);
   }

void lcd_ini()
  {
			cmd(0X38);
			cmd(0X0e);
			cmd(0X06);
			cmd(0X01);
			cmd(0X80);
  }
	
void lcd_pos(int line, int pos)
  {
	    if(line==1)
		     cmd(0x80+pos);
	    else if(line==2)
		     cmd(0xc0+pos);
  }
	
void lcd_str(unsigned char *x)
  {
	    while(*x!='\0')
	      {
		        lcd_display(*x);
		        x++;
	      }
  }
	
void pll()
  {
  		/*PLL IS CONFIGURED TO GET 60HZ pCLK*/
			PLLCFG=0X24;		 // SET PSEL=2 AND MSEL=5
			PLLCON=0X01;		 //PLL IS ACTIVE BUT NOT YET CONNECT
			PLLFEED=0XAA;		 //FEED SEQUENCE
			PLLFEED=0X55;		 //FEED SEQUENCE
			while((PLLSTAT & 0X400)==0);   //WAIT FOR FEED SEQUENCE TO BE INSERTED
			PLLCON=0X03;		 // PLL HAS BEEN ACTIVE AND BEING CONNECTRD
			VPBDIV=0X00;		 // SET PCLK 1/4th of FCCLK
			PLLFEED=0XAA;		 //FEED SEQUENCE
			PLLFEED=0X55;		 //FEED SEQUENCE
  }
	
void adc_ini()
  {
		AD0CR = 1<<21;	 //A/D is Operational
		AD0CR = 0<<21;	 //A/D is in Power Down Mode
		PINSEL1 = 0x01000000;//P0.28 is Configured as Analog to Digital Converter Pin AD0.1
		AD0CR = 0x00200802;  //CLKDIV=4,Channel-0.1 Selected,BURST=0,EDGE=0
		/*PDN=0
		A/D Clock = PCLK /(CLKDIV+1);*/
	
  }
	
unsigned long int adc_data()
   {
	      unsigned long rec;	
				AD0CR |= (1<<24);							//Start Conversion
				while(!(AD0GDR & 0x80000000));
				/*Wait untill the DONE bits Sets*/
				rec = AD0GDR;
				AD0CR &= ~0x01000000;	//Stops the A/D Conversion   				
				rec = rec >> 6;  // data is present after 6 bit
				rec = rec & 0x3FF;    //Clearing all other Bits
			  return (rec);
   }

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

download (1)

_______________________________________________________________________________________________________

 

Content for the tab VIDEO