LPC4078 ADC not working.

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

LPC4078 ADC not working.

Jump to solution
1,755 Views
Mashau
Contributor II

Hi,

I have been working on a project where I am supposed to implement RNG using ADC. The problem is, that I cannot get ADC to work using LPCOpen or registers. Everything is well otherwise, but the status bit never goes to 1, so the program gets stuck in loop waiting for it.

ADC code using registers:

LPC_SYSCTL->PCONP |= (1 << 12) | (1 << 15); // Power/Clock ON
LPC_ADC->CR = 7 | (3 << 8) | (1 << 16) | (1 << 21);

Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 23, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 24, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 25, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));

Uint32 data = 0;
do{
data = LPC_ADC->DR[0];
}while((data & 1<<31) == 0);

data = data >> 4;

data = data & 0xFFF;

ADC code using LPCOpen:

static ADC_CLOCK_SETUP_T ADCSetup;

Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 23, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 24, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));
Chip_IOCON_PinMuxSet(LPC_IOCON, 0, 25, (IOCON_FUNC1 | IOCON_MODE_INACT | IOCON_ADMODE_EN));

Chip_ADC_Init(LPC_ADC, &ADCSetup);

Chip_ADC_SetSampleRate(LPC_ADC, &ADCSetup, ADC_MAX_SAMPLE_RATE);
Chip_ADC_SetBurstCmd(LPC_ADC, LPC_ENABLE);

Chip_ADC_EnableChannel(LPC_ADC, ADC_CH0, LPC_ENABLE);
Chip_ADC_EnableChannel(LPC_ADC, ADC_CH1, LPC_ENABLE);
Chip_ADC_EnableChannel(LPC_ADC, ADC_CH2, LPC_ENABLE);

uint16_t data0, data1, data2;

while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH0, ADC_DR_DONE_STAT) != SET);
Chip_ADC_ReadValue(LPC_ADC, ADC_CH0, &data0);
while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH1, ADC_DR_DONE_STAT) != SET);
Chip_ADC_ReadValue(LPC_ADC, ADC_CH1, &data0);
while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CH2, ADC_DR_DONE_STAT) != SET);
Chip_ADC_ReadValue(LPC_ADC, ADC_CH2, &data2);

 

Labels (3)
0 Kudos
1 Solution
1,622 Views
Mashau
Contributor II

I finally got it working, there was a bit of miscommunication between our HW dev and I. The RTC was changed and the values used for ADC did not match.

Thank you very much for all the help!

View solution in original post

6 Replies
1,739 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @Mashau 

I hope you are doing well!

If I understood properly , you are not able to exit this loop.

 

 

while (Chip_ADC_ReadStatus(LPC_ADC, ADC_CHx, ADC_DR_DONE_STAT) != SET);

 

 

 

If yes, could you try the periph_adc  example with this modification?

diego_charles_0-1625846526438.png

That is : After the ADC channel has been enabled call App_Polling_Test(); function, avoiding all the following part of the example.

In my case, I am currently able to debug with the LPC1769, its ADC has less features than  the  LPC407x , but they share the same adc_17xx_40_xx.c driver.

diego_charles_1-1625846777837.png

I was able to get the ADC conversion ( exit the while(Chip_ADC_ReadStatus)). I have also hardcoded the burst flag, to do a quick test of your setting with this mode. Apparently it worked on my side. 

What are your results?

Diego.

 

0 Kudos
1,699 Views
Mashau
Contributor II

Yes, you are correct, the program gets stuck on that loop.

I tried the LPCOpen ADC example and the end result is the same, it gets stuck in loop.

0 Kudos
1,681 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @Mashau 

Thanks for your reply.

I think that we could also check from the hardware side.  For example ,  ensure to have the ADC supply voltage VREFP, and VDDA/VSS references  according to the DS and UM specifications.  Verify that the ADC pins input voltage does not exceed VSS to VREFP measurement rage. Try an ADC channel that you never used before. 

All the best

Diego.

0 Kudos
1,670 Views
Mashau
Contributor II

Yes, VREFP and VDDA are tied to 3,3 V and VSSA is tied to ground.

Tried channels 0, 1 and 2, none of which work.

0 Kudos
1,642 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @Mashau 

Thank you for your reply!

I am thinking in the following:

 * Check the return value for the  function readADC val. 

Are you getting an error? No valid conversion results for any  ADC channel?

diego_charles_0-1627621135710.png

* And Check the return of the function  Chip_ADC_ReadStatus()  for the ADC_DR_OVERRUN_STAT status

diego_charles_2-1627621611367.png

To see, if you are getting an overrun status as you enabled  burst mode. 

diego_charles_3-1627621720465.png

* Try testing without enabling burst mode. 

* Check what happens with other ADC channels, different than 0 , 1 and 2.

* If , possible, check if this can be replicable with other parts of yours.

I tested your code with the LPCopen drivers , with my LPC1769, and I was able to get out of  the while loop (as ADC conversions complete ). When not, it was because  I did not called (on purpose)  the function  Chip_ADC_EnableChannel() for a specific channel.

 

I hope this could help 

Diego.

 

 

0 Kudos
1,623 Views
Mashau
Contributor II

I finally got it working, there was a bit of miscommunication between our HW dev and I. The RTC was changed and the values used for ADC did not match.

Thank you very much for all the help!