EEEN21000
GROUP 30 Line Following Buggy
Loading...
Searching...
No Matches
QEI.h
Go to the documentation of this file.
1
69#ifndef QEI_H
70#define QEI_H
71
72#include "mbed.h"
73
75#define PREV_MASK 0x1
77#define CURR_MASK 0x2
79#define INVALID 0x3
80
84class QEI {
85 public:
86 typedef enum Encoding {
90
113 QEI(PinName channelA, PinName channelB, PinName index, int pulsesPerRev, Encoding encoding = X2_ENCODING);
114
120 void reset(void);
121
130
139
145 int getPulses(void);
146
152 int getRevolutions(void);
153
160 void setPulses(int newCount);
161
168 void setRevolutions(int newRevs);
169
170 private:
179 void encode(void);
180
185 void index(void);
186
188
189 InterruptIn channelA_;
190 InterruptIn channelB_;
191 InterruptIn index_;
192
196
197 volatile int invalid_;
198
199 volatile int pulses_;
200 volatile int revolutions_;
201};
202
203#endif
Handle reading pulses from encoder.
Definition: QEI.h:84
int prevState_
Definition: QEI.h:194
int pulsesPerRev_
Definition: QEI.h:193
volatile int revolutions_
Definition: QEI.h:200
void setPulses(int newCount)
Set the current pulse count in case you want to init it.
Encoding
Definition: QEI.h:86
@ X4_ENCODING
Definition: QEI.h:88
@ X2_ENCODING
Definition: QEI.h:87
int getCurrentState(void)
Read the state of the encoder.
InterruptIn channelB_
Definition: QEI.h:190
Encoding encoding_
Definition: QEI.h:187
InterruptIn index_
Definition: QEI.h:191
QEI(PinName channelA, PinName channelB, PinName index, int pulsesPerRev, Encoding encoding=X2_ENCODING)
Constructor.
volatile int pulses_
Definition: QEI.h:199
void encode(void)
Update the pulse count.
void reset(void)
Reset the encoder.
InterruptIn channelA_
Definition: QEI.h:189
void index(void)
Called on every rising edge of channel index to update revolution count by one.
int currState_
Definition: QEI.h:195
int getPulses(void)
Read the number of pulses recorded by the encoder.
int getInvalidCount(void)
Read the number of invalid counts.
int getRevolutions(void)
Read the number of revolutions recorded by the encoder on the index channel.
volatile int invalid_
Definition: QEI.h:197
void setRevolutions(int newRevs)
Set the current revolution count in case you want to init it.