2023-03-08 02:08 AM
I am referring to the B-G431-ESC1 source code and i feel there is an error in the battery voltage measurement source code. A conversion factor is used to convert from the ADC voltage to the battery voltage. It is initialized as follows
RDivider_Handle_t BusVoltageSensor_M1 =
{
._Super =
{
.SensorType = REAL_SENSOR,
.ConversionFactor = (uint16_t)(ADC_REFERENCE_VOLTAGE / VBUS_PARTITIONING_FACTOR),
},
The voltage is read in u16Volt format when reading the ADC register value , I assume the adc driver will only give max value of 12Bit (4096) for 3.3V, but where is this conversion added to convert to Battery voltage. Please advise.
Solved! Go to Solution.
2023-03-09 06:49 AM
Hello @Community member,
The ADC is configured to be left aligned, so the maximum value is actually 0xFFF0 = 65 520
The conversion you are looking for is done in function function VBS_GetAvBusVoltage_V from bus_voltage_sensor.c file.
/**
* @brief It return latest averaged Vbus measurement expressed in Volt format
* @param pHandle related Handle of BusVoltageSensor_Handle_t
* @retval uint16_t Latest averaged Vbus measurement in Volt format
*/
__weak uint16_t VBS_GetAvBusVoltage_V(const BusVoltageSensor_Handle_t *pHandle)
{
uint32_t temp;
#ifdef NULL_PTR_CHECK_BUS_VOLT
if (MC_NULL == pHandle)
{
temp = 0U;
}
else
{
#endif
temp = (uint32_t)(pHandle->AvBusVoltage_d);
temp *= pHandle->ConversionFactor;
temp /= 65536U;
#ifdef NULL_PTR_CHECK_BUS_VOLT
}
#endif
return ((uint16_t)temp);
}
2023-03-09 06:49 AM
Hello @Community member,
The ADC is configured to be left aligned, so the maximum value is actually 0xFFF0 = 65 520
The conversion you are looking for is done in function function VBS_GetAvBusVoltage_V from bus_voltage_sensor.c file.
/**
* @brief It return latest averaged Vbus measurement expressed in Volt format
* @param pHandle related Handle of BusVoltageSensor_Handle_t
* @retval uint16_t Latest averaged Vbus measurement in Volt format
*/
__weak uint16_t VBS_GetAvBusVoltage_V(const BusVoltageSensor_Handle_t *pHandle)
{
uint32_t temp;
#ifdef NULL_PTR_CHECK_BUS_VOLT
if (MC_NULL == pHandle)
{
temp = 0U;
}
else
{
#endif
temp = (uint32_t)(pHandle->AvBusVoltage_d);
temp *= pHandle->ConversionFactor;
temp /= 65536U;
#ifdef NULL_PTR_CHECK_BUS_VOLT
}
#endif
return ((uint16_t)temp);
}
2023-03-10 07:09 AM
Thank you very much got response from ST employee, which will help to clarify our doubts and move forward more confidently.
As per the circuit, the maximum Battery voltage = 3.3/0.096 = 34.375V appx.
So if i receive the ADC count of 65520=0xFFF0, the max voltage is 34.375V
and if i receive a adc count of 32768 = 0x8000, the voltage is 17.18V. Am i correct? Please advise.
2023-03-10 07:40 AM
Hello,
I do not see any issue with your computation.
Please note that the Pilot reads volt in unit16_t so you will have only integer values. in your case you should read 17 V.
Hope it helps.
Cedric