![]() | ![]() | ![]() |
| | |||||||
| Micro Controllers Discuss all aspects of micro controllers - building them, coding them, etc. All controllers are welcome - PIC, BASIC, Z8 Encore!, etc. |
| | LinkBack | Thread Tools | Display Modes |
| | (permalink) |
| 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. | |
| |
| | (permalink) | |
| Quote:
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 ... | ||
| |
| | (permalink) |
| Aahh, it is really simple now when you say it =) Thanks anyway! | |
| |
| | (permalink) |
| 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. | |
| |