Hi,
Concerning a LPC51U68 and his ADC.
From McuXpresso i use the configurator
that give me in peripherals.c
const adc_config_t ADC0configStruct = {
.clockMode = kADC_ClockSynchronousMode,
.clockDividerNumber = 8,
.resolution = kADC_Resolution12bit,
.sampleTimeNumber = 7,
.enableBypassCalibration = false
};
/* Conversion sequence A configuration structure */
const adc_conv_seq_config_t ADC0ConvSeqAConfigStruct = {
.channelMask = 1024U,
.triggerMask = 0U,
.triggerPolarity = kADC_TriggerPolarityPositiveEdge,
.enableSyncBypass = false,
.enableSingleStep = false,
.interruptMode = kADC_InterruptForEachConversion
};
void ADC0_init(void) {
/* Perform self calibration */
ADC_DoOffsetCalibration(ADC0_PERIPHERAL, ADC0_CLK_FREQ);
/* Initialize ADC0 peripheral */
ADC_Init(ADC0_PERIPHERAL, &ADC0configStruct);
/* Configure the conversion sequence A */
ADC_SetConvSeqAConfig(ADC0_PERIPHERAL, &ADC0ConvSeqAConfigStruct);
/* Enable the conversion sequence A */
ADC_EnableConvSeqA(ADC0_PERIPHERAL, true);
/* Configure threshold compare interrupt on channel 10 */
ADC_EnableThresholdCompareInterrupt(ADC0_PERIPHERAL, 10U, kADC_ThresholdInterruptDisabled);
}
that is called at the very beginning
in the forever loop i use
POWER_DisablePD(kPDRUNCFG_PD_VREFP_SW);
POWER_DisablePD(kPDRUNCFG_PD_VD7_ENA);
POWER_DisablePD(kPDRUNCFG_PD_ADC0);
IOCON->PIO[1][7] = ((IOCON->PIO[1][7] & (~(IOCON_PIO_FUNC_MASK | IOCON_PIO_MODE_MASK | IOCON_PIO_DIGIMODE_MASK))) /* Mask bits to zero which are setting */
| IOCON_PIO_FUNC(PIO17_FUNC_ALT0) /* Selects pin function.: PORT17 (pin 21) is configured as ADC0_10 */
| IOCON_PIO_MODE(PIO17_MODE_INACTIVE) /* Selects function mode (on-chip pull-up/pull-down resistor control).: Inactive. Inactive (no pull-down/pull-up resistor enabled). */
| IOCON_PIO_DIGIMODE(PIO17_DIGIMODE_ANALOG) /* Select Analog/Digital mode.: Analog mode. */
);
ADC_DoSoftwareTriggerConvSeqA(ADC0_PERIPHERAL);
sysTickDelay(200);
ADC_GetChannelConversionResult(ADC0_PERIPHERAL, 10, &adcResultInfoStruct);
uiVAlim = ((uiVAlim * 2.0) + adcResultInfoStruct.result) / 3.0;
IOCON->PIO[1][7] = ((IOCON->PIO[1][7] & (~(IOCON_PIO_FUNC_MASK | IOCON_PIO_MODE_MASK | IOCON_PIO_DIGIMODE_MASK))) /* Mask bits to zero which are setting */
| IOCON_PIO_FUNC(PIO17_FUNC_ALT0) /* Selects pin function.: PORT17 (pin 21) is configured as ADC0_10 */
| IOCON_PIO_MODE(PIO17_MODE_INACTIVE) /* Selects function mode (on-chip pull-up/pull-down resistor control).: Inactive. Inactive (no pull-down/pull-up resistor enabled). */
| IOCON_PIO_DIGIMODE(PIO18_DIGIMODE_DIGITAL) /* Select Analog/Digital mode.: Analog mode. */
);
POWER_EnablePD(kPDRUNCFG_PD_VREFP_SW);
POWER_EnablePD(kPDRUNCFG_PD_VD7_ENA);
POWER_EnablePD(kPDRUNCFG_PD_ADC0);
(use the errata datasheet recommandation to switch back to a digital , the adc input)
The clock used is the RTC with the PLL to get 9.3MHz
Every thing else doing pretty fine, it is a barometer with logger and i wish to use the ADC to surveil the battery power.