# calculate battery voltage using pic ADC

I need to calculate battery voltage using my PIC's ADC. My battery voltage is 24V and ADC has a 12 bit resolution, the PIC operating voltage is 3.3V.

I am using the PIC's internal Vref+ and Vref- as reference voltages, ferrite bead (model 1206 ) I don't know the correct value. Why is the ferrite bead used?

How can I calculate the battery voltage using this circuit please help me with the calculation clearly?

I will write this answer a little more elaborately, as you do not seem to have very much knowledge about electronics.

First of all, your circuit does not look like a voltage measuring circuit, but more like a supplying circuit. (May be for your PIC microcontroller?)

The zener-diode Z2 limits the voltage on the right side to a maximum of 3.3V. (It does so by just becoming conductive at that voltage.)

Due to this, there is a voltage drop of 24V-3.3V=20.7V over R2, leading to a total current of 20.7mA. From this, 1.5mA will flow through R13, the rest of 19.2mA will flow through Z2.

If you connect something consuming let's say 15mA at 3.3V to the right side, Z2 will only consume 4.2mA. The total current through R2 will still be 1.5mA+15mA+4.2mA=20.7mA, so the voltage drop is still 20.7V and the remaining voltage on the right still is 3.3V.

However, if you connect something consuming more that 19.2mA, the overall current through R2 exceeds 20.7mA and so does the voltage drop. The Voltage on the right breaks down, below 3.3V.

So, this circuit allows to supply a 3.3V device consuming not more than 19.2mA on the right side. But be aware that there will always be a current of 20.7mA, even if no device is connected. This will slowly drain the battery. Also, due to the high voltage drop, over 86% of the battery's power is wasted as heat! That's not very efficient.

C1 and C9 (and their values) are quite typical blocking capacitors used e.g. near micro controllers. The power consumption of a microcontroller can change very quickly, while the wires also have an inductance. This means the circuit can not fulfill the fast changing power demands, leading to an unstable supply voltage for the microcontroller. As result, the microcontroller may not work fine. That capacitors act as buffer and can provide some current until the rest of the circuit provides the full current. (If you want, it's like a pantry)

Comming to the ferrite:
A first remark: 1206 is just the physical size, not the model, nor any electrical parameter
Ferrites block high frequencies and allow low frequencies (and DC) to pass. This also means they can filter sudden spikes of current by smoothing them a little. Let's say you have that microcontroller with its fast changing current consumption and some other circuit very sensitive to a smooth supply voltage. The current consumption of the microcontroller would cause voltage drops, which would be noticed by the other circuit. That ferrite would reduce this effect by smoothing the current flowing to the microcontroller. However, that would cause bigger voltage drops on the microcontroller side, but therefore, you have the capacitors.

Finally, you asked how to measure a battery voltage by ADC. In general, an ADC accepts a certain input voltage range. For the PIC, it is defined by $V_{REF-}$ and $V_{REF-}$ . In most cases, $V_{REF-}$ is 0V and $V_{REF-}$ can be chosen between the supply voltage (3.3V in your case) or an internal reference (see datasheet, I guess 1.25V). But it's also often possible to feed your own, external reference voltage to the ADC.

For precise measurement, use the internal reference, as it is independent from the supply voltage and very stable.

The ADC converts a voltage within that range to a number, i.e. $n=0$ for $V_{ADC\_in}=V_{REF-}$ and $n=2^{12} - 1= 4095$ (12-bit ADC) for $V_{ADC\_in}=V_{REF+}$. So, the conversion is

$$V_{ADC\_in}=(V_{REF+}-V_{REF-})\cdot\frac{n}{2^{12}-1}+V_{REF-}$$

Now, your battery voltage exceeds the range of the ADC, so you want to divide it down until it's in range. Do it so that the expected voltage to be measured will be a little below the upper ADC limit. For example, to measure your 24V using the internal 1.25V reference, use a 19kOhm and a 1kOhm resistor to divide the 24V down to 1/20, which is 1.2V. Of course, you will have to multiply $V_{ADC\_in}$ by 20 to get the actual voltage.

• thank you sweber. Now i am clear about adc calculation . – Pradeep kumark Jul 7 '15 at 6:54

The circuit you show appears to be a power supply. You cannot measure the actual battery voltage from it. The designator BATT.VOLT just means that it is derived from the battery.

If you want to measure battery voltage you need a voltage divider from the +24V to the PIC ADC input. You don't mention the part number, but I think most PICs require the source impedance to be less than 10K or 2.5K, so let's use 2.5K.

So you need two resistors R1 and R2 such that R2/(R1 + R2) = Vref/Vbat(max) where Vbat(max) is the maximum battery voltage you want to measure, and R1*R2/(R1+R2) < 2.5K.

So let's say you are using the FVR module (available on some PICs) for a 2.048V reference and Vbat(max) = 30V. Then you could pick R2 = 2.00K and R1 = 27.4K.

So for a 24V Vbat you'd get 3265 counts, and for a 30V Vbat you would get 4081 counts.

You can calculate Vbat = (ADC_counts/4096) * Vref * (27.4 +2)/2

Ferrite bead is used here just as a noise filter. R2 and R13 is a voltage divider circuit and zener is used to prevent the MCU pin from getting damaged.

As per me at ADC Pin of MCU there should not be a voltage greater than vref, Looking at the schematic it look likes it is 3.3V, since the used zener diode has a breakdown voltage of 3.3V.

Now coming to your schematic and assuming that the maximum sense voltage at MCU's ADC pin is 3.3V. As mentioned your battery voltage is 24V, R2 is 1K and R13 is 2.2K so the voltage at BAT.VOLT which will connect to the ADC pin of MCU can be calculated as below

BAT.VOLT=(R13/(R13+R2))*Vbat = 16.5V, which may damage your MCU pin.Since the maximum voltage that ADC pin can sense is 3.3V(Assumed) so here the value of resister has to be set in such a way that for 24 volt, the voltage at MCU pin should have 3.2V.

Since the ADC has a resolution of 12 bit, So for 3.3V you have a step of around 0.4mV.

And one resister should be used before Back to Back diode as shown in the figure below and the resistor value of voltage devider can be replaced with the value as shown in the figure