How do i make a simple AD conversion with the LPC822?

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on Jun 18, 2016 by lpcware
Content originally posted in LPCWare by ledi007 on Wed Apr 13 02:32:32 MST 2016

i am a newbie to programm the nxp controller and i am struggling with the ADC.

What i want to do is a simple AD conversion (e.g. every 100ms) on ADC_2 (PIO0_14) in the while loop.
I dont want to use the LPCOPEN libraries!

In the LPC82x user manual is this described as:
"To perform a single ADC conversion for ADC0 channel 1 using the analog signal on pin ADC_1, follow these steps":

1. Enable the analog function ADC_1.
2. Configure the system clock to be 25 MHz and select a CLKDIV value of 0 for a sampling rate of 1 Msamples/s using the ADC CTRL register.
3. Select ADC channel 1 to perform the conversion by setting the CHANNELS bits to 0x2 in the SEQA_CTL register.
4. Set the TRIGPOL bit to 1 and the SEQA_ENA bit to 1 in the SEQA_CTRL register.
5. Set the START bit to 1 in the SEQA_CTRL register.
6. Read the RESULT bits in the DAT1 register for the conversion result.

What i have right now is that code:

int main(void)
    SystemCoreClockUpdate();// Read clock settings and update SystemCoreClock variable

    LPC_SYSCON->PDRUNCFG &= ~(1<<4);//power the ADC
    LPC_SYSCON->SYSAHBCLKCTRL   |= (1<<24);    //enable clock for ADC

    /* Need to do a calibration after initialization and trim */
    while (!(Chip_ADC_IsCalibrationDone(LPC_ADC))) {}


    LPC_IOCON->PIO0[IOCON_PIO14] |= (1<<1);//set to ADC mode for pin PIO0_14 (ADC_2)
    LPC_ADC->SEQ_CTRL[ADC_SEQA_IDX] |= 0x4;//Select ADC CH2 (Bit 3) to perform the conversion  in the SEQA_CTL register.

    return 0 ;

Can somebody help me, whith the next steps?
Can somebode post an simple example?