大家好,
我使用的是TI官方的EK-LM4F232H5QD评估板,遇到了以下两个问题。
1、其中PD4(AIN7)外接电池进行AD采样测试,电池电压1.528-1.533V左右,当设置参考电压为内部参考电压时,采样值在1827-1924,1.528/3.3*4096=1896左右,设置为外部3V参考电压时,采样值还是和内部参考电压值时差不多?为什么不是1.528/3*4096=2086左右呢?还是我的代码有问题呢(用的官方ADC例程)?更换为外部3V参考电压仅增加了红色区域的代码。请问要如何使用外部3V参考电压呢?
2、12bit的adc,在参考电压与测试电压值都在较稳定的情况下,为什么AD采样值变化如此大?采用硬件多次平均,效果也不是特别好,ad值偏差也有几十个。
unsigned long ref=0xff;
int main(void)
{
tContext sContext;
char cText[8];
unsigned long ulText;
unsigned long ulADC0_Value[3];
FPUEnable();
FPULazyStackingEnable();
SysCtlClockSet(SYSCTL_SYSDIV_4 | SYSCTL_USE_PLL | SYSCTL_XTAL_16MHZ | SYSCTL_OSC_MAIN);
CFAL96x64x16Init();
GrContextInit(&sContext, &g_sCFAL96x64x16);
GrContextForegroundSet(&sContext, ClrWhite);
GrContextFontSet(&sContext, &g_sFontFixed6x8);
GrStringDraw(&sContext,"ADC Hands On Lab", -1,1, 5, 0);
GrStringDraw(&sContext,"----------------", -1,1, 15, 0);
GrStringDraw(&sContext,"Ad:", -1,20, 25, 0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_ADC0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE);
GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_6);
ref=ADCReferenceGet(ADC0_BASE);
ADCReferenceSet(ADC0_BASE,ADC_REF_EXT_3V);
ref=ADCReferenceGet(ADC0_BASE);
ADCSequenceConfigure(ADC0_BASE, SEQUENCER, ADC_TRIGGER_PROCESSOR, 0);
ADCSequenceStepConfigure(ADC0_BASE, SEQUENCER, 0, ADC_CTL_CH7 | ADC_CTL_IE
|ADC_CTL_END);
ADCSequenceEnable(ADC0_BASE, SEQUENCER);
ADCIntClear(ADC0_BASE, SEQUENCER);
while(1)
{
ADCProcessorTrigger(ADC0_BASE, SEQUENCER);
while(!ADCIntStatus(ADC0_BASE, SEQUENCER, false))
{
}
ADCSequenceDataGet(ADC0_BASE, SEQUENCER, ulADC0_Value);
usprintf(cText, " %d ", ulADC0_Value[0]);
GrStringDraw(&sContext, cText, -1, 45, 25, 1);
SysCtlDelay(SysCtlClockGet() / 12);
GrFlush(&sContext);
}
} |