driver for incremental encoder

Committer:
ianaherne
Date:
Thu Mar 14 16:05:28 2019 +0000
Revision:
5:1a5772466668
Parent:
4:9913990cfd78
Child:
6:2fdce74d2a7b
addressed encoder issues and streamlined code

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ianaherne 0:c3a05fe15b84 1 #ifndef DECODER_H
ianaherne 0:c3a05fe15b84 2 #define DECODER_H
ianaherne 0:c3a05fe15b84 3 #include "mbed.h"
ianaherne 5:1a5772466668 4 extern Serial pc;
ianaherne 0:c3a05fe15b84 5
ianaherne 0:c3a05fe15b84 6
ianaherne 0:c3a05fe15b84 7
ianaherne 0:c3a05fe15b84 8 class decoder{
ianaherne 0:c3a05fe15b84 9
ianaherne 0:c3a05fe15b84 10 public:
ianaherne 0:c3a05fe15b84 11
ianaherne 2:b82d31306c4b 12
ianaherne 2:b82d31306c4b 13 /* These values control the upper and lower limits the the count will go to change limits to suit application*/
ianaherne 2:b82d31306c4b 14 typedef enum{
ianaherne 2:b82d31306c4b 15
ianaherne 2:b82d31306c4b 16
ianaherne 2:b82d31306c4b 17 LOWER_LIMIT = 0,
ianaherne 3:4a03a73d7554 18 UPPER_LIMIT = 19
ianaherne 2:b82d31306c4b 19
ianaherne 2:b82d31306c4b 20
ianaherne 2:b82d31306c4b 21 }limits_t;
ianaherne 2:b82d31306c4b 22
ianaherne 0:c3a05fe15b84 23 decoder(PinName channelA,PinName channelB);
ianaherne 0:c3a05fe15b84 24
ianaherne 0:c3a05fe15b84 25 void isr();
ianaherne 0:c3a05fe15b84 26
ianaherne 0:c3a05fe15b84 27 int8_t getDirection();
ianaherne 0:c3a05fe15b84 28 int16_t getCount();
ianaherne 1:017efde7ab29 29 void reset();
ianaherne 0:c3a05fe15b84 30
ianaherne 0:c3a05fe15b84 31
ianaherne 0:c3a05fe15b84 32
ianaherne 0:c3a05fe15b84 33 private:
ianaherne 0:c3a05fe15b84 34
ianaherne 1:017efde7ab29 35 InterruptIn _channelA; // interrupt only required on one channel
ianaherne 1:017efde7ab29 36 DigitalIn _channelB; // channelB is only required for comparison to determine direction
ianaherne 0:c3a05fe15b84 37
ianaherne 0:c3a05fe15b84 38
ianaherne 0:c3a05fe15b84 39 int8_t _direction;
ianaherne 0:c3a05fe15b84 40 int16_t _count;
ianaherne 4:9913990cfd78 41
ianaherne 0:c3a05fe15b84 42
ianaherne 0:c3a05fe15b84 43
ianaherne 0:c3a05fe15b84 44 };
ianaherne 0:c3a05fe15b84 45
ianaherne 0:c3a05fe15b84 46 #endif