> I am working on a project where I have to incorporate an accurate timer. A
> lively discussion on this very subject occurred a few months ago and I
> started with the results of that discussion.
>
> Both piclist.com and Roman Black's web site have various versions of the
> routines. I started with Roman's page
>
http://centauri.ezy.net.au/~fastvid/one_sec.htm since it contained a nice
> description of the concepts.
>
> Roman's routine is described timer tick rates of 256 or 65,536 cycles. It
> was trivial to change the constants to work with my timer tick rate of 1024
> cycles (4 MHz oscillator, pre-scale set at 1:4).
>
> In the process of doing the above, I found that the timer routines could be
> shortened somewhat.
>
> Roman's routine is:
>
> ;enter here every tick
> tstf bres_mid ; first test for mid==0
> skpnz ; nz = no underflow needed
> decf bres_hi,f ; z, so is underflow, so dec the msb
>
> decfsz bres_mid,f ; dec the mid byte (subtract 256)
> goto main_loop ; nz, so definitely not one second yet.
>
> tstf bres_hi ; test hi for zero too
> skpz ; z = both hi and mid are zero, is one second!
> goto main_loop ; nz, so not one second yet.
> ;1 sec timer elapsed - reload the counters and do whatever you want
>
> I found that I could accomplish the same thing with:
> ;enter here every tick
> decfsz bres_mid,F ;dec mid byte
> incf bres_hi,F ;correct following dec unless reach 0
> decfsz bres_hi,F ;dec upper byte
> goto main_loop ;zero only if upper 2 bytes reached 0
> ;1 sec timer elapsed - reload the counters and do whatever you want
> Note: my version requires that the constant loaded into 'bres_hi' be 1
> higher than calculated - this is because the test for 0 happens whenever
> the mid byte reaches 0 instead of when it wraps under to 0xFF.