How can I get Timer 1 to overflow every 5 seconds


Closed Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2009
    Location
    FLA
    Posts
    9

    Default How can I get Timer 1 to overflow every 5 seconds

    I need a timer to increment and overflow (interrupt) say every 5 seconds but only when when a pin is detected as high (say current is detected). If I use Timer1 on the 16F876, with the maximum prescale allowed of 8 and running at 20 Mhz that would be:

    4 * 0.05 usec * 8 *(65535-0) = ~0.104856 seconds

    How can I get Timer 1 to interrupt at longer timed intervals say 5 to 10 seconds?

    Can I use Timer0 as another prescaler to Timer1? What is the common method for longer timed intervals using timers?

    thanks in advance

  2. #2
    Join Date
    Feb 2006
    Location
    Gilroy, CA
    Posts
    1,530


    Did you find this post helpful? Yes | No

    Default

    How about letting it count 1000ms, and rolling over 5 to ten times? Then on the 5th or tenth time, have it perform an action. MisterE's calculator is a great tool for calculating timer values.

    Here is a picture of it.


    The Pic Multi Calc can be found here:
    http://www.picbasic.co.uk/forum/show...08&postcount=2

  3. #3
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    ...

    The only solution for timer 1 to overflow every 5 sec is to run the CPU clock @ 400 khz ...

    Depends on what you intend to do ...

    but

    Code:
    IF I detect something
    
    Do something .... for 5 sec
    
    Wait for detect.
    Generally is solved by sleep/ wake use of the µP ...

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

  4. #4
    Join Date
    Mar 2009
    Location
    FLA
    Posts
    9


    Did you find this post helpful? Yes | No

    Default

    thanks scalerobotics and acetronics...I guess I had answer my own question

    "...Can I use Timer0 as another prescaler to Timer1?...

    I guess I could use Timer0 and at overflow set any available pin high then low (generate a pulse) and use it as input (via hardwire) to another timer which would be set to read an external clock (that would be the pulse).

    Thinking out of the box.....

    thanks again

  5. #5
    Join Date
    May 2007
    Posts
    604


    Did you find this post helpful? Yes | No

    Default

    Just increment/count a variable in the TIMER1 interrupt service routine and you can achieve any interval that you want - from fractions of a second to hours.

  6. #6
    Join Date
    May 2004
    Location
    NW France
    Posts
    3,648


    Did you find this post helpful? Yes | No

    Wink

    Quote Originally Posted by Acetronics View Post
    ...

    The only solution for timer 1 to overflow every 5 sec is to run the CPU clock @ 400 khz ...

    Alain
    Oh, Oh ...

    I had forgotten the 876 timer1 simply could be driven by its own oscillator up to 200 Khz ... ( NOT the CPU Osc @ 20 Mhz !)

    so, no problem ... 32768 Hz are easy to find Xtals !

    note also exist " Gate driven " Timers on numerous chips ( see 12f 683 i.e)

    Alain
    ************************************************** ***********************
    Why insist on using 32 Bits when you're not even able to deal with the first 8 ones ??? ehhhhhh ...
    ************************************************** ***********************
    IF there is the word "Problem" in your question ...
    certainly the answer is " RTFM " or " RTFDataSheet " !!!
    *****************************************

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