2014年1月2日 星期四
Nuc100 ADC 單週期掃描(single-cycle scan)
單週期掃描(single-cycle scan)
void InitADC(void)
{
/* Step 1. GPIO initial */
GPIOA->OFFD|=0x00030000; //ADC0 ADC1 Disable digital input path
SYS->GPAMFP.ADC0=1; //adc0 Set ADC function 將PA0 切到ADC0
SYS->GPAMFP.ADC1_AD12=1; //adc1 將PA1 切到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 = 2; //single scan mode <<<< 單週期掃描
/* Step 4. Select ADC channel */
ADC->ADCHER.CHEN = 0x03; //選擇 ADC0 & ADC1
/* 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 轉換結果
cnt1=ADC->ADDR[1].RSLT>>3; //取ADC1 轉換結果
ADC->ADCR.ADST=1;
}
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;
}
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;
}
訂閱:
文章 (Atom)