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
QEI/Encoder.h
- Committer:
- mazdo25
- Date:
- 2019-03-09
- Revision:
- 3:01b5e80d842d
- Child:
- 4:208f5279143a
File content as of revision 3:01b5e80d842d:
//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();
}
};