Expanding Timer1 counting range
I use Timer1 as a free running timer, using 4Mhz clock and 16F877A MCU. I do not know how to extend the timer range as it is from 0 to 65536 microsecond using 4Mhz clock.
Can anyone teach me to extend the timer range from 0 to 5 seconds?
Thanks in advance.
Re: Expanding Timer1 counting range
Hello sycluap,
In your code, where you have initiate time counting:
Looping:
While PIR1.0=0
Wend
It appears that you are allowing the timer1 to overflow and then checking to see if the button has been released. This leads me to assume that you don't care if the button is released during the time Timer1 takes to reach rollover.
If this is the case, then is the use of Timer1 really necessary?
If you don't need resolution under a uSec then you might consider using the PBP3 "pauseus" command to create the 1 uSec.
1) Start button is pressed
2) pauseus 1 (delay 1uSec)
3) count0 = count0 + 1
4) if count0 = 65535 then count1 = count1 + 1; count0 = 0
5) check button ( if still pressed loop again)
In this case, you can capture ( minimum 1 uSec - maximum 4294 seconds).
For the math, just use count1 value as a multiplier of 65535
So, then if count1 = 40 you have (65535*40) = 2.6214 seconds accumulated in count1
and then you just add count0 value to that to get the total.
for loop1 = 1 to count1
for loop2 = 1 to 5
micro_sec = micro_sec + 13107
while micro_sec > 999
milli_sec = milli_sec + 1
micro_sec = micro_sec -1000
wend
while milli_sec > 999
sec = sec + 1
milli_sec = milli_sec - 1000
wend
next
next
Lcdout $fe, 1, #sec,":",#milli_sec,":",#micro_sec