This is an example application demonstrating building an EtherCAT system using Esmacat

Dependencies:   EsmacatShield X_NUCLEO_IHM01A1

Basic Information of Esmacat

Information about Esmacat and EASE is provided in the link below. https://os.mbed.com/users/esmacat/code/EASE_Example/wiki/Homepage

Information about the hardware needs and setup is provided in the link below. https://os.mbed.com/users/esmacat/code/EASE_Example/wiki/Hardware-Setup

Information about the structure of the system and it's software is provided in the link below. https://os.mbed.com/users/esmacat/code/EASE_Example/wiki/Software

About this example

This is an example application to demonstrate the ease with which a system, which communicates over EtherCAT, can be build. It measures the RPM of a motor using a proximity sensor.

Following lists the hardware required

  • 2 x Mbed boards with Arduino UNO form factor (NUCLEO-F103RB)
  • 2 x EASE boards
  • 1 x proximity sensor shield (X_NUCLEO_6180XA1)
  • 1 x Motor shield (X-NUCLEO-IHM01A1)
  • 1 x stepper motor
  • 1 x Ethernet POE injector with a 24VDC power supply
  • 2 x Ethernet cables
  • Keyboard, mouse, and monitor
  • PC with Linux/Windows OS installed
  • DC power supply for motor

https://os.mbed.com/media/uploads/pratima_hb/system_pic1.jpg

Click here to know more about this Example

Revision:
40:fc0e002acc8c
Parent:
39:1270497828ca
Child:
42:faa7b7382f2f
--- 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();