發新話題
打印

有關C8051F410 ADC的問題

有關C8051F410 ADC的問題

想請教使用ADC的問題,就是我使用P1.6輸入一組類比訊號,再用ADC去取值,
發現當我啟動ADC去取值時,類比訊號隨著ADC的動作會有100mv大小的noise
產生,理論上ADC應該不會影響輸入訊號才對,不知有什麼要注意的地方呢?
謝謝大家
程式片段如下:
void PORT_Init (void)
{
    // P0.0  -  Unassigned,  Open-Drain, Digital
    // P0.1  -  Unassigned,  Open-Drain, Digital
    // P0.2  -  Unassigned,  Open-Drain, Digital
    // P0.3  -  Unassigned,  Open-Drain, Digital
    // P0.4  -  TX0 (UART0), Push-Pull,  Digital
    // P0.5  -  RX0 (UART0), Open-Drain, Digital
    // P0.6  -  Unassigned,  Open-Drain, Digital
    // P0.7  -  Unassigned,  Open-Drain, Digital

    // P1.0  -  Unassigned,  Open-Drain, Digital
    // P1.1  -  Unassigned,  Open-Drain, Digital
    // P1.2  -  Unassigned,  Open-Drain, Digital
    // P1.3  -  Unassigned,  Open-Drain, Digital
    // P1.4  -  Unassigned,  Open-Drain, Digital
    // P1.5  -  Unassigned,  Open-Drain, Digital
    // P1.6  -  Skipped,     Open-Drain, Analog
    // P1.7  -  Unassigned,  Open-Drain, Digital

    // P2.0  -  Unassigned,  Open-Drain, Digital
    // P2.1  -  Unassigned,  Open-Drain, Digital
    // P2.2  -  Unassigned,  Open-Drain, Digital
    // P2.3  -  Unassigned,  Open-Drain, Digital
    // P2.4  -  Unassigned,  Open-Drain, Digital
    // P2.5  -  Unassigned,  Open-Drain, Digital
    // P2.6  -  Unassigned,  Open-Drain, Digital
    // P2.7  -  Unassigned,  Open-Drain, Digital

    P1MDIN    = 0xBF;
    P0MDOUT   = 0x10;
    P1SKIP    = 0x40;
    XBR0     = 0x01;                    // No digital peripherals selected
}

//-----------------------------------------------------------------------------
//ADC Init
//-----------------------------------------------------------------------------
void ADC_Init(void)
{
    ADC0MX    = 0x0E;                                // P1.6 selected at + input
    ADC0CN    = 0x80;
    ADC0TK    = 0xF7;
    ADC0CF = (SYSCLK/715000) << 3;     
    REF0CN    = 0x09;                       // disable temp sensor, VREF = VDD(2.5v),
    EIE1 &= ~0x08;                      // Disable ADC0 EOC interrupt                                                                       
}
//-----------------------------------------------------------------------------
//ADC measure
//-----------------------------------------------------------------------------
unsigned int measure (void)
{
   unsigned i;                         // Sample counter
   unsigned long accumulator=0L;       // Here's where we integrate the
                                       // ADC samples
   unsigned int currval;
   
   AD0INT = 0;
   AD0BUSY = 1;

   i = 0;
   do
   {
      while (!AD0INT);                 // Wait for conversion to complete
      AD0INT = 0;                      // Clear end-of-conversion indicator

      currval= ADC0H << 8 | ADC0L;                    // Store latest ADC conversion         
      AD0BUSY = 1;                     // Initiate conversion
      accumulator += currval;          // Accumulate
      i++;                             // Update counter
   } while (i != AVG_TIMES);            
   return (unsigned int) (accumulator/AVG_TIMES);
  
}

TOP

1. 您可以使用 410dk測試看看是否如此
2. 可以試著將ad 接到 mcu vcc看看 ad value是否一樣會漂
3. 常見到的都是ad的輸入雜訊比較大,造成ad value 偏移

TOP

首先謝謝版主的回答,已將類比訊號改接至410dk,看來沒問題.
AD我將它接至MCU的VDD似乎也沒問題.在VIO/VREGIN也都放了
1uF/0.1uF電容.
看來是跟硬體電路有關,只是還找不到原因.

TOP

發新話題