我想问一下如何写出ADC的分时复用,我要用来量测不同引脚/物理路的连续AD值
我用的是CC1310 LAUNCHPAD,文挡是用ADCBUF……
我遇到的问题大致有:
1. continuousConversion.adcChannel = 1 //通道-对应引脚
这个参数是建构在continuousConversion里面,那我到底该怎么更新这个参数?在哪里更新?来改变采样引脚
2. 我的想法是采样30个AD值后,便切换引脚,但我只能让他采样完30个数字后转换停止,无法切换到下个引脚,
我的程式该怎么写,求助~~~~
//****************************************************************************
//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);
}
//********************************************************************
}
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);
continuousConversion.arg = NULL; //NULL
continuousConversion.adcChannel = q; //6
continuousConversion.sampleBuffer = sampleBufferOne;
continuousConversion.sampleBufferTwo = sampleBufferTwo;
continuousConversion.samplesRequestedCount = ADCBUFFERSIZE;
//********************************************************************
for(q=0;q<7;q++)
{
ADCBuf_convert(adcBuf, &continuousConversion, 1);
//while(ADCBuf_convertCancel(adcBuf))
}
//********************************************************************
while(1)
{
sleep(1000);
}
}
user151383853:
你应该尽量使用硬件的功能,
简单的, 可考虑使用 ADC 中断, 这中断服务中切换通道再启动.
当然, 还可以使用事件触发, 加 FIFO 或者 DMA 来实现连续转换
hoya:
回复 user151383853:
HI Airwill:
我有尝试使用adc中断,但它的通道参数没有被切换到,如我问题1所述,我不知道是否是因为我中断指令或开启转换的写错位置了,导致没有启动到,
所以我想知道如何使用adc中断并切换通道
hoya:
回复 hoya:
有人可以回答我的问题么