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.

CC2650: ADC in CC2650

Part Number: CC2650
Other Parts Discussed in Thread: SYSBIOS, CC2640R2F

Hi, Team

Thank you so much for the reply, and sorry for the late reply,

I am trying to implement adc concept using cc2650 using DS600+ but  i have some doubt regarding this 

/*
* Copyright (c) 2016, Texas Instruments Incorporated
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
*
* * Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
*
* * Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
*
* * Neither the name of Texas Instruments Incorporated nor the names of
* its contributors may be used to endorse or promote products derived
* from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
* THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
* PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
* EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

/*
* ======== adcsinglechannel.c ========
*/
/* 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>

/* Driver Header files */
#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 ADC_CONV_MIN_VAL 1200
#define ADC_CONV_MAX_VAL 4095
#define ROOM_TEMP_MIN 2500
#define ROOM_TEMP_MAX 3500
#define ADC_CELCIUS_CONV_CONST 509

/* ADC sample count */
#define ADC_SAMPLE_COUNT (10)

/*Task Specific defines */
#define TASKSTACKSIZE (768)

Task_Struct task0Struct;
Char task0Stack[TASKSTACKSIZE];

/* Pin driver handles */
static PIN_Handle buttonPinHandle;
/* Global memory storage for a PIN_Config table */
static PIN_State buttonPinState;

// Temperature sensor related variables declaration
/* ADC conversion result variables */
uint16_t adcValue1[50]={0};
const float adc_conv_volt_const = 0.293040;
const float adc_cel_conv_const = 6.45;
unsigned long volt = 0;
float cel = 0;
int g_Celsius[50]={0};
/*
* Application button pin configuration table:
* - Buttons interrupts are configured to trigger on falling edge.
*/
PIN_Config buttonPinTable[] = {Board_DIO21 | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,PIN_TERMINATE};


/*
* ======== taskFxn1 ========
* Open a ADC handle and get a array of sampling results after
* calling several conversions.
*/
Void taskFxn0(void)
{
/*board initialization for ADC Pins*/
Board_initADC();
ADC_Handle adc;
ADC_Params params;
int_fast16_t res;

char currVal = 0;
char i = 0;
//clearing the buffer
for(i = 0; i<50; i++)
{
g_Celsius[i] = 0;
adcValue1[i] = 0;
}


PIN_setOutputValue(buttonPinHandle, Board_DIO21, currVal); // for temperature sensor active
ADC_Params_init(&params);
adc = ADC_open(Board_ADC0, &params);


if (adc == NULL)
{
System_abort("Error initializing ADC channel 1\n");
}
else
{
System_printf("ADC channel 1 initialized\n");
}


ADC_close(adc);
}

/*
* ======== main ========
*/
int main(void)
{
Task_Params taskParams;

/* Call board init functions */
Board_initGeneral();

buttonPinHandle = PIN_open(&buttonPinState, buttonPinTable);
if(!buttonPinHandle) {
System_abort("Error initializing button pins\n");
}

/* Create tasks */
Task_Params_init(&taskParams);
taskParams.stackSize = TASKSTACKSIZE;
taskParams.stack = &task0Stack;
Task_construct(&task0Struct, (Task_FuncPtr)taskFxn0, &taskParams, NULL);

/* SysMin will only print to the console when you call flush or exit */
System_flush();

BIOS_start();

return (0);
}

this is my code in this i am not getting accurate result in res = ADC_convert(adc, &adcValue1[i]); but i am getting adcValue1 correctly can you please help me? i am so enthusiastics to learn about it

  • Hello santhosh prem,

    What do you mean by not accurate result in res, but correct in adcValue1?

    Have you conferred with the sensor data sheet?

    https://www.mouser.com/datasheet/2/256/DS600-370326.pdf

  • You should also check the return value:

    int_fast16_t res;
    uint_fast16_t adcValue;
    
    res = ADC_convert(adc, &adcValue);
    if (res == ADC_STATUS_SUCCESS) {
    //use adcValue
    }

    file:///C:/ti/tirtos_cc13xx_cc26xx_2_21_01_08/products/tidrivers_cc13xx_cc26xx_2_21_01_01/docs/doxygen/html/_a_d_c_8h.html#afcac5582b8be42a7740091d150aef05c

  • Hi Eirik,

    Thank you so much for the reply,

    I have tried but there is no return value in this, in ds600 only two pin is connected in the cc2650 one is vout and sd. i have connected sd with DIO21 and another pin with DIO24 it is analog pin but there is return value I got it? i don't why can you please help me

  • Test them separately.

    Test the ADC with known values. There are separate ADC examples for both the TI-Driver and the Sensor controller:

    C:\ti\tirtos_cc13xx_cc26xx_2_21_01_08\examples\TI\CC2650_LAUNCHXL\adcsinglechannel

  • You can also find ADC example online at dev.ti.com/.../node

  • Hi Team,

    Thank you so much for the reply, Now the ADC is working fine but it is working in the reference voltage 4.3 but I need 1.44 reference voltage i tried but can you consider whether it is correct or not

     

    /*
    * Copyright (c) 2016, Texas Instruments Incorporated
    * All rights reserved.
    *
    * Redistribution and use in source and binary forms, with or without
    * modification, are permitted provided that the following conditions
    * are met:
    *
    * * Redistributions of source code must retain the above copyright
    * notice, this list of conditions and the following disclaimer.
    *
    * * Redistributions in binary form must reproduce the above copyright
    * notice, this list of conditions and the following disclaimer in the
    * documentation and/or other materials provided with the distribution.
    *
    * * Neither the name of Texas Instruments Incorporated nor the names of
    * its contributors may be used to endorse or promote products derived
    * from this software without specific prior written permission.
    *
    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
    * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
    * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
    * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
    * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
    * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
    * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
    * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
    * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
    */

    /*
    * ======== display.c ========
    */
    /* XDCtools Header files */
    //#include "ti-lib.h"
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    #include <driverlib/aux_adc.h>
    #include <driverlib/aux_wuc.h>
    #include <ti/drivers/Power.h>
    #include <ti/drivers/power/PowerCC26XX.h>
    #include <xdc/std.h>
    #include <xdc/runtime/System.h>
    /* BIOS Header files */
    #include <ti/sysbios/BIOS.h>
    #include <ti/sysbios/knl/Clock.h>
    #include <ti/sysbios/knl/Task.h>
    /* TI-RTOS Header files */
    #include <ti/drivers/PIN.h>
    #include <ti/mw/display/Display.h>
    #include <ti/mw/display/DisplayExt.h>
    /* Board Header files */
    #include "Board.h"

    /* Example GrLib image */
    #include "splash_image.h"

    #define TASKSTACKSIZE 768

    Task_Struct task0Struct;
    Char task0Stack[TASKSTACKSIZE];

    /* Pin driver handle */
    static PIN_Handle ledPinHandle;
    static PIN_State ledPinState;
    static PIN_State buttonPinState;
    static PIN_Handle buttonPinHandle;
    /*
    * Application LED pin configuration table:
    * - All LEDs board LEDs are off.
    */
    //PIN_Config buttonPinTable[] = {Board_DIO24_ANALOG | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,PIN_TERMINATE};

    //PIN_Config buttonPinTable[] = { Board_DIO24_ANALOG | PIN_INPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL | PIN_DRVSTR_MAX,PIN_TERMINATE};
    /*
    * ======== taskFxn ========
    * Toggle the Board_LED0. The Task_sleep is determined by arg0 which
    * is configured for the heartBeat Task instance.
    */
    uint_fast16_t single_sample=0;
    int ActualTemperature;
    #define ADC_CONV_MIN_VAL 4300 //1440
    #define ADC_CONV_MAX_VAL 4095
    // Temperature sensor related variables declaration
    unsigned long volt=0;
    float cel=0;
    int g_Celsius=0;
    unsigned char g_TempHigh;
    unsigned char g_TempLow;
    const float adc_conv_volt_const = 0.293040;
    const float adc_cel_conv_const = 6.45;
    int Celsius =0;
    //ti_lib_ioc_io_port_pull_set(BOARD_IOID_DIO24, IOC_NO_IOPULL)
    /*
    *
    * ======== main ========
    */
    int i;
    int main(void)
    {
    AUXWUCClockEnable(AUX_WUC_ADI_CLOCK|AUX_WUC_ANAIF_CLOCK|AUX_WUC_MODCLKEN0_AUX_ADI4_M);
    AUXADCSelectInput( ADC_COMPB_IN_AUXIO7 );

    AUXADCDisableInputScaling();//I also tried this but to disable the scaling so that the reference volatge will consider as 1.44 v but it is not working 
    AUXADCEnableSync(AUXADC_REF_FIXED , AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL);
    Power_setConstraint(PowerCC26XX_SB_DISALLOW);
    AUXADCGenManualTrigger();
    single_sample = AUXADCReadFifo();
    volt = single_sample * ADC_CONV_MIN_VAL/ADC_CONV_MAX_VAL;
    cel = ((volt- 509)/adc_cel_conv_const);
    cel +=2; //2 cel is added with the actual measurement to calibrate to LM35s measurement
    cel *= 100; //Multiply by 100 to maintain 2 decimal points when casting to integer
    g_Celsius = (int)cel; //Cast down to integer to send over BLE
    BIOS_start();
    return (0);
    }

  • The correct way of disabling scaling for the TI-RTOS driver is to adjust the inputScalingEnabled varaible in the adcCC26xxHWAttrs which is located in the board file (CC2640R2_LAUNCHXL.c). 

    WARNING: 

    Note that different input maximum ratings apply when input scaling is disabled, and that violating these may damage the device.

  • Hi Eirik, 

    Thank you so much for the reply,

    I got some idea from this 

    .adcDIO = Board_DIO23_ANALOG,
    .adcCompBInput = ADC_COMPB_IN_AUXIO7,
    .refSource = ADCCC26XX_VDDS_REFERENCE ,
    .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
    .inputScalingEnabled = false,//true,
    .triggerSource = ADCCC26XX_TRIGGER_MANUAL

    we need to use these two function 

    AUXADCDisable();
     AUXADCDisableInputScaling();

    if we are using above false/true to disable input scaling

    what is the approximate voltage is given in the microcontroller when we are using 1.44 v reference voltage. can you please suggest me?

  • 1. You should not use driverlib calls when you use the TI-RTOS driver. The driver will use driverlib and the application should use the driver only.

    2. The data is given in the data sheet and users guide. If you apply an input voltage above the reference you might destroy the ADC and/or parts of the chip. Usually we do not recommend anyone to disable input scaling unless you have absolute control over the possible input voltage levels.

  • hi eirik,

    Thank you so much for the reply, I got some idea

    when I read user guide I found three reference voltage in ADC

    1) I gave 5v to my sensor(VDD) I have set the fixed voltage 4.3 it works fine

    2) I gave 3.3 to my sensor(VDD) I have set  the  vdds it works fine

    3) i need to set 1.44 as reference voltage so when I read the user guide they have said you need to disable the input scaling as you said i have disabled true/false in input scaling

    can you say why we are using input scaling you have any idea about it?

  • Hello,

    The input scaling will protect the input from damage as the internal circuitry can get damaged when you have input above the reference. The internal reference will stay the same, but because the input is scaled down it appears to be at 4.3 Volt due to the scaling factor.

    If you have external sensors/devices powered by 3 Volt it seems plausible that output voltage levels from these devices might go higher than 1.44V?

  • Hi eirik,

    Thank you so much for your patient reply, can you give any example code for reference voltage for 1.44 v so it will be more useful please can you provide any example code.

  • The examples already exist here for CC2650:

    C:\ti\tirtos_cc13xx_cc26xx_2_21_01_08\examples\TI\CC2650_LAUNCHXL\adcsinglechannel

    And here for CC2640R2F:

    http://dev.ti.com/tirex/explore/node?node=AEci1l.IYgauB29UR6LoxQ__krol.2c__LATEST 

    And in Sensor Controller Studio for CC26xx.

    You simply change the reference voltage and then you must take care in HW to make sure the input voltage never exceed the maximum input rating.

  • Hi Eirik,

    Thank you so much for the reply, If I am setting reference voltage is 1.44v what is the input voltage that should be given? what is the maximum input rating?

  • If you set reference voltage as 1.44v, the input voltage should between 1.48V and 0V.

  • Hi, yikai,

    finally, I got an answer for this, so when you, set reference voltage 1.44 you should give 1.44 v to cc2650. thank you so much for this reply

  • I mean the input voltage of ADC pin should be between 1.48V and 0V. To give power to CC2650, I suppose you still need to use 3V or 3.3V.