Chances are this has been worked out before, I don't know, I didn't really look. But here is the process that was used to determine how to calculate the battery voltage and current. (its like circuits 101 all over again).

Terms:

- V
_{bg}= Voltage of internal bandgap reference on the AVR = 1.1V - A
_{ref}= ADC value returned by reading V_{bg } - V
_{bat}= Voltage of battery - A
_{bat }= ADC value returned by reading V_{bat} - V
_{sense}= Voltage of the negative side of the current sense resistor - A
_{sense}= ADC value returned by reading the negative side of the current sense resistor - R
_{sense}= the value of the resistor used to sense current - I
_{read }= current read by the micro-controller

First assume the ratio of the 1.1V reference to the battery voltage is equal to the ADC reading of the reference to the ADC reading of the battery voltage. (this is *mostly* true)

And that's about it for the voltage calculation, onto current. First we find the voltage at the sense resistor using the same assumption as before that the ratio of the voltage is equal to the ratio of the ADC readings:

Using Ohm's law the current can be found by dividing the change in voltage by the resistance:

Now substituting in the above equations and simplifying yields I_{read}:

That's everything, since everything's now in terms of ADC values its fairly straight forward to simply get the values in software and calculate both the voltage of and current draw from the battery. All the units check out and a few sample calculations I ran seem to show that these equations work well enough (accuracy of the ADC throws current readings off by a few percentage points). If I overlooked something please let me know.

## Discussions

## Become a Hackaday.io Member

Create an account to leave a comment. Already have an account? Log In.