Pratima Gokhale / Mbed OS Example_EtherCAT_System_Using_EASE

Dependencies:   EsmacatShield X_NUCLEO_IHM01A1

Files at this revision

API Documentation at this revision

Comitter:
pratima_hb
Date:
Thu Feb 13 17:16:43 2020 +0000
Parent:
39:1270497828ca
Child:
42:faa7b7382f2f
Commit message:
Example application to build EtherCAT system using EASE

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Thu Feb 06 22:44:58 2020 +0000
+++ b/main.cpp	Thu Feb 13 17:16:43 2020 +0000
@@ -83,17 +83,20 @@
 /* Component specific header files. */
 #include "L6474.h"
 
-/* Esmacat code*/
+///* Esmacat code*/
 #include <EsmacatShield.h>      //Include Esmacat Library
 
 int16_t ease_read[8];                       //EASE 8 registers
 
-/*D9 Chip select for EASE. Remember to change the jumper on the board*/
+///*D9 Chip select for EASE. Remember to change the jumper on the board*/
 DigitalOut selectPin(D9);  
 SPI spi(D11, D12, D13); // mosi, miso, sclk
-/* Esmacat code*/
+///* Esmacat code*/
 
 /* Definitions ---------------------------------------------------------------*/
+
+
+#define STEPS_1 (400 * 8)   /* 1 revolution given a 400 steps motor configured at 1/8 microstep mode. */
 /* Delay in milliseconds. */
 #define DELAY_1 1000
 
@@ -165,15 +168,14 @@
 
 int main()
 {
-    /*----- Initialization of EASE -----*/
-
    
     /*----- Initialization. -----*/
 
-    /* Initializing SPI bus. */
+    /* Initializing SPI bus for Motor */
     DevSPI dev_spi(D11, D12, D13);// SPI device for the motor
     dev_spi.setup(8, 3, 3E6);      // Set-up SPI device for the motor
-    
+ 
+  /* EASE slave object creation and Initializing SPI bus for EASE */
     EsmacatShield slave(spi, selectPin);    //Define Chip Selector Pin
     slave.setup_spi();                      //Setup SPI for EASE
 
@@ -186,10 +188,7 @@
 
     /* Attaching and enabling interrupt handlers. */
     motor->attach_flag_irq(&flag_irq_handler);
-    motor->enable_flag_irq();
-    
-
-
+    motor->enable_flag_irq(); 
 
     while(1)
     {
@@ -202,11 +201,7 @@
         
         // get the data from Esmacat Master
         slave.get_ecat_registers(ease_read);  //read all registers
-        
-        wait_us(1000);  
-           /* Printing to the console. */
-        printf("--> Moving to position : %d\r\n", ease_read[0]);
-      
+       
         
         // This part of the code sets up the Mode 1 for SPI to be used for
         // communication with EASE. This is needed because SPI for EASE operates
@@ -215,9 +210,17 @@
         wait_us(200); 
         
         // command the motor to go to a set postion
-        motor->go_to(ease_read[0]);
-        
-    
+        if (ease_read[0] == 0)
+        {
+            printf("Value from EASE %d.\r\n", ease_read[0]);
+            motor->move(StepperMotor::FWD, STEPS_1);
+        }
+        else if(ease_read[0] == 10)
+        {
+            printf("Value from EASE %d.\r\n", ease_read[0]);
+            motor->move(StepperMotor::BWD, STEPS_1);
+        }
+             
         /* Getting current position. */
        int position = motor->get_position();