On Fri, 15 Oct 2004, James Newtons Massmind wrote: > I think I understand your suggestion, but doesn't the prescaler output cause > the counter to stop counting? Is that what you ment by "clock out the > prescaler"? The prescaler is 'welded' to the rtcc counter. So when the gate closes you have the value in the counter and the value in the prescaler. The value in the rtcc you read out using movf etc since it's a register. Then you have the prescaler to deal with. The prescaler is 8 bits wide (in my case) and takes up to 256 pulses to clear out. Meanwhile, you can't assign to rtcc without clearing the prescaler. So this is done like: movf RTCC,w ; get current counter in w movwf Frtcch ; temp. rtcc storage, also output reg. clrf Frtccl ; it took zero pulses to increment rtcc loop: movf Frtcch,w ; get stored value subwf RTCC,w ; compare: Z = 1 if not changed btfsc STATUS,Z ; not changed goto done_ok ; changed bsf Fgate,Bgate ; pulse rtcc once nop ; allow outputs to settle bcf Fgate,Bgate ; if rtcc overflows rtcc will increment decfsz Frtccl,f ; it took 1 more pulse to inc rtcc goto loop ; keep trying done_ng: ; bad things happened. hardware fault. so do something about it done_ok: ; Ftemp contains the value of rtcc since before we started Peter PS: this code is unchecked, and from memory. My counter actually uses 24 bits so clocking out involves an adjustment for the MSB carry which occurs when/if rtcc,7 goes 1. My gate time is up to 100 seconds afair (with some overflow at 50MHz - the point is to get it accurate for low frequency like 32768Hz). _______________________________________________ http://www.piclist.com View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist