Below is a snippet. I did this a long time ago, so it is not that fresh in my mind.
Remember that it does not give you the speed or the time between pulses directly. It provides the number of "counts" or "clicks" that have taken place and each count represents x microseconds which depends on clock speed, ccp setup and so on.
The PIR1.5 may not be the correct for your specific chip.
Hope this give you some direction.
Code:'configure your PIR, PIE and CCP registers, etc as needed for your specific chip. start: 'do something here like display time or speed waithigh: 'wait here for rising edge and 'handle timer overflow as needed if PIR1.5 = 0 then waithigh 'wait for rising edge TMR1L = 0 'start timer over TMR1H = 0 PIR1.5 = 0 'clear ccp flag clicks.byte0 = CCPR1L 'value of ccp to clicks variable clicks.Byte1 = CCPR1H 'do something here like calculate time 'do something here like calculate speed goto start




Bookmarks