PDA

View Full Version : Counting miliseconds between ON and OFF



peu
- 17th November 2006, 12:19
Hi,

I'm trying to count how many milliseconds pass between I power off an uC cutting its battery power and the subsequent power on.

I need to measure around 500 miliseconds.

The circuit its very simple: a 12F675 and a led on port 2

What would be the best electronical solution? I was thinking about using a capacitor for storing some power after batery shutdown.

Any ideas would be greatly appreciated. Thanks in advance!!


Pablo

sayzer
- 17th November 2006, 12:39
Depending on the state of port pins, HIGH or LOW, it may change.

For example, if you have a LED on a pin and it is ON, then the capacitor you have, say 220uF, will last less compared to OFF state of that LED.

This should be very easy to experience though.

Just make sure, when the LED is OFF, the PIC itself will draw very small current and the capacitor may keep powering the PIC very long, too. Thus, the PIC will be running "secretly" although you may think that it is not running.

-------------------------------

peu
- 17th November 2006, 12:45
Thanks for the prompt reply Sayzer, the led turns on as soon the uC is powered, so I need to put that on the scale to size the capacitor accordingly.

You think I need to go 220uF?
Well, I guess I'll try the best solution at the bench :)


Pablo

peu
- 18th November 2006, 19:02
I forgot to ask, how can I detect that the power went off so I can start counting?


Thanks!

sayzer
- 18th November 2006, 19:05
Have an input pin tied to the power source before the cap;

When the power is OFF, you can detect it while the cap is still powering the PIC.

This way, you can save your variables before the cap is completely gone.


------------------------------

peu
- 18th November 2006, 19:10
Clever, very clever and fast also! Thanks again Saizer!


Pablo

sayzer
- 18th November 2006, 22:05
There are also this tiny caps 100,000uF/5.5v.

or if you have some little more space, 1Farad/5.5v.
(1,000,000uF/5.5v) these are very small compared to the cap size.


If you can use one of these tiny ones, you can have your PIC running for hours when the battery goes off; but to know for how long it would last with a LED in ON state, you need to try.


----------------------------------

peu
- 20th November 2006, 01:14
Now that I know how to detect when the power went down, I simply put the led output pin low and that solves the issue of the capacitor.

You really helped me Sayzer in a very timely fashion. Thanks again


Pablo

peu
- 21st November 2006, 19:02
Sayzer: Today I had time to put your words into code, I tought that I understood it, but now I see I dont :(

Here is what I uderstood from you schematic idea:

http://peu.net/mods/poweroff.gif

Did I getit wrong?

I dont have a clue (again) on how to detect on software that the battery went off.

Any help would be greatly appreciated. Thanks!!!

sayzer
- 22nd November 2006, 06:49
Ok, here is one concept.

You have an advantage here, ADC reading, that you can actually measure the voltage; it does not have to go off as you can continuously check the voltage level.

Since you are using a battery, power-off concept may not be a good (or let say precise) solution for you. But if you had a non battery operation with this circuit, this is the way to go.

Thus, reading (monitoring) the battery voltage at AN0 in your case is much more accurate.


Try and see....


<img src="http://img6.picsplace.to/img6/23/poweroff.gif" alt="Image Hosting by PicsPlace.to" >



Edit: I will post another circuit to read the voltage level with AN0.
------------------------------

peu
- 22nd November 2006, 12:42
My app is always battery powered, that diode makes sense :) I'm keeping an eye on the other circuit. Thanks!

sayzer
- 25th November 2006, 17:35
I was thinking about measuring the battery with ADC but then I realized that Vref will be Battery V+ and the ADC will be tied to V+ also.

As the battery goes down, the ADC Vref will also go down in parallel and the result will never change in theory. Even a resistor tied from ADC pin to either Gnd or V+ will also be perfectly proportional to battery V+ when it is going down. Thus ADC will not see the difference, I think.


This is just possibility came to my mind but I am sure someone already has done something similar and is experienced with this.

Am I right on this or there is another way to do it?


----------------------------

peu
- 25th November 2006, 17:44
Hi Sayzer, I was thinking on using BOD but the fact that it resets the uC when its triggered put the idea to rest.

I know it can be done, because I saw others doing it...

Pablo