AnsweredAssumed Answered

LPC 824 ADC - Issue in getting it to start conversion

Question asked by Flourisha P.C.G on Nov 26, 2019
Latest reply on Nov 28, 2019 by Flourisha P.C.G

I'm trying to read an analog signal on ADC 9 & 10. The issue I'm facing here is, despite setting the start bit to 1 the ADC is not launching the conversion sequence, i.e. the interrupt service routine isn't firing and also there is not update in the flag register. Kindly help. I have mentioned the initialization function below.

 

void adc_init()
{
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<18); //Enable clock to IOCON
LPC_IOCON->PIO0_13 = 0x00000000; //Disable pull up and pull down resistors
LPC_IOCON->PIO0_17 = 0x00000000; //Disable pull up and pull down resistors

LPC_SYSCON->SYSAHBCLKCTRL |= (1<<7); //Enable clock to switch matrix
LPC_SWM->PINENABLE0 |= (0<<23); //Enable ADC_10 on PIO0_13
LPC_SWM->PINENABLE0 |= (0<<22); //Enable ADC_9 on PIO0_17
LPC_SYSCON->SYSAHBCLKCTRL |= (0<<7); //Disable clock to switch matrix

LPC_SYSCON->PDRUNCFG |= (0<<4); //Power the ADC
LPC_SYSCON->SYSAHBCLKCTRL |= (1<<24); //Enable clock to ADC

LPC_SYSCON->PRESETCTRL |= (0<<24); //RESET ADC
LPC_SYSCON->PRESETCTRL |= (1<<24);

LPC_ADC->SEQA_CTRL |= (0<<31); //Disable sequence A

 

LPC_ADC->CTRL = 1; //Set clock div 1

LPC_ADC->SEQA_CTRL |= (1<<10)|(1<<9)|(1<<30); //Sequence A, channel 10, channel 9, EOS enabled

LPC_ADC->FLAGS = 0X00000000; //Clear all flags

LPC_ADC->INTEN |= (1<<0); //sequence A interupt enabled

 

NVIC_EnableIRQ(ADC_SEQA_IRQn); //Enable NVIC interrupt

LPC_ADC->SEQA_CTRL |= (1<<31)|(1<<18); //Enable sequence A
}

 

void start_adc()
{
LPC_ADC->SEQA_CTRL |= (1<<26); //start sequence A
}

 

void ADC_SEQA_IRQHandler(void)
{
SendData0("In handler\n");

if((LPC_ADC->FLAGS & (1<<28)) == 1) //Check for Sequence completion
sequence_complete = 1;

LPC_ADC->FLAGS |= (0<<28); //clear flags
}

 

uint16_t get_data_adc(int chno)
{
uint16_t data;


rawvalue = LPC_ADC->DAT[chno];

data = (rawvalue & 0X0000FFF0)>>4;

rawvalue = 0;

return data;
}

 

int main()
{
int v1,v2;


SystemCoreClockUpdate();

GpioInit();
Uart0Init(9600,8,'N',1);


adc_init();

while(1)
{
start_adc();
while(sequence_complete != 1);
sequence_complete = 0;

v1 = get_data_adc(10);
v2= get_data_adc(9);

sprintf(result,"%d %d\n",v1,v2);
SendData0(result);
}
}

Outcomes