AnsweredAssumed Answered

K22F Multi Channel Signal Read Using ADC with PIT --  About the Delay

Question asked by Jack Xu on Jul 25, 2016
Latest reply on Jul 27, 2016 by Robin_Shen

Dear all,

 

I'm working with the FRDM-K22F, and want to read several signals using ADC, and use PIT to timing for the sample period, also according the value of the single output digital signal. Settings as follows(from demo driver):

 

int main(void)    ADC16_GetDefaultConfig(&adc16ConfigStruct);

{

                             ...............

/**************************ADC INIT***********************************************************************/

    ADC16_Init(DEMO_ADC16_BASE, &adc16ConfigStruct);

    ADC16_EnableHardwareTrigger(DEMO_ADC16_BASE, false); /* Make sure the software trigger is used. */

  #if defined(FSL_FEATURE_ADC16_HAS_CALIBRATION) && FSL_FEATURE_ADC16_HAS_CALIBRATION

    if (kStatus_Success == ADC16_DoAutoCalibration(DEMO_ADC16_BASE))

    {

        //PRINTF("ADC16_DoAutoCalibration() Done.\r\n");

    }

    else

    {

        //PRINTF("ADC16_DoAutoCalibration() Failed.\r\n");

    }

  #endif

 

        adc16ChannelConfigStruct1.channelNumber = DEMO_ADC16_USER_CHANNEL1;

        adc16ChannelConfigStruct.enableInterruptOnConversionCompleted = false;

      #if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE

        adc16ChannelConfigStruct.enableDifferentialConversion = false;

      #endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */

 

                              ...............

 

          adc16ChannelConfigStructn.channelNumber = DEMO_ADC16_USER_CHANNELn;

          adc16ChannelConfigStruct.enableInterruptOnConversionCompleted = false;

        #if defined(FSL_FEATURE_ADC16_HAS_DIFF_MODE) && FSL_FEATURE_ADC16_HAS_DIFF_MODE

          adc16ChannelConfigStruct.enableDifferentialConversion = false;

        #endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */

 

/*********************************************************************************************************/

/*****************************************PIT INIT*******************************************************/

                              ...............

}

 

 

void PIT_IRS_HANDLER(void)

{

    /* Clear interrupt flag.*/

    PIT_ClearStatusFlags(PIT, kPIT_Chnl_0, PIT_TFLG_TIF_MASK);

 

/********************************GET the ADC Value**************************************************/

    ADC16_SetChannelConfig(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP, &adc16ChannelConfigStruct1);

    while (0U == (kADC16_ChannelConversionDoneFlag &

                  ADC16_GetChannelStatusFlags(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP)))

    {

    }

    Analog_Signal_1 = ADC16_GetChannelConversionValue(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP);

/*********************************************************************************************************/

                              ...............

/*********************************************************************************************************/

    ADC16_SetChannelConfig(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP, &adc16ChannelConfigStructn);

    while (0U == (kADC16_ChannelConversionDoneFlag &

                  ADC16_GetChannelStatusFlags(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP)))

    {

    }

    Analog_Signal_n = ADC16_GetChannelConversionValue(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP);

/*********************************************************************************************************/

cnt = (cnt + 1) & 0xff;

if (cnt < 20)

     {

          GPIO_ClearPinsOutput(BOARD_PIN1_GPIO, 1U << BOARD_GPIO_PIN1);

     }

else if(cnt <150)

     {

          GPIO_SetPinsOutput(BOARD_PIN1_GPIO, 1U << BOARD_GPIO_PIN1);

     }

else

     {

          GPIO_ClearPinsOutput(BOARD_PIN1_GPIO, 1U << BOARD_GPIO_PIN1);

     }

                              ...............

}

 

 

When in debug, the cycle of the PIN1 is wrong, will be much more than PIT cycle. After banned the

    ADC16_SetChannelConfig(DEMO_ADC16_BASE, DEMO_ADC16_CHANNEL_GROUP, &adc16ChannelConfigStructn);

then the cycle of PIN1 will be the same as designed.

 

Is there got a better solution to read the analog signals without delay? if got, please show it to me.

 

Thanks in advance!

 

- Jack

Outcomes