3.1 board_adc.c
/*********************************************************************
* INCLUDES
*/
#include "_hal_types.h"
#include <ti/drivers/adc/ADCCC26XX.h>
#include <ti/drivers/pin/PINCC26XX.h>
#include <driverlib/aux_adc.h>
#include <driverlib/aux_wuc.h>
#include "board_adc.h"
/*********************************************************************
* LOCAL VARIABLES
*/
static ADCCC26XX_Object s_adcCC26XXObject[BOARD_ADCCOUNT];
static const ADCCC26XX_HWAttrs s_adcCC26XXHWAttrs[BOARD_ADCCOUNT] =
{
{
.adcDIO = BATTERY_ADC_IO, // DIO_7
.adcCompBInput = ADC_COMPB_IN_AUXIO7,
.refSource = ADCCC26XX_FIXED_REFERENCE,
.samplingDuration = ADCCC26XX_SAMPLING_DURATION_2P7_US,
.inputScalingEnabled = true,
.triggerSource = ADCCC26XX_TRIGGER_MANUAL,
.returnAdjustedVal = 0
},
{
.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 = 0
},
{
.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 = 0
},
{
.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 = 0
}
};
static const ADC_Config s_adcConfig[BOARD_ADCCOUNT] =
{
{
&ADCCC26XX_fxnTable,
&s_adcCC26XXObject[BOARD_ADCCHANNEL7],
&s_adcCC26XXHWAttrs[BOARD_ADCCHANNEL7]
},
{
&ADCCC26XX_fxnTable,
&s_adcCC26XXObject[BOARD_ADCDCOUPL],
&s_adcCC26XXHWAttrs[BOARD_ADCDCOUPL]
},
{
&ADCCC26XX_fxnTable,
&s_adcCC26XXObject[BOARD_ADCVSS],
&s_adcCC26XXHWAttrs[BOARD_ADCVSS]
},
{
&ADCCC26XX_fxnTable,
&s_adcCC26XXObject[BOARD_ADCVDDS],
&s_adcCC26XXHWAttrs[BOARD_ADCVDDS]
},
};
// ADC句柄及参数
static ADC_Handle s_adcHandle;
static ADC_Params s_adcParams;
/*********************************************************************
* PUBLIC FUNCTIONS
*/
/**
@brief ADC的初始化函数
@param 无
@return 无
*/
void ADC_Init(void)
{
ADC_Params_init(&s_adcParams);
s_adcParams.isProtected = TRUE;
s_adcConfig[BOARD_ADCCHANNEL7].fxnTablePtr->closeFxn((ADC_Handle)&s_adcConfig[BOARD_ADCCHANNEL7]);
s_adcHandle = s_adcConfig[BOARD_ADCCHANNEL7].fxnTablePtr->openFxn((ADC_Handle)&s_adcConfig[BOARD_ADCCHANNEL7],&s_adcParams);
}
/**
@brief ADC读取
@param 无
@return 读取电压值
*/
uint16 ADC_Read(void)
{
uint16 adcResult;
s_adcConfig[BOARD_ADCCHANNEL7].fxnTablePtr->convertFxn(s_adcHandle, &adcResult);
return adcResult;
}
/**
@brief ADC短暂读取
@param 无
@return 读取电压值
*/
uint32 Adc_OneShotRead(void)
{
AUXWUCClockEnable(AUX_WUC_MODCLKEN0_ANAIF_M | AUX_WUC_MODCLKEN0_AUX_ADI4_M);
AUXADCSelectInput(ADC_COMPB_IN_AUXIO7);
AUXADCEnableSync(AUXADC_REF_FIXED, AUXADC_SAMPLE_TIME_2P7_US, AUXADC_TRIGGER_MANUAL);
AUXADCGenManualTrigger();
uint32 adcValue = AUXADCReadFifo();
AUXADCDisable();
return adcValue;
}
|