Quadrature decoder

Dependents:   Telliskivi2_2014

Committer:
Reiko
Date:
Mon Jul 29 20:25:05 2013 +0000
Revision:
0:0e8cb3139868
Created decoder library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Reiko 0:0e8cb3139868 1 #ifndef QED_H
Reiko 0:0e8cb3139868 2 #define QED_H
Reiko 0:0e8cb3139868 3
Reiko 0:0e8cb3139868 4 #include "mbed.h"
Reiko 0:0e8cb3139868 5
Reiko 0:0e8cb3139868 6 #define PREV_MASK 0x1 //Mask for the previous state in determining direction of rotation.
Reiko 0:0e8cb3139868 7 #define CURR_MASK 0x2 //Mask for the current state in determining direction of rotation.
Reiko 0:0e8cb3139868 8 #define INVALID 0x3 //XORing two states where both bits have changed.
Reiko 0:0e8cb3139868 9
Reiko 0:0e8cb3139868 10 class QED {
Reiko 0:0e8cb3139868 11 public:
Reiko 0:0e8cb3139868 12 QED(PinName channelA, PinName channelB);
Reiko 0:0e8cb3139868 13
Reiko 0:0e8cb3139868 14 int read();
Reiko 0:0e8cb3139868 15
Reiko 0:0e8cb3139868 16 private:
Reiko 0:0e8cb3139868 17 void decode();
Reiko 0:0e8cb3139868 18
Reiko 0:0e8cb3139868 19 InterruptIn interruptA;
Reiko 0:0e8cb3139868 20 InterruptIn interruptB;
Reiko 0:0e8cb3139868 21
Reiko 0:0e8cb3139868 22 volatile int pulses;
Reiko 0:0e8cb3139868 23
Reiko 0:0e8cb3139868 24 int prevState;
Reiko 0:0e8cb3139868 25 int currState;
Reiko 0:0e8cb3139868 26 };
Reiko 0:0e8cb3139868 27
Reiko 0:0e8cb3139868 28 #endif