View previous topic :: View next topic |
Author |
Message |
matrizoic Guest
|
newbee - battery level |
Posted: Wed Jun 08, 2005 7:07 am |
|
|
Hi !
Battery level check:
How to "periodicly" check if some pin has changed his value ( from 1 to 0 ).
I have set that the pin value is 1 until battery is over minimun. |
|
|
Guest
|
Re: newbee - battery level |
Posted: Wed Jun 08, 2005 9:48 am |
|
|
matrizoic wrote: | Hi !
Battery level check:
How to "periodicly" check if some pin has changed his value ( from 1 to 0 ).
I have set that the pin value is 1 until battery is over minimun. |
I assume that you're using a voltage regulator with an open drain pin that will drive your PIC's pin low when the battery voltage has fallen below a known threshold.
I also assume that your PIC is sleeping most of the time, and waking up periodically when the WDOG times out, bringing you out of sleep. You can check this pin before sleeping again.
OR
If you are not using the WDOG at all, then you had better hook the lo-batt indicator pin to an interrupt pin on the PIC, to wake it up out of sleep. |
|
|
Guest Guest
|
|
Posted: Wed Jun 08, 2005 11:38 am |
|
|
I dont use WDT.
I dont know if this is smart, but should i check the battery level each hour, each day or what?
I meen how to check if the status of the pin is changed in some time...
I will be loosing time and power for such requests ?
Do u have some example ? |
|
|
valemike Guest
|
|
Posted: Wed Jun 08, 2005 1:24 pm |
|
|
The only example I have in any of our products, I did in assembly, just because it was easy enough and i wanted to re-hone my assembly know-how. Even then, i used the wdt to wake myself up every few seconds (set the wdt timeout to max).
If it were up to me, i'd still use the wdt to wake me up from sleep. Otherwise, i would have no protection against a malfunctioning program. The amount of power it takes to wake up every few seconds, check some pins, and go back to sleep is negligible. Take for example - Zigbee. End devices have beacons (?) which make a sleeping device sleep for 5 seconds, wake up, transmit a heartbeat or status announcement, and go back to sleep. Even these applications claim to outlast the battery's shelf life!
Okay, so enough about the wdt preaching. As for how to get the status of a pin without waking up every few seconds to check it -- you'd have to use an interrupt pin. Whether it be RB0/INT or any port b on change interrupts, this is your only choice. |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Wed Jun 08, 2005 1:50 pm |
|
|
We have one product in which I check for a low battery voltage
and display the "LOBAT" symbol on the LCD if it's low.
On the 16F628, I used the comparator to check the voltage
of a 9v battery. The circuit consists of a IRF7306 FET with
one Source pin going to the 9v battery. The two A & B drain
pins go to a voltage divider (with 3.9K on top and 2.2K on the
bottom). The gate on the FET is driven by the Collector pin of
a 2N3904 transistor with a 3.9K to the 9v battery. The emitter
goes to ground, and the base connects to a port B pin on
the PIC, with a 3.9K series resistor. The FET is turned on
for just a few microseconds to check the battery voltage.
You could check it once every second, or once every minute,
or longer. It doesn't really matter because the test is done
so quickly that hardly any power is wasted.
The code is in the post below.
http://www.ccsinfo.com/forum/viewtopic.php?t=2236 |
|
|
guest Guest
|
|
Posted: Thu Jun 09, 2005 8:27 am |
|
|
What is your PIC doing when it is not checking the battery? Is it sleeping? Is it powered off? Is it polling a UART or waiting for a button press?
If all you are doing is testing a bit the resource cost is very low. You could check it every button press or incomming serial character. If you decided to use an 8 bit counter and only check the battery every 256 characters the overhead of incrementing the counter would probably be as much as that of checking the battery and there would be no savings.
Sherpadoug |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
|
Guest Guest
|
|
Posted: Fri Jun 10, 2005 3:23 am |
|
|
Quote: | You could check it every button press |
Chip is sleeping and waiting for button press to read the pin value.
Each time you press button ( that's it how i want to make it ) battery level should be readed... This could be after 1 hour or after few days...
I forget to mention ( and after a saw the PCM Programmer's routine ) , im checking just one pin, so if i get this right then i can make this with setup_Vref() ? Like this: Button pressed - if value at pin B3 == 0 battery low
Could this be done simply on this way ? |
|
|
Guest Guest
|
|
Posted: Sun Jun 12, 2005 8:54 am |
|
|
Sorry for such dumb questions but im newbee in this...
TO PCM'S EXAMPLE
Realy newbee question:
BATTERY_TEST_FET_ON_PIN_B5 ---> IS THIS V P P IN YOUR CASE
BAT_LEVEL_PIN ---> IS THIS V D D IN YOUR CASE
? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 12, 2005 10:36 am |
|
|
Quote: |
BATTERY_TEST_FET_ON_PIN_B5 ---> IS THIS V P P IN YOUR CASE
BAT_LEVEL_PIN ---> IS THIS V D D IN YOUR CASE |
I'm not sure if you understand what my post was about. It seems like
you think it's a PIC programmer. It's not. It's way to measure
the battery voltage of a 9v battery, so that the user can be warned
with a "LOBAT" symbol on a LCD when the battery is getting low.
Here are the pin descriptions. These are for a 16F628:
BATTERY_TEST_FET_ON_PIN_B5 --
This is a pin on Port B of the PIC, and it turns the FET on or off.
This pin goes to a 3.9K resistor, which then goes to the base of a
2N3904 transistor, which controls the FET. The connections are
described in a previous post, above.
BAT_LEVEL_PIN_A1 --
This is the comparator input pin on the PIC. The output of the
voltage divider goes to this pin, so it can be measured. |
|
|
Guest Guest
|
|
Posted: Sun Jun 12, 2005 12:03 pm |
|
|
I need a lobat but i have some problem with understanding...
Teoreticly:
If u would have just one pin ( let's say pin 21 ) that i want to test, and
lets say i have value of 1 on this pin, so long until battery falls under 50%.
After the battery falls under 50% i have 0 on this pin.
I want so check each time, when button will be clicked, the value of that pin.
If its 0 show LOBAT.
How would you do that?
Do i need comparator and can this be this done on this way? |
|
|
PCM programmer
Joined: 06 Sep 2003 Posts: 21708
|
|
Posted: Sun Jun 12, 2005 4:38 pm |
|
|
The design that I posted uses the internal comparator in the 16F628.
I don't want to design a new low battery circuit. The design that I
posted uses very little of the battery power.
Here's an example of a design that wastes the battery.
http://www.circuitcellar.com/library/print/0798/May96/Fig2.htm
Scroll down to the 9v battery input on the left side of the page.
Notice how they have a voltage divider consisting of two 5.1K
resistors connected across the 9v battery. The voltage divider
is always in the circuit. There's no way to disable it. It wastes
0.9ma (or less, as the battery ages) per hour.
You are free to design your own circuit with an external comparator
or whatever you want. |
|
|
|