
Originally Posted by
HenrikOlsson
Hi Rufinus,
Sadly Darrel has passed away and is no longer with us.
I'll try to answer your qeustion.
It's correct that with a prescaler of 1:256 the timer will only overflow every 65536 "tick" but that doesn't prevent Darrels code from measuring frequencies lower than 65536Hz. As I wrote in a previous post the two most significant bytes of the 4 byte result will contains the number of overflows (ie "units" of 65536Hz), the next byte is the TMR0 value which is in units of 256Hz and the least significant byte is what's stored in the prescaler, in units of 1Hz. All provided your "gate time" is precisely 1Hz of course.
So, if your input frequency is 125Hz then after the one second gate time there will be 0 overflows, 0 counts in TMR0 and 125 counts in the prescaler. The prescaler isn't readable so the code then "manually" pulses the counter input to find out how many pulses is needed before the prescaler overflows and TMR0 increases. In this example it would take 131 (125+131=256) which, when stored in a byte and negated "becomes" the value 125.
Changing the prescaler won't help you measure the low frequencies. The only way to gain resolution at the lower end is to increase the gate time, count for 2, 5, 10 or whatever seconds instead of 1 and adjust the calculations accordingly.
/Henrik.
Bookmarks