Test for MAxon EASY 16 Absolute encoder

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
SGLaws
Date:
Wed Jan 10 11:31:04 2018 +0000
Commit message:
Encoder Test MAXON EASY 16 Absolute

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r c9716d965276 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Wed Jan 10 11:31:04 2018 +0000
@@ -0,0 +1,51 @@
+#include "mbed.h"
+Serial pc(USBTX, USBRX); // tx, rx
+DigitalOut led1(LED1);
+DigitalOut led2(LED2);
+DigitalOut led3(LED3);
+DigitalIn butt = (USER_BUTTON);
+
+DigitalOut CLK(PA_3);
+DigitalIn DATA(PD_7);
+
+int readSSI(DigitalOut CLK, DigitalIn DATA){
+    int i,tmp,numBits = 13; 
+    int angle = 0b00000000000000; //Initialise 13 bit 0 binary
+    CLK=1; //Bring CLK high
+    for(i =0;i<numBits;i++){
+         CLK = 0;        
+         wait_us(10);
+         CLK =1;
+         wait_us(10); //CLK cycle
+         tmp = DATA.read(); 
+         angle = angle<<1; //Shift previous read bits
+         angle += tmp; //Add new bit
+    }    
+    wait_us(16); //Timeout 16us from datasheet
+    CLK =0; 
+    return angle;
+}
+
+
+int angle; 
+ 
+int main() {
+    while(butt == 0){   //Startup readings
+        led1 =!led1; 
+        led2=!led2; 
+        led3=!led3; 
+        wait(0.1f);
+    }
+    wait(0.5f);
+    printf("\r\n Start");
+    
+    while(1){
+        printf("\r\n");
+        CLK =0;
+        angle = readSSI(CLK, DATA);
+        printf("\r\n%d\r\n",angle);
+        wait(.5f);
+    }
+}
+
+
diff -r 000000000000 -r c9716d965276 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Wed Jan 10 11:31:04 2018 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/7130f322cb7e
\ No newline at end of file