Simple test application for the STMicroelectronics X-NUCLEO-IHM01A1 Stepper Motor Control Expansion Board.

Dependencies:   X_NUCLEO_IHM01A1 mbed

Fork of HelloWorld_IHM01A1 by ST Expansion SW Team

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 one stepper motor connected to the board, moving the rotor to a specific position, with a given speed value, direction of rotation, etc.

Revision:
3:fffa53c7aed2
Parent:
2:e12e4df7a486
Child:
5:8065b587ade0
--- a/main.cpp	Fri Nov 13 12:59:29 2015 +0000
+++ b/main.cpp	Wed Nov 18 18:45:35 2015 +0000
@@ -54,7 +54,7 @@
 /* Definitions ---------------------------------------------------------------*/
 
 /* Number of steps corresponding to one round angle of the motor. */
-#define ROUND_ANGLE_STEPS 1600
+#define ROUND_ANGLE_STEPS 3200
 
 
 /* Variables -----------------------------------------------------------------*/
@@ -81,14 +81,14 @@
     /* Main Loop. */
     while(true)
     {
-        /*----- Moving forward of N steps. -----*/
+        /*----- Moving. -----*/
 
         /* Printing to the console. */
         printf("--> Moving forward %d steps.\r\n", ROUND_ANGLE_STEPS);
 
         /* Moving N steps in the forward direction. */
-        motor->Move(StepperMotor::CW, ROUND_ANGLE_STEPS);
-        
+        motor->Move(StepperMotor::FWD, ROUND_ANGLE_STEPS);
+
         /* Waiting while the motor is active. */
         motor->WaitWhileActive();
 
@@ -102,13 +102,13 @@
         wait_ms(2000);
 
         
-        /*----- Moving backward N steps. -----*/
+        /*----- Moving. -----*/
         
         /* Printing to the console. */
-        printf("--> Moving backward %d steps.\r\n", ROUND_ANGLE_STEPS);
-        
+        printf("--> Moving backward %d steps.\r\n", ROUND_ANGLE_STEPS >> 1);
+
         /* Moving N steps in the backward direction. */
-        motor->Move(StepperMotor::CCW, ROUND_ANGLE_STEPS);
+        motor->Move(StepperMotor::BWD, ROUND_ANGLE_STEPS >> 1);
         
         /* Waiting while the motor is active. */
         motor->WaitWhileActive();
@@ -118,6 +118,7 @@
         
         /* Printing to the console. */
         printf("    Position: %d.\r\n", position);
+        printf("--> Setting Home.\r\n");
 
         /* Setting the current position to be the home position. */
         motor->SetHome();
@@ -168,13 +169,13 @@
         wait_ms(2000);
 
 
-        /*----- Moving backward. -----*/
+        /*----- Running. -----*/
 
         /* Printing to the console. */
-        printf("--> Moving backward.\r\n");
+        printf("--> Running backward.\r\n");
 
         /* Requesting to run backward. */
-        motor->Run(StepperMotor::CCW);
+        motor->Run(StepperMotor::BWD);
 
         /* Waiting until delay has expired. */
         wait_ms(6000);
@@ -185,7 +186,6 @@
         /* Printing to the console. */
         printf("    Speed: %d.\r\n", speed);
 
-
         /*----- Increasing the speed while running. -----*/
 
         /* Printing to the console. */
@@ -222,18 +222,6 @@
         printf("    Speed: %d.\r\n", speed);
 
 
-        /*----- Moving forward. -----*/
-
-        /* Printing to the console. */
-        printf("--> Moving forward.\r\n");
-
-        /* Requesting to run in forward direction. */
-        motor->Run(StepperMotor::CW);
-
-        /* Waiting until delay has expired. */
-        wait_ms(4000);
-        
-
         /*----- Requiring hard-stop while running. -----*/
 
         /* Printing to the console. */
@@ -261,13 +249,13 @@
         while(1)
         {
             /* Requesting to go to a specified position. */
-            motor->GoTo(- ROUND_ANGLE_STEPS >> 2);
+            motor->GoTo(ROUND_ANGLE_STEPS >> 1);
 
             /* Waiting while the motor is active. */
             motor->WaitWhileActive();
 
             /* Requesting to go to a specified position. */
-            motor->GoTo(ROUND_ANGLE_STEPS >> 2);
+            motor->GoTo(- (ROUND_ANGLE_STEPS >> 1));
 
             /* Waiting while the motor is active. */
             motor->WaitWhileActive();