PDA

View Full Version : How can I get Timer 1 to overflow every 5 seconds



revelator
- 22nd March 2010, 16:04
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

ScaleRobotics
- 22nd March 2010, 16:29
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.
http://www.picbasic.co.uk/forum/attachment.php?attachmentid=4110&stc=1&d=1269275025

The Pic Multi Calc can be found here:
http://www.picbasic.co.uk/forum/showpost.php?p=78308&postcount=2

Acetronics2
- 22nd March 2010, 18:26
...

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




IF I detect something

Do something .... for 5 sec

Wait for detect.



Generally is solved by sleep/ wake use of the µP ...

Alain

revelator
- 22nd March 2010, 19:42
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

rmteo
- 22nd March 2010, 20:00
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.

Acetronics2
- 23rd March 2010, 08:45
...

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