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
Encoder.h
00001 //works only in x2 encoding (512 counts per second) 00002 #include "QEI.h" 00003 class Encoder: public QEI { 00004 private: 00005 Timer dT; //to calculate rate of change of encoder ticks. 00006 int prevPulses; 00007 00008 public: 00009 00010 Encoder(PinName A, PinName B) : QEI(A,B,NC,256,X2_ENCODING) 00011 { 00012 prevPulses = 0; 00013 dT.stop(); 00014 00015 }; 00016 00017 float encoderTickRate() { 00018 int PP = prevPulses; 00019 int CP = QEI::getPulses(); 00020 float deltaT = dT.read(); 00021 prevPulses = CP; 00022 dT.reset(); 00023 return ((float)(CP-PP)/deltaT); 00024 }; 00025 00026 void startTimer(void) 00027 { 00028 dT.start(); 00029 } 00030 00031 };
Generated on Mon Nov 11 2024 23:43:29 by
