Searching \ for 'The Simplest Timing Loop Possible' in subject line. ()
Make payments with PayPal - it's fast, free and secure! Help us get a faster server
FAQ page:
Search entire site for: 'The Simplest Timing Loop Possible'.

Truncated match.
PICList Thread
'The Simplest Timing Loop Possible'
1996\10\21@194008 by myke predko

Hi Gang,

I'm trying to time an event with the best possible granularity (ie fewest
number of instruction cycles needed) and up to 16 bit resolution.

After some dinking around I came up with (assuming you're waiting for RA0 to
go low):

 incfsz        Count                   ;  Increment Least Significant 8 Bits
  incf         Counthi                 ;  Increment the Most Sig. 8 Bits
 btfsc         PORTA, 0                ;  Is RA0 Low?
  goto         Loop                    ;  Nope - Loop Around Again

At the End of this, "Count" is the Correct Value and the Actual Counthi can
be calculated by the formula:

 Actual_Counthi = Count - Counthi      ;  In the 16 Bit Universe

This is because everytime the Count equals zero after an increment, the
Counthi file register is not incremented.  So, to get the actual count, the
Low Value from above has the high Value taken away from it (and when you
work with this in the 8 bit ALU, the correct value falls out).

The Counthi calculation can be done by:

 movf          Counthi                 ;  Get the High Count
 subwf         Count, w                ;   Subtract It from the Low Count
 movwf         Counthi                 ;  Save it Back where it Belongs

I like this routine because it has a granularity of 5 cycles ALL THE TIME.

Does anybody have any comments?  I tried this in MPSIM in a number of cases
and couldn't find anywere it didn't work.

The only drawback of this routine is, I don't think you can get an error
routine out of it (ie always low) because Counthi will roll over to 0.

Does anybody else see any problems?


Do you ever feel like an XT Clone caught in the Pentium Pro Zone?

More... (looser matching)
- Last day of these posts
- In 1996 , 1997 only
- Today
- New search...