Continue to Site

### Welcome to our site!

#### Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

Status
Not open for further replies.

#### brodin

##### New Member
I am building a handheld device with a PIC16F876A. I have got really far in this project, and i am almost finnished.

The circuit is using a 9V battery. I want to be able to check the battery voltage with my pic to warn for low batt. Is there possible to get an 0-9 volts on the A/D inputs? How do i solve this problem?

I have thougt about meassure the voltage after the 5V REG. But will the A/D work correctly when the VDD is below 5V?

I guess it compares the VDD and the A/D port, and if both VDD and the A/D input is the same voltage, that wouldn't work, right?

Measuring on the 5V side of the REG would not be really good anyway if it works, because the circuit stops working when the voltage is below 4V or something. So the resolution would be bad.

brodin said:
I am building a handheld device with a PIC16F876A. I have got really far in this project, and i am almost finnished.

The circuit is using a 9V battery. I want to be able to check the battery voltage with my pic to warn for low batt. Is there possible to get an 0-9 volts on the A/D inputs? How do i solve this problem?

I have thougt about meassure the voltage after the 5V REG. But will the A/D work correctly when the VDD is below 5V?

I guess it compares the VDD and the A/D port, and if both VDD and the A/D input is the same voltage, that wouldn't work, right?.

divide the voltage of your battery by 2 using resistors
connect 2 10K resistors in series between + and - of your battery
between the 2 resistors you'll now have Vbat / 2

so 4.5 V = battery full
4 V = battery 8 V
...

Aahh, it is really simple now when you say it =)

Thanks anyway!

You can also avoid using an ADC altogether. Since you are measuring the battery voltage (which is as close to DC as possible), you can simply estimate its voltage with the internal comparator in some of the pics.

There are a couple of ways to do it:

(1) Attach an RC circuit (know the time constant) to an output pin, which is initially low and to one input of the comparator. Bring the pin high and measure the time until the comparator toggles. Known the time constant allows you to estimate the battery voltage.

(2) Use/Roll a PWM in conjunction with an RC lowpass filter. The DC voltage is proportional to the duty cycle of the pulse. Increase the duty cycle until the comparator bit toggles and you can estimate the voltage.

Status
Not open for further replies.

Replies
37
Views
4K
Replies
7
Views
3K
Replies
30
Views
5K
Replies
9
Views
960
Replies
5
Views
649