r_test1_2017_10_11_Wed_A

Fork of QEI by Aaron Berk

Revision:
1:8658787f9ec5
Parent:
0:5c2ad81551aa
--- a/QEI.h	Thu Sep 02 16:48:55 2010 +0000
+++ b/QEI.h	Wed Oct 11 08:14:24 2017 +0000
@@ -123,122 +123,99 @@
  * of pulses per revolution.
  */
 
+ 
+ 
 #ifndef QEI_H
 #define QEI_H
-
-/**
- * Includes
- */
+ 
+ 
 #include "mbed.h"
-
-/**
- * Defines
- */
+ 
+ 
 #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.
-
-/**
- * Quadrature Encoder Interface.
- */
+ 
 class QEI {
-
+ 
 public:
-
+ 
     typedef enum Encoding {
-
+ 
         X2_ENCODING,
         X4_ENCODING
-
+ 
     } Encoding;
-
-    /**
-     * Constructor.
-     *
-     * Reads the current values on channel A and channel B to determine the
-     * initial state.
-     *
-     * Attaches the encode function to the rise/fall interrupt edges of
-     * channels A and B to perform X4 encoding.
-     *
-     * Attaches the index function to the rise interrupt edge of channel index
-     * (if it is used) to count revolutions.
-     *
-     * @param channelA mbed pin for channel A input.
-     * @param channelB mbed pin for channel B input.
-     * @param index    mbed pin for optional index channel input,
-     *                 (pass NC if not needed).
-     * @param pulsesPerRev Number of pulses in one revolution.
-     * @param encoding The encoding to use. Uses X2 encoding by default. X2
-     *                 encoding uses interrupts on the rising and falling edges
-     *                 of only channel A where as X4 uses them on both
-     *                 channels.
-     */
+ 
+ 
     QEI(PinName channelA, PinName channelB, PinName index, int pulsesPerRev, Encoding encoding = X2_ENCODING);
-
-    /**
-     * Reset the encoder.
-     *
-     * Sets the pulses and revolutions count to zero.
-     */
+ 
     void reset(void);
-
-    /**
-     * Read the state of the encoder.
-     *
-     * @return The current state of the encoder as a 2-bit number, where:
-     *         bit 1 = The reading from channel B
-     *         bit 2 = The reading from channel A
-     */
+ 
     int getCurrentState(void);
-
-    /**
-     * Read the number of pulses recorded by the encoder.
-     *
-     * @return Number of pulses which have occured.
-     */
+ 
+ 
+    void set(int pul , int rev);  
+     
     int getPulses(void);
-
-    /**
-     * Read the number of revolutions recorded by the encoder on the index channel.
-     *
-     * @return Number of revolutions which have occured on the index channel.
-     */
+ 
     int getRevolutions(void);
-
+    
+    int getAng_rev();
+    
+    double getAngle();
+    double getSumangle();
+    double getRPM();
+    double getRPS();
+    double getRPMS();
+    double getRPUS();
+    int          pulsesPerRev_;
 private:
-
-    /**
-     * Update the pulse count.
-     *
-     * Called on every rising/falling edge of channels A/B.
-     *
-     * Reads the state of the channels and determines whether a pulse forward
-     * or backward has occured, updating the count appropriately.
-     */
+    Timer Mper , Rper ,MSper ,USper; 
+    Ticker Tick;
+    double RPM , RPS ,RPMS , RPUS;
+ 
     void encode(void);
-
-    /**
-     * Called on every rising edge of channel index to update revolution
-     * count by one.
-     */
+ 
+ 
     void index(void);
-
+ 
     Encoding encoding_;
-
+ 
     InterruptIn channelA_;
     InterruptIn channelB_;
     InterruptIn index_;
-
-    int          pulsesPerRev_;
+    int          round_rev;
+ 
     int          prevState_;
     int          currState_;
-
+    double angle_ , sumangle;
+    int angle_pulses;
     volatile int pulses_;
     volatile int revolutions_;
-
+ 
 };
+ 
+#endif 
+ 
+/*            
+Repository toolbox
+Import into Compiler
+ Export to desktop IDE
+Repository details
+Type:    Library
+Created:    17 4月 2015
+Imports:     195
+Forks:   1
+Commits:     1
+Dependents:  0
+Dependencies:    0
+Followers:   5
+Software licencing information
 
-#endif /* QEI_H */
+
+The code in this repository is Apache licensed.
+
+*/
\ No newline at end of file