Skip to main content
MQasi.2
Associate II
June 10, 2023
Question

How can i get the Vbat actual value from ADC?

  • June 10, 2023
  • 2 replies
  • 2405 views

Hello,

i'm using STM32G070, The firmware i have programmed converts the analog voltage to didital using ADC. the code is below:


_legacyfs_online_stmicro_images_0693W00000dDX43QAG.pngthe values i get from this is :

OUTPUT:


_legacyfs_online_stmicro_images_0693W00000dDX48QAG.pngIn the datasheet it is mention that a resister bridge for VBAT is 39K ohm which has ratio 3 on VBAT measurement .


_legacyfs_online_stmicro_images_0693W00000dDX4IQAW.pngso according to this the ADC value should be around 1365 which wil give us a voltage vaue of 1.1 but the result is voltage:0.48 and adc value:600.

please give me any suggestion, whats wrong with it.

thanks in advance.

    This topic has been closed for replies.

    2 replies

    S.Ma
    Principal
    June 10, 2023

    I would do:

    1- Configure the ADC and perform calibration if possible

    2- Do your Vbat mesurement, the real value you will sense is Vbat / 3., the measurement is respective to Vdda for 2047 full scale 12 bit value. (3.0, 3.3, 3.6V etc... )

    3- Run a Vref measurement to deduct VddA value in mV

    4- Walk back the path to deduct accurately Vbat.

    Karl Yamashita
    Principal
    September 18, 2024

    Change the sampling time. I used the maximum value 640.5 cycles but you can play with other values. But I know the minimum (default) does not work as I get a lower voltage like ~1V. 

    KarlYamashita_1-1726623682292.png

     

    I did a initial calibration before the main while loop.

    HAL_ADCEx_Calibration_Start(&hadc1, ADC_SINGLE_ENDED);

     

    Measure the VREFP voltage and divide that by 4096 to get the ADC resolution.

    #define ADC_RESOLUTION (3.259 / 4096) // my board measure 3.259V
    
    void ADC_Check(void)
    {
    	char str[32] = {0};
    	float adcVoltage;
    
    	if(adc_data.adcRdy)
    	{
    		adc_data.adcRdy = false;
    		adcVoltage = adc_data.adcValue * 3 * ADC_RESOLUTION;
    		sprintf(str, "vbatt=%f, ADC_Value=0x%lX", adcVoltage, adc_data.adcValue);
    		UART_DMA_NotifyUser(&uart2_msg, str, strlen(str), true);
    	}
    }

     

    Here is Docklight output

    KarlYamashita_0-1726623534310.png

     

     

     

     

     

     

     

     

    If a reply has proven helpful, click on Accept as Solution so that it'll show at top of the post.CAN Jammer an open source CAN bus hacking toolCANableV3 Open Source