如何检测电池电量,有例程源码参考吗?



  • 如何检测电池电量,有例程源码参考吗?



  • 此回复已被删除!


  • 在driver_adc.h中,有说明:
    USAGE SAMPLE
    1. get vbat value
    struct adc_cfg_t cfg;
    uint16_t result, ref_vol;

        memset((void*)&cfg, 0, sizeof(cfg));
        cfg.src = ADC_TRANS_SOURCE_VBAT;
        cfg.ref_sel = ADC_REFERENCE_INTERNAL;
        cfg.int_ref_cfg = ADC_INTERNAL_REF_1_2;
        cfg.clk_sel = ADC_SAMPLE_CLK_24M_DIV13;
        cfg.clk_div = 0x3f;
        adc_init(&cfg);
        adc_enable(NULL, NULL, 0);
    
        adc_get_result(ADC_TRANS_SOURCE_VBAT, 0, &result);
    	ref_vol = adc_get_ref_voltage(ADC_REFERENCE_INTERNAL);
        // vbat_vol = (result * 4 * ref_vol) / 1024 mV.


  • uint16_t Batt_Vol_Detection(void) //电池电量内部检测
    {
    //------------------------------
    uint16_t result, ref_vol,vbat_vol;
    adc_get_result(ADC_TRANS_SOURCE_VBAT, 0, &result);
    ref_vol = adc_get_ref_voltage(ADC_REFERENCE_INTERNAL);
    vbat_vol = (result * 4 * ref_vol) / 1024;
    //------------------------------
    return vbat_vol;
    }