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

Dependencies:   X_NUCLEO_IHM02A1

Fork of HelloWorld_IHM02A1 by ST

Motor Control with the X-NUCLEO-IHM02A1 Expansion Board

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

Files at this revision

API Documentation at this revision

Comitter:
Davidroid
Date:
Fri Dec 11 17:24:01 2015 +0000
Parent:
8:4166b98332de
Child:
10:d1e568b0079d
Commit message:
+ Initialization structure moved from the BSP to the main application.

Changed in this revision

X_NUCLEO_IHM02A1.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_IHM02A1.lib	Thu Dec 10 15:43:00 2015 +0000
+++ b/X_NUCLEO_IHM02A1.lib	Fri Dec 11 17:24:01 2015 +0000
@@ -1,1 +1,1 @@
-https://developer.mbed.org/teams/ST-Expansion-SW-Team/code/X_NUCLEO_IHM02A1/#a9513361a2ec
+https://developer.mbed.org/teams/ST-Expansion-SW-Team/code/X_NUCLEO_IHM02A1/#d70452d7a1e1
--- a/main.cpp	Thu Dec 10 15:43:00 2015 +0000
+++ b/main.cpp	Fri Dec 11 17:24:01 2015 +0000
@@ -69,6 +69,66 @@
 /* Motor Control Expansion Board. */
 X_NUCLEO_IHM02A1 *x_nucleo_ihm02a1;
 
+/* Initialization parameters of the motors connected to the expansion board. */
+MICROSTEPPING_MOTOR_InitTypeDef init[L6470DAISYCHAINSIZE] =
+{
+    /* First Motor. */
+    {
+        9.0,                /* Motor supply voltage in V. */
+        200,                /* Min number of steps per revolution for the motor. */
+        1.7,                /* Max motor phase voltage in A. */
+        3.06,               /* Max motor phase voltage in V. */
+        300.0,              /* Motor initial speed [step/s]. */
+        500.0,              /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
+        500.0,              /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
+        992.0,              /* Motor maximum speed [step/s]. */
+        0.0,                /* Motor minimum speed [step/s]. */
+        602.7,              /* Motor full-step speed threshold [step/s]. */
+        3.06,               /* Holding kval [V]. */
+        3.06,               /* Constant speed kval [V]. */
+        3.06,               /* Acceleration starting kval [V]. */
+        3.06,               /* Deceleration starting kval [V]. */
+        61.52,              /* Intersect speed for bemf compensation curve slope changing [step/s]. */
+        392.1569e-6,        /* Start slope [s/step]. */
+        643.1372e-6,        /* Acceleration final slope [s/step]. */
+        643.1372e-6,        /* Deceleration final slope [s/step]. */
+        0,                  /* Thermal compensation factor (range [0, 15]). */
+        3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
+        3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
+        MICROSTEP_1_128,    /* Step mode selection. */
+        0xFF,               /* Alarm conditions enable. */
+        0x2E88              /* Ic configuration. */
+    },
+
+    /* Second Motor. */
+    {
+        9.0,                /* Motor supply voltage in V. */
+        200,                /* Min number of steps per revolution for the motor. */
+        1.7,                /* Max motor phase voltage in A. */
+        3.06,               /* Max motor phase voltage in V. */
+        300.0,              /* Motor initial speed [step/s]. */
+        500.0,              /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
+        500.0,              /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
+        992.0,              /* Motor maximum speed [step/s]. */
+        0.0,                /* Motor minimum speed [step/s]. */
+        602.7,              /* Motor full-step speed threshold [step/s]. */
+        3.06,               /* Holding kval [V]. */
+        3.06,               /* Constant speed kval [V]. */
+        3.06,               /* Acceleration starting kval [V]. */
+        3.06,               /* Deceleration starting kval [V]. */
+        61.52,              /* Intersect speed for bemf compensation curve slope changing [step/s]. */
+        392.1569e-6,        /* Start slope [s/step]. */
+        643.1372e-6,        /* Acceleration final slope [s/step]. */
+        643.1372e-6,        /* Deceleration final slope [s/step]. */
+        0,                  /* Thermal compensation factor (range [0, 15]). */
+        3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
+        3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
+        MICROSTEP_1_128,    /* Step mode selection. */
+        0xFF,               /* Alarm conditions enable. */
+        0x2E88              /* Ic configuration. */
+    }
+};
+
 
 /* Main ----------------------------------------------------------------------*/
 
@@ -80,7 +140,7 @@
     DevSPI dev_spi(D11, D12, D3);
 
     /* Initializing Motor Control Expansion Board. */
-    x_nucleo_ihm02a1 = new X_NUCLEO_IHM02A1(A4, A5, D4, A2, &dev_spi);
+    x_nucleo_ihm02a1 = new X_NUCLEO_IHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi);
 
     /* Building a list of motor control components. */
     L6470 **motors = x_nucleo_ihm02a1->GetComponents();
@@ -278,7 +338,7 @@
         for (int i = 0; i < MPR_1; i++)
         {
             /* Computing the number of steps. */
-            int steps = (int) (((int) X_NUCLEO_IHM02A1::MotorParameterInitData[0][m].fullstepsperrevolution * pow(2.0f, X_NUCLEO_IHM02A1::MotorParameterInitData[0][m].step_sel)) / MPR_1);
+            int steps = (int) (((int) init[m].fullstepsperrevolution * pow(2.0f, init[m].step_sel)) / MPR_1);
 
             /* Moving. */
             motors[m]->Move(StepperMotor::FWD, steps);