ST Microelectronics IHM02A1 motor driver board for two stepping motors. ST L647OPD motion controller ICs are used on the IHM02A1. Nanotec ST4118X1404-A motors used on testing.

Dependencies:   X_NUCLEO_IHM02A1

Committer:
timo_k2
Date:
Mon Oct 04 07:14:48 2021 +0000
Revision:
29:34ef733fe490
Parent:
28:831587f78478
Wiring diagram added.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Davidroid 0:5148e9486cf2 1 /**
Davidroid 0:5148e9486cf2 2 ******************************************************************************
Davidroid 0:5148e9486cf2 3 * @file main.cpp
Davidroid 12:5be6dd48b94a 4 * @author Davide Aliprandi, STMicroelectronics
Davidroid 0:5148e9486cf2 5 * @version V1.0.0
Davidroid 0:5148e9486cf2 6 * @date November 4th, 2015
Davidroid 12:5be6dd48b94a 7 * @brief mbed test application for the STMicroelectronics X-NUCLEO-IHM02A1
Davidroid 1:9f1974b0960d 8 * Motor Control Expansion Board: control of 2 motors.
Davidroid 0:5148e9486cf2 9 ******************************************************************************
Davidroid 0:5148e9486cf2 10 * @attention
Davidroid 0:5148e9486cf2 11 *
Davidroid 0:5148e9486cf2 12 * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
Davidroid 0:5148e9486cf2 13 *
Davidroid 0:5148e9486cf2 14 * Redistribution and use in source and binary forms, with or without modification,
Davidroid 0:5148e9486cf2 15 * are permitted provided that the following conditions are met:
Davidroid 0:5148e9486cf2 16 * 1. Redistributions of source code must retain the above copyright notice,
Davidroid 0:5148e9486cf2 17 * this list of conditions and the following disclaimer.
Davidroid 0:5148e9486cf2 18 * 2. Redistributions in binary form must reproduce the above copyright notice,
Davidroid 0:5148e9486cf2 19 * this list of conditions and the following disclaimer in the documentation
Davidroid 0:5148e9486cf2 20 * and/or other materials provided with the distribution.
Davidroid 0:5148e9486cf2 21 * 3. Neither the name of STMicroelectronics nor the names of its contributors
Davidroid 0:5148e9486cf2 22 * may be used to endorse or promote products derived from this software
Davidroid 0:5148e9486cf2 23 * without specific prior written permission.
Davidroid 0:5148e9486cf2 24 *
Davidroid 0:5148e9486cf2 25 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
Davidroid 0:5148e9486cf2 26 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
Davidroid 0:5148e9486cf2 27 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
Davidroid 0:5148e9486cf2 28 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
Davidroid 0:5148e9486cf2 29 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
Davidroid 0:5148e9486cf2 30 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
Davidroid 0:5148e9486cf2 31 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
Davidroid 0:5148e9486cf2 32 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
Davidroid 0:5148e9486cf2 33 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
Davidroid 0:5148e9486cf2 34 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
Davidroid 0:5148e9486cf2 35 *
Davidroid 0:5148e9486cf2 36 ******************************************************************************
timo_k2 28:831587f78478 37 * Comments by Timo Karppinen
timo_k2 29:34ef733fe490 38 * For correct use of the NUCLEO-F401RE, L476RG with the X-NUCLEO-IHM02A1,
timo_k2 29:34ef733fe490 39 * the solder bridge SB15 on the NUCLEO-x4xxRx has to be removed /
timo_k2 28:831587f78478 40 * Getting started with X-NUCLEO_IHM02A1, page 3/24. = IHM02A1 L6470 nCS
timo_k2 28:831587f78478 41 *
timo_k2 28:831587f78478 42 * Set the motor parameters before connecting the motor!!! Supply voltage,
timo_k2 28:831587f78478 43 * Maximum motor phase curent and Maximum phase voltage are the most
timo_k2 28:831587f78478 44 * important ones. Set as well the step angle - you will set the number of
timo_k2 28:831587f78478 45 * steps per revolution.
timo_k2 28:831587f78478 46 *
timo_k2 28:831587f78478 47 * On first tests supply the IHM02A1 voltage from a source where you can set
timo_k2 28:831587f78478 48 * the current limit. The limit should correspond the maximum phase current
timo_k2 29:34ef733fe490 49 * given in the step motor data sheet. Two phases are driven at a time
timo_k2 29:34ef733fe490 50 * the current might be double the motor phase current.
timo_k2 29:34ef733fe490 51 *
timo_k2 29:34ef733fe490 52 * Wiring the IHM02A1 --- ST4118X1404-A
timo_k2 29:34ef733fe490 53 * 2A --- Orange phase A\
timo_k2 29:34ef733fe490 54 * 1A --- Brown phase A
timo_k2 29:34ef733fe490 55 * 1B --- Red phase B
timo_k2 29:34ef733fe490 56 * 2B --- Yellow phase B\
timo_k2 28:831587f78478 57 *
Davidroid 0:5148e9486cf2 58 */
Davidroid 0:5148e9486cf2 59
Davidroid 0:5148e9486cf2 60
Davidroid 0:5148e9486cf2 61 /* Includes ------------------------------------------------------------------*/
Davidroid 0:5148e9486cf2 62
Davidroid 0:5148e9486cf2 63 /* mbed specific header files. */
Davidroid 0:5148e9486cf2 64 #include "mbed.h"
Davidroid 27:b25816ce6043 65 #include "rtos.h"
Davidroid 0:5148e9486cf2 66
Davidroid 0:5148e9486cf2 67 /* Helper header files. */
Davidroid 0:5148e9486cf2 68 #include "DevSPI.h"
Davidroid 0:5148e9486cf2 69
Davidroid 0:5148e9486cf2 70 /* Expansion Board specific header files. */
Davidroid 26:caec5f51abe8 71 #include "XNucleoIHM02A1.h"
Davidroid 0:5148e9486cf2 72
Davidroid 0:5148e9486cf2 73
Davidroid 0:5148e9486cf2 74 /* Definitions ---------------------------------------------------------------*/
Davidroid 0:5148e9486cf2 75
Davidroid 0:5148e9486cf2 76 /* Number of movements per revolution. */
Davidroid 0:5148e9486cf2 77 #define MPR_1 4
Davidroid 1:9f1974b0960d 78
Davidroid 1:9f1974b0960d 79 /* Number of steps. */
Davidroid 18:591a007effc2 80 #define STEPS_1 (400 * 128) /* 1 revolution given a 400 steps motor configured at 1/128 microstep mode. */
Davidroid 18:591a007effc2 81 #define STEPS_2 (STEPS_1 * 2)
Davidroid 0:5148e9486cf2 82
Davidroid 0:5148e9486cf2 83 /* Delay in milliseconds. */
Davidroid 1:9f1974b0960d 84 #define DELAY_1 1000
Davidroid 0:5148e9486cf2 85 #define DELAY_2 2000
Davidroid 0:5148e9486cf2 86 #define DELAY_3 5000
Davidroid 0:5148e9486cf2 87
Davidroid 0:5148e9486cf2 88
Davidroid 0:5148e9486cf2 89 /* Variables -----------------------------------------------------------------*/
Davidroid 0:5148e9486cf2 90
Davidroid 0:5148e9486cf2 91 /* Motor Control Expansion Board. */
Davidroid 26:caec5f51abe8 92 XNucleoIHM02A1 *x_nucleo_ihm02a1;
Davidroid 0:5148e9486cf2 93
Davidroid 9:f35fbeedb8f4 94 /* Initialization parameters of the motors connected to the expansion board. */
davide.aliprandi@st.com 24:d1f487cb02ba 95 L6470_init_t init[L6470DAISYCHAINSIZE] = {
Davidroid 9:f35fbeedb8f4 96 /* First Motor. */
Davidroid 9:f35fbeedb8f4 97 {
Davidroid 18:591a007effc2 98 9.0, /* Motor supply voltage in V. */
timo_k2 28:831587f78478 99 200, /* Min number of steps per revolution for the motor. */
timo_k2 28:831587f78478 100 1.0, /* Max motor phase current in A. */
timo_k2 28:831587f78478 101 2.0, /* Max motor phase voltage in V. */
Davidroid 18:591a007effc2 102 300.0, /* Motor initial speed [step/s]. */
Davidroid 18:591a007effc2 103 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
Davidroid 18:591a007effc2 104 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
Davidroid 18:591a007effc2 105 992.0, /* Motor maximum speed [step/s]. */
Davidroid 18:591a007effc2 106 0.0, /* Motor minimum speed [step/s]. */
Davidroid 18:591a007effc2 107 602.7, /* Motor full-step speed threshold [step/s]. */
Davidroid 18:591a007effc2 108 3.06, /* Holding kval [V]. */
Davidroid 18:591a007effc2 109 3.06, /* Constant speed kval [V]. */
Davidroid 18:591a007effc2 110 3.06, /* Acceleration starting kval [V]. */
Davidroid 18:591a007effc2 111 3.06, /* Deceleration starting kval [V]. */
Davidroid 18:591a007effc2 112 61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */
Davidroid 18:591a007effc2 113 392.1569e-6, /* Start slope [s/step]. */
Davidroid 18:591a007effc2 114 643.1372e-6, /* Acceleration final slope [s/step]. */
Davidroid 18:591a007effc2 115 643.1372e-6, /* Deceleration final slope [s/step]. */
Davidroid 18:591a007effc2 116 0, /* Thermal compensation factor (range [0, 15]). */
Davidroid 18:591a007effc2 117 3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
Davidroid 18:591a007effc2 118 3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
Davidroid 18:591a007effc2 119 StepperMotor::STEP_MODE_1_128, /* Step mode selection. */
Davidroid 18:591a007effc2 120 0xFF, /* Alarm conditions enable. */
Davidroid 18:591a007effc2 121 0x2E88 /* Ic configuration. */
Davidroid 9:f35fbeedb8f4 122 },
Davidroid 9:f35fbeedb8f4 123
Davidroid 9:f35fbeedb8f4 124 /* Second Motor. */
Davidroid 9:f35fbeedb8f4 125 {
Davidroid 18:591a007effc2 126 9.0, /* Motor supply voltage in V. */
timo_k2 28:831587f78478 127 200, /* Min number of steps per revolution for the motor. */
timo_k2 28:831587f78478 128 1.0, /* Max motor phase voltage in A. */
timo_k2 28:831587f78478 129 2.0, /* Max motor phase voltage in V. */
Davidroid 18:591a007effc2 130 300.0, /* Motor initial speed [step/s]. */
Davidroid 18:591a007effc2 131 500.0, /* Motor acceleration [step/s^2] (comment for infinite acceleration mode). */
Davidroid 18:591a007effc2 132 500.0, /* Motor deceleration [step/s^2] (comment for infinite deceleration mode). */
Davidroid 18:591a007effc2 133 992.0, /* Motor maximum speed [step/s]. */
Davidroid 18:591a007effc2 134 0.0, /* Motor minimum speed [step/s]. */
Davidroid 18:591a007effc2 135 602.7, /* Motor full-step speed threshold [step/s]. */
Davidroid 18:591a007effc2 136 3.06, /* Holding kval [V]. */
Davidroid 18:591a007effc2 137 3.06, /* Constant speed kval [V]. */
Davidroid 18:591a007effc2 138 3.06, /* Acceleration starting kval [V]. */
Davidroid 18:591a007effc2 139 3.06, /* Deceleration starting kval [V]. */
Davidroid 18:591a007effc2 140 61.52, /* Intersect speed for bemf compensation curve slope changing [step/s]. */
Davidroid 18:591a007effc2 141 392.1569e-6, /* Start slope [s/step]. */
Davidroid 18:591a007effc2 142 643.1372e-6, /* Acceleration final slope [s/step]. */
Davidroid 18:591a007effc2 143 643.1372e-6, /* Deceleration final slope [s/step]. */
Davidroid 18:591a007effc2 144 0, /* Thermal compensation factor (range [0, 15]). */
Davidroid 18:591a007effc2 145 3.06 * 1000 * 1.10, /* Ocd threshold [ma] (range [375 ma, 6000 ma]). */
Davidroid 18:591a007effc2 146 3.06 * 1000 * 1.00, /* Stall threshold [ma] (range [31.25 ma, 4000 ma]). */
Davidroid 18:591a007effc2 147 StepperMotor::STEP_MODE_1_128, /* Step mode selection. */
Davidroid 18:591a007effc2 148 0xFF, /* Alarm conditions enable. */
Davidroid 18:591a007effc2 149 0x2E88 /* Ic configuration. */
Davidroid 9:f35fbeedb8f4 150 }
Davidroid 9:f35fbeedb8f4 151 };
Davidroid 9:f35fbeedb8f4 152
Davidroid 0:5148e9486cf2 153
Davidroid 0:5148e9486cf2 154 /* Main ----------------------------------------------------------------------*/
Davidroid 0:5148e9486cf2 155
Davidroid 0:5148e9486cf2 156 int main()
Davidroid 0:5148e9486cf2 157 {
Davidroid 1:9f1974b0960d 158 /*----- Initialization. -----*/
Davidroid 1:9f1974b0960d 159
Davidroid 2:41eeee48951b 160 /* Initializing SPI bus. */
Davidroid 23:073b26366d03 161 #ifdef TARGET_STM32F429
Davidroid 23:073b26366d03 162 DevSPI dev_spi(D11, D12, D13);
Davidroid 23:073b26366d03 163 #else
Davidroid 3:fd280b953f77 164 DevSPI dev_spi(D11, D12, D3);
Davidroid 23:073b26366d03 165 #endif
Davidroid 0:5148e9486cf2 166
Davidroid 5:3b8e19bbf386 167 /* Initializing Motor Control Expansion Board. */
Davidroid 26:caec5f51abe8 168 x_nucleo_ihm02a1 = new XNucleoIHM02A1(&init[0], &init[1], A4, A5, D4, A2, &dev_spi);
Davidroid 0:5148e9486cf2 169
Davidroid 1:9f1974b0960d 170 /* Building a list of motor control components. */
davide.aliprandi@st.com 24:d1f487cb02ba 171 L6470 **motors = x_nucleo_ihm02a1->get_components();
Davidroid 0:5148e9486cf2 172
Davidroid 0:5148e9486cf2 173 /* Printing to the console. */
Davidroid 0:5148e9486cf2 174 printf("Motor Control Application Example for 2 Motors\r\n\n");
Davidroid 0:5148e9486cf2 175
Davidroid 1:9f1974b0960d 176
Davidroid 1:9f1974b0960d 177 /*----- Setting home and marke positions, getting positions, and going to positions. -----*/
Davidroid 1:9f1974b0960d 178
Davidroid 1:9f1974b0960d 179 /* Printing to the console. */
Davidroid 1:9f1974b0960d 180 printf("--> Setting home position.\r\n");
Davidroid 1:9f1974b0960d 181
Davidroid 1:9f1974b0960d 182 /* Setting the home position. */
davide.aliprandi@st.com 24:d1f487cb02ba 183 motors[0]->set_home();
Davidroid 1:9f1974b0960d 184
Davidroid 1:9f1974b0960d 185 /* Waiting. */
Davidroid 1:9f1974b0960d 186 wait_ms(DELAY_1);
Davidroid 0:5148e9486cf2 187
Davidroid 1:9f1974b0960d 188 /* Getting the current position. */
davide.aliprandi@st.com 24:d1f487cb02ba 189 int position = motors[0]->get_position();
Davidroid 18:591a007effc2 190
Davidroid 1:9f1974b0960d 191 /* Printing to the console. */
Davidroid 1:9f1974b0960d 192 printf("--> Getting the current position: %d\r\n", position);
Davidroid 1:9f1974b0960d 193
Davidroid 1:9f1974b0960d 194 /* Waiting. */
Davidroid 1:9f1974b0960d 195 wait_ms(DELAY_1);
Davidroid 1:9f1974b0960d 196
Davidroid 1:9f1974b0960d 197 /* Printing to the console. */
Davidroid 1:9f1974b0960d 198 printf("--> Moving forward %d steps.\r\n", STEPS_1);
Davidroid 1:9f1974b0960d 199
Davidroid 1:9f1974b0960d 200 /* Moving. */
davide.aliprandi@st.com 24:d1f487cb02ba 201 motors[0]->move(StepperMotor::FWD, STEPS_1);
Davidroid 0:5148e9486cf2 202
Davidroid 1:9f1974b0960d 203 /* Waiting while active. */
davide.aliprandi@st.com 24:d1f487cb02ba 204 motors[0]->wait_while_active();
Davidroid 1:9f1974b0960d 205
Davidroid 1:9f1974b0960d 206 /* Getting the current position. */
davide.aliprandi@st.com 24:d1f487cb02ba 207 position = motors[0]->get_position();
Davidroid 1:9f1974b0960d 208
Davidroid 1:9f1974b0960d 209 /* Printing to the console. */
Davidroid 1:9f1974b0960d 210 printf("--> Getting the current position: %d\r\n", position);
Davidroid 1:9f1974b0960d 211
Davidroid 1:9f1974b0960d 212 /* Printing to the console. */
Davidroid 1:9f1974b0960d 213 printf("--> Marking the current position.\r\n");
Davidroid 0:5148e9486cf2 214
Davidroid 1:9f1974b0960d 215 /* Marking the current position. */
davide.aliprandi@st.com 24:d1f487cb02ba 216 motors[0]->set_mark();
Davidroid 1:9f1974b0960d 217
Davidroid 1:9f1974b0960d 218 /* Waiting. */
Davidroid 1:9f1974b0960d 219 wait_ms(DELAY_1);
Davidroid 1:9f1974b0960d 220
Davidroid 1:9f1974b0960d 221 /* Printing to the console. */
Davidroid 1:9f1974b0960d 222 printf("--> Moving backward %d steps.\r\n", STEPS_2);
Davidroid 1:9f1974b0960d 223
Davidroid 1:9f1974b0960d 224 /* Moving. */
davide.aliprandi@st.com 24:d1f487cb02ba 225 motors[0]->move(StepperMotor::BWD, STEPS_2);
Davidroid 1:9f1974b0960d 226
Davidroid 1:9f1974b0960d 227 /* Waiting while active. */
davide.aliprandi@st.com 24:d1f487cb02ba 228 motors[0]->wait_while_active();
Davidroid 0:5148e9486cf2 229
Davidroid 1:9f1974b0960d 230 /* Waiting. */
Davidroid 1:9f1974b0960d 231 wait_ms(DELAY_1);
Davidroid 1:9f1974b0960d 232
Davidroid 1:9f1974b0960d 233 /* Getting the current position. */
davide.aliprandi@st.com 24:d1f487cb02ba 234 position = motors[0]->get_position();
Davidroid 1:9f1974b0960d 235
Davidroid 1:9f1974b0960d 236 /* Printing to the console. */
Davidroid 1:9f1974b0960d 237 printf("--> Getting the current position: %d\r\n", position);
Davidroid 1:9f1974b0960d 238
Davidroid 1:9f1974b0960d 239 /* Waiting. */
Davidroid 1:9f1974b0960d 240 wait_ms(DELAY_1);
Davidroid 0:5148e9486cf2 241
Davidroid 1:9f1974b0960d 242 /* Printing to the console. */
Davidroid 1:9f1974b0960d 243 printf("--> Going to marked position.\r\n");
Davidroid 0:5148e9486cf2 244
Davidroid 1:9f1974b0960d 245 /* Going to marked position. */
davide.aliprandi@st.com 24:d1f487cb02ba 246 motors[0]->go_mark();
Davidroid 1:9f1974b0960d 247
Davidroid 1:9f1974b0960d 248 /* Waiting while active. */
davide.aliprandi@st.com 24:d1f487cb02ba 249 motors[0]->wait_while_active();
Davidroid 0:5148e9486cf2 250
Davidroid 1:9f1974b0960d 251 /* Waiting. */
Davidroid 1:9f1974b0960d 252 wait_ms(DELAY_1);
Davidroid 0:5148e9486cf2 253
Davidroid 1:9f1974b0960d 254 /* Getting the current position. */
davide.aliprandi@st.com 24:d1f487cb02ba 255 position = motors[0]->get_position();
Davidroid 1:9f1974b0960d 256
Davidroid 1:9f1974b0960d 257 /* Printing to the console. */
Davidroid 1:9f1974b0960d 258 printf("--> Getting the current position: %d\r\n", position);
Davidroid 0:5148e9486cf2 259
Davidroid 1:9f1974b0960d 260 /* Waiting. */
Davidroid 1:9f1974b0960d 261 wait_ms(DELAY_1);
Davidroid 1:9f1974b0960d 262
Davidroid 1:9f1974b0960d 263 /* Printing to the console. */
Davidroid 1:9f1974b0960d 264 printf("--> Going to home position.\r\n");
Davidroid 0:5148e9486cf2 265
Davidroid 1:9f1974b0960d 266 /* Going to home position. */
davide.aliprandi@st.com 24:d1f487cb02ba 267 motors[0]->go_home();
Davidroid 1:9f1974b0960d 268
Davidroid 1:9f1974b0960d 269 /* Waiting while active. */
davide.aliprandi@st.com 24:d1f487cb02ba 270 motors[0]->wait_while_active();
Davidroid 1:9f1974b0960d 271
Davidroid 1:9f1974b0960d 272 /* Waiting. */
Davidroid 1:9f1974b0960d 273 wait_ms(DELAY_1);
Davidroid 0:5148e9486cf2 274
Davidroid 1:9f1974b0960d 275 /* Getting the current position. */
davide.aliprandi@st.com 24:d1f487cb02ba 276 position = motors[0]->get_position();
Davidroid 1:9f1974b0960d 277
Davidroid 1:9f1974b0960d 278 /* Printing to the console. */
Davidroid 1:9f1974b0960d 279 printf("--> Getting the current position: %d\r\n", position);
Davidroid 1:9f1974b0960d 280
Davidroid 1:9f1974b0960d 281 /* Waiting. */
Davidroid 18:591a007effc2 282 wait_ms(DELAY_1);
Davidroid 18:591a007effc2 283
Davidroid 18:591a007effc2 284 /* Printing to the console. */
Davidroid 18:591a007effc2 285 printf("--> Halving the microsteps.\r\n");
Davidroid 18:591a007effc2 286
Davidroid 18:591a007effc2 287 /* Halving the microsteps. */
Davidroid 18:591a007effc2 288 init[0].step_sel = (init[0].step_sel > 0 ? init[0].step_sel - 1 : init[0].step_sel);
davide.aliprandi@st.com 24:d1f487cb02ba 289 if (!motors[0]->set_step_mode((StepperMotor::step_mode_t) init[0].step_sel)) {
Davidroid 18:591a007effc2 290 printf(" Step Mode not allowed.\r\n");
Davidroid 22:e81ccf73bc5d 291 }
Davidroid 18:591a007effc2 292
Davidroid 18:591a007effc2 293 /* Waiting. */
Davidroid 18:591a007effc2 294 wait_ms(DELAY_1);
Davidroid 18:591a007effc2 295
Davidroid 18:591a007effc2 296 /* Printing to the console. */
Davidroid 18:591a007effc2 297 printf("--> Setting home position.\r\n");
Davidroid 18:591a007effc2 298
Davidroid 18:591a007effc2 299 /* Setting the home position. */
davide.aliprandi@st.com 24:d1f487cb02ba 300 motors[0]->set_home();
Davidroid 18:591a007effc2 301
Davidroid 18:591a007effc2 302 /* Waiting. */
Davidroid 18:591a007effc2 303 wait_ms(DELAY_1);
Davidroid 18:591a007effc2 304
Davidroid 18:591a007effc2 305 /* Getting the current position. */
davide.aliprandi@st.com 24:d1f487cb02ba 306 position = motors[0]->get_position();
Davidroid 18:591a007effc2 307
Davidroid 18:591a007effc2 308 /* Printing to the console. */
Davidroid 18:591a007effc2 309 printf("--> Getting the current position: %d\r\n", position);
Davidroid 18:591a007effc2 310
Davidroid 18:591a007effc2 311 /* Waiting. */
Davidroid 18:591a007effc2 312 wait_ms(DELAY_1);
Davidroid 18:591a007effc2 313
Davidroid 18:591a007effc2 314 /* Printing to the console. */
Davidroid 18:591a007effc2 315 printf("--> Moving forward %d steps.\r\n", STEPS_1);
Davidroid 18:591a007effc2 316
Davidroid 18:591a007effc2 317 /* Moving. */
davide.aliprandi@st.com 24:d1f487cb02ba 318 motors[0]->move(StepperMotor::FWD, STEPS_1);
Davidroid 18:591a007effc2 319
Davidroid 18:591a007effc2 320 /* Waiting while active. */
davide.aliprandi@st.com 24:d1f487cb02ba 321 motors[0]->wait_while_active();
Davidroid 18:591a007effc2 322
Davidroid 18:591a007effc2 323 /* Getting the current position. */
davide.aliprandi@st.com 24:d1f487cb02ba 324 position = motors[0]->get_position();
Davidroid 18:591a007effc2 325
Davidroid 18:591a007effc2 326 /* Printing to the console. */
Davidroid 18:591a007effc2 327 printf("--> Getting the current position: %d\r\n", position);
Davidroid 18:591a007effc2 328
Davidroid 18:591a007effc2 329 /* Printing to the console. */
Davidroid 18:591a007effc2 330 printf("--> Marking the current position.\r\n");
Davidroid 18:591a007effc2 331
Davidroid 18:591a007effc2 332 /* Marking the current position. */
davide.aliprandi@st.com 24:d1f487cb02ba 333 motors[0]->set_mark();
Davidroid 18:591a007effc2 334
Davidroid 18:591a007effc2 335 /* Waiting. */
Davidroid 1:9f1974b0960d 336 wait_ms(DELAY_2);
Davidroid 0:5148e9486cf2 337
Davidroid 0:5148e9486cf2 338
Davidroid 1:9f1974b0960d 339 /*----- Running together for a certain amount of time. -----*/
Davidroid 1:9f1974b0960d 340
Davidroid 1:9f1974b0960d 341 /* Printing to the console. */
Davidroid 1:9f1974b0960d 342 printf("--> Running together for %d seconds.\r\n", DELAY_3 / 1000);
Davidroid 0:5148e9486cf2 343
Davidroid 1:9f1974b0960d 344 /* Preparing each motor to perform a run at a specified speed. */
Davidroid 22:e81ccf73bc5d 345 for (int m = 0; m < L6470DAISYCHAINSIZE; m++) {
davide.aliprandi@st.com 24:d1f487cb02ba 346 motors[m]->prepare_run(StepperMotor::BWD, 400);
Davidroid 22:e81ccf73bc5d 347 }
Davidroid 0:5148e9486cf2 348
Davidroid 1:9f1974b0960d 349 /* Performing the action on each motor at the same time. */
davide.aliprandi@st.com 24:d1f487cb02ba 350 x_nucleo_ihm02a1->perform_prepared_actions();
Davidroid 0:5148e9486cf2 351
Davidroid 1:9f1974b0960d 352 /* Waiting. */
Davidroid 1:9f1974b0960d 353 wait_ms(DELAY_3);
Davidroid 1:9f1974b0960d 354
Davidroid 1:9f1974b0960d 355
Davidroid 1:9f1974b0960d 356 /*----- Increasing the speed while running. -----*/
Davidroid 0:5148e9486cf2 357
Davidroid 1:9f1974b0960d 358 /* Preparing each motor to perform a run at a specified speed. */
Davidroid 22:e81ccf73bc5d 359 for (int m = 0; m < L6470DAISYCHAINSIZE; m++) {
davide.aliprandi@st.com 24:d1f487cb02ba 360 motors[m]->prepare_get_speed();
Davidroid 22:e81ccf73bc5d 361 }
Davidroid 0:5148e9486cf2 362
Davidroid 1:9f1974b0960d 363 /* Performing the action on each motor at the same time. */
davide.aliprandi@st.com 24:d1f487cb02ba 364 uint32_t* results = x_nucleo_ihm02a1->perform_prepared_actions();
Davidroid 0:5148e9486cf2 365
Davidroid 1:9f1974b0960d 366 /* Printing to the console. */
Davidroid 1:9f1974b0960d 367 printf(" Speed: M1 %d, M2 %d.\r\n", results[0], results[1]);
Davidroid 1:9f1974b0960d 368
Davidroid 1:9f1974b0960d 369 /* Printing to the console. */
Davidroid 18:591a007effc2 370 printf("--> Doublig the speed while running again for %d seconds.\r\n", DELAY_3 / 1000);
Davidroid 0:5148e9486cf2 371
Davidroid 1:9f1974b0960d 372 /* Preparing each motor to perform a run at a specified speed. */
Davidroid 22:e81ccf73bc5d 373 for (int m = 0; m < L6470DAISYCHAINSIZE; m++) {
davide.aliprandi@st.com 24:d1f487cb02ba 374 motors[m]->prepare_run(StepperMotor::BWD, results[m] << 1);
Davidroid 22:e81ccf73bc5d 375 }
Davidroid 1:9f1974b0960d 376
Davidroid 1:9f1974b0960d 377 /* Performing the action on each motor at the same time. */
davide.aliprandi@st.com 24:d1f487cb02ba 378 results = x_nucleo_ihm02a1->perform_prepared_actions();
Davidroid 0:5148e9486cf2 379
Davidroid 1:9f1974b0960d 380 /* Waiting. */
Davidroid 1:9f1974b0960d 381 wait_ms(DELAY_3);
Davidroid 0:5148e9486cf2 382
Davidroid 1:9f1974b0960d 383 /* Preparing each motor to perform a run at a specified speed. */
Davidroid 22:e81ccf73bc5d 384 for (int m = 0; m < L6470DAISYCHAINSIZE; m++) {
davide.aliprandi@st.com 24:d1f487cb02ba 385 motors[m]->prepare_get_speed();
Davidroid 22:e81ccf73bc5d 386 }
Davidroid 0:5148e9486cf2 387
Davidroid 1:9f1974b0960d 388 /* Performing the action on each motor at the same time. */
davide.aliprandi@st.com 24:d1f487cb02ba 389 results = x_nucleo_ihm02a1->perform_prepared_actions();
Davidroid 0:5148e9486cf2 390
Davidroid 1:9f1974b0960d 391 /* Printing to the console. */
Davidroid 1:9f1974b0960d 392 printf(" Speed: M1 %d, M2 %d.\r\n", results[0], results[1]);
Davidroid 1:9f1974b0960d 393
Davidroid 1:9f1974b0960d 394 /* Waiting. */
Davidroid 1:9f1974b0960d 395 wait_ms(DELAY_1);
Davidroid 0:5148e9486cf2 396
Davidroid 0:5148e9486cf2 397
Davidroid 1:9f1974b0960d 398 /*----- Hard Stop. -----*/
Davidroid 0:5148e9486cf2 399
Davidroid 1:9f1974b0960d 400 /* Printing to the console. */
Davidroid 1:9f1974b0960d 401 printf("--> Hard Stop.\r\n");
Davidroid 0:5148e9486cf2 402
Davidroid 1:9f1974b0960d 403 /* Preparing each motor to perform a hard stop. */
Davidroid 22:e81ccf73bc5d 404 for (int m = 0; m < L6470DAISYCHAINSIZE; m++) {
davide.aliprandi@st.com 24:d1f487cb02ba 405 motors[m]->prepare_hard_stop();
Davidroid 22:e81ccf73bc5d 406 }
Davidroid 0:5148e9486cf2 407
Davidroid 1:9f1974b0960d 408 /* Performing the action on each motor at the same time. */
davide.aliprandi@st.com 24:d1f487cb02ba 409 x_nucleo_ihm02a1->perform_prepared_actions();
Davidroid 0:5148e9486cf2 410
Davidroid 1:9f1974b0960d 411 /* Waiting. */
Davidroid 1:9f1974b0960d 412 wait_ms(DELAY_2);
Davidroid 0:5148e9486cf2 413
Davidroid 0:5148e9486cf2 414
Davidroid 1:9f1974b0960d 415 /*----- Doing a full revolution on each motor, one after the other. -----*/
Davidroid 1:9f1974b0960d 416
Davidroid 1:9f1974b0960d 417 /* Printing to the console. */
Davidroid 1:9f1974b0960d 418 printf("--> Doing a full revolution on each motor, one after the other.\r\n");
Davidroid 1:9f1974b0960d 419
Davidroid 1:9f1974b0960d 420 /* Doing a full revolution on each motor, one after the other. */
Davidroid 22:e81ccf73bc5d 421 for (int m = 0; m < L6470DAISYCHAINSIZE; m++) {
Davidroid 22:e81ccf73bc5d 422 for (int i = 0; i < MPR_1; i++) {
Davidroid 1:9f1974b0960d 423 /* Computing the number of steps. */
Davidroid 9:f35fbeedb8f4 424 int steps = (int) (((int) init[m].fullstepsperrevolution * pow(2.0f, init[m].step_sel)) / MPR_1);
Davidroid 1:9f1974b0960d 425
Davidroid 1:9f1974b0960d 426 /* Moving. */
davide.aliprandi@st.com 24:d1f487cb02ba 427 motors[m]->move(StepperMotor::FWD, steps);
Davidroid 1:9f1974b0960d 428
Davidroid 1:9f1974b0960d 429 /* Waiting while active. */
davide.aliprandi@st.com 24:d1f487cb02ba 430 motors[m]->wait_while_active();
Davidroid 1:9f1974b0960d 431
Davidroid 1:9f1974b0960d 432 /* Waiting. */
Davidroid 1:9f1974b0960d 433 wait_ms(DELAY_1);
Davidroid 1:9f1974b0960d 434 }
Davidroid 22:e81ccf73bc5d 435 }
Davidroid 1:9f1974b0960d 436
Davidroid 1:9f1974b0960d 437 /* Waiting. */
Davidroid 1:9f1974b0960d 438 wait_ms(DELAY_2);
Davidroid 1:9f1974b0960d 439
Davidroid 1:9f1974b0960d 440
Davidroid 1:9f1974b0960d 441 /*----- High Impedance State. -----*/
Davidroid 1:9f1974b0960d 442
Davidroid 1:9f1974b0960d 443 /* Printing to the console. */
Davidroid 1:9f1974b0960d 444 printf("--> High Impedance State.\r\n");
Davidroid 1:9f1974b0960d 445
Davidroid 1:9f1974b0960d 446 /* Preparing each motor to set High Impedance State. */
Davidroid 22:e81ccf73bc5d 447 for (int m = 0; m < L6470DAISYCHAINSIZE; m++) {
davide.aliprandi@st.com 24:d1f487cb02ba 448 motors[m]->prepare_hard_hiz();
Davidroid 22:e81ccf73bc5d 449 }
Davidroid 1:9f1974b0960d 450
Davidroid 1:9f1974b0960d 451 /* Performing the action on each motor at the same time. */
davide.aliprandi@st.com 24:d1f487cb02ba 452 x_nucleo_ihm02a1->perform_prepared_actions();
Davidroid 1:9f1974b0960d 453
Davidroid 1:9f1974b0960d 454 /* Waiting. */
Davidroid 1:9f1974b0960d 455 wait_ms(DELAY_2);
Davidroid 22:e81ccf73bc5d 456 }