K22F analog reads

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

K22F analog reads

Jump to solution
1,530 Views
shibbs
Contributor I

Hello, I am having trouble performing analog reads with the K22F board. I am running adc_lptmr_trigger_frdmk22f example project, and modifying the pin selection within there, using KSDK 1.2, in kinetis design studio 3 on a Mac.

  1. The results are good for ADC0_SE23 and ADC0_SE8
  2. I have not been able to get it working for ADC0_SE21, ADC0_SE7b, ADC0_SE22. Have been selecting the pins via the ADC_INPUT_CHAN variable. The ADCH bits are being set properly, and I have scoped the pin to see that the desired signal is indeed reaching it. However I get output that is essentially pin noise.
  3. Using single ended reads (differential reads give all low)
  4. I can confirm that the pins are set to default/analog in the mux registers
  5. I have tried with ADC_INST as 0 and 1

 

I have spent a few hours on this trying different variations of registers and reading around on this forum, but so far I have had no luck getting it working. Is there something I'm missing here?

Labels (1)
Tags (1)
0 Kudos
Reply
1 Solution
1,159 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Stephen,

In the FRDM-K22 board , the chip is MK222FN512VLH12, it is the 64 LQFP package,

from the Reference Manual -> Pinout, we can see that this chip does not support the

signal of "adc0_se21" "adc0_se22" , it support the signal of "adc0_se7b", please connect the

right pin :

pastedImage_0.png

And you said PTD4 pin, do you think which channel is this pin ?

BR

Alice

View solution in original post

0 Kudos
Reply
5 Replies
1,159 Views
shibbs
Contributor I

Thank you Alice,

I had not realized that the MK22FN512VLH12 and the MK22DN512VLH5 were so different. I was using the family data sheet for the MK22DN512VLH5 (K22P64M50SF4.pdf) which shows that the PTD4 pin can be used for ADC0_SE21.

Thank you,

-Stephen

0 Kudos
Reply
1,159 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello stephen,

Please tell me you use which board or the chip's part number .

Also please show the code about configure the ADC .

BR

Alice

0 Kudos
Reply
1,159 Views
shibbs
Contributor I

Thanks Alice,

We are using the frdmK22F board, so the K22F512. As for the code, we're just using the adc_lptmr_trigger_frdmk22f example located at /KSDK_1.2.0/examples/frdmk22f/demo_apps/adc_hw_trigger/lptmr/kds/ . Some of the most relevant code is attached below, the only changes that we made were to change the ADC_INPUT_CHAN and to explicitly set up pin PTD4 to default mode.

#define ADC_INPUT_CHAN2    (kAdc16Chn8) /* default input signal channel */

#define  ADC_INST2 0U

static int32_t init_adc(uint32_t instance)

{

#if FSL_FEATURE_ADC16_HAS_CALIBRATION

    adc16_calibration_param_t adcCalibraitionParam;

#endif

    adc16_converter_config_t adcUserConfig;

    adc16_chn_config_t adcChnConfig;

    ADC16_DRV_StructInitUserConfigDefault(&adcUserConfig);

    ADC16_DRV_Init(instance, &adcUserConfig);

#if FSL_FEATURE_ADC16_HAS_CALIBRATION

    // Auto calibraion.

    ADC16_DRV_GetAutoCalibrationParam(instance, &adcCalibraitionParam);

    ADC16_DRV_SetCalibrationParam(instance, &adcCalibraitionParam);

#endif

    // Initialization ADC for

    // 12bit resolution, interrrupt mode, hw trigger enabled.

    // normal convert speed, VREFH/L as reference,

    // disable continuouse convert mode.

    ADC16_DRV_StructInitUserConfigDefault(&adcUserConfig);

    adcUserConfig.hwTriggerEnable = true;

    adcUserConfig.continuousConvEnable = false;

    ADC16_DRV_Init(instance, &adcUserConfig);

    // Install Callback function into ISR

    ADC_TEST_InstallCallback(instance, 0U, adc_chn0_isr_callback);

    ADC_TEST_InstallCallback(instance, 1U, adc_chn1_isr_callback);

    adcChnConfig.chnIdx = (adc16_chn_t)ADC_INPUT_CHAN2;

#if FSL_FEATURE_ADC16_HAS_DIFF_MODE

    adcChnConfig.diffConvEnable = false;

#endif /* FSL_FEATURE_ADC16_HAS_DIFF_MODE */

    adcChnConfig.convCompletedIntEnable = true;

    // Configure channel0

    ADC16_DRV_ConfigConvChn(instance, 0U, &adcChnConfig);

    // Configure channel1, which is used in PDB trigger case

    ADC16_DRV_ConfigConvChn(instance, 1U, &adcChnConfig);

    return 0;

}

int main(void)

{

    uint8_t cnt;

    int32_t row;

    // init the hardware board

    hardware_init();

    PORT_HAL_SetMuxMode(PORTD,4u,1);

    PRINTF("\r\nadc_hw_trigger demo running...\r\n\r\n");

    PORT_HAL_SetMuxMode(PORTD,4u,kPortPinDisabled);

#ifdef USE_DAC_OUT_AS_SOURCE

    // use DAC to generate the sine wave

    dac_gen_wave();

#else

    // If no DAC can be use, then a function generator should

    // be used to generate a signal wave, and connect to ADC input

#endif

    // initialize the ADC

    if (init_adc(ADC_INST2))

    {

        PRINTF("Failed to do the ADC init\n");

        return -1;

    }

    // setup the HW trigger source

    init_trigger_source(ADC_INST2);

    // init the print chart array

    sparse_reset();

    for (cnt = 0; cnt < NR_SAMPLES; cnt++)

    {

        uint16_t result;

        double tmpRatio;

        while (gAdcDone != true)

        {

            ;

        }

        result = ADC16_DRV_GetConvValueRAW(ADC_INST2, (uint32_t)gCurChan);

        gAdcDone = false;

        // insert the sample data into the sparse matrix

        tmpRatio = (double)result / RATIO;

        row = (int32_t)tmpRatio;

        if (row >= CHART_ROWS)

        {

            row = CHART_ROWS - 1;

        }

        // fill one samples into sparse matrix

        sparse_insert(row, cnt);

    }

    // print the chart

    for (row = CHART_ROWS - 1; row >= 0; row --)

    {

        sparse_node_ptr p = gChartHead[row];

        uint32_t last = 0;

        while (p)

        {

            for (; last < p->value; last++)

            {

                PRINTF(" ");

            }

            PRINTF("*");

            p = p->next;

            last++;

        }

        PRINTF("\r\n");

    }

    // disable the adc0

    ADC16_DRV_Deinit(ADC_INST2);

    // disable hw trigger source

    deinit_trigger_source(ADC_INST2);

#ifdef USE_DAC_OUT_AS_SOURCE

    // disable dac source

    dac_stop_wave();

#endif

    while(1)

    {}

}

    }

    // disable the adc0

    ADC16_DRV_Deinit(ADC_INST2);

    // disable hw trigger source

    deinit_trigger_source(ADC_INST2);

#ifdef USE_DAC_OUT_AS_SOURCE

    // disable dac source

    dac_stop_wave();

#endif

    while(1)

    {}

}

Thank you,

Steve

0 Kudos
Reply
1,159 Views
shibbs
Contributor I

Any update here?

0 Kudos
Reply
1,160 Views
Alice_Yang
NXP TechSupport
NXP TechSupport

Hello Stephen,

In the FRDM-K22 board , the chip is MK222FN512VLH12, it is the 64 LQFP package,

from the Reference Manual -> Pinout, we can see that this chip does not support the

signal of "adc0_se21" "adc0_se22" , it support the signal of "adc0_se7b", please connect the

right pin :

pastedImage_0.png

And you said PTD4 pin, do you think which channel is this pin ?

BR

Alice

0 Kudos
Reply