cancel
Showing results for 
Search instead for 
Did you mean: 

How to access Bus voltage reading in motor control software

BTrem.1
Senior II

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

1 ACCEPTED SOLUTION

Accepted Solutions

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).

View solution in original post

6 REPLIES 6
AntoineC
ST Employee

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

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 😉

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 👍

Thanks for the pointer, un intended 😉

I hadn't looked into this yet and was assuming I was getting the truncated value. I'll report back after I dig into this.

Brian

Hi,

I ended up using the following:

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

The units of AvBusVoltage_d are uint16_t,

Thanks for your help, my printout now display to two digits, which is great for a 5v supply.

BT

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).