采样4M晶振16倍频,AD设置如下,运行时AD貌似有问题,请各位看下,采用自动采样和转换
void Init_ADC(void)
{
ADCON1bits.FORM = 0;//整形
ADCON1bits.SSRC = 7;//自动转换
ADCON1bits.ASAM = 1;//采样结束后立即转换
ADCON1bits.SIMSAM = 1;//同时采样
ADCON2bits.SMPI = 0;//每1个采样产生中断
ADCON2bits.CHPS = 2;//转换ch0, 1,2 , 3
ADCON3bits.SAMC = 6;//自动采样时间6*TAD
ADCON3bits.ADCS = 23;//TAD=750ns
ADCHS = 0;
ADCSSL = 0x0007;//对AN0,1,2扫描
ADPCFG = 0xFFFF;
ADPCFGbits.PCFG2 = 0;
ADPCFGbits.PCFG0 = 0;
ADPCFGbits.PCFG1 = 0;//模拟输入
IFS0bits.ADIF = 0;
IEC0bits.ADIE = 1;
ADCON1bits.ADON = 1;
}
void __attribute__((interrupt, auto_psv)) _ADCInterrupt(void)
{ IFS0bits.ADIF = 0;
AA1= ADCBUF0;//读取采样值
BB1 = ADCBUF2;
CC1 = ADCBUF3;
}
|