Reply by klemen_dovrtel October 18, 20072007-10-18
--- 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 is complitely different.
ADC in lpc2138 has much less registers than ADC in lpc2148. How could
this LPC2148 code work on LPC2138 device then?

An Engineer's Guide to the LPC2100 Series

Reply by Leon June 7, 20072007-06-07
----- Original Message -----
From: "hus_kalydonios"
To:
Sent: Thursday, June 07, 2007 10:58 AM
Subject: [lpc2000] Re: LPC2138 ADC problem
> Thanks for that Leon, that helps. I've got it working now.
>
> Shame that the ADC is only 10bits though!

Glad it's working. I filched some of that code from somewhere.

Leon
--
Leon Heller
Amateur radio call-sign G1HSM
Yaesu FT-817ND transceiver
Suzuki SV1000S motorcycle
l...@btinternet.com
http://webspace.webring.com/people/jl/leon_heller/
Reply by hus_kalydonios June 7, 20072007-06-07
Thanks for that Leon, that helps. I've got it working now.

Shame that the ADC is only 10bits though!
Reply by Leon June 7, 20072007-06-07
----- 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
Reply by hus_kalydonios June 7, 20072007-06-07
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!

Thanks.