网站建设资讯

NEWS

网站建设资讯

九齐单片机NY8B062E的ADC零点校准程序记录-创新互联

  最消费类的方案开发,一直用到九齐的片子,带AD的基本都是062D,但是后面推出了062E代替了D版,看资料,使用AD需要一个零点校准的初始化程序,刚开始也一脸懵逼,经过一番摸索有,在这里做一个记录,

做网站、网站制作服务团队是一支充满着热情的团队,执着、敏锐、追求更好,是创新互联的标准与要求,同时竭诚为客户提供服务是我们的理念。成都创新互联公司把每个网站当做一个产品来开发,精雕细琢,追求一名工匠心中的细致,我们更用心!

//ADC初始化校准 ---------------------------------------------------------------------------------
//void F_ADJMD(void)
//void F_GND_Convert(char count)
//void ADC_Calibration_Pro(void)

void F_GND_Convert(char count)
{
    char i;
    ADMD  = 0x90 | C_VSS;                // Select (GND) pad as ADC input
    CLRWDT();                            //clear WDT, which is defined in NY8Common.h
    delay(100);                            // Delay 0.56ms(Instruction clock=4MHz/2T) for waiting ADC stable
    for(i=1;i<=count;i++)
    {                  
     ADMDbits.START = 1;                // Start a ADC conversion session
     while(ADMDbits.EOC == 0)
         ;                                // Waiting for ADC conversion complet    
     R_AIN_DATA_LB += ( 0x0F & ADR); 
    }
}

void F_ADJMD(void)
{
 DISI();
 ADMDbits.GCHS = 1;                    // Enable global ADC channel    (SFR "ADMD")
  F_GND_Convert(8);                    // executing GND ADC converting 8 times
  R_AIN_DATA_LB >>= 3;                // Only get Bit7~4

 if(R_AIN_DATA_LB >= 2)
 {
     ADJMD = 0x00;
     while(1)
     {
         CLRWDT();
         R_AIN_DATA_LB = 0;
 F_GND_Convert(8);            // executing GND ADC converting 8 times
     R_AIN_DATA_LB >>= 3;        // Only get Bit7~4
         if((ADJMD<0x1F) & (R_AIN_DATA_LB >= 2)){ADJMD++;}
 else if(ADJMD == 0x1F){ADJMD = 0x00;break;}
 else {R_AIN_DATA_LB = 1;break;}
     }
 }    

 if(R_AIN_DATA_LB == 0)
 {
     ADJMD = 0x20;
     while(1)
     {
         CLRWDT();
 R_AIN_DATA_LB = 0;
 F_GND_Convert(8);                    // executing GND ADC converting 8 times
         R_AIN_DATA_LB >>= 3;                // Only get Bit7~4
         if((ADJMD<0x3F)&(R_AIN_DATA_LB == 0)){ADJMD++;}
 else if(ADJMD == 0x3F){ADJMD = 0x20;break;}        
 else {break;}  
     }
 }
}

void ADC_Calibration_Pro(void)
{
 //----- Initial ADC-----      
 ADMD  = C_ADC_En | C_ADC_CH_Dis | C_VSS ;    // Enable ADC power, Disable global ADC input channel. Select PA1 pad as ADC input (SFR "ADMD")

//----- ADC high reference voltage source select-----
//    ADVREFH = C_Vrefh_VDD;                    // ADC reference high voltage is supplied by internal VDD (Note: ADC clock freq. must be equal or less than 2MHz @ VDD=5.0V) 
//     ADVREFH = C_Vrefh_4V;                    // ADC reference high voltage is supplied by internal 4V  (Note: ADC clock freq. must be equal or less than 1MHz)
//     ADVREFH = C_Vrefh_3V;                    // ADC reference high voltage is supplied by internal 3V  (Note: ADC clock freq. must be equal or less than 500KHz)
 ADVREFH = C_Vrefh_2V;                    // ADC reference high voltage is supplied by internal 2V  (Note: ADC clock freq. must be equal or less than 250KHz)
    delay(100);                                // 4M/2T , 0.56mS
//----- ADC clock frequency select----------------------------     
//    ADR     = C_Ckl_Div1;                        // ADC clock=Fcpu/1, Clear ADIF, disable ADC interrupt    
//    ADR     = C_Ckl_Div2;                     // ADC clock=Fcpu/2, Clear ADIF, disable ADC interrupt    
  ADR      = C_Ckl_Div8;                    // ADC clock=Fcpu/8, Clear ADIF, disable ADC interrupt    
//    ADR     = C_Ckl_Div16;                    // ADC clock=Fcpu/16, Clear ADIF, disable ADC interrupt    

//----- ADC Sampling pulse width select-------------     
  ADCR  = C_Sample_1clk | C_12BIT;        // Sample pulse width=1 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 500KHz)
//     ADCR  = C_Sample_2clk | C_12BIT;        // Sample pulse width=2 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 1MHz)
//  ADCR  = C_Sample_4clk | C_12BIT;        // Sample pulse width=4 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 1.25MHz)
//     ADCR  = C_Sample_8clk | C_12BIT;         // Sample pulse width=8 adc clock, ADC select 12-bit conversion ( Note: ADC clock freq. must be equal or less than 2MHz)    

//--------------------------------------------------    
 ADJMD = 0x00;
 F_ADJMD();
}

你是否还在寻找稳定的海外服务器提供商?创新互联www.cdcxhl.cn海外机房具备T级流量清洗系统配攻击溯源,准确流量调度确保服务器高可用性,企业级服务器适合批量采购,新人活动首月15元起,快前往官网查看详情吧


当前名称:九齐单片机NY8B062E的ADC零点校准程序记录-创新互联
网址分享:http://cdweb.net/article/djciji.html