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

Dependencies:   X_NUCLEO_IHM03A1 mbed

Fork of HelloWorld_IHM03A1 by ST Expansion SW Team

This application provides a simple example of usage of the X-NUCLEO-IHM03A1 High Power Stepper Motor Control Expansion Board.

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

  • moving the rotor a specific number of steps or to a specific position, with a given speed value, direction of rotation;
  • monitoring the motor status;
  • handling an interrupt triggered by the motor driver;
  • getting and setting a motor driver parameter.

For the hardware configuration of the expansion board, please refer to the X_NUCLEO_IHM03A1 home web page.
More API usage is available in IHM03A1_ExampleFor1Motor and IHM03A1_ExampleFor3Motors programs.

Committer:
nucleosam
Date:
Wed Apr 13 13:30:28 2016 +0000
Revision:
0:c44075c08a18
Child:
2:f20ed233a489
Initial version with main.cpp around 300 lines comments included.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
nucleosam 0:c44075c08a18 1 /**
nucleosam 0:c44075c08a18 2 ******************************************************************************
nucleosam 0:c44075c08a18 3 * @file main.cpp
nucleosam 0:c44075c08a18 4 * @author IPC Rennes
nucleosam 0:c44075c08a18 5 * @version V1.0.0
nucleosam 0:c44075c08a18 6 * @date April 13th, 2016
nucleosam 0:c44075c08a18 7 * @brief mbed simple application for the STMicroelectronics X-NUCLEO-IHM03A1
nucleosam 0:c44075c08a18 8 * Motor Control Expansion Board: control of 1 motor.
nucleosam 0:c44075c08a18 9 ******************************************************************************
nucleosam 0:c44075c08a18 10 * @attention
nucleosam 0:c44075c08a18 11 *
nucleosam 0:c44075c08a18 12 * <h2><center>&copy; COPYRIGHT(c) 2016 STMicroelectronics</center></h2>
nucleosam 0:c44075c08a18 13 *
nucleosam 0:c44075c08a18 14 * Redistribution and use in source and binary forms, with or without modification,
nucleosam 0:c44075c08a18 15 * are permitted provided that the following conditions are met:
nucleosam 0:c44075c08a18 16 * 1. Redistributions of source code must retain the above copyright notice,
nucleosam 0:c44075c08a18 17 * this list of conditions and the following disclaimer.
nucleosam 0:c44075c08a18 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
nucleosam 0:c44075c08a18 19 * this list of conditions and the following disclaimer in the documentation
nucleosam 0:c44075c08a18 20 * and/or other materials provided with the distribution.
nucleosam 0:c44075c08a18 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
nucleosam 0:c44075c08a18 22 * may be used to endorse or promote products derived from this software
nucleosam 0:c44075c08a18 23 * without specific prior written permission.
nucleosam 0:c44075c08a18 24 *
nucleosam 0:c44075c08a18 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
nucleosam 0:c44075c08a18 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
nucleosam 0:c44075c08a18 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
nucleosam 0:c44075c08a18 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
nucleosam 0:c44075c08a18 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
nucleosam 0:c44075c08a18 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
nucleosam 0:c44075c08a18 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
nucleosam 0:c44075c08a18 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
nucleosam 0:c44075c08a18 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
nucleosam 0:c44075c08a18 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
nucleosam 0:c44075c08a18 35 *
nucleosam 0:c44075c08a18 36 ******************************************************************************
nucleosam 0:c44075c08a18 37 */
nucleosam 0:c44075c08a18 38
nucleosam 0:c44075c08a18 39 /* Includes ------------------------------------------------------------------*/
nucleosam 0:c44075c08a18 40
nucleosam 0:c44075c08a18 41 /* mbed specific header files. */
nucleosam 0:c44075c08a18 42 #include "mbed.h"
nucleosam 0:c44075c08a18 43
nucleosam 0:c44075c08a18 44 /* Helper header files. */
nucleosam 0:c44075c08a18 45 #include "DevSPI.h"
nucleosam 0:c44075c08a18 46
nucleosam 0:c44075c08a18 47 /* Component specific header files. */
nucleosam 0:c44075c08a18 48 #include "powerstep01_class.h"
nucleosam 0:c44075c08a18 49
nucleosam 0:c44075c08a18 50 /* Variables -----------------------------------------------------------------*/
nucleosam 0:c44075c08a18 51
nucleosam 0:c44075c08a18 52 /* Initialization parameters of the motor connected to the expansion board. */
nucleosam 0:c44075c08a18 53 /* Current mode. */
nucleosam 0:c44075c08a18 54 powerstep01_Init_u_t initDeviceParameters =
nucleosam 0:c44075c08a18 55 {
nucleosam 0:c44075c08a18 56 /* common parameters */
nucleosam 0:c44075c08a18 57 .cm.cp.cmVmSelection = POWERSTEP01_CM_VM_CURRENT, // enum powerstep01_CmVm_t
nucleosam 0:c44075c08a18 58 582, // Acceleration rate in step/s2, range 14.55 to 59590 steps/s^2
nucleosam 0:c44075c08a18 59 582, // Deceleration rate in step/s2, range 14.55 to 59590 steps/s^2
nucleosam 0:c44075c08a18 60 488, // Maximum speed in step/s, range 15.25 to 15610 steps/s
nucleosam 0:c44075c08a18 61 0, // Minimum speed in step/s, range 0 to 976.3 steps/s
nucleosam 0:c44075c08a18 62 POWERSTEP01_LSPD_OPT_OFF, // Low speed optimization bit, enum powerstep01_LspdOpt_t
nucleosam 0:c44075c08a18 63 244.16, // Full step speed in step/s, range 7.63 to 15625 steps/s
nucleosam 0:c44075c08a18 64 POWERSTEP01_BOOST_MODE_OFF, // Boost of the amplitude square wave, enum powerstep01_BoostMode_t
nucleosam 0:c44075c08a18 65 281.25, // Overcurrent threshold settings via enum powerstep01_OcdTh_t
nucleosam 0:c44075c08a18 66 STEP_MODE_1_16, // Step mode settings via enum motorStepMode_t
nucleosam 0:c44075c08a18 67 POWERSTEP01_SYNC_SEL_DISABLED, // Synch. Mode settings via enum powerstep01_SyncSel_t
nucleosam 0:c44075c08a18 68 (POWERSTEP01_ALARM_EN_OVERCURRENT|
nucleosam 0:c44075c08a18 69 POWERSTEP01_ALARM_EN_THERMAL_SHUTDOWN|
nucleosam 0:c44075c08a18 70 POWERSTEP01_ALARM_EN_THERMAL_WARNING|
nucleosam 0:c44075c08a18 71 POWERSTEP01_ALARM_EN_UVLO|
nucleosam 0:c44075c08a18 72 POWERSTEP01_ALARM_EN_STALL_DETECTION|
nucleosam 0:c44075c08a18 73 POWERSTEP01_ALARM_EN_SW_TURN_ON|
nucleosam 0:c44075c08a18 74 POWERSTEP01_ALARM_EN_WRONG_NPERF_CMD), // Alarm settings via bitmap enum powerstep01_AlarmEn_t
nucleosam 0:c44075c08a18 75 POWERSTEP01_IGATE_64mA, // Gate sink/source current via enum powerstep01_Igate_t
nucleosam 0:c44075c08a18 76 POWERSTEP01_TBOOST_0ns, // Duration of the overboost phase during gate turn-off via enum powerstep01_Tboost_t
nucleosam 0:c44075c08a18 77 POWERSTEP01_TCC_500ns, // Controlled current time via enum powerstep01_Tcc_t
nucleosam 0:c44075c08a18 78 POWERSTEP01_WD_EN_DISABLE, // External clock watchdog, enum powerstep01_WdEn_t
nucleosam 0:c44075c08a18 79 POWERSTEP01_TBLANK_375ns, // Duration of the blanking time via enum powerstep01_TBlank_t
nucleosam 0:c44075c08a18 80 POWERSTEP01_TDT_125ns, // Duration of the dead time via enum powerstep01_Tdt_t
nucleosam 0:c44075c08a18 81 /* current mode parameters */
nucleosam 0:c44075c08a18 82 328.12, // Hold torque in mV, range from 7.8mV to 1000 mV
nucleosam 0:c44075c08a18 83 328.12, // Running torque in mV, range from 7.8mV to 1000 mV
nucleosam 0:c44075c08a18 84 328.12, // Acceleration torque in mV, range from 7.8mV to 1000 mV
nucleosam 0:c44075c08a18 85 328.12, // Deceleration torque in mV, range from 7.8mV to 1000 mV
nucleosam 0:c44075c08a18 86 POWERSTEP01_TOFF_FAST_8us, //Maximum fast decay time , enum powerstep01_ToffFast_t
nucleosam 0:c44075c08a18 87 POWERSTEP01_FAST_STEP_12us, //Maximum fall step time , enum powerstep01_FastStep_t
nucleosam 0:c44075c08a18 88 3.0, // Minimum on-time in us, range 0.5us to 64us
nucleosam 0:c44075c08a18 89 21.0, // Minimum off-time in us, range 0.5us to 64us
nucleosam 0:c44075c08a18 90 POWERSTEP01_CONFIG_INT_16MHZ_OSCOUT_2MHZ, // Clock setting , enum powerstep01_ConfigOscMgmt_t
nucleosam 0:c44075c08a18 91 POWERSTEP01_CONFIG_SW_HARD_STOP, // External switch hard stop interrupt mode, enum powerstep01_ConfigSwMode_t
nucleosam 0:c44075c08a18 92 POWERSTEP01_CONFIG_TQ_REG_TVAL_USED, // External torque regulation enabling , enum powerstep01_ConfigEnTqReg_t
nucleosam 0:c44075c08a18 93 POWERSTEP01_CONFIG_VS_COMP_DISABLE, // Motor Supply Voltage Compensation enabling , enum powerstep01_ConfigEnVscomp_t
nucleosam 0:c44075c08a18 94 POWERSTEP01_CONFIG_OC_SD_DISABLE, // Over current shutwdown enabling, enum powerstep01_ConfigOcSd_t
nucleosam 0:c44075c08a18 95 POWERSTEP01_CONFIG_UVLOVAL_LOW, // UVLO Threshold via powerstep01_ConfigUvLoVal_t
nucleosam 0:c44075c08a18 96 POWERSTEP01_CONFIG_VCCVAL_15V, // VCC Val, enum powerstep01_ConfigVccVal_t
nucleosam 0:c44075c08a18 97 POWERSTEP01_CONFIG_TSW_048us, // Switching period, enum powerstep01_ConfigTsw_t
nucleosam 0:c44075c08a18 98 POWERSTEP01_CONFIG_PRED_DISABLE // Predictive current enabling , enum powerstep01_ConfigPredEn_t
nucleosam 0:c44075c08a18 99 };
nucleosam 0:c44075c08a18 100
nucleosam 0:c44075c08a18 101 /* Motor Control Component. */
nucleosam 0:c44075c08a18 102 POWERSTEP01 *motor;
nucleosam 0:c44075c08a18 103
nucleosam 0:c44075c08a18 104 /* Functions -----------------------------------------------------------------*/
nucleosam 0:c44075c08a18 105
nucleosam 0:c44075c08a18 106 /**
nucleosam 0:c44075c08a18 107 * @brief This is an example of user handler for the flag interrupt.
nucleosam 0:c44075c08a18 108 * @param None
nucleosam 0:c44075c08a18 109 * @retval None
nucleosam 0:c44075c08a18 110 * @note If needed, implement it, and then attach and enable it:
nucleosam 0:c44075c08a18 111 * + motor->AttachFlagIRQ(&myFlagIRQHandler);
nucleosam 0:c44075c08a18 112 * + motor->EnableFlagIRQ();
nucleosam 0:c44075c08a18 113 * To disable it:
nucleosam 0:c44075c08a18 114 * + motor->DisbleFlagIRQ();
nucleosam 0:c44075c08a18 115 */
nucleosam 0:c44075c08a18 116 void myFlagIRQHandler(void)
nucleosam 0:c44075c08a18 117 {
nucleosam 0:c44075c08a18 118 /* Set ISR flag. */
nucleosam 0:c44075c08a18 119 motor->isrFlag = TRUE;
nucleosam 0:c44075c08a18 120 /* Get the value of the status register. */
nucleosam 0:c44075c08a18 121 unsigned int statusRegister = motor->GetStatus();
nucleosam 0:c44075c08a18 122 printf(" WARNING: \"FLAG\" interrupt triggered.\r\n");
nucleosam 0:c44075c08a18 123 /* Check SW_F flag: if not set, the SW input is opened */
nucleosam 0:c44075c08a18 124 if ((statusRegister & POWERSTEP01_STATUS_SW_F )!=0)
nucleosam 0:c44075c08a18 125 {
nucleosam 0:c44075c08a18 126 printf(" SW closed (connected to ground).\r\n");
nucleosam 0:c44075c08a18 127 }
nucleosam 0:c44075c08a18 128 /* Check SW_EN bit */
nucleosam 0:c44075c08a18 129 if ((statusRegister & POWERSTEP01_STATUS_SW_EVN)==
nucleosam 0:c44075c08a18 130 POWERSTEP01_STATUS_SW_EVN)
nucleosam 0:c44075c08a18 131 {
nucleosam 0:c44075c08a18 132 printf(" SW turn_on event.\r\n");
nucleosam 0:c44075c08a18 133 }
nucleosam 0:c44075c08a18 134 /* Check Command Error flag: if set, the command received by SPI can't be */
nucleosam 0:c44075c08a18 135 /* performed. This occurs for instance when a move command is sent to the */
nucleosam 0:c44075c08a18 136 /* Powerstep01 while it is already running */
nucleosam 0:c44075c08a18 137 if ((statusRegister & POWERSTEP01_STATUS_CMD_ERROR)==
nucleosam 0:c44075c08a18 138 POWERSTEP01_STATUS_CMD_ERROR)
nucleosam 0:c44075c08a18 139 {
nucleosam 0:c44075c08a18 140 printf(" Non-performable command detected.\r\n");
nucleosam 0:c44075c08a18 141 }
nucleosam 0:c44075c08a18 142 /* Check UVLO flag: if not set, there is an undervoltage lock-out */
nucleosam 0:c44075c08a18 143 if ((statusRegister & POWERSTEP01_STATUS_UVLO)==0)
nucleosam 0:c44075c08a18 144 {
nucleosam 0:c44075c08a18 145 printf(" undervoltage lock-out.\r\n");
nucleosam 0:c44075c08a18 146 }
nucleosam 0:c44075c08a18 147 /* Check thermal STATUS flags: if set, the thermal status is not normal */
nucleosam 0:c44075c08a18 148 if ((statusRegister & POWERSTEP01_STATUS_TH_STATUS)!=0)
nucleosam 0:c44075c08a18 149 {
nucleosam 0:c44075c08a18 150 //thermal status: 1: Warning, 2: Bridge shutdown, 3: Device shutdown
nucleosam 0:c44075c08a18 151 printf(" Thermal status: %d.\r\n", (statusRegister & POWERSTEP01_STATUS_TH_STATUS)>>11);
nucleosam 0:c44075c08a18 152 }
nucleosam 0:c44075c08a18 153 /* Check OCD flag: if not set, there is an overcurrent detection */
nucleosam 0:c44075c08a18 154 if ((statusRegister & POWERSTEP01_STATUS_OCD)==0)
nucleosam 0:c44075c08a18 155 {
nucleosam 0:c44075c08a18 156 printf(" Overcurrent detection.\r\n");
nucleosam 0:c44075c08a18 157 }
nucleosam 0:c44075c08a18 158 /* Reset ISR flag. */
nucleosam 0:c44075c08a18 159 motor->isrFlag = FALSE;
nucleosam 0:c44075c08a18 160 }
nucleosam 0:c44075c08a18 161
nucleosam 0:c44075c08a18 162 /**
nucleosam 0:c44075c08a18 163 * @brief This is an example of error handler.
nucleosam 0:c44075c08a18 164 * @param[in] error Number of the error
nucleosam 0:c44075c08a18 165 * @retval None
nucleosam 0:c44075c08a18 166 * @note If needed, implement it, and then attach it:
nucleosam 0:c44075c08a18 167 * + motor->AttachErrorHandler(&myErrorHandler);
nucleosam 0:c44075c08a18 168 */
nucleosam 0:c44075c08a18 169 void myErrorHandler(uint16_t error)
nucleosam 0:c44075c08a18 170 {
nucleosam 0:c44075c08a18 171 /* Printing to the console. */
nucleosam 0:c44075c08a18 172 printf("Error %d detected\r\n\n", error);
nucleosam 0:c44075c08a18 173
nucleosam 0:c44075c08a18 174 /* Infinite loop */
nucleosam 0:c44075c08a18 175 while(1)
nucleosam 0:c44075c08a18 176 {
nucleosam 0:c44075c08a18 177 }
nucleosam 0:c44075c08a18 178 }
nucleosam 0:c44075c08a18 179
nucleosam 0:c44075c08a18 180 /* Main ----------------------------------------------------------------------*/
nucleosam 0:c44075c08a18 181
nucleosam 0:c44075c08a18 182 int main()
nucleosam 0:c44075c08a18 183 {
nucleosam 0:c44075c08a18 184 /* Printing to the console. */
nucleosam 0:c44075c08a18 185 printf("STARTING MAIN PROGRAM\r\n");
nucleosam 0:c44075c08a18 186 printf(" Reminder:\r\n");
nucleosam 0:c44075c08a18 187 printf(" The position unit is in agreement to the step mode.\r\n");
nucleosam 0:c44075c08a18 188 printf(" The speed, acceleration or deceleration unit\r\n");
nucleosam 0:c44075c08a18 189 printf(" do not depend on the step mode and the step unit is a full step.\r\n");
nucleosam 0:c44075c08a18 190
nucleosam 0:c44075c08a18 191 //----- Initialization
nucleosam 0:c44075c08a18 192 /* Initializing SPI bus. */
nucleosam 0:c44075c08a18 193 DevSPI dev_spi(D11, D12, D13);
nucleosam 0:c44075c08a18 194
nucleosam 0:c44075c08a18 195 /* Initializing Motor Control Component. */
nucleosam 0:c44075c08a18 196 motor = new POWERSTEP01(D2, D4, D8, D9, D10, dev_spi);
nucleosam 0:c44075c08a18 197 if (motor->Init(&initDeviceParameters) != COMPONENT_OK) exit(EXIT_FAILURE);
nucleosam 0:c44075c08a18 198
nucleosam 0:c44075c08a18 199 /* Attaching and enabling an interrupt handler. */
nucleosam 0:c44075c08a18 200 motor->AttachFlagIRQ(&myFlagIRQHandler);
nucleosam 0:c44075c08a18 201 motor->EnableFlagIRQ();
nucleosam 0:c44075c08a18 202
nucleosam 0:c44075c08a18 203 /* Attaching an error handler */
nucleosam 0:c44075c08a18 204 motor->AttachErrorHandler(&myErrorHandler);
nucleosam 0:c44075c08a18 205
nucleosam 0:c44075c08a18 206 /* Printing to the console. */
nucleosam 0:c44075c08a18 207 printf("Motor Control Application Example for 1 Motor\r\n");
nucleosam 0:c44075c08a18 208
nucleosam 0:c44075c08a18 209 //----- Move of 16000 steps in the FW direction
nucleosam 0:c44075c08a18 210 printf("--> Moving forward 16000 steps.\r\n");
nucleosam 0:c44075c08a18 211 motor->Move(StepperMotor::FWD, 16000);
nucleosam 0:c44075c08a18 212
nucleosam 0:c44075c08a18 213 /* Waiting while the motor is active. */
nucleosam 0:c44075c08a18 214 motor->WaitWhileActive();
nucleosam 0:c44075c08a18 215
nucleosam 0:c44075c08a18 216 /* Wait for 2 seconds */
nucleosam 0:c44075c08a18 217 wait_ms(2000);
nucleosam 0:c44075c08a18 218
nucleosam 0:c44075c08a18 219 //----- Go to position -6400
nucleosam 0:c44075c08a18 220 printf("--> Go to position -6400 steps.\r\n");
nucleosam 0:c44075c08a18 221
nucleosam 0:c44075c08a18 222 /* Request device to go to position -6400 */
nucleosam 0:c44075c08a18 223 motor->GoTo(-6400);
nucleosam 0:c44075c08a18 224
nucleosam 0:c44075c08a18 225 /* Wait for the motor ends moving */
nucleosam 0:c44075c08a18 226 motor->WaitWhileActive();
nucleosam 0:c44075c08a18 227
nucleosam 0:c44075c08a18 228 /* Get current position of device and print to the console */
nucleosam 0:c44075c08a18 229 printf(" Position: %d.\r\n", motor->GetPosition());
nucleosam 0:c44075c08a18 230
nucleosam 0:c44075c08a18 231 /* Wait for 2 seconds */
nucleosam 0:c44075c08a18 232 wait_ms(2000);
nucleosam 0:c44075c08a18 233
nucleosam 0:c44075c08a18 234 //----- Go Home
nucleosam 0:c44075c08a18 235 /* Printing to the console. */
nucleosam 0:c44075c08a18 236 printf("--> Go to home position.\r\n");
nucleosam 0:c44075c08a18 237
nucleosam 0:c44075c08a18 238 /* Request device to go to Home */
nucleosam 0:c44075c08a18 239 motor->GoHome();
nucleosam 0:c44075c08a18 240
nucleosam 0:c44075c08a18 241 /* Wait for the motor ends moving */
nucleosam 0:c44075c08a18 242 motor->WaitWhileActive();
nucleosam 0:c44075c08a18 243
nucleosam 0:c44075c08a18 244 /* Wait for 2 seconds */
nucleosam 0:c44075c08a18 245 wait_ms(2000);
nucleosam 0:c44075c08a18 246
nucleosam 0:c44075c08a18 247 //----- Run the motor BACKWARD at 400 step/s
nucleosam 0:c44075c08a18 248 printf("--> Run the motor backward at 400 step/s.\r\n");
nucleosam 0:c44075c08a18 249 motor->Run(StepperMotor::BWD,400);
nucleosam 0:c44075c08a18 250
nucleosam 0:c44075c08a18 251 //----- Get parameter example
nucleosam 0:c44075c08a18 252 /* Wait for device reaches the targeted speed */
nucleosam 0:c44075c08a18 253 while((motor->ReadStatusRegister() & POWERSTEP01_STATUS_MOT_STATUS)!=
nucleosam 0:c44075c08a18 254 POWERSTEP01_STATUS_MOT_STATUS_CONST_SPD);
nucleosam 0:c44075c08a18 255
nucleosam 0:c44075c08a18 256 /* Record the reached speed in step/s and print to the console */
nucleosam 0:c44075c08a18 257 printf(" Reached Speed: %f step/s.\r\n", motor->GetAnalogValue(POWERSTEP01_SPEED));
nucleosam 0:c44075c08a18 258
nucleosam 0:c44075c08a18 259 //----- Soft stopped required while running
nucleosam 0:c44075c08a18 260 printf("--> Soft stop requested.\r\n");
nucleosam 0:c44075c08a18 261
nucleosam 0:c44075c08a18 262 /* Request a soft stop of device and keep the power bridges enabled */
nucleosam 0:c44075c08a18 263 motor->SoftHiZ();
nucleosam 0:c44075c08a18 264
nucleosam 0:c44075c08a18 265 /* Wait for the motor of device ends moving */
nucleosam 0:c44075c08a18 266 motor->WaitWhileActive();
nucleosam 0:c44075c08a18 267
nucleosam 0:c44075c08a18 268 /* Wait for 2 seconds */
nucleosam 0:c44075c08a18 269 wait_ms(2000);
nucleosam 0:c44075c08a18 270
nucleosam 0:c44075c08a18 271 //----- Read inexistent register
nucleosam 0:c44075c08a18 272 printf("--> Try to read an inexistent register.\r\n");
nucleosam 0:c44075c08a18 273 /* Trying to read an inexistent register */
nucleosam 0:c44075c08a18 274 /* triggers the flag interrupt and call the myFlagIRQHandler */
nucleosam 0:c44075c08a18 275 motor->GetRawParameter(0x1F);
nucleosam 0:c44075c08a18 276
nucleosam 0:c44075c08a18 277 //----- Changing a motor setting
nucleosam 0:c44075c08a18 278 printf("--> Set the reference voltage assigned to the torque regulation during acceleration to 500mV.\r\n");
nucleosam 0:c44075c08a18 279 motor->SetRawParameter(POWERSTEP01_TVAL_ACC, POWERSTEP01::Tval_RefVoltage_to_RegVal(500));
nucleosam 0:c44075c08a18 280 //Alternatively, the register value can be written directly as shown below:
nucleosam 0:c44075c08a18 281 //motor->SetRawParameter(POWERSTEP01_TVAL_ACC, 63);
nucleosam 0:c44075c08a18 282
nucleosam 0:c44075c08a18 283 //Print the new parameter value to the console
nucleosam 0:c44075c08a18 284 printf("--> New TVAL_ACC register value is 0x%x .\r\n",motor->GetRawParameter(POWERSTEP01_TVAL_ACC));
nucleosam 0:c44075c08a18 285
nucleosam 0:c44075c08a18 286 /* Infinite Loop. */
nucleosam 0:c44075c08a18 287 printf("--> Infinite Loop...\r\n");
nucleosam 0:c44075c08a18 288 while (1)
nucleosam 0:c44075c08a18 289 {
nucleosam 0:c44075c08a18 290 /* Request device to go position -6400 */
nucleosam 0:c44075c08a18 291 motor->GoTo(-6400);
nucleosam 0:c44075c08a18 292
nucleosam 0:c44075c08a18 293 /* Waiting while the motor is active. */
nucleosam 0:c44075c08a18 294 motor->WaitWhileActive();
nucleosam 0:c44075c08a18 295
nucleosam 0:c44075c08a18 296 /* Request device to go position 6400 */
nucleosam 0:c44075c08a18 297 motor->GoTo(6400);
nucleosam 0:c44075c08a18 298
nucleosam 0:c44075c08a18 299 /* Waiting while the motor is active. */
nucleosam 0:c44075c08a18 300 motor->WaitWhileActive();
nucleosam 0:c44075c08a18 301 }
nucleosam 0:c44075c08a18 302 }
nucleosam 0:c44075c08a18 303 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/