How to Read multiple ADC values on LPC11U68

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

How to Read multiple ADC values on LPC11U68

1,007 Views
daisukefukuda_n
Contributor III

Hi there,

This is Daisuke FUKUDA with NEXTY Electronics Japan. Thank you for your support.

I've been developing a evaluation board for our client with LPC11U68. Now I'm implementing to read ADC values. The key point of this function is the followint.

1. I'd like to read value in PIO0_14 and PIO0_12 with a software trigger when each function is called.

E.g.

a = ReadValue(0); // -> Read in PIO0_14

b = ReadValue(1); // -> Read in PIO0_12

2. I'd like to use only ADC_SEQB_IDX because ADC_SEQA has been already used for the other function.

 

However the read function cannot go out from the infinite loop as below when ReadValue(1) is called after ReadValue(0).

- while(!ADC_DR_DONE(Chip_ADC_GetDataReg(LPC_ADC, tblADCNum[nADC])));

 

The part of codes is below. If you find something for me to check, can you let me know?

 

#define ADC_CLK_RATE 10000
#define ADC_SEQIDX ADC_SEQB_IDX
#define ADC_CH 8 // PIO0_12_ADC

unsigned int tblADCNum[MAX_MY_ADC] = {
6, // MY_ADC_1, // ADC 6 (PIO0_14)
8 // MY_ADC_2, // ADC 8 (PIO0_12)
};

void Init(void)

{

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

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

}

void Init_myADC(void)
{
// eMYADC_NUM i;

/* Setup ADC for 12-bit mode and normal power */
Chip_ADC_Init(LPC_ADC, 0);

/* Need to do a calibration after initialization and trim */
Chip_ADC_StartCalibration(LPC_ADC);
while (!(Chip_ADC_IsCalibrationDone(LPC_ADC))) {}

Chip_ADC_SetClockRate(LPC_ADC, ADC_CLK_RATE);

}

unsigned int GetValue_myADC(eMYADC_NUM nADC)
{
unsigned int val;

uint32_t rawSample;

Chip_ADC_SetupSequencer(LPC_ADC, ADC_SEQIDX,
(ADC_SEQ_CTRL_CHANSEL(tblADCNum[nADC]) | ADC_SEQ_CTRL_MODE_EOS));
Chip_ADC_EnableSequencer(LPC_ADC, ADC_SEQIDX);

while(!ADC_DR_DONE(Chip_ADC_GetDataReg(LPC_ADC, tblADCNum[nADC])));

rawSample = Chip_ADC_GetDataReg(LPC_ADC, tblADCNum[nADC]);

val = ADC_DR_RESULT(rawSample);

Chip_ADC_DisableSequencer(LPC_ADC, ADC_SEQIDX);

Chip_ADC_ClearSequencerBits(LPC_ADC, ADC_SEQIDX,
(ADC_SEQ_CTRL_CHANSEL(tblADCNum[nADC]) | ADC_SEQ_CTRL_MODE_EOS));

return val;
}

 

Best regards,

Daisuke

 

0 Kudos
Reply
3 Replies

981 Views
daisukefukuda_n
Contributor III

Hi Diego,

This is Daisuke FUKUDA with NEXTY Electronics JAPAN. Thank you for your prompt reply.

I'm going to try based on your advice. I'll get back to you.

 

Best regards,

FUKUDA

0 Kudos
Reply

948 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @daisukefukuda_n 

Feel free to update  if you are still facing problems, or any further questions. 

Thank you.

Diego.

0 Kudos
Reply

984 Views
diego_charles
NXP TechSupport
NXP TechSupport

Hi @daisukefukuda_n 

I hope that you are doing well!

So the problem only appears with the order of which channel do you read ? If ReadValue(0) is called before ReadValue(1) the code does not get stuck?

Here I got initial recommendations

Try to force a SW triggered conversion (calling  again Chip_ADC_StartSequencer () ) , and also  check if this conversion mode is actually enabled at register level. 

Also I will recommend to test the ADCA sequencer  in the periph_dma_adc LPCopen example.I think that we could isolate the issue only testing with once SEQ, Could you adapt the example to work with SEQB and verify in your HW? Also this example works through interrupts.

Best regards, 

Diego.

 

0 Kudos
Reply