Hi I am using the LPC54616J, I am trying to read 4 analogue inputs, channels 4, 5, 6 and 7. My problem is that when I have all 4 inputs configured, channels 5 and 6 do not read correctly, and I seem to have an 11 bit input. However, when I use channels 5 and 6 alone, they read correctly.
I attach code and configuration in case anyone knows what is happening to me.
Thank you very much.
#define DEMO_ADC_BASE ADC0
#define DEMO_ADC_SAMPLE_CHANNEL_NUMBER 3U
#define DEMO_ADC_CLOCK_DIVIDER 2U
#define ADC_DIS 3U
#define ADCNS 5U
#define ADCE0 6U
#define ADCRSSI 4U
#define Fsampling 10
#define TSamplingMs (1000 / Fsampling)
/******************************************************//**
** Variables privadas
*********************************************************/
static TaskHandle_t _tskHandleADC; //< Manejador de la tarea de conversión del ADC
static GenRxCallBack_t _repDatTensiones; //< Función de call-back para el reporte de medidas del ADC.
/******************************************************//**
** Métodos privados
*********************************************************/
/*! \fn void _TskConvADC(void)
* \brief Tarea que realiza las lecturas del puerto ADC.
* \return Nada.
*/
static void _TskConvADC(void)__attribute__((noreturn));
static void _TskConvADC(void)
{
adc_result_info_t ValTen;
ADC_savedat_t Save;
while(true)
{
ulTaskNotifyTake(pdFALSE, portMAX_DELAY);
/* Wait for the converter to be done. */
// ADC_GetChannelConversionResult(ADC0, ADC_DIS, &ValTen);
ADC_GetChannelConversionResult(ADC0, ADCNS, &ValTen);
Save.ADC_NS = ValTen.result;
ADC_GetChannelConversionResult(ADC0, ADC_DIS, &ValTen);
Save.ADC_Dis = ValTen.result;
ADC_GetChannelConversionResult(ADC0, ADCRSSI, &ValTen);
Save.ADC_RSSI = ValTen.result;
// ADC_ClearStatusFlags(ADC0, kADC_ConvSeqBInterruptFlag);
// ADC_DoSoftwareTriggerConvSeqB(ADC0);
ADC_GetChannelConversionResult(ADC0, ADCE0, &ValTen);
Save.ADC_EO = ValTen.result;
//Mandamos los datos al módulo Mod_Operaciones
if(_repDatTensiones != NULL)
_repDatTensiones(&Save,sizeof(Save));
}
} //void _TskConvADC(void)
/******************************************************//**
** Métodos públicos
*********************************************************/
/*! \fn void ADCinit(void)
* \brief Inicializa las conversiones AD.
* \return Nada.
*/
void ADCinit(void)
{
BaseType_t xReturned;
// uint32_t frequency = 0U;
// ** Inicializa variables **
_repDatTensiones = NULL;
// ** Inicializa el driver **
POWER_DisablePD(kPDRUNCFG_PD_VDDA); /* Power on VDDA. */
POWER_DisablePD(kPDRUNCFG_PD_ADC0); /* Power on the ADC converter. */
POWER_DisablePD(kPDRUNCFG_PD_VD2_ANA); /* Power on the analog power supply. */
POWER_DisablePD(kPDRUNCFG_PD_VREFP); /* Power on the reference voltage source. */
ADC_DoSelfCalibration(ADC0);
if(!ModoConfig())
{
xReturned = xTaskCreate((TaskFunction_t)_TskConvADC,"TskConvADC",4 * configMINIMAL_STACK_SIZE, NULL, APP_TSK_HIGH_PRIORITY, &_tskHandleADC);
configASSERT(xReturned);
} //if(!ModoConfig())
} // void ADCinit(void)
/*! \fn void AdcStartConv(void)
* \brief Fuerza la conversión(llamada por un timer).
* \return Nada.
*/
void AdcStartConv(void)
{
// ** Fuerza el arranque de la conversión de la secuencia A **
// ADC_DoSoftwareTriggerConvSeqA(ADC0);
ADC_DoSoftwareTriggerConvSeqA(ADC0);
} // void AdcStartConv(void)
/*! \fn void RepDatADC (GenRxCallBack_t callBack)
* \brief Establece la función de call-back para reporte de datos.
* \param[in] callBack Función que establecer.
* \return Nada.
*/
void RepDatADC (GenRxCallBack_t callBack)
{
_repDatTensiones = callBack;
} //void RepDatADC (GenRxCallBack_t callBack)
/* ADC0_SEQA_IRQn interrupt handler */
//void ADC0_ADC_SEQ_A_IRQHANDLER(void)
void ADC0_ADC_SEQ_A_IRQHANDLER(void)
{
BaseType_t tskWoken;
if (kADC_ConvSeqAInterruptFlag == (kADC_ConvSeqAInterruptFlag & ADC_GetStatusFlags(ADC0)))
{
ADC_ClearStatusFlags(ADC0, kADC_ConvSeqAInterruptFlag);
vTaskNotifyGiveFromISR(_tskHandleADC, &tskWoken);
portYIELD_FROM_ISR(tskWoken);
} // if (kADC_ConvSeqAInterruptFlag == (kADC_ConvSeqAInterruptFlag & ADC_GetStatusFlags(ADC0)))
Hi,
Do you say that the samples of all channels are okay after you changed the ADC clock frequency?
BR
XiangJun Rong
@xiangjun_rong Hi, I solved it by lowering the frequency of the clock configured to read these ports, but I don't understand why the clock influences so much?
I think this is basically the same issue as the "Accuracy ADC" thread, which appears to be solved.
I don't understand how ADC clock issues could produce the described error pattern, though.