我在这个循环中来测量单片机的供电电压,发现第一次运行时的q的值是340多,第二次及就是200多,发现严重不准,基准电压2.5v,内部通道, 采样时64个时钟周期,我用官方的例程也是同样的问题。
测试程序如下:
#include <msp430.h>
int main(void)
{
unsigned int q;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
for (;;)
{
ADC10CTL0 &= ~ENC; //ADC10 disabled
ADC10CTL0 &= ~ADC10ON; //OFF the ADC10
ADC10CTL0 |= SREF_1 + ADC10SHT_0 + REFON + ADC10ON+REF2_5V;
ADC10CTL1 |= INCH_12 + CONSEQ_0 ;
//ADC10CTL0 &= ~ENC;
while(ADC10CTL1 & ADC10BUSY);
ADC10CTL0 |= ENC;
ADC10CTL0 |= ADC10SC; //start convert
while (ADC10CTL1 & ADC10BUSY);//(!(ADC10IFG & ADC10IFG0))
q = ADC10MEM;
ADC10CTL0 &= ~ENC; //ADC10 disabled
ADC10CTL0 &= ~ADC10ON; //OFF the ADC10
}
}
哪个大神帮我看看什么问题。不胜感激。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
int main(void)
{
unsigned int q,count;
WDTCTL = WDTPW + WDTHOLD; // Stop WDT
ADC10CTL0 |= SREF_1 + ADC10SHT_3 + REFON + ADC10ON + REF2_5V;
ADC10CTL1 |= INCH_12 + CONSEQ_0;// + ADC10SSEL_2 +ADC10DIV2 ;
for (;;)
{
ADC10CTL0 |= ENC + ADC10SC;
while (ADC10CTL1 & ADC10BUSY);//(!(ADC10IFG & ADC10IFG0))
q = ADC10MEM;
for (count = 0; count< 255; count++);
ADC10CTL0 &= ~ADC10SC; //start convert
ADC10CTL0 &= ~ENC; //ADC10 disabled
}
}
一周热门 更多>