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.

ADC with LCD display in LPC1788

Status
Not open for further replies.

Vignesh_jay

Newbie level 3
Joined
Jun 18, 2013
Messages
3
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
43
Hello,

I am currently working with LPC1788 of NXP,in that I entered into ADC peripheral with single channel for learning purpose.

For displaying the ADC converted data I am using the following code with PCLK as 12MHZ and ADC_CLK as same 12MHZ. And using display device as 16*2 LCD.

//Main func.

int main()
{
unsigned int res;

LPC_SC->PCONP |=(1<<15); //Power up the GPIO's

LPC_SC->PCLKSEL |= (1<<3); //Adding clkdiv value with the default value in PCLKSEL

LPC_GPIO0->DIR |=(7<<4) | (1<<16);//Assigning command lines and P0.16 as o/p

LPC_GPIO2->DIR |=(0xFF<<0); //Assigning data lines as o/p

LPC_GPIO1->DIR |=(1<<14); //Assigning P1.14 as o/p

LPC_GPIO0->CLR |=(1<<16);

LPC_GPIO1->CLR |=(1<<14);

lcd_init(); //Initiating lcd

adc_init();

lcd_string("ADC IN LPC1788");

lcd_cmnd(0xc0);



while(1)
{

res= adc_read();

delay(2);

conversion(res);

}

return TRUE;
}

//adc_read func.

int adc_read()
{
unsigned int adc_result,ADC_Data;


LPC_ADC->CR &= ~(0xFF<<0); //clearing the Channel already used ADC1 in SEL bit of CR

LPC_ADC->CR |= (1 << 24) | (1 << channelNum); // switch channel using SEL,start A/D convert


while(1)
{
adc_result = LPC_ADC->DR[channelNum];

if(adc_result & ADC_DONE)
{
break;
}
}

LPC_ADC->CR &= ~(7<<24); // stop ADC now (i.e.)CR[26:24]=000

ADC_Data = ( adc_result >> 4 ) & 0xFFF; //Getting adc converted result from 4th to 15th bit of DR

return ( ADC_Data );

}

//conversion func.

conversion(unsigned int val)
{
unsigned int m,n,o,p;
m=(val/1000);
n=(val%1000)/100;
o=(val%100)/10;
p=(val%100)%10;
lcd_data(m+0x30);

lcd_data(n+0x30);

lcd_data(o+0x30);

lcd_data(p+0x30);
}

But with this above code the ADC is working properly in simulation,but failed to work in core board and ADC value is not get displaying in LCD.

Can anybody give suggestions for this..:sad:
 

It can't work in simulation also. How can it give right adc value when conversion is wrong?

Code C - [expand]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
conversion(unsigned int val)
{
unsigned int m,n,o,p;
m=(val/1000);
n=(val/100)%10;
o=(val/10)%10;
p=(val/1)%10;
lcd_data(m+0x30);
 
lcd_data(n+0x30);
 
lcd_data(o+0x30);
 
lcd_data(p+0x30);
}

 

m=(val/1000);
n=(val/100)%10;
o=(val/10)%10;
p=(val/1)%10;

Hello jayanth,

Thanks for your suggestion, but for me there is no problem with the conversion function. The thing is adc conversion is working fine with the above code in simulation, but its not working with the 1788 core board with the same setting.
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top