TI中文支持网
TI专业的中文技术问题搜集分享网站

CC1310 ADC数据读取问题

本人使用CC1310来读取IO口的模拟电压,使用的开发板是CC1310DK_7XD,使用的例程为官方adcBufContinuous的例程。模拟引脚为DIO28,将该端口接GND后发现读到的数据并不是0,请问是什么原因。附上更改后的代码:

void conversionStartFxn(UArg arg0, UArg arg1) {
    UART_Params uartParams;
    ADCBuf_Handle adcBuf;
    ADCBuf_Params adcBufParams;
    ADCBuf_Conversion continuousConversion;

    /* Create a UART with data processing off. */
    UART_Params_init(&uartParams);                      //串口参数初始化
    uartParams.writeDataMode = UART_DATA_BINARY;        
    uartParams.writeMode = UART_MODE_CALLBACK;
    uartParams.writeCallback = uartCallback;            //串口回调函数  直接返回不做任何处理
    uartParams.baudRate = 115200;                       //波特率设置
    uart = UART_open(Board_UART0, &uartParams);         //打开串口0

    /* Set up an ADCBuf peripheral in ADCBuf_RECURRENCE_MODE_CONTINUOUS */
    ADCBuf_Params_init(&adcBufParams);                  //ADC参数初始化
    adcBufParams.callbackFxn = adcBufCallback;          //ADC回调函数   ***********************
    adcBufParams.recurrenceMode = ADCBuf_RECURRENCE_MODE_CONTINUOUS;            //连续输出模式
    adcBufParams.returnMode = ADCBuf_RETURN_MODE_CALLBACK;                      //返回模式 立即返回
    adcBufParams.samplingFrequency = 20;               //采样频率为20
    adcBuf = ADCBuf_open(Board_ADCBuf0, &adcBufParams); //打开ADC

    /* Configure the conversion struct */               //配置转换结构
    continuousConversion.arg = NULL;                    //传递给回调函数的参数      continuousConversion.adcChannel = 2;   //ADC采样的通道2********
    continuousConversion.sampleBuffer = sampleBufferOne;        //存储转换结果的缓冲区
    continuousConversion.sampleBufferTwo = sampleBufferTwo;
    continuousConversion.samplesRequestedCount = ADCBUFFERSIZE; //要转换个返回的数量 100

    if (!adcBuf){
        System_abort("adcBuf did not open correctly\n");
    }

    /* Start converting. */
    if (ADCBuf_convert(adcBuf, &continuousConversion, 1) !=             //在一个通道上启动一组转换
        ADCBuf_STATUS_SUCCESS) {
        System_abort("Did not start conversion process correctly\n");
    }

    /*
     * Go to sleep in the foreground thread forever. The data will be collected
     * and transfered in the background thread
     */
    Task_sleep(BIOS_WAIT_FOREVER);                      //任务休眠  后台运行AD转换
}

回调函数

void adcBufCallback(ADCBuf_Handle handle, ADCBuf_Conversion *conversion,
    void *completedADCBuffer, uint32_t completedChannel) {
    uint_fast16_t i;
    uint32_t valueBuf = 0;
    uint32_t avgBuf = 0;

    /* Adjust raw adc values and convert them to microvolts */                          //调整原始ADC的值并且转换他们为微伏
    ADCBuf_adjustRawValues(handle, completedADCBuffer, ADCBUFFERSIZE,                   //此函数调整原始ADC输出缓冲区,使得结果在同一个make的设备之间是可比较的。
        completedChannel);
    ADCBuf_convertAdjustedToMicroVolts(handle, completedChannel,                        //该功能将原始ADC输出值转换为以微伏为单位的值。
        completedADCBuffer, microVoltBuffer, ADCBUFFERSIZE);

    for (i = 0; i < ADCBUFFERSIZE; i++)
    {
        valueBuf += microVoltBuffer[i];
    }
    avgBuf = valueBuf/ADCBUFFERSIZE;
    /* Send out the data via UART */
    UART_write(uart,&avgBuf,sizeof(avgBuf));
}

配置文件CC1310DK_7XD.C

/*
 *  ========================== ADCBuf begin =========================================
 */
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(ADCBuf_config, ".const:ADCBuf_config")
#pragma DATA_SECTION(adcBufCC26xxHWAttrs, ".const:adcBufCC26xxHWAttrs")
#pragma DATA_SECTION(ADCBufCC26XX_adcChannelLut, ".const:ADCBufCC26XX_adcChannelLut")
#endif

/* Include drivers */
#include <ti/drivers/ADCBuf.h>
#include <ti/drivers/adcbuf/ADCBufCC26XX.h>

/* ADC objects */
ADCBufCC26XX_Object adcBufCC26xxObjects[CC1310DK_7XD_ADCBufCOUNT];

/*
 *  This table converts a virtual adc channel into a dio and internal analogue input signal.
 *  This table is necessary for the functioning of the adcBuf driver.
 *  Comment out unused entries to save flash.
 *  Dio and internal signal pairs are hardwired. Do not remap them in the table. You may reorder entire entries though.
 *  The mapping of dio and internal signals is package dependent.
 */
const ADCBufCC26XX_AdcChannelLutEntry ADCBufCC26XX_adcChannelLut[] = {
    {Board_ALS_OUT,  ADC_COMPB_IN_AUXIO7},
    {Board_DIO28_ANALOG,  ADC_COMPB_IN_AUXIO2},
    {Board_DIO30_ANALOG,  ADC_COMPB_IN_AUXIO0},
    {PIN_UNASSIGNED, ADC_COMPB_IN_VDDS}
};

const ADCBufCC26XX_HWAttrs adcBufCC26xxHWAttrs[CC1310DK_7XD_ADCBufCOUNT] = {
    {
        .intPriority = ~0,
        .swiPriority = 0,
        .adcChannelLut = ADCBufCC26XX_adcChannelLut,
        .gpTimerUnit = Board_GPTIMER0A,
        .gptDMAChannelMask = 1 << UDMA_CHAN_TIMER0_A,
    }
};

const ADCBuf_Config ADCBuf_config[] = {
    {&ADCBufCC26XX_fxnTable, &adcBufCC26xxObjects[0], &adcBufCC26xxHWAttrs[0]},
    {NULL, NULL, NULL},
};
/*
 *  ========================== ADCBuf end =========================================
 */

/*
 *  ========================== ADC begin =========================================
 */
/* Place into subsections to allow the TI linker to remove items properly */
#if defined(__TI_COMPILER_VERSION__)
#pragma DATA_SECTION(ADC_config, ".const:ADC_config")
#pragma DATA_SECTION(adcCC26xxHWAttrs, ".const:adcCC26xxHWAttrs")
#endif

/* Include drivers */
#include <ti/drivers/ADC.h>
#include <ti/drivers/adc/ADCCC26XX.h>

/* ADC objects */
ADCCC26XX_Object adcCC26xxObjects[CC1310DK_7XD_ADCCOUNT];

const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1310DK_7XD_ADCCOUNT] = {
    {
        .adcDIO = Board_ALS_OUT,
        .adcCompBInput = ADC_COMPB_IN_AUXIO7,
        .refSource = ADCCC26XX_FIXED_REFERENCE,
        .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
        .inputScalingEnabled = true,
        .triggerSource = ADCCC26XX_TRIGGER_MANUAL
    },
    {
        .adcDIO = Board_DIO28_ANALOG,
        .adcCompBInput = ADC_COMPB_IN_AUXIO2,
        .refSource = ADCCC26XX_FIXED_REFERENCE,
        .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
        .inputScalingEnabled = true,
        .triggerSource = ADCCC26XX_TRIGGER_MANUAL
    },
    {
        .adcDIO = Board_DIO30_ANALOG,
        .adcCompBInput = ADC_COMPB_IN_AUXIO0,
        .refSource = ADCCC26XX_FIXED_REFERENCE,
        .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
        .inputScalingEnabled = true,
        .triggerSource = ADCCC26XX_TRIGGER_MANUAL
    },
    {
        .adcDIO = PIN_UNASSIGNED,
        .adcCompBInput = ADC_COMPB_IN_VDDS,
        .refSource = ADCCC26XX_FIXED_REFERENCE,
        .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
        .inputScalingEnabled = true,
        .triggerSource = ADCCC26XX_TRIGGER_MANUAL
    }
};

const ADC_Config ADC_config[] = {
    {&ADCCC26XX_fxnTable, &adcCC26xxObjects[0], &adcCC26xxHWAttrs[0]},
    {&ADCCC26XX_fxnTable, &adcCC26xxObjects[1], &adcCC26xxHWAttrs[1]},
    {&ADCCC26XX_fxnTable, &adcCC26xxObjects[2], &adcCC26xxHWAttrs[2]},
    {&ADCCC26XX_fxnTable, &adcCC26xxObjects[3], &adcCC26xxHWAttrs[3]},
    {NULL, NULL, NULL},
};

/*
 *  ========================== ADC end =========================================
 */

希望能有大哥指出小弟哪里出错了!

Bin Hu4:

回复 Felix ZF:

配置是对的,其实程序也是对的。只是读取到的数据自己又做了处理,结果自己看不懂了,太尴尬了。谢谢回复。结帖了。

赞(0)
未经允许不得转载:TI中文支持网 » CC1310 ADC数据读取问题
分享到: 更多 (0)