Simple program featuring a few API functions usage of the X_NUCLEO_IHM06A1 library.

Dependencies:   X_NUCLEO_IHM06A1 mbed

Fork of HelloWorld_IHM06A1 by ST Expansion SW Team

This application provides a simple example of usage of the X-NUCLEO-IHM06A1 Bipolar Stepper Motor Control Expansion Board.

It shows how to use a stepper motor connected to the board by:

  • Running the motor;
  • Monitoring the speed and the motor state;
  • Setting/Getting the speed;
  • Setting/Getting the step mode;
  • Setting/Getting the acceleration and deceleration;
  • Moving a defined number of steps or microsteps;
  • Disabling the power bridges;
  • Setting/Getting the torque;
  • Going to home position

It also shows how to monitor the step clock handler duration in order to evaluate the maximum achievable motor speed for a given MCU.

For the hardware configuration of the expansion board, please refer to the X_NUCLEO_IHM06A1 library web page.

Committer:
nucleosam
Date:
Thu May 26 15:54:22 2016 +0000
Revision:
0:9ebe3081c641
Child:
4:0e50964ff610
Initial version.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucleosam 0:9ebe3081c641 1 /**
nucleosam 0:9ebe3081c641 2 ******************************************************************************
nucleosam 0:9ebe3081c641 3 * @file main.cpp
nucleosam 0:9ebe3081c641 4 * @author IPC Rennes
nucleosam 0:9ebe3081c641 5 * @version V1.0.0
nucleosam 0:9ebe3081c641 6 * @date May 26th, 2016
nucleosam 0:9ebe3081c641 7 * @brief mbed simple application for the STMicroelectronics X-NUCLEO-IHM06A1
nucleosam 0:9ebe3081c641 8 * Motor Control Expansion Board: control of 1 motor.
nucleosam 0:9ebe3081c641 9 ******************************************************************************
nucleosam 0:9ebe3081c641 10 * @attention
nucleosam 0:9ebe3081c641 11 *
nucleosam 0:9ebe3081c641 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
nucleosam 0:9ebe3081c641 13 *
nucleosam 0:9ebe3081c641 14 * Redistribution and use in source and binary forms, with or without modification,
nucleosam 0:9ebe3081c641 15 * are permitted provided that the following conditions are met:
nucleosam 0:9ebe3081c641 16 * 1. Redistributions of source code must retain the above copyright notice,
nucleosam 0:9ebe3081c641 17 * this list of conditions and the following disclaimer.
nucleosam 0:9ebe3081c641 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
nucleosam 0:9ebe3081c641 19 * this list of conditions and the following disclaimer in the documentation
nucleosam 0:9ebe3081c641 20 * and/or other materials provided with the distribution.
nucleosam 0:9ebe3081c641 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
nucleosam 0:9ebe3081c641 22 * may be used to endorse or promote products derived from this software
nucleosam 0:9ebe3081c641 23 * without specific prior written permission.
nucleosam 0:9ebe3081c641 24 *
nucleosam 0:9ebe3081c641 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
nucleosam 0:9ebe3081c641 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
nucleosam 0:9ebe3081c641 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
nucleosam 0:9ebe3081c641 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
nucleosam 0:9ebe3081c641 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
nucleosam 0:9ebe3081c641 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
nucleosam 0:9ebe3081c641 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
nucleosam 0:9ebe3081c641 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
nucleosam 0:9ebe3081c641 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nucleosam 0:9ebe3081c641 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nucleosam 0:9ebe3081c641 35 *
nucleosam 0:9ebe3081c641 36 ******************************************************************************
nucleosam 0:9ebe3081c641 37 */
nucleosam 0:9ebe3081c641 38
nucleosam 0:9ebe3081c641 39 /* Includes ------------------------------------------------------------------*/
nucleosam 0:9ebe3081c641 40
nucleosam 0:9ebe3081c641 41 /* mbed specific header files. */
nucleosam 0:9ebe3081c641 42 #include "mbed.h"
nucleosam 0:9ebe3081c641 43
nucleosam 0:9ebe3081c641 44 /* Component specific header files. */
nucleosam 0:9ebe3081c641 45 #include "stspin220_class.h"
nucleosam 0:9ebe3081c641 46
nucleosam 0:9ebe3081c641 47 /* Definitions ---------------------------------------------------------------*/
nucleosam 0:9ebe3081c641 48 #ifdef TARGET_NUCLEO_F302R8
nucleosam 0:9ebe3081c641 49 #define PWM_REF_PIN D11 /* HW mandatory patch: bridge manually D9 with D10 */
nucleosam 0:9ebe3081c641 50 #else
nucleosam 0:9ebe3081c641 51 #define PWM_REF_PIN D9
nucleosam 0:9ebe3081c641 52 #endif
nucleosam 0:9ebe3081c641 53 /* Uncomment the line below to enable the step clock monitoring duration */
nucleosam 0:9ebe3081c641 54 //#define STEP_CLOCK_HANDLER_DURATION_MONITORING
nucleosam 0:9ebe3081c641 55 #ifdef STEP_CLOCK_HANDLER_DURATION_MONITORING
nucleosam 0:9ebe3081c641 56 #define MONITORING_PIN D15
nucleosam 0:9ebe3081c641 57 #endif
nucleosam 0:9ebe3081c641 58
nucleosam 0:9ebe3081c641 59 /* Variables -----------------------------------------------------------------*/
nucleosam 0:9ebe3081c641 60
nucleosam 0:9ebe3081c641 61 /* Initialization parameters of the motor connected to the expansion board. */
nucleosam 0:9ebe3081c641 62 Stspin220_Init_t initDeviceParameters =
nucleosam 0:9ebe3081c641 63 {
nucleosam 0:9ebe3081c641 64 10000, //Acceleration rate in pulse/s2 (must be greater than 0)
nucleosam 0:9ebe3081c641 65 10000, //Deceleration rate in pulse/s2 (must be greater than 0)
nucleosam 0:9ebe3081c641 66 10000, //Running speed in pulse/s (8 pulse/s < Maximum speed <= 10 000 pulse/s )
nucleosam 0:9ebe3081c641 67 400, //Minimum speed in pulse/s (8 pulse/s <= Minimum speed < 10 000 pulse/s)
nucleosam 0:9ebe3081c641 68 20, //Acceleration current torque in % (from 0 to 100)
nucleosam 0:9ebe3081c641 69 15, //Deceleration current torque in % (from 0 to 100)
nucleosam 0:9ebe3081c641 70 10, //Running current torque in % (from 0 to 100)
nucleosam 0:9ebe3081c641 71 25, //Holding current torque in % (from 0 to 100)
nucleosam 0:9ebe3081c641 72 TRUE, //Torque boost speed enable
nucleosam 0:9ebe3081c641 73 200, //Torque boost speed threshold in fullstep/s
nucleosam 0:9ebe3081c641 74 STEP_MODE_1_32, //Step mode via enum motorStepMode_t
nucleosam 0:9ebe3081c641 75 HIZ_MODE, //Automatic HIZ STOP
nucleosam 0:9ebe3081c641 76 100000 //REF frequency (Hz)
nucleosam 0:9ebe3081c641 77 };
nucleosam 0:9ebe3081c641 78
nucleosam 0:9ebe3081c641 79 /* Motor Control Component. */
nucleosam 0:9ebe3081c641 80 STSPIN220 *motor;
nucleosam 0:9ebe3081c641 81
nucleosam 0:9ebe3081c641 82 /* Functions -----------------------------------------------------------------*/
nucleosam 0:9ebe3081c641 83
nucleosam 0:9ebe3081c641 84 /**
nucleosam 0:9ebe3081c641 85 * @brief This is an example of user handler for the flag interrupt.
nucleosam 0:9ebe3081c641 86 * @param None
nucleosam 0:9ebe3081c641 87 * @retval None
nucleosam 0:9ebe3081c641 88 * @note If needed, implement it, and then attach and enable it:
nucleosam 0:9ebe3081c641 89 * + motor->AttachFlagIRQ(&myFlagIRQHandler);
nucleosam 0:9ebe3081c641 90 * + motor->EnableFlagIRQ();
nucleosam 0:9ebe3081c641 91 * To disable it:
nucleosam 0:9ebe3081c641 92 * + motor->DisbleFlagIRQ();
nucleosam 0:9ebe3081c641 93 */
nucleosam 0:9ebe3081c641 94 void myFlagIRQHandler(void)
nucleosam 0:9ebe3081c641 95 {
nucleosam 0:9ebe3081c641 96 printf(" WARNING: \"FLAG\" interrupt triggered:\r\n");
nucleosam 0:9ebe3081c641 97 motor->Disable();
nucleosam 0:9ebe3081c641 98 printf(" Motor disabled.\r\n\n");
nucleosam 0:9ebe3081c641 99 }
nucleosam 0:9ebe3081c641 100
nucleosam 0:9ebe3081c641 101 /**
nucleosam 0:9ebe3081c641 102 * @brief This is an example of error handler.
nucleosam 0:9ebe3081c641 103 * @param[in] error Number of the error
nucleosam 0:9ebe3081c641 104 * @retval None
nucleosam 0:9ebe3081c641 105 * @note If needed, implement it, and then attach it:
nucleosam 0:9ebe3081c641 106 * + motor->AttachErrorHandler(&myErrorHandler);
nucleosam 0:9ebe3081c641 107 */
nucleosam 0:9ebe3081c641 108 void myErrorHandler(uint16_t error)
nucleosam 0:9ebe3081c641 109 {
nucleosam 0:9ebe3081c641 110 /* Printing to the console. */
nucleosam 0:9ebe3081c641 111 printf("Error %d detected\r\n\n", error);
nucleosam 0:9ebe3081c641 112
nucleosam 0:9ebe3081c641 113 /* Infinite loop */
nucleosam 0:9ebe3081c641 114 while(1)
nucleosam 0:9ebe3081c641 115 {
nucleosam 0:9ebe3081c641 116 }
nucleosam 0:9ebe3081c641 117 }
nucleosam 0:9ebe3081c641 118
nucleosam 0:9ebe3081c641 119 /* Main ----------------------------------------------------------------------*/
nucleosam 0:9ebe3081c641 120
nucleosam 0:9ebe3081c641 121 int main()
nucleosam 0:9ebe3081c641 122 {
nucleosam 0:9ebe3081c641 123 /* Printing to the console. */
nucleosam 0:9ebe3081c641 124 printf("STARTING MAIN PROGRAM\r\n");
nucleosam 0:9ebe3081c641 125 printf(" Reminder:\r\n");
nucleosam 0:9ebe3081c641 126 printf(" The position, speed, acceleration and deceleration units\r\n");
nucleosam 0:9ebe3081c641 127 printf(" are in agreement to the step mode.\r\n");
nucleosam 0:9ebe3081c641 128 printf(" In example if the step mode is 1/32th,\r\n");
nucleosam 0:9ebe3081c641 129 printf(" the position is in 1/32th step,\r\n");
nucleosam 0:9ebe3081c641 130 printf(" the speed is in 1/32th step/s,\r\n");
nucleosam 0:9ebe3081c641 131 printf(" the acceleration and the deceleration are in 1/32th step/s^2.\r\n");
nucleosam 0:9ebe3081c641 132
nucleosam 0:9ebe3081c641 133 //----- Initialization
nucleosam 0:9ebe3081c641 134 /* Initializing Motor Control Component. */
nucleosam 0:9ebe3081c641 135 #ifdef STEP_CLOCK_HANDLER_DURATION_MONITORING
nucleosam 0:9ebe3081c641 136 motor = new STSPIN220(D2, D8, D7, D5, D10, D3, PWM_REF_PIN, MONITORING_PIN);
nucleosam 0:9ebe3081c641 137 #else
nucleosam 0:9ebe3081c641 138 motor = new STSPIN220(D2, D8, D7, D5, D10, D3, PWM_REF_PIN);
nucleosam 0:9ebe3081c641 139 #endif
nucleosam 0:9ebe3081c641 140
nucleosam 0:9ebe3081c641 141 if (motor->Init(&initDeviceParameters) != COMPONENT_OK) exit(EXIT_FAILURE);
nucleosam 0:9ebe3081c641 142
nucleosam 0:9ebe3081c641 143 /* Attaching and enabling an interrupt handler. */
nucleosam 0:9ebe3081c641 144 motor->AttachFlagIRQ(&myFlagIRQHandler);
nucleosam 0:9ebe3081c641 145 motor->EnableFlagIRQ();
nucleosam 0:9ebe3081c641 146
nucleosam 0:9ebe3081c641 147 /* Attaching an error handler */
nucleosam 0:9ebe3081c641 148 motor->AttachErrorHandler(&myErrorHandler);
nucleosam 0:9ebe3081c641 149
nucleosam 0:9ebe3081c641 150 /* Printing to the console. */
nucleosam 0:9ebe3081c641 151 printf("Motor Control Application Example for 1 Motor\r\n");
nucleosam 0:9ebe3081c641 152
nucleosam 0:9ebe3081c641 153 //----- Get the step mode after initialization
nucleosam 0:9ebe3081c641 154 StepperMotor::step_mode_t myStepMode = motor->GetStepMode();
nucleosam 0:9ebe3081c641 155
nucleosam 0:9ebe3081c641 156 //----- Run the motor BACKWARD
nucleosam 0:9ebe3081c641 157 printf("--> Running the motor backward.\r\n");
nucleosam 0:9ebe3081c641 158 motor->Run(StepperMotor::BWD);
nucleosam 0:9ebe3081c641 159
nucleosam 0:9ebe3081c641 160 while (motor->GetStatus()!=STEADY)
nucleosam 0:9ebe3081c641 161 {
nucleosam 0:9ebe3081c641 162 /* Print reached speed to the console in step/s or microsteps/s */
nucleosam 0:9ebe3081c641 163 printf(" Reached Speed: %d step/s.\r\n", motor->GetSpeed());
nucleosam 0:9ebe3081c641 164 wait_ms(50);
nucleosam 0:9ebe3081c641 165 }
nucleosam 0:9ebe3081c641 166 printf(" Reached Speed: %d step/s.\r\n", motor->GetSpeed());
nucleosam 0:9ebe3081c641 167
nucleosam 0:9ebe3081c641 168 /* Wait for 1 second */
nucleosam 0:9ebe3081c641 169 wait_ms(1000);
nucleosam 0:9ebe3081c641 170
nucleosam 0:9ebe3081c641 171 //----- Decrease speed while running to one quarter of the previous speed
nucleosam 0:9ebe3081c641 172 printf(" Motor init step mode: %d\r\n", myStepMode);
nucleosam 0:9ebe3081c641 173 int currentStepMode = motor->GetStepMode();
nucleosam 0:9ebe3081c641 174 printf(" Motor current step mode: %d\r\n", currentStepMode);
nucleosam 0:9ebe3081c641 175 int newSpeed = (motor->GetSpeed()<<(myStepMode-currentStepMode))>>2;
nucleosam 0:9ebe3081c641 176 printf(" Set motor max speed to: %d step/s.\r\n", newSpeed);
nucleosam 0:9ebe3081c641 177 if (!motor->SetMaxSpeed(newSpeed))
nucleosam 0:9ebe3081c641 178 {
nucleosam 0:9ebe3081c641 179 printf(" Failed: target speed below min speed.\r\n");
nucleosam 0:9ebe3081c641 180 if (motor->SetMaxSpeed(motor->GetMinSpeed()))
nucleosam 0:9ebe3081c641 181 printf(" Motor max speed set to min speed: %d step/s.\r\n", motor->GetMinSpeed());
nucleosam 0:9ebe3081c641 182 else
nucleosam 0:9ebe3081c641 183 printf(" Failed: check all speed and boost setting.\r\n");
nucleosam 0:9ebe3081c641 184 }
nucleosam 0:9ebe3081c641 185
nucleosam 0:9ebe3081c641 186 /* Wait until the motor starts decelerating */
nucleosam 0:9ebe3081c641 187 while (motor->GetStatus()==STEADY);
nucleosam 0:9ebe3081c641 188 /* Wait and print speed while the motor is not steady running */
nucleosam 0:9ebe3081c641 189 while (motor->GetStatus()!=STEADY)
nucleosam 0:9ebe3081c641 190 {
nucleosam 0:9ebe3081c641 191 /* Print reached speed to the console in step/s or microsteps/s */
nucleosam 0:9ebe3081c641 192 printf(" Reached Speed: %d step/s.\r\n", motor->GetSpeed());
nucleosam 0:9ebe3081c641 193 wait_ms(50);
nucleosam 0:9ebe3081c641 194 }
nucleosam 0:9ebe3081c641 195 printf(" Reached Speed: %d step/s.\r\n", motor->GetSpeed());
nucleosam 0:9ebe3081c641 196
nucleosam 0:9ebe3081c641 197 /* Wait for 5 seconds */
nucleosam 0:9ebe3081c641 198 wait_ms(5000);
nucleosam 0:9ebe3081c641 199
nucleosam 0:9ebe3081c641 200 //----- Soft stop required while running
nucleosam 0:9ebe3081c641 201 printf("--> Soft stop requested.\r\n");
nucleosam 0:9ebe3081c641 202 motor->SoftStop();
nucleosam 0:9ebe3081c641 203
nucleosam 0:9ebe3081c641 204 /* Wait for the motor of device ends moving */
nucleosam 0:9ebe3081c641 205 motor->WaitWhileActive();
nucleosam 0:9ebe3081c641 206
nucleosam 0:9ebe3081c641 207 /* Wait for 2 seconds */
nucleosam 0:9ebe3081c641 208 wait_ms(2000);
nucleosam 0:9ebe3081c641 209
nucleosam 0:9ebe3081c641 210 //----- Change step mode to full step mode
nucleosam 0:9ebe3081c641 211 motor->SetStepMode(StepperMotor::STEP_MODE_FULL);
nucleosam 0:9ebe3081c641 212 printf(" Motor step mode: %d\r\n", motor->GetStepMode());
nucleosam 0:9ebe3081c641 213 printf(" 0:FS 1:1/2 2:1/4\r\n 3:1/8 4:1/16 5:1/32\r\n");
nucleosam 0:9ebe3081c641 214 printf(" 6:1/64 7:1/128 8:1/256\r\n");
nucleosam 0:9ebe3081c641 215
nucleosam 0:9ebe3081c641 216 /* Get current position of device and print to the console */
nucleosam 0:9ebe3081c641 217 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:9ebe3081c641 218
nucleosam 0:9ebe3081c641 219 /* Set speed, acceleration and deceleration to scale with full step mode */
nucleosam 0:9ebe3081c641 220 motor->SetMinSpeed(initDeviceParameters.minSpeed>>myStepMode);
nucleosam 0:9ebe3081c641 221 motor->SetMaxSpeed(initDeviceParameters.maxSpeed>>myStepMode);
nucleosam 0:9ebe3081c641 222 motor->SetAcceleration(motor->GetAcceleration()>>myStepMode);
nucleosam 0:9ebe3081c641 223 motor->SetDeceleration(motor->GetDeceleration()>>myStepMode);
nucleosam 0:9ebe3081c641 224 /* Print parameters to the console */
nucleosam 0:9ebe3081c641 225 printf(" Motor Min Speed: %d step/s.\r\n", motor->GetMinSpeed());
nucleosam 0:9ebe3081c641 226 printf(" Motor Max Speed: %d step/s.\r\n", motor->GetMaxSpeed());
nucleosam 0:9ebe3081c641 227 printf(" Motor Acceleration: %d step/s.\r\n", motor->GetAcceleration());
nucleosam 0:9ebe3081c641 228 printf(" Motor Deceleration: %d step/s.\r\n", motor->GetDeceleration());
nucleosam 0:9ebe3081c641 229
nucleosam 0:9ebe3081c641 230 //----- Move of 200 steps in the FW direction
nucleosam 0:9ebe3081c641 231 printf("--> Moving forward 200 steps.\r\n");
nucleosam 0:9ebe3081c641 232 motor->Move(StepperMotor::FWD, 200);
nucleosam 0:9ebe3081c641 233
nucleosam 0:9ebe3081c641 234 /* Waiting while the motor is active. */
nucleosam 0:9ebe3081c641 235 motor->WaitWhileActive();
nucleosam 0:9ebe3081c641 236
nucleosam 0:9ebe3081c641 237 /* Get current position of device and print to the console */
nucleosam 0:9ebe3081c641 238 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:9ebe3081c641 239
nucleosam 0:9ebe3081c641 240 /* Disable the power bridges */
nucleosam 0:9ebe3081c641 241 motor->Disable();
nucleosam 0:9ebe3081c641 242
nucleosam 0:9ebe3081c641 243 /* Check that the power bridges are actually disabled */
nucleosam 0:9ebe3081c641 244 if (motor->CheckStatusHw()!=0) printf(" Motor driver disabled.\r\n");
nucleosam 0:9ebe3081c641 245 else printf(" Failed to disable the motor driver.\r\n");
nucleosam 0:9ebe3081c641 246
nucleosam 0:9ebe3081c641 247 /* Wait for 2 seconds */
nucleosam 0:9ebe3081c641 248 wait_ms(2000);
nucleosam 0:9ebe3081c641 249
nucleosam 0:9ebe3081c641 250 //----- Restore step mode to its initialization value
nucleosam 0:9ebe3081c641 251 motor->SetStepMode((StepperMotor::step_mode_t)initDeviceParameters.stepMode);
nucleosam 0:9ebe3081c641 252 printf(" Motor step mode: %d\r\n", motor->GetStepMode());
nucleosam 0:9ebe3081c641 253 printf(" 0:FS 1:1/2 2:1/4\r\n 3:1/8 4:1/16 5:1/32\r\n");
nucleosam 0:9ebe3081c641 254 printf(" 6:1/64 7:1/128 8:1/256\r\n");
nucleosam 0:9ebe3081c641 255
nucleosam 0:9ebe3081c641 256 /* Set speed, acceleration and deceleration to scale with microstep mode */
nucleosam 0:9ebe3081c641 257 motor->SetMaxSpeed(motor->GetMaxSpeed()<<myStepMode);
nucleosam 0:9ebe3081c641 258 motor->SetMinSpeed(motor->GetMinSpeed()<<myStepMode);
nucleosam 0:9ebe3081c641 259 motor->SetAcceleration(motor->GetAcceleration()<<myStepMode);
nucleosam 0:9ebe3081c641 260 motor->SetDeceleration(motor->GetDeceleration()<<myStepMode);
nucleosam 0:9ebe3081c641 261 /* Print parameters to the console */
nucleosam 0:9ebe3081c641 262 printf(" Motor Max Speed: %d step/s.\r\n", motor->GetMaxSpeed());
nucleosam 0:9ebe3081c641 263 printf(" Motor Min Speed: %d step/s.\r\n", motor->GetMinSpeed());
nucleosam 0:9ebe3081c641 264 printf(" Motor Acceleration: %d step/s.\r\n", motor->GetAcceleration());
nucleosam 0:9ebe3081c641 265 printf(" Motor Deceleration: %d step/s.\r\n", motor->GetDeceleration());
nucleosam 0:9ebe3081c641 266
nucleosam 0:9ebe3081c641 267 /* Get current position of device and print to the console */
nucleosam 0:9ebe3081c641 268 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:9ebe3081c641 269
nucleosam 0:9ebe3081c641 270 //----- Change torque
nucleosam 0:9ebe3081c641 271 motor->SetTorque(ACC_TORQUE,30);
nucleosam 0:9ebe3081c641 272 motor->SetTorque(DEC_TORQUE,20);
nucleosam 0:9ebe3081c641 273 printf(" Motor acceleration and deceleration torque changed to: %d and %d.\r\n", motor->GetTorque(ACC_TORQUE), motor->GetTorque(DEC_TORQUE));
nucleosam 0:9ebe3081c641 274
nucleosam 0:9ebe3081c641 275 //----- Go to position -6400
nucleosam 0:9ebe3081c641 276 printf("--> Go to position -6400 steps.\r\n");
nucleosam 0:9ebe3081c641 277 motor->GoTo(-6400);
nucleosam 0:9ebe3081c641 278
nucleosam 0:9ebe3081c641 279 /* Wait for the motor ends moving */
nucleosam 0:9ebe3081c641 280 motor->WaitWhileActive();
nucleosam 0:9ebe3081c641 281
nucleosam 0:9ebe3081c641 282 /* Get current position of device and print to the console */
nucleosam 0:9ebe3081c641 283 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:9ebe3081c641 284
nucleosam 0:9ebe3081c641 285 /* Wait for 2 seconds */
nucleosam 0:9ebe3081c641 286 wait_ms(2000);
nucleosam 0:9ebe3081c641 287
nucleosam 0:9ebe3081c641 288 //----- Go Home
nucleosam 0:9ebe3081c641 289 printf("--> Go to home position.\r\n");
nucleosam 0:9ebe3081c641 290 motor->GoHome();
nucleosam 0:9ebe3081c641 291
nucleosam 0:9ebe3081c641 292 /* Wait for the motor ends moving */
nucleosam 0:9ebe3081c641 293 motor->WaitWhileActive();
nucleosam 0:9ebe3081c641 294
nucleosam 0:9ebe3081c641 295 /* Wait for 1 second */
nucleosam 0:9ebe3081c641 296 wait_ms(1000);
nucleosam 0:9ebe3081c641 297
nucleosam 0:9ebe3081c641 298 /* Infinite Loop. */
nucleosam 0:9ebe3081c641 299 printf("--> Infinite Loop...\r\n");
nucleosam 0:9ebe3081c641 300 while (1)
nucleosam 0:9ebe3081c641 301 {
nucleosam 0:9ebe3081c641 302 /* Request device to go position -3200 */
nucleosam 0:9ebe3081c641 303 motor->GoTo(-3200);
nucleosam 0:9ebe3081c641 304 /* Waiting while the motor is active. */
nucleosam 0:9ebe3081c641 305 motor->WaitWhileActive();
nucleosam 0:9ebe3081c641 306 /* Request device to go position 3200 */
nucleosam 0:9ebe3081c641 307 motor->GoTo(3200);
nucleosam 0:9ebe3081c641 308 /* Waiting while the motor is active. */
nucleosam 0:9ebe3081c641 309 motor->WaitWhileActive();
nucleosam 0:9ebe3081c641 310 wait_ms(500);
nucleosam 0:9ebe3081c641 311 }
nucleosam 0:9ebe3081c641 312 }
nucleosam 0:9ebe3081c641 313 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/