Other Parts Discussed in Thread: SYSBIOS
Tool/software: TI-RTOS
Hi there,
I downloaded the adc continuous sampling code from CCS. But I am not sure what is the pin that it assigned. Since I am not sure, I hard code a DIO23 to the code, like below
* ======== adcBufContinuousSampling.c ========
*/
#include <stdint.h>
/* XDCtools Header files */
#include <xdc/std.h>
#include <xdc/runtime/System.h>
/* BIOS Header files */
#include <ti/sysbios/BIOS.h>
#include <ti/sysbios/knl/Task.h>
/* TI-RTOS Header files */
#include <ti/drivers/ADCBuf.h>
#include <ti/drivers/UART.h>
//#if defined(CC2650DK_7ID) || defined(CC1310DK_7XD)
//#include <ti/drivers/PIN.h>
//#endif
/* Example/Board Header files */
#include "Board.h"
#define TASKSTACKSIZE (768)
#define ADCBUFFERSIZE (100)
#define Board_ALS_PWR IOID_23
Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];
uint16_t sampleBufferOne[ADCBUFFERSIZE];
uint16_t sampleBufferTwo[ADCBUFFERSIZE];
uint32_t microVoltBuffer[ADCBUFFERSIZE];
uint32_t buffersCompletedCounter = 0;
char uartTxBuffer[(10 * ADCBUFFERSIZE) + 25];
/* Driver handle shared between the task and the callback function */
UART_Handle uart;
/*
* This function is called whenever a buffer is full.
* The content of the buffer is then converted into human-readable format and
* sent to the PC via UART.
*
*/
void adcBufCallback(ADCBuf_Handle handle, ADCBuf_Conversion *conversion,
void *completedADCBuffer, uint32_t completedChannel) {
uint_fast16_t i;
uint_fast16_t uartTxBufferOffset;
/* Adjust raw adc values and convert them to microvolts */
ADCBuf_adjustRawValues(handle, completedADCBuffer, ADCBUFFERSIZE,
completedChannel);
ADCBuf_convertAdjustedToMicroVolts(handle, completedChannel,
completedADCBuffer, microVoltBuffer, ADCBUFFERSIZE);
/*
* Start with a header message and convert each entry in the current buffer
* to a human-readable format
*/
uartTxBufferOffset = System_sprintf(uartTxBuffer,
"\r\nBuffer %u finished:\r\n", buffersCompletedCounter++);
for (i = 0; i < ADCBUFFERSIZE; i++) {
uartTxBufferOffset += System_sprintf(uartTxBuffer + uartTxBufferOffset,
"%u,", microVoltBuffer[i]);
}
uartTxBuffer[uartTxBufferOffset] = '\n';
/* Send out the data via UART */
UART_write(uart, uartTxBuffer, uartTxBufferOffset + 1);
}
/*
* Callback function to use the UART in callback mode. It does nothing.
*/
void uartCallback(UART_Handle handle, void *buf, size_t count) {
return;
}
/*
* ======== conversionStartFxn ========
* Task for this function is created statically. See the project's .cfg file.
*/
void conversionStartFxn(UArg arg0, UArg arg1) {
UART_Params uartParams;
ADCBuf_Handle adcBuf;
ADCBuf_Params adcBufParams;
ADCBuf_Conversion continuousConversion;
/*
* The CC2650DK_7ID and CC1310DK_7XD measure an ambient light sensor in this example.
* It is not powered by default to avoid high current consumption in other examples.
* The code below turns on the power to the sensor.
*/
PIN_State pinState;
PIN_Config AlsPinTable[] =
{
Board_ALS_PWR | PIN_INPUT_DIS | PIN_GPIO_OUTPUT_DIS, /* Turn on ALS power */
PIN_TERMINATE /* Terminate list */
};
/* Turn on the power to the ambient light sensor */
PIN_open(&pinState, AlsPinTable);
/* 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);
/* 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 = 200;
adcBuf = ADCBuf_open(Board_ADCBuf0, &adcBufParams);
/* Configure the conversion struct */
continuousConversion.arg = NULL;
continuousConversion.adcChannel = Board_ADCBufChannel0;
continuousConversion.sampleBuffer = sampleBufferOne;
continuousConversion.sampleBufferTwo = sampleBufferTwo;
continuousConversion.samplesRequestedCount = ADCBUFFERSIZE;
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);
}
/*
* ======== main ========
*/
int main(void) {
Task_Params taskParams;
/* Call board init functions */
Board_initGeneral();
Board_initADCBuf();
Board_initUART();
/* Construct BIOS objects */
Task_Params_init(&taskParams);
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr) conversionStartFxn,
&taskParams, NULL);
System_printf("Starting the ADC Continuous Sampling example\n"
"System provider is set to SysMin. Halt the target to view any SysMin "
"contents in ROV.\n");
/* SysMin will only print to the console when you call flush or exit */
System_flush();
/* Start BIOS */
BIOS_start();
return (0);
}
And I didnt change the other code from the example. But the data I got are:
3323440
3325536
3322400
3322400
3324496
3324496
3322400
3323440
3323440
3322400
3323440
3325536
3325536
3323440
3323440
3323440
3323440
3323440
3324496
3322400
3325536
3325536
3324496
3321344
3322400
3324496
I understand it is micro volt, but I am putting a sine wave in (0V to 3V). this number represents 3.3V all the time, even when I disconnect DIO23.
So i am wondering where does this value comes from. in the single channel example, I understand that the adcValue comes from singleSample = AUXADCReadFifo();
but I didnt see any similar read function in the continuous sampling code.
Thank you soooo much in advanced.
Cyan