Counting miliseconds between ON and OFF


Closed Thread
Results 1 to 13 of 13
  1. #1
    Join Date
    Feb 2005
    Posts
    130

    Default Counting miliseconds between ON and OFF

    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

  2. #2
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    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.

    -------------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  3. #3
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    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

  4. #4
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    I forgot to ask, how can I detect that the power went off so I can start counting?


    Thanks!

  5. #5
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    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.


    ------------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  6. #6
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    Clever, very clever and fast also! Thanks again Saizer!


    Pablo

  7. #7
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    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.


    ----------------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  8. #8
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    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

  9. #9
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    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:



    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!!!

  10. #10
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    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.
    ------------------------------
    Attached Images Attached Images  
    Last edited by sayzer; - 22nd November 2006 at 06:52.
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  11. #11
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    My app is always battery powered, that diode makes sense I'm keeping an eye on the other circuit. Thanks!

  12. #12
    Join Date
    Jan 2006
    Location
    Istanbul
    Posts
    1,185


    Did you find this post helpful? Yes | No

    Default

    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?


    ----------------------------
    "If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte

  13. #13
    Join Date
    Feb 2005
    Posts
    130


    Did you find this post helpful? Yes | No

    Default

    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

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts