EmbeddedRelated.com
Forums

Re: LPC2138 ADC problem

Started by klemen_dovrtel October 18, 2007
--- In l..., "agentkozz" wrote:
>
> --- In l..., "Leon" wrote:
> >
> > ----- Original Message -----
> > From: "klemen_dovrtel"
> > To:
> > Sent: Thursday, October 18, 2007 11:21 AM
> > Subject: [lpc2000] Re: LPC2138 ADC problem
> >
> >
> > > --- In l..., "Leon" wrote:
> > >>
> > >> ----- Original Message -----
> > >> From: "hus_kalydonios"
> > >> To:
> > >> Sent: Thursday, June 07, 2007 9:49 AM
> > >> Subject: [lpc2000] LPC2138 ADC problem
> > >>
> > >>
> > >> > Hi all,
> > >> >
> > >> > I'm trying to test the ADC on the LPC2138 (using Rowley and
> Olimex
> > >> > evaluation board), but I can't get it to work and I can't
> figure it
> > >> > out. The ADC conversion never completes and my code just
> blocks while
> > >> > waiting for the done bit to be set...
> > >> >
> > >> > Here's my code:
> > >> >
> > >> > //init
> > >> > //#define AD0CR (*((volatile unsigned long *)
> 0xE0034000))
> > >> > //#define AD0DR (*((volatile unsigned long *)
> 0xE0034004))
> > >> >
> > >> > /* ADC Chanel0 is connected to pin P0_27 */
> > >> > PINSEL1 |= mainP0_27__ADC0; //( 1 << 22 )
> > >> >
> > >> > /* ADC Settings */
> > >> > AD0CR = ( 1 << 0 ) | // SEL=1,select channel 0 on ADC0
> > >> > ( ( 14 ) << 8 ) | // CLKDIV = 60MHz / 4.5MHz
> > >> > ( 0 << 16 ) | // no BURST, software controlled
> > >> > ( 0 << 17 ) | // CLKS = 0, 11 clocks/10 bits
> > >> > ( 1 << 21 ) | // PDN = 1, normal operation
> > >> > ( 0 << 22 ) | // TEST1:0 = 00
> > >> > ( 0 << 24 ) | // START = 0 A/D conversion stops
> > >> > ( 0 << 27 ); // EDGE = 0
> > >> >
> > >> > //measure
> > >> > unsigned long AdcResult;
> > >> >
> > >> > /* ADC Conversion start */
> > >> > AD0CR |= (1 << 24);
> > >> >
> > >> > /* Delay needed when executing from flash, unknown why */
> > >> > for (i = 0; i < 32; i++)
> > >> > x++;
> > >> >
> > >> > /* Wait result */
> > >> > do
> > >> > {
> > >> > AdcResult = AD0DR;
> > >> > }while((AdcResult&0x80000000) == 0); //AdcResult is always
> 0x00!
> > >> > AdcResult = (AdcResult >> 12) & 0xF;
> > >> >
> > >> > I can't see where I've gone wrong... Please help!
> > >>
> > >>
> > >> Here is my code for the 2148:
> > >>
> > >> // initialise ADC
> > >>
> > >> PINSEL1 = 0x05000000; // P0.28 and P0.29 set for AD0.1 and
> AD0.2
> > > inputs
> > >> AD0CR = 0x00210004; // setup A/D AD0.1 input (pin 13) and
> AD0.2
> > > input
> > >> (pin 14), 11 clocks/10 bits
> > >>
> > >>
> > >> //------------------------------- read AD0.1---------------//
> > >>
> > >> short int read_AD0_1(void)
> > >> {
> > >> unsigned short int val;
> > >>
> > >> AD0CR = 0x00210002; // setup A/D AD0.1 input (P0.28, pin
> 13), 11
> > >> clocks/10 bits
> > >> AD0CR |= 0x01000000; // start conversion
> > >> while (AD0GDR == 0x8000000) // wait for DONE to go high
> > >> ;
> > >> val = AD0DR1; // get ADC data
> > >> val = ((val >>6) & 0x03FF); // extract result
> > >> return(val);
> > >> }
> > >>
> > >> I just noticed that I'm initialising AD0CR twice, but you should
> get
> > > the
> > >> idea.
> > >>
> > >> Leon
> > >>
> > >
> > >
> > > I checked the the datasheet for lpc2138 and lpc2148, and i saw
> that
> > > the ADC module in these two microcontrollers are complitely
> different.
> > > ADC in lpc2138 has much less registers than lpc2138. How could
> this
> > > LPC2148 code work on LPC2138 device then?
> >
> > I assumed that they were the same, perhaps I was wrong.
> >
> > Leon
> > The ADC in the LPC2148 is an enhanced version of the LPC2138's ADC.
> These enhancements were integrated in the newer LPC2138/01. So if
> you're using the new version, the code can be used without any
> changes.
>
I downloaded all data for lpc213x from nxp web site. There is only one
old UM10120_1 (lpc213x from June 2005) and one new (lpc2101/2102/2103
from August 2007) - i don't know what is this lpc2103 datasheet doing
here.

I saw the note about enhancements brought by LPC213x/01 devices, but
there is no datasheet for this devices. How can i check what revision
of lpc213x i have?

An Engineer's Guide to the LPC2100 Series