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 /** 00002 * Header Encoder KRAI 00003 * untuk membaca nilai rotary encoder 00004 **/ 00005 #ifndef ENCODERKRAI_H 00006 #define ENCODERKRAI_H 00007 00008 //Bismillahirahamnirahim 00009 00010 //LIBRARY 00011 #include "mbed.h" 00012 00013 /************************** 00014 * Konstanta dan Variabel * 00015 **************************/ 00016 00017 //KONSTANTA 00018 #define PREV_MASK 0x1 //Konstanta untuk mengetahui previous direction 00019 #define CURR_MASK 0x2 //Konstanta untuk mengetahui current direction 00020 #define INVALID 0x3 //XORing two states where both bits have changed. 00021 00022 /******************************** 00023 * Quadrature Encoder Interface * 00024 ********************************/ 00025 00026 class encoderKRAI { 00027 00028 public: 00029 00030 typedef enum Encoding { 00031 00032 X2_ENCODING, 00033 X4_ENCODING 00034 00035 } Encoding; 00036 00037 encoderKRAI(PinName channelA, PinName channelB, int pulsesPerRev, Encoding encoding = X2_ENCODING); 00038 /******************************************* 00039 * Membuat interface dari encoder 00040 * @param inA DigitalIn, out A dari encoder 00041 * @param inB DigitalIn, out B dari encoder 00042 *******************************************/ 00043 00044 void reset(void); 00045 /******************************************* 00046 * Reset encoder. 00047 * Reset pembacaaan menjadi 0 00048 *******************************************/ 00049 00050 int getPulses(void); 00051 /******************************************* 00052 * Membaca pulse yang didapat oleh encoder 00053 * @return Nilai pulse yang telah dilalui. 00054 *******************************************/ 00055 00056 int getRevolutions(void); 00057 /******************************************* 00058 * Membaca putaran yang didapat oleh encoder 00059 * @return Nilai revolusi/putaran yang telah dilalui. 00060 *******************************************/ 00061 00062 private: 00063 00064 void encode(void); 00065 /******************************************* 00066 * Menghitung pulse 00067 * Digunakan setiap rising/falling edge baik channel A atau B 00068 * Membaca putaran CW atau CCW => mengakibatkan pertambahan/pengurangan pulse 00069 *******************************************/ 00070 00071 //VARIABEL UNTUK PERHITUNGAN PULSE 00072 Encoding encoding_; 00073 00074 InterruptIn channelA_; 00075 InterruptIn channelB_; 00076 00077 int pulsesPerRev_; 00078 int prevState_; 00079 int currState_; 00080 00081 volatile int pulses_; 00082 volatile int revolutions_; 00083 00084 00085 }; 00086 00087 #endif /* ENCODERKRAI_H */
Generated on Tue Jul 12 2022 22:57:42 by
