Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_IHM01A1
Fork of HelloWorld_IHM01A1 by
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.
Diff: main.cpp
- Revision:
- 34:543d0d1147d9
- Parent:
- 29:a80a213c3c94
- Child:
- 35:2b44ed4ec7a0
diff -r b7c72f06bc38 -r 543d0d1147d9 main.cpp
--- a/main.cpp Fri Oct 28 13:50:25 2016 +0000
+++ b/main.cpp Wed Mar 01 13:31:48 2017 +0000
@@ -70,8 +70,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]. */
@@ -120,11 +119,12 @@
/* Get the value of the status register. */
unsigned int status = motor->GetStatus();
-
+
/* Check NOTPERF_CMD flag: if set, the command received by SPI can't be performed. */
/* This often occures when a command is sent to the L6474 while it is not in HiZ state. */
- if ((status & L6474_STATUS_NOTPERF_CMD) == L6474_STATUS_NOTPERF_CMD)
+ if ((status & L6474_STATUS_NOTPERF_CMD) == L6474_STATUS_NOTPERF_CMD) {
printf(" WARNING: \"FLAG\" interrupt triggered. Non-performable command detected when updating L6474's registers while not in HiZ state.\r\n");
+ }
/* Reset ISR flag. */
motor->isr_flag = FALSE;
@@ -142,8 +142,9 @@
/* 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 interrupt handlers. */
motor->AttachFlagIRQ(&FlagIRQHandler);
@@ -186,8 +187,9 @@
printf("--> Doubling the microsteps.\r\n");
/* Doubling the microsteps. */
- 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");
+ }
/* Waiting. */
wait_ms(DELAY_1);
@@ -348,8 +350,7 @@
motor->SetHome();
/* Infinite Loop. */
- while (1)
- {
+ while (true) {
/* Requesting to go to a specified position. */
motor->GoTo(STEPS_1 >> 1);
