Publishing for Michael McKinley to calibrate.

Fork of Encoders by Bradley Perry

Files at this revision

API Documentation at this revision

Comitter:
perr1940
Date:
Sat Mar 07 01:56:09 2015 +0000
Parent:
0:1d2644a20b71
Commit message:
Publishing for Michael McKinley to calibrate.

Changed in this revision

Encoder.cpp Show annotated file Show diff for this revision Revisions of this file
Encoder.h Show annotated file Show diff for this revision Revisions of this file
diff -r 1d2644a20b71 -r 2e39be3d2088 Encoder.cpp
--- a/Encoder.cpp	Mon Nov 24 03:33:29 2014 +0000
+++ b/Encoder.cpp	Sat Mar 07 01:56:09 2015 +0000
@@ -59,6 +59,19 @@
 
     // XNOR parity check
     parity=~(parity_calc(raw) ^ (raw>>15));
+    if(!parity) {
+        // Select the device by seting chip select low
+        _cs = 0;
+
+        //send a dummy byte to the MOSI to get a reading through the MISO
+        raw=_spi.write(0xFFFF);
+
+        // Set the select back to low to allow the encoder to chill
+        _cs=1;
+
+        // XNOR parity check
+        parity=~(parity_calc(raw) ^ (raw>>15));
+    }
 
     // Mask and bit shift to look at encoder flag value
     enc_flag=(raw & 0x4000)>>14;
@@ -68,9 +81,10 @@
     return raw;
 }
 
-short int Encoder::readRaw(){
+short int Encoder::readRaw()
+{
     return raw;
-    }
+}
 /***********************************************************
 Translate Function - Translates Ticks to Position
 ***********************************************************/
@@ -107,4 +121,4 @@
 void Encoder::flip()
 {
     sign=-sign;
-    }
\ No newline at end of file
+}
\ No newline at end of file
diff -r 1d2644a20b71 -r 2e39be3d2088 Encoder.h
--- a/Encoder.h	Mon Nov 24 03:33:29 2014 +0000
+++ b/Encoder.h	Sat Mar 07 01:56:09 2015 +0000
@@ -18,19 +18,48 @@
     short int readRaw();
     // Functions
 private:
+    /**
+    * SPI bus for communicating with the encoder.
+    **/
     SPI _spi;
+    /**
+    * SPI chip select pin for communicating with the encoder.
+    **/
     DigitalOut _cs;
+    /**
+    *Calculates the parity of the input.
+    *@params x The message that you want to calculate the parity of.
+    *@returns A boolean variable that represents the parity of the message.
+    **/
     bool parity_calc(int x);
+    /**
+    *Sign variable used to flip the direction of the encoder if needed.  
+    **/
     int sign;
+    /**
+    *Reads the encoder, does parity check, and stores the error flag.
+    *@returns An unsigned integer which is the number of ticks away from the zero position.
+    **/
     int read();
+    /**
+    *The parity comparison of the previous transmission
+    **/
     bool parity;
+    /**
+    *The encoder flag of the previous transmission
+    **/
     bool enc_flag;
-    //zero_ang for standing position
+    /**
+    *Zero angle set point for standing position.
+    **/
     float zero_ang;
+    /**
+    *The raw angle from the encoder in encoder ticks.
+    **/
     short int raw;
-
-
-    // Variables
+    /**
+    *Used for translating from encoder ticks to degrees.
+    **/
     const float enc2deg;
 
 };