LPC5420x ADC reading wrong values

取消
显示结果 
显示  仅  | 搜索替代 
您的意思是: 
已解决

LPC5420x ADC reading wrong values

跳至解决方案
871 次查看
gossamer69
Contributor III

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 ?

标签 (2)
标记 (2)
0 项奖励
回复
1 解答
699 次查看
gossamer69
Contributor III

Yeah, well I did oversight the fact that ADC0 on OM13077 is used for LED .. So, my code seems to be ok when I connect it to other AD channel. 

在原帖中查看解决方案

0 项奖励
回复
1 回复
700 次查看
gossamer69
Contributor III

Yeah, well I did oversight the fact that ADC0 on OM13077 is used for LED .. So, my code seems to be ok when I connect it to other AD channel. 

0 项奖励
回复