QEIその2
Dependents: Nucleo_Motor Nucleo_Motor mbed_test_enc mbed_touteki_MR1 ... more
Fork of QEI2 by
QEIver2です。 前回のQEIよりハードウェアの節約を実現しました。 基本的にメソッドの追加などはないですが、コンストラクタに引数を追加しました。 第五引数にTimerクラスのアドレスを突っ込むことでTimerクラスの共有ができます。 また従来のQEIクラスの非効率的なTimerクラスの使い方をなくすことで、複数のQEIを使うことができました
Diff: QEI.h
- Revision:
- 0:a24686ca50ab
- Child:
- 1:1f4e8614d0ed
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/QEI.h Fri Apr 17 06:44:34 2015 +0000 @@ -0,0 +1,76 @@ + + +#ifndef QEI_H +#define QEI_H + + +#include "mbed.h" + + +#define PREV_MASK 0x1 //Mask for the previous state in determining direction +//of rotation. +#define CURR_MASK 0x2 //Mask for the current state in determining direction +//of rotation. +#define INVALID 0x3 //XORing two states where both bits have changed. + +class QEI { + +public: + + typedef enum Encoding { + + X2_ENCODING, + X4_ENCODING + + } Encoding; + + + QEI(PinName channelA, PinName channelB, PinName index, int pulsesPerRev, Encoding encoding = X2_ENCODING); + + void reset(void); + + int getCurrentState(void); + + + void set(int pul , int rev); + + int getPulses(void); + + int getRevolutions(void); + + int getAng_rev(); + + double getAngle(); + double getSumangle(); + double getRPM(); + double getRPS(); + double getRPMS(); + double getRPUS(); + int pulsesPerRev_; +private: + Timer Mper , Rper ,MSper ,USper; + Ticker Tick; + double RPM , RPS ,RPMS , RPUS; + + void encode(void); + + + void index(void); + + Encoding encoding_; + + InterruptIn channelA_; + InterruptIn channelB_; + InterruptIn index_; + int round_rev; + + int prevState_; + int currState_; + double angle_ , sumangle; + int angle_pulses; + volatile int pulses_; + volatile int revolutions_; + +}; + +#endif