Simple test application for the STMicroelectronics X-NUCLEO-IHM02A1 Stepper Motor Control Expansion Board.
Dependencies: X_NUCLEO_IHM02A1 mbed
Fork of HelloWorld_IHM02A1 by
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.
Revision 22:e81ccf73bc5d, committed 2017-03-01
- Comitter:
- Davidroid
- Date:
- Wed Mar 01 17:53:04 2017 +0000
- Parent:
- 21:bf0db5218654
- Child:
- 23:073b26366d03
- Commit message:
- Fitting mbed coding style.
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 Tue Sep 27 13:58:51 2016 +0000 +++ b/X_NUCLEO_IHM02A1.lib Wed Mar 01 17:53:04 2017 +0000 @@ -1,1 +1,1 @@ -https://developer.mbed.org/teams/ST/code/X_NUCLEO_IHM02A1/#e6fa636dbdea +https://developer.mbed.org/teams/ST/code/X_NUCLEO_IHM02A1/#1b7f3e002688
--- a/main.cpp Tue Sep 27 13:58:51 2016 +0000 +++ b/main.cpp Wed Mar 01 17:53:04 2017 +0000 @@ -70,8 +70,7 @@ X_NUCLEO_IHM02A1 *x_nucleo_ihm02a1; /* Initialization parameters of the motors connected to the expansion board. */ -L6470_Init_t init[L6470DAISYCHAINSIZE] = -{ +L6470_Init_t init[L6470DAISYCHAINSIZE] = { /* First Motor. */ { 9.0, /* Motor supply voltage in V. */ @@ -261,8 +260,9 @@ /* Halving the microsteps. */ init[0].step_sel = (init[0].step_sel > 0 ? init[0].step_sel - 1 : init[0].step_sel); - if (!motors[0]->SetStepMode((StepperMotor::step_mode_t) init[0].step_sel)) + if (!motors[0]->SetStepMode((StepperMotor::step_mode_t) init[0].step_sel)) { printf(" Step Mode not allowed.\r\n"); + } /* Waiting. */ wait_ms(DELAY_1); @@ -316,8 +316,9 @@ printf("--> Running together for %d seconds.\r\n", DELAY_3 / 1000); /* Preparing each motor to perform a run at a specified speed. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) + for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { motors[m]->PrepareRun(StepperMotor::BWD, 400); + } /* Performing the action on each motor at the same time. */ x_nucleo_ihm02a1->PerformPreparedActions(); @@ -329,8 +330,9 @@ /*----- Increasing the speed while running. -----*/ /* Preparing each motor to perform a run at a specified speed. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) + for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { motors[m]->PrepareGetSpeed(); + } /* Performing the action on each motor at the same time. */ uint32_t* results = x_nucleo_ihm02a1->PerformPreparedActions(); @@ -342,8 +344,9 @@ printf("--> Doublig the speed while running again for %d seconds.\r\n", DELAY_3 / 1000); /* Preparing each motor to perform a run at a specified speed. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) + for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { motors[m]->PrepareRun(StepperMotor::BWD, results[m] << 1); + } /* Performing the action on each motor at the same time. */ results = x_nucleo_ihm02a1->PerformPreparedActions(); @@ -352,8 +355,9 @@ wait_ms(DELAY_3); /* Preparing each motor to perform a run at a specified speed. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) + for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { motors[m]->PrepareGetSpeed(); + } /* Performing the action on each motor at the same time. */ results = x_nucleo_ihm02a1->PerformPreparedActions(); @@ -371,8 +375,9 @@ printf("--> Hard Stop.\r\n"); /* Preparing each motor to perform a hard stop. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) + for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { motors[m]->PrepareHardStop(); + } /* Performing the action on each motor at the same time. */ x_nucleo_ihm02a1->PerformPreparedActions(); @@ -387,9 +392,8 @@ printf("--> Doing a full revolution on each motor, one after the other.\r\n"); /* Doing a full revolution on each motor, one after the other. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) - for (int i = 0; i < MPR_1; i++) - { + for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { + for (int i = 0; i < MPR_1; i++) { /* Computing the number of steps. */ int steps = (int) (((int) init[m].fullstepsperrevolution * pow(2.0f, init[m].step_sel)) / MPR_1); @@ -402,6 +406,7 @@ /* Waiting. */ wait_ms(DELAY_1); } + } /* Waiting. */ wait_ms(DELAY_2); @@ -413,12 +418,13 @@ printf("--> High Impedance State.\r\n"); /* Preparing each motor to set High Impedance State. */ - for (int m = 0; m < L6470DAISYCHAINSIZE; m++) + for (int m = 0; m < L6470DAISYCHAINSIZE; m++) { motors[m]->PrepareHardHiZ(); + } /* Performing the action on each motor at the same time. */ x_nucleo_ihm02a1->PerformPreparedActions(); /* Waiting. */ wait_ms(DELAY_2); -} \ No newline at end of file +}