我是测试我的板卡,先是通过一个DAC通道输出模拟信号,之后回传到多个ADC通道。
ADC通道配置为差分16位,IAN我直接连接到模拟地,IAP连接到DAC输出。每次采样时总有一个通道采样的数据和其他通道差不很大。不知道问题出在哪里,麻烦各位帮我看下问题。硬件我可以确定没有问题,感觉像是我的逻辑出了问题。
AdcSetMode(ADC_ADCD, ADC_RESOLUTION_16BIT, ADC_SIGNALMODE_DIFFERENTIAL);
AdcdRegs.ADCCTL1.bit.INTPULSEPOS = 1;
AdcdRegs.ADCCTL1.bit.ADCPWDNZ = 1;
AdcdRegs.ADCSOC0CTL.bit.CHSEL = 0x0;
AdcdRegs.ADCSOC0CTL.bit.ACQPS = 100;
AdcdRegs.ADCSOC0CTL.bit.TRIGSEL = 0;
AdcdRegs.ADCSOC0CTL.bit.CHSEL = 0x1;
AdcdRegs.ADCSOC0CTL.bit.ACQPS = 100;
AdcdRegs.ADCSOC0CTL.bit.TRIGSEL = 0;
AdcdRegs.ADCSOC1CTL.bit.CHSEL = 0x2;
AdcdRegs.ADCSOC1CTL.bit.ACQPS = 100;
AdcdRegs.ADCSOC1CTL.bit.TRIGSEL = 0;
AdcdRegs.ADCSOC1CTL.bit.CHSEL = 0x3;
AdcdRegs.ADCSOC1CTL.bit.ACQPS = 100;
AdcdRegs.ADCSOC1CTL.bit.TRIGSEL = 0;
AdcdRegs.ADCSOC2CTL.bit.CHSEL = 0x4;
AdcdRegs.ADCSOC2CTL.bit.ACQPS = 100;
AdcdRegs.ADCSOC2CTL.bit.TRIGSEL = 0;
AdcdRegs.ADCSOC2CTL.bit.CHSEL = 0x5;
AdcdRegs.ADCSOC2CTL.bit.ACQPS = 100;
AdcdRegs.ADCSOC2CTL.bit.TRIGSEL = 0;
AdcdRegs.ADCINTSEL1N2.bit.INT1E = 0;
AdcdRegs.ADCINTSEL1N2.bit.INT1CONT = 0;
AdcdRegs.ADCINTSEL1N2.bit.INT1SEL = 0x2;
AdcdRegs.ADCINTSEL1N2.bit.INT1E = 1;
Uint16 AdcTestDP(void) //test IA2 IB2 IC2 POSITVE
{
Uint16 AdcdResults[3];
float ConvertResults[3];
Uint16 i,Result=0;
DaccRegs.DACVALS.all = 1365;
DELAY_US(1000);
AdcdRegs.ADCSOCFRC1.all=0x0007;
DELAY_US(10000);
for(i=0;i<3;i++)
{
AdcdResults[i]=0;
}
for(i=0;i<3;i++)
{
ConvertResults[i]=0;
}
while(AdcdRegs.ADCINTFLG.bit.ADCINT1 == 0);
AdcdRegs.ADCINTFLG.bit.ADCINT1 = 1;
AdcdResults[2]=AdcdResultRegs.ADCRESULT0; //IA2
AdcdResults[0]=AdcdResultRegs.ADCRESULT1; //IC2
AdcdResults[1]=AdcdResultRegs.ADCRESULT2; //IB2
for(i=0;i<3;i++)
{
ConvertResults[i]=(((float)AdcdResults[i])*(2.0)/((float)65535)-1)*(3.0);
DELAY_US(10);
}
for(i=0;i<3;i++)
{
Result=Result<<1;
if(((0.2)<ConvertResults[i])&&(ConvertResults[i]<(0.6)))
{
Result|=1;
}
else
Result&=0xfffe;
}
AdcdRegs.ADCSOCFRC1.all=0x0000;
return Result; //sequence is IC2 IB2 IA2
}