Solving for a divisor of .33 and picking R1 = 100K, we get a value for R2 of 49.25K. You are not going to find a 49.25K, at least not one you can afford. You will need to select a standard value resistor. First, use 1% resistors. Regular 5% resistors will not give you very accurate readings. The nearest standard 1% resistors are 48.7K and 49.9K ohms. We want the lower value because a higher value resistor would deliver more than 3.3V with a 10V battery.
The voltage divider with 100K and 48.7K resistors will give a divider ratio of 3.275. You might try other combinations of standard resistor values to see if you can get closer to the desired divisor ratio, but it is not usually that important. Whatever divisor ratio you end up using, you will need to factor that in when calculating the actual battery voltage. For example, if the A/D converter reads 4 volts and the divisor was .5, we have 4/.5 or 8V.
So far we had assumed for simplicity that the bottom of R2 was grounded. We would not want to do that in practice because current would also be flowing through the resistors all the time. This will reduce battery life. To prevent this we connect the resistor to a digital I/O pin, P0 in Figure 15-1.
Most of the time this pin is set to be an input. This presents a high impedance at the bottom end of R2 and very little current will flow. When we want to measure the battery voltage we first change the pin to an output set low. This will be very close to ground and we can then take our measurement. After the reading is complete, the pin is changed back to an input.
There will be a bit of voltage drop from the transistor to ground inside the micro. This will cause some loss of accuracy of the voltage reading. This will probably not be too important since battery life estimates are just that, estimates. If you need higher accuracy you can use a FET transistor to ground and turn that on and off. Pick a FET with a low Rds-on specification.
A different version of the battery and regulator is when you use a boost switching regulator. You could for example use a single 1.5V battery with a regulator that bumps the battery voltage up to what the micro can work at, say 3.3V. In this case you could just connect the battery to the A/D input pin. One word of caution though. Switching regulators often generate a fair amount of noise. To get accurate readings you might need a bit of filtering to battery voltage signal to the micro. Part 10 discusses simple RC filtering.
Direct Battery power
Often it is desirable to power the micro directly to the battery with no regulator. This reduces the part cost and does not waste power in the regulator. Of course you need a battery and micro combination where the micro operates properly in the range of voltages the battery will present during its useful life.
We don’t have to worry about putting too much voltage directly to the A/D pin since it will never be higher than the supply voltage. Can we just connect the battery to the A/D pin without the voltage divider?