Skip to main content
BTrem.1
Senior
January 11, 2021
Solved

How to access Bus voltage reading in motor control software

  • January 11, 2021
  • 6 replies
  • 2577 views

I'm using the STM32G431 MCU to run a BLDC motor with the middleware FOC code. I'd like to be able to report the bus voltage in the system but haven't been able to find the way to access the code. I found a procedure declared in bus_voltage_sensor.c, __weak uint16_t VBS_GetAvBusVoltage_V( BusVoltageSensor_Handle_t * pHandle ) but the input is the pointer BusVoltageSensor_Handle_t*pHandle. I'm guessing this is a pointer to a structure for my motor but I don't know where it is defined.

Is using the procedure VBS_GetAvBusVoltage_V the correct approach or is there a different method to use, something closer to the UI interface?

Thanks,

Brian

This topic has been closed for replies.
Best answer by jouko.perkkio

Oh, you're correct. I have the same scaling with value 65535, but it comes in later in my code. Good that this worked out for you (too).

6 replies

AntoineC
ST Employee
January 14, 2021

Hello @BTrem.1​ ,

This approach is the closer to the API, so you can access to the Bus Voltage value with the function  uint16_t VBS_GetAvBusVoltage_V( BusVoltageSensor_Handle_t * pHandle ).

You can find the input parameter in the structure RDivider_Handle_t (in r_divider_bus_voltage_sensor.h) or in PQD_MotorPowMeas_Handle_t (pqd_motor_power_measurement.h) where an access to the bus voltage structure is possible. These structures are initialized in mc_config file.

Example: VBS_GetAvBusVoltage_V(PQD_MotorPowMeasM1.pVBS)

or VBS_GetAvBusVoltage_V(&RealBusVoltageSensorParamsM1._Super)

Best Regards,

Antoine

BTrem.1
BTrem.1Author
Senior
January 15, 2021

Thanks!

This works:

	int32_t bRetVal;
	bRetVal = (int32_t)NTC_GetAvTemp_C(pTemperatureSensor[0]);
	Temp = bRetVal;
	// 
	bRetVal = VBS_GetAvBusVoltage_V(PQD_MotorPowMeasM1.pVBS);
	Volt = bRetVal;

I just wish the voltage had more resolution. My system is using a only a 5V bus voltage so right now it reports Volt = 4

Too bad it didn't have another couple bits to display 4.75 ;)

jouko.perkkio
Associate II
January 18, 2021

Hi, you can try scaling yourself, using the BusVoltageSensor_Handle_t's internal variable. Something like this:

 float V_d = (float)PQD_MotorPowMeasM1.pVBS->AvBusVoltage_d;
 float volts = V_d * (ADC_REFERENCE_VOLTAGE / VBUS_PARTITIONING_FACTOR);
 

 It uses floating points, but your G4 is as good with floats as it is with integers :thumbs_up: