Implement a timer without using an interrupt


Results 1 to 4 of 4

Threaded View

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


    Did you find this post helpful? Yes | No

    Default

    PR2 is is initialized to 255 on reset.

    With Timer2 prescaler & postscaler set to 16, it takes 16*255*16
    clock cycles before PIR1.1 is set.

    At 4MHz this = 65,280uS.

    65,280uS * 350 = 22.848 seconds.

    If you need ~5 seconds, increment Counter up to 76.

    76 * 65,280uS = roughly 4.961S + whatever program over-head you
    have in the process.

    P.S. You need Counter to be a "word" size if it's counting past 255,
    and you should initialize your Counter variable to 0 before Main, then
    clear it once it's reached your max count.
    if Counter = 350 then
    This will never be true since it will roll-over from 255 to 0
    Last edited by Bruce; - 26th February 2006 at 17:33.
    Regards,

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

Similar Threads

  1. Elapsed Timer Demo
    By Darrel Taylor in forum Code Examples
    Replies: 111
    Last Post: - 29th October 2012, 17:39
  2. Can't ID interrupt source with this IntHandler??
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 3rd June 2009, 02:35
  3. Timer interrupt frequency
    By Samoele in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 17th January 2009, 23:49
  4. How to set interrupt for Timer 0
    By chai98a in forum mel PIC BASIC Pro
    Replies: 8
    Last Post: - 18th November 2006, 00:14
  5. USART interrupt not interrupting right
    By Morpheus in forum mel PIC BASIC Pro
    Replies: 12
    Last Post: - 6th March 2005, 01:07

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