STC8 single-chip ADC sampling considerations

STC8 single-chip ADC sampling considerations

Recently doing a module that uses STC8 MCU development Hong Jing Company, the main module uses the ADC sampling device functions because it requires more than 10 channels, and the module should always shaking, so I hope the use of a Naicao a little chip, so I used the STC8 series microcontrollers, 16-channel ADC, sampling precision is 12, can better meet my requirements. A module start to do good, and once after six months to improve on the program I increased the single-chip channel switching time between, but eventually emerged sampling error phenomenon.

Because I want to poll all ADC channels, for design, I used a special order of sampling, the results of sampling error not know how it is, after they changed the program there is a problem, I have always considered the program question, got to the final cynicism, and, feeling is this is a bug STC's?

However, I finally found a clue to the Internet and try to change a bit the method according to the program, ojbk up. Posted about the trail's words:

If the input signal is large resistance (even bigger than 1K, if 10K on the great), then the ADC input capacitance of 0.01 ~ 0.1uF a ground terminal.
After switching channels, the first conversion value discarded.

Why have these requirements? Why a special plug-in ADC also have this same requirement?
For no input buffer ADC (the STC ADC input is no buffer), the sampling input of the ADC via a resistor (r, usually several K ohms) to the sampling capacitor C is charged (the sampling capacitor is generally 10 ~ 30PF, STC of can be calculated by 30PF), is assumed that the signal source resistance R0, the charge is sampled ((R0 + r) * C ), the sampling time t is generally very short, such as several STC fastest sampling clock is, a very short time .

I posted about the ADC acquisition function (before changes):

/**
 * [ADCRead description]
 * @Author     叶鹏程
 * @DateTime   2019-08-01T20:24:46+0800
 * @discrption : ADC采样函数,
 *  
 * @param      n                        [要采样的通道]
 * @param      value_point              [采样值存放地址]
 */
void ADCRead(uint8_t n,unsigned int  xdata *value_point){
    unsigned int adc_value = 0;
    
    ADC_SET_CHANEL(n);  //设置当前待转换的ADC通道
    ADC_START_ENABLE();

    while(ADC_STATE()); //等待转换
    
    ADC_FLAG_CLEAR();  

    adc_value = (int)ADC_RES << 8;                               //读取ADC结果
    adc_value |= (int)ADC_RESL;
    adc_value = adc_value>>4;

    *value_point = adc_value;
}

This is in accordance with the following clues changes:

/**
 * [ADCRead description]
 * @Author     叶鹏程
 * @DateTime   2019-08-01T20:24:46+0800
 * @discrption : ADC采样函数,
 *  
 * @param      n                        [要采样的通道]
 * @param      value_point              [采样值存放地址]
 */
void ADCRead(uint8_t n,unsigned int  xdata *value_point){
    unsigned int adc_value = 0;
    
    ADC_SET_CHANEL(n);  //设置当前待转换的ADC通道
    
    ADC_START_ENABLE();
    while(ADC_STATE()); //等待转换
    ADC_FLAG_CLEAR();  
    
    /* 这是清除了第一次转换的值,采用第二次采样,这样在切换通道时更加稳定*/
    ADC_START_ENABLE();
    while(ADC_STATE()); //等待转换
    ADC_FLAG_CLEAR();  

    adc_value = (int)ADC_RES << 8;                               //读取ADC结果
    adc_value |= (int)ADC_RESL;
    adc_value = adc_value>>4;

    *value_point = adc_value;
}

Summary, this is a problem ADC circuit, the future must pay attention to these things, but it seems their knowledge did not learn solid. Come on!

Guess you like

Origin www.cnblogs.com/Gentleaves/p/11285243.html