Simple test application for the STMicroelectronics X-NUCLEO-IHM01A1 Stepper Motor Control Expansion Board, built against mbed OS.

Dependencies:   X_NUCLEO_IHM01A1

Fork of HelloWorld_IHM01A1_2Motors by ST

Motor Control with the X-NUCLEO-IHM01A1 Expansion Board

This application provides a simple example of usage of the X-NUCLEO-IHM01A1 Stepper Motor Control Expansion Board.
It shows how to use two stepper motors connected to two stacked boards in daisy chain configuration, moving the rotors to specific positions, with given speed values, directions of rotation, etc.

Files at this revision

API Documentation at this revision

Comitter:
Davidroid
Date:
Thu Sep 08 12:52:04 2016 +0000
Parent:
23:0b4fc703dbf4
Child:
25:9cdd060be8a1
Commit message:
Comment about pps added.

Changed in this revision

X_NUCLEO_IHM01A1.lib 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
--- a/X_NUCLEO_IHM01A1.lib	Fri Apr 08 12:57:07 2016 +0000
+++ b/X_NUCLEO_IHM01A1.lib	Thu Sep 08 12:52:04 2016 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/ST/code/X_NUCLEO_IHM01A1/#fd83fecf1ef5
+https://developer.mbed.org/teams/ST/code/X_NUCLEO_IHM01A1/#990963ed581b
--- a/main.cpp	Fri Apr 08 12:57:07 2016 +0000
+++ b/main.cpp	Thu Sep 08 12:52:04 2016 +0000
@@ -51,9 +51,20 @@
 
 /* Definitions ---------------------------------------------------------------*/
 
-/* Number of steps to move. */
+/* Number of steps. */
 #define STEPS 3200
 
+/* Delay in milliseconds. */
+#define DELAY_1 2000
+#define DELAY_2 6000
+#define DELAY_3 8000
+
+/* Speed in pps (Pulses Per Second).
+   In Full Step mode: 1 pps = 1 step/s).
+   In 1/N Step Mode:  N pps = 1 step/s). */
+#define SPEED_1 2400
+#define SPEED_2 1200
+
 
 /* Variables -----------------------------------------------------------------*/
 
@@ -104,7 +115,7 @@
     printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
 
     /* Waiting 2 seconds. */
-    wait_ms(2000);
+    wait_ms(DELAY_1);
 
     
     /*----- Moving. -----*/
@@ -134,7 +145,7 @@
     motor2->SetHome();
 
     /* Waiting 2 seconds. */
-    wait_ms(2000);
+    wait_ms(DELAY_1);
 
 
     /*----- Going to a specified position. -----*/
@@ -158,7 +169,7 @@
     printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
     
     /* Waiting 2 seconds. */
-    wait_ms(2000);
+    wait_ms(DELAY_1);
 
     
     /*----- Going Home. -----*/
@@ -182,7 +193,7 @@
     printf("    Position: M1 %d, M2 %d.\r\n", position1, position2);
 
     /* Waiting 2 seconds. */
-    wait_ms(2000);
+    wait_ms(DELAY_1);
 
 
     /*----- Running. -----*/
@@ -195,7 +206,7 @@
     motor2->Run(StepperMotor::FWD);
 
     /* Waiting until delay has expired. */
-    wait_ms(6000);
+    wait_ms(DELAY_2);
 
     /* Getting current speed. */
     int speed1 = motor1->GetSpeed();
@@ -209,12 +220,12 @@
     /* Printing to the console. */
     printf("--> Increasing the speed while running.\r\n");
 
-    /* Increasing speed to 2400 step/s. */
-    motor1->SetMaxSpeed(2400);
-    motor2->SetMaxSpeed(2400);
+    /* Increasing the speed. */
+    motor1->SetMaxSpeed(SPEED_1);
+    motor2->SetMaxSpeed(SPEED_1);
 
     /* Waiting until delay has expired. */
-    wait_ms(6000);
+    wait_ms(DELAY_2);
 
     /* Getting current speed. */
     speed1 = motor1->GetSpeed();
@@ -229,12 +240,12 @@
     /* Printing to the console. */
     printf("--> Decreasing the speed while running.\r\n");
 
-    /* Decreasing speed to 1200 step/s. */
-    motor1->SetMaxSpeed(1200);
-    motor2->SetMaxSpeed(1200);
+    /* Decreasing the speed. */
+    motor1->SetMaxSpeed(SPEED_2);
+    motor2->SetMaxSpeed(SPEED_2);
 
     /* Waiting until delay has expired. */
-    wait_ms(8000);
+    wait_ms(DELAY_3);
 
     /* Getting current speed. */
     speed1 = motor1->GetSpeed();
@@ -258,7 +269,7 @@
     motor2->WaitWhileActive();
 
     /* Waiting 2 seconds. */
-    wait_ms(2000);
+    wait_ms(DELAY_1);
 
 
     /*----- Infinite Loop. -----*/