lpcware

ADC of LPC824 pulling up voltage divider

Discussion created by lpcware Employee on Jun 15, 2016
Latest reply on May 1, 2018 by Ian Benton
Content originally posted in LPCWare by svensteudte on Sun Oct 18 03:19:21 MST 2015
Hi,

I'm running a cumstom PCB at 2.5V with a LPC824M201JHI33E from which I want to measure the battery (LiPo) voltage with the ADCs. Because the microcontroller runs at 2.5V, the ADC is connected not directly to the VBAT but to a voltage divider having 2x 10k resistors. Vcc is connected to VREFP and VREFN to GND.

But somehow all my readings are higher than expected. So I've measured the voltage directly at the ADC pin and I was astonished. The ADC-reading has been right. But it seems to me, the LPC824 is pulling the ADC up causing a misreading about 0.15V (roughly). Following example: My VBAT is 3.63V. So the ADC actually should have 1.815V (3.63V / 2 due to voltage divider). But the actual ADC reading was 1.94V which was confirmed by my multimeter.

I've checked if the internal resistors were switched off in the IOCON. Pullup and Pulldown have been disabled. Is there something  I'm doing wrong? A code snippet is attached:


#define ADC_BATT_CH11
#define ADC_BATT_PINSWM_FIXED_ADC11
#define REF_MV2500

uint32_t getBatteryMV(void)
{
uint32_t adc = getADC(ADC_BATT_CH);
return (adc * REF_MV) >> 11;// Return battery voltage (voltage divider factor included)
}

uint32_t getADC(uint8_t ad)
{
// Start ADC conversion
Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQA_IDX, ADC_SEQ_CTRL_CHANSEL(ad) | ADC_SEQ_CTRL_MODE_EOS | ADC_SEQ_CTRL_HWTRIG_POLPOS);
Chip_ADC_EnableSequencer(LPC_ADC, ADC_SEQA_IDX);

uint32_t i = 0;
uint32_t gdat = 0;
while((gdat & (ADC_DR_OVERRUN | ADC_SEQ_GDAT_DATAVALID)) == 0)
{
// Retrieve sampled data
gdat = Chip_ADC_GetDataReg(LPC_ADC, ad);
}

return ADC_DR_RESULT(gdat);
}

void ADC_Init(void) {
// Configure pins
Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_SWM);
Chip_SWM_EnableFixedPin(ADC_BATT_PIN);
Chip_Clock_DisablePeriphClock(SYSCTL_CLOCK_SWM);

// Enable ADC clock
Chip_ADC_Init(LPC_ADC, 0);

// Start Calibration
Chip_ADC_StartCalibration(LPC_ADC);
while(!Chip_ADC_IsCalibrationDone(LPC_ADC));

// Configure clock
Chip_ADC_SetClockRate(LPC_ADC, 1000); // Clock 1kHz
}

void ADC_DeInit(void) {
Chip_ADC_DeInit(LPC_ADC); // Power down ADC
}


Regards Sven

Outcomes