Using the LS7366R SPI Quadrature Counter
The LS7366R is a powerful decoder/counter chip which can be connected directly to a motor encoder to count encoder pulses. The 7366 stores a current count of the pulses, which can be read by the PIC via SPI at any time. This is in contrast with the LS7166, which uses a parallel bus to communicate with the PIC. By using the 7366, the PIC can keep track of a motor's current position without devoting any onboard resources to tracking pulses. The 7366 can be configured to store the count as a 1-4 byte number, depending on the application.
The code on this page is for the PIC32.