本帖最后由 uchiha_itachi 于 2018-1-30 09:06 编辑
请教下各位大神
使用的芯片:STM8L051F3
使用内部参考电压1.225v来计算VDD的电压。
网上找的计算公式:VDD=1.225*4096/Nadc
我的输入电压是3.3V,也就是VDD电压3.3v
我的问题:
1.为什么每次读取到的Nadc值不一样?
2.为什么会有误差?我的误差大概在0.1V左右。
读十次,取平均值,有时候在3.2V左右。
我的ADC配置代码如下:
void sys_ADC_Init(void)
{
CLK_PCKENR2_PCKEN20 = 1; // Enable ADC1 clock
ADC1_TRIGR1_VREFINTON = 1; // open internal reference voltage
ADC1_CR1_ADON = 1; // wakes up the ADC from Power down mode.
ADC1_CR1_RES = 0; // Configurable resolution(00: 12-bit resolution)
ADC1_CR1_CONT = 0; // Continuous conversion(0:Single conversion mode)
ADC1_CR2_PRESC = 1; // Clock prescaler
ADC1_SQR1_DMAOFF = 1; // disable DMA
ADC1_CR3_SMTP2 = 0x06;
ADC1_SQR1_CHSEL_S28 = 1;
}
void ADC_Data_Read(uint16_t *AD_Value)
{
uint16_t tmpreg_H = 0;
uint16_t tmpreg_L = 0;
ADC1_CR1_START = 1; // Conversion start
while( ADC1_SR_EOC == 0 ); // Wait for Conversion complete(0: Conversion not complete)
ADC1_SR_EOC = 0; // clear the interrupt flag
tmpreg_H = (uint16_t)((ADC1_DRH_CONV_DATA11 << 3)| (ADC1_DRH_CONV_DATA10 << 2)
| (ADC1_DRH_CONV_DATA9 << 1) | (ADC1_DRH_CONV_DATA8));
tmpreg_L = (uint16_t)((ADC1_DRL_CONV_DATA7 << 7) | (ADC1_DRL_CONV_DATA6 << 6)
| (ADC1_DRL_CONV_DATA5 << 5) | (ADC1_DRL_CONV_DATA4 << 4)
| (ADC1_DRL_CONV_DATA3 << 3) | (ADC1_DRL_CONV_DATA2 << 2)
| (ADC1_DRL_CONV_DATA1 << 1) | (ADC1_DRL_CONV_DATA0));
*AD_Value = (uint16_t)((uint16_t)((uint16_t)tmpreg_H << 8) | tmpreg_L);
}
void Get_battery_power_value(void)
{
uint16_t AD_value_tmp = 0;
uint16_t AD_value_sum = 0;
uint8_t sample_count;
for(sample_count = 0; sample_count < 10; sample_count++){
ADC_Data_Read(&AD_value_tmp);
AD_value_sum += AD_value_tmp;
delay_ms(100);
}
AD_value_sum = AD_value_sum/10;
d_battery_power = (uint16_t)((
5018000/AD_value_sum)); // 5018 = 1.225*4096
}
以上是什么问题?有什么办法解决吗?
先谢过了。
一周热门 更多>