Skip to main content
Visitor II
August 3, 2023
Question

Calculating Analog reference voltage using vref macro

  • August 3, 2023
  • 0 replies
  • 1673 views

I am using stm32wl55 controller to Calculate Analog reference voltage using vref macro, which is defined as follows:

#define __HAL_ADC_CALC_VREFANALOG_VOLTAGE(__VREFINT_ADC_DATA__,\
                                          __ADC_RESOLUTION__) \
__LL_ADC_CALC_VREFANALOG_VOLTAGE((__VREFINT_ADC_DATA__),\
                                 (__ADC_RESOLUTION__))
 
1) Calling a function to get the analog voltage value using:
 
GetBatteryVoltage()
{
    static VVG_HAL::AdcValue    value(GetAdc(), ADC_CHANNEL_VREFINT, AdcVrefintToVoltage);
    return value;
}
/**
 *  Scale an Vrefint ADC input to voltage
 */
float   AdcVrefintToVoltage(float adcVal)
{
    // __HAL_ADC_CALC_VREFANALOG_VOLTAGE returns millivolts
    return float(__HAL_ADC_CALC_VREFANALOG_VOLTAGE(uint32_t(adcVal), ADC_RESOLUTION_12B)) / 1000.0f;
}
 
Problem statement:
I am Getting the adc reading only on the second instance of  calling GetBatteryVoltage().GetValue(), with the analog value not getting converted to float by vref macro.
Please provide some solution to the issue I am facing.

 

 

    This topic has been closed for replies.