LPC51U68 ADC Config Problems

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

LPC51U68 ADC Config Problems

1,810 Views
jplathuile
Contributor III

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.

Labels (1)
0 Kudos
Reply
3 Replies

1,748 Views
jplathuile
Contributor III

Hi,

Problem come from the initialisation sequence in the Mcuxpresso config tool
the adc is not powered automatically nor the clock connected.

static void ADC_ClockPower_Configuration(void) {
POWER_DisablePD(kPDRUNCFG_PD_ADC0); /* Power on the ADC converter. */
POWER_DisablePD(kPDRUNCFG_PD_VD7_ENA); /* Power on the analog power supply. */
POWER_DisablePD(kPDRUNCFG_PD_VREFP_SW); /* Power on the reference voltage source. */
POWER_DisablePD(kPDRUNCFG_PD_TEMPS); /* Power on the temperature sensor. */

CLOCK_EnableClock(kCLOCK_Adc0); /* SYSCON->AHBCLKCTRL[0] |= SYSCON_AHBCLKCTRL_ADC0_MASK; */

const adc_config_t ADC0configStruct = {
.clockMode = kADC_ClockSynchronousMode,
.clockDividerNumber = 0,
.resolution = kADC_Resolution12bit,
.sampleTimeNumber = 0,
.enableBypassCalibration = false
};
/* Conversion sequence A configuration structure */
const adc_conv_seq_config_t ADC0ConvSeqAConfigStruct = {
.channelMask = 2048U,
.triggerMask = 0U,
.triggerPolarity = kADC_TriggerPolarityNegativeEdge,
.enableSyncBypass = false,
.enableSingleStep = false,
.interruptMode = kADC_InterruptForEachConversion
};


/* Perform self calibration */
ADC_DoOffsetCalibration(ADC0, 12000000U);
/* Initialize ADC0 peripheral */
ADC_Init(ADC0, &ADC0configStruct);
/* Configure the conversion sequence A */
ADC_SetConvSeqAConfig(ADC0, &ADC0ConvSeqAConfigStruct);
/* Enable the conversion sequence A */
ADC_EnableConvSeqA(ADC0, true);
}

Called after

BOARD_InitBootPins();
BOARD_InitBootClocks();

BOARD_InitBootPeripherals();
ADC_ClockPower_Configuration();


Regards

JP

0 Kudos
Reply

1,748 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Jean,

Thanks for your sharing, if still have problem, recommend you also can compare your code with ADC demo

under SDK.

Regards,

Alice

0 Kudos
Reply

1,748 Views
jplathuile
Contributor III

Hi,

Yes my solution come mainly from the demo code, the code from the config tool do no function.
This is for measuring the battery tension.
As those microcontroller will be more and more used under battery power, it will be nice if that facility were integrated on silicium.

Regards

JP

0 Kudos
Reply