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

Dependencies:   X_NUCLEO_IHM01A1 mbed

Fork of HelloWorld_IHM01A1 by ST Expansion SW Team

Motor Control with the X-NUCLEO-IHM01A1 Expansion Board

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.

Committer:
Davidroid
Date:
Fri Nov 20 18:02:01 2015 +0000
Revision:
5:8065b587ade0
Parent:
3:fffa53c7aed2
Child:
6:32166bfc04b0
+ FlagIRQHandler and ErrorHandler examples added.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Davidroid 0:e6a49a092e2a 1 /**
Davidroid 0:e6a49a092e2a 2 ******************************************************************************
Davidroid 0:e6a49a092e2a 3 * @file main.cpp
Davidroid 0:e6a49a092e2a 4 * @author Davide Aliprandi / AST
Davidroid 0:e6a49a092e2a 5 * @version V1.0.0
Davidroid 0:e6a49a092e2a 6 * @date October 14th, 2015
Davidroid 0:e6a49a092e2a 7 * @brief mbed test application for the STMicrolectronics X-NUCLEO-IHM01A1
Davidroid 0:e6a49a092e2a 8 * Motor Control Expansion Board: control of 1 motor.
Davidroid 0:e6a49a092e2a 9 * This application makes use of a C++ component architecture obtained
Davidroid 0:e6a49a092e2a 10 * from the C component architecture through the Stm32CubeTOO tool.
Davidroid 0:e6a49a092e2a 11 ******************************************************************************
Davidroid 0:e6a49a092e2a 12 * @attention
Davidroid 0:e6a49a092e2a 13 *
Davidroid 0:e6a49a092e2a 14 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Davidroid 0:e6a49a092e2a 15 *
Davidroid 0:e6a49a092e2a 16 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 0:e6a49a092e2a 17 * are permitted provided that the following conditions are met:
Davidroid 0:e6a49a092e2a 18 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 0:e6a49a092e2a 19 * this list of conditions and the following disclaimer.
Davidroid 0:e6a49a092e2a 20 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 0:e6a49a092e2a 21 * this list of conditions and the following disclaimer in the documentation
Davidroid 0:e6a49a092e2a 22 * and/or other materials provided with the distribution.
Davidroid 0:e6a49a092e2a 23 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 0:e6a49a092e2a 24 * may be used to endorse or promote products derived from this software
Davidroid 0:e6a49a092e2a 25 * without specific prior written permission.
Davidroid 0:e6a49a092e2a 26 *
Davidroid 0:e6a49a092e2a 27 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 0:e6a49a092e2a 28 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 0:e6a49a092e2a 29 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 0:e6a49a092e2a 30 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 0:e6a49a092e2a 31 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 0:e6a49a092e2a 32 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 0:e6a49a092e2a 33 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 0:e6a49a092e2a 34 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 0:e6a49a092e2a 35 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 0:e6a49a092e2a 36 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 0:e6a49a092e2a 37 *
Davidroid 0:e6a49a092e2a 38 ******************************************************************************
Davidroid 0:e6a49a092e2a 39 */
Davidroid 0:e6a49a092e2a 40
Davidroid 0:e6a49a092e2a 41
Davidroid 0:e6a49a092e2a 42 /* Includes ------------------------------------------------------------------*/
Davidroid 0:e6a49a092e2a 43
Davidroid 0:e6a49a092e2a 44 /* mbed specific header files. */
Davidroid 0:e6a49a092e2a 45 #include "mbed.h"
Davidroid 0:e6a49a092e2a 46
Davidroid 0:e6a49a092e2a 47 /* Helper header files. */
Davidroid 0:e6a49a092e2a 48 #include "DevSPI.h"
Davidroid 0:e6a49a092e2a 49
Davidroid 0:e6a49a092e2a 50 /* Component specific header files. */
Davidroid 0:e6a49a092e2a 51 #include "l6474_class.h"
Davidroid 0:e6a49a092e2a 52
Davidroid 0:e6a49a092e2a 53
Davidroid 0:e6a49a092e2a 54 /* Definitions ---------------------------------------------------------------*/
Davidroid 0:e6a49a092e2a 55
Davidroid 0:e6a49a092e2a 56 /* Number of steps corresponding to one round angle of the motor. */
Davidroid 3:fffa53c7aed2 57 #define ROUND_ANGLE_STEPS 3200
Davidroid 0:e6a49a092e2a 58
Davidroid 0:e6a49a092e2a 59
Davidroid 0:e6a49a092e2a 60 /* Variables -----------------------------------------------------------------*/
Davidroid 0:e6a49a092e2a 61
Davidroid 0:e6a49a092e2a 62 /* Motor Control Component. */
Davidroid 1:fbf28f3367aa 63 L6474 *motor;
Davidroid 0:e6a49a092e2a 64
Davidroid 0:e6a49a092e2a 65
Davidroid 5:8065b587ade0 66 /* Functions -----------------------------------------------------------------*/
Davidroid 5:8065b587ade0 67
Davidroid 5:8065b587ade0 68 /**
Davidroid 5:8065b587ade0 69 * @brief This is an example of user handler for the flag interrupt.
Davidroid 5:8065b587ade0 70 * @param None
Davidroid 5:8065b587ade0 71 * @retval None
Davidroid 5:8065b587ade0 72 * @note If needed, implement it, and then attach and enable it:
Davidroid 5:8065b587ade0 73 * + motor->AttachFlagIRQ(&FlagIRQHandler);
Davidroid 5:8065b587ade0 74 * + motor->EnableFlagIRQ();
Davidroid 5:8065b587ade0 75 * To disable it:
Davidroid 5:8065b587ade0 76 * + motor->DisbleFlagIRQ();
Davidroid 5:8065b587ade0 77 */
Davidroid 5:8065b587ade0 78 void FlagIRQHandler(void)
Davidroid 5:8065b587ade0 79 {
Davidroid 5:8065b587ade0 80 /* Set ISR flag. */
Davidroid 5:8065b587ade0 81 motor->isrFlag = TRUE;
Davidroid 5:8065b587ade0 82
Davidroid 5:8065b587ade0 83 /* Get the value of the status register. */
Davidroid 5:8065b587ade0 84 unsigned int status = motor->GetStatus();
Davidroid 5:8065b587ade0 85
Davidroid 5:8065b587ade0 86 /* Check HIZ flag: if set, power brigdes are disabled. */
Davidroid 5:8065b587ade0 87 if ((status & L6474_STATUS_HIZ) == L6474_STATUS_HIZ)
Davidroid 5:8065b587ade0 88 { /* HIZ state. Action to be customized. */ }
Davidroid 5:8065b587ade0 89
Davidroid 5:8065b587ade0 90 /* Check direction. */
Davidroid 5:8065b587ade0 91 if ((status & L6474_STATUS_DIR) == L6474_STATUS_DIR)
Davidroid 5:8065b587ade0 92 { /* Forward direction is set. Action to be customized. */ }
Davidroid 5:8065b587ade0 93 else
Davidroid 5:8065b587ade0 94 { /* Backward direction is set. Action to be customized. */ }
Davidroid 5:8065b587ade0 95
Davidroid 5:8065b587ade0 96 /* Check NOTPERF_CMD flag: if set, the command received by SPI can't be performed. */
Davidroid 5:8065b587ade0 97 /* This often occures when a command is sent to the L6474 while it is in HIZ state. */
Davidroid 5:8065b587ade0 98 if ((status & L6474_STATUS_NOTPERF_CMD) == L6474_STATUS_NOTPERF_CMD)
Davidroid 5:8065b587ade0 99 { /* Command received by SPI can't be performed. Action to be customized. */ }
Davidroid 5:8065b587ade0 100
Davidroid 5:8065b587ade0 101 /* Check WRONG_CMD flag: if set, the command does not exist. */
Davidroid 5:8065b587ade0 102 if ((status & L6474_STATUS_WRONG_CMD) == L6474_STATUS_WRONG_CMD)
Davidroid 5:8065b587ade0 103 { /* The command received by SPI does not exist. Action to be customized. */ }
Davidroid 5:8065b587ade0 104
Davidroid 5:8065b587ade0 105 /* Check UVLO flag: if not set, there is an undervoltage lock-out. */
Davidroid 5:8065b587ade0 106 if ((status & L6474_STATUS_UVLO) == 0)
Davidroid 5:8065b587ade0 107 { /* Undervoltage lock-out. Action to be customized. */ }
Davidroid 5:8065b587ade0 108
Davidroid 5:8065b587ade0 109 /* Check TH_WRN flag: if not set, the thermal warning threshold is reached. */
Davidroid 5:8065b587ade0 110 if ((status & L6474_STATUS_TH_WRN) == 0)
Davidroid 5:8065b587ade0 111 { /* Thermal warning threshold is reached. Action to be customized. */ }
Davidroid 5:8065b587ade0 112
Davidroid 5:8065b587ade0 113 /* Check TH_SHD flag: if not set, the thermal shut down threshold is reached. */
Davidroid 5:8065b587ade0 114 if ((status & L6474_STATUS_TH_SD) == 0)
Davidroid 5:8065b587ade0 115 { /* Thermal shut down threshold is reached. Action to be customized. */ }
Davidroid 5:8065b587ade0 116
Davidroid 5:8065b587ade0 117 /* Check OCD flag: if not set, there is an overcurrent detection. */
Davidroid 5:8065b587ade0 118 if ((status & L6474_STATUS_OCD) == 0)
Davidroid 5:8065b587ade0 119 { /* Overcurrent detection. Action to be customized. */ }
Davidroid 5:8065b587ade0 120
Davidroid 5:8065b587ade0 121 /* Reset ISR flag. */
Davidroid 5:8065b587ade0 122 motor->isrFlag = FALSE;
Davidroid 5:8065b587ade0 123 }
Davidroid 5:8065b587ade0 124
Davidroid 5:8065b587ade0 125 /**
Davidroid 5:8065b587ade0 126 * @brief This is an example of user handler for the errors.
Davidroid 5:8065b587ade0 127 * @param error error-code.
Davidroid 5:8065b587ade0 128 * @retval None
Davidroid 5:8065b587ade0 129 * @note If needed, implement it, and then attach it:
Davidroid 5:8065b587ade0 130 * + motor->AttachErrorHandler(&ErrorHandler);
Davidroid 5:8065b587ade0 131 */
Davidroid 5:8065b587ade0 132 void ErrorHandler(uint16_t error)
Davidroid 5:8065b587ade0 133 {
Davidroid 5:8065b587ade0 134 /* Printing to the console. */
Davidroid 5:8065b587ade0 135 printf("Error: %d.\r\n", error);
Davidroid 5:8065b587ade0 136
Davidroid 5:8065b587ade0 137 /* Aborting the program. */
Davidroid 5:8065b587ade0 138 exit(EXIT_FAILURE);
Davidroid 5:8065b587ade0 139 }
Davidroid 5:8065b587ade0 140
Davidroid 5:8065b587ade0 141
Davidroid 0:e6a49a092e2a 142 /* Main ----------------------------------------------------------------------*/
Davidroid 0:e6a49a092e2a 143
Davidroid 0:e6a49a092e2a 144 int main()
Davidroid 0:e6a49a092e2a 145 {
Davidroid 0:e6a49a092e2a 146 /* Initializing SPI bus. */
Davidroid 0:e6a49a092e2a 147 DevSPI dev_spi(D11, D12, D13);
Davidroid 0:e6a49a092e2a 148
Davidroid 0:e6a49a092e2a 149 /* Initializing Motor Control Component. */
Davidroid 5:8065b587ade0 150 motor = new L6474(D2, D8, D7, D9, D10, dev_spi);
Davidroid 1:fbf28f3367aa 151 if (motor->Init(NULL) != COMPONENT_OK)
Davidroid 0:e6a49a092e2a 152 return false;
Davidroid 0:e6a49a092e2a 153
Davidroid 0:e6a49a092e2a 154 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 155 printf("Motor Control Application Example for 1 Motor\r\n\n");
Davidroid 0:e6a49a092e2a 156
Davidroid 0:e6a49a092e2a 157 /* Main Loop. */
Davidroid 0:e6a49a092e2a 158 while(true)
Davidroid 0:e6a49a092e2a 159 {
Davidroid 3:fffa53c7aed2 160 /*----- Moving. -----*/
Davidroid 0:e6a49a092e2a 161
Davidroid 0:e6a49a092e2a 162 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 163 printf("--> Moving forward %d steps.\r\n", ROUND_ANGLE_STEPS);
Davidroid 0:e6a49a092e2a 164
Davidroid 0:e6a49a092e2a 165 /* Moving N steps in the forward direction. */
Davidroid 3:fffa53c7aed2 166 motor->Move(StepperMotor::FWD, ROUND_ANGLE_STEPS);
Davidroid 3:fffa53c7aed2 167
Davidroid 0:e6a49a092e2a 168 /* Waiting while the motor is active. */
Davidroid 1:fbf28f3367aa 169 motor->WaitWhileActive();
Davidroid 0:e6a49a092e2a 170
Davidroid 0:e6a49a092e2a 171 /* Getting current position. */
Davidroid 1:fbf28f3367aa 172 int position = motor->GetPosition();
Davidroid 0:e6a49a092e2a 173
Davidroid 0:e6a49a092e2a 174 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 175 printf(" Position: %d.\r\n", position);
Davidroid 0:e6a49a092e2a 176
Davidroid 0:e6a49a092e2a 177 /* Waiting 2 seconds. */
Davidroid 0:e6a49a092e2a 178 wait_ms(2000);
Davidroid 0:e6a49a092e2a 179
Davidroid 0:e6a49a092e2a 180
Davidroid 3:fffa53c7aed2 181 /*----- Moving. -----*/
Davidroid 0:e6a49a092e2a 182
Davidroid 0:e6a49a092e2a 183 /* Printing to the console. */
Davidroid 3:fffa53c7aed2 184 printf("--> Moving backward %d steps.\r\n", ROUND_ANGLE_STEPS >> 1);
Davidroid 3:fffa53c7aed2 185
Davidroid 0:e6a49a092e2a 186 /* Moving N steps in the backward direction. */
Davidroid 3:fffa53c7aed2 187 motor->Move(StepperMotor::BWD, ROUND_ANGLE_STEPS >> 1);
Davidroid 0:e6a49a092e2a 188
Davidroid 0:e6a49a092e2a 189 /* Waiting while the motor is active. */
Davidroid 1:fbf28f3367aa 190 motor->WaitWhileActive();
Davidroid 0:e6a49a092e2a 191
Davidroid 0:e6a49a092e2a 192 /* Getting current position. */
Davidroid 1:fbf28f3367aa 193 position = motor->GetPosition();
Davidroid 0:e6a49a092e2a 194
Davidroid 0:e6a49a092e2a 195 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 196 printf(" Position: %d.\r\n", position);
Davidroid 3:fffa53c7aed2 197 printf("--> Setting Home.\r\n");
Davidroid 0:e6a49a092e2a 198
Davidroid 0:e6a49a092e2a 199 /* Setting the current position to be the home position. */
Davidroid 1:fbf28f3367aa 200 motor->SetHome();
Davidroid 0:e6a49a092e2a 201
Davidroid 0:e6a49a092e2a 202 /* Waiting 2 seconds. */
Davidroid 0:e6a49a092e2a 203 wait_ms(2000);
Davidroid 0:e6a49a092e2a 204
Davidroid 0:e6a49a092e2a 205
Davidroid 0:e6a49a092e2a 206 /*----- Going to a specified position. -----*/
Davidroid 0:e6a49a092e2a 207
Davidroid 0:e6a49a092e2a 208 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 209 printf("--> Going to position %d.\r\n", ROUND_ANGLE_STEPS >> 1);
Davidroid 0:e6a49a092e2a 210
Davidroid 0:e6a49a092e2a 211 /* Requesting to go to a specified position. */
Davidroid 1:fbf28f3367aa 212 motor->GoTo(ROUND_ANGLE_STEPS >> 1);
Davidroid 0:e6a49a092e2a 213
Davidroid 0:e6a49a092e2a 214 /* Waiting while the motor is active. */
Davidroid 1:fbf28f3367aa 215 motor->WaitWhileActive();
Davidroid 0:e6a49a092e2a 216
Davidroid 0:e6a49a092e2a 217 /* Getting current position. */
Davidroid 1:fbf28f3367aa 218 position = motor->GetPosition();
Davidroid 0:e6a49a092e2a 219
Davidroid 0:e6a49a092e2a 220 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 221 printf(" Position: %d.\r\n", position);
Davidroid 0:e6a49a092e2a 222
Davidroid 0:e6a49a092e2a 223 /* Waiting 2 seconds. */
Davidroid 0:e6a49a092e2a 224 wait_ms(2000);
Davidroid 0:e6a49a092e2a 225
Davidroid 0:e6a49a092e2a 226
Davidroid 0:e6a49a092e2a 227 /*----- Going Home. -----*/
Davidroid 0:e6a49a092e2a 228
Davidroid 0:e6a49a092e2a 229 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 230 printf("--> Going Home.\r\n");
Davidroid 0:e6a49a092e2a 231
Davidroid 0:e6a49a092e2a 232 /* Requesting to go to home. */
Davidroid 1:fbf28f3367aa 233 motor->GoHome();
Davidroid 0:e6a49a092e2a 234
Davidroid 0:e6a49a092e2a 235 /* Waiting while the motor is active. */
Davidroid 1:fbf28f3367aa 236 motor->WaitWhileActive();
Davidroid 0:e6a49a092e2a 237
Davidroid 0:e6a49a092e2a 238 /* Getting current position. */
Davidroid 1:fbf28f3367aa 239 position = motor->GetPosition();
Davidroid 0:e6a49a092e2a 240
Davidroid 0:e6a49a092e2a 241 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 242 printf(" Position: %d.\r\n", position);
Davidroid 0:e6a49a092e2a 243
Davidroid 0:e6a49a092e2a 244 /* Waiting 2 seconds. */
Davidroid 0:e6a49a092e2a 245 wait_ms(2000);
Davidroid 0:e6a49a092e2a 246
Davidroid 0:e6a49a092e2a 247
Davidroid 3:fffa53c7aed2 248 /*----- Running. -----*/
Davidroid 0:e6a49a092e2a 249
Davidroid 0:e6a49a092e2a 250 /* Printing to the console. */
Davidroid 3:fffa53c7aed2 251 printf("--> Running backward.\r\n");
Davidroid 0:e6a49a092e2a 252
Davidroid 0:e6a49a092e2a 253 /* Requesting to run backward. */
Davidroid 3:fffa53c7aed2 254 motor->Run(StepperMotor::BWD);
Davidroid 0:e6a49a092e2a 255
Davidroid 0:e6a49a092e2a 256 /* Waiting until delay has expired. */
Davidroid 1:fbf28f3367aa 257 wait_ms(6000);
Davidroid 0:e6a49a092e2a 258
Davidroid 0:e6a49a092e2a 259 /* Getting current speed. */
Davidroid 2:e12e4df7a486 260 int speed = motor->GetSpeed();
Davidroid 0:e6a49a092e2a 261
Davidroid 0:e6a49a092e2a 262 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 263 printf(" Speed: %d.\r\n", speed);
Davidroid 0:e6a49a092e2a 264
Davidroid 0:e6a49a092e2a 265 /*----- Increasing the speed while running. -----*/
Davidroid 0:e6a49a092e2a 266
Davidroid 0:e6a49a092e2a 267 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 268 printf("--> Increasing the speed while running.\r\n");
Davidroid 0:e6a49a092e2a 269
Davidroid 0:e6a49a092e2a 270 /* Increasing speed to 2400 step/s. */
Davidroid 1:fbf28f3367aa 271 motor->SetMaxSpeed(2400);
Davidroid 0:e6a49a092e2a 272
Davidroid 0:e6a49a092e2a 273 /* Waiting until delay has expired. */
Davidroid 1:fbf28f3367aa 274 wait_ms(6000);
Davidroid 0:e6a49a092e2a 275
Davidroid 0:e6a49a092e2a 276 /* Getting current speed. */
Davidroid 2:e12e4df7a486 277 speed = motor->GetSpeed();
Davidroid 0:e6a49a092e2a 278
Davidroid 0:e6a49a092e2a 279 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 280 printf(" Speed: %d.\r\n", speed);
Davidroid 0:e6a49a092e2a 281
Davidroid 0:e6a49a092e2a 282
Davidroid 0:e6a49a092e2a 283 /*----- Decreasing the speed while running. -----*/
Davidroid 0:e6a49a092e2a 284
Davidroid 0:e6a49a092e2a 285 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 286 printf("--> Decreasing the speed while running.\r\n");
Davidroid 0:e6a49a092e2a 287
Davidroid 0:e6a49a092e2a 288 /* Decreasing speed to 1200 step/s. */
Davidroid 1:fbf28f3367aa 289 motor->SetMaxSpeed(1200);
Davidroid 0:e6a49a092e2a 290
Davidroid 0:e6a49a092e2a 291 /* Waiting until delay has expired. */
Davidroid 1:fbf28f3367aa 292 wait_ms(8000);
Davidroid 0:e6a49a092e2a 293
Davidroid 0:e6a49a092e2a 294 /* Getting current speed. */
Davidroid 2:e12e4df7a486 295 speed = motor->GetSpeed();
Davidroid 0:e6a49a092e2a 296
Davidroid 0:e6a49a092e2a 297 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 298 printf(" Speed: %d.\r\n", speed);
Davidroid 0:e6a49a092e2a 299
Davidroid 0:e6a49a092e2a 300
Davidroid 0:e6a49a092e2a 301 /*----- Requiring hard-stop while running. -----*/
Davidroid 0:e6a49a092e2a 302
Davidroid 0:e6a49a092e2a 303 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 304 printf("--> Requiring hard-stop while running.\r\n");
Davidroid 0:e6a49a092e2a 305
Davidroid 0:e6a49a092e2a 306 /* Requesting to immediatly stop. */
Davidroid 1:fbf28f3367aa 307 motor->HardStop();
Davidroid 0:e6a49a092e2a 308
Davidroid 0:e6a49a092e2a 309 /* Waiting while the motor is active. */
Davidroid 1:fbf28f3367aa 310 motor->WaitWhileActive();
Davidroid 0:e6a49a092e2a 311
Davidroid 0:e6a49a092e2a 312 /* Waiting 2 seconds. */
Davidroid 0:e6a49a092e2a 313 wait_ms(2000);
Davidroid 0:e6a49a092e2a 314
Davidroid 0:e6a49a092e2a 315
Davidroid 0:e6a49a092e2a 316 /*----- Infinite Loop. -----*/
Davidroid 0:e6a49a092e2a 317
Davidroid 0:e6a49a092e2a 318 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 319 printf("--> Infinite Loop...\r\n");
Davidroid 0:e6a49a092e2a 320
Davidroid 0:e6a49a092e2a 321 /* Setting the current position to be the home position. */
Davidroid 1:fbf28f3367aa 322 motor->SetHome();
Davidroid 0:e6a49a092e2a 323
Davidroid 0:e6a49a092e2a 324 /* Infinite Loop. */
Davidroid 0:e6a49a092e2a 325 while(1)
Davidroid 0:e6a49a092e2a 326 {
Davidroid 0:e6a49a092e2a 327 /* Requesting to go to a specified position. */
Davidroid 3:fffa53c7aed2 328 motor->GoTo(ROUND_ANGLE_STEPS >> 1);
Davidroid 0:e6a49a092e2a 329
Davidroid 0:e6a49a092e2a 330 /* Waiting while the motor is active. */
Davidroid 1:fbf28f3367aa 331 motor->WaitWhileActive();
Davidroid 0:e6a49a092e2a 332
Davidroid 0:e6a49a092e2a 333 /* Requesting to go to a specified position. */
Davidroid 3:fffa53c7aed2 334 motor->GoTo(- (ROUND_ANGLE_STEPS >> 1));
Davidroid 0:e6a49a092e2a 335
Davidroid 0:e6a49a092e2a 336 /* Waiting while the motor is active. */
Davidroid 1:fbf28f3367aa 337 motor->WaitWhileActive();
Davidroid 0:e6a49a092e2a 338 }
Davidroid 0:e6a49a092e2a 339 }
Davidroid 0:e6a49a092e2a 340 }