Robostix quadrature decode
From GumstixDocsWiki
Overview
It is often desirable to use some type of rotary sensor for detecting wheel position. One of the more common techniques involves the use of a quadrature encoder/decoder. This is basically two channels (commonly called A and B) which contain square waves which are 90 degrees out of phase. This is also the simplest form of Gray code.
Some further background is available on the Digital encoders page.
Computer mice (the kind with the balls in them) use quadrature for the X and Y axis: How Computer Mice Work
Source Files
The QD.h and QD.c files (found in the robostix/Common directory) implement polled quadrature. I generally prefer polled quadrature over interrupt driven quadrature since the polled method will automatically compensate for noise.
To track an encoder called Dial, you would add the following definitions to your file (as shown in the QD-Test.c file):
#define Dial_A_PIN PINC
#define Dial_B_PIN PINC
#define Dial_A_BIT 1
#define Dial_B_BIT 0
volatile QD_Counter_t Dial_Count;
QD_State_t Dial_PrevState;
The type of QD_Counter_t defaults to uint16_t and can be set using the CFG_QD_COUNTER_TYPE define in your Config.h file.
You can change the direction of the counting, by swapping the A and B channels.

