Battery Power Management

What are you developing?
Post Reply
peeknot
Posts: 24
Joined: Thu Dec 14, 2017 3:08 pm

Battery Power Management

Post by peeknot » Wed Dec 20, 2017 3:07 pm

Newbie here ,so I`m gathering ideas on how to measure the voltage of a 4 series 12v battery using voltage divider in each node of the circuit, can anyone give me some idea on how to measure it using blue pill. Though I have some ideas for arduino but it might not work in blue pill. Any thoughts?

The circuit below shows the placement of the battery , the 4 wires is where I put the voltage divider.

https://ibb.co/c5pjum

User avatar
mrburnette
Posts: 2190
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Battery Power Management

Post by mrburnette » Wed Dec 20, 2017 4:28 pm

It all comes down to resistance!

If you consider 4x 1.5V cells and a 5V AVR, you know that you can measure 1.5V, 3.0V, and 4.5V without issues (5V reference) but that last cell is going to cook the UNO since 6.0V > 5.0V

So you need a voltage divider. Oh, crap ... that means series and parallel stuff. Unfortunately, yes.

1) how much current are you willing to throw-away as wasted power? Measuring must have a small load since the Analog_input pins are 10K impedance and higher (actual resistance of CMOS very high.)

AN2834 tells all ... PDF warning.

You may find this Google Query useful as this question has been asked in other forums.

Instead of trying to find batteries for your old college Ti calculator, use this circuit simulator: here
Screenshot.png
Screenshot.png (36.54 KiB) Viewed 348 times

Ray

zmemw16
Posts: 1674
Joined: Wed Jul 08, 2015 2:09 pm
Location: St Annes, Lancs,UK

Re: Battery Power Management

Post by zmemw16 » Wed Dec 20, 2017 4:46 pm

someone mention the max input voltage of the adc ?
someone mention the range of output from each battery ?
can it go past 12v i.e. on charging ?

the 1st, bottom battery is perhaps the easiest to do, but won't the resolution get progressively worse with each battery ?
the resistors getting more weird in values and required tolerance?

stephen

User avatar
Pito
Posts: 1731
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Battery Power Management

Post by Pito » Wed Dec 20, 2017 5:43 pm

Your 4x12V is in series. So the voltages are
12V
24V
36V
48V
You want to use four voltage dividers, from each battery output against gnd.
I would use
12V 10k/2k7
24V 22k/2k7
36V 33k/2k7
48V 47k/2k7
as most probably the max voltage of a freshly charged battery could easily be more than 14V.
The max voltage at the particular 2k7 divider node will not be more than 3.3V, so it could be wired to 4 ADC inputs.
You have to calibrate each adc input in software ;) .
Mind there could be voltage peaks (!) at each adc input in case you power an inductive load (motors, relays, dc-dc/dc-ac converters, etc.) with those batteries.
Last edited by Pito on Fri Dec 22, 2017 10:57 am, edited 2 times in total.
Pukao Hats Cleaning Services Ltd.

User avatar
Pito
Posts: 1731
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Battery Power Management

Post by Pito » Wed Dec 20, 2017 6:42 pm

After calibrating each ADC input in software (Vx = kx * ADCx), you may get the particular battery voltage as the difference of the voltages..
For example:

Code: Select all

V1 = k1 * ADC1
V2 = (k2 * ADC2) - (k1 * ADC1)
V3 = (k3 * ADC3) - (k2 * ADC2)
V4 = (k4 * ADC4) - (k3 * ADC3)
The reference voltage of the BluePIll's ADCs is 3.3V.
The ADCs are 12bits = 4096 values for full 3.3V reference.
From these data and the picture below you may get the kx easily.
voltage dividers.JPG
voltage dividers.JPG (59.92 KiB) Viewed 226 times
Last edited by Pito on Fri Dec 22, 2017 11:15 am, edited 2 times in total.
Pukao Hats Cleaning Services Ltd.

peeknot
Posts: 24
Joined: Thu Dec 14, 2017 3:08 pm

Re: Battery Power Management

Post by peeknot » Thu Dec 21, 2017 3:30 am

AN2834 tells all ... PDF warning.

You may find this Google Query useful as this question has been asked in other forums.

Instead of trying to find batteries for your old college Ti calculator, use this circuit simulator: here
I really need this thanks mr burnette


To mr pito thanks for the very informative circuit diagram, lastly I got this source code below to get the exact voltage of a single 12v battery I tested it lately I got good result. Can i use this? changing the 5.015= 3.2 and 1024 = 4096 and what does the k means? sorry about asking so much stuff.

Code: Select all

#define NUM_SAMPLES 10

int sum = 0;                    // sum of samples taken
unsigned char sample_count = 0; // current sample number
float voltage = 0.0;            // calculated voltage

void setup()
{
    Serial.begin(9600);
}

void loop()
{
    // take a number of analog samples and add them up
    while (sample_count < NUM_SAMPLES) {
        sum += analogRead(A2);
        sample_count++;
        delay(10);
    }
    voltage = ((float)sum / (float)NUM_SAMPLES * 5.015) / 1024.0;
    Serial.print(voltage * 11.132);
    Serial.println (" V");
    sample_count = 0;
    sum = 0;
}

User avatar
BennehBoy
Posts: 500
Joined: Thu Jan 05, 2017 8:21 pm
Location: Yorkshire
Contact:

Re: Battery Power Management

Post by BennehBoy » Thu Dec 21, 2017 11:10 am

mrburnette wrote:
Wed Dec 20, 2017 4:28 pm
Instead of trying to find batteries for your old college Ti calculator, use this circuit simulator: here
This is why I find it often pays to read posts that only bare a passing resemblance to things I'm interested in, that simulator is worth its weight in gold, thanks mrburnette.

A long time ago in a galaxy far far away I would've used SPICE for this - alas the force is not strong with this one.
-------------------------------------
https://github.com/BennehBoy

User avatar
mrburnette
Posts: 2190
Joined: Mon Apr 27, 2015 12:50 pm
Location: Greater Atlanta
Contact:

Re: Battery Power Management

Post by mrburnette » Thu Dec 21, 2017 1:26 pm

BennehBoy wrote:
Thu Dec 21, 2017 11:10 am
<...>
This is why I find it often pays to read posts that only bare a passing resemblance to things I'm interested in, that simulator is worth its weight in gold, thanks mrburnette.

A long time ago in a galaxy far far away I would've used SPICE for this - alas the force is not strong with this one.
Yes, we would have all used SPICE at one time because there were few alternatives. The referenced link to the Circuit Simulator was originally written in JAVA and a year or so ago, a dude took on rewriting it in Javascript. The original author adopted the Javascript because it is just superior and will run on most Android tablets (I suspect iPad, too) as the entire simulator runs in the browser context. Simply brilliant.

Another one of my favorite links is here, for quick research and validation... I'm getting old and sometimes need to validate "facts" the way I currently remember them :lol:

For those who love Excel, this is an amazing place for simulations.

Ray

User avatar
Pito
Posts: 1731
Joined: Sat Mar 26, 2016 3:26 pm
Location: Rapa Nui

Re: Battery Power Management

Post by Pito » Fri Dec 22, 2017 10:33 am

..lastly I got this source code below to get the exact voltage of a single 12v battery I tested it lately I got good result. Can i use this? changing the 5.015= 3.2 and 1024 = 4096 and what does the k means?
Do not start with source. Rather try to understand how a voltage divider and an ADC work. Spend a while with simple calculations (a pencil and a sheet of paper). You may need a $3 calculator for most arduino/stm32duino designs, no Spice is needed :)
PS: updated above the resistors values for a better safety margin..
Voltage dividers:
https://learn.sparkfun.com/tutorials/voltage-dividers
ADC (use the "System Voltage" = Vref=3.3V and the "Resolution of ADC"= 4095 with the BluePill)
https://learn.sparkfun.com/tutorials/an ... conversion
Pukao Hats Cleaning Services Ltd.

Post Reply