TI E2ETm 英文论坛海量技术问答的中文版全新上线,可点击相关论坛查看,或在站内搜索 “参考译文” 获取。

This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

LAUNCHXL-CC1310: ADC多通道采样

Part Number: LAUNCHXL-CC1310

如何使用ADCBuf对多通道的电压值进行连续采样?

  • ADCbuf无法对多个通道进行采样

  • 就我我在回调函数里面这里操作会有问题吗?通过init和close来控制adc通道采样,在回调函数中切换采样通道

    void adcBufCallback(ADCBuf_Handle handle, ADCBuf_Conversion *conversion,
        void *completedADCBuffer, uint32_t completedChannel)
    {
    
        /* Adjust raw ADC values and convert them to microvolts */
        ADCBuf_adjustRawValues(handle, completedADCBuffer, ADCBUFFERSIZE, completedChannel);
        ADCBuf_convertAdjustedToMicroVolts(handle, completedChannel, completedADCBuffer, microVoltBuffer, ADCBUFFERSIZE);
    
        //数据处理
    
        if(ADCBuf_STATUS_SUCCESS != ADCBuf_convertCancel(adcBuf))
        {
            //while(1);
        }
    
        //采样通道切换
        continuousConversion.arg = NULL;
        continuousConversion.sampleBuffer = sampleBufferOne;
        continuousConversion.sampleBufferTwo = sampleBufferTwo;
        continuousConversion.samplesRequestedCount = ADCBUFFERSIZE;
        switch(step)
        {
            case 0:
                continuousConversion.adcChannel = Board_ADCBUF0CHANNEL2;
                step = 1;
                break;
            case 1:
                continuousConversion.adcChannel = Board_ADCBUF0CHANNEL3;
                step = 2;
                break;
            case 2:
                continuousConversion.adcChannel = Board_ADCBUF0CHANNEL4;
                step = 3;
                break;
            case 3:
                continuousConversion.adcChannel = Board_ADCBUF0CHANNEL5;
                step = 4;
                break;
            case 4:
                continuousConversion.adcChannel = Board_ADCBUF0CHANNEL6;
                step = 5;
                break;
            case 5:
                continuousConversion.adcChannel = Board_ADCBUF0CHANNEL7;
                step = 6;
                break;
            case 6:
                continuousConversion.adcChannel = Board_ADCBUF0CHANNELVDDS;
                step = 0;
                break;
        }
    
        /* Start converting. */
        if (ADCBuf_convert(adcBuf, &continuousConversion, 1) !=
            ADCBuf_STATUS_SUCCESS) {
            /* Did not start conversion process correctly. */
            while(1);
        }
    }
    
    
    bool adc_init()
    {
        uint8_t i;
    
    
    
        if(adcBuf != NULL)
        {
            return false;
        }
    
        /* Set up an ADCBuf peripheral in ADCBuf_RECURRENCE_MODE_CONTINUOUS */
        ADCBuf_Params_init(&adcBufParams);
        adcBufParams.callbackFxn = adcBufCallback;
        adcBufParams.recurrenceMode = ADCBuf_RECURRENCE_MODE_CONTINUOUS;
        adcBufParams.returnMode = ADCBuf_RETURN_MODE_CALLBACK;
        adcBufParams.samplingFrequency = 10000;
        adcBuf = ADCBuf_open(Board_ADCBUF0, &adcBufParams);
    
        /* Configure the conversion struct */
        continuousConversion.arg = NULL;
        continuousConversion.adcChannel = Board_ADCBUF0CHANNEL2;
        continuousConversion.sampleBuffer = sampleBufferOne;
        continuousConversion.sampleBufferTwo = sampleBufferTwo;
        continuousConversion.samplesRequestedCount = ADCBUFFERSIZE;
    
        if (adcBuf == NULL){
            return false;
            /* ADCBuf failed to open. */
            //while(1){}
        }
    
        /* Start converting. */
        if (ADCBuf_convert(adcBuf, &continuousConversion, 1) !=
            ADCBuf_STATUS_SUCCESS) {
            adc_close();
            return false;
            /* Did not start conversion process correctly. */
            //while(1){}
        }
        return true;
    }
    
    
    void adc_close()
    {
        ADCBufCC26XX_Object   *object;
        if(adcBuf != NULL)
        {
            /* Get the pointer to the object and hwAttrs*/
            object = adcBuf->object;
    
            /* Check if ADC is open and that no other transfer is in progress */
            while(!(object->conversionInProgress));
    
            if(ADCBuf_STATUS_SUCCESS != ADCBuf_convertCancel(adcBuf))
            {
                GPIO_write(Board_GPIO_LED1, ON);
            }
            ADCBuf_close(adcBuf);
            adcBuf = NULL;
        }
    }