LPC11A14 problem with ADC

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

LPC11A14 problem with ADC

594 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LucaCorradi on Sat Feb 08 18:24:40 MST 2014
I have a big problem with lpc11A14 and ADC reading. I try to exlplain it:

This is my peace of code where I'm trying to read something from ADC.

uint16_t dataADC1;

    Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 7, IOCON_FUNC2 | IOCON_ADMODE_EN | IOCON_MODE_INACT);

    ADC_CLOCK_SETUP_T adcClockCfg;

    Chip_ADC_Init(LPC_ADC, &adcClockCfg);
    Chip_ADC_EnableChannel(LPC_ADC, ADC_CH1, ENABLE);

    while(1) {

/* Start A/D conversion */
Chip_ADC_SetStartMode(LPC_ADC, ADC_START_NOW, ADC_TRIGGERMODE_RISING);

/* Waiting for A/D conversion complete */
while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH1, ADC_DR_DONE_STAT) != SET);

/* Read ADC value */
Chip_ADC_ReadValue(LPC_ADC, ADC_CH1, &dataADC1);
    }


I can see in the variable "dataADC1" only 0 or 1023, in particular 0 for about Vin<1,5Volt and 1023 for about Vin>1,5Volt.

I tried to read the internal temperature sensor, reference voltage and internal voltage core, but ADC read only 0.

Has someone this problem with this microcontroller?

(I'm using the LPCOpen libraries and lpcxpresso development suite (red-code and LPC-Link debugger) Whit debugger I have just check the ADC registers and the values seems correct.)


Thanks at all,
Luca Corradi from Italy
Labels (1)
0 Kudos
2 Replies

441 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by LucaCorradi on Sun Mar 09 13:28:52 MST 2014
Thanks a lot! I tried the examples and the adc works correctly, then I checked the lpcopen code. I found the problem:

I modified this code:

/* Initialize the ADC peripheral and the ADC setup structure to default value */
void Chip_ADC_Init(LPC_ADC_T *pADC, ADC_CLOCK_SETUP_T *ADCSetup)
{
uint8_t div;
uint32_t cr = 0;
uint32_t clk;

Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_ADC_PD);

Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ADC);

pADC->INTEN = 0;/* Disable all interrupts */

cr |= ADC_CR_PDN;

ADCSetup->adcRate = ADC_MAX_SAMPLE_RATE;
ADCSetup->bitsAccuracy = ADC_10BITS;
clk = 11;

ADCSetup->burstMode = false;
div = getClkDiv(pADC, false, ADCSetup->adcRate, clk);
cr |= ADC_CR_CLKDIV(div);
cr |= ADC_CR_BITACC(ADCSetup->bitsAccuracy);
pADC->CR = cr;
}


to this:
/* Initialize the ADC peripheral and the ADC setup structure to default value */
void Chip_ADC_Init(LPC_ADC_T *pADC, ADC_CLOCK_SETUP_T *ADCSetup)
{
uint8_t div;
uint32_t cr = 0;
uint32_t clk;

Chip_SYSCTL_PowerUp(SYSCTL_POWERDOWN_ADC_PD);

Chip_Clock_EnablePeriphClock(SYSCTL_CLOCK_ADC);

pADC->INTEN = 0;/* Disable all interrupts */

//cr |= ADC_CR_PDN;

ADCSetup->adcRate = ADC_MAX_SAMPLE_RATE;
ADCSetup->bitsAccuracy = ADC_10BITS;
clk = 11;

ADCSetup->burstMode = false;
div = getClkDiv(pADC, false, ADCSetup->adcRate, clk);
cr |= ADC_CR_CLKDIV(div);
cr |= ADC_CR_BITACC(ADCSetup->bitsAccuracy);
pADC->CR = cr;
}


"cr |= ADC_CR_PDN;" wrote in a reserved register!!


Thanks a lot Jhon  !
Luca
0 Kudos

441 Views
lpcware
NXP Employee
NXP Employee
Content originally posted in LPCWare by John@MPL on Sun Feb 09 03:58:13 MST 2014
Hi,

I have used 2 channels of ADC simultaneously on the LPC11A14 and have worked OK.

I used the examples form Keil, as I use uVision.

It may be worth checking these examples for any differences.

Sorry cannot be of any more help.

Good luck.

John W.
0 Kudos