Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

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....









screen shoot_warning.JPGadc_design.JPG
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
6.18 System control

6.18.1 Crystal oscillator

On-chip integrated oscillator operates with external crystal in range of 1 MHz to 30 MHz
and with external oscillator up to 50 MHz. The oscillator output frequency is called fosc and
the ARM processor clock frequency is referred to as CCLK for purposes of rate equations,
etc. fosc and CCLK are the same value unless the PLL is running and connected. Refer to
Section 6.18.2 “PLL” for additional information.

6.18.2 PLL

The PLL accepts an input clock frequency in the range of 10 MHz to 25 MHz. The input
frequency is multiplied up into the range of 10 MHz to 60 MHz with a Current Controlled
Oscillator (CCO). The multiplier can be an integer value from 1 to 32 (in practice, the
multiplier value cannot be higher than 6 on this family of microcontrollers due to the upper
frequency limit of the CPU). The CCO operates in the range of 156 MHz to 320 MHz, so
there is an additional divider in the loop to keep the CCO within its frequency range while
the PLL is providing the desired output frequency. The output divider may be set to divide
by 2, 4, 8, or 16 to produce the output clock. Since the minimum output divider value is 2,
it is insured that the PLL output has a 50 % duty cycle. The PLL is turned off and
bypassed following a chip reset and may be enabled by software. The program must
configure and activate the PLL, wait for the PLL to Lock, then connect to the PLL as a
clock source. The PLL settling time is 100 s.


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

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top