APS2 MEA Rodrigo Vianna

Dependencies:   mbed X_NUCLEO_IHM01A1

Committer:
Davidroid
Date:
Fri Jan 15 16:43:39 2016 +0000
Revision:
21:0189493b15ec
Parent:
19:1cd7f65c155c
Child:
23:54503e363f67
+ Updated with the new version of the library.

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 21:0189493b15ec 4 * @author Davide Aliprandi, STMicroelectronics
Davidroid 0:e6a49a092e2a 5 * @version V1.0.0
Davidroid 0:e6a49a092e2a 6 * @date October 14th, 2015
Davidroid 21:0189493b15ec 7 * @brief mbed test application for the STMicroelectronics X-NUCLEO-IHM01A1
Davidroid 0:e6a49a092e2a 8 * Motor Control Expansion Board: control of 1 motor.
Davidroid 0:e6a49a092e2a 9 ******************************************************************************
Davidroid 0:e6a49a092e2a 10 * @attention
Davidroid 0:e6a49a092e2a 11 *
Davidroid 0:e6a49a092e2a 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Davidroid 0:e6a49a092e2a 13 *
Davidroid 0:e6a49a092e2a 14 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 0:e6a49a092e2a 15 * are permitted provided that the following conditions are met:
Davidroid 0:e6a49a092e2a 16 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 0:e6a49a092e2a 17 * this list of conditions and the following disclaimer.
Davidroid 0:e6a49a092e2a 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 0:e6a49a092e2a 19 * this list of conditions and the following disclaimer in the documentation
Davidroid 0:e6a49a092e2a 20 * and/or other materials provided with the distribution.
Davidroid 0:e6a49a092e2a 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 0:e6a49a092e2a 22 * may be used to endorse or promote products derived from this software
Davidroid 0:e6a49a092e2a 23 * without specific prior written permission.
Davidroid 0:e6a49a092e2a 24 *
Davidroid 0:e6a49a092e2a 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 0:e6a49a092e2a 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 0:e6a49a092e2a 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 0:e6a49a092e2a 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 0:e6a49a092e2a 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 0:e6a49a092e2a 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 0:e6a49a092e2a 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 0:e6a49a092e2a 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 0:e6a49a092e2a 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 0:e6a49a092e2a 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 0:e6a49a092e2a 35 *
Davidroid 0:e6a49a092e2a 36 ******************************************************************************
Davidroid 0:e6a49a092e2a 37 */
Davidroid 0:e6a49a092e2a 38
Davidroid 0:e6a49a092e2a 39
Davidroid 0:e6a49a092e2a 40 /* Includes ------------------------------------------------------------------*/
Davidroid 0:e6a49a092e2a 41
Davidroid 0:e6a49a092e2a 42 /* mbed specific header files. */
Davidroid 0:e6a49a092e2a 43 #include "mbed.h"
Davidroid 0:e6a49a092e2a 44
Davidroid 0:e6a49a092e2a 45 /* Helper header files. */
Davidroid 0:e6a49a092e2a 46 #include "DevSPI.h"
Davidroid 0:e6a49a092e2a 47
Davidroid 0:e6a49a092e2a 48 /* Component specific header files. */
Davidroid 0:e6a49a092e2a 49 #include "l6474_class.h"
Davidroid 0:e6a49a092e2a 50
Davidroid 0:e6a49a092e2a 51
Davidroid 0:e6a49a092e2a 52 /* Definitions ---------------------------------------------------------------*/
Davidroid 0:e6a49a092e2a 53
Davidroid 10:8f031470ca9f 54 /* Number of steps to move. */
Davidroid 10:8f031470ca9f 55 #define STEPS 3200
Davidroid 0:e6a49a092e2a 56
Davidroid 0:e6a49a092e2a 57
Davidroid 0:e6a49a092e2a 58 /* Variables -----------------------------------------------------------------*/
Davidroid 0:e6a49a092e2a 59
Davidroid 19:1cd7f65c155c 60 /* Initialization parameters. */
Davidroid 19:1cd7f65c155c 61 L6474_InitTypeDef init =
Davidroid 19:1cd7f65c155c 62 {
Davidroid 19:1cd7f65c155c 63 160, /* Acceleration rate in step/s2. Range: (0..+inf). */
Davidroid 19:1cd7f65c155c 64 160, /* Deceleration rate in step/s2. Range: (0..+inf). */
Davidroid 19:1cd7f65c155c 65 1600, /* Maximum speed in step/s. Range: (30..10000]. */
Davidroid 19:1cd7f65c155c 66 800, /* Minimum speed in step/s. Range: [30..10000). */
Davidroid 19:1cd7f65c155c 67 250, /* Torque regulation current in mA. Range: 31.25mA to 4000mA. */
Davidroid 19:1cd7f65c155c 68 L6474_OCD_TH_750mA, /* Overcurrent threshold (OCD_TH register). */
Davidroid 19:1cd7f65c155c 69 L6474_CONFIG_OC_SD_ENABLE, /* Overcurrent shutwdown (OC_SD field of CONFIG register). */
Davidroid 19:1cd7f65c155c 70 L6474_CONFIG_EN_TQREG_TVAL_USED, /* Torque regulation method (EN_TQREG field of CONFIG register). */
Davidroid 19:1cd7f65c155c 71 L6474_STEP_SEL_1_4, /* Step selection (STEP_SEL field of STEP_MODE register). */
Davidroid 19:1cd7f65c155c 72 L6474_SYNC_SEL_1_2, /* Sync selection (SYNC_SEL field of STEP_MODE register). */
Davidroid 19:1cd7f65c155c 73 L6474_FAST_STEP_12us, /* Fall time value (T_FAST field of T_FAST register). Range: 2us to 32us. */
Davidroid 19:1cd7f65c155c 74 L6474_TOFF_FAST_8us, /* Maximum fast decay time (T_OFF field of T_FAST register). Range: 2us to 32us. */
Davidroid 19:1cd7f65c155c 75 3, /* Minimum ON time in us (TON_MIN register). Range: 0.5us to 64us. */
Davidroid 19:1cd7f65c155c 76 21, /* Minimum OFF time in us (TOFF_MIN register). Range: 0.5us to 64us. */
Davidroid 19:1cd7f65c155c 77 L6474_CONFIG_TOFF_044us, /* Target Swicthing Period (field TOFF of CONFIG register). */
Davidroid 19:1cd7f65c155c 78 L6474_CONFIG_SR_320V_us, /* Slew rate (POW_SR field of CONFIG register). */
Davidroid 19:1cd7f65c155c 79 L6474_CONFIG_INT_16MHZ, /* Clock setting (OSC_CLK_SEL field of CONFIG register). */
Davidroid 19:1cd7f65c155c 80 L6474_ALARM_EN_OVERCURRENT |
Davidroid 19:1cd7f65c155c 81 L6474_ALARM_EN_THERMAL_SHUTDOWN |
Davidroid 19:1cd7f65c155c 82 L6474_ALARM_EN_THERMAL_WARNING |
Davidroid 19:1cd7f65c155c 83 L6474_ALARM_EN_UNDERVOLTAGE |
Davidroid 19:1cd7f65c155c 84 L6474_ALARM_EN_SW_TURN_ON |
Davidroid 19:1cd7f65c155c 85 L6474_ALARM_EN_WRONG_NPERF_CMD /* Alarm (ALARM_EN register). */
Davidroid 19:1cd7f65c155c 86 };
Davidroid 19:1cd7f65c155c 87
Davidroid 0:e6a49a092e2a 88 /* Motor Control Component. */
Davidroid 1:fbf28f3367aa 89 L6474 *motor;
Davidroid 0:e6a49a092e2a 90
Davidroid 0:e6a49a092e2a 91
Davidroid 19:1cd7f65c155c 92 /* Functions -----------------------------------------------------------------*/
Davidroid 19:1cd7f65c155c 93
Davidroid 19:1cd7f65c155c 94 /**
Davidroid 19:1cd7f65c155c 95 * @brief This is an example of user handler for the flag interrupt.
Davidroid 19:1cd7f65c155c 96 * @param None
Davidroid 19:1cd7f65c155c 97 * @retval None
Davidroid 19:1cd7f65c155c 98 * @note If needed, implement it, and then attach and enable it:
Davidroid 19:1cd7f65c155c 99 * + motor->AttachFlagIRQ(&FlagIRQHandler);
Davidroid 19:1cd7f65c155c 100 * + motor->EnableFlagIRQ();
Davidroid 19:1cd7f65c155c 101 * To disable it:
Davidroid 19:1cd7f65c155c 102 * + motor->DisbleFlagIRQ();
Davidroid 19:1cd7f65c155c 103 */
Davidroid 19:1cd7f65c155c 104 void FlagIRQHandler(void)
Davidroid 19:1cd7f65c155c 105 {
Davidroid 19:1cd7f65c155c 106 /* Set ISR flag. */
Davidroid 19:1cd7f65c155c 107 motor->isr_flag = TRUE;
Davidroid 19:1cd7f65c155c 108
Davidroid 19:1cd7f65c155c 109 /* Get the value of the status register. */
Davidroid 19:1cd7f65c155c 110 unsigned int status = motor->GetStatus();
Davidroid 19:1cd7f65c155c 111
Davidroid 19:1cd7f65c155c 112 /* Check NOTPERF_CMD flag: if set, the command received by SPI can't be performed. */
Davidroid 19:1cd7f65c155c 113 /* This often occures when a command is sent to the L6474 while it is not in HiZ state. */
Davidroid 19:1cd7f65c155c 114 if ((status & L6474_STATUS_NOTPERF_CMD) == L6474_STATUS_NOTPERF_CMD)
Davidroid 19:1cd7f65c155c 115 printf(" WARNING: \"FLAG\" interrupt triggered. Non-performable command detected when updating L6474's registers while not in HiZ state.\r\n");
Davidroid 19:1cd7f65c155c 116
Davidroid 19:1cd7f65c155c 117 /* Reset ISR flag. */
Davidroid 19:1cd7f65c155c 118 motor->isr_flag = FALSE;
Davidroid 19:1cd7f65c155c 119 }
Davidroid 19:1cd7f65c155c 120
Davidroid 19:1cd7f65c155c 121
Davidroid 0:e6a49a092e2a 122 /* Main ----------------------------------------------------------------------*/
Davidroid 0:e6a49a092e2a 123
Davidroid 0:e6a49a092e2a 124 int main()
Davidroid 0:e6a49a092e2a 125 {
Davidroid 6:32166bfc04b0 126 /*----- Initialization. -----*/
Davidroid 6:32166bfc04b0 127
Davidroid 0:e6a49a092e2a 128 /* Initializing SPI bus. */
Davidroid 0:e6a49a092e2a 129 DevSPI dev_spi(D11, D12, D13);
Davidroid 0:e6a49a092e2a 130
Davidroid 11:3e303a25770d 131 /* Initializing Motor Control Component. */
Davidroid 5:8065b587ade0 132 motor = new L6474(D2, D8, D7, D9, D10, dev_spi);
Davidroid 19:1cd7f65c155c 133 if (motor->Init(&init) != COMPONENT_OK)
Davidroid 17:4830b25fec7f 134 exit(EXIT_FAILURE);
Davidroid 0:e6a49a092e2a 135
Davidroid 19:1cd7f65c155c 136 /* Attaching and enabling interrupt handlers. */
Davidroid 19:1cd7f65c155c 137 motor->AttachFlagIRQ(&FlagIRQHandler);
Davidroid 19:1cd7f65c155c 138 motor->EnableFlagIRQ();
Davidroid 19:1cd7f65c155c 139
Davidroid 0:e6a49a092e2a 140 /* Printing to the console. */
Davidroid 0:e6a49a092e2a 141 printf("Motor Control Application Example for 1 Motor\r\n\n");
Davidroid 0:e6a49a092e2a 142
Davidroid 6:32166bfc04b0 143
Davidroid 6:32166bfc04b0 144 /*----- Moving. -----*/
Davidroid 6:32166bfc04b0 145
Davidroid 6:32166bfc04b0 146 /* Printing to the console. */
Davidroid 10:8f031470ca9f 147 printf("--> Moving forward %d steps.\r\n", STEPS);
Davidroid 6:32166bfc04b0 148
Davidroid 6:32166bfc04b0 149 /* Moving N steps in the forward direction. */
Davidroid 10:8f031470ca9f 150 motor->Move(StepperMotor::FWD, STEPS);
Davidroid 6:32166bfc04b0 151
Davidroid 6:32166bfc04b0 152 /* Waiting while the motor is active. */
Davidroid 6:32166bfc04b0 153 motor->WaitWhileActive();
Davidroid 6:32166bfc04b0 154
Davidroid 6:32166bfc04b0 155 /* Getting current position. */
Davidroid 6:32166bfc04b0 156 int position = motor->GetPosition();
Davidroid 6:32166bfc04b0 157
Davidroid 6:32166bfc04b0 158 /* Printing to the console. */
Davidroid 6:32166bfc04b0 159 printf(" Position: %d.\r\n", position);
Davidroid 6:32166bfc04b0 160
Davidroid 6:32166bfc04b0 161 /* Waiting 2 seconds. */
Davidroid 6:32166bfc04b0 162 wait_ms(2000);
Davidroid 6:32166bfc04b0 163
Davidroid 19:1cd7f65c155c 164
Davidroid 19:1cd7f65c155c 165 /*----- Changing motor setting. -----*/
Davidroid 19:1cd7f65c155c 166
Davidroid 19:1cd7f65c155c 167 /* Printing to the console. */
Davidroid 19:1cd7f65c155c 168 printf("--> Changing Step Mode and Torque.\r\n");
Davidroid 19:1cd7f65c155c 169
Davidroid 19:1cd7f65c155c 170 /* Setting High Impedance State to update L6474's registers. */
Davidroid 19:1cd7f65c155c 171 motor->SoftHiZ();
Davidroid 19:1cd7f65c155c 172
Davidroid 19:1cd7f65c155c 173 /* Changing step mode. */
Davidroid 19:1cd7f65c155c 174 motor->SetParameter(L6474_STEP_MODE, (unsigned int) L6474_STEP_SEL_1_16 | (unsigned int) L6474_SYNC_SEL_1_2);
Davidroid 19:1cd7f65c155c 175
Davidroid 19:1cd7f65c155c 176 /* Increasing the torque regulation current to 500mA. */
Davidroid 19:1cd7f65c155c 177 motor->SetParameter(L6474_TVAL, 500);
Davidroid 19:1cd7f65c155c 178
Davidroid 19:1cd7f65c155c 179 /* Waiting 1 second. */
Davidroid 19:1cd7f65c155c 180 wait_ms(1000);
Davidroid 19:1cd7f65c155c 181
Davidroid 19:1cd7f65c155c 182
Davidroid 6:32166bfc04b0 183 /*----- Moving. -----*/
Davidroid 6:32166bfc04b0 184
Davidroid 6:32166bfc04b0 185 /* Printing to the console. */
Davidroid 19:1cd7f65c155c 186 printf("--> Moving backward %d steps.\r\n", STEPS);
Davidroid 6:32166bfc04b0 187
Davidroid 6:32166bfc04b0 188 /* Moving N steps in the backward direction. */
Davidroid 19:1cd7f65c155c 189 motor->Move(StepperMotor::BWD, STEPS);
Davidroid 6:32166bfc04b0 190
Davidroid 6:32166bfc04b0 191 /* Waiting while the motor is active. */
Davidroid 6:32166bfc04b0 192 motor->WaitWhileActive();
Davidroid 6:32166bfc04b0 193
Davidroid 6:32166bfc04b0 194 /* Getting current position. */
Davidroid 6:32166bfc04b0 195 position = motor->GetPosition();
Davidroid 6:32166bfc04b0 196
Davidroid 6:32166bfc04b0 197 /* Printing to the console. */
Davidroid 6:32166bfc04b0 198 printf(" Position: %d.\r\n", position);
Davidroid 6:32166bfc04b0 199 printf("--> Setting Home.\r\n");
Davidroid 6:32166bfc04b0 200
Davidroid 6:32166bfc04b0 201 /* Setting the current position to be the home position. */
Davidroid 6:32166bfc04b0 202 motor->SetHome();
Davidroid 6:32166bfc04b0 203
Davidroid 6:32166bfc04b0 204 /* Waiting 2 seconds. */
Davidroid 6:32166bfc04b0 205 wait_ms(2000);
Davidroid 6:32166bfc04b0 206
Davidroid 6:32166bfc04b0 207
Davidroid 6:32166bfc04b0 208 /*----- Going to a specified position. -----*/
Davidroid 6:32166bfc04b0 209
Davidroid 6:32166bfc04b0 210 /* Printing to the console. */
Davidroid 19:1cd7f65c155c 211 printf("--> Going to position %d.\r\n", STEPS);
Davidroid 6:32166bfc04b0 212
Davidroid 6:32166bfc04b0 213 /* Requesting to go to a specified position. */
Davidroid 19:1cd7f65c155c 214 motor->GoTo(STEPS);
Davidroid 6:32166bfc04b0 215
Davidroid 6:32166bfc04b0 216 /* Waiting while the motor is active. */
Davidroid 6:32166bfc04b0 217 motor->WaitWhileActive();
Davidroid 6:32166bfc04b0 218
Davidroid 6:32166bfc04b0 219 /* Getting current position. */
Davidroid 6:32166bfc04b0 220 position = motor->GetPosition();
Davidroid 6:32166bfc04b0 221
Davidroid 6:32166bfc04b0 222 /* Printing to the console. */
Davidroid 6:32166bfc04b0 223 printf(" Position: %d.\r\n", position);
Davidroid 6:32166bfc04b0 224
Davidroid 6:32166bfc04b0 225 /* Waiting 2 seconds. */
Davidroid 6:32166bfc04b0 226 wait_ms(2000);
Davidroid 6:32166bfc04b0 227
Davidroid 6:32166bfc04b0 228
Davidroid 6:32166bfc04b0 229 /*----- Going Home. -----*/
Davidroid 6:32166bfc04b0 230
Davidroid 6:32166bfc04b0 231 /* Printing to the console. */
Davidroid 6:32166bfc04b0 232 printf("--> Going Home.\r\n");
Davidroid 6:32166bfc04b0 233
Davidroid 6:32166bfc04b0 234 /* Requesting to go to home. */
Davidroid 6:32166bfc04b0 235 motor->GoHome();
Davidroid 6:32166bfc04b0 236
Davidroid 6:32166bfc04b0 237 /* Waiting while the motor is active. */
Davidroid 6:32166bfc04b0 238 motor->WaitWhileActive();
Davidroid 6:32166bfc04b0 239
Davidroid 6:32166bfc04b0 240 /* Getting current position. */
Davidroid 6:32166bfc04b0 241 position = motor->GetPosition();
Davidroid 6:32166bfc04b0 242
Davidroid 6:32166bfc04b0 243 /* Printing to the console. */
Davidroid 6:32166bfc04b0 244 printf(" Position: %d.\r\n", position);
Davidroid 0:e6a49a092e2a 245
Davidroid 6:32166bfc04b0 246 /* Waiting 2 seconds. */
Davidroid 6:32166bfc04b0 247 wait_ms(2000);
Davidroid 6:32166bfc04b0 248
Davidroid 6:32166bfc04b0 249
Davidroid 6:32166bfc04b0 250 /*----- Running. -----*/
Davidroid 6:32166bfc04b0 251
Davidroid 6:32166bfc04b0 252 /* Printing to the console. */
Davidroid 6:32166bfc04b0 253 printf("--> Running backward.\r\n");
Davidroid 6:32166bfc04b0 254
Davidroid 6:32166bfc04b0 255 /* Requesting to run backward. */
Davidroid 6:32166bfc04b0 256 motor->Run(StepperMotor::BWD);
Davidroid 6:32166bfc04b0 257
Davidroid 6:32166bfc04b0 258 /* Waiting until delay has expired. */
Davidroid 6:32166bfc04b0 259 wait_ms(6000);
Davidroid 6:32166bfc04b0 260
Davidroid 6:32166bfc04b0 261 /* Getting current speed. */
Davidroid 6:32166bfc04b0 262 int speed = motor->GetSpeed();
Davidroid 6:32166bfc04b0 263
Davidroid 6:32166bfc04b0 264 /* Printing to the console. */
Davidroid 6:32166bfc04b0 265 printf(" Speed: %d.\r\n", speed);
Davidroid 6:32166bfc04b0 266
Davidroid 6:32166bfc04b0 267 /*----- Increasing the speed while running. -----*/
Davidroid 6:32166bfc04b0 268
Davidroid 6:32166bfc04b0 269 /* Printing to the console. */
Davidroid 6:32166bfc04b0 270 printf("--> Increasing the speed while running.\r\n");
Davidroid 6:32166bfc04b0 271
Davidroid 6:32166bfc04b0 272 /* Increasing speed to 2400 step/s. */
Davidroid 6:32166bfc04b0 273 motor->SetMaxSpeed(2400);
Davidroid 6:32166bfc04b0 274
Davidroid 6:32166bfc04b0 275 /* Waiting until delay has expired. */
Davidroid 6:32166bfc04b0 276 wait_ms(6000);
Davidroid 6:32166bfc04b0 277
Davidroid 6:32166bfc04b0 278 /* Getting current speed. */
Davidroid 6:32166bfc04b0 279 speed = motor->GetSpeed();
Davidroid 6:32166bfc04b0 280
Davidroid 6:32166bfc04b0 281 /* Printing to the console. */
Davidroid 6:32166bfc04b0 282 printf(" Speed: %d.\r\n", speed);
Davidroid 6:32166bfc04b0 283
Davidroid 6:32166bfc04b0 284
Davidroid 6:32166bfc04b0 285 /*----- Decreasing the speed while running. -----*/
Davidroid 0:e6a49a092e2a 286
Davidroid 6:32166bfc04b0 287 /* Printing to the console. */
Davidroid 6:32166bfc04b0 288 printf("--> Decreasing the speed while running.\r\n");
Davidroid 6:32166bfc04b0 289
Davidroid 6:32166bfc04b0 290 /* Decreasing speed to 1200 step/s. */
Davidroid 6:32166bfc04b0 291 motor->SetMaxSpeed(1200);
Davidroid 6:32166bfc04b0 292
Davidroid 6:32166bfc04b0 293 /* Waiting until delay has expired. */
Davidroid 6:32166bfc04b0 294 wait_ms(8000);
Davidroid 6:32166bfc04b0 295
Davidroid 6:32166bfc04b0 296 /* Getting current speed. */
Davidroid 6:32166bfc04b0 297 speed = motor->GetSpeed();
Davidroid 6:32166bfc04b0 298
Davidroid 6:32166bfc04b0 299 /* Printing to the console. */
Davidroid 6:32166bfc04b0 300 printf(" Speed: %d.\r\n", speed);
Davidroid 6:32166bfc04b0 301
Davidroid 6:32166bfc04b0 302
Davidroid 6:32166bfc04b0 303 /*----- Requiring hard-stop while running. -----*/
Davidroid 6:32166bfc04b0 304
Davidroid 6:32166bfc04b0 305 /* Printing to the console. */
Davidroid 6:32166bfc04b0 306 printf("--> Requiring hard-stop while running.\r\n");
Davidroid 6:32166bfc04b0 307
Davidroid 6:32166bfc04b0 308 /* Requesting to immediatly stop. */
Davidroid 6:32166bfc04b0 309 motor->HardStop();
Davidroid 6:32166bfc04b0 310
Davidroid 6:32166bfc04b0 311 /* Waiting while the motor is active. */
Davidroid 6:32166bfc04b0 312 motor->WaitWhileActive();
Davidroid 6:32166bfc04b0 313
Davidroid 6:32166bfc04b0 314 /* Waiting 2 seconds. */
Davidroid 6:32166bfc04b0 315 wait_ms(2000);
Davidroid 6:32166bfc04b0 316
Davidroid 6:32166bfc04b0 317
Davidroid 6:32166bfc04b0 318 /*----- Infinite Loop. -----*/
Davidroid 6:32166bfc04b0 319
Davidroid 6:32166bfc04b0 320 /* Printing to the console. */
Davidroid 6:32166bfc04b0 321 printf("--> Infinite Loop...\r\n");
Davidroid 6:32166bfc04b0 322
Davidroid 6:32166bfc04b0 323 /* Setting the current position to be the home position. */
Davidroid 6:32166bfc04b0 324 motor->SetHome();
Davidroid 6:32166bfc04b0 325
Davidroid 6:32166bfc04b0 326 /* Infinite Loop. */
Davidroid 6:32166bfc04b0 327 while (1)
Davidroid 6:32166bfc04b0 328 {
Davidroid 6:32166bfc04b0 329 /* Requesting to go to a specified position. */
Davidroid 10:8f031470ca9f 330 motor->GoTo(STEPS >> 1);
Davidroid 3:fffa53c7aed2 331
Davidroid 0:e6a49a092e2a 332 /* Waiting while the motor is active. */
Davidroid 1:fbf28f3367aa 333 motor->WaitWhileActive();
Davidroid 0:e6a49a092e2a 334
Davidroid 0:e6a49a092e2a 335 /* Requesting to go to a specified position. */
Davidroid 10:8f031470ca9f 336 motor->GoTo(- (STEPS >> 1));
Davidroid 0:e6a49a092e2a 337
Davidroid 0:e6a49a092e2a 338 /* Waiting while the motor is active. */
Davidroid 1:fbf28f3367aa 339 motor->WaitWhileActive();
Davidroid 0:e6a49a092e2a 340 }
Davidroid 0:e6a49a092e2a 341 }