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

Dependencies:   X_NUCLEO_IHM01A1

Fork of HelloWorld_IHM01A1_2Motors by ST

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 two stepper motors connected to two stacked boards in daisy chain configuration, moving the rotors to specific positions, with given speed values, directions of rotation, etc.

Committer:
Davidroid
Date:
Wed Oct 14 15:21:49 2015 +0000
Revision:
0:e6a49a092e2a
Child:
1:fbf28f3367aa
mbed test application for the STMicrolectronics X-NUCLEO-IHM01A1; Motor Control Expansion Board: control of 1 motor.

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 0:e6a49a092e2a 57 #define ROUND_ANGLE_STEPS 1600
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 0:e6a49a092e2a 63 L6474 *l6474;
Davidroid 0:e6a49a092e2a 64
Davidroid 0:e6a49a092e2a 65 /* Flag to identify whenever a PWM pulse has finished. */
Davidroid 0:e6a49a092e2a 66 volatile int pwm_pulse_finished_flag;
Davidroid 0:e6a49a092e2a 67
Davidroid 0:e6a49a092e2a 68 /* Flag to identify whenever the desired delay has expired. */
Davidroid 0:e6a49a092e2a 69 volatile int delay_expired_flag;
Davidroid 0:e6a49a092e2a 70
Davidroid 0:e6a49a092e2a 71
Davidroid 0:e6a49a092e2a 72 /* Functions -----------------------------------------------------------------*/
Davidroid 0:e6a49a092e2a 73
Davidroid 0:e6a49a092e2a 74 /*
Davidroid 0:e6a49a092e2a 75 * @brief PWM callback.
Davidroid 0:e6a49a092e2a 76 * @param None
Davidroid 0:e6a49a092e2a 77 * @retval None
Davidroid 0:e6a49a092e2a 78 */
Davidroid 0:e6a49a092e2a 79 void PWMCallback(void)
Davidroid 0:e6a49a092e2a 80 {
Davidroid 0:e6a49a092e2a 81 pwm_pulse_finished_flag = 1;
Davidroid 0:e6a49a092e2a 82 }
Davidroid 0:e6a49a092e2a 83
Davidroid 0:e6a49a092e2a 84 /*
Davidroid 0:e6a49a092e2a 85 * @brief Delay callback.
Davidroid 0:e6a49a092e2a 86 * @param None
Davidroid 0:e6a49a092e2a 87 * @retval None
Davidroid 0:e6a49a092e2a 88 */
Davidroid 0:e6a49a092e2a 89 void DelayCallback()
Davidroid 0:e6a49a092e2a 90 {
Davidroid 0:e6a49a092e2a 91 delay_expired_flag = 1;
Davidroid 0:e6a49a092e2a 92 }
Davidroid 0:e6a49a092e2a 93
Davidroid 0:e6a49a092e2a 94 /*
Davidroid 0:e6a49a092e2a 95 * @brief Waiting until PWM pulse has finished.
Davidroid 0:e6a49a092e2a 96 * @param None
Davidroid 0:e6a49a092e2a 97 * @retval None
Davidroid 0:e6a49a092e2a 98 */
Davidroid 0:e6a49a092e2a 99 void WaitForPWMPulse(void)
Davidroid 0:e6a49a092e2a 100 {
Davidroid 0:e6a49a092e2a 101 /* Waiting until PWM flag is set. */
Davidroid 0:e6a49a092e2a 102 while (pwm_pulse_finished_flag == 0);
Davidroid 0:e6a49a092e2a 103
Davidroid 0:e6a49a092e2a 104 /* Resetting PWM flag. */
Davidroid 0:e6a49a092e2a 105 pwm_pulse_finished_flag = 0;
Davidroid 0:e6a49a092e2a 106
Davidroid 0:e6a49a092e2a 107 /* Setting the device state machine. */
Davidroid 0:e6a49a092e2a 108 if (l6474->GetDeviceState() != INACTIVE)
Davidroid 0:e6a49a092e2a 109 l6474->StepClockHandler();
Davidroid 0:e6a49a092e2a 110 }
Davidroid 0:e6a49a092e2a 111
Davidroid 0:e6a49a092e2a 112 /*
Davidroid 0:e6a49a092e2a 113 * @brief Waiting while the motor is active.
Davidroid 0:e6a49a092e2a 114 * @param None
Davidroid 0:e6a49a092e2a 115 * @retval None
Davidroid 0:e6a49a092e2a 116 */
Davidroid 0:e6a49a092e2a 117 void WaitWhileActive(void)
Davidroid 0:e6a49a092e2a 118 {
Davidroid 0:e6a49a092e2a 119 while (l6474->GetDeviceState() != INACTIVE)
Davidroid 0:e6a49a092e2a 120 WaitForPWMPulse();
Davidroid 0:e6a49a092e2a 121 }
Davidroid 0:e6a49a092e2a 122
Davidroid 0:e6a49a092e2a 123 /*
Davidroid 0:e6a49a092e2a 124 * @brief Waiting until delay has expired.
Davidroid 0:e6a49a092e2a 125 * @param delay delay in milliseconds.
Davidroid 0:e6a49a092e2a 126 * @retval None
Davidroid 0:e6a49a092e2a 127 */
Davidroid 0:e6a49a092e2a 128 void WaitForDelay(int delay)
Davidroid 0:e6a49a092e2a 129 {
Davidroid 0:e6a49a092e2a 130 Timeout timeout;
Davidroid 0:e6a49a092e2a 131 timeout.attach(&DelayCallback, delay / 1E3);
Davidroid 0:e6a49a092e2a 132
Davidroid 0:e6a49a092e2a 133 delay_expired_flag = 0;
Davidroid 0:e6a49a092e2a 134 while (delay_expired_flag == 0)
Davidroid 0:e6a49a092e2a 135 WaitForPWMPulse();
Davidroid 0:e6a49a092e2a 136 }
Davidroid 0:e6a49a092e2a 137
Davidroid 0:e6a49a092e2a 138
Davidroid 0:e6a49a092e2a 139 /* Main ----------------------------------------------------------------------*/
Davidroid 0:e6a49a092e2a 140
Davidroid 0:e6a49a092e2a 141 int main()
Davidroid 0:e6a49a092e2a 142 {
Davidroid 0:e6a49a092e2a 143 /* Initializing SPI bus. */
Davidroid 0:e6a49a092e2a 144 DevSPI dev_spi(D11, D12, D13);
Davidroid 0:e6a49a092e2a 145
Davidroid 0:e6a49a092e2a 146 /* Resetting Timer PWM flag. */
Davidroid 0:e6a49a092e2a 147 pwm_pulse_finished_flag = 0;
Davidroid 0:e6a49a092e2a 148
Davidroid 0:e6a49a092e2a 149 /* Initializing Motor Control Component. */
Davidroid 0:e6a49a092e2a 150 l6474 = new L6474(D8, D7, D9, D10, dev_spi);
Davidroid 0:e6a49a092e2a 151 if (l6474->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 0:e6a49a092e2a 160 /*----- Moving forward of N steps. -----*/
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 0:e6a49a092e2a 166 l6474->Move(FORWARD, ROUND_ANGLE_STEPS);
Davidroid 0:e6a49a092e2a 167
Davidroid 0:e6a49a092e2a 168 /* Waiting while the motor is active. */
Davidroid 0:e6a49a092e2a 169 WaitWhileActive();
Davidroid 0:e6a49a092e2a 170
Davidroid 0:e6a49a092e2a 171 /* Getting current position. */
Davidroid 0:e6a49a092e2a 172 int position = l6474->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 0:e6a49a092e2a 181 /*----- Moving backward N steps. -----*/
Davidroid 0:e6a49a092e2a 182
Davidroid 0:e6a49a092e2a 183 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 184 printf("--> Moving backward %d steps.\r\n", ROUND_ANGLE_STEPS);
Davidroid 0:e6a49a092e2a 185
Davidroid 0:e6a49a092e2a 186 /* Moving N steps in the backward direction. */
Davidroid 0:e6a49a092e2a 187 l6474->Move(BACKWARD, ROUND_ANGLE_STEPS);
Davidroid 0:e6a49a092e2a 188
Davidroid 0:e6a49a092e2a 189 /* Waiting while the motor is active. */
Davidroid 0:e6a49a092e2a 190 WaitWhileActive();
Davidroid 0:e6a49a092e2a 191
Davidroid 0:e6a49a092e2a 192 /* Getting current position. */
Davidroid 0:e6a49a092e2a 193 position = l6474->GetPosition();
Davidroid 0:e6a49a092e2a 194
Davidroid 0:e6a49a092e2a 195 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 196 printf(" Position: %d.\r\n", position);
Davidroid 0:e6a49a092e2a 197
Davidroid 0:e6a49a092e2a 198 /* Setting the current position to be the home position. */
Davidroid 0:e6a49a092e2a 199 l6474->SetHome();
Davidroid 0:e6a49a092e2a 200
Davidroid 0:e6a49a092e2a 201 /* Waiting 2 seconds. */
Davidroid 0:e6a49a092e2a 202 wait_ms(2000);
Davidroid 0:e6a49a092e2a 203
Davidroid 0:e6a49a092e2a 204
Davidroid 0:e6a49a092e2a 205 /*----- Going to a specified position. -----*/
Davidroid 0:e6a49a092e2a 206
Davidroid 0:e6a49a092e2a 207 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 208 printf("--> Going to position %d.\r\n", ROUND_ANGLE_STEPS >> 1);
Davidroid 0:e6a49a092e2a 209
Davidroid 0:e6a49a092e2a 210 /* Requesting to go to a specified position. */
Davidroid 0:e6a49a092e2a 211 l6474->GoTo(ROUND_ANGLE_STEPS >> 1);
Davidroid 0:e6a49a092e2a 212
Davidroid 0:e6a49a092e2a 213 /* Waiting while the motor is active. */
Davidroid 0:e6a49a092e2a 214 WaitWhileActive();
Davidroid 0:e6a49a092e2a 215
Davidroid 0:e6a49a092e2a 216 /* Getting current position. */
Davidroid 0:e6a49a092e2a 217 position = l6474->GetPosition();
Davidroid 0:e6a49a092e2a 218
Davidroid 0:e6a49a092e2a 219 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 220 printf(" Position: %d.\r\n", position);
Davidroid 0:e6a49a092e2a 221
Davidroid 0:e6a49a092e2a 222 /* Waiting 2 seconds. */
Davidroid 0:e6a49a092e2a 223 wait_ms(2000);
Davidroid 0:e6a49a092e2a 224
Davidroid 0:e6a49a092e2a 225
Davidroid 0:e6a49a092e2a 226 /*----- Going Home. -----*/
Davidroid 0:e6a49a092e2a 227
Davidroid 0:e6a49a092e2a 228 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 229 printf("--> Going Home.\r\n");
Davidroid 0:e6a49a092e2a 230
Davidroid 0:e6a49a092e2a 231 /* Requesting to go to home. */
Davidroid 0:e6a49a092e2a 232 l6474->GoHome();
Davidroid 0:e6a49a092e2a 233
Davidroid 0:e6a49a092e2a 234 /* Waiting while the motor is active. */
Davidroid 0:e6a49a092e2a 235 WaitWhileActive();
Davidroid 0:e6a49a092e2a 236
Davidroid 0:e6a49a092e2a 237 /* Getting current position. */
Davidroid 0:e6a49a092e2a 238 position = l6474->GetPosition();
Davidroid 0:e6a49a092e2a 239
Davidroid 0:e6a49a092e2a 240 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 241 printf(" Position: %d.\r\n", position);
Davidroid 0:e6a49a092e2a 242
Davidroid 0:e6a49a092e2a 243 /* Waiting 2 seconds. */
Davidroid 0:e6a49a092e2a 244 wait_ms(2000);
Davidroid 0:e6a49a092e2a 245
Davidroid 0:e6a49a092e2a 246
Davidroid 0:e6a49a092e2a 247 /*----- Moving backward. -----*/
Davidroid 0:e6a49a092e2a 248
Davidroid 0:e6a49a092e2a 249 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 250 printf("--> Moving backward.\r\n");
Davidroid 0:e6a49a092e2a 251
Davidroid 0:e6a49a092e2a 252 /* Requesting to run backward. */
Davidroid 0:e6a49a092e2a 253 l6474->Run(BACKWARD);
Davidroid 0:e6a49a092e2a 254
Davidroid 0:e6a49a092e2a 255 /* Waiting until delay has expired. */
Davidroid 0:e6a49a092e2a 256 WaitForDelay(6000);
Davidroid 0:e6a49a092e2a 257
Davidroid 0:e6a49a092e2a 258 /* Getting current speed. */
Davidroid 0:e6a49a092e2a 259 int speed = l6474->GetCurrentSpeed();
Davidroid 0:e6a49a092e2a 260
Davidroid 0:e6a49a092e2a 261 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 262 printf(" Speed: %d.\r\n", speed);
Davidroid 0:e6a49a092e2a 263
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 0:e6a49a092e2a 271 l6474->SetMaxSpeed(2400);
Davidroid 0:e6a49a092e2a 272
Davidroid 0:e6a49a092e2a 273 /* Waiting until delay has expired. */
Davidroid 0:e6a49a092e2a 274 WaitForDelay(6000);
Davidroid 0:e6a49a092e2a 275
Davidroid 0:e6a49a092e2a 276 /* Getting current speed. */
Davidroid 0:e6a49a092e2a 277 speed = l6474->GetCurrentSpeed();
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 0:e6a49a092e2a 289 l6474->SetMaxSpeed(1200);
Davidroid 0:e6a49a092e2a 290
Davidroid 0:e6a49a092e2a 291 /* Waiting until delay has expired. */
Davidroid 0:e6a49a092e2a 292 WaitForDelay(8000);
Davidroid 0:e6a49a092e2a 293
Davidroid 0:e6a49a092e2a 294 /* Getting current speed. */
Davidroid 0:e6a49a092e2a 295 speed = l6474->GetCurrentSpeed();
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 /*----- Moving forward. -----*/
Davidroid 0:e6a49a092e2a 302
Davidroid 0:e6a49a092e2a 303 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 304 printf("--> Moving forward.\r\n");
Davidroid 0:e6a49a092e2a 305
Davidroid 0:e6a49a092e2a 306 /* Requesting to run in forward direction. */
Davidroid 0:e6a49a092e2a 307 l6474->Run(FORWARD);
Davidroid 0:e6a49a092e2a 308
Davidroid 0:e6a49a092e2a 309 /* Waiting until delay has expired. */
Davidroid 0:e6a49a092e2a 310 WaitForDelay(4000);
Davidroid 0:e6a49a092e2a 311
Davidroid 0:e6a49a092e2a 312
Davidroid 0:e6a49a092e2a 313 /*----- Requiring hard-stop while running. -----*/
Davidroid 0:e6a49a092e2a 314
Davidroid 0:e6a49a092e2a 315 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 316 printf("--> Requiring hard-stop while running.\r\n");
Davidroid 0:e6a49a092e2a 317
Davidroid 0:e6a49a092e2a 318 /* Requesting to immediatly stop. */
Davidroid 0:e6a49a092e2a 319 l6474->HardStop();
Davidroid 0:e6a49a092e2a 320
Davidroid 0:e6a49a092e2a 321 /* Waiting while the motor is active. */
Davidroid 0:e6a49a092e2a 322 WaitWhileActive();
Davidroid 0:e6a49a092e2a 323
Davidroid 0:e6a49a092e2a 324 /* Waiting 2 seconds. */
Davidroid 0:e6a49a092e2a 325 wait_ms(2000);
Davidroid 0:e6a49a092e2a 326
Davidroid 0:e6a49a092e2a 327
Davidroid 0:e6a49a092e2a 328 /*----- Infinite Loop. -----*/
Davidroid 0:e6a49a092e2a 329
Davidroid 0:e6a49a092e2a 330 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 331 printf("--> Infinite Loop...\r\n");
Davidroid 0:e6a49a092e2a 332
Davidroid 0:e6a49a092e2a 333 /* Setting the current position to be the home position. */
Davidroid 0:e6a49a092e2a 334 l6474->SetHome();
Davidroid 0:e6a49a092e2a 335
Davidroid 0:e6a49a092e2a 336 /* Infinite Loop. */
Davidroid 0:e6a49a092e2a 337 while(1)
Davidroid 0:e6a49a092e2a 338 {
Davidroid 0:e6a49a092e2a 339 /* Requesting to go to a specified position. */
Davidroid 0:e6a49a092e2a 340 l6474->GoTo(- ROUND_ANGLE_STEPS >> 2);
Davidroid 0:e6a49a092e2a 341
Davidroid 0:e6a49a092e2a 342 /* Waiting while the motor is active. */
Davidroid 0:e6a49a092e2a 343 WaitWhileActive();
Davidroid 0:e6a49a092e2a 344
Davidroid 0:e6a49a092e2a 345 /* Requesting to go to a specified position. */
Davidroid 0:e6a49a092e2a 346 l6474->GoTo(ROUND_ANGLE_STEPS >> 2);
Davidroid 0:e6a49a092e2a 347
Davidroid 0:e6a49a092e2a 348 /* Waiting while the motor is active. */
Davidroid 0:e6a49a092e2a 349 WaitWhileActive();
Davidroid 0:e6a49a092e2a 350 }
Davidroid 0:e6a49a092e2a 351 }
Davidroid 0:e6a49a092e2a 352 }