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.

RTOS/CC2650EM-7ID-RD: Troubles using ADC

Part Number: CC2650EM-7ID-RD
Other Parts Discussed in Thread: CC2650, SYSBIOS

Tool/software: TI-RTOS

Hello everyone, 

I am still a beginner with microcontroller and programming, so I need your help : 

My final goal is to implement a capacitive sensor using the CC2650. So I need to perform a DCVD (Differential Capacitive Voltage Divider) measurement with the CC2650. 
The principle of this measurement is to charge, share the charge, measure the voltage and discharge the capacitor. By doing this twice (the second time the other way around), we do the DCVD method. 

Then, I thought that my program worked (everything was as expected looking at this oscilloscope) but when I have displayed a graph representif my variable "Mesure DCVD", I have seen that my two ADCs do not measure anything. 

Could you please tell me what is wrong with my program ? Here it is : 

/*********************DCVD.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>
#include <ti/sysbios/knl/Clock.h>

/* TI-RTOS Header files */
#include <ti/drivers/ADCBuf.h>
#include <ti/drivers/UART.h>
#include <ti/drivers/ADC.h>

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

/* Example/Board Header files */
#include "Board.h"

#define TASKSTACKSIZE1 (768)

Task_Struct task1Struct;
Char task1Stack[TASKSTACKSIZE1];
//Clock_tickPeriod

/* Driver handle shared between the task and the callback function */
UART_Handle UART;
ADC_Handle ADC;


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


// ======== Mesure DCVD ========
//Task for this function is created statically. See the project's .cfg file.

void Fxn1(UArg arg0, UArg arg1) {

ADC_Handle ADC;
ADC_Params ADCParams;

PIN_Handle PIN;
UART_Params UARTParams;

uint16_t MesureADCRaw1, MesureADC1;
uint16_t MesureADCRaw2, MesureADC2;

int Ref = 1000000;
int i;
int MesureDCVD ;
char bufADC[7];

/* 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;
UARTParams.readReturnMode = UART_RETURN_NEWLINE;

#if defined(CC2650DK_7ID) || defined(CC1310DK_7XD)
PIN_State pinState;

// Pins configuration
PIN_Config PinTable[] =
{
Board_3V3_EN | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, // Turn on 3.3V power
Board_DIO26_ANALOG |PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL, // Pin UNLOCK to 1 (CAPA)
Board_DIO28_ANALOG |PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL, // Pin Cext to 1
PIN_TERMINATE // Terminate list
};


/* Turn on the power */
PIN = PIN_open(&pinState, PinTable);
#endif


while(1){
PIN_setOutputValue(PIN, Board_DIO28_ANALOG, 1);
PIN_setOutputValue(PIN, Board_DIO26_ANALOG, 1);


// Wait 25µs
i=0;
while (i!=84){i++;}

// Pin config : UNLOCK to input et Cext to 0

PIN_setConfig(PIN, PIN_BM_INPUT_EN, Board_DIO26_ANALOG | PIN_INPUT_EN);
PIN_setConfig(PIN, PIN_BM_GPIO_OUTPUT_EN, Board_DIO26_ANALOG | PIN_GPIO_OUTPUT_DIS);

PIN_setOutputValue(PIN, Board_DIO28_ANALOG, 0);

// Wait 14µs
i=0;
while (i!=38){i++;}


// Set up an ADC peripheral
ADC_Params_init(&ADCParams);

ADC = ADC_open(Board_ADC0, &ADCParams);
if (!ADC){
System_abort("ADC did not open correctly\n");
}

//Start converting 1
ADC_convert(ADC, &MesureADCRaw1);
MesureADC1 = ADC_convertRawToMicroVolts (ADC, MesureADCRaw1);


// Pin config : UNLOCK to 0
PIN_setOutputValue(PIN, Board_DIO26_ANALOG, 0);
PIN_setConfig(PIN, PIN_BM_INPUT_EN, Board_DIO26_ANALOG | PIN_INPUT_DIS);
PIN_setConfig(PIN, PIN_BM_GPIO_OUTPUT_EN, Board_DIO26_ANALOG | PIN_GPIO_OUTPUT_EN);

// Wait 25µs
i=0;
while (i!=84){i++;}

// Pin config : UNLOCK à Input et Cext to 1

PIN_setConfig(PIN, PIN_BM_GPIO_OUTPUT_EN, Board_DIO26_ANALOG | PIN_GPIO_OUTPUT_DIS);
PIN_setConfig(PIN, PIN_BM_INPUT_EN, Board_DIO26_ANALOG | PIN_INPUT_EN);

PIN_setOutputValue(PIN, Board_DIO28_ANALOG, 1);

// Wait 14µs
i=0;
while (i!=38){
i++;
}

//Start converting 2
ADC_convert(ADC, &MesureADCRaw2);
MesureADC2 = ADC_convertRawToMicroVolts (ADC, MesureADCRaw2);

ADC_close(ADC);

// Pin config : UNLOCK & Cext to 0
PIN_setConfig(PIN, PIN_BM_INPUT_EN, Board_DIO26_ANALOG | PIN_INPUT_DIS);
PIN_setConfig(PIN, PIN_BM_GPIO_OUTPUT_EN, Board_DIO26_ANALOG | PIN_GPIO_OUTPUT_EN);
PIN_setOutputValue(PIN, Board_DIO26_ANALOG, 0);

PIN_setOutputValue(PIN, Board_DIO28_ANALOG, 0);

// Wait 14µs
i=0;
while (i!=38){
i++;
}

// Calcul DCVD
MesureDCVD = Ref + MesureADC2 - MesureADC1;

System_sprintf(bufADC, "%d", MesureDCVD);


// Send out the data via UART
UART = UART_open (Board_UART0, &UARTParams);
UART_write(UART, bufADC, 7);

i=0;
while (i!=500){
i++;
}

UART_close(UART);

}

}


// Callback function to use the UART in callback mode. It does nothing.

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


// main.c

int main(void) {

Task_Params taskParams;

// Board init functions
Board_initGeneral();
Board_initUART();
ADC_init();

// Construct BIOS objects
Task_Params_init(&taskParams);
taskParams.stackSize = TASKSTACKSIZE1;
taskParams.stack = &task1Stack;
Task_construct(&task1Struct, (Task_FuncPtr) Fxn1, &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);
}