2014年1月2日 星期四

NUC100 ADC單一觸發模式

單一觸發模式  (程式片段)
void InitADC(void)
{
    /* Step 1. GPIO initial */
    GPIOA->OFFD|=0x00010000;     //ADC0 ADC1 Disable digital input path
    SYS->GPAMFP.ADC0=1;         //adc0 Set ADC function
 // SYS->GPAMFP.ADC1_AD12=1; //adc1                       
    /* Step 2. Enable and Select ADC clock source, and then enable ADC module */         
    SYSCLK->CLKSEL1.ADC_S = 2;    //Select 22Mhz for ADC
    SYSCLK->CLKDIV.ADC_N = 1;    //ADC clock source = 22Mhz/2 =11Mhz;
    SYSCLK->APBCLK.ADC_EN = 1;    //Enable clock source
    ADC->ADCR.ADEN = 1;            //Enable ADC module

    /* Step 3. Select Operation mode */
    ADC->ADCR.DIFFEN = 0;         //single end input
    ADC->ADCR.ADMD   = 0;         //single mode
       
    /* Step 4. Select ADC channel */
    ADC->ADCHER.CHEN = 0x01; // adc0
   
    /* Step 5. Enable ADC interrupt */
    ADC->ADSR.ADF =1;             //clear the A/D interrupt flags for safe
    ADC->ADCR.ADIE = 1;    //must set "1"
//    NVIC_EnableIRQ(ADC_IRQn);
   
    /* Step 6. start convert */
    ADC->ADCR.ADST=1;
}

 int main (void)
{    

    InitADC();
    ADC->ADCALR.CALEN=1;   // 校正
     while(  (ADC->ADCALR.CALDONE)==0  ){}
 //--------------------------------------------------------------//

       
     while(ADC->ADSR.ADF==0);
        ADC->ADSR.ADF=1;  //clear adf flag
       CNT=ADC->ADDR[0].RSLT>>3;   //取ADC0值 , 捨棄最後3BIT ,且放入CNT
        ADC->ADCR.ADST=1;


}

沒有留言:

張貼留言