
Originally Posted by
DynamoBen
In the datasheet there is a note stating "...the user should keep in mind that reading the 16-bit timer in two 8-bit values itself, poses certain problems, since the timer may overflow between the reads"
... That (DynamoBen's) max. value should not get to the point where the timer would overflow:
You not only need to worry about the timer overflowing from $FFFF to $0000 but from $xxFF to $x(x+1)00. IF you read the lowbyte and then the lowbyte overflows before you read the high byte, you will get the wrong answer. If you cannot stop the timer in your application, try something like this
Code:
X var BYTE ' in addition to your variables
period.highbyte = TMR1H
period.lowbyte = TMR1L
X = TMR1H – period.highbyte
If X = 0 then Continue
period.highbyte = TMR1H
period.lowbyte = TMR1L
Continue:
to ensure you get the correct time. (If at all an option, I would stop timer before reading and then your issue goes away.) Although you did not mention it, you should stop the timer before you write to it per a recommendation from Microchip.
Paul Borgmeier
Salt Lake City, Utah
USA
Bookmarks