PDA

View Full Version : Voltage Monitoring



Megahertz
- 7th July 2011, 09:22
I have a RFmodule & a PIC (16F877A). They both can run upto 3V to 5V. One pin of the RF module gives a constant voltage of 2.8V.

I plan to run the PIC on 4 AA batteries, rechargeable. (appx 1.2v - 1.3v when fully charged).

I want to take this lower voltage (2.8V) as a reference and check when battery pack reaches 3.6. Can someone please guide me how I can take the lower voltage as a ref and check the supply voltage. Thanks

mackrackit
- 7th July 2011, 11:09
One way would be to use a voltage divider on the battery pack so when it reaches 3.6 the divider returns 2.8.

Charles Linquis
- 7th July 2011, 13:21
If you set Vref to Vdd and read the A/D, you will find that the constant 2.8V will give you an A/D count of LARGER than 716 when the battery voltage drops below 4V. No resistors needed.

Megahertz
- 7th July 2011, 14:02
If you set Vref to Vdd and read the A/D, you will find that the constant 2.8V will give you an A/D count of LARGER than 716 when the battery voltage drops below 4V. No resistors needed.

Since it is a battery powered application. This seems a better option. Could you please explain more. I not an expert on this subject.

Megahertz
- 7th July 2011, 15:03
What setting of ADCON1 should I choose and what to connect where? I need maximum number of PortA pins as digital. Thanks

Charles Linquis
- 8th July 2011, 02:13
I think you can read the datasheet as far as ADCON1 goes.

Most PICs let you choose between two sources of Vref. You can choose AN3 or Vdd. If you choose AN3, then you must connect a reference voltage to that pin. All A/D readings will be compared against that reference.
If the reference is 3.0V the a 10 bit A/D will read 3.0V on any other A/D input as 1023. The "count" (1023) is equal to (input/reference) * ((2^10) - 1).
If you apply 2.0V to an A/D input, and the reference is 3.0V, the count will be 2/3 * 1023 = 682.
Everything is compared AGAINST the reference.

If you set Vdd as your reference, then every A/D conversion will be compared to Vdd.
Since your external chip puts out a constant 2.8V, if Vdd (the reference) is 5.0V then the A/D will output 2.8/5 * 1023 = 573
If Vdd drops to 4.0V, then the A/D will output 2.8/4 * 1023 = 716
If Vdd drops even further, the A/D output will go higher than 716


If you set

Charles Linquis
- 8th July 2011, 02:24
Additionally, if you have any other voltages to measure, connect your 2.8V to AN3. You can change Vref on the fly. Set Vref to AN3, and you can measure the other voltages accurately without regard to the battery voltage. Then set Vref to Vdd and measure the battery voltage, switch it back and measure your other voltages...

I use this technique often when reading absolute voltages (which must be compared against a constant reference) and ratiometric sensors, whose output varies as a percentage of their supply voltage (such as Hall-effect current sensors).

Megahertz
- 9th July 2011, 02:45
Thanks Charles. Points noted. Very useful information. I am going to go ahead and try to play with Analog settings a little. Thanks again.

Megahertz
- 9th July 2011, 22:26
Just a quick question to re-confirm my understanding.

I will be using a 3V fixed voltage regulator for my PIC. Now I just to know that, If the setting of ADCON1 can be "1110" ?

I am planning to use supply voltage as reference and by using a voltage divider, send the battery voltage to PortA.0.

PIC is - 16f877a

Charles Linquis
- 10th July 2011, 17:54
First - if you read the datasheet, the 16F877A is not rated to run below 4.0V unless you choose the "LF" version.
Second, why do you need a voltage regulator at all? If you are running off batteries, and the battery voltage doesn't go above 5.5V, then using a voltage regulator will DECREASE battery life.

If you want to have the longest battery life AND be able to measure battery voltage, then connect VDD directly to the battery. No voltage regulator.
Connect your 2.8V signal to AN0 and ADCON1 to %01001110 . Read AN0. If it is above 716, then your battery is below 4V.

jellis00
- 10th July 2011, 20:36
I have a RFmodule & a PIC (16F877A). They both can run upto 3V to 5V. One pin of the RF module gives a constant voltage of 2.8V.

I plan to run the PIC on 4 AA batteries, rechargeable. (appx 1.2v - 1.3v when fully charged).

I want to take this lower voltage (2.8V) as a reference and check when battery pack reaches 3.6. Can someone please guide me how I can take the lower voltage as a ref and check the supply voltage. Thanks

I didn't check the Data Sheet for the 16F877A to see whether it has an HLVD module or not. If it does, you can easily use the technique I described in an article on this forum to check the supply voltage. Check it out at: http://www.picbasic.co.uk/forum/content.php?r=321-How-to-use-the-HLVD-module-as-a-low-voltage-monitor . It has schematic, layout, code, et al. Hope this helps.

Megahertz
- 10th July 2011, 21:20
Got it. Thanks a lot

Charles Linquis
- 11th July 2011, 23:51
If you want to know when the battery goes below 3.6V, then you would check AN0 for a count greater than 796.

2.8/3.6 = .77777
.777 X 1023 = 796