已回答假定已回答

主ADC转换错误

梦归魂 在 2013-6-6 詢問的問題
最後回覆由ADI_XUN於2013-6-7提供

各位大侠好:

     我使用的MCU为ADuC7061,我使用主ADC,配置为单端模式、转换速率4Hz、使用内部基准电压源1.2V、主ADC增益为1,使用ADC3通道。我出现的故障是我ADC3的电压为0.59V,但是经ADC转换后却出现主ADC转换错误ADC0DAT里面值为0x00,ADCSTA的值为0x1000.请问大侠这是怎么回事?下面附上我的程序

 

 

************************************************************************************************/

#include<aduc7060.h>
# include "stdio.h"
# include "string.h"

// Bit Definitions
#define BIT0  0x01
#define BIT1  0x02
#define BIT2  0x04
#define BIT3  0x08
#define BIT4  0x10
#define BIT5  0x20
#define BIT6  0x40
#define BIT7  0x80
#define BIT8  0x100
#define BIT9  0x200
#define BIT10 0x400
#define BIT11 0x800
#define BIT12 0x1000
#define BIT13 0x2000
#define BIT14 0x4000
#define BIT15 0x8000


volatile unsigned char bSendResultToUART = 0; // Flag used to indicate ADC3 resutl ready to send to UART
unsigned char szTemp[16] = "";     // Used to store ADC3 result before printing to UART
unsigned char ucTxBufferEmpty  = 0;    // Used to indicate that the UART Tx buffer is empty
volatile unsigned long ulADC0Result = 0;  // Variable that ADC0DAT is read into in ADC0 IRQ


//函数声明
void ADC0Init(void);
void UARTInit(void);
void Delay(int a);

 

/******************************************************************************
函数名     :  int main(void)
描述       :  主函数
输入       :  void
输出  :  void
返回  :  
*******************************************************************************/
int main(void)
{

      unsigned char i = 0;
      unsigned char nLen = 0;

      POWKEY1 = 0x1;
      POWCON0 = 0x78;     // Set core to max CPU speed of 10.24Mhz
      POWKEY2 = 0xF4;

      UARTInit()
      ADC0Init();

      IRQEN = BIT10 + BIT11; // Enable ADC and UART interrupts
      bSendResultToUART = 0;

      while (1)
      { }
}


/******************************************************************************
函数名     :  void IRQ_Handler(void) __irq
描述       :  IRQ中断服务程序
输入       :  void
输出  :  void
返回  :  void
*******************************************************************************/
void IRQ_Handler(void) __irq
{
      unsigned long IRQSTATUS = 0;
      unsigned char ucCOMIID0 = 0;

      IRQSTATUS = IRQSTA;         // Read off IRQSTA register
      if ((IRQSTATUS & BIT11) == BIT11)      //UART interrupt source
      {
          ucCOMIID0 = COMIID0;
          if ((ucCOMIID0 & 0x2) == 0x2)        // Transmit buffer empty
          {
               ucTxBufferEmpty = 1;
          } 
      }

      if ((IRQSTATUS & BIT10) == BIT10)      //If ADC0 interrupt source
      {
          ulADC0Result = ADC0DAT;      // Read ADC0 conversion result
          bSendResultToUART = 1;
      }
}

/******************************************************************************
函数名     :  ADC0Init()
描述       :  初始化ADuC7061的主ADC
输入       :  void
输出  :  void
返回  :  void
*******************************************************************************/
void ADC0Init(void)
{
     //
      // Configure ADC0 for continuous conversions, 4hz, AIN3 in Single-ended mode
      //
      ADCMSKI = BIT0;                                 // Enable ADC0 result ready interrupt source
     ADCFLT = 0xFF1F;                               // Chop on, Averaging, AF=63, SF=31, 4Hz
     ADCCFG = 0;      

      ADC0CON = BIT6 + BIT7 + BIT8 +    // ADC3/ADC5(单端模式),AIN3,使用内部基准电压1.2V。
                           BIT10 +                           // Unipolar ADC output
                           BIT15;                            // Enable Primary_ADC.

      ADCMDE  = 0x94;                                          // Offest Self Calibration
     while((ADCSTA & BIT15) == BIT15){}            // Wait for Calibration routine to complete
      ADCMDE  = 0x95;                                          // Gain Self Calibration
     while((ADCSTA & BIT15) == BIT15){}            // Wait for Calibration routine to complete  

     ADCMDE  = BIT0 + BIT4 + BIT7;               // continuous conversions
}


/******************************************************************************
函数名     :  UARTInit()
描述       :  初始化ADuC7061的主UART
输入       :  void
输出  :  void
返回  :  void
*******************************************************************************/
void UARTInit(void)
{
  // Initialize the UART for 9600-8-N
GP1CON = BIT0 + BIT4;  // Select UART functionality for P1.0/P1.1
COMCON0 = BIT7;   // Enable access to COMDIV registers
COMDIV0 = 0x21;   // Set baud rate to 9600.
COMDIV1 = 0x00;
//COMDIV2 = 0x21 + BIT11; // Enable fractional divider for more accurate baud rate setting
COMCON0 = BIT0 + BIT1 + BIT2;
COMIEN0 = BIT0 + BIT1;  // Enable UART interrupts when Rx full and Tx buffer empty.
}


/******************************************************************************
函数名     :  void Delay(int a)
描述       :  延时函数
输入       :  int a
输出  :  void
返回  :  void
*******************************************************************************/
void Delay(int a)
{
int i,j;
for(i = 1 ; i < a ; i++)
  for(j = 1 ; j < 1000 ; j++);
}

結果