本帖最后由 Q80351951 于 2019-12-17 17:18 编辑
ADC不准,非常不准,问题在哪里?
uint8_t Adc_test(void)
{
stc_adc_cfg_t stcAdcCfg;
stc_adc_norm_cfg_t stcAdcNormCfg;
DDL_ZERO_STRUCT(stcAdcCfg);
DDL_ZERO_STRUCT(stcAdcNormCfg);
if (Ok != Clk_SetPeripheralGate(ClkPeripheralAdcBgr, TRUE))
{
return Error;
}
Adc_Enable();
M0P_BGR->CR_f.BGR_EN = 0x1u; //BGR必须使能
M0P_BGR->CR_f.TS_EN = 0x0u;
SysTick_m26_delay(3);
stcAdcCfg.enAdcOpMode = AdcNormalMode; //单次采样模式
stcAdcCfg.enAdcClkSel = AdcClkSysTDiv1; //PCLK
stcAdcCfg.enAdcSampTimeSel = AdcSampTime8Clk; //4个采样时钟
stcAdcCfg.enAdcRefVolSel = RefVolSelInBgr2p5; //RefVolSelAVDD;//参考电压:内部2.5V(avdd>3V,SPS<=200kHz) SPS速率 = ADC时钟 / (采样时钟 + 16CLK)
stcAdcCfg.bAdcInBufEn = TRUE; //电压跟随器如果使能,SPS采样速率 <=200K
stcAdcCfg.u32AdcRegHighThd = 0u; //比较阈值上门限
stcAdcCfg.u32AdcRegLowThd = 0u; //比较阈值下门限
stcAdcCfg.enAdcTrig0Sel = AdcTrigDisable; //ADC转换自动触发设置
stcAdcCfg.enAdcTrig1Sel = AdcTrigDisable;
Adc_Init(&stcAdcCfg);
stcAdcNormCfg.enAdcNormModeCh = AdcAVccDiV3Input; //通道0 P24
stcAdcNormCfg.bAdcResultAccEn = FALSE;
Adc_ConfigNormMode(&stcAdcCfg, &stcAdcNormCfg);
while (1)
{
Adc_Start();
while (FALSE != Adc_PollBusyState())
;
Adc_GetResult(&batt_voltage_data);
Adc_ClrAccResult();
batt_voltage = batt_voltage_data * 7500 / 4096; //电池电压
Uart1_Send_str((uint8_t *)"\r\n电");
Uart1_Send_str(uint16_to_5DEC(batt_voltage));
Uart1_Send_str((uint8_t *)" 电da");
Uart1_Send_str(uint16_to_5DEC(batt_voltage_data));
SysTick_m26_delay(1000);
Wdt_Feed(); //喂狗
}
}
|