我在实验过程中通过ADCSS0采了8条通道,其中7道都接地,CH6采集3V电压。最后通过串口输出发现CH6(3V)对应的数据不在pui32ADC0Value[6]的位置。
void ADC0Init()
{
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOE); GPIOPinTypeADC(GPIO_PORTE_BASE, GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0);
SysCtlPeripheralEnable(SYSCTL_PERIPH_GPIOD);
GPIOPinTypeADC(GPIO_PORTD_BASE, GPIO_PIN_3 | GPIO_PIN_2 | GPIO_PIN_1 | GPIO_PIN_0);
ADCSequenceConfigure(ADC0_BASE, 0, ADC_TRIGGER_ALWAYS, 0);
//
// Configure step 0–7 on sequence 0.
//
ADCSequenceStepConfigure(ADC0_BASE, 0, 0, ADC_CTL_CH0);
ADCSequenceStepConfigure(ADC0_BASE, 0, 1, ADC_CTL_CH1);
ADCSequenceStepConfigure(ADC0_BASE, 0, 2, ADC_CTL_CH2);
ADCSequenceStepConfigure(ADC0_BASE, 0, 3, ADC_CTL_CH3);
ADCSequenceStepConfigure(ADC0_BASE, 0, 4, ADC_CTL_CH4);
ADCSequenceStepConfigure(ADC0_BASE, 0, 5, ADC_CTL_CH5);
ADCSequenceStepConfigure(ADC0_BASE, 0, 6, ADC_CTL_CH6);
ADCSequenceStepConfigure(ADC0_BASE, 0, 7, ADC_CTL_CH7 | ADC_CTL_IE | ADC_CTL_END );
//
// enable ADC0 sequence 0 interrupt
//
ADCIntEnable(ADC0_BASE, 0);
//IntEnable(INT_ADC0SS0);
IntMasterEnable();
ADCSequenceEnable(ADC0_BASE, 0);
ADCIntClear(ADC0_BASE, 0);
}
while(1)
{
while(!ADCIntStatus(ADC0_BASE,0,true));
ADCSequenceDisable(ADC0_BASE,0);
ADCSequenceDataGet(ADC0_BASE, 0, pui32ADC0Value);
for(i = 0; i < 8; i++)
{
UARTprintf("%d(%d),",pui32ADC0Value[i],i);
}
UARTprintf(" –\n");
ADCSequenceEnable(ADC0_BASE,0);
ADCIntClear(ADC0_BASE, 0);
}
经过修改之后发现在while循环中进入中断后先关闭ADCSS0,最后再使能加清楚中断标志,这个数据就不会乱串,但是位置还是不对,CH6的数据跑到了pui32ADC0Value[5],换了个通道采同样还是数据会靠前一位输出。
Susan Yang:
您可以参考下勘误表内的ADC#13 A Glitch can Occur on pin PE3 When Using any ADC Analog Input Channel to Sample