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.
encoderKRAI.h
00001 #ifndef ENCODERKRAI_H 00002 #define ENCODERKRAI_H 00003 00004 /** 00005 * Includes 00006 */ 00007 #include "mbed.h" 00008 00009 /** 00010 * Defines 00011 */ 00012 #define PREV_MASK 0x1 //Mask for the previous state in determining direction 00013 //of rotation. 00014 #define CURR_MASK 0x2 //Mask for the current state in determining direction 00015 //of rotation. 00016 #define INVALID 0x3 //XORing two states where both bits have changed. 00017 00018 /** 00019 * Quadrature Encoder Interface. 00020 */ 00021 class encoderKRAI { 00022 00023 public: 00024 00025 typedef enum Encoding { 00026 00027 X2_ENCODING, 00028 X4_ENCODING 00029 00030 } Encoding; 00031 00032 /** Membuat interface dari encoder 00033 * 00034 * @param inA DigitalIn, out A dari encoder 00035 * @param inB DigitalIn, out B dari encoder 00036 */ 00037 encoderKRAI(PinName channelA, PinName channelB, int pulsesPerRev, Encoding encoding = X2_ENCODING); 00038 00039 /** 00040 * Reset encoder. 00041 * 00042 * Menset pulse dan revolusi/putaran menjadi 0 00043 */ 00044 void reset(void); 00045 00046 /** 00047 * Membaca pulse yang didapat oleh encoder 00048 * 00049 * @return Nilai pulse yang telah dilalui. 00050 */ 00051 int getPulses(void); 00052 00053 /** 00054 * Membaca putaran yang didapat oleh encoder 00055 * 00056 * @return Nilai revolusi/putaran yang telah dilalui. 00057 */ 00058 int getRevolutions(void); 00059 00060 /** 00061 * Membaca pulse yang didapat oleh encoder 00062 * 00063 * @return Nilai pulse yang telah dilalui. 00064 */ 00065 //int readDeltaPulses(void); 00066 00067 /** 00068 * Membaca putaran yang didapat oleh encoder 00069 * 00070 * @return Nilai revolusi/putaran yang telah dilalui. 00071 */ 00072 //int readDeltaRevolutions(void); 00073 00074 private: 00075 00076 /** 00077 * Menghitung pulse 00078 * 00079 * Digunakan setiap rising/falling edge baik channel A atau B 00080 * Membaca putaran CW atau CCW => mengakibatkan pertambahan/pengurangan pulse 00081 */ 00082 void encode(void); 00083 00084 /** 00085 * Indeks setiap rising edge untuk menghitung putaran 00086 * Nilai bertambah 1 00087 */ 00088 //void index(void); 00089 00090 Encoding encoding_; 00091 00092 InterruptIn channelA_; 00093 InterruptIn channelB_; 00094 //InterruptIn index_; 00095 00096 int pulsesPerRev_; 00097 int prevState_; 00098 int currState_; 00099 00100 volatile int pulses_; 00101 volatile int revolutions_; 00102 00103 00104 }; 00105 00106 #endif /* ENCODERKRAI_H */
Generated on Thu Jul 14 2022 21:26:57 by
1.7.2