GroupA / Mbed 2 deprecated Lab_6_WaG

Dependencies:   mbed

Fork of WaG by GroupA

Files at this revision

API Documentation at this revision

Comitter:
spm71
Date:
Thu Mar 08 17:16:18 2018 +0000
Parent:
21:88f9f280931b
Child:
23:3da1d39c1ae9
Commit message:
Final code rework

Changed in this revision

display.cpp Show annotated file Show diff for this revision Revisions of this file
io_pins.h Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
stepper.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/display.cpp	Wed Mar 07 00:50:57 2018 +0000
+++ b/display.cpp	Thu Mar 08 17:16:18 2018 +0000
@@ -8,7 +8,7 @@
 * Purpose: Contain function definitions
 * 
 * Created: 03/01/2018
-* Last Modified: 03/02/2018
+* Last Modified: 03/08/2018
 *
 ******************************************************************************/
 #include "mbed.h"
@@ -26,17 +26,14 @@
 extern spi_cfg as1107;
 
 /*
- * void initial_setup(DigitalOut SS, int data_length, int frequency);
+ * void initial_setup(struct spi_cfg spi_obj);
  * Description: setup spi data length (in bit), spi frequency, set LED 
  *              display to normal operation, and set all display numbers
  *              to 0.
  * 
  * Inputs: 
  *      Parameters:
- *          SPI spi: spi object 
- *          DigitalOut SS: chip select pin
- *          int data_length: spi data length in bit
- *          int frequency: frequency of SPI communication
+ *          struct spi_cfg spi_obj: spi_cfg object 
  *      
  * Outputs:
  *      Returns: void
--- a/io_pins.h	Wed Mar 07 00:50:57 2018 +0000
+++ b/io_pins.h	Thu Mar 08 17:16:18 2018 +0000
@@ -8,7 +8,7 @@
 * Purpose: Declare symbolic constants for each of I/O pins
 * 
 * Created: 03/01/2018
-* Last Modified: 03/02/2018
+* Last Modified: 03/08/2018
 *
 ******************************************************************************/
 
@@ -22,7 +22,7 @@
 
 //Stepper
 #define STP_HOME_SENSOR PE_11
-#define STP_DRV8806_NCS PE_15
+#define STP_DRV8806_NCS PA_15
 
 //Display
 #define DSP_AS1107_NCS PC_7
--- a/main.cpp	Wed Mar 07 00:50:57 2018 +0000
+++ b/main.cpp	Thu Mar 08 17:16:18 2018 +0000
@@ -5,10 +5,10 @@
 * 
 * Authors: Sam Morrison and Phong Nguyen 
 * File name: main.cpp
-* Purpose: Configures the dispaly for 4-digit display
+* Purpose: Configures the dispaly for 4-digit display or motor control
 *
 * Created: 03/01/2018
-* Last Modified: 03/02/2018
+* Last Modified: 03/08/2018
 *
 ******************************************************************************/
 #include "mbed.h"
@@ -20,14 +20,10 @@
 #include <stdio.h>
 #include <string.h>
 
-int data_length = 16;
-int frequency = 1000000;
-
-//DigitalOut SS(DSP_AS1107_NCS);
 SPI wag_spi(MOSI, MISO, SCLK);
 Serial pc(USBTX, USBRX);
 DigitalIn jog_cw(PF_14);
-DigitalIn jog_ccw(PF_13);
+DigitalIn jog_ccw(PE_13);
 
 struct spi_cfg as1107{
     SPI_AS1107_ID,
@@ -37,6 +33,7 @@
     AS1107_SPI_NO_BITS,
 };
 
+
 int main(void) {
     initial_setup(as1107);
     char bcd[4];
@@ -75,12 +72,15 @@
     else {
         jog_cw.mode(PullUp);
         jog_ccw.mode(PullUp);
+        stp_step(1);
         pc.printf("Press a pushbutton to turn step motor\n");
         while(1) {
             if (jog_ccw == 0) {
+                //pc.printf("turning CCW\n");
                 stp_step(STP_CCW);
             }
             if (jog_cw == 0) {
+                //pc.printf("turning CW\n");
                 stp_step(STP_CW);
             } 
         }
--- 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