read encoder

Dependencies:   mbed

Revision:
1:2f2a74337b77
Parent:
0:f2657b94ea70
Child:
2:33062fc279ca
--- a/main.cpp	Tue Jul 31 12:18:02 2018 +0000
+++ b/main.cpp	Tue Jul 31 13:24:56 2018 +0000
@@ -1,4 +1,5 @@
 #include "mbed.h"
+#include "encoder.h"
  
 Serial uart(USBTX, USBRX); 
 //Serial uart(D10,D2);            // TX : D10     RX : D2           // blueteeth
@@ -10,16 +11,16 @@
 
 
 // encoder
-DigitalOut encoder_cs(D9);
-SPI spi_encoder(D11, D12, D13); // mosi, miso, sclk
-unsigned short encoder_value = 0;
-unsigned short angle = 0;
-unsigned short angle_old;
-unsigned short angle_init;
-int angle_dif;
-int a_dif;
-int Angle;
-unsigned short k = 0;
+//DigitalOut encoder_cs(D9);
+//SPI spi_encoder(D11, D12, D13); // mosi, miso, sclk
+//unsigned short encoder_value = 0;
+//unsigned short angle = 0;
+//unsigned short angle_old;
+//unsigned short angle_init;
+//int angle_dif;
+//int a_dif;
+//int Angle;
+//unsigned short k = 0;
 
 // uart_tx
 union splitter {
@@ -31,13 +32,13 @@
 int i = 0;
 
 // function
-void init_encoder();
-void init_SPI();
+//void init_encoder();
+//void init_SPI_encoder();
 void init_UART();
 void init_TIMER();
 void timer1_ITR();
-void angle_measure();
-int angle_count(unsigned short,unsigned short);
+//void angle_measure();
+//int angle_count(unsigned short,unsigned short);
 void uart_tx();
 
 
@@ -47,7 +48,7 @@
     wait_ms(500);
     // initial sensor
     init_encoder();
-    init_SPI();
+    init_SPI_encoder();
     // initial uart
     init_UART();
     
@@ -60,7 +61,7 @@
     }
     
 }
-
+/*
 void init_encoder()
 {
 //    encoder_cs = 1;  // disable encoder
@@ -71,13 +72,14 @@
     encoder_cs = 1; // Deselect the device
     
 }
-
-void init_SPI()
+*/
+/*
+void init_SPI_encoder()
 {
     spi_encoder.format(16,3);
     spi_encoder.frequency(1000000); // 1MHz clock rate
 }
-
+*/
 void init_UART()
 {
     uart.baud(115200);
@@ -94,7 +96,7 @@
 //    angle_count();
     uart_tx();
 }
-
+/*
 void angle_measure()
 {    
     encoder_cs = 0; // Select the device by seting chip select low
@@ -108,10 +110,6 @@
         Angle = angle_init + angle_dif;
         angle_old = angle;
         k++;
-//        angle_dif = angle_count();
-//        Angle = angle_init + angle_dif;
-//        angle_old = angle;
-//        k++;
     }
     else
     {
@@ -120,7 +118,8 @@
         angle_old = angle;
     }
 }    
-
+*/
+/*
 int angle_count(unsigned short now,unsigned short old)
 {
     a_dif = now - old;
@@ -133,7 +132,7 @@
     
     return a_dif;
 }
-
+*/
 void uart_tx()
 {
     splitter s1;