Tool/software: Code Composer Studio
Hi,
I'm trying to use the TI-RTOS ADC driver to read battery voltage. Analog input DIO07 of the CC2640 is connected to a voltage divider circuit directly from the battery.
I've implemented the ADC definition in the board definition files:
Board Specific header file CC2640_5XD.h:
/*! * @def CC2650DK_7ID_ADCName * @brief Enum of ADCs */ typedef enum CC2650DK_5XD_ADCName { CC2650DK_5XD_ADCVDDS = 0, CC2650DK_5XD_ADCCOUNT } CC2650DK_5XD_ADCName;
Board source file CC2640_5XD.c:
/* * ========================== ADC begin ========================================= */ /* Place into subsections to allow the TI linker to remove items properly */ #if defined(__TI_COMPILER_VERSION__) #pragma DATA_SECTION(ADC_config, ".const:ADC_config") #pragma DATA_SECTION(adcCC26xxHWAttrs, ".const:adcCC26xxHWAttrs") #endif /* Include drivers */ #include <ti/drivers/ADC.h> #include <ti/drivers/adc/ADCCC26XX.h> /* ADC objects */ ADCCC26XX_Object adcCC26xxObjects[CC2650DK_5XD_ADCCOUNT]; const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC2650DK_5XD_ADCCOUNT] = { { .adcDIO = IOID_7, .adcCompBInput = ADC_COMPB_IN_VDDS, .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]}, {NULL, NULL, NULL}, }; /* * ========================== ADC end ========================================= */
Board.h:
#define Board_ADC0 CC2650DK_5XD_ADCVDDS #define Board_initADC() ADC_init()
The main application task initialized the ADC driver by calling Board_initADC().
The ADC CC26XX header file is included in an application as follows:
#include <ti/drivers/ADC.h> #include <ti/drivers/adc/ADCCC26XX.h>
The following function is called to read the current voltage level on DIO07 analog input:
static void multi_role_readBattVoltage() { ADC_Handle adc; ADC_Params params; int_fast16_t res; uint16_t adcValue0; ADC_Params_init(¶ms); adc = ADC_open(Board_ADC0, ¶ms); if (adc == NULL) { return; } /* Blocking mode conversion */ res = ADC_convert(adc, &adcValue0); if (res == ADC_STATUS_SUCCESS) { batteryVoltage = adcValue0; //voltage = ADC_convertRawToMicroVolts(ADC0Handle, temp); //voltage = (voltage/1000) * ((R1+R2)/R2); } ADC_close(adc); }
An ADC value is read successfully but I'm not sure if it actually is the current input voltage level.
I'm wondering if the ADC driver is implemented correctly for a CC2640 5XD chip and how the voltage level need to be calculated?
It's using the internal fixed voltage reference (4.3V) with input scaling enabled. In this mode, the output is a function of the input voltage multiplied
by the resolution in alternatives divided by the upper voltage range of the ADC. Output = Input (V) * 2^12 / (ADC range (V)).
Do I need to use this calculation or the ADC_convertRawToMicroVolts() function?
Thanks.
Using:
BLE stack v2.2.2
RTOS v2.21.1.08