/* Setup ADC for 12-bit mode and normal power */ Chip_ADC_Init(LPC_ADC, 0);
/* Need to do a calibration after initialization and trim */ Chip_ADC_StartCalibration(LPC_ADC); while (!(Chip_ADC_IsCalibrationDone(LPC_ADC))) {}
/* Setup for maximum ADC clock rate using sycnchronous clocking */ Chip_ADC_SetClockRate(LPC_ADC, ADC_MAX_SAMPLE_RATE);
/* Optionally, you can setup the ADC to use asycnchronous clocking mode. To enable this, mode use 'LPC_ADC->CTRL |= ADC_CR_ASYNMODE;'. In asycnchronous clocking mode mode, the following functions are used to set and determine ADC rates: Chip_Clock_SetADCASYNCSource(); Chip_Clock_SetADCASYNCClockDiv(); Chip_Clock_GetADCASYNCRate(); clkRate = Chip_Clock_GetADCASYNCRate() / Chip_Clock_GetADCASYNCClockDiv; */
/* Setup sequencer A for ADC channel 0, EOS interrupt */ //#if defined(BOARD_NXP_LPCXPRESSO_824) /* Setup a sequencer to do the following: Perform ADC conversion of ADC channels 0 only */ Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQA_IDX, (ADC_SEQ_CTRL_CHANSEL(3) | ADC_SEQ_CTRL_CHANSEL(9) | ADC_SEQ_CTRL_CHANSEL(10) | ADC_SEQ_CTRL_MODE_EOS));
/* Enable the clock to the Switch Matrix */ Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
/* Configure the SWM for P0-23 as the input for the ADC3 */ Chip_SWM_EnableFixedPin(SWM_FIXED_ADC3); /* Configure the SWM for P0-17 as the input for the ADC9 */ Chip_SWM_EnableFixedPin(SWM_FIXED_ADC9); /* Configure the SWM for P0-13 as the input for the ADC10 */ Chip_SWM_EnableFixedPin(SWM_FIXED_ADC10);
/* Disable the clock to the Switch Matrix to save power */ //Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM); //#else //#warning "No ADC setup for this example" //#endif
/* Setup threshold 0 low and high values to about 25% and 75% of max */ Chip_ADC_SetThrLowValue(LPC_ADC, 0, ((1 * 0xFFF) / 4)); Chip_ADC_SetThrHighValue(LPC_ADC, 0, ((3 * 0xFFF) / 4));
/* Clear all pending interrupts */ Chip_ADC_ClearFlags(LPC_ADC, Chip_ADC_GetFlags(LPC_ADC));
/* Enable ADC overrun and sequence A completion interrupts */ Chip_ADC_EnableInt(LPC_ADC, (ADC_INTEN_SEQA_ENABLE | ADC_INTEN_OVRRUN_ENABLE));
/* Use threshold 0 for ADC channel and enable threshold interrupt mode for channel as crossing */ Chip_ADC_SelectTH0Channels(LPC_ADC, ADC_THRSEL_CHAN_SEL_THR1(BOARD_ADC_CH)); Chip_ADC_SetThresholdInt(LPC_ADC, BOARD_ADC_CH, ADC_INTEN_THCMP_CROSSING);
Content originally posted in LPCWare by krishna.mohan on Mon Oct 19 01:39:02 MST 2015 I've downloaded sample Project from https://www.lpcware.com/content/nxpfile/lpcopen-software-development-platform-lpc8xx-packages Build the periph_adc project in LPC Xpresso IDE. and tried to debug project though LPC-LINK2 debugger. it was prompting error window all the time even after restarting the LPC Xpresso.