Lab 6 code.

Dependencies:   mbed

Fork of WaG by GroupA

Revision:
22:09dd6977576b
Parent:
21:88f9f280931b
Child:
36:ad2b3d6f0e5a
--- a/stepper.cpp	Wed Mar 07 00:50:57 2018 +0000
+++ b/stepper.cpp	Thu Mar 08 17:16:18 2018 +0000
@@ -8,7 +8,7 @@
 * Purpose: Driver for stepper motor
 *
 * Created: 03/02/2018
-* Last Modified: 03/02/2018
+* Last Modified: 03/08/2018
 *
 ******************************************************************************/
 
@@ -17,9 +17,9 @@
 #include "spi.h"
 #include "stepper.h"
 
-DigitalOut stp_ncs(STP_DRV8806_NCS);
 extern DigitalIn jog_ccw;
 extern DigitalIn jog_cw;
+extern Serial pc;
 
 int stp_cur_pos;
 int stp_sensor_pos[NUM_SENSORS + 1];
@@ -69,12 +69,18 @@
     //static int cur_pos = stp_cur_pos;
     static int turn[4] = {0x03, 0x06, 0x0c, 0x09};
     if (direction == STP_CW) {
-        for (int i = 0; i < 4; i++)
+        for (int i = 0; i < 4; i++) {
+            wait(0.002);
+            //pc.printf("i = %d\n", i);
             spi_send(drv8806, turn[i]);
+        }
     }
     else if (direction == STP_CCW) {
-        for (int i = 3; i >= 0; i--)
+        for (int i = 3; i >= 0; i--) {
+            wait(0.002);
+            //pc.printf("i = %d\n", i);
             spi_send(drv8806, turn[i]);
+        }
     }
     
 }
\ No newline at end of file