EmbeddedRelated.com
Forums

Re: Multiple ADCs on LPC 2148

Started by Leon Heller January 19, 2010
On 18/01/2010 13:52, ucartist wrote:
> Hi
>
> I am using LPC2148 R2T board and IAR EWARM
>
> I have been trying to use multiple ADC channels than the default channel ad0.3. The sample code for the adc in IAR embedded work bench checks the result in the AD0DR and uses burst mode. I have tried to read more channels by polling method with a function that takes channel number as described in the nxp technical note TN06004 but it doesn't work.
>
> Does anyone else experience the same problem?
This is a function I use to read an LPC2148 ADC channel:

//-------------------------- getAnalogueInput_AD0 function ---------------//

unsigned short int getAnalogueInput_AD0(unsigned char channel)
{
unsigned short int val;

//start conversion (for selected channel)
AD0CR = (AD0CR & 0xFFFFFF00) | (1 << channel) | (1 << 24);

//wait until done
while((AD0GDR & 0x80000000) == 0)
;

// get ADC data
val = ((AD0GDR & 0x0000FFC0)) >> 6;
return(val);
}

Here is the initialisation code:

// initialise ADC

PINSEL0 = PINSEL0 | 0x00003C00; // P0.5, P0.6 setup for AD0.7, AD1.0
inputs
// bits 13:12 11:10
// 11 11
PINSEL1 = 0x15000000; // P0.28, P0.29, P0.30 set for AD0.1, AD0.2,
AD0.3 inputs
// bits 25:24 27:26 30:29
// 01 01 01
AD0CR = 0x00200604; // enable ADC, 11 clocks/10 bits, ADC clock 4.286 MHz
AD1CR = 0x00208001;

Leon

An Engineer's Guide to the LPC2100 Series