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
Bookmarks