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.

CCS/CC2640: ADC example not working on CC2640

Part Number: CC2640
Other Parts Discussed in Thread: CC2650

Tool/software: Code Composer Studio

I have used DIO_8 pin as ADC pin in my code and i am trying to read ADC value from that pin but adc is not working it showing random values. I want to understand two things.

What is the reference voltage that the adc is using?

How to check if pin is correctly mapped to adc or not?

please if anybody can solve this please do reply.

Smriti

  • Which chip model do you use? 7x7, 5x5, or 4x4?
  • The ADC reference voltage is 4,.3V and you have to make sure to define DIO_8 as ADC pin in your board file.

  • i have done both the things
  • I don't use 5x5 so cannot help further.
  • Hey YK Chen,

    My bluetooth receive code is not working on CC2640 MCU can you help me with this?

    Smriti
  • I test my CC2650EM-5XD to run ADC example at dev.ti.com/.../ . After I revise the following board files, I can read ADC from DIO_7 without problem.

    1. Change BoardGpioInitTable[] in CC2650_LAUNCHXL.c

    const PIN_Config BoardGpioInitTable[] = {

    Board_RLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
    Board_GLED | PIN_GPIO_OUTPUT_EN | PIN_GPIO_LOW | PIN_PUSHPULL | PIN_DRVSTR_MAX, /* LED initially off */
    Board_UART_RX | PIN_INPUT_EN | PIN_PULLDOWN, /* UART RX via debugger back channel */
    Board_UART_TX | PIN_GPIO_OUTPUT_EN | PIN_GPIO_HIGH | PIN_PUSHPULL, /* UART TX via debugger back channel */

    PIN_TERMINATE
    };

    2. Change Board_GLED and Board_DIO23_ANALOG define in CC2650_LAUNCHXL.h

    ...
    #define Board_GLED IOID_6
    ...
    #define Board_DIO23_ANALOG IOID_7
    ...

    3. Change Board_ADC1 define in Board.h
    #define Board_ADC1 CC2650_LAUNCHXL_ADC0
  • Hi,

    I will look into this and reply back to you.

    Smriti
  • Hi YK Chen,

    I don't understand what do you exactly want me to do.
    Why do we need to change board pin table.
    why have you mapped ADC1 to ADC0.

    Also what i am facing is i have mapped Dio_8 to AUX6 and DIO_10 to AUX1 but i don't know why when i connect di08 then i am getting value in my adc. when i connect dio10 i am getting value in adc used by dio8.

    Smriti
  • Hi YK,

    adc is not showing value and also one adc value is coming in other adc.
  • Also YK Chen,

    I want to use 5 adc pins what should i do for that.

    Smriti
  • I have show you how to use DIO 7 as ADC input and you should be able to do others accordingly.
  • const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC2650DK_7ID_ADCCOUNT] = {
       {
            .adcDIO = Board_DIO8_ANALOG,                                       //battery voltage
            .adcCompBInput = ADC_COMPB_IN_AUXIO6,                                  //ADC1
            .refSource =   ADCCC26XX_FIXED_REFERENCE,
            .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
            .inputScalingEnabled = true,
            .triggerSource = ADCCC26XX_TRIGGER_MANUAL
        },
        {
            .adcDIO = Board_DIO9_ANALOG,                                        //ADC2
            .adcCompBInput = ADC_COMPB_IN_AUXIO4,
            .refSource = ADCCC26XX_FIXED_REFERENCE,
            .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
            .inputScalingEnabled = true,
            .triggerSource = ADCCC26XX_TRIGGER_MANUAL
        },
        {
            .adcDIO = Board_DIO10_ANALOG,                                      //ADC3
            .adcCompBInput = ADC_COMPB_IN_AUXIO0,
            .refSource = ADCCC26XX_FIXED_REFERENCE,
            .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
            .inputScalingEnabled = true,
            .triggerSource = ADCCC26XX_TRIGGER_MANUAL
        },
        {
            .adcDIO = Board_DIO12_ANALOG,                                     //ADC4
            .adcCompBInput = ADC_COMPB_IN_AUXIO2,
            .refSource = ADCCC26XX_FIXED_REFERENCE,
            .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
            .inputScalingEnabled = true,
            .triggerSource = ADCCC26XX_TRIGGER_MANUAL
        },
       {
              .adcDIO = Board_DIO13_ANALOG,                                //ADC5
              .adcCompBInput = ADC_COMPB_IN_AUXIO3,
              .refSource = ADCCC26XX_FIXED_REFERENCE,
              .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
              .inputScalingEnabled = true,
              .triggerSource = ADCCC26XX_TRIGGER_MANUAL
          }
    };
    const ADC_Config ADC_config[] = {
        {&ADCCC26XX_fxnTable, &adcCC26xxObjects[0], &adcCC26xxHWAttrs[0]},
        {&ADCCC26XX_fxnTable, &adcCC26xxObjects[1], &adcCC26xxHWAttrs[1]},
        {&ADCCC26XX_fxnTable, &adcCC26xxObjects[2], &adcCC26xxHWAttrs[2]},
        {&ADCCC26XX_fxnTable, &adcCC26xxObjects[3], &adcCC26xxHWAttrs[3]},
        {&ADCCC26XX_fxnTable, &adcCC26xxObjects[4], &adcCC26xxHWAttrs[4]},
        {NULL, NULL, NULL},
    };
    please see this

    Hi YK Chen,

    i have done the same way. but i am not able to see any value.

  • please look into this.
  • You don't have to change adcCC26xxHWAttrs. You should define the following ADC pins which is for 5x5 packages.

    #define Board_DIO23_ANALOG IOID_7
    #define Board_DIO24_ANALOG IOID_8
    #define Board_DIO25_ANALOG IOID_9
    #define Board_DIO26_ANALOG IOID_10
    #define Board_DIO27_ANALOG IOID_11
    #define Board_DIO28_ANALOG IOID_12
    #define Board_DIO29_ANALOG IOID_13
    #define Board_DIO30_ANALOG IOID_14

    When you want to use DIO_7 as ADC input, you just need to use ADC_open(CC2650_LAUNCHXL_ADC0, &params), in which CC2650_LAUNCHXL_ADC0 is mapped to DIO_7

    When you want to use DIO_8 as ADC input, you just need to use ADC_open(CC2650_LAUNCHXL_ADC1, &params), in which CC2650_LAUNCHXL_ADC1 is mapped to DIO_8

    And you can use DIO_9, DIO_10, or other ADC pings accordingly.
  • Hi YK Chen,

    I did what you told me to.

    I have connected my battery at IO8 which is mapped to aux6 and charger to IO10 which is mapped to aux5. i saw pin mapping to aux mapping in SCS.
    when i connect my battery to IO8 to see it's reading. i can see the value in charger adc also. and also when i connect my charger to IO10 to see it's reading i can see the result in battery adc also. When i connect both then i see charger voltage in both adcs. Can you tell me why is this happening. why adc result of one is shown in both the adc.

    Please look into this.

    Smriti
  • I couldn't understand your descriptions.
  • I have connected my battery to IO8 and charger to IO10.
    I have two variable bat_volt and charger_volt to tell me adc measured values repectively.
    Now, when i open debug to see my adc values, i see charger voltage in both bat_volt and charger_volt.
    when i disconnect charger and connect battery only my chrger voltage should be zero but i see battery voltage in both the variables.
    when i disconnect battery and connect charger only, my bat_volt should be zero but i see charger voltage in both the variables.
  • can you please look into this and tell me what is the problem
  • If you connect DIO 10 to GND and disconnect charger, do you still see the same issue?
  • If i don't connect charger and i don't connect battery then the value on both adc is zero
  • Also when i connect charger and battery both i get charger voltage in both the adcs
  • Hi YK chen,
    please look into this it is urgently required.

    Smriti
  • I cannot access to my EVB this week so I cannot help you. To me, this seems a sw issue so I suggest you to check your code thoroughly.
  • i have mapped the pins to aux pins in the way given in SCS, i have called ADC_open and ADC_convert of both adcs together at one place can that cause any problem.
  • Do you use ADC from sensor controller or from CC2650 Cortex-M3?
  • No I use it in ccs. i just saw aux mapping in SCS to confirm my pins are mapped correctly.
  • Can you show me your code?
  • code-

    const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC2650DK_7ID_ADCCOUNT] = {
       {
            .adcDIO = Board_DIO8_ANALOG,
            .adcCompBInput = ADC_COMPB_IN_AUXIO6,
            .refSource =   ADCCC26XX_FIXED_REFERENCE,
            .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
            .inputScalingEnabled = true,
            .triggerSource = ADCCC26XX_TRIGGER_MANUAL
        },
        {
            .adcDIO = Board_DIO9_ANALOG,
            .adcCompBInput = ADC_COMPB_IN_AUXIO4,
            .refSource = ADCCC26XX_FIXED_REFERENCE,
            .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
            .inputScalingEnabled = true,
            .triggerSource = ADCCC26XX_TRIGGER_MANUAL
        },
        {
            .adcDIO = Board_DIO10_ANALOG,
            .adcCompBInput = ADC_COMPB_IN_AUXIO5,
            .refSource = ADCCC26XX_FIXED_REFERENCE,
            .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
            .inputScalingEnabled = true,
            .triggerSource = ADCCC26XX_TRIGGER_MANUAL
        },
        {
            .adcDIO = Board_DIO12_ANALOG,
            .adcCompBInput = ADC_COMPB_IN_AUXIO2,
            .refSource = ADCCC26XX_FIXED_REFERENCE,
            .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
            .inputScalingEnabled = true,
            .triggerSource = ADCCC26XX_TRIGGER_MANUAL
        },
       {
              .adcDIO = Board_DIO13_ANALOG,
              .adcCompBInput = ADC_COMPB_IN_AUXIO1,
              .refSource = ADCCC26XX_FIXED_REFERENCE,
              .samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
              .inputScalingEnabled = true,
              .triggerSource = ADCCC26XX_TRIGGER_MANUAL
          }
    };
    

    #include "string.h"
    #include "fitbelt_init.h"
    #include "stdio.h"
    #include "battery_service.h"
    //#include "serv_adc.h"
    
    /*  macro -------------------------------------------------------------*/
    #define VDDA 4300
    /*  variables ---------------------------------------------------------*/
    uint8_t Bat_Per;
    uint32_t bat_volt;
    uint32_t bat_adc_volt;
    uint32_t prev_bat_adc_volt=0;
    uint32_t charger_volt;
    uint32_t charger_adc_volt;
    uint32_t prev_charger_adc_volt=0;
    unsigned int battery_debounce_counter;
    void get_battery_voltage( void );
    #define COUNT12BIT 4095
    
    int_fast16_t status_bat_read;
    int_fast16_t status_charger_read;
    
    uint16_t g_batsamp;
    uint16_t g_chargervoltsamp;
    
    
    
    /**
      * @Function Name:read_battery_charger_voltage
      * @brief    : Function to give battery status in %
      * @param IN :BatPer-->address for battery status variable
      * @param OUT:returns battery status
      * @retval : none
      */
    //ADC_convert(BatteryVolt_ADC, &adcValue1);
    
    void read_battery_charger_voltage( void ) //To read the voltage input from battery and charger ADC.
    {
            ADC_Params   params1,params2;
            ADC_Params_init(&params1);
            ADC_Params_init(&params2);
    
            BatteryVolt_ADC=   ADC_open(Board_ADC1,&params1);
    
    
        status_bat_read=ADC_convert(BatteryVolt_ADC, &g_batsamp);
    
        Task_sleep(100);
    
        ADC_close(BatteryVolt_ADC);
    
        Task_sleep(100);
    
        ChargerVolt_ADC=   ADC_open(Board_ADC3,&params2);
    
        Task_sleep(100);
    
        status_charger_read= ADC_convert(ChargerVolt_ADC, &g_chargervoltsamp);
    
        Task_sleep(100);
    
        //if( (status_bat_read == ADC_STATUS_SUCCESS ) || (status_charger_read == ADC_STATUS_SUCCESS ) )
        {
        bat_adc_volt = prev_bat_adc_volt + ( ( VDDA / COUNT12BIT ) * ( g_batsamp ) );   //battery adc voltage
        prev_bat_adc_volt = bat_adc_volt;
    
        charger_adc_volt =prev_charger_adc_volt + ( ( VDDA / COUNT12BIT ) * ( g_chargervoltsamp ) );   //battery adc voltage
        prev_charger_adc_volt =charger_adc_volt;
    
        battery_debounce_counter++;
        }
        if( battery_debounce_counter ==BAT_DEBOUNCE_COUNT )
            {
            //Battery percentage is calculated every 250ms avg is taken of total of 30*5*50 samples
            bat_adc_volt =bat_adc_volt /BAT_DEBOUNCE_COUNT;
            bat_volt =( ( bat_adc_volt ) * GAIN_BAT );                  // Actual battery voltage
    
            Bat_Per =( uint8_t )( ( bat_volt*B_STAT_M ) - B_STAT_C ); //Battery percentage from battery voltage
            prev_bat_adc_volt =0;
            battery_debounce_counter =0;
    
            /*------For charger voltage reading--------------------------------*/
            charger_adc_volt =charger_adc_volt /BAT_DEBOUNCE_COUNT;
            charger_volt =( ( charger_adc_volt ) * GAIN_BAT );                  // Actual battery voltage
           // charger_volt =( charger_volt + DIODE_DROP );                  //Add diode drop
            prev_charger_adc_volt =0;
          }
    
    
        ADC_close(ChargerVolt_ADC);
    
    }

    #include "temp_service.h"
    #include "fitbelt_init.h"
    
     int_fast16_t res;
    uint16_t temp_samp;
    float LiveTemp,var=0;
    
    
    void service_temperarture_adc(void )
    {
        ADC_Params   params;
        ADC_Params_init(&params);
    
        TempSensor_adc =   ADC_open(Board_ADC4, &params);
    
       res = ADC_convert(TempSensor_adc, &temp_samp);
       if (res == ADC_STATUS_SUCCESS)
       {
       // System_printf("ADC channel 0 convert result: 0x%x\n", adcValue0);
        var= (temp_samp*4.3)/4095;
        LiveTemp= (var*1000)/20;
        }
        else
        {
        // System_printf("ADC channel 0 convert failed\n");
        }
    
        ADC_close(TempSensor_adc);
    
        //System_flush();
    }
    

  • these are the functions which i have called to read adc values.
  • Do you do battery charger reading and temperature reading in two different tasks? If so, do you use resource mutext to avoid ADC been called at the same time from two different task?
  • no they are not in different task. i get temp value correctly. the problem that is happening is i get batterey voltage in both bat_volt and charger_volt.
  • How do you use read_battery_charger_voltage and service_temperarture_adc in your application?
  • I call them directly in main
  • is that wrong to do so
  • You should use ADC in a task.
  • I did that also there is no effect. I made one task and converted all values in that. but there was no effect effect
  • can aux6 and aux5 be internally short.
  • I don’t think so. If you try other ADC pins, do you see similar issue?
  • no problem is only in aux5 and aux6
  • If there’s no problem on other ADC pins, I suggest you to use others instead of AUX5&6.
  • but on my pcb i have battery input in DIO8 which is mapped to aux6 and charger input on DIO10 which is on aux5. I can't change it.
  • I cannot help you for now since I cannot access to my development kits.
  • I had tried to help you in your another similar post.