Other Parts Discussed in Thread: CC1310
Tool/software:
res = ADC_convert(adc, &adcValue0);
adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0);
Can I use the gain and offset parameters of the ADC to correct the error?
Tool/software:
res = ADC_convert(adc, &adcValue0);
adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0);
Can I use the gain and offset parameters of the ADC to correct the error?
When you are using the ADC driver in the SDK you are already using the gain/offset compensation factors stored in FCFG1.
Also see the following post on things that can cause errors in your reading.
Siri
I want the DIO9 pin of 4*4 1310 as the ADC input to measure the VDDS connection battery voltage, how should I set it? here is my code.
/* Analog capable DIOs */
#define CC1310_LAUNCHXL_DIO23_ANALOG IOID_9// IOID_23
#define CC1310_LAUNCHXL_DIO24_ANALOG IOID_24
#define CC1310_LAUNCHXL_DIO25_ANALOG IOID_25
#define CC1310_LAUNCHXL_DIO26_ANALOG IOID_26
#define CC1310_LAUNCHXL_DIO27_ANALOG IOID_27
#define CC1310_LAUNCHXL_DIO28_ANALOG IOID_28
#define CC1310_LAUNCHXL_DIO29_ANALOG IOID_29
#define CC1310_LAUNCHXL_DIO30_ANALOG IOID_30
#include "adc.h"
#include "gpio.h"
/*
* =============================== ADCBuf ===============================
*/
#include <ti/drivers/ADCBuf.h>
#include <ti/drivers/adcbuf/ADCBufCC26XX.h>
ADCBufCC26XX_Object adcBufCC26xxObjects[CC1310_LAUNCHXL_ADCBUFCOUNT];
/*
* This table converts a virtual adc channel into a dio and internal analogue
* input signal. This table is necessary for the functioning of the adcBuf
* driver. Comment out unused entries to save flash. Dio and internal signal
* pairs are hardwired. Do not remap them in the table. You may reorder entire
* entries. The mapping of dio and internal signals is package dependent.
*/
const ADCBufCC26XX_AdcChannelLutEntry ADCBufCC26XX_adcChannelLut[CC1310_LAUNCHXL_ADCBUF0CHANNELCOUNT] = {
{CC1310_LAUNCHXL_DIO23_ANALOG, ADC_COMPB_IN_AUXIO3}, //ADC_COMPB_IN_AUXIO7
{CC1310_LAUNCHXL_DIO24_ANALOG, ADC_COMPB_IN_AUXIO6},
{CC1310_LAUNCHXL_DIO25_ANALOG, ADC_COMPB_IN_AUXIO5},
{CC1310_LAUNCHXL_DIO26_ANALOG, ADC_COMPB_IN_AUXIO4},
{CC1310_LAUNCHXL_DIO27_ANALOG, ADC_COMPB_IN_AUXIO3},
{CC1310_LAUNCHXL_DIO28_ANALOG, ADC_COMPB_IN_AUXIO2},
{CC1310_LAUNCHXL_DIO29_ANALOG, ADC_COMPB_IN_AUXIO1},
{CC1310_LAUNCHXL_DIO30_ANALOG, ADC_COMPB_IN_AUXIO0},
{PIN_UNASSIGNED, ADC_COMPB_IN_VDDS},
{PIN_UNASSIGNED, ADC_COMPB_IN_DCOUPL},
{PIN_UNASSIGNED, ADC_COMPB_IN_VSS},
};
const ADCBufCC26XX_HWAttrs adcBufCC26xxHWAttrs[CC1310_LAUNCHXL_ADCBUFCOUNT] = {
{
.intPriority = ~0,
.swiPriority = 0,
.adcChannelLut = ADCBufCC26XX_adcChannelLut,
}
};
const ADCBuf_Config ADCBuf_config[CC1310_LAUNCHXL_ADCBUFCOUNT] = {
{
&ADCBufCC26XX_fxnTable,
&adcBufCC26xxObjects[CC1310_LAUNCHXL_ADCBUF0],
&adcBufCC26xxHWAttrs[CC1310_LAUNCHXL_ADCBUF0]
},
};
const uint_least8_t ADCBuf_count = CC1310_LAUNCHXL_ADCBUFCOUNT;
/*
* =============================== ADC ===============================
*/
#include <ti/drivers/ADC.h>
#include <ti/drivers/adc/ADCCC26XX.h>
ADCCC26XX_Object adcCC26xxObjects[CC1310_LAUNCHXL_ADCCOUNT];
const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADCCOUNT] = {
{
.adcDIO = CC1310_LAUNCHXL_DIO23_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO3, //ADC_COMPB_IN_AUXIO7
.refSource = ADCCC26XX_VDDS_REFERENCE, //ADCCC26XX_FIXED_REFERENCE ADCCC26XX_VDDS_REFERENCE
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
{
.adcDIO = CC1310_LAUNCHXL_DIO24_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO6,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
{
.adcDIO = CC1310_LAUNCHXL_DIO25_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO5,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
{
.adcDIO = CC1310_LAUNCHXL_DIO26_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO4,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
{
.adcDIO = CC1310_LAUNCHXL_DIO27_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO3,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
{
.adcDIO = CC1310_LAUNCHXL_DIO28_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO2,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
{
.adcDIO = CC1310_LAUNCHXL_DIO29_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO1,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
{
.adcDIO = CC1310_LAUNCHXL_DIO30_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO0,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_10P9_MS,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
{
.adcDIO = PIN_UNASSIGNED,
.adcCompBInput = ADC_COMPB_IN_DCOUPL,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
{
.adcDIO = PIN_UNASSIGNED,
.adcCompBInput = ADC_COMPB_IN_VSS,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
{
.adcDIO = PIN_UNASSIGNED,
.adcCompBInput = ADC_COMPB_IN_VDDS,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
}
};
const ADC_Config ADC_config[CC1310_LAUNCHXL_ADCCOUNT] = {
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC0], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC0]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC1], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC1]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC2], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC2]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC3], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC3]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC4], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC4]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC5], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC5]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC6], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC6]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADC7], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADC7]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADCDCOUPL], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADCDCOUPL]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADCVSS], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADCVSS]},
{&ADCCC26XX_fxnTable, &adcCC26xxObjects[CC1310_LAUNCHXL_ADCVDDS], &adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADCVDDS]},
};
const uint_least8_t ADC_count = CC1310_LAUNCHXL_ADCCOUNT;
uint8_t ADC_GetVol(void)
{
#define USE_ADC
#ifdef USE_ADC
ADC_Handle adc;
ADC_Params params;
uint8_t i=0;
int_fast16_t res;
uint32_t adcValue0MicroVolt;
uint16_t adcValue0=0;
uint32_t adcValue=0;
uint8_t bat_vol=0;
static uint8_t last_batvol=0; //记录上次电量档位,防止电量档位跳变
float Vbat=0.00;
float Vbat1=0.00;
ADC_init();
ADC_Params_init(¶ms);
adc = ADC_open(0, ¶ms); //DIO7
if (adc == NULL) {
while(1);
}
/* Blocking mode conversion */
for(i=0;i<5;i++)
{
res = ADC_convert(adc, &adcValue0);
Vbat += 3.60*adcValue0/4096.0;
// Vbat1+=(ADC_convertRawToMicroVolts(adc, adcValue0)/1000000.0);
}
// Vbat1=(float)Vbat1/5.0;
Vbat=2.0*(float)Vbat/5.0;
if (res == ADC_STATUS_SUCCESS) {
// adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0);
// Vbat=2.0*(float)adcValue0MicroVolt/1000000.0;//换算电池电压
ADC_close(adc);
for(i=0;i<5;i++)
{
if(Vbat>=bat_level[i])
{
bat_vol=5-i;
if(bat_vol>last_batvol)//防止电量临界值导致档位跳变
{
bat_vol=last_batvol;
}
last_batvol=bat_vol;
break;
}
}
if(Vbat<2.04)//0格电量
{
bat_vol=0;
last_batvol=bat_vol;
}
return bat_vol;
}
ADC_close(adc);
return 0;
}
There is so much going on in this post, so *I am a bit unsure what you are actually needing help with.
Is theproblem that you are not able to read the voltage on the DIO9, or are you able to, but are not reading the correct value?
If the latter is the case, what is the voltage you input to the DIO0, and what is the value you are measuring?
You should not have to do anything other than to get the voltage:
res = ADC_convert(adc, &adcValue0);
if (res == ADC_STATUS_SUCCESS)
{
adcValue0MicroVolt = ADC_convertRawToMicroVolts(adc, adcValue0);
}
Regarding the reference:
/*!
* @brief Specifies whether the internal reference of the ADC is sourced from the battery voltage or a fixed internal source.
*
* - In practice, using the internal fixed voltage reference sets the upper range of the ADC to a fixed value. That value is 4.3V with
* input scaling enabled and ~1.4785V with input scaling disabled. In this mode, the output is a function of the input voltage multiplied
* by the resolution in alternatives (not bits) divided by the upper voltage range of the ADC. Output = Input (V) * 2^12 / (ADC range (V))
*
* - Using VDDS as a reference scales the upper range of the ADC with the battery voltage. As the battery depletes and its voltage drops, so does
* the range of the ADC. This is helpful when measuring signals that are generated relative to the battery voltage. In this mode, the output is
* a function of the input voltage multiplied by the resolution in alternatives (not bits) divided by VDDS multiplied by a scaling factor derived
* from the input scaling. Output = Input (V) * 2^12 / (VDDS (V) * Scaling factor), where the scaling factor is ~1.4785/4.3 for input scaling
* disabled and 1 for input scaling enabled.
*
* @note The actual reference values are slightly different for each device and are higher than the values specified above. This gain is saved in
* the FCFG. The function ::ADC_convertToMicroVolts() must be used to derive actual voltage values. Do not attempt to compare raw values
* between devices or derive a voltage from them yourself. The results of doing so will only be approximately correct.
*
* @warning Even though the upper voltage range of the ADC is 4.3 volts in fixed mode with input scaling enabled, the input should never exceed
* VDDS as per the data sheet.
*/
typedef enum ADCCC26XX_Reference_Source {
ADCCC26XX_FIXED_REFERENCE = AUXADC_REF_FIXED,
ADCCC26XX_VDDS_REFERENCE = AUXADC_REF_VDDS_REL
} ADCCC26XX_Reference_Source;
Siri
The input voltage range of the board is 0-3.6V, and the range of the ADC pin acquisition voltage is 0-1.8V after the resistor divider, and VDDS is selected as the reference voltage.
The voltage measured from the pin is 1.77V, the adc value is 2070, 2.22V is calculated using the api, and 1.81V is calculated using the formula
ADC_init();
ADC_Params_init(¶ms);
adc = ADC_open(0, ¶ms); //DIO7
if (adc == NULL) {
while(1);
}
/* Blocking mode conversion */
for(i=0;i<5;i++)
{
res = ADC_convert(adc, &adcValue0);
Vbat += 3.6*adcValue0/4096.0;
Vbat1+=(ADC_convertRawToMicroVolts(adc, adcValue0)/1000000.0);
}
Vbat1=(float)Vbat1/5.0;
Vbat=(float)Vbat/5.0;
const ADCCC26XX_HWAttrs adcCC26xxHWAttrs[CC1310_LAUNCHXL_ADCCOUNT] = {
{
.adcDIO = CC1310_LAUNCHXL_DIO23_ANALOG,
.adcCompBInput = ADC_COMPB_IN_AUXIO3, //ADC_COMPB_IN_AUXIO7
.refSource = ADCCC26XX_VDDS_REFERENCE, //ADCCC26XX_FIXED_REFERENCE ADCCC26XX_VDDS_REFERENCE
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = false
},
Do you have aCC1310 LP so that you can try to implement what exactly you want to do there?
That way you can share your code and I can test it here on a LP. Once we are able to get the desired results on a HW that we have availabe, I can try to help you port it to the 4x4.
BR
Siri
I used the cc1310 launchpad to test the history using ADCCC26XX_FIXED_REFERENCE as a reference, and the input voltage collected by the DIO23 pin was accurate, but now I am changing to a 4*4 board and found that the voltage value collected by the api ADC_convertRawToMicroVoltsc is inaccurate, I want to know the formula for the specific conversion voltage of the API
You should not have to change anything in the API even if you are changing the device.
you should only do a re-mapping of the analog pins, nothing else.
The rest of the code should be kept as the code you have already tested on the LP.
Please see the following past on what changes should be done:
After implemeting the changes, test one of the analog input the exact same way as yuo were testing DIO23, to see that you can reproduce the result.
since I do not have any HW with this package, I am unfortunately not able to do any testing for you.
Siri