我在这个循环中来测量单片机的供电电压,发现第一次运行时的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
}
}
哪个大神帮我看看什么问题。不胜感激。
友情提示: 此问题已得到解决,问题已经关闭,关闭后问题禁止继续编辑,回答。
~ADC10ON
这两个放到循环体外试试看,循环体内只要ADC10SC
另外,ADC10SHT_0是64个时钟周期?
各位大神有时间再帮我看看是什么问题?
以下是2272的ADC寄存器。
/* ADC10CTL0 */
#define ADC10SC (0x001) /* ADC10 Start Conversion */
#define ENC (0x002) /* ADC10 Enable Conversion */
#define ADC10IFG (0x004) /* ADC10 Interrupt Flag */
#define ADC10IE (0x008) /* ADC10 Interrupt Enalbe */
#define ADC10ON (0x010) /* ADC10 On/Enable */
#define REFON (0x020) /* ADC10 Reference on */
#define REF2_5V (0x040) /* ADC10 Ref 0:1.5V / 1:2.5V */
#define MSC (0x080) /* ADC10 Multiple SampleConversion */
#define REFBURST (0x100) /* ADC10 Reference Burst Mode */
#define REFOUT (0x200) /* ADC10 Enalbe output of Ref. */
#define ADC10SR (0x400) /* ADC10 Sampling Rate 0:200ksps / 1:50ksps */
#define ADC10SHT0 (0x800) /* ADC10 Sample Hold Select Bit: 0 */
#define ADC10SHT1 (0x1000u) /* ADC10 Sample Hold Select Bit: 1 */
#define SREF0 (0x2000u) /* ADC10 Reference Select Bit: 0 */
#define SREF1 (0x4000u) /* ADC10 Reference Select Bit: 1 */
#define SREF2 (0x8000u) /* ADC10 Reference Select Bit: 2 */
#define ADC10SHT_0 (0*0x800u) /* 4 x ADC10CLKs */
#define ADC10SHT_1 (1*0x800u) /* 8 x ADC10CLKs */
#define ADC10SHT_2 (2*0x800u) /* 16 x ADC10CLKs */
#define ADC10SHT_3 (3*0x800u) /* 64 x ADC10CLKs */
#define SREF_0 (0*0x2000u) /* VR+ = AVCC and VR- = AVSS */
#define SREF_1 (1*0x2000u) /* VR+ = VREF+ and VR- = AVSS */
#define SREF_2 (2*0x2000u) /* VR+ = VEREF+ and VR- = AVSS */
#define SREF_3 (3*0x2000u) /* VR+ = VEREF+ and VR- = AVSS */
#define SREF_4 (4*0x2000u) /* VR+ = AVCC and VR- = VREF-/VEREF- */
#define SREF_5 (5*0x2000u) /* VR+ = VREF+ and VR- = VREF-/VEREF- */
#define SREF_6 (6*0x2000u) /* VR+ = VEREF+ and VR- = VREF-/VEREF- */
#define SREF_7 (7*0x2000u) /* VR+ = VEREF+ and VR- = VREF-/VEREF- */
/* ADC10CTL1 */
#define ADC10BUSY (0x0001u) /* ADC10 BUSY */
#define CONSEQ0 (0x0002u) /* ADC10 Conversion Sequence Select 0 */
#define CONSEQ1 (0x0004u) /* ADC10 Conversion Sequence Select 1 */
#define ADC10SSEL0 (0x0008u) /* ADC10 Clock Source Select Bit: 0 */
#define ADC10SSEL1 (0x0010u) /* ADC10 Clock Source Select Bit: 1 */
#define ADC10DIV0 (0x0020u) /* ADC10 Clock Divider Select Bit: 0 */
#define ADC10DIV1 (0x0040u) /* ADC10 Clock Divider Select Bit: 1 */
#define ADC10DIV2 (0x0080u) /* ADC10 Clock Divider Select Bit: 2 */
#define ISSH (0x0100u) /* ADC10 Invert Sample Hold Signal */
#define ADC10DF (0x0200u) /* ADC10 Data Format 0:binary 1:2's complement */
#define SHS0 (0x0400u) /* ADC10 Sample/Hold Source Bit: 0 */
#define SHS1 (0x0800u) /* ADC10 Sample/Hold Source Bit: 1 */
#define INCH0 (0x1000u) /* ADC10 Input Channel Select Bit: 0 */
#define INCH1 (0x2000u) /* ADC10 Input Channel Select Bit: 1 */
#define INCH2 (0x4000u) /* ADC10 Input Channel Select Bit: 2 */
#define INCH3 (0x8000u) /* ADC10 Input Channel Select Bit: 3 */
#define CONSEQ_0 (0*2u) /* Single channel single conversion */
#define CONSEQ_1 (1*2u) /* Sequence of channels */
#define CONSEQ_2 (2*2u) /* Repeat single channel */
#define CONSEQ_3 (3*2u) /* Repeat sequence of channels */
#define ADC10SSEL_0 (0*8u) /* ADC10OSC */
#define ADC10SSEL_1 (1*8u) /* ACLK */
#define ADC10SSEL_2 (2*8u) /* MCLK */
#define ADC10SSEL_3 (3*8u) /* SMCLK */
#define ADC10DIV_0 (0*0x20u) /* ADC10 Clock Divider Select 0 */
#define ADC10DIV_1 (1*0x20u) /* ADC10 Clock Divider Select 1 */
#define ADC10DIV_2 (2*0x20u) /* ADC10 Clock Divider Select 2 */
#define ADC10DIV_3 (3*0x20u) /* ADC10 Clock Divider Select 3 */
#define ADC10DIV_4 (4*0x20u) /* ADC10 Clock Divider Select 4 */
#define ADC10DIV_5 (5*0x20u) /* ADC10 Clock Divider Select 5 */
#define ADC10DIV_6 (6*0x20u) /* ADC10 Clock Divider Select 6 */
#define ADC10DIV_7 (7*0x20u) /* ADC10 Clock Divider Select 7 */
#define SHS_0 (0*0x400u) /* ADC10SC */
#define SHS_1 (1*0x400u) /* TA3 OUT1 */
#define SHS_2 (2*0x400u) /* TA3 OUT0 */
#define SHS_3 (3*0x400u) /* TA3 OUT2 */
#define INCH_0 (0*0x1000u) /* Selects Channel 0 */
#define INCH_1 (1*0x1000u) /* Selects Channel 1 */
#define INCH_2 (2*0x1000u) /* Selects Channel 2 */
#define INCH_3 (3*0x1000u) /* Selects Channel 3 */
#define INCH_4 (4*0x1000u) /* Selects Channel 4 */
#define INCH_5 (5*0x1000u) /* Selects Channel 5 */
#define INCH_6 (6*0x1000u) /* Selects Channel 6 */
#define INCH_7 (7*0x1000u) /* Selects Channel 7 */
#define INCH_8 (8*0x1000u) /* Selects Channel 8 */
#define INCH_9 (9*0x1000u) /* Selects Channel 9 */
#define INCH_10 (10*0x1000u) /* Selects Channel 10 */
#define INCH_11 (11*0x1000u) /* Selects Channel 11 */
#define INCH_12 (12*0x1000u) /* Selects Channel 12 */
#define INCH_13 (13*0x1000u) /* Selects Channel 13 */
#define INCH_14 (14*0x1000u) /* Selects Channel 14 */
#define INCH_15 (15*0x1000u) /* Selects Channel 15 */
/* ADC10DTC0 */
#define ADC10FETCH (0x001) /* This bit should normally be reset */
#define ADC10B1 (0x002) /* ADC10 block one */
#define ADC10CT (0x004) /* ADC10 continuous transfer */
#define ADC10TB (0x008) /* ADC10 two-block mode */
#define ADC10DISABLE (0x000) /* ADC10DTC1 */
一周热门 更多>