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

Dependencies:   X_NUCLEO_IHM01A1

Fork of MotorControl_IHM01A1 by ST

Motor Control with the X-NUCLEO-IHM01A1 Expansion Board

This application provides a more complex 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, with an example of ISR and error handler, as well as an almost complete coverage of the available APIs, e.g.:

  • moving the rotor to a specific position;
  • moving the rotor for a certain amount of time;
  • setting the speed value;
  • setting the direction of rotation;
  • changing the stepper motor mode;
  • soft/hard stopping the rotor;
  • powering off the power bridge.
Revision:
25:205b3d09e64e
Parent:
22:ce8a202d67ac
Child:
26:7a58cede28f7
diff -r 0ff22ad6da45 -r 205b3d09e64e main.cpp
--- a/main.cpp	Fri Oct 28 13:37:16 2016 +0000
+++ b/main.cpp	Wed Mar 01 15:55:18 2017 +0000
@@ -53,8 +53,7 @@
 /* Variables -----------------------------------------------------------------*/
 
 /* Initialization parameters. */
-L6474_Init_t init =
-{
+L6474_Init_t init = {
     160,                              /* Acceleration rate in pps^2. Range: (0..+inf). */
     160,                              /* Deceleration rate in pps^2. Range: (0..+inf). */
     1600,                             /* Maximum speed in pps. Range: (30..10000]. */
@@ -88,8 +87,9 @@
 
 /**
   * @brief  This is an example of user handler for the flag interrupt.
-  * @param  None
-  * @retval None
+  *         Empty parts can be implemented by the user upon needs.
+  * @param  None.
+  * @retval None.
   * @note   If needed, implement it, and then attach and enable it:
   *           + motor->AttachFlagIRQ(&FlagIRQHandler);
   *           + motor->EnableFlagIRQ();
@@ -171,8 +171,13 @@
 
     /* Initializing Motor Control Component. */
     motor = new L6474(D2, D8, D7, D9, D10, dev_spi);
-    if (motor->Init(&init) != COMPONENT_OK)
+    if (motor->Init(&init) != COMPONENT_OK) {
         exit(EXIT_FAILURE);
+    }
+
+    /* Attaching and enabling the user handler for the flag interrupt. */
+    motor->AttachFlagIRQ(&FlagIRQHandler);
+    motor->EnableFlagIRQ();
 
     /* Printing to the console. */
     printf("Motor Control Application Example for 1 Motor\r\n\n");
@@ -491,8 +496,9 @@
     printf("--> Changing step mode to full step mode.\r\n");
 
     /* Selecting full step mode. */
-    if (!motor->SetStepMode((StepperMotor::step_mode_t) STEP_MODE_FULL))
+    if (!motor->SetStepMode((StepperMotor::step_mode_t) STEP_MODE_FULL)) {
         printf("    Step Mode not allowed.\r\n");
+    }
 
     /* Setting speed and acceleration to be consistent with full step mode. */
     motor->SetMaxSpeed(100);
@@ -522,8 +528,9 @@
     printf("--> Restoring 1/16 microstepping mode.\r\n");
 
     /* Resetting to 1/16 microstepping mode */
-    if (!motor->SetStepMode((StepperMotor::step_mode_t) STEP_MODE_1_16))
+    if (!motor->SetStepMode((StepperMotor::step_mode_t) STEP_MODE_1_16)) {
         printf("    Step Mode not allowed.\r\n");
+    }
 
     /* Update speed, acceleration, deceleration for 1/16 microstepping mode*/
     motor->SetMaxSpeed(1600);
@@ -538,8 +545,7 @@
     printf("--> Infinite Loop...\r\n");
 
     /* Infinite Loop. */
-    while(1)
-    {
+    while (true) {
         /* Requesting to go to a specified position. */
         motor->GoTo(-6400);