Test application for the STMicroelectronics X-NUCLEO-IHM01A1 Stepper Motor Control Expansion Board.
Dependencies: X_NUCLEO_IHM01A1
Fork of MotorControl_IHM01A1 by
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.
Diff: main.cpp
- Revision:
- 3:82f4c46cccd0
- Parent:
- 2:d956260240b0
- Child:
- 4:43df256f26d9
--- a/main.cpp Fri Nov 13 13:00:23 2015 +0000 +++ b/main.cpp Wed Nov 18 19:13:32 2015 +0000 @@ -82,7 +82,7 @@ printf("--> Moving forward 16000 steps.\r\n"); /* Moving 16000 steps in the forward direction. */ - motor->Move(StepperMotor::CW, 16000); + motor->Move(StepperMotor::FWD, 16000); /* Waiting while the motor is active. */ motor->WaitWhileActive(); @@ -97,11 +97,14 @@ printf("--> Moving backward 16000 steps.\r\n"); /* Moving 16000 steps in the backward direction. */ - motor->Move(StepperMotor::CCW, 16000); + motor->Move(StepperMotor::BWD, 16000); /* Waiting while the motor is active. */ motor->WaitWhileActive(); + /* Printing to the console. */ + printf("--> Setting Home.\r\n"); + /* Setting the current position to be the home position. */ motor->SetHome(); @@ -126,6 +129,9 @@ /* Printing to the console. */ printf(" Position: %d.\r\n", position); + /* Printing to the console. */ + printf("--> Setting a mark.\r\n"); + /* Setting the current position to be the mark position. */ motor->SetMark(); @@ -178,7 +184,7 @@ /*----- Going to mark which was set previously after going to -6400. -----*/ /* Printing to the console. */ - printf("--> Going to mark which was set previously after going to -6400.\r\n"); + printf("--> Going to the mark set previously.\r\n"); /* Requesting to go to mark position. */ motor->GoMark(); @@ -196,13 +202,13 @@ wait_ms(2000); - /*----- Moving backward. -----*/ + /*----- Running backward. -----*/ /* 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(5000); @@ -298,10 +304,10 @@ printf(" Speed: %d.\r\n", speed); - /*----- Requiring soft-stop while running. -----*/ + /*----- Requesting soft-stop while running. -----*/ /* Printing to the console. */ - printf("--> Requiring soft-stop while running.\r\n"); + printf("--> Requesting soft-stop while running.\r\n"); /* Requesting soft stop. */ motor->SoftStop(); @@ -313,17 +319,20 @@ wait_ms(2000); - /*----- Requiring hard-stop while running. -----*/ + /*----- Requesting hard-stop while running. -----*/ /* Printing to the console. */ - printf("--> Requiring hard-stop while running.\r\n"); - + printf("--> Running forward.\r\n"); + /* Requesting to run in forward direction. */ - motor->Run(StepperMotor::CW); + motor->Run(StepperMotor::FWD); /* Waiting until delay has expired. */ wait_ms(5000); - + + /* Printing to the console. */ + printf("--> Requesting hard-stop while running.\r\n"); + /* Requesting to immediatly stop. */ motor->HardStop(); @@ -337,14 +346,17 @@ /*----- GOTO stopped by soft-stop. -----*/ /* Printing to the console. */ - printf("--> GOTO stopped by soft-stop.\r\n"); - + printf("--> Going to position 20000.\r\n"); + /* Requesting to go to a specified position. */ motor->GoTo(20000); /* Waiting while the motor is active. */ wait_ms(5000); + /* Printing to the console. */ + printf("--> Requiring soft-stop while running.\r\n"); + /* Requesting to perform a soft stop */ motor->SoftStop();