Is there any way of estimation the battery life from pwm outputs which goes to motors in microcontroller level. I'm planning to estimate path range with this. Microcontroller, sensor and other electronic device should be neglected.
Battery life is generally measured in amp hours. From a PWM perspective, you are pulsing current at a constant voltage, so you could estimate current output to be (duty cycle)*(rated current) where rated current is the nominal current draw at your operating voltage. Remember too that P=IV, so you could get a rated current by dividing rated power by operating voltage.
So now that you have an estimate for current draw, you can do a simplistic state of charge estimate called "Coulomb counting", which is just current integration.
This means that you take your current and multiply it by whatever your sample time interval is, then add it to the previous measurement.
spentCapacity = spentCapacity + (dutyCycle*maxCurrent)*dT
In this manner you accumulate how much current you have "spent" and can compare that to how much you started with.
This is not super accurate by any means, but if you're interested in a basic setup that will get you in the right ballpark this is it.
If you go this route, better current measurements are an easy way to improve accuracy, but Texas Instruments makes some "battery fuel gage" chips that are pretty slick too.
$\begingroup$ I'd just like to point out that you need to measure apples to apples. For comparisons, spentCapacity, your current multiplied by your sample time, should be in the same units that your battery capacity is in. The only exception to this might be if the conversion involves division, in which case I would suggest leaving spentCapacity in native units and only converting when you need to poll capacity. $\endgroup$– ChuckJul 25, 2015 at 11:38
$\begingroup$ So if current is measured in mA, but you're sample time is measured in seconds, then your spentCapacity is measured in mAs instead of the more common mAh. You could convert every sample to mAh with the following
spentCapacity = spentCapacity + (dutyCycle*maxCurrent)*dT/3600but then you're dividing by 3600 every time you update spentCapacity (high frequency). Instead, divide by 3600 only when you poll spentCapacity (low frequency) and save yourself the computational cost of all that division. $\endgroup$– ChuckJul 25, 2015 at 11:43