打印

28069 AD使用外部参考电压时AD值不对

[复制链接]
1616|0
手机看帖
扫描二维码
随时随地手机跟帖
跳转到指定楼层
楼主
easycome|  楼主 | 2016-6-9 16:30 | 只看该作者 回帖奖励 |倒序浏览 |阅读模式
我将AD参考电压设置为外部参考,Vreflo管脚接地,Vrefhi管脚接2.5V参考电压(我确定管脚电压是2.5V)。理论上AD输入管脚电压为2.5V时AD值会满,到达4095左右。但是测试发现此时AD值并没有达到4095,而只有3100左右。而我把输入电压调到3.3V时,AD值才满。貌似是AD仍然用的是内部3.3V参考电压,而我设置的外部参考无效。下面是我AD设置的程序,请大神们帮我看看哪里不对。

void MDG_InitAdc(void)
{
        EALLOW;

    /* Enable Clock */
        SysCtrlRegs.PCLKCR0.bit.ADCENCLK = 1;

    /* If the boot ROM code is bypassed during the debug process, the following function MUST be called */
        (*Device_cal)();

        /* Power Up */
    AdcRegs.ADCCTL1.bit.ADCBGPWD  = 1;      // Power band gap : 0 = off; 1 = on      用外部参考时“带隙电压”应关闭???
    AdcRegs.ADCCTL1.bit.ADCREFPWD = 1;      // Power reference : 0 = 0ff; 1 = on
    AdcRegs.ADCCTL1.bit.ADCPWDN   = 1;      // ADC core: 0 =  power Down; 1 = power Up
    AdcRegs.ADCCTL1.bit.ADCENABLE = 1;      // Enable ADC: 0 = Disable; 1 = Enable
    AdcRegs.ADCCTL1.bit.ADCREFSEL = 1;      // Reference select: 0 = internal band gap; 1 = external reference

    /* divide AD clock */
    AdcRegs.ADCCTL2.bit.CLKDIV2EN = 1;                // DIV2EN,DIV4EN: 00 = SYSCLK; 01 = SYSCLK; 10 = SYSCLK/2; 11 = SYSCLK/4
    AdcRegs.ADCCTL2.bit.CLKDIV4EN = 1;
    EDIS;

    /* re-calibrates */
    DELAY_US(1000);           // Delay before converting ADC channels
        AdcOffsetSelfCal(); // re-calibrates the ADC zero offset

    /* Select channel */
    EALLOW;
    AdcRegs.ADCSOC0CTL.bit.CHSEL = 15;                 // SOC0 input channel :15 = B7(threshold)
    AdcRegs.ADCSOC1CTL.bit.CHSEL = 9;                 // SOC1 input channel : 9 = B1(signal)

    /* Set the ADC sample window to the desired value (Sample window = ACQPS + 1) */
    AdcRegs.ADCSOC0CTL.bit.ACQPS  = 6;                 // 6 + 1 = 7
    AdcRegs.ADCSOC1CTL.bit.ACQPS  = 6;


    /* Select simultaneous or sequential mode */
        AdcRegs.ADCSAMPLEMODE.bit.SIMULEN0 = 0; // SOC0/1: 0 = sequential; 1 = simultaneous

    /* EOC0-EOC15 trigger source to ADCINTx  */
    AdcRegs.INTSEL1N2.bit.INT1SEL  = 0;         // EOC0      AD中断1由EOC0触发      EOC对应SOC
        AdcRegs.INTSEL1N2.bit.INT2SEL  = 1;                // EOC1

    /* Enabled ADCINTx */
    AdcRegs.INTSEL1N2.bit.INT1E  = 1;                 // 0 = Disable;  1 = Enable
        AdcRegs.INTSEL1N2.bit.INT2E  = 1;

    /* Continuous sampling setting */
    AdcRegs.INTSEL1N2.bit.INT1CONT = 1;                // 1 = continue; 0 = pulse
        AdcRegs.INTSEL1N2.bit.INT2CONT = 1;

    /* ADCINTs trigger at end or begin of conversion */
    AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;         // 0:begin; 1:end

        /* SOCx interrupt trigger select*/
        AdcRegs.ADCINTSOCSEL1.bit.SOC0  = 0;         // 0 = Trigger; 1 = ADCINT1; 2 = ADCINT2; 3 = Invalid
        AdcRegs.ADCINTSOCSEL1.bit.SOC1  = 1;         // ADCIN1       ADCINT1 will trigger SOCx.TRIGSEL field is ignored.


        /* SOCx trigger source select. */
        AdcRegs.ADCSOC0CTL.bit.TRIGSEL  = 1;                // TINT0


    /* interrupt pulse control */
    AdcRegs.ADCCTL1.bit.INTPULSEPOS = 1;          // interrupt occurs at : 0 = begin; 1 = end

    /* setting Interrupt */
        PieVectTable.ADCINT2 = &MDG_ADCINT2_ISR;         // vector relocation
        PieCtrlRegs.PIEIFR1.bit.INTx1 = 0;                 // Clear ADCINT1 flags
        PieCtrlRegs.PIEIFR1.bit.INTx2 = 0;                 // Clear ADCINT2 flags
        PieCtrlRegs.PIEIER1.bit.INTx1 = 0;                 // ADCINT1 = INT1.1
        PieCtrlRegs.PIEIER1.bit.INTx2 = 1;                 // ADCINT2 = INT1.2
        PieCtrlRegs.PIEACK.bit.ACK1 = 1;                 // Enable ACK1.x
        IFR &= ~(1 << (1 - 1));                                 // Clear  flags
        IER |= 1 << (1 - 1);                                         // Enable INT1.x
        EDIS;
}

相关帖子

发新帖 我要提问
您需要登录后才可以回帖 登录 | 注册

本版积分规则

5

主题

20

帖子

0

粉丝