AnsweredAssumed Answered

Kinetis ADC usage issue

Question asked by Alven WU on May 1, 2018
Latest reply on May 7, 2018 by Robin_Shen

I try to use the ADC conversion function on the Kinetis,  basically there are two steps ,   1. ADC initialization 2 Start a ADC conversion.   I use the interrupt mode , which means after the conversion completion , ADC should raise a interrupt , then the program tries to get the conversion data from the ADC data register. Is that process right ? Here is two questions:

1.  should the cpu pins involved ADC device be configured at first during the initialization phase.

2.  there are two modes , query  and interrupt mode to indicate the conversion completion , but when I set the interrupt enable , and start the conversion , however , seems the interrupt is lost, what kind of problem would cause it ?


Here the source code of ADC module:

1. initialization:

static int adc_setup(FAR struct adc_lowerhalf_s *dev)
    uint32_t regval = 0;
        FAR struct kinetis_adc_s *pt_Adcdev = (FAR struct kinetis_adc_s *)dev;
    DEBUGASSERT(NULL != pt_Adcdev);


        /* config the sim clock rate*/   
        /* CFG config the adc clock to get the ADCK, and select sample time and low-power   */
                     | ADC_CFG1_ADLSMP | ADC_CFG1_MODE_1011BIT;                    
        adc_putreg(pt_Adcdev, KINETIS_ADC_CFG1_OFFSET, regval);


        /* SC2 select the trigger :software */      
        regval = ADC_SC2_REFSEL_ALT;
        adc_putreg(pt_Adcdev, KINETIS_ADC_SC2_OFFSET, regval);     


        /* SC3 select hardware averaging*/
        regval = ADC_SC3_AVGS_32SMPLS | ADC_SC3_AVGE;
        adc_putreg(pt_Adcdev, KINETIS_ADC_SC3_OFFSET, regval);        
         /* calibrate ADC */
        if (FALSE == adc_alibration(pt_Adcdev))
        return -EINVAL;


        return OK;


2. start the conversion

static void adc_start(FAR struct adc_lowerhalf_s *dev, FAR char cChannelid)
    uint32_t regval = 0;
    FAR struct kinetis_adc_s *pt_Adcdev = (FAR struct kinetis_adc_s *)dev;
        DEBUGASSERT(NULL != pt_Adcdev);
        /*choose a channel*/
    regval = ((cChannelid << ADC_SC1_ADCH_SHIFT) & ADC_SC1_ADCH_MASK) | ADC_SC1_AIEN;
        printf("adc start!\n");


        /*start a conversion*/
        adc_putreg(pt_Adcdev, KINETIS_ADC_SC1A_OFFSET, regval);