微波EDA网,见证研发工程师的成长!
首页 > 研发问答 > 无线和射频 > TI无线射频设计 > adc通道该怎么切换?求TI大神帮帮忙啊

adc通道该怎么切换?求TI大神帮帮忙啊

时间:12-23 整理:3721RD 点击:

我要采样每支引脚的数据并转换,之前有指点过我可以使用分时复用来切换物理路,但尝试了一下发现,它没有重启下一个的转换,该怎么使用TI提供的ADC中断???如何切换通道并开启下一组转换???麻烦TI大神~~~~~

//adc test
//

#include <stdint.h>
#include <stdio.h>
#include <unistd.h>

#include <ti/drivers/ADCBuf.h>
#include <ti/drivers/UART.h>
#if defined(CC2650DK_7ID) || defined(CC1310DK_7XD)
#include <ti/drivers/PIN.h>
#endif

#include "Board.h"

#define ADCBUFFERSIZE (1)

uint16_t sampleBufferOne[ADCBUFFERSIZE];
uint16_t sampleBufferTwo[ADCBUFFERSIZE];
uint32_t microVoltBuffer[ADCBUFFERSIZE];
uint32_t buffersCompletedCounter = 0;
char uartTxBuffer[(10 * ADCBUFFERSIZE) + 25];


UART_Handle uart;

int c =0; //一组adc转换的次数
int q =0; //第几组/第几pin 做adc转换

void adcBufCallback(ADCBuf_Handle handle, ADCBuf_Conversion *conversion, void *completedADCBuffer, uint32_t completedChannel) {

uint_fast16_t i;
uint_fast16_t uartTxBufferOffset;
ADCBuf_adjustRawValues(handle, completedADCBuffer, ADCBUFFERSIZE, completedChannel);
ADCBuf_convertAdjustedToMicroVolts(handle, completedChannel, completedADCBuffer, microVoltBuffer, ADCBUFFERSIZE);
uartTxBufferOffset = sprintf(uartTxBuffer, "\r\nBuffer %u finished:\r\n", (unsigned int)buffersCompletedCounter++);
for (i = 0; i < ADCBUFFERSIZE; i++)
{
uartTxBufferOffset += sprintf(uartTxBuffer + uartTxBufferOffset, "%u,", (unsigned int)microVoltBuffer[i]);
}
uartTxBuffer[uartTxBufferOffset] = '\n';
UART_write(uart, uartTxBuffer, uartTxBufferOffset + 1);


//********************************************************************
c++;
//转换30次 : 0-29
if(c%30==0)
{
ADCBuf_convertCancel(handle);
ADCBuf_close(handle);
}
//********************************************************************

}

void uartCallback(UART_Handle handle, void *buf, size_t count)
{
return;
}

void *mainThread(void *arg0)
{

UART_Params uartParams;
ADCBuf_Handle adcBuf;
ADCBuf_Params adcBufParams;
ADCBuf_Conversion continuousConversion;
ADCBuf_init();
UART_init();
#if defined(CC2650DK_7ID) || defined(CC1310DK_7XD)
PIN_State pinState;

PIN_Config AlsPinTable[] =
{
Board_ALS_PWR | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, // Turn on ALS power /
PIN_TERMINATE // Terminate list /
};


PIN_open(&pinState, AlsPinTable);
#endif

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);

ADCBuf_Params_init(&adcBufParams);
adcBufParams.callbackFxn = adcBufCallback;
adcBufParams.recurrenceMode = ADCBuf_RECURRENCE_MODE_CONTINUOUS;
adcBufParams.returnMode = ADCBuf_RETURN_MODE_CALLBACK;
adcBufParams.samplingFrequency = 0.2;
adcBuf = ADCBuf_open(CC1310_LAUNCHXL_ADCBUF0, &adcBufParams);

for(q=0;q<8;q++)
{
continuousConversion.arg = NULL; //NULL
continuousConversion.adcChannel = q; //6
continuousConversion.sampleBuffer = sampleBufferOne;
continuousConversion.sampleBufferTwo = sampleBufferTwo;
continuousConversion.samplesRequestedCount = ADCBUFFERSIZE;

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

if (!adcBuf)
{
while(1);
}

if (ADCBuf_convert(adcBuf, &continuousConversion, 1) !=ADCBuf_STATUS_SUCCESS)
{
while(1);
}

while(1)
{
sleep(1000);

}

}
}

重新初始化adc,修改对应的adc引脚。

您好,您说的初始化adc指的是ADCBUF_init()吗?是在void *mainThread(void *arg0)里面初始化吗?

void *threadFxn0(void *arg0)
{
ADC_Handle adc;
ADC_Params params;
int_fast16_t res;

ledPinHandle = PIN_open(&ledPinState, LEDpinTable);
PIN_setOutputValue(ledPinHandle, Board_PIN_LED2,1);

ADC_Params_init(&params);

while(1){

adc = ADC_open(Board_ADC0, &params);

if (adc == NULL) {
Display_printf(display, 0, 0, "Error initializing ADC channel 0\n");
while (1);
}

/* Blocking mode conversion */
res = ADC_convert(adc, &adcValue0);

if (res == ADC_STATUS_SUCCESS) {

adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0);

Display_printf(display, 0, 0, "ADC channel 0 convert result: %d uV\n", adcValue0MicroVolt);
}
else {
Display_printf(display, 0, 0, "ADC channel 0 convert failed\n");
}

ADC_close(adc);
sleep(1);

PIN_setOutputValue(ledPinHandle, Board_PIN_LED2,0);
adc = ADC_open(CC1310_LAUNCHXL_ADC1, &params);

if (adc == NULL) {
Display_printf(display, 0, 0, "Error initializing ADC channel 1\n");
while (1);
}

/* Blocking mode conversion */
res = ADC_convert(adc, &adcValue0);

if (res == ADC_STATUS_SUCCESS) {

adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0);

Display_printf(display, 0, 0, "ADC channel 1 convert result: %d uV\n", adcValue0MicroVolt);
}
else {
Display_printf(display, 0, 0, "ADC channel 1 convert failed\n");
}

ADC_close(adc);
sleep(1);

PIN_setOutputValue(ledPinHandle, Board_PIN_LED2,1);
adc = ADC_open(CC1310_LAUNCHXL_ADC2, &params);

if (adc == NULL) {
Display_printf(display, 0, 0, "Error initializing ADC channel 2\n");
while (1);
}

/* Blocking mode conversion */
res = ADC_convert(adc, &adcValue0);

if (res == ADC_STATUS_SUCCESS) {

adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0);

Display_printf(display, 0, 0, "ADC channel 2 convert result: %d uV\n", adcValue0MicroVolt);
}
else {
Display_printf(display, 0, 0, "ADC channel 2 convert failed\n");
}

ADC_close(adc);
sleep(1);

adc = ADC_open(CC1310_LAUNCHXL_ADC3, &params);

if (adc == NULL) {
Display_printf(display, 0, 0, "Error initializing ADC channel 3\n");
while (1);
}

/* Blocking mode conversion */
res = ADC_convert(adc, &adcValue0);

if (res == ADC_STATUS_SUCCESS) {

adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0);

Display_printf(display, 0, 0, "ADC channel 3 convert result: %d uV\n", adcValue0MicroVolt);
}
else {
Display_printf(display, 0, 0, "ADC channel 3 convert failed\n");
}

ADC_close(adc);
sleep(1);
}

return (NULL);
}

以上这段代码是4通道单次采样最简单的实现方式,基于例程adcsinglechannel改的。

HI:Choret Longer

谢谢您的分享!

Copyright © 2017-2020 微波EDA网 版权所有

网站地图

Top