Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Diff: QEI/Encoder.h
- Revision:
- 3:01b5e80d842d
- Child:
- 4:208f5279143a
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/QEI/Encoder.h Sat Mar 09 14:27:48 2019 +0000
@@ -0,0 +1,31 @@
+//works only in x2 encoding (512 counts per second)
+#include "QEI.h"
+class Encoder: public QEI {
+ private:
+ Timer dT; //to calculate rate of change of encoder ticks.
+ int prevPulses;
+
+ public:
+
+ Encoder(PinName A, PinName B) : QEI(A,B,NC,256,X2_ENCODING)
+ {
+ prevPulses = 0;
+ dT.stop();
+
+ };
+
+ float encoderTickRate() {
+ int PP = prevPulses;
+ int CP = QEI::getPulses();
+ float deltaT = dT.read();
+ prevPulses = CP;
+ dT.reset();
+ return ((float)(CP-PP)/deltaT);
+ };
+
+ void startTimer(void)
+ {
+ dT.start();
+ }
+
+};
\ No newline at end of file