Implement a timer without using an interrupt


Closed Thread
Results 1 to 4 of 4

Hybrid View

  1. #1
    Join Date
    Oct 2005
    Location
    Las Vegas, Nevada, USA
    Posts
    27


    Did you find this post helpful? Yes | No

    Smile Thanks Bruce

    I am not sure why you mention "PR2 is initialized to 255 on reset". I have no idea what you are trying to tell me.

    However, your explanation and advice to change my Counter trigger to 76 did the trick with the addition of resetting the Counter to 0 when I turn the timer on.

    Works like a charm.

    Ken

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


    Did you find this post helpful? Yes | No

    Default

    When Timer2 counts up to the value in PR2, PIR1.1 is set, and Timer2 is
    reset to 0. It doesn't over flow when it rolls-over from 255 to 0 like other
    8-bit timers.

    The time is takes for PIR1.1 to be set =;

    (prescaler)*(PR2)*(postscaler)*(instruction cycle time).

    Since PR2 is initialized to 255, and you're using both prescaler & postscaler
    set to 16, then (assuming a 4MHz osc) 16*255*16*1uS* your Counter value
    of 76 = 4.9 seconds.

    Look in the Timer2 section of your data sheet for the whole story..;o}

    Try placing PR2 = 127 in the startup section of your code to see the effect.
    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