Unable to read multiple adc channel readings

cancel
Showing results for 
Search instead for 
Did you mean: 

Unable to read multiple adc channel readings

872 Views
rahul_eris
Contributor II

We are using FRDM K64F evaluation board.

Using KDS 3.0.0 and KSDK 1.2.0. Using MQXRTOS in KSDK

 

 

In our project,i want to read multiple adc channels.

Using the pins PTB2,PTB3(ADC0) and PTB10,PTB11(ADC1).

But currently i can only read PTB2 & PTB10 values, ie single channels from each modules.

 

we are blocked in this

Can any one help me to solve this problem.

 

configuration codes are copied below:::::::::::::::::::::::::::::::::::::::

 

configuration for adc0(therm1):

 

const adc16_converter_config_t therm1_InitConfig0 = {

  .lowPowerEnable = false,

  .clkDividerMode = kAdc16ClkDividerOf1,

  .longSampleTimeEnable = false,

  .resolution = kAdc16ResolutionBitOfSingleEndAs12,

  .clkSrc = kAdc16ClkSrcOfBusClk,

  .asyncClkEnable = false,

  .highSpeedEnable = false,

  .longSampleCycleMode = kAdc16LongSampleCycleOf24,

  .hwTriggerEnable = false,

  .refVoltSrc = kAdc16RefVoltSrcOfVref,

  .continuousConvEnable = true,

  .dmaEnable = false,

};

 

const adc16_converter_config_t therm1_InitConfig1 = {

  .lowPowerEnable = false,

  .clkDividerMode = kAdc16ClkDividerOf1,

  .longSampleTimeEnable = false,

  .resolution = kAdc16ResolutionBitOfSingleEndAs8,

  .clkSrc = kAdc16ClkSrcOfBusClk,

  .asyncClkEnable = false,

  .highSpeedEnable = false,

  .longSampleCycleMode = kAdc16LongSampleCycleOf24,

  .hwTriggerEnable = false,

  .refVoltSrc = kAdc16RefVoltSrcOfVref,

  .continuousConvEnable = true,

  .dmaEnable = false,

};

 

 

const adc16_hw_cmp_config_t therm1_HwConfig0 = {

};

 

const adc16_chn_config_t therm1_ChnConfig1 = {

  .chnIdx = kAdc16Chn13,

  .convCompletedIntEnable = false,

  .diffConvEnable = false

};

const adc16_chn_config_t therm1_ChnConfig0 = {

  .chnIdx = kAdc16Chn12,

  .convCompletedIntEnable = false,

  .diffConvEnable = false

};

/* END therm1. */

 

 

configuration for adc1 module(universal)

 

const adc16_converter_config_t universal_InitConfig0 = {

  .lowPowerEnable = false,

  .clkDividerMode = kAdc16ClkDividerOf1,

  .longSampleTimeEnable = false,

  .resolution = kAdc16ResolutionBitOfSingleEndAs12,

  .clkSrc = kAdc16ClkSrcOfBusClk,

  .asyncClkEnable = false,

  .highSpeedEnable = false,

  .longSampleCycleMode = kAdc16LongSampleCycleOf24,

  .hwTriggerEnable = false,

  .refVoltSrc = kAdc16RefVoltSrcOfVref,

  .continuousConvEnable = true,

  .dmaEnable = false,

};

 

const adc16_converter_config_t universal_InitConfig1 = {

  .lowPowerEnable = false,

  .clkDividerMode = kAdc16ClkDividerOf1,

  .longSampleTimeEnable = false,

  .resolution = kAdc16ResolutionBitOfSingleEndAs12,

  .clkSrc = kAdc16ClkSrcOfBusClk,

  .asyncClkEnable = false,

  .highSpeedEnable = false,

  .longSampleCycleMode = kAdc16LongSampleCycleOf24,

  .hwTriggerEnable = false,

  .refVoltSrc = kAdc16RefVoltSrcOfVref,

  .continuousConvEnable = true,

  .dmaEnable = false,

};

 

const adc16_chn_config_t universal_ChnConfig0 = {

  .chnIdx = kAdc16Chn14,

  .convCompletedIntEnable = false,

  .diffConvEnable = false

};

const adc16_chn_config_t universal_ChnConfig1 = {

  .chnIdx = kAdc16Chn15,

  .convCompletedIntEnable = false,

  .diffConvEnable = false

};

/* END universal. */

 

 

 

task1()

 

while(1)

  {

  //Read Analog Inputs

  ADC16_DRV_ConfigConvChn(FSL_THERM1,1,&therm1_ChnConfig0);

  ADC16_DRV_WaitConvDone(FSL_THERM1,0);

  value1=ADC16_DRV_GetConvValueSigned(FSL_THERM1,0);

  PRINTF("ADC1 value is %d\n",value1);

 

  ADC16_DRV_ConfigConvChn(FSL_THERM1,1,&therm1_ChnConfig1);

  DelayFunction ();

  ADC16_DRV_WaitConvDone(FSL_THERM1,1);

  value2=ADC16_DRV_GetConvValueSigned(FSL_THERM1,1);

  PRINTF("ADC2 value is %d\n",value2);

 

  ADC16_DRV_ConfigConvChn(FSL_UNIVERSAL,1,&universal_ChnConfig0);

  ADC16_DRV_WaitConvDone(FSL_UNIVERSAL,0);

  value3=ADC16_DRV_GetConvValueSigned(FSL_UNIVERSAL,0);

  PRINTF("ADC3 value is %d\n",value3);

 

  ADC16_DRV_ConfigConvChn(FSL_UNIVERSAL,1,&universal_ChnConfig1);

  DelayFunction ();

  ADC16_DRV_WaitConvDone(FSL_UNIVERSAL,1);

  value4=ADC16_DRV_GetConvValueSigned(FSL_UNIVERSAL,1);

  PRINTF("ADC4 value is %d\n",value4);

 

  }

 

 

What may be the fault in this procedure................Waiting for a solution asap..

 

 

 

Thanks

RAHUL

Labels (1)
0 Kudos
2 Replies

270 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello RAHUL,

Here :

pastedImage_0.png

the parameter of "uint32_tchnGroup " , i think is 1 , for in the ADC16_DRV_ConfigConvChn function , you have choose "1" .

It is the same about ADC1 .

Hope it helps

Alice

0 Kudos

270 Views
rahul_eris
Contributor II

Thanks Alice_Yang

while resetting the parameters passed, its worked for me.

I think parameter of "uint32_tchnGroup" is same for all channels in one module

Parameter value will change for the next adc module.

while(1)

  {

   ADC16_DRV_ConfigConvChn(FSL_ADC1,0,&adc1_ChnConfig0);

   value=ADC16_DRV_GetConvValueRAW(FSL_ADC1,0);

   printf("value=%d",value);

   ADC16_DRV_ConfigConvChn(FSL_ADC1,0,&adc1_ChnConfig1);

   value2=ADC16_DRV_GetConvValueRAW(FSL_ADC1,0);

   printf("value=%d",value2);

   ADC16_DRV_ConfigConvChn(FSL_ADC2,0,&adc2_ChnConfig0);

   value3=ADC16_DRV_GetConvValueRAW(FSL_ADC2,0);

   printf("value=%d",value3);

   ADC16_DRV_ConfigConvChn(FSL_ADC2,0,&adc2_ChnConfig1);

   value4=ADC16_DRV_GetConvValueRAW(FSL_ADC2,0);

   printf("value=%d",value4);

}

It worked for me now...Not sure whether it may misbehave in future......

Thanks

Rahul

0 Kudos