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