Problem in adc while programing in lpc21xx

Status
Not open for further replies.

bondkicha

Newbie level 4
Joined
Jul 22, 2010
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
india
Activity points
1,316
I am attaching my code for adc conversion and its proteus design . the code is not working....










Code:
#include <lpc213x.h>
#include "usart0.c"

int main()
{
	unsigned int data;
	usart0_init();
	usart0_char('a');
	PINSEL1 |= 0X01000000;			//SET THE FUNCTION FOR PORT PIN AS ADC FOR ADC0.1
	AD0CR = 0X00000002;				//SELECT ADC0.1 CHANNEL
	AD0CR |= 0X00000200;				//SELECT THE CLKDIV(division factor) AS 2 i.e, 12/(2+1) = 4MHz
	AD0CR |= (~(1<<16));				//SET BURST AS 0
	AD0CR |= 0X00000000;				//NO. OF CLOCKS = 11 (CLKS = 000)
	AD0CR |= (1<<21);						//SET A/D IN OPERATIONAL MODE (PDN = 1)
	
	
	while(1)
	{
		AD0CR |= (1<<24);
		//ADGSR |= (1<<24);
		while(!(AD0DR1 & 0x80000000));
		data = AD0DR1 & 0X0000FFC0;
		data = data>>6;
		usart0_char(data);
		//AD0CR |= (~(1<<24));
		//ADGSR |= (~(1<<24));
	}
}

Code:
#define Fosc            12000000                    
#define Fcclk           (Fosc * 5)                  
#define Fcco            (Fcclk * 4)                 
#define Fpclk           (Fcclk / 4) * 1             

#define  UART_BPS	9600	

//void UART0_RXC() __irq;

void usart0_init()
{
	//unsigned char temp;
	unsigned int Baud16;
	PINSEL0 = 0X05;			// selecting P0.0 & P0.1 for usart0 function
	U0FCR = 7;								// clear FIFO, transmit & recieve enable
	U0LCR = 0X83;							//DLAB = 1, stopbits =1, data length = 8bit
	Baud16 = (Fpclk / 16) / UART_BPS;  
  U0DLM = Baud16 / 256;							
  U0DLL = Baud16 % 256;							
	U0LCR = 0X03;							// clearing DLAB bit
// 	U0IER = 0x0001;
// 	dummy = U0IIR;
// 	VICIntSelect=0x00000000;
// 	VICIntEnable=0x00000040;
// 	VICVectCntl0=0x20|6;
// 	VICVectAddr0=(unsigned long) UART0_RXC;
}


void usart0_string(unsigned char *data)
{
 	while(*data)							// transmit only
	{
		U0THR = *data;
		while(!(U0LSR & 0X20));
		data++;
	}
}	



// 	{
// 		while (!(U0LSR & 0x01)); //receive and transmit
// 		temp = U0RBR;

void usart0_char(unsigned char temp)
{
 		U0THR = temp;
 		while(!(U0LSR & 0X20));	
}

// void UART0_RXC() __irq
// {
// 		unsigned char temp;	
// 		U0IER = 0x0000;
// 		temp = U0RBR;
// 		U0THR = temp;
// 		while(!(U0LSR & 0X20));
// 		U0IER = 0x0001;
// 		VICVectAddr = 0;
// }
 

First check your clock settings whether you have choosen internal oscillator as clock source or external crystal. If external, attach a crystal with capacitors at XTAL1 &XTAL2 pins.
 

As KSHATRIYA mentioned, you are dead in the water without configuring a clock source:

Reference: , Section: 6.18 System control


You first need to download the devices datasheet and study the relevant sections concerning proper configuration of the devices system clock.







BigDog
 

In proteus the crystal is not modeled, there is a property when you open the mcu properties where you can set the crystal clock frequency.
 

clock freq is 12 MHz in my mcu properties... is that ok
 

Status
Not open for further replies.

Similar threads

Cookies are required to use this site. You must accept them to continue using the site. Learn more…