Measure battery voltage
Measure battery voltage
Hello. How can I measure battery voltage from stm32f405 ( crazyflie 2.0 ) in my own firmware, if I don't use nrf51822? I want to get relationship between residual capacity of battery an engine thrust to realize vertical motion model.
Re: Measure battery voltage
Currently the battery voltage is sent 100 times per second to the stm32 and you can get it using the pmGetBatteryVoltage function. If you want faster sampling then you would have to connect the VCOM expansion board pin to a stm32 ADC pin through a voltage divider. The battery voltage can currently also be logged from the cfclient "pm->vbat".
Re: Measure battery voltage
tobias. Thank you for answer.
Excuse me for noob question, but i can't understand who measure the battery voltage and put this value to variable "batteryVoltage" in pm.c module? There is no initializing of ADC in crazyflie 2.0 firmware.
Excuse me for noob question, but i can't understand who measure the battery voltage and put this value to variable "batteryVoltage" in pm.c module? There is no initializing of ADC in crazyflie 2.0 firmware.
Re: Measure battery voltage
Hi,
The reason there is no ADC setup in the STM32 is that the battery voltage is measured by the nRF51 chip. You can look at the schematic http://wiki.bitcraze.se/_media/projects ... matics.pdf the stm32 is not connected to the battery voltage.
Pm.c receives the battery voltage from syslink, the communication link between the STM32 and the NRF51. This is communicated 100 times per seconds and cannot be faster for hardware reason (the resistor bridge used to measure the battery voltage has a too high impedance to allow faster measurement). In the detail, this code in the NRF51 sends the battery voltage to syslink: https://github.com/bitcraze/crazyflie2- ... ain.c#L270 (the actual measurement is in pm.c) and then it arrives in syslink in the STM32 there https://github.com/bitcraze/crazyflie-f ... ink.c#L153 and the pmSyslinkUpdate function interprets the packet and set the battery voltage in STM32 https://github.com/bitcraze/crazyflie-f ... 405.c#L187.
If you want synchronized battery measurement at a rate higher than 100Hz you will have to cable it yourself by connecting VCOM to a STM32 ADC input throw a voltage divider. This can be done on the prototyping exp board for example.
I hope this sheds some light on the battery measurement.
/Arnaud
The reason there is no ADC setup in the STM32 is that the battery voltage is measured by the nRF51 chip. You can look at the schematic http://wiki.bitcraze.se/_media/projects ... matics.pdf the stm32 is not connected to the battery voltage.
Pm.c receives the battery voltage from syslink, the communication link between the STM32 and the NRF51. This is communicated 100 times per seconds and cannot be faster for hardware reason (the resistor bridge used to measure the battery voltage has a too high impedance to allow faster measurement). In the detail, this code in the NRF51 sends the battery voltage to syslink: https://github.com/bitcraze/crazyflie2- ... ain.c#L270 (the actual measurement is in pm.c) and then it arrives in syslink in the STM32 there https://github.com/bitcraze/crazyflie-f ... ink.c#L153 and the pmSyslinkUpdate function interprets the packet and set the battery voltage in STM32 https://github.com/bitcraze/crazyflie-f ... 405.c#L187.
If you want synchronized battery measurement at a rate higher than 100Hz you will have to cable it yourself by connecting VCOM to a STM32 ADC input throw a voltage divider. This can be done on the prototyping exp board for example.
I hope this sheds some light on the battery measurement.
/Arnaud
Re: Measure battery voltage
Thank you Arnaud. I understand now.
I need measure battery voltage on stm32, not nrf51.
And VCOM voltage == VBAT if battery in rest state ( not charging ).
During charging there, for example, 4.01 V on VBAT and 4.35 V on VCOM, - not equal.
So, what if i connect the VBAT connector to a stm32 ADC pin through a voltage divider? Is there is a possibility that I will damage quadcopter?
I need measure battery voltage on stm32, not nrf51.
And VCOM voltage == VBAT if battery in rest state ( not charging ).
During charging there, for example, 4.01 V on VBAT and 4.35 V on VCOM, - not equal.
So, what if i connect the VBAT connector to a stm32 ADC pin through a voltage divider? Is there is a possibility that I will damage quadcopter?
Re: Measure battery voltage
It is only when USB power is not there the VCOM will be the battery voltage so if you need to measure the battery voltage during charging it is a problem yes.During charging there, for example, 4.01 V on VBAT and 4.35 V on VCOM, - not equal.
As long as the ADC pin voltage does not exceed VCCA which is 3.0V it is OK so design the voltage divider for that.So, what if i connect the VBAT connector to a stm32 ADC pin through a voltage divider? Is there is a possibility that I will damage quadcopter?
Are you sure the battery voltage measured by the nRF51 isn't good enough?
Re: Measure battery voltage
Just a though: When switching the copter OFF, the NRF51 is still powered but the STM32 is not.
Will it not damage the STM32 if there is voltage on one of the PIN while it is not powered?
Will it not damage the STM32 if there is voltage on one of the PIN while it is not powered?
Re: Measure battery voltage
Yes it could so VCOM should be used as it will be switched off when the power is off.Will it not damage the STM32 if there is voltage on one of the PIN while it is not powered?
Re: Measure battery voltage
I write firmware for stm32f405 without using nRF.Are you sure the battery voltage measured by the nRF51 isn't good enough?
I do it before you write this) As long as it works)Will it not damage the STM32 if there is voltage on one of the PIN while it is not powered?
Re: Measure battery voltage
Then I would advise you to disconnect the battery when switching OFF the copter. So that you avoid stressing too much the stm32 GPIO.I do it before you write this) As long as it works)