Just wanted to say thanks Steve. Your approach did the trick nicely. I did one thing differently. When the pin goes low indicating we want to read the TMR0 and prescaler values, I switch the TMR0 to increment from the PA4/T0CKI pin instead of the internal CLKOUT clock. This allows me to clock the PA4/T0CKI pin manually to determine the count remaining in the prescaler without having to have a tight counting/polling loop. Thanks again, --Anil At 12:00 PM 2/12/97 EST, you wrote: >> From: Anil Patel >> [cut] >> If anyone has a way of measuring pulse widths accurately, please let me know. > >The '84 does have a 16-bit counter, i.e. the prescaler (which is not >directly accessible) and TMR0. The trick is to somehow find out >the contents of the prescaler at a particular point. Although I have >not tested the following idea, it should work. Polling is used >rather than interrupts because: > . interrupt latency is relatively tricky to deal with > . since this is a servo application, there's plenty of > time between pulses to accomplish something else. > >Set the prescaler to 1:256 so that TMR0 increments every 128us. Now >poll the input until it goes high. Clear TMR0 (which also clears the >prescaler). Poll input until it goes low. The combination of >prescaler/TMR0 holds the low and high byte of the count (units of >0.5us). Save the high byte (TMR0), then poll TMR0 until it changes -- >you can just check its LSB. While polling, an auxiliary counter is >incremented to get an estimate of the remaining count left in the >prescaler. If the complete polling loop is N instruction cycles, then >the aux count is multiplied by N to get the prescaler remainder, then >subtracted from 256 to estimate the prescaler count at the time the >input went low -- this becomes the low byte of the overall timer >count. > >In reality, you will need a few other corrections to account for >differing code path delays etc., however you should be able to get a >resolution of about 3us. > >Regards, >SJH >Canberra, Australia >