使用28335的内置ADC采样时出现了以下几个问题(使用ADAIN0单路采样):
1、无输入时会有一个0.8V左右的采样值如图:
2、将输入信号频率提高时,幅值范围会缩小,比如输入幅值最高值为2V,直流偏置为1V的正弦信号时,采样到的信号如下图:
程序代码如下:
void main(void)
{
Uint16 i,j;
Uint16 array_index;
InitSysCtrl();
asm(" RPT #8 || NOP");
DINT;
InitGpio();
DINT;
InitPieCtrl();
DINT;
InitFlash();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
asm(" RPT #8 || NOP");
InitAdc(); // For this example, init the ADC
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
// Secific ADC setup for this example:
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; // Sequential mode: Sample rate = 1/[(2+ACQ_PS)*ADC clock in ns]
// = 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)
// = 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)
// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode
AdcRegs.ADCTRL3.bit.SMODE_SEL=0;
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV12 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV13 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV14 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV15 = 0x0;
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; // Enable Sequencer override feature
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0xF; // convert and store in 8 results registers
// AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x0;
DINT; // Clear SampleTable
for (j=0; j<BUF_SIZE; j++)
{
SampleTable[j] = 0;
}
// Start SEQ1
AdcRegs.ADCTRL2.all = 0x2000;
array_index = 0;
while(1)
{ for (i=0; i<(BUF_SIZE/16); i++)
{
while (AdcRegs.ADCST.bit.INT_SEQ1== 0){}
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT0)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT1)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT2)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT3)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT4)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT5)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT6)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT7)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT8)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT9)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT10)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT11)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT12)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT13)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT14)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT15)>>4)*3.0/4095.0;
if(array_index>=512)
{
array_index=0;
}
EINT;
}
}
}
请问怎么去除无输入时的偏置值以及高频率时采样不准确是否可以通过软件设置解决?
期待答复中
user5883879:我写了个取最大值加最小值除以2的值,用所有数据减这个值得到偏置消去的效果,如果波形好的话是很有效果的,但是采样值随频率变化我也是如此,也没有办法。
使用28335的内置ADC采样时出现了以下几个问题(使用ADAIN0单路采样):
1、无输入时会有一个0.8V左右的采样值如图:
2、将输入信号频率提高时,幅值范围会缩小,比如输入幅值最高值为2V,直流偏置为1V的正弦信号时,采样到的信号如下图:
程序代码如下:
void main(void)
{
Uint16 i,j;
Uint16 array_index;
InitSysCtrl();
asm(" RPT #8 || NOP");
DINT;
InitGpio();
DINT;
InitPieCtrl();
DINT;
InitFlash();
IER = 0x0000;
IFR = 0x0000;
InitPieVectTable();
asm(" RPT #8 || NOP");
InitAdc(); // For this example, init the ADC
EALLOW;
SysCtrlRegs.HISPCP.all = ADC_MODCLK; // HSPCLK = SYSCLKOUT/ADC_MODCLK
EDIS;
// Secific ADC setup for this example:
AdcRegs.ADCTRL1.bit.ACQ_PS = ADC_SHCLK; // Sequential mode: Sample rate = 1/[(2+ACQ_PS)*ADC clock in ns]
// = 1/(3*40ns) =8.3MHz (for 150 MHz SYSCLKOUT)
// = 1/(3*80ns) =4.17MHz (for 100 MHz SYSCLKOUT)
// If Simultaneous mode enabled: Sample rate = 1/[(3+ACQ_PS)*ADC clock in ns]
AdcRegs.ADCTRL3.bit.ADCCLKPS = ADC_CKPS;
AdcRegs.ADCTRL1.bit.SEQ_CASC = 1; // 1 Cascaded mode
AdcRegs.ADCTRL3.bit.SMODE_SEL=0;
AdcRegs.ADCCHSELSEQ1.bit.CONV00 = 0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV01 = 0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV02 = 0x0;
AdcRegs.ADCCHSELSEQ1.bit.CONV03 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV04 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV05 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV06 = 0x0;
AdcRegs.ADCCHSELSEQ2.bit.CONV07 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV08 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV09 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV10 = 0x0;
AdcRegs.ADCCHSELSEQ3.bit.CONV11 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV12 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV13 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV14 = 0x0;
AdcRegs.ADCCHSELSEQ4.bit.CONV15 = 0x0;
AdcRegs.ADCTRL1.bit.CONT_RUN = 1; // Setup continuous run
AdcRegs.ADCTRL1.bit.SEQ_OVRD = 1; // Enable Sequencer override feature
AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0xF; // convert and store in 8 results registers
// AdcRegs.ADCMAXCONV.bit.MAX_CONV1 = 0x0;
DINT; // Clear SampleTable
for (j=0; j<BUF_SIZE; j++)
{
SampleTable[j] = 0;
}
// Start SEQ1
AdcRegs.ADCTRL2.all = 0x2000;
array_index = 0;
while(1)
{ for (i=0; i<(BUF_SIZE/16); i++)
{
while (AdcRegs.ADCST.bit.INT_SEQ1== 0){}
AdcRegs.ADCST.bit.INT_SEQ1_CLR = 1;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT0)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT1)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT2)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT3)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT4)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT5)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT6)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT7)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT8)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT9)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT10)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT11)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT12)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT13)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT14)>>4)*3.0/4095.0;
SampleTable[array_index++]= ( (AdcRegs.ADCRESULT15)>>4)*3.0/4095.0;
if(array_index>=512)
{
array_index=0;
}
EINT;
}
}
}
请问怎么去除无输入时的偏置值以及高频率时采样不准确是否可以通过软件设置解决?
期待答复中
yq k:
回复 user5883879:
那这样处理的话还能算采样得到的真实数据吗?采样值随频率变化当时我加大了采样速率好像是解决了,时间久了不太记得了