Not getting this timer thing.


Results 1 to 10 of 10

Threaded View

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


    Did you find this post helpful? Yes | No

    Default Re: Not getting this timer thing.

    Hardware timers will continue running once enabled. It runs on its own, in the background, until you disable it.

    If you're in a loop reading the timer, checking for a value > x, the value you read indicates how long the timer has run.

    When you insert the test loop, this wastes time, which adds to the timer count since it's still running while your code in the test loop executes.

    So - the more code that executes before you read the timer, the larger the count will be. At least until it rolls-over back to 0.

    The timer is also running during your PAUSE time. At 16MHz, with a prescaler of 1:1, Fosc/4 as the timer clock source, timer1 increments by 1 count every 250nS. Since timer1 is a 16-bit timer it will count from 0 to 65,535 then roll-over back to 0 and continue counting.

    Here's a neat example showing how to use a timer to see how long PBP code takes to execute.
    http://www.picbasic.co.uk/forum/showthread.php?t=365

    Here's on using timer2 as a clock
    http://www.picbasic.co.uk/forum/show...0262#post70262
    Last edited by Bruce; - 29th July 2011 at 13:29. Reason: Links
    Regards,

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

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