AnsweredAssumed Answered

LPC5420x ADC reading wrong values

Question asked by Sven Savic on Aug 27, 2016
Latest reply on Aug 30, 2016 by Sven Savic

I have set ADC to work in sync mode, enabled clock, peripheral, VREF, VDDA in SYSCON. Set the pin to analog. I am using single step conversion with setting start bit in CTRL.

While my oscilloscope is showing different voltages from input on ADC0, my ADC reads almost the same value all the time, 0xfec.

I have ran the calibration upon initialisation. Do I need to do anything with that value ?

 

setup:

m_port = LPC_ADC;

m_pin = a_pin;

LPC_SYSCON->PDRUNCFGCLR |= (1<<10);

LPC_SYSCON->PDRUNCFGCLR |= (1<<19) | (1<<23); //VDDA ad VREF

LPC_SYSCON->AHBCLKCTRLSET[0] |= (1<<27) | (1<<13); //adc and iocon

LPC_SYSCON->PRESETCTRLCLR[0] |= (1<<27) | (1<<13);

LPC_SYSCON->ADCCLKDIV = 0x01; //clock divider

 

m_port->CTRL |= (1<<0);

LPC_IOCON->PIO[0][29] = 0x120; //ADC_0, analog, filter off, invert disabled, mode inactive, od normal.

m_port->CTRL &= ~(1<<8); //sync mode

m_port->CTRL &= ~(0x3<<9); //clear res

m_port->CTRL |= (0x02<<9); //10-bit res

m_port->SEQ_CTRL[0] &= ~_BV(31); //disable ADC

m_port->SEQ_CTRL[0] |= _BV(18); //TrigPolarity

m_port->SEQ_CTRL[0] |= _BV(31); //enable ADC

m_port->STARTUP = 1;

m_port->CALIBR |= (1<<0); //start calibration

while(IS_BIT_ENABLED(m_port->CALIBR, 0));

 

Read:

unsigned long timeout=1000;

m_port->SEQ_CTRL[0] |= _BV(m_pin); //enable ADC channel

m_port->SEQ_CTRL[0] |= _BV(28);

m_port->SEQ_CTRL[0] |= _BV(26);

while (!IS_BIT_ENABLED(m_port->DAT[m_pin], 31)) //wait until end of conversion

if (--timeout == 0) return 0; }

m_port->SEQ_CTRL[0] &= ~_BV(26);

return (m_port->DAT[m_pin] >> 4) & 0xfff;

 

I am using OM13077. VREFP is 3.3v, VREFN is gnd. Internal RC clock is used.

Am i missing something ?

Outcomes