How do you time an operation?


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Sep 2007
    Posts
    59

    Default How do you time an operation?

    I want to monitor an input for a given period of time, let's say 5 minutes. If it stays high for 5 minutes I then want to turn on another input until the original is turned off.

    Can someone help point me in the right direction.

    I'm using a 18F6520 with a 4mhz crystal.

    thank you,
    Hylan

  2. #2
    Join Date
    Nov 2003
    Location
    Wellton, U.S.A.
    Posts
    5,924


    Did you find this post helpful? Yes | No

    Default

    Idea.

    Set up a timer interrupt to check the pin every second. After 300 seconds if the pin is still high then..
    Dave
    Always wear safety glasses while programming.

  3. #3
    Join Date
    Jul 2003
    Posts
    2,405


    Did you find this post helpful? Yes | No

    Default

    You can also do this without interrupts by just monitoring a timer overflow flag bit.

    Here's one example;
    http://www.picbasic.co.uk/forum/showthread.php?t=6957
    Regards,

    -Bruce
    tech at rentron.com
    http://www.rentron.com

  4. #4
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default

    Hi Bruce. At the link above, you posted a timer code. I do not get it why you are adding the timer value to the T1LO/T1HI values instead off just loading the timer with the timout value.

    Sorry I seem like Goofy right now....

    Ioannis

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,516


    Did you find this post helpful? Yes | No

    Default

    Hi Ioannis,
    I think doing it that way accounts for any variance in latency etc. Since the code just polls TMR1 interrupt flag rather than actually cause an interrupt the timer may have counted "a while" before the code actually gets to reloading it. If you then simply reload it the time already passed since it overflowed will get lost. By adding the preload value to the actual value already accumulated in the timer you won't loose any time.

    Does that make any sense?

    /Henrik.

  6. #6
    Join Date
    Nov 2003
    Location
    Greece
    Posts
    3,795


    Did you find this post helpful? Yes | No

    Default

    Ohh yeah! I see the light!

    Thanks Henrik.

    Ioannis
    Last edited by Ioannis; - 19th May 2010 at 19:49.

Members who have read this thread : 1

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

Tags for this Thread

Posting Permissions

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