On Wed, 13 Nov 1996, Robert Lunn wrote: > This is just unrolling the loop once. The number of > instructions is the same (you save a test on "overflow" > but add a "lo = timer"). That was what I thought when I first rewrote it, but it's not really just an unrolling (though you could arrive at that by unrolling and then deducing which parts were unnecessary, I suppose), and if the PIC had a conditional branch I think the instruction counts would be the same. My assumption is that lo can held in W after it has been captured and then assigned once "past the end" of the pseudo code. > I prefer the looped version because it handles the > situation where the timer overflows immediately after > you've cleared overflow. Both version handle that case, in that they leave a coherent sample of the timer's state in hi:lo. Neither version will work well if the code isn't executed at least often enought to catch every overflow, of course. > This seems a trifle more robust to me. It also more > closely matches what I intuitively expect the code to > do, which is to tell me the current 'time'. I disagree that either version is more robust. They do give results different by one count for a right-near-the-edge timing coincidence, but that's a half-full/half-empty choice. I would suggest that if this choice makes any significant difference then you really needed a higher resolution in the timer anyway. code originally at top of message: > >> repeat > >> if overflow then > >> begin > >> hi := hi + 1; > >> clear overflow > >> end{if}; > >> lo := timer > >> until not overflow > > > >Or just > > > > lo = timer > > if (overflow) { > > lo = timer > > ++hi > > clear overflow > > }