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);
}
} |