2021-01-11 10:46 AM
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
Solved! Go to Solution.
2021-01-25 11:19 PM
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).
2021-01-14 01:44 AM
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
2021-01-14 09:28 PM
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 ;)
2021-01-17 10:15 PM
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:
2021-01-18 09:35 AM
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
2021-01-25 04:47 PM
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
2021-01-25 11:19 PM
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).