Measure battery voltage

Firmware/software/electronics/mechanics
almaz_1c
Member
Posts: 43
Joined: Tue Dec 09, 2014 12:58 pm

Measure battery voltage

Post by almaz_1c »

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.
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Measure battery voltage

Post by tobias »

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".
almaz_1c
Member
Posts: 43
Joined: Tue Dec 09, 2014 12:58 pm

Re: Measure battery voltage

Post by almaz_1c »

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.
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Measure battery voltage

Post by arnaud »

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
almaz_1c
Member
Posts: 43
Joined: Tue Dec 09, 2014 12:58 pm

Re: Measure battery voltage

Post by almaz_1c »

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?
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Measure battery voltage

Post by tobias »

During charging there, for example, 4.01 V on VBAT and 4.35 V on VCOM, - not equal.
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.
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?
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.

Are you sure the battery voltage measured by the nRF51 isn't good enough?
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Measure battery voltage

Post by arnaud »

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?
tobias
Bitcraze
Posts: 2339
Joined: Mon Jan 28, 2013 7:17 pm
Location: Sweden

Re: Measure battery voltage

Post by tobias »

Will it not damage the STM32 if there is voltage on one of the PIN while it is not powered?
Yes it could so VCOM should be used as it will be switched off when the power is off.
almaz_1c
Member
Posts: 43
Joined: Tue Dec 09, 2014 12:58 pm

Re: Measure battery voltage

Post by almaz_1c »

Are you sure the battery voltage measured by the nRF51 isn't good enough?
I write firmware for stm32f405 without using nRF.
Will it not damage the STM32 if there is voltage on one of the PIN while it is not powered?
I do it before you write this) As long as it works)
arnaud
Bitcraze
Posts: 2538
Joined: Tue Feb 06, 2007 12:36 pm

Re: Measure battery voltage

Post by arnaud »

I do it before you write this) As long as it works)
Then I would advise you to disconnect the battery when switching OFF the copter. So that you avoid stressing too much the stm32 GPIO.
Post Reply